@btc-vision/bitcoin 7.0.0-alpha.8 → 7.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/benchmark-compare/BENCHMARK.md +144 -0
- package/benchmark-compare/compare.bench.ts +1024 -0
- package/benchmark-compare/harness.ts +220 -0
- package/benchmark-compare/package.json +18 -0
- package/browser/address.d.ts.map +1 -1
- package/browser/block.d.ts.map +1 -1
- package/browser/chunks/{psbt-parallel-PtTJ19DC.js → psbt-parallel-B-dfm5GZ.js} +2433 -2524
- package/browser/crypto-hashes.d.ts +4 -0
- package/browser/crypto-hashes.d.ts.map +1 -0
- package/browser/crypto-hashes.native.d.ts +4 -0
- package/browser/crypto-hashes.native.d.ts.map +1 -0
- package/browser/crypto.d.ts.map +1 -1
- package/browser/index.d.ts +3 -3
- package/browser/index.d.ts.map +1 -1
- package/browser/index.js +571 -547
- package/browser/io/base58check.d.ts +26 -0
- package/browser/io/base58check.d.ts.map +1 -0
- package/browser/io/base64.d.ts +8 -0
- package/browser/io/base64.d.ts.map +1 -1
- package/browser/io/hex.d.ts.map +1 -1
- package/browser/io/index.d.ts +2 -1
- package/browser/io/index.d.ts.map +1 -1
- package/browser/io/utils.d.ts.map +1 -1
- package/browser/payments/bip341.d.ts.map +1 -1
- package/browser/payments/p2op.d.ts.map +1 -1
- package/browser/payments/p2pkh.d.ts.map +1 -1
- package/browser/payments/p2sh.d.ts.map +1 -1
- package/browser/payments/p2tr.d.ts.map +1 -1
- package/browser/payments/p2wpkh.d.ts.map +1 -1
- package/browser/psbt/PsbtCache.d.ts.map +1 -1
- package/browser/psbt/PsbtSigner.d.ts.map +1 -1
- package/browser/psbt/PsbtTransaction.d.ts +2 -2
- package/browser/psbt/PsbtTransaction.d.ts.map +1 -1
- package/browser/psbt/bip371.d.ts.map +1 -1
- package/browser/psbt.d.ts +1 -1
- package/browser/psbt.d.ts.map +1 -1
- package/browser/react-native-quick-crypto.d.ts +11 -0
- package/browser/script.d.ts.map +1 -1
- package/browser/transaction.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.sequential.d.ts.map +1 -1
- package/browser/workers/index.js +5 -5
- package/build/address.d.ts.map +1 -1
- package/build/address.js +19 -12
- package/build/address.js.map +1 -1
- package/build/bech32utils.js.map +1 -1
- package/build/bip66.js +4 -4
- package/build/bip66.js.map +1 -1
- package/build/block.d.ts.map +1 -1
- package/build/block.js +9 -2
- package/build/block.js.map +1 -1
- package/build/crypto-hashes.d.ts +4 -0
- package/build/crypto-hashes.d.ts.map +1 -0
- package/build/crypto-hashes.js +4 -0
- package/build/crypto-hashes.js.map +1 -0
- package/build/crypto-hashes.native.d.ts +4 -0
- package/build/crypto-hashes.native.d.ts.map +1 -0
- package/build/crypto-hashes.native.js +15 -0
- package/build/crypto-hashes.native.js.map +1 -0
- package/build/crypto.d.ts.map +1 -1
- package/build/crypto.js +1 -2
- package/build/crypto.js.map +1 -1
- package/build/env.js.map +1 -1
- package/build/index.d.ts +3 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/io/BinaryReader.js +1 -1
- package/build/io/BinaryReader.js.map +1 -1
- package/build/io/base58check.d.ts +26 -0
- package/build/io/base58check.d.ts.map +1 -0
- package/build/io/base58check.js +32 -0
- package/build/io/base58check.js.map +1 -0
- package/build/io/base64.d.ts +8 -0
- package/build/io/base64.d.ts.map +1 -1
- package/build/io/base64.js +14 -0
- package/build/io/base64.js.map +1 -1
- package/build/io/hex.d.ts.map +1 -1
- package/build/io/hex.js +3 -2
- package/build/io/hex.js.map +1 -1
- package/build/io/index.d.ts +2 -1
- package/build/io/index.d.ts.map +1 -1
- package/build/io/index.js +4 -2
- package/build/io/index.js.map +1 -1
- package/build/io/utils.d.ts.map +1 -1
- package/build/io/utils.js +3 -4
- package/build/io/utils.js.map +1 -1
- package/build/merkle.js.map +1 -1
- package/build/payments/bip341.d.ts.map +1 -1
- package/build/payments/bip341.js +4 -3
- package/build/payments/bip341.js.map +1 -1
- package/build/payments/embed.js.map +1 -1
- package/build/payments/p2ms.js.map +1 -1
- package/build/payments/p2op.d.ts.map +1 -1
- package/build/payments/p2op.js +6 -4
- package/build/payments/p2op.js.map +1 -1
- package/build/payments/p2pk.js.map +1 -1
- package/build/payments/p2pkh.d.ts.map +1 -1
- package/build/payments/p2pkh.js +3 -4
- package/build/payments/p2pkh.js.map +1 -1
- package/build/payments/p2sh.d.ts.map +1 -1
- package/build/payments/p2sh.js +3 -4
- package/build/payments/p2sh.js.map +1 -1
- package/build/payments/p2tr.d.ts.map +1 -1
- package/build/payments/p2tr.js +13 -6
- package/build/payments/p2tr.js.map +1 -1
- package/build/payments/p2wpkh.d.ts.map +1 -1
- package/build/payments/p2wpkh.js +7 -5
- package/build/payments/p2wpkh.js.map +1 -1
- package/build/payments/p2wsh.js.map +1 -1
- package/build/psbt/PsbtCache.d.ts.map +1 -1
- package/build/psbt/PsbtCache.js +8 -4
- package/build/psbt/PsbtCache.js.map +1 -1
- package/build/psbt/PsbtFinalizer.js +14 -8
- package/build/psbt/PsbtFinalizer.js.map +1 -1
- package/build/psbt/PsbtSigner.d.ts.map +1 -1
- package/build/psbt/PsbtSigner.js +3 -2
- package/build/psbt/PsbtSigner.js.map +1 -1
- package/build/psbt/PsbtTransaction.d.ts +2 -2
- package/build/psbt/PsbtTransaction.d.ts.map +1 -1
- package/build/psbt/PsbtTransaction.js.map +1 -1
- package/build/psbt/bip371.d.ts.map +1 -1
- package/build/psbt/bip371.js +4 -3
- package/build/psbt/bip371.js.map +1 -1
- package/build/psbt/utils.js.map +1 -1
- package/build/psbt.d.ts +1 -1
- package/build/psbt.d.ts.map +1 -1
- package/build/psbt.js.map +1 -1
- package/build/push_data.js +1 -1
- package/build/push_data.js.map +1 -1
- package/build/script.d.ts.map +1 -1
- package/build/script.js +4 -3
- package/build/script.js.map +1 -1
- package/build/script_number.js +1 -1
- package/build/script_number.js.map +1 -1
- package/build/script_signature.js.map +1 -1
- package/build/transaction.d.ts.map +1 -1
- package/build/transaction.js +2 -1
- package/build/transaction.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.js.map +1 -1
- package/build/workers/WorkerSigningPool.js.map +1 -1
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.node.js +25 -3
- package/build/workers/WorkerSigningPool.node.js.map +1 -1
- package/build/workers/WorkerSigningPool.sequential.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.sequential.js +2 -0
- package/build/workers/WorkerSigningPool.sequential.js.map +1 -1
- package/build/workers/index.js.map +1 -1
- package/build/workers/psbt-parallel.js.map +1 -1
- package/package.json +7 -5
- package/src/address.ts +18 -13
- package/src/bech32utils.ts +3 -3
- package/src/bip66.ts +18 -18
- package/src/block.ts +8 -3
- package/src/crypto-hashes.native.ts +18 -0
- package/src/crypto-hashes.ts +3 -0
- package/src/crypto.ts +1 -2
- package/src/env.ts +10 -8
- package/src/index.ts +4 -0
- package/src/io/BinaryReader.ts +1 -1
- package/src/io/base58check.ts +35 -0
- package/src/io/base64.ts +15 -0
- package/src/io/hex.ts +3 -2
- package/src/io/index.ts +5 -2
- package/src/io/utils.ts +6 -7
- package/src/merkle.ts +3 -3
- package/src/payments/bip341.ts +8 -7
- package/src/payments/embed.ts +1 -1
- package/src/payments/p2ms.ts +2 -2
- package/src/payments/p2op.ts +6 -4
- package/src/payments/p2pk.ts +2 -2
- package/src/payments/p2pkh.ts +7 -8
- package/src/payments/p2sh.ts +8 -9
- package/src/payments/p2tr.ts +24 -17
- package/src/payments/p2wpkh.ts +9 -7
- package/src/payments/p2wsh.ts +3 -3
- package/src/psbt/PsbtCache.ts +14 -11
- package/src/psbt/PsbtFinalizer.ts +17 -11
- package/src/psbt/PsbtSigner.ts +7 -6
- package/src/psbt/PsbtTransaction.ts +2 -2
- package/src/psbt/bip371.ts +4 -3
- package/src/psbt/utils.ts +1 -1
- package/src/psbt.ts +11 -9
- package/src/push_data.ts +5 -5
- package/src/react-native-quick-crypto.d.ts +11 -0
- package/src/script.ts +5 -4
- package/src/script_number.ts +6 -6
- package/src/script_signature.ts +2 -2
- package/src/transaction.ts +15 -14
- package/src/types.ts +1 -1
- package/src/workers/WorkerSigningPool.node.ts +28 -4
- package/src/workers/WorkerSigningPool.sequential.ts +2 -1
- package/src/workers/WorkerSigningPool.ts +3 -3
- package/src/workers/index.ts +1 -1
- package/src/workers/psbt-parallel.ts +3 -3
- package/test/address.spec.ts +1 -0
- package/test/bitcoin.core.spec.ts +9 -2
- package/test/browser/psbt.spec.ts +54 -29
- package/test/browser/workers-signing.spec.ts +8 -8
- package/test/crypto.spec.ts +1 -1
- package/test/env.spec.ts +2 -2
- package/test/integration/_regtest.ts +2 -2
- package/test/integration/blocks.spec.ts +1 -1
- package/test/integration/csv.spec.ts +1 -1
- package/test/integration/payments.spec.ts +2 -2
- package/test/integration/taproot.spec.ts +3 -3
- package/test/integration/transactions.spec.ts +6 -5
- package/test/psbt.spec.ts +49 -25
- package/test/transaction.spec.ts +6 -3
- package/test/workers-pool.spec.ts +5 -5
- package/test/workers-signing.spec.ts +8 -8
- package/test/workers.spec.ts +3 -3
|
@@ -11,7 +11,7 @@ import { randomBytes } from './setup.js';
|
|
|
11
11
|
import { convertScriptTree } from '../payments.utils.js';
|
|
12
12
|
import { LEAF_VERSION_TAPSCRIPT } from '../../src/payments/bip341.js';
|
|
13
13
|
import { tapTreeFromList, tapTreeToList } from '../../src/psbt/bip371.js';
|
|
14
|
-
import type { Bytes32, EccLib,
|
|
14
|
+
import type { Bytes32, EccLib, PrivateKey, PublicKey, Satoshi, Script, Signature, Taptree, } from '../../src/types.js';
|
|
15
15
|
import type { HDSigner, Signer, SignerAsync, ValidateSigFunction } from '../../src/index.js';
|
|
16
16
|
import { initEccLib, networks, payments, Psbt } from '../../src/index.js';
|
|
17
17
|
import { equals } from '../../src/io/index.js';
|
|
@@ -19,6 +19,7 @@ import { equals } from '../../src/io/index.js';
|
|
|
19
19
|
import preFixtures from '../fixtures/psbt.json' with { type: 'json' };
|
|
20
20
|
import taprootFixtures from '../fixtures/p2tr.json' with { type: 'json' };
|
|
21
21
|
import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
|
|
22
|
+
import type { MessageHash } from '@btc-vision/ecpair';
|
|
22
23
|
import type { Network } from '../../src/networks.js';
|
|
23
24
|
|
|
24
25
|
const bip32 = BIP32Factory(ecc);
|
|
@@ -46,8 +47,8 @@ const initBuffers = (object: any): typeof preFixtures =>
|
|
|
46
47
|
const result = regex.exec(value);
|
|
47
48
|
if (!result) return value;
|
|
48
49
|
|
|
49
|
-
const data = result[1]
|
|
50
|
-
const encoding = result[2]
|
|
50
|
+
const data = result[1]!;
|
|
51
|
+
const encoding = result[2]!;
|
|
51
52
|
|
|
52
53
|
return Buffer.from(data, encoding as BufferEncoding);
|
|
53
54
|
});
|
|
@@ -59,7 +60,7 @@ const upperCaseFirstLetter = (str: string): string => str.replace(/^./, (s) => s
|
|
|
59
60
|
const toAsyncSigner = (signer: Signer): SignerAsync => {
|
|
60
61
|
return {
|
|
61
62
|
publicKey: signer.publicKey,
|
|
62
|
-
sign: (hash:
|
|
63
|
+
sign: (hash: MessageHash, lowerR: boolean | undefined): Promise<Signature> => {
|
|
63
64
|
return new Promise((resolve, rejects): void => {
|
|
64
65
|
setTimeout(() => {
|
|
65
66
|
try {
|
|
@@ -71,12 +72,12 @@ const toAsyncSigner = (signer: Signer): SignerAsync => {
|
|
|
71
72
|
}, 10);
|
|
72
73
|
});
|
|
73
74
|
},
|
|
74
|
-
};
|
|
75
|
+
} as unknown as SignerAsync;
|
|
75
76
|
};
|
|
76
|
-
const failedAsyncSigner = (publicKey:
|
|
77
|
-
return
|
|
77
|
+
const failedAsyncSigner = (publicKey: Uint8Array): SignerAsync => {
|
|
78
|
+
return {
|
|
78
79
|
publicKey: publicKey as unknown as PublicKey,
|
|
79
|
-
sign: (__:
|
|
80
|
+
sign: (__: MessageHash): Promise<Signature> => {
|
|
80
81
|
return new Promise((_, reject): void => {
|
|
81
82
|
setTimeout(() => {
|
|
82
83
|
reject(new Error('sign failed'));
|
|
@@ -181,10 +182,13 @@ describe(`Psbt`, () => {
|
|
|
181
182
|
fixtures.bip174.combiner.forEach((f) => {
|
|
182
183
|
it('Combines two PSBTs to the expected result', () => {
|
|
183
184
|
const psbts = f.psbts.map((psbt) => Psbt.fromBase64(psbt));
|
|
185
|
+
const psbt0 = psbts[0];
|
|
186
|
+
const psbt1 = psbts[1];
|
|
187
|
+
assert(psbt0 && psbt1);
|
|
184
188
|
|
|
185
|
-
|
|
189
|
+
psbt0.combine(psbt1);
|
|
186
190
|
|
|
187
|
-
assert.strictEqual(
|
|
191
|
+
assert.strictEqual(psbt0.toHex(), Psbt.fromBase64(f.result).toHex());
|
|
188
192
|
});
|
|
189
193
|
});
|
|
190
194
|
|
|
@@ -211,8 +215,10 @@ describe(`Psbt`, () => {
|
|
|
211
215
|
assert.strictEqual(transaction1, f.transaction);
|
|
212
216
|
|
|
213
217
|
const psbt3 = Psbt.fromBase64(f.psbt);
|
|
214
|
-
|
|
215
|
-
|
|
218
|
+
const psbt3Input0 = psbt3.data.inputs[0];
|
|
219
|
+
assert(psbt3Input0);
|
|
220
|
+
delete psbt3Input0.finalScriptSig;
|
|
221
|
+
delete psbt3Input0.finalScriptWitness;
|
|
216
222
|
assert.throws(() => {
|
|
217
223
|
psbt3.extractTransaction();
|
|
218
224
|
}, new RegExp('Not finalized'));
|
|
@@ -264,7 +270,7 @@ describe(`Psbt`, () => {
|
|
|
264
270
|
await assert.rejects(async () => {
|
|
265
271
|
await psbtThatShouldsign.signInputAsync(
|
|
266
272
|
f.shouldSign.inputToCheck,
|
|
267
|
-
failedAsyncSigner(ECPair.fromWIF(f.shouldSign.WIF).publicKey),
|
|
273
|
+
failedAsyncSigner(ECPair.fromWIF(f.shouldSign.WIF).publicKey as unknown as Buffer),
|
|
268
274
|
f.shouldSign.sighashTypes || undefined,
|
|
269
275
|
);
|
|
270
276
|
}, failMessage);
|
|
@@ -688,9 +694,13 @@ describe(`Psbt`, () => {
|
|
|
688
694
|
});
|
|
689
695
|
|
|
690
696
|
assert.strictEqual(psbt.inputCount, 1);
|
|
691
|
-
|
|
697
|
+
const txIn0 = psbt.txInputs[0];
|
|
698
|
+
assert(txIn0);
|
|
699
|
+
assert.strictEqual(txIn0.sequence, 0xffffffff);
|
|
692
700
|
psbt.setInputSequence(0, 0);
|
|
693
|
-
|
|
701
|
+
const txIn0After = psbt.txInputs[0];
|
|
702
|
+
assert(txIn0After);
|
|
703
|
+
assert.strictEqual(txIn0After.sequence, 0);
|
|
694
704
|
});
|
|
695
705
|
|
|
696
706
|
it('throws if input index is too high', () => {
|
|
@@ -844,6 +854,9 @@ describe(`Psbt`, () => {
|
|
|
844
854
|
index: 0,
|
|
845
855
|
});
|
|
846
856
|
|
|
857
|
+
const input0 = psbt.data.inputs[0];
|
|
858
|
+
assert(input0);
|
|
859
|
+
|
|
847
860
|
assert.throws(() => {
|
|
848
861
|
psbt.inputHasPubkey(0, testPubkey);
|
|
849
862
|
}, new RegExp("Can't find pubkey in input without Utxo data"));
|
|
@@ -853,7 +866,7 @@ describe(`Psbt`, () => {
|
|
|
853
866
|
value: 1337n as Satoshi,
|
|
854
867
|
script: payments.p2sh({
|
|
855
868
|
redeem: { output: Buffer.from([0x51]) as unknown as Script },
|
|
856
|
-
}).output
|
|
869
|
+
}).output as Script,
|
|
857
870
|
},
|
|
858
871
|
});
|
|
859
872
|
|
|
@@ -861,14 +874,14 @@ describe(`Psbt`, () => {
|
|
|
861
874
|
psbt.inputHasPubkey(0, testPubkey);
|
|
862
875
|
}, new RegExp('scriptPubkey is P2SH but redeemScript missing'));
|
|
863
876
|
|
|
864
|
-
delete
|
|
877
|
+
delete input0.witnessUtxo;
|
|
865
878
|
|
|
866
879
|
psbt.updateInput(0, {
|
|
867
880
|
witnessUtxo: {
|
|
868
881
|
value: 1337n as Satoshi,
|
|
869
882
|
script: payments.p2wsh({
|
|
870
883
|
redeem: { output: Buffer.from([0x51]) as unknown as Script },
|
|
871
|
-
}).output
|
|
884
|
+
}).output as Script,
|
|
872
885
|
},
|
|
873
886
|
});
|
|
874
887
|
|
|
@@ -876,7 +889,7 @@ describe(`Psbt`, () => {
|
|
|
876
889
|
psbt.inputHasPubkey(0, testPubkey);
|
|
877
890
|
}, new RegExp('scriptPubkey or redeemScript is P2WSH but witnessScript missing'));
|
|
878
891
|
|
|
879
|
-
delete
|
|
892
|
+
delete input0.witnessUtxo;
|
|
880
893
|
|
|
881
894
|
// Create a script that contains the test pubkey
|
|
882
895
|
const scriptWithPubkey = Buffer.concat([
|
|
@@ -1008,7 +1021,9 @@ describe(`Psbt`, () => {
|
|
|
1008
1021
|
psbt3.outputHasPubkey(0, testPubkey);
|
|
1009
1022
|
}, new RegExp('scriptPubkey or redeemScript is P2WSH but witnessScript missing'));
|
|
1010
1023
|
|
|
1011
|
-
|
|
1024
|
+
const psbt3Output0 = psbt3.data.outputs[0];
|
|
1025
|
+
assert(psbt3Output0);
|
|
1026
|
+
delete psbt3Output0.redeemScript;
|
|
1012
1027
|
|
|
1013
1028
|
psbt.updateOutput(0, {
|
|
1014
1029
|
witnessScript: scriptWithPubkey,
|
|
@@ -1043,7 +1058,9 @@ describe(`Psbt`, () => {
|
|
|
1043
1058
|
assert.strictEqual(clone.toBase64(), notAClone.toBase64());
|
|
1044
1059
|
assert.strictEqual(psbt.toBase64(), notAClone.toBase64());
|
|
1045
1060
|
// Mutate data layer to prove clone is independent
|
|
1046
|
-
psbt.data.inputs[0]
|
|
1061
|
+
const cloneInput0 = psbt.data.inputs[0];
|
|
1062
|
+
assert(cloneInput0);
|
|
1063
|
+
cloneInput0.partialSig = [];
|
|
1047
1064
|
assert.notStrictEqual(clone.toBase64(), psbt.toBase64());
|
|
1048
1065
|
assert.notStrictEqual(clone.toBase64(), notAClone.toBase64());
|
|
1049
1066
|
assert.strictEqual(psbt.toBase64(), notAClone.toBase64());
|
|
@@ -1410,17 +1427,20 @@ describe(`Psbt`, () => {
|
|
|
1410
1427
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
1411
1428
|
const index = f.inputIndex;
|
|
1412
1429
|
|
|
1430
|
+
const cacheInput = psbt.data.inputs[index];
|
|
1431
|
+
assert(cacheInput);
|
|
1432
|
+
|
|
1413
1433
|
// nonWitnessUtxo is not set before updateInput
|
|
1414
|
-
assert.strictEqual(
|
|
1434
|
+
assert.strictEqual(cacheInput.nonWitnessUtxo, undefined);
|
|
1415
1435
|
|
|
1416
1436
|
// After updateInput, the nonWitnessUtxo is stored on the input
|
|
1417
1437
|
psbt.updateInput(index, {
|
|
1418
1438
|
nonWitnessUtxo: f.nonWitnessUtxo as any,
|
|
1419
1439
|
});
|
|
1420
|
-
assert.ok(
|
|
1440
|
+
assert.ok(cacheInput.nonWitnessUtxo);
|
|
1421
1441
|
assert.ok(
|
|
1422
1442
|
equals(
|
|
1423
|
-
|
|
1443
|
+
cacheInput.nonWitnessUtxo as Uint8Array,
|
|
1424
1444
|
f.nonWitnessUtxo as any,
|
|
1425
1445
|
),
|
|
1426
1446
|
);
|
|
@@ -1436,10 +1456,11 @@ describe(`Psbt`, () => {
|
|
|
1436
1456
|
});
|
|
1437
1457
|
|
|
1438
1458
|
const input = psbt.data.inputs[index];
|
|
1459
|
+
assert(input);
|
|
1439
1460
|
const desc = Object.getOwnPropertyDescriptor(input, 'nonWitnessUtxo');
|
|
1440
1461
|
assert.ok(desc, 'property should exist');
|
|
1441
|
-
assert.strictEqual(desc
|
|
1442
|
-
assert.strictEqual(desc
|
|
1462
|
+
assert.strictEqual(desc.get, undefined, 'should not have a getter');
|
|
1463
|
+
assert.strictEqual(desc.set, undefined, 'should not have a setter');
|
|
1443
1464
|
});
|
|
1444
1465
|
});
|
|
1445
1466
|
|
|
@@ -1469,17 +1490,19 @@ describe(`Psbt`, () => {
|
|
|
1469
1490
|
psbt.addInput({ hash, index });
|
|
1470
1491
|
|
|
1471
1492
|
const input = psbt.txInputs[0];
|
|
1493
|
+
assert(input);
|
|
1472
1494
|
const originalHash = new Uint8Array(input.hash);
|
|
1473
1495
|
const originalIndex = input.index;
|
|
1474
1496
|
const originalSequence = input.sequence;
|
|
1475
1497
|
|
|
1476
1498
|
// Mutate the returned clone
|
|
1477
1499
|
input.hash[0] = 123;
|
|
1478
|
-
input.index = 123;
|
|
1479
|
-
input.sequence = 123;
|
|
1500
|
+
(input as { index: number }).index = 123;
|
|
1501
|
+
(input as { sequence: number }).sequence = 123;
|
|
1480
1502
|
|
|
1481
1503
|
// Internal state should be unchanged
|
|
1482
1504
|
const fresh = psbt.txInputs[0];
|
|
1505
|
+
assert(fresh);
|
|
1483
1506
|
assert.ok(equals(fresh.hash, originalHash));
|
|
1484
1507
|
assert.strictEqual(fresh.index, originalIndex);
|
|
1485
1508
|
assert.strictEqual(fresh.sequence, originalSequence);
|
|
@@ -1492,6 +1515,7 @@ describe(`Psbt`, () => {
|
|
|
1492
1515
|
psbt.addOutput({ address, value });
|
|
1493
1516
|
|
|
1494
1517
|
const output = psbt.txOutputs[0];
|
|
1518
|
+
assert(output);
|
|
1495
1519
|
assert.strictEqual(output.address, address);
|
|
1496
1520
|
|
|
1497
1521
|
const originalScript = new Uint8Array(output.script);
|
|
@@ -1499,10 +1523,11 @@ describe(`Psbt`, () => {
|
|
|
1499
1523
|
|
|
1500
1524
|
// Mutate the returned clone
|
|
1501
1525
|
output.script[0] = 123;
|
|
1502
|
-
output.value = 123n;
|
|
1526
|
+
(output as { value: bigint }).value = 123n;
|
|
1503
1527
|
|
|
1504
1528
|
// Internal state should be unchanged
|
|
1505
1529
|
const fresh = psbt.txOutputs[0];
|
|
1530
|
+
assert(fresh);
|
|
1506
1531
|
assert.ok(equals(fresh.script, originalScript));
|
|
1507
1532
|
assert.strictEqual(fresh.value, originalValue);
|
|
1508
1533
|
});
|
|
@@ -83,7 +83,7 @@ describe('Worker Signing - Signature Verification', () => {
|
|
|
83
83
|
const signature = ecc.sign(hash, keyPair.privateKey!);
|
|
84
84
|
|
|
85
85
|
const modifiedHash = Buffer.from(hash);
|
|
86
|
-
modifiedHash[0] ^= 0xff;
|
|
86
|
+
modifiedHash[0]! ^= 0xff;
|
|
87
87
|
|
|
88
88
|
const isValid = ecc.verify(modifiedHash, keyPair.publicKey, signature);
|
|
89
89
|
expect(isValid).toBe(false);
|
|
@@ -95,7 +95,7 @@ describe('Worker Signing - Signature Verification', () => {
|
|
|
95
95
|
|
|
96
96
|
const signature = Buffer.from(ecc.sign(hash, keyPair.privateKey!));
|
|
97
97
|
|
|
98
|
-
signature[0] ^= 0xff;
|
|
98
|
+
signature[0]! ^= 0xff;
|
|
99
99
|
|
|
100
100
|
const isValid = ecc.verify(hash, keyPair.publicKey, signature);
|
|
101
101
|
expect(isValid).toBe(false);
|
|
@@ -150,7 +150,7 @@ describe('Worker Signing - Signature Verification', () => {
|
|
|
150
150
|
const signature = ecc.signSchnorr(hash, keyPair.privateKey!);
|
|
151
151
|
|
|
152
152
|
const modifiedHash = Buffer.from(hash);
|
|
153
|
-
modifiedHash[0] ^= 0xff;
|
|
153
|
+
modifiedHash[0]! ^= 0xff;
|
|
154
154
|
|
|
155
155
|
const xOnlyPubkey = toXOnly(keyPair.publicKey);
|
|
156
156
|
const isValid = ecc.verifySchnorr(modifiedHash, xOnlyPubkey, signature);
|
|
@@ -162,7 +162,7 @@ describe('Worker Signing - Signature Verification', () => {
|
|
|
162
162
|
const hash = randomBytes(32);
|
|
163
163
|
|
|
164
164
|
const signature = Buffer.from(ecc.signSchnorr(hash, keyPair.privateKey!));
|
|
165
|
-
signature[0] ^= 0xff;
|
|
165
|
+
signature[0]! ^= 0xff;
|
|
166
166
|
|
|
167
167
|
const xOnlyPubkey = toXOnly(keyPair.publicKey);
|
|
168
168
|
const isValid = ecc.verifySchnorr(hash, xOnlyPubkey, signature);
|
|
@@ -173,7 +173,7 @@ describe('Worker Signing - Signature Verification', () => {
|
|
|
173
173
|
describe('WorkerEccLib Interface Compatibility', () => {
|
|
174
174
|
it('should create WorkerEccLib compatible wrapper', () => {
|
|
175
175
|
const eccLib: WorkerEccLib = {
|
|
176
|
-
sign: (hash: Uint8Array, privateKey: Uint8Array,
|
|
176
|
+
sign: (hash: Uint8Array, privateKey: Uint8Array, _lowR?: boolean): Uint8Array => {
|
|
177
177
|
return ecc.sign(hash, privateKey, undefined);
|
|
178
178
|
},
|
|
179
179
|
signSchnorr: (hash: Uint8Array, privateKey: Uint8Array): Uint8Array => {
|
|
@@ -256,7 +256,7 @@ describe('Worker Signing - Signature Verification', () => {
|
|
|
256
256
|
const signatures = hashes.map((hash) => ecc.sign(hash, keyPair.privateKey!));
|
|
257
257
|
|
|
258
258
|
for (let i = 0; i < hashes.length; i++) {
|
|
259
|
-
expect(ecc.verify(hashes[i]
|
|
259
|
+
expect(ecc.verify(hashes[i]!, keyPair.publicKey, signatures[i]!)).toBe(true);
|
|
260
260
|
}
|
|
261
261
|
});
|
|
262
262
|
|
|
@@ -325,7 +325,7 @@ describe('Worker Signing - Signature Verification', () => {
|
|
|
325
325
|
}
|
|
326
326
|
});
|
|
327
327
|
|
|
328
|
-
|
|
328
|
+
void (Date.now() - startTime);
|
|
329
329
|
|
|
330
330
|
let validCount = 0;
|
|
331
331
|
for (const result of results) {
|
|
@@ -406,7 +406,7 @@ describe('Worker Signing - Signature Verification', () => {
|
|
|
406
406
|
let signature: Uint8Array;
|
|
407
407
|
|
|
408
408
|
try {
|
|
409
|
-
if (signatureType === SignatureType.Schnorr) {
|
|
409
|
+
if ((signatureType as SignatureType) === SignatureType.Schnorr) {
|
|
410
410
|
if (!eccLib.signSchnorr) {
|
|
411
411
|
throw new Error('ECC library does not support Schnorr');
|
|
412
412
|
}
|
package/test/crypto.spec.ts
CHANGED
|
@@ -49,7 +49,7 @@ describe('crypto', () => {
|
|
|
49
49
|
|
|
50
50
|
for (const key of storedKeys) {
|
|
51
51
|
assert.ok(
|
|
52
|
-
equals(TAGGED_HASH_PREFIXES[key as TaggedHashPrefix], taggedHashPrefixes[key]),
|
|
52
|
+
equals(TAGGED_HASH_PREFIXES[key as TaggedHashPrefix], taggedHashPrefixes[key] as Uint8Array),
|
|
53
53
|
`Mismatch for tag ${key}`,
|
|
54
54
|
);
|
|
55
55
|
}
|
package/test/env.spec.ts
CHANGED
|
@@ -30,7 +30,7 @@ describe('Runtime capability check — hard requirements', () => {
|
|
|
30
30
|
|
|
31
31
|
it('should throw when DataView.getBigInt64 is missing', async () => {
|
|
32
32
|
const orig = DataView.prototype.getBigInt64;
|
|
33
|
-
(DataView.prototype as Record<string, unknown>)['getBigInt64'] = undefined;
|
|
33
|
+
(DataView.prototype as unknown as Record<string, unknown>)['getBigInt64'] = undefined;
|
|
34
34
|
|
|
35
35
|
try {
|
|
36
36
|
await import('../src/env.js');
|
|
@@ -261,7 +261,7 @@ describe('Polyfill — Promise.allSettled', () => {
|
|
|
261
261
|
|
|
262
262
|
it('should polyfill Promise.allSettled when missing', async () => {
|
|
263
263
|
const orig = Promise.allSettled;
|
|
264
|
-
(Promise as Record<string, unknown>)['allSettled'] = undefined;
|
|
264
|
+
(Promise as unknown as Record<string, unknown>)['allSettled'] = undefined;
|
|
265
265
|
|
|
266
266
|
try {
|
|
267
267
|
await import('../src/env.js');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RegtestUtils } from 'regtest-client';
|
|
2
2
|
|
|
3
|
-
const APIPASS = process.env
|
|
4
|
-
const APIURL = process.env
|
|
3
|
+
const APIPASS = process.env['APIPASS'] || 'satoshi';
|
|
4
|
+
const APIURL = process.env['APIURL'] || 'https://regtest.bitbank.cc/1';
|
|
5
5
|
|
|
6
6
|
export const regtestUtils = new RegtestUtils({ APIPASS, APIURL });
|
|
7
7
|
|
|
@@ -17,7 +17,7 @@ describe('bitcoinjs-lib (blocks)', () => {
|
|
|
17
17
|
const tx = bitcoin.Transaction.fromHex(txHex);
|
|
18
18
|
|
|
19
19
|
assert.strictEqual(tx.ins.length, 1);
|
|
20
|
-
const script = tx.ins[0]
|
|
20
|
+
const script = tx.ins[0]!.script;
|
|
21
21
|
// bitcoin.script.decompile(script) // returns [] :(
|
|
22
22
|
|
|
23
23
|
assert.strictEqual(script[0], 0x03);
|
|
@@ -403,7 +403,7 @@ function csvGetFinalScripts(
|
|
|
403
403
|
output: script,
|
|
404
404
|
// This logic should be more strict and make sure the pubkeys in the
|
|
405
405
|
// meaningful script are the ones signing in the PSBT etc.
|
|
406
|
-
input: bitcoin.script.compile([input.partialSig![0]
|
|
406
|
+
input: bitcoin.script.compile([input.partialSig![0]!.signature, bitcoin.opcodes.OP_TRUE]),
|
|
407
407
|
};
|
|
408
408
|
if (isP2WSH && isSegwit)
|
|
409
409
|
payment = bitcoin.payments.p2wsh({
|
|
@@ -42,7 +42,7 @@ async function buildAndSign(
|
|
|
42
42
|
psbt.signInput(0, keyPair);
|
|
43
43
|
});
|
|
44
44
|
} else if (depends.signature) {
|
|
45
|
-
psbt.signInput(0, keyPairs[0]);
|
|
45
|
+
psbt.signInput(0, keyPairs[0]!);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return regtestUtils.broadcast(psbt.finalizeAllInputs().extractTransaction().toHex());
|
|
@@ -54,7 +54,7 @@ async function buildAndSign(
|
|
|
54
54
|
const fn: any = (bitcoin.payments as any)[k];
|
|
55
55
|
|
|
56
56
|
const base: any = {};
|
|
57
|
-
if (depends.pubkey) base.pubkey = keyPairs[0]
|
|
57
|
+
if (depends.pubkey) base.pubkey = keyPairs[0]!.publicKey;
|
|
58
58
|
if (depends.pubkeys) base.pubkeys = keyPairs.map((x) => x.publicKey);
|
|
59
59
|
if (depends.m) base.m = base.pubkeys.length;
|
|
60
60
|
|
|
@@ -508,9 +508,9 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
|
|
|
508
508
|
psbt.addOutput({ value: BigInt(sendAmount) as Satoshi, address: address! });
|
|
509
509
|
|
|
510
510
|
// random order for signers
|
|
511
|
-
psbt.signInput(0, leafKeys[1]);
|
|
512
|
-
psbt.signInput(0, leafKeys[2]);
|
|
513
|
-
psbt.signInput(0, leafKeys[0]);
|
|
511
|
+
psbt.signInput(0, leafKeys[1]!);
|
|
512
|
+
psbt.signInput(0, leafKeys[2]!);
|
|
513
|
+
psbt.signInput(0, leafKeys[0]!);
|
|
514
514
|
|
|
515
515
|
psbt.finalizeInput(0);
|
|
516
516
|
const tx = psbt.extractTransaction();
|
|
@@ -2,7 +2,8 @@ import assert from 'assert';
|
|
|
2
2
|
import { BIP32Factory } from '@btc-vision/bip32';
|
|
3
3
|
import * as ecc from 'tiny-secp256k1';
|
|
4
4
|
import { describe, it } from 'vitest';
|
|
5
|
-
import type {
|
|
5
|
+
import type { PrivateKey, PublicKey, Satoshi, Signature } from '../../src/index.js';
|
|
6
|
+
import type { MessageHash } from '../../src/types.js';
|
|
6
7
|
import * as bitcoin from '../../src/index.js';
|
|
7
8
|
import { compare, fromHex } from '../../src/index.js';
|
|
8
9
|
import type { HDSigner } from '../../src/psbt/types.js';
|
|
@@ -600,13 +601,13 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
|
|
|
600
601
|
function createPayment(_type: string, myKeys?: any[], network?: any): any {
|
|
601
602
|
network = network || regtest;
|
|
602
603
|
const splitType = _type.split('-').reverse();
|
|
603
|
-
const isMultisig = splitType[0]
|
|
604
|
+
const isMultisig = splitType[0]!.slice(0, 4) === 'p2ms';
|
|
604
605
|
const keys = myKeys || [];
|
|
605
606
|
let m: number | undefined;
|
|
606
607
|
if (isMultisig) {
|
|
607
|
-
const match = splitType[0]
|
|
608
|
-
m = parseInt(match![1]
|
|
609
|
-
let n = parseInt(match![2]
|
|
608
|
+
const match = splitType[0]!.match(/^p2ms\((\d+) of (\d+)\)$/);
|
|
609
|
+
m = parseInt(match![1]!, 10);
|
|
610
|
+
let n = parseInt(match![2]!, 10);
|
|
610
611
|
if (keys.length > 0 && keys.length !== n) {
|
|
611
612
|
throw new Error('Need n keys for multisig');
|
|
612
613
|
}
|
package/test/psbt.spec.ts
CHANGED
|
@@ -42,8 +42,8 @@ const initBuffers = (object: any): typeof preFixtures =>
|
|
|
42
42
|
const result = regex.exec(value);
|
|
43
43
|
if (!result) return value;
|
|
44
44
|
|
|
45
|
-
const data = result[1];
|
|
46
|
-
const encoding = result[2];
|
|
45
|
+
const data = result[1] as string;
|
|
46
|
+
const encoding = result[2] as string;
|
|
47
47
|
|
|
48
48
|
return Buffer.from(data, encoding as BufferEncoding);
|
|
49
49
|
});
|
|
@@ -55,7 +55,7 @@ const upperCaseFirstLetter = (str: string): string => str.replace(/^./, (s) => s
|
|
|
55
55
|
const toAsyncSigner = (signer: Signer): SignerAsync => {
|
|
56
56
|
return {
|
|
57
57
|
publicKey: signer.publicKey,
|
|
58
|
-
sign: (hash:
|
|
58
|
+
sign: (hash: MessageHash, lowerR: boolean | undefined): Promise<Signature> => {
|
|
59
59
|
return new Promise((resolve, rejects): void => {
|
|
60
60
|
setTimeout(() => {
|
|
61
61
|
try {
|
|
@@ -69,10 +69,10 @@ const toAsyncSigner = (signer: Signer): SignerAsync => {
|
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
|
-
const failedAsyncSigner = (publicKey:
|
|
72
|
+
const failedAsyncSigner = (publicKey: Uint8Array): SignerAsync => {
|
|
73
73
|
return <SignerAsync>{
|
|
74
74
|
publicKey: publicKey as unknown as PublicKey,
|
|
75
|
-
sign: (__:
|
|
75
|
+
sign: (__: MessageHash): Promise<Signature> => {
|
|
76
76
|
return new Promise((_, reject): void => {
|
|
77
77
|
setTimeout(() => {
|
|
78
78
|
reject(new Error('sign failed'));
|
|
@@ -178,14 +178,17 @@ describe(`Psbt`, () => {
|
|
|
178
178
|
fixtures.bip174.combiner.forEach((f) => {
|
|
179
179
|
it('Combines two PSBTs to the expected result', () => {
|
|
180
180
|
const psbts = f.psbts.map((psbt) => Psbt.fromBase64(psbt));
|
|
181
|
+
const psbt0 = psbts[0];
|
|
182
|
+
const psbt1 = psbts[1];
|
|
183
|
+
assert(psbt0 && psbt1);
|
|
181
184
|
|
|
182
|
-
|
|
185
|
+
psbt0.combine(psbt1);
|
|
183
186
|
|
|
184
187
|
// Produces a different Base64 string due to implementation specific key-value ordering.
|
|
185
188
|
// That means this test will fail:
|
|
186
189
|
// assert.strictEqual(psbts[0].toBase64(), f.result)
|
|
187
190
|
// Compare the serialized PSBT hex instead - this is deterministic
|
|
188
|
-
assert.strictEqual(
|
|
191
|
+
assert.strictEqual(psbt0.toHex(), Psbt.fromBase64(f.result).toHex());
|
|
189
192
|
});
|
|
190
193
|
});
|
|
191
194
|
|
|
@@ -212,8 +215,10 @@ describe(`Psbt`, () => {
|
|
|
212
215
|
assert.strictEqual(transaction1, f.transaction);
|
|
213
216
|
|
|
214
217
|
const psbt3 = Psbt.fromBase64(f.psbt);
|
|
215
|
-
|
|
216
|
-
|
|
218
|
+
const psbt3Input0 = psbt3.data.inputs[0];
|
|
219
|
+
assert(psbt3Input0);
|
|
220
|
+
delete psbt3Input0.finalScriptSig;
|
|
221
|
+
delete psbt3Input0.finalScriptWitness;
|
|
217
222
|
assert.throws(() => {
|
|
218
223
|
psbt3.extractTransaction();
|
|
219
224
|
}, new RegExp('Not finalized'));
|
|
@@ -691,9 +696,13 @@ describe(`Psbt`, () => {
|
|
|
691
696
|
});
|
|
692
697
|
|
|
693
698
|
assert.strictEqual(psbt.inputCount, 1);
|
|
694
|
-
|
|
699
|
+
const txIn0 = psbt.txInputs[0];
|
|
700
|
+
assert(txIn0);
|
|
701
|
+
assert.strictEqual(txIn0.sequence, 0xffffffff);
|
|
695
702
|
psbt.setInputSequence(0, 0);
|
|
696
|
-
|
|
703
|
+
const txIn0After = psbt.txInputs[0];
|
|
704
|
+
assert(txIn0After);
|
|
705
|
+
assert.strictEqual(txIn0After.sequence, 0);
|
|
697
706
|
});
|
|
698
707
|
|
|
699
708
|
it('throws if input index is too high', () => {
|
|
@@ -847,6 +856,9 @@ describe(`Psbt`, () => {
|
|
|
847
856
|
index: 0,
|
|
848
857
|
});
|
|
849
858
|
|
|
859
|
+
const input0 = psbt.data.inputs[0];
|
|
860
|
+
assert(input0);
|
|
861
|
+
|
|
850
862
|
assert.throws(() => {
|
|
851
863
|
psbt.inputHasPubkey(0, testPubkey);
|
|
852
864
|
}, new RegExp("Can't find pubkey in input without Utxo data"));
|
|
@@ -856,7 +868,7 @@ describe(`Psbt`, () => {
|
|
|
856
868
|
value: 1337n as Satoshi,
|
|
857
869
|
script: payments.p2sh({
|
|
858
870
|
redeem: { output: Buffer.from([0x51]) as unknown as Script },
|
|
859
|
-
}).output
|
|
871
|
+
}).output as Script,
|
|
860
872
|
},
|
|
861
873
|
});
|
|
862
874
|
|
|
@@ -864,14 +876,14 @@ describe(`Psbt`, () => {
|
|
|
864
876
|
psbt.inputHasPubkey(0, testPubkey);
|
|
865
877
|
}, new RegExp('scriptPubkey is P2SH but redeemScript missing'));
|
|
866
878
|
|
|
867
|
-
delete
|
|
879
|
+
delete input0.witnessUtxo;
|
|
868
880
|
|
|
869
881
|
psbt.updateInput(0, {
|
|
870
882
|
witnessUtxo: {
|
|
871
883
|
value: 1337n as Satoshi,
|
|
872
884
|
script: payments.p2wsh({
|
|
873
885
|
redeem: { output: Buffer.from([0x51]) as unknown as Script },
|
|
874
|
-
}).output
|
|
886
|
+
}).output as Script,
|
|
875
887
|
},
|
|
876
888
|
});
|
|
877
889
|
|
|
@@ -879,7 +891,7 @@ describe(`Psbt`, () => {
|
|
|
879
891
|
psbt.inputHasPubkey(0, testPubkey);
|
|
880
892
|
}, new RegExp('scriptPubkey or redeemScript is P2WSH but witnessScript missing'));
|
|
881
893
|
|
|
882
|
-
delete
|
|
894
|
+
delete input0.witnessUtxo;
|
|
883
895
|
|
|
884
896
|
// Create a script that contains the test pubkey
|
|
885
897
|
const scriptWithPubkey = Buffer.concat([
|
|
@@ -1011,7 +1023,9 @@ describe(`Psbt`, () => {
|
|
|
1011
1023
|
psbt3.outputHasPubkey(0, testPubkey);
|
|
1012
1024
|
}, new RegExp('scriptPubkey or redeemScript is P2WSH but witnessScript missing'));
|
|
1013
1025
|
|
|
1014
|
-
|
|
1026
|
+
const psbt3Output0 = psbt3.data.outputs[0];
|
|
1027
|
+
assert(psbt3Output0);
|
|
1028
|
+
delete psbt3Output0.redeemScript;
|
|
1015
1029
|
|
|
1016
1030
|
psbt.updateOutput(0, {
|
|
1017
1031
|
witnessScript: scriptWithPubkey,
|
|
@@ -1046,7 +1060,9 @@ describe(`Psbt`, () => {
|
|
|
1046
1060
|
assert.strictEqual(clone.toBase64(), notAClone.toBase64());
|
|
1047
1061
|
assert.strictEqual(psbt.toBase64(), notAClone.toBase64());
|
|
1048
1062
|
// Mutate data layer to prove clone is independent
|
|
1049
|
-
psbt.data.inputs[0]
|
|
1063
|
+
const cloneInput0 = psbt.data.inputs[0];
|
|
1064
|
+
assert(cloneInput0);
|
|
1065
|
+
cloneInput0.partialSig = [];
|
|
1050
1066
|
assert.notStrictEqual(clone.toBase64(), psbt.toBase64());
|
|
1051
1067
|
assert.notStrictEqual(clone.toBase64(), notAClone.toBase64());
|
|
1052
1068
|
assert.strictEqual(psbt.toBase64(), notAClone.toBase64());
|
|
@@ -1414,17 +1430,20 @@ describe(`Psbt`, () => {
|
|
|
1414
1430
|
const psbt = Psbt.fromBase64(f.psbt);
|
|
1415
1431
|
const index = f.inputIndex;
|
|
1416
1432
|
|
|
1433
|
+
const cacheInput = psbt.data.inputs[index];
|
|
1434
|
+
assert(cacheInput);
|
|
1435
|
+
|
|
1417
1436
|
// nonWitnessUtxo is not set before updateInput
|
|
1418
|
-
assert.strictEqual(
|
|
1437
|
+
assert.strictEqual(cacheInput.nonWitnessUtxo, undefined);
|
|
1419
1438
|
|
|
1420
1439
|
// After updateInput, the nonWitnessUtxo is stored on the input
|
|
1421
1440
|
psbt.updateInput(index, {
|
|
1422
1441
|
nonWitnessUtxo: f.nonWitnessUtxo as any,
|
|
1423
1442
|
});
|
|
1424
|
-
assert.ok(
|
|
1443
|
+
assert.ok(cacheInput.nonWitnessUtxo);
|
|
1425
1444
|
assert.ok(
|
|
1426
1445
|
equals(
|
|
1427
|
-
|
|
1446
|
+
cacheInput.nonWitnessUtxo as Uint8Array,
|
|
1428
1447
|
f.nonWitnessUtxo as any,
|
|
1429
1448
|
),
|
|
1430
1449
|
);
|
|
@@ -1440,10 +1459,11 @@ describe(`Psbt`, () => {
|
|
|
1440
1459
|
});
|
|
1441
1460
|
|
|
1442
1461
|
const input = psbt.data.inputs[index];
|
|
1462
|
+
assert(input);
|
|
1443
1463
|
const desc = Object.getOwnPropertyDescriptor(input, 'nonWitnessUtxo');
|
|
1444
1464
|
assert.ok(desc, 'property should exist');
|
|
1445
|
-
assert.strictEqual(desc
|
|
1446
|
-
assert.strictEqual(desc
|
|
1465
|
+
assert.strictEqual(desc.get, undefined, 'should not have a getter');
|
|
1466
|
+
assert.strictEqual(desc.set, undefined, 'should not have a setter');
|
|
1447
1467
|
});
|
|
1448
1468
|
});
|
|
1449
1469
|
|
|
@@ -1473,17 +1493,19 @@ describe(`Psbt`, () => {
|
|
|
1473
1493
|
psbt.addInput({ hash, index });
|
|
1474
1494
|
|
|
1475
1495
|
const input = psbt.txInputs[0];
|
|
1496
|
+
assert(input);
|
|
1476
1497
|
const originalHash = new Uint8Array(input.hash);
|
|
1477
1498
|
const originalIndex = input.index;
|
|
1478
1499
|
const originalSequence = input.sequence;
|
|
1479
1500
|
|
|
1480
1501
|
// Mutate the returned clone
|
|
1481
1502
|
input.hash[0] = 123;
|
|
1482
|
-
input.index = 123;
|
|
1483
|
-
input.sequence = 123;
|
|
1503
|
+
(input as { index: number }).index = 123;
|
|
1504
|
+
(input as { sequence: number }).sequence = 123;
|
|
1484
1505
|
|
|
1485
1506
|
// Internal state should be unchanged
|
|
1486
1507
|
const fresh = psbt.txInputs[0];
|
|
1508
|
+
assert(fresh);
|
|
1487
1509
|
assert.ok(equals(fresh.hash, originalHash));
|
|
1488
1510
|
assert.strictEqual(fresh.index, originalIndex);
|
|
1489
1511
|
assert.strictEqual(fresh.sequence, originalSequence);
|
|
@@ -1496,6 +1518,7 @@ describe(`Psbt`, () => {
|
|
|
1496
1518
|
psbt.addOutput({ address, value });
|
|
1497
1519
|
|
|
1498
1520
|
const output = psbt.txOutputs[0];
|
|
1521
|
+
assert(output);
|
|
1499
1522
|
assert.strictEqual(output.address, address);
|
|
1500
1523
|
|
|
1501
1524
|
const originalScript = new Uint8Array(output.script);
|
|
@@ -1503,10 +1526,11 @@ describe(`Psbt`, () => {
|
|
|
1503
1526
|
|
|
1504
1527
|
// Mutate the returned clone
|
|
1505
1528
|
output.script[0] = 123;
|
|
1506
|
-
output.value = 123n;
|
|
1529
|
+
(output as { value: bigint }).value = 123n;
|
|
1507
1530
|
|
|
1508
1531
|
// Internal state should be unchanged
|
|
1509
1532
|
const fresh = psbt.txOutputs[0];
|
|
1533
|
+
assert(fresh);
|
|
1510
1534
|
assert.ok(equals(fresh.script, originalScript));
|
|
1511
1535
|
assert.strictEqual(fresh.value, originalValue);
|
|
1512
1536
|
});
|