diff --git a/lib/expmt/stealthaddress.js b/lib/expmt/stealthaddress.js index 0d82128..66ae9c6 100644 --- a/lib/expmt/stealthaddress.js +++ b/lib/expmt/stealthaddress.js @@ -26,6 +26,15 @@ StealthAddress.prototype.set = function(obj) { return this; }; +StealthAddress.prototype.fromJSON = function(json) { + this.fromString(json); + return this; +}; + +StealthAddress.prototype.toJSON = function() { + return this.toString(); +}; + StealthAddress.prototype.fromStealthkey = function(stealthkey) { this.set({ payloadPubkey: stealthkey.payloadKeypair.pubkey, diff --git a/test/stealthaddress.js b/test/stealthaddress.js index 0c8f56d..8ab30a9 100644 --- a/test/stealthaddress.js +++ b/test/stealthaddress.js @@ -38,6 +38,25 @@ describe('StealthAddress', function() { should.exist(sa); }); + describe('#fromJSON', function() { + + it('should give a stealthkey address with the right pubkeys', function() { + var sa = new StealthAddress(); + sa.fromJSON(addressString); + sa.payloadPubkey.toString().should.equal(stealthkey.payloadKeypair.pubkey.toString()); + sa.scanPubkey.toString().should.equal(stealthkey.scanKeypair.pubkey.toString()); + }); + + }); + + describe('#toJSON', function() { + + it('should return this known address string', function() { + StealthAddress().fromJSON(addressString).toJSON().should.equal(addressString); + }); + + }); + describe('#fromBuffer', function() { it('should give a stealthkey address with the right pubkeys', function() {