@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,190 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertScriptTree = exports.from = exports.preform = exports.equate = void 0;
4
- const t = require("assert");
5
- const BNETWORKS = require("../src/networks");
6
- const bscript = require("../src/script");
7
- function tryHex(x) {
8
- if (Buffer.isBuffer(x))
9
- return x.toString('hex');
10
- if (Array.isArray(x))
11
- return x.map(tryHex);
12
- return x;
13
- }
14
- function fromHex(x) {
15
- if (typeof x === 'string')
16
- return Buffer.from(x, 'hex');
17
- if (Array.isArray(x))
18
- return x.map(fromHex);
19
- return x;
20
- }
21
- function tryASM(x) {
22
- if (Buffer.isBuffer(x))
23
- return bscript.toASM(x);
24
- return x;
25
- }
26
- function asmToBuffer(x) {
27
- if (x === '')
28
- return Buffer.alloc(0);
29
- return bscript.fromASM(x);
30
- }
31
- function carryOver(a, b) {
32
- for (const k in b) {
33
- if (!k)
34
- continue;
35
- if (k in a && k === 'redeem') {
36
- carryOver(a[k], b[k]);
37
- continue;
38
- }
39
- // don't, the value was specified
40
- if (k in a)
41
- continue;
42
- // otherwise, expect match
43
- a[k] = b[k];
44
- }
45
- }
46
- function equateBase(a, b, context) {
47
- if ('output' in b)
48
- t.strictEqual(tryASM(a.output), tryASM(b.output), `Inequal ${context}output`);
49
- if ('input' in b)
50
- t.strictEqual(tryASM(a.input), tryASM(b.input), `Inequal ${context}input`);
51
- if ('witness' in b)
52
- t.deepStrictEqual(tryHex(a.witness), tryHex(b.witness), `Inequal ${context}witness`);
53
- if ('redeemVersion' in b)
54
- t.strictEqual(a.redeemVersion, b.redeemVersion, `Inequal ${context}redeemVersion`);
55
- }
56
- function equate(a, b, args) {
57
- b = Object.assign({}, b);
58
- carryOver(b, args);
59
- // by null, we mean 'undefined', but JSON
60
- if (b.input === null)
61
- b.input = undefined;
62
- if (b.output === null)
63
- b.output = undefined;
64
- if (b.witness === null)
65
- b.witness = undefined;
66
- if (b.redeemVersion === null)
67
- b.redeemVersion = undefined;
68
- if (b.redeem) {
69
- if (b.redeem.input === null)
70
- b.redeem.input = undefined;
71
- if (b.redeem.output === null)
72
- b.redeem.output = undefined;
73
- if (b.redeem.witness === null)
74
- b.redeem.witness = undefined;
75
- if (b.redeem.redeemVersion === null)
76
- b.redeem.redeemVersion = undefined;
77
- }
78
- equateBase(a, b, '');
79
- if (b.redeem)
80
- equateBase(a.redeem, b.redeem, 'redeem.');
81
- if (b.network)
82
- t.deepStrictEqual(a.network, BNETWORKS[b.network], 'Inequal *.network');
83
- // contextual
84
- if (b.signature === null)
85
- b.signature = undefined;
86
- if (b.signatures === null)
87
- b.signatures = undefined;
88
- if ('address' in b)
89
- t.strictEqual(a.address, b.address, 'Inequal *.address');
90
- if ('name' in b)
91
- t.strictEqual(a.name, b.name, 'Inequal *.name');
92
- if ('hash' in b)
93
- t.strictEqual(tryHex(a.hash), tryHex(b.hash), 'Inequal *.hash');
94
- if ('pubkey' in b)
95
- t.strictEqual(tryHex(a.pubkey), tryHex(b.pubkey), 'Inequal *.pubkey');
96
- if ('internalPubkey' in b)
97
- t.strictEqual(tryHex(a.internalPubkey), tryHex(b.internalPubkey), 'Inequal *.internalPubkey');
98
- if ('signature' in b)
99
- t.strictEqual(tryHex(a.signature), tryHex(b.signature), 'Inequal signature');
100
- if ('m' in b)
101
- t.strictEqual(a.m, b.m, 'Inequal *.m');
102
- if ('n' in b)
103
- t.strictEqual(a.n, b.n, 'Inequal *.n');
104
- if ('pubkeys' in b)
105
- t.deepStrictEqual(tryHex(a.pubkeys), tryHex(b.pubkeys), 'Inequal *.pubkeys');
106
- if ('signatures' in b)
107
- t.deepStrictEqual(tryHex(a.signatures), tryHex(b.signatures), 'Inequal *.signatures');
108
- if ('data' in b)
109
- t.deepStrictEqual(tryHex(a.data), tryHex(b.data), 'Inequal *.data');
110
- }
111
- exports.equate = equate;
112
- function preform(x) {
113
- x = Object.assign({}, x);
114
- if (x.network)
115
- x.network = BNETWORKS[x.network];
116
- if (typeof x.inputHex === 'string') {
117
- x.input = Buffer.from(x.inputHex, 'hex');
118
- delete x.inputHex;
119
- }
120
- if (typeof x.outputHex === 'string') {
121
- x.output = Buffer.from(x.outputHex, 'hex');
122
- delete x.outputHex;
123
- }
124
- if (typeof x.output === 'string')
125
- x.output = asmToBuffer(x.output);
126
- if (typeof x.input === 'string')
127
- x.input = asmToBuffer(x.input);
128
- if (Array.isArray(x.witness))
129
- x.witness = x.witness.map(fromHex);
130
- if (x.data)
131
- x.data = x.data.map(fromHex);
132
- if (x.hash)
133
- x.hash = Buffer.from(x.hash, 'hex');
134
- if (x.pubkey)
135
- x.pubkey = Buffer.from(x.pubkey, 'hex');
136
- if (x.internalPubkey)
137
- x.internalPubkey = Buffer.from(x.internalPubkey, 'hex');
138
- if (x.signature)
139
- x.signature = Buffer.from(x.signature, 'hex');
140
- if (x.pubkeys)
141
- x.pubkeys = x.pubkeys.map(fromHex);
142
- if (x.signatures)
143
- x.signatures = x.signatures.map((y) => {
144
- return Number.isFinite(y) ? y : Buffer.from(y, 'hex');
145
- });
146
- if (x.redeem) {
147
- x.redeem = Object.assign({}, x.redeem);
148
- if (typeof x.redeem.input === 'string')
149
- x.redeem.input = asmToBuffer(x.redeem.input);
150
- if (typeof x.redeem.output === 'string')
151
- x.redeem.output = asmToBuffer(x.redeem.output);
152
- if (Array.isArray(x.redeem.witness))
153
- x.redeem.witness = x.redeem.witness.map(fromHex);
154
- if (x.redeem.network)
155
- x.redeem.network = BNETWORKS[x.redeem.network];
156
- }
157
- if (x.scriptTree)
158
- x.scriptTree = convertScriptTree(x.scriptTree);
159
- return x;
160
- }
161
- exports.preform = preform;
162
- function from(path, object, result) {
163
- const paths = path.split('.');
164
- result = result || {};
165
- let r = result;
166
- paths.forEach((k, i) => {
167
- if (i < paths.length - 1) {
168
- r[k] = r[k] || {};
169
- // recurse
170
- r = r[k];
171
- object = object[k];
172
- }
173
- else {
174
- r[k] = object[k];
175
- }
176
- });
177
- return result;
178
- }
179
- exports.from = from;
180
- function convertScriptTree(scriptTree, leafVersion) {
181
- if (Array.isArray(scriptTree))
182
- return scriptTree.map(tr => convertScriptTree(tr, leafVersion));
183
- const script = Object.assign({}, scriptTree);
184
- if (typeof script.output === 'string') {
185
- script.output = asmToBuffer(scriptTree.output);
186
- script.version = script.version || leafVersion;
187
- }
188
- return script;
189
- }
190
- exports.convertScriptTree = convertScriptTree;