add extra validation to prevent invalid public keys being used. (as per issue 39)
This commit is contained in:
parent
c276998687
commit
27c9bff17e
1 changed files with 15 additions and 12 deletions
27
js/coin.js
27
js/coin.js
|
@ -278,20 +278,23 @@
|
||||||
|
|
||||||
/* decompress an compressed public key */
|
/* decompress an compressed public key */
|
||||||
coinjs.pubkeydecompress = function(pubkey) {
|
coinjs.pubkeydecompress = function(pubkey) {
|
||||||
var curve = EllipticCurve.getSECCurveByName("secp256k1");
|
if((typeof(pubkey) == 'string') && pubkey.match(/^[a-f0-9]+$/i)){
|
||||||
try {
|
var curve = EllipticCurve.getSECCurveByName("secp256k1");
|
||||||
var pt = curve.curve.decodePointHex(pubkey);
|
try {
|
||||||
var x = pt.getX().toBigInteger();
|
var pt = curve.curve.decodePointHex(pubkey);
|
||||||
var y = pt.getY().toBigInteger();
|
var x = pt.getX().toBigInteger();
|
||||||
|
var y = pt.getY().toBigInteger();
|
||||||
|
|
||||||
var publicKeyBytes = EllipticCurve.integerToBytes(x, 32);
|
var publicKeyBytes = EllipticCurve.integerToBytes(x, 32);
|
||||||
publicKeyBytes = publicKeyBytes.concat(EllipticCurve.integerToBytes(y,32));
|
publicKeyBytes = publicKeyBytes.concat(EllipticCurve.integerToBytes(y,32));
|
||||||
publicKeyBytes.unshift(0x04);
|
publicKeyBytes.unshift(0x04);
|
||||||
return Crypto.util.bytesToHex(publicKeyBytes);
|
return Crypto.util.bytesToHex(publicKeyBytes);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// console.log(e);
|
// console.log(e);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
coinjs.testdeterministicK = function() {
|
coinjs.testdeterministicK = function() {
|
||||||
|
|
Loading…
Reference in a new issue