MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / ECPoint

Class ECPoint

modules/crypt/arith/ecp.js:40–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38import Modular from "modular";
39
40export default class ECPoint {
41 constructor(x, y, identity = false) {
42 this.x = x;
43 this.y = y;
44 this.z = identity ? 0n : 1n;
45 };
46 get X() {
47 return this.x;
48 }
49 get Y() {
50 return this.y;
51 }
52 set X(x) {
53 this.x = x;
54 }
55 set Y(y) {
56 this.y = y;
57 }
58 isZero() {
59 return this.z == 0n;
60 };
61 toString() {
62// this.norm();
63 if (this.isZero())
64 return "0"
65 else
66 return this.x + "," + this.y + "," + this.z;
67 }
68 static serialize(o) {
69 o.toString();
70 };
71 static parse(txt) {
72 let a = txt.split(",");
73 if (3 === a.length) {
74 return new ECPoint(a[0], a[1], a[2]);
75 }
76 };
77 static fromOctetString(os) {
78 if (os[0] != 0x04)
79 throw new Error("unsupported format");
80 let flen = (os.length - 1) >> 1;
81 let x = BigInt.fromArrayBuffer(os.slice(1, 1 + flen).buffer);
82 let y = BigInt.fromArrayBuffer(os.slice(1 + flen, os.length).buffer);
83 return new ECPoint(x, y);
84 }
85};
86
87Object.freeze(ECPoint.prototype);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected