@alexbosworth/blockchain 4.8.0 → 4.9.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/CHANGELOG.md +4 -0
- package/README.md +34 -0
- package/index.js +2 -0
- package/package.json +12 -2
- package/script/conf/networks.json +22 -0
- package/script/index.js +2 -0
- package/script/output_script_for_address.js +96 -0
- package/.gitattributes +0 -1
- package/.tm_properties +0 -1
- package/test/5bit/test_bytes_as_words.js +0 -49
- package/test/5bit/test_words_as_bytes.js +0 -79
- package/test/addresses/test_bech32_type.js +0 -29
- package/test/addresses/test_decode_base58.js +0 -109
- package/test/addresses/test_decode_base58_address.js +0 -94
- package/test/addresses/test_decode_bech32.js +0 -49
- package/test/addresses/test_decode_bech32_address.js +0 -188
- package/test/addresses/test_encode_base58_address.js +0 -127
- package/test/addresses/test_encode_bech32.js +0 -69
- package/test/addresses/test_encode_bech32_address.js +0 -167
- package/test/fixtures/tx_invalid.json +0 -397
- package/test/fixtures/tx_valid.json +0 -528
- package/test/hashes/test_hash_for_p2pkh.js +0 -54
- package/test/hashes/test_hash_for_p2wpkh.js +0 -54
- package/test/hashes/test_id_for_block.js +0 -38
- package/test/hashes/test_no_locktime_id_for_transaction.js +0 -56
- package/test/hashes/test_previous_block_id.js +0 -38
- package/test/numbers/test_compact_int_as_number.js +0 -104
- package/test/numbers/test_encode_push_bytes_count.js +0 -82
- package/test/numbers/test_number_as_compact_int.js +0 -77
- package/test/numbers/test_number_as_little_endian.js +0 -77
- package/test/numbers/test_parse_push_bytes_count.js +0 -67
- package/test/script/test_p2ms_script.js +0 -106
- package/test/script/test_p2pkh_output_script.js +0 -41
- package/test/script/test_p2sh_output_script.js +0 -41
- package/test/script/test_p2tr_output_script.js +0 -43
- package/test/script/test_p2wpkh_output_script.js +0 -41
- package/test/script/test_p2wsh_output_script.js +0 -43
- package/test/script/test_script_as_script_elements.js +0 -84
- package/test/script/test_script_elements_as_script.js +0 -72
- package/test/transactions/test_components_of_transaction.js +0 -352
- package/test/transactions/test_core_tx_vectors.js +0 -70
- package/test/transactions/test_id_for_transaction.js +0 -72
- package/test/transactions/test_non_witness_hash_to_sign.js +0 -404
- package/test/transactions/test_query_transactions.js +0 -87
- package/test/transactions/test_size_of_transaction.js +0 -84
- package/test/transactions/test_transaction_from_components.js +0 -281
- package/test/transactions/test_unsigned_tx_from_psbt.js +0 -89
- package/test/transactions/test_v0_hash_to_sign.js +0 -262
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
-
const {throws} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const {componentsOfTransaction} = require('./../../');
|
|
6
|
-
const {transactionFromComponents} = require('./../../');
|
|
7
|
-
|
|
8
|
-
const tests = [
|
|
9
|
-
{
|
|
10
|
-
args: {},
|
|
11
|
-
description: 'An array of inputs is required',
|
|
12
|
-
error: 'ExpectedArrayOfInputsToFormTransactionFromComponents',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
args: {inputs: [{id: '00'}]},
|
|
16
|
-
description: 'Inputs are required to have spending transaction ids',
|
|
17
|
-
error: 'ExpectedSpendingTransactionIdsToFormTransaction',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
args: {inputs: [null]},
|
|
21
|
-
description: 'Inputs are required to be defined',
|
|
22
|
-
error: 'ExpectedSpendingTransactionIdsToFormTransaction',
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
args: {
|
|
26
|
-
inputs: [{
|
|
27
|
-
id: Buffer.alloc(32).toString('hex'),
|
|
28
|
-
script: 'not hex',
|
|
29
|
-
}],
|
|
30
|
-
},
|
|
31
|
-
description: 'Inputs are required to have hex encoded scripts',
|
|
32
|
-
error: 'ExpectedHexEncodedInputScriptsToFormTransaction',
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
args: {
|
|
36
|
-
inputs: [{id: Buffer.alloc(32).toString('hex'), script: ''}],
|
|
37
|
-
},
|
|
38
|
-
description: 'A locktime is required',
|
|
39
|
-
error: 'ExpectedLocktimeToFormTransactionFromComponents',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
args: {
|
|
43
|
-
inputs: [{id: Buffer.alloc(32).toString('hex'), script: ''}],
|
|
44
|
-
locktime: 0,
|
|
45
|
-
},
|
|
46
|
-
description: 'An array of outputs is required',
|
|
47
|
-
error: 'ExpectedArrayOfOutputsToFormTransactionFromComponents',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
args: {
|
|
51
|
-
inputs: [{id: Buffer.alloc(32).toString('hex'), script: ''}],
|
|
52
|
-
locktime: 0,
|
|
53
|
-
outputs: [{script: 'not hex', tokens: 1}],
|
|
54
|
-
},
|
|
55
|
-
description: 'Outputs are required to have hex encoded scripts',
|
|
56
|
-
error: 'ExpectedHexEncodedOutputScriptsToFormTransaction',
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
args: {
|
|
60
|
-
inputs: [{id: Buffer.alloc(32).toString('hex'), script: ''}],
|
|
61
|
-
locktime: 0,
|
|
62
|
-
outputs: [{tokens: 1}, {script: 'not hex', tokens: 1}],
|
|
63
|
-
},
|
|
64
|
-
description: 'Outputs with absent scripts are checked for hex scripts',
|
|
65
|
-
error: 'ExpectedHexEncodedOutputScriptsToFormTransaction',
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
args: {
|
|
69
|
-
inputs: [{id: Buffer.alloc(32).toString('hex'), script: ''}],
|
|
70
|
-
locktime: 0,
|
|
71
|
-
outputs: [null],
|
|
72
|
-
},
|
|
73
|
-
description: 'Outputs are required to be defined',
|
|
74
|
-
error: 'ExpectedHexEncodedOutputScriptsToFormTransaction',
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
args: {
|
|
78
|
-
inputs: [{id: Buffer.alloc(32).toString('hex'), script: ''}],
|
|
79
|
-
locktime: 0,
|
|
80
|
-
outputs: [],
|
|
81
|
-
},
|
|
82
|
-
description: 'A version number is required',
|
|
83
|
-
error: 'ExpectedVersionNumberToFormTransactionFromComponents',
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
args: {
|
|
87
|
-
inputs: [{
|
|
88
|
-
id: '0000000000000000000000000000000000000000000000000000000000000000',
|
|
89
|
-
script: '',
|
|
90
|
-
sequence: 4294967295,
|
|
91
|
-
vout: 0,
|
|
92
|
-
witness: ['zz'],
|
|
93
|
-
}],
|
|
94
|
-
locktime: 0,
|
|
95
|
-
outputs: [{script: '6a', tokens: 1}],
|
|
96
|
-
version: 1,
|
|
97
|
-
},
|
|
98
|
-
description: 'Hex encoded witness stack elements are expected',
|
|
99
|
-
error: 'ExpectedHexEncodedWitnessElementsToFormTransaction',
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
args: {
|
|
103
|
-
inputs: [{
|
|
104
|
-
id: '0000000000000000000000000000000000000000000000000000000000000000',
|
|
105
|
-
script: '',
|
|
106
|
-
sequence: 4294967295,
|
|
107
|
-
vout: 4294967295,
|
|
108
|
-
witness: [],
|
|
109
|
-
}],
|
|
110
|
-
locktime: 0,
|
|
111
|
-
outputs: [{script: '6a', tokens: 1}],
|
|
112
|
-
version: 1,
|
|
113
|
-
},
|
|
114
|
-
description: 'Empty witness stacks are encoded as a legacy transaction',
|
|
115
|
-
expected: {
|
|
116
|
-
transaction: '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff010100000000000000016a00000000',
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
args: {
|
|
121
|
-
inputs: [{
|
|
122
|
-
id: '0000000000000000000000000000000000000000000000000000000000000000',
|
|
123
|
-
script: '04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73',
|
|
124
|
-
sequence: 4294967295,
|
|
125
|
-
vout: 4294967295,
|
|
126
|
-
}],
|
|
127
|
-
locktime: 0,
|
|
128
|
-
outputs: [{
|
|
129
|
-
script: '4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac',
|
|
130
|
-
tokens: 5000000000,
|
|
131
|
-
}],
|
|
132
|
-
version: 1,
|
|
133
|
-
},
|
|
134
|
-
description: 'A coinbase transaction is formed',
|
|
135
|
-
expected: {
|
|
136
|
-
transaction: '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000',
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
args: {
|
|
141
|
-
inputs: [
|
|
142
|
-
{
|
|
143
|
-
id: '523e6d953a12ce92824c29d542455fa524f577639da29725146188ad3aaf8cae',
|
|
144
|
-
script: '',
|
|
145
|
-
sequence: 4294967295,
|
|
146
|
-
vout: 0,
|
|
147
|
-
witness: [
|
|
148
|
-
'30450221008ac71eff4d7e298941be012fc14f0ac9bf62ae6ffeac13522bb27b5b4108d3aa0220192a69ad6fdb86b1e09c7fdcaaafeb58d25060e44199c734dc0d7d385b5d800d01',
|
|
149
|
-
'029943eaccd3987fa495a6b4f47f2fafeb0521e4e12f39498d9465a564ef753296',
|
|
150
|
-
],
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
id: '572477126b95bd17aacdb94a559ed4024fa198a1759d480cb977a631551cbb9c',
|
|
154
|
-
script: '',
|
|
155
|
-
sequence: 4294967295,
|
|
156
|
-
vout: 2,
|
|
157
|
-
witness: [
|
|
158
|
-
'3045022100f9cde9adb00c0a6c62dae8604ca750039201288c0dafff952461da3caf05e3ae0220679c01f2518413951de3b62531b1cf36bb92562e3bd4197f0fa6e6e3e231272e01',
|
|
159
|
-
'027326b48c9f2729597e328ab6d05f5af75866e1ffa203fadf78387a3b202ff80d',
|
|
160
|
-
],
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
id: '572477126b95bd17aacdb94a559ed4024fa198a1759d480cb977a631551cbb9c',
|
|
164
|
-
script: '',
|
|
165
|
-
sequence: 4294967295,
|
|
166
|
-
vout: 1,
|
|
167
|
-
witness: [
|
|
168
|
-
'304402202550beec478845af2df929abf85708f9fcceaae31377f2e01d803e2acf7b426f022036c312b1e38ca333fe70aa37d3093387ac7486f08438eb8eed323699594468cb01',
|
|
169
|
-
'02275a197f7ccfece19cf0532b068b6e38ceceda146e791875ecbdc55500bb7efe',
|
|
170
|
-
],
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
locktime: 0,
|
|
174
|
-
outputs: [
|
|
175
|
-
{
|
|
176
|
-
script: '0014eaa9b76637b1ad340b6efadf773a73b53637d5b6',
|
|
177
|
-
tokens: 1000000,
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
script: '5120f4c82416bcb08422c195af995e1d248d1378d8b48dafa9f45bc213b83101d492',
|
|
181
|
-
tokens: 4998992350,
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
script: '00148729d17b2aa507ab19051a028384bc6e0ce25e45',
|
|
185
|
-
tokens: 1000000,
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
script: '51200249ccc5af06fa5642f12d42d2a34bfbb08688d54a9b99d07b98619b35df03b4',
|
|
189
|
-
tokens: 8992350,
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
script: '0014d2d59a8a59f997cbc8888411010faf1658e0e346',
|
|
193
|
-
tokens: 1000000,
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
script: '51207febd720c78518b52aa1a2443823cc8f55e373910f616e112d5d7bd622fe1ab2',
|
|
197
|
-
tokens: 8992350,
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
version: 2,
|
|
201
|
-
},
|
|
202
|
-
description: 'A transaction with witnesses is formed',
|
|
203
|
-
expected: {
|
|
204
|
-
transaction: '02000000000103ae8caf3aad8861142597a29d6377f524a55f4542d5294c8292ce123a956d3e520000000000ffffffff9cbb1c5531a677b90c489d75a198a14f02d49e554ab9cdaa17bd956b127724570200000000ffffffff9cbb1c5531a677b90c489d75a198a14f02d49e554ab9cdaa17bd956b127724570100000000ffffffff0640420f0000000000160014eaa9b76637b1ad340b6efadf773a73b53637d5b6de91f62901000000225120f4c82416bcb08422c195af995e1d248d1378d8b48dafa9f45bc213b83101d49240420f00000000001600148729d17b2aa507ab19051a028384bc6e0ce25e455e368900000000002251200249ccc5af06fa5642f12d42d2a34bfbb08688d54a9b99d07b98619b35df03b440420f0000000000160014d2d59a8a59f997cbc8888411010faf1658e0e3465e368900000000002251207febd720c78518b52aa1a2443823cc8f55e373910f616e112d5d7bd622fe1ab2024830450221008ac71eff4d7e298941be012fc14f0ac9bf62ae6ffeac13522bb27b5b4108d3aa0220192a69ad6fdb86b1e09c7fdcaaafeb58d25060e44199c734dc0d7d385b5d800d0121029943eaccd3987fa495a6b4f47f2fafeb0521e4e12f39498d9465a564ef75329602483045022100f9cde9adb00c0a6c62dae8604ca750039201288c0dafff952461da3caf05e3ae0220679c01f2518413951de3b62531b1cf36bb92562e3bd4197f0fa6e6e3e231272e0121027326b48c9f2729597e328ab6d05f5af75866e1ffa203fadf78387a3b202ff80d0247304402202550beec478845af2df929abf85708f9fcceaae31377f2e01d803e2acf7b426f022036c312b1e38ca333fe70aa37d3093387ac7486f08438eb8eed323699594468cb012102275a197f7ccfece19cf0532b068b6e38ceceda146e791875ecbdc55500bb7efe00000000',
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
args: {
|
|
209
|
-
inputs: [
|
|
210
|
-
{
|
|
211
|
-
id: '523e6d953a12ce92824c29d542455fa524f577639da29725146188ad3aaf8cae',
|
|
212
|
-
script: '',
|
|
213
|
-
sequence: 4294967295,
|
|
214
|
-
vout: 0,
|
|
215
|
-
witness: [
|
|
216
|
-
'30450221008ac71eff4d7e298941be012fc14f0ac9bf62ae6ffeac13522bb27b5b4108d3aa0220192a69ad6fdb86b1e09c7fdcaaafeb58d25060e44199c734dc0d7d385b5d800d01',
|
|
217
|
-
'029943eaccd3987fa495a6b4f47f2fafeb0521e4e12f39498d9465a564ef753296',
|
|
218
|
-
],
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
id: 'cbebc4da731e8995fe97f6fadcd731b36ad40e5ecb31e38e904f6e5982fa09f7',
|
|
222
|
-
script: '2103611f9a45c18f28f06f19076ad571c344c82ce8fcfe34464cf8085217a2d294a6ac',
|
|
223
|
-
sequence: 4294967294,
|
|
224
|
-
vout: 1,
|
|
225
|
-
},
|
|
226
|
-
],
|
|
227
|
-
locktime: 0,
|
|
228
|
-
outputs: [{
|
|
229
|
-
script: '0014eaa9b76637b1ad340b6efadf773a73b53637d5b6',
|
|
230
|
-
tokens: 1000000,
|
|
231
|
-
}],
|
|
232
|
-
version: 2,
|
|
233
|
-
},
|
|
234
|
-
description: 'A transaction with mixed witness and non-witness inputs is formed',
|
|
235
|
-
expected: {
|
|
236
|
-
transaction: '02000000000102ae8caf3aad8861142597a29d6377f524a55f4542d5294c8292ce123a956d3e520000000000fffffffff709fa82596e4f908ee331cb5e0ed46ab331d7dcfaf697fe95891e73dac4ebcb01000000232103611f9a45c18f28f06f19076ad571c344c82ce8fcfe34464cf8085217a2d294a6acfeffffff0140420f0000000000160014eaa9b76637b1ad340b6efadf773a73b53637d5b6024830450221008ac71eff4d7e298941be012fc14f0ac9bf62ae6ffeac13522bb27b5b4108d3aa0220192a69ad6fdb86b1e09c7fdcaaafeb58d25060e44199c734dc0d7d385b5d800d0121029943eaccd3987fa495a6b4f47f2fafeb0521e4e12f39498d9465a564ef7532960000000000',
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
args: {
|
|
241
|
-
inputs: [{
|
|
242
|
-
id: 'cbebc4da731e8995fe97f6fadcd731b36ad40e5ecb31e38e904f6e5982fa09f7',
|
|
243
|
-
script: '20ca42095840735e89283fec298e62ac2ddea9b5f34a8cbb7097ad965b87568100201b1b01dc829177da4a14551d2fc96a9db00c6501edfa12f22cd9cefd335c227f483045022100a9df60536df5733dd0de6bc921fab0b3eee6426501b43a228afa2c90072eb5ca02201c78b74266fac7d1db5deff080d8a403743203f109fbcabf6d5a760bf87386d20100',
|
|
244
|
-
sequence: 4294967295,
|
|
245
|
-
vout: 0,
|
|
246
|
-
}],
|
|
247
|
-
locktime: 0,
|
|
248
|
-
outputs: [{
|
|
249
|
-
script: '2103611f9a45c18f28f06f19076ad571c344c82ce8fcfe34464cf8085217a2d294a6ac',
|
|
250
|
-
tokens: 7960000,
|
|
251
|
-
}],
|
|
252
|
-
version: 1,
|
|
253
|
-
},
|
|
254
|
-
description: 'A non-segwit transaction is formed',
|
|
255
|
-
expected: {
|
|
256
|
-
transaction: '0100000001f709fa82596e4f908ee331cb5e0ed46ab331d7dcfaf697fe95891e73dac4ebcb000000008c20ca42095840735e89283fec298e62ac2ddea9b5f34a8cbb7097ad965b87568100201b1b01dc829177da4a14551d2fc96a9db00c6501edfa12f22cd9cefd335c227f483045022100a9df60536df5733dd0de6bc921fab0b3eee6426501b43a228afa2c90072eb5ca02201c78b74266fac7d1db5deff080d8a403743203f109fbcabf6d5a760bf87386d20100ffffffff01c075790000000000232103611f9a45c18f28f06f19076ad571c344c82ce8fcfe34464cf8085217a2d294a6ac00000000',
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
];
|
|
260
|
-
|
|
261
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
262
|
-
return test(description, (t, end) => {
|
|
263
|
-
if (!!error) {
|
|
264
|
-
throws(() => transactionFromComponents(args), new Error(error), 'Err');
|
|
265
|
-
} else {
|
|
266
|
-
const res = transactionFromComponents(args);
|
|
267
|
-
|
|
268
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
269
|
-
|
|
270
|
-
const components = componentsOfTransaction(res);
|
|
271
|
-
|
|
272
|
-
deepStrictEqual(
|
|
273
|
-
transactionFromComponents(components),
|
|
274
|
-
expected,
|
|
275
|
-
'Components round trip back to the transaction'
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return end();
|
|
280
|
-
});
|
|
281
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
-
const {throws} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const {unsignedTxFromPsbt} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
{
|
|
11
|
-
args: {},
|
|
12
|
-
description: 'A psbt is required',
|
|
13
|
-
error: 'ExpectedPsbtToGetUnsignedTransaction',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
args: {psbt: '70736274ff01'},
|
|
17
|
-
description: 'A key type byte is expected after the psbt start bytes',
|
|
18
|
-
error: 'ExpectedUnsignedTransactionKeyTypeInPsbt',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
args: {psbt: '70736274ff0101'},
|
|
22
|
-
description: 'An unsigned transaction global key type is expected',
|
|
23
|
-
error: 'ExpectedUnsignedTransactionKeyTypeInPsbt',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
args: {
|
|
27
|
-
psbt: '70736274ff01003e01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff010100000000000000016a0000000000',
|
|
28
|
-
},
|
|
29
|
-
description: 'The declared unsigned transaction length must match',
|
|
30
|
-
error: 'UnexpectedByteLengthOfPsbtUnsignedTransaction',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
args: {
|
|
34
|
-
psbt: '0200000001268171371edff285e937adeea4b37b78000c0566cbb3ad64641713ca42171bf6000000006a473044022070b2245123e6bf474d60c5b50c043d4c691a5d2435f09a34a7662a9dc251790a022001329ca9dacf280bdf30740ec0390422422c81cb45839457aeb76fc12edd95b3012102657d118d3357b8e0f4c2cd46db7b39f6d9c38d9a70abcb9b2de5dc8dbfe4ce31feffffff02d3dff505000000001976a914d0c59903c5bac2868760e90fd521a4665aa7652088ac00e1f5050000000017a9143545e6e33b832c47050f24d3eeb93c9c03948bc787b32e1300',
|
|
35
|
-
},
|
|
36
|
-
description: 'A valid psbt is required',
|
|
37
|
-
error: 'ExpectedKnownPsbtStartBytesToGetUnsignedTransaction',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
args: {
|
|
41
|
-
psbt: '70736274ff0100fd630102000000030146055816a5ce735defea7c69abb584946fadb54befc4ce55eb039f9ccfdda10000000000ffffffff16d3dad203d4d016ede6ffef29ed24b1bce4ba8efbe4ad8482bacf65d92ed57e0000000000ffffffff01e7e7e51596634dbccb27ee5031276293f2765084b72a889d5bb0aa84425ad80000000000ffffffff06a0860100000000002200203a291e21dee6c814294f159dcf259e9e82ffa3881fd09b22537400b8c5a8d0c8c76a042a01000000160014ca4be4a08bbd2acc8431e920a41f7ccfcd8fc8ada086010000000000220020f21b761d396210ba5cfd796db936bef36432f13d20afe55b57872a090415ce98c76a042a010000001600148b25e25be092a33e4524a9b2da5046fcc6e27e05a086010000000000220020eed63c2f9175915a94ad626ba35dcbf876a72116ea6fbd50b094b08b347e8688c76a042a010000001600147e5b3b51cc3217ac8f384a665285f90a4dd6826a0000000000000100a9020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0401680101ffffffff0200f2052a01000000160014fb9ae43f439741acb5d4f2813b4177adb09a52950000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9012000000000000000000000000000000000000000000000000000000000000000000000000001011f00f2052a01000000160014fb9ae43f439741acb5d4f2813b4177adb09a52952202025008f4d43049ea3ff9e71bca9b96402cc92c1c911adebcf5722d94e5bc84b48f47304402202e7f867ac0647b7c659d8742a0dae894437354106c98413a4b7beea2758e973502205787be7f941ecdda56cc099b297d4f71dfca5e859c6f5709852a1efd9d6995cc01010304010000002206025008f4d43049ea3ff9e71bca9b96402cc92c1c911adebcf5722d94e5bc84b48f180000000054000080000000800000008000000000010000000000000000000000',
|
|
42
|
-
},
|
|
43
|
-
description: 'An unsigned tx with empty inputs is pulled out of the PSBT',
|
|
44
|
-
expected: {
|
|
45
|
-
transaction: hexAsBuffer('02000000030146055816a5ce735defea7c69abb584946fadb54befc4ce55eb039f9ccfdda10000000000ffffffff16d3dad203d4d016ede6ffef29ed24b1bce4ba8efbe4ad8482bacf65d92ed57e0000000000ffffffff01e7e7e51596634dbccb27ee5031276293f2765084b72a889d5bb0aa84425ad80000000000ffffffff06a0860100000000002200203a291e21dee6c814294f159dcf259e9e82ffa3881fd09b22537400b8c5a8d0c8c76a042a01000000160014ca4be4a08bbd2acc8431e920a41f7ccfcd8fc8ada086010000000000220020f21b761d396210ba5cfd796db936bef36432f13d20afe55b57872a090415ce98c76a042a010000001600148b25e25be092a33e4524a9b2da5046fcc6e27e05a086010000000000220020eed63c2f9175915a94ad626ba35dcbf876a72116ea6fbd50b094b08b347e8688c76a042a010000001600147e5b3b51cc3217ac8f384a665285f90a4dd6826a00000000'),
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
args: {
|
|
50
|
-
psbt: '70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000000000000000000',
|
|
51
|
-
},
|
|
52
|
-
description: 'An blank tx is pulled out of the PSBT',
|
|
53
|
-
expected: {
|
|
54
|
-
transaction: hexAsBuffer('020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000'),
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
args: {
|
|
59
|
-
psbt: '70736274ff0100a00200000002ab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be40000000000feffffffab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be40100000000feffffff02603bea0b000000001976a914768a40bbd740cbe81d988e71de2a4d5c71396b1d88ac8e240000000000001976a9146f4620b553fa095e721b9ee0efe9fa039cca459788ac000000000001076a47304402204759661797c01b036b25928948686218347d89864b719e1f7fcf57d1e511658702205309eabf56aa4d8891ffd111fdf1336f3a29da866d7f8486d75546ceedaf93190121035cdc61fc7ba971c0b501a646a2a83b102cb43881217ca682dc86e2d73fa882920001012000e1f5050000000017a9143545e6e33b832c47050f24d3eeb93c9c03948bc787010416001485d13537f2e265405a34dbafa9e3dda01fb82308000000',
|
|
60
|
-
},
|
|
61
|
-
description: 'An tx with varied inputs is pulled out of the PSBT',
|
|
62
|
-
expected: {
|
|
63
|
-
transaction: hexAsBuffer('0200000002ab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be40000000000feffffffab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be40100000000feffffff02603bea0b000000001976a914768a40bbd740cbe81d988e71de2a4d5c71396b1d88ac8e240000000000001976a9146f4620b553fa095e721b9ee0efe9fa039cca459788ac00000000'),
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
args: {
|
|
68
|
-
psbt: '70736274ff0100750200000001268171371edff285e937adeea4b37b78000c0566cbb3ad64641713ca42171bf60000000000feffffff02d3dff505000000001976a914d0c59903c5bac2868760e90fd521a4665aa7652088ac00e1f5050000000017a9143545e6e33b832c47050f24d3eeb93c9c03948bc787b32e1300000100fda5010100000000010289a3c71eab4d20e0371bbba4cc698fa295c9463afa2e397f8533ccb62f9567e50100000017160014be18d152a9b012039daf3da7de4f53349eecb985ffffffff86f8aa43a71dff1448893a530a7237ef6b4608bbb2dd2d0171e63aec6a4890b40100000017160014fe3e9ef1a745e974d902c4355943abcb34bd5353ffffffff0200c2eb0b000000001976a91485cff1097fd9e008bb34af709c62197b38978a4888ac72fef84e2c00000017a914339725ba21efd62ac753a9bcd067d6c7a6a39d05870247304402202712be22e0270f394f568311dc7ca9a68970b8025fdd3b240229f07f8a5f3a240220018b38d7dcd314e734c9276bd6fb40f673325bc4baa144c800d2f2f02db2765c012103d2e15674941bad4a996372cb87e1856d3652606d98562fe39c5e9e7e413f210502483045022100d12b852d85dcd961d2f5f4ab660654df6eedcc794c0c33ce5cc309ffb5fce58d022067338a8e0e1725c197fb1a88af59f51e44e4255b20167c8684031c05d1f2592a01210223b72beef0965d10be0778efecd61fcac6f79a4ea169393380734464f84f2ab300000000000000',
|
|
69
|
-
},
|
|
70
|
-
description: 'A simple transaction is pulled out of the PSBT',
|
|
71
|
-
expected: {
|
|
72
|
-
transaction: hexAsBuffer('0200000001268171371edff285e937adeea4b37b78000c0566cbb3ad64641713ca42171bf60000000000feffffff02d3dff505000000001976a914d0c59903c5bac2868760e90fd521a4665aa7652088ac00e1f5050000000017a9143545e6e33b832c47050f24d3eeb93c9c03948bc787b32e1300'),
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
78
|
-
return test(description, (t, end) => {
|
|
79
|
-
if (!!error) {
|
|
80
|
-
throws(() => unsignedTxFromPsbt(args), new Error(error), 'Got err');
|
|
81
|
-
} else {
|
|
82
|
-
const res = unsignedTxFromPsbt(args);
|
|
83
|
-
|
|
84
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return end();
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
-
const {throws} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const {v0HashToSign} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const nativeP2shP2wshTransaction = '010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000';
|
|
8
|
-
const p2shP2wshWitnessScript = '56210307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba32103b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b21034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a21033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f42103a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac162102d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b56ae';
|
|
9
|
-
|
|
10
|
-
const singleAnyoneCanPayTransaction = '0100000002e9b542c5176808107ff1df906f46bb1f2583b16112b95ee5380665ba7fcfc0010000000000ffffffff80e68831516392fcd100d186b3c2c7b95c80b53c77e77c35ba03a66b429a2a1b0000000000ffffffff0280969800000000001976a914de4b231626ef508c9a74a8517e6783c0546d6b2888ac80969800000000001976a9146648a8cd4531e1ec47f35916de8e259237294d1e88ac00000000';
|
|
11
|
-
|
|
12
|
-
const tests = [
|
|
13
|
-
{
|
|
14
|
-
args: {script: undefined},
|
|
15
|
-
description: 'A script code hex string is required',
|
|
16
|
-
error: 'ExpectedScriptCodeHexStringToCalculateV0HashToSign',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
args: {script: '00', sighash: 0x04},
|
|
20
|
-
description: 'A known signature hash type is required',
|
|
21
|
-
error: 'ExpectedValidSignatureHashTypeToCalculateV0HashToSign',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
args: {script: '00', sighash: 0x01},
|
|
25
|
-
description: 'A spend tokens number is required',
|
|
26
|
-
error: 'ExpectedSpendTokensNumberToCalculateV0HashToSign',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
args: {script: '00', sighash: 0x01, tokens: 1},
|
|
30
|
-
description: 'A transaction hex string is required',
|
|
31
|
-
error: 'ExpectedTransactionHexStringToCalculateV0HashToSign',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
args: {
|
|
35
|
-
script: '00',
|
|
36
|
-
sighash: 0x01,
|
|
37
|
-
tokens: 1,
|
|
38
|
-
transaction: nativeP2shP2wshTransaction,
|
|
39
|
-
},
|
|
40
|
-
description: 'An input index number is required',
|
|
41
|
-
error: 'ExpectedInputIndexNumberToCalculateV0HashToSign',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
args: {
|
|
45
|
-
script: '00',
|
|
46
|
-
sighash: 0x01,
|
|
47
|
-
tokens: 1,
|
|
48
|
-
transaction: nativeP2shP2wshTransaction,
|
|
49
|
-
vin: 1,
|
|
50
|
-
},
|
|
51
|
-
description: 'A matching input is required',
|
|
52
|
-
error: 'ExpectedMatchingInputToCalculateV0HashToSign',
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
args: {
|
|
56
|
-
script: '76a9141d0f172a0ecb48aee1be1f2687d2963ae33f71a188ac',
|
|
57
|
-
sighash: 0x01,
|
|
58
|
-
tokens: 600000000,
|
|
59
|
-
transaction: '0100000002fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f0000000000eeffffffef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a0100000000ffffffff02202cb206000000001976a9148280b37df378db99f66f85c95a783a76ac7a6d5988ac9093510d000000001976a9143bde42dbee7e4dbe6a21b2d50ce2f0167faa815988ac11000000',
|
|
60
|
-
vin: 1,
|
|
61
|
-
},
|
|
62
|
-
description: 'A native P2WPKH input hash to sign is calculated',
|
|
63
|
-
expected: {
|
|
64
|
-
hash: 'c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670',
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
args: {
|
|
69
|
-
script: '76a91479091972186c449eb1ded22b78e40d009bdf008988ac',
|
|
70
|
-
tokens: 1000000000,
|
|
71
|
-
transaction: '0100000001db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a54770100000000feffffff02b8b4eb0b000000001976a914a457b684d7f0d539a46a45bbc043f35b59d0d96388ac0008af2f000000001976a914fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c88ac92040000',
|
|
72
|
-
vin: 0,
|
|
73
|
-
},
|
|
74
|
-
description: 'A P2SH-P2WPKH input hash to sign uses the default sighash',
|
|
75
|
-
expected: {
|
|
76
|
-
hash: '64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6',
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
args: {
|
|
81
|
-
script: '21026dccc749adc2a9d0d89497ac511f760f45c47dc5ed9cf352a58ac706453880aeadab210255a9626aebf5e29c0e6538428ba0d1dcf6ca98ffdf086aa8ced5e0d0215ea465ac',
|
|
82
|
-
sighash: 0x03,
|
|
83
|
-
tokens: 4900000000,
|
|
84
|
-
transaction: '0100000002fe3dc9208094f3ffd12645477b3dc56f60ec4fa8e6f5d67c565d1c6b9216b36e0000000000ffffffff0815cf020f013ed6cf91d29f4202e8a58726b1ac6c79da47c23d1bee0a6925f80000000000ffffffff0100f2052a010000001976a914a30741f8145e5acadf23f751864167f32e0963f788ac00000000',
|
|
85
|
-
vin: 1,
|
|
86
|
-
},
|
|
87
|
-
description: 'A single hash with no matching output commits to a zero hash',
|
|
88
|
-
expected: {
|
|
89
|
-
hash: '82dde6e4f1e94d02c2b7ad03d2115d691f48d064e9d52f58194a6637e4194391',
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
args: {
|
|
94
|
-
script: '76a91479091972186c449eb1ded22b78e40d009bdf008988ac',
|
|
95
|
-
sighash: 0x01,
|
|
96
|
-
tokens: 1000000000,
|
|
97
|
-
transaction: 'ffffffff01db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a54770100000000feffffff02b8b4eb0b000000001976a914a457b684d7f0d539a46a45bbc043f35b59d0d96388ac0008af2f000000001976a914fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c88ac92040000',
|
|
98
|
-
vin: 0,
|
|
99
|
-
},
|
|
100
|
-
description: 'A negative version number is committed to as signed bytes',
|
|
101
|
-
expected: {
|
|
102
|
-
hash: '78ce09cf80ea77a65379cfca01af97312d9d6d03d011f9d53a0db17decb4a22f',
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
args: {
|
|
107
|
-
script: '210255a9626aebf5e29c0e6538428ba0d1dcf6ca98ffdf086aa8ced5e0d0215ea465ac',
|
|
108
|
-
sighash: 0x03,
|
|
109
|
-
tokens: 4900000000,
|
|
110
|
-
transaction: '0100000002fe3dc9208094f3ffd12645477b3dc56f60ec4fa8e6f5d67c565d1c6b9216b36e0000000000ffffffff0815cf020f013ed6cf91d29f4202e8a58726b1ac6c79da47c23d1bee0a6925f80000000000ffffffff0100f2052a010000001976a914a30741f8145e5acadf23f751864167f32e0963f788ac00000000',
|
|
111
|
-
vin: 1,
|
|
112
|
-
},
|
|
113
|
-
description: 'A script code following a code separator is committed to',
|
|
114
|
-
expected: {
|
|
115
|
-
hash: 'fef7bd749cce710c5c052bd796df1af0d935e59cea63736268bcbe2d2134fc47',
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
args: {
|
|
120
|
-
script: '0063ab68210392972e2eb617b2388771abe27235fd5ac44af8e61693261550447a4c3e39da98ac',
|
|
121
|
-
sighash: 0x83,
|
|
122
|
-
tokens: 16777215,
|
|
123
|
-
transaction: singleAnyoneCanPayTransaction,
|
|
124
|
-
vin: 0,
|
|
125
|
-
},
|
|
126
|
-
description: 'A single anyone can pay hash commits to the first input',
|
|
127
|
-
expected: {
|
|
128
|
-
hash: 'e9071e75e25b8a1e298a72f0d2e9f4f95a0f5cdf86a533cda597eb402ed13b3a',
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
args: {
|
|
133
|
-
script: '68210392972e2eb617b2388771abe27235fd5ac44af8e61693261550447a4c3e39da98ac',
|
|
134
|
-
sighash: 0x83,
|
|
135
|
-
tokens: 16777215,
|
|
136
|
-
transaction: singleAnyoneCanPayTransaction,
|
|
137
|
-
vin: 1,
|
|
138
|
-
},
|
|
139
|
-
description: 'A single anyone can pay hash commits to the second input',
|
|
140
|
-
expected: {
|
|
141
|
-
hash: 'cd72f1f1a433ee9df816857fad88d8ebd97e09a75cd481583eb841c330275e54',
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
args: {
|
|
146
|
-
script: 'ad4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e01',
|
|
147
|
-
sighash: 0x01,
|
|
148
|
-
tokens: 200000,
|
|
149
|
-
transaction: '010000000169c12106097dc2e0526493ef67f21269fe888ef05c7a3a5dacab38e1ac8387f14c1d000000ffffffff0101000000000000000000000000',
|
|
150
|
-
vin: 0,
|
|
151
|
-
},
|
|
152
|
-
description: 'A signature in a script code is not found and deleted',
|
|
153
|
-
expected: {
|
|
154
|
-
hash: '71c9cd9b2869b9c70b01b1f0360c148f42dee72297db312638df136f43311f23',
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
args: {
|
|
159
|
-
script: '52af4830450220487fb382c4974de3f7d834c1b617fe15860828c7f96454490edd6d891556dcc9022100baf95feb48f845d5bfc9882eb6aeefa1bc3790e39f59eaa46ff7f15ae626c53e0148304502205286f726690b2e9b0207f0345711e63fa7012045b9eb0f19c2458ce1db90cf43022100e89f17f86abc5b149eba4115d4f128bcf45d77fb3ecdd34f594091340c0395960175',
|
|
160
|
-
sighash: 0x01,
|
|
161
|
-
tokens: 200000,
|
|
162
|
-
transaction: '01000000019275cb8d4a485ce95741c013f7c0d28722160008021bb469a11982d47a6628964c1d000000ffffffff010100000000000000000000000000',
|
|
163
|
-
vin: 0,
|
|
164
|
-
},
|
|
165
|
-
description: 'Signatures in a multisig script code are not deleted',
|
|
166
|
-
expected: {
|
|
167
|
-
hash: 'c1628a1e7c67f14ca0c27c06e4fdeec2e6d1a73c7a91d7c046ff83e835aebb72',
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
args: {
|
|
172
|
-
script: p2shP2wshWitnessScript,
|
|
173
|
-
sighash: 0x01,
|
|
174
|
-
tokens: 987654321,
|
|
175
|
-
transaction: nativeP2shP2wshTransaction,
|
|
176
|
-
vin: 0,
|
|
177
|
-
},
|
|
178
|
-
description: 'A P2SH-P2WSH input hash to sign is calculated for all',
|
|
179
|
-
expected: {
|
|
180
|
-
hash: '185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c',
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
args: {
|
|
185
|
-
script: p2shP2wshWitnessScript,
|
|
186
|
-
sighash: 0x02,
|
|
187
|
-
tokens: 987654321,
|
|
188
|
-
transaction: nativeP2shP2wshTransaction,
|
|
189
|
-
vin: 0,
|
|
190
|
-
},
|
|
191
|
-
description: 'A P2SH-P2WSH input hash to sign is calculated for none',
|
|
192
|
-
expected: {
|
|
193
|
-
hash: 'e9733bc60ea13c95c6527066bb975a2ff29a925e80aa14c213f686cbae5d2f36',
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
args: {
|
|
198
|
-
script: p2shP2wshWitnessScript,
|
|
199
|
-
sighash: 0x03,
|
|
200
|
-
tokens: 987654321,
|
|
201
|
-
transaction: nativeP2shP2wshTransaction,
|
|
202
|
-
vin: 0,
|
|
203
|
-
},
|
|
204
|
-
description: 'A P2SH-P2WSH input hash to sign is calculated for single',
|
|
205
|
-
expected: {
|
|
206
|
-
hash: '1e1f1c303dc025bd664acb72e583e933fae4cff9148bf78c157d1e8f78530aea',
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
args: {
|
|
211
|
-
script: p2shP2wshWitnessScript,
|
|
212
|
-
sighash: 0x81,
|
|
213
|
-
tokens: 987654321,
|
|
214
|
-
transaction: nativeP2shP2wshTransaction,
|
|
215
|
-
vin: 0,
|
|
216
|
-
},
|
|
217
|
-
description: 'A P2SH-P2WSH hash to sign is calculated for all one pays',
|
|
218
|
-
expected: {
|
|
219
|
-
hash: '2a67f03e63a6a422125878b40b82da593be8d4efaafe88ee528af6e5a9955c6e',
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
args: {
|
|
224
|
-
script: p2shP2wshWitnessScript,
|
|
225
|
-
sighash: 0x82,
|
|
226
|
-
tokens: 987654321,
|
|
227
|
-
transaction: nativeP2shP2wshTransaction,
|
|
228
|
-
vin: 0,
|
|
229
|
-
},
|
|
230
|
-
description: 'A P2SH-P2WSH hash to sign is calculated for none one pays',
|
|
231
|
-
expected: {
|
|
232
|
-
hash: '781ba15f3779d5542ce8ecb5c18716733a5ee42a6f51488ec96154934e2c890a',
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
args: {
|
|
237
|
-
script: p2shP2wshWitnessScript,
|
|
238
|
-
sighash: 0x83,
|
|
239
|
-
tokens: 987654321,
|
|
240
|
-
transaction: nativeP2shP2wshTransaction,
|
|
241
|
-
vin: 0,
|
|
242
|
-
},
|
|
243
|
-
description: 'A P2SH-P2WSH hash to sign is calculated for single one pays',
|
|
244
|
-
expected: {
|
|
245
|
-
hash: '511e8e52ed574121fc1b654970395502128263f62662e076dc6baf05c2e6a99b',
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
];
|
|
249
|
-
|
|
250
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
251
|
-
return test(description, (t, end) => {
|
|
252
|
-
if (!!error) {
|
|
253
|
-
throws(() => v0HashToSign(args), new Error(error), 'Got error');
|
|
254
|
-
} else {
|
|
255
|
-
const res = v0HashToSign(args);
|
|
256
|
-
|
|
257
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return end();
|
|
261
|
-
});
|
|
262
|
-
});
|