verify pubkey.
This commit is contained in:
parent
fb370eda1c
commit
fec9f2e308
@ -56,7 +56,7 @@ ec.publicKeyCreate = function publicKeyCreate(priv, compressed) {
|
||||
ec.random = function random(size) {
|
||||
if (crypto)
|
||||
return crypto.randomBytes(size);
|
||||
return new Buffer(elliptic.rand(size));
|
||||
return new Buffer(ec.elliptic.rand(size));
|
||||
};
|
||||
|
||||
ec.verify = function verify(msg, sig, key, historical) {
|
||||
@ -86,26 +86,22 @@ ec.verify = function verify(msg, sig, key, historical) {
|
||||
// Import from DER.
|
||||
sig = secp256k1.signatureImport(sig);
|
||||
|
||||
// This is supposed to lower the S value
|
||||
// but it doesn't seem to work.
|
||||
// if (historical)
|
||||
// sig = bcoin.secp256k1.signatureNormalize(sig);
|
||||
|
||||
return secp256k1.verify(msg, sig, key);
|
||||
}
|
||||
return ec.elliptic.verify(msg, sig, key);
|
||||
} catch (e) {
|
||||
utils.debug('Elliptic threw during verification:');
|
||||
utils.debug(e.stack + '');
|
||||
utils.debug({
|
||||
msg: utils.toHex(msg),
|
||||
sig: utils.toHex(sig),
|
||||
key: utils.toHex(key)
|
||||
});
|
||||
// if (!ec.publicKeyVerify(key))
|
||||
// utils.debug('Public key is invalid.');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
ec.publicKeyVerify = function publicKeyVerify(key) {
|
||||
if (secp256k1)
|
||||
return secp256k1.publicKeyVerify(key);
|
||||
return ec.elliptic.keyPair({ pub: key }).validate();
|
||||
};
|
||||
|
||||
ec.sign = function sign(msg, key) {
|
||||
var sig;
|
||||
|
||||
|
||||
@ -135,7 +135,7 @@ KeyPair.prototype.toJSON = function toJSON(passphrase) {
|
||||
encrypted: passphrase ? true : false
|
||||
};
|
||||
|
||||
if (this.key.priv) {
|
||||
if (this.key.privateKey) {
|
||||
json.privateKey = passphrase
|
||||
? utils.encrypt(this.toSecret(), passphrase)
|
||||
: this.toSecret();
|
||||
@ -148,13 +148,13 @@ KeyPair.prototype.toJSON = function toJSON(passphrase) {
|
||||
};
|
||||
|
||||
KeyPair._fromJSON = function _fromJSON(json, passphrase) {
|
||||
var privateKey, publicKey, compressed;
|
||||
var privateKey;
|
||||
|
||||
assert.equal(json.v, 1);
|
||||
assert.equal(json.name, 'keypair');
|
||||
|
||||
if (json.encrypted && !passphrase)
|
||||
throw new Error('Cannot decrypt address');
|
||||
throw new Error('Cannot decrypt key.');
|
||||
|
||||
if (json.privateKey) {
|
||||
privateKey = json.privateKey;
|
||||
@ -164,11 +164,9 @@ KeyPair._fromJSON = function _fromJSON(json, passphrase) {
|
||||
}
|
||||
|
||||
if (json.publicKey) {
|
||||
publicKey = utils.fromBase58(json.publicKey);
|
||||
compressed = publicKey[0] !== 0x04;
|
||||
return {
|
||||
publicKey: publicKey,
|
||||
compressed: compressed
|
||||
publicKey: utils.fromBase58(json.publicKey),
|
||||
compressed: publicKey[0] !== 0x04
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user