@btc-vision/bitcoin 7.0.0-alpha.1 → 7.0.0-alpha.10
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 +455 -155
- package/browser/address.d.ts +5 -1
- package/browser/address.d.ts.map +1 -1
- package/browser/branded.d.ts +3 -14
- package/browser/branded.d.ts.map +1 -1
- package/browser/chunks/psbt-parallel-BBFlkmiv.js +10717 -0
- package/browser/ecc/context.d.ts +22 -21
- package/browser/ecc/context.d.ts.map +1 -1
- package/browser/ecc/index.d.ts +1 -1
- package/browser/ecc/index.d.ts.map +1 -1
- package/browser/ecc/types.d.ts +10 -123
- package/browser/ecc/types.d.ts.map +1 -1
- package/browser/env.d.ts +13 -0
- package/browser/env.d.ts.map +1 -0
- package/browser/index.d.ts +6 -6
- package/browser/index.d.ts.map +1 -1
- package/browser/index.js +2602 -11786
- package/browser/io/hex.d.ts.map +1 -1
- package/browser/io/index.d.ts +0 -1
- package/browser/io/index.d.ts.map +1 -1
- package/browser/opcodes.d.ts +11 -0
- package/browser/opcodes.d.ts.map +1 -1
- package/browser/payments/p2tr.d.ts.map +1 -1
- package/browser/psbt/PsbtCache.d.ts +54 -0
- package/browser/psbt/PsbtCache.d.ts.map +1 -0
- package/browser/psbt/PsbtFinalizer.d.ts +21 -0
- package/browser/psbt/PsbtFinalizer.d.ts.map +1 -0
- package/browser/psbt/PsbtSigner.d.ts +32 -0
- package/browser/psbt/PsbtSigner.d.ts.map +1 -0
- package/browser/psbt/PsbtTransaction.d.ts +25 -0
- package/browser/psbt/PsbtTransaction.d.ts.map +1 -0
- package/browser/psbt/types.d.ts +4 -70
- package/browser/psbt/types.d.ts.map +1 -1
- package/browser/psbt/validation.d.ts +1 -1
- package/browser/psbt/validation.d.ts.map +1 -1
- package/browser/psbt.d.ts +26 -40
- package/browser/psbt.d.ts.map +1 -1
- package/browser/script.d.ts.map +1 -1
- package/browser/transaction.d.ts +4 -4
- package/browser/transaction.d.ts.map +1 -1
- package/browser/types.d.ts +5 -3
- package/browser/types.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.d.ts +7 -0
- package/browser/workers/WorkerSigningPool.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.node.d.ts +7 -0
- package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.sequential.d.ts +67 -0
- package/browser/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.worklet.d.ts +64 -0
- package/browser/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
- package/browser/workers/index.browser.d.ts +16 -0
- package/browser/workers/index.browser.d.ts.map +1 -0
- package/browser/workers/index.d.ts +4 -64
- package/browser/workers/index.d.ts.map +1 -1
- package/browser/workers/index.js +28 -0
- package/browser/workers/index.node.d.ts +17 -0
- package/browser/workers/index.node.d.ts.map +1 -0
- package/browser/workers/index.react-native.d.ts +28 -0
- package/browser/workers/index.react-native.d.ts.map +1 -0
- package/browser/workers/index.shared.d.ts +15 -0
- package/browser/workers/index.shared.d.ts.map +1 -0
- package/browser/workers/psbt-parallel.d.ts +2 -3
- package/browser/workers/psbt-parallel.d.ts.map +1 -1
- package/browser/workers/types.d.ts +17 -0
- package/browser/workers/types.d.ts.map +1 -1
- package/build/address.d.ts +5 -1
- package/build/address.d.ts.map +1 -1
- package/build/address.js +29 -17
- package/build/address.js.map +1 -1
- package/build/bech32utils.js.map +1 -1
- package/build/block.js.map +1 -1
- package/build/branded.d.ts +3 -14
- package/build/branded.d.ts.map +1 -1
- package/build/branded.js +0 -5
- package/build/branded.js.map +1 -1
- package/build/ecc/context.d.ts +22 -21
- package/build/ecc/context.d.ts.map +1 -1
- package/build/ecc/context.js +23 -95
- package/build/ecc/context.js.map +1 -1
- package/build/ecc/index.d.ts +1 -1
- package/build/ecc/index.d.ts.map +1 -1
- package/build/ecc/types.d.ts +7 -126
- package/build/ecc/types.d.ts.map +1 -1
- package/build/ecc/types.js +4 -1
- package/build/ecc/types.js.map +1 -1
- package/build/env.d.ts +13 -0
- package/build/env.d.ts.map +1 -0
- package/build/env.js +198 -0
- package/build/env.js.map +1 -0
- package/build/index.d.ts +7 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -5
- package/build/index.js.map +1 -1
- package/build/io/hex.d.ts.map +1 -1
- package/build/io/hex.js +2 -1
- package/build/io/hex.js.map +1 -1
- package/build/io/index.d.ts +0 -1
- package/build/io/index.d.ts.map +1 -1
- package/build/io/index.js +0 -2
- package/build/io/index.js.map +1 -1
- package/build/opcodes.d.ts +11 -0
- package/build/opcodes.d.ts.map +1 -1
- package/build/opcodes.js +19 -4
- package/build/opcodes.js.map +1 -1
- 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/p2pk.js.map +1 -1
- package/build/payments/p2pkh.js.map +1 -1
- package/build/payments/p2sh.js.map +1 -1
- package/build/payments/p2tr.d.ts.map +1 -1
- package/build/payments/p2tr.js +2 -3
- package/build/payments/p2tr.js.map +1 -1
- package/build/payments/p2wpkh.js.map +1 -1
- package/build/payments/p2wsh.js.map +1 -1
- package/build/psbt/PsbtCache.d.ts +54 -0
- package/build/psbt/PsbtCache.d.ts.map +1 -0
- package/build/psbt/PsbtCache.js +249 -0
- package/build/psbt/PsbtCache.js.map +1 -0
- package/build/psbt/PsbtFinalizer.d.ts +21 -0
- package/build/psbt/PsbtFinalizer.d.ts.map +1 -0
- package/build/psbt/PsbtFinalizer.js +157 -0
- package/build/psbt/PsbtFinalizer.js.map +1 -0
- package/build/psbt/PsbtSigner.d.ts +32 -0
- package/build/psbt/PsbtSigner.d.ts.map +1 -0
- package/build/psbt/PsbtSigner.js +192 -0
- package/build/psbt/PsbtSigner.js.map +1 -0
- package/build/psbt/PsbtTransaction.d.ts +25 -0
- package/build/psbt/PsbtTransaction.d.ts.map +1 -0
- package/build/psbt/PsbtTransaction.js +61 -0
- package/build/psbt/PsbtTransaction.js.map +1 -0
- package/build/psbt/types.d.ts +4 -70
- package/build/psbt/types.d.ts.map +1 -1
- package/build/psbt/validation.d.ts +1 -1
- package/build/psbt/validation.d.ts.map +1 -1
- package/build/psbt.d.ts +26 -40
- package/build/psbt.d.ts.map +1 -1
- package/build/psbt.js +177 -799
- package/build/psbt.js.map +1 -1
- package/build/script.d.ts.map +1 -1
- package/build/script.js +2 -2
- package/build/script.js.map +1 -1
- package/build/transaction.d.ts +4 -4
- package/build/transaction.d.ts.map +1 -1
- package/build/transaction.js +5 -4
- package/build/transaction.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.d.ts +5 -3
- package/build/types.d.ts.map +1 -1
- package/build/types.js +11 -16
- package/build/types.js.map +1 -1
- package/build/workers/WorkerSigningPool.d.ts +7 -0
- package/build/workers/WorkerSigningPool.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.js +12 -1
- package/build/workers/WorkerSigningPool.js.map +1 -1
- package/build/workers/WorkerSigningPool.node.d.ts +7 -0
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.node.js +37 -5
- package/build/workers/WorkerSigningPool.node.js.map +1 -1
- package/build/workers/WorkerSigningPool.sequential.d.ts +76 -0
- package/build/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.sequential.js +160 -0
- package/build/workers/WorkerSigningPool.sequential.js.map +1 -0
- package/build/workers/WorkerSigningPool.worklet.d.ts +79 -0
- package/build/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.worklet.js +390 -0
- package/build/workers/WorkerSigningPool.worklet.js.map +1 -0
- package/build/workers/index.browser.d.ts +24 -0
- package/build/workers/index.browser.d.ts.map +1 -0
- package/build/workers/index.browser.js +30 -0
- package/build/workers/index.browser.js.map +1 -0
- package/build/workers/index.d.ts +6 -18
- package/build/workers/index.d.ts.map +1 -1
- package/build/workers/index.js +12 -14
- package/build/workers/index.js.map +1 -1
- package/build/workers/index.node.d.ts +38 -0
- package/build/workers/index.node.d.ts.map +1 -0
- package/build/workers/index.node.js +45 -0
- package/build/workers/index.node.js.map +1 -0
- package/build/workers/index.react-native.d.ts +28 -0
- package/build/workers/index.react-native.d.ts.map +1 -0
- package/build/workers/index.react-native.js +67 -0
- package/build/workers/index.react-native.js.map +1 -0
- package/build/workers/index.shared.d.ts +15 -0
- package/build/workers/index.shared.d.ts.map +1 -0
- package/build/workers/index.shared.js +20 -0
- package/build/workers/index.shared.js.map +1 -0
- package/build/workers/psbt-parallel.d.ts +2 -3
- package/build/workers/psbt-parallel.d.ts.map +1 -1
- package/build/workers/psbt-parallel.js +4 -4
- package/build/workers/psbt-parallel.js.map +1 -1
- package/build/workers/types.d.ts +17 -0
- package/build/workers/types.d.ts.map +1 -1
- package/package.json +46 -8
- package/src/address.ts +41 -18
- package/src/bech32utils.ts +3 -3
- package/src/block.ts +2 -2
- package/src/branded.ts +15 -13
- package/src/ecc/context.ts +30 -133
- package/src/ecc/index.ts +2 -2
- package/src/ecc/types.ts +7 -138
- package/src/env.ts +239 -0
- package/src/index.ts +45 -9
- package/src/io/hex.ts +2 -1
- package/src/io/index.ts +0 -3
- package/src/opcodes.ts +21 -4
- package/src/payments/bip341.ts +3 -3
- package/src/payments/embed.ts +1 -1
- package/src/payments/p2ms.ts +2 -2
- package/src/payments/p2pk.ts +2 -2
- package/src/payments/p2pkh.ts +3 -3
- package/src/payments/p2sh.ts +4 -4
- package/src/payments/p2tr.ts +9 -9
- package/src/payments/p2wpkh.ts +5 -5
- package/src/payments/p2wsh.ts +2 -2
- package/src/psbt/PsbtCache.ts +325 -0
- package/src/psbt/PsbtFinalizer.ts +213 -0
- package/src/psbt/PsbtSigner.ts +302 -0
- package/src/psbt/PsbtTransaction.ts +82 -0
- package/src/psbt/types.ts +4 -86
- package/src/psbt/validation.ts +1 -1
- package/src/psbt.ts +349 -1198
- package/src/script.ts +2 -2
- package/src/transaction.ts +10 -9
- package/src/types.ts +18 -28
- package/src/workers/WorkerSigningPool.node.ts +41 -5
- package/src/workers/WorkerSigningPool.sequential.ts +191 -0
- package/src/workers/WorkerSigningPool.ts +14 -1
- package/src/workers/WorkerSigningPool.worklet.ts +522 -0
- package/src/workers/index.browser.ts +34 -0
- package/src/workers/index.node.ts +50 -0
- package/src/workers/index.react-native.ts +110 -0
- package/src/workers/index.shared.ts +58 -0
- package/src/workers/index.ts +14 -65
- package/src/workers/psbt-parallel.ts +7 -7
- package/src/workers/types.ts +21 -0
- package/test/address.spec.ts +2 -2
- package/test/bitcoin.core.spec.ts +5 -2
- package/test/browser/payments.spec.ts +151 -0
- package/test/browser/psbt.spec.ts +1510 -0
- package/test/browser/script.spec.ts +223 -0
- package/test/browser/setup.ts +13 -0
- package/test/browser/workers-signing.spec.ts +537 -0
- package/test/crypto.spec.ts +2 -2
- package/test/env.spec.ts +418 -0
- package/test/fixtures/core/base58_encode_decode.json +12 -48
- package/test/fixtures/core/base58_keys_invalid.json +50 -150
- package/test/fixtures/core/sighash.json +1 -3
- package/test/fixtures/core/tx_valid.json +133 -501
- package/test/fixtures/embed.json +3 -11
- package/test/fixtures/p2ms.json +21 -91
- package/test/fixtures/p2pk.json +5 -24
- package/test/fixtures/p2pkh.json +7 -36
- package/test/fixtures/p2sh.json +8 -54
- package/test/fixtures/p2tr.json +2 -6
- package/test/fixtures/p2wpkh.json +7 -36
- package/test/fixtures/p2wsh.json +14 -59
- package/test/fixtures/psbt.json +2 -6
- package/test/fixtures/script.json +12 -48
- package/test/integration/addresses.spec.ts +11 -5
- package/test/integration/bip32.spec.ts +1 -1
- package/test/integration/cltv.spec.ts +10 -6
- package/test/integration/csv.spec.ts +10 -9
- package/test/integration/payments.spec.ts +8 -4
- package/test/integration/taproot.spec.ts +26 -6
- package/test/integration/transactions.spec.ts +22 -8
- package/test/payments.spec.ts +1 -1
- package/test/payments.utils.ts +1 -1
- package/test/psbt.spec.ts +250 -64
- package/test/script_signature.spec.ts +1 -1
- package/test/transaction.spec.ts +18 -5
- package/test/tsconfig.json +6 -20
- package/test/workers-pool.spec.ts +65 -23
- package/test/workers-sequential.spec.ts +669 -0
- package/test/workers-signing.spec.ts +7 -3
- package/test/workers-worklet.spec.ts +500 -0
- package/test/workers.spec.ts +6 -7
- package/typedoc.json +11 -1
- package/vite.config.browser.ts +31 -6
- package/vitest.config.browser.ts +68 -0
- package/browser/ecpair.d.ts +0 -99
- package/browser/io/MemoryPool.d.ts +0 -220
- package/browser/io/MemoryPool.d.ts.map +0 -1
- package/build/io/MemoryPool.d.ts +0 -220
- package/build/io/MemoryPool.d.ts.map +0 -1
- package/build/io/MemoryPool.js +0 -309
- package/build/io/MemoryPool.js.map +0 -1
- package/src/ecpair.d.ts +0 -99
- package/src/io/MemoryPool.ts +0 -343
- package/test/taproot-cache.spec.ts +0 -694
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-adapted version of test/script.spec.ts
|
|
3
|
+
* Removes minimaldata native module dependency and its test section.
|
|
4
|
+
*/
|
|
5
|
+
import assert from 'assert';
|
|
6
|
+
import { describe, it } from 'vitest';
|
|
7
|
+
import * as bscript from '../../src/script.js';
|
|
8
|
+
import { toHex } from '../../src/io/index.js';
|
|
9
|
+
import fixtures from '../fixtures/script.json' with { type: 'json' };
|
|
10
|
+
|
|
11
|
+
describe('script', () => {
|
|
12
|
+
describe('isCanonicalPubKey', () => {
|
|
13
|
+
it('rejects if not provided a Buffer', () => {
|
|
14
|
+
assert.strictEqual(bscript.isCanonicalPubKey(0 as any), false);
|
|
15
|
+
assert.strictEqual(bscript.isCanonicalPubKey('string' as any), false);
|
|
16
|
+
assert.strictEqual(bscript.isCanonicalPubKey(null as any), false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('rejects smaller than 33 bytes', () => {
|
|
20
|
+
for (let i = 0; i < 33; i++) {
|
|
21
|
+
assert.strictEqual(bscript.isCanonicalPubKey(Buffer.allocUnsafe(i)), false);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('accepts valid compressed pubkey (33 bytes, starts with 0x02)', () => {
|
|
26
|
+
const compressedEven = Buffer.from(
|
|
27
|
+
'0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
|
|
28
|
+
'hex',
|
|
29
|
+
);
|
|
30
|
+
assert.strictEqual(bscript.isCanonicalPubKey(compressedEven), true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('accepts valid compressed pubkey (33 bytes, starts with 0x03)', () => {
|
|
34
|
+
const compressedOdd = Buffer.from(
|
|
35
|
+
'03df51984d6b8b8b1cc693e239491f77a36c9e9dfe4a486e9972a18e03610a0d22',
|
|
36
|
+
'hex',
|
|
37
|
+
);
|
|
38
|
+
assert.strictEqual(bscript.isCanonicalPubKey(compressedOdd), true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('accepts valid uncompressed pubkey (65 bytes, starts with 0x04)', () => {
|
|
42
|
+
const uncompressed = Buffer.from(
|
|
43
|
+
'0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
|
|
44
|
+
'hex',
|
|
45
|
+
);
|
|
46
|
+
assert.strictEqual(bscript.isCanonicalPubKey(uncompressed), true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('rejects invalid format indicator', () => {
|
|
50
|
+
const invalidFormat = Buffer.from(
|
|
51
|
+
'0579be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
|
|
52
|
+
'hex',
|
|
53
|
+
);
|
|
54
|
+
assert.strictEqual(bscript.isCanonicalPubKey(invalidFormat), false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('isCanonicalScriptSignature', () => {
|
|
59
|
+
it('rejects if not provided a Buffer', () => {
|
|
60
|
+
assert.strictEqual(bscript.isCanonicalScriptSignature(0 as any), false);
|
|
61
|
+
assert.strictEqual(bscript.isCanonicalScriptSignature('string' as any), false);
|
|
62
|
+
assert.strictEqual(bscript.isCanonicalScriptSignature(null as any), false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('rejects if hash type is invalid', () => {
|
|
66
|
+
const sigWithBadHashType = Buffer.from(
|
|
67
|
+
'3044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb00',
|
|
68
|
+
'hex',
|
|
69
|
+
);
|
|
70
|
+
assert.strictEqual(bscript.isCanonicalScriptSignature(sigWithBadHashType), false);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('accepts valid canonical signature with SIGHASH_ALL', () => {
|
|
74
|
+
const validSig = Buffer.from(
|
|
75
|
+
'3044022047ac8e878352d3ebbde1c94ce3a10d057c24175747116f8288e5d794d12d482f0220217f36a485cae903c713331d877c1f64677e3622ad4010726870540656fe9dcb01',
|
|
76
|
+
'hex',
|
|
77
|
+
);
|
|
78
|
+
assert.strictEqual(bscript.isCanonicalScriptSignature(validSig), true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('rejects signature with invalid DER encoding', () => {
|
|
82
|
+
const invalidDer = Buffer.from('3045022047ac8e8701', 'hex');
|
|
83
|
+
assert.strictEqual(bscript.isCanonicalScriptSignature(invalidDer), false);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('fromASM/toASM', () => {
|
|
88
|
+
fixtures.valid.forEach((f) => {
|
|
89
|
+
it('encodes/decodes ' + f.asm, () => {
|
|
90
|
+
const script = bscript.fromASM(f.asm);
|
|
91
|
+
assert.strictEqual(bscript.toASM(script), f.asm);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
fixtures.invalid.fromASM.forEach((f) => {
|
|
96
|
+
it('throws ' + f.description, () => {
|
|
97
|
+
assert.throws(() => {
|
|
98
|
+
bscript.fromASM(f.script);
|
|
99
|
+
}, new RegExp(f.description));
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('toASM', () => {
|
|
105
|
+
const OP_RETURN = bscript.opcodes.OP_RETURN;
|
|
106
|
+
it('encodes empty buffer as OP_0', () => {
|
|
107
|
+
const chunks = [OP_RETURN, Buffer.from([])];
|
|
108
|
+
assert.strictEqual(bscript.toASM(chunks), 'OP_RETURN OP_0');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
for (let i = 1; i <= 16; i++) {
|
|
112
|
+
it(`encodes one byte buffer [${i}] as OP_${i}`, () => {
|
|
113
|
+
const chunks = [OP_RETURN, Buffer.from([i])];
|
|
114
|
+
assert.strictEqual(bscript.toASM(chunks), 'OP_RETURN OP_' + i);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('fromASM/toASM (templates)', () => {
|
|
120
|
+
fixtures.valid2.forEach((f) => {
|
|
121
|
+
if (f.inputHex) {
|
|
122
|
+
const ih = bscript.toASM(Buffer.from(f.inputHex, 'hex'));
|
|
123
|
+
|
|
124
|
+
it('encodes/decodes ' + ih, () => {
|
|
125
|
+
const script = bscript.fromASM(f.input);
|
|
126
|
+
assert.strictEqual(toHex(script), f.inputHex);
|
|
127
|
+
assert.strictEqual(bscript.toASM(script), f.input);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (f.outputHex) {
|
|
132
|
+
it('encodes/decodes ' + f.output, () => {
|
|
133
|
+
const script = bscript.fromASM(f.output);
|
|
134
|
+
assert.strictEqual(toHex(script), f.outputHex);
|
|
135
|
+
assert.strictEqual(bscript.toASM(script), f.output);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('isPushOnly', () => {
|
|
142
|
+
fixtures.valid.forEach((f) => {
|
|
143
|
+
it('returns ' + !!f.stack + ' for ' + f.asm, () => {
|
|
144
|
+
const script = bscript.fromASM(f.asm);
|
|
145
|
+
const chunks = bscript.decompile(script);
|
|
146
|
+
|
|
147
|
+
assert.strictEqual(bscript.isPushOnly(chunks!), !!f.stack);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('toStack', () => {
|
|
153
|
+
fixtures.valid.forEach((f) => {
|
|
154
|
+
it('returns ' + !!f.stack + ' for ' + f.asm, () => {
|
|
155
|
+
if (!f.stack || !f.asm) return;
|
|
156
|
+
|
|
157
|
+
const script = bscript.fromASM(f.asm);
|
|
158
|
+
|
|
159
|
+
const stack = bscript.toStack(script);
|
|
160
|
+
assert.deepStrictEqual(
|
|
161
|
+
stack.map((x) => {
|
|
162
|
+
return toHex(x);
|
|
163
|
+
}),
|
|
164
|
+
f.stack,
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
assert.strictEqual(
|
|
168
|
+
bscript.toASM(bscript.compile(stack)),
|
|
169
|
+
f.asm,
|
|
170
|
+
'should rebuild same script from stack',
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe('compile (via fromASM)', () => {
|
|
177
|
+
fixtures.valid.forEach((f) => {
|
|
178
|
+
it('compiles ' + f.asm, () => {
|
|
179
|
+
const scriptSig = bscript.fromASM(f.asm);
|
|
180
|
+
|
|
181
|
+
assert.strictEqual(toHex(scriptSig), f.script);
|
|
182
|
+
|
|
183
|
+
if (f.nonstandard) {
|
|
184
|
+
const scriptSigNS = bscript.fromASM(f.nonstandard.scriptSig);
|
|
185
|
+
|
|
186
|
+
assert.strictEqual(toHex(scriptSigNS), f.script);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('decompile', () => {
|
|
193
|
+
fixtures.valid.forEach((f) => {
|
|
194
|
+
it('decompiles ' + f.asm, () => {
|
|
195
|
+
const chunks = bscript.decompile(Buffer.from(f.script, 'hex'));
|
|
196
|
+
|
|
197
|
+
assert.strictEqual(toHex(bscript.compile(chunks!)), f.script);
|
|
198
|
+
assert.strictEqual(bscript.toASM(chunks!), f.asm);
|
|
199
|
+
|
|
200
|
+
if (f.nonstandard) {
|
|
201
|
+
const chunksNS = bscript.decompile(
|
|
202
|
+
Buffer.from(f.nonstandard.scriptSigHex, 'hex'),
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
assert.strictEqual(toHex(bscript.compile(chunksNS!)), f.script);
|
|
206
|
+
|
|
207
|
+
assert.strictEqual(bscript.toASM(chunksNS!), f.nonstandard.scriptSig);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
fixtures.invalid.decompile.forEach((f) => {
|
|
213
|
+
it('fails to decompile ' + f.script + ', because "' + f.description + '"', () => {
|
|
214
|
+
const chunks = bscript.decompile(Buffer.from(f.script, 'hex'));
|
|
215
|
+
|
|
216
|
+
assert.strictEqual(chunks, null);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// NOTE: SCRIPT_VERIFY_MINIMALDATA tests excluded in browser build
|
|
222
|
+
// because the 'minimaldata' package is a native Node.js module
|
|
223
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe utilities for tests that need crypto.randomBytes().
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Browser-safe replacement for Node.js `crypto.randomBytes()`.
|
|
7
|
+
* Uses the Web Crypto API (`crypto.getRandomValues()`).
|
|
8
|
+
*/
|
|
9
|
+
export function randomBytes(size: number): Uint8Array {
|
|
10
|
+
const buf = new Uint8Array(size);
|
|
11
|
+
globalThis.crypto.getRandomValues(buf);
|
|
12
|
+
return buf;
|
|
13
|
+
}
|