import * as polkadot_api from 'polkadot-api'; import { TerminalAdapter, UserSession } from '@parity/product-sdk-terminal'; /** * Structural mirror of host-papp's `ApAllocatableResource` codec type. We * declare it locally because host-papp's package root doesn't re-export the * codec types yet — when it does (and product-sdk-terminal threads them * through) this can be replaced with a direct import. * * StatementStoreAllowance — write to the SSS (host_chat, allowance ring). * BulletInAllowance — write to Bulletin (TransactionStorage.store). * SmartContractAllowance — PGAS sponsoring for Revive contract calls. * The `value` is the derivation index of the * product account (0 for the default account). * AutoSigning — surrender the product-account signing key to * the host so it can sign on the user's behalf * without per-call prompts. Not used today. * * NOTE: host-api v0.8 renamed this variant to 'BulletinAllowance', but the * SSO resource-allocation codec (host-papp, which this path reaches via * product-sdk-terminal) retains the old 'BulletInAllowance' spelling as of * host-papp 0.8.5 / terminal 0.3.1. Ours must match the SSO codec — the * _SDK_COMPAT_PIN below fails the build if the SDK's spelling ever changes. */ type AllocatableResource = { tag: "StatementStoreAllowance"; value: undefined; } | { tag: "BulletInAllowance"; value: undefined; } | { tag: "SmartContractAllowance"; value: number; } | { tag: "AutoSigning"; value: undefined; }; /** * Outcome of one allocation. We don't read the inner `Allocated` payload * (allowance slot keys, derivation secrets) — the host stores them and uses * them transparently on subsequent calls. We just need the tag to know * whether the allocation succeeded. */ type AllocationOutcome = { tag: "Allocated"; value: unknown; } | { tag: "Rejected"; value: undefined; } | { tag: "NotAvailable"; value: undefined; }; /** Tag-only view, handy for downstream code that doesn't care about payloads. */ type ResourceTag = AllocatableResource["tag"]; type OnExistingAllowancePolicy = "Ignore" | "Increase"; /** * Default mobile-granted resource set for a CLI product account: write access * to the statement store + Bulletin, plus PGAS sponsoring for the default * (index 0) product account. */ declare const DEFAULT_RESOURCES: AllocatableResource[]; /** * The BulletInAllowance resource singleton. Callers that only need this one * resource (e.g. createSlotAccountSigner) use this constant instead of * constructing the literal — keeps the SSO codec spelling in one place. */ declare const BULLETIN_RESOURCE: AllocatableResource; /** * Send a `host_request_resource_allocation` request over the user's active * session. The host (mobile wallet) prompts the user to approve and returns * one outcome per requested resource in order. Granted key material is cached * to disk by the terminal facet (`{appId}_AllowanceKeys.json`) so subsequent * calls (and the storage-signer reader) find it without a second wallet prompt. * * Throws on transport-level failures (Statement Store unreachable, encryption * error, etc.). Per-resource refusals are reported as `Rejected`/`NotAvailable` * outcomes — callers inspect the array to decide whether to proceed. * * `onExisting` is pinned to "Ignore": return existing cached keys if any, else * allocate a new slot. Auto-pick would give "Increase" when all slot-table * resources are already cached, which re-prompts the user unnecessarily. */ declare function requestResourceAllocation(session: UserSession, adapter: TerminalAdapter, resources?: AllocatableResource[], onExisting?: OnExistingAllowancePolicy): Promise; interface AllocationSummary { granted: AllocatableResource[]; rejected: AllocatableResource[]; unavailable: AllocatableResource[]; } /** * Bucket allocation outcomes by tag. Order-sensitive: `outcomes[i]` maps to * `resources[i]`. Outcomes without a matching resource are silently dropped. */ declare function summarizeOutcomes(outcomes: AllocationOutcome[], resources: AllocatableResource[]): AllocationSummary; /** * Read a previously allocated slot signer from the terminal cache * (`{appId}_AllowanceKeys.json`) written by `requestResourceAllocation`. * * Returns `null` on a cache miss — never triggers a phone prompt. Use this * instead of `adapter.allowance.getBulletinSigner()` when the allocation has * already been claimed in the same session (e.g. after a successful * `requestResourceAllocation(DEFAULT_RESOURCES)` call) so that step 2 of the * login flow is a guaranteed cache-hit with zero additional wallet interaction. * * Throws only for SmartContractAllowance / AutoSigning resources (not applicable * to BulletInAllowance). Returns `null` for BulletInAllowance when no cached * entry exists. */ declare function createSlotAccountSigner(adapter: TerminalAdapter, resource: AllocatableResource): Promise; export { type AllocatableResource as A, BULLETIN_RESOURCE as B, DEFAULT_RESOURCES as D, type OnExistingAllowancePolicy as O, type ResourceTag as R, type AllocationOutcome as a, type AllocationSummary as b, createSlotAccountSigner as c, requestResourceAllocation as r, summarizeOutcomes as s };