@chipi-stack/chipi-react 14.2.1 → 14.3.1
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 +74 -19
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +74 -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 +86 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { ChipiSDK } from '@chipi-stack/backend';
|
|
|
4
4
|
import { ChipiSDKConfig } from '@chipi-stack/types';
|
|
5
5
|
export * from '@chipi-stack/types';
|
|
6
6
|
export { Chain, ChainToken } from '@chipi-stack/types';
|
|
7
|
-
export { ChipiWalletData, SessionState, SessionWallet, UseChipiSessionConfig, UseChipiSessionReturn, UseChipiWalletConfig, UseChipiWalletReturn, UseX402PaymentConfig, UseX402PaymentReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransaction, useGetTransactionList, useGetTransactionStatus, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useTransfer, useUpdateWalletEncryption, useX402Payment } from './hooks.mjs';
|
|
7
|
+
export { ChipiWalletData, SessionState, SessionWallet, UseChipiSessionConfig, UseChipiSessionReturn, UseChipiWalletConfig, UseChipiWalletReturn, UseTransferConfig, UseX402PaymentConfig, UseX402PaymentReturn, 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 } from './hooks.mjs';
|
|
8
8
|
import '@tanstack/react-query';
|
|
9
9
|
|
|
10
10
|
interface PasskeyAdapter {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ChipiSDK } from '@chipi-stack/backend';
|
|
|
4
4
|
import { ChipiSDKConfig } from '@chipi-stack/types';
|
|
5
5
|
export * from '@chipi-stack/types';
|
|
6
6
|
export { Chain, ChainToken } from '@chipi-stack/types';
|
|
7
|
-
export { ChipiWalletData, SessionState, SessionWallet, UseChipiSessionConfig, UseChipiSessionReturn, UseChipiWalletConfig, UseChipiWalletReturn, UseX402PaymentConfig, UseX402PaymentReturn, useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuPurchase, useGetTokenBalance, useGetTransaction, useGetTransactionList, useGetTransactionStatus, useGetWallet, useMigrateWalletToPasskey, usePurchaseSku, useRecordSendTransaction, useRevokeSessionKey, useTransfer, useUpdateWalletEncryption, useX402Payment } from './hooks.js';
|
|
7
|
+
export { ChipiWalletData, SessionState, SessionWallet, UseChipiSessionConfig, UseChipiSessionReturn, UseChipiWalletConfig, UseChipiWalletReturn, UseTransferConfig, UseX402PaymentConfig, UseX402PaymentReturn, 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 } from './hooks.js';
|
|
8
8
|
import '@tanstack/react-query';
|
|
9
9
|
|
|
10
10
|
interface PasskeyAdapter {
|
package/dist/index.js
CHANGED
|
@@ -16,8 +16,18 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
16
16
|
// src/context/ChipiProvider.tsx
|
|
17
17
|
var ChipiContext = React.createContext(null);
|
|
18
18
|
var defaultPasskeyAdapter = {
|
|
19
|
-
// Web default:
|
|
20
|
-
getWalletEncryptKey: async () =>
|
|
19
|
+
// Web default: attempts passkey auth, returns null on failure (caller uses PIN backup)
|
|
20
|
+
getWalletEncryptKey: async () => {
|
|
21
|
+
try {
|
|
22
|
+
return await chipiPasskey.getWalletEncryptKey();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.warn(
|
|
25
|
+
"[ChipiProvider] Passkey auth failed, falling back to PIN:",
|
|
26
|
+
error instanceof Error ? error.message : error
|
|
27
|
+
);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
21
31
|
};
|
|
22
32
|
var createDefaultQueryClient = () => new reactQuery.QueryClient({
|
|
23
33
|
defaultOptions: {
|
|
@@ -64,6 +74,10 @@ function useCreateWallet() {
|
|
|
64
74
|
const mutation = reactQuery.useMutation({
|
|
65
75
|
mutationFn: async (input) => {
|
|
66
76
|
let encryptKey = input.params.encryptKey;
|
|
77
|
+
let encryptKeyBackup;
|
|
78
|
+
let credentialId;
|
|
79
|
+
let prfSupported;
|
|
80
|
+
let authMethod;
|
|
67
81
|
if (input.params.usePasskey) {
|
|
68
82
|
if (!input.params.externalUserId) {
|
|
69
83
|
throw new Error("externalUserId is required when using passkey");
|
|
@@ -72,15 +86,25 @@ function useCreateWallet() {
|
|
|
72
86
|
const passkeyResult = await chipiPasskey.createWalletPasskey(
|
|
73
87
|
input.params.externalUserId,
|
|
74
88
|
input.params.externalUserId
|
|
75
|
-
// Using externalUserId as userName
|
|
76
89
|
);
|
|
77
|
-
|
|
90
|
+
credentialId = passkeyResult.credentialId;
|
|
91
|
+
prfSupported = passkeyResult.prfSupported;
|
|
92
|
+
if (encryptKey) {
|
|
93
|
+
encryptKeyBackup = encryptKey;
|
|
94
|
+
encryptKey = passkeyResult.encryptKey;
|
|
95
|
+
authMethod = "passkey+pin";
|
|
96
|
+
} else {
|
|
97
|
+
encryptKey = passkeyResult.encryptKey;
|
|
98
|
+
authMethod = "passkey";
|
|
99
|
+
}
|
|
78
100
|
} catch (error) {
|
|
79
101
|
if (error instanceof Error) {
|
|
80
102
|
throw new Error(`Passkey creation failed: ${error.message}`);
|
|
81
103
|
}
|
|
82
104
|
throw new Error("Failed to create passkey for wallet");
|
|
83
105
|
}
|
|
106
|
+
} else {
|
|
107
|
+
authMethod = encryptKey ? "pin" : void 0;
|
|
84
108
|
}
|
|
85
109
|
if (!encryptKey) {
|
|
86
110
|
throw new Error("encryptKey is required when usePasskey is false");
|
|
@@ -88,7 +112,12 @@ function useCreateWallet() {
|
|
|
88
112
|
return chipiSDK.createWallet({
|
|
89
113
|
params: {
|
|
90
114
|
...input.params,
|
|
91
|
-
encryptKey
|
|
115
|
+
encryptKey,
|
|
116
|
+
encryptKeyBackup,
|
|
117
|
+
authMethod,
|
|
118
|
+
credentialId,
|
|
119
|
+
prfSupported,
|
|
120
|
+
deviceType: "web"
|
|
92
121
|
},
|
|
93
122
|
bearerToken: input.bearerToken
|
|
94
123
|
});
|
|
@@ -688,31 +717,40 @@ function useUpdateWalletEncryption() {
|
|
|
688
717
|
reset: mutation.reset
|
|
689
718
|
};
|
|
690
719
|
}
|
|
691
|
-
function useTransfer() {
|
|
720
|
+
function useTransfer(config) {
|
|
692
721
|
const { chipiSDK, passkeyAdapter } = useChipiContext();
|
|
693
722
|
const mutation = reactQuery.useMutation({
|
|
694
723
|
mutationFn: async (input) => {
|
|
695
724
|
let encryptKey = input.params.encryptKey;
|
|
725
|
+
let walletForTransfer = input.params.wallet;
|
|
696
726
|
if (input.params.usePasskey) {
|
|
697
727
|
if (!input.params.externalUserId) {
|
|
698
728
|
throw new Error("externalUserId is required when usePasskey is true");
|
|
699
729
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
730
|
+
const passkeyKey = await passkeyAdapter.getWalletEncryptKey({
|
|
731
|
+
externalUserId: input.params.externalUserId
|
|
732
|
+
});
|
|
733
|
+
if (passkeyKey) {
|
|
734
|
+
encryptKey = passkeyKey;
|
|
735
|
+
} else {
|
|
736
|
+
const wallet = input.params.wallet;
|
|
737
|
+
if (wallet.encryptedPrivateKeyBackup && config?.onPinRequired) {
|
|
738
|
+
const pin = await config.onPinRequired();
|
|
739
|
+
if (!pin) {
|
|
740
|
+
throw new Error("Transfer cancelled \u2014 PIN required as passkey fallback");
|
|
741
|
+
}
|
|
742
|
+
encryptKey = pin;
|
|
743
|
+
walletForTransfer = {
|
|
744
|
+
...wallet,
|
|
745
|
+
encryptedPrivateKey: wallet.encryptedPrivateKeyBackup
|
|
746
|
+
};
|
|
747
|
+
} else if (wallet.encryptedPrivateKeyBackup) {
|
|
748
|
+
throw new Error(
|
|
749
|
+
"Passkey authentication failed. Provide an onPinRequired callback to use PIN backup."
|
|
750
|
+
);
|
|
751
|
+
} else {
|
|
752
|
+
throw new Error("Passkey authentication failed and no PIN backup available.");
|
|
714
753
|
}
|
|
715
|
-
throw new Error("Failed to authenticate with passkey");
|
|
716
754
|
}
|
|
717
755
|
}
|
|
718
756
|
if (!encryptKey) {
|
|
@@ -726,6 +764,7 @@ function useTransfer() {
|
|
|
726
764
|
return chipiSDK.transfer({
|
|
727
765
|
params: {
|
|
728
766
|
...transferParams,
|
|
767
|
+
wallet: walletForTransfer,
|
|
729
768
|
amount: String(transferParams.amount),
|
|
730
769
|
encryptKey
|
|
731
770
|
},
|
|
@@ -948,6 +987,31 @@ function useGetTransactionStatus(input) {
|
|
|
948
987
|
fetchTransactionStatus
|
|
949
988
|
};
|
|
950
989
|
}
|
|
990
|
+
function useSyncOnChainTransfers() {
|
|
991
|
+
const { chipiSDK } = useChipiContext();
|
|
992
|
+
const queryClient = reactQuery.useQueryClient();
|
|
993
|
+
const mutation = reactQuery.useMutation({
|
|
994
|
+
mutationFn: async (input) => {
|
|
995
|
+
const { bearerToken, ...params } = input;
|
|
996
|
+
return chipiSDK.transactions.syncOnChainTransfers(params, bearerToken);
|
|
997
|
+
},
|
|
998
|
+
onSuccess: () => {
|
|
999
|
+
queryClient.invalidateQueries({
|
|
1000
|
+
predicate: (query) => query.queryKey[0] === "transaction-list"
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
});
|
|
1004
|
+
return {
|
|
1005
|
+
syncTransfers: mutation.mutate,
|
|
1006
|
+
syncTransfersAsync: mutation.mutateAsync,
|
|
1007
|
+
data: mutation.data,
|
|
1008
|
+
isLoading: mutation.isPending,
|
|
1009
|
+
isError: mutation.isError,
|
|
1010
|
+
error: mutation.error,
|
|
1011
|
+
isSuccess: mutation.isSuccess,
|
|
1012
|
+
reset: mutation.reset
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
951
1015
|
function usePurchaseSku() {
|
|
952
1016
|
const { chipiSDK } = useChipiContext();
|
|
953
1017
|
const mutation = reactQuery.useMutation({
|
|
@@ -1570,6 +1634,7 @@ exports.useMigrateWalletToPasskey = useMigrateWalletToPasskey;
|
|
|
1570
1634
|
exports.usePurchaseSku = usePurchaseSku;
|
|
1571
1635
|
exports.useRecordSendTransaction = useRecordSendTransaction;
|
|
1572
1636
|
exports.useRevokeSessionKey = useRevokeSessionKey;
|
|
1637
|
+
exports.useSyncOnChainTransfers = useSyncOnChainTransfers;
|
|
1573
1638
|
exports.useTransfer = useTransfer;
|
|
1574
1639
|
exports.useUpdateWalletEncryption = useUpdateWalletEncryption;
|
|
1575
1640
|
exports.useX402Payment = useX402Payment;
|