@chipi-stack/chipi-react 13.11.0 → 13.13.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/hooks.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { CreateWalletParams, CreateWalletResponse, GetWalletParams, GetWalletResponse, ChainToken, GetTokenBalanceResponse, WalletType, WalletData, SessionKeyData, SessionDataResponse, CreateSessionKeyParams, SessionConfig, Call, MigrateWalletToPasskeyParams, TransferHookInput, ApproveHookInput, GetTransactionListQuery, PaginatedResponse, Transaction, CreateSkuPurchaseParams, GetSkuListQuery, Sku, CallAnyContractParams, RecordSendTransactionParams, GetTokenBalanceParams, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, ExecuteWithSessionParams } from '@chipi-stack/types';
1
+ import { CreateWalletParams, CreateWalletResponse, GetWalletParams, GetWalletResponse, ChainToken, GetTokenBalanceResponse, WalletType, WalletData, SessionKeyData, SessionDataResponse, CreateSessionKeyParams, SessionConfig, Call, MigrateWalletToPasskeyParams, UpdateWalletEncryptionParams, UpdateWalletEncryptionResponse, TransferHookInput, ApproveHookInput, GetTransactionListQuery, PaginatedResponse, Transaction, CreateSkuPurchaseParams, GetSkuListQuery, Sku, CallAnyContractParams, RecordSendTransactionParams, GetTokenBalanceParams, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, ExecuteWithSessionParams } from '@chipi-stack/types';
2
2
  import * as _tanstack_react_query from '@tanstack/react-query';
3
3
  import { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
4
4
 
@@ -466,6 +466,25 @@ declare function useMigrateWalletToPasskey(): {
466
466
  reset: () => void;
467
467
  };
468
468
 
469
+ type UpdateWalletEncryptionInput = UpdateWalletEncryptionParams & {
470
+ bearerToken: string;
471
+ };
472
+ /**
473
+ * Hook for updating a wallet's encrypted private key.
474
+ * Use when the user changes their passkey or PIN; the client re-encrypts the private key
475
+ * and sends the new ciphertext here.
476
+ */
477
+ declare function useUpdateWalletEncryption(): {
478
+ updateWalletEncryption: (input: UpdateWalletEncryptionInput) => void;
479
+ updateWalletEncryptionAsync: (input: UpdateWalletEncryptionInput) => Promise<UpdateWalletEncryptionResponse>;
480
+ data: UpdateWalletEncryptionResponse | undefined;
481
+ isLoading: boolean;
482
+ isError: boolean;
483
+ error: Error | null;
484
+ isSuccess: boolean;
485
+ reset: () => void;
486
+ };
487
+
469
488
  type TransferInput = {
470
489
  params: TransferHookInput;
471
490
  bearerToken: string;
@@ -1625,4 +1644,4 @@ declare function useExecuteWithSession(): {
1625
1644
  reset: () => void;
1626
1645
  };
1627
1646
 
1628
- export { type ChipiWalletData, type SessionState, type SessionWallet, type UseChipiSessionConfig, type UseChipiSessionReturn, type UseChipiWalletConfig, type UseChipiWalletReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransactionList, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useTransfer };
1647
+ export { type ChipiWalletData, type SessionState, type SessionWallet, type UseChipiSessionConfig, type UseChipiSessionReturn, type UseChipiWalletConfig, type UseChipiWalletReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransactionList, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useTransfer, useUpdateWalletEncryption };
package/dist/hooks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CreateWalletParams, CreateWalletResponse, GetWalletParams, GetWalletResponse, ChainToken, GetTokenBalanceResponse, WalletType, WalletData, SessionKeyData, SessionDataResponse, CreateSessionKeyParams, SessionConfig, Call, MigrateWalletToPasskeyParams, TransferHookInput, ApproveHookInput, GetTransactionListQuery, PaginatedResponse, Transaction, CreateSkuPurchaseParams, GetSkuListQuery, Sku, CallAnyContractParams, RecordSendTransactionParams, GetTokenBalanceParams, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, ExecuteWithSessionParams } from '@chipi-stack/types';
1
+ import { CreateWalletParams, CreateWalletResponse, GetWalletParams, GetWalletResponse, ChainToken, GetTokenBalanceResponse, WalletType, WalletData, SessionKeyData, SessionDataResponse, CreateSessionKeyParams, SessionConfig, Call, MigrateWalletToPasskeyParams, UpdateWalletEncryptionParams, UpdateWalletEncryptionResponse, TransferHookInput, ApproveHookInput, GetTransactionListQuery, PaginatedResponse, Transaction, CreateSkuPurchaseParams, GetSkuListQuery, Sku, CallAnyContractParams, RecordSendTransactionParams, GetTokenBalanceParams, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, ExecuteWithSessionParams } from '@chipi-stack/types';
2
2
  import * as _tanstack_react_query from '@tanstack/react-query';
3
3
  import { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
4
4
 
@@ -466,6 +466,25 @@ declare function useMigrateWalletToPasskey(): {
466
466
  reset: () => void;
467
467
  };
468
468
 
469
+ type UpdateWalletEncryptionInput = UpdateWalletEncryptionParams & {
470
+ bearerToken: string;
471
+ };
472
+ /**
473
+ * Hook for updating a wallet's encrypted private key.
474
+ * Use when the user changes their passkey or PIN; the client re-encrypts the private key
475
+ * and sends the new ciphertext here.
476
+ */
477
+ declare function useUpdateWalletEncryption(): {
478
+ updateWalletEncryption: (input: UpdateWalletEncryptionInput) => void;
479
+ updateWalletEncryptionAsync: (input: UpdateWalletEncryptionInput) => Promise<UpdateWalletEncryptionResponse>;
480
+ data: UpdateWalletEncryptionResponse | undefined;
481
+ isLoading: boolean;
482
+ isError: boolean;
483
+ error: Error | null;
484
+ isSuccess: boolean;
485
+ reset: () => void;
486
+ };
487
+
469
488
  type TransferInput = {
470
489
  params: TransferHookInput;
471
490
  bearerToken: string;
@@ -1625,4 +1644,4 @@ declare function useExecuteWithSession(): {
1625
1644
  reset: () => void;
1626
1645
  };
1627
1646
 
1628
- export { type ChipiWalletData, type SessionState, type SessionWallet, type UseChipiSessionConfig, type UseChipiSessionReturn, type UseChipiWalletConfig, type UseChipiWalletReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransactionList, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useTransfer };
1647
+ export { type ChipiWalletData, type SessionState, type SessionWallet, type UseChipiSessionConfig, type UseChipiSessionReturn, type UseChipiWalletConfig, type UseChipiWalletReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransactionList, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useTransfer, useUpdateWalletEncryption };
package/dist/hooks.js CHANGED
@@ -3,8 +3,8 @@
3
3
  var reactQuery = require('@tanstack/react-query');
4
4
  var react = require('react');
5
5
  var backend = require('@chipi-stack/backend');
6
- require('react/jsx-runtime');
7
6
  var chipiPasskey = require('@chipi-stack/chipi-passkey');
7
+ require('react/jsx-runtime');
8
8
  var shared = require('@chipi-stack/shared');
9
9
  var types = require('@chipi-stack/types');
10
10
 
@@ -522,15 +522,47 @@ function useMigrateWalletToPasskey() {
522
522
  reset: mutation.reset
523
523
  };
524
524
  }
525
- function useTransfer() {
525
+ function useUpdateWalletEncryption() {
526
526
  const { chipiSDK } = useChipiContext();
527
+ const queryClient = reactQuery.useQueryClient();
528
+ const mutation = reactQuery.useMutation({
529
+ mutationFn: async (input) => {
530
+ const { bearerToken, ...params } = input;
531
+ return chipiSDK.wallets.updateWalletEncryption(params, bearerToken);
532
+ },
533
+ onSuccess: (_, variables) => {
534
+ queryClient.invalidateQueries({
535
+ queryKey: ["chipi-wallet", variables.externalUserId]
536
+ });
537
+ }
538
+ });
539
+ return {
540
+ updateWalletEncryption: mutation.mutate,
541
+ updateWalletEncryptionAsync: mutation.mutateAsync,
542
+ data: mutation.data,
543
+ isLoading: mutation.isPending,
544
+ isError: mutation.isError,
545
+ error: mutation.error,
546
+ isSuccess: mutation.isSuccess,
547
+ reset: mutation.reset
548
+ };
549
+ }
550
+ function useTransfer() {
551
+ const { chipiSDK, passkeyAdapter } = useChipiContext();
527
552
  const mutation = reactQuery.useMutation(
528
553
  {
529
554
  mutationFn: async (input) => {
530
555
  let encryptKey = input.params.encryptKey;
531
556
  if (input.params.usePasskey) {
557
+ if (!input.params.externalUserId) {
558
+ throw new Error(
559
+ "externalUserId is required when usePasskey is true"
560
+ );
561
+ }
532
562
  try {
533
- const key = await chipiPasskey.getWalletEncryptKey();
563
+ const key = await passkeyAdapter.getWalletEncryptKey({
564
+ externalUserId: input.params.externalUserId
565
+ });
534
566
  if (!key) {
535
567
  throw new Error("Passkey authentication was cancelled");
536
568
  }
@@ -567,13 +599,18 @@ function useTransfer() {
567
599
  };
568
600
  }
569
601
  function useApprove() {
570
- const { chipiSDK } = useChipiContext();
602
+ const { chipiSDK, passkeyAdapter } = useChipiContext();
571
603
  const mutation = reactQuery.useMutation({
572
604
  mutationFn: async (params) => {
573
605
  let encryptKey = params.params.encryptKey;
574
606
  if (params.params.usePasskey) {
607
+ if (!params.params.externalUserId) {
608
+ throw new Error("externalUserId is required when usePasskey is true");
609
+ }
575
610
  try {
576
- const key = await chipiPasskey.getWalletEncryptKey();
611
+ const key = await passkeyAdapter.getWalletEncryptKey({
612
+ externalUserId: params.params.externalUserId
613
+ });
577
614
  if (!key) {
578
615
  throw new Error("Passkey authentication was cancelled");
579
616
  }
@@ -807,13 +844,20 @@ function useGetSku(input) {
807
844
  };
808
845
  }
809
846
  function useCallAnyContract() {
810
- const { chipiSDK } = useChipiContext();
847
+ const { chipiSDK, passkeyAdapter } = useChipiContext();
811
848
  const mutation = reactQuery.useMutation({
812
849
  mutationFn: async (params) => {
813
850
  let encryptKey = params.params.encryptKey;
814
851
  if (params.params.usePasskey) {
852
+ if (!params.params.externalUserId) {
853
+ throw new Error(
854
+ "externalUserId is required when usePasskey is true"
855
+ );
856
+ }
815
857
  try {
816
- const key = await chipiPasskey.getWalletEncryptKey();
858
+ const key = await passkeyAdapter.getWalletEncryptKey({
859
+ externalUserId: params.params.externalUserId
860
+ });
817
861
  if (!key) {
818
862
  throw new Error("Passkey authentication was cancelled");
819
863
  }
@@ -1031,5 +1075,6 @@ exports.usePurchaseSku = usePurchaseSku;
1031
1075
  exports.useRecordSendTransaction = useRecordSendTransaction;
1032
1076
  exports.useRevokeSessionKey = useRevokeSessionKey;
1033
1077
  exports.useTransfer = useTransfer;
1078
+ exports.useUpdateWalletEncryption = useUpdateWalletEncryption;
1034
1079
  //# sourceMappingURL=hooks.js.map
1035
1080
  //# sourceMappingURL=hooks.js.map