Skip to content

Commit

Permalink
readd encode point function
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu committed Jul 11, 2024
1 parent 74e5536 commit 4b98a63
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ class Point {
this.y = new BN(y, "hex");
this.ecCurve = ecCurve;
}

encode(enc: string): Buffer {
switch (enc) {
case "arr":
return Buffer.concat([
Buffer.from("04", "hex"),
Buffer.from(this.x.toString("hex", 64), "hex"),
Buffer.from(this.y.toString("hex", 64), "hex"),
]);
case "elliptic-compressed": {
const key = this.ecCurve.keyFromPublic({ x: this.x.toString("hex", 64), y: this.y.toString("hex", 64) }, "hex");
return Buffer.from(key.getPublic(true, "hex"));
}
default:
throw new Error("encoding doesn't exist in Point");
}
}
}

export default Point;

0 comments on commit 4b98a63

Please sign in to comment.