From 3c7df20851c5b29a01477cedc90017ae77b1282e Mon Sep 17 00:00:00 2001 From: junderw Date: Thu, 19 Sep 2024 17:59:45 +0900 Subject: [PATCH] Fix CJS for bip174 --- .github/workflows/main_ci.yml | 10 ++ fixup.cjs | 24 ++++ package.json | 10 +- src/cjs/lib/combiner/{index.js => index.cjs} | 2 +- src/cjs/lib/combiner/index.d.ts | 2 - .../global/{globalXpub.js => globalXpub.cjs} | 2 +- src/cjs/lib/converter/global/globalXpub.d.ts | 6 - .../global/{unsignedTx.js => unsignedTx.cjs} | 2 +- src/cjs/lib/converter/global/unsignedTx.d.ts | 2 - src/cjs/lib/converter/{index.js => index.cjs} | 42 +++---- src/cjs/lib/converter/index.d.ts | 108 ----------------- .../{finalScriptSig.js => finalScriptSig.cjs} | 2 +- .../lib/converter/input/finalScriptSig.d.ts | 6 - ...criptWitness.js => finalScriptWitness.cjs} | 2 +- .../converter/input/finalScriptWitness.d.ts | 6 - .../{nonWitnessUtxo.js => nonWitnessUtxo.cjs} | 2 +- .../lib/converter/input/nonWitnessUtxo.d.ts | 6 - .../input/{partialSig.js => partialSig.cjs} | 2 +- src/cjs/lib/converter/input/partialSig.d.ts | 6 - .../{porCommitment.js => porCommitment.cjs} | 2 +- .../lib/converter/input/porCommitment.d.ts | 6 - .../input/{sighashType.js => sighashType.cjs} | 2 +- src/cjs/lib/converter/input/sighashType.d.ts | 6 - .../input/{tapKeySig.js => tapKeySig.cjs} | 2 +- src/cjs/lib/converter/input/tapKeySig.d.ts | 6 - .../{tapLeafScript.js => tapLeafScript.cjs} | 2 +- .../lib/converter/input/tapLeafScript.d.ts | 6 - .../{tapMerkleRoot.js => tapMerkleRoot.cjs} | 2 +- .../lib/converter/input/tapMerkleRoot.d.ts | 6 - .../{tapScriptSig.js => tapScriptSig.cjs} | 2 +- src/cjs/lib/converter/input/tapScriptSig.d.ts | 6 - .../input/{witnessUtxo.js => witnessUtxo.cjs} | 2 +- src/cjs/lib/converter/input/witnessUtxo.d.ts | 6 - .../output/{tapTree.js => tapTree.cjs} | 2 +- src/cjs/lib/converter/output/tapTree.d.ts | 6 - ...bip32Derivation.js => bip32Derivation.cjs} | 0 .../lib/converter/shared/bip32Derivation.d.ts | 8 -- .../{checkPubkey.js => checkPubkey.cjs} | 0 src/cjs/lib/converter/shared/checkPubkey.d.ts | 2 - .../{redeemScript.js => redeemScript.cjs} | 0 .../lib/converter/shared/redeemScript.d.ts | 8 -- ...32Derivation.js => tapBip32Derivation.cjs} | 2 +- .../converter/shared/tapBip32Derivation.d.ts | 8 -- .../{tapInternalKey.js => tapInternalKey.cjs} | 0 .../lib/converter/shared/tapInternalKey.d.ts | 8 -- .../{witnessScript.js => witnessScript.cjs} | 0 .../lib/converter/shared/witnessScript.d.ts | 8 -- src/cjs/lib/converter/{tools.js => tools.cjs} | 0 src/cjs/lib/converter/tools.d.ts | 5 - src/cjs/lib/{interfaces.js => interfaces.cjs} | 0 src/cjs/lib/interfaces.d.ts | 114 ------------------ .../parser/{fromBuffer.js => fromBuffer.cjs} | 6 +- src/cjs/lib/parser/fromBuffer.d.ts | 11 -- src/cjs/lib/parser/{index.js => index.cjs} | 4 +- src/cjs/lib/parser/index.d.ts | 8 -- .../lib/parser/{toBuffer.js => toBuffer.cjs} | 4 +- src/cjs/lib/parser/toBuffer.d.ts | 8 -- src/cjs/lib/{psbt.js => psbt.cjs} | 10 +- src/cjs/lib/psbt.d.ts | 26 ---- src/cjs/lib/{typeFields.js => typeFields.cjs} | 0 src/cjs/lib/typeFields.d.ts | 33 ----- src/cjs/lib/{utils.js => utils.cjs} | 2 +- src/cjs/lib/utils.d.ts | 13 -- test.cjs | 39 ++++++ tsconfig.cjs.json | 2 +- 65 files changed, 130 insertions(+), 505 deletions(-) create mode 100755 fixup.cjs rename src/cjs/lib/combiner/{index.js => index.cjs} (98%) delete mode 100644 src/cjs/lib/combiner/index.d.ts rename src/cjs/lib/converter/global/{globalXpub.js => globalXpub.cjs} (98%) delete mode 100644 src/cjs/lib/converter/global/globalXpub.d.ts rename src/cjs/lib/converter/global/{unsignedTx.js => unsignedTx.cjs} (80%) delete mode 100644 src/cjs/lib/converter/global/unsignedTx.d.ts rename src/cjs/lib/converter/{index.js => index.cjs} (78%) delete mode 100644 src/cjs/lib/converter/index.d.ts rename src/cjs/lib/converter/input/{finalScriptSig.js => finalScriptSig.cjs} (95%) delete mode 100644 src/cjs/lib/converter/input/finalScriptSig.d.ts rename src/cjs/lib/converter/input/{finalScriptWitness.js => finalScriptWitness.cjs} (95%) delete mode 100644 src/cjs/lib/converter/input/finalScriptWitness.d.ts rename src/cjs/lib/converter/input/{nonWitnessUtxo.js => nonWitnessUtxo.cjs} (95%) delete mode 100644 src/cjs/lib/converter/input/nonWitnessUtxo.d.ts rename src/cjs/lib/converter/input/{partialSig.js => partialSig.cjs} (97%) delete mode 100644 src/cjs/lib/converter/input/partialSig.d.ts rename src/cjs/lib/converter/input/{porCommitment.js => porCommitment.cjs} (95%) delete mode 100644 src/cjs/lib/converter/input/porCommitment.d.ts rename src/cjs/lib/converter/input/{sighashType.js => sighashType.cjs} (95%) delete mode 100644 src/cjs/lib/converter/input/sighashType.d.ts rename src/cjs/lib/converter/input/{tapKeySig.js => tapKeySig.cjs} (95%) delete mode 100644 src/cjs/lib/converter/input/tapKeySig.d.ts rename src/cjs/lib/converter/input/{tapLeafScript.js => tapLeafScript.cjs} (97%) delete mode 100644 src/cjs/lib/converter/input/tapLeafScript.d.ts rename src/cjs/lib/converter/input/{tapMerkleRoot.js => tapMerkleRoot.cjs} (95%) delete mode 100644 src/cjs/lib/converter/input/tapMerkleRoot.d.ts rename src/cjs/lib/converter/input/{tapScriptSig.js => tapScriptSig.cjs} (97%) delete mode 100644 src/cjs/lib/converter/input/tapScriptSig.d.ts rename src/cjs/lib/converter/input/{witnessUtxo.js => witnessUtxo.cjs} (97%) delete mode 100644 src/cjs/lib/converter/input/witnessUtxo.d.ts rename src/cjs/lib/converter/output/{tapTree.js => tapTree.cjs} (97%) delete mode 100644 src/cjs/lib/converter/output/tapTree.d.ts rename src/cjs/lib/converter/shared/{bip32Derivation.js => bip32Derivation.cjs} (100%) delete mode 100644 src/cjs/lib/converter/shared/bip32Derivation.d.ts rename src/cjs/lib/converter/shared/{checkPubkey.js => checkPubkey.cjs} (100%) delete mode 100644 src/cjs/lib/converter/shared/checkPubkey.d.ts rename src/cjs/lib/converter/shared/{redeemScript.js => redeemScript.cjs} (100%) delete mode 100644 src/cjs/lib/converter/shared/redeemScript.d.ts rename src/cjs/lib/converter/shared/{tapBip32Derivation.js => tapBip32Derivation.cjs} (99%) delete mode 100644 src/cjs/lib/converter/shared/tapBip32Derivation.d.ts rename src/cjs/lib/converter/shared/{tapInternalKey.js => tapInternalKey.cjs} (100%) delete mode 100644 src/cjs/lib/converter/shared/tapInternalKey.d.ts rename src/cjs/lib/converter/shared/{witnessScript.js => witnessScript.cjs} (100%) delete mode 100644 src/cjs/lib/converter/shared/witnessScript.d.ts rename src/cjs/lib/converter/{tools.js => tools.cjs} (100%) delete mode 100644 src/cjs/lib/converter/tools.d.ts rename src/cjs/lib/{interfaces.js => interfaces.cjs} (100%) delete mode 100644 src/cjs/lib/interfaces.d.ts rename src/cjs/lib/parser/{fromBuffer.js => fromBuffer.cjs} (98%) delete mode 100644 src/cjs/lib/parser/fromBuffer.d.ts rename src/cjs/lib/parser/{index.js => index.cjs} (69%) delete mode 100644 src/cjs/lib/parser/index.d.ts rename src/cjs/lib/parser/{toBuffer.js => toBuffer.cjs} (95%) delete mode 100644 src/cjs/lib/parser/toBuffer.d.ts rename src/cjs/lib/{psbt.js => psbt.cjs} (95%) delete mode 100644 src/cjs/lib/psbt.d.ts rename src/cjs/lib/{typeFields.js => typeFields.cjs} (100%) delete mode 100644 src/cjs/lib/typeFields.d.ts rename src/cjs/lib/{utils.js => utils.cjs} (98%) delete mode 100644 src/cjs/lib/utils.d.ts create mode 100755 test.cjs diff --git a/.github/workflows/main_ci.yml b/.github/workflows/main_ci.yml index 2109d39..f97c25f 100644 --- a/.github/workflows/main_ci.yml +++ b/.github/workflows/main_ci.yml @@ -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: diff --git a/fixup.cjs b/fixup.cjs new file mode 100755 index 0000000..c939164 --- /dev/null +++ b/fixup.cjs @@ -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); diff --git a/package.json b/package.json index 6f44158..62c354f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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", diff --git a/src/cjs/lib/combiner/index.js b/src/cjs/lib/combiner/index.cjs similarity index 98% rename from src/cjs/lib/combiner/index.js rename to src/cjs/lib/combiner/index.cjs index 29e44a6..6ce2fdd 100644 --- a/src/cjs/lib/combiner/index.js +++ b/src/cjs/lib/combiner/index.cjs @@ -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]; diff --git a/src/cjs/lib/combiner/index.d.ts b/src/cjs/lib/combiner/index.d.ts deleted file mode 100644 index f4ebd8c..0000000 --- a/src/cjs/lib/combiner/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { PsbtAttributes } from '../parser/index.js'; -export declare function combine(psbts: PsbtAttributes[]): PsbtAttributes; diff --git a/src/cjs/lib/converter/global/globalXpub.js b/src/cjs/lib/converter/global/globalXpub.cjs similarity index 98% rename from src/cjs/lib/converter/global/globalXpub.js rename to src/cjs/lib/converter/global/globalXpub.cjs index 198e604..18449b7 100644 --- a/src/cjs/lib/converter/global/globalXpub.js +++ b/src/cjs/lib/converter/global/globalXpub.cjs @@ -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) { diff --git a/src/cjs/lib/converter/global/globalXpub.d.ts b/src/cjs/lib/converter/global/globalXpub.d.ts deleted file mode 100644 index a3b0d11..0000000 --- a/src/cjs/lib/converter/global/globalXpub.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { GlobalXpub, KeyValue } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): GlobalXpub; -export declare function encode(data: GlobalXpub): KeyValue; -export declare const expected = "{ masterFingerprint: Uint8Array; extendedPubkey: Uint8Array; path: string; }"; -export declare function check(data: any): data is GlobalXpub; -export declare function canAddToArray(array: GlobalXpub[], item: GlobalXpub, dupeSet: Set): boolean; diff --git a/src/cjs/lib/converter/global/unsignedTx.js b/src/cjs/lib/converter/global/unsignedTx.cjs similarity index 80% rename from src/cjs/lib/converter/global/unsignedTx.js rename to src/cjs/lib/converter/global/unsignedTx.cjs index bc402e0..6822620 100644 --- a/src/cjs/lib/converter/global/unsignedTx.js +++ b/src/cjs/lib/converter/global/unsignedTx.cjs @@ -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]), diff --git a/src/cjs/lib/converter/global/unsignedTx.d.ts b/src/cjs/lib/converter/global/unsignedTx.d.ts deleted file mode 100644 index ddcdce4..0000000 --- a/src/cjs/lib/converter/global/unsignedTx.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { KeyValue, Transaction } from '../../interfaces'; -export declare function encode(data: Transaction): KeyValue; diff --git a/src/cjs/lib/converter/index.js b/src/cjs/lib/converter/index.cjs similarity index 78% rename from src/cjs/lib/converter/index.js rename to src/cjs/lib/converter/index.cjs index 16c908e..f94d2ad 100644 --- a/src/cjs/lib/converter/index.js +++ b/src/cjs/lib/converter/index.cjs @@ -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, diff --git a/src/cjs/lib/converter/index.d.ts b/src/cjs/lib/converter/index.d.ts deleted file mode 100644 index f152688..0000000 --- a/src/cjs/lib/converter/index.d.ts +++ /dev/null @@ -1,108 +0,0 @@ -import * as globalXpub from './global/globalXpub.js'; -import * as unsignedTx from './global/unsignedTx.js'; -import * as finalScriptSig from './input/finalScriptSig.js'; -import * as finalScriptWitness from './input/finalScriptWitness.js'; -import * as nonWitnessUtxo from './input/nonWitnessUtxo.js'; -import * as partialSig from './input/partialSig.js'; -import * as porCommitment from './input/porCommitment.js'; -import * as sighashType from './input/sighashType.js'; -import * as tapKeySig from './input/tapKeySig.js'; -import * as tapLeafScript from './input/tapLeafScript.js'; -import * as tapMerkleRoot from './input/tapMerkleRoot.js'; -import * as tapScriptSig from './input/tapScriptSig.js'; -import * as witnessUtxo from './input/witnessUtxo.js'; -import * as tapTree from './output/tapTree.js'; -declare const globals: { - unsignedTx: typeof unsignedTx; - globalXpub: typeof globalXpub; - checkPubkey: (keyVal: import("../interfaces.js").KeyValue) => Uint8Array | undefined; -}; -declare const inputs: { - nonWitnessUtxo: typeof nonWitnessUtxo; - partialSig: typeof partialSig; - sighashType: typeof sighashType; - finalScriptSig: typeof finalScriptSig; - finalScriptWitness: typeof finalScriptWitness; - porCommitment: typeof porCommitment; - witnessUtxo: typeof witnessUtxo; - bip32Derivation: { - decode: (keyVal: import("../interfaces.js").KeyValue) => import("../interfaces.js").Bip32Derivation; - encode: (data: import("../interfaces.js").Bip32Derivation) => import("../interfaces.js").KeyValue; - check: (data: any) => data is import("../interfaces.js").Bip32Derivation; - expected: string; - canAddToArray: (array: import("../interfaces.js").Bip32Derivation[], item: import("../interfaces.js").Bip32Derivation, dupeSet: Set) => boolean; - }; - redeemScript: { - decode: (keyVal: import("../interfaces.js").KeyValue) => Uint8Array; - encode: (data: Uint8Array) => import("../interfaces.js").KeyValue; - check: (data: any) => data is Uint8Array; - expected: string; - canAdd: (currentData: any, newData: any) => boolean; - }; - witnessScript: { - decode: (keyVal: import("../interfaces.js").KeyValue) => Uint8Array; - encode: (data: Uint8Array) => import("../interfaces.js").KeyValue; - check: (data: any) => data is Uint8Array; - expected: string; - canAdd: (currentData: any, newData: any) => boolean; - }; - checkPubkey: (keyVal: import("../interfaces.js").KeyValue) => Uint8Array | undefined; - tapKeySig: typeof tapKeySig; - tapScriptSig: typeof tapScriptSig; - tapLeafScript: typeof tapLeafScript; - tapBip32Derivation: { - decode: (keyVal: import("../interfaces.js").KeyValue) => import("../interfaces.js").TapBip32Derivation; - encode: (data: import("../interfaces.js").TapBip32Derivation) => import("../interfaces.js").KeyValue; - check: (data: any) => data is import("../interfaces.js").TapBip32Derivation; - expected: string; - canAddToArray: (array: import("../interfaces.js").TapBip32Derivation[], item: import("../interfaces.js").TapBip32Derivation, dupeSet: Set) => boolean; - }; - tapInternalKey: { - decode: (keyVal: import("../interfaces.js").KeyValue) => Uint8Array; - encode: (data: Uint8Array) => import("../interfaces.js").KeyValue; - check: (data: any) => data is Uint8Array; - expected: string; - canAdd: (currentData: any, newData: any) => boolean; - }; - tapMerkleRoot: typeof tapMerkleRoot; -}; -declare const outputs: { - bip32Derivation: { - decode: (keyVal: import("../interfaces.js").KeyValue) => import("../interfaces.js").Bip32Derivation; - encode: (data: import("../interfaces.js").Bip32Derivation) => import("../interfaces.js").KeyValue; - check: (data: any) => data is import("../interfaces.js").Bip32Derivation; - expected: string; - canAddToArray: (array: import("../interfaces.js").Bip32Derivation[], item: import("../interfaces.js").Bip32Derivation, dupeSet: Set) => boolean; - }; - redeemScript: { - decode: (keyVal: import("../interfaces.js").KeyValue) => Uint8Array; - encode: (data: Uint8Array) => import("../interfaces.js").KeyValue; - check: (data: any) => data is Uint8Array; - expected: string; - canAdd: (currentData: any, newData: any) => boolean; - }; - witnessScript: { - decode: (keyVal: import("../interfaces.js").KeyValue) => Uint8Array; - encode: (data: Uint8Array) => import("../interfaces.js").KeyValue; - check: (data: any) => data is Uint8Array; - expected: string; - canAdd: (currentData: any, newData: any) => boolean; - }; - checkPubkey: (keyVal: import("../interfaces.js").KeyValue) => Uint8Array | undefined; - tapBip32Derivation: { - decode: (keyVal: import("../interfaces.js").KeyValue) => import("../interfaces.js").TapBip32Derivation; - encode: (data: import("../interfaces.js").TapBip32Derivation) => import("../interfaces.js").KeyValue; - check: (data: any) => data is import("../interfaces.js").TapBip32Derivation; - expected: string; - canAddToArray: (array: import("../interfaces.js").TapBip32Derivation[], item: import("../interfaces.js").TapBip32Derivation, dupeSet: Set) => boolean; - }; - tapTree: typeof tapTree; - tapInternalKey: { - decode: (keyVal: import("../interfaces.js").KeyValue) => Uint8Array; - encode: (data: Uint8Array) => import("../interfaces.js").KeyValue; - check: (data: any) => data is Uint8Array; - expected: string; - canAdd: (currentData: any, newData: any) => boolean; - }; -}; -export { globals, inputs, outputs }; diff --git a/src/cjs/lib/converter/input/finalScriptSig.js b/src/cjs/lib/converter/input/finalScriptSig.cjs similarity index 95% rename from src/cjs/lib/converter/input/finalScriptSig.js rename to src/cjs/lib/converter/input/finalScriptSig.cjs index 239598f..2111e73 100644 --- a/src/cjs/lib/converter/input/finalScriptSig.js +++ b/src/cjs/lib/converter/input/finalScriptSig.cjs @@ -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) { diff --git a/src/cjs/lib/converter/input/finalScriptSig.d.ts b/src/cjs/lib/converter/input/finalScriptSig.d.ts deleted file mode 100644 index f08bc72..0000000 --- a/src/cjs/lib/converter/input/finalScriptSig.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { FinalScriptSig, KeyValue } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): FinalScriptSig; -export declare function encode(data: FinalScriptSig): KeyValue; -export declare const expected = "Uint8Array"; -export declare function check(data: any): data is FinalScriptSig; -export declare function canAdd(currentData: any, newData: any): boolean; diff --git a/src/cjs/lib/converter/input/finalScriptWitness.js b/src/cjs/lib/converter/input/finalScriptWitness.cjs similarity index 95% rename from src/cjs/lib/converter/input/finalScriptWitness.js rename to src/cjs/lib/converter/input/finalScriptWitness.cjs index 9c1f91a..c76e2fb 100644 --- a/src/cjs/lib/converter/input/finalScriptWitness.js +++ b/src/cjs/lib/converter/input/finalScriptWitness.cjs @@ -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) { diff --git a/src/cjs/lib/converter/input/finalScriptWitness.d.ts b/src/cjs/lib/converter/input/finalScriptWitness.d.ts deleted file mode 100644 index aa64099..0000000 --- a/src/cjs/lib/converter/input/finalScriptWitness.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { FinalScriptWitness, KeyValue } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): FinalScriptWitness; -export declare function encode(data: FinalScriptWitness): KeyValue; -export declare const expected = "Uint8Array"; -export declare function check(data: any): data is FinalScriptWitness; -export declare function canAdd(currentData: any, newData: any): boolean; diff --git a/src/cjs/lib/converter/input/nonWitnessUtxo.js b/src/cjs/lib/converter/input/nonWitnessUtxo.cjs similarity index 95% rename from src/cjs/lib/converter/input/nonWitnessUtxo.js rename to src/cjs/lib/converter/input/nonWitnessUtxo.cjs index 5d7847a..f2451dc 100644 --- a/src/cjs/lib/converter/input/nonWitnessUtxo.js +++ b/src/cjs/lib/converter/input/nonWitnessUtxo.cjs @@ -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) { diff --git a/src/cjs/lib/converter/input/nonWitnessUtxo.d.ts b/src/cjs/lib/converter/input/nonWitnessUtxo.d.ts deleted file mode 100644 index 498a9ba..0000000 --- a/src/cjs/lib/converter/input/nonWitnessUtxo.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { KeyValue, NonWitnessUtxo } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): NonWitnessUtxo; -export declare function encode(data: NonWitnessUtxo): KeyValue; -export declare const expected = "Uint8Array"; -export declare function check(data: any): data is NonWitnessUtxo; -export declare function canAdd(currentData: any, newData: any): boolean; diff --git a/src/cjs/lib/converter/input/partialSig.js b/src/cjs/lib/converter/input/partialSig.cjs similarity index 97% rename from src/cjs/lib/converter/input/partialSig.js rename to src/cjs/lib/converter/input/partialSig.cjs index a790584..6c50212 100644 --- a/src/cjs/lib/converter/input/partialSig.js +++ b/src/cjs/lib/converter/input/partialSig.cjs @@ -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) { diff --git a/src/cjs/lib/converter/input/partialSig.d.ts b/src/cjs/lib/converter/input/partialSig.d.ts deleted file mode 100644 index b7fd8c5..0000000 --- a/src/cjs/lib/converter/input/partialSig.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { KeyValue, PartialSig } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): PartialSig; -export declare function encode(pSig: PartialSig): KeyValue; -export declare const expected = "{ pubkey: Uint8Array; signature: Uint8Array; }"; -export declare function check(data: any): data is PartialSig; -export declare function canAddToArray(array: PartialSig[], item: PartialSig, dupeSet: Set): boolean; diff --git a/src/cjs/lib/converter/input/porCommitment.js b/src/cjs/lib/converter/input/porCommitment.cjs similarity index 95% rename from src/cjs/lib/converter/input/porCommitment.js rename to src/cjs/lib/converter/input/porCommitment.cjs index 30cd582..47b8340 100644 --- a/src/cjs/lib/converter/input/porCommitment.js +++ b/src/cjs/lib/converter/input/porCommitment.cjs @@ -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) { diff --git a/src/cjs/lib/converter/input/porCommitment.d.ts b/src/cjs/lib/converter/input/porCommitment.d.ts deleted file mode 100644 index 1f45bb3..0000000 --- a/src/cjs/lib/converter/input/porCommitment.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { KeyValue, PorCommitment } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): PorCommitment; -export declare function encode(data: PorCommitment): KeyValue; -export declare const expected = "string"; -export declare function check(data: any): data is PorCommitment; -export declare function canAdd(currentData: any, newData: any): boolean; diff --git a/src/cjs/lib/converter/input/sighashType.js b/src/cjs/lib/converter/input/sighashType.cjs similarity index 95% rename from src/cjs/lib/converter/input/sighashType.js rename to src/cjs/lib/converter/input/sighashType.cjs index 623f100..263dd28 100644 --- a/src/cjs/lib/converter/input/sighashType.js +++ b/src/cjs/lib/converter/input/sighashType.cjs @@ -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) { diff --git a/src/cjs/lib/converter/input/sighashType.d.ts b/src/cjs/lib/converter/input/sighashType.d.ts deleted file mode 100644 index a86e990..0000000 --- a/src/cjs/lib/converter/input/sighashType.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { KeyValue, SighashType } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): SighashType; -export declare function encode(data: SighashType): KeyValue; -export declare const expected = "number"; -export declare function check(data: any): data is SighashType; -export declare function canAdd(currentData: any, newData: any): boolean; diff --git a/src/cjs/lib/converter/input/tapKeySig.js b/src/cjs/lib/converter/input/tapKeySig.cjs similarity index 95% rename from src/cjs/lib/converter/input/tapKeySig.js rename to src/cjs/lib/converter/input/tapKeySig.cjs index 9449eeb..c28a6a3 100644 --- a/src/cjs/lib/converter/input/tapKeySig.js +++ b/src/cjs/lib/converter/input/tapKeySig.cjs @@ -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 ( diff --git a/src/cjs/lib/converter/input/tapKeySig.d.ts b/src/cjs/lib/converter/input/tapKeySig.d.ts deleted file mode 100644 index 07b357b..0000000 --- a/src/cjs/lib/converter/input/tapKeySig.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { KeyValue, TapKeySig } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): TapKeySig; -export declare function encode(value: TapKeySig): KeyValue; -export declare const expected = "Uint8Array"; -export declare function check(data: any): data is TapKeySig; -export declare function canAdd(currentData: any, newData: any): boolean; diff --git a/src/cjs/lib/converter/input/tapLeafScript.js b/src/cjs/lib/converter/input/tapLeafScript.cjs similarity index 97% rename from src/cjs/lib/converter/input/tapLeafScript.js rename to src/cjs/lib/converter/input/tapLeafScript.cjs index ff4382b..d3feb6b 100644 --- a/src/cjs/lib/converter/input/tapLeafScript.js +++ b/src/cjs/lib/converter/input/tapLeafScript.cjs @@ -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) { diff --git a/src/cjs/lib/converter/input/tapLeafScript.d.ts b/src/cjs/lib/converter/input/tapLeafScript.d.ts deleted file mode 100644 index f0ac9da..0000000 --- a/src/cjs/lib/converter/input/tapLeafScript.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { KeyValue, TapLeafScript } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): TapLeafScript; -export declare function encode(tScript: TapLeafScript): KeyValue; -export declare const expected = "{ controlBlock: Uint8Array; leafVersion: number, script: Uint8Array; }"; -export declare function check(data: any): data is TapLeafScript; -export declare function canAddToArray(array: TapLeafScript[], item: TapLeafScript, dupeSet: Set): boolean; diff --git a/src/cjs/lib/converter/input/tapMerkleRoot.js b/src/cjs/lib/converter/input/tapMerkleRoot.cjs similarity index 95% rename from src/cjs/lib/converter/input/tapMerkleRoot.js rename to src/cjs/lib/converter/input/tapMerkleRoot.cjs index a233a7f..df22167 100644 --- a/src/cjs/lib/converter/input/tapMerkleRoot.js +++ b/src/cjs/lib/converter/input/tapMerkleRoot.cjs @@ -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 ( diff --git a/src/cjs/lib/converter/input/tapMerkleRoot.d.ts b/src/cjs/lib/converter/input/tapMerkleRoot.d.ts deleted file mode 100644 index 1e222dc..0000000 --- a/src/cjs/lib/converter/input/tapMerkleRoot.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { KeyValue, TapMerkleRoot } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): TapMerkleRoot; -export declare function encode(value: TapMerkleRoot): KeyValue; -export declare const expected = "Uint8Array"; -export declare function check(data: any): data is TapMerkleRoot; -export declare function canAdd(currentData: any, newData: any): boolean; diff --git a/src/cjs/lib/converter/input/tapScriptSig.js b/src/cjs/lib/converter/input/tapScriptSig.cjs similarity index 97% rename from src/cjs/lib/converter/input/tapScriptSig.js rename to src/cjs/lib/converter/input/tapScriptSig.cjs index ad2b2db..818fad1 100644 --- a/src/cjs/lib/converter/input/tapScriptSig.js +++ b/src/cjs/lib/converter/input/tapScriptSig.cjs @@ -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_SCRIPT_SIG) { diff --git a/src/cjs/lib/converter/input/tapScriptSig.d.ts b/src/cjs/lib/converter/input/tapScriptSig.d.ts deleted file mode 100644 index 6172daa..0000000 --- a/src/cjs/lib/converter/input/tapScriptSig.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { KeyValue, TapScriptSig } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): TapScriptSig; -export declare function encode(tSig: TapScriptSig): KeyValue; -export declare const expected = "{ pubkey: Uint8Array; leafHash: Uint8Array; signature: Uint8Array; }"; -export declare function check(data: any): data is TapScriptSig; -export declare function canAddToArray(array: TapScriptSig[], item: TapScriptSig, dupeSet: Set): boolean; diff --git a/src/cjs/lib/converter/input/witnessUtxo.js b/src/cjs/lib/converter/input/witnessUtxo.cjs similarity index 97% rename from src/cjs/lib/converter/input/witnessUtxo.js rename to src/cjs/lib/converter/input/witnessUtxo.cjs index 1c56e96..3979d9d 100644 --- a/src/cjs/lib/converter/input/witnessUtxo.js +++ b/src/cjs/lib/converter/input/witnessUtxo.cjs @@ -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 varuint = __importStar(require('varuint-bitcoin')); function decode(keyVal) { diff --git a/src/cjs/lib/converter/input/witnessUtxo.d.ts b/src/cjs/lib/converter/input/witnessUtxo.d.ts deleted file mode 100644 index f670563..0000000 --- a/src/cjs/lib/converter/input/witnessUtxo.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { KeyValue, WitnessUtxo } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): WitnessUtxo; -export declare function encode(data: WitnessUtxo): KeyValue; -export declare const expected = "{ script: Uint8Array; value: bigint; }"; -export declare function check(data: any): data is WitnessUtxo; -export declare function canAdd(currentData: any, newData: any): boolean; diff --git a/src/cjs/lib/converter/output/tapTree.js b/src/cjs/lib/converter/output/tapTree.cjs similarity index 97% rename from src/cjs/lib/converter/output/tapTree.js rename to src/cjs/lib/converter/output/tapTree.cjs index ed3aac5..8fd1dd4 100644 --- a/src/cjs/lib/converter/output/tapTree.js +++ b/src/cjs/lib/converter/output/tapTree.cjs @@ -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 varuint = __importStar(require('varuint-bitcoin')); const tools = __importStar(require('uint8array-tools')); function decode(keyVal) { diff --git a/src/cjs/lib/converter/output/tapTree.d.ts b/src/cjs/lib/converter/output/tapTree.d.ts deleted file mode 100644 index f976363..0000000 --- a/src/cjs/lib/converter/output/tapTree.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { KeyValue, TapTree } from '../../interfaces'; -export declare function decode(keyVal: KeyValue): TapTree; -export declare function encode(tree: TapTree): KeyValue; -export declare const expected = "{ leaves: [{ depth: number; leafVersion: number, script: Uint8Array; }] }"; -export declare function check(data: any): data is TapTree; -export declare function canAdd(currentData: any, newData: any): boolean; diff --git a/src/cjs/lib/converter/shared/bip32Derivation.js b/src/cjs/lib/converter/shared/bip32Derivation.cjs similarity index 100% rename from src/cjs/lib/converter/shared/bip32Derivation.js rename to src/cjs/lib/converter/shared/bip32Derivation.cjs diff --git a/src/cjs/lib/converter/shared/bip32Derivation.d.ts b/src/cjs/lib/converter/shared/bip32Derivation.d.ts deleted file mode 100644 index d3b646d..0000000 --- a/src/cjs/lib/converter/shared/bip32Derivation.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Bip32Derivation, KeyValue } from '../../interfaces'; -export declare function makeConverter(TYPE_BYTE: number, isValidPubkey?: (pubkey: Uint8Array) => boolean): { - decode: (keyVal: KeyValue) => Bip32Derivation; - encode: (data: Bip32Derivation) => KeyValue; - check: (data: any) => data is Bip32Derivation; - expected: string; - canAddToArray: (array: Bip32Derivation[], item: Bip32Derivation, dupeSet: Set) => boolean; -}; diff --git a/src/cjs/lib/converter/shared/checkPubkey.js b/src/cjs/lib/converter/shared/checkPubkey.cjs similarity index 100% rename from src/cjs/lib/converter/shared/checkPubkey.js rename to src/cjs/lib/converter/shared/checkPubkey.cjs diff --git a/src/cjs/lib/converter/shared/checkPubkey.d.ts b/src/cjs/lib/converter/shared/checkPubkey.d.ts deleted file mode 100644 index 0966a06..0000000 --- a/src/cjs/lib/converter/shared/checkPubkey.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { KeyValue } from '../../interfaces'; -export declare function makeChecker(pubkeyTypes: number[]): (keyVal: KeyValue) => Uint8Array | undefined; diff --git a/src/cjs/lib/converter/shared/redeemScript.js b/src/cjs/lib/converter/shared/redeemScript.cjs similarity index 100% rename from src/cjs/lib/converter/shared/redeemScript.js rename to src/cjs/lib/converter/shared/redeemScript.cjs diff --git a/src/cjs/lib/converter/shared/redeemScript.d.ts b/src/cjs/lib/converter/shared/redeemScript.d.ts deleted file mode 100644 index fa1f0d8..0000000 --- a/src/cjs/lib/converter/shared/redeemScript.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { KeyValue, RedeemScript } from '../../interfaces'; -export declare function makeConverter(TYPE_BYTE: number): { - decode: (keyVal: KeyValue) => RedeemScript; - encode: (data: RedeemScript) => KeyValue; - check: (data: any) => data is RedeemScript; - expected: string; - canAdd: (currentData: any, newData: any) => boolean; -}; diff --git a/src/cjs/lib/converter/shared/tapBip32Derivation.js b/src/cjs/lib/converter/shared/tapBip32Derivation.cjs similarity index 99% rename from src/cjs/lib/converter/shared/tapBip32Derivation.js rename to src/cjs/lib/converter/shared/tapBip32Derivation.cjs index aeb9289..5d89b4c 100644 --- a/src/cjs/lib/converter/shared/tapBip32Derivation.js +++ b/src/cjs/lib/converter/shared/tapBip32Derivation.cjs @@ -13,7 +13,7 @@ var __importStar = Object.defineProperty(exports, '__esModule', { value: true }); const varuint = __importStar(require('varuint-bitcoin')); const tools = __importStar(require('uint8array-tools')); -const bip32Derivation = __importStar(require('./bip32Derivation.js')); +const bip32Derivation = __importStar(require('./bip32Derivation.cjs')); const isValidBIP340Key = pubkey => pubkey.length === 32; function makeConverter(TYPE_BYTE) { const parent = bip32Derivation.makeConverter(TYPE_BYTE, isValidBIP340Key); diff --git a/src/cjs/lib/converter/shared/tapBip32Derivation.d.ts b/src/cjs/lib/converter/shared/tapBip32Derivation.d.ts deleted file mode 100644 index ef42ca9..0000000 --- a/src/cjs/lib/converter/shared/tapBip32Derivation.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { KeyValue, TapBip32Derivation } from '../../interfaces'; -export declare function makeConverter(TYPE_BYTE: number): { - decode: (keyVal: KeyValue) => TapBip32Derivation; - encode: (data: TapBip32Derivation) => KeyValue; - check: (data: any) => data is TapBip32Derivation; - expected: string; - canAddToArray: (array: TapBip32Derivation[], item: TapBip32Derivation, dupeSet: Set) => boolean; -}; diff --git a/src/cjs/lib/converter/shared/tapInternalKey.js b/src/cjs/lib/converter/shared/tapInternalKey.cjs similarity index 100% rename from src/cjs/lib/converter/shared/tapInternalKey.js rename to src/cjs/lib/converter/shared/tapInternalKey.cjs diff --git a/src/cjs/lib/converter/shared/tapInternalKey.d.ts b/src/cjs/lib/converter/shared/tapInternalKey.d.ts deleted file mode 100644 index 30e5e4f..0000000 --- a/src/cjs/lib/converter/shared/tapInternalKey.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { KeyValue, TapInternalKey } from '../../interfaces'; -export declare function makeConverter(TYPE_BYTE: number): { - decode: (keyVal: KeyValue) => TapInternalKey; - encode: (data: TapInternalKey) => KeyValue; - check: (data: any) => data is TapInternalKey; - expected: string; - canAdd: (currentData: any, newData: any) => boolean; -}; diff --git a/src/cjs/lib/converter/shared/witnessScript.js b/src/cjs/lib/converter/shared/witnessScript.cjs similarity index 100% rename from src/cjs/lib/converter/shared/witnessScript.js rename to src/cjs/lib/converter/shared/witnessScript.cjs diff --git a/src/cjs/lib/converter/shared/witnessScript.d.ts b/src/cjs/lib/converter/shared/witnessScript.d.ts deleted file mode 100644 index 809c322..0000000 --- a/src/cjs/lib/converter/shared/witnessScript.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { KeyValue, WitnessScript } from '../../interfaces'; -export declare function makeConverter(TYPE_BYTE: number): { - decode: (keyVal: KeyValue) => WitnessScript; - encode: (data: WitnessScript) => KeyValue; - check: (data: any) => data is WitnessScript; - expected: string; - canAdd: (currentData: any, newData: any) => boolean; -}; diff --git a/src/cjs/lib/converter/tools.js b/src/cjs/lib/converter/tools.cjs similarity index 100% rename from src/cjs/lib/converter/tools.js rename to src/cjs/lib/converter/tools.cjs diff --git a/src/cjs/lib/converter/tools.d.ts b/src/cjs/lib/converter/tools.d.ts deleted file mode 100644 index 0fbb8a6..0000000 --- a/src/cjs/lib/converter/tools.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { KeyValue } from '../interfaces'; -export declare const range: (n: number) => number[]; -export declare function reverseBuffer(buffer: Uint8Array): Uint8Array; -export declare function keyValsToBuffer(keyVals: KeyValue[]): Uint8Array; -export declare function keyValToBuffer(keyVal: KeyValue): Uint8Array; diff --git a/src/cjs/lib/interfaces.js b/src/cjs/lib/interfaces.cjs similarity index 100% rename from src/cjs/lib/interfaces.js rename to src/cjs/lib/interfaces.cjs diff --git a/src/cjs/lib/interfaces.d.ts b/src/cjs/lib/interfaces.d.ts deleted file mode 100644 index 9a5112e..0000000 --- a/src/cjs/lib/interfaces.d.ts +++ /dev/null @@ -1,114 +0,0 @@ -export declare type TransactionFromBuffer = (buffer: Uint8Array) => Transaction; -export interface Transaction { - getInputOutputCounts(): { - inputCount: number; - outputCount: number; - }; - addInput(objectArg: any): void; - addOutput(objectArg: any): void; - toBuffer(): Uint8Array; -} -export interface KeyValue { - key: Uint8Array; - value: Uint8Array; -} -export interface PsbtGlobal extends PsbtGlobalUpdate { - unsignedTx: Transaction; - unknownKeyVals?: KeyValue[]; -} -export interface PsbtGlobalUpdate { - globalXpub?: GlobalXpub[]; -} -export interface PsbtInput extends PsbtInputUpdate { - unknownKeyVals?: KeyValue[]; -} -export interface PsbtInputUpdate { - partialSig?: PartialSig[]; - nonWitnessUtxo?: NonWitnessUtxo; - witnessUtxo?: WitnessUtxo; - sighashType?: SighashType; - redeemScript?: RedeemScript; - witnessScript?: WitnessScript; - bip32Derivation?: Bip32Derivation[]; - finalScriptSig?: FinalScriptSig; - finalScriptWitness?: FinalScriptWitness; - porCommitment?: PorCommitment; - tapKeySig?: TapKeySig; - tapScriptSig?: TapScriptSig[]; - tapLeafScript?: TapLeafScript[]; - tapBip32Derivation?: TapBip32Derivation[]; - tapInternalKey?: TapInternalKey; - tapMerkleRoot?: TapMerkleRoot; -} -export interface PsbtInputExtended extends PsbtInput { - [index: string]: any; -} -export interface PsbtOutput extends PsbtOutputUpdate { - unknownKeyVals?: KeyValue[]; -} -export interface PsbtOutputUpdate { - redeemScript?: RedeemScript; - witnessScript?: WitnessScript; - bip32Derivation?: Bip32Derivation[]; - tapBip32Derivation?: TapBip32Derivation[]; - tapTree?: TapTree; - tapInternalKey?: TapInternalKey; -} -export interface PsbtOutputExtended extends PsbtOutput { - [index: string]: any; -} -export interface GlobalXpub { - extendedPubkey: Uint8Array; - masterFingerprint: Uint8Array; - path: string; -} -export interface PartialSig { - pubkey: Uint8Array; - signature: Uint8Array; -} -export interface Bip32Derivation { - masterFingerprint: Uint8Array; - pubkey: Uint8Array; - path: string; -} -export interface WitnessUtxo { - script: Uint8Array; - value: bigint; -} -export declare type NonWitnessUtxo = Uint8Array; -export declare type SighashType = number; -export declare type RedeemScript = Uint8Array; -export declare type WitnessScript = Uint8Array; -export declare type FinalScriptSig = Uint8Array; -export declare type FinalScriptWitness = Uint8Array; -export declare type PorCommitment = string; -export declare type TapKeySig = Uint8Array; -export interface TapScriptSig extends PartialSig { - leafHash: Uint8Array; -} -interface TapScript { - leafVersion: number; - script: Uint8Array; -} -export declare type ControlBlock = Uint8Array; -export interface TapLeafScript extends TapScript { - controlBlock: ControlBlock; -} -export interface TapBip32Derivation extends Bip32Derivation { - leafHashes: Uint8Array[]; -} -export declare type TapInternalKey = Uint8Array; -export declare type TapMerkleRoot = Uint8Array; -export interface TapLeaf extends TapScript { - depth: number; -} -export interface TapTree { - leaves: TapLeaf[]; -} -export declare type TransactionIOCountGetter = (txBuffer: Uint8Array) => { - inputCount: number; - outputCount: number; -}; -export declare type TransactionVersionSetter = (version: number, txBuffer: Uint8Array) => Uint8Array; -export declare type TransactionLocktimeSetter = (locktime: number, txBuffer: Uint8Array) => Uint8Array; -export {}; diff --git a/src/cjs/lib/parser/fromBuffer.js b/src/cjs/lib/parser/fromBuffer.cjs similarity index 98% rename from src/cjs/lib/parser/fromBuffer.js rename to src/cjs/lib/parser/fromBuffer.cjs index 91249a4..2492341 100644 --- a/src/cjs/lib/parser/fromBuffer.js +++ b/src/cjs/lib/parser/fromBuffer.cjs @@ -11,11 +11,11 @@ var __importStar = return result; }; Object.defineProperty(exports, '__esModule', { value: true }); -const convert = __importStar(require('../converter/index.js')); -const tools_js_1 = require('../converter/tools.js'); +const convert = __importStar(require('../converter/index.cjs')); +const tools_js_1 = require('../converter/tools.cjs'); const varuint = __importStar(require('varuint-bitcoin')); const tools = __importStar(require('uint8array-tools')); -const typeFields_js_1 = require('../typeFields.js'); +const typeFields_js_1 = require('../typeFields.cjs'); function psbtFromBuffer(buffer, txGetter) { let offset = 0; function varSlice() { diff --git a/src/cjs/lib/parser/fromBuffer.d.ts b/src/cjs/lib/parser/fromBuffer.d.ts deleted file mode 100644 index f59bc3b..0000000 --- a/src/cjs/lib/parser/fromBuffer.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { KeyValue, Transaction, TransactionFromBuffer } from '../interfaces'; -import { PsbtAttributes } from './index.js'; -export declare function psbtFromBuffer(buffer: Uint8Array, txGetter: TransactionFromBuffer): PsbtAttributes; -interface PsbtFromKeyValsArg { - globalMapKeyVals: KeyValue[]; - inputKeyVals: KeyValue[][]; - outputKeyVals: KeyValue[][]; -} -export declare function checkKeyBuffer(type: string, keyBuf: Uint8Array, keyNum: number): void; -export declare function psbtFromKeyVals(unsignedTx: Transaction, { globalMapKeyVals, inputKeyVals, outputKeyVals }: PsbtFromKeyValsArg): PsbtAttributes; -export {}; diff --git a/src/cjs/lib/parser/index.js b/src/cjs/lib/parser/index.cjs similarity index 69% rename from src/cjs/lib/parser/index.js rename to src/cjs/lib/parser/index.cjs index 6f30632..ceb0073 100644 --- a/src/cjs/lib/parser/index.js +++ b/src/cjs/lib/parser/index.cjs @@ -3,5 +3,5 @@ function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, '__esModule', { value: true }); -__export(require('./fromBuffer.js')); -__export(require('./toBuffer.js')); +__export(require('./fromBuffer.cjs')); +__export(require('./toBuffer.cjs')); diff --git a/src/cjs/lib/parser/index.d.ts b/src/cjs/lib/parser/index.d.ts deleted file mode 100644 index bbd9eae..0000000 --- a/src/cjs/lib/parser/index.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { PsbtGlobal, PsbtInput, PsbtOutput } from '../interfaces'; -export * from './fromBuffer.js'; -export * from './toBuffer.js'; -export interface PsbtAttributes { - globalMap: PsbtGlobal; - inputs: PsbtInput[]; - outputs: PsbtOutput[]; -} diff --git a/src/cjs/lib/parser/toBuffer.js b/src/cjs/lib/parser/toBuffer.cjs similarity index 95% rename from src/cjs/lib/parser/toBuffer.js rename to src/cjs/lib/parser/toBuffer.cjs index c1596aa..c9e9192 100644 --- a/src/cjs/lib/parser/toBuffer.js +++ b/src/cjs/lib/parser/toBuffer.cjs @@ -11,8 +11,8 @@ var __importStar = return result; }; Object.defineProperty(exports, '__esModule', { value: true }); -const convert = __importStar(require('../converter/index.js')); -const tools_js_1 = require('../converter/tools.js'); +const convert = __importStar(require('../converter/index.cjs')); +const tools_js_1 = require('../converter/tools.cjs'); const tools = __importStar(require('uint8array-tools')); function psbtToBuffer({ globalMap, inputs, outputs }) { const { globalKeyVals, inputKeyVals, outputKeyVals } = psbtToKeyVals({ diff --git a/src/cjs/lib/parser/toBuffer.d.ts b/src/cjs/lib/parser/toBuffer.d.ts deleted file mode 100644 index 4e7b230..0000000 --- a/src/cjs/lib/parser/toBuffer.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { KeyValue } from '../interfaces'; -import { PsbtAttributes } from './index.js'; -export declare function psbtToBuffer({ globalMap, inputs, outputs, }: PsbtAttributes): Uint8Array; -export declare function psbtToKeyVals({ globalMap, inputs, outputs, }: PsbtAttributes): { - globalKeyVals: KeyValue[]; - inputKeyVals: KeyValue[][]; - outputKeyVals: KeyValue[][]; -}; diff --git a/src/cjs/lib/psbt.js b/src/cjs/lib/psbt.cjs similarity index 95% rename from src/cjs/lib/psbt.js rename to src/cjs/lib/psbt.cjs index c41024a..2118dda 100644 --- a/src/cjs/lib/psbt.js +++ b/src/cjs/lib/psbt.cjs @@ -11,10 +11,10 @@ var __importStar = return result; }; Object.defineProperty(exports, '__esModule', { value: true }); -const index_js_1 = require('./combiner/index.js'); -const index_js_2 = require('./parser/index.js'); -const typeFields_js_1 = require('./typeFields.js'); -const utils_js_1 = require('./utils.js'); +const index_js_1 = require('./combiner/index.cjs'); +const index_js_2 = require('./parser/index.cjs'); +const typeFields_js_1 = require('./typeFields.cjs'); +const utils_js_1 = require('./utils.cjs'); const tools = __importStar(require('uint8array-tools')); class Psbt { constructor(tx) { @@ -158,6 +158,6 @@ class Psbt { } } exports.Psbt = Psbt; -var utils_js_2 = require('./utils.js'); +var utils_js_2 = require('./utils.cjs'); exports.checkForInput = utils_js_2.checkForInput; exports.checkForOutput = utils_js_2.checkForOutput; diff --git a/src/cjs/lib/psbt.d.ts b/src/cjs/lib/psbt.d.ts deleted file mode 100644 index 48bd057..0000000 --- a/src/cjs/lib/psbt.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { KeyValue, PsbtGlobal, PsbtGlobalUpdate, PsbtInput, PsbtInputExtended, PsbtInputUpdate, PsbtOutput, PsbtOutputExtended, PsbtOutputUpdate, Transaction, TransactionFromBuffer } from './interfaces.js'; -export declare class Psbt { - static fromBase64(this: T, data: string, txFromBuffer: TransactionFromBuffer): InstanceType; - static fromHex(this: T, data: string, txFromBuffer: TransactionFromBuffer): InstanceType; - static fromBuffer(this: T, buffer: Uint8Array, txFromBuffer: TransactionFromBuffer): InstanceType; - readonly inputs: PsbtInput[]; - readonly outputs: PsbtOutput[]; - readonly globalMap: PsbtGlobal; - constructor(tx: Transaction); - toBase64(): string; - toHex(): string; - toBuffer(): Uint8Array; - updateGlobal(updateData: PsbtGlobalUpdate): this; - updateInput(inputIndex: number, updateData: PsbtInputUpdate): this; - updateOutput(outputIndex: number, updateData: PsbtOutputUpdate): this; - addUnknownKeyValToGlobal(keyVal: KeyValue): this; - addUnknownKeyValToInput(inputIndex: number, keyVal: KeyValue): this; - addUnknownKeyValToOutput(outputIndex: number, keyVal: KeyValue): this; - addInput(inputData: PsbtInputExtended): this; - addOutput(outputData: PsbtOutputExtended): this; - clearFinalizedInput(inputIndex: number): this; - combine(...those: this[]): this; - getTransaction(): Uint8Array; -} -export { Bip32Derivation, NonWitnessUtxo, ControlBlock, FinalScriptSig, FinalScriptWitness, GlobalXpub, KeyValue, PartialSig, PorCommitment, PsbtGlobal, PsbtGlobalUpdate, PsbtInput, PsbtInputExtended, PsbtInputUpdate, PsbtOutput, PsbtOutputExtended, PsbtOutputUpdate, RedeemScript, SighashType, TapBip32Derivation, TapInternalKey, TapKeySig, TapLeaf, TapLeafScript, TapMerkleRoot, TapScriptSig, TapTree, Transaction, TransactionFromBuffer, TransactionIOCountGetter, TransactionLocktimeSetter, TransactionVersionSetter, WitnessScript, WitnessUtxo, } from './interfaces.js'; -export { checkForInput, checkForOutput } from './utils.js'; diff --git a/src/cjs/lib/typeFields.js b/src/cjs/lib/typeFields.cjs similarity index 100% rename from src/cjs/lib/typeFields.js rename to src/cjs/lib/typeFields.cjs diff --git a/src/cjs/lib/typeFields.d.ts b/src/cjs/lib/typeFields.d.ts deleted file mode 100644 index e8cbcbe..0000000 --- a/src/cjs/lib/typeFields.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -export declare enum GlobalTypes { - UNSIGNED_TX = 0, - GLOBAL_XPUB = 1 -} -export declare const GLOBAL_TYPE_NAMES: string[]; -export declare enum InputTypes { - NON_WITNESS_UTXO = 0, - WITNESS_UTXO = 1, - PARTIAL_SIG = 2, - SIGHASH_TYPE = 3, - REDEEM_SCRIPT = 4, - WITNESS_SCRIPT = 5, - BIP32_DERIVATION = 6, - FINAL_SCRIPTSIG = 7, - FINAL_SCRIPTWITNESS = 8, - POR_COMMITMENT = 9, - TAP_KEY_SIG = 19, - TAP_SCRIPT_SIG = 20, - TAP_LEAF_SCRIPT = 21, - TAP_BIP32_DERIVATION = 22, - TAP_INTERNAL_KEY = 23, - TAP_MERKLE_ROOT = 24 -} -export declare const INPUT_TYPE_NAMES: string[]; -export declare enum OutputTypes { - REDEEM_SCRIPT = 0, - WITNESS_SCRIPT = 1, - BIP32_DERIVATION = 2, - TAP_INTERNAL_KEY = 5, - TAP_TREE = 6, - TAP_BIP32_DERIVATION = 7 -} -export declare const OUTPUT_TYPE_NAMES: string[]; diff --git a/src/cjs/lib/utils.js b/src/cjs/lib/utils.cjs similarity index 98% rename from src/cjs/lib/utils.js rename to src/cjs/lib/utils.cjs index 03c4ca1..57bcabb 100644 --- a/src/cjs/lib/utils.js +++ b/src/cjs/lib/utils.cjs @@ -11,7 +11,7 @@ var __importStar = return result; }; Object.defineProperty(exports, '__esModule', { value: true }); -const converter = __importStar(require('./converter/index.js')); +const converter = __importStar(require('./converter/index.cjs')); const tools = __importStar(require('uint8array-tools')); function checkForInput(inputs, inputIndex) { const input = inputs[inputIndex]; diff --git a/src/cjs/lib/utils.d.ts b/src/cjs/lib/utils.d.ts deleted file mode 100644 index 40f5e34..0000000 --- a/src/cjs/lib/utils.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { KeyValue, PsbtGlobal, PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, PsbtOutput, PsbtOutputUpdate } from './interfaces.js'; -export declare function checkForInput(inputs: PsbtInput[], inputIndex: number): PsbtInput; -export declare function checkForOutput(outputs: PsbtOutput[], outputIndex: number): PsbtOutput; -export declare function checkHasKey(checkKeyVal: KeyValue, keyVals: KeyValue[] | undefined, enumLength: number): void; -export declare function getEnumLength(myenum: any): number; -export declare function inputCheckUncleanFinalized(inputIndex: number, input: PsbtInput): void; -export declare const updateGlobal: (updateData: PsbtGlobalUpdate, mainData: PsbtGlobal) => void; -export declare const updateInput: (updateData: PsbtInputUpdate, mainData: PsbtInput) => void; -export declare const updateOutput: (updateData: PsbtOutputUpdate, mainData: PsbtOutput) => void; -export declare function addInputAttributes(inputs: PsbtInput[], data: any): void; -export declare function addOutputAttributes(outputs: PsbtOutput[], data: any): void; -export declare function defaultVersionSetter(version: number, txBuf: Uint8Array): Uint8Array; -export declare function defaultLocktimeSetter(locktime: number, txBuf: Uint8Array): Uint8Array; diff --git a/test.cjs b/test.cjs new file mode 100755 index 0000000..4be73a2 --- /dev/null +++ b/test.cjs @@ -0,0 +1,39 @@ +const fs = require('fs'); +const childProcess = require('child_process'); + +let mainFile = JSON.parse(fs.readFileSync('./package.json').toString()).module; +if (!mainFile.startsWith('.')) { + // ESM imports of files must start with ./ + mainFile = `./${mainFile}`; +} +const cjsFile = './tmp.cjs'; +const esmFile = './tmp.mjs'; +const cjs = `const x = require('.')\nconsole.log(x)`; +const esm = `import * as x from '${mainFile}';\nconsole.log(x)`; + +fs.writeFileSync(cjsFile, cjs); +fs.writeFileSync(esmFile, esm); + +const result1 = childProcess.spawnSync('node', [cjsFile], { + cwd: __dirname, +}); +const result2 = childProcess.spawnSync('node', [esmFile], { + cwd: __dirname, +}); + +fs.unlinkSync(cjsFile); +fs.unlinkSync(esmFile); + +const errors = []; +if (result1.status !== 0) { + errors.push(result1.stderr.toString()); +} +if (result2.status !== 0) { + errors.push(result2.stderr.toString()); +} +if (errors.length > 0) { + console.error( + `Failed to run this library under CJS or ESM. Errors:\n${errors.join('\n')}`, + ); + process.exit(1); +} diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json index c93762f..e84bac6 100644 --- a/tsconfig.cjs.json +++ b/tsconfig.cjs.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.base.json", "compilerOptions": { - "declaration": true, + "declaration": false, "emitDeclarationOnly": false, "outDir": "src/cjs", "module": "commonjs"