Adds verify to ECPubKey
This commit is contained in:
parent
c42e0fb8e0
commit
f1414b0d2f
1 changed files with 16 additions and 15 deletions
23
src/eckey.js
23
src/eckey.js
|
@ -110,6 +110,14 @@ ECKey.prototype.multiply = function(key) {
|
||||||
return ECKey(this.priv.multiply(ECKey(key).priv),this.compressed)
|
return ECKey(this.priv.multiply(ECKey(key).priv),this.compressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ECKey.prototype.sign = function(hash) {
|
||||||
|
return ecdsa.sign(hash, this.priv);
|
||||||
|
}
|
||||||
|
|
||||||
|
ECKey.prototype.verify = function(hash, sig) {
|
||||||
|
return this.getPub().verify(hash, sig)
|
||||||
|
}
|
||||||
|
|
||||||
var ECPubKey = function(input, compressed) {
|
var ECPubKey = function(input, compressed) {
|
||||||
if (!(this instanceof ECPubKey)) { return new ECPubKey(input, compressed); }
|
if (!(this instanceof ECPubKey)) { return new ECPubKey(input, compressed); }
|
||||||
if (!input) {
|
if (!input) {
|
||||||
|
@ -178,18 +186,11 @@ ECPubKey.prototype.getAddress = function(version) {
|
||||||
return new Address(util.sha256ripe160(this.toBytes()), version);
|
return new Address(util.sha256ripe160(this.toBytes()), version);
|
||||||
}
|
}
|
||||||
|
|
||||||
ECKey.prototype.sign = function (hash) {
|
ECPubKey.prototype.verify = function(hash, sig) {
|
||||||
return ecdsa.sign(hash, this.priv);
|
return ecdsa.verify(hash, sig, this.toBytes())
|
||||||
};
|
}
|
||||||
|
|
||||||
ECKey.prototype.verify = function (hash, sig) {
|
|
||||||
return ecdsa.verify(hash, sig, this.getPub()['export']('bytes'));
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse an exported private key contained in a string.
|
|
||||||
*/
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ECKey: ECKey,
|
ECKey: ECKey,
|
||||||
ECPubKey: ECPubKey
|
ECPubKey: ECPubKey
|
||||||
};
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue