From d9aabe978d741e5e0da601c51b155b5e23b825ef Mon Sep 17 00:00:00 2001 From: Nathan HERVIER <113121626+Elli610@users.noreply.github.com> Date: Mon, 19 Feb 2024 20:04:53 +0100 Subject: [PATCH] noble-secp256k1 is not handling properly the point at infinity (#121) * fix Point.fromAffine * new build * formatting * new build * formatting & new build * Fix formatting --------- Co-authored-by: Elli610 Co-authored-by: Paul Miller --- index.js | 7 ++++++- index.ts | 5 ++++- package-lock.json | 20 ++++++++++---------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index b634592..5b46e3b 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,12 @@ class Point { this.py = py; this.pz = pz; } //3d=less inversions - static fromAffine(p) { return new Point(p.x, p.y, 1n); } + static fromAffine(p) { + if ((p.x === 0n) && (p.y === 0n)) + return new Point(0n, 1n, 0n); + else + return new Point(p.x, p.y, 1n); + } static fromHex(hex) { hex = toU8(hex); // convert hex string to Uint8Array let p = undefined; diff --git a/index.ts b/index.ts index 01428d7..773c48b 100644 --- a/index.ts +++ b/index.ts @@ -26,7 +26,10 @@ class Point { // Point in 3d xyz proje constructor(readonly px: bigint, readonly py: bigint, readonly pz: bigint) {} //3d=less inversions static readonly BASE = new Point(Gx, Gy, 1n); // Generator / base point static readonly ZERO = new Point(0n, 1n, 0n); // Identity / zero point - static fromAffine(p: AffinePoint) { return new Point(p.x, p.y, 1n); } + static fromAffine (p: AffinePoint) { + if ((p.x === 0n) && (p.y === 0n)) return Point.ZERO; + else return new Point(p.x, p.y, 1n) ; + } static fromHex(hex: Hex): Point { // Convert Uint8Array or hex string to Point hex = toU8(hex); // convert hex string to Uint8Array let p: Point | undefined = undefined; diff --git a/package-lock.json b/package-lock.json index a501d6f..03f8143 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.0.0", "license": "MIT", "devDependencies": { - "@noble/hashes": "1.3.0", + "@noble/hashes": "1.3.2", "fast-check": "3.0.0", "micro-bmark": "0.3.0", "micro-should": "0.4.0", @@ -20,16 +20,16 @@ } }, "node_modules/@noble/hashes": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.0.tgz", - "integrity": "sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } }, "node_modules/fast-check": { "version": "3.0.0",