UNPKG

@acurast/cli

Version:

A cli to interact with the Acurast Cloud.

43 lines 1.64 kB
import { randomBytes } from 'node:crypto'; import open from 'open'; /** * A `@polkadot/api` {@link Signer} that delegates signing to a browser wallet * via the local bridge server. Each `signPayload`/`signRaw` call registers the * payload, opens the bridge page, and waits for the wallet's signature. * * A single instance serves multiple sequential signatures (a deploy signs * `deploy`, then later `setEnvironments`), so polkadot.js assembles and submits * the extrinsic over the CLI's own RPC connection — the CLI keeps full control * of submission + progress reporting. */ export class RemoteSigner { constructor(deps) { this.deps = deps; this.counter = 0; } async signPayload(payload) { return this.request(payload); } async signRaw(raw) { return this.request(raw); } async request(payload) { const callIndex = this.counter; const id = ++this.counter; // Unguessable routing id (the bridge endpoints are additionally token-guarded). const reqId = randomBytes(16).toString('hex'); const summary = this.deps.getSummary?.(payload, callIndex); const signaturePromise = this.deps.requestSignature(reqId, payload, summary); const url = this.deps.bridgeUrl(reqId); this.deps.onOpen?.(reqId, url); try { await open(url); } catch { // Non-interactive environment: the bridge URL was surfaced via onOpen. } const signature = await signaturePromise; return { id, signature: signature }; } } //# sourceMappingURL=remoteSigner.js.map