@bsv/sdk 1.1.13 → 1.1.14

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 (136) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/primitives/Point.js +28 -8
  3. package/dist/cjs/src/primitives/Point.js.map +1 -1
  4. package/dist/cjs/src/primitives/Polynomial.js +81 -0
  5. package/dist/cjs/src/primitives/Polynomial.js.map +1 -0
  6. package/dist/cjs/src/primitives/PrivateKey.js +165 -0
  7. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
  8. package/dist/cjs/src/primitives/PublicKey.js +16 -2
  9. package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
  10. package/dist/cjs/src/primitives/index.js +5 -1
  11. package/dist/cjs/src/primitives/index.js.map +1 -1
  12. package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
  13. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
  14. package/dist/cjs/src/transaction/broadcasters/ARC.js +4 -4
  15. package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -1
  16. package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  17. package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +3 -3
  18. package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
  19. package/dist/cjs/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
  20. package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js +2 -2
  21. package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
  22. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  23. package/dist/cjs/src/transaction/http/DefaultHttpClient.js +2 -2
  24. package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
  25. package/dist/cjs/src/transaction/http/FetchHttpClient.js +2 -2
  26. package/dist/cjs/src/transaction/http/FetchHttpClient.js.map +1 -1
  27. package/dist/cjs/src/transaction/http/NodejsHttpClient.js +2 -2
  28. package/dist/cjs/src/transaction/http/NodejsHttpClient.js.map +1 -1
  29. package/dist/cjs/src/transaction/http/index.js.map +1 -1
  30. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  31. package/dist/esm/src/primitives/Point.js +28 -8
  32. package/dist/esm/src/primitives/Point.js.map +1 -1
  33. package/dist/esm/src/primitives/Polynomial.js +77 -0
  34. package/dist/esm/src/primitives/Polynomial.js.map +1 -0
  35. package/dist/esm/src/primitives/PrivateKey.js +143 -0
  36. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  37. package/dist/esm/src/primitives/PublicKey.js +16 -2
  38. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  39. package/dist/esm/src/primitives/index.js +2 -1
  40. package/dist/esm/src/primitives/index.js.map +1 -1
  41. package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
  42. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
  43. package/dist/esm/src/transaction/broadcasters/ARC.js +7 -7
  44. package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -1
  45. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
  46. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  47. package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +4 -4
  48. package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
  49. package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js +1 -1
  50. package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
  51. package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js +3 -3
  52. package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
  53. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  54. package/dist/esm/src/transaction/http/DefaultHttpClient.js +2 -2
  55. package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
  56. package/dist/esm/src/transaction/http/FetchHttpClient.js +2 -2
  57. package/dist/esm/src/transaction/http/FetchHttpClient.js.map +1 -1
  58. package/dist/esm/src/transaction/http/NodejsHttpClient.js +2 -2
  59. package/dist/esm/src/transaction/http/NodejsHttpClient.js.map +1 -1
  60. package/dist/esm/src/transaction/http/index.js.map +1 -1
  61. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  62. package/dist/types/src/primitives/Point.d.ts +19 -1
  63. package/dist/types/src/primitives/Point.d.ts.map +1 -1
  64. package/dist/types/src/primitives/Polynomial.d.ts +32 -0
  65. package/dist/types/src/primitives/Polynomial.d.ts.map +1 -0
  66. package/dist/types/src/primitives/PrivateKey.d.ts +72 -0
  67. package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
  68. package/dist/types/src/primitives/PublicKey.d.ts +12 -1
  69. package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
  70. package/dist/types/src/primitives/index.d.ts +2 -1
  71. package/dist/types/src/primitives/index.d.ts.map +1 -1
  72. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
  73. package/dist/types/src/transaction/broadcasters/ARC.d.ts +1 -1
  74. package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -1
  75. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts +1 -1
  76. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts.map +1 -1
  77. package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts +1 -1
  78. package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts.map +1 -1
  79. package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts +1 -1
  80. package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts.map +1 -1
  81. package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts +2 -2
  82. package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts.map +1 -1
  83. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -1
  84. package/dist/types/src/transaction/http/DefaultHttpClient.d.ts.map +1 -1
  85. package/dist/types/src/transaction/http/FetchHttpClient.d.ts +7 -9
  86. package/dist/types/src/transaction/http/FetchHttpClient.d.ts.map +1 -1
  87. package/dist/types/src/transaction/http/HttpClient.d.ts +5 -5
  88. package/dist/types/src/transaction/http/HttpClient.d.ts.map +1 -1
  89. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts +5 -6
  90. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts.map +1 -1
  91. package/dist/types/src/transaction/http/index.d.ts.map +1 -1
  92. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  93. package/docs/primitives.md +231 -16
  94. package/docs/transaction.md +38 -37
  95. package/package.json +1 -1
  96. package/src/compat/__tests/BSM.test.ts +37 -37
  97. package/src/compat/__tests/ECIES.test.ts +71 -71
  98. package/src/compat/__tests/HD.test.ts +362 -362
  99. package/src/compat/__tests/Mnemonic.test.ts +147 -148
  100. package/src/compat/__tests/Mnemonic.vectors.ts +170 -170
  101. package/src/messages/__tests/EncryptedMessage.test.ts +16 -16
  102. package/src/primitives/Point.ts +29 -10
  103. package/src/primitives/Polynomial.ts +89 -0
  104. package/src/primitives/PrivateKey.ts +147 -1
  105. package/src/primitives/PublicKey.ts +17 -2
  106. package/src/primitives/__tests/AESGCM.test.ts +20 -20
  107. package/src/primitives/__tests/Hash.test.ts +2 -2
  108. package/src/primitives/__tests/PBKDF2.vectors.ts +93 -93
  109. package/src/primitives/__tests/PrivateKey.split.test.ts +70 -0
  110. package/src/primitives/__tests/PublicKey.test.ts +14 -1
  111. package/src/primitives/__tests/bug-31.test.ts +24 -26
  112. package/src/primitives/__tests/utils.test.ts +13 -13
  113. package/src/primitives/index.ts +2 -1
  114. package/src/script/__tests/Script.test.ts +1 -1
  115. package/src/script/__tests/SpendComplex.test.ts +6 -6
  116. package/src/script/__tests/script.invalid.vectors.ts +1464 -1464
  117. package/src/script/__tests/script.valid.vectors.ts +1962 -1962
  118. package/src/script/__tests/spend.valid.vectors.ts +1369 -1369
  119. package/src/script/templates/P2PKH.ts +6 -6
  120. package/src/script/templates/RPuzzle.ts +1 -1
  121. package/src/transaction/__tests/Transaction.test.ts +5 -5
  122. package/src/transaction/__tests/bump.invalid.vectors.ts +1 -1
  123. package/src/transaction/__tests/bump.valid.vectors.ts +3 -3
  124. package/src/transaction/broadcasters/ARC.ts +20 -21
  125. package/src/transaction/broadcasters/DefaultBroadcaster.ts +3 -3
  126. package/src/transaction/broadcasters/WhatsOnChainBroadcaster.ts +10 -10
  127. package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +7 -10
  128. package/src/transaction/chaintrackers/DefaultChainTracker.ts +3 -3
  129. package/src/transaction/chaintrackers/WhatsOnChain.ts +10 -12
  130. package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +13 -17
  131. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +2 -2
  132. package/src/transaction/http/DefaultHttpClient.ts +13 -13
  133. package/src/transaction/http/FetchHttpClient.ts +14 -16
  134. package/src/transaction/http/HttpClient.ts +22 -23
  135. package/src/transaction/http/NodejsHttpClient.ts +23 -25
  136. package/src/transaction/http/index.ts +6 -6
@@ -2,403 +2,403 @@ import HD from '../../../dist/cjs/src/compat/HD'
2
2
  import { fromBase58Check, toArray, toHex } from '../../../dist/cjs/src/primitives/utils'
3
3
 
4
4
  describe('HD', () => {
5
- it('should satisfy these basic API features', () => {
6
- expect(HD.fromRandom().toString().slice(0, 4)).toEqual('xprv')
7
- expect(HD.fromRandom().toPublic().toString().slice(0, 4)).toEqual('xpub')
8
- })
9
-
10
- // test vectors: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
11
- const vector1master = '000102030405060708090a0b0c0d0e0f'
12
- const vector1mPublic =
5
+ it('should satisfy these basic API features', () => {
6
+ expect(HD.fromRandom().toString().slice(0, 4)).toEqual('xprv')
7
+ expect(HD.fromRandom().toPublic().toString().slice(0, 4)).toEqual('xpub')
8
+ })
9
+
10
+ // test vectors: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
11
+ const vector1master = '000102030405060708090a0b0c0d0e0f'
12
+ const vector1mPublic =
13
13
  'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8'
14
- const vector1mPrivate =
14
+ const vector1mPrivate =
15
15
  'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
16
- const vector1m0hPublic =
16
+ const vector1m0hPublic =
17
17
  'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw'
18
- const vector1m0hPrivate =
18
+ const vector1m0hPrivate =
19
19
  'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7'
20
- const vector1m0h1Public =
20
+ const vector1m0h1Public =
21
21
  'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ'
22
- const vector1m0h1Private =
22
+ const vector1m0h1Private =
23
23
  'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs'
24
- const vector1m0h12hPublic =
24
+ const vector1m0h12hPublic =
25
25
  'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5'
26
- const vector1m0h12hPrivate =
26
+ const vector1m0h12hPrivate =
27
27
  'xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM'
28
- const vector1m0h12h2Public =
28
+ const vector1m0h12h2Public =
29
29
  'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV'
30
- const vector1m0h12h2Private =
30
+ const vector1m0h12h2Private =
31
31
  'xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334'
32
- const vector1m0h12h21000000000Public =
32
+ const vector1m0h12h21000000000Public =
33
33
  'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy'
34
- const vector1m0h12h21000000000Private =
34
+ const vector1m0h12h21000000000Private =
35
35
  'xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76'
36
- const vector2master =
36
+ const vector2master =
37
37
  'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542'
38
- const vector2mPublic =
38
+ const vector2mPublic =
39
39
  'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB'
40
- const vector2mPrivate =
40
+ const vector2mPrivate =
41
41
  'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U'
42
- const vector2m0Public =
42
+ const vector2m0Public =
43
43
  'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH'
44
- const vector2m0Private =
44
+ const vector2m0Private =
45
45
  'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt'
46
- const vector2m02147483647hPublic =
46
+ const vector2m02147483647hPublic =
47
47
  'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a'
48
- const vector2m02147483647hPrivate =
48
+ const vector2m02147483647hPrivate =
49
49
  'xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9'
50
- const vector2m02147483647h1Public =
50
+ const vector2m02147483647h1Public =
51
51
  'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon'
52
- const vector2m02147483647h1Private =
52
+ const vector2m02147483647h1Private =
53
53
  'xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef'
54
- const vector2m02147483647h12147483646hPublic =
54
+ const vector2m02147483647h12147483646hPublic =
55
55
  'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL'
56
- const vector2m02147483647h12147483646hPrivate =
56
+ const vector2m02147483647h12147483646hPrivate =
57
57
  'xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc'
58
- const vector2m02147483647h12147483646h2Public =
58
+ const vector2m02147483647h12147483646h2Public =
59
59
  'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt'
60
- const vector2m02147483647h12147483646h2Private =
60
+ const vector2m02147483647h12147483646h2Private =
61
61
  'xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j'
62
62
 
63
- it('should make a new a bip32', () => {
64
- let bip32
65
- bip32 = new HD()
66
- expect(bip32).toBeDefined()
67
- expect(HD.fromString(vector1mPrivate).toString()).toEqual(vector1mPrivate)
68
- expect(HD.fromString(HD.fromString(vector1mPrivate).toString())
69
- .toString())
70
- .toEqual(vector1mPrivate)
71
- })
72
-
73
- it('should initialize test vector 1 from the extended public key', () => {
74
- const bip32 = HD.fromString(vector1mPublic)
75
- expect(bip32).toBeDefined()
76
- })
77
-
78
- it('should initialize test vector 1 from the extended private key', () => {
79
- const bip32 = HD.fromString(vector1mPrivate)
80
- expect(bip32).toBeDefined()
81
- })
82
-
83
- it('should get the extended public key from the extended private key for test vector 1', () => {
84
- const bip32 = HD.fromString(vector1mPrivate)
85
- expect(bip32.toPublic().toString()).toEqual(vector1mPublic)
86
- })
87
-
88
- it("should get m/0' ext. private key from test vector 1", () => {
89
- const bip32 = HD.fromString(vector1mPrivate)
90
- const child = bip32.derive("m/0'")
91
- expect(child).toBeDefined()
92
- expect(child.toString()).toEqual(vector1m0hPrivate)
93
- })
94
-
95
- it("should get m/0' ext. public key from test vector 1", () => {
96
- const bip32 = HD.fromString(vector1mPrivate)
97
- const child = bip32.derive("m/0'")
98
- expect(child).toBeDefined()
99
- expect(child.toPublic().toString()).toEqual(vector1m0hPublic)
100
- })
101
-
102
- it("should get m/0'/1 ext. private key from test vector 1", () => {
103
- const bip32 = HD.fromString(vector1mPrivate)
104
- const child = bip32.derive("m/0'/1")
105
- expect(child).toBeDefined()
106
- expect(child.toString()).toEqual(vector1m0h1Private)
107
- })
108
-
109
- it("should get m/0'/1 ext. public key from test vector 1", () => {
110
- const bip32 = HD.fromString(vector1mPrivate)
111
- const child = bip32.derive("m/0'/1")
112
- expect(child).toBeDefined()
113
- expect(child.toPublic().toString()).toEqual(vector1m0h1Public)
114
- })
115
-
116
- it("should get m/0'/1 ext. public key from m/0' public key from test vector 1", () => {
117
- const bip32 = HD.fromString(vector1mPrivate)
118
- const child = bip32.derive("m/0'")
119
- const childPub = HD.fromString(child.toPublic().toString())
120
- const child2 = childPub.derive('m/1')
121
- expect(child2).toBeDefined()
122
- expect(child2.toPublic().toString()).toEqual(vector1m0h1Public)
123
- })
124
-
125
- it("should get m/0'/1/2h ext. private key from test vector 1", () => {
126
- const bip32 = HD.fromString(vector1mPrivate)
127
- const child = bip32.derive("m/0'/1/2'")
128
- expect(child).toBeDefined()
129
- expect(child.toString()).toEqual(vector1m0h12hPrivate)
130
- })
131
-
132
- it("should get m/0'/1/2h ext. public key from test vector 1", () => {
133
- const bip32 = HD.fromString(vector1mPrivate)
134
- const child = bip32.derive("m/0'/1/2'")
135
- expect(child).toBeDefined()
136
- expect(child.toPublic().toString()).toEqual(vector1m0h12hPublic)
137
- })
138
-
139
- it("should get m/0'/1/2h/2 ext. private key from test vector 1", () => {
140
- const bip32 = HD.fromString(vector1mPrivate)
141
- const child = bip32.derive("m/0'/1/2'/2")
142
- expect(child).toBeDefined()
143
- expect(child.toString()).toEqual(vector1m0h12h2Private)
144
- })
145
-
146
- it("should get m/0'/1/2'/2 ext. public key from m/0'/1/2' public key from test vector 1", () => {
147
- const bip32 = HD.fromString(vector1mPrivate)
148
- const child = bip32.derive("m/0'/1/2'")
149
- const childPub = HD.fromString(child.toPublic().toString())
150
- const child2 = childPub.derive('m/2')
151
- expect(child2).toBeDefined()
152
- expect(child2.toPublic().toString()).toEqual(vector1m0h12h2Public)
153
- })
154
-
155
- it("should get m/0'/1/2h/2 ext. public key from test vector 1", () => {
156
- const bip32 = HD.fromString(vector1mPrivate)
157
- const child = bip32.derive("m/0'/1/2'/2")
158
- expect(child).toBeDefined()
159
- expect(child.toPublic().toString()).toEqual(vector1m0h12h2Public)
160
- })
161
-
162
- it("should get m/0'/1/2h/2/1000000000 ext. private key from test vector 1", () => {
163
- const bip32 = HD.fromString(vector1mPrivate)
164
- const child = bip32.derive("m/0'/1/2'/2/1000000000")
165
- expect(child).toBeDefined()
166
- expect(child.toString()).toEqual(vector1m0h12h21000000000Private)
167
- })
168
-
169
- it("should get m/0'/1/2h/2/1000000000 ext. public key from test vector 1", () => {
170
- const bip32 = HD.fromString(vector1mPrivate)
171
- const child = bip32.derive("m/0'/1/2'/2/1000000000")
172
- expect(child).toBeDefined()
173
- expect(child.toPublic().toString()).toEqual(vector1m0h12h21000000000Public)
174
- })
175
-
176
- it("should get m/0'/1/2'/2/1000000000 ext. public key from m/0'/1/2'/2 public key from test vector 1", () => {
177
- const bip32 = HD.fromString(vector1mPrivate)
178
- const child = bip32.derive("m/0'/1/2'/2")
179
- const childPub = HD.fromString(child.toPublic().toString())
180
- const child2 = childPub.derive('m/1000000000')
181
- expect(child2).toBeDefined()
182
- expect(child2.toPublic().toString()).toEqual(vector1m0h12h21000000000Public)
183
- })
184
-
185
- it('should initialize test vector 2 from the extended public key', () => {
186
- const bip32 = HD.fromString(vector2mPublic)
187
- expect(bip32).toBeDefined()
188
- })
189
-
190
- it('should initialize test vector 2 from the extended private key', () => {
191
- const bip32 = HD.fromString(vector2mPrivate)
192
- expect(bip32).toBeDefined()
193
- })
194
-
195
- it('should get the extended public key from the extended private key for test vector 2', () => {
196
- const bip32 = HD.fromString(vector2mPrivate)
197
- expect(bip32.toPublic().toString()).toEqual(vector2mPublic)
198
- })
199
-
200
- it('should get m/0 ext. private key from test vector 2', () => {
201
- const bip32 = HD.fromString(vector2mPrivate)
202
- const child = bip32.derive('m/0')
203
- expect(child).toBeDefined()
204
- expect(child.toString()).toEqual(vector2m0Private)
205
- })
206
-
207
- it('should get m/0 ext. public key from test vector 2', () => {
208
- const bip32 = HD.fromString(vector2mPrivate)
209
- const child = bip32.derive('m/0')
210
- expect(child).toBeDefined()
211
- expect(child.toPublic().toString()).toEqual(vector2m0Public)
212
- })
213
-
214
- it('should get m/0 ext. public key from m public key from test vector 2', () => {
215
- const bip32 = HD.fromString(vector2mPrivate)
216
- const child = bip32.derive('m')
217
- const childPub = HD.fromString(child.toPublic().toString())
218
- const child2 = childPub.derive('m/0')
219
- expect(child2).toBeDefined()
220
- expect(child2.toPublic().toString()).toEqual(vector2m0Public)
221
- })
222
-
223
- it('should get m/0/2147483647h ext. private key from test vector 2', () => {
224
- const bip32 = HD.fromString(vector2mPrivate)
225
- const child = bip32.derive("m/0/2147483647'")
226
- expect(child).toBeDefined()
227
- expect(child.toString()).toEqual(vector2m02147483647hPrivate)
228
- })
229
-
230
- it('should get m/0/2147483647h ext. public key from test vector 2', () => {
231
- const bip32 = HD.fromString(vector2mPrivate)
232
- const child = bip32.derive("m/0/2147483647'")
233
- expect(child).toBeDefined()
234
- expect(child.toPublic().toString()).toEqual(vector2m02147483647hPublic)
235
- })
236
-
237
- it('should get m/0/2147483647h/1 ext. private key from test vector 2', () => {
238
- const bip32 = HD.fromString(vector2mPrivate)
239
- const child = bip32.derive("m/0/2147483647'/1")
240
- expect(child).toBeDefined()
241
- expect(child.toString()).toEqual(vector2m02147483647h1Private)
242
- })
243
-
244
- it('should get m/0/2147483647h/1 ext. public key from test vector 2', () => {
245
- const bip32 = HD.fromString(vector2mPrivate)
246
- const child = bip32.derive("m/0/2147483647'/1")
247
- expect(child).toBeDefined()
248
- expect(child.toPublic().toString()).toEqual(vector2m02147483647h1Public)
249
- })
250
-
251
- it('should get m/0/2147483647h/1 ext. public key from m/0/2147483647h public key from test vector 2', () => {
252
- const bip32 = HD.fromString(vector2mPrivate)
253
- const child = bip32.derive("m/0/2147483647'")
254
- const childPub = HD.fromString(child.toPublic().toString())
255
- const child2 = childPub.derive('m/1')
256
- expect(child2).toBeDefined()
257
- expect(child2.toPublic().toString()).toEqual(vector2m02147483647h1Public)
258
- })
259
-
260
- it('should get m/0/2147483647h/1/2147483646h ext. private key from test vector 2', () => {
261
- const bip32 = HD.fromString(vector2mPrivate)
262
- const child = bip32.derive("m/0/2147483647'/1/2147483646'")
263
- expect(child).toBeDefined()
264
- expect(child.toString()).toEqual(vector2m02147483647h12147483646hPrivate)
265
- })
266
-
267
- it('should get m/0/2147483647h/1/2147483646h ext. public key from test vector 2', () => {
268
- const bip32 = HD.fromString(vector2mPrivate)
269
- const child = bip32.derive("m/0/2147483647'/1/2147483646'")
270
- expect(child).toBeDefined()
271
- expect(child.toPublic().toString()).toEqual(vector2m02147483647h12147483646hPublic)
272
- })
273
-
274
- it('should get m/0/2147483647h/1/2147483646h/2 ext. private key from test vector 2', () => {
275
- const bip32 = HD.fromString(vector2mPrivate)
276
- const child = bip32.derive("m/0/2147483647'/1/2147483646'/2")
277
- expect(child).toBeDefined()
278
- expect(child.toString()).toEqual(vector2m02147483647h12147483646h2Private)
279
- })
280
-
281
- it('should get m/0/2147483647h/1/2147483646h/2 ext. public key from test vector 2', () => {
282
- const bip32 = HD.fromString(vector2mPrivate)
283
- const child = bip32.derive("m/0/2147483647'/1/2147483646'/2")
284
- expect(child).toBeDefined()
285
- expect(child.toPublic().toString()).toEqual(vector2m02147483647h12147483646h2Public)
286
- })
287
-
288
- it('should get m/0/2147483647h/1/2147483646h/2 ext. public key from m/0/2147483647h/2147483646h public key from test vector 2', () => {
289
- const bip32 = HD.fromString(vector2mPrivate)
290
- const child = bip32.derive("m/0/2147483647'/1/2147483646'")
291
- const childPub = HD.fromString(child.toPublic().toString())
292
- const child2 = childPub.derive('m/2')
293
- expect(child2).toBeDefined()
294
- expect(child2.toPublic().toString()).toEqual(vector2m02147483647h12147483646h2Public)
295
- })
296
-
297
- describe('#fromRandom', () => {
298
- it('should not return the same one twice', () => {
299
- const bip32a = HD.fromRandom()
300
- const bip32b = HD.fromRandom()
301
- expect(bip32a.toString()).not.toEqual(bip32b.toString())
302
- })
303
- })
304
-
305
- describe('@fromRandom', () => {
306
- it('should not return the same one twice', () => {
307
- const bip32a = HD.fromRandom()
308
- const bip32b = HD.fromRandom()
309
- expect(bip32a.toString()).not.toEqual(bip32b.toString())
310
- })
311
- })
312
-
313
- describe('#fromSeed', () => {
314
- it('should initialize a new Bip32 correctly from test vector 1 seed', () => {
315
- const hex = vector1master
316
- const bip32 = HD.fromSeed(toArray(hex, 'hex'))
317
- expect(bip32).toBeDefined()
318
- expect(bip32.toString()).toEqual(vector1mPrivate)
319
- expect(bip32.toPublic().toString()).toEqual(vector1mPublic)
320
- })
321
-
322
- it('should initialize a new Bip32 correctly from test vector 2 seed', () => {
323
- const hex = vector2master
324
- const bip32 = HD.fromSeed(toArray(hex, 'hex'))
325
- expect(bip32).toBeDefined()
326
- expect(bip32.toString()).toEqual(vector2mPrivate)
327
- expect(bip32.toPublic().toString()).toEqual(vector2mPublic)
328
- })
329
- })
330
-
331
- describe('@fromSeed', () => {
332
- it('should initialize a new Bip32 correctly from test vector 1 seed', () => {
333
- const hex = vector1master
334
- const bip32 = HD.fromSeed(toArray(hex, 'hex'))
335
- expect(bip32).toBeDefined()
336
- expect(bip32.toString()).toEqual(vector1mPrivate)
337
- expect(bip32.toPublic().toString()).toEqual(vector1mPublic)
338
- })
339
-
340
- it('should initialize a new Bip32 correctly from test vector 2 seed', () => {
341
- const hex = vector2master
342
- const bip32 = HD.fromSeed(toArray(hex, 'hex'))
343
- expect(bip32).toBeDefined()
344
- expect(bip32.toString()).toEqual(vector2mPrivate)
345
- expect(bip32.toPublic().toString()).toEqual(vector2mPublic)
346
- })
347
- })
348
-
349
- describe('#fromBinary', () => {
350
- it('should make a bip32 from binary', () => {
351
- const str =
63
+ it('should make a new a bip32', () => {
64
+ let bip32
65
+ bip32 = new HD()
66
+ expect(bip32).toBeDefined()
67
+ expect(HD.fromString(vector1mPrivate).toString()).toEqual(vector1mPrivate)
68
+ expect(HD.fromString(HD.fromString(vector1mPrivate).toString())
69
+ .toString())
70
+ .toEqual(vector1mPrivate)
71
+ })
72
+
73
+ it('should initialize test vector 1 from the extended public key', () => {
74
+ const bip32 = HD.fromString(vector1mPublic)
75
+ expect(bip32).toBeDefined()
76
+ })
77
+
78
+ it('should initialize test vector 1 from the extended private key', () => {
79
+ const bip32 = HD.fromString(vector1mPrivate)
80
+ expect(bip32).toBeDefined()
81
+ })
82
+
83
+ it('should get the extended public key from the extended private key for test vector 1', () => {
84
+ const bip32 = HD.fromString(vector1mPrivate)
85
+ expect(bip32.toPublic().toString()).toEqual(vector1mPublic)
86
+ })
87
+
88
+ it("should get m/0' ext. private key from test vector 1", () => {
89
+ const bip32 = HD.fromString(vector1mPrivate)
90
+ const child = bip32.derive("m/0'")
91
+ expect(child).toBeDefined()
92
+ expect(child.toString()).toEqual(vector1m0hPrivate)
93
+ })
94
+
95
+ it("should get m/0' ext. public key from test vector 1", () => {
96
+ const bip32 = HD.fromString(vector1mPrivate)
97
+ const child = bip32.derive("m/0'")
98
+ expect(child).toBeDefined()
99
+ expect(child.toPublic().toString()).toEqual(vector1m0hPublic)
100
+ })
101
+
102
+ it("should get m/0'/1 ext. private key from test vector 1", () => {
103
+ const bip32 = HD.fromString(vector1mPrivate)
104
+ const child = bip32.derive("m/0'/1")
105
+ expect(child).toBeDefined()
106
+ expect(child.toString()).toEqual(vector1m0h1Private)
107
+ })
108
+
109
+ it("should get m/0'/1 ext. public key from test vector 1", () => {
110
+ const bip32 = HD.fromString(vector1mPrivate)
111
+ const child = bip32.derive("m/0'/1")
112
+ expect(child).toBeDefined()
113
+ expect(child.toPublic().toString()).toEqual(vector1m0h1Public)
114
+ })
115
+
116
+ it("should get m/0'/1 ext. public key from m/0' public key from test vector 1", () => {
117
+ const bip32 = HD.fromString(vector1mPrivate)
118
+ const child = bip32.derive("m/0'")
119
+ const childPub = HD.fromString(child.toPublic().toString())
120
+ const child2 = childPub.derive('m/1')
121
+ expect(child2).toBeDefined()
122
+ expect(child2.toPublic().toString()).toEqual(vector1m0h1Public)
123
+ })
124
+
125
+ it("should get m/0'/1/2h ext. private key from test vector 1", () => {
126
+ const bip32 = HD.fromString(vector1mPrivate)
127
+ const child = bip32.derive("m/0'/1/2'")
128
+ expect(child).toBeDefined()
129
+ expect(child.toString()).toEqual(vector1m0h12hPrivate)
130
+ })
131
+
132
+ it("should get m/0'/1/2h ext. public key from test vector 1", () => {
133
+ const bip32 = HD.fromString(vector1mPrivate)
134
+ const child = bip32.derive("m/0'/1/2'")
135
+ expect(child).toBeDefined()
136
+ expect(child.toPublic().toString()).toEqual(vector1m0h12hPublic)
137
+ })
138
+
139
+ it("should get m/0'/1/2h/2 ext. private key from test vector 1", () => {
140
+ const bip32 = HD.fromString(vector1mPrivate)
141
+ const child = bip32.derive("m/0'/1/2'/2")
142
+ expect(child).toBeDefined()
143
+ expect(child.toString()).toEqual(vector1m0h12h2Private)
144
+ })
145
+
146
+ it("should get m/0'/1/2'/2 ext. public key from m/0'/1/2' public key from test vector 1", () => {
147
+ const bip32 = HD.fromString(vector1mPrivate)
148
+ const child = bip32.derive("m/0'/1/2'")
149
+ const childPub = HD.fromString(child.toPublic().toString())
150
+ const child2 = childPub.derive('m/2')
151
+ expect(child2).toBeDefined()
152
+ expect(child2.toPublic().toString()).toEqual(vector1m0h12h2Public)
153
+ })
154
+
155
+ it("should get m/0'/1/2h/2 ext. public key from test vector 1", () => {
156
+ const bip32 = HD.fromString(vector1mPrivate)
157
+ const child = bip32.derive("m/0'/1/2'/2")
158
+ expect(child).toBeDefined()
159
+ expect(child.toPublic().toString()).toEqual(vector1m0h12h2Public)
160
+ })
161
+
162
+ it("should get m/0'/1/2h/2/1000000000 ext. private key from test vector 1", () => {
163
+ const bip32 = HD.fromString(vector1mPrivate)
164
+ const child = bip32.derive("m/0'/1/2'/2/1000000000")
165
+ expect(child).toBeDefined()
166
+ expect(child.toString()).toEqual(vector1m0h12h21000000000Private)
167
+ })
168
+
169
+ it("should get m/0'/1/2h/2/1000000000 ext. public key from test vector 1", () => {
170
+ const bip32 = HD.fromString(vector1mPrivate)
171
+ const child = bip32.derive("m/0'/1/2'/2/1000000000")
172
+ expect(child).toBeDefined()
173
+ expect(child.toPublic().toString()).toEqual(vector1m0h12h21000000000Public)
174
+ })
175
+
176
+ it("should get m/0'/1/2'/2/1000000000 ext. public key from m/0'/1/2'/2 public key from test vector 1", () => {
177
+ const bip32 = HD.fromString(vector1mPrivate)
178
+ const child = bip32.derive("m/0'/1/2'/2")
179
+ const childPub = HD.fromString(child.toPublic().toString())
180
+ const child2 = childPub.derive('m/1000000000')
181
+ expect(child2).toBeDefined()
182
+ expect(child2.toPublic().toString()).toEqual(vector1m0h12h21000000000Public)
183
+ })
184
+
185
+ it('should initialize test vector 2 from the extended public key', () => {
186
+ const bip32 = HD.fromString(vector2mPublic)
187
+ expect(bip32).toBeDefined()
188
+ })
189
+
190
+ it('should initialize test vector 2 from the extended private key', () => {
191
+ const bip32 = HD.fromString(vector2mPrivate)
192
+ expect(bip32).toBeDefined()
193
+ })
194
+
195
+ it('should get the extended public key from the extended private key for test vector 2', () => {
196
+ const bip32 = HD.fromString(vector2mPrivate)
197
+ expect(bip32.toPublic().toString()).toEqual(vector2mPublic)
198
+ })
199
+
200
+ it('should get m/0 ext. private key from test vector 2', () => {
201
+ const bip32 = HD.fromString(vector2mPrivate)
202
+ const child = bip32.derive('m/0')
203
+ expect(child).toBeDefined()
204
+ expect(child.toString()).toEqual(vector2m0Private)
205
+ })
206
+
207
+ it('should get m/0 ext. public key from test vector 2', () => {
208
+ const bip32 = HD.fromString(vector2mPrivate)
209
+ const child = bip32.derive('m/0')
210
+ expect(child).toBeDefined()
211
+ expect(child.toPublic().toString()).toEqual(vector2m0Public)
212
+ })
213
+
214
+ it('should get m/0 ext. public key from m public key from test vector 2', () => {
215
+ const bip32 = HD.fromString(vector2mPrivate)
216
+ const child = bip32.derive('m')
217
+ const childPub = HD.fromString(child.toPublic().toString())
218
+ const child2 = childPub.derive('m/0')
219
+ expect(child2).toBeDefined()
220
+ expect(child2.toPublic().toString()).toEqual(vector2m0Public)
221
+ })
222
+
223
+ it('should get m/0/2147483647h ext. private key from test vector 2', () => {
224
+ const bip32 = HD.fromString(vector2mPrivate)
225
+ const child = bip32.derive("m/0/2147483647'")
226
+ expect(child).toBeDefined()
227
+ expect(child.toString()).toEqual(vector2m02147483647hPrivate)
228
+ })
229
+
230
+ it('should get m/0/2147483647h ext. public key from test vector 2', () => {
231
+ const bip32 = HD.fromString(vector2mPrivate)
232
+ const child = bip32.derive("m/0/2147483647'")
233
+ expect(child).toBeDefined()
234
+ expect(child.toPublic().toString()).toEqual(vector2m02147483647hPublic)
235
+ })
236
+
237
+ it('should get m/0/2147483647h/1 ext. private key from test vector 2', () => {
238
+ const bip32 = HD.fromString(vector2mPrivate)
239
+ const child = bip32.derive("m/0/2147483647'/1")
240
+ expect(child).toBeDefined()
241
+ expect(child.toString()).toEqual(vector2m02147483647h1Private)
242
+ })
243
+
244
+ it('should get m/0/2147483647h/1 ext. public key from test vector 2', () => {
245
+ const bip32 = HD.fromString(vector2mPrivate)
246
+ const child = bip32.derive("m/0/2147483647'/1")
247
+ expect(child).toBeDefined()
248
+ expect(child.toPublic().toString()).toEqual(vector2m02147483647h1Public)
249
+ })
250
+
251
+ it('should get m/0/2147483647h/1 ext. public key from m/0/2147483647h public key from test vector 2', () => {
252
+ const bip32 = HD.fromString(vector2mPrivate)
253
+ const child = bip32.derive("m/0/2147483647'")
254
+ const childPub = HD.fromString(child.toPublic().toString())
255
+ const child2 = childPub.derive('m/1')
256
+ expect(child2).toBeDefined()
257
+ expect(child2.toPublic().toString()).toEqual(vector2m02147483647h1Public)
258
+ })
259
+
260
+ it('should get m/0/2147483647h/1/2147483646h ext. private key from test vector 2', () => {
261
+ const bip32 = HD.fromString(vector2mPrivate)
262
+ const child = bip32.derive("m/0/2147483647'/1/2147483646'")
263
+ expect(child).toBeDefined()
264
+ expect(child.toString()).toEqual(vector2m02147483647h12147483646hPrivate)
265
+ })
266
+
267
+ it('should get m/0/2147483647h/1/2147483646h ext. public key from test vector 2', () => {
268
+ const bip32 = HD.fromString(vector2mPrivate)
269
+ const child = bip32.derive("m/0/2147483647'/1/2147483646'")
270
+ expect(child).toBeDefined()
271
+ expect(child.toPublic().toString()).toEqual(vector2m02147483647h12147483646hPublic)
272
+ })
273
+
274
+ it('should get m/0/2147483647h/1/2147483646h/2 ext. private key from test vector 2', () => {
275
+ const bip32 = HD.fromString(vector2mPrivate)
276
+ const child = bip32.derive("m/0/2147483647'/1/2147483646'/2")
277
+ expect(child).toBeDefined()
278
+ expect(child.toString()).toEqual(vector2m02147483647h12147483646h2Private)
279
+ })
280
+
281
+ it('should get m/0/2147483647h/1/2147483646h/2 ext. public key from test vector 2', () => {
282
+ const bip32 = HD.fromString(vector2mPrivate)
283
+ const child = bip32.derive("m/0/2147483647'/1/2147483646'/2")
284
+ expect(child).toBeDefined()
285
+ expect(child.toPublic().toString()).toEqual(vector2m02147483647h12147483646h2Public)
286
+ })
287
+
288
+ it('should get m/0/2147483647h/1/2147483646h/2 ext. public key from m/0/2147483647h/2147483646h public key from test vector 2', () => {
289
+ const bip32 = HD.fromString(vector2mPrivate)
290
+ const child = bip32.derive("m/0/2147483647'/1/2147483646'")
291
+ const childPub = HD.fromString(child.toPublic().toString())
292
+ const child2 = childPub.derive('m/2')
293
+ expect(child2).toBeDefined()
294
+ expect(child2.toPublic().toString()).toEqual(vector2m02147483647h12147483646h2Public)
295
+ })
296
+
297
+ describe('#fromRandom', () => {
298
+ it('should not return the same one twice', () => {
299
+ const bip32a = HD.fromRandom()
300
+ const bip32b = HD.fromRandom()
301
+ expect(bip32a.toString()).not.toEqual(bip32b.toString())
302
+ })
303
+ })
304
+
305
+ describe('@fromRandom', () => {
306
+ it('should not return the same one twice', () => {
307
+ const bip32a = HD.fromRandom()
308
+ const bip32b = HD.fromRandom()
309
+ expect(bip32a.toString()).not.toEqual(bip32b.toString())
310
+ })
311
+ })
312
+
313
+ describe('#fromSeed', () => {
314
+ it('should initialize a new Bip32 correctly from test vector 1 seed', () => {
315
+ const hex = vector1master
316
+ const bip32 = HD.fromSeed(toArray(hex, 'hex'))
317
+ expect(bip32).toBeDefined()
318
+ expect(bip32.toString()).toEqual(vector1mPrivate)
319
+ expect(bip32.toPublic().toString()).toEqual(vector1mPublic)
320
+ })
321
+
322
+ it('should initialize a new Bip32 correctly from test vector 2 seed', () => {
323
+ const hex = vector2master
324
+ const bip32 = HD.fromSeed(toArray(hex, 'hex'))
325
+ expect(bip32).toBeDefined()
326
+ expect(bip32.toString()).toEqual(vector2mPrivate)
327
+ expect(bip32.toPublic().toString()).toEqual(vector2mPublic)
328
+ })
329
+ })
330
+
331
+ describe('@fromSeed', () => {
332
+ it('should initialize a new Bip32 correctly from test vector 1 seed', () => {
333
+ const hex = vector1master
334
+ const bip32 = HD.fromSeed(toArray(hex, 'hex'))
335
+ expect(bip32).toBeDefined()
336
+ expect(bip32.toString()).toEqual(vector1mPrivate)
337
+ expect(bip32.toPublic().toString()).toEqual(vector1mPublic)
338
+ })
339
+
340
+ it('should initialize a new Bip32 correctly from test vector 2 seed', () => {
341
+ const hex = vector2master
342
+ const bip32 = HD.fromSeed(toArray(hex, 'hex'))
343
+ expect(bip32).toBeDefined()
344
+ expect(bip32.toString()).toEqual(vector2mPrivate)
345
+ expect(bip32.toPublic().toString()).toEqual(vector2mPublic)
346
+ })
347
+ })
348
+
349
+ describe('#fromBinary', () => {
350
+ it('should make a bip32 from binary', () => {
351
+ const str =
352
352
  'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
353
- const buf = fromBase58Check(str)
354
- let bip32 = HD.fromBinary([...buf.prefix, ...buf.data])
355
- expect(bip32).toBeDefined()
356
- expect(bip32.toString()).toEqual(str)
357
- bip32 = bip32.toPublic()
358
- const xpub = bip32.toString()
359
- bip32 = HD.fromBinary(bip32.toBinary())
360
- expect(bip32.toString()).toEqual(xpub)
361
- })
362
- })
363
-
364
- describe('#toBinary', () => {
365
- it('should return a bip32 buffer', () => {
366
- const str =
353
+ const buf = fromBase58Check(str)
354
+ let bip32 = HD.fromBinary([...buf.prefix, ...buf.data])
355
+ expect(bip32).toBeDefined()
356
+ expect(bip32.toString()).toEqual(str)
357
+ bip32 = bip32.toPublic()
358
+ const xpub = bip32.toString()
359
+ bip32 = HD.fromBinary(bip32.toBinary())
360
+ expect(bip32.toString()).toEqual(xpub)
361
+ })
362
+ })
363
+
364
+ describe('#toBinary', () => {
365
+ it('should return a bip32 buffer', () => {
366
+ const str =
367
367
  'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
368
- const buf = fromBase58Check(str)
369
- const bip32 = HD.fromString(str)
370
- expect(toHex(bip32.toBinary())).toEqual(toHex([...buf.prefix, ...buf.data]))
371
- })
368
+ const buf = fromBase58Check(str)
369
+ const bip32 = HD.fromString(str)
370
+ expect(toHex(bip32.toBinary())).toEqual(toHex([...buf.prefix, ...buf.data]))
372
371
  })
372
+ })
373
373
 
374
- describe('#fromString', () => {
375
- it('should make a bip32 from a string', () => {
376
- const str =
374
+ describe('#fromString', () => {
375
+ it('should make a bip32 from a string', () => {
376
+ const str =
377
377
  'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
378
- const bip32 = HD.fromString(str)
379
- expect(bip32).toBeDefined()
380
- expect(bip32.toString()).toEqual(str)
381
- })
378
+ const bip32 = HD.fromString(str)
379
+ expect(bip32).toBeDefined()
380
+ expect(bip32.toString()).toEqual(str)
382
381
  })
382
+ })
383
383
 
384
- describe('#toString', () => {
385
- const bip32 = new HD()
386
- bip32.fromRandom()
387
- it('should return an xprv string', () => {
388
- expect(bip32.toString().slice(0, 4)).toEqual('xprv')
389
- })
384
+ describe('#toString', () => {
385
+ const bip32 = new HD()
386
+ bip32.fromRandom()
387
+ it('should return an xprv string', () => {
388
+ expect(bip32.toString().slice(0, 4)).toEqual('xprv')
389
+ })
390
390
 
391
- it('should return an xpub string', () => {
392
- expect(bip32.toPublic().toString().slice(0, 4)).toEqual('xpub')
393
- })
391
+ it('should return an xpub string', () => {
392
+ expect(bip32.toPublic().toString().slice(0, 4)).toEqual('xpub')
394
393
  })
394
+ })
395
395
 
396
- describe('#isPrivate', () => {
397
- it('should know if this bip32 is private', () => {
398
- const bip32priv = HD.fromRandom()
399
- const bip32pub = bip32priv.toPublic()
400
- expect(bip32priv.isPrivate()).toEqual(true)
401
- expect(bip32pub.isPrivate()).toEqual(false)
402
- })
396
+ describe('#isPrivate', () => {
397
+ it('should know if this bip32 is private', () => {
398
+ const bip32priv = HD.fromRandom()
399
+ const bip32pub = bip32priv.toPublic()
400
+ expect(bip32priv.isPrivate()).toEqual(true)
401
+ expect(bip32pub.isPrivate()).toEqual(false)
403
402
  })
403
+ })
404
404
  })