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.
chainsafe-bls/src/publicKey.ts

37 lines
793 B
TypeScript

import {G1point} from "./helpers/g1point";
import {PrivateKey} from "./privateKey";
import {BLSPubkey} from "./types";
export class PublicKey {
private point: G1point;
public constructor(point: G1point) {
this.point = point;
}
public getPoint(): G1point {
return this.point;
}
public toBytesCompressed(): BLSPubkey {
return this.point.toBytesCompressed();
}
public toHexString(): string {
return `0x${this.toBytesCompressed().toString('hex')}`;
}
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)
);
}
}