// Dapp bridge for Sia, run in the isolated world of pages matching // addon.json "page-inject".origins. Exposes window.siacoin; every call goes // through the wallet's activate() context in main, which shows the approval // overlay and enforces per-origin permissions. // // `theseus` is provided by the host: { id, origin, contextBridge, invoke }. const call = (msg, payload) => theseus.invoke(msg, payload).catch((e) => { const text = String(e && e.message || e).replace(/^Error invoking remote method '[^']+': (Error: )?/, ""); throw new Error(text); }); theseus.contextBridge.exposeInMainWorld("siacoin", { isTheseus: true, version: "0.1.0", network: "mainnet", // Current receiving address (76-hex). First call per origin asks the user; // "always allow" makes later calls silent. getAddress: () => call("getAddress"), // txSpec: { to, amount } or { outputs: [{ to, amount }] } — amounts are // hastings as decimal strings (1 SC = 1e24). Always approval-gated; // resolves { txid }. signAndSend: (txSpec) => call("signAndSend", txSpec && typeof txSpec === "object" ? txSpec : {}), // ed25519 signature over blake2b-256(message) with the current address's // key. Always approval-gated; resolves { address, publicKey, signature }. signMessage: (message) => call("signMessage", { message: String(message ?? "") }), });