Skip to content

Commit

Permalink
Fix CJS for bip174
Browse files Browse the repository at this point in the history
  • Loading branch information
junderw committed Sep 19, 2024
1 parent 9c876f1 commit 3c7df20
Show file tree
Hide file tree
Showing 65 changed files with 130 additions and 505 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/main_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ jobs:
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run format:ci
check-hybrid:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run checkHybrid
gitdiff:
runs-on: ubuntu-latest
steps:
Expand Down
24 changes: 24 additions & 0 deletions fixup.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fs = require('fs');
const path = require('path');

const updateRequires = (filePath) => {
let content = fs.readFileSync(filePath, 'utf8');
//replace local imports eg. require("./ecpair.js") to require("ecpair.cjs")
content = content.replace(/require\('\.([^']*)\.js'\)/g, "require('.$1.cjs')");

fs.writeFileSync(filePath, content, 'utf8');
};

const processFiles = (dir) => {
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
if (fs.lstatSync(filePath).isDirectory()) {
processFiles(filePath);
} else if (filePath.endsWith('.cjs')) {
updateRequires(filePath);
}
});
};

const dir = path.join(__dirname, 'src', 'cjs');
processFiles(dir);
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "bip174",
"version": "3.0.0-rc.0",
"description": "",
"main": "src/cjs/lib/psbt.js",
"main": "src/cjs/lib/psbt.cjs",
"module": "src/esm/lib/psbt.js",
"types": "src/cjs/lib/psbt.d.ts",
"types": "src/esm/lib/psbt.d.ts",
"exports": {
".": {
"types": "./src/cjs/lib/psbt.d.ts",
"types": "./src/esm/lib/psbt.d.ts",
"import": "./src/esm/lib/psbt.js",
"require": "./src/cjs/lib/psbt.js"
"require": "./src/cjs/lib/psbt.cjs"
}
},
"type": "module",
Expand All @@ -22,6 +22,7 @@
},
"scripts": {
"build": "npm run clean && tsc -p ./tsconfig.json && tsc -p ./tsconfig.cjs.json && npm run formatjs",
"checkHybrid": "chmod +x test.cjs && node test.cjs",
"clean": "rimraf src types",
"coverage": "c8 --check-coverage --include='src/esm/lib/**/*.js' --reporter=lcov --reporter=text --branches 90 --functions 90 --lines 90 npm run unit",
"flb": "npm run format && npm run lint && npm run build",
Expand All @@ -30,6 +31,7 @@
"format:ci": "npm run prettier -- --check && npm run prettierjs -- --check",
"gitdiff:ci": "npm run build && git diff --exit-code",
"lint": "tslint -p tsconfig.json -c tslint.json",
"postbuild": "find src/cjs -type f -name \"*.js\" -exec bash -c 'mv \"$0\" \"${0%.js}.cjs\"' {} \\; && chmod +x fixup.cjs && node fixup.cjs",
"prettier": "prettier 'ts_src/**/*.ts' --ignore-path ./.prettierignore",
"prettierjs": "prettier 'src/**/*.js' --ignore-path ./.prettierignore",
"test": "npm run format:ci && npm run lint && npm run build && npm run coverage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const index_js_1 = require('../parser/index.js');
const index_js_1 = require('../parser/index.cjs');
const tools = __importStar(require('uint8array-tools'));
function combine(psbts) {
const self = psbts[0];
Expand Down
2 changes: 0 additions & 2 deletions src/cjs/lib/combiner/index.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../../typeFields.js');
const typeFields_js_1 = require('../../typeFields.cjs');
const tools = __importStar(require('uint8array-tools'));
const range = n => [...Array(n).keys()];
function decode(keyVal) {
Expand Down
6 changes: 0 additions & 6 deletions src/cjs/lib/converter/global/globalXpub.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../../typeFields.js');
const typeFields_js_1 = require('../../typeFields.cjs');
function encode(data) {
return {
key: new Uint8Array([typeFields_js_1.GlobalTypes.UNSIGNED_TX]),
Expand Down
2 changes: 0 additions & 2 deletions src/cjs/lib/converter/global/unsignedTx.d.ts

This file was deleted.

42 changes: 21 additions & 21 deletions src/cjs/lib/converter/index.js → src/cjs/lib/converter/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../typeFields.js');
const globalXpub = __importStar(require('./global/globalXpub.js'));
const unsignedTx = __importStar(require('./global/unsignedTx.js'));
const finalScriptSig = __importStar(require('./input/finalScriptSig.js'));
const typeFields_js_1 = require('../typeFields.cjs');
const globalXpub = __importStar(require('./global/globalXpub.cjs'));
const unsignedTx = __importStar(require('./global/unsignedTx.cjs'));
const finalScriptSig = __importStar(require('./input/finalScriptSig.cjs'));
const finalScriptWitness = __importStar(
require('./input/finalScriptWitness.js'),
require('./input/finalScriptWitness.cjs'),
);
const nonWitnessUtxo = __importStar(require('./input/nonWitnessUtxo.js'));
const partialSig = __importStar(require('./input/partialSig.js'));
const porCommitment = __importStar(require('./input/porCommitment.js'));
const sighashType = __importStar(require('./input/sighashType.js'));
const tapKeySig = __importStar(require('./input/tapKeySig.js'));
const tapLeafScript = __importStar(require('./input/tapLeafScript.js'));
const tapMerkleRoot = __importStar(require('./input/tapMerkleRoot.js'));
const tapScriptSig = __importStar(require('./input/tapScriptSig.js'));
const witnessUtxo = __importStar(require('./input/witnessUtxo.js'));
const tapTree = __importStar(require('./output/tapTree.js'));
const bip32Derivation = __importStar(require('./shared/bip32Derivation.js'));
const checkPubkey = __importStar(require('./shared/checkPubkey.js'));
const redeemScript = __importStar(require('./shared/redeemScript.js'));
const nonWitnessUtxo = __importStar(require('./input/nonWitnessUtxo.cjs'));
const partialSig = __importStar(require('./input/partialSig.cjs'));
const porCommitment = __importStar(require('./input/porCommitment.cjs'));
const sighashType = __importStar(require('./input/sighashType.cjs'));
const tapKeySig = __importStar(require('./input/tapKeySig.cjs'));
const tapLeafScript = __importStar(require('./input/tapLeafScript.cjs'));
const tapMerkleRoot = __importStar(require('./input/tapMerkleRoot.cjs'));
const tapScriptSig = __importStar(require('./input/tapScriptSig.cjs'));
const witnessUtxo = __importStar(require('./input/witnessUtxo.cjs'));
const tapTree = __importStar(require('./output/tapTree.cjs'));
const bip32Derivation = __importStar(require('./shared/bip32Derivation.cjs'));
const checkPubkey = __importStar(require('./shared/checkPubkey.cjs'));
const redeemScript = __importStar(require('./shared/redeemScript.cjs'));
const tapBip32Derivation = __importStar(
require('./shared/tapBip32Derivation.js'),
require('./shared/tapBip32Derivation.cjs'),
);
const tapInternalKey = __importStar(require('./shared/tapInternalKey.js'));
const witnessScript = __importStar(require('./shared/witnessScript.js'));
const tapInternalKey = __importStar(require('./shared/tapInternalKey.cjs'));
const witnessScript = __importStar(require('./shared/witnessScript.cjs'));
const globals = {
unsignedTx,
globalXpub,
Expand Down
108 changes: 0 additions & 108 deletions src/cjs/lib/converter/index.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../../typeFields.js');
const typeFields_js_1 = require('../../typeFields.cjs');
const tools = __importStar(require('uint8array-tools'));
function decode(keyVal) {
if (keyVal.key[0] !== typeFields_js_1.InputTypes.FINAL_SCRIPTSIG) {
Expand Down
6 changes: 0 additions & 6 deletions src/cjs/lib/converter/input/finalScriptSig.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../../typeFields.js');
const typeFields_js_1 = require('../../typeFields.cjs');
const tools = __importStar(require('uint8array-tools'));
function decode(keyVal) {
if (keyVal.key[0] !== typeFields_js_1.InputTypes.FINAL_SCRIPTWITNESS) {
Expand Down
6 changes: 0 additions & 6 deletions src/cjs/lib/converter/input/finalScriptWitness.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../../typeFields.js');
const typeFields_js_1 = require('../../typeFields.cjs');
const tools = __importStar(require('uint8array-tools'));
function decode(keyVal) {
if (keyVal.key[0] !== typeFields_js_1.InputTypes.NON_WITNESS_UTXO) {
Expand Down
6 changes: 0 additions & 6 deletions src/cjs/lib/converter/input/nonWitnessUtxo.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../../typeFields.js');
const typeFields_js_1 = require('../../typeFields.cjs');
const tools = __importStar(require('uint8array-tools'));
function decode(keyVal) {
if (keyVal.key[0] !== typeFields_js_1.InputTypes.PARTIAL_SIG) {
Expand Down
6 changes: 0 additions & 6 deletions src/cjs/lib/converter/input/partialSig.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../../typeFields.js');
const typeFields_js_1 = require('../../typeFields.cjs');
const tools = __importStar(require('uint8array-tools'));
function decode(keyVal) {
if (keyVal.key[0] !== typeFields_js_1.InputTypes.POR_COMMITMENT) {
Expand Down
6 changes: 0 additions & 6 deletions src/cjs/lib/converter/input/porCommitment.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../../typeFields.js');
const typeFields_js_1 = require('../../typeFields.cjs');
const tools = __importStar(require('uint8array-tools'));
function decode(keyVal) {
if (keyVal.key[0] !== typeFields_js_1.InputTypes.SIGHASH_TYPE) {
Expand Down
6 changes: 0 additions & 6 deletions src/cjs/lib/converter/input/sighashType.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../../typeFields.js');
const typeFields_js_1 = require('../../typeFields.cjs');
const tools = __importStar(require('uint8array-tools'));
function decode(keyVal) {
if (
Expand Down
6 changes: 0 additions & 6 deletions src/cjs/lib/converter/input/tapKeySig.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var __importStar =
return result;
};
Object.defineProperty(exports, '__esModule', { value: true });
const typeFields_js_1 = require('../../typeFields.js');
const typeFields_js_1 = require('../../typeFields.cjs');
const tools = __importStar(require('uint8array-tools'));
function decode(keyVal) {
if (keyVal.key[0] !== typeFields_js_1.InputTypes.TAP_LEAF_SCRIPT) {
Expand Down
Loading

0 comments on commit 3c7df20

Please sign in to comment.