/** * Product-side Host API facade. * * `createProductFacade` builds the full product-side communication stack: * provider → transport (with handshake and codec upgrade) → typed facade. * * Every request method returns a `ResultAsync` from neverthrow * so callers can chain with `.map()`, `.andThen()`, `.match()`, etc. * * Handler param/ok/err types are derived from the SCALE codec definitions * in `hostApiProtocol` via `RequestParams`, `ResponseOk`, `ResponseErr`, * `SubscriptionParams`, and `SubscriptionPayload`. */ import type { Subscription } from "../shared/transport/transport.js"; import type { SubscriptionMethod, StartCodecType, ReceiveCodecType, RequestParams, SubscriptionParams, SubscriptionPayload } from "../api/protocol.js"; import type { Messaging } from "../shared/transport/provider.js"; import { ResultAsync } from "neverthrow"; export type CreateProductFacadeOptions = { /** How the product communicates with the host. */ messaging: Messaging; /** Protocol version for handshake validation. Defaults to 1. */ protocolVersionId?: number; }; /** * Create a product-side ProductFacade. * * Builds the full stack internally: creates the appropriate provider from * `messaging`, creates a transport with `handshake: 'initiate'`, and wraps * it with automatic codec upgrade negotiation. */ export declare function createProductFacade(options: CreateProductFacadeOptions): { /** Resolves when the handshake and codec negotiation are complete. */ whenReady(): Promise; /** * Register a handler for a host-initiated subscription. * * This is the product-side counterpart to `transport.handleSubscription`. * Used for the one protocol method where the product is the handler * rather than the initiator (`product_chat_custom_message_render_subscribe`). */ handleHostSubscription(method: M, handler: (params: StartCodecType, send: (value: ReceiveCodecType) => void, interrupt: () => void) => () => void): () => void; featureSupported(payload: RequestParams<"host_feature_supported", "v1">): ResultAsync; pushNotification(payload: RequestParams<"host_push_notification", "v1">): ResultAsync; navigateTo(payload: RequestParams<"host_navigate_to", "v1">): ResultAsync; devicePermission(payload: RequestParams<"host_device_permission", "v1">): ResultAsync; permission(payload: RequestParams<"remote_permission", "v1">): ResultAsync; localStorageRead(payload: RequestParams<"host_local_storage_read", "v1">): ResultAsync | undefined, { tag: "Unknown"; value: { reason: string; }; } | { tag: "Full"; value: undefined; }>; localStorageWrite(payload: RequestParams<"host_local_storage_write", "v1">): ResultAsync; localStorageClear(payload: RequestParams<"host_local_storage_clear", "v1">): ResultAsync; accountConnectionStatusSubscribe(args: SubscriptionParams<"host_account_connection_status_subscribe", "v1">, callback: (payload: SubscriptionPayload<"host_account_connection_status_subscribe", "v1">) => void): Subscription; accountGet(payload: RequestParams<"host_account_get", "v1">): ResultAsync<{ publicKey: Uint8Array; name: string | undefined; }, { tag: "NotConnected"; value: undefined; } | { tag: "Rejected"; value: undefined; } | { tag: "DomainNotValid"; value: undefined; } | { tag: "Unknown"; value: { reason: string; }; }>; accountGetAlias(payload: RequestParams<"host_account_get_alias", "v1">): ResultAsync<{ context: Uint8Array; alias: Uint8Array; }, { tag: "NotConnected"; value: undefined; } | { tag: "Rejected"; value: undefined; } | { tag: "DomainNotValid"; value: undefined; } | { tag: "Unknown"; value: { reason: string; }; }>; accountCreateProof(payload: RequestParams<"host_account_create_proof", "v1">): ResultAsync, { tag: "Rejected"; value: undefined; } | { tag: "Unknown"; value: { reason: string; }; } | { tag: "RingNotFound"; value: undefined; }>; getNonProductAccounts(payload: RequestParams<"host_get_non_product_accounts", "v1">): ResultAsync<{ publicKey: Uint8Array; name: string | undefined; }[], { tag: "NotConnected"; value: undefined; } | { tag: "Rejected"; value: undefined; } | { tag: "DomainNotValid"; value: undefined; } | { tag: "Unknown"; value: { reason: string; }; }>; paymentBalanceSubscribe(args: SubscriptionParams<"host_payment_balance_subscribe", "v1">, callback: (payload: SubscriptionPayload<"host_payment_balance_subscribe", "v1">) => void): Subscription; paymentTopUp(payload: RequestParams<"host_payment_top_up", "v1">): ResultAsync; paymentRequest(payload: RequestParams<"host_payment_request", "v1">): ResultAsync<{ id: string; }, { reason: string; }>; paymentStatusSubscribe(args: SubscriptionParams<"host_payment_status_subscribe", "v1">, callback: (payload: SubscriptionPayload<"host_payment_status_subscribe", "v1">) => void): Subscription; createTransaction(payload: RequestParams<"host_create_transaction", "v1">): ResultAsync<`0x${string}`, { tag: "Rejected"; value: undefined; } | { tag: "Unknown"; value: { reason: string; }; } | { tag: "FailedToDecode"; value: undefined; } | { tag: "PermissionDenied"; value: undefined; } | { tag: "NotSupported"; value: string; }>; createTransactionWithNonProductAccount(payload: RequestParams<"host_create_transaction_with_non_product_account", "v1">): ResultAsync<`0x${string}`, { tag: "Rejected"; value: undefined; } | { tag: "Unknown"; value: { reason: string; }; } | { tag: "FailedToDecode"; value: undefined; } | { tag: "PermissionDenied"; value: undefined; } | { tag: "NotSupported"; value: string; }>; signRaw(payload: RequestParams<"host_sign_raw", "v1">): ResultAsync<{ signature: `0x${string}`; signedTransaction: `0x${string}` | undefined; }, { tag: "Rejected"; value: undefined; } | { tag: "Unknown"; value: { reason: string; }; } | { tag: "FailedToDecode"; value: undefined; } | { tag: "PermissionDenied"; value: undefined; }>; signPayload(payload: RequestParams<"host_sign_payload", "v1">): ResultAsync<{ signature: `0x${string}`; signedTransaction: `0x${string}` | undefined; }, { tag: "Rejected"; value: undefined; } | { tag: "Unknown"; value: { reason: string; }; } | { tag: "FailedToDecode"; value: undefined; } | { tag: "PermissionDenied"; value: undefined; }>; chatListSubscribe(args: SubscriptionParams<"host_chat_list_subscribe", "v1">, callback: (payload: SubscriptionPayload<"host_chat_list_subscribe", "v1">) => void): Subscription; chatCreateRoom(payload: RequestParams<"host_chat_create_room", "v1">): ResultAsync<{ status: "New" | "Exists"; }, { tag: "Unknown"; value: { reason: string; }; } | { tag: "PermissionDenied"; value: undefined; }>; chatRegisterBot(payload: RequestParams<"host_chat_register_bot", "v1">): ResultAsync<{ status: "New" | "Exists"; }, { tag: "Unknown"; value: { reason: string; }; } | { tag: "PermissionDenied"; value: undefined; }>; chatPostMessage(payload: RequestParams<"host_chat_post_message", "v1">): ResultAsync<{ messageId: string; }, { tag: "Unknown"; value: { reason: string; }; } | { tag: "MessageTooLarge"; value: undefined; }>; chatActionSubscribe(args: SubscriptionParams<"host_chat_action_subscribe", "v1">, callback: (payload: SubscriptionPayload<"host_chat_action_subscribe", "v1">) => void): Subscription; statementStoreSubscribe(args: SubscriptionParams<"remote_statement_store_subscribe", "v1">, callback: (payload: SubscriptionPayload<"remote_statement_store_subscribe", "v1">) => void): Subscription; statementStoreCreateProof(payload: RequestParams<"remote_statement_store_create_proof", "v1">): ResultAsync<{ tag: "Sr25519"; value: { signature: Uint8Array; signer: Uint8Array; }; } | { tag: "Ed25519"; value: { signature: Uint8Array; signer: Uint8Array; }; } | { tag: "Ecdsa"; value: { signature: Uint8Array; signer: Uint8Array; }; } | { tag: "OnChain"; value: { who: Uint8Array; blockHash: Uint8Array; event: bigint; }; }, { tag: "Unknown"; value: { reason: string; }; } | { tag: "UnableToSign"; value: undefined; } | { tag: "UnknownAccount"; value: undefined; }>; statementStoreSubmit(payload: RequestParams<"remote_statement_store_submit", "v1">): ResultAsync; preimageLookupSubscribe(args: SubscriptionParams<"remote_preimage_lookup_subscribe", "v1">, callback: (payload: SubscriptionPayload<"remote_preimage_lookup_subscribe", "v1">) => void): Subscription; preimageSubmit(payload: RequestParams<"remote_preimage_submit", "v1">): ResultAsync<`0x${string}`, { tag: "Unknown"; value: { reason: string; }; }>; jsonrpcMessageSend(payload: RequestParams<"host_jsonrpc_message_send", "v1">): ResultAsync; jsonrpcMessageSubscribe(args: SubscriptionParams<"host_jsonrpc_message_subscribe", "v1">, callback: (payload: SubscriptionPayload<"host_jsonrpc_message_subscribe", "v1">) => void): Subscription; chainHeadFollow(args: SubscriptionParams<"remote_chain_head_follow", "v1">, callback: (payload: SubscriptionPayload<"remote_chain_head_follow", "v1">) => void): Subscription; chainHeadHeader(payload: RequestParams<"remote_chain_head_header", "v1">): ResultAsync<`0x${string}` | undefined, { reason: string; }>; chainHeadBody(payload: RequestParams<"remote_chain_head_body", "v1">): ResultAsync<{ tag: "Started"; value: { operationId: string; }; } | { tag: "LimitReached"; value: undefined; }, { reason: string; }>; chainHeadStorage(payload: RequestParams<"remote_chain_head_storage", "v1">): ResultAsync<{ tag: "Started"; value: { operationId: string; }; } | { tag: "LimitReached"; value: undefined; }, { reason: string; }>; chainHeadCall(payload: RequestParams<"remote_chain_head_call", "v1">): ResultAsync<{ tag: "Started"; value: { operationId: string; }; } | { tag: "LimitReached"; value: undefined; }, { reason: string; }>; chainHeadUnpin(payload: RequestParams<"remote_chain_head_unpin", "v1">): ResultAsync; chainHeadContinue(payload: RequestParams<"remote_chain_head_continue", "v1">): ResultAsync; chainHeadStopOperation(payload: RequestParams<"remote_chain_head_stop_operation", "v1">): ResultAsync; chainSpecGenesisHash(payload: RequestParams<"remote_chain_spec_genesis_hash", "v1">): ResultAsync<`0x${string}`, { reason: string; }>; chainSpecChainName(payload: RequestParams<"remote_chain_spec_chain_name", "v1">): ResultAsync; chainSpecProperties(payload: RequestParams<"remote_chain_spec_properties", "v1">): ResultAsync; chainTransactionBroadcast(payload: RequestParams<"remote_chain_transaction_broadcast", "v1">): ResultAsync; chainTransactionStop(payload: RequestParams<"remote_chain_transaction_stop", "v1">): ResultAsync; }; /** * Return type of `createProductFacade`. */ export type ProductFacade = ReturnType; //# sourceMappingURL=hostApi.d.ts.map