bsv2 2.0.24 → 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.
Files changed (113) hide show
  1. package/{.babelrc.test → .babel.test} +1 -1
  2. package/.husky/pre-commit +1 -1
  3. package/.mocharc.yml +1 -1
  4. package/.travis.yml +1 -1
  5. package/babel.config.cjs +44 -0
  6. package/benchmark.js +10 -18
  7. package/bin/bsv.js +1 -1
  8. package/bin/network.js +2 -1
  9. package/dist/bsv2.mjs +36061 -4
  10. package/dist/bsv2.umd.js +28 -0
  11. package/doc/assets/anchor.js +350 -0
  12. package/doc/assets/bass-addons.css +12 -0
  13. package/doc/assets/bass.css +544 -0
  14. package/doc/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
  15. package/doc/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
  16. package/doc/assets/fonts/LICENSE.txt +93 -0
  17. package/doc/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
  18. package/doc/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
  19. package/doc/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
  20. package/doc/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
  21. package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
  22. package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
  23. package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
  24. package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
  25. package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
  26. package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
  27. package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
  28. package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
  29. package/doc/assets/fonts/source-code-pro.css +23 -0
  30. package/doc/assets/github.css +123 -0
  31. package/doc/assets/site.js +168 -0
  32. package/doc/assets/split.css +15 -0
  33. package/doc/assets/split.js +782 -0
  34. package/doc/assets/style.css +147 -0
  35. package/doc/index.html +9461 -0
  36. package/entry.js +2 -3
  37. package/eslint.config.mjs +8 -0
  38. package/index.js +1 -5
  39. package/{karma.conf.js → karma.conf.ts} +2 -3
  40. package/lib/ach.js +5 -5
  41. package/lib/address.js +11 -9
  42. package/lib/aescbc.js +3 -3
  43. package/lib/bip-39.js +12 -11
  44. package/lib/block.js +2 -2
  45. package/lib/bn.js +12 -17
  46. package/lib/bsm.js +1 -1
  47. package/lib/config.js +1 -1
  48. package/lib/constants.js +1 -1
  49. package/lib/ecdsa.js +24 -23
  50. package/lib/interp.js +18 -14
  51. package/lib/merkle.js +1 -1
  52. package/lib/op-code.js +137 -135
  53. package/lib/priv-key.js +1 -1
  54. package/lib/script.js +44 -42
  55. package/lib/sig.js +12 -12
  56. package/lib/struct.js +9 -6
  57. package/lib/tx.js +6 -6
  58. package/load-babel.js +3 -1
  59. package/mtest/test.html +6 -4
  60. package/mtest/test.js +1 -1
  61. package/out/Sig.html +541 -0
  62. package/out/bip-32.js.html +523 -0
  63. package/out/bip-39.js.html +336 -0
  64. package/out/block.js.html +183 -0
  65. package/out/bn.js.html +512 -0
  66. package/out/ecdsa.js.html +546 -0
  67. package/out/fonts/OpenSans-Bold-webfont.eot +0 -0
  68. package/out/fonts/OpenSans-Bold-webfont.svg +1830 -0
  69. package/out/fonts/OpenSans-Bold-webfont.woff +0 -0
  70. package/out/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  71. package/out/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  72. package/out/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  73. package/out/fonts/OpenSans-Italic-webfont.eot +0 -0
  74. package/out/fonts/OpenSans-Italic-webfont.svg +1830 -0
  75. package/out/fonts/OpenSans-Italic-webfont.woff +0 -0
  76. package/out/fonts/OpenSans-Light-webfont.eot +0 -0
  77. package/out/fonts/OpenSans-Light-webfont.svg +1831 -0
  78. package/out/fonts/OpenSans-Light-webfont.woff +0 -0
  79. package/out/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  80. package/out/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  81. package/out/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  82. package/out/fonts/OpenSans-Regular-webfont.eot +0 -0
  83. package/out/fonts/OpenSans-Regular-webfont.svg +1831 -0
  84. package/out/fonts/OpenSans-Regular-webfont.woff +0 -0
  85. package/out/global.html +220 -0
  86. package/out/index.html +128 -0
  87. package/out/interp.js.html +2064 -0
  88. package/out/merkle.js.html +143 -0
  89. package/out/msg.js.html +235 -0
  90. package/out/priv-key.js.html +208 -0
  91. package/out/pub-key.js.html +281 -0
  92. package/out/script.js.html +876 -0
  93. package/out/scripts/linenumber.js +25 -0
  94. package/out/scripts/prettify/Apache-License-2.0.txt +202 -0
  95. package/out/scripts/prettify/lang-css.js +2 -0
  96. package/out/scripts/prettify/prettify.js +28 -0
  97. package/out/sig-operations.js.html +171 -0
  98. package/out/sig.js.html +450 -0
  99. package/out/struct.js.html +440 -0
  100. package/out/styles/jsdoc-default.css +358 -0
  101. package/out/styles/prettify-jsdoc.css +111 -0
  102. package/out/styles/prettify-tomorrow.css +132 -0
  103. package/out/tx-builder.js.html +644 -0
  104. package/out/tx-in.js.html +223 -0
  105. package/out/tx-verifier.js.html +260 -0
  106. package/out/tx.js.html +481 -0
  107. package/package.json +34 -39
  108. package/vite.config.js +36 -0
  109. package/dist/bsv2.bundle.js +0 -8
  110. package/dist/bsv2.cjs.js +0 -2
  111. package/dist/bsv2.cjs.js.LICENSE.txt +0 -1
  112. package/dist/bsv2.module.js +0 -2
  113. /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. "OP_RETURN", which comes from the name of that constant in the bitcoind
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
- "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,
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
- "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,
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
- "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,
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
- "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,
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
- "INVERT": 0x83,
86
- "AND": 0x84,
87
- "OR": 0x85,
88
- "XOR": 0x86,
89
- "EQUAL": 0x87,
90
- "EQUALVERIFY": 0x88,
91
- "RESERVED1": 0x89,
92
- "RESERVED2": 0x8a,
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
- "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,
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
- "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,
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
- "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,
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
- "SMALLDATA": 0xf9,
154
- "SMALLINTEGER": 0xfa,
155
- "PUBKEYS": 0xfb,
156
- "PUBKEYHASH": 0xfd,
157
- "PUBKEY": 0xfe,
153
+ SMALLDATA: 0xf9,
154
+ SMALLINTEGER: 0xfa,
155
+ PUBKEYS: 0xfb,
156
+ PUBKEYHASH: 0xfd,
157
+ PUBKEY: 0xfe,
158
158
 
159
- "INVALIDOPCODE": 0xff
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 "OP_"+this.num.toNumber()
359
+ } else {
360
+ return 'OP_' + this.num.toNumber()
359
361
  }
360
- // throw new Error('OpCode does not have a string representation')
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
- // throw new Error('OpCode does not have a string representation')
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
@@ -40,7 +40,7 @@ class PrivKey extends Struct {
40
40
  } while (!condition)
41
41
 
42
42
  this.fromObject({
43
- bn: bn,
43
+ bn,
44
44
  compressed: true
45
45
  })
46
46
  return this
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: len,
54
- opCodeNum: 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: buf,
65
- len: len,
66
- opCodeNum: 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: buf,
77
- len: len,
78
- opCodeNum: 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: buf,
89
- len: len,
90
- opCodeNum: opCodeNum
88
+ buf,
89
+ len,
90
+ opCodeNum
91
91
  })
92
92
  } else {
93
93
  this.chunks.push({
94
- opCodeNum: 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: 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: opCodeNum
172
+ opCodeNum
173
173
  })
174
174
  i = i + 3
175
175
  } else {
176
176
  this.chunks.push({
177
- opCodeNum: 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.hasOwnProperty("num") ? chunk.opCodeNum.num : 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 = opts.noOp ? str + ' ' + new OpCode(opCodeNum).toNoOpString(): str + ' ' + new OpCode(opCodeNum).toString()
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
- str = opts.noOp ? str + ' ' + new OpCode(opCodeNum).toNoOpString(): str + ' ' + new OpCode(opCodeNum).toString()
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("hex")
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: 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: 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: buf,
329
+ buf,
331
330
  len: buf.length,
332
- opCodeNum: opCodeNum
331
+ opCodeNum
333
332
  })
334
333
  i = i + 1
335
334
  } else {
336
335
  this.chunks.push({
337
- opCodeNum: 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
- var str = ''
354
- for (var i = 0; i < this.chunks.length; i++) {
355
- var chunk = this.chunks[i]
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
- var opCodeNum = chunk.opCodeNum
364
- var str = ''
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
- var numstr = opCodeNum.toString(16)
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
- var chunks = this.chunks.slice(1)
559
- var script2 = new Script(chunks)
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("You can't push that much data")
777
+ throw new Error('You can\'t push that much data')
776
778
  }
777
779
  this.chunks.push({
778
- buf: buf,
779
- len: len,
780
- opCodeNum: 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: header,
197
- length: length,
198
- rheader: rheader,
199
- rlength: rlength,
200
- rneg: rneg,
201
- rbuf: rbuf,
202
- r: r,
203
- sheader: sheader,
204
- slength: slength,
205
- sneg: sneg,
206
- sbuf: sbuf,
207
- s: 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: buf,
139
- remainderbuf: 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
- var json = {}
316
- for (var val in this) {
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 (var i in this[val]) {
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 {
package/lib/tx.js CHANGED
@@ -44,9 +44,9 @@ class Tx extends Struct {
44
44
  this.fromObject({
45
45
  versionBytesNum: json.versionBytesNum,
46
46
  txInsVi: new VarInt().fromJSON(json.txInsVi),
47
- txIns: txIns,
47
+ txIns,
48
48
  txOutsVi: new VarInt().fromJSON(json.txOutsVi),
49
- txOuts: txOuts,
49
+ txOuts,
50
50
  nLockTime: json.nLockTime
51
51
  })
52
52
  return this
@@ -64,9 +64,9 @@ class Tx extends Struct {
64
64
  return {
65
65
  versionBytesNum: this.versionBytesNum,
66
66
  txInsVi: this.txInsVi.toJSON(),
67
- txIns: txIns,
67
+ txIns,
68
68
  txOutsVi: this.txOutsVi.toJSON(),
69
- txOuts: txOuts,
69
+ txOuts,
70
70
  nLockTime: this.nLockTime
71
71
  }
72
72
  }
@@ -208,7 +208,7 @@ class Tx extends Struct {
208
208
  bw.write(hashOutputs)
209
209
  bw.writeUInt32LE(this.nLockTime)
210
210
  bw.writeUInt32LE(nHashType >>> 0)
211
-
211
+
212
212
  return bw.toBuffer()
213
213
  }
214
214
 
@@ -297,7 +297,7 @@ class Tx extends Struct {
297
297
  const hashBuf = this.sighash(nHashType, nIn, subScript, valueBn, flags, hashCache)
298
298
  this.preImageBuf = hashBuf
299
299
  const sig = Ecdsa.sign(hashBuf, keyPair, 'little').fromObject({
300
- nHashType: nHashType
300
+ nHashType
301
301
  })
302
302
  return sig
303
303
  }