@parity/product-sdk-host 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,120 +1,78 @@
1
- import * as polkadot_api from 'polkadot-api';
2
1
  import { JsonRpcProvider } from 'polkadot-api';
3
- import { CodecType, AllocatableResource as AllocatableResource$1, AllocationOutcome as AllocationOutcome$1, RemotePermission as RemotePermission$1, Statement as Statement$1 } from '@novasamatech/host-api';
2
+ import * as _novasamatech_host_api from '@novasamatech/host-api';
3
+ import { Subscription, Transport, CodecType, AllocatableResource as AllocatableResource$1, AllocationOutcome as AllocationOutcome$1, RemotePermission as RemotePermission$1, DevicePermission } from '@novasamatech/host-api';
4
4
  export { HexString, assertEnumVariant, enumValue, fromHex, isEnumVariant, resultErr, resultOk, toHex, unwrapResultOrThrow } from '@novasamatech/host-api';
5
+ import * as _novasamatech_host_api_wrapper from '@novasamatech/host-api-wrapper';
6
+ import { hostLocalStorage, createStatementStore, ProductAccountId as ProductAccountId$1, SignedStatement as SignedStatement$1, Statement as Statement$1, StatementTopicFilter as StatementTopicFilter$1, StatementsPage as StatementsPage$1, Topic as Topic$1, createAccountsProvider, preimageManager, ThemeMode as ThemeMode$1, createThemeProvider, ChatBotRegistrationResult as ChatBotRegistrationResult$1, ChatCustomMessageRenderer as ChatCustomMessageRenderer$1, ChatCustomMessageRendererParams as ChatCustomMessageRendererParams$1, createProductChatManager, ChatMessageContent as ChatMessageContent$1, ChatReceivedAction as ChatReceivedAction$1, ChatRoom as ChatRoom$1, ChatRoomRegistrationResult as ChatRoomRegistrationResult$1, PaymentBalance as PaymentBalance$1, paymentManager, PaymentStatus as PaymentStatus$1, TopUpSource as TopUpSource$1 } from '@novasamatech/host-api-wrapper';
5
7
 
6
8
  /**
7
- * Persistent string and JSON storage exposed by the host container. Most
8
- * apps reach it indirectly through the Storage package's `KvStore`; reach for
9
- * it directly via {@link getHostLocalStorage} when you need raw host storage
10
- * without the KV abstraction.
11
- */
12
- interface HostLocalStorage {
13
- readString(key: string): Promise<string | null>;
14
- writeString(key: string, value: string): Promise<void>;
15
- readJSON<T>(key: string): Promise<T | null>;
16
- writeJSON<T>(key: string, value: T): Promise<void>;
17
- /**
18
- * Clear a specific key from storage.
19
- * @param key - The key to clear
20
- */
21
- clear(key: string): Promise<void>;
22
- }
9
+ * Public types for the host wrappers.
10
+ *
11
+ * These are re-exported from `@novasamatech/host-api-wrapper` (the runtime
12
+ * objects the host getters cast to) rather than hand-mirrored, so the
13
+ * Parity surface stays in lockstep with the upstream codec types.
14
+ */
15
+
16
+ /**
17
+ * Persistent storage exposed by the host container, including string, JSON
18
+ * and raw byte (`readBytes`/`writeBytes`) accessors. Most apps reach it
19
+ * indirectly through the Storage package's `KvStore`; reach for it directly
20
+ * via {@link getHostLocalStorage} when you need raw host storage without the
21
+ * KV abstraction.
22
+ *
23
+ * Type identical to `hostLocalStorage` from `@novasamatech/host-api-wrapper`.
24
+ */
25
+ type HostLocalStorage = typeof hostLocalStorage;
23
26
  /**
24
27
  * Cryptographic proof attached to a statement before submission, returned by
25
28
  * {@link HostStatementStore.createProof}. Variants cover the supported
26
- * signature schemes `Sr25519`, `Ed25519`, `Ecdsa`, and `OnChain` (chain-
29
+ * signature schemes - `Sr25519`, `Ed25519`, `Ecdsa`, and `OnChain` (chain-
27
30
  * attestation-based proofs).
28
31
  *
29
- * Mirrors `@novasamatech/product-sdk@0.7`'s proof shape.
30
- */
31
- type StatementProof = {
32
- tag: "Sr25519";
33
- value: {
34
- signature: Uint8Array;
35
- signer: Uint8Array;
36
- };
37
- } | {
38
- tag: "Ed25519";
39
- value: {
40
- signature: Uint8Array;
41
- signer: Uint8Array;
42
- };
43
- } | {
44
- tag: "Ecdsa";
45
- value: {
46
- signature: Uint8Array;
47
- signer: Uint8Array;
48
- };
49
- } | {
50
- tag: "OnChain";
51
- value: {
52
- who: Uint8Array;
53
- blockHash: Uint8Array;
54
- event: bigint;
55
- };
56
- };
32
+ * Inferred from `createStatementStore().createProof`'s return type so codec
33
+ * changes surface here as compile errors, not runtime decode failures.
34
+ */
35
+ type StatementProof = Awaited<ReturnType<ReturnType<typeof createStatementStore>["createProof"]>>;
57
36
  /**
58
- * Topic-based subscription filter. Mirrors `StatementTopicFilter` from
59
- * `@novasamatech/product-sdk` — the host delivers statements that match
37
+ * Topic-based subscription filter. The host delivers statements that match
60
38
  * either *all* of the listed topics (`matchAll`) or *any* of them
61
- * (`matchAny`).
39
+ * (`matchAny`). Re-exported from `@novasamatech/host-api-wrapper`.
62
40
  */
63
- type StatementTopicFilter = {
64
- matchAll: Uint8Array[];
65
- } | {
66
- matchAny: Uint8Array[];
67
- };
41
+ type StatementTopicFilter = StatementTopicFilter$1;
42
+ /** A single topic value used inside a {@link StatementTopicFilter}. Re-exported from `@novasamatech/host-api-wrapper`. */
43
+ type Topic = Topic$1;
44
+ /** `[ss58Address, chainPrefix]` tuple identifying a product account at the codec layer. Re-exported from `@novasamatech/host-api-wrapper`. */
45
+ type ProductAccountId = ProductAccountId$1;
46
+ /** Unsigned statement payload. Re-exported from `@novasamatech/host-api-wrapper`. */
47
+ type Statement = Statement$1;
48
+ /** Statement bundled with its {@link StatementProof}. Re-exported from `@novasamatech/host-api-wrapper`. */
49
+ type SignedStatement = SignedStatement$1;
68
50
  /**
69
51
  * A page of signed statements delivered by {@link HostStatementStore.subscribe}.
70
52
  *
71
53
  * Pages arrive sequentially. `isComplete` is `true` on the final page of a
72
54
  * subscription's initial backfill; subsequent pages contain new statements
73
- * as they appear on chain.
55
+ * as they appear on chain. `statements` is `SignedStatement[]` (typed,
56
+ * not `unknown[]`).
74
57
  */
75
- interface StatementsPage {
76
- statements: unknown[];
77
- isComplete: boolean;
78
- }
79
- /** Subscription handle returned by the host. */
80
- interface HostSubscription {
81
- unsubscribe: () => void;
82
- }
58
+ type StatementsPage = StatementsPage$1;
59
+ /**
60
+ * Subscription handle returned by the host - equivalent to
61
+ * `Subscription<void>` from `@novasamatech/host-api`. Exposes
62
+ * `unsubscribe()` plus an `onInterrupt` hook that fires if the host
63
+ * interrupts the subscription server-side.
64
+ */
65
+ type HostSubscription = Subscription<void>;
83
66
  /**
84
67
  * Statement Store handle exposed by the host container. Provides
85
68
  * `subscribe`, `createProof`, and `submit` operations that go through the
86
69
  * host's native binary protocol; the `statement-store` package layers a
87
70
  * higher-level client on top.
88
71
  *
89
- * Shape matches `@novasamatech/product-sdk@0.7`'s `createStatementStore()`.
90
- */
91
- interface HostStatementStore {
92
- /**
93
- * Subscribe to statements matching the given topic filter.
94
- *
95
- * The callback is invoked once per page of statements. After the initial
96
- * backfill completes (signaled by `page.isComplete === true`), subsequent
97
- * pages contain new statements as they're produced.
98
- *
99
- * @param filter - Topic match filter (`matchAll` or `matchAny`).
100
- * @param callback - Called with each `StatementsPage` from the host.
101
- * @returns Subscription handle with `unsubscribe`.
102
- */
103
- subscribe(filter: StatementTopicFilter, callback: (page: StatementsPage) => void): HostSubscription;
104
- /**
105
- * Create a proof for a statement using the given account.
106
- *
107
- * @param accountId - The account ID tuple `[ss58Address, chainPrefix]` from product-sdk.
108
- * @param statement - The unsigned statement.
109
- * @returns The proof (signature + signer info, or chain-attestation reference).
110
- */
111
- createProof(accountId: [string, number], statement: unknown): Promise<StatementProof>;
112
- /**
113
- * Submit a signed statement to the bulletin chain.
114
- * @param signedStatement - Statement with attached proof.
115
- */
116
- submit(signedStatement: unknown): Promise<void>;
117
- }
72
+ * Type identical to `createStatementStore()` from
73
+ * `@novasamatech/host-api-wrapper`.
74
+ */
75
+ type HostStatementStore = ReturnType<typeof createStatementStore>;
118
76
 
119
77
  /**
120
78
  * Detect if running inside a Host container (Polkadot Browser / Polkadot Desktop).
@@ -131,12 +89,24 @@ declare function isInsideContainer(): Promise<boolean>;
131
89
  * Returns null outside a container or when product-sdk is unavailable.
132
90
  */
133
91
  declare function getHostLocalStorage(): Promise<HostLocalStorage | null>;
92
+ /**
93
+ * Construct a fresh host-backed `HostLocalStorage` instance with an optional
94
+ * custom transport. Use this when you need a non-default transport (e.g.
95
+ * for tests); otherwise prefer {@link getHostLocalStorage}, which returns
96
+ * the shared singleton.
97
+ *
98
+ * Mirrors `createLocalStorage` from `@novasamatech/host-api-wrapper`.
99
+ *
100
+ * @param transport - Optional transport; defaults to the sandbox transport.
101
+ * @returns A new `HostLocalStorage` instance, or `null` if unavailable.
102
+ */
103
+ declare function createHostLocalStorage(transport?: Transport): Promise<HostLocalStorage | null>;
134
104
  /**
135
105
  * Get a PAPI-compatible JSON-RPC provider that routes through the host connection.
136
106
  *
137
107
  * When running inside a Polkadot container, this wraps the chain connection via the
138
108
  * host's `createPapiProvider`, enabling shared connections and efficient routing.
139
- * Returns `null` when `@novasamatech/product-sdk` is unavailable.
109
+ * Returns `null` when `@novasamatech/host-api-wrapper` is unavailable.
140
110
  *
141
111
  * @param genesisHash - Genesis hash of the target chain (`0x`-prefixed hex string).
142
112
  * @returns A host-routed `JsonRpcProvider`, or `null` if unavailable.
@@ -155,7 +125,7 @@ declare function isInsideContainerSync(): boolean;
155
125
  *
156
126
  * Returns a statement store with `subscribe`, `createProof`, and `submit` methods
157
127
  * that communicate through the host's native binary protocol — bypassing JSON-RPC
158
- * entirely. Returns `null` when `@novasamatech/product-sdk` is unavailable.
128
+ * entirely. Returns `null` when `@novasamatech/host-api-wrapper` is unavailable.
159
129
  *
160
130
  * @returns The host statement store, or `null` if unavailable.
161
131
  */
@@ -166,36 +136,51 @@ declare function getStatementStore(): Promise<HostStatementStore | null>;
166
136
  * chain-specific endpoints used by multiple packages.
167
137
  */
168
138
  /**
169
- * Bulletin Chain RPC endpoints per network environment. `paseo` and `previewnet`
170
- * are populated today; `polkadot` and `kusama` are reserved for when those
139
+ * Bulletin Chain RPC endpoints per network environment. `paseo` is
140
+ * populated today; `polkadot` and `kusama` are reserved for when those
171
141
  * Bulletin deployments go live.
172
142
  */
173
143
  declare const BULLETIN_RPCS: {
174
144
  readonly paseo: readonly ["wss://paseo-bulletin-next-rpc.polkadot.io"];
175
- readonly previewnet: readonly ["wss://previewnet.substrate.dev/bulletin"];
176
145
  readonly polkadot: string[];
177
146
  readonly kusama: string[];
178
147
  };
179
148
  /** Default Bulletin Chain endpoint — the first entry under {@link BULLETIN_RPCS}.paseo. */
180
149
  declare const DEFAULT_BULLETIN_ENDPOINT: string;
181
150
 
151
+ /**
152
+ * Extract a human-readable message from a host-side error. Hosts wrap
153
+ * errors in versioned envelopes (`{ tag: "v1", value: CodecError }`); this
154
+ * helper unwraps the envelope and renders the inner error's `name`/`message`
155
+ * so callers see the host's actual diagnostic instead of `"[object Object]"`
156
+ * (from `String(err)`) or a JSON-stringified envelope.
157
+ *
158
+ * Exported for the higher-level wrappers (`requestPermission`,
159
+ * `deriveEntropy`, etc.) that build their `throw new Error(...)` messages.
160
+ */
161
+ declare function formatHostError(err: unknown): string;
162
+
182
163
  /**
183
164
  * The TruApi type - provides low-level methods for communicating with the host.
184
165
  *
185
166
  * Methods include:
186
- * - `navigateTo(url)` Navigate to a URL within the host
187
- * - `permission(permissions)` Request permissions from the host
188
- * - `localStorageRead/Write/Clear` Host-backed storage
189
- * - `sign(payload)` Request transaction signing
190
- * - `deriveEntropy(context)` Derive deterministic entropy
191
- * - `themeSubscribe()` Subscribe to host theme changes
167
+ * - `navigateTo(url)` - Navigate to a URL within the host
168
+ * - `permission(permissions)` - Request permissions from the host
169
+ * - `localStorageRead/Write/Clear` - Host-backed storage
170
+ * - `sign(payload)` - Request transaction signing
171
+ * - `deriveEntropy(context)` - Derive deterministic entropy
172
+ * - `themeSubscribe()` - Subscribe to host theme changes
192
173
  * - And many more...
174
+ *
175
+ * Type identical to `hostApi` from `@novasamatech/host-api-wrapper` so that
176
+ * `truApi.X(...)` calls keep their full inference (return types, method
177
+ * names, parameter shapes) instead of decaying to `any`.
193
178
  */
194
- type TruApi = any;
179
+ type TruApi = typeof _novasamatech_host_api_wrapper.hostApi;
195
180
  /**
196
181
  * Get the TruAPI instance for direct low-level access.
197
182
  *
198
- * Returns the `hostApi` object from `@novasamatech/product-sdk` which provides
183
+ * Returns the `hostApi` object from `@novasamatech/host-api-wrapper` which provides
199
184
  * methods for communicating directly with the host container. Returns `null`
200
185
  * when running outside a container or when the SDK is unavailable.
201
186
  *
@@ -251,26 +236,24 @@ declare function getTruApi(): Promise<TruApi | null>;
251
236
  */
252
237
  declare function getPreimageManager(): Promise<PreimageManager | null>;
253
238
  /**
254
- * Preimage manager interface for bulletin chain operations.
255
- */
256
- interface PreimageManager {
257
- /**
258
- * Submit a preimage to the bulletin chain.
259
- * @param data - The data to submit.
260
- * @returns The preimage key (hex string).
261
- */
262
- submit(data: Uint8Array): Promise<string>;
263
- /**
264
- * Look up a preimage by key.
265
- * @param key - The preimage key (hex string).
266
- * @param callback - Called with the data when found, or null if not yet available.
267
- * @returns Subscription handle with unsubscribe method.
268
- */
269
- lookup(key: string, callback: (preimage: Uint8Array | null) => void): {
270
- unsubscribe: () => void;
271
- onInterrupt: (cb: () => void) => () => void;
272
- };
273
- }
239
+ * Preimage manager handle for bulletin chain operations. `lookup` returns a
240
+ * `Subscription<void>` (`unsubscribe` + `onInterrupt`); `submit` returns a
241
+ * `0x`-prefixed hex preimage key.
242
+ *
243
+ * Type identical to `preimageManager` from `@novasamatech/host-api-wrapper`.
244
+ */
245
+ type PreimageManager = typeof preimageManager;
246
+ /**
247
+ * Construct a fresh `PreimageManager` instance with an optional custom
248
+ * transport. Use this when you need a non-default transport; otherwise
249
+ * prefer {@link getPreimageManager}, which returns the shared singleton.
250
+ *
251
+ * Mirrors `createPreimageManager` from `@novasamatech/host-api-wrapper`.
252
+ *
253
+ * @param transport - Optional transport; defaults to the sandbox transport.
254
+ * @returns A new `PreimageManager` instance, or `null` if unavailable.
255
+ */
256
+ declare function createHostPreimageManager(transport?: _novasamatech_host_api.Transport): Promise<PreimageManager | null>;
274
257
  /**
275
258
  * Get the accounts provider for managing host accounts.
276
259
  *
@@ -322,21 +305,6 @@ type RemotePermissionTag = RemotePermission["tag"];
322
305
  * ```
323
306
  */
324
307
  declare function requestResourceAllocation(resources: AllocatableResource[]): Promise<AllocationOutcome[]>;
325
- /**
326
- * A Statement payload destined for the Statement Store. Matches the
327
- * `pallet-statement` Statement structure.
328
- *
329
- * The optional `proof` field is the same {@link StatementProof} shape that
330
- * {@link createProofAuthorized} returns: pass `undefined` here, call
331
- * `createProofAuthorized` to obtain the proof, then attach it before
332
- * submitting via `HostStatementStore.submit`. The `OnChain` variant of
333
- * `StatementProof` is a chain-attestation reference; the `Sr25519` /
334
- * `Ed25519` / `Ecdsa` variants are signing proofs.
335
- *
336
- * Derived from the upstream codec so structural changes surface as compile
337
- * errors here, not runtime decode failures.
338
- */
339
- type Statement = CodecType<typeof Statement$1>;
340
308
  /**
341
309
  * Have the host sign a Statement using an allowance-bearing account it
342
310
  * picks internally — RFC-10 §"Statement Store allowance".
@@ -423,96 +391,44 @@ interface ResultAsync<T, E> {
423
391
  match: <A, B = A>(ok: (t: T) => A, err: (e: E) => B) => Promise<A | B>;
424
392
  }
425
393
  /**
426
- * Accounts provider interface from @novasamatech/product-sdk.
427
- *
428
- * Provides methods for accessing host wallet accounts, product accounts,
429
- * and Ring VRF operations.
430
- */
431
- interface AccountsProvider {
432
- /**
433
- * Get legacy accounts (user's external wallets connected to the host).
434
- *
435
- * Renamed from `getNonProductAccounts` in @novasamatech/product-sdk 0.7.
436
- *
437
- * @returns ResultAsync resolving to array of accounts.
438
- */
439
- getLegacyAccounts: () => ResultAsync<HostAccount[], unknown>;
440
- /**
441
- * Get a signer for a legacy account.
442
- *
443
- * Renamed from `getNonProductAccountSigner` in @novasamatech/product-sdk 0.7.
444
- *
445
- * @param account - The product account (used for public key lookup).
446
- * @returns A PolkadotSigner for signing transactions.
447
- */
448
- getLegacyAccountSigner: (account: ProductAccount) => polkadot_api.PolkadotSigner;
449
- /**
450
- * Get an app-scoped product account from the host.
451
- *
452
- * Product accounts are derived by the host wallet for each app, identified
453
- * by `dotNsIdentifier` (e.g., "mark3t.dot"). The user controls these accounts
454
- * but they are scoped to the requesting app.
455
- *
456
- * @param dotNsIdentifier - App identifier (e.g., "mark3t.dot").
457
- * @param derivationIndex - Derivation index within the app scope. Default: 0
458
- * @returns ResultAsync resolving to the account.
459
- */
460
- getProductAccount: (dotNsIdentifier: string, derivationIndex?: number) => ResultAsync<HostAccount, unknown>;
461
- /**
462
- * Get a signer for a product account.
463
- *
464
- * @param account - The product account.
465
- * @returns A PolkadotSigner for signing transactions.
466
- */
467
- getProductAccountSigner: (account: ProductAccount) => polkadot_api.PolkadotSigner;
468
- /**
469
- * Get a contextual alias for a product account via Ring VRF.
470
- *
471
- * Aliases prove account membership in a ring without revealing which
472
- * account produced the alias.
473
- *
474
- * @param dotNsIdentifier - App identifier.
475
- * @param derivationIndex - Derivation index. Default: 0
476
- * @returns ResultAsync resolving to the contextual alias.
477
- */
478
- getProductAccountAlias: (dotNsIdentifier: string, derivationIndex?: number) => ResultAsync<ContextualAlias, unknown>;
479
- /**
480
- * Create a Ring VRF proof for anonymous operations.
481
- *
482
- * Proves that the signer is a member of the ring at the given location
483
- * without revealing which member.
484
- *
485
- * @param dotNsIdentifier - App identifier.
486
- * @param derivationIndex - Derivation index.
487
- * @param location - Ring location on-chain.
488
- * @param message - Message to sign.
489
- * @returns ResultAsync resolving to the proof bytes.
490
- */
491
- createRingVRFProof: (dotNsIdentifier: string, derivationIndex: number, location: unknown, message: Uint8Array) => ResultAsync<Uint8Array, unknown>;
492
- /**
493
- * Subscribe to account connection status changes.
494
- *
495
- * @param callback - Called with status string ("connected" | "disconnected").
496
- * @returns Unsubscribe handle.
497
- */
498
- subscribeAccountConnectionStatus: (callback: (status: string) => void) => {
499
- unsubscribe: () => void;
500
- } | (() => void);
501
- }
394
+ * Accounts provider handle from `@novasamatech/host-api-wrapper`. Surfaces the
395
+ * full upstream API - host wallet accounts, app-scoped product accounts,
396
+ * Ring VRF, user identity (`getUserId`, `requestLogin`), and connection
397
+ * status subscription.
398
+ *
399
+ * Type identical to `createAccountsProvider()` from
400
+ * `@novasamatech/host-api-wrapper`; methods return neverthrow `ResultAsync`
401
+ * values with typed `CodecError` variants in the error channel.
402
+ */
403
+ type AccountsProvider = ReturnType<typeof createAccountsProvider>;
502
404
 
503
405
  /**
504
- * Higher-level wrapper for the host's single-permission flow.
406
+ * Higher-level wrappers for the host's single-permission flows.
505
407
  *
506
- * `hostApi.permission` takes a versioned envelope (`enumValue("v1", ...)`)
507
- * and returns a neverthrow `ResultAsync` of an unwrapped versioned response.
508
- * Consumers rebuild that wrap/unwrap dance every time. `requestPermission`
509
- * collapses it to a one-liner that matches the shape of
510
- * {@link requestResourceAllocation} (throws on error, returns the unwrapped
511
- * payload on success).
408
+ * `hostApi.permission` / `hostApi.devicePermission` take a versioned
409
+ * envelope (`enumValue("v1", ...)`) and return a neverthrow `ResultAsync`
410
+ * of an unwrapped versioned response. Consumers rebuild that wrap/unwrap
411
+ * dance every time. {@link requestPermission} and
412
+ * {@link requestDevicePermission} collapse it to one-liners that match the
413
+ * shape of {@link requestResourceAllocation} (throws on error, returns
414
+ * the unwrapped payload on success).
512
415
  *
513
416
  * @module
514
417
  */
515
418
 
419
+ /**
420
+ * Device permission the dapp can ask the host to grant via
421
+ * {@link requestDevicePermission}.
422
+ *
423
+ * Derived from the upstream codec so variant renames surface as compile
424
+ * errors, not runtime failures.
425
+ */
426
+ type DevicePermissionKind = CodecType<typeof DevicePermission>;
427
+ /**
428
+ * Alias of {@link RemotePermission} matching the upstream
429
+ * `@novasamatech/host-api-wrapper` name. Use either freely.
430
+ */
431
+ type RemotePermissionItem = RemotePermission;
516
432
  /**
517
433
  * Request a single remote permission from the host.
518
434
  *
@@ -532,5 +448,244 @@ interface AccountsProvider {
532
448
  * ```
533
449
  */
534
450
  declare function requestPermission(permission: RemotePermission): Promise<boolean>;
451
+ /**
452
+ * Request a single device permission (camera, microphone, etc.) from the
453
+ * host.
454
+ *
455
+ * Builds the `v1` envelope, calls `hostApi.devicePermission`, unwraps the
456
+ * response, and returns the host's boolean granted/denied outcome.
457
+ *
458
+ * @param permission - The device permission to request.
459
+ * @returns `true` if the host granted the permission, `false` if denied.
460
+ * @throws If the host is unavailable or the request fails.
461
+ *
462
+ * @example
463
+ * ```ts
464
+ * const granted = await requestDevicePermission("Camera");
465
+ * if (!granted) {
466
+ * showCameraDeniedMessage();
467
+ * }
468
+ * ```
469
+ */
470
+ declare function requestDevicePermission(permission: DevicePermissionKind): Promise<boolean>;
471
+
472
+ /**
473
+ * Higher-level wrapper for the host's theme subscription.
474
+ *
475
+ * `hostApi.themeSubscribe` is reachable via {@link getTruApi}, but consumers
476
+ * have to wire the subscription envelope themselves. `getThemeProvider`
477
+ * returns the `@novasamatech/host-api-wrapper` theme provider object directly,
478
+ * giving callers a `subscribeTheme(cb)` method that resolves to a typed
479
+ * `ThemeMode` ("Light" | "Dark") and yields a `Subscription<void>` handle.
480
+ *
481
+ * @module
482
+ */
483
+
484
+ /**
485
+ * Host theme provider handle. Exposes `subscribeTheme(callback)` which
486
+ * receives a typed `ThemeMode` on every change and returns a
487
+ * `Subscription<void>` (`unsubscribe` + `onInterrupt`).
488
+ *
489
+ * Type identical to `createThemeProvider()` from
490
+ * `@novasamatech/host-api-wrapper`.
491
+ */
492
+ type ThemeProvider = ReturnType<typeof createThemeProvider>;
493
+ /** Host theme mode value. Re-exported from `@novasamatech/host-api-wrapper`. */
494
+ type ThemeMode = ThemeMode$1;
495
+ /**
496
+ * Get the host theme provider.
497
+ *
498
+ * Returns the theme-subscription handle exported by
499
+ * `@novasamatech/host-api-wrapper`, or `null` if the package is unavailable
500
+ * (running outside a host container or the optional peer dep isn't
501
+ * installed).
502
+ *
503
+ * Implementation note: upstream `@novasamatech/host-api-wrapper` exports only
504
+ * the `createThemeProvider` factory and no `themeProvider` singleton, so
505
+ * this getter constructs a fresh instance on each call (unlike
506
+ * {@link getPreimageManager} or {@link getHostLocalStorage}, which return
507
+ * upstream singletons). The constructed provider is cheap to allocate; it
508
+ * only opens a subscription when `subscribeTheme` is called.
509
+ *
510
+ * @returns The theme provider, or `null` if unavailable.
511
+ *
512
+ * @example
513
+ * ```ts
514
+ * import { getThemeProvider } from "@parity/product-sdk-host";
515
+ *
516
+ * const provider = await getThemeProvider();
517
+ * if (provider) {
518
+ * const sub = provider.subscribeTheme((mode) => {
519
+ * document.documentElement.dataset.theme = mode.toLowerCase();
520
+ * });
521
+ * // sub.unsubscribe() to stop listening
522
+ * }
523
+ * ```
524
+ */
525
+ declare function getThemeProvider(): Promise<ThemeProvider | null>;
526
+
527
+ /**
528
+ * Higher-level wrapper for the host's entropy derivation (RFC-0007).
529
+ *
530
+ * `hostApi.deriveEntropy` is reachable via {@link getTruApi}, but consumers
531
+ * have to wrap the value in the versioned envelope (`enumValue("v1", ...)`)
532
+ * and unwrap the neverthrow `ResultAsync` themselves. `deriveEntropy`
533
+ * collapses that to a throw-on-error Promise that matches the shape of
534
+ * {@link requestPermission} and {@link requestResourceAllocation}.
535
+ *
536
+ * @module
537
+ */
538
+ /**
539
+ * Derive deterministic entropy from a context key (RFC-0007).
540
+ *
541
+ * The host derives entropy from the user's wallet + the provided context
542
+ * key. Calling with the same key on the same wallet yields the same bytes;
543
+ * different keys (or different wallets) yield uncorrelated entropy.
544
+ *
545
+ * @param key - Context key bytes (typically a SCALE-encoded discriminator).
546
+ * @returns The derived entropy bytes.
547
+ * @throws If the host is unavailable or the host-side derivation fails.
548
+ *
549
+ * @example
550
+ * ```ts
551
+ * import { deriveEntropy } from "@parity/product-sdk-host";
552
+ *
553
+ * const seed = await deriveEntropy(new TextEncoder().encode("my-app:seed-v1"));
554
+ * ```
555
+ */
556
+ declare function deriveEntropy(key: Uint8Array): Promise<Uint8Array>;
557
+
558
+ /**
559
+ * Wrapper for the host's chat surface (`host_chat_*` family).
560
+ *
561
+ * Shipped flat-in-host rather than as `getTruApi().chat.*` (the shape
562
+ * sketched in issue #93) because the upstream JS `hostApi` is itself a
563
+ * flat object - there is no `.chat` accessor to mirror. A flat
564
+ * `getChatManager()` matches the pattern already used by
565
+ * {@link getThemeProvider}, {@link getAccountsProvider}, and
566
+ * {@link getStatementStore}; if a namespaced view is desirable later, it
567
+ * can be layered on top without breaking this surface.
568
+ *
569
+ * @module
570
+ */
571
+
572
+ /** Chat message payload variants. Re-exported from `@novasamatech/host-api-wrapper`. */
573
+ type ChatMessageContent = ChatMessageContent$1;
574
+ /** Action received via {@link ChatManager.subscribeAction}. Re-exported from `@novasamatech/host-api-wrapper`. */
575
+ type ChatReceivedAction = ChatReceivedAction$1;
576
+ /** Room metadata delivered to {@link ChatManager.subscribeChatList}. Re-exported from `@novasamatech/host-api-wrapper`. */
577
+ type ChatRoom = ChatRoom$1;
578
+ /** Result of registering a chat room (`"New" | "Exists"`). Re-exported from `@novasamatech/host-api-wrapper`. */
579
+ type ChatRoomRegistrationResult = ChatRoomRegistrationResult$1;
580
+ /** Result of registering a bot (`"New" | "Exists"`). Re-exported from `@novasamatech/host-api-wrapper`. */
581
+ type ChatBotRegistrationResult = ChatBotRegistrationResult$1;
582
+ /** Renderer callback for custom message types. Re-exported from `@novasamatech/host-api-wrapper`. */
583
+ type ChatCustomMessageRenderer = ChatCustomMessageRenderer$1;
584
+ /** Parameters passed to a {@link ChatCustomMessageRenderer}. Re-exported from `@novasamatech/host-api-wrapper`. */
585
+ type ChatCustomMessageRendererParams<T = Uint8Array> = ChatCustomMessageRendererParams$1<T>;
586
+ /**
587
+ * Chat manager handle. Exposes room/bot registration, message sending,
588
+ * subscription to room list and incoming actions, and custom-renderer
589
+ * registration.
590
+ *
591
+ * Type identical to `createProductChatManager()` from
592
+ * `@novasamatech/host-api-wrapper`.
593
+ */
594
+ type ChatManager = ReturnType<typeof createProductChatManager>;
595
+ /**
596
+ * Get the host chat manager.
597
+ *
598
+ * Returns the chat manager from `@novasamatech/host-api-wrapper`, or `null` if
599
+ * the package is unavailable (running outside a host container or the
600
+ * optional peer dep isn't installed).
601
+ *
602
+ * @returns The chat manager, or `null` if unavailable.
603
+ *
604
+ * @example
605
+ * ```ts
606
+ * import { getChatManager } from "@parity/product-sdk-host";
607
+ *
608
+ * const chat = await getChatManager();
609
+ * if (chat) {
610
+ * await chat.registerBot({ botId: "echo", name: "Echo Bot", icon: "" });
611
+ * chat.subscribeAction((action) => { ... });
612
+ * }
613
+ * ```
614
+ */
615
+ declare function getChatManager(): Promise<ChatManager | null>;
616
+ /**
617
+ * Dispatch helper that composes multiple custom-message renderers into a
618
+ * single {@link ChatCustomMessageRenderer} keyed by `messageType`.
619
+ *
620
+ * Mirrors `matchChatCustomRenderers` from `@novasamatech/host-api-wrapper`
621
+ * inline (the upstream implementation is pure dispatch logic with no
622
+ * transport / runtime dependency on Novasama), so callers get the same
623
+ * sync signature instead of an async-with-null wrapper.
624
+ *
625
+ * @param map - Object mapping `messageType` strings to renderers.
626
+ * @returns A composed renderer that dispatches to the entry matching
627
+ * `params.messageType`, or throws if no renderer is registered.
628
+ */
629
+ declare function matchChatCustomRenderers(map: Record<string, ChatCustomMessageRenderer>): ChatCustomMessageRenderer;
630
+
631
+ /**
632
+ * Wrapper for the host's payment manager (RFC-0006).
633
+ *
634
+ * Shipped flat-in-host rather than as `getTruApi().payment.*` because the
635
+ * upstream JS `hostApi` is itself a flat object - there is no `.payment`
636
+ * accessor to mirror. A flat `getPaymentManager()` matches the singleton
637
+ * pattern already used by {@link getPreimageManager},
638
+ * {@link getHostLocalStorage}, and {@link getAccountsProvider}.
639
+ *
640
+ * Returns the shared `paymentManager` singleton from
641
+ * `@novasamatech/host-api-wrapper` (not a fresh `createPaymentManager()`
642
+ * instance) so callers share one wrapper + hostApi closure across the app.
643
+ *
644
+ * Distinct from the CoinPayment / merchant-payments surface tracked under
645
+ * `@parity/product-sdk-merchant-payments` (RFC-0017). RFC-0006 is the
646
+ * user-initiated balance / top-up / payment-request flow; RFC-0017 is the
647
+ * merchant-initiated checkout flow.
648
+ *
649
+ * @module
650
+ */
651
+
652
+ /** Available balance for the user's payment account. Re-exported from `@novasamatech/host-api-wrapper`. */
653
+ type PaymentBalance = PaymentBalance$1;
654
+ /** Status of an in-flight payment request. Re-exported from `@novasamatech/host-api-wrapper`. */
655
+ type PaymentStatus = PaymentStatus$1;
656
+ /** Source for {@link PaymentManager.topUp}. Re-exported from `@novasamatech/host-api-wrapper`. */
657
+ type TopUpSource = TopUpSource$1;
658
+ /**
659
+ * Payment manager handle. Exposes balance subscription, top-up, payment
660
+ * requests, and payment status subscription.
661
+ *
662
+ * Type identical to `paymentManager` from `@novasamatech/host-api-wrapper`.
663
+ */
664
+ type PaymentManager = typeof paymentManager;
665
+ /**
666
+ * Get the host payment manager.
667
+ *
668
+ * Returns the shared `paymentManager` singleton from
669
+ * `@novasamatech/host-api-wrapper`, or `null` if the package is unavailable
670
+ * (running outside a host container or the optional peer dep isn't
671
+ * installed).
672
+ *
673
+ * @returns The payment manager, or `null` if unavailable.
674
+ *
675
+ * @example
676
+ * ```ts
677
+ * import { getPaymentManager } from "@parity/product-sdk-host";
678
+ *
679
+ * const payments = await getPaymentManager();
680
+ * if (payments) {
681
+ * const sub = payments.subscribeBalance((b) => { ... });
682
+ * await payments.topUp(1_000_000n, { type: "productAccount", derivationIndex: 0 });
683
+ * const destination = new Uint8Array(32);
684
+ * const { id } = await payments.requestPayment(500n, destination);
685
+ * sub.unsubscribe();
686
+ * }
687
+ * ```
688
+ */
689
+ declare function getPaymentManager(): Promise<PaymentManager | null>;
535
690
 
536
- export { type AccountsProvider, type AllocatableResource, type AllocatableResourceTag, type AllocationOutcome, type AllocationOutcomeTag, BULLETIN_RPCS, type ContextualAlias, DEFAULT_BULLETIN_ENDPOINT, type HostAccount, type HostLocalStorage, type HostStatementStore, type HostSubscription, type PreimageManager, type ProductAccount, type RemotePermission, type RemotePermissionTag, type ResultAsync, type Statement, type StatementProof, type StatementTopicFilter, type StatementsPage, type TruApi, createProofAuthorized, getAccountsProvider, getHostLocalStorage, getHostProvider, getPreimageManager, getStatementStore, getTruApi, isInsideContainer, isInsideContainerSync, requestPermission, requestResourceAllocation };
691
+ export { type AccountsProvider, type AllocatableResource, type AllocatableResourceTag, type AllocationOutcome, type AllocationOutcomeTag, BULLETIN_RPCS, type ChatBotRegistrationResult, type ChatCustomMessageRenderer, type ChatCustomMessageRendererParams, type ChatManager, type ChatMessageContent, type ChatReceivedAction, type ChatRoom, type ChatRoomRegistrationResult, type ContextualAlias, DEFAULT_BULLETIN_ENDPOINT, type DevicePermissionKind, type HostAccount, type HostLocalStorage, type HostStatementStore, type HostSubscription, type PaymentBalance, type PaymentManager, type PaymentStatus, type PreimageManager, type ProductAccount, type ProductAccountId, type RemotePermission, type RemotePermissionItem, type RemotePermissionTag, type ResultAsync, type SignedStatement, type Statement, type StatementProof, type StatementTopicFilter, type StatementsPage, type ThemeMode, type ThemeProvider, type TopUpSource, type Topic, type TruApi, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, formatHostError, getAccountsProvider, getChatManager, getHostLocalStorage, getHostProvider, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isInsideContainer, isInsideContainerSync, matchChatCustomRenderers, requestDevicePermission, requestPermission, requestResourceAllocation };