import { PolkadotSigner } from 'polkadot-api'; /** * Read the BulletInAllowance slot account from the product-sdk-terminal allowance cache. * Returns null when not cached. storageDir defaults to os.homedir(). * * Cache format: @parity/product-sdk-terminal host-cache.ts v1. * * NOTE: reads the pre-0.8.6 plaintext cache format (_AllowanceKeys.json). On host-papp 0.8.6+ * the cache is AES-encrypted and keyed by sessionId (_AllowanceKeys_.json), so * this function returns null on 0.8.6+ installations. Use adapter.allowance.getBulletinSigner() * for runtime checks instead. */ declare function readBulletinSlotSigner(appId: string, storageDir?: string): Promise<{ signer: PolkadotSigner; ss58: string; } | null>; /** * Write a BulletInAllowance slot key to the product-sdk-terminal cache (v1 format). * Read-modify-write so other entries are preserved. */ declare function writeBulletinSlotKey(appId: string, hexKey: `0x${string}`, storageDir?: string): Promise; /** * Extract the BulletInAllowance slot key hex from a requestResourceAllocation outcome array. * The vendored allocations.ts does not parse or persist the key material — callers must * call this and then writeBulletinSlotKey. */ declare function extractBulletinSlotKey(outcomes: { tag: string; value: unknown; }[]): `0x${string}` | null; /** * Typed error thrown by getSlotSignerProvider when the slot account is not * usably authorized on-chain. The `reason` field lets callers produce * targeted messages without string-matching. * * "missing" — no active authorization: never granted, or already lapsed * (account_authorization hides expired entries, so a live read * cannot tell those apart). * "expired" — expiration ≤ finalized block; only a cached/lagging read. */ declare class BulletinSlotAuthError extends Error { readonly reason: "missing" | "expired"; /** The on-chain expiration block (only set when reason === "expired"). */ readonly expiration?: number; constructor(reason: "missing" | "expired", ss58: string, expiration?: number); } /** * Pure active-test for a Bulletin authorization. * Shared by getSlotSignerProvider (single probe) and the poll loop in * waitForBulletinAuthorization (repeated probes). * * @param auth Result of readAccountAuthorization — null when nothing is active. * Structurally typed for the injected-queryFn seam the tests drive. * @param blockNumber Current finalized block number. */ declare function isBulletinAuthActive(auth: { expiration?: bigint | number; } | null | undefined, blockNumber: number): { active: true; expiration: number; } | { active: false; reason: "missing" | "expired"; expiration?: number; }; /** * Internal poll loop for waitForBulletinAuthorization. * Injecting the query function keeps the loop unit-testable without a real WS connection. * * @param queryFn Async function that returns {auth, blockNumber} — mock in tests. * @param opts pollMs (default 2000), timeoutMs (default 90000). * * Transient query errors (thrown by queryFn) are retried until the deadline — a * flaky WS read is NOT treated as "unauthorized". Only a clean active-check * returning false advances toward timeout. */ declare function pollUntilBulletinAuthorized(queryFn: () => Promise<{ auth: { expiration?: bigint | number; } | null | undefined; blockNumber: number; }>, opts?: { timeoutMs?: number; pollMs?: number; }): Promise<{ authorized: true; expiration: number; } | { authorized: false; reason: "timeout"; }>; /** * Open a Bulletin WS connection, poll account_authorization until the slot * account's authorization lands on-chain, then destroy the connection and return. * * Intended for the fresh-login path in src/commands/login.ts to gate the * success summary until the authorization is finalized (avoids the first-run * race where deploy checks immediately after phone approval but before the * on-chain tx is included). * * Does NOT print any progress — the caller (login.ts) owns the output via a * spinner. Pass `quiet: true` to suppress connection status chatter so the * caller's spinner owns the line. * * @returns `{ authorized: true, expiration }` on success; * `{ authorized: false, reason: "timeout" }` after the configured timeout. */ declare function waitForBulletinAuthorization(ss58: string, opts?: { timeoutMs?: number; pollMs?: number; quiet?: boolean; endpoints?: string[]; }): Promise<{ authorized: true; expiration: number; } | { authorized: false; reason: "timeout"; }>; /** * Generic retry wrapper for a single flaky step. Retries any thrown error * EXCEPT `BulletinSlotAuthError` up to `retries` times (default 2, i.e. 3 * total attempts) with `delayMs` between attempts (default 1000ms). * * `BulletinSlotAuthError` ("missing" | "expired") is a definitive on-chain * fact, not a network blip — retrying it would just re-read the same state * and waste time, so it always propagates on the first attempt. * * Extracted for #1058: getSlotSignerProvider's connect + authorization * probe is a single WS round-trip performed once per deploy; a transient * WS/RPC hiccup on that one attempt used to permanently commit the whole * upload to the pool-account fallback (selectStorageReconnect in * src/deploy.ts never retries the slot path once it has failed once). * Mirrors the existing "a flaky read is NOT unauthorized" tolerance already * used by pollUntilBulletinAuthorized (login path), bounded to a much * shorter budget appropriate for a synchronous deploy-time connect. */ declare function withTransientRetry(attempt: () => Promise, opts?: { retries?: number; delayMs?: number; }): Promise; /** * Create a Bulletin WS connection for the slot-account signer. * Checks on-chain authorization. A transient connect/query error (WS blip, * RPC timeout) is retried up to twice via withTransientRetry before giving * up; a clean read that is definitively missing/expired throws * BulletinSlotAuthError immediately (no retry — see withTransientRetry) so * callers can distinguish and produce targeted messages. */ declare function getSlotSignerProvider(signer: PolkadotSigner, ss58: string): Promise<{ client: any; unsafeApi: any; signer: PolkadotSigner; ss58: string; }>; export { BulletinSlotAuthError, extractBulletinSlotKey, getSlotSignerProvider, isBulletinAuthActive, pollUntilBulletinAuthorized, readBulletinSlotSigner, waitForBulletinAuthorization, withTransientRetry, writeBulletinSlotKey };