UNPKG

@yubing744/rooch-sdk

Version:
46 lines (45 loc) 1.05 kB
import { toB64 } from "../../types/bcs"; function bytesEqual(a, b) { if (a === b) return true; if (a.length !== b.length) { return false; } for (let i = 0; i < a.length; i++) { if (a[i] !== b[i]) { return false; } } return true; } class PublicKey { /** * Checks if two public keys are equal */ equals(publicKey) { return bytesEqual(this.toBytes(), publicKey.toBytes()); } /** * Return the base-64 representation of the public key */ toBase64() { return toB64(this.toBytes()); } /** * Return the Rooch representation of the public key encoded in * base-64. A Rooch public key is formed by the concatenation * of the scheme flag with the raw bytes of the public key */ toRoochPublicKey() { const bytes = this.toBytes(); const roochPublicKey = new Uint8Array(bytes.length + 1); roochPublicKey.set([this.flag()]); roochPublicKey.set(bytes, 1); return toB64(roochPublicKey); } } export { PublicKey, bytesEqual }; //# sourceMappingURL=publickey.js.map