@@ -17,8 +17,8 @@ describe("hdkey", function () {
1717 var hdkey = HDKey . fromMasterSeed ( Buffer . from ( f . seed , "hex" ) ) ;
1818 var childkey = hdkey . derive ( f . path ) ;
1919
20- assert . equal ( childkey . privateExtendedKey , f . private ) ;
21- assert . equal ( childkey . publicExtendedKey , f . public ) ;
20+ assert . equal ( childkey . getPrivateExtendedKey ( ) , f . private ) ;
21+ assert . equal ( childkey . getPublicExtendedKey ( ) , f . public ) ;
2222 } ) ;
2323
2424 describe ( "> " + f . path + " toJSON() / fromJSON()" , function ( ) {
@@ -34,44 +34,44 @@ describe("hdkey", function () {
3434 assert . deepEqual ( childkey . toJSON ( ) , obj ) ;
3535
3636 var newKey = HDKey . fromJSON ( obj ) ;
37- assert . strictEqual ( newKey . privateExtendedKey , f . private ) ;
38- assert . strictEqual ( newKey . publicExtendedKey , f . public ) ;
37+ assert . strictEqual ( newKey . getPrivateExtendedKey ( ) , f . private ) ;
38+ assert . strictEqual ( newKey . getPublicExtendedKey ( ) , f . public ) ;
3939 } ) ;
4040 } ) ;
4141 } ) ;
4242 } ) ;
4343
4444 describe ( "- privateKey" , function ( ) {
4545 it ( "should throw an error if incorrect key size" , function ( ) {
46- var hdkey = new HDKey ( ) ;
46+ var hdkey = HDKey . create ( ) ;
4747 assert . throws ( function ( ) {
48- hdkey . privateKey = Buffer . from ( [ 1 , 2 , 3 , 4 ] ) ;
48+ hdkey . setPrivateKey ( Buffer . from ( [ 1 , 2 , 3 , 4 ] ) ) ;
4949 } , / k e y m u s t b e 3 2 / ) ;
5050 } ) ;
5151 } ) ;
5252
5353 describe ( "- publicKey" , function ( ) {
5454 it ( "should throw an error if incorrect key size" , function ( ) {
5555 assert . throws ( function ( ) {
56- var hdkey = new HDKey ( ) ;
57- hdkey . publicKey = Buffer . from ( [ 1 , 2 , 3 , 4 ] ) ;
56+ var hdkey = HDKey . create ( ) ;
57+ hdkey . setPublicKey ( Buffer . from ( [ 1 , 2 , 3 , 4 ] ) ) ;
5858 } , / k e y m u s t b e 3 3 o r 6 5 / ) ;
5959 } ) ;
6060
6161 it ( "should not throw if key is 33 bytes (compressed)" , function ( ) {
6262 var priv = secureRandom . randomBuffer ( 32 ) ;
6363 var pub = curve . G . multiply ( BigInteger . fromBuffer ( priv ) ) . getEncoded ( true ) ;
6464 assert . equal ( pub . length , 33 ) ;
65- var hdkey = new HDKey ( ) ;
66- hdkey . publicKey = pub ;
65+ var hdkey = HDKey . create ( ) ;
66+ hdkey . setPublicKey ( pub ) ;
6767 } ) ;
6868
6969 it ( "should not throw if key is 65 bytes (not compressed)" , function ( ) {
7070 var priv = secureRandom . randomBuffer ( 32 ) ;
7171 var pub = curve . G . multiply ( BigInteger . fromBuffer ( priv ) ) . getEncoded ( false ) ;
7272 assert . equal ( pub . length , 65 ) ;
73- var hdkey = new HDKey ( ) ;
74- hdkey . publicKey = pub ;
73+ var hdkey = HDKey . create ( ) ;
74+ hdkey . setPublicKey ( pub ) ;
7575 } ) ;
7676 } ) ;
7777
@@ -92,7 +92,7 @@ describe("hdkey", function () {
9292 "9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271" ,
9393 ) ;
9494 assert . equal (
95- hdkey . privateKey . toString ( "hex" ) ,
95+ hdkey . getPrivateKey ( ) . toString ( "hex" ) ,
9696 "bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23" ,
9797 ) ;
9898 assert . equal (
@@ -121,7 +121,7 @@ describe("hdkey", function () {
121121 hdkey . chainCode . toString ( "hex" ) ,
122122 "9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271" ,
123123 ) ;
124- assert . equal ( hdkey . privateKey , null ) ;
124+ assert . equal ( hdkey . getPrivateKey ( ) , null ) ;
125125 assert . equal (
126126 hdkey . publicKey . toString ( "hex" ) ,
127127 "024d902e1a2fc7a8755ab5b694c575fce742c48d9ff192e63df5193e4c7afe1f9c" ,
@@ -146,7 +146,7 @@ describe("hdkey", function () {
146146 hdkey . chainCode . toString ( "hex" ) ,
147147 "9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271" ,
148148 ) ;
149- assert . equal ( hdkey . privateKey , null ) ;
149+ assert . equal ( hdkey . getPrivateKey ( ) , null ) ;
150150 assert . equal (
151151 hdkey . publicKey . toString ( "hex" ) ,
152152 "024d902e1a2fc7a8755ab5b694c575fce742c48d9ff192e63df5193e4c7afe1f9c" ,
@@ -203,7 +203,7 @@ describe("hdkey", function () {
203203
204204 var expected =
205205 "xpub6JdKdVJtdx6sC3nh87pDvnGhotXuU5Kz6Qy7Piy84vUAwWSYShsUGULE8u6gCivTHgz7cCKJHiXaaMeieB4YnoFVAsNgHHKXJ2mN6jCMbH1" ;
206- assert . equal ( derivedHDKey . publicExtendedKey , expected ) ;
206+ assert . equal ( derivedHDKey . getPublicExtendedKey ( ) , expected ) ;
207207 } ) ;
208208 } ) ;
209209
@@ -215,7 +215,7 @@ describe("hdkey", function () {
215215 var newKey = masterKey . derive ( "m/44'/6'/4'" ) ;
216216 var expected =
217217 "xprv9ymoag6W7cR6KBcJzhCM6qqTrb3rRVVwXKzwNqp1tDWcwierEv3BA9if3ARHMhMPh9u2jNoutcgpUBLMfq3kADDo7LzfoCnhhXMRGX3PXDx" ;
218- assert . equal ( newKey . privateExtendedKey , expected ) ;
218+ assert . equal ( newKey . getPrivateExtendedKey ( ) , expected ) ;
219219 } ) ;
220220 } ) ;
221221
@@ -231,12 +231,12 @@ describe("hdkey", function () {
231231 "xprv9s21ZrQH143K3ckY9DgU79uMTJkQRLdbCCVDh81SnxTgPzLLGax6uHeBULTtaEtcAvKjXfT7ZWtHzKjTpujMkUd9dDb8msDeAfnJxrgAYhr" ;
232232 var hdkey = HDKey . fromExtendedKey ( key ) ;
233233 assert . equal (
234- hdkey . privateKey . toString ( "hex" ) ,
234+ hdkey . getPrivateKey ( ) . toString ( "hex" ) ,
235235 "00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd" ,
236236 ) ;
237237 var derived = hdkey . derive ( "m/44'/0'/0'/0/0'" ) ;
238238 assert . equal (
239- derived . privateKey . toString ( "hex" ) ,
239+ derived . getPrivateKey ( ) . toString ( "hex" ) ,
240240 "3348069561d2a0fb925e74bf198762acc47dce7db27372257d2d959a9e6f8aeb" ,
241241 ) ;
242242 } ) ;
@@ -247,14 +247,14 @@ describe("hdkey", function () {
247247 var seed = "000102030405060708090a0b0c0d0e0f" ;
248248 var masterKey = HDKey . fromMasterSeed ( Buffer . from ( seed , "hex" ) ) ;
249249
250- assert . ok ( masterKey . privateExtendedKey , "xpriv is truthy" ) ;
251- masterKey . _privateKey = null ;
250+ assert . ok ( masterKey . getPrivateExtendedKey ( ) , "xpriv is truthy" ) ;
251+ masterKey . wipePrivateData ( ) ;
252252
253253 assert . doesNotThrow ( function ( ) {
254- masterKey . privateExtendedKey ;
254+ masterKey . getPrivateExtendedKey ( ) ;
255255 } ) ;
256256
257- assert . ok ( ! masterKey . privateExtendedKey , "xpriv is falsy" ) ;
257+ assert . ok ( ! masterKey . getPrivateExtendedKey ( ) , "xpriv is falsy" ) ;
258258 } ) ;
259259 } ) ;
260260
@@ -274,7 +274,8 @@ describe("hdkey", function () {
274274 describe ( " - when the path given to derive does not begin with master extended key" , function ( ) {
275275 it ( "should throw an error" , function ( ) {
276276 assert . throws ( function ( ) {
277- HDKey . prototype . derive ( "123" ) ;
277+ const hdkey = HDKey . create ( ) ;
278+ hdkey . derive ( "123" ) ;
278279 } , / P a t h m u s t s t a r t w i t h " m " o r " M " / ) ;
279280 } ) ;
280281 } ) ;
@@ -284,16 +285,16 @@ describe("hdkey", function () {
284285 const hdkey = HDKey . fromMasterSeed (
285286 Buffer . from ( fixtures . valid [ 6 ] . seed , "hex" ) ,
286287 ) . wipePrivateData ( ) ;
287- assert . equal ( hdkey . privateKey , null ) ;
288- assert . equal ( hdkey . privateExtendedKey , null ) ;
288+ assert . equal ( hdkey . getPrivateKey ( ) , null ) ;
289+ assert . equal ( hdkey . getPrivateExtendedKey ( ) , null ) ;
289290 assert . throws (
290291 ( ) => hdkey . sign ( Buffer . alloc ( 32 ) ) ,
291292 "shouldn't be able to sign" ,
292293 ) ;
293294 const childKey = hdkey . derive ( "m/0" ) ;
294- assert . equal ( childKey . publicExtendedKey , fixtures . valid [ 7 ] . public ) ;
295- assert . equal ( childKey . privateKey , null ) ;
296- assert . equal ( childKey . privateExtendedKey , null ) ;
295+ assert . equal ( childKey . getPublicExtendedKey ( ) , fixtures . valid [ 7 ] . public ) ;
296+ assert . equal ( childKey . getPrivateKey ( ) , null ) ;
297+ assert . equal ( childKey . getPrivateExtendedKey ( ) , null ) ;
297298 } ) ;
298299
299300 it ( "should have correct data" , function ( ) {
@@ -332,32 +333,32 @@ describe("hdkey", function () {
332333 it ( "should not throw if called on hdkey without private data" , function ( ) {
333334 const hdkey = HDKey . fromExtendedKey ( fixtures . valid [ 0 ] . public ) ;
334335 assert . doesNotThrow ( ( ) => hdkey . wipePrivateData ( ) ) ;
335- assert . equal ( hdkey . publicExtendedKey , fixtures . valid [ 0 ] . public ) ;
336+ assert . equal ( hdkey . getPublicExtendedKey ( ) , fixtures . valid [ 0 ] . public ) ;
336337 } ) ;
337338 } ) ;
338339
339340 describe ( "Deriving a child key does not mutate the internal state" , function ( ) {
340341 it ( "should not mutate it when deriving with a private key" , function ( ) {
341342 const hdkey = HDKey . fromExtendedKey ( fixtures . valid [ 0 ] . private ) ;
342343 const path = "m/123" ;
343- const privateKeyBefore = hdkey . privateKey . toString ( "hex" ) ;
344+ const privateKeyBefore = hdkey . getPrivateKey ( ) . toString ( "hex" ) ;
344345
345346 const child = hdkey . derive ( path ) ;
346- assert . equal ( hdkey . privateKey . toString ( "hex" ) , privateKeyBefore ) ;
347+ assert . equal ( hdkey . getPrivateKey ( ) . toString ( "hex" ) , privateKeyBefore ) ;
347348
348349 const child2 = hdkey . derive ( path ) ;
349- assert . equal ( hdkey . privateKey . toString ( "hex" ) , privateKeyBefore ) ;
350+ assert . equal ( hdkey . getPrivateKey ( ) . toString ( "hex" ) , privateKeyBefore ) ;
350351
351352 const child3 = hdkey . derive ( path ) ;
352- assert . equal ( hdkey . privateKey . toString ( "hex" ) , privateKeyBefore ) ;
353+ assert . equal ( hdkey . getPrivateKey ( ) . toString ( "hex" ) , privateKeyBefore ) ;
353354
354355 assert . equal (
355- child . privateKey . toString ( "hex" ) ,
356- child2 . privateKey . toString ( "hex" ) ,
356+ child . getPrivateKey ( ) . toString ( "hex" ) ,
357+ child2 . getPrivateKey ( ) . toString ( "hex" ) ,
357358 ) ;
358359 assert . equal (
359- child2 . privateKey . toString ( "hex" ) ,
360- child3 . privateKey . toString ( "hex" ) ,
360+ child2 . getPrivateKey ( ) . toString ( "hex" ) ,
361+ child3 . getPrivateKey ( ) . toString ( "hex" ) ,
361362 ) ;
362363 } ) ;
363364
0 commit comments