Browse Source

return private key rather than HD wallet node

hk-custom-address
Wei Lu 11 years ago
parent
commit
207163704b
  1. 4
      src/wallet.js
  2. 12
      test/wallet.js

4
src/wallet.js

@ -182,11 +182,11 @@ var Wallet = function (seed, options) {
this.getMasterKey = function() { return masterkey } this.getMasterKey = function() { return masterkey }
this.getPrivateKey = function(index) { this.getPrivateKey = function(index) {
return this.externalAccount.derive(index) return this.externalAccount.derive(index).priv
} }
this.getInternalPrivateKey = function(index) { this.getInternalPrivateKey = function(index) {
return this.internalAccount.derive(index) return this.internalAccount.derive(index).priv
} }
this.getPrivateKeyForAddress = function(address) { this.getPrivateKeyForAddress = function(address) {

12
test/wallet.js

@ -79,8 +79,8 @@ describe('Wallet', function() {
it('returns the private key at the given index of external account', function(){ it('returns the private key at the given index of external account', function(){
var wallet = new Wallet(seed, {network: 'testnet'}) var wallet = new Wallet(seed, {network: 'testnet'})
assertPrivateKeyEqual(wallet.getPrivateKey(0), wallet.externalAccount.derive(0)) assertPrivateKeyEqual(wallet.getPrivateKey(0), wallet.externalAccount.derive(0).priv)
assertPrivateKeyEqual(wallet.getPrivateKey(1), wallet.externalAccount.derive(1)) assertPrivateKeyEqual(wallet.getPrivateKey(1), wallet.externalAccount.derive(1).priv)
}) })
}) })
@ -88,8 +88,8 @@ describe('Wallet', function() {
it('returns the private key at the given index of internal account', function(){ it('returns the private key at the given index of internal account', function(){
var wallet = new Wallet(seed, {network: 'testnet'}) var wallet = new Wallet(seed, {network: 'testnet'})
assertPrivateKeyEqual(wallet.getInternalPrivateKey(0), wallet.internalAccount.derive(0)) assertPrivateKeyEqual(wallet.getInternalPrivateKey(0), wallet.internalAccount.derive(0).priv)
assertPrivateKeyEqual(wallet.getInternalPrivateKey(1), wallet.internalAccount.derive(1)) assertPrivateKeyEqual(wallet.getInternalPrivateKey(1), wallet.internalAccount.derive(1).priv)
}) })
}) })
@ -101,9 +101,9 @@ describe('Wallet', function() {
wallet.generateAddress() wallet.generateAddress()
assertPrivateKeyEqual(wallet.getPrivateKeyForAddress("n2fiWrHqD6GM5GiEqkbWAc6aaZQp3ba93X"), assertPrivateKeyEqual(wallet.getPrivateKeyForAddress("n2fiWrHqD6GM5GiEqkbWAc6aaZQp3ba93X"),
wallet.externalAccount.derive(1)) wallet.externalAccount.derive(1).priv)
assertPrivateKeyEqual(wallet.getPrivateKeyForAddress("mnXiDR4MKsFxcKJEZjx4353oXvo55iuptn"), assertPrivateKeyEqual(wallet.getPrivateKeyForAddress("mnXiDR4MKsFxcKJEZjx4353oXvo55iuptn"),
wallet.internalAccount.derive(0)) wallet.internalAccount.derive(0).priv)
}) })
it('raises an error when address is not found', function(){ it('raises an error when address is not found', function(){

Loading…
Cancel
Save