From 258dab9d6d06a0de013e4dc89bb9b2807cbe98a2 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Tue, 2 Sep 2014 12:08:33 -0700 Subject: [PATCH] convenience: Stealth(payloadKeypair, scanKeypair) --- lib/expmt/stealthkey.js | 15 ++++++++++++--- test/stealthkey.js | 8 ++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/expmt/stealthkey.js b/lib/expmt/stealthkey.js index 9d25830d2..f249d4831 100644 --- a/lib/expmt/stealthkey.js +++ b/lib/expmt/stealthkey.js @@ -6,11 +6,20 @@ var Hash = require('../hash'); var KDF = require('../kdf'); var base58check = require('../base58check'); -var Stealthkey = function Stealthkey(obj) { +var Stealthkey = function Stealthkey(payloadKeypair, scanKeypair) { if (!(this instanceof Stealthkey)) - return new Stealthkey(obj); - if (obj) + return new Stealthkey(payloadKeypair, scanKeypair); + + if (payloadKeypair instanceof Keypair) { + this.set({ + payloadKeypair: payloadKeypair, + scanKeypair: scanKeypair + }); + } + else if (payloadKeypair) { + var obj = payloadKeypair; this.set(obj); + } }; Stealthkey.prototype.set = function(obj) { diff --git a/test/stealthkey.js b/test/stealthkey.js index 7b2a871a0..5a44fa6e5 100644 --- a/test/stealthkey.js +++ b/test/stealthkey.js @@ -36,6 +36,14 @@ describe('Stealthkey', function() { should.exist(stealthkey); }); + it('should create a new stealthkey with both keypairs in the constructor', function() { + var keypair1 = Keypair(); + var keypair2 = Keypair(); + var stealthkey = Stealthkey(keypair1, keypair2); + should.exist(stealthkey.payloadKeypair); + should.exist(stealthkey.scanKeypair); + }); + describe('#set', function() { it('should set payload key', function() {