@smartledger/bsv 9.0.0 → 9.1.1

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 (155) hide show
  1. package/CHANGELOG.md +164 -0
  2. package/README.md +152 -1041
  3. package/STABILITY.md +134 -0
  4. package/bsv-gdaf.min.js +53 -48
  5. package/bsv-ltp.min.js +23 -18
  6. package/bsv-smartcontract.min.js +18 -18
  7. package/bsv.bundle.js +53 -48
  8. package/bsv.min.js +53 -48
  9. package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
  10. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  11. package/docs/getting-started/INSTALLATION.md +23 -23
  12. package/docs/getting-started/QUICK_START.md +7 -7
  13. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  14. package/docs/proposals/10.0.0-package-split.md +131 -0
  15. package/index.js +5 -0
  16. package/lib/block/merkleblock.js +53 -9
  17. package/lib/hdprivatekey.js +15 -0
  18. package/lib/script/interpreter.js +109 -1
  19. package/lib/smart_contract/builder.js +14 -0
  20. package/lib/util/deprecate.js +159 -0
  21. package/package.json +19 -82
  22. package/version.js +1 -1
  23. package/.mocharc.json +0 -5
  24. package/test/address.js +0 -629
  25. package/test/block/block.js +0 -239
  26. package/test/block/blockheader.js +0 -270
  27. package/test/block/merkleblock.js +0 -207
  28. package/test/build/bundle_crypto_shim.js +0 -104
  29. package/test/build/bundle_externals.js +0 -125
  30. package/test/build/bundle_smoke.js +0 -55
  31. package/test/build/esbuild_main.js +0 -65
  32. package/test/build/esm_wrapper.js +0 -97
  33. package/test/build/exports_resolution.js +0 -84
  34. package/test/build/version_sync.js +0 -14
  35. package/test/cli/smoke.js +0 -261
  36. package/test/consensus/base58-vectors.js +0 -120
  37. package/test/consensus/sv-script-vectors.js +0 -81
  38. package/test/consensus/sv-sighash-vectors.js +0 -51
  39. package/test/consensus/sv-tx-vectors.js +0 -48
  40. package/test/credentials-test.js +0 -332
  41. package/test/crypto/backend_selection.js +0 -126
  42. package/test/crypto/bn.js +0 -168
  43. package/test/crypto/ecdsa.js +0 -426
  44. package/test/crypto/elliptic-fixed.js +0 -61
  45. package/test/crypto/hash.browser.js +0 -121
  46. package/test/crypto/hash.js +0 -122
  47. package/test/crypto/point.js +0 -193
  48. package/test/crypto/random.js +0 -105
  49. package/test/crypto/security.js +0 -176
  50. package/test/crypto/shamir.js +0 -177
  51. package/test/crypto/shamir_rngcap.js +0 -29
  52. package/test/crypto/signature.js +0 -399
  53. package/test/data/bip69.json +0 -215
  54. package/test/data/bitcoin-sv/README.md +0 -170
  55. package/test/data/bitcoin-sv/base58_encode_decode.json +0 -14
  56. package/test/data/bitcoin-sv/base58_keys_invalid.json +0 -152
  57. package/test/data/bitcoin-sv/base58_keys_valid.json +0 -452
  58. package/test/data/bitcoin-sv/script_tests.json +0 -2591
  59. package/test/data/bitcoin-sv/sighash.json +0 -1003
  60. package/test/data/bitcoin-sv/tx_invalid.json +0 -285
  61. package/test/data/bitcoin-sv/tx_valid.json +0 -367
  62. package/test/data/bitcoind/base58_keys_invalid.json +0 -152
  63. package/test/data/bitcoind/base58_keys_valid.json +0 -452
  64. package/test/data/bitcoind/blocks.json +0 -27
  65. package/test/data/bitcoind/script_tests.json +0 -2244
  66. package/test/data/bitcoind/sig_canonical.json +0 -7
  67. package/test/data/bitcoind/sig_noncanonical.json +0 -22
  68. package/test/data/bitcoind/tx_invalid.json +0 -177
  69. package/test/data/bitcoind/tx_valid.json +0 -224
  70. package/test/data/blk86756-testnet.dat +0 -0
  71. package/test/data/blk86756-testnet.js +0 -12
  72. package/test/data/blk86756-testnet.json +0 -684
  73. package/test/data/brc220-batch-vector.json +0 -129
  74. package/test/data/ecdsa.json +0 -230
  75. package/test/data/merkleblocks.js +0 -486
  76. package/test/data/messages.json +0 -22
  77. package/test/data/sighash.json +0 -1004
  78. package/test/data/tx_creation.json +0 -85
  79. package/test/didweb/relationships.js +0 -144
  80. package/test/ecies/bitcore-ecies.js +0 -178
  81. package/test/ecies/electrum-ecies.js +0 -206
  82. package/test/encoding/base58.js +0 -131
  83. package/test/encoding/base58check.js +0 -145
  84. package/test/encoding/bufferreader.js +0 -328
  85. package/test/encoding/bufferwriter.js +0 -160
  86. package/test/encoding/varint.js +0 -104
  87. package/test/gdaf/anchor_no_key_leak.js +0 -146
  88. package/test/gdaf/anchor_spv.js +0 -163
  89. package/test/gdaf/canonicalization.js +0 -106
  90. package/test/gdaf/canonicalize.js +0 -140
  91. package/test/gdaf/zk_prover.js +0 -204
  92. package/test/hdkeys.js +0 -365
  93. package/test/hdprivatekey.js +0 -339
  94. package/test/hdpublickey.js +0 -293
  95. package/test/index.js +0 -16
  96. package/test/ltp/ids.js +0 -74
  97. package/test/ltp/right.js +0 -198
  98. package/test/ltp/verify_failclosed.js +0 -134
  99. package/test/message/message.js +0 -190
  100. package/test/mnemonic/data/fixtures.json +0 -300
  101. package/test/mnemonic/mnemonic.js +0 -277
  102. package/test/mnemonic/mocha.opts +0 -1
  103. package/test/mnemonic/pbkdf2.test.js +0 -43
  104. package/test/networks.js +0 -207
  105. package/test/notaryhash/batch_leaf.js +0 -140
  106. package/test/notaryhash/batch_vector.js +0 -282
  107. package/test/notaryhash/certificate.js +0 -249
  108. package/test/notaryhash/encoding.js +0 -186
  109. package/test/notaryhash/interop.js +0 -112
  110. package/test/notaryhash/merkle.js +0 -181
  111. package/test/notaryhash/script.js +0 -270
  112. package/test/notaryhash/verify.js +0 -342
  113. package/test/opcode.js +0 -186
  114. package/test/ordinals/bsv20.js +0 -337
  115. package/test/ordinals/inscription.js +0 -329
  116. package/test/ordinals/ordlock.js +0 -567
  117. package/test/privatekey.js +0 -540
  118. package/test/publickey.js +0 -411
  119. package/test/regressions.js +0 -215
  120. package/test/script/chronicle.js +0 -543
  121. package/test/script/defaults.js +0 -160
  122. package/test/script/genesis_limits.js +0 -203
  123. package/test/script/interpreter.js +0 -776
  124. package/test/script/script.js +0 -1259
  125. package/test/script/string_ops.js +0 -88
  126. package/test/security/fail_closed_contracts.js +0 -104
  127. package/test/security/threat_model_coverage.js +0 -31
  128. package/test/smart_contract/covenants.js +0 -207
  129. package/test/smart_contract/dsl_debugger.js +0 -92
  130. package/test/smart_contract/extract_field.js +0 -61
  131. package/test/smart_contract/nonenforcing_guard.js +0 -44
  132. package/test/smart_contract/ordinal_transfer.js +0 -71
  133. package/test/smart_contract/preimage.js +0 -98
  134. package/test/smart_contract/sighash_marketplace.js +0 -98
  135. package/test/smart_contract/token_generalized.js +0 -175
  136. package/test/spv/headerchain.js +0 -86
  137. package/test/spv/merkleproof.js +0 -133
  138. package/test/statuslist/failclosed.js +0 -78
  139. package/test/transaction/deserialize.js +0 -33
  140. package/test/transaction/input/input.js +0 -92
  141. package/test/transaction/input/multisig.js +0 -174
  142. package/test/transaction/input/multisigscripthash.js +0 -111
  143. package/test/transaction/input/publickey.js +0 -68
  144. package/test/transaction/input/publickeyhash.js +0 -59
  145. package/test/transaction/output.js +0 -185
  146. package/test/transaction/sighash.js +0 -91
  147. package/test/transaction/signature.js +0 -127
  148. package/test/transaction/transaction.js +0 -1299
  149. package/test/transaction/unspentoutput.js +0 -97
  150. package/test/types/dts_drift.js +0 -124
  151. package/test/types/surface_honesty.js +0 -102
  152. package/test/util/id.js +0 -72
  153. package/test/util/js.js +0 -76
  154. package/test/util/preconditions.js +0 -79
  155. package/test/vcjwt/interop.js +0 -126
package/test/hdkeys.js DELETED
@@ -1,365 +0,0 @@
1
- 'use strict'
2
-
3
- // Relax some linter options:
4
- // * quote marks so "m/0'/1/2'/" doesn't need to be scaped
5
- // * too many tests, maxstatements -> 100
6
- // * store test vectors at the end, latedef: false
7
- // * should call is never defined
8
-
9
- var _ = require('../lib/util/_')
10
- require('chai').should()
11
- var expect = require('chai').expect
12
- var sinon = require('sinon')
13
- var bsv = require('..')
14
- var Networks = bsv.Networks
15
- var HDPrivateKey = bsv.HDPrivateKey
16
- var HDPublicKey = bsv.HDPublicKey
17
-
18
- describe('HDKeys building with static methods', function () {
19
- var classes = [HDPublicKey, HDPrivateKey]
20
-
21
- _.each(classes, function (Clazz) {
22
- var expectStaticMethodFail = function (staticMethod, argument, message) {
23
- expect(Clazz[staticMethod].bind(null, argument)).to.throw(message)
24
- }
25
- it(Clazz.name + ' fromJSON checks that a valid JSON is provided', function () {
26
- var errorMessage = 'Invalid Argument: No valid argument was provided'
27
- var method = 'fromObject'
28
- expectStaticMethodFail(method, undefined, errorMessage)
29
- expectStaticMethodFail(method, null, errorMessage)
30
- expectStaticMethodFail(method, 'invalid JSON', errorMessage)
31
- expectStaticMethodFail(method, '{\'singlequotes\': true}', errorMessage)
32
- })
33
- it(Clazz.name + ' fromString checks that a string is provided', function () {
34
- var errorMessage = 'No valid string was provided'
35
- var method = 'fromString'
36
- expectStaticMethodFail(method, undefined, errorMessage)
37
- expectStaticMethodFail(method, null, errorMessage)
38
- expectStaticMethodFail(method, {}, errorMessage)
39
- })
40
- it(Clazz.name + ' fromObject checks that an object is provided', function () {
41
- var errorMessage = 'No valid argument was provided'
42
- var method = 'fromObject'
43
- expectStaticMethodFail(method, undefined, errorMessage)
44
- expectStaticMethodFail(method, null, errorMessage)
45
- expectStaticMethodFail(method, '', errorMessage)
46
- })
47
- })
48
- })
49
-
50
- describe('BIP32 compliance', function () {
51
- it('should initialize test vector 1 from the extended public key', function () {
52
- new HDPublicKey(vector1MPublic).xpubkey.should.equal(vector1MPublic)
53
- })
54
-
55
- it('should initialize test vector 1 from the extended private key', function () {
56
- new HDPrivateKey(vector1MPrivate).xprivkey.should.equal(vector1MPrivate)
57
- })
58
-
59
- it('can initialize a public key from an extended private key', function () {
60
- new HDPublicKey(vector1MPrivate).xpubkey.should.equal(vector1MPublic)
61
- })
62
-
63
- it('toString should be equal to the `xpubkey` member', function () {
64
- var privateKey = new HDPrivateKey(vector1MPrivate)
65
- privateKey.toString().should.equal(privateKey.xprivkey)
66
- })
67
-
68
- it('toString should be equal to the `xpubkey` member', function () {
69
- var publicKey = new HDPublicKey(vector1MPublic)
70
- publicKey.toString().should.equal(publicKey.xpubkey)
71
- })
72
-
73
- it('should get the extended public key from the extended private key for test vector 1', function () {
74
- HDPrivateKey(vector1MPrivate).xpubkey.should.equal(vector1MPublic)
75
- })
76
-
77
- it("should get m/0' ext. private key from test vector 1", function () {
78
- var privateKey = new HDPrivateKey(vector1MPrivate).deriveChild("m/0'")
79
- privateKey.xprivkey.should.equal(vector1m0hprivate)
80
- })
81
-
82
- it("should get m/0' ext. public key from test vector 1", function () {
83
- HDPrivateKey(vector1MPrivate).deriveChild("m/0'")
84
- .xpubkey.should.equal(vector1m0hPublic)
85
- })
86
-
87
- it("should get m/0'/1 ext. private key from test vector 1", function () {
88
- HDPrivateKey(vector1MPrivate).deriveChild("m/0'/1")
89
- .xprivkey.should.equal(vector1m0h1private)
90
- })
91
-
92
- it("should get m/0'/1 ext. public key from test vector 1", function () {
93
- HDPrivateKey(vector1MPrivate).deriveChild("m/0'/1")
94
- .xpubkey.should.equal(vector1m0h1public)
95
- })
96
-
97
- it("should get m/0'/1 ext. public key from m/0' public key from test vector 1", function () {
98
- var derivedPublic = HDPrivateKey(vector1MPrivate).deriveChild("m/0'").hdPublicKey.deriveChild('m/1')
99
- derivedPublic.xpubkey.should.equal(vector1m0h1public)
100
- })
101
-
102
- it("should get m/0'/1/2' ext. private key from test vector 1", function () {
103
- var privateKey = new HDPrivateKey(vector1MPrivate)
104
- var derived = privateKey.deriveChild("m/0'/1/2'")
105
- derived.xprivkey.should.equal(vector1m0h12hprivate)
106
- })
107
-
108
- it("should get m/0'/1/2' ext. public key from test vector 1", function () {
109
- HDPrivateKey(vector1MPrivate).deriveChild("m/0'/1/2'")
110
- .xpubkey.should.equal(vector1m0h12hpublic)
111
- })
112
-
113
- it("should get m/0'/1/2'/2 ext. private key from test vector 1", function () {
114
- HDPrivateKey(vector1MPrivate).deriveChild("m/0'/1/2'/2")
115
- .xprivkey.should.equal(vector1m0h12h2private)
116
- })
117
-
118
- it("should get m/0'/1/2'/2 ext. public key from m/0'/1/2' public key from test vector 1", function () {
119
- var derived = HDPrivateKey(vector1MPrivate).deriveChild("m/0'/1/2'").hdPublicKey
120
- derived.deriveChild('m/2').xpubkey.should.equal(vector1m0h12h2public)
121
- })
122
-
123
- it("should get m/0'/1/2h/2 ext. public key from test vector 1", function () {
124
- HDPrivateKey(vector1MPrivate).deriveChild("m/0'/1/2'/2")
125
- .xpubkey.should.equal(vector1m0h12h2public)
126
- })
127
-
128
- it("should get m/0'/1/2h/2/1000000000 ext. private key from test vector 1", function () {
129
- HDPrivateKey(vector1MPrivate).deriveChild("m/0'/1/2'/2/1000000000")
130
- .xprivkey.should.equal(vector1m0h12h21000000000private)
131
- })
132
-
133
- it("should get m/0'/1/2h/2/1000000000 ext. public key from test vector 1", function () {
134
- HDPrivateKey(vector1MPrivate).deriveChild("m/0'/1/2'/2/1000000000")
135
- .xpubkey.should.equal(vector1m0h12h21000000000public)
136
- })
137
-
138
- it("should get m/0'/1/2'/2/1000000000 ext. public key from m/0'/1/2'/2 public key from test vector 1", function () {
139
- var derived = HDPrivateKey(vector1MPrivate).deriveChild("m/0'/1/2'/2").hdPublicKey
140
- derived.deriveChild('m/1000000000').xpubkey.should.equal(vector1m0h12h21000000000public)
141
- })
142
-
143
- it('should initialize test vector 2 from the extended public key', function () {
144
- HDPublicKey(vector2mpublic).xpubkey.should.equal(vector2mpublic)
145
- })
146
-
147
- it('should initialize test vector 2 from the extended private key', function () {
148
- HDPrivateKey(vector2mprivate).xprivkey.should.equal(vector2mprivate)
149
- })
150
-
151
- it('should get the extended public key from the extended private key for test vector 2', function () {
152
- HDPrivateKey(vector2mprivate).xpubkey.should.equal(vector2mpublic)
153
- })
154
-
155
- it('should get m/0 ext. private key from test vector 2', function () {
156
- HDPrivateKey(vector2mprivate).deriveChild(0).xprivkey.should.equal(vector2m0private)
157
- })
158
-
159
- it('should get m/0 ext. public key from test vector 2', function () {
160
- HDPrivateKey(vector2mprivate).deriveChild(0).xpubkey.should.equal(vector2m0public)
161
- })
162
-
163
- it('should get m/0 ext. public key from m public key from test vector 2', function () {
164
- HDPrivateKey(vector2mprivate).hdPublicKey.deriveChild(0).xpubkey.should.equal(vector2m0public)
165
- })
166
-
167
- it('should get m/0/2147483647h ext. private key from test vector 2', function () {
168
- HDPrivateKey(vector2mprivate).deriveChild("m/0/2147483647'")
169
- .xprivkey.should.equal(vector2m02147483647hprivate)
170
- })
171
-
172
- it('should get m/0/2147483647h ext. public key from test vector 2', function () {
173
- HDPrivateKey(vector2mprivate).deriveChild("m/0/2147483647'")
174
- .xpubkey.should.equal(vector2m02147483647hpublic)
175
- })
176
-
177
- it('should get m/0/2147483647h/1 ext. private key from test vector 2', function () {
178
- HDPrivateKey(vector2mprivate).deriveChild("m/0/2147483647'/1")
179
- .xprivkey.should.equal(vector2m02147483647h1private)
180
- })
181
-
182
- it('should get m/0/2147483647h/1 ext. public key from test vector 2', function () {
183
- HDPrivateKey(vector2mprivate).deriveChild("m/0/2147483647'/1")
184
- .xpubkey.should.equal(vector2m02147483647h1public)
185
- })
186
-
187
- it('should get m/0/2147483647h/1 ext. public key from m/0/2147483647h public key from test vector 2', function () {
188
- var derived = HDPrivateKey(vector2mprivate).deriveChild("m/0/2147483647'").hdPublicKey
189
- derived.deriveChild(1).xpubkey.should.equal(vector2m02147483647h1public)
190
- })
191
-
192
- it('should get m/0/2147483647h/1/2147483646h ext. private key from test vector 2', function () {
193
- HDPrivateKey(vector2mprivate).deriveChild("m/0/2147483647'/1/2147483646'")
194
- .xprivkey.should.equal(vector2m02147483647h12147483646hprivate)
195
- })
196
-
197
- it('should get m/0/2147483647h/1/2147483646h ext. public key from test vector 2', function () {
198
- HDPrivateKey(vector2mprivate).deriveChild("m/0/2147483647'/1/2147483646'")
199
- .xpubkey.should.equal(vector2m02147483647h12147483646hpublic)
200
- })
201
-
202
- it('should get m/0/2147483647h/1/2147483646h/2 ext. private key from test vector 2', function () {
203
- HDPrivateKey(vector2mprivate).deriveChild("m/0/2147483647'/1/2147483646'/2")
204
- .xprivkey.should.equal(vector2m02147483647h12147483646h2private)
205
- })
206
-
207
- it('should get m/0/2147483647h/1/2147483646h/2 ext. public key from test vector 2', function () {
208
- HDPrivateKey(vector2mprivate).deriveChild("m/0/2147483647'/1/2147483646'/2")
209
- .xpubkey.should.equal(vector2m02147483647h12147483646h2public)
210
- })
211
-
212
- it('should get m/0/2147483647h/1/2147483646h/2 ext. public key from m/0/2147483647h/2147483646h public key from test vector 2', function () {
213
- var derivedPublic = HDPrivateKey(vector2mprivate)
214
- .deriveChild("m/0/2147483647'/1/2147483646'").hdPublicKey
215
- derivedPublic.deriveChild('m/2')
216
- .xpubkey.should.equal(vector2m02147483647h12147483646h2public)
217
- })
218
-
219
- it('should use full 32 bytes for private key data that is hashed (as per bip32)', function () {
220
- // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
221
- var privateKeyBuffer = Buffer.from('00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd', 'hex')
222
- var chainCodeBuffer = Buffer.from('9c8a5c863e5941f3d99453e6ba66b328bb17cf0b8dec89ed4fc5ace397a1c089', 'hex')
223
- var key = HDPrivateKey.fromObject({
224
- network: 'testnet',
225
- depth: 0,
226
- parentFingerPrint: 0,
227
- childIndex: 0,
228
- privateKey: privateKeyBuffer,
229
- chainCode: chainCodeBuffer
230
- })
231
- var derived = key.deriveChild("m/44'/0'/0'/0/0'")
232
- derived.privateKey.toHex().should.equal('3348069561d2a0fb925e74bf198762acc47dce7db27372257d2d959a9e6f8aeb')
233
- })
234
-
235
- it('should NOT use full 32 bytes for private key data that is hashed with nonCompliant flag', function () {
236
- // This is to test that the previously implemented non-compliant to BIP32
237
- var privateKeyBuffer = Buffer.from('00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd', 'hex')
238
- var chainCodeBuffer = Buffer.from('9c8a5c863e5941f3d99453e6ba66b328bb17cf0b8dec89ed4fc5ace397a1c089', 'hex')
239
- var key = HDPrivateKey.fromObject({
240
- network: 'testnet',
241
- depth: 0,
242
- parentFingerPrint: 0,
243
- childIndex: 0,
244
- privateKey: privateKeyBuffer,
245
- chainCode: chainCodeBuffer
246
- })
247
- var derived = key.deriveNonCompliantChild("m/44'/0'/0'/0/0'")
248
- derived.privateKey.toHex().should.equal('4811a079bab267bfdca855b3bddff20231ff7044e648514fa099158472df2836')
249
- })
250
-
251
- it('should NOT use full 32 bytes for private key data that is hashed with the nonCompliant derive method', function () {
252
- // This is to test that the previously implemented non-compliant to BIP32
253
- var privateKeyBuffer = Buffer.from('00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd', 'hex')
254
- var chainCodeBuffer = Buffer.from('9c8a5c863e5941f3d99453e6ba66b328bb17cf0b8dec89ed4fc5ace397a1c089', 'hex')
255
- var key = HDPrivateKey.fromObject({
256
- network: 'testnet',
257
- depth: 0,
258
- parentFingerPrint: 0,
259
- childIndex: 0,
260
- privateKey: privateKeyBuffer,
261
- chainCode: chainCodeBuffer
262
- })
263
- var derived = key.deriveNonCompliantChild("m/44'/0'/0'/0/0'")
264
- derived.privateKey.toHex().should.equal('4811a079bab267bfdca855b3bddff20231ff7044e648514fa099158472df2836')
265
- })
266
-
267
- describe('edge cases', function () {
268
- var sandbox = sinon.createSandbox()
269
- afterEach(function () {
270
- sandbox.restore()
271
- })
272
- it('will handle edge case that derived private key is invalid', function () {
273
- var invalid = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex')
274
- var privateKeyBuffer = Buffer.from('5f72914c48581fc7ddeb944a9616389200a9560177d24f458258e5b04527bcd1', 'hex')
275
- var chainCodeBuffer = Buffer.from('39816057bba9d952fe87fe998b7fd4d690a1bb58c2ff69141469e4d1dffb4b91', 'hex')
276
- var unstubbed = bsv.crypto.BN.prototype.toBuffer
277
- var count = 0
278
- sandbox.stub(bsv.crypto.BN.prototype, 'toBuffer').callsFake(function (args) {
279
- // On the fourth call to the function give back an invalid private key
280
- // otherwise use the normal behavior.
281
- count++
282
- if (count === 4) {
283
- return invalid
284
- }
285
- var ret = unstubbed.apply(this, arguments)
286
- return ret
287
- })
288
- sandbox.spy(bsv.PrivateKey, 'isValid')
289
- var key = HDPrivateKey.fromObject({
290
- network: 'testnet',
291
- depth: 0,
292
- parentFingerPrint: 0,
293
- childIndex: 0,
294
- privateKey: privateKeyBuffer,
295
- chainCode: chainCodeBuffer
296
- })
297
- var derived = key.deriveChild("m/44'")
298
- derived.privateKey.toHex().should.equal('b15bce3608d607ee3a49069197732c656bca942ee59f3e29b4d56914c1de6825')
299
- bsv.PrivateKey.isValid.callCount.should.equal(2)
300
- })
301
- it('will handle edge case that a derive public key is invalid', function () {
302
- var publicKeyBuffer = Buffer.from('029e58b241790284ef56502667b15157b3fc58c567f044ddc35653860f9455d099', 'hex')
303
- var chainCodeBuffer = Buffer.from('39816057bba9d952fe87fe998b7fd4d690a1bb58c2ff69141469e4d1dffb4b91', 'hex')
304
- var key = new HDPublicKey({
305
- network: 'testnet',
306
- depth: 0,
307
- parentFingerPrint: 0,
308
- childIndex: 0,
309
- chainCode: chainCodeBuffer,
310
- publicKey: publicKeyBuffer
311
- })
312
- var unstubbed = bsv.PublicKey.fromPoint
313
- bsv.PublicKey.fromPoint = function () {
314
- bsv.PublicKey.fromPoint = unstubbed
315
- throw new Error('Point cannot be equal to Infinity')
316
- }
317
- sandbox.spy(key, '_deriveWithNumber')
318
- key.deriveChild('m/44')
319
- key._deriveWithNumber.callCount.should.equal(2)
320
- key.publicKey.toString().should.equal('029e58b241790284ef56502667b15157b3fc58c567f044ddc35653860f9455d099')
321
- })
322
- })
323
-
324
- describe('seed', function () {
325
- it('should initialize a new BIP32 correctly from test vector 1 seed', function () {
326
- var seededKey = HDPrivateKey.fromSeed(vector1Master, Networks.livenet)
327
- seededKey.xprivkey.should.equal(vector1MPrivate)
328
- seededKey.xpubkey.should.equal(vector1MPublic)
329
- })
330
-
331
- it('should initialize a new BIP32 correctly from test vector 2 seed', function () {
332
- var seededKey = HDPrivateKey.fromSeed(vector2master, Networks.livenet)
333
- seededKey.xprivkey.should.equal(vector2mprivate)
334
- seededKey.xpubkey.should.equal(vector2mpublic)
335
- })
336
- })
337
- })
338
-
339
- // test vectors: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
340
- var vector1Master = '000102030405060708090a0b0c0d0e0f'
341
- var vector1MPublic = 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8'
342
- var vector1MPrivate = 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
343
- var vector1m0hPublic = 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw'
344
- var vector1m0hprivate = 'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7'
345
- var vector1m0h1public = 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
346
- var vector1m0h1private = 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs'
347
- var vector1m0h12hpublic = 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5'
348
- var vector1m0h12hprivate = 'xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM'
349
- var vector1m0h12h2public = 'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV'
350
- var vector1m0h12h2private = 'xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334'
351
- var vector1m0h12h21000000000public = 'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy'
352
- var vector1m0h12h21000000000private = 'xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76'
353
- var vector2master = 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542'
354
- var vector2mpublic = 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB'
355
- var vector2mprivate = 'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U'
356
- var vector2m0public = 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH'
357
- var vector2m0private = 'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt'
358
- var vector2m02147483647hpublic = 'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a'
359
- var vector2m02147483647hprivate = 'xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9'
360
- var vector2m02147483647h1public = 'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon'
361
- var vector2m02147483647h1private = 'xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef'
362
- var vector2m02147483647h12147483646hpublic = 'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL'
363
- var vector2m02147483647h12147483646hprivate = 'xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc'
364
- var vector2m02147483647h12147483646h2public = 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt'
365
- var vector2m02147483647h12147483646h2private = 'xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j'