@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 +21 -2
- package/dist/hooks.d.ts +21 -2
- package/dist/hooks.js +52 -7
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +52 -8
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +65 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import React, { createContext, useContext, useMemo, useCallback, useState, useEffect } from 'react';
|
|
2
2
|
import { QueryClient, QueryClientProvider, useMutation, useQueryClient, useQuery } from '@tanstack/react-query';
|
|
3
3
|
import { ChipiSDK, decryptPrivateKey, encryptPrivateKey } from '@chipi-stack/backend';
|
|
4
|
+
import { getWalletEncryptKey, createWalletPasskey } from '@chipi-stack/chipi-passkey';
|
|
4
5
|
import { jsx } from 'react/jsx-runtime';
|
|
5
|
-
import { createWalletPasskey, getWalletEncryptKey } from '@chipi-stack/chipi-passkey';
|
|
6
6
|
import { ChipiApiError } from '@chipi-stack/shared';
|
|
7
7
|
import { Chain, ChainToken } from '@chipi-stack/types';
|
|
8
8
|
export { Chain, ChainToken } from '@chipi-stack/types';
|
|
9
9
|
|
|
10
10
|
// src/context/ChipiProvider.tsx
|
|
11
11
|
var ChipiContext = createContext(null);
|
|
12
|
+
var defaultPasskeyAdapter = {
|
|
13
|
+
// Web default: externalUserId is accepted for cross-platform API consistency
|
|
14
|
+
getWalletEncryptKey: async () => getWalletEncryptKey()
|
|
15
|
+
};
|
|
12
16
|
var createDefaultQueryClient = () => new QueryClient({
|
|
13
17
|
defaultOptions: {
|
|
14
18
|
queries: {
|
|
@@ -28,15 +32,21 @@ var createDefaultQueryClient = () => new QueryClient({
|
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
});
|
|
31
|
-
function ChipiProvider({
|
|
35
|
+
function ChipiProvider({
|
|
36
|
+
children,
|
|
37
|
+
config,
|
|
38
|
+
passkeyAdapter
|
|
39
|
+
}) {
|
|
32
40
|
const queryClient = React.useMemo(() => createDefaultQueryClient(), []);
|
|
33
41
|
const chipiSDK = React.useMemo(() => new ChipiSDK(config), [config]);
|
|
42
|
+
const resolvedPasskeyAdapter = passkeyAdapter ?? defaultPasskeyAdapter;
|
|
34
43
|
const value = React.useMemo(
|
|
35
44
|
() => ({
|
|
36
45
|
chipiSDK,
|
|
37
|
-
config
|
|
46
|
+
config,
|
|
47
|
+
passkeyAdapter: resolvedPasskeyAdapter
|
|
38
48
|
}),
|
|
39
|
-
[chipiSDK, config]
|
|
49
|
+
[chipiSDK, config, resolvedPasskeyAdapter]
|
|
40
50
|
);
|
|
41
51
|
return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(ChipiContext.Provider, { value, children }) });
|
|
42
52
|
}
|
|
@@ -552,15 +562,47 @@ function useMigrateWalletToPasskey() {
|
|
|
552
562
|
reset: mutation.reset
|
|
553
563
|
};
|
|
554
564
|
}
|
|
555
|
-
function
|
|
565
|
+
function useUpdateWalletEncryption() {
|
|
556
566
|
const { chipiSDK } = useChipiContext();
|
|
567
|
+
const queryClient = useQueryClient();
|
|
568
|
+
const mutation = useMutation({
|
|
569
|
+
mutationFn: async (input) => {
|
|
570
|
+
const { bearerToken, ...params } = input;
|
|
571
|
+
return chipiSDK.wallets.updateWalletEncryption(params, bearerToken);
|
|
572
|
+
},
|
|
573
|
+
onSuccess: (_, variables) => {
|
|
574
|
+
queryClient.invalidateQueries({
|
|
575
|
+
queryKey: ["chipi-wallet", variables.externalUserId]
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
return {
|
|
580
|
+
updateWalletEncryption: mutation.mutate,
|
|
581
|
+
updateWalletEncryptionAsync: mutation.mutateAsync,
|
|
582
|
+
data: mutation.data,
|
|
583
|
+
isLoading: mutation.isPending,
|
|
584
|
+
isError: mutation.isError,
|
|
585
|
+
error: mutation.error,
|
|
586
|
+
isSuccess: mutation.isSuccess,
|
|
587
|
+
reset: mutation.reset
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
function useTransfer() {
|
|
591
|
+
const { chipiSDK, passkeyAdapter } = useChipiContext();
|
|
557
592
|
const mutation = useMutation(
|
|
558
593
|
{
|
|
559
594
|
mutationFn: async (input) => {
|
|
560
595
|
let encryptKey = input.params.encryptKey;
|
|
561
596
|
if (input.params.usePasskey) {
|
|
597
|
+
if (!input.params.externalUserId) {
|
|
598
|
+
throw new Error(
|
|
599
|
+
"externalUserId is required when usePasskey is true"
|
|
600
|
+
);
|
|
601
|
+
}
|
|
562
602
|
try {
|
|
563
|
-
const key = await getWalletEncryptKey(
|
|
603
|
+
const key = await passkeyAdapter.getWalletEncryptKey({
|
|
604
|
+
externalUserId: input.params.externalUserId
|
|
605
|
+
});
|
|
564
606
|
if (!key) {
|
|
565
607
|
throw new Error("Passkey authentication was cancelled");
|
|
566
608
|
}
|
|
@@ -597,13 +639,18 @@ function useTransfer() {
|
|
|
597
639
|
};
|
|
598
640
|
}
|
|
599
641
|
function useApprove() {
|
|
600
|
-
const { chipiSDK } = useChipiContext();
|
|
642
|
+
const { chipiSDK, passkeyAdapter } = useChipiContext();
|
|
601
643
|
const mutation = useMutation({
|
|
602
644
|
mutationFn: async (params) => {
|
|
603
645
|
let encryptKey = params.params.encryptKey;
|
|
604
646
|
if (params.params.usePasskey) {
|
|
647
|
+
if (!params.params.externalUserId) {
|
|
648
|
+
throw new Error("externalUserId is required when usePasskey is true");
|
|
649
|
+
}
|
|
605
650
|
try {
|
|
606
|
-
const key = await getWalletEncryptKey(
|
|
651
|
+
const key = await passkeyAdapter.getWalletEncryptKey({
|
|
652
|
+
externalUserId: params.params.externalUserId
|
|
653
|
+
});
|
|
607
654
|
if (!key) {
|
|
608
655
|
throw new Error("Passkey authentication was cancelled");
|
|
609
656
|
}
|
|
@@ -837,13 +884,20 @@ function useGetSku(input) {
|
|
|
837
884
|
};
|
|
838
885
|
}
|
|
839
886
|
function useCallAnyContract() {
|
|
840
|
-
const { chipiSDK } = useChipiContext();
|
|
887
|
+
const { chipiSDK, passkeyAdapter } = useChipiContext();
|
|
841
888
|
const mutation = useMutation({
|
|
842
889
|
mutationFn: async (params) => {
|
|
843
890
|
let encryptKey = params.params.encryptKey;
|
|
844
891
|
if (params.params.usePasskey) {
|
|
892
|
+
if (!params.params.externalUserId) {
|
|
893
|
+
throw new Error(
|
|
894
|
+
"externalUserId is required when usePasskey is true"
|
|
895
|
+
);
|
|
896
|
+
}
|
|
845
897
|
try {
|
|
846
|
-
const key = await getWalletEncryptKey(
|
|
898
|
+
const key = await passkeyAdapter.getWalletEncryptKey({
|
|
899
|
+
externalUserId: params.params.externalUserId
|
|
900
|
+
});
|
|
847
901
|
if (!key) {
|
|
848
902
|
throw new Error("Passkey authentication was cancelled");
|
|
849
903
|
}
|
|
@@ -1041,6 +1095,6 @@ function useExecuteWithSession() {
|
|
|
1041
1095
|
};
|
|
1042
1096
|
}
|
|
1043
1097
|
|
|
1044
|
-
export { ChipiProvider, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiContext, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransactionList, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useTransfer };
|
|
1098
|
+
export { ChipiProvider, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiContext, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransactionList, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useTransfer, useUpdateWalletEncryption };
|
|
1045
1099
|
//# sourceMappingURL=index.mjs.map
|
|
1046
1100
|
//# sourceMappingURL=index.mjs.map
|