noble-secp256k1
Advanced tools
Comparing version 1.2.12 to 1.2.13
@@ -67,2 +67,3 @@ /*! noble-secp256k1 - MIT License (c) Paul Miller (paulmillr.com) */ | ||
canonical?: true; | ||
der?: boolean; | ||
}; | ||
@@ -72,2 +73,3 @@ declare type OptsNoRecov = { | ||
canonical?: true; | ||
der?: boolean; | ||
}; | ||
@@ -74,0 +76,0 @@ declare function sign(msgHash: U8A, privKey: PrivKey, opts: OptsRecov): Promise<[U8A, number]>; |
20
index.js
@@ -368,4 +368,5 @@ "use strict"; | ||
static fromDER(hex) { | ||
const fn = 'Signature.fromDER'; | ||
if (typeof hex !== 'string' && !(hex instanceof Uint8Array)) { | ||
throw new TypeError(`Signature.fromHex: Expected string or Uint8Array`); | ||
throw new TypeError(`${fn}: Expected string or Uint8Array`); | ||
} | ||
@@ -375,3 +376,3 @@ const str = hex instanceof Uint8Array ? bytesToHex(hex) : hex; | ||
if (str.slice(0, 2) !== '30' || length !== str.length - 4 || str.slice(4, 6) !== '02') { | ||
throw new Error('Signature.fromHex: Invalid signature'); | ||
throw new Error(`${fn}: Invalid signature ${str}`); | ||
} | ||
@@ -382,3 +383,3 @@ const rLen = parseByte(str.slice(6, 8)); | ||
if (rr.startsWith('00') && parseByte(rr.slice(2, 4)) <= 0x7f) { | ||
throw new Error('Signature.fromHex: Invalid r with trailing length'); | ||
throw new Error(`${fn}: Invalid r with trailing length`); | ||
} | ||
@@ -388,3 +389,3 @@ const r = hexToNumber(rr); | ||
if (separator !== '02') { | ||
throw new Error('Signature.fromHex: Invalid r-s separator'); | ||
throw new Error(`${fn}: Invalid r-s separator`); | ||
} | ||
@@ -394,6 +395,6 @@ const sLen = parseByte(str.slice(rEnd + 2, rEnd + 4)); | ||
if (diff > 0 || diff === -4) { | ||
throw new Error(`Signature.fromHex: Invalid total length`); | ||
throw new Error(`${fn}: Invalid total length`); | ||
} | ||
if (sLen > length - rLen - 4) { | ||
throw new Error(`Signature.fromHex: Invalid s`); | ||
throw new Error(`${fn}: Invalid s`); | ||
} | ||
@@ -403,3 +404,3 @@ const sStart = rEnd + 4; | ||
if (ss.startsWith('00') && parseByte(ss.slice(2, 4)) <= 0x7f) { | ||
throw new Error(`Signature.fromHex: Invalid s with trailing length`); | ||
throw new Error(`${fn}: Invalid s with trailing length`); | ||
} | ||
@@ -771,3 +772,3 @@ const s = hexToNumber(ss); | ||
const [q, r, s] = qrs; | ||
let { canonical, recovered } = opts; | ||
let { canonical, der, recovered } = opts; | ||
let recovery = (q.x === r ? 0 : 2) | Number(q.y & 1n); | ||
@@ -782,3 +783,4 @@ let adjustedS = s; | ||
sig.assertValidity(); | ||
const hashed = str ? sig.toDERHex() : sig.toDERRawBytes(); | ||
const hex = der === false ? sig.toCompactHex() : sig.toDERHex(); | ||
const hashed = str ? hex : hexToBytes(hex); | ||
return recovered ? [hashed, recovery] : hashed; | ||
@@ -785,0 +787,0 @@ } |
{ | ||
"name": "noble-secp256k1", | ||
"version": "1.2.12", | ||
"version": "1.2.13", | ||
"description": "Fastest JS implementation of secp256k1. Independently audited, high-security, 0-dependency ECDSA & Schnorr signatures", | ||
@@ -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
56394
1098