Skip to content

Commit

Permalink
noble-secp256k1 is not handling properly the point at infinity (#121)
Browse files Browse the repository at this point in the history
* fix Point.fromAffine

* new build

* formatting

* new build

* formatting & new build

* Fix formatting

---------

Co-authored-by: Elli610 <[email protected]>
Co-authored-by: Paul Miller <[email protected]>
  • Loading branch information
3 people authored Feb 19, 2024
1 parent 24f89fd commit d9aabe9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d9aabe9

Please sign in to comment.