|
@ -1,6 +1,7 @@ |
|
|
var Stealthkey = require('./stealthkey'); |
|
|
var Stealthkey = require('./stealthkey'); |
|
|
var Base58check = require('../base58check'); |
|
|
var Base58check = require('../base58check'); |
|
|
var Pubkey = require('../pubkey'); |
|
|
var Pubkey = require('../pubkey'); |
|
|
|
|
|
var KDF = require('../kdf'); |
|
|
|
|
|
|
|
|
var StealthAddress = function StealthAddress(addrstr) { |
|
|
var StealthAddress = function StealthAddress(addrstr) { |
|
|
if (!(this instanceof StealthAddress)) |
|
|
if (!(this instanceof StealthAddress)) |
|
@ -27,8 +28,8 @@ StealthAddress.prototype.set = function(obj) { |
|
|
|
|
|
|
|
|
StealthAddress.prototype.fromStealthkey = function(stealthkey) { |
|
|
StealthAddress.prototype.fromStealthkey = function(stealthkey) { |
|
|
this.set({ |
|
|
this.set({ |
|
|
payloadPubkey: stealthkey.payloadPubkey, |
|
|
payloadPubkey: stealthkey.payloadKeypair.pubkey, |
|
|
scanPubkey: stealthkey.scanPubkey |
|
|
scanPubkey: stealthkey.scanKeypair.pubkey |
|
|
}); |
|
|
}); |
|
|
return this; |
|
|
return this; |
|
|
}; |
|
|
}; |
|
@ -53,6 +54,22 @@ StealthAddress.prototype.fromString = function(str) { |
|
|
return this; |
|
|
return this; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
StealthAddress.prototype.getSharedKeypair = function(senderKeypair) { |
|
|
|
|
|
var sharedSecretPoint = this.scanPubkey.point.mul(senderKeypair.privkey.bn); |
|
|
|
|
|
var sharedSecretPubkey = Pubkey(sharedSecretPoint); |
|
|
|
|
|
var buf = sharedSecretPubkey.toDER(true); |
|
|
|
|
|
var sharedKeypair = KDF.sha256hmac2keypair(buf); |
|
|
|
|
|
|
|
|
|
|
|
return sharedKeypair; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
StealthAddress.prototype.getReceivePubkey = function(senderKeypair) { |
|
|
|
|
|
var sharedKeypair = this.getSharedKeypair(senderKeypair); |
|
|
|
|
|
var pubkey = Pubkey(this.payloadPubkey.point.add(sharedKeypair.pubkey.point)); |
|
|
|
|
|
|
|
|
|
|
|
return pubkey; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
StealthAddress.prototype.toBuffer = function() { |
|
|
StealthAddress.prototype.toBuffer = function() { |
|
|
var pBuf = this.payloadPubkey.toDER(true); |
|
|
var pBuf = this.payloadPubkey.toDER(true); |
|
|
var sBuf = this.scanPubkey.toDER(true); |
|
|
var sBuf = this.scanPubkey.toDER(true); |
|
|