@parity/product-sdk-host 0.15.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chain-discovery-BEvu7HaV.d.ts +107 -0
- package/dist/chunk-PAKEUP2Q.js +89 -0
- package/dist/chunk-PAKEUP2Q.js.map +1 -0
- package/dist/index.d.ts +108 -16
- package/dist/index.js +266 -56
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +39 -8
- package/dist/testing.js +26 -7
- package/dist/testing.js.map +1 -1
- package/package.json +4 -4
- package/src/accounts.ts +485 -43
- package/src/chain-discovery.ts +287 -0
- package/src/chains.ts +10 -3
- package/src/index.ts +17 -1
- package/src/papi-provider.ts +370 -37
- package/src/payments.ts +1 -1
- package/src/testing.ts +115 -13
- package/src/transport.ts +228 -4
- package/src/truapi.ts +3 -2
- package/dist/chunk-GDXSV7JV.js +0 -50
- package/dist/chunk-GDXSV7JV.js.map +0 -1
- package/dist/transport-B0cdhwrp.d.ts +0 -31
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getClient, isCorrectEnvironment, subscribeWithInterrupt } from './chunk-
|
|
2
|
-
export { isCorrectEnvironment as isInsideContainerSync } from './chunk-
|
|
1
|
+
import { getClient, isCorrectEnvironment, subscribeWithInterrupt } from './chunk-PAKEUP2Q.js';
|
|
2
|
+
export { isCorrectEnvironment as isInsideContainerSync, subscribeConnectionStatus } from './chunk-PAKEUP2Q.js';
|
|
3
3
|
import { createLogger } from '@parity/product-sdk-logger';
|
|
4
4
|
import { scale } from '@parity/truapi';
|
|
5
5
|
import { err, ok } from '@parity/result';
|
|
@@ -68,6 +68,23 @@ function isHostError(error) {
|
|
|
68
68
|
var log = createLogger("host:papi");
|
|
69
69
|
var JSON_RPC_INTERNAL_ERROR = -32603;
|
|
70
70
|
var JSON_RPC_METHOD_NOT_FOUND = -32601;
|
|
71
|
+
function followOperationId(item) {
|
|
72
|
+
switch (item.tag) {
|
|
73
|
+
case "OperationBodyDone":
|
|
74
|
+
case "OperationCallDone":
|
|
75
|
+
case "OperationStorageItems":
|
|
76
|
+
case "OperationStorageDone":
|
|
77
|
+
case "OperationWaitingForContinue":
|
|
78
|
+
case "OperationInaccessible":
|
|
79
|
+
case "OperationError":
|
|
80
|
+
return item.value.operationId;
|
|
81
|
+
default:
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function isTerminalOperationItem(item) {
|
|
86
|
+
return item.tag === "OperationBodyDone" || item.tag === "OperationCallDone" || item.tag === "OperationStorageDone" || item.tag === "OperationInaccessible" || item.tag === "OperationError";
|
|
87
|
+
}
|
|
71
88
|
var STORAGE_TYPE_MAP = {
|
|
72
89
|
value: "Value",
|
|
73
90
|
hash: "Hash",
|
|
@@ -174,6 +191,8 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
174
191
|
return (onMessage) => {
|
|
175
192
|
const activeFollows = /* @__PURE__ */ new Map();
|
|
176
193
|
const activeBroadcasts = /* @__PURE__ */ new Set();
|
|
194
|
+
const followOperations = /* @__PURE__ */ new Map();
|
|
195
|
+
const pendingOperationStarts = /* @__PURE__ */ new Map();
|
|
177
196
|
function sendJsonRpcResponse(id, result) {
|
|
178
197
|
onMessage({ jsonrpc: "2.0", id, result });
|
|
179
198
|
}
|
|
@@ -187,6 +206,72 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
187
206
|
params: { subscription, result: event }
|
|
188
207
|
});
|
|
189
208
|
}
|
|
209
|
+
function forwardFollowItem(followSubscriptionId, item) {
|
|
210
|
+
const operationId = followOperationId(item);
|
|
211
|
+
if (operationId === void 0) {
|
|
212
|
+
sendFollowEvent(followSubscriptionId, convertFollowEventToJsonRpc(item));
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const operations = followOperations.get(followSubscriptionId);
|
|
216
|
+
if (!operations) return;
|
|
217
|
+
let operation = operations.get(operationId);
|
|
218
|
+
if (!operation) {
|
|
219
|
+
if ((pendingOperationStarts.get(followSubscriptionId) ?? 0) === 0) {
|
|
220
|
+
sendFollowEvent(followSubscriptionId, convertFollowEventToJsonRpc(item));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
operation = { announced: false, items: [] };
|
|
224
|
+
operations.set(operationId, operation);
|
|
225
|
+
}
|
|
226
|
+
if (!operation.announced) {
|
|
227
|
+
operation.items.push(item);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
sendFollowEvent(followSubscriptionId, convertFollowEventToJsonRpc(item));
|
|
231
|
+
if (isTerminalOperationItem(item)) {
|
|
232
|
+
operations.delete(operationId);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function sendOperationStartedResponse(id, followSubscriptionId, result) {
|
|
236
|
+
sendJsonRpcResponse(id, convertOperationResultToJsonRpc(result));
|
|
237
|
+
if (result.tag !== "Started") return;
|
|
238
|
+
const operations = followOperations.get(followSubscriptionId);
|
|
239
|
+
if (!operations) return;
|
|
240
|
+
const operationId = result.value.operationId;
|
|
241
|
+
let operation = operations.get(operationId);
|
|
242
|
+
if (!operation) {
|
|
243
|
+
operation = { announced: true, items: [] };
|
|
244
|
+
operations.set(operationId, operation);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
operation.announced = true;
|
|
248
|
+
const pendingItems = operation.items;
|
|
249
|
+
operation.items = [];
|
|
250
|
+
for (const item of pendingItems) {
|
|
251
|
+
forwardFollowItem(followSubscriptionId, item);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function startOperationRequest(id, followSubscriptionId) {
|
|
255
|
+
const pending = pendingOperationStarts.get(followSubscriptionId);
|
|
256
|
+
if (pending !== void 0) {
|
|
257
|
+
pendingOperationStarts.set(followSubscriptionId, pending + 1);
|
|
258
|
+
}
|
|
259
|
+
const settle = () => {
|
|
260
|
+
const outstanding = pendingOperationStarts.get(followSubscriptionId);
|
|
261
|
+
if (outstanding === void 0) return;
|
|
262
|
+
pendingOperationStarts.set(followSubscriptionId, Math.max(0, outstanding - 1));
|
|
263
|
+
};
|
|
264
|
+
return {
|
|
265
|
+
ok: (response) => {
|
|
266
|
+
settle();
|
|
267
|
+
sendOperationStartedResponse(id, followSubscriptionId, response.operation);
|
|
268
|
+
},
|
|
269
|
+
err: (error) => {
|
|
270
|
+
settle();
|
|
271
|
+
hostError(id)(error);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
190
275
|
const hostError = (id) => (error) => sendJsonRpcError(id, JSON_RPC_INTERNAL_ERROR, formatHostError(error));
|
|
191
276
|
function handleMessage(message) {
|
|
192
277
|
const { id, method } = message;
|
|
@@ -199,8 +284,10 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
199
284
|
const forwardItem = (followSubscriptionId2, item) => {
|
|
200
285
|
if (item.tag === "Stop" && activeFollows.delete(followSubscriptionId2)) {
|
|
201
286
|
ref.handle?.unsubscribe();
|
|
287
|
+
followOperations.delete(followSubscriptionId2);
|
|
288
|
+
pendingOperationStarts.delete(followSubscriptionId2);
|
|
202
289
|
}
|
|
203
|
-
|
|
290
|
+
forwardFollowItem(followSubscriptionId2, item);
|
|
204
291
|
};
|
|
205
292
|
ref.handle = subscribeWithInterrupt(
|
|
206
293
|
chain.followHeadSubscribe({ request: { genesisHash, withRuntime } }),
|
|
@@ -224,11 +311,15 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
224
311
|
break;
|
|
225
312
|
}
|
|
226
313
|
ref.handle.onInterrupt(() => {
|
|
314
|
+
followOperations.delete(followSubscriptionId);
|
|
315
|
+
pendingOperationStarts.delete(followSubscriptionId);
|
|
227
316
|
if (activeFollows.delete(followSubscriptionId)) {
|
|
228
317
|
sendFollowEvent(followSubscriptionId, { event: "stop" });
|
|
229
318
|
}
|
|
230
319
|
});
|
|
231
320
|
activeFollows.set(followSubscriptionId, ref.handle);
|
|
321
|
+
followOperations.set(followSubscriptionId, /* @__PURE__ */ new Map());
|
|
322
|
+
pendingOperationStarts.set(followSubscriptionId, 0);
|
|
232
323
|
sendJsonRpcResponse(id, followSubscriptionId);
|
|
233
324
|
for (const item of pendingItems) {
|
|
234
325
|
forwardItem(followSubscriptionId, item);
|
|
@@ -242,6 +333,8 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
242
333
|
follow.unsubscribe();
|
|
243
334
|
activeFollows.delete(followSubId);
|
|
244
335
|
}
|
|
336
|
+
followOperations.delete(followSubId);
|
|
337
|
+
pendingOperationStarts.delete(followSubId);
|
|
245
338
|
sendJsonRpcResponse(id, null);
|
|
246
339
|
break;
|
|
247
340
|
}
|
|
@@ -255,13 +348,8 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
255
348
|
}
|
|
256
349
|
case "chainHead_v1_body": {
|
|
257
350
|
const [followSubscriptionId, hash] = params;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
id,
|
|
261
|
-
convertOperationResultToJsonRpc(response.operation)
|
|
262
|
-
),
|
|
263
|
-
hostError(id)
|
|
264
|
-
);
|
|
351
|
+
const bodyStart = startOperationRequest(id, followSubscriptionId);
|
|
352
|
+
chain.getHeadBody({ genesisHash, followSubscriptionId, hash }).match(bodyStart.ok, bodyStart.err);
|
|
265
353
|
break;
|
|
266
354
|
}
|
|
267
355
|
case "chainHead_v1_storage": {
|
|
@@ -270,6 +358,7 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
270
358
|
key: item.key,
|
|
271
359
|
queryType: convertStorageType(item.type)
|
|
272
360
|
}));
|
|
361
|
+
const storageStart = startOperationRequest(id, followSubscriptionId);
|
|
273
362
|
chain.getHeadStorage({
|
|
274
363
|
genesisHash,
|
|
275
364
|
followSubscriptionId,
|
|
@@ -281,30 +370,19 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
281
370
|
// the inner Hex codec on `null`, which throws
|
|
282
371
|
// (`null.startsWith`). Coerce `null` → `undefined`.
|
|
283
372
|
childTrie: childTrie ?? void 0
|
|
284
|
-
}).match(
|
|
285
|
-
(response) => sendJsonRpcResponse(
|
|
286
|
-
id,
|
|
287
|
-
convertOperationResultToJsonRpc(response.operation)
|
|
288
|
-
),
|
|
289
|
-
hostError(id)
|
|
290
|
-
);
|
|
373
|
+
}).match(storageStart.ok, storageStart.err);
|
|
291
374
|
break;
|
|
292
375
|
}
|
|
293
376
|
case "chainHead_v1_call": {
|
|
294
377
|
const [followSubscriptionId, hash, fn, callParameters] = params;
|
|
378
|
+
const callStart = startOperationRequest(id, followSubscriptionId);
|
|
295
379
|
chain.callHead({
|
|
296
380
|
genesisHash,
|
|
297
381
|
followSubscriptionId,
|
|
298
382
|
hash,
|
|
299
383
|
function: fn,
|
|
300
384
|
callParameters
|
|
301
|
-
}).match(
|
|
302
|
-
(response) => sendJsonRpcResponse(
|
|
303
|
-
id,
|
|
304
|
-
convertOperationResultToJsonRpc(response.operation)
|
|
305
|
-
),
|
|
306
|
-
hostError(id)
|
|
307
|
-
);
|
|
385
|
+
}).match(callStart.ok, callStart.err);
|
|
308
386
|
break;
|
|
309
387
|
}
|
|
310
388
|
case "chainHead_v1_unpin": {
|
|
@@ -320,7 +398,10 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
320
398
|
}
|
|
321
399
|
case "chainHead_v1_stopOperation": {
|
|
322
400
|
const [followSubscriptionId, operationId] = params;
|
|
323
|
-
chain.stopHeadOperation({ genesisHash, followSubscriptionId, operationId }).match(() =>
|
|
401
|
+
chain.stopHeadOperation({ genesisHash, followSubscriptionId, operationId }).match(() => {
|
|
402
|
+
followOperations.get(followSubscriptionId)?.delete(operationId);
|
|
403
|
+
sendJsonRpcResponse(id, null);
|
|
404
|
+
}, hostError(id));
|
|
324
405
|
break;
|
|
325
406
|
}
|
|
326
407
|
case "chainSpec_v1_genesisHash": {
|
|
@@ -387,6 +468,8 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
387
468
|
handle.unsubscribe();
|
|
388
469
|
}
|
|
389
470
|
activeFollows.clear();
|
|
471
|
+
followOperations.clear();
|
|
472
|
+
pendingOperationStarts.clear();
|
|
390
473
|
for (const operationId of activeBroadcasts) {
|
|
391
474
|
chain.stopTransaction({ genesisHash, operationId }).match(
|
|
392
475
|
() => {
|
|
@@ -575,18 +658,109 @@ async function getStatementStore() {
|
|
|
575
658
|
// src/chains.ts
|
|
576
659
|
var BULLETIN_RPCS = {
|
|
577
660
|
paseo: ["wss://paseo-bulletin-next-rpc.polkadot.io"],
|
|
661
|
+
previewnet: ["wss://previewnet.substrate.dev/bulletin"],
|
|
578
662
|
devnet: ["wss://bulletin-paseo.tservices.es:8443"],
|
|
579
663
|
polkadot: [],
|
|
580
664
|
kusama: []
|
|
581
665
|
};
|
|
582
666
|
var DEFAULT_BULLETIN_ENDPOINT = BULLETIN_RPCS.paseo[0];
|
|
583
|
-
|
|
584
|
-
|
|
667
|
+
var log3 = createLogger("host");
|
|
668
|
+
var TRANSIENT_FAILURE = /* @__PURE__ */ Symbol("transient-failure");
|
|
669
|
+
var PROBE_TIMEOUT_MS = 3e3;
|
|
670
|
+
var discoveryCache = /* @__PURE__ */ new WeakMap();
|
|
671
|
+
async function getHostChainInfo(identifiers) {
|
|
672
|
+
const client = await getClient();
|
|
673
|
+
if (!client) return null;
|
|
674
|
+
let bySet = discoveryCache.get(client);
|
|
675
|
+
if (!bySet) {
|
|
676
|
+
bySet = /* @__PURE__ */ new Map();
|
|
677
|
+
discoveryCache.set(client, bySet);
|
|
678
|
+
}
|
|
679
|
+
const key = [...identifiers].sort().join(",");
|
|
680
|
+
let cached = bySet.get(key);
|
|
681
|
+
if (!cached) {
|
|
682
|
+
cached = fetchChainInfo(client, identifiers).then((result) => {
|
|
683
|
+
if (result === TRANSIENT_FAILURE) {
|
|
684
|
+
bySet.delete(key);
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
return result;
|
|
688
|
+
});
|
|
689
|
+
bySet.set(key, cached);
|
|
690
|
+
}
|
|
691
|
+
return cached;
|
|
692
|
+
}
|
|
693
|
+
async function fetchChainInfo(client, identifiers) {
|
|
694
|
+
try {
|
|
695
|
+
let timer;
|
|
696
|
+
const probe = Promise.all(
|
|
697
|
+
identifiers.map(
|
|
698
|
+
(id) => client.chain.getChainInfo({ chain: id }).match(
|
|
699
|
+
(value) => ({ id, ok: value }),
|
|
700
|
+
(error) => ({ id, err: error })
|
|
701
|
+
)
|
|
702
|
+
)
|
|
703
|
+
);
|
|
704
|
+
const outcomes = await Promise.race([
|
|
705
|
+
probe,
|
|
706
|
+
new Promise((resolve) => {
|
|
707
|
+
timer = setTimeout(() => resolve("timeout"), PROBE_TIMEOUT_MS);
|
|
708
|
+
})
|
|
709
|
+
]).finally(() => clearTimeout(timer));
|
|
710
|
+
if (outcomes === "timeout") {
|
|
711
|
+
log3.warn("getChainInfo probe timed out, treating the host as pre-discovery for now");
|
|
712
|
+
return TRANSIENT_FAILURE;
|
|
713
|
+
}
|
|
714
|
+
let network;
|
|
715
|
+
const chains = {};
|
|
716
|
+
for (const outcome of outcomes) {
|
|
717
|
+
if ("ok" in outcome) {
|
|
718
|
+
network = outcome.ok.network;
|
|
719
|
+
chains[outcome.id] = outcome.ok.genesisHash;
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
if (outcome.err.tag === "Unsupported") return null;
|
|
723
|
+
if (isNotSupported(outcome.err)) continue;
|
|
724
|
+
log3.warn(`getChainInfo failed: ${formatHostError(outcome.err)}`);
|
|
725
|
+
return TRANSIENT_FAILURE;
|
|
726
|
+
}
|
|
727
|
+
if (network === void 0) return null;
|
|
728
|
+
return { network, chains };
|
|
729
|
+
} catch (error) {
|
|
730
|
+
log3.warn(`getChainInfo failed: ${formatHostError(error)}`);
|
|
731
|
+
return TRANSIENT_FAILURE;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
function isNotSupported(error) {
|
|
735
|
+
return error.tag === "Domain" && error.value.value.tag === "NotSupported";
|
|
736
|
+
}
|
|
737
|
+
function sameRingLocation(a, b) {
|
|
738
|
+
if (a.chainId.toLowerCase() !== b.chainId.toLowerCase() || a.junctions.length !== b.junctions.length) {
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
return a.junctions.every((junction, index) => {
|
|
742
|
+
const candidate = b.junctions[index];
|
|
743
|
+
if (junction.tag === "PalletInstance") {
|
|
744
|
+
return candidate.tag === "PalletInstance" && junction.value === candidate.value;
|
|
745
|
+
}
|
|
746
|
+
return candidate.tag === "CollectionId" && junction.value.toLowerCase() === candidate.value.toLowerCase();
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
function findRingVrfKeyHandle(keys, ring) {
|
|
750
|
+
return keys.find((key) => key.rings.some((candidate) => sameRingLocation(candidate, ring)))?.handle;
|
|
751
|
+
}
|
|
752
|
+
function selectHostTxExtVersion(versions) {
|
|
585
753
|
if (versions.length === 0) {
|
|
586
754
|
throw new Error("No extrinsic version found in metadata");
|
|
587
755
|
}
|
|
588
|
-
|
|
589
|
-
|
|
756
|
+
if (versions.includes(4)) {
|
|
757
|
+
return 0;
|
|
758
|
+
}
|
|
759
|
+
return versions.reduce((acc, version) => Math.max(acc, version), 0);
|
|
760
|
+
}
|
|
761
|
+
function deriveTxExtVersion(metadata) {
|
|
762
|
+
const versions = unifyMetadata(decAnyMetadata(metadata)).extrinsic.version;
|
|
763
|
+
return selectHostTxExtVersion(versions);
|
|
590
764
|
}
|
|
591
765
|
var deps = { deriveTxExtVersion };
|
|
592
766
|
function toHostExtensions(signedExtensions) {
|
|
@@ -596,8 +770,11 @@ function toHostExtensions(signedExtensions) {
|
|
|
596
770
|
additionalSigned: toHex(ext.additionalSigned)
|
|
597
771
|
}));
|
|
598
772
|
}
|
|
599
|
-
function toWireProductAccountId(
|
|
600
|
-
|
|
773
|
+
function toWireProductAccountId({
|
|
774
|
+
dotNsIdentifier,
|
|
775
|
+
derivationIndex = 0
|
|
776
|
+
}) {
|
|
777
|
+
return { dotNsIdentifier, derivationIndex: { tag: "Index", value: derivationIndex } };
|
|
601
778
|
}
|
|
602
779
|
function adaptAccountsProvider(client) {
|
|
603
780
|
const account = client.account;
|
|
@@ -613,15 +790,31 @@ function adaptAccountsProvider(client) {
|
|
|
613
790
|
},
|
|
614
791
|
getProductAccount(dotNsIdentifier, derivationIndex = 0) {
|
|
615
792
|
return account.getAccount({
|
|
616
|
-
productAccountId: toWireProductAccountId(dotNsIdentifier, derivationIndex)
|
|
793
|
+
productAccountId: toWireProductAccountId({ dotNsIdentifier, derivationIndex })
|
|
617
794
|
}).map((response) => ({
|
|
618
795
|
publicKey: fromHex(response.account.publicKey),
|
|
619
796
|
dotNsIdentifier,
|
|
620
797
|
derivationIndex
|
|
621
798
|
}));
|
|
622
799
|
},
|
|
623
|
-
|
|
624
|
-
return account.
|
|
800
|
+
registerRingVrfKey(index, ring) {
|
|
801
|
+
return account.registerRingVrfKey({ index: { tag: "Index", value: index }, ring }).map(fromHex);
|
|
802
|
+
},
|
|
803
|
+
listRingVrfKeys(owner, disclosure = "Anonymized") {
|
|
804
|
+
return account.listRingVrfKeys({ owner, disclosure }).map(
|
|
805
|
+
(keys) => keys.map((key) => ({
|
|
806
|
+
...key,
|
|
807
|
+
handle: key.handle,
|
|
808
|
+
publicKey: key.publicKey === void 0 ? void 0 : fromHex(key.publicKey)
|
|
809
|
+
}))
|
|
810
|
+
);
|
|
811
|
+
},
|
|
812
|
+
getProductAccountAlias(keyHandle, context, location) {
|
|
813
|
+
return account.getAccountAlias({
|
|
814
|
+
keyHandle,
|
|
815
|
+
context,
|
|
816
|
+
ringLocation: location
|
|
817
|
+
}).map((response) => ({
|
|
625
818
|
context: fromHex(response.context),
|
|
626
819
|
alias: fromHex(response.alias)
|
|
627
820
|
}));
|
|
@@ -634,8 +827,9 @@ function adaptAccountsProvider(client) {
|
|
|
634
827
|
}))
|
|
635
828
|
);
|
|
636
829
|
},
|
|
637
|
-
createRingVRFProof(context, location, message) {
|
|
830
|
+
createRingVRFProof(keyHandle, context, location, message) {
|
|
638
831
|
return account.createAccountProof({
|
|
832
|
+
keyHandle,
|
|
639
833
|
context,
|
|
640
834
|
ringLocation: location,
|
|
641
835
|
message: toHex(message)
|
|
@@ -649,11 +843,27 @@ function adaptAccountsProvider(client) {
|
|
|
649
843
|
ringRevision: response.ringRevision
|
|
650
844
|
}));
|
|
651
845
|
},
|
|
846
|
+
ringVrfSign(keyHandle, message) {
|
|
847
|
+
return account.ringVrfSign({
|
|
848
|
+
keyHandle,
|
|
849
|
+
message: toHex(message)
|
|
850
|
+
}).map(fromHex);
|
|
851
|
+
},
|
|
852
|
+
signVrf(account_, transcriptLabel, items) {
|
|
853
|
+
return account.signVrf({
|
|
854
|
+
account: toWireProductAccountId(account_),
|
|
855
|
+
transcriptLabel: toHex(transcriptLabel),
|
|
856
|
+
items: items.map(({ label, value }) => ({
|
|
857
|
+
label: toHex(label),
|
|
858
|
+
value: toHex(value)
|
|
859
|
+
}))
|
|
860
|
+
}).map((response) => ({
|
|
861
|
+
preOutput: fromHex(response.preOutput),
|
|
862
|
+
proof: fromHex(response.proof)
|
|
863
|
+
}));
|
|
864
|
+
},
|
|
652
865
|
getProductAccountSigner(account_) {
|
|
653
|
-
const productAccountId = toWireProductAccountId(
|
|
654
|
-
account_.dotNsIdentifier,
|
|
655
|
-
account_.derivationIndex
|
|
656
|
-
);
|
|
866
|
+
const productAccountId = toWireProductAccountId(account_);
|
|
657
867
|
return {
|
|
658
868
|
publicKey: account_.publicKey,
|
|
659
869
|
async signTx(callData, signedExtensions, metadata) {
|
|
@@ -728,13 +938,13 @@ async function getAccountsProvider() {
|
|
|
728
938
|
const client = await getClient();
|
|
729
939
|
return client ? adaptAccountsProvider(client) : null;
|
|
730
940
|
}
|
|
731
|
-
var
|
|
941
|
+
var log4 = createLogger("host:permissions");
|
|
732
942
|
async function requestPermission(permission) {
|
|
733
943
|
const truApi = await getTruApi();
|
|
734
944
|
if (!truApi) {
|
|
735
945
|
return err(new HostUnavailableError("requestPermission: TruAPI unavailable"));
|
|
736
946
|
}
|
|
737
|
-
|
|
947
|
+
log4.debug("requestPermission", { tag: permission.tag });
|
|
738
948
|
return mapHostResult(
|
|
739
949
|
truApi.permissions.requestRemotePermission({ permission }),
|
|
740
950
|
(response) => response.granted,
|
|
@@ -746,7 +956,7 @@ async function requestDevicePermission(permission) {
|
|
|
746
956
|
if (!truApi) {
|
|
747
957
|
return err(new HostUnavailableError("requestDevicePermission: TruAPI unavailable"));
|
|
748
958
|
}
|
|
749
|
-
|
|
959
|
+
log4.debug("requestDevicePermission", { permission });
|
|
750
960
|
return mapHostResult(
|
|
751
961
|
truApi.permissions.requestDevicePermission(permission),
|
|
752
962
|
(response) => response.granted,
|
|
@@ -766,13 +976,13 @@ async function getThemeProvider() {
|
|
|
766
976
|
const client = await getClient();
|
|
767
977
|
return client ? adaptThemeProvider(client) : null;
|
|
768
978
|
}
|
|
769
|
-
var
|
|
979
|
+
var log5 = createLogger("host:entropy");
|
|
770
980
|
async function deriveEntropy(key) {
|
|
771
981
|
const truApi = await getTruApi();
|
|
772
982
|
if (!truApi) {
|
|
773
983
|
return err(new HostUnavailableError("deriveEntropy: TruAPI unavailable"));
|
|
774
984
|
}
|
|
775
|
-
|
|
985
|
+
log5.debug("deriveEntropy", { keyLen: key.length });
|
|
776
986
|
return mapHostResult(
|
|
777
987
|
truApi.entropy.derive({ context: toHex(key) }),
|
|
778
988
|
(response) => fromHex(response.entropy),
|
|
@@ -885,22 +1095,22 @@ async function getNotificationManager() {
|
|
|
885
1095
|
const client = await getClient();
|
|
886
1096
|
return client ? adaptNotificationManager(client) : null;
|
|
887
1097
|
}
|
|
888
|
-
var
|
|
1098
|
+
var log6 = createLogger("host:navigation");
|
|
889
1099
|
async function navigateTo(url) {
|
|
890
1100
|
const truApi = await getTruApi();
|
|
891
1101
|
if (!truApi) {
|
|
892
1102
|
return err(new HostUnavailableError("navigateTo: TruAPI unavailable"));
|
|
893
1103
|
}
|
|
894
|
-
|
|
1104
|
+
log6.debug("navigateTo", { url });
|
|
895
1105
|
return mapHostResult(truApi.system.navigateTo({ url }), () => void 0, "navigateTo failed");
|
|
896
1106
|
}
|
|
897
|
-
var
|
|
1107
|
+
var log7 = createLogger("host:features");
|
|
898
1108
|
async function featureSupported(feature) {
|
|
899
1109
|
const truApi = await getTruApi();
|
|
900
1110
|
if (!truApi) {
|
|
901
1111
|
return err(new HostUnavailableError("featureSupported: TruAPI unavailable"));
|
|
902
1112
|
}
|
|
903
|
-
|
|
1113
|
+
log7.debug("featureSupported", { tag: feature.tag });
|
|
904
1114
|
return mapHostResult(
|
|
905
1115
|
truApi.system.featureSupported({ tag: feature.tag, value: { genesisHash: feature.value } }),
|
|
906
1116
|
(response) => response.supported,
|
|
@@ -910,14 +1120,14 @@ async function featureSupported(feature) {
|
|
|
910
1120
|
async function isChainSupported(genesisHash) {
|
|
911
1121
|
return featureSupported({ tag: "Chain", value: genesisHash });
|
|
912
1122
|
}
|
|
913
|
-
var
|
|
1123
|
+
var log8 = createLogger("host:chain-spec");
|
|
914
1124
|
async function getChainSpec(genesisHash) {
|
|
915
1125
|
const truApi = await getTruApi();
|
|
916
1126
|
if (!truApi) {
|
|
917
|
-
|
|
1127
|
+
log8.debug("getChainSpec: TruAPI unavailable");
|
|
918
1128
|
return ok(null);
|
|
919
1129
|
}
|
|
920
|
-
|
|
1130
|
+
log8.debug("getChainSpec", { genesisHash });
|
|
921
1131
|
const [genesisHashResult, nameResult, propertiesResult] = await Promise.all([
|
|
922
1132
|
mapHostResult(
|
|
923
1133
|
truApi.chain.getSpecGenesisHash({ genesisHash }),
|
|
@@ -943,7 +1153,7 @@ async function getChainSpec(genesisHash) {
|
|
|
943
1153
|
try {
|
|
944
1154
|
properties = JSON.parse(propertiesRaw);
|
|
945
1155
|
} catch (parseError) {
|
|
946
|
-
|
|
1156
|
+
log8.debug("getChainSpec: properties JSON parse failed", parseError);
|
|
947
1157
|
properties = null;
|
|
948
1158
|
}
|
|
949
1159
|
return ok({
|
|
@@ -953,13 +1163,13 @@ async function getChainSpec(genesisHash) {
|
|
|
953
1163
|
propertiesRaw
|
|
954
1164
|
});
|
|
955
1165
|
}
|
|
956
|
-
var
|
|
1166
|
+
var log9 = createLogger("host:chain-transaction");
|
|
957
1167
|
async function broadcastTransaction(genesisHash, transaction) {
|
|
958
1168
|
const truApi = await getTruApi();
|
|
959
1169
|
if (!truApi) {
|
|
960
1170
|
return err(new HostUnavailableError("broadcastTransaction: TruAPI unavailable"));
|
|
961
1171
|
}
|
|
962
|
-
|
|
1172
|
+
log9.debug("broadcastTransaction", { genesisHash });
|
|
963
1173
|
return mapHostResult(
|
|
964
1174
|
truApi.chain.broadcastTransaction({ genesisHash, transaction }),
|
|
965
1175
|
(response) => response.operationId ?? null,
|
|
@@ -971,7 +1181,7 @@ async function stopTransaction(genesisHash, operationId) {
|
|
|
971
1181
|
if (!truApi) {
|
|
972
1182
|
return err(new HostUnavailableError("stopTransaction: TruAPI unavailable"));
|
|
973
1183
|
}
|
|
974
|
-
|
|
1184
|
+
log9.debug("stopTransaction", { genesisHash, operationId });
|
|
975
1185
|
return mapHostResult(
|
|
976
1186
|
truApi.chain.stopTransaction({ genesisHash, operationId }),
|
|
977
1187
|
() => void 0,
|
|
@@ -979,6 +1189,6 @@ async function stopTransaction(genesisHash, operationId) {
|
|
|
979
1189
|
);
|
|
980
1190
|
}
|
|
981
1191
|
|
|
982
|
-
export { BULLETIN_RPCS, ChainNotSupportedError, DEFAULT_BULLETIN_ENDPOINT, HostCallFailedError, HostError, HostUnavailableError, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, formatHostError, fromHex, getAccountsProvider, getChainSpec, getChatManager, getHostLocalStorage, getHostProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isHostError, isInsideContainer, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction, toHex };
|
|
1192
|
+
export { BULLETIN_RPCS, ChainNotSupportedError, DEFAULT_BULLETIN_ENDPOINT, HostCallFailedError, HostError, HostUnavailableError, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, findRingVrfKeyHandle, formatHostError, fromHex, getAccountsProvider, getChainSpec, getChatManager, getHostChainInfo, getHostLocalStorage, getHostProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isHostError, isInsideContainer, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction, toHex };
|
|
983
1193
|
//# sourceMappingURL=index.js.map
|
|
984
1194
|
//# sourceMappingURL=index.js.map
|