This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
2019-08-05 15:48:26 +00:00
|
|
|
import {G1point} from "./helpers/g1point";
|
|
|
|
import {PrivateKey} from "./privateKey";
|
2019-08-12 07:51:18 +00:00
|
|
|
import {BLSPubkey} from "@chainsafe/eth2.0-types";
|
2019-08-05 15:48:26 +00:00
|
|
|
|
|
|
|
export class PublicKey {
|
|
|
|
|
|
|
|
private point: G1point;
|
|
|
|
|
|
|
|
public constructor(point: G1point) {
|
|
|
|
this.point = point;
|
|
|
|
}
|
2019-08-28 15:18:51 +00:00
|
|
|
|
2019-08-05 15:48:26 +00:00
|
|
|
public static fromPrivateKey(privateKey: PrivateKey): PublicKey {
|
|
|
|
return new PublicKey(
|
|
|
|
G1point.generator().mul(privateKey.getValue())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static fromBytes(publicKey: BLSPubkey): PublicKey {
|
|
|
|
return new PublicKey(
|
|
|
|
G1point.fromBytesCompressed(publicKey)
|
|
|
|
);
|
|
|
|
}
|
2019-08-28 15:18:51 +00:00
|
|
|
|
|
|
|
public getPoint(): G1point {
|
|
|
|
return this.point;
|
|
|
|
}
|
|
|
|
|
|
|
|
public toBytesCompressed(): BLSPubkey {
|
|
|
|
return this.point.toBytesCompressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public toHexString(): string {
|
|
|
|
return `0x${this.toBytesCompressed().toString("hex")}`;
|
|
|
|
}
|
2019-08-05 15:48:26 +00:00
|
|
|
}
|