@parity/truapi 0.1.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 +21 -0
- package/README.md +102 -0
- package/dist/client.d.ts +20 -0
- package/dist/client.js +320 -0
- package/dist/generated/client.d.ts +243 -0
- package/dist/generated/client.js +1081 -0
- package/dist/generated/index.d.ts +2 -0
- package/dist/generated/index.js +2 -0
- package/dist/generated/types.d.ts +2666 -0
- package/dist/generated/types.js +877 -0
- package/dist/generated/wire-table.d.ts +246 -0
- package/dist/generated/wire-table.js +249 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -0
- package/dist/playground/codegen/services.d.ts +2 -0
- package/dist/playground/codegen/services.js +456 -0
- package/dist/playground/services-types.d.ts +12 -0
- package/dist/playground/services-types.js +1 -0
- package/dist/scale.d.ts +77 -0
- package/dist/scale.js +121 -0
- package/dist/transport.d.ts +237 -0
- package/dist/transport.js +238 -0
- package/package.json +57 -0
|
@@ -0,0 +1,1081 @@
|
|
|
1
|
+
// Auto-generated by truapi-codegen. Do not edit.
|
|
2
|
+
import { err, ok } from "neverthrow";
|
|
3
|
+
import * as S from "../scale.js";
|
|
4
|
+
import { SubscriptionError } from "../transport.js";
|
|
5
|
+
import * as T from "./types.js";
|
|
6
|
+
import * as W from "./wire-table.js";
|
|
7
|
+
export { SubscriptionError };
|
|
8
|
+
export const TRUAPI_VERSION = 1;
|
|
9
|
+
export const TRUAPI_CODEC_VERSION = 1;
|
|
10
|
+
function toSubscriptionError(error) {
|
|
11
|
+
if (error instanceof SubscriptionError)
|
|
12
|
+
return error;
|
|
13
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
14
|
+
return new SubscriptionError(cause.message, { cause });
|
|
15
|
+
}
|
|
16
|
+
function createObservable({ transport, ids, payload, decodeItem, decodeInterrupt, }) {
|
|
17
|
+
return {
|
|
18
|
+
subscribe(observer = {}) {
|
|
19
|
+
let closed = false;
|
|
20
|
+
let raw;
|
|
21
|
+
const fail = (error, stop = true) => {
|
|
22
|
+
if (closed)
|
|
23
|
+
return;
|
|
24
|
+
closed = true;
|
|
25
|
+
try {
|
|
26
|
+
if (stop)
|
|
27
|
+
raw?.unsubscribe();
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
observer.error?.(toSubscriptionError(error));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
raw = transport.subscribeRaw({
|
|
34
|
+
ids,
|
|
35
|
+
payload,
|
|
36
|
+
onReceive: (payload) => {
|
|
37
|
+
if (closed)
|
|
38
|
+
return;
|
|
39
|
+
try {
|
|
40
|
+
observer.next?.(decodeItem(payload));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
fail(error);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
onInterrupt: (payload) => {
|
|
47
|
+
if (closed)
|
|
48
|
+
return;
|
|
49
|
+
if (decodeInterrupt) {
|
|
50
|
+
let reason;
|
|
51
|
+
try {
|
|
52
|
+
reason = decodeInterrupt(payload);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
fail(error, false);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
fail(new SubscriptionError("Subscription interrupted", { reason }), false);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
closed = true;
|
|
62
|
+
observer.complete?.();
|
|
63
|
+
},
|
|
64
|
+
onClose: fail,
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
get subscriptionId() {
|
|
68
|
+
return raw?.subscriptionId ?? "";
|
|
69
|
+
},
|
|
70
|
+
unsubscribe: () => {
|
|
71
|
+
if (closed)
|
|
72
|
+
return;
|
|
73
|
+
closed = true;
|
|
74
|
+
raw?.unsubscribe();
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Account lookup, aliasing, and proof generation. */
|
|
81
|
+
export class AccountClient {
|
|
82
|
+
transport;
|
|
83
|
+
constructor(transport) {
|
|
84
|
+
this.transport = transport;
|
|
85
|
+
}
|
|
86
|
+
/** Subscribe to account connection status changes. */
|
|
87
|
+
connectionStatusSubscribe() {
|
|
88
|
+
return createObservable({
|
|
89
|
+
transport: this.transport,
|
|
90
|
+
ids: W.ACCOUNT_CONNECTION_STATUS_SUBSCRIBE,
|
|
91
|
+
payload: S.indexedTaggedUnion({ V1: [0, S._void] }).enc({
|
|
92
|
+
tag: "V1",
|
|
93
|
+
value: undefined,
|
|
94
|
+
}),
|
|
95
|
+
decodeItem: (payload) => T.VersionedHostAccountConnectionStatusSubscribeItem.dec(payload).value,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/** Retrieve a product-scoped account. */
|
|
99
|
+
async getAccount(request) {
|
|
100
|
+
const result = await this.transport.request({
|
|
101
|
+
ids: W.ACCOUNT_GET_ACCOUNT,
|
|
102
|
+
payload: T.VersionedHostAccountGetRequest.enc({
|
|
103
|
+
tag: "V1",
|
|
104
|
+
value: request,
|
|
105
|
+
}),
|
|
106
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
107
|
+
V1: [
|
|
108
|
+
0,
|
|
109
|
+
S.Result(T.HostAccountGetResponse, T.HostAccountGetError),
|
|
110
|
+
],
|
|
111
|
+
}).dec(payload).value,
|
|
112
|
+
});
|
|
113
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
114
|
+
}
|
|
115
|
+
/** Retrieve a contextual alias for a product account. */
|
|
116
|
+
async getAccountAlias(request) {
|
|
117
|
+
const result = await this.transport.request({
|
|
118
|
+
ids: W.ACCOUNT_GET_ACCOUNT_ALIAS,
|
|
119
|
+
payload: T.VersionedHostAccountGetAliasRequest.enc({
|
|
120
|
+
tag: "V1",
|
|
121
|
+
value: request,
|
|
122
|
+
}),
|
|
123
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
124
|
+
V1: [
|
|
125
|
+
0,
|
|
126
|
+
S.Result(T.HostAccountGetAliasResponse, T.HostAccountGetError),
|
|
127
|
+
],
|
|
128
|
+
}).dec(payload).value,
|
|
129
|
+
});
|
|
130
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
131
|
+
}
|
|
132
|
+
/** Generate a ring VRF proof for a product account. */
|
|
133
|
+
async createAccountProof(request) {
|
|
134
|
+
const result = await this.transport.request({
|
|
135
|
+
ids: W.ACCOUNT_CREATE_ACCOUNT_PROOF,
|
|
136
|
+
payload: T.VersionedHostAccountCreateProofRequest.enc({
|
|
137
|
+
tag: "V1",
|
|
138
|
+
value: request,
|
|
139
|
+
}),
|
|
140
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
141
|
+
V1: [
|
|
142
|
+
0,
|
|
143
|
+
S.Result(T.HostAccountCreateProofResponse, T.HostAccountCreateProofError),
|
|
144
|
+
],
|
|
145
|
+
}).dec(payload).value,
|
|
146
|
+
});
|
|
147
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
148
|
+
}
|
|
149
|
+
/** List non-product accounts the user owns. */
|
|
150
|
+
async getLegacyAccounts() {
|
|
151
|
+
const result = await this.transport.request({
|
|
152
|
+
ids: W.ACCOUNT_GET_LEGACY_ACCOUNTS,
|
|
153
|
+
payload: T.VersionedHostGetLegacyAccountsRequest.enc({
|
|
154
|
+
tag: "V1",
|
|
155
|
+
value: undefined,
|
|
156
|
+
}),
|
|
157
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
158
|
+
V1: [
|
|
159
|
+
0,
|
|
160
|
+
S.Result(T.HostGetLegacyAccountsResponse, T.HostAccountGetError),
|
|
161
|
+
],
|
|
162
|
+
}).dec(payload).value,
|
|
163
|
+
});
|
|
164
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
165
|
+
}
|
|
166
|
+
/** Fetch the user's primary identity. */
|
|
167
|
+
async getUserId() {
|
|
168
|
+
const result = await this.transport.request({
|
|
169
|
+
ids: W.ACCOUNT_GET_USER_ID,
|
|
170
|
+
payload: T.VersionedHostGetUserIdRequest.enc({
|
|
171
|
+
tag: "V1",
|
|
172
|
+
value: undefined,
|
|
173
|
+
}),
|
|
174
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
175
|
+
V1: [
|
|
176
|
+
0,
|
|
177
|
+
S.Result(T.HostGetUserIdResponse, T.HostGetUserIdError),
|
|
178
|
+
],
|
|
179
|
+
}).dec(payload).value,
|
|
180
|
+
});
|
|
181
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Request the host to present the login flow to the user.
|
|
185
|
+
*
|
|
186
|
+
* Products should call this in response to a user action (e.g. tapping a
|
|
187
|
+
* "Sign in" button), not automatically on load.
|
|
188
|
+
*/
|
|
189
|
+
async requestLogin(request) {
|
|
190
|
+
const result = await this.transport.request({
|
|
191
|
+
ids: W.ACCOUNT_REQUEST_LOGIN,
|
|
192
|
+
payload: T.VersionedHostRequestLoginRequest.enc({
|
|
193
|
+
tag: "V1",
|
|
194
|
+
value: request,
|
|
195
|
+
}),
|
|
196
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
197
|
+
V1: [
|
|
198
|
+
0,
|
|
199
|
+
S.Result(T.HostRequestLoginResponse, T.HostRequestLoginError),
|
|
200
|
+
],
|
|
201
|
+
}).dec(payload).value,
|
|
202
|
+
});
|
|
203
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** Chain interaction methods. */
|
|
207
|
+
export class ChainClient {
|
|
208
|
+
transport;
|
|
209
|
+
constructor(transport) {
|
|
210
|
+
this.transport = transport;
|
|
211
|
+
}
|
|
212
|
+
/** Follow the chain head and receive block events. */
|
|
213
|
+
followHeadSubscribe({ request, }) {
|
|
214
|
+
return createObservable({
|
|
215
|
+
transport: this.transport,
|
|
216
|
+
ids: W.CHAIN_FOLLOW_HEAD_SUBSCRIBE,
|
|
217
|
+
payload: T.VersionedRemoteChainHeadFollowRequest.enc({
|
|
218
|
+
tag: "V1",
|
|
219
|
+
value: request,
|
|
220
|
+
}),
|
|
221
|
+
decodeItem: (payload) => T.VersionedRemoteChainHeadFollowItem.dec(payload).value,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/** Fetch a block header. */
|
|
225
|
+
async getHeadHeader(request) {
|
|
226
|
+
const result = await this.transport.request({
|
|
227
|
+
ids: W.CHAIN_GET_HEAD_HEADER,
|
|
228
|
+
payload: T.VersionedRemoteChainHeadHeaderRequest.enc({
|
|
229
|
+
tag: "V1",
|
|
230
|
+
value: request,
|
|
231
|
+
}),
|
|
232
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
233
|
+
V1: [
|
|
234
|
+
0,
|
|
235
|
+
S.Result(T.RemoteChainHeadHeaderResponse, T.GenericError),
|
|
236
|
+
],
|
|
237
|
+
}).dec(payload).value,
|
|
238
|
+
});
|
|
239
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
240
|
+
}
|
|
241
|
+
/** Fetch a block body. */
|
|
242
|
+
async getHeadBody(request) {
|
|
243
|
+
const result = await this.transport.request({
|
|
244
|
+
ids: W.CHAIN_GET_HEAD_BODY,
|
|
245
|
+
payload: T.VersionedRemoteChainHeadBodyRequest.enc({
|
|
246
|
+
tag: "V1",
|
|
247
|
+
value: request,
|
|
248
|
+
}),
|
|
249
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
250
|
+
V1: [
|
|
251
|
+
0,
|
|
252
|
+
S.Result(T.RemoteChainHeadBodyResponse, T.GenericError),
|
|
253
|
+
],
|
|
254
|
+
}).dec(payload).value,
|
|
255
|
+
});
|
|
256
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
257
|
+
}
|
|
258
|
+
/** Query runtime storage at a specific block. */
|
|
259
|
+
async getHeadStorage(request) {
|
|
260
|
+
const result = await this.transport.request({
|
|
261
|
+
ids: W.CHAIN_GET_HEAD_STORAGE,
|
|
262
|
+
payload: T.VersionedRemoteChainHeadStorageRequest.enc({
|
|
263
|
+
tag: "V1",
|
|
264
|
+
value: request,
|
|
265
|
+
}),
|
|
266
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
267
|
+
V1: [
|
|
268
|
+
0,
|
|
269
|
+
S.Result(T.RemoteChainHeadStorageResponse, T.GenericError),
|
|
270
|
+
],
|
|
271
|
+
}).dec(payload).value,
|
|
272
|
+
});
|
|
273
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
274
|
+
}
|
|
275
|
+
/** Invoke a runtime call at a specific block. */
|
|
276
|
+
async callHead(request) {
|
|
277
|
+
const result = await this.transport.request({
|
|
278
|
+
ids: W.CHAIN_CALL_HEAD,
|
|
279
|
+
payload: T.VersionedRemoteChainHeadCallRequest.enc({
|
|
280
|
+
tag: "V1",
|
|
281
|
+
value: request,
|
|
282
|
+
}),
|
|
283
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
284
|
+
V1: [
|
|
285
|
+
0,
|
|
286
|
+
S.Result(T.RemoteChainHeadCallResponse, T.GenericError),
|
|
287
|
+
],
|
|
288
|
+
}).dec(payload).value,
|
|
289
|
+
});
|
|
290
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
291
|
+
}
|
|
292
|
+
/** Release pinned blocks. */
|
|
293
|
+
async unpinHead(request) {
|
|
294
|
+
const result = await this.transport.request({
|
|
295
|
+
ids: W.CHAIN_UNPIN_HEAD,
|
|
296
|
+
payload: T.VersionedRemoteChainHeadUnpinRequest.enc({
|
|
297
|
+
tag: "V1",
|
|
298
|
+
value: request,
|
|
299
|
+
}),
|
|
300
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
301
|
+
V1: [0, S.Result(S._void, T.GenericError)],
|
|
302
|
+
}).dec(payload).value,
|
|
303
|
+
});
|
|
304
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
305
|
+
}
|
|
306
|
+
/** Continue a paused chain-head operation. */
|
|
307
|
+
async continueHead(request) {
|
|
308
|
+
const result = await this.transport.request({
|
|
309
|
+
ids: W.CHAIN_CONTINUE_HEAD,
|
|
310
|
+
payload: T.VersionedRemoteChainHeadContinueRequest.enc({
|
|
311
|
+
tag: "V1",
|
|
312
|
+
value: request,
|
|
313
|
+
}),
|
|
314
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
315
|
+
V1: [0, S.Result(S._void, T.GenericError)],
|
|
316
|
+
}).dec(payload).value,
|
|
317
|
+
});
|
|
318
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
319
|
+
}
|
|
320
|
+
/** Stop a chain-head operation. */
|
|
321
|
+
async stopHeadOperation(request) {
|
|
322
|
+
const result = await this.transport.request({
|
|
323
|
+
ids: W.CHAIN_STOP_HEAD_OPERATION,
|
|
324
|
+
payload: T.VersionedRemoteChainHeadStopOperationRequest.enc({
|
|
325
|
+
tag: "V1",
|
|
326
|
+
value: request,
|
|
327
|
+
}),
|
|
328
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
329
|
+
V1: [0, S.Result(S._void, T.GenericError)],
|
|
330
|
+
}).dec(payload).value,
|
|
331
|
+
});
|
|
332
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
333
|
+
}
|
|
334
|
+
/** Fetch the canonical genesis hash for a chain. */
|
|
335
|
+
async getSpecGenesisHash(request) {
|
|
336
|
+
const result = await this.transport.request({
|
|
337
|
+
ids: W.CHAIN_GET_SPEC_GENESIS_HASH,
|
|
338
|
+
payload: T.VersionedRemoteChainSpecGenesisHashRequest.enc({
|
|
339
|
+
tag: "V1",
|
|
340
|
+
value: request,
|
|
341
|
+
}),
|
|
342
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
343
|
+
V1: [
|
|
344
|
+
0,
|
|
345
|
+
S.Result(T.RemoteChainSpecGenesisHashResponse, T.GenericError),
|
|
346
|
+
],
|
|
347
|
+
}).dec(payload).value,
|
|
348
|
+
});
|
|
349
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
350
|
+
}
|
|
351
|
+
/** Fetch the display name of a chain. */
|
|
352
|
+
async getSpecChainName(request) {
|
|
353
|
+
const result = await this.transport.request({
|
|
354
|
+
ids: W.CHAIN_GET_SPEC_CHAIN_NAME,
|
|
355
|
+
payload: T.VersionedRemoteChainSpecChainNameRequest.enc({
|
|
356
|
+
tag: "V1",
|
|
357
|
+
value: request,
|
|
358
|
+
}),
|
|
359
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
360
|
+
V1: [
|
|
361
|
+
0,
|
|
362
|
+
S.Result(T.RemoteChainSpecChainNameResponse, T.GenericError),
|
|
363
|
+
],
|
|
364
|
+
}).dec(payload).value,
|
|
365
|
+
});
|
|
366
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
367
|
+
}
|
|
368
|
+
/** Fetch the JSON-encoded properties of a chain. */
|
|
369
|
+
async getSpecProperties(request) {
|
|
370
|
+
const result = await this.transport.request({
|
|
371
|
+
ids: W.CHAIN_GET_SPEC_PROPERTIES,
|
|
372
|
+
payload: T.VersionedRemoteChainSpecPropertiesRequest.enc({
|
|
373
|
+
tag: "V1",
|
|
374
|
+
value: request,
|
|
375
|
+
}),
|
|
376
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
377
|
+
V1: [
|
|
378
|
+
0,
|
|
379
|
+
S.Result(T.RemoteChainSpecPropertiesResponse, T.GenericError),
|
|
380
|
+
],
|
|
381
|
+
}).dec(payload).value,
|
|
382
|
+
});
|
|
383
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
384
|
+
}
|
|
385
|
+
/** Broadcast a signed transaction. */
|
|
386
|
+
async broadcastTransaction(request) {
|
|
387
|
+
const result = await this.transport.request({
|
|
388
|
+
ids: W.CHAIN_BROADCAST_TRANSACTION,
|
|
389
|
+
payload: T.VersionedRemoteChainTransactionBroadcastRequest.enc({
|
|
390
|
+
tag: "V1",
|
|
391
|
+
value: request,
|
|
392
|
+
}),
|
|
393
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
394
|
+
V1: [
|
|
395
|
+
0,
|
|
396
|
+
S.Result(T.RemoteChainTransactionBroadcastResponse, T.GenericError),
|
|
397
|
+
],
|
|
398
|
+
}).dec(payload).value,
|
|
399
|
+
});
|
|
400
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
401
|
+
}
|
|
402
|
+
/** Stop a transaction broadcast. */
|
|
403
|
+
async stopTransaction(request) {
|
|
404
|
+
const result = await this.transport.request({
|
|
405
|
+
ids: W.CHAIN_STOP_TRANSACTION,
|
|
406
|
+
payload: T.VersionedRemoteChainTransactionStopRequest.enc({
|
|
407
|
+
tag: "V1",
|
|
408
|
+
value: request,
|
|
409
|
+
}),
|
|
410
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
411
|
+
V1: [0, S.Result(S._void, T.GenericError)],
|
|
412
|
+
}).dec(payload).value,
|
|
413
|
+
});
|
|
414
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/** Chat room, bot, and message APIs. */
|
|
418
|
+
export class ChatClient {
|
|
419
|
+
transport;
|
|
420
|
+
constructor(transport) {
|
|
421
|
+
this.transport = transport;
|
|
422
|
+
}
|
|
423
|
+
/** Create a chat room. */
|
|
424
|
+
async createRoom(request) {
|
|
425
|
+
const result = await this.transport.request({
|
|
426
|
+
ids: W.CHAT_CREATE_ROOM,
|
|
427
|
+
payload: T.VersionedHostChatCreateRoomRequest.enc({
|
|
428
|
+
tag: "V1",
|
|
429
|
+
value: request,
|
|
430
|
+
}),
|
|
431
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
432
|
+
V1: [
|
|
433
|
+
0,
|
|
434
|
+
S.Result(T.HostChatCreateRoomResponse, T.HostChatCreateRoomError),
|
|
435
|
+
],
|
|
436
|
+
}).dec(payload).value,
|
|
437
|
+
});
|
|
438
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
439
|
+
}
|
|
440
|
+
/** Register a chat bot. */
|
|
441
|
+
async registerBot(request) {
|
|
442
|
+
const result = await this.transport.request({
|
|
443
|
+
ids: W.CHAT_REGISTER_BOT,
|
|
444
|
+
payload: T.VersionedHostChatRegisterBotRequest.enc({
|
|
445
|
+
tag: "V1",
|
|
446
|
+
value: request,
|
|
447
|
+
}),
|
|
448
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
449
|
+
V1: [
|
|
450
|
+
0,
|
|
451
|
+
S.Result(T.HostChatRegisterBotResponse, T.HostChatRegisterBotError),
|
|
452
|
+
],
|
|
453
|
+
}).dec(payload).value,
|
|
454
|
+
});
|
|
455
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
456
|
+
}
|
|
457
|
+
/** Subscribe to the list of chat rooms. */
|
|
458
|
+
listSubscribe() {
|
|
459
|
+
return createObservable({
|
|
460
|
+
transport: this.transport,
|
|
461
|
+
ids: W.CHAT_LIST_SUBSCRIBE,
|
|
462
|
+
payload: S.indexedTaggedUnion({ V1: [0, S._void] }).enc({
|
|
463
|
+
tag: "V1",
|
|
464
|
+
value: undefined,
|
|
465
|
+
}),
|
|
466
|
+
decodeItem: (payload) => T.VersionedHostChatListSubscribeItem.dec(payload).value,
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
/** Post a message to a chat room. */
|
|
470
|
+
async postMessage(request) {
|
|
471
|
+
const result = await this.transport.request({
|
|
472
|
+
ids: W.CHAT_POST_MESSAGE,
|
|
473
|
+
payload: T.VersionedHostChatPostMessageRequest.enc({
|
|
474
|
+
tag: "V1",
|
|
475
|
+
value: request,
|
|
476
|
+
}),
|
|
477
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
478
|
+
V1: [
|
|
479
|
+
0,
|
|
480
|
+
S.Result(T.HostChatPostMessageResponse, T.HostChatPostMessageError),
|
|
481
|
+
],
|
|
482
|
+
}).dec(payload).value,
|
|
483
|
+
});
|
|
484
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
485
|
+
}
|
|
486
|
+
/** Subscribe to received chat actions. */
|
|
487
|
+
actionSubscribe() {
|
|
488
|
+
return createObservable({
|
|
489
|
+
transport: this.transport,
|
|
490
|
+
ids: W.CHAT_ACTION_SUBSCRIBE,
|
|
491
|
+
payload: S.indexedTaggedUnion({ V1: [0, S._void] }).enc({
|
|
492
|
+
tag: "V1",
|
|
493
|
+
value: undefined,
|
|
494
|
+
}),
|
|
495
|
+
decodeItem: (payload) => T.VersionedHostChatActionSubscribeItem.dec(payload).value,
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Subscribe to custom message render requests from the host. Each
|
|
500
|
+
* emitted item is a [`CustomRendererNode`](crate::v01::CustomRendererNode)
|
|
501
|
+
* tree describing the rendered UI.
|
|
502
|
+
*/
|
|
503
|
+
customMessageRenderSubscribe({ request, }) {
|
|
504
|
+
return createObservable({
|
|
505
|
+
transport: this.transport,
|
|
506
|
+
ids: W.CHAT_CUSTOM_MESSAGE_RENDER_SUBSCRIBE,
|
|
507
|
+
payload: T.VersionedProductChatCustomMessageRenderSubscribeRequest.enc({
|
|
508
|
+
tag: "V1",
|
|
509
|
+
value: request,
|
|
510
|
+
}),
|
|
511
|
+
decodeItem: (payload) => T.VersionedProductChatCustomMessageRenderSubscribeItem.dec(payload).value,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
/** Deterministic entropy derivation. */
|
|
516
|
+
export class EntropyClient {
|
|
517
|
+
transport;
|
|
518
|
+
constructor(transport) {
|
|
519
|
+
this.transport = transport;
|
|
520
|
+
}
|
|
521
|
+
/** Derive deterministic entropy. */
|
|
522
|
+
async derive(request) {
|
|
523
|
+
const result = await this.transport.request({
|
|
524
|
+
ids: W.ENTROPY_DERIVE,
|
|
525
|
+
payload: T.VersionedHostDeriveEntropyRequest.enc({
|
|
526
|
+
tag: "V1",
|
|
527
|
+
value: request,
|
|
528
|
+
}),
|
|
529
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
530
|
+
V1: [
|
|
531
|
+
0,
|
|
532
|
+
S.Result(T.HostDeriveEntropyResponse, T.HostDeriveEntropyError),
|
|
533
|
+
],
|
|
534
|
+
}).dec(payload).value,
|
|
535
|
+
});
|
|
536
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
/** JSON-RPC transport methods. */
|
|
540
|
+
export class JsonRpcClient {
|
|
541
|
+
transport;
|
|
542
|
+
constructor(transport) {
|
|
543
|
+
this.transport = transport;
|
|
544
|
+
}
|
|
545
|
+
/** Send a JSON-RPC message. */
|
|
546
|
+
async sendMessage(request) {
|
|
547
|
+
const result = await this.transport.request({
|
|
548
|
+
ids: W.JSON_RPC_SEND_MESSAGE,
|
|
549
|
+
payload: T.VersionedHostJsonrpcMessageSendRequest.enc({
|
|
550
|
+
tag: "V1",
|
|
551
|
+
value: request,
|
|
552
|
+
}),
|
|
553
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
554
|
+
V1: [0, S.Result(S._void, T.GenericError)],
|
|
555
|
+
}).dec(payload).value,
|
|
556
|
+
});
|
|
557
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
558
|
+
}
|
|
559
|
+
/** Subscribe to inbound JSON-RPC messages. */
|
|
560
|
+
subscribeMessages({ request, }) {
|
|
561
|
+
return createObservable({
|
|
562
|
+
transport: this.transport,
|
|
563
|
+
ids: W.JSON_RPC_SUBSCRIBE_MESSAGES,
|
|
564
|
+
payload: T.VersionedHostJsonrpcMessageSubscribeRequest.enc({
|
|
565
|
+
tag: "V1",
|
|
566
|
+
value: request,
|
|
567
|
+
}),
|
|
568
|
+
decodeItem: (payload) => T.VersionedHostJsonrpcMessageSubscribeItem.dec(payload).value,
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
/** Local key/value storage scoped to the calling product. */
|
|
573
|
+
export class LocalStorageClient {
|
|
574
|
+
transport;
|
|
575
|
+
constructor(transport) {
|
|
576
|
+
this.transport = transport;
|
|
577
|
+
}
|
|
578
|
+
/** Read a value by key. */
|
|
579
|
+
async read(request) {
|
|
580
|
+
const result = await this.transport.request({
|
|
581
|
+
ids: W.LOCAL_STORAGE_READ,
|
|
582
|
+
payload: T.VersionedHostLocalStorageReadRequest.enc({
|
|
583
|
+
tag: "V1",
|
|
584
|
+
value: request,
|
|
585
|
+
}),
|
|
586
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
587
|
+
V1: [
|
|
588
|
+
0,
|
|
589
|
+
S.Result(T.HostLocalStorageReadResponse, T.HostLocalStorageReadError),
|
|
590
|
+
],
|
|
591
|
+
}).dec(payload).value,
|
|
592
|
+
});
|
|
593
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
594
|
+
}
|
|
595
|
+
/** Write a value to a key. */
|
|
596
|
+
async write(request) {
|
|
597
|
+
const result = await this.transport.request({
|
|
598
|
+
ids: W.LOCAL_STORAGE_WRITE,
|
|
599
|
+
payload: T.VersionedHostLocalStorageWriteRequest.enc({
|
|
600
|
+
tag: "V1",
|
|
601
|
+
value: request,
|
|
602
|
+
}),
|
|
603
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
604
|
+
V1: [0, S.Result(S._void, T.HostLocalStorageReadError)],
|
|
605
|
+
}).dec(payload).value,
|
|
606
|
+
});
|
|
607
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
608
|
+
}
|
|
609
|
+
/** Clear a value by key. */
|
|
610
|
+
async clear(request) {
|
|
611
|
+
const result = await this.transport.request({
|
|
612
|
+
ids: W.LOCAL_STORAGE_CLEAR,
|
|
613
|
+
payload: T.VersionedHostLocalStorageClearRequest.enc({
|
|
614
|
+
tag: "V1",
|
|
615
|
+
value: request,
|
|
616
|
+
}),
|
|
617
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
618
|
+
V1: [0, S.Result(S._void, T.HostLocalStorageReadError)],
|
|
619
|
+
}).dec(payload).value,
|
|
620
|
+
});
|
|
621
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
/** Payment request and balance/status subscription methods. */
|
|
625
|
+
export class PaymentClient {
|
|
626
|
+
transport;
|
|
627
|
+
constructor(transport) {
|
|
628
|
+
this.transport = transport;
|
|
629
|
+
}
|
|
630
|
+
/** Subscribe to payment balance updates. */
|
|
631
|
+
balanceSubscribe() {
|
|
632
|
+
return createObservable({
|
|
633
|
+
transport: this.transport,
|
|
634
|
+
ids: W.PAYMENT_BALANCE_SUBSCRIBE,
|
|
635
|
+
payload: T.VersionedHostPaymentBalanceSubscribeRequest.enc({
|
|
636
|
+
tag: "V1",
|
|
637
|
+
value: undefined,
|
|
638
|
+
}),
|
|
639
|
+
decodeItem: (payload) => T.VersionedHostPaymentBalanceSubscribeItem.dec(payload).value,
|
|
640
|
+
decodeInterrupt: (payload) => T.VersionedHostPaymentBalanceSubscribeError.dec(payload).value,
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
/** Request a payment from the user. */
|
|
644
|
+
async request(request) {
|
|
645
|
+
const result = await this.transport.request({
|
|
646
|
+
ids: W.PAYMENT_REQUEST,
|
|
647
|
+
payload: T.VersionedHostPaymentRequestRequest.enc({
|
|
648
|
+
tag: "V1",
|
|
649
|
+
value: request,
|
|
650
|
+
}),
|
|
651
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
652
|
+
V1: [
|
|
653
|
+
0,
|
|
654
|
+
S.Result(T.HostPaymentRequestResponse, T.HostPaymentRequestError),
|
|
655
|
+
],
|
|
656
|
+
}).dec(payload).value,
|
|
657
|
+
});
|
|
658
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
659
|
+
}
|
|
660
|
+
/** Subscribe to payment lifecycle updates for a specific payment. */
|
|
661
|
+
statusSubscribe({ request, }) {
|
|
662
|
+
return createObservable({
|
|
663
|
+
transport: this.transport,
|
|
664
|
+
ids: W.PAYMENT_STATUS_SUBSCRIBE,
|
|
665
|
+
payload: T.VersionedHostPaymentStatusSubscribeRequest.enc({
|
|
666
|
+
tag: "V1",
|
|
667
|
+
value: request,
|
|
668
|
+
}),
|
|
669
|
+
decodeItem: (payload) => T.VersionedHostPaymentStatusSubscribeItem.dec(payload).value,
|
|
670
|
+
decodeInterrupt: (payload) => T.VersionedHostPaymentStatusSubscribeError.dec(payload).value,
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
/** Top up the user's payment balance. */
|
|
674
|
+
async topUp(request) {
|
|
675
|
+
const result = await this.transport.request({
|
|
676
|
+
ids: W.PAYMENT_TOP_UP,
|
|
677
|
+
payload: T.VersionedHostPaymentTopUpRequest.enc({
|
|
678
|
+
tag: "V1",
|
|
679
|
+
value: request,
|
|
680
|
+
}),
|
|
681
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
682
|
+
V1: [0, S.Result(S._void, T.HostPaymentTopUpError)],
|
|
683
|
+
}).dec(payload).value,
|
|
684
|
+
});
|
|
685
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
/** Permission request methods. */
|
|
689
|
+
export class PermissionsClient {
|
|
690
|
+
transport;
|
|
691
|
+
constructor(transport) {
|
|
692
|
+
this.transport = transport;
|
|
693
|
+
}
|
|
694
|
+
/** Request a device-capability permission from the user. */
|
|
695
|
+
async requestDevicePermission(request) {
|
|
696
|
+
const result = await this.transport.request({
|
|
697
|
+
ids: W.PERMISSIONS_REQUEST_DEVICE_PERMISSION,
|
|
698
|
+
payload: T.VersionedHostDevicePermissionRequest.enc({
|
|
699
|
+
tag: "V1",
|
|
700
|
+
value: request,
|
|
701
|
+
}),
|
|
702
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
703
|
+
V1: [
|
|
704
|
+
0,
|
|
705
|
+
S.Result(T.HostDevicePermissionResponse, T.GenericError),
|
|
706
|
+
],
|
|
707
|
+
}).dec(payload).value,
|
|
708
|
+
});
|
|
709
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
710
|
+
}
|
|
711
|
+
/** Request one or more remote-operation permissions. */
|
|
712
|
+
async requestRemotePermission(request) {
|
|
713
|
+
const result = await this.transport.request({
|
|
714
|
+
ids: W.PERMISSIONS_REQUEST_REMOTE_PERMISSION,
|
|
715
|
+
payload: T.VersionedRemotePermissionRequest.enc({
|
|
716
|
+
tag: "V1",
|
|
717
|
+
value: request,
|
|
718
|
+
}),
|
|
719
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
720
|
+
V1: [
|
|
721
|
+
0,
|
|
722
|
+
S.Result(T.RemotePermissionResponse, T.GenericError),
|
|
723
|
+
],
|
|
724
|
+
}).dec(payload).value,
|
|
725
|
+
});
|
|
726
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
/** Preimage lookup and submission methods. */
|
|
730
|
+
export class PreimageClient {
|
|
731
|
+
transport;
|
|
732
|
+
constructor(transport) {
|
|
733
|
+
this.transport = transport;
|
|
734
|
+
}
|
|
735
|
+
/** Subscribe to preimage lookups for a given key. */
|
|
736
|
+
lookupSubscribe({ request, }) {
|
|
737
|
+
return createObservable({
|
|
738
|
+
transport: this.transport,
|
|
739
|
+
ids: W.PREIMAGE_LOOKUP_SUBSCRIBE,
|
|
740
|
+
payload: T.VersionedRemotePreimageLookupSubscribeRequest.enc({
|
|
741
|
+
tag: "V1",
|
|
742
|
+
value: request,
|
|
743
|
+
}),
|
|
744
|
+
decodeItem: (payload) => T.VersionedRemotePreimageLookupSubscribeItem.dec(payload).value,
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
/** Submit a preimage. Returns the preimage key (hash) on success. */
|
|
748
|
+
async submit(request) {
|
|
749
|
+
const result = await this.transport.request({
|
|
750
|
+
ids: W.PREIMAGE_SUBMIT,
|
|
751
|
+
payload: T.VersionedRemotePreimageSubmitRequest.enc({
|
|
752
|
+
tag: "V1",
|
|
753
|
+
value: request,
|
|
754
|
+
}),
|
|
755
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
756
|
+
V1: [0, S.Result(S.Hex(), T.PreimageSubmitError)],
|
|
757
|
+
}).dec(payload).value,
|
|
758
|
+
});
|
|
759
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
/** Resource pre-allocation (allowance management). */
|
|
763
|
+
export class ResourceAllocationClient {
|
|
764
|
+
transport;
|
|
765
|
+
constructor(transport) {
|
|
766
|
+
this.transport = transport;
|
|
767
|
+
}
|
|
768
|
+
/** Request the host to pre-allocate one or more resources. */
|
|
769
|
+
async request(request) {
|
|
770
|
+
const result = await this.transport.request({
|
|
771
|
+
ids: W.RESOURCE_ALLOCATION_REQUEST,
|
|
772
|
+
payload: T.VersionedHostRequestResourceAllocationRequest.enc({
|
|
773
|
+
tag: "V1",
|
|
774
|
+
value: request,
|
|
775
|
+
}),
|
|
776
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
777
|
+
V1: [
|
|
778
|
+
0,
|
|
779
|
+
S.Result(T.HostRequestResourceAllocationResponse, T.ResourceAllocationError),
|
|
780
|
+
],
|
|
781
|
+
}).dec(payload).value,
|
|
782
|
+
});
|
|
783
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
/** Signing operations. */
|
|
787
|
+
export class SigningClient {
|
|
788
|
+
transport;
|
|
789
|
+
constructor(transport) {
|
|
790
|
+
this.transport = transport;
|
|
791
|
+
}
|
|
792
|
+
/** Construct a signed transaction for a product account. */
|
|
793
|
+
async createTransaction(request) {
|
|
794
|
+
const result = await this.transport.request({
|
|
795
|
+
ids: W.SIGNING_CREATE_TRANSACTION,
|
|
796
|
+
payload: T.VersionedHostCreateTransactionRequest.enc({
|
|
797
|
+
tag: "V1",
|
|
798
|
+
value: request,
|
|
799
|
+
}),
|
|
800
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
801
|
+
V1: [
|
|
802
|
+
0,
|
|
803
|
+
S.Result(T.HostCreateTransactionResponse, T.HostCreateTransactionError),
|
|
804
|
+
],
|
|
805
|
+
}).dec(payload).value,
|
|
806
|
+
});
|
|
807
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
808
|
+
}
|
|
809
|
+
/** Construct a signed transaction for a non-product account. */
|
|
810
|
+
async createTransactionWithLegacyAccount(request) {
|
|
811
|
+
const result = await this.transport.request({
|
|
812
|
+
ids: W.SIGNING_CREATE_TRANSACTION_WITH_LEGACY_ACCOUNT,
|
|
813
|
+
payload: T.VersionedHostCreateTransactionWithLegacyAccountRequest.enc({
|
|
814
|
+
tag: "V1",
|
|
815
|
+
value: request,
|
|
816
|
+
}),
|
|
817
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
818
|
+
V1: [
|
|
819
|
+
0,
|
|
820
|
+
S.Result(T.HostCreateTransactionWithLegacyAccountResponse, T.HostCreateTransactionError),
|
|
821
|
+
],
|
|
822
|
+
}).dec(payload).value,
|
|
823
|
+
});
|
|
824
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
825
|
+
}
|
|
826
|
+
/** Sign raw bytes with a non-product account. */
|
|
827
|
+
async signRawWithLegacyAccount(request) {
|
|
828
|
+
const result = await this.transport.request({
|
|
829
|
+
ids: W.SIGNING_SIGN_RAW_WITH_LEGACY_ACCOUNT,
|
|
830
|
+
payload: T.VersionedHostSignRawWithLegacyAccountRequest.enc({
|
|
831
|
+
tag: "V1",
|
|
832
|
+
value: request,
|
|
833
|
+
}),
|
|
834
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
835
|
+
V1: [
|
|
836
|
+
0,
|
|
837
|
+
S.Result(T.HostSignPayloadResponse, T.HostSignPayloadError),
|
|
838
|
+
],
|
|
839
|
+
}).dec(payload).value,
|
|
840
|
+
});
|
|
841
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
842
|
+
}
|
|
843
|
+
/** Sign an extrinsic payload with a non-product account. */
|
|
844
|
+
async signPayloadWithLegacyAccount(request) {
|
|
845
|
+
const result = await this.transport.request({
|
|
846
|
+
ids: W.SIGNING_SIGN_PAYLOAD_WITH_LEGACY_ACCOUNT,
|
|
847
|
+
payload: T.VersionedHostSignPayloadWithLegacyAccountRequest.enc({
|
|
848
|
+
tag: "V1",
|
|
849
|
+
value: request,
|
|
850
|
+
}),
|
|
851
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
852
|
+
V1: [
|
|
853
|
+
0,
|
|
854
|
+
S.Result(T.HostSignPayloadResponse, T.HostSignPayloadError),
|
|
855
|
+
],
|
|
856
|
+
}).dec(payload).value,
|
|
857
|
+
});
|
|
858
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
859
|
+
}
|
|
860
|
+
/** Sign raw bytes or a message. */
|
|
861
|
+
async signRaw(request) {
|
|
862
|
+
const result = await this.transport.request({
|
|
863
|
+
ids: W.SIGNING_SIGN_RAW,
|
|
864
|
+
payload: T.VersionedHostSignRawRequest.enc({ tag: "V1", value: request }),
|
|
865
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
866
|
+
V1: [
|
|
867
|
+
0,
|
|
868
|
+
S.Result(T.HostSignPayloadResponse, T.HostSignPayloadError),
|
|
869
|
+
],
|
|
870
|
+
}).dec(payload).value,
|
|
871
|
+
});
|
|
872
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
873
|
+
}
|
|
874
|
+
/** Sign an extrinsic payload. */
|
|
875
|
+
async signPayload(request) {
|
|
876
|
+
const result = await this.transport.request({
|
|
877
|
+
ids: W.SIGNING_SIGN_PAYLOAD,
|
|
878
|
+
payload: T.VersionedHostSignPayloadRequest.enc({
|
|
879
|
+
tag: "V1",
|
|
880
|
+
value: request,
|
|
881
|
+
}),
|
|
882
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
883
|
+
V1: [
|
|
884
|
+
0,
|
|
885
|
+
S.Result(T.HostSignPayloadResponse, T.HostSignPayloadError),
|
|
886
|
+
],
|
|
887
|
+
}).dec(payload).value,
|
|
888
|
+
});
|
|
889
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
/** Statement store methods. */
|
|
893
|
+
export class StatementStoreClient {
|
|
894
|
+
transport;
|
|
895
|
+
constructor(transport) {
|
|
896
|
+
this.transport = transport;
|
|
897
|
+
}
|
|
898
|
+
/** Subscribe to statements matching a topic filter. */
|
|
899
|
+
subscribe({ request, }) {
|
|
900
|
+
return createObservable({
|
|
901
|
+
transport: this.transport,
|
|
902
|
+
ids: W.STATEMENT_STORE_SUBSCRIBE,
|
|
903
|
+
payload: T.VersionedRemoteStatementStoreSubscribeRequest.enc({
|
|
904
|
+
tag: "V1",
|
|
905
|
+
value: request,
|
|
906
|
+
}),
|
|
907
|
+
decodeItem: (payload) => T.VersionedRemoteStatementStoreSubscribeItem.dec(payload).value,
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
/** Create a proof for a statement. */
|
|
911
|
+
async createProof(request) {
|
|
912
|
+
const result = await this.transport.request({
|
|
913
|
+
ids: W.STATEMENT_STORE_CREATE_PROOF,
|
|
914
|
+
payload: T.VersionedRemoteStatementStoreCreateProofRequest.enc({
|
|
915
|
+
tag: "V1",
|
|
916
|
+
value: request,
|
|
917
|
+
}),
|
|
918
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
919
|
+
V1: [
|
|
920
|
+
0,
|
|
921
|
+
S.Result(T.RemoteStatementStoreCreateProofResponse, T.RemoteStatementStoreCreateProofError),
|
|
922
|
+
],
|
|
923
|
+
}).dec(payload).value,
|
|
924
|
+
});
|
|
925
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Create a proof for a statement using a pre-allocated allowance account,
|
|
929
|
+
* bypassing the per-call signing prompt.
|
|
930
|
+
*/
|
|
931
|
+
async createProofAuthorized(request) {
|
|
932
|
+
const result = await this.transport.request({
|
|
933
|
+
ids: W.STATEMENT_STORE_CREATE_PROOF_AUTHORIZED,
|
|
934
|
+
payload: T.VersionedRemoteStatementStoreCreateProofAuthorizedRequest.enc({
|
|
935
|
+
tag: "V1",
|
|
936
|
+
value: request,
|
|
937
|
+
}),
|
|
938
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
939
|
+
V1: [
|
|
940
|
+
0,
|
|
941
|
+
S.Result(T.RemoteStatementStoreCreateProofResponse, T.RemoteStatementStoreCreateProofError),
|
|
942
|
+
],
|
|
943
|
+
}).dec(payload).value,
|
|
944
|
+
});
|
|
945
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Submit a signed statement to the network. The request body is the
|
|
949
|
+
* [`SignedStatement`](crate::v01::SignedStatement) directly (no wrapping
|
|
950
|
+
* struct), matching upstream `triangle-js-sdks`.
|
|
951
|
+
*/
|
|
952
|
+
async submit(request) {
|
|
953
|
+
const result = await this.transport.request({
|
|
954
|
+
ids: W.STATEMENT_STORE_SUBMIT,
|
|
955
|
+
payload: T.VersionedRemoteStatementStoreSubmitRequest.enc({
|
|
956
|
+
tag: "V1",
|
|
957
|
+
value: request,
|
|
958
|
+
}),
|
|
959
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
960
|
+
V1: [0, S.Result(S._void, T.GenericError)],
|
|
961
|
+
}).dec(payload).value,
|
|
962
|
+
});
|
|
963
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* General-purpose TrUAPI methods for handshake, feature detection,
|
|
968
|
+
* navigation, and notifications.
|
|
969
|
+
*/
|
|
970
|
+
export class SystemClient {
|
|
971
|
+
transport;
|
|
972
|
+
constructor(transport) {
|
|
973
|
+
this.transport = transport;
|
|
974
|
+
}
|
|
975
|
+
/** Negotiate the wire codec version with the product. */
|
|
976
|
+
async handshake() {
|
|
977
|
+
const result = await this.transport.request({
|
|
978
|
+
ids: W.SYSTEM_HANDSHAKE,
|
|
979
|
+
payload: T.VersionedHostHandshakeRequest.enc({
|
|
980
|
+
tag: "V1",
|
|
981
|
+
value: { codecVersion: this.transport.codecVersion },
|
|
982
|
+
}),
|
|
983
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
984
|
+
V1: [0, S.Result(S._void, T.HostHandshakeError)],
|
|
985
|
+
}).dec(payload).value,
|
|
986
|
+
});
|
|
987
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
988
|
+
}
|
|
989
|
+
/** Query whether the host supports a specific feature. */
|
|
990
|
+
async featureSupported(request) {
|
|
991
|
+
const result = await this.transport.request({
|
|
992
|
+
ids: W.SYSTEM_FEATURE_SUPPORTED,
|
|
993
|
+
payload: T.VersionedHostFeatureSupportedRequest.enc({
|
|
994
|
+
tag: "V1",
|
|
995
|
+
value: request,
|
|
996
|
+
}),
|
|
997
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
998
|
+
V1: [
|
|
999
|
+
0,
|
|
1000
|
+
S.Result(T.HostFeatureSupportedResponse, T.GenericError),
|
|
1001
|
+
],
|
|
1002
|
+
}).dec(payload).value,
|
|
1003
|
+
});
|
|
1004
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
1005
|
+
}
|
|
1006
|
+
/** Send a push notification to the user. */
|
|
1007
|
+
async pushNotification(request) {
|
|
1008
|
+
const result = await this.transport.request({
|
|
1009
|
+
ids: W.SYSTEM_PUSH_NOTIFICATION,
|
|
1010
|
+
payload: T.VersionedHostPushNotificationRequest.enc({
|
|
1011
|
+
tag: "V1",
|
|
1012
|
+
value: request,
|
|
1013
|
+
}),
|
|
1014
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
1015
|
+
V1: [0, S.Result(S._void, T.GenericError)],
|
|
1016
|
+
}).dec(payload).value,
|
|
1017
|
+
});
|
|
1018
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
1019
|
+
}
|
|
1020
|
+
/** Request the host to open a URL. */
|
|
1021
|
+
async navigateTo(request) {
|
|
1022
|
+
const result = await this.transport.request({
|
|
1023
|
+
ids: W.SYSTEM_NAVIGATE_TO,
|
|
1024
|
+
payload: T.VersionedHostNavigateToRequest.enc({
|
|
1025
|
+
tag: "V1",
|
|
1026
|
+
value: request,
|
|
1027
|
+
}),
|
|
1028
|
+
decodeResponse: (payload) => S.indexedTaggedUnion({
|
|
1029
|
+
V1: [0, S.Result(S._void, T.HostNavigateToError)],
|
|
1030
|
+
}).dec(payload).value,
|
|
1031
|
+
});
|
|
1032
|
+
return result.success ? ok(result.value) : err(result.value);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
/** Host theme subscription. */
|
|
1036
|
+
export class ThemeClient {
|
|
1037
|
+
transport;
|
|
1038
|
+
constructor(transport) {
|
|
1039
|
+
this.transport = transport;
|
|
1040
|
+
}
|
|
1041
|
+
/** Subscribe to host theme changes. */
|
|
1042
|
+
subscribe() {
|
|
1043
|
+
return createObservable({
|
|
1044
|
+
transport: this.transport,
|
|
1045
|
+
ids: W.THEME_SUBSCRIBE,
|
|
1046
|
+
payload: S.indexedTaggedUnion({ V1: [0, S._void] }).enc({
|
|
1047
|
+
tag: "V1",
|
|
1048
|
+
value: undefined,
|
|
1049
|
+
}),
|
|
1050
|
+
decodeItem: (payload) => T.VersionedHostThemeSubscribeItem.dec(payload).value,
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
function withGeneratedTransportVersions(transport) {
|
|
1055
|
+
return {
|
|
1056
|
+
...transport,
|
|
1057
|
+
truapiVersion: transport.truapiVersion ?? TRUAPI_VERSION,
|
|
1058
|
+
codecVersion: transport.codecVersion ?? TRUAPI_CODEC_VERSION,
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
/** Creates the generated client facade by binding each service namespace to the
|
|
1062
|
+
* shared transport instance. */
|
|
1063
|
+
export function createClient(transport) {
|
|
1064
|
+
const versionedTransport = withGeneratedTransportVersions(transport);
|
|
1065
|
+
return {
|
|
1066
|
+
account: new AccountClient(versionedTransport),
|
|
1067
|
+
chain: new ChainClient(versionedTransport),
|
|
1068
|
+
chat: new ChatClient(versionedTransport),
|
|
1069
|
+
entropy: new EntropyClient(versionedTransport),
|
|
1070
|
+
jsonRpc: new JsonRpcClient(versionedTransport),
|
|
1071
|
+
localStorage: new LocalStorageClient(versionedTransport),
|
|
1072
|
+
payment: new PaymentClient(versionedTransport),
|
|
1073
|
+
permissions: new PermissionsClient(versionedTransport),
|
|
1074
|
+
preimage: new PreimageClient(versionedTransport),
|
|
1075
|
+
resourceAllocation: new ResourceAllocationClient(versionedTransport),
|
|
1076
|
+
signing: new SigningClient(versionedTransport),
|
|
1077
|
+
statementStore: new StatementStoreClient(versionedTransport),
|
|
1078
|
+
system: new SystemClient(versionedTransport),
|
|
1079
|
+
theme: new ThemeClient(versionedTransport),
|
|
1080
|
+
};
|
|
1081
|
+
}
|