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.
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 +190 -26
  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 +8 -7
  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/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
  }
@@ -140,7 +140,7 @@ class Tx extends Struct {
140
140
  * p2sh transaction, subScript is usually the redeemScript. If you're not
141
141
  * normal because you're using OP_CODESEPARATORs, you know what to do.
142
142
  */
143
- sighash (nHashType, nIn, subScript, valueBn, flags = 0, hashCache = new HashCache()) {
143
+ sighash (nHashType, nIn, subScript, valueBn, flags = Tx.SCRIPT_ENABLE_SIGHASH_FORKID, hashCache = new HashCache()) {
144
144
  const buf = this.sighashPreimage(nHashType, nIn, subScript, valueBn, flags, hashCache)
145
145
  if (buf.compare(Buffer.from('0000000000000000000000000000000000000000000000000000000000000001', 'hex')) === 0) {
146
146
  return buf
@@ -160,7 +160,7 @@ class Tx extends Struct {
160
160
  return workersResult.resbuf
161
161
  }
162
162
 
163
- sighashPreimage (nHashType, nIn, subScript, valueBn, flags = 0, hashCache = new HashCache()) {
163
+ sighashPreimage (nHashType, nIn, subScript, valueBn, flags = Tx.SCRIPT_ENABLE_SIGHASH_FORKID, hashCache = new HashCache()) {
164
164
  // start with UAHF part (Bitcoin SV)
165
165
  // https://github.com/Bitcoin-UAHF/spec/blob/master/replay-protected-sighash.md
166
166
  if (
@@ -295,8 +295,9 @@ class Tx extends Struct {
295
295
  // This function returns a signature but does not update any inputs
296
296
  sign (keyPair, nHashType = Sig.SIGHASH_ALL | Sig.SIGHASH_FORKID, nIn, subScript, valueBn, flags = Tx.SCRIPT_ENABLE_SIGHASH_FORKID, hashCache = {}) {
297
297
  const hashBuf = this.sighash(nHashType, nIn, subScript, valueBn, flags, hashCache)
298
+ this.preImageBuf = hashBuf
298
299
  const sig = Ecdsa.sign(hashBuf, keyPair, 'little').fromObject({
299
- nHashType: nHashType
300
+ nHashType
300
301
  })
301
302
  return sig
302
303
  }
package/load-babel.js CHANGED
@@ -1,3 +1,5 @@
1
- require('@babel/register')({
1
+ import babelRegister from "@babel/register"
2
+
3
+ babelRegister({
2
4
  configFile: './.babelrc.test'
3
5
  })
package/mtest/test.html CHANGED
@@ -4,12 +4,14 @@
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
6
  <title>Test</title>
7
- <script type="text/javascript" src="../dist/bsv2.bundle.js"></script>
8
- <script type="text/javascript">
9
- console.log(bsv2)
7
+ <script type="text/javascript" src="https://bsv.direct/lib/bsv2.umd.js"></script>
8
+ <script type="module" src="https://bsv.direct/lib/bsv2.mjs"></script>
9
+
10
+ <script type="module">
11
+ console.log(window)
10
12
  </script>
11
13
  </head>
12
14
  <body>
13
-
15
+ Hola
14
16
  </body>
15
17
  </html>
package/mtest/test.js CHANGED
@@ -1,2 +1,2 @@
1
- let bsv2 =require ('../dist/bsv.cjs.js');
1
+ let bsv2 =require ('../dist/bsv2.umd.js');
2
2
  console.log(bsv2)
package/out/Sig.html ADDED
@@ -0,0 +1,541 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>JSDoc: Class: Sig</title>
6
+
7
+ <script src="scripts/prettify/prettify.js"> </script>
8
+ <script src="scripts/prettify/lang-css.js"> </script>
9
+ <!--[if lt IE 9]>
10
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11
+ <![endif]-->
12
+ <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13
+ <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14
+ </head>
15
+
16
+ <body>
17
+
18
+ <div id="main">
19
+
20
+ <h1 class="page-title">Class: Sig</h1>
21
+
22
+
23
+
24
+
25
+
26
+
27
+ <section>
28
+
29
+ <header>
30
+
31
+ <h2><span class="attribs"><span class="type-signature"></span></span>Sig<span class="signature">()</span><span class="type-signature"></span></h2>
32
+
33
+ <div class="class-description">r, s: big numbers constiting a cryptographic signature
34
+ nHashType: found at the end of a signature in a transaction
35
+ recovery: public key recovery number
36
+ compressed: whether the recovered pubKey is compressed</div>
37
+
38
+
39
+ </header>
40
+
41
+ <article>
42
+ <div class="container-overview">
43
+
44
+
45
+
46
+
47
+ <h2>Constructor</h2>
48
+
49
+
50
+
51
+ <h4 class="name" id="Sig"><span class="type-signature"></span>new Sig<span class="signature">()</span><span class="type-signature"></span></h4>
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+ <dl class="details">
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+ <dt class="tag-source">Source:</dt>
98
+ <dd class="tag-source"><ul class="dummy"><li>
99
+ <a href="sig.js.html">sig.js</a>, <a href="sig.js.html#line31">line 31</a>
100
+ </li></ul></dd>
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+ </dl>
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+ </div>
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+ <h3 class="subsection-title">Methods</h3>
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+ <h4 class="name" id="hasDefinedHashType"><span class="type-signature"></span>hasDefinedHashType<span class="signature">()</span><span class="type-signature"></span></h4>
156
+
157
+
158
+
159
+
160
+
161
+
162
+ <div class="description">
163
+ Ensures the nHashType is exactly equal to one of the standard options or combinations thereof.
164
+ Translated from bitcoind's IsDefinedHashtypeSignature
165
+ </div>
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+ <dl class="details">
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+ <dt class="tag-source">Source:</dt>
207
+ <dd class="tag-source"><ul class="dummy"><li>
208
+ <a href="sig.js.html">sig.js</a>, <a href="sig.js.html#line317">line 317</a>
209
+ </li></ul></dd>
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+ </dl>
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+ <h4 class="name" id="hasLowS"><span class="type-signature"></span>hasLowS<span class="signature">()</span><span class="type-signature"></span></h4>
245
+
246
+
247
+
248
+
249
+
250
+
251
+ <div class="description">
252
+ Compares to bitcoind's IsLowDERSignature
253
+ See also Ecdsa signature algorithm which enforces this.
254
+ See also Bip 62, "low S values in signatures"
255
+ </div>
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+ <dl class="details">
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+ <dt class="tag-source">Source:</dt>
297
+ <dd class="tag-source"><ul class="dummy"><li>
298
+ <a href="sig.js.html">sig.js</a>, <a href="sig.js.html#line296">line 296</a>
299
+ </li></ul></dd>
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+ </dl>
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+ <h4 class="name" id=".IsTxDer"><span class="type-signature">(static) </span>IsTxDer<span class="signature">()</span><span class="type-signature"></span></h4>
335
+
336
+
337
+
338
+
339
+
340
+
341
+ <div class="description">
342
+ This function is translated from bitcoind's IsDERSignature and is used in
343
+ the script interpreter. This "DER" format actually includes an extra byte,
344
+ the nHashType, at the end. It is really the tx format, not DER format.
345
+
346
+ A canonical signature exists of: [30] [total len] [02] [len R] [R] [02] [len S] [S] [hashtype]
347
+ Where R and S are not negative (their first byte has its highest bit not set), and not
348
+ excessively padded (do not start with a 0 byte, unless an otherwise negative number follows,
349
+ in which case a single 0 byte is necessary and even required).
350
+
351
+ See https://bitcointalk.org/index.php?topic=8392.msg127623#msg127623
352
+ </div>
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+ <dl class="details">
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+ <dt class="tag-source">Source:</dt>
394
+ <dd class="tag-source"><ul class="dummy"><li>
395
+ <a href="sig.js.html">sig.js</a>, <a href="sig.js.html#line225">line 225</a>
396
+ </li></ul></dd>
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+ </dl>
405
+
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+ <h4 class="name" id=".parseDer"><span class="type-signature">(static) </span>parseDer<span class="signature">()</span><span class="type-signature"></span></h4>
432
+
433
+
434
+
435
+
436
+
437
+
438
+ <div class="description">
439
+ In order to mimic the non-strict DER encoding of OpenSSL, set strict = false.
440
+ </div>
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+ <dl class="details">
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+ <dt class="tag-source">Source:</dt>
482
+ <dd class="tag-source"><ul class="dummy"><li>
483
+ <a href="sig.js.html">sig.js</a>, <a href="sig.js.html#line141">line 141</a>
484
+ </li></ul></dd>
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+ </dl>
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+ </article>
520
+
521
+ </section>
522
+
523
+
524
+
525
+
526
+ </div>
527
+
528
+ <nav>
529
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sig.html">Sig</a></li></ul><h3>Global</h3><ul><li><a href="global.html#decorate">decorate</a></li></ul>
530
+ </nav>
531
+
532
+ <br class="clear">
533
+
534
+ <footer>
535
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Fri Feb 28 2025 03:51:24 GMT+0100 (hora estándar de Europa central)
536
+ </footer>
537
+
538
+ <script> prettyPrint(); </script>
539
+ <script src="scripts/linenumber.js"> </script>
540
+ </body>
541
+ </html>