@parity/product-sdk-host 0.13.0 → 0.14.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 +63 -47
- package/dist/index.js +28 -17
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +4 -3
- package/dist/testing.js +10 -1
- package/dist/testing.js.map +1 -1
- package/package.json +6 -5
- package/src/accounts.ts +101 -37
- package/src/chains.ts +3 -9
- package/src/errors.ts +77 -41
- package/src/index.ts +2 -0
- package/src/payments.ts +8 -7
- package/src/testing.ts +15 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JsonRpcProvider, PolkadotSigner } from 'polkadot-api';
|
|
2
|
-
import { Topic, RemoteStatementStoreSubscribeItem, Statement, StatementProof, SignedStatement, HexString,
|
|
3
|
-
export { AllocatableResource, AllocationOutcome, ChatMessageContent, ChatRoom, HexString, HostPaymentBalanceSubscribeItem, HostPaymentStatusSubscribeItem, NotificationId, PaymentTopUpSource, ProductAccountId, HostPushNotificationError as PushNotificationError, RemotePermission, RingLocation, SignedStatement, Statement, StatementProof, ThemeName, ThemeVariant, Topic } from '@parity/truapi';
|
|
2
|
+
import { Topic, RemoteStatementStoreSubscribeItem, Statement, StatementProof, SignedStatement, HexString, scale, TrUApiClient, AllocatableResource, AllocationOutcome, VersionedHostGetUserIdError, HostRequestLoginResponse, VersionedHostRequestLoginError, ProductAccountId, ProductAccount as ProductAccount$1, VersionedHostAccountGetError, ProductProofContext, RingLocation, ContextualAlias as ContextualAlias$1, VersionedHostAccountGetAliasError, LegacyAccount, VersionedHostGetLegacyAccountsError, HostAccountCreateProofResponse, VersionedHostAccountCreateProofError, HostAccountConnectionStatusSubscribeItem, HostDevicePermissionRequest, RemotePermission, HostThemeSubscribeItem, ChatBotRegistrationStatus, HostChatCreateRoomRequest, ChatRoomRegistrationStatus, HostChatRegisterBotRequest, ChatMessageContent, ChatRoom, HostChatActionSubscribeItem, HostPaymentBalanceSubscribeItem, CoinPaymentPurseId, Balance, PaymentTopUpSource, HostPaymentStatusSubscribeItem, HostPushNotificationRequest, NotificationId } from '@parity/truapi';
|
|
3
|
+
export { AllocatableResource, AllocationOutcome, ChatMessageContent, ChatRoom, HexString, HostPaymentBalanceSubscribeItem, HostPaymentStatusSubscribeItem, NotificationId, PaymentTopUpSource, ProductAccountId, ProductProofContext, HostPushNotificationError as PushNotificationError, RemotePermission, RingLocation, 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';
|
|
6
6
|
import { Result } from '@parity/result';
|
|
@@ -156,13 +156,12 @@ declare function getStatementStore(): Promise<HostStatementStore | null>;
|
|
|
156
156
|
* chain-specific endpoints used by multiple packages.
|
|
157
157
|
*/
|
|
158
158
|
/**
|
|
159
|
-
* Bulletin Chain RPC endpoints per network environment. `paseo` (Paseo Next v2)
|
|
160
|
-
*
|
|
161
|
-
*
|
|
159
|
+
* Bulletin Chain RPC endpoints per network environment. `paseo` (Paseo Next v2)
|
|
160
|
+
* and `devnet` (public Paseo testnet) are populated today; `polkadot` and
|
|
161
|
+
* `kusama` are reserved for when those Bulletin deployments go live.
|
|
162
162
|
*/
|
|
163
163
|
declare const BULLETIN_RPCS: {
|
|
164
164
|
readonly paseo: readonly ["wss://paseo-bulletin-next-rpc.polkadot.io"];
|
|
165
|
-
readonly summit: readonly ["wss://summit-bulletin-rpc.polkadot.io"];
|
|
166
165
|
readonly devnet: readonly ["wss://bulletin-paseo.tservices.es:8443"];
|
|
167
166
|
readonly polkadot: string[];
|
|
168
167
|
readonly kusama: string[];
|
|
@@ -189,34 +188,25 @@ declare const DEFAULT_BULLETIN_ENDPOINT: string;
|
|
|
189
188
|
*/
|
|
190
189
|
|
|
191
190
|
/**
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* - the catch-all {@link GenericError} (`{ reason }`),
|
|
197
|
-
* - a unit tagged variant (`{ tag }`), or
|
|
198
|
-
* - a tagged variant carrying a reason (`{ tag, value: { reason } }`).
|
|
199
|
-
*
|
|
200
|
-
* `GenericError` is imported from `@parity/truapi`; the `{ tag }` members are a
|
|
201
|
-
* deliberate widening of truapi's per-domain named variants (the formatter is
|
|
202
|
-
* tag-agnostic). truapi has no umbrella error union to import today — once it
|
|
203
|
-
* exports a canonical tagged-error union from codegen, replace these local
|
|
204
|
-
* members with that import so the type is protocol-sourced rather than
|
|
205
|
-
* hand-widened.
|
|
206
|
-
*
|
|
207
|
-
* This is the *payload* the host public API carries inside a
|
|
208
|
-
* {@link HostCallFailedError} on the `err` channel of its `Result` returns — not
|
|
209
|
-
* the error type consumers branch on.
|
|
191
|
+
* What a `Domain`-tagged call error carries. Widened from truapi's per-domain
|
|
192
|
+
* `Versioned*Error` types (all `{ tag: "V1", value: <domain error> }` today)
|
|
193
|
+
* so one payload type covers every call.
|
|
210
194
|
*/
|
|
211
|
-
type
|
|
212
|
-
tag: string;
|
|
213
|
-
value?: undefined;
|
|
214
|
-
} | {
|
|
195
|
+
type VersionedDomainError = {
|
|
215
196
|
tag: string;
|
|
216
|
-
value
|
|
217
|
-
reason: string;
|
|
218
|
-
};
|
|
197
|
+
value?: unknown;
|
|
219
198
|
};
|
|
199
|
+
/**
|
|
200
|
+
* The error a host call puts on its `Err` channel — truapi's canonical
|
|
201
|
+
* {@link scale.CallErrorValue} envelope. `Denied` / `Unsupported` /
|
|
202
|
+
* `MalformedFrame` / `HostFailure` are transport-level failures; `Domain`
|
|
203
|
+
* wraps the actual per-domain error in a versioned envelope, which
|
|
204
|
+
* {@link formatHostError} digs through when rendering.
|
|
205
|
+
*
|
|
206
|
+
* This is the payload {@link HostCallFailedError} carries — not the error
|
|
207
|
+
* type consumers branch on.
|
|
208
|
+
*/
|
|
209
|
+
type HostErrorPayload = scale.CallErrorValue<VersionedDomainError>;
|
|
220
210
|
/**
|
|
221
211
|
* Extract a human-readable message from a host-side error.
|
|
222
212
|
*
|
|
@@ -426,10 +416,24 @@ type ProductAccount = ProductAccountId & Omit<ProductAccount$1, "publicKey"> & {
|
|
|
426
416
|
*
|
|
427
417
|
* Proves account membership in a ring without revealing which account.
|
|
428
418
|
*
|
|
429
|
-
* Derived from `@parity/truapi`'s
|
|
419
|
+
* Derived from `@parity/truapi`'s `ContextualAlias`, with both fields decoded to bytes.
|
|
430
420
|
*/
|
|
431
421
|
type ContextualAlias = {
|
|
432
|
-
[K in keyof
|
|
422
|
+
[K in keyof ContextualAlias$1]: Uint8Array;
|
|
423
|
+
};
|
|
424
|
+
/**
|
|
425
|
+
* A Ring VRF proof plus the values needed to verify it downstream (e.g.
|
|
426
|
+
* against a precompile): the alias it commits to, and the ring member index /
|
|
427
|
+
* revision the proof was generated against.
|
|
428
|
+
*
|
|
429
|
+
* Derived from `@parity/truapi`'s `HostAccountCreateProofResponse`, with the
|
|
430
|
+
* byte fields decoded.
|
|
431
|
+
*/
|
|
432
|
+
type RingVRFProof = Omit<HostAccountCreateProofResponse, "proof" | "contextualAlias"> & {
|
|
433
|
+
/** Raw ring VRF proof bytes. */
|
|
434
|
+
proof: Uint8Array;
|
|
435
|
+
/** Alias derived for the request's context. */
|
|
436
|
+
contextualAlias: ContextualAlias;
|
|
433
437
|
};
|
|
434
438
|
/**
|
|
435
439
|
* Accounts provider handle, backed by `truApi.account.*` / `truApi.signing.*`.
|
|
@@ -437,17 +441,28 @@ type ContextualAlias = {
|
|
|
437
441
|
* user identity, connection status, and `PolkadotSigner` factories.
|
|
438
442
|
*
|
|
439
443
|
* Lookup methods return a neverthrow `ResultAsync` (use `.match(ok, err)`);
|
|
440
|
-
* the signer factories return a synchronous PAPI `PolkadotSigner`.
|
|
444
|
+
* the signer factories return a synchronous PAPI `PolkadotSigner`. The `err`
|
|
445
|
+
* channel carries truapi's canonical `CallErrorValue` envelope around the
|
|
446
|
+
* per-call versioned domain error, exactly as the generated client returns it.
|
|
441
447
|
*/
|
|
442
448
|
interface AccountsProvider {
|
|
443
449
|
getUserId(): ResultAsync$1<{
|
|
444
450
|
primaryUsername: string;
|
|
445
|
-
},
|
|
446
|
-
requestLogin(reason?: string): ResultAsync$1<HostRequestLoginResponse,
|
|
447
|
-
getProductAccount(dotNsIdentifier: string, derivationIndex?: number): ResultAsync$1<ProductAccount,
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
+
}, scale.CallErrorValue<VersionedHostGetUserIdError>>;
|
|
452
|
+
requestLogin(reason?: string): ResultAsync$1<HostRequestLoginResponse, scale.CallErrorValue<VersionedHostRequestLoginError>>;
|
|
453
|
+
getProductAccount(dotNsIdentifier: string, derivationIndex?: number): ResultAsync$1<ProductAccount, scale.CallErrorValue<VersionedHostAccountGetError>>;
|
|
454
|
+
/**
|
|
455
|
+
* Derive the contextual alias for a proof context and ring. The host
|
|
456
|
+
* selects the member key within the ring — no per-account addressing.
|
|
457
|
+
*/
|
|
458
|
+
getProductAccountAlias(context: ProductProofContext, location: RingLocation): ResultAsync$1<ContextualAlias, scale.CallErrorValue<VersionedHostAccountGetAliasError>>;
|
|
459
|
+
getLegacyAccounts(): ResultAsync$1<HostAccount[], scale.CallErrorValue<VersionedHostGetLegacyAccountsError>>;
|
|
460
|
+
/**
|
|
461
|
+
* Generate a Ring VRF proof binding `message` to the product-scoped
|
|
462
|
+
* `context`. The host selects the member key within the ring; the result
|
|
463
|
+
* carries the proof plus its verification values ({@link RingVRFProof}).
|
|
464
|
+
*/
|
|
465
|
+
createRingVRFProof(context: ProductProofContext, location: RingLocation, message: Uint8Array): ResultAsync$1<RingVRFProof, scale.CallErrorValue<VersionedHostAccountCreateProofError>>;
|
|
451
466
|
/**
|
|
452
467
|
* Build a `PolkadotSigner` for a product account. Signing routes through the
|
|
453
468
|
* host's `createTransaction` path: the host decodes the metadata and forwards
|
|
@@ -669,9 +684,10 @@ declare function getChatManager(): Promise<ChatManager | null>;
|
|
|
669
684
|
* `truApi.payment.*`.
|
|
670
685
|
*
|
|
671
686
|
* Exposes balance subscription, top-up, payment requests, and payment-status
|
|
672
|
-
* subscription.
|
|
673
|
-
* (RFC-0017)
|
|
674
|
-
* flow
|
|
687
|
+
* subscription. The flow is distinct from the CoinPayment / merchant-payments
|
|
688
|
+
* surface (RFC-0017) — RFC-0006 is the user-initiated balance / top-up /
|
|
689
|
+
* payment-request flow — but both operate on the same CoinPayment purses,
|
|
690
|
+
* hence the shared `CoinPaymentPurseId` (omitted = the main purse).
|
|
675
691
|
*
|
|
676
692
|
* @module
|
|
677
693
|
*/
|
|
@@ -685,9 +701,9 @@ declare function getChatManager(): Promise<ChatManager | null>;
|
|
|
685
701
|
* `PaymentTopUpSource` — used directly rather than re-aliased.
|
|
686
702
|
*/
|
|
687
703
|
interface PaymentManager {
|
|
688
|
-
subscribeBalance(callback: (balance: HostPaymentBalanceSubscribeItem) => void, purse?:
|
|
689
|
-
topUp(amount: Balance, source: PaymentTopUpSource, into?:
|
|
690
|
-
requestPayment(amount: Balance, destination: HexString, from?:
|
|
704
|
+
subscribeBalance(callback: (balance: HostPaymentBalanceSubscribeItem) => void, purse?: CoinPaymentPurseId): HostSubscription;
|
|
705
|
+
topUp(amount: Balance, source: PaymentTopUpSource, into?: CoinPaymentPurseId): Promise<void>;
|
|
706
|
+
requestPayment(amount: Balance, destination: HexString, from?: CoinPaymentPurseId): Promise<{
|
|
691
707
|
id: string;
|
|
692
708
|
}>;
|
|
693
709
|
subscribePaymentStatus(paymentId: string, callback: (status: HostPaymentStatusSubscribeItem) => void): HostSubscription;
|
|
@@ -998,4 +1014,4 @@ declare function broadcastTransaction(genesisHash: HexString, transaction: HexSt
|
|
|
998
1014
|
*/
|
|
999
1015
|
declare function stopTransaction(genesisHash: HexString, operationId: string): Promise<Result<void, HostError>>;
|
|
1000
1016
|
|
|
1001
|
-
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 PushNotificationInput, type RemotePermissionItem, type ResultAsync, type StatementTopicFilter, type StatementsPage, type ThemeMode, type ThemeProvider, type TruApi, 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 };
|
|
1017
|
+
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 PushNotificationInput, type RemotePermissionItem, type ResultAsync, type RingVRFProof, type StatementTopicFilter, type StatementsPage, type ThemeMode, type ThemeProvider, type TruApi, 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 };
|
package/dist/index.js
CHANGED
|
@@ -9,21 +9,25 @@ import { unifyMetadata, decAnyMetadata } from '@polkadot-api/substrate-bindings'
|
|
|
9
9
|
import { AccountId } from 'polkadot-api';
|
|
10
10
|
|
|
11
11
|
// src/errors.ts
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
function isTagged(value) {
|
|
13
|
+
return value != null && typeof value === "object" && typeof value.tag === "string";
|
|
14
|
+
}
|
|
15
|
+
function hasReason(value) {
|
|
16
|
+
return value != null && typeof value === "object" && typeof value.reason === "string";
|
|
16
17
|
}
|
|
17
18
|
function formatHostError(error) {
|
|
18
19
|
if (error instanceof Error) return error.message;
|
|
19
20
|
if (typeof error === "string") return error;
|
|
20
|
-
if (
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return error.tag
|
|
21
|
+
if (isTagged(error)) {
|
|
22
|
+
if (error.tag === "Domain" && isTagged(error.value) && error.value.value !== void 0) {
|
|
23
|
+
return formatHostError(error.value.value);
|
|
24
|
+
}
|
|
25
|
+
if (hasReason(error.value)) {
|
|
26
|
+
return `${error.tag}: ${error.value.reason}`;
|
|
26
27
|
}
|
|
28
|
+
return error.tag;
|
|
29
|
+
}
|
|
30
|
+
if (hasReason(error)) {
|
|
27
31
|
return error.reason;
|
|
28
32
|
}
|
|
29
33
|
if (error != null && typeof error === "object" && "message" in error) {
|
|
@@ -552,7 +556,6 @@ async function getStatementStore() {
|
|
|
552
556
|
// src/chains.ts
|
|
553
557
|
var BULLETIN_RPCS = {
|
|
554
558
|
paseo: ["wss://paseo-bulletin-next-rpc.polkadot.io"],
|
|
555
|
-
summit: ["wss://summit-bulletin-rpc.polkadot.io"],
|
|
556
559
|
devnet: ["wss://bulletin-paseo.tservices.es:8443"],
|
|
557
560
|
polkadot: [],
|
|
558
561
|
kusama: []
|
|
@@ -593,8 +596,8 @@ function adaptAccountsProvider(client) {
|
|
|
593
596
|
derivationIndex
|
|
594
597
|
}));
|
|
595
598
|
},
|
|
596
|
-
getProductAccountAlias(
|
|
597
|
-
return account.getAccountAlias({
|
|
599
|
+
getProductAccountAlias(context, location) {
|
|
600
|
+
return account.getAccountAlias({ context, ringLocation: location }).map((response) => ({
|
|
598
601
|
context: fromHex(response.context),
|
|
599
602
|
alias: fromHex(response.alias)
|
|
600
603
|
}));
|
|
@@ -607,12 +610,20 @@ function adaptAccountsProvider(client) {
|
|
|
607
610
|
}))
|
|
608
611
|
);
|
|
609
612
|
},
|
|
610
|
-
createRingVRFProof(
|
|
613
|
+
createRingVRFProof(context, location, message) {
|
|
611
614
|
return account.createAccountProof({
|
|
612
|
-
|
|
615
|
+
context,
|
|
613
616
|
ringLocation: location,
|
|
614
|
-
|
|
615
|
-
}).map((response) =>
|
|
617
|
+
message: toHex(message)
|
|
618
|
+
}).map((response) => ({
|
|
619
|
+
proof: fromHex(response.proof),
|
|
620
|
+
contextualAlias: {
|
|
621
|
+
context: fromHex(response.contextualAlias.context),
|
|
622
|
+
alias: fromHex(response.contextualAlias.alias)
|
|
623
|
+
},
|
|
624
|
+
ringIndex: response.ringIndex,
|
|
625
|
+
ringRevision: response.ringRevision
|
|
626
|
+
}));
|
|
616
627
|
},
|
|
617
628
|
getProductAccountSigner(account_) {
|
|
618
629
|
const productAccountId = {
|