@btc-vision/bitcoin 6.3.5 → 6.4.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.
Files changed (72) 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/browser/psbt/psbtutils.d.ts +1 -1
  7. package/build/address.d.ts +1 -1
  8. package/build/address.js +12 -5
  9. package/build/block.js +2 -2
  10. package/build/bufferutils.js +5 -5
  11. package/build/networks.d.ts +1 -0
  12. package/build/networks.js +11 -0
  13. package/build/psbt/psbtutils.js +2 -2
  14. package/build/psbt.js +3 -7
  15. package/package.json +26 -26
  16. package/src/address.ts +20 -6
  17. package/src/block.ts +233 -233
  18. package/src/bufferutils.ts +188 -180
  19. package/src/index.ts +86 -86
  20. package/src/networks.ts +12 -0
  21. package/src/psbt/bip371.ts +441 -441
  22. package/src/psbt/psbtutils.ts +4 -3
  23. package/src/psbt.ts +2187 -2187
  24. package/test/address.spec.ts +155 -177
  25. package/test/bitcoin.core.spec.ts +212 -234
  26. package/test/block.spec.ts +171 -194
  27. package/test/bufferutils.spec.ts +450 -513
  28. package/test/crypto.spec.ts +49 -55
  29. package/test/fixtures/address.json +3 -3
  30. package/test/integration/addresses.spec.ts +142 -154
  31. package/test/integration/bip32.spec.ts +130 -151
  32. package/test/integration/blocks.spec.ts +28 -28
  33. package/test/integration/cltv.spec.ts +241 -283
  34. package/test/integration/csv.spec.ts +452 -527
  35. package/test/integration/payments.spec.ts +110 -135
  36. package/test/integration/taproot.spec.ts +663 -707
  37. package/test/integration/transactions.spec.ts +668 -769
  38. package/test/payments.spec.ts +114 -125
  39. package/test/payments.utils.ts +165 -208
  40. package/test/psbt.spec.ts +1285 -1414
  41. package/test/script.spec.ts +186 -210
  42. package/test/script_number.spec.ts +26 -29
  43. package/test/script_signature.spec.ts +66 -66
  44. package/test/transaction.spec.ts +337 -387
  45. package/test/ts-node-register.js +7 -5
  46. package/test/tsconfig.json +4 -1
  47. package/test/types.spec.ts +53 -58
  48. package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  49. package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  50. package/.nyc_output/processinfo/index.json +0 -1
  51. package/test/address.spec.js +0 -124
  52. package/test/bitcoin.core.spec.js +0 -170
  53. package/test/block.spec.js +0 -141
  54. package/test/bufferutils.spec.js +0 -427
  55. package/test/crypto.spec.js +0 -41
  56. package/test/integration/_regtest.js +0 -7
  57. package/test/integration/addresses.spec.js +0 -116
  58. package/test/integration/bip32.spec.js +0 -85
  59. package/test/integration/blocks.spec.js +0 -26
  60. package/test/integration/cltv.spec.js +0 -199
  61. package/test/integration/csv.spec.js +0 -362
  62. package/test/integration/payments.spec.js +0 -98
  63. package/test/integration/taproot.spec.js +0 -532
  64. package/test/integration/transactions.spec.js +0 -561
  65. package/test/payments.spec.js +0 -97
  66. package/test/payments.utils.js +0 -190
  67. package/test/psbt.spec.js +0 -1044
  68. package/test/script.spec.js +0 -151
  69. package/test/script_number.spec.js +0 -24
  70. package/test/script_signature.spec.js +0 -52
  71. package/test/transaction.spec.js +0 -269
  72. package/test/types.spec.js +0 -46
@@ -1 +0,0 @@
1
- {"parent":null,"pid":78344,"argv":["C:\\Program Files\\nodejs\\node.exe","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\node_modules\\mocha\\bin\\mocha.js"],"execArgv":[],"cwd":"C:\\Users\\felix\\Desktop\\moto\\bitcoin","time":1735543317036,"ppid":66896,"coverageFilename":"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\.nyc_output\\6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json","externalId":"","uuid":"6368a5b2-daa5-4821-8ed0-b742d6fc7eab","files":["C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\address.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\networks.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\index.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\embed.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\script.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\bip66.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\ops.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\push_data.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\script_number.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\script_signature.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\types.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\lazy.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2ms.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2pk.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2pkh.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\crypto.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2sh.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2wpkh.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2wsh.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2tr.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\ecc_lib.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\bip341.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\bufferutils.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\index.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\block.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\merkle.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\transaction.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\psbt.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\psbt\\bip371.js","C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\psbt\\psbtutils.js"]}
@@ -1 +0,0 @@
1
- {"processes":{"6368a5b2-daa5-4821-8ed0-b742d6fc7eab":{"parent":null,"children":[]}},"files":{"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\address.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\networks.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\index.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\embed.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\script.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\bip66.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\ops.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\push_data.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\script_number.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\script_signature.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\types.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\lazy.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2ms.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2pk.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2pkh.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\crypto.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2sh.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2wpkh.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2wsh.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\p2tr.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\ecc_lib.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\payments\\bip341.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\bufferutils.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\index.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\block.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\merkle.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\transaction.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\psbt.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\psbt\\bip371.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"],"C:\\Users\\felix\\Desktop\\moto\\bitcoin\\src\\psbt\\psbtutils.js":["6368a5b2-daa5-4821-8ed0-b742d6fc7eab"]},"externalIds":{}}
@@ -1,124 +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 ecc = require("tiny-secp256k1");
6
- const baddress = require("../src/address");
7
- const bscript = require("../src/script");
8
- const fixtures = require("./fixtures/address.json");
9
- const src_1 = require("../src");
10
- const NETWORKS = Object.assign({
11
- litecoin: {
12
- messagePrefix: '\x19Litecoin Signed Message:\n',
13
- bip32: {
14
- public: 0x019da462,
15
- private: 0x019d9cfe,
16
- },
17
- pubKeyHash: 0x30,
18
- scriptHash: 0x32,
19
- wif: 0xb0,
20
- },
21
- }, require('../src/networks'));
22
- (0, mocha_1.describe)('address', () => {
23
- (0, mocha_1.describe)('fromBase58Check', () => {
24
- fixtures.standard.forEach(f => {
25
- if (!f.base58check)
26
- return;
27
- (0, mocha_1.it)('decodes ' + f.base58check, () => {
28
- const decode = baddress.fromBase58Check(f.base58check);
29
- assert.strictEqual(decode.version, f.version);
30
- assert.strictEqual(decode.hash.toString('hex'), f.hash);
31
- });
32
- });
33
- fixtures.invalid.fromBase58Check.forEach(f => {
34
- (0, mocha_1.it)('throws on ' + f.exception, () => {
35
- assert.throws(() => {
36
- baddress.fromBase58Check(f.address);
37
- }, new RegExp(f.address + ' ' + f.exception));
38
- });
39
- });
40
- });
41
- (0, mocha_1.describe)('fromBech32', () => {
42
- fixtures.standard.forEach(f => {
43
- if (!f.bech32)
44
- return;
45
- (0, mocha_1.it)('decodes ' + f.bech32, () => {
46
- const actual = baddress.fromBech32(f.bech32);
47
- assert.strictEqual(actual.version, f.version);
48
- assert.strictEqual(actual.prefix, NETWORKS[f.network].bech32);
49
- assert.strictEqual(actual.data.toString('hex'), f.data);
50
- });
51
- });
52
- fixtures.invalid.bech32.forEach(f => {
53
- (0, mocha_1.it)('decode fails for ' + f.address + '(' + f.exception + ')', () => {
54
- assert.throws(() => {
55
- baddress.fromBech32(f.address);
56
- }, new RegExp(f.exception));
57
- });
58
- });
59
- });
60
- (0, mocha_1.describe)('fromOutputScript', () => {
61
- (0, src_1.initEccLib)(ecc);
62
- fixtures.standard.forEach(f => {
63
- (0, mocha_1.it)('encodes ' + f.script.slice(0, 30) + '... (' + f.network + ')', () => {
64
- const script = bscript.fromASM(f.script);
65
- const address = baddress.fromOutputScript(script, NETWORKS[f.network]);
66
- assert.strictEqual(address, f.base58check || f.bech32.toLowerCase());
67
- });
68
- });
69
- fixtures.invalid.fromOutputScript.forEach(f => {
70
- (0, mocha_1.it)('throws when ' + f.script.slice(0, 30) + '... ' + f.exception, () => {
71
- const script = bscript.fromASM(f.script);
72
- assert.throws(() => {
73
- baddress.fromOutputScript(script, undefined);
74
- }, new RegExp(f.exception));
75
- });
76
- });
77
- });
78
- (0, mocha_1.describe)('toBase58Check', () => {
79
- fixtures.standard.forEach(f => {
80
- if (!f.base58check)
81
- return;
82
- (0, mocha_1.it)('encodes ' + f.hash + ' (' + f.network + ')', () => {
83
- const address = baddress.toBase58Check(Buffer.from(f.hash, 'hex'), f.version);
84
- assert.strictEqual(address, f.base58check);
85
- });
86
- });
87
- });
88
- (0, mocha_1.describe)('toBech32', () => {
89
- fixtures.bech32.forEach(f => {
90
- if (!f.address)
91
- return;
92
- const data = Buffer.from(f.data, 'hex');
93
- (0, mocha_1.it)('encode ' + f.address, () => {
94
- assert.deepStrictEqual(baddress.toBech32(data, f.version, f.prefix), f.address.toLowerCase());
95
- });
96
- });
97
- // TODO: These fixtures (according to TypeScript) have none of the data used below
98
- fixtures.invalid.bech32.forEach((f) => {
99
- if (!f.prefix || f.version === undefined || f.data === undefined)
100
- return;
101
- (0, mocha_1.it)('encode fails (' + f.exception, () => {
102
- assert.throws(() => {
103
- baddress.toBech32(Buffer.from(f.data, 'hex'), f.version, f.prefix);
104
- }, new RegExp(f.exception));
105
- });
106
- });
107
- });
108
- (0, mocha_1.describe)('toOutputScript', () => {
109
- fixtures.standard.forEach(f => {
110
- (0, mocha_1.it)('decodes ' + f.script.slice(0, 30) + '... (' + f.network + ')', () => {
111
- const script = baddress.toOutputScript((f.base58check || f.bech32), NETWORKS[f.network]);
112
- assert.strictEqual(bscript.toASM(script), f.script);
113
- });
114
- });
115
- fixtures.invalid.toOutputScript.forEach(f => {
116
- (0, mocha_1.it)('throws when ' + (f.exception || f.paymentException), () => {
117
- const exception = f.paymentException || `${f.address} ${f.exception}`;
118
- assert.throws(() => {
119
- baddress.toOutputScript(f.address, f.network);
120
- }, new RegExp(exception));
121
- });
122
- });
123
- });
124
- });
@@ -1,170 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const base58 = require("bs58");
5
- const mocha_1 = require("mocha");
6
- const bitcoin = require("..");
7
- const base58EncodeDecode = require("./fixtures/core/base58_encode_decode.json");
8
- const base58KeysInvalid = require("./fixtures/core/base58_keys_invalid.json");
9
- const base58KeysValid = require("./fixtures/core/base58_keys_valid.json");
10
- const blocksValid = require("./fixtures/core/blocks.json");
11
- const sigCanonical = require("./fixtures/core/sig_canonical.json");
12
- const sigNoncanonical = require("./fixtures/core/sig_noncanonical.json");
13
- const sigHash = require("./fixtures/core/sighash.json");
14
- const txValid = require("./fixtures/core/tx_valid.json");
15
- (0, mocha_1.describe)('Bitcoin-core', () => {
16
- // base58EncodeDecode
17
- (0, mocha_1.describe)('base58', () => {
18
- base58EncodeDecode.forEach(f => {
19
- const fhex = f[0];
20
- const fb58 = f[1];
21
- (0, mocha_1.it)('can decode ' + fb58, () => {
22
- const buffer = base58.decode(fb58);
23
- const actual = buffer.toString('hex');
24
- assert.strictEqual(actual, fhex);
25
- });
26
- (0, mocha_1.it)('can encode ' + fhex, () => {
27
- const buffer = Buffer.from(fhex, 'hex');
28
- const actual = base58.encode(buffer);
29
- assert.strictEqual(actual, fb58);
30
- });
31
- });
32
- });
33
- // base58KeysValid
34
- (0, mocha_1.describe)('address.toBase58Check', () => {
35
- const typeMap = {
36
- pubkey: 'pubKeyHash',
37
- script: 'scriptHash',
38
- };
39
- base58KeysValid.forEach(f => {
40
- const expected = f[0];
41
- const hash = Buffer.from(f[1], 'hex');
42
- const params = f[2];
43
- if (params.isPrivkey)
44
- return;
45
- const network = params.isTestnet
46
- ? bitcoin.networks.testnet
47
- : bitcoin.networks.bitcoin;
48
- const version = network[typeMap[params.addrType]];
49
- (0, mocha_1.it)('can export ' + expected, () => {
50
- assert.strictEqual(bitcoin.address.toBase58Check(hash, version), expected);
51
- });
52
- });
53
- });
54
- // base58KeysInvalid
55
- (0, mocha_1.describe)('address.fromBase58Check', () => {
56
- const allowedNetworks = [
57
- bitcoin.networks.bitcoin.pubKeyHash,
58
- bitcoin.networks.bitcoin.scriptHash,
59
- bitcoin.networks.testnet.pubKeyHash,
60
- bitcoin.networks.testnet.scriptHash,
61
- ];
62
- base58KeysInvalid.forEach(f => {
63
- const strng = f[0];
64
- (0, mocha_1.it)('throws on ' + strng, () => {
65
- assert.throws(() => {
66
- const address = bitcoin.address.fromBase58Check(strng);
67
- assert.notStrictEqual(allowedNetworks.indexOf(address.version), -1, 'Invalid network');
68
- }, /(Invalid (checksum|network))|(too (short|long))/);
69
- });
70
- });
71
- });
72
- (0, mocha_1.describe)('Block.fromHex', () => {
73
- blocksValid.forEach(f => {
74
- (0, mocha_1.it)('can parse ' + f.id, () => {
75
- const block = bitcoin.Block.fromHex(f.hex);
76
- assert.strictEqual(block.getId(), f.id);
77
- assert.strictEqual(block.transactions.length, f.transactions);
78
- });
79
- });
80
- });
81
- // txValid
82
- (0, mocha_1.describe)('Transaction.fromHex', () => {
83
- txValid.forEach(f => {
84
- // Objects that are only a single string are ignored
85
- if (f.length === 1)
86
- return;
87
- const inputs = f[0];
88
- const fhex = f[1];
89
- // const verifyFlags = f[2] // TODO: do we need to test this?
90
- (0, mocha_1.it)('can decode ' + fhex, () => {
91
- const transaction = bitcoin.Transaction.fromHex(fhex);
92
- transaction.ins.forEach((txIn, i) => {
93
- const input = inputs[i];
94
- // reverse because test data is reversed
95
- const prevOutHash = Buffer.from(input[0], 'hex').reverse();
96
- const prevOutIndex = input[1];
97
- assert.deepStrictEqual(txIn.hash, prevOutHash);
98
- // we read UInt32, not Int32
99
- assert.strictEqual(txIn.index & 0xffffffff, prevOutIndex);
100
- });
101
- });
102
- });
103
- });
104
- // sighash
105
- (0, mocha_1.describe)('Transaction', () => {
106
- sigHash.forEach(f => {
107
- // Objects that are only a single string are ignored
108
- if (f.length === 1)
109
- return;
110
- const txHex = f[0];
111
- const scriptHex = f[1];
112
- const inIndex = f[2];
113
- const hashType = f[3];
114
- const expectedHash = f[4];
115
- const hashTypes = [];
116
- if ((hashType & 0x1f) === bitcoin.Transaction.SIGHASH_NONE)
117
- hashTypes.push('SIGHASH_NONE');
118
- else if ((hashType & 0x1f) === bitcoin.Transaction.SIGHASH_SINGLE)
119
- hashTypes.push('SIGHASH_SINGLE');
120
- else
121
- hashTypes.push('SIGHASH_ALL');
122
- if (hashType & bitcoin.Transaction.SIGHASH_ANYONECANPAY)
123
- hashTypes.push('SIGHASH_ANYONECANPAY');
124
- const hashTypeName = hashTypes.join(' | ');
125
- (0, mocha_1.it)('should hash ' +
126
- txHex.slice(0, 40) +
127
- '... (' +
128
- hashTypeName +
129
- ')', () => {
130
- const transaction = bitcoin.Transaction.fromHex(txHex);
131
- assert.strictEqual(transaction.toHex(), txHex);
132
- const script = Buffer.from(scriptHex, 'hex');
133
- const scriptChunks = bitcoin.script.decompile(script);
134
- assert.strictEqual(bitcoin.script.compile(scriptChunks).toString('hex'), scriptHex);
135
- const hash = transaction.hashForSignature(inIndex, script, hashType);
136
- // reverse because test data is reversed
137
- assert.strictEqual(hash.reverse().toString('hex'), expectedHash);
138
- assert.doesNotThrow(() => transaction.hashForWitnessV0(inIndex, script, 0,
139
- // convert to UInt32
140
- hashType < 0 ? 0x100000000 + hashType : hashType));
141
- });
142
- });
143
- });
144
- (0, mocha_1.describe)('script.signature.decode', () => {
145
- sigCanonical.forEach(hex => {
146
- const buffer = Buffer.from(hex, 'hex');
147
- (0, mocha_1.it)('can parse ' + hex, () => {
148
- const parsed = bitcoin.script.signature.decode(buffer);
149
- const actual = bitcoin.script.signature.encode(parsed.signature, parsed.hashType);
150
- assert.strictEqual(actual.toString('hex'), hex);
151
- });
152
- });
153
- sigNoncanonical.forEach((hex, i) => {
154
- if (i === 0)
155
- return;
156
- if (i % 2 !== 0)
157
- return;
158
- const description = sigNoncanonical[i - 1].slice(0, -1);
159
- const buffer = Buffer.from(hex, 'hex');
160
- (0, mocha_1.it)('throws on ' + description, () => {
161
- const reg = new RegExp('Expected DER (integer|sequence)|(R|S) value (excessively ' +
162
- 'padded|is negative)|(R|S|DER sequence) length is (zero|too ' +
163
- 'short|too long|invalid)|Invalid hashType');
164
- assert.throws(() => {
165
- bitcoin.script.signature.decode(buffer);
166
- }, reg);
167
- });
168
- });
169
- });
170
- });
@@ -1,141 +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 fixtures = require("./fixtures/block.json");
7
- (0, mocha_1.describe)('Block', () => {
8
- (0, mocha_1.describe)('version', () => {
9
- (0, mocha_1.it)('should be interpreted as an int32le', () => {
10
- const blockHex = 'ffffffff000000000000000000000000000000000000000000000000000000000000' +
11
- '00004141414141414141414141414141414141414141414141414141414141414141' +
12
- '01000000020000000300000000';
13
- const block = __1.Block.fromHex(blockHex);
14
- assert.strictEqual(-1, block.version);
15
- assert.strictEqual(1, block.timestamp);
16
- });
17
- });
18
- (0, mocha_1.describe)('calculateTarget', () => {
19
- fixtures.targets.forEach(f => {
20
- (0, mocha_1.it)('returns ' + f.expected + ' for 0x' + f.bits, () => {
21
- const bits = parseInt(f.bits, 16);
22
- assert.strictEqual(__1.Block.calculateTarget(bits).toString('hex'), f.expected);
23
- });
24
- });
25
- });
26
- (0, mocha_1.describe)('fromBuffer/fromHex', () => {
27
- fixtures.valid.forEach(f => {
28
- (0, mocha_1.it)('imports ' + f.description, () => {
29
- const block = __1.Block.fromHex(f.hex);
30
- assert.strictEqual(block.version, f.version);
31
- assert.strictEqual(block.prevHash.toString('hex'), f.prevHash);
32
- assert.strictEqual(block.merkleRoot.toString('hex'), f.merkleRoot);
33
- if (block.witnessCommit) {
34
- assert.strictEqual(block.witnessCommit.toString('hex'), f.witnessCommit);
35
- }
36
- assert.strictEqual(block.timestamp, f.timestamp);
37
- assert.strictEqual(block.bits, f.bits);
38
- assert.strictEqual(block.nonce, f.nonce);
39
- assert.strictEqual(!block.transactions, f.hex.length === 160);
40
- if (f.size && f.strippedSize && f.weight) {
41
- assert.strictEqual(block.byteLength(false, true), f.size);
42
- assert.strictEqual(block.byteLength(false, false), f.strippedSize);
43
- assert.strictEqual(block.weight(), f.weight);
44
- }
45
- });
46
- });
47
- fixtures.invalid.forEach(f => {
48
- (0, mocha_1.it)('throws on ' + f.exception, () => {
49
- assert.throws(() => {
50
- __1.Block.fromHex(f.hex);
51
- }, new RegExp(f.exception));
52
- });
53
- });
54
- });
55
- (0, mocha_1.describe)('toBuffer/toHex', () => {
56
- fixtures.valid.forEach(f => {
57
- let block;
58
- (0, mocha_1.beforeEach)(() => {
59
- block = __1.Block.fromHex(f.hex);
60
- });
61
- (0, mocha_1.it)('exports ' + f.description, () => {
62
- assert.strictEqual(block.toHex(true), f.hex.slice(0, 160));
63
- assert.strictEqual(block.toHex(), f.hex);
64
- });
65
- });
66
- });
67
- (0, mocha_1.describe)('getHash/getId', () => {
68
- fixtures.valid.forEach(f => {
69
- let block;
70
- (0, mocha_1.beforeEach)(() => {
71
- block = __1.Block.fromHex(f.hex);
72
- });
73
- (0, mocha_1.it)('returns ' + f.id + ' for ' + f.description, () => {
74
- assert.strictEqual(block.getHash().toString('hex'), f.hash);
75
- assert.strictEqual(block.getId(), f.id);
76
- });
77
- });
78
- });
79
- (0, mocha_1.describe)('getUTCDate', () => {
80
- fixtures.valid.forEach(f => {
81
- let block;
82
- (0, mocha_1.beforeEach)(() => {
83
- block = __1.Block.fromHex(f.hex);
84
- });
85
- (0, mocha_1.it)('returns UTC date of ' + f.id, () => {
86
- const utcDate = block.getUTCDate().getTime();
87
- assert.strictEqual(utcDate, f.timestamp * 1e3);
88
- });
89
- });
90
- });
91
- (0, mocha_1.describe)('calculateMerkleRoot', () => {
92
- (0, mocha_1.it)('should throw on zero-length transaction array', () => {
93
- assert.throws(() => {
94
- __1.Block.calculateMerkleRoot([]);
95
- }, /Cannot compute merkle root for zero transactions/);
96
- });
97
- fixtures.valid.forEach(f => {
98
- if (f.hex.length === 160)
99
- return;
100
- let block;
101
- (0, mocha_1.beforeEach)(() => {
102
- block = __1.Block.fromHex(f.hex);
103
- });
104
- (0, mocha_1.it)('returns ' + f.merkleRoot + ' for ' + f.id, () => {
105
- assert.strictEqual(__1.Block.calculateMerkleRoot(block.transactions).toString('hex'), f.merkleRoot);
106
- });
107
- if (f.witnessCommit) {
108
- (0, mocha_1.it)('returns witness commit ' +
109
- f.witnessCommit +
110
- ' for ' +
111
- f.id, () => {
112
- assert.strictEqual(__1.Block.calculateMerkleRoot(block.transactions, true).toString('hex'), f.witnessCommit);
113
- });
114
- }
115
- });
116
- });
117
- (0, mocha_1.describe)('checkTxRoots', () => {
118
- fixtures.valid.forEach(f => {
119
- if (f.hex.length === 160)
120
- return;
121
- let block;
122
- (0, mocha_1.beforeEach)(() => {
123
- block = __1.Block.fromHex(f.hex);
124
- });
125
- (0, mocha_1.it)('returns ' + f.valid + ' for ' + f.id, () => {
126
- assert.strictEqual(block.checkTxRoots(), true);
127
- });
128
- });
129
- });
130
- (0, mocha_1.describe)('checkProofOfWork', () => {
131
- fixtures.valid.forEach(f => {
132
- let block;
133
- (0, mocha_1.beforeEach)(() => {
134
- block = __1.Block.fromHex(f.hex);
135
- });
136
- (0, mocha_1.it)('returns ' + f.valid + ' for ' + f.id, () => {
137
- assert.strictEqual(block.checkProofOfWork(), f.valid);
138
- });
139
- });
140
- });
141
- });