Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KeyStore.dumpAddress and KeyStore.loadAddress #145

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Keystore.resetAddress and Keystore.getAddressAndEncKeys
  • Loading branch information
Yuanfei Zhu committed Apr 29, 2017
commit a88e412e8c214590d7e6c5dd7038c809e25cfcf3
37 changes: 33 additions & 4 deletions lib/keystore.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,29 @@ KeyStore.prototype.getAddresses = function (hdPathString) {

};

KeyStore.prototype.getAddressWithEncKey = function (address, hdPathString) {
address = strip0x(address);

return {
address: address,
encPrivKey: this.ksData[hdPathString].encPrivKeys[address]
}
}

KeyStore.prototype.getAddressWithEncKeys = function (hdPathString) {
if (hdPathString === undefined) {
hdPathString = this.defaultHdPathString;
}

this._checkHdPathPurpose(hdPathString, 'sign');

let addresses = this.ksData[hdPathString].addresses;

return addresses.map(function(addr) {
return this.getAddressWithEncKey(addr, hdPathString);
});
}

/**
* Serialize a address
*
Expand All @@ -450,10 +473,7 @@ KeyStore.prototype.dumpAddress = function (address, hdPathString) {
address = strip0x(address);
this._checkAddressExists(address, hdPathString);

var jsonAddr = {
address: address,
encPrivKey: this.ksData[hdPathString].encPrivKeys[address]
}
var jsonAddr = this.getAddressWithEncKey(address, hdPathString)

return JSON.stringify(jsonAddr);
}
Expand Down Expand Up @@ -546,6 +566,15 @@ KeyStore.prototype.exportPrivateKey = function (address, pwDerivedKey, hdPathStr
return privKey;
};

KeyStore.prototype.resetAddress = function(hdPathString) {
if (hdPathString === undefined) {
hdPathString = this.defaultHdPathString;
}

this.ksData[hdPathString].encPrivKeys = [];
this.ksData[hdPathString].addresses = [];
};

KeyStore.prototype.generateNewAddress = function(pwDerivedKey, n, hdPathString) {

if(!this.isDerivedKeyCorrect(pwDerivedKey)) {
Expand Down