@parity/product-sdk-host 0.0.0-dev.312.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/LICENSE +201 -0
- package/dist/chain-discovery-nLrPzb3d.d.ts +70 -0
- package/dist/chunk-GDXSV7JV.js +50 -0
- package/dist/chunk-GDXSV7JV.js.map +1 -0
- package/dist/index.d.ts +1210 -0
- package/dist/index.js +1163 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.d.ts +105 -0
- package/dist/testing.js +177 -0
- package/dist/testing.js.map +1 -0
- package/package.json +46 -0
- package/src/accounts.ts +1052 -0
- package/src/chain-discovery.ts +287 -0
- package/src/chain-spec.ts +272 -0
- package/src/chain-transaction.ts +241 -0
- package/src/chains.ts +46 -0
- package/src/chat.ts +122 -0
- package/src/container.ts +339 -0
- package/src/entropy.ts +105 -0
- package/src/errors.ts +239 -0
- package/src/features.ts +172 -0
- package/src/index.ts +149 -0
- package/src/navigation.ts +128 -0
- package/src/notifications.ts +113 -0
- package/src/papi-provider.ts +741 -0
- package/src/payments.ts +117 -0
- package/src/permissions.ts +236 -0
- package/src/result.ts +13 -0
- package/src/testing.ts +493 -0
- package/src/theme.ts +78 -0
- package/src/transport.ts +181 -0
- package/src/truapi.ts +313 -0
- package/src/types.ts +101 -0
- package/src/worker.ts +261 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1210 @@
|
|
|
1
|
+
import { JsonRpcProvider, PolkadotSigner } from 'polkadot-api';
|
|
2
|
+
import { Topic, RemoteStatementStoreSubscribeItem, Statement, StatementProof, SignedStatement, HexString, scale, TrUApiClient, AllocatableResource, AllocationOutcome, VersionedHostGetUserIdError, HostRequestLoginResponse, VersionedHostRequestLoginError, ProductAccountId, ProductAccount as ProductAccount$1, VersionedHostAccountGetError, RingLocation, VersionedHostAccountRegisterRingVrfKeyError, RingVrfKeyDisclosure, RegisteredRingVrfKey as RegisteredRingVrfKey$1, VersionedHostAccountListRingVrfKeysError, ProductProofContext, ContextualAlias as ContextualAlias$1, VersionedHostAccountGetAliasError, LegacyAccount, VersionedHostGetLegacyAccountsError, HostAccountCreateProofResponse, VersionedHostAccountCreateProofError, VersionedHostAccountRingVrfSignError, VrfTranscriptItem as VrfTranscriptItem$1, VrfSignature as VrfSignature$1, VersionedHostAccountSignVrfError, HostAccountConnectionStatusSubscribeItem, HostDevicePermissionRequest, RemotePermission, HostThemeSubscribeItem, ChatBotRegistrationStatus, HostChatCreateRoomRequest, ChatRoomRegistrationStatus, HostChatRegisterBotRequest, ChatMessageContent, ChatRoom, HostChatActionSubscribeItem, HostPaymentBalanceSubscribeItem, CoinPaymentPurseId, Balance, PaymentTopUpSource, HostPaymentStatusSubscribeItem, HostPushNotificationRequest, NotificationId } from '@parity/truapi';
|
|
3
|
+
export { AllocatableResource, AllocationOutcome, ChatMessageContent, ChatRoom, DerivationIndex, HexString, HostPaymentBalanceSubscribeItem, HostPaymentStatusSubscribeItem, NotificationId, PaymentTopUpSource, ProductAccountId, ProductProofContext, HostPushNotificationError as PushNotificationError, RemotePermission, RingLocation, RingVrfKeyDisclosure, SignedStatement, Statement, StatementProof, ThemeName, ThemeVariant, Topic } from '@parity/truapi';
|
|
4
|
+
import { SdkError } from '@parity/product-sdk-errors';
|
|
5
|
+
export { SdkError, isSdkError } from '@parity/product-sdk-errors';
|
|
6
|
+
import { Result } from '@parity/result';
|
|
7
|
+
export { Result, err, ok } from '@parity/result';
|
|
8
|
+
export { H as HostChainDiscovery, a as HostChainIdentifier, g as getHostChainInfo, i as isInsideContainerSync } from './chain-discovery-nLrPzb3d.js';
|
|
9
|
+
import { ResultAsync as ResultAsync$1 } from 'neverthrow';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Public types for the host wrappers.
|
|
13
|
+
*
|
|
14
|
+
* The statement-store types are re-exported from `@parity/truapi` so the Parity
|
|
15
|
+
* surface stays in lockstep with the in-house protocol codec types. Their fields
|
|
16
|
+
* are `0x`-prefixed hex strings (`HexString`) and their enums are `{ tag }` unions.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Persistent storage exposed by the host container, including string, JSON
|
|
21
|
+
* and raw byte (`readBytes`/`writeBytes`) accessors. Most apps reach it
|
|
22
|
+
* indirectly through the Storage package's `KvStore`; reach for it directly
|
|
23
|
+
* via {@link getHostLocalStorage} when you need raw host storage without the
|
|
24
|
+
* KV abstraction.
|
|
25
|
+
*
|
|
26
|
+
* Backed by `truApi.localStorage.*` (raw `read`/`write`/`clear` over hex bytes);
|
|
27
|
+
* {@link getHostLocalStorage} adapts that into this richer surface. `readString`
|
|
28
|
+
* resolves to `""` for a missing key and `readJSON`/`readBytes` to
|
|
29
|
+
* `null`/`undefined`.
|
|
30
|
+
*/
|
|
31
|
+
interface HostLocalStorage {
|
|
32
|
+
/** Read a UTF-8 string value; `""` when the key is absent. */
|
|
33
|
+
readString(key: string): Promise<string>;
|
|
34
|
+
/** Write a UTF-8 string value. */
|
|
35
|
+
writeString(key: string, value: string): Promise<void>;
|
|
36
|
+
/** Read and JSON-parse a value; `null` when the key is absent. */
|
|
37
|
+
readJSON(key: string): Promise<unknown>;
|
|
38
|
+
/** JSON-stringify and write a value. */
|
|
39
|
+
writeJSON(key: string, value: unknown): Promise<void>;
|
|
40
|
+
/** Read raw bytes; `undefined` when the key is absent. */
|
|
41
|
+
readBytes(key: string): Promise<Uint8Array | undefined>;
|
|
42
|
+
/** Write raw bytes. */
|
|
43
|
+
writeBytes(key: string, value: Uint8Array): Promise<void>;
|
|
44
|
+
/** Remove a key. */
|
|
45
|
+
clear(key: string): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Topic-based subscription filter. The host delivers statements that match
|
|
49
|
+
* either *all* of the listed topics (`matchAll`) or *any* of them (`matchAny`).
|
|
50
|
+
*
|
|
51
|
+
* This is a field-discriminated form of truapi's `RemoteStatementStoreSubscribeRequest`,
|
|
52
|
+
* which is a tagged union (`{ tag: "MatchAll"; value: Topic[] } | { tag: "MatchAny"; value: Topic[] }`).
|
|
53
|
+
* The transport maps between the two.
|
|
54
|
+
*/
|
|
55
|
+
type StatementTopicFilter = {
|
|
56
|
+
matchAll: Topic[];
|
|
57
|
+
} | {
|
|
58
|
+
matchAny: Topic[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A page of signed statements delivered by {@link HostStatementStore.subscribe}.
|
|
62
|
+
*
|
|
63
|
+
* truapi's `RemoteStatementStoreSubscribeItem`, re-exported under a friendlier
|
|
64
|
+
* name. Pages arrive sequentially; `isComplete` is `false` while the host
|
|
65
|
+
* streams the historical backfill and `true` once it's done (and on every
|
|
66
|
+
* subsequent live-update page).
|
|
67
|
+
*/
|
|
68
|
+
type StatementsPage = RemoteStatementStoreSubscribeItem;
|
|
69
|
+
/**
|
|
70
|
+
* Subscription handle returned by the host. Exposes `unsubscribe()` plus an
|
|
71
|
+
* `onInterrupt` hook that fires if the host interrupts the subscription
|
|
72
|
+
* server-side; `onInterrupt` returns a function that cancels the hook.
|
|
73
|
+
*/
|
|
74
|
+
interface HostSubscription {
|
|
75
|
+
unsubscribe(): void;
|
|
76
|
+
onInterrupt(callback: (reason?: unknown) => void): () => void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Statement Store handle exposed by the host container, backed by
|
|
80
|
+
* `truApi.statementStore.*`. `subscribe` streams matching statements;
|
|
81
|
+
* `createProofAuthorized` signs a statement with the product's RFC-10 allowance
|
|
82
|
+
* account (the sponsored path — no per-call account id); `submit` publishes a
|
|
83
|
+
* signed statement. The `statement-store` package layers a higher-level client
|
|
84
|
+
* on top.
|
|
85
|
+
*/
|
|
86
|
+
interface HostStatementStore {
|
|
87
|
+
subscribe(filter: StatementTopicFilter, callback: (page: StatementsPage) => void): HostSubscription;
|
|
88
|
+
createProofAuthorized(statement: Statement): Promise<StatementProof>;
|
|
89
|
+
submit(signedStatement: SignedStatement): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Thrown by {@link getHostProvider} when the host container is reachable but does
|
|
94
|
+
* not support the requested chain — e.g. the chain isn't enabled in this host
|
|
95
|
+
* build, or the descriptor's genesis hash has drifted from the host's after a
|
|
96
|
+
* network reset.
|
|
97
|
+
*
|
|
98
|
+
* Surfacing this as a thrown error (rather than handing back a provider that
|
|
99
|
+
* silently swallows every JSON-RPC request) is what lets callers of
|
|
100
|
+
* `createChainClient` detect the failure. Without it, the host's fallback no-op
|
|
101
|
+
* provider drops every request on the floor and queries await forever.
|
|
102
|
+
*/
|
|
103
|
+
declare class ChainNotSupportedError extends Error {
|
|
104
|
+
/** Genesis hash of the chain the host refused, for programmatic detection. */
|
|
105
|
+
readonly genesisHash: string;
|
|
106
|
+
constructor(genesisHash: string);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Detect if running inside a Host container (Polkadot Browser / Polkadot Desktop).
|
|
110
|
+
*
|
|
111
|
+
* The SDK is designed to run exclusively inside a host container. This function
|
|
112
|
+
* is primarily useful for early validation or informational purposes.
|
|
113
|
+
*/
|
|
114
|
+
declare function isInsideContainer(): Promise<boolean>;
|
|
115
|
+
/**
|
|
116
|
+
* Get the Host API localStorage instance when running inside a container.
|
|
117
|
+
* Returns null outside a container or when the host transport is unavailable.
|
|
118
|
+
*/
|
|
119
|
+
declare function getHostLocalStorage(): Promise<HostLocalStorage | null>;
|
|
120
|
+
/**
|
|
121
|
+
* Construct a host-backed `HostLocalStorage` instance. Retained for API
|
|
122
|
+
* compatibility; with the single cached TruAPI client this is equivalent to
|
|
123
|
+
* {@link getHostLocalStorage}.
|
|
124
|
+
*
|
|
125
|
+
* @returns A `HostLocalStorage` instance, or `null` if unavailable.
|
|
126
|
+
*/
|
|
127
|
+
declare function createHostLocalStorage(): Promise<HostLocalStorage | null>;
|
|
128
|
+
/**
|
|
129
|
+
* Get a PAPI-compatible JSON-RPC provider that routes through the host connection.
|
|
130
|
+
*
|
|
131
|
+
* When running inside a Polkadot container, this builds a `JsonRpcProvider` over
|
|
132
|
+
* `truApi.chain.*` (see {@link module:papi-provider}), enabling shared
|
|
133
|
+
* connections and efficient routing. Returns `null` when not running inside a
|
|
134
|
+
* container.
|
|
135
|
+
*
|
|
136
|
+
* @param genesisHash - Genesis hash of the target chain (`0x`-prefixed hex string).
|
|
137
|
+
* @returns A host-routed `JsonRpcProvider`, or `null` if unavailable.
|
|
138
|
+
* @throws {ChainNotSupportedError} When inside a container but the host can't serve
|
|
139
|
+
* the chain — surfaced instead of returning a provider that would hang forever.
|
|
140
|
+
*/
|
|
141
|
+
declare function getHostProvider(genesisHash: HexString): Promise<JsonRpcProvider | null>;
|
|
142
|
+
/**
|
|
143
|
+
* Get the host statement store when running inside a container, backed by
|
|
144
|
+
* `truApi.statementStore.*`.
|
|
145
|
+
*
|
|
146
|
+
* Returns a store with `subscribe`, `createProofAuthorized`, and `submit` that
|
|
147
|
+
* communicate through the host's native binary protocol — bypassing JSON-RPC
|
|
148
|
+
* entirely. Returns `null` outside a host container.
|
|
149
|
+
*
|
|
150
|
+
* @returns The host statement store, or `null` if unavailable.
|
|
151
|
+
*/
|
|
152
|
+
declare function getStatementStore(): Promise<HostStatementStore | null>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Shared chain network configuration — single source of truth for
|
|
156
|
+
* chain-specific endpoints used by multiple packages.
|
|
157
|
+
*/
|
|
158
|
+
/**
|
|
159
|
+
* Bulletin Chain RPC endpoints per network environment. `paseo` (Paseo Next v2)
|
|
160
|
+
* and `devnet` (public Paseo testnet) are populated today; `polkadot` and
|
|
161
|
+
* `kusama` are reserved for when those Bulletin deployments go live.
|
|
162
|
+
*/
|
|
163
|
+
declare const BULLETIN_RPCS: {
|
|
164
|
+
readonly paseo: readonly ["wss://paseo-bulletin-next-rpc.polkadot.io"];
|
|
165
|
+
readonly devnet: readonly ["wss://bulletin-paseo.tservices.es:8443"];
|
|
166
|
+
readonly polkadot: string[];
|
|
167
|
+
readonly kusama: string[];
|
|
168
|
+
};
|
|
169
|
+
/** Default Bulletin Chain endpoint — the first entry under {@link BULLETIN_RPCS}.paseo. */
|
|
170
|
+
declare const DEFAULT_BULLETIN_ENDPOINT: string;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Typed errors carried on the `err` channel of the host public API's
|
|
174
|
+
* {@link Result} returns.
|
|
175
|
+
*
|
|
176
|
+
* The hierarchy mirrors `@parity/product-sdk-signer`'s error classes
|
|
177
|
+
* (`HostUnavailableError` / `HostRejectedError`), so the two layers share one
|
|
178
|
+
* idiom: branch with `instanceof`, and every error is a real `Error` with a
|
|
179
|
+
* stack trace and `cause`. The structured truapi wire error
|
|
180
|
+
* ({@link HostErrorPayload}) rides along as {@link HostCallFailedError.payload}
|
|
181
|
+
* for callers that want fine-grained tag-level handling.
|
|
182
|
+
*
|
|
183
|
+
* This module also owns {@link HostErrorPayload} (the wire-error shape) and
|
|
184
|
+
* {@link formatHostError} (renders a payload to a message) — co-located with the
|
|
185
|
+
* error classes that consume them so the host error model lives in one place.
|
|
186
|
+
*
|
|
187
|
+
* @module
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* What a `Domain`-tagged call error carries. Widened from truapi's per-domain
|
|
192
|
+
* `Versioned*Error` types (all `{ tag: "V1", value: <domain error> }` today)
|
|
193
|
+
* so one payload type covers every call.
|
|
194
|
+
*/
|
|
195
|
+
type VersionedDomainError = {
|
|
196
|
+
tag: string;
|
|
197
|
+
value?: unknown;
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* The error a host call puts on its `Err` channel — truapi's canonical
|
|
201
|
+
* {@link scale.CallErrorValue} envelope. `Denied` / `Unsupported` /
|
|
202
|
+
* `MalformedFrame` / `HostFailure` are transport-level failures; `Domain`
|
|
203
|
+
* wraps the actual per-domain error in a versioned envelope, which
|
|
204
|
+
* {@link formatHostError} digs through when rendering.
|
|
205
|
+
*
|
|
206
|
+
* This is the payload {@link HostCallFailedError} carries — not the error
|
|
207
|
+
* type consumers branch on.
|
|
208
|
+
*/
|
|
209
|
+
type HostErrorPayload = scale.CallErrorValue<VersionedDomainError>;
|
|
210
|
+
/**
|
|
211
|
+
* Extract a human-readable message from a host-side error.
|
|
212
|
+
*
|
|
213
|
+
* Renders the {@link HostErrorPayload} shapes `@parity/truapi` surfaces. Accepts
|
|
214
|
+
* `unknown` because it is also the catch-all formatter for thrown adapter-method
|
|
215
|
+
* `Error` messages, so it falls back to `Error`/string/JSON rendering for
|
|
216
|
+
* anything that isn't a recognized host error payload.
|
|
217
|
+
*
|
|
218
|
+
* Used by {@link HostCallFailedError} to render its message, and by the throwing
|
|
219
|
+
* adapter-method helper `unwrapHostResult`.
|
|
220
|
+
*/
|
|
221
|
+
declare function formatHostError(error: unknown): string;
|
|
222
|
+
/**
|
|
223
|
+
* Base class for all host errors. Use `instanceof HostError` (or {@link isHostError})
|
|
224
|
+
* to catch any host-related failure. Implements the cross-package
|
|
225
|
+
* {@link SdkError} marker so `isSdkError(e)` also recognizes it.
|
|
226
|
+
*/
|
|
227
|
+
declare class HostError extends Error implements SdkError {
|
|
228
|
+
readonly isSdkError: true;
|
|
229
|
+
readonly source = "host";
|
|
230
|
+
constructor(message: string, options?: ErrorOptions);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The host API is not available — the app is running outside a Polkadot host
|
|
234
|
+
* container (no injected TruAPI transport). The dominant case during local
|
|
235
|
+
* development. Branch with `instanceof HostUnavailableError` to surface an
|
|
236
|
+
* "open this app in a Polkadot host" message.
|
|
237
|
+
*/
|
|
238
|
+
declare class HostUnavailableError extends HostError {
|
|
239
|
+
constructor(message?: string);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* A host call reached the container but failed on the `Err` channel. Wraps the
|
|
243
|
+
* structured truapi {@link HostErrorPayload} as {@link payload} (also preserved
|
|
244
|
+
* as `cause`); the message is rendered via {@link formatHostError}.
|
|
245
|
+
*/
|
|
246
|
+
declare class HostCallFailedError extends HostError {
|
|
247
|
+
readonly payload: HostErrorPayload;
|
|
248
|
+
constructor(label: string, payload: HostErrorPayload);
|
|
249
|
+
}
|
|
250
|
+
/** Check whether a value is any {@link HostError}. */
|
|
251
|
+
declare function isHostError(error: unknown): error is HostError;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* TruAPI - the protocol for communicating between apps and the Polkadot host container.
|
|
255
|
+
*
|
|
256
|
+
* This module centralizes access to the in-house `@parity/truapi` client,
|
|
257
|
+
* allowing other `@parity/product-sdk-*` packages to import from here rather
|
|
258
|
+
* than depending directly on the protocol package. The client is built and
|
|
259
|
+
* cached by {@link module:transport}; this module adds the accessor plus the
|
|
260
|
+
* two helpers the convenience wrappers fold truapi's `ResultAsync` through —
|
|
261
|
+
* {@link mapHostResult} (returns a `Result`, used by the public operations) and
|
|
262
|
+
* {@link unwrapHostResult} (throws, used by the adapter-object methods).
|
|
263
|
+
*
|
|
264
|
+
* @module
|
|
265
|
+
*/
|
|
266
|
+
|
|
267
|
+
/** Convert bytes to a `0x`-prefixed lower-case hex string. */
|
|
268
|
+
declare function toHex(bytes: Uint8Array): HexString;
|
|
269
|
+
/** Convert a hex string (with or without `0x`) to bytes. */
|
|
270
|
+
declare function fromHex(hex: string): Uint8Array;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The TruApi client — namespaced access to every host protocol domain
|
|
274
|
+
* (`permissions`, `entropy`, `signing`, `statementStore`, `system`,
|
|
275
|
+
* `localStorage`, …). Identical to `TrUApiClient` from `@parity/truapi`.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* const truApi = await getTruApi();
|
|
280
|
+
* if (truApi) {
|
|
281
|
+
* await truApi.permissions.requestRemotePermission({
|
|
282
|
+
* permission: { tag: "ChainSubmit", value: undefined },
|
|
283
|
+
* });
|
|
284
|
+
* await truApi.system.navigateTo({ url: "polkadot://settings" });
|
|
285
|
+
* }
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
type TruApi = TrUApiClient;
|
|
289
|
+
/**
|
|
290
|
+
* Get the TruAPI client for direct low-level access to host protocol domains.
|
|
291
|
+
*
|
|
292
|
+
* Returns the cached `@parity/truapi` client once the host transport is built
|
|
293
|
+
* and the handshake has run, or `null` when running outside a container.
|
|
294
|
+
*
|
|
295
|
+
* For most use cases, prefer the higher-level functions like
|
|
296
|
+
* {@link requestPermission}, {@link deriveEntropy}, or `getHostLocalStorage()`.
|
|
297
|
+
*
|
|
298
|
+
* @returns The TruAPI client, or `null` if unavailable.
|
|
299
|
+
*/
|
|
300
|
+
declare function getTruApi(): Promise<TruApi | null>;
|
|
301
|
+
/**
|
|
302
|
+
* Preimage manager handle for bulletin chain operations, backed by
|
|
303
|
+
* `truApi.preimage.*`. `lookup` opens a {@link HostSubscription} (`unsubscribe`
|
|
304
|
+
* + `onInterrupt`) that delivers the preimage bytes — or `null` until the host
|
|
305
|
+
* finds them; `submit` uploads a preimage and resolves to its `0x`-prefixed hex
|
|
306
|
+
* key.
|
|
307
|
+
*/
|
|
308
|
+
interface PreimageManager {
|
|
309
|
+
lookup(key: HexString, callback: (preimage: Uint8Array | null) => void): HostSubscription;
|
|
310
|
+
submit(value: Uint8Array): Promise<HexString>;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Get the preimage manager for bulletin chain operations.
|
|
314
|
+
*
|
|
315
|
+
* @returns The preimage manager, or `null` if unavailable (outside a container).
|
|
316
|
+
*/
|
|
317
|
+
declare function getPreimageManager(): Promise<PreimageManager | null>;
|
|
318
|
+
/**
|
|
319
|
+
* Construct a `PreimageManager`. Retained for API compatibility; with the single
|
|
320
|
+
* cached TruAPI client this is equivalent to {@link getPreimageManager}.
|
|
321
|
+
*
|
|
322
|
+
* @returns A `PreimageManager` instance, or `null` if unavailable.
|
|
323
|
+
*/
|
|
324
|
+
declare function createHostPreimageManager(): Promise<PreimageManager | null>;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Request the host to pre-allocate one or more resource allowances.
|
|
328
|
+
*
|
|
329
|
+
* The host prompts the user once; subsequent operations covered by the
|
|
330
|
+
* granted allowance don't re-prompt.
|
|
331
|
+
*
|
|
332
|
+
* @param resources - Resources to request.
|
|
333
|
+
* @returns `ok` with per-resource outcomes in the same order as `resources`, or
|
|
334
|
+
* `err(HostUnavailableError | HostCallFailedError)`.
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```ts
|
|
338
|
+
* const r = await requestResourceAllocation([
|
|
339
|
+
* { tag: "BulletinAllowance", value: undefined },
|
|
340
|
+
* ]);
|
|
341
|
+
* if (r.ok && r.value[0] === "Allocated") { ... }
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
declare function requestResourceAllocation(resources: AllocatableResource[]): Promise<Result<AllocationOutcome[], HostError>>;
|
|
345
|
+
/**
|
|
346
|
+
* Have the host sign a Statement using the product's allowance-bearing account,
|
|
347
|
+
* which it picks internally — RFC-10 §"Statement Store allowance". No per-call
|
|
348
|
+
* account id is needed (this is the sponsored-submission path).
|
|
349
|
+
*
|
|
350
|
+
* Pairs with {@link getStatementStore}'s `submit`: call this to obtain a proof,
|
|
351
|
+
* attach it to the Statement, and submit the result.
|
|
352
|
+
*
|
|
353
|
+
* @param statement - The Statement to be signed.
|
|
354
|
+
* @returns `ok` with the proof to attach before submitting, or
|
|
355
|
+
* `err(HostUnavailableError | HostCallFailedError)`.
|
|
356
|
+
*/
|
|
357
|
+
declare function createProofAuthorized(statement: Statement): Promise<Result<StatementProof, HostError>>;
|
|
358
|
+
/**
|
|
359
|
+
* Neverthrow-style ResultAsync returned by product-sdk methods.
|
|
360
|
+
*
|
|
361
|
+
* Use `.match(onOk, onErr)` to handle success/error cases.
|
|
362
|
+
*/
|
|
363
|
+
interface ResultAsync<T, E> {
|
|
364
|
+
match: <A, B = A>(ok: (t: T) => A, err: (e: E) => B) => Promise<A | B>;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Wrapper for calling this product's own background worker from its rendered
|
|
369
|
+
* surface (App, Widget, or Funding).
|
|
370
|
+
*
|
|
371
|
+
* A product ships two things: the web application the host renders, and a
|
|
372
|
+
* single background worker published at `worker.<product_id>.<tld>`. They run
|
|
373
|
+
* in different sandboxes and cannot reach each other directly. This module is
|
|
374
|
+
* the host-mediated path between them.
|
|
375
|
+
*
|
|
376
|
+
* **What crosses is data, never code.** `call(apiName, payload)` names an
|
|
377
|
+
* export the worker archive already declared; the host resolves it against the
|
|
378
|
+
* pinned, verified bundle. A page cannot hand the worker a function, a script,
|
|
379
|
+
* or an import path — that would let anything able to inject into the page
|
|
380
|
+
* (an XSS, a compromised dependency) run with worker authority, which is
|
|
381
|
+
* strictly wider than the page's own.
|
|
382
|
+
*
|
|
383
|
+
* **The page never names the product.** The host supplies the product identity
|
|
384
|
+
* from the surface it is rendering, so this call can only ever reach *your*
|
|
385
|
+
* worker.
|
|
386
|
+
*
|
|
387
|
+
* **Opt in on chain, not here.** The host only routes this call when the worker
|
|
388
|
+
* manifest declares the surface in `includes`. A worker published without it
|
|
389
|
+
* answers `unavailable`, exactly as a host with no worker support would.
|
|
390
|
+
*
|
|
391
|
+
* ```ts
|
|
392
|
+
* const worker = getWorkerManager();
|
|
393
|
+
* const { jobId } = await worker.call<{ jobId: string }>("startSettlement", {
|
|
394
|
+
* rail: "BANK",
|
|
395
|
+
* intentId,
|
|
396
|
+
* });
|
|
397
|
+
* ```
|
|
398
|
+
*
|
|
399
|
+
* @module
|
|
400
|
+
*/
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Why a worker call did not produce a result — the frozen error set the host
|
|
404
|
+
* runtime reports, surfaced verbatim so callers can branch rather than parse
|
|
405
|
+
* a message.
|
|
406
|
+
*
|
|
407
|
+
* - `unavailable` — no worker registered, the user disabled it, the manifest
|
|
408
|
+
* declares no ceiling for this surface, or the worker is in crash
|
|
409
|
+
* quarantine. This is the one worth handling: it is the normal answer on a
|
|
410
|
+
* host that does not run workers at all.
|
|
411
|
+
* - `denied` — the call passed the ceiling but failed a downstream
|
|
412
|
+
* authorization check.
|
|
413
|
+
* - `invalid` — the worker exports no such name, or the payload is malformed
|
|
414
|
+
* or over the host's size bound.
|
|
415
|
+
* - `timeout` — the call outlived its deadline and was revoked.
|
|
416
|
+
* - `crashed` — the worker threw or died handling the call.
|
|
417
|
+
* - `version` — the worker and host disagree on the protocol.
|
|
418
|
+
*/
|
|
419
|
+
type WorkerErrorTag = "unavailable" | "denied" | "invalid" | "timeout" | "crashed" | "version";
|
|
420
|
+
/**
|
|
421
|
+
* A worker call that reached the host and came back without a result. Branch
|
|
422
|
+
* on {@link WorkerCallError.tag}; `unavailable` is the expected answer when the
|
|
423
|
+
* product ships no worker or the user has switched it off, so treat it as a
|
|
424
|
+
* capability check rather than a fault.
|
|
425
|
+
*/
|
|
426
|
+
declare class WorkerCallError extends HostError {
|
|
427
|
+
/** Which of the frozen failure modes this was. */
|
|
428
|
+
readonly tag: WorkerErrorTag;
|
|
429
|
+
constructor(tag: WorkerErrorTag, reason?: string);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Handle for this product's background worker. Obtain one with
|
|
433
|
+
* {@link getWorkerManager}.
|
|
434
|
+
*/
|
|
435
|
+
interface WorkerManager {
|
|
436
|
+
/**
|
|
437
|
+
* Whether the host exposes the worker bridge at all. `false` outside a host
|
|
438
|
+
* container, and on hosts that predate the bridge. A `true` here does not
|
|
439
|
+
* promise the product *has* a worker — that surfaces as an `unavailable`
|
|
440
|
+
* {@link WorkerCallError} on the first call.
|
|
441
|
+
*/
|
|
442
|
+
isAvailable(): boolean;
|
|
443
|
+
/**
|
|
444
|
+
* Invoke an export the worker archive declared.
|
|
445
|
+
*
|
|
446
|
+
* @param apiName - Export name, as published in the worker bundle.
|
|
447
|
+
* @param payload - JSON-serialisable arguments. Bounded by the host's
|
|
448
|
+
* payload ceiling; keep it to identifiers and parameters, not blobs.
|
|
449
|
+
* @param options - `deadlineMs` overrides the host default and is clamped
|
|
450
|
+
* to the host's own window.
|
|
451
|
+
* @throws {@link WorkerCallError} for every typed failure, and
|
|
452
|
+
* {@link HostUnavailableError} when there is no host bridge at all.
|
|
453
|
+
*/
|
|
454
|
+
call<Result = unknown>(apiName: string, payload?: unknown, options?: {
|
|
455
|
+
deadlineMs?: number;
|
|
456
|
+
}): Promise<Result>;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Get the handle for this product's background worker.
|
|
460
|
+
*
|
|
461
|
+
* Follows the singleton accessor pattern used by `getNotificationManager` and
|
|
462
|
+
* `getPaymentManager`: cheap to call repeatedly, no setup, resolves the bridge
|
|
463
|
+
* lazily so a page that never talks to its worker pays nothing.
|
|
464
|
+
*/
|
|
465
|
+
declare function getWorkerManager(): WorkerManager;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Host wallet accounts, backed by `truApi.account.*` and `truApi.signing.*`.
|
|
469
|
+
*
|
|
470
|
+
* `getAccountsProvider()` returns the full accounts surface — user identity
|
|
471
|
+
* (`getUserId` / `requestLogin`), the user's existing wallet accounts
|
|
472
|
+
* (`getLegacyAccounts`), app-scoped product accounts (`getProductAccount` /
|
|
473
|
+
* `getProductAccountAlias`), Ring VRF proofs (`createRingVRFProof`), sr25519 VRF
|
|
474
|
+
* signatures over a caller-supplied Merlin transcript (`signVrf`), connection
|
|
475
|
+
* status, and PAPI `PolkadotSigner` factories for both product and legacy
|
|
476
|
+
* accounts.
|
|
477
|
+
*
|
|
478
|
+
* The signer factories build a PAPI `PolkadotSigner` directly over
|
|
479
|
+
* `truApi.signing.createTransaction` (product) /
|
|
480
|
+
* `createTransactionWithLegacyAccount` (legacy) — `signTx` derives the
|
|
481
|
+
* metadata-driven `txExtVersion` and maps the signed extensions to the host's
|
|
482
|
+
* wire shape; `signBytes` calls `signing.signRaw(WithLegacyAccount)`. No PJS
|
|
483
|
+
* bridge is involved, so opaque signed extensions (e.g. Paseo Next's `AsPgas`)
|
|
484
|
+
* survive end-to-end.
|
|
485
|
+
*
|
|
486
|
+
* @module
|
|
487
|
+
*/
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* One of the user's existing wallet accounts, surfaced through the host and
|
|
491
|
+
* identified by its public key and an optional name. Contrast with
|
|
492
|
+
* {@link ProductAccount}, which is also user-controlled but derived by the
|
|
493
|
+
* host for a specific app rather than picked from the user's existing keys.
|
|
494
|
+
*
|
|
495
|
+
* Derived from `@parity/truapi`'s `LegacyAccount`, with `publicKey` decoded to bytes.
|
|
496
|
+
*/
|
|
497
|
+
type HostAccount = Omit<LegacyAccount, "publicKey"> & {
|
|
498
|
+
/** Raw public key bytes. */
|
|
499
|
+
publicKey: Uint8Array;
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* A product account — an app-scoped derived account managed by the host wallet.
|
|
503
|
+
*
|
|
504
|
+
* The host derives a unique keypair for each app (identified by `dotNsIdentifier`)
|
|
505
|
+
* so apps get their own account that the user controls but is scoped to the app.
|
|
506
|
+
*
|
|
507
|
+
* Combines `@parity/truapi`'s `ProductAccountId` (the `{ dotNsIdentifier,
|
|
508
|
+
* derivationIndex }` lookup key) with the `ProductAccount` payload, with
|
|
509
|
+
* `publicKey` decoded to bytes and `derivationIndex` kept as the plain
|
|
510
|
+
* numeric index (the adapter wraps it into the wire's tagged
|
|
511
|
+
* {@link DerivationIndex} selector).
|
|
512
|
+
*/
|
|
513
|
+
type ProductAccount = Omit<ProductAccountId, "derivationIndex"> & Omit<ProductAccount$1, "publicKey"> & {
|
|
514
|
+
/** Plain account index within the product subtree. */
|
|
515
|
+
derivationIndex: number;
|
|
516
|
+
/** Raw public key bytes. */
|
|
517
|
+
publicKey: Uint8Array;
|
|
518
|
+
};
|
|
519
|
+
/**
|
|
520
|
+
* How callers address a product account: app identifier plus an optional index,
|
|
521
|
+
* defaulting to 0. A {@link ProductAccount} satisfies this, so an account from
|
|
522
|
+
* {@link AccountsProvider.getProductAccount} can be passed straight back in.
|
|
523
|
+
*/
|
|
524
|
+
type ProductAccountLookup = Omit<ProductAccountId, "derivationIndex"> & {
|
|
525
|
+
/** Plain account index within the product subtree. Defaults to 0. */
|
|
526
|
+
derivationIndex?: number;
|
|
527
|
+
};
|
|
528
|
+
declare const ringVrfKeyHandleBrand: unique symbol;
|
|
529
|
+
/**
|
|
530
|
+
* Opaque public name of a registered ring-VRF key.
|
|
531
|
+
*
|
|
532
|
+
* Handles come from {@link AccountsProvider.listRingVrfKeys}; product code
|
|
533
|
+
* cannot construct one from a derivation index.
|
|
534
|
+
*/
|
|
535
|
+
type RingVrfKeyHandle = {
|
|
536
|
+
readonly [ringVrfKeyHandleBrand]: "RingVrfKeyHandle";
|
|
537
|
+
};
|
|
538
|
+
/** Ring-VRF member public key, decoded from the wire's hex string. */
|
|
539
|
+
type RingVrfPublicKey = Uint8Array;
|
|
540
|
+
/** Registered key metadata returned by the host. */
|
|
541
|
+
type RegisteredRingVrfKey = Omit<RegisteredRingVrfKey$1, "handle" | "publicKey"> & {
|
|
542
|
+
/** Opaque handle to pass back for alias and proof requests. */
|
|
543
|
+
handle: RingVrfKeyHandle;
|
|
544
|
+
/** Present when public-key disclosure was granted. */
|
|
545
|
+
publicKey?: RingVrfPublicKey;
|
|
546
|
+
};
|
|
547
|
+
/**
|
|
548
|
+
* Select a registered key by its declared ring and return its opaque handle.
|
|
549
|
+
*
|
|
550
|
+
* Consumers must not hard-code another product's derivation index. Registry
|
|
551
|
+
* order breaks ties when an owner declares multiple keys for the same ring.
|
|
552
|
+
*/
|
|
553
|
+
declare function findRingVrfKeyHandle(keys: RegisteredRingVrfKey[], ring: RingLocation): RingVrfKeyHandle | undefined;
|
|
554
|
+
/**
|
|
555
|
+
* A contextual alias obtained from Ring VRF.
|
|
556
|
+
*
|
|
557
|
+
* Proves account membership in a ring without revealing which account.
|
|
558
|
+
*
|
|
559
|
+
* Derived from `@parity/truapi`'s `ContextualAlias`, with both fields decoded to bytes.
|
|
560
|
+
*/
|
|
561
|
+
type ContextualAlias = {
|
|
562
|
+
[K in keyof ContextualAlias$1]: Uint8Array;
|
|
563
|
+
};
|
|
564
|
+
/**
|
|
565
|
+
* A Ring VRF proof plus the values needed to verify it downstream (e.g.
|
|
566
|
+
* against a precompile): the alias it commits to, and the ring member index /
|
|
567
|
+
* revision the proof was generated against.
|
|
568
|
+
*
|
|
569
|
+
* Derived from `@parity/truapi`'s `HostAccountCreateProofResponse`, with the
|
|
570
|
+
* byte fields decoded.
|
|
571
|
+
*/
|
|
572
|
+
type RingVRFProof = Omit<HostAccountCreateProofResponse, "proof" | "contextualAlias"> & {
|
|
573
|
+
/** Raw ring VRF proof bytes. */
|
|
574
|
+
proof: Uint8Array;
|
|
575
|
+
/** Alias derived for the request's context. */
|
|
576
|
+
contextualAlias: ContextualAlias;
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* One `append_message(label, value)` call replayed against a VRF transcript.
|
|
580
|
+
* Merlin labels are ASCII by convention: use `utf8ToBytes("round")`.
|
|
581
|
+
*
|
|
582
|
+
* Derived from `@parity/truapi`'s `VrfTranscriptItem`, decoded to bytes.
|
|
583
|
+
*/
|
|
584
|
+
type VrfTranscriptItem = {
|
|
585
|
+
[K in keyof VrfTranscriptItem$1]: Uint8Array;
|
|
586
|
+
};
|
|
587
|
+
/**
|
|
588
|
+
* An sr25519 VRF signature: the pre-output and its DLEQ proof.
|
|
589
|
+
*
|
|
590
|
+
* Derived from `@parity/truapi`'s `VrfSignature`, decoded to bytes.
|
|
591
|
+
*/
|
|
592
|
+
type VrfSignature = {
|
|
593
|
+
[K in keyof VrfSignature$1]: Uint8Array;
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* Accounts provider handle, backed by `truApi.account.*` / `truApi.signing.*`.
|
|
597
|
+
* Surfaces the user's wallet accounts, app-scoped product accounts, Ring VRF,
|
|
598
|
+
* user identity, connection status, and `PolkadotSigner` factories.
|
|
599
|
+
*
|
|
600
|
+
* Lookup methods return a neverthrow `ResultAsync` (use `.match(ok, err)`);
|
|
601
|
+
* the signer factories return a synchronous PAPI `PolkadotSigner`. The `err`
|
|
602
|
+
* channel carries truapi's canonical `CallErrorValue` envelope around the
|
|
603
|
+
* per-call versioned domain error, exactly as the generated client returns it.
|
|
604
|
+
*/
|
|
605
|
+
interface AccountsProvider {
|
|
606
|
+
getUserId(): ResultAsync$1<{
|
|
607
|
+
primaryUsername: string;
|
|
608
|
+
}, scale.CallErrorValue<VersionedHostGetUserIdError>>;
|
|
609
|
+
requestLogin(reason?: string): ResultAsync$1<HostRequestLoginResponse, scale.CallErrorValue<VersionedHostRequestLoginError>>;
|
|
610
|
+
getProductAccount(dotNsIdentifier: string, derivationIndex?: number): ResultAsync$1<ProductAccount, scale.CallErrorValue<VersionedHostAccountGetError>>;
|
|
611
|
+
/**
|
|
612
|
+
* Register a ring-VRF key owned by the calling product.
|
|
613
|
+
*
|
|
614
|
+
* `index` is the plain derivation index within the product's ring-VRF
|
|
615
|
+
* domain; the adapter wraps it into the wire's tagged selector.
|
|
616
|
+
*
|
|
617
|
+
* Registration returns the key's public key. Call {@link listRingVrfKeys}
|
|
618
|
+
* afterward to obtain the opaque handle required by alias and proof calls.
|
|
619
|
+
*/
|
|
620
|
+
registerRingVrfKey(index: number, ring: RingLocation): ResultAsync$1<RingVrfPublicKey, scale.CallErrorValue<VersionedHostAccountRegisterRingVrfKeyError>>;
|
|
621
|
+
/** List an owner's registered ring-VRF keys. */
|
|
622
|
+
listRingVrfKeys(owner: string, disclosure?: RingVrfKeyDisclosure): ResultAsync$1<RegisteredRingVrfKey[], scale.CallErrorValue<VersionedHostAccountListRingVrfKeysError>>;
|
|
623
|
+
/** Derive a contextual alias with an explicitly registered ring-VRF key. */
|
|
624
|
+
getProductAccountAlias(keyHandle: RingVrfKeyHandle, context: ProductProofContext, location: RingLocation): ResultAsync$1<ContextualAlias, scale.CallErrorValue<VersionedHostAccountGetAliasError>>;
|
|
625
|
+
getLegacyAccounts(): ResultAsync$1<HostAccount[], scale.CallErrorValue<VersionedHostGetLegacyAccountsError>>;
|
|
626
|
+
/**
|
|
627
|
+
* Generate a Ring VRF proof with an explicitly registered key, binding
|
|
628
|
+
* `message` to the product-scoped `context`.
|
|
629
|
+
*/
|
|
630
|
+
createRingVRFProof(keyHandle: RingVrfKeyHandle, context: ProductProofContext, location: RingLocation, message: Uint8Array): ResultAsync$1<RingVRFProof, scale.CallErrorValue<VersionedHostAccountCreateProofError>>;
|
|
631
|
+
/**
|
|
632
|
+
* Sign `message` directly with an explicitly registered ring-VRF key.
|
|
633
|
+
*
|
|
634
|
+
* Unlike {@link createRingVRFProof} this proves nothing about ring
|
|
635
|
+
* membership; it is the plain signature under the member key, for
|
|
636
|
+
* protocols that carry their own proof.
|
|
637
|
+
*/
|
|
638
|
+
ringVrfSign(keyHandle: RingVrfKeyHandle, message: Uint8Array): ResultAsync$1<Uint8Array, scale.CallErrorValue<VersionedHostAccountRingVrfSignError>>;
|
|
639
|
+
/**
|
|
640
|
+
* Produce an sr25519 VRF signature from a product account (RFC-0023).
|
|
641
|
+
*
|
|
642
|
+
* The host builds a Merlin transcript from `transcriptLabel` and `items`,
|
|
643
|
+
* then signs it with the account's key. Unlike {@link createRingVRFProof},
|
|
644
|
+
* this names the signing account instead of proving ring membership.
|
|
645
|
+
*
|
|
646
|
+
* The caller owns four things the types cannot enforce:
|
|
647
|
+
*
|
|
648
|
+
* - Domain separation. A label borrowed from another protocol makes the
|
|
649
|
+
* output replayable across both.
|
|
650
|
+
* - Freshness. The VRF is deterministic, so per-round values belong in
|
|
651
|
+
* `items`.
|
|
652
|
+
* - Size. Hosts cap the transcript at 32 items and 8 KiB total.
|
|
653
|
+
* - Authorization. An `AutoSigning` allowance makes these calls silent. It
|
|
654
|
+
* is not VRF-scoped, so it covers other signing by that account too.
|
|
655
|
+
*
|
|
656
|
+
* Hosts predating the call reject it through the error channel.
|
|
657
|
+
*/
|
|
658
|
+
signVrf(account: ProductAccountLookup, transcriptLabel: Uint8Array, items: VrfTranscriptItem[]): ResultAsync$1<VrfSignature, scale.CallErrorValue<VersionedHostAccountSignVrfError>>;
|
|
659
|
+
/**
|
|
660
|
+
* Build a `PolkadotSigner` for a product account. Signing routes through the
|
|
661
|
+
* host's `createTransaction` path: the host decodes the metadata and forwards
|
|
662
|
+
* the opaque signed-extension bytes, so unknown extensions survive end-to-end.
|
|
663
|
+
*/
|
|
664
|
+
getProductAccountSigner(account: ProductAccount): PolkadotSigner;
|
|
665
|
+
/**
|
|
666
|
+
* Build a `PolkadotSigner` for one of the user's existing wallet accounts.
|
|
667
|
+
* `name` is accepted for callsite ergonomics but unused — the signer is
|
|
668
|
+
* derived from `publicKey` alone.
|
|
669
|
+
*/
|
|
670
|
+
getLegacyAccountSigner(account: {
|
|
671
|
+
publicKey: Uint8Array;
|
|
672
|
+
name?: string;
|
|
673
|
+
}): PolkadotSigner;
|
|
674
|
+
subscribeAccountConnectionStatus(callback: (status: HostAccountConnectionStatusSubscribeItem) => void): HostSubscription;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Get the accounts provider for managing host accounts, backed by
|
|
678
|
+
* `truApi.account.*` / `truApi.signing.*`. Returns `null` when running outside
|
|
679
|
+
* a host container.
|
|
680
|
+
*
|
|
681
|
+
* @returns The accounts provider, or `null` if unavailable.
|
|
682
|
+
*/
|
|
683
|
+
declare function getAccountsProvider(): Promise<AccountsProvider | null>;
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Higher-level wrappers for the host's single-permission flows.
|
|
687
|
+
*
|
|
688
|
+
* `truApi.permissions.requestRemotePermission` / `requestDevicePermission`
|
|
689
|
+
* return a neverthrow `ResultAsync` of a `{ granted }` response.
|
|
690
|
+
* {@link requestPermission} and {@link requestDevicePermission} collapse that
|
|
691
|
+
* to one-liners returning a `Result<boolean, HostError>` — the granted flag on
|
|
692
|
+
* success, a typed {@link HostError} on the `err` channel.
|
|
693
|
+
*
|
|
694
|
+
* @module
|
|
695
|
+
*/
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Device permission the dapp can ask the host to grant via
|
|
699
|
+
* {@link requestDevicePermission}. A string union (`"Camera"`, `"Microphone"`,
|
|
700
|
+
* …) re-exported from `@parity/truapi`.
|
|
701
|
+
*/
|
|
702
|
+
type DevicePermissionKind = HostDevicePermissionRequest;
|
|
703
|
+
/**
|
|
704
|
+
* Legacy alias of {@link RemotePermission}, kept for back-compat with code that
|
|
705
|
+
* used the older name. Use either freely.
|
|
706
|
+
*/
|
|
707
|
+
type RemotePermissionItem = RemotePermission;
|
|
708
|
+
/**
|
|
709
|
+
* Request a single remote permission from the host.
|
|
710
|
+
*
|
|
711
|
+
* Calls `truApi.permissions.requestRemotePermission` and returns the host's
|
|
712
|
+
* boolean granted/denied outcome.
|
|
713
|
+
*
|
|
714
|
+
* @param permission - The remote permission to request.
|
|
715
|
+
* @returns `ok(true)` if the host granted the permission, `ok(false)` if denied,
|
|
716
|
+
* or `err(HostUnavailableError | HostCallFailedError)`.
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* ```ts
|
|
720
|
+
* const r = await requestPermission({ tag: "ChainSubmit", value: undefined });
|
|
721
|
+
* if (!r.ok || !r.value) {
|
|
722
|
+
* tellUserToReconnect();
|
|
723
|
+
* }
|
|
724
|
+
* ```
|
|
725
|
+
*/
|
|
726
|
+
declare function requestPermission(permission: RemotePermission): Promise<Result<boolean, HostError>>;
|
|
727
|
+
/**
|
|
728
|
+
* Request a single device permission (camera, microphone, etc.) from the
|
|
729
|
+
* host.
|
|
730
|
+
*
|
|
731
|
+
* Calls `truApi.permissions.requestDevicePermission` and returns the host's
|
|
732
|
+
* boolean granted/denied outcome.
|
|
733
|
+
*
|
|
734
|
+
* @param permission - The device permission to request.
|
|
735
|
+
* @returns `ok(true)` if the host granted the permission, `ok(false)` if denied,
|
|
736
|
+
* or `err(HostUnavailableError | HostCallFailedError)`.
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* ```ts
|
|
740
|
+
* const r = await requestDevicePermission("Camera");
|
|
741
|
+
* if (!r.ok || !r.value) {
|
|
742
|
+
* showCameraDeniedMessage();
|
|
743
|
+
* }
|
|
744
|
+
* ```
|
|
745
|
+
*/
|
|
746
|
+
declare function requestDevicePermission(permission: DevicePermissionKind): Promise<Result<boolean, HostError>>;
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Higher-level wrapper for the host's theme subscription, backed by
|
|
750
|
+
* `truApi.theme.subscribe`.
|
|
751
|
+
*
|
|
752
|
+
* `getThemeProvider` returns a handle whose `subscribeTheme(cb)` delivers a
|
|
753
|
+
* typed {@link ThemeMode} — a `{ name, variant }` struct where `variant` is
|
|
754
|
+
* `"Light" | "Dark"` and `name` is `{ tag: "Default" }` or
|
|
755
|
+
* `{ tag: "Custom", value }` — and yields a {@link HostSubscription}
|
|
756
|
+
* (`unsubscribe` + `onInterrupt`).
|
|
757
|
+
*
|
|
758
|
+
* @module
|
|
759
|
+
*/
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Host theme value. A `{ name, variant }` struct re-exported from
|
|
763
|
+
* `@parity/truapi`.
|
|
764
|
+
*/
|
|
765
|
+
type ThemeMode = HostThemeSubscribeItem;
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Host theme provider handle. `subscribeTheme(callback)` receives a typed
|
|
769
|
+
* {@link ThemeMode} on every change and returns a {@link HostSubscription}.
|
|
770
|
+
*/
|
|
771
|
+
interface ThemeProvider {
|
|
772
|
+
subscribeTheme(callback: (theme: ThemeMode) => void): HostSubscription;
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Get the host theme provider, backed by `truApi.theme.*`. Returns `null` when
|
|
776
|
+
* running outside a host container.
|
|
777
|
+
*
|
|
778
|
+
* @returns The theme provider, or `null` if unavailable.
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* ```ts
|
|
782
|
+
* import { getThemeProvider } from "@parity/product-sdk-host";
|
|
783
|
+
*
|
|
784
|
+
* const provider = await getThemeProvider();
|
|
785
|
+
* if (provider) {
|
|
786
|
+
* const sub = provider.subscribeTheme((theme) => {
|
|
787
|
+
* document.documentElement.dataset.theme = theme.variant.toLowerCase();
|
|
788
|
+
* if (theme.name.tag === "Custom") loadCustomTheme(theme.name.value);
|
|
789
|
+
* });
|
|
790
|
+
* // sub.unsubscribe() to stop listening
|
|
791
|
+
* }
|
|
792
|
+
* ```
|
|
793
|
+
*/
|
|
794
|
+
declare function getThemeProvider(): Promise<ThemeProvider | null>;
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Higher-level wrapper for the host's entropy derivation (RFC-0007).
|
|
798
|
+
*
|
|
799
|
+
* `truApi.entropy.derive` takes a hex `context` and returns a hex `entropy`
|
|
800
|
+
* payload wrapped in a neverthrow `ResultAsync`. `deriveEntropy` keeps the
|
|
801
|
+
* ergonomic `Uint8Array → Result<Uint8Array, HostError>` signature: it
|
|
802
|
+
* hex-encodes the context on the way in and decodes the entropy on the way out.
|
|
803
|
+
*
|
|
804
|
+
* @module
|
|
805
|
+
*/
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Derive deterministic entropy from a context key (RFC-0007).
|
|
809
|
+
*
|
|
810
|
+
* The host derives entropy from the user's wallet + the provided context
|
|
811
|
+
* key. Calling with the same key on the same wallet yields the same bytes;
|
|
812
|
+
* different keys (or different wallets) yield uncorrelated entropy.
|
|
813
|
+
*
|
|
814
|
+
* @param key - Context key bytes (typically a SCALE-encoded discriminator).
|
|
815
|
+
* @returns `ok` with the derived entropy bytes, or
|
|
816
|
+
* `err(HostUnavailableError | HostCallFailedError)`.
|
|
817
|
+
*
|
|
818
|
+
* @example
|
|
819
|
+
* ```ts
|
|
820
|
+
* import { deriveEntropy } from "@parity/product-sdk-host";
|
|
821
|
+
*
|
|
822
|
+
* const r = await deriveEntropy(new TextEncoder().encode("my-app:seed-v1"));
|
|
823
|
+
* if (r.ok) { const seed = r.value; }
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
declare function deriveEntropy(key: Uint8Array): Promise<Result<Uint8Array, HostError>>;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Wrapper for the host's chat surface, backed by `truApi.chat.*`.
|
|
830
|
+
*
|
|
831
|
+
* `getChatManager()` returns a manager for room/bot registration, message
|
|
832
|
+
* sending, and subscription to the room list and incoming actions.
|
|
833
|
+
*
|
|
834
|
+
* @module
|
|
835
|
+
*/
|
|
836
|
+
|
|
837
|
+
/** Action received via {@link ChatManager.subscribeAction} (`{ roomId, peer, payload }`). Re-exported from `@parity/truapi`. */
|
|
838
|
+
type ChatReceivedAction = HostChatActionSubscribeItem;
|
|
839
|
+
/** Result of registering a chat room (`"New" | "Exists"`). Re-exported from `@parity/truapi`. */
|
|
840
|
+
type ChatRoomRegistrationResult = ChatRoomRegistrationStatus;
|
|
841
|
+
/** Result of registering a bot (`"New" | "Exists"`). Re-exported from `@parity/truapi`. */
|
|
842
|
+
type ChatBotRegistrationResult = ChatBotRegistrationStatus;
|
|
843
|
+
/**
|
|
844
|
+
* Chat manager handle. Exposes room/bot registration, message sending, and
|
|
845
|
+
* subscription to the room list and incoming actions.
|
|
846
|
+
*/
|
|
847
|
+
interface ChatManager {
|
|
848
|
+
registerRoom(request: HostChatCreateRoomRequest): Promise<ChatRoomRegistrationResult>;
|
|
849
|
+
registerBot(request: HostChatRegisterBotRequest): Promise<ChatBotRegistrationResult>;
|
|
850
|
+
sendMessage(roomId: string, payload: ChatMessageContent): Promise<{
|
|
851
|
+
messageId: string;
|
|
852
|
+
}>;
|
|
853
|
+
subscribeChatList(callback: (rooms: ChatRoom[]) => void): HostSubscription;
|
|
854
|
+
subscribeAction(callback: (action: ChatReceivedAction) => void): HostSubscription;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Get the host chat manager, backed by `truApi.chat.*`. Returns `null` when
|
|
858
|
+
* running outside a host container.
|
|
859
|
+
*
|
|
860
|
+
* @returns The chat manager, or `null` if unavailable.
|
|
861
|
+
*
|
|
862
|
+
* @example
|
|
863
|
+
* ```ts
|
|
864
|
+
* import { getChatManager } from "@parity/product-sdk-host";
|
|
865
|
+
*
|
|
866
|
+
* const chat = await getChatManager();
|
|
867
|
+
* if (chat) {
|
|
868
|
+
* await chat.registerBot({ botId: "echo", name: "Echo Bot", icon: "" });
|
|
869
|
+
* chat.subscribeAction((action) => { ... });
|
|
870
|
+
* }
|
|
871
|
+
* ```
|
|
872
|
+
*/
|
|
873
|
+
declare function getChatManager(): Promise<ChatManager | null>;
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Wrapper for the host's payment manager (RFC-0006), backed by
|
|
877
|
+
* `truApi.payment.*`.
|
|
878
|
+
*
|
|
879
|
+
* Exposes balance subscription, top-up, payment requests, and payment-status
|
|
880
|
+
* subscription. The flow is distinct from the CoinPayment / merchant-payments
|
|
881
|
+
* surface (RFC-0017) — RFC-0006 is the user-initiated balance / top-up /
|
|
882
|
+
* payment-request flow — but both operate on the same CoinPayment purses,
|
|
883
|
+
* hence the shared `CoinPaymentPurseId` (omitted = the main purse).
|
|
884
|
+
*
|
|
885
|
+
* @module
|
|
886
|
+
*/
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* Payment manager handle. Exposes balance subscription, top-up, payment
|
|
890
|
+
* requests, and payment-status subscription.
|
|
891
|
+
*
|
|
892
|
+
* The balance / status / top-up-source shapes are `@parity/truapi`'s
|
|
893
|
+
* `HostPaymentBalanceSubscribeItem`, `HostPaymentStatusSubscribeItem`, and
|
|
894
|
+
* `PaymentTopUpSource` — used directly rather than re-aliased.
|
|
895
|
+
*/
|
|
896
|
+
interface PaymentManager {
|
|
897
|
+
subscribeBalance(callback: (balance: HostPaymentBalanceSubscribeItem) => void, purse?: CoinPaymentPurseId): HostSubscription;
|
|
898
|
+
topUp(amount: Balance, source: PaymentTopUpSource, into?: CoinPaymentPurseId): Promise<void>;
|
|
899
|
+
requestPayment(amount: Balance, destination: HexString, from?: CoinPaymentPurseId): Promise<{
|
|
900
|
+
id: string;
|
|
901
|
+
}>;
|
|
902
|
+
subscribePaymentStatus(paymentId: string, callback: (status: HostPaymentStatusSubscribeItem) => void): HostSubscription;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Get the host payment manager, backed by `truApi.payment.*`. Returns `null`
|
|
906
|
+
* when running outside a host container.
|
|
907
|
+
*
|
|
908
|
+
* @returns The payment manager, or `null` if unavailable.
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* ```ts
|
|
912
|
+
* import { getPaymentManager } from "@parity/product-sdk-host";
|
|
913
|
+
*
|
|
914
|
+
* const payments = await getPaymentManager();
|
|
915
|
+
* if (payments) {
|
|
916
|
+
* const sub = payments.subscribeBalance((b) => { ... });
|
|
917
|
+
* await payments.topUp(1_000_000n, { tag: "ProductAccount", value: { derivationIndex: { tag: "Index", value: 0 } } });
|
|
918
|
+
* const { id } = await payments.requestPayment(500n, "0x…");
|
|
919
|
+
* sub.unsubscribe();
|
|
920
|
+
* }
|
|
921
|
+
* ```
|
|
922
|
+
*/
|
|
923
|
+
declare function getPaymentManager(): Promise<PaymentManager | null>;
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Wrapper for the host's scheduled push-notification surface (RFC-0019),
|
|
927
|
+
* backed by `truApi.notifications.*`.
|
|
928
|
+
*
|
|
929
|
+
* `getNotificationManager()` returns a handle exposing `push(input)` (resolves
|
|
930
|
+
* to a {@link NotificationId}) and `cancel(id)`, matching the singleton
|
|
931
|
+
* pattern already used by {@link getPaymentManager}, {@link getPreimageManager},
|
|
932
|
+
* and {@link getHostLocalStorage}.
|
|
933
|
+
*
|
|
934
|
+
* @module
|
|
935
|
+
*/
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* Push payload: `text`, an optional `deeplink`, and an optional `scheduledAt`
|
|
939
|
+
* (Unix timestamp in milliseconds; omit for immediate delivery). Re-exported
|
|
940
|
+
* from the truapi wire request type so the shape stays in lockstep with the
|
|
941
|
+
* protocol.
|
|
942
|
+
*/
|
|
943
|
+
type PushNotificationInput = HostPushNotificationRequest;
|
|
944
|
+
/**
|
|
945
|
+
* Host notification manager handle. Exposes `push(input)` (resolves to a
|
|
946
|
+
* {@link NotificationId}) and `cancel(id)`.
|
|
947
|
+
*/
|
|
948
|
+
interface NotificationManager {
|
|
949
|
+
push(input: PushNotificationInput): Promise<NotificationId>;
|
|
950
|
+
cancel(id: NotificationId): Promise<void>;
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Get the host notification manager, backed by `truApi.notifications.*`.
|
|
954
|
+
* Returns `null` when running outside a host container.
|
|
955
|
+
*
|
|
956
|
+
* @returns The notification manager, or `null` if unavailable.
|
|
957
|
+
*
|
|
958
|
+
* @example
|
|
959
|
+
* ```ts
|
|
960
|
+
* import { getNotificationManager, type PushNotificationError } from "@parity/product-sdk-host";
|
|
961
|
+
*
|
|
962
|
+
* const notifications = await getNotificationManager();
|
|
963
|
+
* if (notifications) {
|
|
964
|
+
* try {
|
|
965
|
+
* const id = await notifications.push({
|
|
966
|
+
* text: "Doors open in 1h",
|
|
967
|
+
* scheduledAt: someUnixMs,
|
|
968
|
+
* });
|
|
969
|
+
* // later: await notifications.cancel(id);
|
|
970
|
+
* } catch (err) {
|
|
971
|
+
* const cause = (err as Error).cause as PushNotificationError | undefined;
|
|
972
|
+
* if (cause?.tag === "ScheduleLimitReached") {
|
|
973
|
+
* // host hit its pending-notification cap — surface to the user
|
|
974
|
+
* }
|
|
975
|
+
* }
|
|
976
|
+
* }
|
|
977
|
+
* ```
|
|
978
|
+
*/
|
|
979
|
+
declare function getNotificationManager(): Promise<NotificationManager | null>;
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* Higher-level wrapper for the host's deep-link navigation.
|
|
983
|
+
*
|
|
984
|
+
* `truApi.system.navigateTo` returns a neverthrow `ResultAsync`; consumers
|
|
985
|
+
* still have to unwrap it themselves. {@link navigateTo} collapses that to a
|
|
986
|
+
* `Result<void, HostError>`-returning Promise.
|
|
987
|
+
*
|
|
988
|
+
* @module
|
|
989
|
+
*/
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Ask the host to navigate to a URL (deep link or external link).
|
|
993
|
+
*
|
|
994
|
+
* Calls `truApi.system.navigateTo` and unwraps the response. The host resolves
|
|
995
|
+
* the destination itself — a `dot`-suffixed deep link (e.g.
|
|
996
|
+
* `"https://search.dot"`) routes to another app/route inside the container, an
|
|
997
|
+
* `https://` URL opens externally.
|
|
998
|
+
*
|
|
999
|
+
* @param url - The URL to navigate to.
|
|
1000
|
+
* @returns `ok` on success, or `err`: {@link HostUnavailableError} if the host
|
|
1001
|
+
* is unavailable, or {@link HostCallFailedError} if it denies the navigation
|
|
1002
|
+
* (`NavigateToErr::PermissionDenied`) or fails otherwise (`NavigateToErr::Unknown`).
|
|
1003
|
+
*
|
|
1004
|
+
* @example
|
|
1005
|
+
* ```ts
|
|
1006
|
+
* import { navigateTo } from "@parity/product-sdk-host";
|
|
1007
|
+
*
|
|
1008
|
+
* const r = await navigateTo("https://search.dot");
|
|
1009
|
+
* if (!r.ok) handle(r.error);
|
|
1010
|
+
* ```
|
|
1011
|
+
*/
|
|
1012
|
+
declare function navigateTo(url: string): Promise<Result<void, HostError>>;
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Higher-level wrappers for the host's feature-support probe.
|
|
1016
|
+
*
|
|
1017
|
+
* `truApi.system.featureSupported` returns a neverthrow `ResultAsync`;
|
|
1018
|
+
* {@link featureSupported} collapses that to a `Result` carrying the host's
|
|
1019
|
+
* boolean answer. {@link isChainSupported} is a convenience over the only
|
|
1020
|
+
* feature variant the host exposes today (`Chain`).
|
|
1021
|
+
*
|
|
1022
|
+
* @module
|
|
1023
|
+
*/
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* A feature the host can be probed for via {@link featureSupported}.
|
|
1027
|
+
*
|
|
1028
|
+
* The only variant today is `Chain`, carrying the chain's `0x`-prefixed genesis
|
|
1029
|
+
* hash. This is a flattened form of truapi's `HostFeatureSupportedRequest`,
|
|
1030
|
+
* which nests the hash as `{ tag: "Chain"; value: { genesisHash } }` — we
|
|
1031
|
+
* inline `value` as the `HexString` for ergonomics and re-nest it at the call
|
|
1032
|
+
* site. New variants surface here as a widening of the union.
|
|
1033
|
+
*/
|
|
1034
|
+
type Feature = {
|
|
1035
|
+
tag: "Chain";
|
|
1036
|
+
value: HexString;
|
|
1037
|
+
};
|
|
1038
|
+
/**
|
|
1039
|
+
* Probe the host for support of a specific feature.
|
|
1040
|
+
*
|
|
1041
|
+
* Calls `truApi.system.featureSupported`, unwraps the response, and returns the
|
|
1042
|
+
* host's boolean answer.
|
|
1043
|
+
*
|
|
1044
|
+
* @param feature - The feature to probe for.
|
|
1045
|
+
* @returns `ok(true)` if the host supports the feature, `ok(false)` otherwise,
|
|
1046
|
+
* or `err(HostUnavailableError | HostCallFailedError)`.
|
|
1047
|
+
*
|
|
1048
|
+
* @example
|
|
1049
|
+
* ```ts
|
|
1050
|
+
* import { featureSupported } from "@parity/product-sdk-host";
|
|
1051
|
+
*
|
|
1052
|
+
* const r = await featureSupported({ tag: "Chain", value: genesisHash });
|
|
1053
|
+
* if (r.ok && r.value) { ... }
|
|
1054
|
+
* ```
|
|
1055
|
+
*/
|
|
1056
|
+
declare function featureSupported(feature: Feature): Promise<Result<boolean, HostError>>;
|
|
1057
|
+
/**
|
|
1058
|
+
* Convenience probe: is the chain with the given genesis hash supported by the
|
|
1059
|
+
* host? Wraps {@link featureSupported} for the `Chain` feature variant.
|
|
1060
|
+
*
|
|
1061
|
+
* @param genesisHash - The chain's `0x`-prefixed genesis hash.
|
|
1062
|
+
* @returns `ok(true)` if the host supports the chain, `ok(false)` otherwise, or
|
|
1063
|
+
* `err(HostUnavailableError | HostCallFailedError)`.
|
|
1064
|
+
*
|
|
1065
|
+
* @example
|
|
1066
|
+
* ```ts
|
|
1067
|
+
* import { isChainSupported } from "@parity/product-sdk-host";
|
|
1068
|
+
*
|
|
1069
|
+
* const r = await isChainSupported(genesisHash);
|
|
1070
|
+
* if (!r.ok || !r.value) {
|
|
1071
|
+
* tellUserChainUnavailable();
|
|
1072
|
+
* }
|
|
1073
|
+
* ```
|
|
1074
|
+
*/
|
|
1075
|
+
declare function isChainSupported(genesisHash: HexString): Promise<Result<boolean, HostError>>;
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Higher-level wrapper for the host's chain-spec lookups.
|
|
1079
|
+
*
|
|
1080
|
+
* The host exposes three separate chain-spec calls — `chain.getSpecGenesisHash`,
|
|
1081
|
+
* `chain.getSpecChainName`, and `chain.getSpecProperties` — each reachable via
|
|
1082
|
+
* {@link getTruApi} and each returning a neverthrow `ResultAsync`.
|
|
1083
|
+
* {@link getChainSpec} fetches all three in one call and returns a single
|
|
1084
|
+
* struct so callers read whichever field they need, matching the JSON-RPC
|
|
1085
|
+
* `chainSpec_v1_*` family they mirror.
|
|
1086
|
+
*
|
|
1087
|
+
* @module
|
|
1088
|
+
*/
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Chain SS58/token properties as reported by the host's
|
|
1092
|
+
* `chainSpecProperties` call.
|
|
1093
|
+
*
|
|
1094
|
+
* The host returns this as a JSON string (mirroring the substrate
|
|
1095
|
+
* `chainSpec_v1_properties` JSON-RPC, whose payload is an open-ended object).
|
|
1096
|
+
* {@link getChainSpec} parses it into {@link ChainSpec.properties} and also
|
|
1097
|
+
* surfaces the untouched JSON as {@link ChainSpec.propertiesRaw}. The well-known substrate fields are
|
|
1098
|
+
* typed for convenience; the index signature keeps any chain-specific extras
|
|
1099
|
+
* reachable without `any` at the call site.
|
|
1100
|
+
*/
|
|
1101
|
+
interface ChainProperties {
|
|
1102
|
+
/** Address prefix used for SS58 encoding (e.g. `0` for Polkadot). */
|
|
1103
|
+
ss58Format?: number;
|
|
1104
|
+
/** Decimal places of the chain's native token(s). */
|
|
1105
|
+
tokenDecimals?: number | number[];
|
|
1106
|
+
/** Ticker symbol(s) of the chain's native token(s). */
|
|
1107
|
+
tokenSymbol?: string | string[];
|
|
1108
|
+
/** Chain-specific extras passed through verbatim from the JSON payload. */
|
|
1109
|
+
[key: string]: unknown;
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Combined chain-spec view returned by {@link getChainSpec}.
|
|
1113
|
+
*/
|
|
1114
|
+
interface ChainSpec {
|
|
1115
|
+
/** The chain's `0x`-prefixed genesis hash, as reported by the host. */
|
|
1116
|
+
genesisHash: HexString;
|
|
1117
|
+
/** Human-readable chain name (e.g. `"Polkadot"`). */
|
|
1118
|
+
name: string;
|
|
1119
|
+
/**
|
|
1120
|
+
* Parsed chain properties, or `null` if the host's JSON payload couldn't
|
|
1121
|
+
* be parsed. Inspect {@link propertiesRaw} for the original string.
|
|
1122
|
+
*/
|
|
1123
|
+
properties: ChainProperties | null;
|
|
1124
|
+
/** The untouched JSON string the host returned for properties. */
|
|
1125
|
+
propertiesRaw: string;
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Fetch a chain's full spec (genesis hash, name, and properties) from the host
|
|
1129
|
+
* in one call.
|
|
1130
|
+
*
|
|
1131
|
+
* Issues the three underlying `chain.getSpec*` requests concurrently, unwraps
|
|
1132
|
+
* each response, and parses the properties JSON. Note the `genesisHash` in the
|
|
1133
|
+
* result is the value the host echoes back from `getSpecGenesisHash` for the
|
|
1134
|
+
* looked-up chain — pass the chain's known genesis hash as the lookup key.
|
|
1135
|
+
*
|
|
1136
|
+
* `null` (outside a container) is preserved as an `ok` value — it is an
|
|
1137
|
+
* expected state, not a failure — so callers branch on `r.ok && r.value`. A
|
|
1138
|
+
* real host-call failure surfaces on the `err` channel.
|
|
1139
|
+
*
|
|
1140
|
+
* @param genesisHash - The `0x`-prefixed genesis hash identifying the chain.
|
|
1141
|
+
* @returns `ok(spec)` with the combined {@link ChainSpec}, `ok(null)` if the
|
|
1142
|
+
* host is unavailable (running outside a container), or
|
|
1143
|
+
* `err(HostCallFailedError)` if any underlying host call fails.
|
|
1144
|
+
*
|
|
1145
|
+
* @example
|
|
1146
|
+
* ```ts
|
|
1147
|
+
* import { getChainSpec } from "@parity/product-sdk-host";
|
|
1148
|
+
*
|
|
1149
|
+
* const r = await getChainSpec(genesisHash);
|
|
1150
|
+
* if (r.ok && r.value) {
|
|
1151
|
+
* console.log(r.value.name, r.value.properties?.tokenSymbol);
|
|
1152
|
+
* }
|
|
1153
|
+
* ```
|
|
1154
|
+
*/
|
|
1155
|
+
declare function getChainSpec(genesisHash: HexString): Promise<Result<ChainSpec | null, HostError>>;
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* Higher-level wrappers for the host's transaction broadcast lifecycle.
|
|
1159
|
+
*
|
|
1160
|
+
* `truApi.chain.broadcastTransaction` / `truApi.chain.stopTransaction` are
|
|
1161
|
+
* reachable via {@link getTruApi}, but consumers have to unwrap the neverthrow
|
|
1162
|
+
* `ResultAsync` themselves. {@link broadcastTransaction} and
|
|
1163
|
+
* {@link stopTransaction} collapse that to `Result`-returning Promises, mirroring
|
|
1164
|
+
* the JSON-RPC `transaction_v1_broadcast` / `transaction_v1_stop` pair they
|
|
1165
|
+
* wrap.
|
|
1166
|
+
*
|
|
1167
|
+
* @module
|
|
1168
|
+
*/
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* Broadcast a signed transaction to the network via the host.
|
|
1172
|
+
*
|
|
1173
|
+
* Calls `truApi.chain.broadcastTransaction` and unwraps the response. The host
|
|
1174
|
+
* keeps re-broadcasting until the transaction is finalized/dropped or
|
|
1175
|
+
* {@link stopTransaction} is called with the returned operation id.
|
|
1176
|
+
*
|
|
1177
|
+
* @param genesisHash - The `0x`-prefixed genesis hash of the target chain.
|
|
1178
|
+
* @param transaction - The `0x`-prefixed SCALE-encoded signed transaction.
|
|
1179
|
+
* @returns `ok` with the operation id to pass to {@link stopTransaction} (or
|
|
1180
|
+
* `null` if the host accepted the broadcast without issuing one), or
|
|
1181
|
+
* `err(HostUnavailableError | HostCallFailedError)`.
|
|
1182
|
+
*
|
|
1183
|
+
* @example
|
|
1184
|
+
* ```ts
|
|
1185
|
+
* import { broadcastTransaction, stopTransaction } from "@parity/product-sdk-host";
|
|
1186
|
+
*
|
|
1187
|
+
* const r = await broadcastTransaction(genesisHash, signedTx);
|
|
1188
|
+
* // later, to stop re-broadcasting:
|
|
1189
|
+
* if (r.ok && r.value) await stopTransaction(genesisHash, r.value);
|
|
1190
|
+
* ```
|
|
1191
|
+
*/
|
|
1192
|
+
declare function broadcastTransaction(genesisHash: HexString, transaction: HexString): Promise<Result<string | null, HostError>>;
|
|
1193
|
+
/**
|
|
1194
|
+
* Stop an in-flight broadcast started by {@link broadcastTransaction}.
|
|
1195
|
+
*
|
|
1196
|
+
* Calls `truApi.chain.stopTransaction` and unwraps the response.
|
|
1197
|
+
*
|
|
1198
|
+
* @param genesisHash - The `0x`-prefixed genesis hash of the target chain.
|
|
1199
|
+
* @param operationId - The operation id returned by
|
|
1200
|
+
* {@link broadcastTransaction}.
|
|
1201
|
+
* @returns `ok` on success, or `err(HostUnavailableError | HostCallFailedError)`.
|
|
1202
|
+
*
|
|
1203
|
+
* @example
|
|
1204
|
+
* ```ts
|
|
1205
|
+
* await stopTransaction(genesisHash, operationId);
|
|
1206
|
+
* ```
|
|
1207
|
+
*/
|
|
1208
|
+
declare function stopTransaction(genesisHash: HexString, operationId: string): Promise<Result<void, HostError>>;
|
|
1209
|
+
|
|
1210
|
+
export { type AccountsProvider, BULLETIN_RPCS, ChainNotSupportedError, type ChainProperties, type ChainSpec, type ChatBotRegistrationResult, type ChatManager, type ChatReceivedAction, type ChatRoomRegistrationResult, type ContextualAlias, DEFAULT_BULLETIN_ENDPOINT, type DevicePermissionKind, type Feature, type HostAccount, HostCallFailedError, HostError, type HostErrorPayload, type HostLocalStorage, type HostStatementStore, type HostSubscription, HostUnavailableError, type NotificationManager, type PaymentManager, type PreimageManager, type ProductAccount, type ProductAccountLookup, type PushNotificationInput, type RegisteredRingVrfKey, type RemotePermissionItem, type ResultAsync, type RingVRFProof, type RingVrfKeyHandle, type RingVrfPublicKey, type StatementTopicFilter, type StatementsPage, type ThemeMode, type ThemeProvider, type TruApi, type VrfSignature, type VrfTranscriptItem, WorkerCallError, type WorkerErrorTag, type WorkerManager, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, findRingVrfKeyHandle, formatHostError, fromHex, getAccountsProvider, getChainSpec, getChatManager, getHostLocalStorage, getHostProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, getWorkerManager, isChainSupported, isHostError, isInsideContainer, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction, toHex };
|