Browse Source

Key.prototype.set

patch-2
Ryan X. Charles 11 years ago
parent
commit
28d3a40704
  1. 6
      lib/expmt/stealth.js
  2. 2
      lib/kdf.js
  3. 14
      lib/key.js
  4. 10
      test/test.key.js

6
lib/expmt/stealth.js

@ -22,9 +22,9 @@ Stealth.prototype.fromAddressBuffer = function(buf) {
var sPubBuf = buf.slice(33, 66);
var payloadPubkey = Pubkey().fromDER(pPubBuf);
this.payloadKey = Key(undefined, payloadPubkey);
this.payloadKey = Key({pubkey: payloadPubkey});
var scanPubkey = Pubkey().fromDER(sPubBuf);
this.scanKey = Key(undefined, scanPubkey);
this.scanKey = Key({pubkey: scanPubkey});
return this;
};
@ -78,7 +78,7 @@ Stealth.prototype.getReceivePubkeyAsSender = function(senderKey) {
Stealth.prototype.getReceiveKey = function(senderPubkey) {
var sharedKey = this.getSharedKeyAsReceiver(senderPubkey);
var privkey = Privkey(this.payloadKey.privkey.bn.add(sharedKey.privkey.bn).mod(Point.getN()));
var key = Key(privkey);
var key = Key({privkey: privkey});
key.privkey2pubkey();
return key;

2
lib/kdf.js

@ -14,7 +14,7 @@ KDF.buf2key = function(buf) {
KDF.sha256hmac2key = function(buf) {
var privkey = KDF.sha256hmac2privkey(buf);
var key = new Key(privkey);
var key = new Key({privkey: privkey});
key.privkey2pubkey();
return key;
};

14
lib/key.js

@ -5,11 +5,17 @@ var Random = require('./random');
var Bn = require('./bn');
var point = require('./point');
var Key = function Key(privkey, pubkey) {
var Key = function Key(obj) {
if (!(this instanceof Key))
return new Key(privkey, pubkey);
this.privkey = privkey;
this.pubkey = pubkey;
return new Key(obj);
if (obj)
this.set(obj);
};
Key.prototype.set = function(obj) {
this.privkey = obj.privkey || this.privkey || undefined;
this.pubkey = obj.pubkey || this.pubkey || undefined;
return this;
};
Key.prototype.fromRandom = function() {

10
test/test.key.js

@ -16,12 +16,20 @@ describe('Key', function() {
it('should make a key with a priv and pub', function() {
var priv = new Privkey();
var pub = new Pubkey();
var key = new Key(priv, pub);
var key = new Key({privkey: priv, pubkey: pub});
should.exist(key);
should.exist(key.privkey);
should.exist(key.pubkey);
});
describe("#set", function() {
it('should make a new priv and pub', function() {
should.exist(Key().set({privkey: Privkey()}).privkey);
});
});
describe("#fromRandom", function() {
it('should make a new priv and pub', function() {

Loading…
Cancel
Save