noble-secp256k1
Advanced tools
Comparing version 1.2.2 to 1.2.3
39
index.js
@@ -368,3 +368,3 @@ "use strict"; | ||
if (typeof hex !== 'string' && !(hex instanceof Uint8Array)) { | ||
throw new TypeError(`Invalid signature. Expected string or Uint8Array`); | ||
throw new TypeError(`Signature.fromHex: Expected string or Uint8Array`); | ||
} | ||
@@ -378,14 +378,28 @@ const str = hex instanceof Uint8Array ? bytesToHex(hex) : hex; | ||
const rEnd = 8 + rLen; | ||
const r = hexToNumber(str.slice(8, rEnd)); | ||
const check3 = str.slice(rEnd, rEnd + 2); | ||
if (check3 !== '02') { | ||
throw new Error('Signature.fromHex: Invalid signature'); | ||
const rr = str.slice(8, rEnd); | ||
if (rr.startsWith('00') && parseByte(rr.slice(2, 4)) <= 0x7f) { | ||
throw new Error('Signature.fromHex: Invalid r with trailing length'); | ||
} | ||
const r = hexToNumber(rr); | ||
const separator = str.slice(rEnd, rEnd + 2); | ||
if (separator !== '02') { | ||
throw new Error('Signature.fromHex: Invalid r-s separator'); | ||
} | ||
const sLen = parseByte(str.slice(rEnd + 2, rEnd + 4)); | ||
const diff = length - sLen - rLen - 10; | ||
if (diff > 0 || diff === -4) { | ||
throw new Error(`Signature.fromHex: Invalid total length`); | ||
} | ||
if (sLen > length - rLen - 4) { | ||
throw new Error(`Signature.fromHex: Invalid s`); | ||
} | ||
const sStart = rEnd + 4; | ||
const s = hexToNumber(str.slice(sStart, sStart + sLen)); | ||
const ss = str.slice(sStart, sStart + sLen); | ||
if (ss.startsWith('00') && parseByte(ss.slice(2, 4)) <= 0x7f) { | ||
throw new Error(`Signature.fromHex: Invalid s with trailing length`); | ||
} | ||
const s = hexToNumber(ss); | ||
return new Signature(r, s); | ||
} | ||
assertValidity() { | ||
const { n } = CURVE; | ||
const { r, s } = this; | ||
@@ -716,6 +730,9 @@ if (!isWithinCurveOrder(r)) | ||
const s1 = invert(s, n); | ||
const Ghs1 = JacobianPoint.BASE.multiply(mod(h * s1, n)); | ||
const Prs1 = pubKey.multiplyUnsafe(mod(r * s1, n)); | ||
const res = Ghs1.add(Prs1).toAffine(); | ||
return res.x === r; | ||
const u1 = mod(h * s1, n); | ||
const u2 = mod(r * s1, n); | ||
const Ghs1 = JacobianPoint.BASE.multiply(u1); | ||
const Prs1 = pubKey.multiplyUnsafe(u2); | ||
const R = Ghs1.add(Prs1).toAffine(); | ||
const v = mod(R.x, n); | ||
return v === r; | ||
} | ||
@@ -722,0 +739,0 @@ exports.verify = verify; |
{ | ||
"name": "noble-secp256k1", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Fastest JS implementation of secp256k1. Zero-dependency, high-security, audited ECDSA & Schnorr", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50933
983