bsv2 2.0.24 → 2.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 (170) hide show
  1. package/dist/bsv2.mjs +36061 -4
  2. package/package.json +35 -39
  3. package/.babelrc.test +0 -10
  4. package/.editorconfig +0 -4
  5. package/.env.defaults +0 -1
  6. package/.env.schema +0 -1
  7. package/.husky/pre-commit +0 -1
  8. package/.mocharc.yml +0 -4
  9. package/.nvmrc +0 -1
  10. package/.travis.yml +0 -7
  11. package/benchmark.js +0 -50
  12. package/bin/bsv.js +0 -11
  13. package/bin/network.js +0 -92
  14. package/build/index.html +0 -20
  15. package/dist/bsv2.bundle.js +0 -8
  16. package/dist/bsv2.cjs.js +0 -2
  17. package/dist/bsv2.cjs.js.LICENSE.txt +0 -1
  18. package/dist/bsv2.module.js +0 -2
  19. package/entry.js +0 -82
  20. package/index.js +0 -102
  21. package/karma.conf.js +0 -78
  22. package/lib/ach.js +0 -59
  23. package/lib/address.js +0 -264
  24. package/lib/aes.js +0 -57
  25. package/lib/aescbc.js +0 -38
  26. package/lib/base-58-check.js +0 -83
  27. package/lib/base-58.js +0 -59
  28. package/lib/bip-32.js +0 -472
  29. package/lib/bip-39-en-wordlist.js +0 -2054
  30. package/lib/bip-39-en.js +0 -10
  31. package/lib/bip-39-es-wordlist.js +0 -2055
  32. package/lib/bip-39-es.js +0 -10
  33. package/lib/bip-39-jp-wordlist.js +0 -2053
  34. package/lib/bip-39-jp.js +0 -10
  35. package/lib/bip-39-words.js +0 -5
  36. package/lib/bip-39.js +0 -285
  37. package/lib/block-header.js +0 -79
  38. package/lib/block.js +0 -132
  39. package/lib/bn.js +0 -467
  40. package/lib/br.js +0 -172
  41. package/lib/bsm.js +0 -127
  42. package/lib/bw.js +0 -188
  43. package/lib/cbc.js +0 -140
  44. package/lib/cmp.js +0 -37
  45. package/lib/config.js +0 -50
  46. package/lib/constants.js +0 -150
  47. package/lib/ecdsa.js +0 -495
  48. package/lib/ecies.js +0 -151
  49. package/lib/hash-cache.js +0 -41
  50. package/lib/hash.js +0 -191
  51. package/lib/interp.js +0 -2013
  52. package/lib/inv.js +0 -49
  53. package/lib/key-pair.js +0 -133
  54. package/lib/mainnet-address.js +0 -5
  55. package/lib/mainnet-bip-32.js +0 -5
  56. package/lib/mainnet-key-pair.js +0 -5
  57. package/lib/mainnet-priv-key.js +0 -5
  58. package/lib/merkle.js +0 -92
  59. package/lib/msg.js +0 -184
  60. package/lib/op-code.js +0 -398
  61. package/lib/point.js +0 -134
  62. package/lib/priv-key.js +0 -157
  63. package/lib/pub-key.js +0 -230
  64. package/lib/random.js +0 -28
  65. package/lib/script.js +0 -826
  66. package/lib/sig-operations.js +0 -120
  67. package/lib/sig.js +0 -399
  68. package/lib/struct.js +0 -389
  69. package/lib/testnet-address.js +0 -5
  70. package/lib/testnet-bip-32.js +0 -5
  71. package/lib/testnet-key-pair.js +0 -5
  72. package/lib/testnet-priv-key.js +0 -5
  73. package/lib/tx-builder.js +0 -593
  74. package/lib/tx-in.js +0 -172
  75. package/lib/tx-out-map.js +0 -57
  76. package/lib/tx-out.js +0 -73
  77. package/lib/tx-verifier.js +0 -209
  78. package/lib/tx.js +0 -430
  79. package/lib/var-int.js +0 -73
  80. package/lib/version.js +0 -92
  81. package/lib/workers-result.js +0 -65
  82. package/lib/workers.js +0 -77
  83. package/load-babel.js +0 -3
  84. package/mtest/test.html +0 -15
  85. package/mtest/test.js +0 -2
  86. package/mtest/test.mjs +0 -2
  87. package/test/ach.js +0 -172
  88. package/test/address.js +0 -464
  89. package/test/aes.js +0 -96
  90. package/test/aescbc.js +0 -65
  91. package/test/base-58-check.js +0 -128
  92. package/test/base-58.js +0 -113
  93. package/test/bip-32.js +0 -721
  94. package/test/bip-39.js +0 -282
  95. package/test/block-header.js +0 -152
  96. package/test/block.js +0 -243
  97. package/test/bn.js +0 -643
  98. package/test/br.js +0 -353
  99. package/test/bsm.js +0 -141
  100. package/test/bw.js +0 -292
  101. package/test/cbc.js +0 -335
  102. package/test/cmp.js +0 -56
  103. package/test/data/bip69.json +0 -215
  104. package/test/data/bitcoind/base58_keys_invalid.json +0 -152
  105. package/test/data/bitcoind/base58_keys_valid.json +0 -452
  106. package/test/data/bitcoind/blocks.json +0 -27
  107. package/test/data/bitcoind/script_tests.json +0 -2244
  108. package/test/data/bitcoind/sig_canonical.json +0 -7
  109. package/test/data/bitcoind/sig_noncanonical.json +0 -22
  110. package/test/data/bitcoind/tx_invalid.json +0 -177
  111. package/test/data/bitcoind/tx_valid.json +0 -224
  112. package/test/data/blk86756-testnet.dat +0 -0
  113. package/test/data/blk86756-testnet.js +0 -12
  114. package/test/data/blk86756-testnet.json +0 -684
  115. package/test/data/ecdsa.json +0 -230
  116. package/test/data/messages.json +0 -22
  117. package/test/data/sighash.json +0 -1004
  118. package/test/data/tx_creation.json +0 -85
  119. package/test/ecdsa.js +0 -748
  120. package/test/ecies.js +0 -238
  121. package/test/global.js +0 -13
  122. package/test/hash-cache.js +0 -52
  123. package/test/hash.js +0 -354
  124. package/test/index.js +0 -10
  125. package/test/interp.js +0 -512
  126. package/test/inv.js +0 -65
  127. package/test/key-pair.js +0 -243
  128. package/test/merkle.js +0 -179
  129. package/test/msg.js +0 -295
  130. package/test/op-code.js +0 -79
  131. package/test/point.js +0 -375
  132. package/test/priv-key.js +0 -264
  133. package/test/pub-key.js +0 -549
  134. package/test/random.js +0 -31
  135. package/test/script.js +0 -1340
  136. package/test/sig-operations.js +0 -149
  137. package/test/sig.js +0 -662
  138. package/test/struct.js +0 -552
  139. package/test/tx-builder.js +0 -2104
  140. package/test/tx-in.js +0 -198
  141. package/test/tx-out-map.js +0 -104
  142. package/test/tx-out.js +0 -162
  143. package/test/tx-verifier.js +0 -246
  144. package/test/tx.js +0 -539
  145. package/test/var-int.js +0 -132
  146. package/test/vectors/aes.json +0 -10392
  147. package/test/vectors/aescbc.json +0 -620
  148. package/test/vectors/bip39.json +0 -502
  149. package/test/vectors/bip69.json +0 -215
  150. package/test/vectors/bitcoin-abc/script_tests.json +0 -48
  151. package/test/vectors/bitcoin-abc/sighash.json +0 -7004
  152. package/test/vectors/bitcoin-sv/script_tests.json +0 -248
  153. package/test/vectors/bitcoind/script_invalid.json +0 -1151
  154. package/test/vectors/bitcoind/script_valid.json +0 -1462
  155. package/test/vectors/bitcoind/sighash.json +0 -3503
  156. package/test/vectors/bitcoind/tx_invalid.json +0 -883
  157. package/test/vectors/bitcoind/tx_valid.json +0 -1150
  158. package/test/vectors/coolest-tx-ever-sent.json +0 -8
  159. package/test/vectors/ecdsa.json +0 -300
  160. package/test/vectors/hash.json +0 -6133
  161. package/test/vectors/kdf.json +0 -47
  162. package/test/vectors/largesttx.json +0 -5
  163. package/test/vectors/largesttxblock.json +0 -6
  164. package/test/vectors/sig.json +0 -79
  165. package/test/vectors/sighash-single-bug.json +0 -8
  166. package/test/version.js +0 -81
  167. package/test/workers-result.js +0 -89
  168. package/test/workers.js +0 -91
  169. package/test-index.js +0 -3
  170. package/webpack.config.js +0 -115
package/test/bip-32.js DELETED
@@ -1,721 +0,0 @@
1
- /* global describe,it */
2
- 'use strict'
3
- import { Bip32 } from '../lib/bip-32'
4
- import { Base58Check } from '../lib/base-58-check'
5
- import { PrivKey } from '../lib/priv-key'
6
- import should from 'should'
7
-
8
- describe('Bip32', function () {
9
- it('should satisfy these basic API features', function () {
10
- Bip32.fromRandom()
11
- .toString()
12
- .slice(0, 4)
13
- .should.equal('xprv')
14
- Bip32.fromRandom()
15
- .toPublic()
16
- .toString()
17
- .slice(0, 4)
18
- .should.equal('xpub')
19
- Bip32.Testnet.fromRandom()
20
- .toString()
21
- .slice(0, 4)
22
- .should.equal('tprv')
23
- Bip32.Testnet.fromRandom()
24
- .toPublic()
25
- .toString()
26
- .slice(0, 4)
27
- .should.equal('tpub')
28
- })
29
-
30
- // test vectors: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
31
- const vector1master = '000102030405060708090a0b0c0d0e0f'
32
- const vector1mPublic =
33
- 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8'
34
- const vector1mPrivate =
35
- 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
36
- const vector1m0hPublic =
37
- 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw'
38
- const vector1m0hPrivate =
39
- 'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7'
40
- const vector1m0h1Public =
41
- 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
42
- const vector1m0h1Private =
43
- 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs'
44
- const vector1m0h12hPublic =
45
- 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5'
46
- const vector1m0h12hPrivate =
47
- 'xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM'
48
- const vector1m0h12h2Public =
49
- 'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV'
50
- const vector1m0h12h2Private =
51
- 'xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334'
52
- const vector1m0h12h21000000000Public =
53
- 'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy'
54
- const vector1m0h12h21000000000Private =
55
- 'xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76'
56
- const vector2master =
57
- 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542'
58
- const vector2mPublic =
59
- 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB'
60
- const vector2mPrivate =
61
- 'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U'
62
- const vector2m0Public =
63
- 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH'
64
- const vector2m0Private =
65
- 'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt'
66
- const vector2m02147483647hPublic =
67
- 'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a'
68
- const vector2m02147483647hPrivate =
69
- 'xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9'
70
- const vector2m02147483647h1Public =
71
- 'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon'
72
- const vector2m02147483647h1Private =
73
- 'xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef'
74
- const vector2m02147483647h12147483646hPublic =
75
- 'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL'
76
- const vector2m02147483647h12147483646hPrivate =
77
- 'xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc'
78
- const vector2m02147483647h12147483646h2Public =
79
- 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt'
80
- const vector2m02147483647h12147483646h2Private =
81
- 'xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j'
82
-
83
- it('should make a new a bip32', function () {
84
- let bip32
85
- bip32 = new Bip32()
86
- should.exist(bip32)
87
- bip32 = new Bip32()
88
- should.exist(bip32)
89
- new Bip32()
90
- .fromString(vector1mPrivate)
91
- .toString()
92
- .should.equal(vector1mPrivate)
93
- new Bip32()
94
- .fromString(vector1mPrivate)
95
- .toString()
96
- .should.equal(vector1mPrivate)
97
- new Bip32()
98
- .fromString(new Bip32().fromString(vector1mPrivate).toString())
99
- .toString()
100
- .should.equal(vector1mPrivate)
101
- })
102
-
103
- it('should initialize test vector 1 from the extended public key', function () {
104
- const bip32 = new Bip32().fromString(vector1mPublic)
105
- should.exist(bip32)
106
- })
107
-
108
- it('should initialize test vector 1 from the extended private key', function () {
109
- const bip32 = new Bip32().fromString(vector1mPrivate)
110
- should.exist(bip32)
111
- })
112
-
113
- it('should get the extended public key from the extended private key for test vector 1', function () {
114
- const bip32 = new Bip32().fromString(vector1mPrivate)
115
- bip32
116
- .toPublic()
117
- .toString()
118
- .should.equal(vector1mPublic)
119
- })
120
-
121
- it("should get m/0' ext. private key from test vector 1", function () {
122
- const bip32 = new Bip32().fromString(vector1mPrivate)
123
- const child = bip32.derive("m/0'")
124
- should.exist(child)
125
- child.toString().should.equal(vector1m0hPrivate)
126
- })
127
-
128
- it("should asynchronously get m/0' ext. private key from test vector 1", async function () {
129
- const bip32 = new Bip32().fromString(vector1mPrivate)
130
- const child = await bip32.asyncDerive("m/0'")
131
- should.exist(child)
132
- child.toString().should.equal(vector1m0hPrivate)
133
- })
134
-
135
- it("should get m/0' ext. public key from test vector 1", function () {
136
- const bip32 = new Bip32().fromString(vector1mPrivate)
137
- const child = bip32.derive("m/0'")
138
- should.exist(child)
139
- child
140
- .toPublic()
141
- .toString()
142
- .should.equal(vector1m0hPublic)
143
- })
144
-
145
- it("should get m/0'/1 ext. private key from test vector 1", function () {
146
- const bip32 = new Bip32().fromString(vector1mPrivate)
147
- const child = bip32.derive("m/0'/1")
148
- should.exist(child)
149
- child.toString().should.equal(vector1m0h1Private)
150
- })
151
-
152
- it("should get m/0'/1 ext. public key from test vector 1", function () {
153
- const bip32 = new Bip32().fromString(vector1mPrivate)
154
- const child = bip32.derive("m/0'/1")
155
- should.exist(child)
156
- child
157
- .toPublic()
158
- .toString()
159
- .should.equal(vector1m0h1Public)
160
- })
161
-
162
- it("should get m/0'/1 ext. public key from m/0' public key from test vector 1", function () {
163
- const bip32 = new Bip32().fromString(vector1mPrivate)
164
- const child = bip32.derive("m/0'")
165
- const childPub = new Bip32().fromString(child.toPublic().toString())
166
- const child2 = childPub.derive('m/1')
167
- should.exist(child2)
168
- child2
169
- .toPublic()
170
- .toString()
171
- .should.equal(vector1m0h1Public)
172
- })
173
-
174
- it("should asynchronously get m/0'/1 ext. public key from m/0' public key from test vector 1", async function () {
175
- const bip32 = new Bip32().fromString(vector1mPrivate)
176
- const child = bip32.derive("m/0'")
177
- const childPub = new Bip32().fromString(child.toPublic().toString())
178
- const child2 = await childPub.asyncDerive('m/1')
179
- should.exist(child2)
180
- child2
181
- .toPublic()
182
- .toString()
183
- .should.equal(vector1m0h1Public)
184
- })
185
-
186
- it("should get m/0'/1/2h ext. private key from test vector 1", function () {
187
- const bip32 = new Bip32().fromString(vector1mPrivate)
188
- const child = bip32.derive("m/0'/1/2'")
189
- should.exist(child)
190
- child.toString().should.equal(vector1m0h12hPrivate)
191
- })
192
-
193
- it("should get m/0'/1/2h ext. public key from test vector 1", function () {
194
- const bip32 = new Bip32().fromString(vector1mPrivate)
195
- const child = bip32.derive("m/0'/1/2'")
196
- should.exist(child)
197
- child
198
- .toPublic()
199
- .toString()
200
- .should.equal(vector1m0h12hPublic)
201
- })
202
-
203
- it("should get m/0'/1/2h/2 ext. private key from test vector 1", function () {
204
- const bip32 = new Bip32().fromString(vector1mPrivate)
205
- const child = bip32.derive("m/0'/1/2'/2")
206
- should.exist(child)
207
- child.toString().should.equal(vector1m0h12h2Private)
208
- })
209
-
210
- it("should get m/0'/1/2'/2 ext. public key from m/0'/1/2' public key from test vector 1", function () {
211
- const bip32 = new Bip32().fromString(vector1mPrivate)
212
- const child = bip32.derive("m/0'/1/2'")
213
- const childPub = new Bip32().fromString(child.toPublic().toString())
214
- const child2 = childPub.derive('m/2')
215
- should.exist(child2)
216
- child2
217
- .toPublic()
218
- .toString()
219
- .should.equal(vector1m0h12h2Public)
220
- })
221
-
222
- it("should get m/0'/1/2h/2 ext. public key from test vector 1", function () {
223
- const bip32 = new Bip32().fromString(vector1mPrivate)
224
- const child = bip32.derive("m/0'/1/2'/2")
225
- should.exist(child)
226
- child
227
- .toPublic()
228
- .toString()
229
- .should.equal(vector1m0h12h2Public)
230
- })
231
-
232
- it("should get m/0'/1/2h/2/1000000000 ext. private key from test vector 1", function () {
233
- const bip32 = new Bip32().fromString(vector1mPrivate)
234
- const child = bip32.derive("m/0'/1/2'/2/1000000000")
235
- should.exist(child)
236
- child.toString().should.equal(vector1m0h12h21000000000Private)
237
- })
238
-
239
- it("should get m/0'/1/2h/2/1000000000 ext. public key from test vector 1", function () {
240
- const bip32 = new Bip32().fromString(vector1mPrivate)
241
- const child = bip32.derive("m/0'/1/2'/2/1000000000")
242
- should.exist(child)
243
- child
244
- .toPublic()
245
- .toString()
246
- .should.equal(vector1m0h12h21000000000Public)
247
- })
248
-
249
- 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 () {
250
- const bip32 = new Bip32().fromString(vector1mPrivate)
251
- const child = bip32.derive("m/0'/1/2'/2")
252
- const childPub = new Bip32().fromString(child.toPublic().toString())
253
- const child2 = childPub.derive('m/1000000000')
254
- should.exist(child2)
255
- child2
256
- .toPublic()
257
- .toString()
258
- .should.equal(vector1m0h12h21000000000Public)
259
- })
260
-
261
- it('should initialize test vector 2 from the extended public key', function () {
262
- const bip32 = new Bip32().fromString(vector2mPublic)
263
- should.exist(bip32)
264
- })
265
-
266
- it('should initialize test vector 2 from the extended private key', function () {
267
- const bip32 = new Bip32().fromString(vector2mPrivate)
268
- should.exist(bip32)
269
- })
270
-
271
- it('should get the extended public key from the extended private key for test vector 2', function () {
272
- const bip32 = new Bip32().fromString(vector2mPrivate)
273
- bip32
274
- .toPublic()
275
- .toString()
276
- .should.equal(vector2mPublic)
277
- })
278
-
279
- it('should get m/0 ext. private key from test vector 2', function () {
280
- const bip32 = new Bip32().fromString(vector2mPrivate)
281
- const child = bip32.derive('m/0')
282
- should.exist(child)
283
- child.toString().should.equal(vector2m0Private)
284
- })
285
-
286
- it('should get m/0 ext. public key from test vector 2', function () {
287
- const bip32 = new Bip32().fromString(vector2mPrivate)
288
- const child = bip32.derive('m/0')
289
- should.exist(child)
290
- child
291
- .toPublic()
292
- .toString()
293
- .should.equal(vector2m0Public)
294
- })
295
-
296
- it('should get m/0 ext. public key from m public key from test vector 2', function () {
297
- const bip32 = new Bip32().fromString(vector2mPrivate)
298
- const child = bip32.derive('m')
299
- const childPub = new Bip32().fromString(child.toPublic().toString())
300
- const child2 = childPub.derive('m/0')
301
- should.exist(child2)
302
- child2
303
- .toPublic()
304
- .toString()
305
- .should.equal(vector2m0Public)
306
- })
307
-
308
- it('should get m/0/2147483647h ext. private key from test vector 2', function () {
309
- const bip32 = new Bip32().fromString(vector2mPrivate)
310
- const child = bip32.derive("m/0/2147483647'")
311
- should.exist(child)
312
- child.toString().should.equal(vector2m02147483647hPrivate)
313
- })
314
-
315
- it('should get m/0/2147483647h ext. public key from test vector 2', function () {
316
- const bip32 = new Bip32().fromString(vector2mPrivate)
317
- const child = bip32.derive("m/0/2147483647'")
318
- should.exist(child)
319
- child
320
- .toPublic()
321
- .toString()
322
- .should.equal(vector2m02147483647hPublic)
323
- })
324
-
325
- it('should get m/0/2147483647h/1 ext. private key from test vector 2', function () {
326
- const bip32 = new Bip32().fromString(vector2mPrivate)
327
- const child = bip32.derive("m/0/2147483647'/1")
328
- should.exist(child)
329
- child.toString().should.equal(vector2m02147483647h1Private)
330
- })
331
-
332
- it('should get m/0/2147483647h/1 ext. public key from test vector 2', function () {
333
- const bip32 = new Bip32().fromString(vector2mPrivate)
334
- const child = bip32.derive("m/0/2147483647'/1")
335
- should.exist(child)
336
- child
337
- .toPublic()
338
- .toString()
339
- .should.equal(vector2m02147483647h1Public)
340
- })
341
-
342
- it('should get m/0/2147483647h/1 ext. public key from m/0/2147483647h public key from test vector 2', function () {
343
- const bip32 = new Bip32().fromString(vector2mPrivate)
344
- const child = bip32.derive("m/0/2147483647'")
345
- const childPub = new Bip32().fromString(child.toPublic().toString())
346
- const child2 = childPub.derive('m/1')
347
- should.exist(child2)
348
- child2
349
- .toPublic()
350
- .toString()
351
- .should.equal(vector2m02147483647h1Public)
352
- })
353
-
354
- it('should get m/0/2147483647h/1/2147483646h ext. private key from test vector 2', function () {
355
- const bip32 = new Bip32().fromString(vector2mPrivate)
356
- const child = bip32.derive("m/0/2147483647'/1/2147483646'")
357
- should.exist(child)
358
- child.toString().should.equal(vector2m02147483647h12147483646hPrivate)
359
- })
360
-
361
- it('should get m/0/2147483647h/1/2147483646h ext. public key from test vector 2', function () {
362
- const bip32 = new Bip32().fromString(vector2mPrivate)
363
- const child = bip32.derive("m/0/2147483647'/1/2147483646'")
364
- should.exist(child)
365
- child
366
- .toPublic()
367
- .toString()
368
- .should.equal(vector2m02147483647h12147483646hPublic)
369
- })
370
-
371
- it('should get m/0/2147483647h/1/2147483646h/2 ext. private key from test vector 2', function () {
372
- const bip32 = new Bip32().fromString(vector2mPrivate)
373
- const child = bip32.derive("m/0/2147483647'/1/2147483646'/2")
374
- should.exist(child)
375
- child.toString().should.equal(vector2m02147483647h12147483646h2Private)
376
- })
377
-
378
- it('should get m/0/2147483647h/1/2147483646h/2 ext. public key from test vector 2', function () {
379
- const bip32 = new Bip32().fromString(vector2mPrivate)
380
- const child = bip32.derive("m/0/2147483647'/1/2147483646'/2")
381
- should.exist(child)
382
- child
383
- .toPublic()
384
- .toString()
385
- .should.equal(vector2m02147483647h12147483646h2Public)
386
- })
387
-
388
- it('should get m/0/2147483647h/1/2147483646h/2 ext. public key from m/0/2147483647h/2147483646h public key from test vector 2', function () {
389
- const bip32 = new Bip32().fromString(vector2mPrivate)
390
- const child = bip32.derive("m/0/2147483647'/1/2147483646'")
391
- const childPub = new Bip32().fromString(child.toPublic().toString())
392
- const child2 = childPub.derive('m/2')
393
- should.exist(child2)
394
- child2
395
- .toPublic()
396
- .toString()
397
- .should.equal(vector2m02147483647h12147483646h2Public)
398
- })
399
-
400
- describe('testnet', function () {
401
- it('should initialize a new Bip32 correctly from a random Bip32', function () {
402
- const b1 = new Bip32.Testnet()
403
- b1.fromRandom()
404
- ;(b1.privKey instanceof PrivKey.Testnet).should.equal(true)
405
- const b2 = new Bip32.Testnet().fromString(b1.toPublic().toString())
406
- b2
407
- .toPublic()
408
- .toString()
409
- .should.equal(b1.toPublic().toString())
410
- })
411
-
412
- it('should generate valid ext pub key for testnet', function () {
413
- const b = new Bip32.Testnet()
414
- b.fromRandom()
415
- ;(b.privKey instanceof PrivKey.Testnet).should.equal(true)
416
- b
417
- .toPublic()
418
- .toString()
419
- .substring(0, 4)
420
- .should.equal('tpub')
421
- })
422
- })
423
-
424
- describe('#fromObject', function () {
425
- it('should set this bip32', function () {
426
- const bip32 = new Bip32().fromString(vector1mPrivate)
427
- const bip322 = new Bip32().fromObject({
428
- versionBytesNum: bip32.versionBytesNum,
429
- depth: bip32.depth,
430
- parentFingerPrint: bip32.parentFingerPrint,
431
- childIndex: bip32.childIndex,
432
- chainCode: bip32.chainCode,
433
- privKey: bip32.privKey,
434
- pubKey: bip32.pubKey,
435
- hasPrivKey: bip32.hasPrivKey
436
- })
437
- bip322.toString().should.equal(bip32.toString())
438
- bip322
439
- .fromObject({})
440
- .toString()
441
- .should.equal(bip32.toString())
442
- })
443
- })
444
-
445
- describe('#fromRandom', function () {
446
- it('should not return the same one twice', function () {
447
- const bip32a = new Bip32().fromRandom()
448
- const bip32b = new Bip32().fromRandom()
449
- bip32a.toString().should.not.equal(bip32b.toString())
450
- })
451
- })
452
-
453
- describe('@fromRandom', function () {
454
- it('should not return the same one twice', function () {
455
- const bip32a = Bip32.fromRandom()
456
- const bip32b = Bip32.fromRandom()
457
- bip32a.toString().should.not.equal(bip32b.toString())
458
- })
459
- })
460
-
461
- describe('#fromSeed', function () {
462
- it('should initialize a new Bip32 correctly from test vector 1 seed', function () {
463
- const hex = vector1master
464
- const bip32 = new Bip32().fromSeed(Buffer.from(hex, 'hex'), 'mainnet')
465
- should.exist(bip32)
466
- bip32.toString().should.equal(vector1mPrivate)
467
- bip32
468
- .toPublic()
469
- .toString()
470
- .should.equal(vector1mPublic)
471
- })
472
-
473
- it('should initialize a new Bip32 correctly from test vector 2 seed', function () {
474
- const hex = vector2master
475
- const bip32 = new Bip32().fromSeed(Buffer.from(hex, 'hex'), 'mainnet')
476
- should.exist(bip32)
477
- bip32.toString().should.equal(vector2mPrivate)
478
- bip32
479
- .toPublic()
480
- .toString()
481
- .should.equal(vector2mPublic)
482
- })
483
- })
484
-
485
- describe('@fromSeed', function () {
486
- it('should initialize a new Bip32 correctly from test vector 1 seed', function () {
487
- const hex = vector1master
488
- const bip32 = Bip32.fromSeed(Buffer.from(hex, 'hex'), 'mainnet')
489
- should.exist(bip32)
490
- bip32.toString().should.equal(vector1mPrivate)
491
- bip32
492
- .toPublic()
493
- .toString()
494
- .should.equal(vector1mPublic)
495
- })
496
-
497
- it('should initialize a new Bip32 correctly from test vector 2 seed', function () {
498
- const hex = vector2master
499
- const bip32 = Bip32.fromSeed(Buffer.from(hex, 'hex'), 'mainnet')
500
- should.exist(bip32)
501
- bip32.toString().should.equal(vector2mPrivate)
502
- bip32
503
- .toPublic()
504
- .toString()
505
- .should.equal(vector2mPublic)
506
- })
507
- })
508
-
509
- describe('#asyncFromSeed', function () {
510
- it('should initialize a new Bip32 correctly from test vector 1 seed', async function () {
511
- const hex = vector1master
512
- const bip32 = await new Bip32().asyncFromSeed(
513
- Buffer.from(hex, 'hex'),
514
- 'mainnet'
515
- )
516
- should.exist(bip32)
517
- bip32.toString().should.equal(vector1mPrivate)
518
- bip32
519
- .toPublic()
520
- .toString()
521
- .should.equal(vector1mPublic)
522
- })
523
-
524
- it('should initialize a new Bip32 correctly from test vector 2 seed', async function () {
525
- const hex = vector2master
526
- const bip32 = await new Bip32().asyncFromSeed(
527
- Buffer.from(hex, 'hex'),
528
- 'mainnet'
529
- )
530
- should.exist(bip32)
531
- bip32.toString().should.equal(vector2mPrivate)
532
- bip32
533
- .toPublic()
534
- .toString()
535
- .should.equal(vector2mPublic)
536
- })
537
- })
538
-
539
- describe('@asyncFromSeed', function () {
540
- it('should initialize a new Bip32 correctly from test vector 1 seed', async function () {
541
- const hex = vector1master
542
- const bip32 = await Bip32.asyncFromSeed(Buffer.from(hex, 'hex'), 'mainnet')
543
- should.exist(bip32)
544
- bip32.toString().should.equal(vector1mPrivate)
545
- bip32
546
- .toPublic()
547
- .toString()
548
- .should.equal(vector1mPublic)
549
- })
550
-
551
- it('should initialize a new Bip32 correctly from test vector 2 seed', async function () {
552
- const hex = vector2master
553
- const bip32 = await Bip32.asyncFromSeed(Buffer.from(hex, 'hex'), 'mainnet')
554
- should.exist(bip32)
555
- bip32.toString().should.equal(vector2mPrivate)
556
- bip32
557
- .toPublic()
558
- .toString()
559
- .should.equal(vector2mPublic)
560
- })
561
- })
562
-
563
- describe('#fromHex', function () {
564
- it('should make a bip32 from a hex string', function () {
565
- const str =
566
- 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
567
- const buf = Base58Check.decode(str)
568
- const hex = buf.toString('hex')
569
- let bip32 = new Bip32().fromHex(hex)
570
- should.exist(bip32)
571
- bip32.toString().should.equal(str)
572
- bip32 = bip32.toPublic()
573
- const xpub = bip32.toString()
574
- bip32 = new Bip32().fromHex(bip32.toHex())
575
- bip32.toString().should.equal(xpub)
576
- })
577
- })
578
-
579
- describe('#fromBuffer', function () {
580
- it('should make a bip32 from a buffer', function () {
581
- const str =
582
- 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
583
- const buf = Base58Check.decode(str)
584
- let bip32 = new Bip32().fromBuffer(buf)
585
- should.exist(bip32)
586
- bip32.toString().should.equal(str)
587
- bip32 = bip32.toPublic()
588
- const xpub = bip32.toString()
589
- bip32 = new Bip32().fromBuffer(bip32.toBuffer())
590
- bip32.toString().should.equal(xpub)
591
- })
592
- })
593
-
594
- describe('#toHex', function () {
595
- it('should return a bip32 hex string', function () {
596
- const str =
597
- 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
598
- const hex = Base58Check.decode(str).toString('hex')
599
- const bip32 = new Bip32().fromString(str)
600
- bip32.toHex().should.equal(hex)
601
- })
602
- })
603
-
604
- describe('#toBuffer', function () {
605
- it('should return a bip32 buffer', function () {
606
- const str =
607
- 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
608
- const buf = Base58Check.decode(str)
609
- const bip32 = new Bip32().fromString(str)
610
- bip32
611
- .toBuffer()
612
- .toString('hex')
613
- .should.equal(buf.toString('hex'))
614
- })
615
- })
616
-
617
- describe('#fromString', function () {
618
- it('should make a bip32 from a string', function () {
619
- const str =
620
- 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
621
- const bip32 = new Bip32().fromString(str)
622
- should.exist(bip32)
623
- bip32.toString().should.equal(str)
624
- })
625
- })
626
-
627
- describe('#asyncFromString', function () {
628
- it('should make a bip32 from a string asynchronously', async function () {
629
- const str =
630
- 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
631
- const bip32 = new Bip32().fromString(str)
632
- should.exist(bip32)
633
- const bip32b = await new Bip32().asyncFromString(str)
634
- bip32.toString().should.equal(str)
635
- bip32.toString().should.equal(bip32b.toString())
636
- })
637
- })
638
-
639
- describe('#toString', function () {
640
- const bip32 = new Bip32()
641
- bip32.fromRandom()
642
- const tip32 = new Bip32.Testnet()
643
- tip32.fromRandom()
644
-
645
- it('should return an xprv string', function () {
646
- bip32
647
- .toString()
648
- .slice(0, 4)
649
- .should.equal('xprv')
650
- })
651
-
652
- it('should return an xpub string', function () {
653
- bip32
654
- .toPublic()
655
- .toString()
656
- .slice(0, 4)
657
- .should.equal('xpub')
658
- })
659
-
660
- it('should return a tprv string', function () {
661
- tip32
662
- .toString()
663
- .slice(0, 4)
664
- .should.equal('tprv')
665
- ;(tip32.privKey instanceof PrivKey.Testnet).should.equal(true)
666
- })
667
-
668
- it('should return a tpub string', function () {
669
- tip32
670
- .toPublic()
671
- .toString()
672
- .slice(0, 4)
673
- .should.equal('tpub')
674
- })
675
- })
676
-
677
- describe('#asyncToString', function () {
678
- it('should convert to a string same as toString', async function () {
679
- const bip32 = new Bip32().fromRandom()
680
- const str1 = bip32.toString()
681
- const str2 = await bip32.asyncToString()
682
- str1.should.equal(str2)
683
- })
684
- })
685
-
686
- describe('#toJSON', function () {
687
- it('should be the same as toFastHex', function () {
688
- const bip32 = Bip32.fromRandom()
689
- bip32.toJSON().should.equal(bip32.toFastHex())
690
- })
691
- })
692
-
693
- describe('#fromJSON', function () {
694
- it('should be the same as fromFastHex', function () {
695
- const bip32 = Bip32.fromRandom()
696
- const hex = bip32.toHex()
697
- const bip32a = new Bip32().fromJSON(hex)
698
- const bip32b = new Bip32().fromFastHex(hex)
699
- bip32a.toString().should.equal(bip32b.toString())
700
- })
701
- })
702
-
703
- describe('@fromJSON', function () {
704
- it('should be the same as fromFastHex', function () {
705
- const bip32 = Bip32.fromRandom()
706
- const hex = bip32.toHex()
707
- const bip32a = Bip32.fromJSON(hex)
708
- const bip32b = Bip32.fromFastHex(hex)
709
- bip32a.toString().should.equal(bip32b.toString())
710
- })
711
- })
712
-
713
- describe('#isPrivate', function () {
714
- it('should know if this bip32 is private', function () {
715
- const bip32priv = new Bip32().fromRandom()
716
- const bip32pub = bip32priv.toPublic()
717
- bip32priv.isPrivate().should.equal(true)
718
- bip32pub.isPrivate().should.equal(false)
719
- })
720
- })
721
- })