UNPKG

@interchainjs/auth

Version:
46 lines (45 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PublicKey = void 0; const utils_1 = require("@interchainjs/utils"); const algorithms_1 = require("../config/algorithms"); const address_1 = require("./address"); class PublicKey { value; algo; compressed; _algo; constructor(value, algo, compressed) { this.value = value; this.algo = algo; this.compressed = compressed; // Resolve algo once during construction this._algo = (0, algorithms_1.resolveAlgo)(algo); } toAddress(config, prefix) { // Note: This method is optional in the interface // Some chains (e.g., Solana) don't have separate addresses return address_1.Address.fromPublicKey(this, config, prefix); } async verify(data, signature) { // Note: The caller is responsible for hashing the data if needed // This should match the hashing used during signing return this._algo.verify(signature.value, data, this.value.value); } toHex() { return this.value.toHex(); } toBase64() { return this.value.toBase64(); } static fromPrivateKey(privateKey, config) { return privateKey.toPublicKey(config); } static fromBytes(bytes, algo, compressed = true) { return new PublicKey(bytes, algo, compressed); } static fromHex(hex, algo, compressed = true) { return PublicKey.fromBytes(utils_1.BaseCryptoBytes.fromHex(hex), algo, compressed); } } exports.PublicKey = PublicKey;