From 48ae69cab06d0f8278091c1a0bdda1b3d6a3fbf2 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Tue, 2 Sep 2014 14:23:11 -0700 Subject: [PATCH] convenience: StealthAddress(str) or StealthAddress(buf) --- lib/expmt/stealthaddress.js | 17 +++++++++++++---- test/stealthaddress.js | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/expmt/stealthaddress.js b/lib/expmt/stealthaddress.js index b7d58a6..9f6e3f9 100644 --- a/lib/expmt/stealthaddress.js +++ b/lib/expmt/stealthaddress.js @@ -2,12 +2,21 @@ var Stealthkey = require('./stealthkey'); var Base58check = require('../base58check'); var Pubkey = require('../pubkey'); -var StealthAddress = function StealthAddress(obj) { +var StealthAddress = function StealthAddress(addrstr) { if (!(this instanceof StealthAddress)) - return new StealthAddress(obj); - - if (obj) + return new StealthAddress(addrstr); + + if (typeof addrstr === 'string') { + this.fromString(addrstr) + } + else if (Buffer.isBuffer(addrstr)) { + var buf = addrstr; + this.fromBuffer(buf); + } + else if (addrstr) { + var obj = addrstr; this.set(obj); + } }; StealthAddress.prototype.set = function(obj) { diff --git a/test/stealthaddress.js b/test/stealthaddress.js index a976b6c..872b1de 100644 --- a/test/stealthaddress.js +++ b/test/stealthaddress.js @@ -32,6 +32,10 @@ describe('StealthAddress', function() { should.exist(sa); sa = StealthAddress(); should.exist(sa); + sa = StealthAddress(addressString); + should.exist(sa); + sa = StealthAddress(Base58check.decode(addressString)); + should.exist(sa); }); describe('#fromBuffer', function() {