@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 +24 -2
- package/dist/hooks.d.ts +24 -2
- package/dist/hooks.js +217 -36
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +217 -37
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +216 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +217 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var React = require('react');
|
|
|
4
4
|
var reactQuery = require('@tanstack/react-query');
|
|
5
5
|
var backend = require('@chipi-stack/backend');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var chipiPasskey = require('@chipi-stack/chipi-passkey');
|
|
7
8
|
var shared = require('@chipi-stack/shared');
|
|
8
9
|
|
|
9
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -53,10 +54,34 @@ function useChipiContext() {
|
|
|
53
54
|
function useCreateWallet() {
|
|
54
55
|
const { chipiSDK } = useChipiContext();
|
|
55
56
|
const mutation = reactQuery.useMutation({
|
|
56
|
-
mutationFn: (input) =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
mutationFn: async (input) => {
|
|
58
|
+
let encryptKey = input.params.encryptKey;
|
|
59
|
+
if (input.params.usePasskey) {
|
|
60
|
+
if (!input.params.externalUserId) {
|
|
61
|
+
throw new Error("externalUserId is required when using passkey");
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const passkeyResult = await chipiPasskey.createWalletPasskey(
|
|
65
|
+
input.params.externalUserId,
|
|
66
|
+
input.params.externalUserId
|
|
67
|
+
// Using externalUserId as userName
|
|
68
|
+
);
|
|
69
|
+
encryptKey = passkeyResult.encryptKey;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (error instanceof Error) {
|
|
72
|
+
throw new Error(`Passkey creation failed: ${error.message}`);
|
|
73
|
+
}
|
|
74
|
+
throw new Error("Failed to create passkey for wallet");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return chipiSDK.createWallet({
|
|
78
|
+
params: {
|
|
79
|
+
...input.params,
|
|
80
|
+
encryptKey
|
|
81
|
+
},
|
|
82
|
+
bearerToken: input.bearerToken
|
|
83
|
+
});
|
|
84
|
+
}
|
|
60
85
|
});
|
|
61
86
|
return {
|
|
62
87
|
createWallet: mutation.mutate,
|
|
@@ -476,17 +501,91 @@ function useChipiSession(config) {
|
|
|
476
501
|
error: combinedError
|
|
477
502
|
};
|
|
478
503
|
}
|
|
504
|
+
function useMigrateWalletToPasskey() {
|
|
505
|
+
const { chipiSDK } = useChipiContext();
|
|
506
|
+
const mutation = reactQuery.useMutation({
|
|
507
|
+
mutationFn: async (input) => {
|
|
508
|
+
const { wallet, oldEncryptKey, externalUserId, bearerToken } = input;
|
|
509
|
+
try {
|
|
510
|
+
const passkeyResult = await chipiPasskey.createWalletPasskey(
|
|
511
|
+
externalUserId,
|
|
512
|
+
externalUserId
|
|
513
|
+
// Using externalUserId as userName
|
|
514
|
+
);
|
|
515
|
+
let decryptedPrivateKey;
|
|
516
|
+
try {
|
|
517
|
+
decryptedPrivateKey = backend.decryptPrivateKey(
|
|
518
|
+
wallet.encryptedPrivateKey,
|
|
519
|
+
oldEncryptKey
|
|
520
|
+
);
|
|
521
|
+
} catch (error) {
|
|
522
|
+
throw new Error(
|
|
523
|
+
"Failed to decrypt wallet with provided encryptKey. Please verify your PIN/password is correct."
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
const newEncryptedPrivateKey = backend.encryptPrivateKey(
|
|
527
|
+
decryptedPrivateKey,
|
|
528
|
+
passkeyResult.encryptKey
|
|
529
|
+
);
|
|
530
|
+
const updatedWallet = {
|
|
531
|
+
...wallet,
|
|
532
|
+
encryptedPrivateKey: newEncryptedPrivateKey
|
|
533
|
+
};
|
|
534
|
+
return {
|
|
535
|
+
success: true,
|
|
536
|
+
wallet: updatedWallet,
|
|
537
|
+
credentialId: passkeyResult.credentialId
|
|
538
|
+
};
|
|
539
|
+
} catch (error) {
|
|
540
|
+
if (error instanceof Error) {
|
|
541
|
+
throw new Error(`Migration failed: ${error.message}`);
|
|
542
|
+
}
|
|
543
|
+
throw new Error("Failed to migrate wallet to passkey");
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
return {
|
|
548
|
+
migrateWalletToPasskey: mutation.mutate,
|
|
549
|
+
migrateWalletToPasskeyAsync: mutation.mutateAsync,
|
|
550
|
+
data: mutation.data,
|
|
551
|
+
isLoading: mutation.isPending,
|
|
552
|
+
isError: mutation.isError,
|
|
553
|
+
error: mutation.error,
|
|
554
|
+
isSuccess: mutation.isSuccess,
|
|
555
|
+
reset: mutation.reset
|
|
556
|
+
};
|
|
557
|
+
}
|
|
479
558
|
function useTransfer() {
|
|
480
559
|
const { chipiSDK } = useChipiContext();
|
|
481
560
|
const mutation = reactQuery.useMutation(
|
|
482
561
|
{
|
|
483
|
-
mutationFn: (input) =>
|
|
484
|
-
params
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
562
|
+
mutationFn: async (input) => {
|
|
563
|
+
let encryptKey = input.params.encryptKey;
|
|
564
|
+
if (input.params.usePasskey) {
|
|
565
|
+
try {
|
|
566
|
+
const key = await chipiPasskey.getWalletEncryptKey();
|
|
567
|
+
if (!key) {
|
|
568
|
+
throw new Error("Passkey authentication was cancelled");
|
|
569
|
+
}
|
|
570
|
+
encryptKey = key;
|
|
571
|
+
} catch (error) {
|
|
572
|
+
if (error instanceof Error) {
|
|
573
|
+
throw new Error(
|
|
574
|
+
`Passkey authentication failed: ${error.message}`
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
throw new Error("Failed to authenticate with passkey");
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return chipiSDK.transfer({
|
|
581
|
+
params: {
|
|
582
|
+
...input.params,
|
|
583
|
+
amount: String(input.params.amount),
|
|
584
|
+
encryptKey
|
|
585
|
+
},
|
|
586
|
+
bearerToken: input.bearerToken
|
|
587
|
+
});
|
|
588
|
+
}
|
|
490
589
|
}
|
|
491
590
|
);
|
|
492
591
|
return {
|
|
@@ -503,13 +602,31 @@ function useTransfer() {
|
|
|
503
602
|
function useApprove() {
|
|
504
603
|
const { chipiSDK } = useChipiContext();
|
|
505
604
|
const mutation = reactQuery.useMutation({
|
|
506
|
-
mutationFn: (params) =>
|
|
507
|
-
params
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
605
|
+
mutationFn: async (params) => {
|
|
606
|
+
let encryptKey = params.params.encryptKey;
|
|
607
|
+
if (params.params.usePasskey) {
|
|
608
|
+
try {
|
|
609
|
+
const key = await chipiPasskey.getWalletEncryptKey();
|
|
610
|
+
if (!key) {
|
|
611
|
+
throw new Error("Passkey authentication was cancelled");
|
|
612
|
+
}
|
|
613
|
+
encryptKey = key;
|
|
614
|
+
} catch (error) {
|
|
615
|
+
if (error instanceof Error) {
|
|
616
|
+
throw new Error(`Passkey authentication failed: ${error.message}`);
|
|
617
|
+
}
|
|
618
|
+
throw new Error("Failed to authenticate with passkey");
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return chipiSDK.approve({
|
|
622
|
+
params: {
|
|
623
|
+
...params.params,
|
|
624
|
+
amount: String(params.params.amount),
|
|
625
|
+
encryptKey
|
|
626
|
+
},
|
|
627
|
+
bearerToken: params.bearerToken
|
|
628
|
+
});
|
|
629
|
+
}
|
|
513
630
|
});
|
|
514
631
|
return {
|
|
515
632
|
approve: mutation.mutate,
|
|
@@ -724,13 +841,33 @@ function useGetSku(input) {
|
|
|
724
841
|
function useStakeVesuUsdc() {
|
|
725
842
|
const { chipiSDK } = useChipiContext();
|
|
726
843
|
const mutation = reactQuery.useMutation({
|
|
727
|
-
mutationFn: (params) =>
|
|
728
|
-
params
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
844
|
+
mutationFn: async (params) => {
|
|
845
|
+
let encryptKey = params.params.encryptKey;
|
|
846
|
+
if (params.params.usePasskey) {
|
|
847
|
+
try {
|
|
848
|
+
const key = await chipiPasskey.getWalletEncryptKey();
|
|
849
|
+
if (!key) {
|
|
850
|
+
throw new Error("Passkey authentication was cancelled");
|
|
851
|
+
}
|
|
852
|
+
encryptKey = key;
|
|
853
|
+
} catch (error) {
|
|
854
|
+
if (error instanceof Error) {
|
|
855
|
+
throw new Error(
|
|
856
|
+
`Passkey authentication failed: ${error.message}`
|
|
857
|
+
);
|
|
858
|
+
}
|
|
859
|
+
throw new Error("Failed to authenticate with passkey");
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return chipiSDK.stakeVesuUsdc({
|
|
863
|
+
params: {
|
|
864
|
+
...params.params,
|
|
865
|
+
amount: String(params.params.amount),
|
|
866
|
+
encryptKey
|
|
867
|
+
},
|
|
868
|
+
bearerToken: params.bearerToken
|
|
869
|
+
});
|
|
870
|
+
}
|
|
734
871
|
});
|
|
735
872
|
return {
|
|
736
873
|
stakeVesuUsdc: mutation.mutate,
|
|
@@ -746,13 +883,33 @@ function useStakeVesuUsdc() {
|
|
|
746
883
|
function useWithdrawVesuUsdc() {
|
|
747
884
|
const { chipiSDK } = useChipiContext();
|
|
748
885
|
const mutation = reactQuery.useMutation({
|
|
749
|
-
mutationFn: (params) =>
|
|
750
|
-
params
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
886
|
+
mutationFn: async (params) => {
|
|
887
|
+
let encryptKey = params.params.encryptKey;
|
|
888
|
+
if (params.params.usePasskey) {
|
|
889
|
+
try {
|
|
890
|
+
const key = await chipiPasskey.getWalletEncryptKey();
|
|
891
|
+
if (!key) {
|
|
892
|
+
throw new Error("Passkey authentication was cancelled");
|
|
893
|
+
}
|
|
894
|
+
encryptKey = key;
|
|
895
|
+
} catch (error) {
|
|
896
|
+
if (error instanceof Error) {
|
|
897
|
+
throw new Error(
|
|
898
|
+
`Passkey authentication failed: ${error.message}`
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
throw new Error("Failed to authenticate with passkey");
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
return chipiSDK.withdrawVesuUsdc({
|
|
905
|
+
params: {
|
|
906
|
+
...params.params,
|
|
907
|
+
amount: String(params.params.amount),
|
|
908
|
+
encryptKey
|
|
909
|
+
},
|
|
910
|
+
bearerToken: params.bearerToken
|
|
911
|
+
});
|
|
912
|
+
}
|
|
756
913
|
});
|
|
757
914
|
return {
|
|
758
915
|
withdrawVesuUsdc: mutation.mutate,
|
|
@@ -768,7 +925,32 @@ function useWithdrawVesuUsdc() {
|
|
|
768
925
|
function useCallAnyContract() {
|
|
769
926
|
const { chipiSDK } = useChipiContext();
|
|
770
927
|
const mutation = reactQuery.useMutation({
|
|
771
|
-
mutationFn: (params) =>
|
|
928
|
+
mutationFn: async (params) => {
|
|
929
|
+
let encryptKey = params.params.encryptKey;
|
|
930
|
+
if (params.params.usePasskey) {
|
|
931
|
+
try {
|
|
932
|
+
const key = await chipiPasskey.getWalletEncryptKey();
|
|
933
|
+
if (!key) {
|
|
934
|
+
throw new Error("Passkey authentication was cancelled");
|
|
935
|
+
}
|
|
936
|
+
encryptKey = key;
|
|
937
|
+
} catch (error) {
|
|
938
|
+
if (error instanceof Error) {
|
|
939
|
+
throw new Error(
|
|
940
|
+
`Passkey authentication failed: ${error.message}`
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
throw new Error("Failed to authenticate with passkey");
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return chipiSDK.callAnyContract({
|
|
947
|
+
params: {
|
|
948
|
+
...params.params,
|
|
949
|
+
encryptKey
|
|
950
|
+
},
|
|
951
|
+
bearerToken: params.bearerToken
|
|
952
|
+
});
|
|
953
|
+
}
|
|
772
954
|
});
|
|
773
955
|
return {
|
|
774
956
|
callAnyContract: mutation.mutate,
|
|
@@ -1049,6 +1231,7 @@ exports.useGetTokenBalance = useGetTokenBalance;
|
|
|
1049
1231
|
exports.useGetTransactionList = useGetTransactionList;
|
|
1050
1232
|
exports.useGetUser = useGetUser;
|
|
1051
1233
|
exports.useGetWallet = useGetWallet;
|
|
1234
|
+
exports.useMigrateWalletToPasskey = useMigrateWalletToPasskey;
|
|
1052
1235
|
exports.useRecordSendTransaction = useRecordSendTransaction;
|
|
1053
1236
|
exports.useRevokeSessionKey = useRevokeSessionKey;
|
|
1054
1237
|
exports.useStakeVesuUsdc = useStakeVesuUsdc;
|