@btc-vision/bitcoin 6.3.6 → 6.4.1

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.
Files changed (71) hide show
  1. package/.mocharc.json +13 -0
  2. package/browser/address.d.ts +1 -1
  3. package/browser/index.js +1 -1
  4. package/browser/index.js.LICENSE.txt +3 -3
  5. package/browser/networks.d.ts +1 -0
  6. package/build/address.d.ts +2 -1
  7. package/build/address.js +68 -13
  8. package/build/block.js +2 -2
  9. package/build/bufferutils.js +5 -5
  10. package/build/networks.d.ts +1 -0
  11. package/build/networks.js +11 -0
  12. package/build/psbt/psbtutils.js +2 -2
  13. package/build/psbt.js +3 -7
  14. package/package.json +26 -26
  15. package/src/address.ts +91 -15
  16. package/src/block.ts +2 -2
  17. package/src/bufferutils.ts +15 -7
  18. package/src/index.ts +86 -86
  19. package/src/networks.ts +12 -0
  20. package/src/psbt/bip371.ts +441 -441
  21. package/src/psbt/psbtutils.ts +320 -319
  22. package/src/psbt.ts +8 -8
  23. package/test/address.spec.ts +55 -77
  24. package/test/bitcoin.core.spec.ts +47 -69
  25. package/test/block.spec.ts +23 -46
  26. package/test/bufferutils.spec.ts +32 -95
  27. package/test/crypto.spec.ts +9 -15
  28. package/test/fixtures/address.json +3 -3
  29. package/test/integration/addresses.spec.ts +12 -24
  30. package/test/integration/bip32.spec.ts +10 -31
  31. package/test/integration/blocks.spec.ts +2 -2
  32. package/test/integration/cltv.spec.ts +21 -63
  33. package/test/integration/csv.spec.ts +30 -105
  34. package/test/integration/payments.spec.ts +16 -41
  35. package/test/integration/taproot.spec.ts +31 -75
  36. package/test/integration/transactions.spec.ts +37 -138
  37. package/test/payments.spec.ts +95 -106
  38. package/test/payments.utils.ts +20 -63
  39. package/test/psbt.spec.ts +100 -229
  40. package/test/script.spec.ts +26 -50
  41. package/test/script_number.spec.ts +6 -9
  42. package/test/script_signature.spec.ts +7 -7
  43. package/test/transaction.spec.ts +46 -96
  44. package/test/ts-node-register.js +3 -1
  45. package/test/tsconfig.json +4 -1
  46. package/test/types.spec.ts +7 -12
  47. package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  48. package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  49. package/.nyc_output/processinfo/index.json +0 -1
  50. package/test/address.spec.js +0 -124
  51. package/test/bitcoin.core.spec.js +0 -170
  52. package/test/block.spec.js +0 -141
  53. package/test/bufferutils.spec.js +0 -427
  54. package/test/crypto.spec.js +0 -41
  55. package/test/integration/_regtest.js +0 -7
  56. package/test/integration/addresses.spec.js +0 -116
  57. package/test/integration/bip32.spec.js +0 -85
  58. package/test/integration/blocks.spec.js +0 -26
  59. package/test/integration/cltv.spec.js +0 -199
  60. package/test/integration/csv.spec.js +0 -362
  61. package/test/integration/payments.spec.js +0 -98
  62. package/test/integration/taproot.spec.js +0 -532
  63. package/test/integration/transactions.spec.js +0 -561
  64. package/test/payments.spec.js +0 -97
  65. package/test/payments.utils.js +0 -190
  66. package/test/psbt.spec.js +0 -1044
  67. package/test/script.spec.js +0 -151
  68. package/test/script_number.spec.js +0 -24
  69. package/test/script_signature.spec.js +0 -52
  70. package/test/transaction.spec.js +0 -269
  71. package/test/types.spec.js +0 -46
@@ -1,151 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const mocha_1 = require("mocha");
5
- const bscript = require("../src/script");
6
- const fixtures = require("./fixtures/script.json");
7
- const minimalData = require('minimaldata');
8
- (0, mocha_1.describe)('script', () => {
9
- // TODO
10
- (0, mocha_1.describe)('isCanonicalPubKey', () => {
11
- (0, mocha_1.it)('rejects if not provided a Buffer', () => {
12
- assert.strictEqual(false, bscript.isCanonicalPubKey(0));
13
- });
14
- (0, mocha_1.it)('rejects smaller than 33', () => {
15
- for (let i = 0; i < 33; i++) {
16
- assert.strictEqual(false, bscript.isCanonicalPubKey(Buffer.allocUnsafe(i)));
17
- }
18
- });
19
- });
20
- mocha_1.describe.skip('isCanonicalScriptSignature', () => {
21
- assert.ok(true);
22
- });
23
- (0, mocha_1.describe)('fromASM/toASM', () => {
24
- fixtures.valid.forEach(f => {
25
- (0, mocha_1.it)('encodes/decodes ' + f.asm, () => {
26
- const script = bscript.fromASM(f.asm);
27
- assert.strictEqual(bscript.toASM(script), f.asm);
28
- });
29
- });
30
- fixtures.invalid.fromASM.forEach(f => {
31
- (0, mocha_1.it)('throws ' + f.description, () => {
32
- assert.throws(() => {
33
- bscript.fromASM(f.script);
34
- }, new RegExp(f.description));
35
- });
36
- });
37
- });
38
- (0, mocha_1.describe)('toASM', () => {
39
- const OP_RETURN = bscript.OPS.OP_RETURN;
40
- (0, mocha_1.it)('encodes empty buffer as OP_0', () => {
41
- const chunks = [OP_RETURN, Buffer.from([])];
42
- assert.strictEqual(bscript.toASM(chunks), 'OP_RETURN OP_0');
43
- });
44
- for (let i = 1; i <= 16; i++) {
45
- (0, mocha_1.it)(`encodes one byte buffer [${i}] as OP_${i}`, () => {
46
- const chunks = [OP_RETURN, Buffer.from([i])];
47
- assert.strictEqual(bscript.toASM(chunks), 'OP_RETURN OP_' + i);
48
- });
49
- }
50
- });
51
- (0, mocha_1.describe)('fromASM/toASM (templates)', () => {
52
- fixtures.valid2.forEach(f => {
53
- if (f.inputHex) {
54
- const ih = bscript.toASM(Buffer.from(f.inputHex, 'hex'));
55
- (0, mocha_1.it)('encodes/decodes ' + ih, () => {
56
- const script = bscript.fromASM(f.input);
57
- assert.strictEqual(script.toString('hex'), f.inputHex);
58
- assert.strictEqual(bscript.toASM(script), f.input);
59
- });
60
- }
61
- if (f.outputHex) {
62
- (0, mocha_1.it)('encodes/decodes ' + f.output, () => {
63
- const script = bscript.fromASM(f.output);
64
- assert.strictEqual(script.toString('hex'), f.outputHex);
65
- assert.strictEqual(bscript.toASM(script), f.output);
66
- });
67
- }
68
- });
69
- });
70
- (0, mocha_1.describe)('isPushOnly', () => {
71
- fixtures.valid.forEach(f => {
72
- (0, mocha_1.it)('returns ' + !!f.stack + ' for ' + f.asm, () => {
73
- const script = bscript.fromASM(f.asm);
74
- const chunks = bscript.decompile(script);
75
- assert.strictEqual(bscript.isPushOnly(chunks), !!f.stack);
76
- });
77
- });
78
- });
79
- (0, mocha_1.describe)('toStack', () => {
80
- fixtures.valid.forEach(f => {
81
- (0, mocha_1.it)('returns ' + !!f.stack + ' for ' + f.asm, () => {
82
- if (!f.stack || !f.asm)
83
- return;
84
- const script = bscript.fromASM(f.asm);
85
- const stack = bscript.toStack(script);
86
- assert.deepStrictEqual(stack.map(x => {
87
- return x.toString('hex');
88
- }), f.stack);
89
- assert.strictEqual(bscript.toASM(bscript.compile(stack)), f.asm, 'should rebuild same script from stack');
90
- });
91
- });
92
- });
93
- (0, mocha_1.describe)('compile (via fromASM)', () => {
94
- fixtures.valid.forEach(f => {
95
- (0, mocha_1.it)('compiles ' + f.asm, () => {
96
- const scriptSig = bscript.fromASM(f.asm);
97
- assert.strictEqual(scriptSig.toString('hex'), f.script);
98
- if (f.nonstandard) {
99
- const scriptSigNS = bscript.fromASM(f.nonstandard.scriptSig);
100
- assert.strictEqual(scriptSigNS.toString('hex'), f.script);
101
- }
102
- });
103
- });
104
- });
105
- (0, mocha_1.describe)('decompile', () => {
106
- fixtures.valid.forEach(f => {
107
- (0, mocha_1.it)('decompiles ' + f.asm, () => {
108
- const chunks = bscript.decompile(Buffer.from(f.script, 'hex'));
109
- assert.strictEqual(bscript.compile(chunks).toString('hex'), f.script);
110
- assert.strictEqual(bscript.toASM(chunks), f.asm);
111
- if (f.nonstandard) {
112
- const chunksNS = bscript.decompile(Buffer.from(f.nonstandard.scriptSigHex, 'hex'));
113
- assert.strictEqual(bscript.compile(chunksNS).toString('hex'), f.script);
114
- // toASM converts verbatim, only `compile` transforms the script to a minimalpush compliant script
115
- assert.strictEqual(bscript.toASM(chunksNS), f.nonstandard.scriptSig);
116
- }
117
- });
118
- });
119
- fixtures.invalid.decompile.forEach(f => {
120
- (0, mocha_1.it)('fails to decompile ' +
121
- f.script +
122
- ', because "' +
123
- f.description +
124
- '"', () => {
125
- const chunks = bscript.decompile(Buffer.from(f.script, 'hex'));
126
- assert.strictEqual(chunks, null);
127
- });
128
- });
129
- });
130
- (0, mocha_1.describe)('SCRIPT_VERIFY_MINIMALDATA policy', () => {
131
- fixtures.valid.forEach(f => {
132
- (0, mocha_1.it)('compliant for scriptSig ' + f.asm, () => {
133
- const script = Buffer.from(f.script, 'hex');
134
- assert(minimalData(script));
135
- });
136
- });
137
- function testEncodingForSize(num) {
138
- (0, mocha_1.it)('compliant for data PUSH of length ' + num, () => {
139
- const buffer = Buffer.alloc(num);
140
- const script = bscript.compile([buffer]);
141
- assert(minimalData(script), 'Failed for ' +
142
- num +
143
- ' length script: ' +
144
- script.toString('hex'));
145
- });
146
- }
147
- for (let i = 0; i < 520; ++i) {
148
- testEncodingForSize(i);
149
- }
150
- });
151
- });
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const mocha_1 = require("mocha");
5
- const scriptNumber = require("../src/script_number");
6
- const fixtures = require("./fixtures/script_number.json");
7
- (0, mocha_1.describe)('script-number', () => {
8
- (0, mocha_1.describe)('decode', () => {
9
- fixtures.forEach(f => {
10
- (0, mocha_1.it)(f.hex + ' returns ' + f.number, () => {
11
- const actual = scriptNumber.decode(Buffer.from(f.hex, 'hex'), f.bytes);
12
- assert.strictEqual(actual, f.number);
13
- });
14
- });
15
- });
16
- (0, mocha_1.describe)('encode', () => {
17
- fixtures.forEach(f => {
18
- (0, mocha_1.it)(f.number + ' returns ' + f.hex, () => {
19
- const actual = scriptNumber.encode(f.number);
20
- assert.strictEqual(actual.toString('hex'), f.hex);
21
- });
22
- });
23
- });
24
- });
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const mocha_1 = require("mocha");
5
- const script_1 = require("../src/script");
6
- const fixtures = require("./fixtures/signature.json");
7
- (0, mocha_1.describe)('Script Signatures', () => {
8
- function fromRaw(signature) {
9
- return Buffer.concat([Buffer.from(signature.r, 'hex'), Buffer.from(signature.s, 'hex')], 64);
10
- }
11
- function toRaw(signature) {
12
- return {
13
- r: signature.slice(0, 32).toString('hex'),
14
- s: signature.slice(32, 64).toString('hex'),
15
- };
16
- }
17
- (0, mocha_1.describe)('encode', () => {
18
- fixtures.valid.forEach(f => {
19
- (0, mocha_1.it)('encodes ' + f.hex, () => {
20
- const buffer = script_1.signature.encode(fromRaw(f.raw), f.hashType);
21
- assert.strictEqual(buffer.toString('hex'), f.hex);
22
- });
23
- });
24
- fixtures.invalid.forEach(f => {
25
- if (!f.raw)
26
- return;
27
- (0, mocha_1.it)('throws ' + f.exception, () => {
28
- const signature = fromRaw(f.raw);
29
- assert.throws(() => {
30
- script_1.signature.encode(signature, f.hashType);
31
- }, new RegExp(f.exception));
32
- });
33
- });
34
- });
35
- (0, mocha_1.describe)('decode', () => {
36
- fixtures.valid.forEach(f => {
37
- (0, mocha_1.it)('decodes ' + f.hex, () => {
38
- const decode = script_1.signature.decode(Buffer.from(f.hex, 'hex'));
39
- assert.deepStrictEqual(toRaw(decode.signature), f.raw);
40
- assert.strictEqual(decode.hashType, f.hashType);
41
- });
42
- });
43
- fixtures.invalid.forEach(f => {
44
- (0, mocha_1.it)('throws on ' + f.hex, () => {
45
- const buffer = Buffer.from(f.hex, 'hex');
46
- assert.throws(() => {
47
- script_1.signature.decode(buffer);
48
- }, new RegExp(f.exception));
49
- });
50
- });
51
- });
52
- });
@@ -1,269 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const mocha_1 = require("mocha");
5
- const __1 = require("..");
6
- const bscript = require("../src/script");
7
- const fixtures = require("./fixtures/transaction.json");
8
- (0, mocha_1.describe)('Transaction', () => {
9
- function fromRaw(raw, noWitness) {
10
- const tx = new __1.Transaction();
11
- tx.version = raw.version;
12
- tx.locktime = raw.locktime;
13
- raw.ins.forEach((txIn, i) => {
14
- const txHash = Buffer.from(txIn.hash, 'hex');
15
- let scriptSig;
16
- if (txIn.data) {
17
- scriptSig = Buffer.from(txIn.data, 'hex');
18
- }
19
- else if (txIn.script) {
20
- scriptSig = bscript.fromASM(txIn.script);
21
- }
22
- tx.addInput(txHash, txIn.index, txIn.sequence, scriptSig);
23
- if (!noWitness && txIn.witness) {
24
- const witness = txIn.witness.map((x) => {
25
- return Buffer.from(x, 'hex');
26
- });
27
- tx.setWitness(i, witness);
28
- }
29
- });
30
- raw.outs.forEach((txOut) => {
31
- let script;
32
- if (txOut.data) {
33
- script = Buffer.from(txOut.data, 'hex');
34
- }
35
- else if (txOut.script) {
36
- script = bscript.fromASM(txOut.script);
37
- }
38
- tx.addOutput(script, txOut.value);
39
- });
40
- return tx;
41
- }
42
- (0, mocha_1.describe)('fromBuffer/fromHex', () => {
43
- function importExport(f) {
44
- const id = f.id || f.hash;
45
- const txHex = f.hex || f.txHex;
46
- (0, mocha_1.it)('imports ' + f.description + ' (' + id + ')', () => {
47
- const actual = __1.Transaction.fromHex(txHex);
48
- assert.strictEqual(actual.toHex(), txHex);
49
- });
50
- if (f.whex) {
51
- (0, mocha_1.it)('imports ' + f.description + ' (' + id + ') as witness', () => {
52
- const actual = __1.Transaction.fromHex(f.whex);
53
- assert.strictEqual(actual.toHex(), f.whex);
54
- });
55
- }
56
- }
57
- fixtures.valid.forEach(importExport);
58
- fixtures.hashForSignature.forEach(importExport);
59
- fixtures.hashForWitnessV0.forEach(importExport);
60
- fixtures.invalid.fromBuffer.forEach(f => {
61
- (0, mocha_1.it)('throws on ' + f.exception, () => {
62
- assert.throws(() => {
63
- __1.Transaction.fromHex(f.hex);
64
- }, new RegExp(f.exception));
65
- });
66
- });
67
- (0, mocha_1.it)('.version should be interpreted as an int32le', () => {
68
- const txHex = 'ffffffff0000ffffffff';
69
- const tx = __1.Transaction.fromHex(txHex);
70
- assert.strictEqual(-1, tx.version);
71
- assert.strictEqual(0xffffffff, tx.locktime);
72
- });
73
- });
74
- (0, mocha_1.describe)('toBuffer/toHex', () => {
75
- fixtures.valid.forEach(f => {
76
- (0, mocha_1.it)('exports ' + f.description + ' (' + f.id + ')', () => {
77
- const actual = fromRaw(f.raw, true);
78
- assert.strictEqual(actual.toHex(), f.hex);
79
- });
80
- if (f.whex) {
81
- (0, mocha_1.it)('exports ' + f.description + ' (' + f.id + ') as witness', () => {
82
- const wactual = fromRaw(f.raw);
83
- assert.strictEqual(wactual.toHex(), f.whex);
84
- });
85
- }
86
- });
87
- (0, mocha_1.it)('accepts target Buffer and offset parameters', () => {
88
- const f = fixtures.valid[0];
89
- const actual = fromRaw(f.raw);
90
- const byteLength = actual.byteLength();
91
- const target = Buffer.alloc(byteLength * 2);
92
- const a = actual.toBuffer(target, 0);
93
- const b = actual.toBuffer(target, byteLength);
94
- assert.strictEqual(a.length, byteLength);
95
- assert.strictEqual(b.length, byteLength);
96
- assert.strictEqual(a.toString('hex'), f.hex);
97
- assert.strictEqual(b.toString('hex'), f.hex);
98
- assert.deepStrictEqual(a, b);
99
- assert.deepStrictEqual(a, target.slice(0, byteLength));
100
- assert.deepStrictEqual(b, target.slice(byteLength));
101
- });
102
- });
103
- (0, mocha_1.describe)('hasWitnesses', () => {
104
- fixtures.valid.forEach(f => {
105
- (0, mocha_1.it)('detects if the transaction has witnesses: ' +
106
- (f.whex ? 'true' : 'false'), () => {
107
- assert.strictEqual(__1.Transaction.fromHex(f.whex ? f.whex : f.hex).hasWitnesses(), !!f.whex);
108
- });
109
- });
110
- });
111
- (0, mocha_1.describe)('weight/virtualSize', () => {
112
- (0, mocha_1.it)('computes virtual size', () => {
113
- fixtures.valid.forEach(f => {
114
- const transaction = __1.Transaction.fromHex(f.whex ? f.whex : f.hex);
115
- assert.strictEqual(transaction.virtualSize(), f.virtualSize);
116
- });
117
- });
118
- (0, mocha_1.it)('computes weight', () => {
119
- fixtures.valid.forEach(f => {
120
- const transaction = __1.Transaction.fromHex(f.whex ? f.whex : f.hex);
121
- assert.strictEqual(transaction.weight(), f.weight);
122
- });
123
- });
124
- });
125
- (0, mocha_1.describe)('addInput', () => {
126
- let prevTxHash;
127
- (0, mocha_1.beforeEach)(() => {
128
- prevTxHash = Buffer.from('ffffffff00ffff000000000000000000000000000000000000000000101010ff', 'hex');
129
- });
130
- (0, mocha_1.it)('returns an index', () => {
131
- const tx = new __1.Transaction();
132
- assert.strictEqual(tx.addInput(prevTxHash, 0), 0);
133
- assert.strictEqual(tx.addInput(prevTxHash, 0), 1);
134
- });
135
- (0, mocha_1.it)('defaults to empty script, witness and 0xffffffff SEQUENCE number', () => {
136
- const tx = new __1.Transaction();
137
- tx.addInput(prevTxHash, 0);
138
- assert.strictEqual(tx.ins[0].script.length, 0);
139
- assert.strictEqual(tx.ins[0].witness.length, 0);
140
- assert.strictEqual(tx.ins[0].sequence, 0xffffffff);
141
- });
142
- fixtures.invalid.addInput.forEach(f => {
143
- (0, mocha_1.it)('throws on ' + f.exception, () => {
144
- const tx = new __1.Transaction();
145
- const hash = Buffer.from(f.hash, 'hex');
146
- assert.throws(() => {
147
- tx.addInput(hash, f.index);
148
- }, new RegExp(f.exception));
149
- });
150
- });
151
- });
152
- (0, mocha_1.describe)('addOutput', () => {
153
- (0, mocha_1.it)('returns an index', () => {
154
- const tx = new __1.Transaction();
155
- assert.strictEqual(tx.addOutput(Buffer.alloc(0), 0), 0);
156
- assert.strictEqual(tx.addOutput(Buffer.alloc(0), 0), 1);
157
- });
158
- });
159
- (0, mocha_1.describe)('clone', () => {
160
- fixtures.valid.forEach(f => {
161
- let actual;
162
- let expected;
163
- (0, mocha_1.beforeEach)(() => {
164
- expected = __1.Transaction.fromHex(f.hex);
165
- actual = expected.clone();
166
- });
167
- (0, mocha_1.it)('should have value equality', () => {
168
- assert.deepStrictEqual(actual, expected);
169
- });
170
- (0, mocha_1.it)('should not have reference equality', () => {
171
- assert.notStrictEqual(actual, expected);
172
- });
173
- });
174
- });
175
- (0, mocha_1.describe)('getHash/getId', () => {
176
- function verify(f) {
177
- (0, mocha_1.it)('should return the id for ' + f.id + '(' + f.description + ')', () => {
178
- const tx = __1.Transaction.fromHex(f.whex || f.hex);
179
- assert.strictEqual(tx.getHash().toString('hex'), f.hash);
180
- assert.strictEqual(tx.getId(), f.id);
181
- });
182
- }
183
- fixtures.valid.forEach(verify);
184
- });
185
- (0, mocha_1.describe)('isCoinbase', () => {
186
- function verify(f) {
187
- (0, mocha_1.it)('should return ' +
188
- f.coinbase +
189
- ' for ' +
190
- f.id +
191
- '(' +
192
- f.description +
193
- ')', () => {
194
- const tx = __1.Transaction.fromHex(f.hex);
195
- assert.strictEqual(tx.isCoinbase(), f.coinbase);
196
- });
197
- }
198
- fixtures.valid.forEach(verify);
199
- });
200
- (0, mocha_1.describe)('hashForSignature', () => {
201
- (0, mocha_1.it)('does not use Witness serialization', () => {
202
- const randScript = Buffer.from('6a', 'hex');
203
- const tx = new __1.Transaction();
204
- tx.addInput(Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex'), 0);
205
- tx.addOutput(randScript, 5000000000);
206
- const original = tx.__toBuffer;
207
- tx.__toBuffer = function (a, b, c) {
208
- if (c !== false)
209
- throw new Error('hashForSignature MUST pass false');
210
- return original.call(this, a, b, c);
211
- };
212
- assert.throws(() => {
213
- tx.__toBuffer(undefined, undefined, true);
214
- }, /hashForSignature MUST pass false/);
215
- // assert hashForSignature does not pass false
216
- assert.doesNotThrow(() => {
217
- tx.hashForSignature(0, randScript, 1);
218
- });
219
- });
220
- fixtures.hashForSignature.forEach(f => {
221
- (0, mocha_1.it)('should return ' +
222
- f.hash +
223
- ' for ' +
224
- (f.description ? 'case "' + f.description + '"' : f.script), () => {
225
- const tx = __1.Transaction.fromHex(f.txHex);
226
- const script = bscript.fromASM(f.script);
227
- assert.strictEqual(tx
228
- .hashForSignature(f.inIndex, script, f.type)
229
- .toString('hex'), f.hash);
230
- });
231
- });
232
- });
233
- (0, mocha_1.describe)('hashForWitnessV0', () => {
234
- fixtures.hashForWitnessV0.forEach(f => {
235
- (0, mocha_1.it)('should return ' +
236
- f.hash +
237
- ' for ' +
238
- (f.description ? 'case "' + f.description + '"' : ''), () => {
239
- const tx = __1.Transaction.fromHex(f.txHex);
240
- const script = bscript.fromASM(f.script);
241
- assert.strictEqual(tx
242
- .hashForWitnessV0(f.inIndex, script, f.value, f.type)
243
- .toString('hex'), f.hash);
244
- });
245
- });
246
- });
247
- (0, mocha_1.describe)('taprootSigning', () => {
248
- fixtures.taprootSigning.forEach(f => {
249
- const tx = __1.Transaction.fromHex(f.txHex);
250
- const prevOutScripts = f.utxos.map(({ scriptHex }) => Buffer.from(scriptHex, 'hex'));
251
- const values = f.utxos.map(({ value }) => value);
252
- f.cases.forEach(c => {
253
- let hash;
254
- (0, mocha_1.it)(`should hash to ${c.hash} for ${f.description}:${c.vin}`, () => {
255
- const hashType = Buffer.from(c.typeHex, 'hex').readUInt8(0);
256
- hash = tx.hashForWitnessV1(c.vin, prevOutScripts, values, hashType);
257
- assert.strictEqual(hash.toString('hex'), c.hash);
258
- });
259
- });
260
- });
261
- });
262
- (0, mocha_1.describe)('setWitness', () => {
263
- (0, mocha_1.it)('only accepts a witness stack (Array of Buffers)', () => {
264
- assert.throws(() => {
265
- new __1.Transaction().setWitness(0, 'foobar');
266
- }, /Expected property "1" of type \[Buffer], got String "foobar"/);
267
- });
268
- });
269
- });
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const mocha_1 = require("mocha");
5
- const types = require("../src/types");
6
- const typeforce = require('typeforce');
7
- (0, mocha_1.describe)('types', () => {
8
- (0, mocha_1.describe)('Buffer Hash160/Hash256', () => {
9
- const buffer20byte = Buffer.alloc(20);
10
- const buffer32byte = Buffer.alloc(32);
11
- (0, mocha_1.it)('return true for valid size', () => {
12
- assert(types.Hash160bit(buffer20byte));
13
- assert(types.Hash256bit(buffer32byte));
14
- });
15
- (0, mocha_1.it)('return true for oneOf', () => {
16
- assert.doesNotThrow(() => {
17
- typeforce(types.oneOf(types.Hash160bit, types.Hash256bit), buffer32byte);
18
- });
19
- assert.doesNotThrow(() => {
20
- typeforce(types.oneOf(types.Hash256bit, types.Hash160bit), buffer32byte);
21
- });
22
- });
23
- (0, mocha_1.it)('throws for invalid size', () => {
24
- assert.throws(() => {
25
- types.Hash160bit(buffer32byte);
26
- }, /Expected Buffer\(Length: 20\), got Buffer\(Length: 32\)/);
27
- assert.throws(() => {
28
- types.Hash256bit(buffer20byte);
29
- }, /Expected Buffer\(Length: 32\), got Buffer\(Length: 20\)/);
30
- });
31
- });
32
- (0, mocha_1.describe)('Satoshi', () => {
33
- [
34
- { value: -1, result: false },
35
- { value: 0, result: true },
36
- { value: 1, result: true },
37
- { value: 20999999 * 1e8, result: true },
38
- { value: 21000000 * 1e8, result: true },
39
- { value: 21000001 * 1e8, result: false },
40
- ].forEach(f => {
41
- (0, mocha_1.it)('returns ' + f.result + ' for valid for ' + f.value, () => {
42
- assert.strictEqual(types.Satoshi(f.value), f.result);
43
- });
44
- });
45
- });
46
- });