@parity/product-sdk-host 0.3.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 +462 -203
- package/dist/index.js +163 -19
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/chains.ts +2 -8
- package/src/chat.ts +124 -0
- package/src/container.ts +45 -9
- package/src/entropy.ts +65 -0
- package/src/index.ts +41 -1
- package/src/payments.ts +98 -0
- package/src/permissions.ts +232 -0
- package/src/theme.ts +82 -0
- package/src/truapi.ts +225 -126
- package/src/types.ts +62 -71
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
|
|
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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
29
|
+
* signature schemes - `Sr25519`, `Ed25519`, `Ecdsa`, and `OnChain` (chain-
|
|
27
30
|
* attestation-based proofs).
|
|
28
31
|
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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.
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
*
|
|
90
|
-
|
|
91
|
-
|
|
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/
|
|
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/
|
|
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`
|
|
170
|
-
*
|
|
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)`
|
|
187
|
-
* - `permission(permissions)`
|
|
188
|
-
* - `localStorageRead/Write/Clear`
|
|
189
|
-
* - `sign(payload)`
|
|
190
|
-
* - `deriveEntropy(context)`
|
|
191
|
-
* - `themeSubscribe()`
|
|
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 =
|
|
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/
|
|
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
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
*
|
|
@@ -283,12 +266,26 @@ declare function getAccountsProvider(): Promise<AccountsProvider | null>;
|
|
|
283
266
|
* errors, not runtime failures.
|
|
284
267
|
*/
|
|
285
268
|
type AllocatableResource = CodecType<typeof AllocatableResource$1>;
|
|
269
|
+
/** Tag-only view of {@link AllocatableResource} for places that just need the variant name. */
|
|
270
|
+
type AllocatableResourceTag = AllocatableResource["tag"];
|
|
286
271
|
/**
|
|
287
272
|
* Per-resource outcome from {@link requestResourceAllocation}.
|
|
288
273
|
* The host strips secret payloads from `Allocated` before returning, so
|
|
289
274
|
* `value` is always `undefined` on the product side.
|
|
290
275
|
*/
|
|
291
276
|
type AllocationOutcome = CodecType<typeof AllocationOutcome$1>;
|
|
277
|
+
/** Tag-only view of {@link AllocationOutcome} (`"Allocated" | "Rejected" | "NotAvailable"`). */
|
|
278
|
+
type AllocationOutcomeTag = AllocationOutcome["tag"];
|
|
279
|
+
/**
|
|
280
|
+
* Remote permission the dapp can ask the host to grant via
|
|
281
|
+
* {@link requestPermission}.
|
|
282
|
+
*
|
|
283
|
+
* Derived from the upstream codec so variant renames surface as compile
|
|
284
|
+
* errors, not runtime failures.
|
|
285
|
+
*/
|
|
286
|
+
type RemotePermission = CodecType<typeof RemotePermission$1>;
|
|
287
|
+
/** Tag-only view of {@link RemotePermission}. */
|
|
288
|
+
type RemotePermissionTag = RemotePermission["tag"];
|
|
292
289
|
/**
|
|
293
290
|
* Request the host to pre-allocate one or more resource allowances.
|
|
294
291
|
*
|
|
@@ -308,6 +305,48 @@ type AllocationOutcome = CodecType<typeof AllocationOutcome$1>;
|
|
|
308
305
|
* ```
|
|
309
306
|
*/
|
|
310
307
|
declare function requestResourceAllocation(resources: AllocatableResource[]): Promise<AllocationOutcome[]>;
|
|
308
|
+
/**
|
|
309
|
+
* Have the host sign a Statement using an allowance-bearing account it
|
|
310
|
+
* picks internally — RFC-10 §"Statement Store allowance".
|
|
311
|
+
*
|
|
312
|
+
* The product passes only the Statement payload; the host chooses the
|
|
313
|
+
* `//allowance//statement-store//{productId}` account that holds SSS
|
|
314
|
+
* allowance and signs with it. Allowance is provisioned implicitly on
|
|
315
|
+
* first use if the host hasn't already pre-allocated via
|
|
316
|
+
* {@link requestResourceAllocation}; products never see the signing
|
|
317
|
+
* account or its key material.
|
|
318
|
+
*
|
|
319
|
+
* Pairs with {@link getStatementStore}'s `submit`: call this to obtain
|
|
320
|
+
* a proof, attach it to the Statement, and submit the result.
|
|
321
|
+
*
|
|
322
|
+
* @param statement - The Statement to be signed.
|
|
323
|
+
* @returns The proof to attach before submitting.
|
|
324
|
+
* @throws If the host is unavailable or the host-side signing fails.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* import { createProofAuthorized, getStatementStore } from "@parity/product-sdk-host";
|
|
329
|
+
*
|
|
330
|
+
* const statement = {
|
|
331
|
+
* proof: undefined,
|
|
332
|
+
* decryptionKey: undefined,
|
|
333
|
+
* expiry: undefined,
|
|
334
|
+
* channel: undefined,
|
|
335
|
+
* topics: [],
|
|
336
|
+
* data: payload,
|
|
337
|
+
* };
|
|
338
|
+
* const proof = await createProofAuthorized(statement);
|
|
339
|
+
* const store = await getStatementStore();
|
|
340
|
+
* await store?.submit({ ...statement, proof });
|
|
341
|
+
* ```
|
|
342
|
+
*
|
|
343
|
+
* @remarks
|
|
344
|
+
* RFC-10 introduces this as a new, strictly additive TruAPI call. The
|
|
345
|
+
* pre-existing `HostStatementStore.createProof(accountId, statement)`
|
|
346
|
+
* surface stays available for products that own a non-allowance signing
|
|
347
|
+
* account; this wrapper is the sponsored-submission path.
|
|
348
|
+
*/
|
|
349
|
+
declare function createProofAuthorized(statement: Statement): Promise<StatementProof>;
|
|
311
350
|
/**
|
|
312
351
|
* One of the user's existing wallet accounts, surfaced through the host and
|
|
313
352
|
* identified by its public key and an optional name. Contrast with
|
|
@@ -352,81 +391,301 @@ interface ResultAsync<T, E> {
|
|
|
352
391
|
match: <A, B = A>(ok: (t: T) => A, err: (e: E) => B) => Promise<A | B>;
|
|
353
392
|
}
|
|
354
393
|
/**
|
|
355
|
-
* Accounts provider
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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>;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Higher-level wrappers for the host's single-permission flows.
|
|
407
|
+
*
|
|
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).
|
|
415
|
+
*
|
|
416
|
+
* @module
|
|
417
|
+
*/
|
|
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;
|
|
432
|
+
/**
|
|
433
|
+
* Request a single remote permission from the host.
|
|
434
|
+
*
|
|
435
|
+
* Builds the `v1` envelope, calls `hostApi.permission`, unwraps the response,
|
|
436
|
+
* and returns the host's boolean granted/denied outcome.
|
|
437
|
+
*
|
|
438
|
+
* @param permission - The remote permission to request.
|
|
439
|
+
* @returns `true` if the host granted the permission, `false` if denied.
|
|
440
|
+
* @throws If the host is unavailable or the request fails.
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```ts
|
|
444
|
+
* const granted = await requestPermission({ tag: "ChainSubmit", value: undefined });
|
|
445
|
+
* if (!granted) {
|
|
446
|
+
* tellUserToReconnect();
|
|
447
|
+
* }
|
|
448
|
+
* ```
|
|
449
|
+
*/
|
|
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>;
|
|
431
690
|
|
|
432
|
-
export { type AccountsProvider, type AllocatableResource, type AllocationOutcome, BULLETIN_RPCS, type ContextualAlias, DEFAULT_BULLETIN_ENDPOINT, type HostAccount, type HostLocalStorage, type HostStatementStore, type HostSubscription, type PreimageManager, type ProductAccount, type ResultAsync, type StatementProof, type StatementTopicFilter, type StatementsPage, type TruApi, getAccountsProvider, getHostLocalStorage, getHostProvider, getPreimageManager, getStatementStore, getTruApi, isInsideContainer, isInsideContainerSync, 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 };
|