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/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
|
-
|
|
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 = {
|
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.
|
|
102
|
-
bsv.env = process.env
|
|
98
|
+
bsv.env = import.meta.env
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
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
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
this.Wordlist = en
|
|
31
|
+
this.es = es
|
|
32
|
+
this.jp = jp
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
setLang (lang){
|
|
37
|
-
switch(lang){
|
|
38
|
-
|
|
39
|
-
case
|
|
40
|
-
case
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}else if(buf.byteLength <= nMaxNumSize){
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
package/lib/config.js
CHANGED
package/lib/constants.js
CHANGED
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
|
|
111
|
-
keyPair: new KeyPair().fromObject({ pubKey
|
|
112
|
-
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
|
|
279
|
-
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
|
|
287
|
-
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
|
|
403
|
-
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
|
|
456
|
-
endian
|
|
457
|
-
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
|
|
465
|
-
endian
|
|
466
|
-
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
|
|
476
|
-
endian
|
|
477
|
-
sig
|
|
478
|
-
keyPair: new KeyPair().fromObject({ 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
|
|
486
|
-
endian
|
|
487
|
-
sig
|
|
488
|
-
keyPair: new KeyPair().fromObject({ 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
|