UNPKG

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

Version:

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

50 lines 1.83 kB
import { Ed25519Signer, HubError } from '@farcaster/core'; import { err, ok } from 'neverthrow'; /** * External Ed25519 signer that allows signatures to be computed by an external service. */ export class ExternalEd25519Signer extends 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 ok(await this._getSignerKey()); } catch (e) { return err(new 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 ok(signature); } catch (e) { return err(new HubError('unknown', e instanceof Error ? e.message : 'Unable to sign message hash')); } } } //# sourceMappingURL=signers.js.map