UNPKG

@standard-crypto/farcaster-js-hub-rest

Version:

A tool for interacting with the REST API of any Farcaster hub.

54 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExternalEd25519Signer = void 0; const core_1 = require("@farcaster/core"); const neverthrow_1 = require("neverthrow"); /** * External Ed25519 signer that allows signatures to be computed by an external service. */ class ExternalEd25519Signer extends core_1.Ed25519Signer { _signMessageHash; _getSignerKey; /** * Creates a new ExternalEd25519Signer. This class allows the signing of Farcaster message hashes to be delegated to an external service * such that a private key is not required to be in memory. * * @param signMessageHash Proxy function that signs a message hash. Called internally by _signMessageHash. * @param getSignerKey Proxy function that returns the public key of the signer. Called internally by _getSignerKey. */ constructor(signMessageHash, getSignerKey) { super(); this._signMessageHash = signMessageHash; this._getSignerKey = getSignerKey; } /** * Returns the public key of the signer as a Uint8Array. * * @returns public key of the signer */ async getSignerKey() { try { return (0, neverthrow_1.ok)(await this._getSignerKey()); } catch (e) { return (0, neverthrow_1.err)(new core_1.HubError('unknown', e instanceof Error ? e.message : 'Unable to get signer key')); } } /** * Signs a Farcaster message hash. * * @param hash blake3 hash of the Farcaster message to be signed * @returns signature of the hash */ async signMessageHash(hash) { try { const signature = await this._signMessageHash(hash); return (0, neverthrow_1.ok)(signature); } catch (e) { return (0, neverthrow_1.err)(new core_1.HubError('unknown', e instanceof Error ? e.message : 'Unable to sign message hash')); } } } exports.ExternalEd25519Signer = ExternalEd25519Signer; //# sourceMappingURL=signers.js.map