import { TerminalAdapter, UserSession } from '@parity/product-sdk-terminal'; import { PolkadotSigner } from 'polkadot-api'; import { AllocationOutcome } from './allocations.js'; import { AuthConfig } from './types.js'; import { AllocatableResource, OnExistingAllowancePolicy } from '@parity/product-sdk-terminal/host'; /** * The three addresses we surface from a paired session. * * - `rootAddress` — SS58 of `session.rootAccountId`, the `rootUserAccountId` * the mobile app sent over the SSO handshake (bare-mnemonic sr25519 root on * current mobile builds). Keyed by `Resources.Consumers` on the People * parachain, so it's the right input for `lookupUsername`. * - `productAddress`: SS58 of the RFC-0022 product account * `//product//{productId}/{index}`. This is what actually signs on-chain * transactions from the CLI. * - `productH160` — the same product pubkey as a 20-byte EVM address (Revive / * contracts view). Derived from the SAME pubkey as `productAddress`. */ interface SessionAddresses { rootAddress: string; productAddress: string; productH160: `0x${string}`; } type ConnectResult = { kind: "existing"; address: string; addresses: SessionAddresses; } | { kind: "qr"; qrCode: string; login: LoginHandle; }; type LoginStatus = { step: "waiting"; } | { step: "paired"; } | { step: "pending"; stage: string; } | { step: "success"; address: string; addresses: SessionAddresses; } | { step: "error"; message: string; }; interface LoginHandle { adapter: TerminalAdapter; /** The authenticate() promise — already running since connect(). */ authPromise: ReturnType; } /** * A session signer bundle — the signer plus an explicit `destroy()` that tears * down the long-lived adapter the signer depends on. Callers MUST invoke * `destroy()` once done — the WebSocket keeps the event loop alive. * * `adapter` is exposed so callers that need to send a host request (e.g. * `requestResourceAllocation`) can pass it without creating a second WebSocket. */ interface SessionHandle { address: string; addresses: SessionAddresses; /** Product id the account, signer and allowances are scoped to. */ productId: string; signer: PolkadotSigner; userSession: UserSession; adapter: TerminalAdapter; destroy(): void; } type LogoutStatus = { step: "disconnecting"; address: string; } | { step: "success"; address: string; } | { step: "partial"; address: string; reason: string; } | { step: "error"; message: string; }; interface LogoutHandle { adapter: TerminalAdapter; address: string; session: UserSession; } /** The product-bound auth surface returned by `createAuthClient`. */ interface AuthClient { connect(): Promise; waitForLogin(handle: LoginHandle, onStatus: (status: LoginStatus) => void): Promise; getSessionSigner(): Promise; findSession(): Promise; waitForLogout(handle: LogoutHandle, onStatus: (status: LogoutStatus) => void): Promise; requestAllocation(session: UserSession, adapter: TerminalAdapter, resources?: AllocatableResource[], onExisting?: OnExistingAllowancePolicy): Promise; clearLocalAppStorage(dir?: string): Promise; } /** * Build an auth client bound to a product's `AuthConfig`. All adapter creation, * address derivation, and session-storage scoping read from `config`, so the * same code serves any product. */ declare function createAuthClient(config: AuthConfig): AuthClient; export { type AuthClient, type ConnectResult, type LoginHandle, type LoginStatus, type LogoutHandle, type LogoutStatus, type SessionAddresses, type SessionHandle, createAuthClient };