From ce195c913397dfca81a120f005b2e2175f19d238 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 13 Dec 2023 16:15:55 +0000 Subject: [PATCH] Fix ECDSA DER signature detection --- backend/src/api/common.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/api/common.ts b/backend/src/api/common.ts index 00f4328ce..42dae7eb0 100644 --- a/backend/src/api/common.ts +++ b/backend/src/api/common.ts @@ -171,8 +171,8 @@ export class Common { // heuristic to detect probable DER signatures return (w.length >= 18 && w.startsWith('30') // minimum DER signature length is 8 bytes + sighash flag (see https://mempool.space/testnet/tx/c6c232a36395fa338da458b86ff1327395a9afc28c5d2daa4273e410089fd433) - && ['01, 02, 03, 81, 82, 83'].includes(w.slice(-2)) // signature must end with a valid sighash flag - && (w.length === parseInt(w.slice(2, 4), 16) + 6) // second byte encodes the combined length of the R and S components + && ['01', '02', '03', '81', '82', '83'].includes(w.slice(-2)) // signature must end with a valid sighash flag + && (w.length === (2 * parseInt(w.slice(2, 4), 16)) + 6) // second byte encodes the combined length of the R and S components ); }