bsv2 2.1.0 → 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 (241) hide show
  1. package/dist/bsv2.mjs +1 -1
  2. package/package.json +3 -2
  3. package/.babel.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/babel.config.cjs +0 -44
  12. package/benchmark.js +0 -42
  13. package/bin/bsv.js +0 -11
  14. package/bin/network.js +0 -93
  15. package/build/index.html +0 -20
  16. package/dist/bsv2.umd.js +0 -28
  17. package/doc/assets/anchor.js +0 -350
  18. package/doc/assets/bass-addons.css +0 -12
  19. package/doc/assets/bass.css +0 -544
  20. package/doc/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
  21. package/doc/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
  22. package/doc/assets/fonts/LICENSE.txt +0 -93
  23. package/doc/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
  24. package/doc/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
  25. package/doc/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
  26. package/doc/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
  27. package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
  28. package/doc/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
  29. package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
  30. package/doc/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
  31. package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
  32. package/doc/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
  33. package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
  34. package/doc/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
  35. package/doc/assets/fonts/source-code-pro.css +0 -23
  36. package/doc/assets/github.css +0 -123
  37. package/doc/assets/site.js +0 -168
  38. package/doc/assets/split.css +0 -15
  39. package/doc/assets/split.js +0 -782
  40. package/doc/assets/style.css +0 -147
  41. package/doc/index.html +0 -9461
  42. package/entry.js +0 -81
  43. package/eslint.config.mjs +0 -8
  44. package/index.js +0 -98
  45. package/karma.conf.ts +0 -77
  46. package/lib/ach.js +0 -59
  47. package/lib/address.js +0 -266
  48. package/lib/aes.js +0 -57
  49. package/lib/aescbc.js +0 -38
  50. package/lib/base-58-check.js +0 -83
  51. package/lib/base-58.js +0 -59
  52. package/lib/bip-32.js +0 -472
  53. package/lib/bip-39-en-wordlist.js +0 -2054
  54. package/lib/bip-39-en.js +0 -10
  55. package/lib/bip-39-es-wordlist.js +0 -2055
  56. package/lib/bip-39-es.js +0 -10
  57. package/lib/bip-39-jp-wordlist.js +0 -2053
  58. package/lib/bip-39-jp.js +0 -10
  59. package/lib/bip-39-words.js +0 -5
  60. package/lib/bip-39.js +0 -286
  61. package/lib/block-header.js +0 -79
  62. package/lib/block.js +0 -132
  63. package/lib/bn.js +0 -462
  64. package/lib/br.js +0 -172
  65. package/lib/bsm.js +0 -127
  66. package/lib/bw.js +0 -188
  67. package/lib/cbc.js +0 -140
  68. package/lib/cmp.js +0 -37
  69. package/lib/config.js +0 -50
  70. package/lib/constants.js +0 -150
  71. package/lib/ecdsa.js +0 -496
  72. package/lib/ecies.js +0 -151
  73. package/lib/hash-cache.js +0 -41
  74. package/lib/hash.js +0 -191
  75. package/lib/interp.js +0 -2017
  76. package/lib/inv.js +0 -49
  77. package/lib/key-pair.js +0 -133
  78. package/lib/mainnet-address.js +0 -5
  79. package/lib/mainnet-bip-32.js +0 -5
  80. package/lib/mainnet-key-pair.js +0 -5
  81. package/lib/mainnet-priv-key.js +0 -5
  82. package/lib/merkle.js +0 -92
  83. package/lib/msg.js +0 -184
  84. package/lib/op-code.js +0 -400
  85. package/lib/point.js +0 -134
  86. package/lib/priv-key.js +0 -157
  87. package/lib/pub-key.js +0 -230
  88. package/lib/random.js +0 -28
  89. package/lib/script.js +0 -828
  90. package/lib/sig-operations.js +0 -120
  91. package/lib/sig.js +0 -399
  92. package/lib/struct.js +0 -392
  93. package/lib/testnet-address.js +0 -5
  94. package/lib/testnet-bip-32.js +0 -5
  95. package/lib/testnet-key-pair.js +0 -5
  96. package/lib/testnet-priv-key.js +0 -5
  97. package/lib/tx-builder.js +0 -593
  98. package/lib/tx-in.js +0 -172
  99. package/lib/tx-out-map.js +0 -57
  100. package/lib/tx-out.js +0 -73
  101. package/lib/tx-verifier.js +0 -209
  102. package/lib/tx.js +0 -430
  103. package/lib/var-int.js +0 -73
  104. package/lib/version.js +0 -92
  105. package/lib/workers-result.js +0 -65
  106. package/lib/workers.js +0 -77
  107. package/load-babel.js +0 -5
  108. package/mtest/test.html +0 -17
  109. package/mtest/test.js +0 -2
  110. package/mtest/test.mjs +0 -2
  111. package/mtest/webpack.config.js +0 -115
  112. package/out/Sig.html +0 -541
  113. package/out/bip-32.js.html +0 -523
  114. package/out/bip-39.js.html +0 -336
  115. package/out/block.js.html +0 -183
  116. package/out/bn.js.html +0 -512
  117. package/out/ecdsa.js.html +0 -546
  118. package/out/fonts/OpenSans-Bold-webfont.eot +0 -0
  119. package/out/fonts/OpenSans-Bold-webfont.svg +0 -1830
  120. package/out/fonts/OpenSans-Bold-webfont.woff +0 -0
  121. package/out/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  122. package/out/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  123. package/out/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  124. package/out/fonts/OpenSans-Italic-webfont.eot +0 -0
  125. package/out/fonts/OpenSans-Italic-webfont.svg +0 -1830
  126. package/out/fonts/OpenSans-Italic-webfont.woff +0 -0
  127. package/out/fonts/OpenSans-Light-webfont.eot +0 -0
  128. package/out/fonts/OpenSans-Light-webfont.svg +0 -1831
  129. package/out/fonts/OpenSans-Light-webfont.woff +0 -0
  130. package/out/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  131. package/out/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  132. package/out/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  133. package/out/fonts/OpenSans-Regular-webfont.eot +0 -0
  134. package/out/fonts/OpenSans-Regular-webfont.svg +0 -1831
  135. package/out/fonts/OpenSans-Regular-webfont.woff +0 -0
  136. package/out/global.html +0 -220
  137. package/out/index.html +0 -128
  138. package/out/interp.js.html +0 -2064
  139. package/out/merkle.js.html +0 -143
  140. package/out/msg.js.html +0 -235
  141. package/out/priv-key.js.html +0 -208
  142. package/out/pub-key.js.html +0 -281
  143. package/out/script.js.html +0 -876
  144. package/out/scripts/linenumber.js +0 -25
  145. package/out/scripts/prettify/Apache-License-2.0.txt +0 -202
  146. package/out/scripts/prettify/lang-css.js +0 -2
  147. package/out/scripts/prettify/prettify.js +0 -28
  148. package/out/sig-operations.js.html +0 -171
  149. package/out/sig.js.html +0 -450
  150. package/out/struct.js.html +0 -440
  151. package/out/styles/jsdoc-default.css +0 -358
  152. package/out/styles/prettify-jsdoc.css +0 -111
  153. package/out/styles/prettify-tomorrow.css +0 -132
  154. package/out/tx-builder.js.html +0 -644
  155. package/out/tx-in.js.html +0 -223
  156. package/out/tx-verifier.js.html +0 -260
  157. package/out/tx.js.html +0 -481
  158. package/test/ach.js +0 -172
  159. package/test/address.js +0 -464
  160. package/test/aes.js +0 -96
  161. package/test/aescbc.js +0 -65
  162. package/test/base-58-check.js +0 -128
  163. package/test/base-58.js +0 -113
  164. package/test/bip-32.js +0 -721
  165. package/test/bip-39.js +0 -282
  166. package/test/block-header.js +0 -152
  167. package/test/block.js +0 -243
  168. package/test/bn.js +0 -643
  169. package/test/br.js +0 -353
  170. package/test/bsm.js +0 -141
  171. package/test/bw.js +0 -292
  172. package/test/cbc.js +0 -335
  173. package/test/cmp.js +0 -56
  174. package/test/data/bip69.json +0 -215
  175. package/test/data/bitcoind/base58_keys_invalid.json +0 -152
  176. package/test/data/bitcoind/base58_keys_valid.json +0 -452
  177. package/test/data/bitcoind/blocks.json +0 -27
  178. package/test/data/bitcoind/script_tests.json +0 -2244
  179. package/test/data/bitcoind/sig_canonical.json +0 -7
  180. package/test/data/bitcoind/sig_noncanonical.json +0 -22
  181. package/test/data/bitcoind/tx_invalid.json +0 -177
  182. package/test/data/bitcoind/tx_valid.json +0 -224
  183. package/test/data/blk86756-testnet.dat +0 -0
  184. package/test/data/blk86756-testnet.js +0 -12
  185. package/test/data/blk86756-testnet.json +0 -684
  186. package/test/data/ecdsa.json +0 -230
  187. package/test/data/messages.json +0 -22
  188. package/test/data/sighash.json +0 -1004
  189. package/test/data/tx_creation.json +0 -85
  190. package/test/ecdsa.js +0 -748
  191. package/test/ecies.js +0 -238
  192. package/test/global.js +0 -13
  193. package/test/hash-cache.js +0 -52
  194. package/test/hash.js +0 -354
  195. package/test/index.js +0 -10
  196. package/test/interp.js +0 -512
  197. package/test/inv.js +0 -65
  198. package/test/key-pair.js +0 -243
  199. package/test/merkle.js +0 -179
  200. package/test/msg.js +0 -295
  201. package/test/op-code.js +0 -79
  202. package/test/point.js +0 -375
  203. package/test/priv-key.js +0 -264
  204. package/test/pub-key.js +0 -549
  205. package/test/random.js +0 -31
  206. package/test/script.js +0 -1340
  207. package/test/sig-operations.js +0 -149
  208. package/test/sig.js +0 -662
  209. package/test/struct.js +0 -552
  210. package/test/tx-builder.js +0 -2104
  211. package/test/tx-in.js +0 -198
  212. package/test/tx-out-map.js +0 -104
  213. package/test/tx-out.js +0 -162
  214. package/test/tx-verifier.js +0 -246
  215. package/test/tx.js +0 -539
  216. package/test/var-int.js +0 -132
  217. package/test/vectors/aes.json +0 -10392
  218. package/test/vectors/aescbc.json +0 -620
  219. package/test/vectors/bip39.json +0 -502
  220. package/test/vectors/bip69.json +0 -215
  221. package/test/vectors/bitcoin-abc/script_tests.json +0 -48
  222. package/test/vectors/bitcoin-abc/sighash.json +0 -7004
  223. package/test/vectors/bitcoin-sv/script_tests.json +0 -248
  224. package/test/vectors/bitcoind/script_invalid.json +0 -1151
  225. package/test/vectors/bitcoind/script_valid.json +0 -1462
  226. package/test/vectors/bitcoind/sighash.json +0 -3503
  227. package/test/vectors/bitcoind/tx_invalid.json +0 -883
  228. package/test/vectors/bitcoind/tx_valid.json +0 -1150
  229. package/test/vectors/coolest-tx-ever-sent.json +0 -8
  230. package/test/vectors/ecdsa.json +0 -300
  231. package/test/vectors/hash.json +0 -6133
  232. package/test/vectors/kdf.json +0 -47
  233. package/test/vectors/largesttx.json +0 -5
  234. package/test/vectors/largesttxblock.json +0 -6
  235. package/test/vectors/sig.json +0 -79
  236. package/test/vectors/sighash-single-bug.json +0 -8
  237. package/test/version.js +0 -81
  238. package/test/workers-result.js +0 -89
  239. package/test/workers.js +0 -91
  240. package/test-index.js +0 -3
  241. package/vite.config.js +0 -36
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
- })