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/entry.js CHANGED
@@ -13,10 +13,9 @@ import bs58 from 'bs58'
13
13
  import elliptic from 'bitcoin-elliptic'
14
14
  import hashjs from 'hash.js'
15
15
  import pbkdf2 from 'pbkdf2'
16
- import { Buffer } from 'buffer';
16
+ import { Buffer } from 'buffer'
17
17
 
18
- // version string.
19
- import pkgInfo from './package.json' assert {type: 'json'};
18
+ import pkgInfo from './package.json' with { type: 'json' }
20
19
 
21
20
  // Dependencies, subject to change.
22
21
  const deps = {
@@ -0,0 +1,8 @@
1
+ import globals from "globals";
2
+ import pluginJs from "@eslint/js";
3
+
4
+
5
+ /** @type {import('eslint').Linter.Config[]} */
6
+ export default [
7
+ {languageOptions: { globals: {...globals.browser, ...globals.node} }},
8
+ ];
package/index.js CHANGED
@@ -14,9 +14,6 @@
14
14
  * const Address = require('bsv/lib/address').
15
15
  */
16
16
  'use strict'
17
- if (!global._babelPolyfill) {
18
- require('babel-polyfill')
19
- }
20
17
  require('./lib/config')
21
18
 
22
19
  const bsv = module.exports
@@ -98,5 +95,4 @@ Object.keys(bsv).forEach(function (key) {
98
95
  bsv.Mainnet = Mainnet
99
96
  bsv.Testnet = Testnet
100
97
 
101
- bsv.browser = process.browser
102
- bsv.env = process.env
98
+ bsv.env = import.meta.env
@@ -1,8 +1,7 @@
1
- const webpack = require('webpack')
1
+ import webpack from 'webpack';
2
2
  // Karma configuration
3
3
  // Generated on Sat May 16 2020 20:12:10 GMT-0300 (Argentina Standard Time)
4
-
5
- module.exports = function (config) {
4
+ export function (config) {
6
5
  config.set({
7
6
 
8
7
  // base path that will be used to resolve all patterns (eg. files, exclude)
package/lib/ach.js CHANGED
@@ -10,11 +10,11 @@
10
10
  */
11
11
  'use strict'
12
12
 
13
- import { Aescbc } from './aescbc'
14
- import { Hash } from './hash'
15
- import { Random } from './random'
16
- import { Workers } from './workers'
17
- import { cmp } from './cmp'
13
+ import { Aescbc } from './aescbc.js'
14
+ import { Hash } from './hash.js'
15
+ import { Random } from './random.js'
16
+ import { Workers } from './workers.js'
17
+ import { cmp } from './cmp.js'
18
18
 
19
19
  class Ach { }
20
20
 
package/lib/address.js CHANGED
@@ -18,15 +18,15 @@
18
18
  */
19
19
  'use strict'
20
20
 
21
- import { Base58Check } from './base-58-check'
22
- import { Constants } from './constants'
23
- import { Hash } from './hash'
24
- import { OpCode } from './op-code'
25
- import { PubKey } from './pub-key'
26
- import { PrivKey } from './priv-key'
27
- import { Script } from './script'
28
- import { Struct } from './struct'
29
- import { Workers } from './workers'
21
+ import { Base58Check } from './base-58-check.js'
22
+ import { Constants } from './constants.js'
23
+ import { Hash } from './hash.js'
24
+ import { OpCode } from './op-code.js'
25
+ import { PubKey } from './pub-key.js'
26
+ import { PrivKey } from './priv-key.js'
27
+ import { Script } from './script.js'
28
+ import { Struct } from './struct.js'
29
+ import { Workers } from './workers.js'
30
30
 
31
31
  class Address extends Struct {
32
32
  constructor (versionByteNum, hashBuf, constants = null) {
@@ -152,6 +152,7 @@ class Address extends Struct {
152
152
  let address
153
153
  try {
154
154
  address = new Address().fromString(addrstr)
155
+
155
156
  } catch (e) {
156
157
  return false
157
158
  }
@@ -162,6 +163,7 @@ class Address extends Struct {
162
163
  try {
163
164
  this.validate()
164
165
  return true
166
+
165
167
  } catch (e) {
166
168
  return false
167
169
  }
package/lib/aescbc.js CHANGED
@@ -8,9 +8,9 @@
8
8
  */
9
9
  'use strict'
10
10
 
11
- import { Aes } from './aes'
12
- import { Cbc } from './cbc'
13
- import { Random } from './random'
11
+ import { Aes } from './aes.js'
12
+ import { Cbc } from './cbc.js'
13
+ import { Random } from './random.js'
14
14
 
15
15
  class Aescbc { }
16
16
 
package/lib/bip-39.js CHANGED
@@ -21,25 +21,25 @@ import { Hash } from './hash'
21
21
  import pbkdf2 from 'pbkdf2'
22
22
  import { Random } from './random'
23
23
  import { Struct } from './struct'
24
- import {en, es, jp} from './bip-39-words'
24
+ import { en, es, jp } from './bip-39-words'
25
25
  import { Workers } from './workers'
26
26
 
27
27
  class Bip39 extends Struct {
28
- constructor (mnemonic, seed, wordlist ) {
28
+ constructor (mnemonic, seed, wordlist) {
29
29
  super({ mnemonic, seed, wordlist })
30
- this.Wordlist = en
31
- this.es = es
32
- this.jp = jp
33
-
30
+ this.Wordlist = en
31
+ this.es = es
32
+ this.jp = jp
34
33
  }
35
34
 
36
- setLang (lang){
37
- switch(lang){
38
- default: case "en": this.Wordlist = en; break;
39
- case "es": this.Wordlist = es; break;
40
- case "jp": this.Wordlist = jp; break;
35
+ setLang (lang) {
36
+ switch (lang) {
37
+ case 'es': this.Wordlist = es; break
38
+ case 'jp': this.Wordlist = jp; break
39
+ case 'en': default: this.Wordlist = en; break
41
40
  }
42
41
  }
42
+
43
43
  toBw (bw) {
44
44
  if (!bw) {
45
45
  bw = new Bw()
@@ -271,6 +271,7 @@ class Bip39 extends Struct {
271
271
  let isValid
272
272
  try {
273
273
  isValid = !!this.mnemonic2Seed(passphrase)
274
+
274
275
  } catch (err) {
275
276
  isValid = false
276
277
  }
package/lib/block.js CHANGED
@@ -35,7 +35,7 @@ class Block extends Struct {
35
35
  this.fromObject({
36
36
  blockHeader: new BlockHeader().fromJSON(json.blockHeader),
37
37
  txsVi: new VarInt().fromJSON(json.txsVi),
38
- txs: txs
38
+ txs
39
39
  })
40
40
  return this
41
41
  }
@@ -48,7 +48,7 @@ class Block extends Struct {
48
48
  return {
49
49
  blockHeader: this.blockHeader.toJSON(),
50
50
  txsVi: this.txsVi.toJSON(),
51
- txs: txs
51
+ txs
52
52
  }
53
53
  }
54
54
 
package/lib/bn.js CHANGED
@@ -271,9 +271,8 @@ Bn.prototype.fromScriptNumBuffer = function (
271
271
  buf,
272
272
  fRequireMinimal,
273
273
  nMaxNumSize,
274
- big_int = false
274
+ bigInt = false
275
275
  ) {
276
-
277
276
  if (nMaxNumSize === undefined) {
278
277
  nMaxNumSize = 4
279
278
  }
@@ -281,7 +280,6 @@ Bn.prototype.fromScriptNumBuffer = function (
281
280
  throw new Error(`script number overflow nMaxNumSize: ${nMaxNumSize}`)
282
281
  }
283
282
 
284
-
285
283
  if (fRequireMinimal && buf.length > 0) {
286
284
  // Check that the number is encoded with the minimum possible
287
285
  // number of bytes.
@@ -302,20 +300,16 @@ Bn.prototype.fromScriptNumBuffer = function (
302
300
  }
303
301
  // TODO?
304
302
  // https://github.com/bitcoin-sv/bitcoin-sv/blob/4d3444909a5a98f129d3d2991bf8f0f7f15d3969/src/script/script_num.cpp#L34
305
- if (buf.byteLength===0){
306
- if(big_int){
307
- //m_value = bint{0};
308
- }
309
- }else if(buf.byteLength <= nMaxNumSize){
310
- if (big_int){
311
- // m_value = bsv::bint::deserialize(span);
312
-
313
- }else{
314
- // m_value = bsv::deserialize<int64_t>(span.begin(), span.end());
315
-
316
-
317
- }
318
-
303
+ if (buf.byteLength === 0) {
304
+ if (bigInt) {
305
+ // m_value = bint{0};
306
+ }
307
+ } else if (buf.byteLength <= nMaxNumSize) {
308
+ if (bigInt) {
309
+ // m_value = bsv::bint::deserialize(span);
310
+ } else {
311
+ // m_value = bsv::deserialize<int64_t>(span.begin(), span.end());
312
+ }
319
313
  }
320
314
 
321
315
  return this.fromSm(buf, { endian: 'little' })
@@ -325,6 +319,7 @@ Bn.prototype.fromScriptNumBuffer = function (
325
319
  // an error if the output is larger than four bytes. (Which can happen if
326
320
  // performing a numerical operation that results in an overflow to more than 4
327
321
  // bytes).
322
+
328
323
  Bn.prototype.toScriptNumBuffer = function (buf) {
329
324
  return this.toSm({ endian: 'little' })
330
325
  }
package/lib/bsm.js CHANGED
@@ -83,7 +83,7 @@ class Bsm extends Struct {
83
83
  sign () {
84
84
  const hashBuf = Bsm.magicHash(this.messageBuf)
85
85
  const ecdsa = new Ecdsa().fromObject({
86
- hashBuf: hashBuf,
86
+ hashBuf,
87
87
  keyPair: this.keyPair
88
88
  })
89
89
  ecdsa.sign()
package/lib/config.js CHANGED
@@ -44,7 +44,7 @@ class ConfigBuilder {
44
44
  }
45
45
 
46
46
  const config = new ConfigBuilder()
47
- .addValue('NETWORK', process.env.NETWORK || 'mainnet')
47
+ .addValue('NETWORK', import.meta.env.NETWORK || 'mainnet')
48
48
  .build()
49
49
 
50
50
  export { config }
package/lib/constants.js CHANGED
@@ -33,7 +33,7 @@ Constants.Mainnet = {
33
33
  },
34
34
  TxBuilder: {
35
35
  dust: 0, // number of satoshis that an output can't be less than
36
- feePerKbNum: 0.00000050e8
36
+ feePerKbNum: 1
37
37
  },
38
38
  Workers: {
39
39
  // Cannot be 5 seconds. This is actually too low for low end devices. We
package/lib/ecdsa.js CHANGED
@@ -75,6 +75,7 @@ class Ecdsa extends Struct {
75
75
  this.sig.recovery = recovery
76
76
  try {
77
77
  Qprime = this.sig2PubKey()
78
+
78
79
  } catch (e) {
79
80
  continue
80
81
  }
@@ -107,9 +108,9 @@ class Ecdsa extends Struct {
107
108
  */
108
109
  static calcrecovery (sig, pubKey, hashBuf) {
109
110
  const ecdsa = new Ecdsa().fromObject({
110
- sig: sig,
111
- keyPair: new KeyPair().fromObject({ pubKey: pubKey }),
112
- hashBuf: hashBuf
111
+ sig,
112
+ keyPair: new KeyPair().fromObject({ pubKey }),
113
+ hashBuf
113
114
  })
114
115
  return ecdsa.calcrecovery().sig
115
116
  }
@@ -275,16 +276,16 @@ class Ecdsa extends Struct {
275
276
 
276
277
  static sig2PubKey (sig, hashBuf) {
277
278
  const ecdsa = new Ecdsa().fromObject({
278
- sig: sig,
279
- hashBuf: hashBuf
279
+ sig,
280
+ hashBuf
280
281
  })
281
282
  return ecdsa.sig2PubKey()
282
283
  }
283
284
 
284
285
  static async asyncSig2PubKey (sig, hashBuf) {
285
286
  const ecdsa = new Ecdsa().fromObject({
286
- sig: sig,
287
- hashBuf: hashBuf
287
+ sig,
288
+ hashBuf
288
289
  })
289
290
  const pubKey = await ecdsa.asyncSig2PubKey()
290
291
  return pubKey
@@ -399,8 +400,8 @@ class Ecdsa extends Struct {
399
400
  s = Point.getN().sub(s)
400
401
  }
401
402
  this.sig = Sig.fromObject({
402
- r: r,
403
- s: s,
403
+ r,
404
+ s,
404
405
  compressed: this.keyPair.pubKey.compressed
405
406
  })
406
407
  return this
@@ -452,18 +453,18 @@ class Ecdsa extends Struct {
452
453
  static sign (hashBuf, keyPair, endian) {
453
454
  return new Ecdsa()
454
455
  .fromObject({
455
- hashBuf: hashBuf,
456
- endian: endian,
457
- keyPair: keyPair
456
+ hashBuf,
457
+ endian,
458
+ keyPair
458
459
  })
459
460
  .sign().sig
460
461
  }
461
462
 
462
463
  static async asyncSign (hashBuf, keyPair, endian) {
463
464
  const ecdsa = new Ecdsa().fromObject({
464
- hashBuf: hashBuf,
465
- endian: endian,
466
- keyPair: keyPair
465
+ hashBuf,
466
+ endian,
467
+ keyPair
467
468
  })
468
469
  await ecdsa.asyncSign()
469
470
  return ecdsa.sig
@@ -472,20 +473,20 @@ class Ecdsa extends Struct {
472
473
  static verify (hashBuf, sig, pubKey, endian, enforceLowS = true) {
473
474
  return new Ecdsa()
474
475
  .fromObject({
475
- hashBuf: hashBuf,
476
- endian: endian,
477
- sig: sig,
478
- keyPair: new KeyPair().fromObject({ pubKey: pubKey })
476
+ hashBuf,
477
+ endian,
478
+ sig,
479
+ keyPair: new KeyPair().fromObject({ pubKey })
479
480
  })
480
481
  .verify(enforceLowS).verified
481
482
  }
482
483
 
483
484
  static async asyncVerify (hashBuf, sig, pubKey, endian, enforceLowS = true) {
484
485
  const ecdsa = new Ecdsa().fromObject({
485
- hashBuf: hashBuf,
486
- endian: endian,
487
- sig: sig,
488
- keyPair: new KeyPair().fromObject({ pubKey: pubKey })
486
+ hashBuf,
487
+ endian,
488
+ sig,
489
+ keyPair: new KeyPair().fromObject({ pubKey })
489
490
  })
490
491
  await ecdsa.asyncVerify(enforceLowS)
491
492
  return ecdsa.verified