AsReceiver implied
This commit is contained in:
parent
558a7672ef
commit
219aa528c8
|
@ -35,7 +35,7 @@ Stealthkey.prototype.fromRandom = function() {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
Stealthkey.prototype.getSharedKeypairAsReceiver = function(senderPubkey) {
|
Stealthkey.prototype.getSharedKeypair = function(senderPubkey) {
|
||||||
var sharedSecretPoint = senderPubkey.point.mul(this.scanKeypair.privkey.bn);
|
var sharedSecretPoint = senderPubkey.point.mul(this.scanKeypair.privkey.bn);
|
||||||
var sharedSecretPubkey = Pubkey({point: sharedSecretPoint});
|
var sharedSecretPubkey = Pubkey({point: sharedSecretPoint});
|
||||||
var buf = sharedSecretPubkey.toDER(true);
|
var buf = sharedSecretPubkey.toDER(true);
|
||||||
|
@ -44,15 +44,15 @@ Stealthkey.prototype.getSharedKeypairAsReceiver = function(senderPubkey) {
|
||||||
return sharedKeypair;
|
return sharedKeypair;
|
||||||
};
|
};
|
||||||
|
|
||||||
Stealthkey.prototype.getReceivePubkeyAsReceiver = function(senderPubkey) {
|
Stealthkey.prototype.getReceivePubkey = function(senderPubkey) {
|
||||||
var sharedKeypair = this.getSharedKeypairAsReceiver(senderPubkey);
|
var sharedKeypair = this.getSharedKeypair(senderPubkey);
|
||||||
var pubkey = Pubkey({point: this.payloadKeypair.pubkey.point.add(sharedKeypair.pubkey.point)});
|
var pubkey = Pubkey({point: this.payloadKeypair.pubkey.point.add(sharedKeypair.pubkey.point)});
|
||||||
|
|
||||||
return pubkey;
|
return pubkey;
|
||||||
};
|
};
|
||||||
|
|
||||||
Stealthkey.prototype.getReceiveKeypair = function(senderPubkey) {
|
Stealthkey.prototype.getReceiveKeypair = function(senderPubkey) {
|
||||||
var sharedKeypair = this.getSharedKeypairAsReceiver(senderPubkey);
|
var sharedKeypair = this.getSharedKeypair(senderPubkey);
|
||||||
var privkey = Privkey({bn: this.payloadKeypair.privkey.bn.add(sharedKeypair.privkey.bn).mod(Point.getN())});
|
var privkey = Privkey({bn: this.payloadKeypair.privkey.bn.add(sharedKeypair.privkey.bn).mod(Point.getN())});
|
||||||
var key = Keypair({privkey: privkey});
|
var key = Keypair({privkey: privkey});
|
||||||
key.privkey2pubkey();
|
key.privkey2pubkey();
|
||||||
|
@ -61,7 +61,7 @@ Stealthkey.prototype.getReceiveKeypair = function(senderPubkey) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Stealthkey.prototype.isForMe = function(senderPubkey, myPossiblePubkeyhash) {
|
Stealthkey.prototype.isForMe = function(senderPubkey, myPossiblePubkeyhash) {
|
||||||
var pubkey = this.getReceivePubkeyAsReceiver(senderPubkey);
|
var pubkey = this.getReceivePubkey(senderPubkey);
|
||||||
var pubkeybuf = pubkey.toDER(true);
|
var pubkeybuf = pubkey.toDER(true);
|
||||||
var pubkeyhash = Hash.sha256ripemd160(pubkeybuf);
|
var pubkeyhash = Hash.sha256ripemd160(pubkeybuf);
|
||||||
|
|
||||||
|
|
|
@ -71,13 +71,13 @@ describe('StealthAddress', function() {
|
||||||
(key instanceof Keypair).should.equal(true);
|
(key instanceof Keypair).should.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the same key as Stealthkey.prototype.getSharedKeypairAsReceiver', function() {
|
it('should return the same key as Stealthkey.prototype.getSharedKeypair', function() {
|
||||||
var sa = new StealthAddress();
|
var sa = new StealthAddress();
|
||||||
sa.payloadPubkey = stealthkey.payloadKeypair.pubkey;
|
sa.payloadPubkey = stealthkey.payloadKeypair.pubkey;
|
||||||
sa.scanPubkey = stealthkey.scanKeypair.pubkey;
|
sa.scanPubkey = stealthkey.scanKeypair.pubkey;
|
||||||
var key = sa.getSharedKeypair(senderKeypair);
|
var key = sa.getSharedKeypair(senderKeypair);
|
||||||
|
|
||||||
var key2 = stealthkey.getSharedKeypairAsReceiver(senderKeypair.pubkey);
|
var key2 = stealthkey.getSharedKeypair(senderKeypair.pubkey);
|
||||||
key.toString().should.equal(key2.toString());
|
key.toString().should.equal(key2.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -90,9 +90,9 @@ describe('StealthAddress', function() {
|
||||||
(pubkey instanceof Pubkey).should.equal(true);
|
(pubkey instanceof Pubkey).should.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the same pubkey as getReceivePubkeyAsReceiver', function() {
|
it('should return the same pubkey as getReceivePubkey', function() {
|
||||||
var pubkey = StealthAddress().fromStealthkey(stealthkey).getReceivePubkey(senderKeypair);
|
var pubkey = StealthAddress().fromStealthkey(stealthkey).getReceivePubkey(senderKeypair);
|
||||||
var pubkey2 = stealthkey.getReceivePubkeyAsReceiver(senderKeypair.pubkey);
|
var pubkey2 = stealthkey.getReceivePubkey(senderKeypair.pubkey);
|
||||||
pubkey2.toString().should.equal(pubkey.toString());
|
pubkey2.toString().should.equal(pubkey.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -62,19 +62,19 @@ describe('Stealthkey', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getSharedKeypairAsReceiver', function() {
|
describe('#getSharedKeypair', function() {
|
||||||
|
|
||||||
it('should return a key', function() {
|
it('should return a key', function() {
|
||||||
var key = stealthkey.getSharedKeypairAsReceiver(senderKeypair.pubkey);
|
var key = stealthkey.getSharedKeypair(senderKeypair.pubkey);
|
||||||
(key instanceof Keypair).should.equal(true);
|
(key instanceof Keypair).should.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getReceivePubkeyAsReceiver', function() {
|
describe('#getReceivePubkey', function() {
|
||||||
|
|
||||||
it('should return a pubkey', function() {
|
it('should return a pubkey', function() {
|
||||||
var pubkey = stealthkey.getReceivePubkeyAsReceiver(senderKeypair.pubkey);
|
var pubkey = stealthkey.getReceivePubkey(senderKeypair.pubkey);
|
||||||
(pubkey instanceof Pubkey).should.equal(true);
|
(pubkey instanceof Pubkey).should.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -87,9 +87,9 @@ describe('Stealthkey', function() {
|
||||||
(key instanceof Keypair).should.equal(true);
|
(key instanceof Keypair).should.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a key with the same pubkey as getReceivePubkeyAsReceiver', function() {
|
it('should return a key with the same pubkey as getReceivePubkey', function() {
|
||||||
var key = stealthkey.getReceiveKeypair(senderKeypair.pubkey);
|
var key = stealthkey.getReceiveKeypair(senderKeypair.pubkey);
|
||||||
var pubkey = stealthkey.getReceivePubkeyAsReceiver(senderKeypair.pubkey);
|
var pubkey = stealthkey.getReceivePubkey(senderKeypair.pubkey);
|
||||||
key.pubkey.toString().should.equal(pubkey.toString());
|
key.pubkey.toString().should.equal(pubkey.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue