@bsv/sdk 1.1.13 → 1.1.15
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/dist/cjs/package.json +1 -1
- package/dist/cjs/src/compat/BIP39.js +272 -0
- package/dist/cjs/src/compat/BIP39.js.map +1 -0
- package/dist/cjs/src/index.js +5 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/primitives/Polynomial.js +81 -0
- package/dist/cjs/src/primitives/Polynomial.js.map +1 -0
- package/dist/cjs/src/primitives/PrivateKey.js +165 -0
- package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
- package/dist/cjs/src/primitives/index.js +5 -1
- package/dist/cjs/src/primitives/index.js.map +1 -1
- package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
- package/dist/cjs/src/script/templates/P2PKHT.js +99 -0
- package/dist/cjs/src/script/templates/P2PKHT.js.map +1 -0
- package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
- package/dist/cjs/src/totp/converters.js +14 -0
- package/dist/cjs/src/totp/converters.js.map +1 -0
- package/dist/cjs/src/totp/pike-totp.js +75 -0
- package/dist/cjs/src/totp/pike-totp.js.map +1 -0
- package/dist/cjs/src/totp/types.js +3 -0
- package/dist/cjs/src/totp/types.js.map +1 -0
- package/dist/cjs/src/transaction/broadcasters/ARC.js +4 -4
- package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -1
- package/dist/cjs/src/transaction/broadcasters/BRC22.js +25 -0
- package/dist/cjs/src/transaction/broadcasters/BRC22.js.map +1 -0
- package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
- package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +3 -3
- package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
- package/dist/cjs/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
- package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js +2 -2
- package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
- package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
- package/dist/cjs/src/transaction/http/DefaultHttpClient.js +2 -2
- package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/FetchHttpClient.js +2 -2
- package/dist/cjs/src/transaction/http/FetchHttpClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/NodejsHttpClient.js +2 -2
- package/dist/cjs/src/transaction/http/NodejsHttpClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/index.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/compat/BIP39.js +272 -0
- package/dist/esm/src/compat/BIP39.js.map +1 -0
- package/dist/esm/src/primitives/Polynomial.js +77 -0
- package/dist/esm/src/primitives/Polynomial.js.map +1 -0
- package/dist/esm/src/primitives/PrivateKey.js +143 -0
- package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
- package/dist/esm/src/primitives/index.js +2 -1
- package/dist/esm/src/primitives/index.js.map +1 -1
- package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
- package/dist/esm/src/script/templates/P2PKHT.js +96 -0
- package/dist/esm/src/script/templates/P2PKHT.js.map +1 -0
- package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
- package/dist/esm/src/totp/converters.js +9 -0
- package/dist/esm/src/totp/converters.js.map +1 -0
- package/dist/esm/src/totp/pike-totp.js +67 -0
- package/dist/esm/src/totp/pike-totp.js.map +1 -0
- package/dist/esm/src/totp/types.js +2 -0
- package/dist/esm/src/totp/types.js.map +1 -0
- package/dist/esm/src/transaction/broadcasters/ARC.js +7 -7
- package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -1
- package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
- package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
- package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +4 -4
- package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
- package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js +1 -1
- package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
- package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js +3 -3
- package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
- package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
- package/dist/esm/src/transaction/http/DefaultHttpClient.js +2 -2
- package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
- package/dist/esm/src/transaction/http/FetchHttpClient.js +2 -2
- package/dist/esm/src/transaction/http/FetchHttpClient.js.map +1 -1
- package/dist/esm/src/transaction/http/NodejsHttpClient.js +2 -2
- package/dist/esm/src/transaction/http/NodejsHttpClient.js.map +1 -1
- package/dist/esm/src/transaction/http/index.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/compat/BIP39.d.ts +132 -0
- package/dist/types/src/compat/BIP39.d.ts.map +1 -0
- package/dist/types/src/primitives/Polynomial.d.ts +32 -0
- package/dist/types/src/primitives/Polynomial.d.ts.map +1 -0
- package/dist/types/src/primitives/PrivateKey.d.ts +72 -0
- package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
- package/dist/types/src/primitives/index.d.ts +2 -1
- package/dist/types/src/primitives/index.d.ts.map +1 -1
- package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
- package/dist/types/src/script/templates/P2PKHT.d.ts +37 -0
- package/dist/types/src/script/templates/P2PKHT.d.ts.map +1 -0
- package/dist/types/src/totp/converters.d.ts +3 -0
- package/dist/types/src/totp/converters.d.ts.map +1 -0
- package/dist/types/src/totp/pike-totp.d.ts +25 -0
- package/dist/types/src/totp/pike-totp.d.ts.map +1 -0
- package/dist/types/src/totp/types.d.ts +11 -0
- package/dist/types/src/totp/types.d.ts.map +1 -0
- package/dist/types/src/transaction/broadcasters/ARC.d.ts +1 -1
- package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -1
- package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts +1 -1
- package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts.map +1 -1
- package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts +1 -1
- package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts.map +1 -1
- package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts +1 -1
- package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts.map +1 -1
- package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts +2 -2
- package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts.map +1 -1
- package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -1
- package/dist/types/src/transaction/http/DefaultHttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/FetchHttpClient.d.ts +7 -9
- package/dist/types/src/transaction/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/HttpClient.d.ts +5 -5
- package/dist/types/src/transaction/http/HttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/NodejsHttpClient.d.ts +5 -6
- package/dist/types/src/transaction/http/NodejsHttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/index.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/docs/primitives.md +231 -16
- package/docs/transaction.md +38 -37
- package/package.json +1 -1
- package/src/compat/__tests/BSM.test.ts +37 -37
- package/src/compat/__tests/ECIES.test.ts +71 -71
- package/src/compat/__tests/HD.test.ts +362 -362
- package/src/compat/__tests/Mnemonic.test.ts +147 -148
- package/src/compat/__tests/Mnemonic.vectors.ts +170 -170
- package/src/messages/__tests/EncryptedMessage.test.ts +16 -16
- package/src/primitives/Point.ts +29 -10
- package/src/primitives/Polynomial.ts +89 -0
- package/src/primitives/PrivateKey.ts +147 -1
- package/src/primitives/PublicKey.ts +17 -2
- package/src/primitives/__tests/AESGCM.test.ts +20 -20
- package/src/primitives/__tests/Hash.test.ts +2 -2
- package/src/primitives/__tests/PBKDF2.vectors.ts +93 -93
- package/src/primitives/__tests/PrivateKey.split.test.ts +70 -0
- package/src/primitives/__tests/PublicKey.test.ts +14 -1
- package/src/primitives/__tests/bug-31.test.ts +24 -26
- package/src/primitives/__tests/utils.test.ts +13 -13
- package/src/primitives/index.ts +2 -1
- package/src/script/__tests/Script.test.ts +1 -1
- package/src/script/__tests/SpendComplex.test.ts +6 -6
- package/src/script/__tests/script.invalid.vectors.ts +1464 -1464
- package/src/script/__tests/script.valid.vectors.ts +1962 -1962
- package/src/script/__tests/spend.valid.vectors.ts +1369 -1369
- package/src/script/templates/P2PKH.ts +6 -6
- package/src/script/templates/RPuzzle.ts +1 -1
- package/src/transaction/__tests/Transaction.test.ts +5 -5
- package/src/transaction/__tests/bump.invalid.vectors.ts +1 -1
- package/src/transaction/__tests/bump.valid.vectors.ts +3 -3
- package/src/transaction/broadcasters/ARC.ts +20 -21
- package/src/transaction/broadcasters/DefaultBroadcaster.ts +3 -3
- package/src/transaction/broadcasters/WhatsOnChainBroadcaster.ts +10 -10
- package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +7 -10
- package/src/transaction/chaintrackers/DefaultChainTracker.ts +3 -3
- package/src/transaction/chaintrackers/WhatsOnChain.ts +10 -12
- package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +13 -17
- package/src/transaction/fee-models/SatoshisPerKilobyte.ts +2 -2
- package/src/transaction/http/DefaultHttpClient.ts +13 -13
- package/src/transaction/http/FetchHttpClient.ts +14 -16
- package/src/transaction/http/HttpClient.ts +22 -23
- package/src/transaction/http/NodejsHttpClient.ts +23 -25
- package/src/transaction/http/index.ts +6 -6
|
@@ -6,172 +6,171 @@ import HD from '../../../dist/cjs/src/compat/HD'
|
|
|
6
6
|
import { toBase58Check, toHex, toArray } from '../../../dist/cjs/src/primitives/utils'
|
|
7
7
|
|
|
8
8
|
describe('Mnemonic', function () {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
it('should initialize the class', () => {
|
|
10
|
+
expect(Mnemonic).toBeDefined()
|
|
11
|
+
expect(new Mnemonic()).toBeDefined()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('should have a wordlist of length 2048', () => {
|
|
15
|
+
expect(enWordList.value.length).toEqual(2048)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('should handle this community-derived test vector', () => {
|
|
19
|
+
// There was a bug in Copay and bip32jp about deriving addresses with Mnemonic
|
|
20
|
+
// and bip44. This confirms we are handling the situation correctly and
|
|
21
|
+
// derive the correct value.
|
|
22
|
+
//
|
|
23
|
+
// More information here:
|
|
24
|
+
// https://github.com/iancoleman/bip39/issues/58
|
|
25
|
+
const seed = Mnemonic.fromString('fruit wave dwarf banana earth journey tattoo true farm silk olive fence').toSeed(
|
|
26
|
+
'banana'
|
|
27
|
+
)
|
|
28
|
+
let bip32 = HD.fromSeed(seed)
|
|
29
|
+
bip32 = bip32.derive("m/44'/0'/0'/0/0")
|
|
30
|
+
const pkh = bip32.pubKey.toHash()
|
|
31
|
+
const addr = toBase58Check(pkh)
|
|
32
|
+
expect(addr).toEqual('17rxURoF96VhmkcEGCj5LNQkmN9HVhWb7F')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('should generate a mnemonic phrase that passes the check', () => {
|
|
36
|
+
let mnemonic
|
|
37
|
+
|
|
38
|
+
// should be able to make a mnemonic with or without the default wordlist
|
|
39
|
+
let m = new Mnemonic().fromRandom(128)
|
|
40
|
+
expect(m.check()).toEqual(true)
|
|
41
|
+
m = new Mnemonic().fromRandom(128)
|
|
42
|
+
expect(m.check()).toEqual(true)
|
|
43
|
+
|
|
44
|
+
const entropy = Array(32)
|
|
45
|
+
entropy.fill(0)
|
|
46
|
+
m = new Mnemonic().fromEntropy(entropy)
|
|
47
|
+
expect(m.check()).toEqual(true)
|
|
48
|
+
|
|
49
|
+
mnemonic = m.mnemonic
|
|
50
|
+
|
|
51
|
+
// mnemonics with extra whitespace do not pass the check
|
|
52
|
+
m = new Mnemonic().fromString(mnemonic + ' ')
|
|
53
|
+
expect(m.check()).toEqual(false)
|
|
54
|
+
|
|
55
|
+
// mnemonics with a word replaced do not pass the check
|
|
56
|
+
const words = mnemonic.split(' ')
|
|
57
|
+
expect(words[words.length - 1]).not.toEqual('zoo')
|
|
58
|
+
words[words.length - 1] = 'zoo'
|
|
59
|
+
mnemonic = words.join(' ')
|
|
60
|
+
expect(new Mnemonic().fromString(mnemonic).check()).toEqual(false)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
describe('#toBinary', () => {
|
|
64
|
+
it('should convert to a binary array', () => {
|
|
65
|
+
const m = new Mnemonic().fromRandom()
|
|
66
|
+
expect(m.seed).toBeDefined()
|
|
67
|
+
expect(m.mnemonic).toBeDefined()
|
|
68
|
+
const buf = m.toBinary()
|
|
69
|
+
expect(buf.length).toBeGreaterThan(512 / 8 + 1 + 1)
|
|
12
70
|
})
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('#fromBinary', () => {
|
|
74
|
+
it('should convert from a binary array', () => {
|
|
75
|
+
const mA = new Mnemonic().fromRandom()
|
|
76
|
+
const mB = new Mnemonic().fromBinary(mA.toBinary())
|
|
77
|
+
expect(mA.mnemonic).toEqual(mB.mnemonic)
|
|
78
|
+
expect(toHex(mA.seed)).toEqual(toHex(mB.seed))
|
|
16
79
|
})
|
|
80
|
+
})
|
|
17
81
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// More information here:
|
|
24
|
-
// https://github.com/iancoleman/bip39/issues/58
|
|
25
|
-
const seed = Mnemonic.fromString('fruit wave dwarf banana earth journey tattoo true farm silk olive fence').toSeed(
|
|
26
|
-
'banana'
|
|
27
|
-
)
|
|
28
|
-
let bip32 = HD.fromSeed(seed)
|
|
29
|
-
bip32 = bip32.derive("m/44'/0'/0'/0/0")
|
|
30
|
-
const pkh = bip32.pubKey.toHash()
|
|
31
|
-
const addr = toBase58Check(pkh)
|
|
32
|
-
expect(addr).toEqual('17rxURoF96VhmkcEGCj5LNQkmN9HVhWb7F')
|
|
82
|
+
describe('#fromRandom', () => {
|
|
83
|
+
it('should throw an error if bits is too low', () => {
|
|
84
|
+
expect(() => {
|
|
85
|
+
new Mnemonic().fromRandom(127)
|
|
86
|
+
}).toThrow('bits must be multiple of 32')
|
|
33
87
|
})
|
|
34
88
|
|
|
35
|
-
it('should
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let m = new Mnemonic().fromRandom(128)
|
|
40
|
-
expect(m.check()).toEqual(true)
|
|
41
|
-
m = new Mnemonic().fromRandom(128)
|
|
42
|
-
expect(m.check()).toEqual(true)
|
|
43
|
-
|
|
44
|
-
const entropy = Array(32)
|
|
45
|
-
entropy.fill(0)
|
|
46
|
-
m = new Mnemonic().fromEntropy(entropy)
|
|
47
|
-
expect(m.check()).toEqual(true)
|
|
48
|
-
|
|
49
|
-
mnemonic = m.mnemonic
|
|
50
|
-
|
|
51
|
-
// mnemonics with extra whitespace do not pass the check
|
|
52
|
-
m = new Mnemonic().fromString(mnemonic + ' ')
|
|
53
|
-
expect(m.check()).toEqual(false)
|
|
54
|
-
|
|
55
|
-
// mnemonics with a word replaced do not pass the check
|
|
56
|
-
const words = mnemonic.split(' ')
|
|
57
|
-
expect(words[words.length - 1]).not.toEqual('zoo')
|
|
58
|
-
words[words.length - 1] = 'zoo'
|
|
59
|
-
mnemonic = words.join(' ')
|
|
60
|
-
expect(new Mnemonic().fromString(mnemonic).check()).toEqual(false)
|
|
89
|
+
it('should throw an error if bits is not a multiple of 32', () => {
|
|
90
|
+
expect(() => {
|
|
91
|
+
new Mnemonic().fromRandom(256 - 1)
|
|
92
|
+
}).toThrow('bits must be multiple of 32')
|
|
61
93
|
})
|
|
94
|
+
})
|
|
62
95
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const buf = m.toBinary()
|
|
69
|
-
expect(buf.length).toBeGreaterThan(512 / 8 + 1 + 1)
|
|
70
|
-
})
|
|
96
|
+
describe('@fromRandom', () => {
|
|
97
|
+
it('should throw an error if bits is too low', () => {
|
|
98
|
+
expect(() => {
|
|
99
|
+
Mnemonic.fromRandom(127)
|
|
100
|
+
}).toThrow('bits must be multiple of 32')
|
|
71
101
|
})
|
|
72
102
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
expect(mA.mnemonic).toEqual(mB.mnemonic)
|
|
78
|
-
expect(toHex(mA.seed as number[])).toEqual(toHex(mB.seed as number[]))
|
|
79
|
-
})
|
|
103
|
+
it('should throw an error if bits is not a multiple of 32', () => {
|
|
104
|
+
expect(() => {
|
|
105
|
+
Mnemonic.fromRandom(256 - 1)
|
|
106
|
+
}).toThrow('bits must be multiple of 32')
|
|
80
107
|
})
|
|
108
|
+
})
|
|
81
109
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}).toThrow('bits must be multiple of 32')
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('should throw an error if bits is not a multiple of 32', () => {
|
|
90
|
-
expect(() => {
|
|
91
|
-
new Mnemonic().fromRandom(256 - 1)
|
|
92
|
-
}).toThrow('bits must be multiple of 32')
|
|
93
|
-
})
|
|
110
|
+
describe('#fromEntropy', () => {
|
|
111
|
+
it('should build from entropy', () => {
|
|
112
|
+
const m = new Mnemonic().fromEntropy(Random(32))
|
|
113
|
+
expect(m).toBeDefined()
|
|
94
114
|
})
|
|
115
|
+
})
|
|
95
116
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}).toThrow('bits must be multiple of 32')
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('should throw an error if bits is not a multiple of 32', () => {
|
|
104
|
-
expect(() => {
|
|
105
|
-
Mnemonic.fromRandom(256 - 1)
|
|
106
|
-
}).toThrow('bits must be multiple of 32')
|
|
107
|
-
})
|
|
117
|
+
describe('@fromEntropy', () => {
|
|
118
|
+
it('should build from entropy', () => {
|
|
119
|
+
const m = Mnemonic.fromEntropy(Random(32))
|
|
120
|
+
expect(m).toBeDefined()
|
|
108
121
|
})
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
it('should build from entropy', () => {
|
|
119
|
-
const m = Mnemonic.fromEntropy(Random(32))
|
|
120
|
-
expect(m).toBeDefined()
|
|
121
|
-
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
describe('#entropy2Mnemonic', () => {
|
|
125
|
+
it('should throw an error if you do not use enough entropy', () => {
|
|
126
|
+
const buf = Buffer.alloc(128 / 8 - 1)
|
|
127
|
+
buf.fill(0)
|
|
128
|
+
expect(() => {
|
|
129
|
+
new Mnemonic().entropy2Mnemonic([...buf])
|
|
130
|
+
}).toThrow('Entropy is less than 128 bits. It must be 128 bits or more.')
|
|
122
131
|
})
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe('#fromString', () => {
|
|
135
|
+
it('should throw an error in invalid mnemonic', () => {
|
|
136
|
+
expect(() => {
|
|
137
|
+
new Mnemonic().fromString('invalid mnemonic').toSeed()
|
|
138
|
+
}).toThrow(
|
|
139
|
+
'Mnemonic does not pass the check - was the mnemonic typed incorrectly? Are there extra spaces?'
|
|
140
|
+
)
|
|
132
141
|
})
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
describe('@isValid', () => {
|
|
145
|
+
it('should know this is valid', () => {
|
|
146
|
+
const isValid = Mnemonic.isValid(
|
|
147
|
+
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
|
|
148
|
+
'TREZOR'
|
|
149
|
+
)
|
|
150
|
+
expect(isValid).toBe(true)
|
|
142
151
|
})
|
|
143
152
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
expect(isValid).toBe(true)
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
it('should know this is invalid', () => {
|
|
154
|
-
const isValid = Mnemonic.isValid(
|
|
155
|
-
'abandonnnnnnn abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
|
|
156
|
-
'TREZOR'
|
|
157
|
-
)
|
|
158
|
-
expect(isValid).toEqual(false)
|
|
159
|
-
})
|
|
153
|
+
it('should know this is invalid', () => {
|
|
154
|
+
const isValid = Mnemonic.isValid(
|
|
155
|
+
'abandonnnnnnn abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
|
|
156
|
+
'TREZOR'
|
|
157
|
+
)
|
|
158
|
+
expect(isValid).toEqual(false)
|
|
160
159
|
})
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
describe('vectors', () => {
|
|
163
|
+
// eslint-disable-next-line ban/ban
|
|
164
|
+
vectors.english.forEach((vector, v) => {
|
|
165
|
+
it('should pass english test vector ' + v, () => {
|
|
166
|
+
const entropy = toArray(vector.entropy, 'hex')
|
|
167
|
+
const m = new Mnemonic().fromEntropy(entropy)
|
|
168
|
+
expect(m.toString()).toEqual(vector.mnemonic)
|
|
169
|
+
expect(m.check()).toEqual(true)
|
|
170
|
+
const seed = m.toSeed(vector.passphrase)
|
|
171
|
+
expect(toHex(seed)).toEqual(vector.seed)
|
|
172
|
+
expect(HD.fromSeed(seed).toString()).toEqual(vector.bip32_xprv)
|
|
173
|
+
})
|
|
176
174
|
})
|
|
175
|
+
})
|
|
177
176
|
})
|