@parity/product-sdk-host 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +94 -13
- package/dist/index.js +177 -69
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +3 -2
- package/dist/testing.js +4 -2
- package/dist/testing.js.map +1 -1
- package/package.json +4 -4
- package/src/accounts.ts +295 -107
- package/src/errors.ts +46 -0
- package/src/index.ts +6 -0
- package/src/locale.ts +76 -0
- package/src/testing.ts +7 -4
- package/src/truapi.ts +139 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonRpcProvider, PolkadotSigner } from 'polkadot-api';
|
|
2
|
-
import { Topic, RemoteStatementStoreSubscribeItem, Statement, StatementProof, SignedStatement, HexString, scale, TrUApiClient, AllocatableResource, AllocationOutcome, VersionedHostGetUserIdError, HostRequestLoginResponse, VersionedHostRequestLoginError, ProductAccountId, ProductAccount as ProductAccount$1, VersionedHostAccountGetError, RingLocation, VersionedHostAccountRegisterRingVrfKeyError, RingVrfKeyDisclosure, RegisteredRingVrfKey as RegisteredRingVrfKey$1, VersionedHostAccountListRingVrfKeysError, ProductProofContext, ContextualAlias as ContextualAlias$1, VersionedHostAccountGetAliasError, LegacyAccount, VersionedHostGetLegacyAccountsError, HostAccountCreateProofResponse, VersionedHostAccountCreateProofError, VersionedHostAccountRingVrfSignError, VrfTranscriptItem as VrfTranscriptItem$1, VrfSignature as VrfSignature$1, VersionedHostAccountSignVrfError, HostAccountConnectionStatusSubscribeItem, HostDevicePermissionRequest, RemotePermission, HostThemeSubscribeItem, ChatBotRegistrationStatus, HostChatCreateRoomRequest, ChatRoomRegistrationStatus, HostChatRegisterBotRequest, ChatMessageContent, ChatRoom, HostChatActionSubscribeItem, HostPaymentBalanceSubscribeItem, CoinPaymentPurseId, Balance, PaymentTopUpSource, HostPaymentStatusSubscribeItem, HostPushNotificationRequest, NotificationId } from '@parity/truapi';
|
|
2
|
+
import { Topic, RemoteStatementStoreSubscribeItem, Statement, StatementProof, SignedStatement, HexString, scale, TrUApiClient, AllocatableResource, AllocationOutcome, VersionedHostGetUserIdError, HostRequestLoginResponse, VersionedHostRequestLoginError, ProductAccountId, ProductAccount as ProductAccount$1, VersionedHostAccountGetError, RingLocation, VersionedHostAccountRegisterRingVrfKeyError, RingVrfKeyDisclosure, RegisteredRingVrfKey as RegisteredRingVrfKey$1, VersionedHostAccountListRingVrfKeysError, ProductProofContext, ContextualAlias as ContextualAlias$1, VersionedHostAccountGetAliasError, LegacyAccount, VersionedHostGetLegacyAccountsError, HostAccountCreateProofResponse, VersionedHostAccountCreateProofError, VersionedHostAccountRingVrfSignError, VrfTranscriptItem as VrfTranscriptItem$1, VrfSignature as VrfSignature$1, VersionedHostAccountSignVrfError, HostAccountConnectionStatusSubscribeItem, HostDevicePermissionRequest, RemotePermission, HostThemeSubscribeItem, HostLocaleSubscribeItem, ChatBotRegistrationStatus, HostChatCreateRoomRequest, ChatRoomRegistrationStatus, HostChatRegisterBotRequest, ChatMessageContent, ChatRoom, HostChatActionSubscribeItem, HostPaymentBalanceSubscribeItem, CoinPaymentPurseId, Balance, PaymentTopUpSource, HostPaymentStatusSubscribeItem, HostPushNotificationRequest, NotificationId } from '@parity/truapi';
|
|
3
3
|
export { AllocatableResource, AllocationOutcome, ChatMessageContent, ChatRoom, DerivationIndex, HexString, HostPaymentBalanceSubscribeItem, HostPaymentStatusSubscribeItem, NotificationId, PaymentTopUpSource, ProductAccountId, ProductProofContext, HostPushNotificationError as PushNotificationError, RemotePermission, RingLocation, RingVrfKeyDisclosure, SignedStatement, Statement, StatementProof, ThemeName, ThemeVariant, Topic } from '@parity/truapi';
|
|
4
4
|
import { SdkError } from '@parity/product-sdk-errors';
|
|
5
5
|
export { SdkError, isSdkError } from '@parity/product-sdk-errors';
|
|
@@ -250,6 +250,29 @@ declare class HostCallFailedError extends HostError {
|
|
|
250
250
|
readonly payload: HostErrorPayload;
|
|
251
251
|
constructor(label: string, payload: HostErrorPayload);
|
|
252
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* A host call could not be processed to completion: the `ResultAsync` the
|
|
255
|
+
* truapi client returns rejected instead of resolving to an ok/err. The usual
|
|
256
|
+
* cause is a response the client's SCALE codec can't decode (a
|
|
257
|
+
* `RangeError: Offset is outside the bounds of the DataView`) because the host
|
|
258
|
+
* and the `@parity/truapi` version the product is built against disagree on the
|
|
259
|
+
* wire shape of that call — a protocol-version skew. A host channel that closed
|
|
260
|
+
* mid-call looks identical from here, so this does not assert the skew; the
|
|
261
|
+
* real error is preserved on {@link cause}.
|
|
262
|
+
*
|
|
263
|
+
* The truapi client catches the decode throw in its message handler and turns
|
|
264
|
+
* it into a promise rejection, then wraps the call with
|
|
265
|
+
* `ResultAsync.fromSafePromise`, which installs no rejection handler — so the
|
|
266
|
+
* rejection escapes the `Result` channel rather than landing on its err side.
|
|
267
|
+
* Without this boundary that surfaces as a raw `RangeError` with a stack naming
|
|
268
|
+
* neither the call nor the cause. This names the call, so a bug report has
|
|
269
|
+
* somewhere to start.
|
|
270
|
+
*/
|
|
271
|
+
declare class HostResponseDecodeError extends HostError {
|
|
272
|
+
/** The host-API call whose response failed to decode, e.g. `"createRingVRFProof"`. */
|
|
273
|
+
readonly call: string;
|
|
274
|
+
constructor(call: string, cause: unknown);
|
|
275
|
+
}
|
|
253
276
|
/** Check whether a value is any {@link HostError}. */
|
|
254
277
|
declare function isHostError(error: unknown): error is HostError;
|
|
255
278
|
|
|
@@ -495,6 +518,13 @@ type VrfTranscriptItem = {
|
|
|
495
518
|
type VrfSignature = {
|
|
496
519
|
[K in keyof VrfSignature$1]: Uint8Array;
|
|
497
520
|
};
|
|
521
|
+
/**
|
|
522
|
+
* A call's declared `Err` channel, plus {@link HostResponseDecodeError}: any
|
|
523
|
+
* host reply can fail to decode if the host and the product's `@parity/truapi`
|
|
524
|
+
* client are on different protocol versions, so every decoded call can surface
|
|
525
|
+
* it in addition to its own typed errors.
|
|
526
|
+
*/
|
|
527
|
+
type WithDecodeError<E> = E | HostResponseDecodeError;
|
|
498
528
|
/**
|
|
499
529
|
* Accounts provider handle, backed by `truApi.account.*` / `truApi.signing.*`.
|
|
500
530
|
* Surfaces the user's wallet accounts, app-scoped product accounts, Ring VRF,
|
|
@@ -503,14 +533,17 @@ type VrfSignature = {
|
|
|
503
533
|
* Lookup methods return a neverthrow `ResultAsync` (use `.match(ok, err)`);
|
|
504
534
|
* the signer factories return a synchronous PAPI `PolkadotSigner`. The `err`
|
|
505
535
|
* channel carries truapi's canonical `CallErrorValue` envelope around the
|
|
506
|
-
* per-call versioned domain error, exactly as the generated client returns it
|
|
536
|
+
* per-call versioned domain error, exactly as the generated client returns it,
|
|
537
|
+
* plus a {@link HostResponseDecodeError} for the case where the host's reply
|
|
538
|
+
* cannot be decoded at all (a host/client protocol-version skew) — see
|
|
539
|
+
* {@link WithDecodeError}.
|
|
507
540
|
*/
|
|
508
541
|
interface AccountsProvider {
|
|
509
542
|
getUserId(): ResultAsync$1<{
|
|
510
543
|
primaryUsername: string;
|
|
511
|
-
}, scale.CallErrorValue<VersionedHostGetUserIdError
|
|
512
|
-
requestLogin(reason?: string): ResultAsync$1<HostRequestLoginResponse, scale.CallErrorValue<VersionedHostRequestLoginError
|
|
513
|
-
getProductAccount(dotNsIdentifier: string, derivationIndex?: number): ResultAsync$1<ProductAccount, scale.CallErrorValue<VersionedHostAccountGetError
|
|
544
|
+
}, WithDecodeError<scale.CallErrorValue<VersionedHostGetUserIdError>>>;
|
|
545
|
+
requestLogin(reason?: string): ResultAsync$1<HostRequestLoginResponse, WithDecodeError<scale.CallErrorValue<VersionedHostRequestLoginError>>>;
|
|
546
|
+
getProductAccount(dotNsIdentifier: string, derivationIndex?: number): ResultAsync$1<ProductAccount, WithDecodeError<scale.CallErrorValue<VersionedHostAccountGetError>>>;
|
|
514
547
|
/**
|
|
515
548
|
* Register a ring-VRF key owned by the calling product.
|
|
516
549
|
*
|
|
@@ -520,17 +553,17 @@ interface AccountsProvider {
|
|
|
520
553
|
* Registration returns the key's public key. Call {@link listRingVrfKeys}
|
|
521
554
|
* afterward to obtain the opaque handle required by alias and proof calls.
|
|
522
555
|
*/
|
|
523
|
-
registerRingVrfKey(index: number, ring: RingLocation): ResultAsync$1<RingVrfPublicKey, scale.CallErrorValue<VersionedHostAccountRegisterRingVrfKeyError
|
|
556
|
+
registerRingVrfKey(index: number, ring: RingLocation): ResultAsync$1<RingVrfPublicKey, WithDecodeError<scale.CallErrorValue<VersionedHostAccountRegisterRingVrfKeyError>>>;
|
|
524
557
|
/** List an owner's registered ring-VRF keys. */
|
|
525
|
-
listRingVrfKeys(owner: string, disclosure?: RingVrfKeyDisclosure): ResultAsync$1<RegisteredRingVrfKey[], scale.CallErrorValue<VersionedHostAccountListRingVrfKeysError
|
|
558
|
+
listRingVrfKeys(owner: string, disclosure?: RingVrfKeyDisclosure): ResultAsync$1<RegisteredRingVrfKey[], WithDecodeError<scale.CallErrorValue<VersionedHostAccountListRingVrfKeysError>>>;
|
|
526
559
|
/** Derive a contextual alias with an explicitly registered ring-VRF key. */
|
|
527
|
-
getProductAccountAlias(keyHandle: RingVrfKeyHandle, context: ProductProofContext, location: RingLocation): ResultAsync$1<ContextualAlias, scale.CallErrorValue<VersionedHostAccountGetAliasError
|
|
528
|
-
getLegacyAccounts(): ResultAsync$1<HostAccount[], scale.CallErrorValue<VersionedHostGetLegacyAccountsError
|
|
560
|
+
getProductAccountAlias(keyHandle: RingVrfKeyHandle, context: ProductProofContext, location: RingLocation): ResultAsync$1<ContextualAlias, WithDecodeError<scale.CallErrorValue<VersionedHostAccountGetAliasError>>>;
|
|
561
|
+
getLegacyAccounts(): ResultAsync$1<HostAccount[], WithDecodeError<scale.CallErrorValue<VersionedHostGetLegacyAccountsError>>>;
|
|
529
562
|
/**
|
|
530
563
|
* Generate a Ring VRF proof with an explicitly registered key, binding
|
|
531
564
|
* `message` to the product-scoped `context`.
|
|
532
565
|
*/
|
|
533
|
-
createRingVRFProof(keyHandle: RingVrfKeyHandle, context: ProductProofContext, location: RingLocation, message: Uint8Array): ResultAsync$1<RingVRFProof, scale.CallErrorValue<VersionedHostAccountCreateProofError
|
|
566
|
+
createRingVRFProof(keyHandle: RingVrfKeyHandle, context: ProductProofContext, location: RingLocation, message: Uint8Array): ResultAsync$1<RingVRFProof, WithDecodeError<scale.CallErrorValue<VersionedHostAccountCreateProofError>>>;
|
|
534
567
|
/**
|
|
535
568
|
* Sign `message` directly with an explicitly registered ring-VRF key.
|
|
536
569
|
*
|
|
@@ -538,7 +571,7 @@ interface AccountsProvider {
|
|
|
538
571
|
* membership; it is the plain signature under the member key, for
|
|
539
572
|
* protocols that carry their own proof.
|
|
540
573
|
*/
|
|
541
|
-
ringVrfSign(keyHandle: RingVrfKeyHandle, message: Uint8Array): ResultAsync$1<Uint8Array, scale.CallErrorValue<VersionedHostAccountRingVrfSignError
|
|
574
|
+
ringVrfSign(keyHandle: RingVrfKeyHandle, message: Uint8Array): ResultAsync$1<Uint8Array, WithDecodeError<scale.CallErrorValue<VersionedHostAccountRingVrfSignError>>>;
|
|
542
575
|
/**
|
|
543
576
|
* Produce an sr25519 VRF signature from a product account (RFC-0023).
|
|
544
577
|
*
|
|
@@ -558,7 +591,7 @@ interface AccountsProvider {
|
|
|
558
591
|
*
|
|
559
592
|
* Hosts predating the call reject it through the error channel.
|
|
560
593
|
*/
|
|
561
|
-
signVrf(account: ProductAccountLookup, transcriptLabel: Uint8Array, items: VrfTranscriptItem[]): ResultAsync$1<VrfSignature, scale.CallErrorValue<VersionedHostAccountSignVrfError
|
|
594
|
+
signVrf(account: ProductAccountLookup, transcriptLabel: Uint8Array, items: VrfTranscriptItem[]): ResultAsync$1<VrfSignature, WithDecodeError<scale.CallErrorValue<VersionedHostAccountSignVrfError>>>;
|
|
562
595
|
/**
|
|
563
596
|
* Build a `PolkadotSigner` for a product account. Signing routes through the
|
|
564
597
|
* host's `createTransaction` path: the host decodes the metadata and forwards
|
|
@@ -696,6 +729,54 @@ interface ThemeProvider {
|
|
|
696
729
|
*/
|
|
697
730
|
declare function getThemeProvider(): Promise<ThemeProvider | null>;
|
|
698
731
|
|
|
732
|
+
/**
|
|
733
|
+
* Higher-level wrapper for the host's locale subscription, backed by
|
|
734
|
+
* `truApi.locale.subscribe`.
|
|
735
|
+
*
|
|
736
|
+
* `getLocaleProvider` returns a handle whose `subscribeLocale(cb)` delivers a
|
|
737
|
+
* typed {@link LocaleInfo} — a `{ languageTag }` struct carrying a BCP 47 tag
|
|
738
|
+
* such as `"en"`, `"pt-BR"` or `"zh-Hans"` — and yields a
|
|
739
|
+
* {@link HostSubscription} (`unsubscribe` + `onInterrupt`).
|
|
740
|
+
*
|
|
741
|
+
* @module
|
|
742
|
+
*/
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Host locale value. A `{ languageTag }` struct re-exported from
|
|
746
|
+
* `@parity/truapi`.
|
|
747
|
+
*/
|
|
748
|
+
type LocaleInfo = HostLocaleSubscribeItem;
|
|
749
|
+
/**
|
|
750
|
+
* Host locale provider handle. `subscribeLocale(callback)` receives a typed
|
|
751
|
+
* {@link LocaleInfo} on every change and returns a {@link HostSubscription}.
|
|
752
|
+
*/
|
|
753
|
+
interface LocaleProvider {
|
|
754
|
+
subscribeLocale(callback: (locale: LocaleInfo) => void): HostSubscription;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Get the host locale provider, backed by `truApi.locale.*`. Returns `null`
|
|
758
|
+
* when running outside a host container.
|
|
759
|
+
*
|
|
760
|
+
* The tag is whatever the host reports; a product that ships no catalog entry
|
|
761
|
+
* for it chooses its own fallback.
|
|
762
|
+
*
|
|
763
|
+
* @returns The locale provider, or `null` if unavailable.
|
|
764
|
+
*
|
|
765
|
+
* @example
|
|
766
|
+
* ```ts
|
|
767
|
+
* import { getLocaleProvider } from "@parity/product-sdk-host";
|
|
768
|
+
*
|
|
769
|
+
* const provider = await getLocaleProvider();
|
|
770
|
+
* if (provider) {
|
|
771
|
+
* const sub = provider.subscribeLocale((locale) => {
|
|
772
|
+
* i18n.activate(SUPPORTED.has(locale.languageTag) ? locale.languageTag : "en");
|
|
773
|
+
* });
|
|
774
|
+
* // sub.unsubscribe() to stop listening
|
|
775
|
+
* }
|
|
776
|
+
* ```
|
|
777
|
+
*/
|
|
778
|
+
declare function getLocaleProvider(): Promise<LocaleProvider | null>;
|
|
779
|
+
|
|
699
780
|
/**
|
|
700
781
|
* Higher-level wrapper for the host's entropy derivation (RFC-0007).
|
|
701
782
|
*
|
|
@@ -1110,4 +1191,4 @@ declare function broadcastTransaction(genesisHash: HexString, transaction: HexSt
|
|
|
1110
1191
|
*/
|
|
1111
1192
|
declare function stopTransaction(genesisHash: HexString, operationId: string): Promise<Result<void, HostError>>;
|
|
1112
1193
|
|
|
1113
|
-
export { type AccountsProvider, BULLETIN_RPCS, ChainNotSupportedError, type ChainProperties, type ChainSpec, type ChatBotRegistrationResult, type ChatManager, type ChatReceivedAction, type ChatRoomRegistrationResult, type ContextualAlias, DEFAULT_BULLETIN_ENDPOINT, type DevicePermissionKind, type Feature, type HostAccount, HostCallFailedError, HostError, type HostErrorPayload, type HostLocalStorage, type HostStatementStore, type HostSubscription, HostUnavailableError, type NotificationManager, type PaymentManager, type PreimageManager, type ProductAccount, type ProductAccountLookup, type PushNotificationInput, type RegisteredRingVrfKey, type RemotePermissionItem, type ResultAsync, type RingVRFProof, type RingVrfKeyHandle, type RingVrfPublicKey, type StatementTopicFilter, type StatementsPage, type ThemeMode, type ThemeProvider, type TruApi, type VrfSignature, type VrfTranscriptItem, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, findRingVrfKeyHandle, formatHostError, fromHex, getAccountsProvider, getChainSpec, getChatManager, getHostLocalStorage, getHostProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isHostError, isInsideContainer, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction, toHex };
|
|
1194
|
+
export { type AccountsProvider, BULLETIN_RPCS, ChainNotSupportedError, type ChainProperties, type ChainSpec, type ChatBotRegistrationResult, type ChatManager, type ChatReceivedAction, type ChatRoomRegistrationResult, type ContextualAlias, DEFAULT_BULLETIN_ENDPOINT, type DevicePermissionKind, type Feature, type HostAccount, HostCallFailedError, HostError, type HostErrorPayload, type HostLocalStorage, HostResponseDecodeError, type HostStatementStore, type HostSubscription, HostUnavailableError, type LocaleInfo, type LocaleProvider, type NotificationManager, type PaymentManager, type PreimageManager, type ProductAccount, type ProductAccountLookup, type PushNotificationInput, type RegisteredRingVrfKey, type RemotePermissionItem, type ResultAsync, type RingVRFProof, type RingVrfKeyHandle, type RingVrfPublicKey, type StatementTopicFilter, type StatementsPage, type ThemeMode, type ThemeProvider, type TruApi, type VrfSignature, type VrfTranscriptItem, type WithDecodeError, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, findRingVrfKeyHandle, formatHostError, fromHex, getAccountsProvider, getChainSpec, getChatManager, getHostLocalStorage, getHostProvider, getLocaleProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isHostError, isInsideContainer, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction, toHex };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { err, ok } from '@parity/result';
|
|
|
6
6
|
export { err, ok } from '@parity/result';
|
|
7
7
|
export { isSdkError } from '@parity/product-sdk-errors';
|
|
8
8
|
import { unifyMetadata, decAnyMetadata } from '@polkadot-api/substrate-bindings';
|
|
9
|
+
import { ResultAsync } from 'neverthrow';
|
|
9
10
|
import { AccountId } from 'polkadot-api';
|
|
10
11
|
|
|
11
12
|
// src/errors.ts
|
|
@@ -62,6 +63,18 @@ var HostCallFailedError = class extends HostError {
|
|
|
62
63
|
this.payload = payload;
|
|
63
64
|
}
|
|
64
65
|
};
|
|
66
|
+
var HostResponseDecodeError = class extends HostError {
|
|
67
|
+
/** The host-API call whose response failed to decode, e.g. `"createRingVRFProof"`. */
|
|
68
|
+
call;
|
|
69
|
+
constructor(call, cause) {
|
|
70
|
+
super(
|
|
71
|
+
`Could not process the host's response to ${call}: ${formatHostError(cause)}. The usual cause is a protocol-version skew between the host app and the @parity/truapi version this product is built against; a host channel that closed mid-call looks the same.`,
|
|
72
|
+
{ cause }
|
|
73
|
+
);
|
|
74
|
+
this.name = "HostResponseDecodeError";
|
|
75
|
+
this.call = call;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
65
78
|
function isHostError(error) {
|
|
66
79
|
return error instanceof HostError;
|
|
67
80
|
}
|
|
@@ -486,18 +499,59 @@ function createHostPapiProvider(client, genesisHash) {
|
|
|
486
499
|
|
|
487
500
|
// src/truapi.ts
|
|
488
501
|
var log2 = createLogger("host");
|
|
502
|
+
async function matchGuarded(result, label, onOk, onErr, onDecode) {
|
|
503
|
+
try {
|
|
504
|
+
return await result.match(
|
|
505
|
+
(value) => {
|
|
506
|
+
try {
|
|
507
|
+
return onOk(value);
|
|
508
|
+
} catch (thrown) {
|
|
509
|
+
throw new HandlerThrow(thrown);
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
(error) => {
|
|
513
|
+
try {
|
|
514
|
+
return onErr(error);
|
|
515
|
+
} catch (thrown) {
|
|
516
|
+
throw new HandlerThrow(thrown);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
);
|
|
520
|
+
} catch (cause) {
|
|
521
|
+
if (cause instanceof HandlerThrow) throw cause.thrown;
|
|
522
|
+
return onDecode(
|
|
523
|
+
cause instanceof HostResponseDecodeError ? cause : new HostResponseDecodeError(label, cause)
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
var HandlerThrow = class {
|
|
528
|
+
constructor(thrown) {
|
|
529
|
+
this.thrown = thrown;
|
|
530
|
+
}
|
|
531
|
+
thrown;
|
|
532
|
+
};
|
|
489
533
|
function unwrapHostResult(result, label) {
|
|
490
|
-
return
|
|
534
|
+
return matchGuarded(
|
|
535
|
+
result,
|
|
536
|
+
label,
|
|
491
537
|
(value) => value,
|
|
492
538
|
(error) => {
|
|
493
539
|
throw new Error(`${label}: ${formatHostError(error)}`, { cause: error });
|
|
540
|
+
},
|
|
541
|
+
// A response the client can't decode would otherwise reject with a raw
|
|
542
|
+
// `RangeError`; throw it as a typed, named error instead.
|
|
543
|
+
(decodeError) => {
|
|
544
|
+
throw decodeError;
|
|
494
545
|
}
|
|
495
546
|
);
|
|
496
547
|
}
|
|
497
548
|
function mapHostResult(result, map, label) {
|
|
498
|
-
return
|
|
549
|
+
return matchGuarded(
|
|
550
|
+
result,
|
|
551
|
+
label,
|
|
499
552
|
(value) => ok(map(value)),
|
|
500
|
-
(error) => err(new HostCallFailedError(label, error))
|
|
553
|
+
(error) => err(new HostCallFailedError(label, error)),
|
|
554
|
+
(decodeError) => err(decodeError)
|
|
501
555
|
);
|
|
502
556
|
}
|
|
503
557
|
function toHex(bytes) {
|
|
@@ -749,18 +803,23 @@ function sameRingLocation(a, b) {
|
|
|
749
803
|
function findRingVrfKeyHandle(keys, ring) {
|
|
750
804
|
return keys.find((key) => key.rings.some((candidate) => sameRingLocation(candidate, ring)))?.handle;
|
|
751
805
|
}
|
|
752
|
-
|
|
753
|
-
|
|
806
|
+
var V5_FORMAT_SELECTOR = 5;
|
|
807
|
+
function selectHostTxExtVersion(formatVersions) {
|
|
808
|
+
if (formatVersions.length === 0) {
|
|
754
809
|
throw new Error("No extrinsic version found in metadata");
|
|
755
810
|
}
|
|
756
|
-
if (
|
|
811
|
+
if (formatVersions.includes(4)) {
|
|
757
812
|
return 0;
|
|
758
813
|
}
|
|
759
|
-
|
|
814
|
+
if (formatVersions.includes(5)) {
|
|
815
|
+
return V5_FORMAT_SELECTOR;
|
|
816
|
+
}
|
|
817
|
+
throw new Error(
|
|
818
|
+
`Runtime offers no extrinsic format 4 or 5 (offers: ${formatVersions.join(", ")}); the host protocol has no txExtVersion for it.`
|
|
819
|
+
);
|
|
760
820
|
}
|
|
761
821
|
function deriveTxExtVersion(metadata) {
|
|
762
|
-
|
|
763
|
-
return selectHostTxExtVersion(versions);
|
|
822
|
+
return selectHostTxExtVersion(unifyMetadata(decAnyMetadata(metadata)).extrinsic.version);
|
|
764
823
|
}
|
|
765
824
|
var deps = { deriveTxExtVersion };
|
|
766
825
|
function toHostExtensions(signedExtensions) {
|
|
@@ -776,91 +835,127 @@ function toWireProductAccountId({
|
|
|
776
835
|
}) {
|
|
777
836
|
return { dotNsIdentifier, derivationIndex: { tag: "Index", value: derivationIndex } };
|
|
778
837
|
}
|
|
838
|
+
function guardDecode(call, result) {
|
|
839
|
+
return ResultAsync.fromPromise(
|
|
840
|
+
Promise.resolve(result),
|
|
841
|
+
(cause) => new HostResponseDecodeError(call, cause)
|
|
842
|
+
).andThen((inner) => inner);
|
|
843
|
+
}
|
|
779
844
|
function adaptAccountsProvider(client) {
|
|
780
845
|
const account = client.account;
|
|
781
846
|
const signing = client.signing;
|
|
782
847
|
return {
|
|
783
848
|
getUserId() {
|
|
784
|
-
return
|
|
785
|
-
|
|
786
|
-
|
|
849
|
+
return guardDecode(
|
|
850
|
+
"getUserId",
|
|
851
|
+
account.getUserId().map((response) => ({
|
|
852
|
+
primaryUsername: response.primaryUsername
|
|
853
|
+
}))
|
|
854
|
+
);
|
|
787
855
|
},
|
|
788
856
|
requestLogin(reason) {
|
|
789
|
-
return account.requestLogin({ reason });
|
|
857
|
+
return guardDecode("requestLogin", account.requestLogin({ reason }));
|
|
790
858
|
},
|
|
791
859
|
getProductAccount(dotNsIdentifier, derivationIndex = 0) {
|
|
792
|
-
return
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
860
|
+
return guardDecode(
|
|
861
|
+
"getProductAccount",
|
|
862
|
+
account.getAccount({
|
|
863
|
+
productAccountId: toWireProductAccountId({
|
|
864
|
+
dotNsIdentifier,
|
|
865
|
+
derivationIndex
|
|
866
|
+
})
|
|
867
|
+
}).map((response) => ({
|
|
868
|
+
publicKey: fromHex(response.account.publicKey),
|
|
869
|
+
dotNsIdentifier,
|
|
870
|
+
derivationIndex
|
|
871
|
+
}))
|
|
872
|
+
);
|
|
799
873
|
},
|
|
800
874
|
registerRingVrfKey(index, ring) {
|
|
801
|
-
return
|
|
875
|
+
return guardDecode(
|
|
876
|
+
"registerRingVrfKey",
|
|
877
|
+
account.registerRingVrfKey({ index: { tag: "Index", value: index }, ring }).map(fromHex)
|
|
878
|
+
);
|
|
802
879
|
},
|
|
803
880
|
listRingVrfKeys(owner, disclosure = "Anonymized") {
|
|
804
|
-
return
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
881
|
+
return guardDecode(
|
|
882
|
+
"listRingVrfKeys",
|
|
883
|
+
account.listRingVrfKeys({ owner, disclosure }).map(
|
|
884
|
+
(keys) => keys.map((key) => ({
|
|
885
|
+
...key,
|
|
886
|
+
handle: key.handle,
|
|
887
|
+
publicKey: key.publicKey === void 0 ? void 0 : fromHex(key.publicKey)
|
|
888
|
+
}))
|
|
889
|
+
)
|
|
810
890
|
);
|
|
811
891
|
},
|
|
812
892
|
getProductAccountAlias(keyHandle, context, location) {
|
|
813
|
-
return
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
893
|
+
return guardDecode(
|
|
894
|
+
"getProductAccountAlias",
|
|
895
|
+
account.getAccountAlias({
|
|
896
|
+
keyHandle,
|
|
897
|
+
context,
|
|
898
|
+
ringLocation: location
|
|
899
|
+
}).map((response) => ({
|
|
900
|
+
context: fromHex(response.context),
|
|
901
|
+
alias: fromHex(response.alias)
|
|
902
|
+
}))
|
|
903
|
+
);
|
|
821
904
|
},
|
|
822
905
|
getLegacyAccounts() {
|
|
823
|
-
return
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
906
|
+
return guardDecode(
|
|
907
|
+
"getLegacyAccounts",
|
|
908
|
+
account.getLegacyAccounts().map(
|
|
909
|
+
(response) => response.accounts.map((a) => ({
|
|
910
|
+
publicKey: fromHex(a.publicKey),
|
|
911
|
+
name: a.name
|
|
912
|
+
}))
|
|
913
|
+
)
|
|
828
914
|
);
|
|
829
915
|
},
|
|
830
916
|
createRingVRFProof(keyHandle, context, location, message) {
|
|
831
|
-
return
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
917
|
+
return guardDecode(
|
|
918
|
+
"createRingVRFProof",
|
|
919
|
+
account.createAccountProof({
|
|
920
|
+
keyHandle,
|
|
921
|
+
context,
|
|
922
|
+
ringLocation: location,
|
|
923
|
+
message: toHex(message)
|
|
924
|
+
}).map((response) => ({
|
|
925
|
+
proof: fromHex(response.proof),
|
|
926
|
+
contextualAlias: {
|
|
927
|
+
context: fromHex(response.contextualAlias.context),
|
|
928
|
+
alias: fromHex(response.contextualAlias.alias)
|
|
929
|
+
},
|
|
930
|
+
ringIndex: response.ringIndex,
|
|
931
|
+
ringRevision: response.ringRevision
|
|
932
|
+
}))
|
|
933
|
+
);
|
|
845
934
|
},
|
|
846
935
|
ringVrfSign(keyHandle, message) {
|
|
847
|
-
return
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
936
|
+
return guardDecode(
|
|
937
|
+
"ringVrfSign",
|
|
938
|
+
account.ringVrfSign({
|
|
939
|
+
keyHandle,
|
|
940
|
+
message: toHex(message)
|
|
941
|
+
}).map(fromHex)
|
|
942
|
+
);
|
|
851
943
|
},
|
|
852
944
|
signVrf(account_, transcriptLabel, items) {
|
|
853
|
-
return
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
945
|
+
return guardDecode(
|
|
946
|
+
"signVrf",
|
|
947
|
+
account.signVrf({
|
|
948
|
+
account: toWireProductAccountId(account_),
|
|
949
|
+
transcriptLabel: toHex(transcriptLabel),
|
|
950
|
+
items: items.map(({ label, value }) => ({
|
|
951
|
+
label: toHex(label),
|
|
952
|
+
value: toHex(value)
|
|
953
|
+
}))
|
|
954
|
+
}).map((response) => ({
|
|
955
|
+
preOutput: fromHex(response.preOutput),
|
|
956
|
+
proof: fromHex(response.proof)
|
|
859
957
|
}))
|
|
860
|
-
|
|
861
|
-
preOutput: fromHex(response.preOutput),
|
|
862
|
-
proof: fromHex(response.proof)
|
|
863
|
-
}));
|
|
958
|
+
);
|
|
864
959
|
},
|
|
865
960
|
getProductAccountSigner(account_) {
|
|
866
961
|
const productAccountId = toWireProductAccountId(account_);
|
|
@@ -976,6 +1071,19 @@ async function getThemeProvider() {
|
|
|
976
1071
|
const client = await getClient();
|
|
977
1072
|
return client ? adaptThemeProvider(client) : null;
|
|
978
1073
|
}
|
|
1074
|
+
|
|
1075
|
+
// src/locale.ts
|
|
1076
|
+
function adaptLocaleProvider(client) {
|
|
1077
|
+
return {
|
|
1078
|
+
subscribeLocale(callback) {
|
|
1079
|
+
return subscribeWithInterrupt(client.locale.subscribe(), callback);
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
async function getLocaleProvider() {
|
|
1084
|
+
const client = await getClient();
|
|
1085
|
+
return client ? adaptLocaleProvider(client) : null;
|
|
1086
|
+
}
|
|
979
1087
|
var log5 = createLogger("host:entropy");
|
|
980
1088
|
async function deriveEntropy(key) {
|
|
981
1089
|
const truApi = await getTruApi();
|
|
@@ -1189,6 +1297,6 @@ async function stopTransaction(genesisHash, operationId) {
|
|
|
1189
1297
|
);
|
|
1190
1298
|
}
|
|
1191
1299
|
|
|
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 };
|
|
1300
|
+
export { BULLETIN_RPCS, ChainNotSupportedError, DEFAULT_BULLETIN_ENDPOINT, HostCallFailedError, HostError, HostResponseDecodeError, HostUnavailableError, broadcastTransaction, createHostLocalStorage, createHostPreimageManager, createProofAuthorized, deriveEntropy, featureSupported, findRingVrfKeyHandle, formatHostError, fromHex, getAccountsProvider, getChainSpec, getChatManager, getHostChainInfo, getHostLocalStorage, getHostProvider, getLocaleProvider, getNotificationManager, getPaymentManager, getPreimageManager, getStatementStore, getThemeProvider, getTruApi, isChainSupported, isHostError, isInsideContainer, navigateTo, requestDevicePermission, requestPermission, requestResourceAllocation, stopTransaction, toHex };
|
|
1193
1301
|
//# sourceMappingURL=index.js.map
|
|
1194
1302
|
//# sourceMappingURL=index.js.map
|