@yubing744/rooch-sdk
Version:
66 lines (65 loc) • 2.02 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var publickey_exports = {};
__export(publickey_exports, {
PublicKey: () => PublicKey,
bytesEqual: () => bytesEqual
});
module.exports = __toCommonJS(publickey_exports);
var import_bcs = require("../../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 (0, import_bcs.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 (0, import_bcs.toB64)(roochPublicKey);
}
}
//# sourceMappingURL=publickey.js.map