@parity/product-sdk-host 0.14.1 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { JsonRpcProvider, PolkadotSigner } from 'polkadot-api';
2
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';
3
+ export { AllocatableResource, AllocationOutcome, ChatMessageContent, ChatRoom, DerivationIndex, 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';
@@ -405,9 +405,13 @@ type HostAccount = Omit<LegacyAccount, "publicKey"> & {
405
405
  *
406
406
  * Combines `@parity/truapi`'s `ProductAccountId` (the `{ dotNsIdentifier,
407
407
  * derivationIndex }` lookup key) with the `ProductAccount` payload, with
408
- * `publicKey` decoded to bytes.
408
+ * `publicKey` decoded to bytes and `derivationIndex` kept as the plain
409
+ * numeric index (the adapter wraps it into the wire's tagged
410
+ * {@link DerivationIndex} selector).
409
411
  */
410
- type ProductAccount = ProductAccountId & Omit<ProductAccount$1, "publicKey"> & {
412
+ type ProductAccount = Omit<ProductAccountId, "derivationIndex"> & Omit<ProductAccount$1, "publicKey"> & {
413
+ /** Plain account index within the product subtree. */
414
+ derivationIndex: number;
411
415
  /** Raw public key bytes. */
412
416
  publicKey: Uint8Array;
413
417
  };
@@ -721,7 +725,7 @@ interface PaymentManager {
721
725
  * const payments = await getPaymentManager();
722
726
  * if (payments) {
723
727
  * const sub = payments.subscribeBalance((b) => { ... });
724
- * await payments.topUp(1_000_000n, { tag: "ProductAccount", value: { derivationIndex: 0 } });
728
+ * await payments.topUp(1_000_000n, { tag: "ProductAccount", value: { derivationIndex: { tag: "Left", value: 0 } } });
725
729
  * const { id } = await payments.requestPayment(500n, "0x…");
726
730
  * sub.unsubscribe();
727
731
  * }
package/dist/index.js CHANGED
@@ -596,6 +596,9 @@ function toHostExtensions(signedExtensions) {
596
596
  additionalSigned: toHex(ext.additionalSigned)
597
597
  }));
598
598
  }
599
+ function toWireProductAccountId(dotNsIdentifier, derivationIndex) {
600
+ return { dotNsIdentifier, derivationIndex: { tag: "Left", value: derivationIndex } };
601
+ }
599
602
  function adaptAccountsProvider(client) {
600
603
  const account = client.account;
601
604
  const signing = client.signing;
@@ -609,7 +612,9 @@ function adaptAccountsProvider(client) {
609
612
  return account.requestLogin({ reason });
610
613
  },
611
614
  getProductAccount(dotNsIdentifier, derivationIndex = 0) {
612
- return account.getAccount({ productAccountId: { dotNsIdentifier, derivationIndex } }).map((response) => ({
615
+ return account.getAccount({
616
+ productAccountId: toWireProductAccountId(dotNsIdentifier, derivationIndex)
617
+ }).map((response) => ({
613
618
  publicKey: fromHex(response.account.publicKey),
614
619
  dotNsIdentifier,
615
620
  derivationIndex
@@ -645,10 +650,10 @@ function adaptAccountsProvider(client) {
645
650
  }));
646
651
  },
647
652
  getProductAccountSigner(account_) {
648
- const productAccountId = {
649
- dotNsIdentifier: account_.dotNsIdentifier,
650
- derivationIndex: account_.derivationIndex
651
- };
653
+ const productAccountId = toWireProductAccountId(
654
+ account_.dotNsIdentifier,
655
+ account_.derivationIndex
656
+ );
652
657
  return {
653
658
  publicKey: account_.publicKey,
654
659
  async signTx(callData, signedExtensions, metadata) {