keyring json.

This commit is contained in:
Christopher Jeffrey 2016-06-30 22:18:28 -07:00
parent 59cdc96c9f
commit cfdbe2e970
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -620,9 +620,9 @@ KeyRing.prototype.toJSON = function toJSON() {
index: this.index,
key: utils.toBase58(this.key),
keys: this.keys.map(utils.toBase58),
keyAddress: this.getKeyAddress(),
scriptAddress: this.getScriptAddress(),
programAddress: this.getProgramAddress()
keyAddress: this.getKeyAddress('base58'),
scriptAddress: this.getScriptAddress('base58'),
programAddress: this.getProgramAddress('base58')
};
};
@ -635,6 +635,20 @@ KeyRing.prototype.toJSON = function toJSON() {
KeyRing.prototype.fromJSON = function fromJSON(json) {
var i;
assert(json);
assert(typeof json.network === 'string');
assert(typeof json.type === 'string');
assert(utils.isNumber(json.m));
assert(utils.isNumber(json.n));
assert(typeof json.witness === 'boolean');
assert(!json.id || typeof json.id === 'string');
assert(!json.name || typeof json.name === 'string');
assert(utils.isNumber(json.account));
assert(utils.isNumber(json.change));
assert(utils.isNumber(json.index));
assert(typeof json.key === 'string');
assert(Array.isArray(json.keys));
this.nework = bcoin.network.get(json.network);
this.type = json.type;
this.m = json.m;