bsv2 2.0.23 → 2.1.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/{.babelrc.test → .babel.test} +1 -1
- package/.husky/pre-commit +1 -1
- package/.mocharc.yml +1 -1
- package/.travis.yml +1 -1
- package/babel.config.cjs +44 -0
- package/benchmark.js +10 -18
- package/bin/bsv.js +1 -1
- package/bin/network.js +2 -1
- package/dist/bsv2.mjs +36061 -4
- package/dist/bsv2.umd.js +28 -0
- package/doc/assets/anchor.js +350 -0
- package/doc/assets/bass-addons.css +12 -0
- package/doc/assets/bass.css +544 -0
- package/doc/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
- package/doc/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
- package/doc/assets/fonts/LICENSE.txt +93 -0
- package/doc/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
- package/doc/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
- package/doc/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
- package/doc/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
- package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
- package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
- package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
- package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
- package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
- package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
- package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
- package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
- package/doc/assets/fonts/source-code-pro.css +23 -0
- package/doc/assets/github.css +123 -0
- package/doc/assets/site.js +168 -0
- package/doc/assets/split.css +15 -0
- package/doc/assets/split.js +782 -0
- package/doc/assets/style.css +147 -0
- package/doc/index.html +9461 -0
- package/entry.js +2 -3
- package/eslint.config.mjs +8 -0
- package/index.js +1 -5
- package/{karma.conf.js → karma.conf.ts} +2 -3
- package/lib/ach.js +5 -5
- package/lib/address.js +11 -9
- package/lib/aescbc.js +3 -3
- package/lib/bip-39.js +12 -11
- package/lib/block.js +2 -2
- package/lib/bn.js +12 -17
- package/lib/bsm.js +1 -1
- package/lib/config.js +1 -1
- package/lib/constants.js +1 -1
- package/lib/ecdsa.js +24 -23
- package/lib/interp.js +190 -26
- package/lib/merkle.js +1 -1
- package/lib/op-code.js +137 -135
- package/lib/priv-key.js +1 -1
- package/lib/script.js +44 -42
- package/lib/sig.js +12 -12
- package/lib/struct.js +9 -6
- package/lib/tx.js +8 -7
- package/load-babel.js +3 -1
- package/mtest/test.html +6 -4
- package/mtest/test.js +1 -1
- package/out/Sig.html +541 -0
- package/out/bip-32.js.html +523 -0
- package/out/bip-39.js.html +336 -0
- package/out/block.js.html +183 -0
- package/out/bn.js.html +512 -0
- package/out/ecdsa.js.html +546 -0
- package/out/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/out/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/out/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/out/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/out/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/out/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Light-webfont.eot +0 -0
- package/out/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/out/fonts/OpenSans-Light-webfont.woff +0 -0
- package/out/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/out/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/out/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/out/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/out/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/out/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/out/global.html +220 -0
- package/out/index.html +128 -0
- package/out/interp.js.html +2064 -0
- package/out/merkle.js.html +143 -0
- package/out/msg.js.html +235 -0
- package/out/priv-key.js.html +208 -0
- package/out/pub-key.js.html +281 -0
- package/out/script.js.html +876 -0
- package/out/scripts/linenumber.js +25 -0
- package/out/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/out/scripts/prettify/lang-css.js +2 -0
- package/out/scripts/prettify/prettify.js +28 -0
- package/out/sig-operations.js.html +171 -0
- package/out/sig.js.html +450 -0
- package/out/struct.js.html +440 -0
- package/out/styles/jsdoc-default.css +358 -0
- package/out/styles/prettify-jsdoc.css +111 -0
- package/out/styles/prettify-tomorrow.css +132 -0
- package/out/tx-builder.js.html +644 -0
- package/out/tx-in.js.html +223 -0
- package/out/tx-verifier.js.html +260 -0
- package/out/tx.js.html +481 -0
- package/package.json +34 -39
- package/vite.config.js +36 -0
- 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/{webpack.config.js → mtest/webpack.config.js} +0 -0
package/lib/op-code.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* An opCode is one of the operations in the bitcoin scripting language. Each
|
|
6
6
|
* operation is just a number from 0-255, and it has a corresponding string,
|
|
7
|
-
* e.g.
|
|
7
|
+
* e.g. 'OP_RETURN', which comes from the name of that constant in the bitcoind
|
|
8
8
|
* source code. The way you probably want to use this is with
|
|
9
9
|
* new OpCode(str).toNumber() or new OpCode(num).toString()
|
|
10
10
|
*/
|
|
@@ -13,150 +13,150 @@
|
|
|
13
13
|
import { Struct } from './struct'
|
|
14
14
|
const noopmap = {
|
|
15
15
|
// push value
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
FALSE: 0x00,
|
|
17
|
+
0: 0x00,
|
|
18
|
+
PUSHDATA1: 0x4c,
|
|
19
|
+
PUSHDATA2: 0x4d,
|
|
20
|
+
PUSHDATA4: 0x4e,
|
|
21
|
+
'1NEGATE': 0x4f,
|
|
22
|
+
RESERVED: 0x50,
|
|
23
|
+
TRUE: 0x51,
|
|
24
|
+
1: 0x51,
|
|
25
|
+
2: 0x52,
|
|
26
|
+
3: 0x53,
|
|
27
|
+
4: 0x54,
|
|
28
|
+
5: 0x55,
|
|
29
|
+
6: 0x56,
|
|
30
|
+
7: 0x57,
|
|
31
|
+
8: 0x58,
|
|
32
|
+
9: 0x59,
|
|
33
|
+
10: 0x5a,
|
|
34
|
+
11: 0x5b,
|
|
35
|
+
12: 0x5c,
|
|
36
|
+
13: 0x5d,
|
|
37
|
+
14: 0x5e,
|
|
38
|
+
15: 0x5f,
|
|
39
|
+
16: 0x60,
|
|
40
40
|
|
|
41
41
|
// control
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
NOP: 0x61,
|
|
43
|
+
VER: 0x62,
|
|
44
|
+
IF: 0x63,
|
|
45
|
+
NOTIF: 0x64,
|
|
46
|
+
VERIF: 0x65,
|
|
47
|
+
VERNOTIF: 0x66,
|
|
48
|
+
ELSE: 0x67,
|
|
49
|
+
ENDIF: 0x68,
|
|
50
|
+
VERIFY: 0x69,
|
|
51
|
+
RETURN: 0x6a,
|
|
52
52
|
|
|
53
53
|
// stack ops
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
TOALTSTACK: 0x6b,
|
|
55
|
+
FROMALTSTACK: 0x6c,
|
|
56
|
+
'2DROP': 0x6d,
|
|
57
|
+
'2DUP': 0x6e,
|
|
58
|
+
'3DUP': 0x6f,
|
|
59
|
+
'2OVER': 0x70,
|
|
60
|
+
'2ROT': 0x71,
|
|
61
|
+
'2SWAP': 0x72,
|
|
62
|
+
IFDUP: 0x73,
|
|
63
|
+
DEPTH: 0x74,
|
|
64
|
+
DROP: 0x75,
|
|
65
|
+
DUP: 0x76,
|
|
66
|
+
NIP: 0x77,
|
|
67
|
+
OVER: 0x78,
|
|
68
|
+
PICK: 0x79,
|
|
69
|
+
ROLL: 0x7a,
|
|
70
|
+
ROT: 0x7b,
|
|
71
|
+
SWAP: 0x7c,
|
|
72
|
+
TUCK: 0x7d,
|
|
73
73
|
|
|
74
74
|
// data manipulation ops
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
CAT: 0x7e,
|
|
76
|
+
SUBSTR: 0x7f, // Replaced in BSV
|
|
77
|
+
SPLIT: 0x7f,
|
|
78
|
+
LEFT: 0x80, // Replaced in BSV
|
|
79
|
+
NUM2BIN: 0x80,
|
|
80
|
+
RIGHT: 0x81, // Replaced in BSV
|
|
81
|
+
BIN2NUM: 0x81,
|
|
82
|
+
SIZE: 0x82,
|
|
83
83
|
|
|
84
84
|
// bit logic
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
INVERT: 0x83,
|
|
86
|
+
AND: 0x84,
|
|
87
|
+
OR: 0x85,
|
|
88
|
+
XOR: 0x86,
|
|
89
|
+
EQUAL: 0x87,
|
|
90
|
+
EQUALVERIFY: 0x88,
|
|
91
|
+
RESERVED1: 0x89,
|
|
92
|
+
RESERVED2: 0x8a,
|
|
93
93
|
|
|
94
94
|
// numeric
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
95
|
+
'1ADD': 0x8b,
|
|
96
|
+
'1SUB': 0x8c,
|
|
97
|
+
'2MUL': 0x8d,
|
|
98
|
+
'2DIV': 0x8e,
|
|
99
|
+
NEGATE: 0x8f,
|
|
100
|
+
ABS: 0x90,
|
|
101
|
+
NOT: 0x91,
|
|
102
|
+
'0NOTEQUAL': 0x92,
|
|
103
|
+
|
|
104
|
+
ADD: 0x93,
|
|
105
|
+
SUB: 0x94,
|
|
106
|
+
MUL: 0x95,
|
|
107
|
+
DIV: 0x96,
|
|
108
|
+
MOD: 0x97,
|
|
109
|
+
LSHIFT: 0x98,
|
|
110
|
+
RSHIFT: 0x99,
|
|
111
|
+
|
|
112
|
+
BOOLAND: 0x9a,
|
|
113
|
+
BOOLOR: 0x9b,
|
|
114
|
+
NUMEQUAL: 0x9c,
|
|
115
|
+
NUMEQUALVERIFY: 0x9d,
|
|
116
|
+
NUMNOTEQUAL: 0x9e,
|
|
117
|
+
LESSTHAN: 0x9f,
|
|
118
|
+
GREATERTHAN: 0xa0,
|
|
119
|
+
LESSTHANOREQUAL: 0xa1,
|
|
120
|
+
GREATERTHANOREQUAL: 0xa2,
|
|
121
|
+
MIN: 0xa3,
|
|
122
|
+
MAX: 0xa4,
|
|
123
|
+
|
|
124
|
+
WITHIN: 0xa5,
|
|
125
125
|
|
|
126
126
|
// crypto
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
RIPEMD160: 0xa6,
|
|
128
|
+
SHA1: 0xa7,
|
|
129
|
+
SHA256: 0xa8,
|
|
130
|
+
HASH160: 0xa9,
|
|
131
|
+
HASH256: 0xaa,
|
|
132
|
+
CODESEPARATOR: 0xab,
|
|
133
|
+
CHECKSIG: 0xac,
|
|
134
|
+
CHECKSIGVERIFY: 0xad,
|
|
135
|
+
CHECKMULTISIG: 0xae,
|
|
136
|
+
CHECKMULTISIGVERIFY: 0xaf,
|
|
137
137
|
|
|
138
138
|
// expansion
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
139
|
+
NOP1: 0xb0,
|
|
140
|
+
NOP2: 0xb1,
|
|
141
|
+
CHECKLOCKTIMEVERIFY: 0xb1,
|
|
142
|
+
NOP3: 0xb2,
|
|
143
|
+
CHECKSEQUENCEVERIFY: 0xb2,
|
|
144
|
+
NOP4: 0xb3,
|
|
145
|
+
NOP5: 0xb4,
|
|
146
|
+
NOP6: 0xb5,
|
|
147
|
+
NOP7: 0xb6,
|
|
148
|
+
NOP8: 0xb7,
|
|
149
|
+
NOP9: 0xb8,
|
|
150
|
+
NOP10: 0xb9,
|
|
151
151
|
|
|
152
152
|
// template matching params
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
153
|
+
SMALLDATA: 0xf9,
|
|
154
|
+
SMALLINTEGER: 0xfa,
|
|
155
|
+
PUBKEYS: 0xfb,
|
|
156
|
+
PUBKEYHASH: 0xfd,
|
|
157
|
+
PUBKEY: 0xfe,
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
INVALIDOPCODE: 0xff
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
const map = {
|
|
@@ -333,6 +333,7 @@ class OpCode extends Struct {
|
|
|
333
333
|
this.num = num
|
|
334
334
|
return this
|
|
335
335
|
}
|
|
336
|
+
|
|
336
337
|
fromNoOpString (str) {
|
|
337
338
|
const num = noopmap[str]
|
|
338
339
|
if (num === undefined) {
|
|
@@ -345,6 +346,7 @@ class OpCode extends Struct {
|
|
|
345
346
|
static fromString (str) {
|
|
346
347
|
return new this().fromString(str)
|
|
347
348
|
}
|
|
349
|
+
|
|
348
350
|
static fromNoOpString (str) {
|
|
349
351
|
return new this().fromNoOpString(str)
|
|
350
352
|
}
|
|
@@ -354,25 +356,26 @@ class OpCode extends Struct {
|
|
|
354
356
|
if (str === undefined) {
|
|
355
357
|
if (this.num > 0 && this.num < OpCode.OP_PUSHDATA1) {
|
|
356
358
|
return this.num.toString()
|
|
357
|
-
}else{
|
|
358
|
-
return
|
|
359
|
+
} else {
|
|
360
|
+
return 'OP_' + this.num.toNumber()
|
|
359
361
|
}
|
|
360
|
-
//
|
|
362
|
+
// throw new Error('OpCode does not have a string representation')
|
|
361
363
|
}
|
|
362
364
|
return str
|
|
363
365
|
}
|
|
366
|
+
|
|
364
367
|
toNoOpString () {
|
|
365
368
|
const str = OpCode.noopstr[this.num]
|
|
366
369
|
if (str === undefined) {
|
|
367
370
|
if (this.num > 0 && this.num < OpCode.OP_PUSHDATA1) {
|
|
368
371
|
return this.num.toString()
|
|
369
|
-
}else{
|
|
372
|
+
} else {
|
|
370
373
|
return this.num.toNumber()
|
|
371
374
|
}
|
|
372
|
-
|
|
375
|
+
// throw new Error('OpCode does not have a string representation')
|
|
373
376
|
}
|
|
374
377
|
return str
|
|
375
|
-
}
|
|
378
|
+
}
|
|
376
379
|
}
|
|
377
380
|
|
|
378
381
|
OpCode.str = {}
|
|
@@ -394,5 +397,4 @@ for (const CodeStr in noopmap) {
|
|
|
394
397
|
}
|
|
395
398
|
}
|
|
396
399
|
|
|
397
|
-
|
|
398
400
|
export { OpCode }
|
package/lib/priv-key.js
CHANGED
package/lib/script.js
CHANGED
|
@@ -50,8 +50,8 @@ class Script extends Struct {
|
|
|
50
50
|
len = opCodeNum
|
|
51
51
|
this.chunks.push({
|
|
52
52
|
buf: br.read(len),
|
|
53
|
-
len
|
|
54
|
-
opCodeNum
|
|
53
|
+
len,
|
|
54
|
+
opCodeNum
|
|
55
55
|
})
|
|
56
56
|
} else if (opCodeNum === OpCode.OP_PUSHDATA1) {
|
|
57
57
|
try {
|
|
@@ -61,9 +61,9 @@ class Script extends Struct {
|
|
|
61
61
|
br.read()
|
|
62
62
|
}
|
|
63
63
|
this.chunks.push({
|
|
64
|
-
buf
|
|
65
|
-
len
|
|
66
|
-
opCodeNum
|
|
64
|
+
buf,
|
|
65
|
+
len,
|
|
66
|
+
opCodeNum
|
|
67
67
|
})
|
|
68
68
|
} else if (opCodeNum === OpCode.OP_PUSHDATA2) {
|
|
69
69
|
try {
|
|
@@ -73,9 +73,9 @@ class Script extends Struct {
|
|
|
73
73
|
br.read()
|
|
74
74
|
}
|
|
75
75
|
this.chunks.push({
|
|
76
|
-
buf
|
|
77
|
-
len
|
|
78
|
-
opCodeNum
|
|
76
|
+
buf,
|
|
77
|
+
len,
|
|
78
|
+
opCodeNum
|
|
79
79
|
})
|
|
80
80
|
} else if (opCodeNum === OpCode.OP_PUSHDATA4) {
|
|
81
81
|
try {
|
|
@@ -85,13 +85,13 @@ class Script extends Struct {
|
|
|
85
85
|
br.read()
|
|
86
86
|
}
|
|
87
87
|
this.chunks.push({
|
|
88
|
-
buf
|
|
89
|
-
len
|
|
90
|
-
opCodeNum
|
|
88
|
+
buf,
|
|
89
|
+
len,
|
|
90
|
+
opCodeNum
|
|
91
91
|
})
|
|
92
92
|
} else {
|
|
93
93
|
this.chunks.push({
|
|
94
|
-
opCodeNum
|
|
94
|
+
opCodeNum
|
|
95
95
|
})
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -147,7 +147,7 @@ class Script extends Struct {
|
|
|
147
147
|
this.chunks.push({
|
|
148
148
|
buf: Buffer.from(tokens[i + 1].slice(2), 'hex'),
|
|
149
149
|
len: opCodeNum,
|
|
150
|
-
opCodeNum
|
|
150
|
+
opCodeNum
|
|
151
151
|
})
|
|
152
152
|
i = i + 2
|
|
153
153
|
} else if (opCodeNum === 0) {
|
|
@@ -169,12 +169,12 @@ class Script extends Struct {
|
|
|
169
169
|
this.chunks.push({
|
|
170
170
|
buf: Buffer.from(tokens[i + 2].slice(2), 'hex'),
|
|
171
171
|
len: parseInt(tokens[i + 1], 10),
|
|
172
|
-
opCodeNum
|
|
172
|
+
opCodeNum
|
|
173
173
|
})
|
|
174
174
|
i = i + 3
|
|
175
175
|
} else {
|
|
176
176
|
this.chunks.push({
|
|
177
|
-
opCodeNum
|
|
177
|
+
opCodeNum
|
|
178
178
|
})
|
|
179
179
|
i = i + 1
|
|
180
180
|
}
|
|
@@ -182,15 +182,15 @@ class Script extends Struct {
|
|
|
182
182
|
return this
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
toString (opts={ noOp:false}) {
|
|
185
|
+
toString (opts = { noOp: false }) {
|
|
186
186
|
let str = ''
|
|
187
187
|
|
|
188
188
|
for (let i = 0; i < this.chunks.length; i++) {
|
|
189
189
|
const chunk = this.chunks[i]
|
|
190
|
-
const opCodeNum = chunk.opCodeNum
|
|
190
|
+
const opCodeNum = chunk.opCodeNum?.num ? chunk.opCodeNum.num : chunk.opCodeNum
|
|
191
191
|
if (!chunk.buf) {
|
|
192
|
-
if (OpCode.str[opCodeNum] !== undefined || OpCode.noopstr[opCodeNum]!== undefined) {
|
|
193
|
-
str =
|
|
192
|
+
if (OpCode.str[opCodeNum] !== undefined || OpCode.noopstr[opCodeNum] !== undefined) {
|
|
193
|
+
str = opts.noOp ? str + ' ' + new OpCode(opCodeNum).toNoOpString() : str + ' ' + new OpCode(opCodeNum).toString()
|
|
194
194
|
} else {
|
|
195
195
|
str = str + ' ' + '0x' + opCodeNum.toString(16)
|
|
196
196
|
}
|
|
@@ -200,17 +200,16 @@ class Script extends Struct {
|
|
|
200
200
|
opCodeNum === OpCode.OP_PUSHDATA2 ||
|
|
201
201
|
opCodeNum === OpCode.OP_PUSHDATA4
|
|
202
202
|
) {
|
|
203
|
-
|
|
203
|
+
str = opts.noOp ? str + ' ' + new OpCode(opCodeNum).toNoOpString() : str + ' ' + new OpCode(opCodeNum).toString()
|
|
204
204
|
}
|
|
205
205
|
str = str + ' ' + chunk.len
|
|
206
|
-
str = str + ' ' + '0x' + chunk.buf.toString(
|
|
206
|
+
str = str + ' ' + '0x' + chunk.buf.toString('hex')
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
return str.substr(1)
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
|
|
214
213
|
/**
|
|
215
214
|
* Input the script from the script string format used in bitcoind data tests
|
|
216
215
|
*/
|
|
@@ -301,13 +300,13 @@ class Script extends Struct {
|
|
|
301
300
|
if (token === '0') {
|
|
302
301
|
opCodeNum = 0
|
|
303
302
|
this.chunks.push({
|
|
304
|
-
opCodeNum
|
|
303
|
+
opCodeNum
|
|
305
304
|
})
|
|
306
305
|
i = i + 1
|
|
307
306
|
} else if (token === '-1') {
|
|
308
307
|
opCodeNum = OpCode.OP_1NEGATE
|
|
309
308
|
this.chunks.push({
|
|
310
|
-
opCodeNum
|
|
309
|
+
opCodeNum
|
|
311
310
|
})
|
|
312
311
|
i = i + 1
|
|
313
312
|
} else if (opCode === undefined) {
|
|
@@ -327,14 +326,14 @@ class Script extends Struct {
|
|
|
327
326
|
opCodeNum = OpCode.OP_PUSHDATA4
|
|
328
327
|
}
|
|
329
328
|
this.chunks.push({
|
|
330
|
-
buf
|
|
329
|
+
buf,
|
|
331
330
|
len: buf.length,
|
|
332
|
-
opCodeNum
|
|
331
|
+
opCodeNum
|
|
333
332
|
})
|
|
334
333
|
i = i + 1
|
|
335
334
|
} else {
|
|
336
335
|
this.chunks.push({
|
|
337
|
-
opCodeNum
|
|
336
|
+
opCodeNum
|
|
338
337
|
})
|
|
339
338
|
i = i + 1
|
|
340
339
|
}
|
|
@@ -349,19 +348,19 @@ class Script extends Struct {
|
|
|
349
348
|
/**
|
|
350
349
|
* Output the script to the script string format used in bitcoind data tests.
|
|
351
350
|
*/
|
|
352
|
-
toAsmString (opts={noOp:false}) {
|
|
353
|
-
|
|
354
|
-
for (
|
|
355
|
-
|
|
351
|
+
toAsmString (opts = { noOp: false }) {
|
|
352
|
+
let str = ''
|
|
353
|
+
for (let i = 0; i < this.chunks.length; i++) {
|
|
354
|
+
const chunk = this.chunks[i]
|
|
356
355
|
str += this._chunkToString(chunk, opts)
|
|
357
356
|
}
|
|
358
357
|
|
|
359
358
|
return str.substr(1)
|
|
360
359
|
}
|
|
361
360
|
|
|
362
|
-
_chunkToString (chunk, opts={noOp: false}) {
|
|
363
|
-
|
|
364
|
-
|
|
361
|
+
_chunkToString (chunk, opts = { noOp: false }) {
|
|
362
|
+
const opCodeNum = chunk.opCodeNum
|
|
363
|
+
let str = ''
|
|
365
364
|
if (!chunk.buf) {
|
|
366
365
|
// no data chunk
|
|
367
366
|
if (typeof OpCode.str[opCodeNum] !== 'undefined') {
|
|
@@ -374,10 +373,10 @@ class Script extends Struct {
|
|
|
374
373
|
// OP_1NEGATE -> 1
|
|
375
374
|
str = str + ' -1'
|
|
376
375
|
} else {
|
|
377
|
-
str = opts.noOp ? str + ' ' + new OpCode(opCodeNum).toNoOpString():str + ' ' + new OpCode(opCodeNum).toString()
|
|
376
|
+
str = opts.noOp ? str + ' ' + new OpCode(opCodeNum).toNoOpString() : str + ' ' + new OpCode(opCodeNum).toString()
|
|
378
377
|
}
|
|
379
378
|
} else {
|
|
380
|
-
|
|
379
|
+
let numstr = opCodeNum.toString(16)
|
|
381
380
|
if (numstr.length % 2 !== 0) {
|
|
382
381
|
numstr = '0' + numstr
|
|
383
382
|
}
|
|
@@ -461,6 +460,9 @@ class Script extends Struct {
|
|
|
461
460
|
}
|
|
462
461
|
|
|
463
462
|
static sortPubKeys (pubKeys) {
|
|
463
|
+
/* eslint array-callback-return: "off"
|
|
464
|
+
--------
|
|
465
|
+
The function returns the value on the for loop */
|
|
464
466
|
return pubKeys.slice().sort((pubKey1, pubKey2) => {
|
|
465
467
|
const buf1 = pubKey1.toBuffer()
|
|
466
468
|
const buf2 = pubKey2.toBuffer()
|
|
@@ -555,8 +557,8 @@ class Script extends Struct {
|
|
|
555
557
|
if (this.chunks[0].opCodeNum !== OpCode.OP_FALSE) {
|
|
556
558
|
return false
|
|
557
559
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
+
const chunks = this.chunks.slice(1)
|
|
561
|
+
const script2 = new Script(chunks)
|
|
560
562
|
return script2.isOpReturn()
|
|
561
563
|
}
|
|
562
564
|
|
|
@@ -772,12 +774,12 @@ class Script extends Struct {
|
|
|
772
774
|
} else if (buf.length < Math.pow(2, 32)) {
|
|
773
775
|
opCodeNum = OpCode.OP_PUSHDATA4
|
|
774
776
|
} else {
|
|
775
|
-
throw new Error(
|
|
777
|
+
throw new Error('You can\'t push that much data')
|
|
776
778
|
}
|
|
777
779
|
this.chunks.push({
|
|
778
|
-
buf
|
|
779
|
-
len
|
|
780
|
-
opCodeNum
|
|
780
|
+
buf,
|
|
781
|
+
len,
|
|
782
|
+
opCodeNum
|
|
781
783
|
})
|
|
782
784
|
return this
|
|
783
785
|
}
|
package/lib/sig.js
CHANGED
|
@@ -193,18 +193,18 @@ class Sig extends Struct {
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
const obj = {
|
|
196
|
-
header
|
|
197
|
-
length
|
|
198
|
-
rheader
|
|
199
|
-
rlength
|
|
200
|
-
rneg
|
|
201
|
-
rbuf
|
|
202
|
-
r
|
|
203
|
-
sheader
|
|
204
|
-
slength
|
|
205
|
-
sneg
|
|
206
|
-
sbuf
|
|
207
|
-
s
|
|
196
|
+
header,
|
|
197
|
+
length,
|
|
198
|
+
rheader,
|
|
199
|
+
rlength,
|
|
200
|
+
rneg,
|
|
201
|
+
rbuf,
|
|
202
|
+
r,
|
|
203
|
+
sheader,
|
|
204
|
+
slength,
|
|
205
|
+
sneg,
|
|
206
|
+
sbuf,
|
|
207
|
+
s
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
return obj
|
package/lib/struct.js
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
|
|
40
40
|
import { Br } from './br'
|
|
41
41
|
import { Bw } from './bw'
|
|
42
|
-
import {isHexadecimal} from 'is-hexadecimal'
|
|
42
|
+
import { isHexadecimal } from 'is-hexadecimal'
|
|
43
43
|
|
|
44
44
|
const isHex = isHexadecimal
|
|
45
45
|
class Struct {
|
|
@@ -135,8 +135,8 @@ class Struct {
|
|
|
135
135
|
const remainderbuf = buf.slice(buf.length - overlen, buf.length)
|
|
136
136
|
buf = buf.slice(0, buf.length - overlen)
|
|
137
137
|
return {
|
|
138
|
-
buf
|
|
139
|
-
remainderbuf
|
|
138
|
+
buf,
|
|
139
|
+
remainderbuf
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -312,12 +312,15 @@ class Struct {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
toJSON () {
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
/* eslint prefer-const: "off"
|
|
316
|
+
--------
|
|
317
|
+
The json can't be constant as will be modified on execution. */
|
|
318
|
+
let json = {}
|
|
319
|
+
for (const val in this) {
|
|
317
320
|
// arrays
|
|
318
321
|
if (Array.isArray(this[val])) {
|
|
319
322
|
const arr = []
|
|
320
|
-
for (
|
|
323
|
+
for (const i in this[val]) {
|
|
321
324
|
if (typeof this[val][i].toJSON === 'function') {
|
|
322
325
|
arr.push(this[val][i].toJSON())
|
|
323
326
|
} else {
|