From 1c0caac8c3ad57efe4706e06115211756ad50a1d Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 12 Dec 2014 18:39:16 -0500 Subject: [PATCH] HDKeys: Added toObject method and changed toJSON to return a string --- lib/hdprivatekey.js | 6 +++++- lib/hdpublickey.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/hdprivatekey.js b/lib/hdprivatekey.js index 0145912..b1b4862 100644 --- a/lib/hdprivatekey.js +++ b/lib/hdprivatekey.js @@ -406,7 +406,7 @@ HDPrivateKey.prototype.toString = function() { * * @return {Object} */ -HDPrivateKey.prototype.toJSON = function() { +HDPrivateKey.prototype.toObject = function toObject() { return { network: Network.get(BufferUtil.integerFromBuffer(this._buffers.version)).name, depth: BufferUtil.integerFromSingleByteBuffer(this._buffers.depth), @@ -420,6 +420,10 @@ HDPrivateKey.prototype.toJSON = function() { }; }; +HDPrivateKey.prototype.toJSON = function toJSON() { + return JSON.stringify(this.toObject()); +}; + HDPrivateKey.DefaultDepth = 0; HDPrivateKey.DefaultFingerprint = 0; HDPrivateKey.DefaultChildIndex = 0; diff --git a/lib/hdpublickey.js b/lib/hdpublickey.js index 7a64019..2c0ff6e 100644 --- a/lib/hdpublickey.js +++ b/lib/hdpublickey.js @@ -366,7 +366,7 @@ HDPublicKey.prototype.toString = function () { * * xpubkey: the string with the base58 representation of this extended key * * checksum: the base58 checksum of xpubkey */ -HDPublicKey.prototype.toJSON = function () { +HDPublicKey.prototype.toObject = function toObject() { return { network: Network.get(BufferUtil.integerFromBuffer(this._buffers.version)).name, depth: BufferUtil.integerFromSingleByteBuffer(this._buffers.depth), @@ -380,6 +380,10 @@ HDPublicKey.prototype.toJSON = function () { }; }; +HDPublicKey.prototype.toJSON = function toJSON() { + return JSON.stringify(this.toObject()); +}; + HDPublicKey.Hardened = 0x80000000; HDPublicKey.RootElementAlias = ['m', 'M'];