@chipi-stack/chipi-react 14.2.0 → 14.3.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 +93 -5
- package/dist/hooks.d.ts +93 -5
- package/dist/hooks.js +92 -19
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +92 -20
- 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 +104 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +105 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/hooks.mjs
CHANGED
|
@@ -21,6 +21,10 @@ function useCreateWallet() {
|
|
|
21
21
|
const mutation = useMutation({
|
|
22
22
|
mutationFn: async (input) => {
|
|
23
23
|
let encryptKey = input.params.encryptKey;
|
|
24
|
+
let encryptKeyBackup;
|
|
25
|
+
let credentialId;
|
|
26
|
+
let prfSupported;
|
|
27
|
+
let authMethod;
|
|
24
28
|
if (input.params.usePasskey) {
|
|
25
29
|
if (!input.params.externalUserId) {
|
|
26
30
|
throw new Error("externalUserId is required when using passkey");
|
|
@@ -29,15 +33,25 @@ function useCreateWallet() {
|
|
|
29
33
|
const passkeyResult = await createWalletPasskey(
|
|
30
34
|
input.params.externalUserId,
|
|
31
35
|
input.params.externalUserId
|
|
32
|
-
// Using externalUserId as userName
|
|
33
36
|
);
|
|
34
|
-
|
|
37
|
+
credentialId = passkeyResult.credentialId;
|
|
38
|
+
prfSupported = passkeyResult.prfSupported;
|
|
39
|
+
if (encryptKey) {
|
|
40
|
+
encryptKeyBackup = encryptKey;
|
|
41
|
+
encryptKey = passkeyResult.encryptKey;
|
|
42
|
+
authMethod = "passkey+pin";
|
|
43
|
+
} else {
|
|
44
|
+
encryptKey = passkeyResult.encryptKey;
|
|
45
|
+
authMethod = "passkey";
|
|
46
|
+
}
|
|
35
47
|
} catch (error) {
|
|
36
48
|
if (error instanceof Error) {
|
|
37
49
|
throw new Error(`Passkey creation failed: ${error.message}`);
|
|
38
50
|
}
|
|
39
51
|
throw new Error("Failed to create passkey for wallet");
|
|
40
52
|
}
|
|
53
|
+
} else {
|
|
54
|
+
authMethod = encryptKey ? "pin" : void 0;
|
|
41
55
|
}
|
|
42
56
|
if (!encryptKey) {
|
|
43
57
|
throw new Error("encryptKey is required when usePasskey is false");
|
|
@@ -45,7 +59,12 @@ function useCreateWallet() {
|
|
|
45
59
|
return chipiSDK.createWallet({
|
|
46
60
|
params: {
|
|
47
61
|
...input.params,
|
|
48
|
-
encryptKey
|
|
62
|
+
encryptKey,
|
|
63
|
+
encryptKeyBackup,
|
|
64
|
+
authMethod,
|
|
65
|
+
credentialId,
|
|
66
|
+
prfSupported,
|
|
67
|
+
deviceType: "web"
|
|
49
68
|
},
|
|
50
69
|
bearerToken: input.bearerToken
|
|
51
70
|
});
|
|
@@ -553,6 +572,7 @@ function useChipiSession(config) {
|
|
|
553
572
|
}
|
|
554
573
|
function useMigrateWalletToPasskey() {
|
|
555
574
|
const { chipiSDK } = useChipiContext();
|
|
575
|
+
const queryClient = useQueryClient();
|
|
556
576
|
const mutation = useMutation({
|
|
557
577
|
mutationFn: async (input) => {
|
|
558
578
|
const { wallet, oldEncryptKey, externalUserId, bearerToken } = input;
|
|
@@ -574,10 +594,27 @@ function useMigrateWalletToPasskey() {
|
|
|
574
594
|
decryptedPrivateKey,
|
|
575
595
|
passkeyResult.encryptKey
|
|
576
596
|
);
|
|
597
|
+
const updateResult = await chipiSDK.wallets.updateWalletEncryption(
|
|
598
|
+
{
|
|
599
|
+
externalUserId,
|
|
600
|
+
newEncryptedPrivateKey,
|
|
601
|
+
publicKey: wallet.publicKey
|
|
602
|
+
},
|
|
603
|
+
bearerToken
|
|
604
|
+
);
|
|
605
|
+
if (updateResult?.success === false) {
|
|
606
|
+
throw new Error("Backend rejected wallet encryption update");
|
|
607
|
+
}
|
|
577
608
|
const updatedWallet = {
|
|
578
609
|
...wallet,
|
|
579
610
|
encryptedPrivateKey: newEncryptedPrivateKey
|
|
580
611
|
};
|
|
612
|
+
queryClient.invalidateQueries({
|
|
613
|
+
queryKey: ["chipi-wallet", externalUserId]
|
|
614
|
+
});
|
|
615
|
+
queryClient.invalidateQueries({
|
|
616
|
+
queryKey: ["wallet", externalUserId]
|
|
617
|
+
});
|
|
581
618
|
return {
|
|
582
619
|
success: true,
|
|
583
620
|
wallet: updatedWallet,
|
|
@@ -627,31 +664,40 @@ function useUpdateWalletEncryption() {
|
|
|
627
664
|
reset: mutation.reset
|
|
628
665
|
};
|
|
629
666
|
}
|
|
630
|
-
function useTransfer() {
|
|
667
|
+
function useTransfer(config) {
|
|
631
668
|
const { chipiSDK, passkeyAdapter } = useChipiContext();
|
|
632
669
|
const mutation = useMutation({
|
|
633
670
|
mutationFn: async (input) => {
|
|
634
671
|
let encryptKey = input.params.encryptKey;
|
|
672
|
+
let walletForTransfer = input.params.wallet;
|
|
635
673
|
if (input.params.usePasskey) {
|
|
636
674
|
if (!input.params.externalUserId) {
|
|
637
675
|
throw new Error("externalUserId is required when usePasskey is true");
|
|
638
676
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
677
|
+
const passkeyKey = await passkeyAdapter.getWalletEncryptKey({
|
|
678
|
+
externalUserId: input.params.externalUserId
|
|
679
|
+
});
|
|
680
|
+
if (passkeyKey) {
|
|
681
|
+
encryptKey = passkeyKey;
|
|
682
|
+
} else {
|
|
683
|
+
const wallet = input.params.wallet;
|
|
684
|
+
if (wallet.encryptedPrivateKeyBackup && config?.onPinRequired) {
|
|
685
|
+
const pin = await config.onPinRequired();
|
|
686
|
+
if (!pin) {
|
|
687
|
+
throw new Error("Transfer cancelled \u2014 PIN required as passkey fallback");
|
|
688
|
+
}
|
|
689
|
+
encryptKey = pin;
|
|
690
|
+
walletForTransfer = {
|
|
691
|
+
...wallet,
|
|
692
|
+
encryptedPrivateKey: wallet.encryptedPrivateKeyBackup
|
|
693
|
+
};
|
|
694
|
+
} else if (wallet.encryptedPrivateKeyBackup) {
|
|
695
|
+
throw new Error(
|
|
696
|
+
"Passkey authentication failed. Provide an onPinRequired callback to use PIN backup."
|
|
697
|
+
);
|
|
698
|
+
} else {
|
|
699
|
+
throw new Error("Passkey authentication failed and no PIN backup available.");
|
|
653
700
|
}
|
|
654
|
-
throw new Error("Failed to authenticate with passkey");
|
|
655
701
|
}
|
|
656
702
|
}
|
|
657
703
|
if (!encryptKey) {
|
|
@@ -665,6 +711,7 @@ function useTransfer() {
|
|
|
665
711
|
return chipiSDK.transfer({
|
|
666
712
|
params: {
|
|
667
713
|
...transferParams,
|
|
714
|
+
wallet: walletForTransfer,
|
|
668
715
|
amount: String(transferParams.amount),
|
|
669
716
|
encryptKey
|
|
670
717
|
},
|
|
@@ -887,6 +934,31 @@ function useGetTransactionStatus(input) {
|
|
|
887
934
|
fetchTransactionStatus
|
|
888
935
|
};
|
|
889
936
|
}
|
|
937
|
+
function useSyncOnChainTransfers() {
|
|
938
|
+
const { chipiSDK } = useChipiContext();
|
|
939
|
+
const queryClient = useQueryClient();
|
|
940
|
+
const mutation = useMutation({
|
|
941
|
+
mutationFn: async (input) => {
|
|
942
|
+
const { bearerToken, ...params } = input;
|
|
943
|
+
return chipiSDK.transactions.syncOnChainTransfers(params, bearerToken);
|
|
944
|
+
},
|
|
945
|
+
onSuccess: () => {
|
|
946
|
+
queryClient.invalidateQueries({
|
|
947
|
+
predicate: (query) => query.queryKey[0] === "transaction-list"
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
return {
|
|
952
|
+
syncTransfers: mutation.mutate,
|
|
953
|
+
syncTransfersAsync: mutation.mutateAsync,
|
|
954
|
+
data: mutation.data,
|
|
955
|
+
isLoading: mutation.isPending,
|
|
956
|
+
isError: mutation.isError,
|
|
957
|
+
error: mutation.error,
|
|
958
|
+
isSuccess: mutation.isSuccess,
|
|
959
|
+
reset: mutation.reset
|
|
960
|
+
};
|
|
961
|
+
}
|
|
890
962
|
function usePurchaseSku() {
|
|
891
963
|
const { chipiSDK } = useChipiContext();
|
|
892
964
|
const mutation = useMutation({
|
|
@@ -1478,6 +1550,6 @@ function useX402Payment(config) {
|
|
|
1478
1550
|
};
|
|
1479
1551
|
}
|
|
1480
1552
|
|
|
1481
|
-
export { useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransaction, useGetTransactionList, useGetTransactionStatus, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useTransfer, useUpdateWalletEncryption, useX402Payment };
|
|
1553
|
+
export { useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransaction, useGetTransactionList, useGetTransactionStatus, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useSyncOnChainTransfers, useTransfer, useUpdateWalletEncryption, useX402Payment };
|
|
1482
1554
|
//# sourceMappingURL=hooks.mjs.map
|
|
1483
1555
|
//# sourceMappingURL=hooks.mjs.map
|