@useragent-kit/wasm 0.0.1

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.
@@ -0,0 +1,838 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * JS-facing chain state machine.
6
+ *
7
+ * Does NOT manage the smoldot client itself — that lives in TypeScript via
8
+ * the `smoldot` NPM package. This handle provides:
9
+ * - Chain status tracking (processes JSON-RPC responses from smoldot-js)
10
+ * - Request generation (subscriptions, health checks, DB saves)
11
+ * - Chain database persistence (localStorage by default, or a custom JS store)
12
+ * - Chain spec access (for TypeScript to pass to smoldot's `addChain`)
13
+ *
14
+ * Only Substrate/Polkadot chains (smoldot backend) are supported on WASM.
15
+ */
16
+ export class ChainClientHandle {
17
+ free(): void;
18
+ [Symbol.dispose](): void;
19
+ /**
20
+ * Get all chain statuses.
21
+ */
22
+ allStatuses(): any;
23
+ /**
24
+ * Get chain specs for a smoldot chain. Returns [relaySpec, paraSpec] or null.
25
+ */
26
+ chainSpecs(chain_name: string): any;
27
+ /**
28
+ * Create a handle backed by a custom JS store (e.g. IndexedDB).
29
+ *
30
+ * The `store` object must implement `load(key: string): string | null | undefined` and
31
+ * `save(key: string, data: string): void`.
32
+ */
33
+ static fromStore(store: any): ChainClientHandle;
34
+ /**
35
+ * JSON-RPC health check request (incrementing ID per chain).
36
+ */
37
+ healthCheckRequest(chain_name: string): string;
38
+ /**
39
+ * Load persisted parachain DB from localStorage.
40
+ */
41
+ loadParaDb(chain_name: string): string;
42
+ /**
43
+ * Load persisted relay chain DB from localStorage.
44
+ */
45
+ loadRelayDb(chain_name: string): string;
46
+ constructor();
47
+ /**
48
+ * JSON-RPC request to save parachain DB (send to parachain).
49
+ */
50
+ paraDbSaveRequest(): string;
51
+ /**
52
+ * Parse a statement subscription notification. Returns Array<string> of hex statements.
53
+ * Returns an empty array if the text is not a statement notification.
54
+ */
55
+ parseStatementNotification(text: string): Array<any>;
56
+ /**
57
+ * Process a JSON-RPC response from the relay chain (for DB save only).
58
+ */
59
+ processRelayResponse(chain_name: string, text: string): void;
60
+ /**
61
+ * Process a JSON-RPC response from smoldot for a parachain.
62
+ * Call this for every response from `chain.nextJsonRpcResponse()`.
63
+ */
64
+ processResponse(chain_name: string, text: string): void;
65
+ /**
66
+ * Register a chain for status tracking. Call after adding the chain to smoldot.
67
+ */
68
+ registerChain(chain_name: string): void;
69
+ /**
70
+ * JSON-RPC request to save relay chain DB (send to relay chain).
71
+ */
72
+ relayDbSaveRequest(): string;
73
+ /**
74
+ * Report an error for a chain (e.g. smoldot addChain failure).
75
+ */
76
+ setError(chain_name: string, msg: string): void;
77
+ /**
78
+ * JSON-RPC request to fetch broadcast statements by topic.
79
+ */
80
+ statementBroadcastsRequest(topic_hexes: Array<any>, request_id: number): string;
81
+ /**
82
+ * JSON-RPC request to remove a statement by statement id/hash.
83
+ */
84
+ statementRemoveRequest(statement_id_hex: string, request_id: number): string;
85
+ /**
86
+ * JSON-RPC request to submit a statement (hex-encoded).
87
+ */
88
+ statementSubmitRequest(encoded_hex: string, request_id: number): string;
89
+ /**
90
+ * JSON-RPC request to subscribe to statement notifications.
91
+ */
92
+ statementSubscribeRequest(request_id: number): string;
93
+ /**
94
+ * JSON-RPC request to unsubscribe from statement notifications.
95
+ */
96
+ statementUnsubscribeRequest(sub_id: string, request_id: number): string;
97
+ /**
98
+ * Get the current status of a chain.
99
+ */
100
+ status(chain_name: string): any;
101
+ /**
102
+ * JSON-RPC request to subscribe to finalized heads.
103
+ */
104
+ subscribeFinalizedHeadsRequest(): string;
105
+ /**
106
+ * JSON-RPC request to subscribe to new heads.
107
+ */
108
+ subscribeNewHeadsRequest(): string;
109
+ /**
110
+ * Unregister a chain. Call after removing the chain from smoldot.
111
+ */
112
+ unregisterChain(chain_name: string): void;
113
+ }
114
+
115
+ /**
116
+ * JS-facing chat crypto handle for hosts that already own an attested
117
+ * sr25519 session account.
118
+ *
119
+ * This is intentionally narrower than `WalletHandle`: callers provide the
120
+ * account id and sr25519 session secret explicitly, and the handle only owns
121
+ * the P-256 material needed for chat request/session encryption. Statement
122
+ * signing stays with the embedding host via a callback in the TypeScript SDK.
123
+ */
124
+ export class ChatSessionHandle {
125
+ free(): void;
126
+ [Symbol.dispose](): void;
127
+ /**
128
+ * Decrypt data produced by `chatP256Encrypt`.
129
+ */
130
+ chatP256Decrypt(peer_identifier_key: Uint8Array, ciphertext: Uint8Array): Uint8Array;
131
+ /**
132
+ * Encrypt with the v2 P-256/AES-GCM stack.
133
+ */
134
+ chatP256Encrypt(peer_identifier_key: Uint8Array, plaintext: Uint8Array): Uint8Array;
135
+ /**
136
+ * Build v2-compatible directional P-256 session ids and channels.
137
+ */
138
+ chatP256Session(peer_account_id: Uint8Array, peer_identifier_key: Uint8Array, own_pin?: string | null, peer_pin?: string | null): any;
139
+ /**
140
+ * Canonical 65-byte uncompressed P-256 identifier key for this chat identity.
141
+ */
142
+ identifierKey(): Uint8Array;
143
+ /**
144
+ * Build chat P-256 material from an existing sr25519 session account.
145
+ *
146
+ * `account_id` must be the 32-byte public key registered on People chain.
147
+ * `session_secret` must contain at least the 32-byte scalar half used by
148
+ * sr25519 signing implementations such as host-papp.
149
+ */
150
+ constructor(account_id: Uint8Array, session_secret: Uint8Array);
151
+ /**
152
+ * 32-byte sr25519 public key for this chat identity.
153
+ */
154
+ walletPublicKey(): Uint8Array;
155
+ }
156
+
157
+ /**
158
+ * JS-facing DOTNS encoding utilities.
159
+ *
160
+ * All functions are pure — no I/O or network. The browser is responsible
161
+ * for transport (e.g. polkadot-api / smoldot-js).
162
+ */
163
+ export class DotnsHandle {
164
+ free(): void;
165
+ [Symbol.dispose](): void;
166
+ /**
167
+ * Parse a contenthash into a CIDv1 base32 string.
168
+ */
169
+ contenthashToCid(contenthash: Uint8Array): string;
170
+ /**
171
+ * Decode ABI-encoded `bytes` from Solidity return data.
172
+ */
173
+ decodeAbiBytes(data: Uint8Array): Uint8Array;
174
+ /**
175
+ * Decode the ContractResult from a `ReviveApi_call` response.
176
+ */
177
+ decodeContractResult(response: Uint8Array): Uint8Array;
178
+ /**
179
+ * ABI-encode `contenthash(bytes32)` call data for the given namehash.
180
+ */
181
+ encodeContenthashCall(node: Uint8Array): Uint8Array;
182
+ /**
183
+ * Hex-decode a `0x`-prefixed (or bare) hex string.
184
+ */
185
+ hexDecode(s: string): Uint8Array;
186
+ /**
187
+ * Hex-encode bytes with `0x` prefix.
188
+ */
189
+ hexEncode(bytes: Uint8Array): string;
190
+ /**
191
+ * Compute ENS-style namehash for a `.dot` domain.
192
+ */
193
+ namehash(name: string): Uint8Array;
194
+ constructor();
195
+ /**
196
+ * Parse a CARv1 `.prod` bundle into an asset map.
197
+ *
198
+ * Returns a plain JS object where each key is a filename and each value is a `Uint8Array`.
199
+ */
200
+ parseCarAssets(data: Uint8Array): any;
201
+ /**
202
+ * Resolve a `.dot` name, fetch from IPFS, and return an asset map as a JS object.
203
+ *
204
+ * The returned value is a plain JS object where each key is a filename (string)
205
+ * and each value is a `Uint8Array`. Automatically converts to a `Promise` for JS callers.
206
+ */
207
+ resolveAndFetch(name: string): Promise<any>;
208
+ /**
209
+ * SCALE-encode `ReviveApi::call()` parameters.
210
+ */
211
+ scaleEncodeReviveCall(contract_addr: Uint8Array, call_data: Uint8Array): Uint8Array;
212
+ }
213
+
214
+ /**
215
+ * JS-facing wrapper over `useragent_api::HostApi`.
216
+ *
217
+ * Processes binary SCALE-encoded messages from Polkadot apps and returns
218
+ * structured outcomes that the TypeScript adapter routes to the appropriate
219
+ * subsystem (smoldot JS, wallet, navigation).
220
+ */
221
+ export class HostApiHandle {
222
+ free(): void;
223
+ [Symbol.dispose](): void;
224
+ /**
225
+ * Get the HOST_API_BRIDGE_SCRIPT for WebView injection.
226
+ */
227
+ static bridgeScript(): string;
228
+ encodeAccountCreateProofError(request_id: string, error_kind: string, reason?: string | null): Uint8Array;
229
+ encodeAccountCreateProofResponse(request_id: string, proof: Uint8Array): Uint8Array;
230
+ encodeAccountGetAliasError(request_id: string, error_kind: string, reason?: string | null): Uint8Array;
231
+ encodeAccountGetAliasResponse(request_id: string, context: Uint8Array, alias: Uint8Array): Uint8Array;
232
+ encodeAccountGetError(request_id: string, error_kind: string, reason?: string | null): Uint8Array;
233
+ /**
234
+ * Encode a `host_account_get` success response (v0.7.4).
235
+ *
236
+ * Wire shape: `Result::Ok(ProductAccount { publicKey })` — `name` was
237
+ * removed in v0.7.4; SPAs use `host_get_user_id` for display names.
238
+ */
239
+ encodeAccountGetResponse(request_id: string, public_key: Uint8Array): Uint8Array;
240
+ /**
241
+ * Encode a chain-head follow event notification.
242
+ */
243
+ encodeChainFollowEvent(request_id: string, json_rpc_msg: string): Uint8Array;
244
+ /**
245
+ * Encode a synthetic follow stop event for unsupported/disconnected chains.
246
+ */
247
+ encodeChainFollowStop(request_id: string): Uint8Array;
248
+ /**
249
+ * Encode a one-shot JSON-RPC error for `NeedsChainQuery`.
250
+ */
251
+ encodeChainQueryError(request_id: string): Uint8Array;
252
+ /**
253
+ * Encode a one-shot JSON-RPC response for `NeedsChainQuery`.
254
+ */
255
+ encodeChainQueryResponse(request_id: string, json_rpc_result: string): Uint8Array;
256
+ /**
257
+ * Encode a chain RPC error using the correct chain protocol envelope.
258
+ */
259
+ encodeChainRpcError(request_id: string, request_tag: number, reason: string): Uint8Array;
260
+ /**
261
+ * Encode a chain RPC response using the correct chain protocol envelope.
262
+ */
263
+ encodeChainRpcResponse(request_id: string, request_tag: number, json_rpc_msg: string): Uint8Array;
264
+ /**
265
+ * Encode a streaming JSON-RPC subscription message for `NeedsChainSubscription`.
266
+ */
267
+ encodeChainSubNotification(request_id: string, json_rpc_msg: string): Uint8Array;
268
+ /**
269
+ * Encode a `host_create_transaction` error response.
270
+ *
271
+ * `error_kind`: one of `"rejected"`, `"not_supported"`, `"permission_denied"`,
272
+ * `"failed_to_decode"`, or `"unknown"` (default).
273
+ */
274
+ encodeCreateTransactionError(request_id: string, error_kind: string, reason?: string | null): Uint8Array;
275
+ /**
276
+ * Encode a successful `host_create_transaction` response.
277
+ */
278
+ encodeCreateTransactionResponse(request_id: string, signed_tx_bytes: Uint8Array): Uint8Array;
279
+ /**
280
+ * Encode a `host_create_transaction_with_legacy_account` error response.
281
+ */
282
+ encodeCreateTxNonProductError(request_id: string, error_kind: string, reason?: string | null): Uint8Array;
283
+ /**
284
+ * Encode a successful `host_create_transaction_with_legacy_account` response.
285
+ */
286
+ encodeCreateTxNonProductResponse(request_id: string, signed_tx_bytes: Uint8Array): Uint8Array;
287
+ /**
288
+ * Encode a `host_device_permission` error response.
289
+ */
290
+ encodeDevicePermissionError(request_id: string): Uint8Array;
291
+ /**
292
+ * Encode a `host_device_permission` response.
293
+ */
294
+ encodeDevicePermissionResponse(request_id: string, granted: boolean): Uint8Array;
295
+ /**
296
+ * Encode a navigation acknowledgement.
297
+ */
298
+ encodeNavigateResponse(request_id: string): Uint8Array;
299
+ /**
300
+ * Encode a payment balance snapshot for `NeedsPaymentBalanceSubscription`.
301
+ *
302
+ * `balance` must be a JS object with shape:
303
+ * `{ available: { currency: string, minor_units: string }, pending: { currency: string, minor_units: string } }`.
304
+ */
305
+ encodePaymentBalance(request_id: string, balance: any): Uint8Array;
306
+ /**
307
+ * Encode a failed payment request response for `NeedsPaymentRequest`.
308
+ */
309
+ encodePaymentRequestError(request_id: string, reason: string): Uint8Array;
310
+ /**
311
+ * Encode a successful payment request response for `NeedsPaymentRequest`.
312
+ *
313
+ * `receipt_id` is the ID of the payment receipt returned by the host.
314
+ */
315
+ encodePaymentRequestResponse(request_id: string, receipt_id: string): Uint8Array;
316
+ /**
317
+ * Encode a payment status update for `NeedsPaymentStatusSubscription`.
318
+ *
319
+ * `status` must be a JS object with shape:
320
+ * `{ type: "Processing" | "Completed" | "Failed", reason?: string }`.
321
+ */
322
+ encodePaymentStatus(request_id: string, status: any): Uint8Array;
323
+ /**
324
+ * Encode a failed payment top-up response for `NeedsPaymentTopUp`.
325
+ */
326
+ encodePaymentTopUpError(request_id: string, reason: string): Uint8Array;
327
+ /**
328
+ * Encode a successful payment top-up acknowledgement for `NeedsPaymentTopUp`.
329
+ */
330
+ encodePaymentTopUpResponse(request_id: string): Uint8Array;
331
+ /**
332
+ * Encode a push notification acknowledgement.
333
+ */
334
+ encodePushNotificationResponse(request_id: string): Uint8Array;
335
+ /**
336
+ * Encode a `remote_permission` error response.
337
+ */
338
+ encodeRemotePermissionError(request_id: string): Uint8Array;
339
+ /**
340
+ * Encode a `remote_permission` response.
341
+ */
342
+ encodeRemotePermissionResponse(request_id: string, granted: boolean): Uint8Array;
343
+ /**
344
+ * Encode a sign_payload or sign_raw error response.
345
+ */
346
+ encodeSignError(request_id: string, request_tag: number): Uint8Array;
347
+ /**
348
+ * Encode a sign_payload or sign_raw success response.
349
+ */
350
+ encodeSignResponse(request_id: string, request_tag: number, signature: Uint8Array): Uint8Array;
351
+ /**
352
+ * Encode a storage clear acknowledgement for `NeedsStorageClear`.
353
+ */
354
+ encodeStorageClearResponse(request_id: string): Uint8Array;
355
+ /**
356
+ * Encode a storage read response for `NeedsStorageRead`.
357
+ *
358
+ * Pass `None` if the key was not found; `Some(bytes)` with the stored value otherwise.
359
+ */
360
+ encodeStorageReadResponse(request_id: string, value?: Uint8Array | null): Uint8Array;
361
+ /**
362
+ * Encode a storage write acknowledgement for `NeedsStorageWrite`.
363
+ */
364
+ encodeStorageWriteResponse(request_id: string): Uint8Array;
365
+ /**
366
+ * Process a binary SCALE message from the app.
367
+ *
368
+ * Returns a JS object describing the outcome. The `type` field indicates
369
+ * the variant:
370
+ *
371
+ * - `"Response"` — send `data` (byte array) back to the app
372
+ * - `"NeedsSign"` — route to wallet for signing
373
+ * - `"NeedsChainQuery"` — route to smoldot/polkadot-api
374
+ * - `"NeedsChainSubscription"` — start a streaming subscription
375
+ * - `"NeedsNavigate"` — open a URL
376
+ * - `"NeedsPushNotification"` — display a push notification/toast
377
+ * - `"NeedsChainFollow"` — start chainHead follow
378
+ * - `"NeedsChainRpc"` — route to chain RPC
379
+ * - `"Silent"` — no response needed
380
+ */
381
+ handleMessage(raw: Uint8Array, app_id: string): any;
382
+ /**
383
+ * Create a new host API engine.
384
+ */
385
+ constructor();
386
+ /**
387
+ * Set accounts for host-api compatibility.
388
+ *
389
+ * `host_get_legacy_accounts` currently returns an empty list to avoid
390
+ * exposing a stable cross-product identifier. This setter is retained so
391
+ * existing hosts do not fail during initialization.
392
+ *
393
+ * Accepts a JSON array of `LegacyAccount` records:
394
+ * `[{"public_key": [1,2,...], "name": "Alice"}, ...]`
395
+ */
396
+ setAccounts(accounts_json: string): void;
397
+ /**
398
+ * Set the set of supported chain genesis hashes for feature detection.
399
+ *
400
+ * Expects a JS array of `Uint8Array` values, each exactly 32 bytes.
401
+ */
402
+ setSupportedChains(chains: Array<any>): void;
403
+ }
404
+
405
+ /**
406
+ * JS-facing Resources pallet encoding utilities for People chains.
407
+ *
408
+ * All functions are pure — no I/O or network. The browser is responsible
409
+ * for the actual `state_getStorage` RPC call using the smoldot driver it
410
+ * already manages.
411
+ */
412
+ export class IdentityHandle {
413
+ free(): void;
414
+ [Symbol.dispose](): void;
415
+ /**
416
+ * Build the `state_getStorage` key hex for `Resources.Consumers`.
417
+ *
418
+ * `account_id_hex` must be a `0x`-prefixed or bare 64-character hex
419
+ * string representing a 32-byte `AccountId32`.
420
+ *
421
+ * Returns the key as a `0x`-prefixed hex string, or throws on invalid
422
+ * input.
423
+ */
424
+ consumersKey(account_id_hex: string): string;
425
+ /**
426
+ * Decode a `Resources.UsernameOwnerOf` storage response.
427
+ *
428
+ * `PaseoPeopleNext` stores a bare `AccountId32` here, so the browser path
429
+ * must decode the raw owner bytes rather than `Identity::UsernameInfoOf`.
430
+ */
431
+ decodeAccountOfUsername(data: Uint8Array): any;
432
+ /**
433
+ * Decode a SCALE-encoded `ConsumerInfo` from `Resources.Consumers`.
434
+ *
435
+ * `data` is the raw bytes from the `state_getStorage` response (after
436
+ * hex-decoding the `"result"` field).
437
+ *
438
+ * Returns a JS object `{ identifierKey: Uint8Array, fullUsername: string |
439
+ * null, liteUsername: string, credibility: object }`, or `null` if data is
440
+ * empty (storage slot absent). Throws on malformed SCALE data.
441
+ *
442
+ * `credibility` is one of:
443
+ * - `{ type: "Lite" }`
444
+ * - `{ type: "Person", alias: Uint8Array, lastUpdate: number }`
445
+ */
446
+ decodeConsumerInfo(data: Uint8Array): any;
447
+ /**
448
+ * Construct a full PeopleLite username from base and suffix.
449
+ */
450
+ makeLiteFullUsername(base: string, suffix: string): string;
451
+ constructor();
452
+ /**
453
+ * Normalize a PeopleLite username base for signup.
454
+ *
455
+ * Validates: lowercase letters only, 6-27 characters.
456
+ */
457
+ normalizeLiteUsernameBase(base: string): string;
458
+ /**
459
+ * Normalize a username: ASCII lowercase, validate charset (`[a-z0-9.]`)
460
+ * and maximum length (32 bytes).
461
+ *
462
+ * Returns the normalized UTF-8 bytes, or throws if the username is
463
+ * invalid.
464
+ */
465
+ normalizeUsername(username: string): Uint8Array;
466
+ /**
467
+ * Build the `state_getStorage` key hex for `Resources.UsernameOwnerOf`.
468
+ *
469
+ * Browser hosts use this for PeopleLite username lookup on
470
+ * `PaseoPeopleNext`, where username ownership lives under the `Resources`
471
+ * pallet instead of `Identity::UsernameInfoOf`.
472
+ */
473
+ usernameOwnerOfKey(username: string): string;
474
+ /**
475
+ * Validate a PeopleLite numeric suffix.
476
+ */
477
+ validateLiteUsernameSuffix(suffix: string): void;
478
+ }
479
+
480
+ /**
481
+ * JS-facing handle for QR code URI encoding and parsing.
482
+ *
483
+ * Pure functions — no I/O, no state. Handles the `substrate:` URI format
484
+ * used in QR codes for Substrate address transfer.
485
+ */
486
+ export class QrHandle {
487
+ free(): void;
488
+ [Symbol.dispose](): void;
489
+ /**
490
+ * Decode an SS58 address, returning the 32-byte public key.
491
+ *
492
+ * Validates the base58 encoding and blake2b checksum.
493
+ */
494
+ decodeSs58Address(address: string): Uint8Array;
495
+ /**
496
+ * Encode a Substrate address into a QR-friendly URI string.
497
+ *
498
+ * Format: `substrate:{address}[?genesis_hash={hex}&amount={planck}]`
499
+ *
500
+ * `genesis_hash` must be exactly 32 bytes (Uint8Array) if provided.
501
+ * `amount` is a decimal string (supports u128 range).
502
+ */
503
+ encodeSubstrateUri(address: string, genesis_hash?: Uint8Array | null, amount?: string | null): string;
504
+ constructor();
505
+ /**
506
+ * Parse a QR code string into structured content.
507
+ *
508
+ * Returns a JS object with:
509
+ * - `contentType`: `"substrate_transfer"`, `"raw_address"`, `"deep_link"`, or `"unknown"`
510
+ * - `address`: SS58 address (for `substrate_transfer` and `raw_address`)
511
+ * - `genesisHash`: Uint8Array (for `substrate_transfer`, if present)
512
+ * - `amount`: decimal string (for `substrate_transfer`, if present)
513
+ * - `rawContent`: string (for `deep_link` and `unknown`)
514
+ */
515
+ parseSubstrateUri(data: string): any;
516
+ }
517
+
518
+ /**
519
+ * JS-facing statement store encoding utilities.
520
+ *
521
+ * All functions are pure — no I/O. The browser is responsible for transport.
522
+ */
523
+ export class StatementHandle {
524
+ free(): void;
525
+ [Symbol.dispose](): void;
526
+ /**
527
+ * Assemble a complete encoded statement from a signing payload and signature.
528
+ *
529
+ * `signing_payload_with_header` must be the exact bytes from `buildSigningPayload`.
530
+ */
531
+ assembleStatement(signing_payload_with_header: Uint8Array, sr25519_pubkey: Uint8Array, sr25519_signature: Uint8Array): Uint8Array;
532
+ /**
533
+ * Compute a blake2b-256 hash of arbitrary bytes.
534
+ */
535
+ blake2b256(data: Uint8Array): Uint8Array;
536
+ /**
537
+ * Build the signing payload for a statement.
538
+ *
539
+ * Returns the raw bytes that must be signed. Use `WalletHandle.sign()` to
540
+ * sign the payload, then pass the result to `assembleStatement()`.
541
+ */
542
+ buildSigningPayload(now_secs: number, decryption_key: Uint8Array | null | undefined, channel: Uint8Array | null | undefined, priority: number, topics_flat: Uint8Array, data: Uint8Array): Uint8Array;
543
+ /**
544
+ * Build the signing payload for a specific statement-store dialect.
545
+ */
546
+ buildSigningPayloadWithDialect(dialect_name: string, now_secs: number, decryption_key: Uint8Array | null | undefined, channel: Uint8Array | null | undefined, priority: number, topics_flat: Uint8Array, data: Uint8Array): Uint8Array;
547
+ /**
548
+ * Decode a statement from binary encoding.
549
+ * Returns a JSON string with the decoded fields.
550
+ */
551
+ decodeStatement(encoded: Uint8Array): any;
552
+ /**
553
+ * Decode a statement using a specific statement-store dialect.
554
+ */
555
+ decodeStatementWithDialect(dialect_name: string, encoded: Uint8Array): any;
556
+ /**
557
+ * Encode a statement into the sp-statement-store binary format.
558
+ *
559
+ * Convenience method that combines `buildSigningPayload` + `assembleStatement`
560
+ * for callers who already have a pre-computed signature.
561
+ *
562
+ * `now_secs` is the current Unix timestamp in seconds (use `Date.now() / 1000 | 0`).
563
+ * `topics_flat` is a flat `Uint8Array` of concatenated 32-byte topics.
564
+ */
565
+ encodeStatement(now_secs: number, decryption_key: Uint8Array | null | undefined, channel: Uint8Array | null | undefined, priority: number, topics_flat: Uint8Array, data: Uint8Array, sr25519_pubkey: Uint8Array, sr25519_signature: Uint8Array): Uint8Array;
566
+ /**
567
+ * Encode a statement using a specific statement-store dialect.
568
+ */
569
+ encodeStatementWithDialect(dialect_name: string, now_secs: number, decryption_key: Uint8Array | null | undefined, channel: Uint8Array | null | undefined, priority: number, topics_flat: Uint8Array, data: Uint8Array, sr25519_pubkey: Uint8Array, sr25519_signature: Uint8Array): Uint8Array;
570
+ /**
571
+ * Hex-decode a `0x`-prefixed (or bare) hex string.
572
+ */
573
+ hexDecode(s: string): Uint8Array;
574
+ /**
575
+ * Hex-encode bytes with `0x` prefix.
576
+ */
577
+ hexEncode(bytes: Uint8Array): string;
578
+ constructor();
579
+ /**
580
+ * Hash a string into a 32-byte Topic (blake2b-256).
581
+ */
582
+ stringToTopic(s: string): Uint8Array;
583
+ }
584
+
585
+ /**
586
+ * JS-facing handle for the statement store subscription system.
587
+ *
588
+ * The JS host calls `pushStatement()` for each raw statement received
589
+ * from the SmoldotDriver. The Rust side decodes, deduplicates, and
590
+ * dispatches to registered handlers.
591
+ *
592
+ * # Example (TypeScript)
593
+ * ```typescript
594
+ * const store = new StatementStoreHandle();
595
+ * store.addTopic("0xabc..."); // 32-byte topic hex
596
+ * // In your smoldot notification handler:
597
+ * store.pushStatement(rawBytes);
598
+ * // When done:
599
+ * store.stop();
600
+ * ```
601
+ */
602
+ export class StatementStoreHandle {
603
+ free(): void;
604
+ [Symbol.dispose](): void;
605
+ /**
606
+ * Add a topic to the subscription filter (hex-encoded 32 bytes).
607
+ *
608
+ * Accepts both `0x`-prefixed and bare hex strings.
609
+ */
610
+ addTopic(topic_hex: string): void;
611
+ /**
612
+ * Whether the subscription is accepting statement deliveries.
613
+ */
614
+ isRunning(): boolean;
615
+ /**
616
+ * Create a new statement store handle and start push-based delivery.
617
+ */
618
+ constructor();
619
+ /**
620
+ * Push a raw statement from the JS transport layer.
621
+ *
622
+ * The statement is decoded, deduplicated, and dispatched to registered
623
+ * handlers. Malformed bytes are logged and silently dropped.
624
+ */
625
+ pushStatement(raw: Uint8Array): void;
626
+ /**
627
+ * Remove a topic from the subscription filter.
628
+ *
629
+ * Accepts both `0x`-prefixed and bare hex strings.
630
+ */
631
+ removeTopic(topic_hex: string): void;
632
+ /**
633
+ * Stop the subscription and prevent further delivery. Idempotent.
634
+ */
635
+ stop(): void;
636
+ }
637
+
638
+ /**
639
+ * JS-facing wrapper over `useragent_wallet::WalletManager`.
640
+ *
641
+ * Manages sr25519/secp256k1 key material in WASM memory. The platform
642
+ * keystore is not available — use `load_mnemonic()` to supply the phrase
643
+ * and `lock()` to clear keys from memory.
644
+ */
645
+ export class WalletHandle {
646
+ free(): void;
647
+ [Symbol.dispose](): void;
648
+ /**
649
+ * SS58 address for a derived app account (Polkadot prefix 0).
650
+ */
651
+ appAddress(app_id: string, index: number): string;
652
+ /**
653
+ * 32-byte sr25519 public key for a derived app account.
654
+ */
655
+ appPublicKey(app_id: string, index: number): Uint8Array;
656
+ /**
657
+ * P2WPKH (bech32) Bitcoin mainnet address.
658
+ */
659
+ btcAddress(): string;
660
+ /**
661
+ * BIP-137 message signing with BTC key. Returns Base64 string.
662
+ */
663
+ btcSignMessage(msg: Uint8Array): string;
664
+ /**
665
+ * Sign a raw 32-byte digest with BTC key. Returns DER-encoded signature.
666
+ */
667
+ btcSignRaw(digest: Uint8Array): Uint8Array;
668
+ /**
669
+ * Decrypt data produced by `chatP256Encrypt`.
670
+ */
671
+ chatP256Decrypt(peer_identifier_key: Uint8Array, ciphertext: Uint8Array): Uint8Array;
672
+ /**
673
+ * Encrypt with the v2 P-256/AES-GCM stack.
674
+ *
675
+ * Output is `nonce(12) || ciphertext || tag(16)`, matching CryptoKit's
676
+ * combined AES-GCM sealed box representation.
677
+ */
678
+ chatP256Encrypt(peer_identifier_key: Uint8Array, plaintext: Uint8Array): Uint8Array;
679
+ /**
680
+ * Build v2-compatible directional P-256 session ids and channels.
681
+ *
682
+ * Returns a JS object with the same fields as native
683
+ * `MobileChatP256Session`, using `Uint8Array` for byte fields.
684
+ */
685
+ chatP256Session(peer_account_id: Uint8Array, peer_identifier_key: Uint8Array, own_pin?: string | null, peer_pin?: string | null): any;
686
+ /**
687
+ * Decode and verify a first-contact chat request using the canonical host-sdk wire format.
688
+ */
689
+ decodeChatRequest(data: Uint8Array): any;
690
+ /**
691
+ * 32-byte Ed25519 public key at `//ed25519//<app_id>//<index>`.
692
+ */
693
+ ed25519PublicKey(app_id: string, index: number): Uint8Array;
694
+ /**
695
+ * Encode a chat-accept request using the canonical host-sdk wire format.
696
+ */
697
+ encodeChatAccept(request_id: string, text: string, timestamp: number, recipient_identifier_key?: Uint8Array | null): Uint8Array;
698
+ /**
699
+ * Encode a first-contact chat request using the canonical host-sdk wire format.
700
+ */
701
+ encodeChatRequest(text: string, timestamp: number, recipient_identifier_key?: Uint8Array | null): Uint8Array;
702
+ /**
703
+ * EIP-55 checksummed Ethereum address.
704
+ */
705
+ ethAddress(): string;
706
+ /**
707
+ * EIP-191 personal_sign with ETH key. Returns 65-byte signature (r+s+v).
708
+ */
709
+ ethSignPersonal(data: Uint8Array): Uint8Array;
710
+ /**
711
+ * Canonical 65-byte uncompressed P-256 identifier key at `//wallet//chat`.
712
+ */
713
+ identifierKey(): Uint8Array;
714
+ /**
715
+ * Load key material from a BIP-39 mnemonic phrase.
716
+ *
717
+ * The wallet is unlocked immediately. The mnemonic is NOT persisted —
718
+ * the browser host must store it externally (e.g. encrypted localStorage).
719
+ */
720
+ loadMnemonic(phrase: string): void;
721
+ /**
722
+ * Lock the wallet — clear all in-memory key material.
723
+ */
724
+ lock(): void;
725
+ /**
726
+ * Create a new (locked, empty) wallet handle.
727
+ */
728
+ constructor();
729
+ /**
730
+ * Root SS58 address (Polkadot format, prefix 0).
731
+ */
732
+ rootAddress(): string;
733
+ /**
734
+ * Root 32-byte sr25519 public key.
735
+ */
736
+ rootPublicKey(): Uint8Array | undefined;
737
+ /**
738
+ * Sign with app-scoped sr25519 keypair. Returns 64-byte signature.
739
+ */
740
+ sign(app_id: string, index: number, payload: Uint8Array): Uint8Array;
741
+ /**
742
+ * Sign with Ed25519 key at `//ed25519//<app_id>//<index>`. Returns 64-byte signature.
743
+ */
744
+ signEd25519(app_id: string, index: number, payload: Uint8Array): Uint8Array;
745
+ /**
746
+ * Sign with root sr25519 keypair. Returns 64-byte signature.
747
+ */
748
+ signRoot(payload: Uint8Array): Uint8Array;
749
+ /**
750
+ * Sign with Substrate ECDSA key at `//ecdsa//<app_id>//<index>`. Returns 65 bytes (r+s+recovery).
751
+ */
752
+ signSubstrateEcdsa(app_id: string, index: number, payload: Uint8Array): Uint8Array;
753
+ /**
754
+ * Sign with the `//wallet` sr25519 keypair. Returns 64-byte signature.
755
+ *
756
+ * This matches the signing identity used by the native chat-request and
757
+ * statement-store flows.
758
+ */
759
+ signWallet(payload: Uint8Array): Uint8Array;
760
+ /**
761
+ * Current wallet state: "NoWallet" | "Locked" | "Unlocked".
762
+ */
763
+ state(): string;
764
+ /**
765
+ * 33-byte compressed secp256k1 public key at `//ecdsa//<app_id>//<index>`.
766
+ */
767
+ substrateEcdsaPublicKey(app_id: string, index: number): Uint8Array;
768
+ /**
769
+ * Check auto-lock timeout. Call once per frame. Returns true if locked.
770
+ */
771
+ tick(): boolean;
772
+ /**
773
+ * 32-byte sr25519 public key at `//wallet`.
774
+ *
775
+ * This is the chat identity account ID used by the native chat-request
776
+ * and statement-store protocol.
777
+ */
778
+ walletPublicKey(): Uint8Array;
779
+ }
780
+
781
+ /**
782
+ * Decode raw call data bytes against runtime metadata.
783
+ *
784
+ * Returns a JS object: `{ pallet: string, call: string, argsJson: object, nestedCalls: array }`.
785
+ *
786
+ * `call_data` is the raw bytes starting with the pallet index byte and call
787
+ * index byte, followed by SCALE-encoded call arguments — exactly the prefix of
788
+ * `callDataAndExtra` from `decodeSignPayload`, minus the signed-extension extra
789
+ * bytes. Trailing signed-extension bytes are silently ignored.
790
+ *
791
+ * `metadata_scale` must be SCALE bytes for `RuntimeMetadataPrefixed` (V14, V15,
792
+ * or V16 with the magic prefix `0x6d657461`).
793
+ *
794
+ * Throws a `JsError` on any decoding failure.
795
+ */
796
+ export function decodeCallData(call_data: Uint8Array, metadata_scale: Uint8Array): any;
797
+
798
+ /**
799
+ * Decode a Substrate extrinsic against runtime metadata.
800
+ *
801
+ * Returns a JS object: `{ pallet: string, call: string, argsJson: object, nestedCalls: array }`.
802
+ *
803
+ * `extrinsic_scale` must be compact-length-prefixed SCALE bytes for one extrinsic,
804
+ * exactly as returned by a Substrate node (the outer `Vec<u8>` element from the block body).
805
+ *
806
+ * `metadata_scale` must be SCALE bytes for `RuntimeMetadataPrefixed` (V14, V15, or V16
807
+ * with the magic prefix `0x6d657461`).
808
+ *
809
+ * Throws a `JsError` on any decoding failure. On success the returned `argsJson` contains
810
+ * each argument name mapped to its decoded JSON value, and `nestedCalls` is a (possibly empty)
811
+ * array of the same structure for inner calls in batch/proxy/multisig extrinsics.
812
+ */
813
+ export function decodeExtrinsic(extrinsic_scale: Uint8Array, metadata_scale: Uint8Array): any;
814
+
815
+ /**
816
+ * Decode a Substrate extrinsic signing payload into structured fields.
817
+ *
818
+ * Use this on the `payload` bytes from a `NeedsSign` outcome when
819
+ * `request_tag` equals `TAG_SIGN_PAYLOAD_REQ` (116 in v0.7.4 — formerly 36
820
+ * in v0.7.3). Returns a JS object with `genesisHash`, `blockHash`,
821
+ * `specVersion`, `txVersion`, `metadataHash` (Uint8Array or null), and
822
+ * `callDataAndExtra`.
823
+ *
824
+ * This is a heuristic decoder for display purposes — see the
825
+ * `useragent_encoding::extrinsic` module docs for limitations.
826
+ */
827
+ export function decodeSignPayload(payload: Uint8Array): any;
828
+
829
+ /**
830
+ * SCALE-encode a raw signature as a Substrate MultiSignature.
831
+ * `scheme`: 0 = Ed25519, 1 = Sr25519, 2 = Ecdsa.
832
+ */
833
+ export function encodeMultiSignature(sig_bytes: Uint8Array, scheme: number): Uint8Array;
834
+
835
+ /**
836
+ * Generate a fresh 12-word BIP-39 mnemonic.
837
+ */
838
+ export function generateMnemonic(): string;