bsv2 2.0.24 → 2.1.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.
- package/dist/bsv2.mjs +36061 -4
- package/package.json +35 -39
- package/.babelrc.test +0 -10
- package/.editorconfig +0 -4
- package/.env.defaults +0 -1
- package/.env.schema +0 -1
- package/.husky/pre-commit +0 -1
- package/.mocharc.yml +0 -4
- package/.nvmrc +0 -1
- package/.travis.yml +0 -7
- package/benchmark.js +0 -50
- package/bin/bsv.js +0 -11
- package/bin/network.js +0 -92
- package/build/index.html +0 -20
- package/dist/bsv2.bundle.js +0 -8
- package/dist/bsv2.cjs.js +0 -2
- package/dist/bsv2.cjs.js.LICENSE.txt +0 -1
- package/dist/bsv2.module.js +0 -2
- package/entry.js +0 -82
- package/index.js +0 -102
- package/karma.conf.js +0 -78
- package/lib/ach.js +0 -59
- package/lib/address.js +0 -264
- package/lib/aes.js +0 -57
- package/lib/aescbc.js +0 -38
- package/lib/base-58-check.js +0 -83
- package/lib/base-58.js +0 -59
- package/lib/bip-32.js +0 -472
- package/lib/bip-39-en-wordlist.js +0 -2054
- package/lib/bip-39-en.js +0 -10
- package/lib/bip-39-es-wordlist.js +0 -2055
- package/lib/bip-39-es.js +0 -10
- package/lib/bip-39-jp-wordlist.js +0 -2053
- package/lib/bip-39-jp.js +0 -10
- package/lib/bip-39-words.js +0 -5
- package/lib/bip-39.js +0 -285
- package/lib/block-header.js +0 -79
- package/lib/block.js +0 -132
- package/lib/bn.js +0 -467
- package/lib/br.js +0 -172
- package/lib/bsm.js +0 -127
- package/lib/bw.js +0 -188
- package/lib/cbc.js +0 -140
- package/lib/cmp.js +0 -37
- package/lib/config.js +0 -50
- package/lib/constants.js +0 -150
- package/lib/ecdsa.js +0 -495
- package/lib/ecies.js +0 -151
- package/lib/hash-cache.js +0 -41
- package/lib/hash.js +0 -191
- package/lib/interp.js +0 -2013
- package/lib/inv.js +0 -49
- package/lib/key-pair.js +0 -133
- package/lib/mainnet-address.js +0 -5
- package/lib/mainnet-bip-32.js +0 -5
- package/lib/mainnet-key-pair.js +0 -5
- package/lib/mainnet-priv-key.js +0 -5
- package/lib/merkle.js +0 -92
- package/lib/msg.js +0 -184
- package/lib/op-code.js +0 -398
- package/lib/point.js +0 -134
- package/lib/priv-key.js +0 -157
- package/lib/pub-key.js +0 -230
- package/lib/random.js +0 -28
- package/lib/script.js +0 -826
- package/lib/sig-operations.js +0 -120
- package/lib/sig.js +0 -399
- package/lib/struct.js +0 -389
- package/lib/testnet-address.js +0 -5
- package/lib/testnet-bip-32.js +0 -5
- package/lib/testnet-key-pair.js +0 -5
- package/lib/testnet-priv-key.js +0 -5
- package/lib/tx-builder.js +0 -593
- package/lib/tx-in.js +0 -172
- package/lib/tx-out-map.js +0 -57
- package/lib/tx-out.js +0 -73
- package/lib/tx-verifier.js +0 -209
- package/lib/tx.js +0 -430
- package/lib/var-int.js +0 -73
- package/lib/version.js +0 -92
- package/lib/workers-result.js +0 -65
- package/lib/workers.js +0 -77
- package/load-babel.js +0 -3
- package/mtest/test.html +0 -15
- package/mtest/test.js +0 -2
- package/mtest/test.mjs +0 -2
- package/test/ach.js +0 -172
- package/test/address.js +0 -464
- package/test/aes.js +0 -96
- package/test/aescbc.js +0 -65
- package/test/base-58-check.js +0 -128
- package/test/base-58.js +0 -113
- package/test/bip-32.js +0 -721
- package/test/bip-39.js +0 -282
- package/test/block-header.js +0 -152
- package/test/block.js +0 -243
- package/test/bn.js +0 -643
- package/test/br.js +0 -353
- package/test/bsm.js +0 -141
- package/test/bw.js +0 -292
- package/test/cbc.js +0 -335
- package/test/cmp.js +0 -56
- package/test/data/bip69.json +0 -215
- package/test/data/bitcoind/base58_keys_invalid.json +0 -152
- package/test/data/bitcoind/base58_keys_valid.json +0 -452
- package/test/data/bitcoind/blocks.json +0 -27
- package/test/data/bitcoind/script_tests.json +0 -2244
- package/test/data/bitcoind/sig_canonical.json +0 -7
- package/test/data/bitcoind/sig_noncanonical.json +0 -22
- package/test/data/bitcoind/tx_invalid.json +0 -177
- package/test/data/bitcoind/tx_valid.json +0 -224
- package/test/data/blk86756-testnet.dat +0 -0
- package/test/data/blk86756-testnet.js +0 -12
- package/test/data/blk86756-testnet.json +0 -684
- package/test/data/ecdsa.json +0 -230
- package/test/data/messages.json +0 -22
- package/test/data/sighash.json +0 -1004
- package/test/data/tx_creation.json +0 -85
- package/test/ecdsa.js +0 -748
- package/test/ecies.js +0 -238
- package/test/global.js +0 -13
- package/test/hash-cache.js +0 -52
- package/test/hash.js +0 -354
- package/test/index.js +0 -10
- package/test/interp.js +0 -512
- package/test/inv.js +0 -65
- package/test/key-pair.js +0 -243
- package/test/merkle.js +0 -179
- package/test/msg.js +0 -295
- package/test/op-code.js +0 -79
- package/test/point.js +0 -375
- package/test/priv-key.js +0 -264
- package/test/pub-key.js +0 -549
- package/test/random.js +0 -31
- package/test/script.js +0 -1340
- package/test/sig-operations.js +0 -149
- package/test/sig.js +0 -662
- package/test/struct.js +0 -552
- package/test/tx-builder.js +0 -2104
- package/test/tx-in.js +0 -198
- package/test/tx-out-map.js +0 -104
- package/test/tx-out.js +0 -162
- package/test/tx-verifier.js +0 -246
- package/test/tx.js +0 -539
- package/test/var-int.js +0 -132
- package/test/vectors/aes.json +0 -10392
- package/test/vectors/aescbc.json +0 -620
- package/test/vectors/bip39.json +0 -502
- package/test/vectors/bip69.json +0 -215
- package/test/vectors/bitcoin-abc/script_tests.json +0 -48
- package/test/vectors/bitcoin-abc/sighash.json +0 -7004
- package/test/vectors/bitcoin-sv/script_tests.json +0 -248
- package/test/vectors/bitcoind/script_invalid.json +0 -1151
- package/test/vectors/bitcoind/script_valid.json +0 -1462
- package/test/vectors/bitcoind/sighash.json +0 -3503
- package/test/vectors/bitcoind/tx_invalid.json +0 -883
- package/test/vectors/bitcoind/tx_valid.json +0 -1150
- package/test/vectors/coolest-tx-ever-sent.json +0 -8
- package/test/vectors/ecdsa.json +0 -300
- package/test/vectors/hash.json +0 -6133
- package/test/vectors/kdf.json +0 -47
- package/test/vectors/largesttx.json +0 -5
- package/test/vectors/largesttxblock.json +0 -6
- package/test/vectors/sig.json +0 -79
- package/test/vectors/sighash-single-bug.json +0 -8
- package/test/version.js +0 -81
- package/test/workers-result.js +0 -89
- package/test/workers.js +0 -91
- package/test-index.js +0 -3
- package/webpack.config.js +0 -115
package/test/script.js
DELETED
|
@@ -1,1340 +0,0 @@
|
|
|
1
|
-
/* global describe,it */
|
|
2
|
-
'use strict'
|
|
3
|
-
import { Bn } from '../lib/bn'
|
|
4
|
-
import { OpCode } from '../lib/op-code'
|
|
5
|
-
import { PrivKey } from '../lib/priv-key'
|
|
6
|
-
import { PubKey } from '../lib/pub-key'
|
|
7
|
-
import { Script } from '../lib/script'
|
|
8
|
-
import should from 'should'
|
|
9
|
-
|
|
10
|
-
import scriptInvalid from './vectors/bitcoind/script_invalid.json'
|
|
11
|
-
import scriptValid from './vectors/bitcoind/script_valid.json'
|
|
12
|
-
|
|
13
|
-
describe('Script', function () {
|
|
14
|
-
it('should make a new script', function () {
|
|
15
|
-
const script = new Script()
|
|
16
|
-
should.exist(script)
|
|
17
|
-
new Script().toString().should.equal('')
|
|
18
|
-
new Script()
|
|
19
|
-
.writeString('')
|
|
20
|
-
.toString()
|
|
21
|
-
.should.equal('')
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
describe('#fromHex', function () {
|
|
25
|
-
it('should parse this hex string containing an OP code', function () {
|
|
26
|
-
const buf = Buffer.alloc(1)
|
|
27
|
-
buf[0] = new OpCode().fromString('OP_0').toNumber()
|
|
28
|
-
const script = new Script().fromHex(buf.toString('hex'))
|
|
29
|
-
script.chunks.length.should.equal(1)
|
|
30
|
-
script.chunks[0].opCodeNum.should.equal(buf[0])
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
describe('#fromBuffer', function () {
|
|
35
|
-
it('should parse this buffer containing an OP code', function () {
|
|
36
|
-
const buf = Buffer.alloc(1)
|
|
37
|
-
buf[0] = new OpCode().fromString('OP_0').toNumber()
|
|
38
|
-
const script = new Script().fromBuffer(buf)
|
|
39
|
-
script.chunks.length.should.equal(1)
|
|
40
|
-
script.chunks[0].opCodeNum.should.equal(buf[0])
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('should parse this buffer containing another OP code', function () {
|
|
44
|
-
const buf = Buffer.alloc(1)
|
|
45
|
-
buf[0] = new OpCode().fromString('OP_CHECKMULTISIG').toNumber()
|
|
46
|
-
const script = new Script().fromBuffer(buf)
|
|
47
|
-
script.chunks.length.should.equal(1)
|
|
48
|
-
script.chunks[0].opCodeNum.should.equal(buf[0])
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('should parse this buffer containing three bytes of data', function () {
|
|
52
|
-
const buf = Buffer.from([3, 1, 2, 3])
|
|
53
|
-
const script = new Script().fromBuffer(buf)
|
|
54
|
-
script.chunks.length.should.equal(1)
|
|
55
|
-
script.chunks[0].buf.toString('hex').should.equal('010203')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('should parse this buffer containing OP_PUSHDATA1 and three bytes of data', function () {
|
|
59
|
-
const buf = Buffer.from([0, 0, 1, 2, 3])
|
|
60
|
-
buf[0] = new OpCode().fromString('OP_PUSHDATA1').toNumber()
|
|
61
|
-
buf.writeUInt8(3, 1)
|
|
62
|
-
const script = new Script().fromBuffer(buf)
|
|
63
|
-
script.chunks.length.should.equal(1)
|
|
64
|
-
script.chunks[0].buf.toString('hex').should.equal('010203')
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('should parse this buffer containing OP_PUSHDATA1 and zero bytes of data', function () {
|
|
68
|
-
const buf = Buffer.from([0])
|
|
69
|
-
buf[0] = new OpCode().fromString('OP_PUSHDATA1').toNumber()
|
|
70
|
-
const script = new Script().fromBuffer(buf)
|
|
71
|
-
script.chunks.length.should.equal(1)
|
|
72
|
-
script.chunks[0].buf.toString('hex').should.equal('')
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should parse this buffer containing OP_PUSHDATA2 and zero bytes of data', function () {
|
|
76
|
-
const buf = Buffer.from([0])
|
|
77
|
-
buf[0] = new OpCode().fromString('OP_PUSHDATA2').toNumber()
|
|
78
|
-
const script = new Script().fromBuffer(buf)
|
|
79
|
-
script.chunks.length.should.equal(1)
|
|
80
|
-
script.chunks[0].buf.toString('hex').should.equal('')
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('should parse this buffer containing OP_PUSHDATA2 and three bytes of data', function () {
|
|
84
|
-
const buf = Buffer.from([0, 0, 0, 1, 2, 3])
|
|
85
|
-
buf[0] = new OpCode().fromString('OP_PUSHDATA2').toNumber()
|
|
86
|
-
buf.writeUInt16LE(3, 1)
|
|
87
|
-
const script = new Script().fromBuffer(buf)
|
|
88
|
-
script.chunks.length.should.equal(1)
|
|
89
|
-
script.chunks[0].buf.toString('hex').should.equal('010203')
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('should parse this buffer containing OP_PUSHDATA4 and zero bytes of data', function () {
|
|
93
|
-
const buf = Buffer.from([0, 0])
|
|
94
|
-
buf[0] = new OpCode().fromString('OP_PUSHDATA4').toNumber()
|
|
95
|
-
const script = new Script().fromBuffer(buf)
|
|
96
|
-
script.chunks.length.should.equal(1)
|
|
97
|
-
script.chunks[0].buf.toString('hex').should.equal('')
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
it('should parse this buffer containing OP_PUSHDATA4 and three bytes of data', function () {
|
|
101
|
-
const buf = Buffer.from([0, 0, 0, 0, 0, 1, 2, 3])
|
|
102
|
-
buf[0] = new OpCode().fromString('OP_PUSHDATA4').toNumber()
|
|
103
|
-
buf.writeUInt16LE(3, 1)
|
|
104
|
-
const script = new Script().fromBuffer(buf)
|
|
105
|
-
script.chunks.length.should.equal(1)
|
|
106
|
-
script.chunks[0].buf.toString('hex').should.equal('010203')
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('should parse this buffer an OP code, data, and another OP code', function () {
|
|
110
|
-
const buf = Buffer.from([0, 0, 0, 0, 0, 0, 1, 2, 3, 0])
|
|
111
|
-
buf[0] = new OpCode().fromString('OP_0').toNumber()
|
|
112
|
-
buf[1] = new OpCode().fromString('OP_PUSHDATA4').toNumber()
|
|
113
|
-
buf.writeUInt16LE(3, 2)
|
|
114
|
-
buf[buf.length - 1] = new OpCode().fromString('OP_0').toNumber()
|
|
115
|
-
const script = new Script().fromBuffer(buf)
|
|
116
|
-
script.chunks.length.should.equal(3)
|
|
117
|
-
script.chunks[0].opCodeNum.should.equal(buf[0])
|
|
118
|
-
script.chunks[1].buf.toString('hex').should.equal('010203')
|
|
119
|
-
script.chunks[2].opCodeNum.should.equal(buf[buf.length - 1])
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
describe('#toBuffer', function () {
|
|
124
|
-
it('should output this hex string containing an OP code', function () {
|
|
125
|
-
const buf = Buffer.alloc(1)
|
|
126
|
-
buf[0] = new OpCode().fromString('OP_0').toNumber()
|
|
127
|
-
const script = new Script().fromHex(buf.toString('hex'))
|
|
128
|
-
script.chunks.length.should.equal(1)
|
|
129
|
-
script.chunks[0].opCodeNum.should.equal(buf[0])
|
|
130
|
-
script.toHex().should.equal(buf.toString('hex'))
|
|
131
|
-
})
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
describe('#toBuffer', function () {
|
|
135
|
-
it('should output this buffer containing an OP code', function () {
|
|
136
|
-
const buf = Buffer.alloc(1)
|
|
137
|
-
buf[0] = new OpCode().fromString('OP_0').toNumber()
|
|
138
|
-
const script = new Script().fromBuffer(buf)
|
|
139
|
-
script.chunks.length.should.equal(1)
|
|
140
|
-
script.chunks[0].opCodeNum.should.equal(buf[0])
|
|
141
|
-
script
|
|
142
|
-
.toBuffer()
|
|
143
|
-
.toString('hex')
|
|
144
|
-
.should.equal(buf.toString('hex'))
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
it('should output this buffer containing another OP code', function () {
|
|
148
|
-
const buf = Buffer.alloc(1)
|
|
149
|
-
buf[0] = new OpCode().fromString('OP_CHECKMULTISIG').toNumber()
|
|
150
|
-
const script = new Script().fromBuffer(buf)
|
|
151
|
-
script.chunks.length.should.equal(1)
|
|
152
|
-
script.chunks[0].opCodeNum.should.equal(buf[0])
|
|
153
|
-
script
|
|
154
|
-
.toBuffer()
|
|
155
|
-
.toString('hex')
|
|
156
|
-
.should.equal(buf.toString('hex'))
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
it('should output this buffer containing three bytes of data', function () {
|
|
160
|
-
const buf = Buffer.from([3, 1, 2, 3])
|
|
161
|
-
const script = new Script().fromBuffer(buf)
|
|
162
|
-
script.chunks.length.should.equal(1)
|
|
163
|
-
script.chunks[0].buf.toString('hex').should.equal('010203')
|
|
164
|
-
script
|
|
165
|
-
.toBuffer()
|
|
166
|
-
.toString('hex')
|
|
167
|
-
.should.equal(buf.toString('hex'))
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('should output this buffer containing OP_PUSHDATA1 and three bytes of data', function () {
|
|
171
|
-
const buf = Buffer.from([0, 0, 1, 2, 3])
|
|
172
|
-
buf[0] = new OpCode().fromString('OP_PUSHDATA1').toNumber()
|
|
173
|
-
buf.writeUInt8(3, 1)
|
|
174
|
-
const script = new Script().fromBuffer(buf)
|
|
175
|
-
script.chunks.length.should.equal(1)
|
|
176
|
-
script.chunks[0].buf.toString('hex').should.equal('010203')
|
|
177
|
-
script
|
|
178
|
-
.toBuffer()
|
|
179
|
-
.toString('hex')
|
|
180
|
-
.should.equal(buf.toString('hex'))
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
it('should output this buffer containing OP_PUSHDATA2 and three bytes of data', function () {
|
|
184
|
-
const buf = Buffer.from([0, 0, 0, 1, 2, 3])
|
|
185
|
-
buf[0] = new OpCode().fromString('OP_PUSHDATA2').toNumber()
|
|
186
|
-
buf.writeUInt16LE(3, 1)
|
|
187
|
-
const script = new Script().fromBuffer(buf)
|
|
188
|
-
script.chunks.length.should.equal(1)
|
|
189
|
-
script.chunks[0].buf.toString('hex').should.equal('010203')
|
|
190
|
-
script
|
|
191
|
-
.toBuffer()
|
|
192
|
-
.toString('hex')
|
|
193
|
-
.should.equal(buf.toString('hex'))
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
it('should output this buffer containing OP_PUSHDATA4 and three bytes of data', function () {
|
|
197
|
-
const buf = Buffer.from([0, 0, 0, 0, 0, 1, 2, 3])
|
|
198
|
-
buf[0] = new OpCode().fromString('OP_PUSHDATA4').toNumber()
|
|
199
|
-
buf.writeUInt16LE(3, 1)
|
|
200
|
-
const script = new Script().fromBuffer(buf)
|
|
201
|
-
script.chunks.length.should.equal(1)
|
|
202
|
-
script.chunks[0].buf.toString('hex').should.equal('010203')
|
|
203
|
-
script
|
|
204
|
-
.toBuffer()
|
|
205
|
-
.toString('hex')
|
|
206
|
-
.should.equal(buf.toString('hex'))
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
it('should output this buffer an OP code, data, and another OP code', function () {
|
|
210
|
-
const buf = Buffer.from([0, 0, 0, 0, 0, 0, 1, 2, 3, 0])
|
|
211
|
-
buf[0] = new OpCode().fromString('OP_0').toNumber()
|
|
212
|
-
buf[1] = new OpCode().fromString('OP_PUSHDATA4').toNumber()
|
|
213
|
-
buf.writeUInt16LE(3, 2)
|
|
214
|
-
buf[buf.length - 1] = new OpCode().fromString('OP_0').toNumber()
|
|
215
|
-
const script = new Script().fromBuffer(buf)
|
|
216
|
-
script.chunks.length.should.equal(3)
|
|
217
|
-
script.chunks[0].opCodeNum.should.equal(buf[0])
|
|
218
|
-
script.chunks[1].buf.toString('hex').should.equal('010203')
|
|
219
|
-
script.chunks[2].opCodeNum.should.equal(buf[buf.length - 1])
|
|
220
|
-
script
|
|
221
|
-
.toBuffer()
|
|
222
|
-
.toString('hex')
|
|
223
|
-
.should.equal(buf.toString('hex'))
|
|
224
|
-
})
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
describe('#fromString', function () {
|
|
228
|
-
it('should parse these known scripts', function () {
|
|
229
|
-
new Script()
|
|
230
|
-
.fromString('OP_0 OP_PUSHDATA4 3 0x010203 OP_0')
|
|
231
|
-
.toString()
|
|
232
|
-
.should.equal('OP_0 OP_PUSHDATA4 3 0x010203 OP_0')
|
|
233
|
-
new Script()
|
|
234
|
-
.fromString('OP_DUP OP_HASH160 20 0x1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIG')
|
|
235
|
-
.toString()
|
|
236
|
-
.should.equal('OP_DUP OP_HASH160 20 0x1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIG')
|
|
237
|
-
new Script()
|
|
238
|
-
.fromString('OP_SHA256 32 0x8cc17e2a2b10e1da145488458a6edec4a1fdb1921c2d5ccbc96aa0ed31b4d5f8 OP_EQUALVERIFY OP_DUP OP_HASH160 20 0x1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIGVERIFY OP_EQUALVERIFY OP_DUP OP_HASH160 20 0x1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIG')
|
|
239
|
-
.toString()
|
|
240
|
-
.should.equal('OP_SHA256 32 0x8cc17e2a2b10e1da145488458a6edec4a1fdb1921c2d5ccbc96aa0ed31b4d5f8 OP_EQUALVERIFY OP_DUP OP_HASH160 20 0x1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIGVERIFY OP_EQUALVERIFY OP_DUP OP_HASH160 20 0x1451baa3aad777144a0759998a03538018dd7b4b OP_EQUALVERIFY OP_CHECKSIG')
|
|
241
|
-
new Script()
|
|
242
|
-
.fromString('OP_0 OP_PUSHDATA2 3 0x010203 OP_0')
|
|
243
|
-
.toString()
|
|
244
|
-
.should.equal('OP_0 OP_PUSHDATA2 3 0x010203 OP_0')
|
|
245
|
-
new Script()
|
|
246
|
-
.fromString('OP_0 OP_PUSHDATA1 3 0x010203 OP_0')
|
|
247
|
-
.toString()
|
|
248
|
-
.should.equal('OP_0 OP_PUSHDATA1 3 0x010203 OP_0')
|
|
249
|
-
new Script()
|
|
250
|
-
.fromString('OP_0 3 0x010203 OP_0')
|
|
251
|
-
.toString()
|
|
252
|
-
.should.equal('OP_0 3 0x010203 OP_0')
|
|
253
|
-
new Script()
|
|
254
|
-
.fromString('')
|
|
255
|
-
.toString()
|
|
256
|
-
.should.equal('')
|
|
257
|
-
new Script()
|
|
258
|
-
.fromString()
|
|
259
|
-
.toString()
|
|
260
|
-
.should.equal('')
|
|
261
|
-
})
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
describe('#toString', function () {
|
|
265
|
-
it('should output this buffer an OP code, data, and another OP code', function () {
|
|
266
|
-
const buf = Buffer.from([0, 0, 0, 0, 0, 0, 1, 2, 3, 0])
|
|
267
|
-
buf[0] = new OpCode().fromString('OP_0').toNumber()
|
|
268
|
-
buf[1] = new OpCode().fromString('OP_PUSHDATA4').toNumber()
|
|
269
|
-
buf.writeUInt16LE(3, 2)
|
|
270
|
-
buf[buf.length - 1] = new OpCode().fromString('OP_0').toNumber()
|
|
271
|
-
const script = new Script().fromBuffer(buf)
|
|
272
|
-
script.chunks.length.should.equal(3)
|
|
273
|
-
script.chunks[0].opCodeNum.should.equal(buf[0])
|
|
274
|
-
script.chunks[1].buf.toString('hex').should.equal('010203')
|
|
275
|
-
script.chunks[2].opCodeNum.should.equal(buf[buf.length - 1])
|
|
276
|
-
script
|
|
277
|
-
.toString()
|
|
278
|
-
.toString('hex')
|
|
279
|
-
.should.equal('OP_0 OP_PUSHDATA4 3 0x010203 OP_0')
|
|
280
|
-
})
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
describe('#fromBitcoindString', function () {
|
|
284
|
-
it('should convert from this known string', function () {
|
|
285
|
-
new Script()
|
|
286
|
-
.fromBitcoindString('DEPTH 0 EQUAL')
|
|
287
|
-
.toBitcoindString()
|
|
288
|
-
.should.equal('DEPTH 0 EQUAL')
|
|
289
|
-
new Script()
|
|
290
|
-
.fromBitcoindString(
|
|
291
|
-
"'Azzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz' EQUAL"
|
|
292
|
-
)
|
|
293
|
-
.toBitcoindString()
|
|
294
|
-
.should.equal(
|
|
295
|
-
'0x4b417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a EQUAL'
|
|
296
|
-
)
|
|
297
|
-
|
|
298
|
-
const str =
|
|
299
|
-
'0x4c47304402203acf75dd59bbef171aeeedae4f1020b824195820db82575c2b323b8899f95de9022067df297d3a5fad049ba0bb81255d0e495643cbcf9abae9e396988618bc0c6dfe01 0x47304402205f8b859230c1cab7d4e8de38ff244d2ebe046b64e8d3f4219b01e483c203490a022071bdc488e31b557f7d9e5c8a8bec90dc92289ca70fa317685f4f140e38b30c4601'
|
|
300
|
-
new Script()
|
|
301
|
-
.fromBitcoindString(str)
|
|
302
|
-
.toBitcoindString()
|
|
303
|
-
.should.equal(str)
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
it('should convert to this known string', function () {
|
|
307
|
-
new Script()
|
|
308
|
-
.fromBitcoindString('DEPTH 0 EQUAL')
|
|
309
|
-
.toBitcoindString()
|
|
310
|
-
.should.equal('DEPTH 0 EQUAL')
|
|
311
|
-
})
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
describe('@fromBitcoindString', function () {
|
|
315
|
-
it('should convert from this known string', function () {
|
|
316
|
-
Script.fromBitcoindString('DEPTH 0 EQUAL')
|
|
317
|
-
.toBitcoindString()
|
|
318
|
-
.should.equal('DEPTH 0 EQUAL')
|
|
319
|
-
Script.fromBitcoindString(
|
|
320
|
-
"'Azzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz' EQUAL"
|
|
321
|
-
)
|
|
322
|
-
.toBitcoindString()
|
|
323
|
-
.should.equal(
|
|
324
|
-
'0x4b417a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a EQUAL'
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
const str =
|
|
328
|
-
'0x4c47304402203acf75dd59bbef171aeeedae4f1020b824195820db82575c2b323b8899f95de9022067df297d3a5fad049ba0bb81255d0e495643cbcf9abae9e396988618bc0c6dfe01 0x47304402205f8b859230c1cab7d4e8de38ff244d2ebe046b64e8d3f4219b01e483c203490a022071bdc488e31b557f7d9e5c8a8bec90dc92289ca70fa317685f4f140e38b30c4601'
|
|
329
|
-
Script.fromBitcoindString(str)
|
|
330
|
-
.toBitcoindString()
|
|
331
|
-
.should.equal(str)
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
it('should convert to this known string', function () {
|
|
335
|
-
Script.fromBitcoindString('DEPTH 0 EQUAL')
|
|
336
|
-
.toBitcoindString()
|
|
337
|
-
.should.equal('DEPTH 0 EQUAL')
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
it('should convert to this known string', function () {
|
|
341
|
-
Script.fromAsmString('OP_DUP OP_HASH160 6fa5502ea094d59576898b490d866b32a61b89f6 OP_EQUALVERIFY OP_CHECKSIG')
|
|
342
|
-
.toAsmString()
|
|
343
|
-
.should.equal('OP_DUP OP_HASH160 6fa5502ea094d59576898b490d866b32a61b89f6 OP_EQUALVERIFY OP_CHECKSIG')
|
|
344
|
-
})
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
describe('@fromAsmString', function () {
|
|
348
|
-
it('should parse this known script in ASM', function () {
|
|
349
|
-
var asm = 'OP_DUP OP_HASH160 f4c03610e60ad15100929cc23da2f3a799af1725 OP_EQUALVERIFY OP_CHECKSIG'
|
|
350
|
-
var script = Script.fromAsmString(asm)
|
|
351
|
-
script.chunks[0].opCodeNum.should.equal(OpCode.OP_DUP)
|
|
352
|
-
script.chunks[1].opCodeNum.should.equal(OpCode.OP_HASH160)
|
|
353
|
-
script.chunks[2].opCodeNum.should.equal(20)
|
|
354
|
-
script.chunks[2].buf.toString('hex').should.equal('f4c03610e60ad15100929cc23da2f3a799af1725')
|
|
355
|
-
script.chunks[3].opCodeNum.should.equal(OpCode.OP_EQUALVERIFY)
|
|
356
|
-
script.chunks[4].opCodeNum.should.equal(OpCode.OP_CHECKSIG)
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
it('should parse this known problematic script in ASM', function () {
|
|
360
|
-
var asm = 'OP_RETURN 026d02 0568656c6c6f'
|
|
361
|
-
var script = Script.fromAsmString(asm)
|
|
362
|
-
script.toAsmString().should.equal(asm)
|
|
363
|
-
})
|
|
364
|
-
|
|
365
|
-
it('should know this is invalid hex', function () {
|
|
366
|
-
var asm = 'OP_RETURN 026d02 0568656c6c6fzz'
|
|
367
|
-
let errors = 0
|
|
368
|
-
try {
|
|
369
|
-
errors++
|
|
370
|
-
var script = Script.fromAsmString(asm)
|
|
371
|
-
script.toAsmString().should.equal(asm)
|
|
372
|
-
} catch (err) {
|
|
373
|
-
err.message.should.equal('invalid hex string in script')
|
|
374
|
-
}
|
|
375
|
-
errors.should.equal(1)
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
it('should parse this long PUSHDATA1 script in ASM', function () {
|
|
379
|
-
var buf = Buffer.alloc(220, 0)
|
|
380
|
-
var asm = 'OP_RETURN ' + buf.toString('hex')
|
|
381
|
-
var script = Script.fromAsmString(asm)
|
|
382
|
-
script.chunks[1].opCodeNum.should.equal(OpCode.OP_PUSHDATA1)
|
|
383
|
-
script.toAsmString().should.equal(asm)
|
|
384
|
-
})
|
|
385
|
-
|
|
386
|
-
it('should parse this long PUSHDATA2 script in ASM', function () {
|
|
387
|
-
var buf = Buffer.alloc(1024, 0)
|
|
388
|
-
var asm = 'OP_RETURN ' + buf.toString('hex')
|
|
389
|
-
var script = Script.fromAsmString(asm)
|
|
390
|
-
script.chunks[1].opCodeNum.should.equal(OpCode.OP_PUSHDATA2)
|
|
391
|
-
script.toAsmString().should.equal(asm)
|
|
392
|
-
})
|
|
393
|
-
|
|
394
|
-
it('should parse this long PUSHDATA4 script in ASM', function () {
|
|
395
|
-
var buf = Buffer.alloc(Math.pow(2, 17), 0)
|
|
396
|
-
var asm = 'OP_RETURN ' + buf.toString('hex')
|
|
397
|
-
var script = Script.fromAsmString(asm)
|
|
398
|
-
script.chunks[1].opCodeNum.should.equal(OpCode.OP_PUSHDATA4)
|
|
399
|
-
script.toAsmString().should.equal(asm)
|
|
400
|
-
})
|
|
401
|
-
|
|
402
|
-
it('should return this script correctly', function () {
|
|
403
|
-
var asm1 = 'OP_FALSE'
|
|
404
|
-
var asm2 = 'OP_0'
|
|
405
|
-
var asm3 = '0'
|
|
406
|
-
Script.fromAsmString(asm1).toAsmString().should.equal(asm3)
|
|
407
|
-
Script.fromAsmString(asm2).toAsmString().should.equal(asm3)
|
|
408
|
-
Script.fromAsmString(asm3).toAsmString().should.equal(asm3)
|
|
409
|
-
})
|
|
410
|
-
|
|
411
|
-
it('should return this script correctly', function () {
|
|
412
|
-
var asm1 = 'OP_1NEGATE'
|
|
413
|
-
var asm2 = '-1'
|
|
414
|
-
Script.fromAsmString(asm1).toAsmString().should.equal(asm2)
|
|
415
|
-
Script.fromAsmString(asm2).toAsmString().should.equal(asm2)
|
|
416
|
-
})
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
describe('#fromJSON', function () {
|
|
420
|
-
it('should parse this known script', function () {
|
|
421
|
-
new Script()
|
|
422
|
-
.fromJSON('OP_0 OP_PUSHDATA4 3 0x010203 OP_0')
|
|
423
|
-
.toString()
|
|
424
|
-
.should.equal('OP_0 OP_PUSHDATA4 3 0x010203 OP_0')
|
|
425
|
-
})
|
|
426
|
-
})
|
|
427
|
-
|
|
428
|
-
describe('#toJSON', function () {
|
|
429
|
-
it('should output this known script', function () {
|
|
430
|
-
new Script()
|
|
431
|
-
.fromString('OP_0 OP_PUSHDATA4 3 0x010203 OP_0')
|
|
432
|
-
.toJSON()
|
|
433
|
-
.should.equal('OP_0 OP_PUSHDATA4 3 0x010203 OP_0')
|
|
434
|
-
})
|
|
435
|
-
})
|
|
436
|
-
|
|
437
|
-
describe('@fromOpReturnData', function () {
|
|
438
|
-
it('should create valid op return output', function () {
|
|
439
|
-
const script = Script.fromOpReturnData(Buffer.from('yours bitcoin'))
|
|
440
|
-
script.isOpReturn().should.equal(true)
|
|
441
|
-
})
|
|
442
|
-
})
|
|
443
|
-
|
|
444
|
-
describe('@fromSafeData', function () {
|
|
445
|
-
it('should create valid op return output', function () {
|
|
446
|
-
const script = Script.fromSafeData(Buffer.from('yours bitcoin'))
|
|
447
|
-
script.isSafeDataOut().should.equal(true)
|
|
448
|
-
})
|
|
449
|
-
|
|
450
|
-
it('should create valid op return output', function () {
|
|
451
|
-
Script.fromSafeDataArray([Buffer.from('ff', 'hex'), Buffer.from('aa', 'hex')]).toAsmString().should.equal('0 OP_RETURN ff aa')
|
|
452
|
-
Script.fromSafeDataArray([Buffer.from('ff', 'hex'), Buffer.from('aa', 'hex')]).toString().should.equal('OP_0 OP_RETURN 1 0xff 1 0xaa')
|
|
453
|
-
})
|
|
454
|
-
})
|
|
455
|
-
|
|
456
|
-
describe('@fromSafeDataArray', function () {
|
|
457
|
-
it('should create valid op return output', function () {
|
|
458
|
-
const script = Script.fromSafeDataArray([Buffer.from('yours bitcoin'), Buffer.from('bsv')])
|
|
459
|
-
script.isSafeDataOut().should.equal(true)
|
|
460
|
-
})
|
|
461
|
-
})
|
|
462
|
-
|
|
463
|
-
describe('#getData', function () {
|
|
464
|
-
it('should create valid op return output', function () {
|
|
465
|
-
const script = Script.fromSafeDataArray([Buffer.from('yours bitcoin'), Buffer.from('bsv')])
|
|
466
|
-
script.isSafeDataOut().should.equal(true)
|
|
467
|
-
const bufs = script.getData()
|
|
468
|
-
bufs[0].toString().should.equal('yours bitcoin')
|
|
469
|
-
bufs[1].toString().should.equal('bsv')
|
|
470
|
-
})
|
|
471
|
-
})
|
|
472
|
-
|
|
473
|
-
describe('#fromPubKeyHash', function () {
|
|
474
|
-
it('should create pubKeyHash output script', function () {
|
|
475
|
-
const hashBuf = Buffer.alloc(20)
|
|
476
|
-
hashBuf.fill(0)
|
|
477
|
-
new Script()
|
|
478
|
-
.fromPubKeyHash(hashBuf)
|
|
479
|
-
.toString()
|
|
480
|
-
.should.equal(
|
|
481
|
-
'OP_DUP OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG'
|
|
482
|
-
)
|
|
483
|
-
})
|
|
484
|
-
})
|
|
485
|
-
|
|
486
|
-
describe('@fromPubKeyHash', function () {
|
|
487
|
-
it('should create pubKeyHash output script', function () {
|
|
488
|
-
const hashBuf = Buffer.alloc(20)
|
|
489
|
-
hashBuf.fill(0)
|
|
490
|
-
Script.fromPubKeyHash(hashBuf)
|
|
491
|
-
.toString()
|
|
492
|
-
.should.equal(
|
|
493
|
-
'OP_DUP OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG'
|
|
494
|
-
)
|
|
495
|
-
})
|
|
496
|
-
})
|
|
497
|
-
|
|
498
|
-
describe('@sortPubKeys', function () {
|
|
499
|
-
it('should sort these pubKeys in a known order', function () {
|
|
500
|
-
const testPubKeysHex = [
|
|
501
|
-
'02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0',
|
|
502
|
-
'02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758',
|
|
503
|
-
'0266dd7664e65958f3cc67bf92ad6243bc495df5ab56691719263977104b635bea',
|
|
504
|
-
'02ee91377073b04d1d9d19597b81a7be3db6554bd7d16151cb5599a6107a589e70',
|
|
505
|
-
'02c8f63ad4822ef360b5c300f08488fa0fa24af2b2bebb6d6b602ca938ee5af793'
|
|
506
|
-
]
|
|
507
|
-
const pubKeys = testPubKeysHex.map(hex => new PubKey().fromHex(hex))
|
|
508
|
-
const pubKeysSorted = Script.sortPubKeys(pubKeys)
|
|
509
|
-
pubKeysSorted[0].toString('hex').should.equal(testPubKeysHex[2])
|
|
510
|
-
pubKeysSorted[1].toString('hex').should.equal(testPubKeysHex[1])
|
|
511
|
-
pubKeysSorted[2].toString('hex').should.equal(testPubKeysHex[0])
|
|
512
|
-
pubKeysSorted[3].toString('hex').should.equal(testPubKeysHex[4])
|
|
513
|
-
pubKeysSorted[4].toString('hex').should.equal(testPubKeysHex[3])
|
|
514
|
-
})
|
|
515
|
-
})
|
|
516
|
-
|
|
517
|
-
describe('#fromPubKeys', function () {
|
|
518
|
-
it('should generate this known script from a list of public keys', function () {
|
|
519
|
-
const privKey = new PrivKey().fromBn(new Bn(5))
|
|
520
|
-
const pubKey = new PubKey().fromPrivKey(privKey)
|
|
521
|
-
const script = new Script().fromPubKeys(2, [pubKey, pubKey, pubKey])
|
|
522
|
-
script
|
|
523
|
-
.toString()
|
|
524
|
-
.should.equal(
|
|
525
|
-
'OP_2 33 0x022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 33 0x022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 33 0x022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 OP_3 OP_CHECKMULTISIG'
|
|
526
|
-
)
|
|
527
|
-
})
|
|
528
|
-
|
|
529
|
-
it('should generate this known script from a list of public keys, sorted', function () {
|
|
530
|
-
const pubKey1 = new PubKey().fromHex(
|
|
531
|
-
'02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0'
|
|
532
|
-
)
|
|
533
|
-
const pubKey2 = new PubKey().fromHex(
|
|
534
|
-
'02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758'
|
|
535
|
-
)
|
|
536
|
-
const script = new Script().fromPubKeys(2, [pubKey1, pubKey2])
|
|
537
|
-
script
|
|
538
|
-
.toString()
|
|
539
|
-
.should.equal(
|
|
540
|
-
'OP_2 33 0x02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758 33 0x02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0 OP_2 OP_CHECKMULTISIG'
|
|
541
|
-
)
|
|
542
|
-
})
|
|
543
|
-
|
|
544
|
-
it('should generate this known script from a list of public keys, sorted explicitly', function () {
|
|
545
|
-
const pubKey1 = new PubKey().fromHex(
|
|
546
|
-
'02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0'
|
|
547
|
-
)
|
|
548
|
-
const pubKey2 = new PubKey().fromHex(
|
|
549
|
-
'02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758'
|
|
550
|
-
)
|
|
551
|
-
const script = new Script().fromPubKeys(2, [pubKey1, pubKey2], true)
|
|
552
|
-
script
|
|
553
|
-
.toString()
|
|
554
|
-
.should.equal(
|
|
555
|
-
'OP_2 33 0x02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758 33 0x02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0 OP_2 OP_CHECKMULTISIG'
|
|
556
|
-
)
|
|
557
|
-
})
|
|
558
|
-
|
|
559
|
-
it('should generate this known script from a list of public keys, unsorted', function () {
|
|
560
|
-
const pubKey1 = new PubKey().fromHex(
|
|
561
|
-
'02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0'
|
|
562
|
-
)
|
|
563
|
-
const pubKey2 = new PubKey().fromHex(
|
|
564
|
-
'02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758'
|
|
565
|
-
)
|
|
566
|
-
const script = new Script().fromPubKeys(2, [pubKey1, pubKey2], false)
|
|
567
|
-
script
|
|
568
|
-
.toString()
|
|
569
|
-
.should.equal(
|
|
570
|
-
'OP_2 33 0x02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0 33 0x02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758 OP_2 OP_CHECKMULTISIG'
|
|
571
|
-
)
|
|
572
|
-
})
|
|
573
|
-
})
|
|
574
|
-
|
|
575
|
-
describe('@fromPubKeys', function () {
|
|
576
|
-
it('should generate this known script from a list of public keys', function () {
|
|
577
|
-
const privKey = PrivKey.fromBn(new Bn(5))
|
|
578
|
-
const pubKey = PubKey.fromPrivKey(privKey)
|
|
579
|
-
const script = Script.fromPubKeys(2, [pubKey, pubKey, pubKey])
|
|
580
|
-
script
|
|
581
|
-
.toString()
|
|
582
|
-
.should.equal(
|
|
583
|
-
'OP_2 33 0x022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 33 0x022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 33 0x022f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4 OP_3 OP_CHECKMULTISIG'
|
|
584
|
-
)
|
|
585
|
-
})
|
|
586
|
-
|
|
587
|
-
it('should generate this known script from a list of public keys, sorted', function () {
|
|
588
|
-
const pubKey1 = PubKey.fromHex(
|
|
589
|
-
'02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0'
|
|
590
|
-
)
|
|
591
|
-
const pubKey2 = PubKey.fromHex(
|
|
592
|
-
'02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758'
|
|
593
|
-
)
|
|
594
|
-
const script = Script.fromPubKeys(2, [pubKey1, pubKey2])
|
|
595
|
-
script
|
|
596
|
-
.toString()
|
|
597
|
-
.should.equal(
|
|
598
|
-
'OP_2 33 0x02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758 33 0x02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0 OP_2 OP_CHECKMULTISIG'
|
|
599
|
-
)
|
|
600
|
-
})
|
|
601
|
-
|
|
602
|
-
it('should generate this known script from a list of public keys, sorted explicitly', function () {
|
|
603
|
-
const pubKey1 = PubKey.fromHex(
|
|
604
|
-
'02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0'
|
|
605
|
-
)
|
|
606
|
-
const pubKey2 = PubKey.fromHex(
|
|
607
|
-
'02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758'
|
|
608
|
-
)
|
|
609
|
-
const script = Script.fromPubKeys(2, [pubKey1, pubKey2], true)
|
|
610
|
-
script
|
|
611
|
-
.toString()
|
|
612
|
-
.should.equal(
|
|
613
|
-
'OP_2 33 0x02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758 33 0x02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0 OP_2 OP_CHECKMULTISIG'
|
|
614
|
-
)
|
|
615
|
-
})
|
|
616
|
-
|
|
617
|
-
it('should generate this known script from a list of public keys, unsorted', function () {
|
|
618
|
-
const pubKey1 = PubKey.fromHex(
|
|
619
|
-
'02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0'
|
|
620
|
-
)
|
|
621
|
-
const pubKey2 = PubKey.fromHex(
|
|
622
|
-
'02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758'
|
|
623
|
-
)
|
|
624
|
-
const script = Script.fromPubKeys(2, [pubKey1, pubKey2], false)
|
|
625
|
-
script
|
|
626
|
-
.toString()
|
|
627
|
-
.should.equal(
|
|
628
|
-
'OP_2 33 0x02c525d65d18be8fb36ab50a21bee02ac9fdc2c176fa18791ac664ea4b95572ae0 33 0x02b937d54b550a3afdc2819772822d25869495f9e588b56a0205617d80514f0758 OP_2 OP_CHECKMULTISIG'
|
|
629
|
-
)
|
|
630
|
-
})
|
|
631
|
-
})
|
|
632
|
-
|
|
633
|
-
describe('#removeCodeseparators', function () {
|
|
634
|
-
it('should remove any OP_CODESEPARATORs', function () {
|
|
635
|
-
new Script()
|
|
636
|
-
.writeString('OP_CODESEPARATOR OP_0 OP_CODESEPARATOR')
|
|
637
|
-
.removeCodeseparators()
|
|
638
|
-
.toString()
|
|
639
|
-
.should.equal('OP_0')
|
|
640
|
-
})
|
|
641
|
-
})
|
|
642
|
-
|
|
643
|
-
describe('#isPushOnly', function () {
|
|
644
|
-
it("should know these scripts are or aren't push only", function () {
|
|
645
|
-
new Script()
|
|
646
|
-
.writeString('OP_0')
|
|
647
|
-
.isPushOnly()
|
|
648
|
-
.should.equal(true)
|
|
649
|
-
new Script()
|
|
650
|
-
.writeString('OP_0 OP_RETURN')
|
|
651
|
-
.isPushOnly()
|
|
652
|
-
.should.equal(false)
|
|
653
|
-
new Script()
|
|
654
|
-
.writeString('OP_PUSHDATA1 5 0x1010101010')
|
|
655
|
-
.isPushOnly()
|
|
656
|
-
.should.equal(true)
|
|
657
|
-
|
|
658
|
-
// like bitcoind, we regard OP_RESERVED as being "push only"
|
|
659
|
-
new Script()
|
|
660
|
-
.writeString('OP_RESERVED')
|
|
661
|
-
.isPushOnly()
|
|
662
|
-
.should.equal(true)
|
|
663
|
-
})
|
|
664
|
-
})
|
|
665
|
-
|
|
666
|
-
describe('#isOpReturn', function () {
|
|
667
|
-
it('should know this is a (blank) OP_RETURN script', function () {
|
|
668
|
-
new Script()
|
|
669
|
-
.writeString('OP_RETURN')
|
|
670
|
-
.isOpReturn()
|
|
671
|
-
.should.equal(true)
|
|
672
|
-
})
|
|
673
|
-
|
|
674
|
-
it('should know this is an OP_RETURN script', function () {
|
|
675
|
-
const buf = Buffer.alloc(40)
|
|
676
|
-
buf.fill(0)
|
|
677
|
-
new Script()
|
|
678
|
-
.writeString('OP_RETURN 40 0x' + buf.toString('hex'))
|
|
679
|
-
.isOpReturn()
|
|
680
|
-
.should.equal(true)
|
|
681
|
-
})
|
|
682
|
-
|
|
683
|
-
it('should know this is not an OP_RETURN script', function () {
|
|
684
|
-
const buf = Buffer.alloc(40)
|
|
685
|
-
buf.fill(0)
|
|
686
|
-
new Script()
|
|
687
|
-
.writeString('OP_CHECKMULTISIG 40 0x' + buf.toString('hex'))
|
|
688
|
-
.isOpReturn()
|
|
689
|
-
.should.equal(false)
|
|
690
|
-
})
|
|
691
|
-
})
|
|
692
|
-
|
|
693
|
-
describe('#isPubKeyHashIn', function () {
|
|
694
|
-
it('should classify this known pubKeyHashin', function () {
|
|
695
|
-
new Script()
|
|
696
|
-
.writeString(
|
|
697
|
-
'73 0x3046022100bb3c194a30e460d81d34be0a230179c043a656f67e3c5c8bf47eceae7c4042ee0221008bf54ca11b2985285be0fd7a212873d243e6e73f5fad57e8eb14c4f39728b8c601 65 0x04e365859b3c78a8b7c202412b949ebca58e147dba297be29eee53cd3e1d300a6419bc780cc9aec0dc94ed194e91c8f6433f1b781ee00eac0ead2aae1e8e0712c6'
|
|
698
|
-
)
|
|
699
|
-
.isPubKeyHashIn()
|
|
700
|
-
.should.equal(true)
|
|
701
|
-
})
|
|
702
|
-
|
|
703
|
-
it('should classify this known non-pubKeyHashin', function () {
|
|
704
|
-
new Script()
|
|
705
|
-
.writeString(
|
|
706
|
-
'73 0x3046022100bb3c194a30e460d81d34be0a230179c043a656f67e3c5c8bf47eceae7c4042ee0221008bf54ca11b2985285be0fd7a212873d243e6e73f5fad57e8eb14c4f39728b8c601 65 0x04e365859b3c78a8b7c202412b949ebca58e147dba297be29eee53cd3e1d300a6419bc780cc9aec0dc94ed194e91c8f6433f1b781ee00eac0ead2aae1e8e0712c6 OP_CHECKSIG'
|
|
707
|
-
)
|
|
708
|
-
.isPubKeyHashIn()
|
|
709
|
-
.should.equal(false)
|
|
710
|
-
})
|
|
711
|
-
})
|
|
712
|
-
|
|
713
|
-
describe('#isPubKeyHashOut', function () {
|
|
714
|
-
it('should classify this known pubKeyHashout as pubKeyHashout', function () {
|
|
715
|
-
new Script()
|
|
716
|
-
.writeString(
|
|
717
|
-
'OP_DUP OP_HASH160 20 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG'
|
|
718
|
-
)
|
|
719
|
-
.isPubKeyHashOut()
|
|
720
|
-
.should.equal(true)
|
|
721
|
-
})
|
|
722
|
-
|
|
723
|
-
it('should classify this known non-pubKeyHashout as not pubKeyHashout', function () {
|
|
724
|
-
new Script()
|
|
725
|
-
.writeString(
|
|
726
|
-
'OP_DUP OP_HASH160 20 0000000000000000000000000000000000000000'
|
|
727
|
-
)
|
|
728
|
-
.isPubKeyHashOut()
|
|
729
|
-
.should.equal(false)
|
|
730
|
-
})
|
|
731
|
-
})
|
|
732
|
-
|
|
733
|
-
describe('#isScriptHashIn', function () {
|
|
734
|
-
it('should classify this known scriptHashin', function () {
|
|
735
|
-
new Script()
|
|
736
|
-
.writeString('20 0000000000000000000000000000000000000000')
|
|
737
|
-
.isScriptHashIn()
|
|
738
|
-
.should.equal(true)
|
|
739
|
-
})
|
|
740
|
-
|
|
741
|
-
it('should classify this known non-scriptHashin', function () {
|
|
742
|
-
new Script()
|
|
743
|
-
.writeString('20 0000000000000000000000000000000000000000 OP_CHECKSIG')
|
|
744
|
-
.isScriptHashIn()
|
|
745
|
-
.should.equal(false)
|
|
746
|
-
})
|
|
747
|
-
})
|
|
748
|
-
|
|
749
|
-
describe('#isScriptHashOut', function () {
|
|
750
|
-
it('should classify this known pubKeyHashout as pubKeyHashout', function () {
|
|
751
|
-
new Script()
|
|
752
|
-
.writeString(
|
|
753
|
-
'OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUAL'
|
|
754
|
-
)
|
|
755
|
-
.isScriptHashOut()
|
|
756
|
-
.should.equal(true)
|
|
757
|
-
})
|
|
758
|
-
|
|
759
|
-
it('should classify these known non-pubKeyHashout as not pubKeyHashout', function () {
|
|
760
|
-
new Script()
|
|
761
|
-
.writeString(
|
|
762
|
-
'OP_HASH160 20 0x0000000000000000000000000000000000000000 OP_EQUAL OP_EQUAL'
|
|
763
|
-
)
|
|
764
|
-
.isScriptHashOut()
|
|
765
|
-
.should.equal(false)
|
|
766
|
-
new Script()
|
|
767
|
-
.writeString(
|
|
768
|
-
'OP_HASH160 21 0x000000000000000000000000000000000000000000 OP_EQUAL'
|
|
769
|
-
)
|
|
770
|
-
.isScriptHashOut()
|
|
771
|
-
.should.equal(false)
|
|
772
|
-
})
|
|
773
|
-
})
|
|
774
|
-
|
|
775
|
-
describe('#isMultiSigIn', function () {
|
|
776
|
-
it('should know this is a valid multisig input', function () {
|
|
777
|
-
new Script()
|
|
778
|
-
.writeString(
|
|
779
|
-
'OP_0 71 0x3044022053cacd1a0720e3497b3e78dedfc3ac144b3ff8fb0e231a4121bf4c18a05e606702205d4c69f2611cbca41c8a392b4c274cb07477bae78efef45c65517e4fdea5c0d801 71 0x3044022017dda0d737a9a65b262a1a8da97e73c23550351d6337ca13a8a1dbdbeae2775d02202fe4c031050d9d4ee0a2b1d5302869e1432577129f842c952462fca92a7b012901'
|
|
780
|
-
)
|
|
781
|
-
.isMultiSigIn()
|
|
782
|
-
.should.equal(true)
|
|
783
|
-
})
|
|
784
|
-
|
|
785
|
-
it('should know this is not a valid multisig input', function () {
|
|
786
|
-
new Script()
|
|
787
|
-
.writeString(
|
|
788
|
-
'OP_1 71 0x3044022053cacd1a0720e3497b3e78dedfc3ac144b3ff8fb0e231a4121bf4c18a05e606702205d4c69f2611cbca41c8a392b4c274cb07477bae78efef45c65517e4fdea5c0d801 71 0x3044022017dda0d737a9a65b262a1a8da97e73c23550351d6337ca13a8a1dbdbeae2775d02202fe4c031050d9d4ee0a2b1d5302869e1432577129f842c952462fca92a7b012901'
|
|
789
|
-
)
|
|
790
|
-
.isMultiSigIn()
|
|
791
|
-
.should.equal(false)
|
|
792
|
-
})
|
|
793
|
-
|
|
794
|
-
it('should know this is not a valid multisig input', function () {
|
|
795
|
-
new Script()
|
|
796
|
-
.writeString('OP_0')
|
|
797
|
-
.isMultiSigIn()
|
|
798
|
-
.should.equal(false)
|
|
799
|
-
})
|
|
800
|
-
})
|
|
801
|
-
|
|
802
|
-
describe('#isMultiSigOut', function () {
|
|
803
|
-
it('should know this is a valid multisig output', function () {
|
|
804
|
-
new Script()
|
|
805
|
-
.writeString(
|
|
806
|
-
'OP_1 33 0x029cf97e1052008852da9d107411b2d47aad387612558fa864b723c484f8931176 33 0x02f23ab919b3a4795c75552b3985982f54c4164a26948b9fe87625705f694e7aa9 OP_2 OP_CHECKMULTISIG'
|
|
807
|
-
)
|
|
808
|
-
.isMultiSigOut()
|
|
809
|
-
.should.equal(true)
|
|
810
|
-
})
|
|
811
|
-
|
|
812
|
-
it('should know this is a valid multisig output', function () {
|
|
813
|
-
new Script()
|
|
814
|
-
.writeString(
|
|
815
|
-
'OP_2 33 0x029cf97e1052008852da9d107411b2d47aad387612558fa864b723c484f8931176 33 0x02f23ab919b3a4795c75552b3985982f54c4164a26948b9fe87625705f694e7aa9 OP_2 OP_CHECKMULTISIG'
|
|
816
|
-
)
|
|
817
|
-
.isMultiSigOut()
|
|
818
|
-
.should.equal(true)
|
|
819
|
-
})
|
|
820
|
-
|
|
821
|
-
it('should know this is not a valid multisig output', function () {
|
|
822
|
-
new Script()
|
|
823
|
-
.writeString(
|
|
824
|
-
'OP_2 33 0x029cf97e1052008852da9d107411b2d47aad387612558fa864b723c484f8931176 33 0x02f23ab919b3a4795c75552b3985982f54c4164a26948b9fe87625705f694e7aa9 OP_1 OP_CHECKMULTISIG'
|
|
825
|
-
)
|
|
826
|
-
.isMultiSigOut()
|
|
827
|
-
.should.equal(false)
|
|
828
|
-
})
|
|
829
|
-
|
|
830
|
-
it('should know this is not a valid multisig output', function () {
|
|
831
|
-
new Script()
|
|
832
|
-
.writeString(
|
|
833
|
-
'OP_2 33 0x029cf97e1052008852da9d107411b2d47aad387612558fa864b723c484f8931176 33 0x02f23ab919b3a4795c75552b3985982f54c4164a26948b9fe87625705f694e7aa9 OP_2 OP_RETURN'
|
|
834
|
-
)
|
|
835
|
-
.isMultiSigOut()
|
|
836
|
-
.should.equal(false)
|
|
837
|
-
})
|
|
838
|
-
|
|
839
|
-
it('should know this is not a valid multisig output', function () {
|
|
840
|
-
new Script()
|
|
841
|
-
.writeString(
|
|
842
|
-
'OP_2 33 0x029cf97e1052008852da9d107411b2d47aad387612558fa864b723c484f8931176 32 0xf23ab919b3a4795c75552b3985982f54c4164a26948b9fe87625705f694e7aa9 OP_2 OP_CHECKMULTISIG'
|
|
843
|
-
)
|
|
844
|
-
.isMultiSigOut()
|
|
845
|
-
.should.equal(false)
|
|
846
|
-
})
|
|
847
|
-
})
|
|
848
|
-
|
|
849
|
-
describe('#findAndDelete', function () {
|
|
850
|
-
it('should find and deconste this buffer', function () {
|
|
851
|
-
new Script()
|
|
852
|
-
.writeString('OP_RETURN 2 0xf0f0')
|
|
853
|
-
.findAndDelete(new Script().writeString('2 0xf0f0'))
|
|
854
|
-
.toString()
|
|
855
|
-
.should.equal('OP_RETURN')
|
|
856
|
-
})
|
|
857
|
-
})
|
|
858
|
-
|
|
859
|
-
describe('#writeScript', function () {
|
|
860
|
-
it('should write these scripts', function () {
|
|
861
|
-
const script1 = new Script().fromString('OP_CHECKMULTISIG')
|
|
862
|
-
const script2 = new Script().fromString('OP_CHECKMULTISIG')
|
|
863
|
-
const script = script1.writeScript(script2)
|
|
864
|
-
script.toString().should.equal('OP_CHECKMULTISIG OP_CHECKMULTISIG')
|
|
865
|
-
})
|
|
866
|
-
})
|
|
867
|
-
|
|
868
|
-
describe('@writeScript', function () {
|
|
869
|
-
it('should write these scripts', function () {
|
|
870
|
-
const script1 = Script.fromString('OP_CHECKMULTISIG')
|
|
871
|
-
const script2 = Script.fromString('OP_CHECKMULTISIG')
|
|
872
|
-
const script = script1.writeScript(script2)
|
|
873
|
-
script.toString().should.equal('OP_CHECKMULTISIG OP_CHECKMULTISIG')
|
|
874
|
-
})
|
|
875
|
-
})
|
|
876
|
-
|
|
877
|
-
describe('#writeOpCode', function () {
|
|
878
|
-
it('should write this op', function () {
|
|
879
|
-
new Script()
|
|
880
|
-
.writeOpCode(OpCode.OP_CHECKMULTISIG)
|
|
881
|
-
.toString()
|
|
882
|
-
.should.equal('OP_CHECKMULTISIG')
|
|
883
|
-
})
|
|
884
|
-
})
|
|
885
|
-
|
|
886
|
-
describe('@writeOpCode', function () {
|
|
887
|
-
it('should write this op', function () {
|
|
888
|
-
Script.writeOpCode(OpCode.OP_CHECKMULTISIG)
|
|
889
|
-
.toString()
|
|
890
|
-
.should.equal('OP_CHECKMULTISIG')
|
|
891
|
-
})
|
|
892
|
-
})
|
|
893
|
-
|
|
894
|
-
describe('#setChunkOpCode', function () {
|
|
895
|
-
it('should set this op', function () {
|
|
896
|
-
const script = new Script().writeOpCode(OpCode.OP_CHECKMULTISIG)
|
|
897
|
-
script.setChunkOpCode(0, OpCode.OP_CHECKSEQUENCEVERIFY)
|
|
898
|
-
script.chunks[0].opCodeNum.should.equal(OpCode.OP_CHECKSEQUENCEVERIFY)
|
|
899
|
-
})
|
|
900
|
-
})
|
|
901
|
-
|
|
902
|
-
describe('#writeBn', function () {
|
|
903
|
-
it('should write these numbers', function () {
|
|
904
|
-
new Script()
|
|
905
|
-
.writeBn(new Bn(0))
|
|
906
|
-
.toBuffer()
|
|
907
|
-
.toString('hex')
|
|
908
|
-
.should.equal('00')
|
|
909
|
-
new Script()
|
|
910
|
-
.writeBn(new Bn(1))
|
|
911
|
-
.toBuffer()
|
|
912
|
-
.toString('hex')
|
|
913
|
-
.should.equal('51')
|
|
914
|
-
new Script()
|
|
915
|
-
.writeBn(new Bn(16))
|
|
916
|
-
.toBuffer()
|
|
917
|
-
.toString('hex')
|
|
918
|
-
.should.equal('60')
|
|
919
|
-
new Script()
|
|
920
|
-
.writeBn(new Bn(-1))
|
|
921
|
-
.toBuffer()
|
|
922
|
-
.toString('hex')
|
|
923
|
-
.should.equal('4f')
|
|
924
|
-
new Script()
|
|
925
|
-
.writeBn(new Bn(-2))
|
|
926
|
-
.toBuffer()
|
|
927
|
-
.toString('hex')
|
|
928
|
-
.should.equal('0182')
|
|
929
|
-
})
|
|
930
|
-
})
|
|
931
|
-
|
|
932
|
-
describe('@writeBn', function () {
|
|
933
|
-
it('should write these numbers', function () {
|
|
934
|
-
Script.writeBn(new Bn(0))
|
|
935
|
-
.toBuffer()
|
|
936
|
-
.toString('hex')
|
|
937
|
-
.should.equal('00')
|
|
938
|
-
Script.writeBn(new Bn(1))
|
|
939
|
-
.toBuffer()
|
|
940
|
-
.toString('hex')
|
|
941
|
-
.should.equal('51')
|
|
942
|
-
Script.writeBn(new Bn(16))
|
|
943
|
-
.toBuffer()
|
|
944
|
-
.toString('hex')
|
|
945
|
-
.should.equal('60')
|
|
946
|
-
Script.writeBn(new Bn(-1))
|
|
947
|
-
.toBuffer()
|
|
948
|
-
.toString('hex')
|
|
949
|
-
.should.equal('4f')
|
|
950
|
-
Script.writeBn(new Bn(-2))
|
|
951
|
-
.toBuffer()
|
|
952
|
-
.toString('hex')
|
|
953
|
-
.should.equal('0182')
|
|
954
|
-
})
|
|
955
|
-
})
|
|
956
|
-
|
|
957
|
-
describe('#writeNumber', function () {
|
|
958
|
-
it('should write these numbers', function () {
|
|
959
|
-
new Script()
|
|
960
|
-
.writeNumber(0)
|
|
961
|
-
.toBuffer()
|
|
962
|
-
.toString('hex')
|
|
963
|
-
.should.equal('00')
|
|
964
|
-
new Script()
|
|
965
|
-
.writeNumber(1)
|
|
966
|
-
.toBuffer()
|
|
967
|
-
.toString('hex')
|
|
968
|
-
.should.equal('51')
|
|
969
|
-
new Script()
|
|
970
|
-
.writeNumber(16)
|
|
971
|
-
.toBuffer()
|
|
972
|
-
.toString('hex')
|
|
973
|
-
.should.equal('60')
|
|
974
|
-
new Script()
|
|
975
|
-
.writeNumber(-1)
|
|
976
|
-
.toBuffer()
|
|
977
|
-
.toString('hex')
|
|
978
|
-
.should.equal('4f')
|
|
979
|
-
new Script()
|
|
980
|
-
.writeNumber(-2)
|
|
981
|
-
.toBuffer()
|
|
982
|
-
.toString('hex')
|
|
983
|
-
.should.equal('0182')
|
|
984
|
-
})
|
|
985
|
-
})
|
|
986
|
-
|
|
987
|
-
describe('@writeNumber', function () {
|
|
988
|
-
it('should write these numbers', function () {
|
|
989
|
-
Script.writeNumber(0)
|
|
990
|
-
.toBuffer()
|
|
991
|
-
.toString('hex')
|
|
992
|
-
.should.equal('00')
|
|
993
|
-
Script.writeNumber(1)
|
|
994
|
-
.toBuffer()
|
|
995
|
-
.toString('hex')
|
|
996
|
-
.should.equal('51')
|
|
997
|
-
Script.writeNumber(16)
|
|
998
|
-
.toBuffer()
|
|
999
|
-
.toString('hex')
|
|
1000
|
-
.should.equal('60')
|
|
1001
|
-
Script.writeNumber(-1)
|
|
1002
|
-
.toBuffer()
|
|
1003
|
-
.toString('hex')
|
|
1004
|
-
.should.equal('4f')
|
|
1005
|
-
Script.writeNumber(-2)
|
|
1006
|
-
.toBuffer()
|
|
1007
|
-
.toString('hex')
|
|
1008
|
-
.should.equal('0182')
|
|
1009
|
-
})
|
|
1010
|
-
})
|
|
1011
|
-
|
|
1012
|
-
describe('#setChunkBn', function () {
|
|
1013
|
-
it('should set this bn', function () {
|
|
1014
|
-
const script = new Script().writeOpCode(OpCode.OP_CHECKMULTISIG)
|
|
1015
|
-
script.setChunkBn(0, new Bn(5000000000000000))
|
|
1016
|
-
script.chunks[0].buf
|
|
1017
|
-
.toString('hex')
|
|
1018
|
-
.should.equal(
|
|
1019
|
-
new Bn(5000000000000000)
|
|
1020
|
-
.toBuffer({ endian: 'little' })
|
|
1021
|
-
.toString('hex')
|
|
1022
|
-
)
|
|
1023
|
-
})
|
|
1024
|
-
})
|
|
1025
|
-
|
|
1026
|
-
describe('#writeBuffer', function () {
|
|
1027
|
-
it('should write these push data', function () {
|
|
1028
|
-
let buf = Buffer.alloc(1)
|
|
1029
|
-
buf.fill(0)
|
|
1030
|
-
new Script()
|
|
1031
|
-
.writeBuffer(buf)
|
|
1032
|
-
.toString()
|
|
1033
|
-
.should.equal('1 0x00')
|
|
1034
|
-
buf = Buffer.alloc(255)
|
|
1035
|
-
buf.fill(0)
|
|
1036
|
-
new Script()
|
|
1037
|
-
.writeBuffer(buf)
|
|
1038
|
-
.toString()
|
|
1039
|
-
.should.equal('OP_PUSHDATA1 255 0x' + buf.toString('hex'))
|
|
1040
|
-
buf = Buffer.alloc(256)
|
|
1041
|
-
buf.fill(0)
|
|
1042
|
-
new Script()
|
|
1043
|
-
.writeBuffer(buf)
|
|
1044
|
-
.toString()
|
|
1045
|
-
.should.equal('OP_PUSHDATA2 256 0x' + buf.toString('hex'))
|
|
1046
|
-
buf = Buffer.alloc(Math.pow(2, 16))
|
|
1047
|
-
buf.fill(0)
|
|
1048
|
-
new Script()
|
|
1049
|
-
.writeBuffer(buf)
|
|
1050
|
-
.toString()
|
|
1051
|
-
.should.equal(
|
|
1052
|
-
'OP_PUSHDATA4 ' + Math.pow(2, 16) + ' 0x' + buf.toString('hex')
|
|
1053
|
-
)
|
|
1054
|
-
})
|
|
1055
|
-
})
|
|
1056
|
-
|
|
1057
|
-
describe('@writeBuffer', function () {
|
|
1058
|
-
it('should write these push data', function () {
|
|
1059
|
-
let buf = Buffer.alloc(1)
|
|
1060
|
-
buf.fill(0)
|
|
1061
|
-
Script.writeBuffer(buf)
|
|
1062
|
-
.toString()
|
|
1063
|
-
.should.equal('1 0x00')
|
|
1064
|
-
buf = Buffer.alloc(255)
|
|
1065
|
-
buf.fill(0)
|
|
1066
|
-
Script.writeBuffer(buf)
|
|
1067
|
-
.toString()
|
|
1068
|
-
.should.equal('OP_PUSHDATA1 255 0x' + buf.toString('hex'))
|
|
1069
|
-
buf = Buffer.alloc(256)
|
|
1070
|
-
buf.fill(0)
|
|
1071
|
-
Script.writeBuffer(buf)
|
|
1072
|
-
.toString()
|
|
1073
|
-
.should.equal('OP_PUSHDATA2 256 0x' + buf.toString('hex'))
|
|
1074
|
-
buf = Buffer.alloc(Math.pow(2, 16))
|
|
1075
|
-
buf.fill(0)
|
|
1076
|
-
Script.writeBuffer(buf)
|
|
1077
|
-
.toString()
|
|
1078
|
-
.should.equal(
|
|
1079
|
-
'OP_PUSHDATA4 ' + Math.pow(2, 16) + ' 0x' + buf.toString('hex')
|
|
1080
|
-
)
|
|
1081
|
-
})
|
|
1082
|
-
})
|
|
1083
|
-
|
|
1084
|
-
describe('#setChunkBuffer', function () {
|
|
1085
|
-
it('should set this buffer', function () {
|
|
1086
|
-
const script = new Script().writeOpCode(OpCode.OP_CHECKMULTISIG)
|
|
1087
|
-
const buf = new Bn(5000000000000000).toBuffer()
|
|
1088
|
-
script.setChunkBuffer(0, buf)
|
|
1089
|
-
script.chunks[0].buf.toString('hex').should.equal(buf.toString('hex'))
|
|
1090
|
-
})
|
|
1091
|
-
})
|
|
1092
|
-
|
|
1093
|
-
describe('#writeString', function () {
|
|
1094
|
-
it('should write both pushdata and non-pushdata chunks', function () {
|
|
1095
|
-
new Script()
|
|
1096
|
-
.writeString('OP_CHECKMULTISIG')
|
|
1097
|
-
.toString()
|
|
1098
|
-
.should.equal('OP_CHECKMULTISIG')
|
|
1099
|
-
})
|
|
1100
|
-
})
|
|
1101
|
-
|
|
1102
|
-
describe('@writeString', function () {
|
|
1103
|
-
it('should write both pushdata and non-pushdata chunks', function () {
|
|
1104
|
-
Script.writeString('OP_CHECKMULTISIG')
|
|
1105
|
-
.toString()
|
|
1106
|
-
.should.equal('OP_CHECKMULTISIG')
|
|
1107
|
-
})
|
|
1108
|
-
})
|
|
1109
|
-
|
|
1110
|
-
describe('#checkMinimalPush', function () {
|
|
1111
|
-
it('should check these minimal pushes', function () {
|
|
1112
|
-
let buf
|
|
1113
|
-
new Script()
|
|
1114
|
-
.writeBn(new Bn(1))
|
|
1115
|
-
.checkMinimalPush(0)
|
|
1116
|
-
.should.equal(true)
|
|
1117
|
-
new Script()
|
|
1118
|
-
.writeBn(new Bn(0))
|
|
1119
|
-
.checkMinimalPush(0)
|
|
1120
|
-
.should.equal(true)
|
|
1121
|
-
new Script()
|
|
1122
|
-
.writeBn(new Bn(-1))
|
|
1123
|
-
.checkMinimalPush(0)
|
|
1124
|
-
.should.equal(true)
|
|
1125
|
-
new Script()
|
|
1126
|
-
.writeBuffer(Buffer.from([0]))
|
|
1127
|
-
.checkMinimalPush(0)
|
|
1128
|
-
.should.equal(true)
|
|
1129
|
-
|
|
1130
|
-
buf = Buffer.alloc(75)
|
|
1131
|
-
buf.fill(1)
|
|
1132
|
-
new Script()
|
|
1133
|
-
.writeBuffer(buf)
|
|
1134
|
-
.checkMinimalPush(0)
|
|
1135
|
-
.should.equal(true)
|
|
1136
|
-
|
|
1137
|
-
buf = Buffer.alloc(76)
|
|
1138
|
-
buf.fill(1)
|
|
1139
|
-
new Script()
|
|
1140
|
-
.writeBuffer(buf)
|
|
1141
|
-
.checkMinimalPush(0)
|
|
1142
|
-
.should.equal(true)
|
|
1143
|
-
|
|
1144
|
-
buf = Buffer.alloc(256)
|
|
1145
|
-
buf.fill(1)
|
|
1146
|
-
new Script()
|
|
1147
|
-
.writeBuffer(buf)
|
|
1148
|
-
.checkMinimalPush(0)
|
|
1149
|
-
.should.equal(true)
|
|
1150
|
-
})
|
|
1151
|
-
})
|
|
1152
|
-
|
|
1153
|
-
describe('#isOpReturn', () => {
|
|
1154
|
-
it('returns true if the script its only an OP_RETURN opcode', () => {
|
|
1155
|
-
const script = new Script().writeOpCode(OpCode.OP_RETURN)
|
|
1156
|
-
should(script.isOpReturn()).be.true()
|
|
1157
|
-
})
|
|
1158
|
-
|
|
1159
|
-
it('returns false if the script starts with an opcode that is not OP_RETURN', () => {
|
|
1160
|
-
const script = new Script()
|
|
1161
|
-
.writeOpCode(OpCode.OP_ADD)
|
|
1162
|
-
should(script.isOpReturn()).be.false()
|
|
1163
|
-
})
|
|
1164
|
-
|
|
1165
|
-
it('returns false if the script starts with a push data', () => {
|
|
1166
|
-
const script = new Script()
|
|
1167
|
-
.writeBuffer(Buffer.from("I'm a buffer"))
|
|
1168
|
-
should(script.isOpReturn()).be.false()
|
|
1169
|
-
})
|
|
1170
|
-
|
|
1171
|
-
it('returns false if the script starts with "OP_FALSE OP_RETURN"', () => {
|
|
1172
|
-
const script = new Script()
|
|
1173
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1174
|
-
.writeOpCode(OpCode.OP_RETURN)
|
|
1175
|
-
should(script.isOpReturn()).be.false()
|
|
1176
|
-
})
|
|
1177
|
-
|
|
1178
|
-
it('returns false if the script starts OP_RETURN and is followed by an OP_FALSE', () => {
|
|
1179
|
-
const script = new Script()
|
|
1180
|
-
.writeOpCode(OpCode.OP_RETURN)
|
|
1181
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1182
|
-
should(script.isOpReturn()).be.false()
|
|
1183
|
-
})
|
|
1184
|
-
|
|
1185
|
-
it('returns false if the script starts OP_RETURN and is followed by data and then OP_FALSE', () => {
|
|
1186
|
-
const script = new Script()
|
|
1187
|
-
.writeOpCode(OpCode.OP_RETURN)
|
|
1188
|
-
.writeBuffer(Buffer.from("I'm a buffer"))
|
|
1189
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1190
|
-
should(script.isOpReturn()).be.false()
|
|
1191
|
-
})
|
|
1192
|
-
|
|
1193
|
-
it('returns false for the asm script "OP_RETURN 0"', () => {
|
|
1194
|
-
const script = Script.fromAsmString('OP_RETURN 0')
|
|
1195
|
-
should(script.isOpReturn()).be.false()
|
|
1196
|
-
})
|
|
1197
|
-
|
|
1198
|
-
it('throws for empty script', () => {
|
|
1199
|
-
const script = new Script()
|
|
1200
|
-
should(() => script.isOpReturn()).throw()
|
|
1201
|
-
})
|
|
1202
|
-
|
|
1203
|
-
it('returns false for only push data script', () => {
|
|
1204
|
-
const script = new Script().writeBuffer(Buffer.from("I'm a lonely buffer"))
|
|
1205
|
-
should(script.isOpReturn()).be.false()
|
|
1206
|
-
})
|
|
1207
|
-
})
|
|
1208
|
-
|
|
1209
|
-
describe('#isNonSpendable', () => {
|
|
1210
|
-
it('returns false when OP_TRUE only', () => {
|
|
1211
|
-
const script = new Script().writeOpCode(OpCode.OP_TRUE)
|
|
1212
|
-
should(script.isNonSpendable()).be.false()
|
|
1213
|
-
})
|
|
1214
|
-
|
|
1215
|
-
it('returns true when "OP_FALSE OP_RETURN"', () => {
|
|
1216
|
-
const script = new Script()
|
|
1217
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1218
|
-
.writeOpCode(OpCode.OP_RETURN)
|
|
1219
|
-
should(script.isNonSpendable()).be.true()
|
|
1220
|
-
})
|
|
1221
|
-
|
|
1222
|
-
it('returns false when starts with OP_FALSE but is followed by opcode that is not OP_RETURN', () => {
|
|
1223
|
-
const script = new Script()
|
|
1224
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1225
|
-
.writeOpCode(OpCode.OP_ADD)
|
|
1226
|
-
should(script.isNonSpendable()).be.false()
|
|
1227
|
-
})
|
|
1228
|
-
|
|
1229
|
-
it('returns false when is only OP_FALSE', () => {
|
|
1230
|
-
const script = new Script()
|
|
1231
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1232
|
-
should(script.isNonSpendable()).be.false()
|
|
1233
|
-
})
|
|
1234
|
-
|
|
1235
|
-
it('returns true when is OP_FALSE OP_RETURN and then data', () => {
|
|
1236
|
-
const script = new Script()
|
|
1237
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1238
|
-
.writeOpCode(OpCode.OP_RETURN)
|
|
1239
|
-
.writeBuffer(Buffer.from('some'))
|
|
1240
|
-
.writeBuffer(Buffer.from('data'))
|
|
1241
|
-
|
|
1242
|
-
should(script.isNonSpendable()).be.true()
|
|
1243
|
-
})
|
|
1244
|
-
|
|
1245
|
-
it('returns true when is OP_FALSE OP_RETURN and then data plus opcodes', () => {
|
|
1246
|
-
const script = new Script()
|
|
1247
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1248
|
-
.writeOpCode(OpCode.OP_RETURN)
|
|
1249
|
-
.writeBuffer(Buffer.from('some'))
|
|
1250
|
-
.writeBuffer(Buffer.from('data'))
|
|
1251
|
-
.writeOpCode(OpCode.OP_ADD)
|
|
1252
|
-
.writeBuffer(Buffer.from('more data'))
|
|
1253
|
-
|
|
1254
|
-
should(script.isNonSpendable()).be.true()
|
|
1255
|
-
})
|
|
1256
|
-
|
|
1257
|
-
it('returns true when is OP_FALSE OP_RETURN and then opcodes', () => {
|
|
1258
|
-
const script = new Script()
|
|
1259
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1260
|
-
.writeOpCode(OpCode.OP_RETURN)
|
|
1261
|
-
.writeOpCode(OpCode.OP_ADD)
|
|
1262
|
-
.writeOpCode(OpCode.OP_MUL)
|
|
1263
|
-
|
|
1264
|
-
should(script.isNonSpendable()).be.true()
|
|
1265
|
-
})
|
|
1266
|
-
|
|
1267
|
-
it('returns true when is OP_FALSE OP_RETURN and then OP_FALSE', () => {
|
|
1268
|
-
const script = new Script()
|
|
1269
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1270
|
-
.writeOpCode(OpCode.OP_RETURN)
|
|
1271
|
-
.writeOpCode(OpCode.OP_FALSE)
|
|
1272
|
-
|
|
1273
|
-
should(script.isNonSpendable()).be.true()
|
|
1274
|
-
})
|
|
1275
|
-
|
|
1276
|
-
it('returns true when for asm script "OP_FALSE OP_RETURN 0"', () => {
|
|
1277
|
-
const script = new Script().fromAsmString('OP_FALSE OP_RETURN 0')
|
|
1278
|
-
|
|
1279
|
-
should(script.isNonSpendable()).be.true()
|
|
1280
|
-
})
|
|
1281
|
-
})
|
|
1282
|
-
|
|
1283
|
-
describe('vectors', function () {
|
|
1284
|
-
scriptValid.forEach(function (a, i) {
|
|
1285
|
-
if (a.length === 1) {
|
|
1286
|
-
return
|
|
1287
|
-
}
|
|
1288
|
-
it('should not fail when reading scriptValid vector ' + i, function () {
|
|
1289
|
-
;(function () {
|
|
1290
|
-
new Script().fromBitcoindString(a[0]).toString()
|
|
1291
|
-
new Script().fromBitcoindString(a[0]).toBitcoindString()
|
|
1292
|
-
}.should.not.throw())
|
|
1293
|
-
;(function () {
|
|
1294
|
-
new Script().fromBitcoindString(a[1]).toString()
|
|
1295
|
-
new Script().fromBitcoindString(a[1]).toBitcoindString()
|
|
1296
|
-
}.should.not.throw())
|
|
1297
|
-
|
|
1298
|
-
// should be able to return the same output over and over
|
|
1299
|
-
let str = new Script().fromBitcoindString(a[0]).toBitcoindString()
|
|
1300
|
-
new Script()
|
|
1301
|
-
.fromBitcoindString(str)
|
|
1302
|
-
.toBitcoindString()
|
|
1303
|
-
.should.equal(str)
|
|
1304
|
-
str = new Script().fromBitcoindString(a[1]).toBitcoindString()
|
|
1305
|
-
new Script()
|
|
1306
|
-
.fromBitcoindString(str)
|
|
1307
|
-
.toBitcoindString()
|
|
1308
|
-
.should.equal(str)
|
|
1309
|
-
})
|
|
1310
|
-
})
|
|
1311
|
-
|
|
1312
|
-
scriptInvalid.forEach(function (a, i) {
|
|
1313
|
-
if (a.length === 1) {
|
|
1314
|
-
return
|
|
1315
|
-
}
|
|
1316
|
-
it('should not fail when reading scriptInvalid vector ' + i, function () {
|
|
1317
|
-
;(function () {
|
|
1318
|
-
new Script().fromBitcoindString(a[0]).toString()
|
|
1319
|
-
new Script().fromBitcoindString(a[0]).toBitcoindString()
|
|
1320
|
-
}.should.not.throw())
|
|
1321
|
-
;(function () {
|
|
1322
|
-
new Script().fromBitcoindString(a[1]).toString()
|
|
1323
|
-
new Script().fromBitcoindString(a[1]).toBitcoindString()
|
|
1324
|
-
}.should.not.throw())
|
|
1325
|
-
|
|
1326
|
-
// should be able to return the same output over and over
|
|
1327
|
-
let str = new Script().fromBitcoindString(a[0]).toBitcoindString()
|
|
1328
|
-
new Script()
|
|
1329
|
-
.fromBitcoindString(str)
|
|
1330
|
-
.toBitcoindString()
|
|
1331
|
-
.should.equal(str)
|
|
1332
|
-
str = new Script().fromBitcoindString(a[1]).toBitcoindString()
|
|
1333
|
-
new Script()
|
|
1334
|
-
.fromBitcoindString(str)
|
|
1335
|
-
.toBitcoindString()
|
|
1336
|
-
.should.equal(str)
|
|
1337
|
-
})
|
|
1338
|
-
})
|
|
1339
|
-
})
|
|
1340
|
-
})
|