@chipi-stack/chipi-react 12.2.0 → 12.4.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, TransferHookInput, ApproveHookInput, GetTransactionListQuery, PaginatedResponse, Transaction, CreateSkuTransactionParams, SkuTransaction, GetSkuListQuery, Sku, StakeVesuUsdcHookInputParams, WithdrawVesuUsdcHookInputParams, CallAnyContractParams, RecordSendTransactionParams, GetTokenBalanceParams, GetUserParams, User, CreateUserParams, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, ExecuteWithSessionParams } from '@chipi-stack/types';
1
+ import { CreateWalletParams, CreateWalletResponse, GetWalletParams, GetWalletResponse, ChainToken, GetTokenBalanceResponse, WalletType, WalletData, SessionKeyData, SessionDataResponse, CreateSessionKeyParams, SessionConfig, Call, MigrateWalletToPasskeyParams, TransferHookInput, ApproveHookInput, GetTransactionListQuery, PaginatedResponse, Transaction, CreateSkuTransactionParams, SkuTransaction, GetSkuListQuery, Sku, StakeVesuUsdcHookInputParams, WithdrawVesuUsdcHookInputParams, CallAnyContractParams, RecordSendTransactionParams, GetTokenBalanceParams, GetUserParams, User, CreateUserParams, 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
 
@@ -444,6 +444,28 @@ interface UseChipiSessionReturn {
444
444
  */
445
445
  declare function useChipiSession(config: UseChipiSessionConfig): UseChipiSessionReturn;
446
446
 
447
+ type MigrateWalletToPasskeyInput = MigrateWalletToPasskeyParams & {
448
+ bearerToken: string;
449
+ };
450
+ interface MigrateWalletToPasskeyResult {
451
+ success: boolean;
452
+ wallet: WalletData;
453
+ credentialId: string;
454
+ }
455
+ /**
456
+ * Hook for migrating a wallet from encryptKey (PIN) to passkey authentication
457
+ */
458
+ declare function useMigrateWalletToPasskey(): {
459
+ migrateWalletToPasskey: (input: MigrateWalletToPasskeyInput) => void;
460
+ migrateWalletToPasskeyAsync: (input: MigrateWalletToPasskeyInput) => Promise<MigrateWalletToPasskeyResult>;
461
+ data: MigrateWalletToPasskeyResult | undefined;
462
+ isLoading: boolean;
463
+ isError: boolean;
464
+ error: Error | null;
465
+ isSuccess: boolean;
466
+ reset: () => void;
467
+ };
468
+
447
469
  type TransferInput = {
448
470
  params: TransferHookInput;
449
471
  bearerToken: string;
@@ -1874,4 +1896,4 @@ declare function useExecuteWithSession(): {
1874
1896
  reset: () => void;
1875
1897
  };
1876
1898
 
1877
- export { type ChipiWalletData, type SessionState, type SessionWallet, type UseChipiSessionConfig, type UseChipiSessionReturn, type UseChipiWalletConfig, type UseChipiWalletReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateSkuTransaction, useCreateUser, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuTransaction, useGetTokenBalance, useGetTransactionList, useGetUser, useGetWallet, useRecordSendTransaction, useRevokeSessionKey, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
1899
+ export { type ChipiWalletData, type SessionState, type SessionWallet, type UseChipiSessionConfig, type UseChipiSessionReturn, type UseChipiWalletConfig, type UseChipiWalletReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateSkuTransaction, useCreateUser, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuTransaction, useGetTokenBalance, useGetTransactionList, useGetUser, useGetWallet, useMigrateWalletToPasskey, useRecordSendTransaction, useRevokeSessionKey, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
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, TransferHookInput, ApproveHookInput, GetTransactionListQuery, PaginatedResponse, Transaction, CreateSkuTransactionParams, SkuTransaction, GetSkuListQuery, Sku, StakeVesuUsdcHookInputParams, WithdrawVesuUsdcHookInputParams, CallAnyContractParams, RecordSendTransactionParams, GetTokenBalanceParams, GetUserParams, User, CreateUserParams, AddSessionKeyParams, RevokeSessionKeyParams, GetSessionDataParams, ExecuteWithSessionParams } from '@chipi-stack/types';
1
+ import { CreateWalletParams, CreateWalletResponse, GetWalletParams, GetWalletResponse, ChainToken, GetTokenBalanceResponse, WalletType, WalletData, SessionKeyData, SessionDataResponse, CreateSessionKeyParams, SessionConfig, Call, MigrateWalletToPasskeyParams, TransferHookInput, ApproveHookInput, GetTransactionListQuery, PaginatedResponse, Transaction, CreateSkuTransactionParams, SkuTransaction, GetSkuListQuery, Sku, StakeVesuUsdcHookInputParams, WithdrawVesuUsdcHookInputParams, CallAnyContractParams, RecordSendTransactionParams, GetTokenBalanceParams, GetUserParams, User, CreateUserParams, 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
 
@@ -444,6 +444,28 @@ interface UseChipiSessionReturn {
444
444
  */
445
445
  declare function useChipiSession(config: UseChipiSessionConfig): UseChipiSessionReturn;
446
446
 
447
+ type MigrateWalletToPasskeyInput = MigrateWalletToPasskeyParams & {
448
+ bearerToken: string;
449
+ };
450
+ interface MigrateWalletToPasskeyResult {
451
+ success: boolean;
452
+ wallet: WalletData;
453
+ credentialId: string;
454
+ }
455
+ /**
456
+ * Hook for migrating a wallet from encryptKey (PIN) to passkey authentication
457
+ */
458
+ declare function useMigrateWalletToPasskey(): {
459
+ migrateWalletToPasskey: (input: MigrateWalletToPasskeyInput) => void;
460
+ migrateWalletToPasskeyAsync: (input: MigrateWalletToPasskeyInput) => Promise<MigrateWalletToPasskeyResult>;
461
+ data: MigrateWalletToPasskeyResult | undefined;
462
+ isLoading: boolean;
463
+ isError: boolean;
464
+ error: Error | null;
465
+ isSuccess: boolean;
466
+ reset: () => void;
467
+ };
468
+
447
469
  type TransferInput = {
448
470
  params: TransferHookInput;
449
471
  bearerToken: string;
@@ -1874,4 +1896,4 @@ declare function useExecuteWithSession(): {
1874
1896
  reset: () => void;
1875
1897
  };
1876
1898
 
1877
- export { type ChipiWalletData, type SessionState, type SessionWallet, type UseChipiSessionConfig, type UseChipiSessionReturn, type UseChipiWalletConfig, type UseChipiWalletReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateSkuTransaction, useCreateUser, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuTransaction, useGetTokenBalance, useGetTransactionList, useGetUser, useGetWallet, useRecordSendTransaction, useRevokeSessionKey, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
1899
+ export { type ChipiWalletData, type SessionState, type SessionWallet, type UseChipiSessionConfig, type UseChipiSessionReturn, type UseChipiWalletConfig, type UseChipiWalletReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateSkuTransaction, useCreateUser, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuTransaction, useGetTokenBalance, useGetTransactionList, useGetUser, useGetWallet, useMigrateWalletToPasskey, useRecordSendTransaction, useRevokeSessionKey, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
package/dist/hooks.js CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  var reactQuery = require('@tanstack/react-query');
4
4
  var react = require('react');
5
- require('@chipi-stack/backend');
5
+ var backend = require('@chipi-stack/backend');
6
6
  require('react/jsx-runtime');
7
+ var chipiPasskey = require('@chipi-stack/chipi-passkey');
7
8
  var shared = require('@chipi-stack/shared');
8
9
 
9
10
  // src/hooks/useCreateWallet.ts
@@ -15,15 +16,37 @@ function useChipiContext() {
15
16
  }
16
17
  return context;
17
18
  }
18
-
19
- // src/hooks/useCreateWallet.ts
20
19
  function useCreateWallet() {
21
20
  const { chipiSDK } = useChipiContext();
22
21
  const mutation = reactQuery.useMutation({
23
- mutationFn: (input) => chipiSDK.createWallet({
24
- params: input.params,
25
- bearerToken: input.bearerToken
26
- })
22
+ mutationFn: async (input) => {
23
+ let encryptKey = input.params.encryptKey;
24
+ if (input.params.usePasskey) {
25
+ if (!input.params.externalUserId) {
26
+ throw new Error("externalUserId is required when using passkey");
27
+ }
28
+ try {
29
+ const passkeyResult = await chipiPasskey.createWalletPasskey(
30
+ input.params.externalUserId,
31
+ input.params.externalUserId
32
+ // Using externalUserId as userName
33
+ );
34
+ encryptKey = passkeyResult.encryptKey;
35
+ } catch (error) {
36
+ if (error instanceof Error) {
37
+ throw new Error(`Passkey creation failed: ${error.message}`);
38
+ }
39
+ throw new Error("Failed to create passkey for wallet");
40
+ }
41
+ }
42
+ return chipiSDK.createWallet({
43
+ params: {
44
+ ...input.params,
45
+ encryptKey
46
+ },
47
+ bearerToken: input.bearerToken
48
+ });
49
+ }
27
50
  });
28
51
  return {
29
52
  createWallet: mutation.mutate,
@@ -443,17 +466,91 @@ function useChipiSession(config) {
443
466
  error: combinedError
444
467
  };
445
468
  }
469
+ function useMigrateWalletToPasskey() {
470
+ const { chipiSDK } = useChipiContext();
471
+ const mutation = reactQuery.useMutation({
472
+ mutationFn: async (input) => {
473
+ const { wallet, oldEncryptKey, externalUserId, bearerToken } = input;
474
+ try {
475
+ const passkeyResult = await chipiPasskey.createWalletPasskey(
476
+ externalUserId,
477
+ externalUserId
478
+ // Using externalUserId as userName
479
+ );
480
+ let decryptedPrivateKey;
481
+ try {
482
+ decryptedPrivateKey = backend.decryptPrivateKey(
483
+ wallet.encryptedPrivateKey,
484
+ oldEncryptKey
485
+ );
486
+ } catch (error) {
487
+ throw new Error(
488
+ "Failed to decrypt wallet with provided encryptKey. Please verify your PIN/password is correct."
489
+ );
490
+ }
491
+ const newEncryptedPrivateKey = backend.encryptPrivateKey(
492
+ decryptedPrivateKey,
493
+ passkeyResult.encryptKey
494
+ );
495
+ const updatedWallet = {
496
+ ...wallet,
497
+ encryptedPrivateKey: newEncryptedPrivateKey
498
+ };
499
+ return {
500
+ success: true,
501
+ wallet: updatedWallet,
502
+ credentialId: passkeyResult.credentialId
503
+ };
504
+ } catch (error) {
505
+ if (error instanceof Error) {
506
+ throw new Error(`Migration failed: ${error.message}`);
507
+ }
508
+ throw new Error("Failed to migrate wallet to passkey");
509
+ }
510
+ }
511
+ });
512
+ return {
513
+ migrateWalletToPasskey: mutation.mutate,
514
+ migrateWalletToPasskeyAsync: mutation.mutateAsync,
515
+ data: mutation.data,
516
+ isLoading: mutation.isPending,
517
+ isError: mutation.isError,
518
+ error: mutation.error,
519
+ isSuccess: mutation.isSuccess,
520
+ reset: mutation.reset
521
+ };
522
+ }
446
523
  function useTransfer() {
447
524
  const { chipiSDK } = useChipiContext();
448
525
  const mutation = reactQuery.useMutation(
449
526
  {
450
- mutationFn: (input) => chipiSDK.transfer({
451
- params: {
452
- ...input.params,
453
- amount: String(input.params.amount)
454
- },
455
- bearerToken: input.bearerToken
456
- })
527
+ mutationFn: async (input) => {
528
+ let encryptKey = input.params.encryptKey;
529
+ if (input.params.usePasskey) {
530
+ try {
531
+ const key = await chipiPasskey.getWalletEncryptKey();
532
+ if (!key) {
533
+ throw new Error("Passkey authentication was cancelled");
534
+ }
535
+ encryptKey = key;
536
+ } catch (error) {
537
+ if (error instanceof Error) {
538
+ throw new Error(
539
+ `Passkey authentication failed: ${error.message}`
540
+ );
541
+ }
542
+ throw new Error("Failed to authenticate with passkey");
543
+ }
544
+ }
545
+ return chipiSDK.transfer({
546
+ params: {
547
+ ...input.params,
548
+ amount: String(input.params.amount),
549
+ encryptKey
550
+ },
551
+ bearerToken: input.bearerToken
552
+ });
553
+ }
457
554
  }
458
555
  );
459
556
  return {
@@ -470,13 +567,31 @@ function useTransfer() {
470
567
  function useApprove() {
471
568
  const { chipiSDK } = useChipiContext();
472
569
  const mutation = reactQuery.useMutation({
473
- mutationFn: (params) => chipiSDK.approve({
474
- params: {
475
- ...params.params,
476
- amount: String(params.params.amount)
477
- },
478
- bearerToken: params.bearerToken
479
- })
570
+ mutationFn: async (params) => {
571
+ let encryptKey = params.params.encryptKey;
572
+ if (params.params.usePasskey) {
573
+ try {
574
+ const key = await chipiPasskey.getWalletEncryptKey();
575
+ if (!key) {
576
+ throw new Error("Passkey authentication was cancelled");
577
+ }
578
+ encryptKey = key;
579
+ } catch (error) {
580
+ if (error instanceof Error) {
581
+ throw new Error(`Passkey authentication failed: ${error.message}`);
582
+ }
583
+ throw new Error("Failed to authenticate with passkey");
584
+ }
585
+ }
586
+ return chipiSDK.approve({
587
+ params: {
588
+ ...params.params,
589
+ amount: String(params.params.amount),
590
+ encryptKey
591
+ },
592
+ bearerToken: params.bearerToken
593
+ });
594
+ }
480
595
  });
481
596
  return {
482
597
  approve: mutation.mutate,
@@ -691,13 +806,33 @@ function useGetSku(input) {
691
806
  function useStakeVesuUsdc() {
692
807
  const { chipiSDK } = useChipiContext();
693
808
  const mutation = reactQuery.useMutation({
694
- mutationFn: (params) => chipiSDK.stakeVesuUsdc({
695
- params: {
696
- ...params.params,
697
- amount: String(params.params.amount)
698
- },
699
- bearerToken: params.bearerToken
700
- })
809
+ mutationFn: async (params) => {
810
+ let encryptKey = params.params.encryptKey;
811
+ if (params.params.usePasskey) {
812
+ try {
813
+ const key = await chipiPasskey.getWalletEncryptKey();
814
+ if (!key) {
815
+ throw new Error("Passkey authentication was cancelled");
816
+ }
817
+ encryptKey = key;
818
+ } catch (error) {
819
+ if (error instanceof Error) {
820
+ throw new Error(
821
+ `Passkey authentication failed: ${error.message}`
822
+ );
823
+ }
824
+ throw new Error("Failed to authenticate with passkey");
825
+ }
826
+ }
827
+ return chipiSDK.stakeVesuUsdc({
828
+ params: {
829
+ ...params.params,
830
+ amount: String(params.params.amount),
831
+ encryptKey
832
+ },
833
+ bearerToken: params.bearerToken
834
+ });
835
+ }
701
836
  });
702
837
  return {
703
838
  stakeVesuUsdc: mutation.mutate,
@@ -713,13 +848,33 @@ function useStakeVesuUsdc() {
713
848
  function useWithdrawVesuUsdc() {
714
849
  const { chipiSDK } = useChipiContext();
715
850
  const mutation = reactQuery.useMutation({
716
- mutationFn: (params) => chipiSDK.withdrawVesuUsdc({
717
- params: {
718
- ...params.params,
719
- amount: String(params.params.amount)
720
- },
721
- bearerToken: params.bearerToken
722
- })
851
+ mutationFn: async (params) => {
852
+ let encryptKey = params.params.encryptKey;
853
+ if (params.params.usePasskey) {
854
+ try {
855
+ const key = await chipiPasskey.getWalletEncryptKey();
856
+ if (!key) {
857
+ throw new Error("Passkey authentication was cancelled");
858
+ }
859
+ encryptKey = key;
860
+ } catch (error) {
861
+ if (error instanceof Error) {
862
+ throw new Error(
863
+ `Passkey authentication failed: ${error.message}`
864
+ );
865
+ }
866
+ throw new Error("Failed to authenticate with passkey");
867
+ }
868
+ }
869
+ return chipiSDK.withdrawVesuUsdc({
870
+ params: {
871
+ ...params.params,
872
+ amount: String(params.params.amount),
873
+ encryptKey
874
+ },
875
+ bearerToken: params.bearerToken
876
+ });
877
+ }
723
878
  });
724
879
  return {
725
880
  withdrawVesuUsdc: mutation.mutate,
@@ -735,7 +890,32 @@ function useWithdrawVesuUsdc() {
735
890
  function useCallAnyContract() {
736
891
  const { chipiSDK } = useChipiContext();
737
892
  const mutation = reactQuery.useMutation({
738
- mutationFn: (params) => chipiSDK.callAnyContract(params)
893
+ mutationFn: async (params) => {
894
+ let encryptKey = params.params.encryptKey;
895
+ if (params.params.usePasskey) {
896
+ try {
897
+ const key = await chipiPasskey.getWalletEncryptKey();
898
+ if (!key) {
899
+ throw new Error("Passkey authentication was cancelled");
900
+ }
901
+ encryptKey = key;
902
+ } catch (error) {
903
+ if (error instanceof Error) {
904
+ throw new Error(
905
+ `Passkey authentication failed: ${error.message}`
906
+ );
907
+ }
908
+ throw new Error("Failed to authenticate with passkey");
909
+ }
910
+ }
911
+ return chipiSDK.callAnyContract({
912
+ params: {
913
+ ...params.params,
914
+ encryptKey
915
+ },
916
+ bearerToken: params.bearerToken
917
+ });
918
+ }
739
919
  });
740
920
  return {
741
921
  callAnyContract: mutation.mutate,
@@ -1014,6 +1194,7 @@ exports.useGetTokenBalance = useGetTokenBalance;
1014
1194
  exports.useGetTransactionList = useGetTransactionList;
1015
1195
  exports.useGetUser = useGetUser;
1016
1196
  exports.useGetWallet = useGetWallet;
1197
+ exports.useMigrateWalletToPasskey = useMigrateWalletToPasskey;
1017
1198
  exports.useRecordSendTransaction = useRecordSendTransaction;
1018
1199
  exports.useRevokeSessionKey = useRevokeSessionKey;
1019
1200
  exports.useStakeVesuUsdc = useStakeVesuUsdc;