@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/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
|
});
|
|
@@ -596,6 +625,7 @@ function useChipiSession(config) {
|
|
|
596
625
|
}
|
|
597
626
|
function useMigrateWalletToPasskey() {
|
|
598
627
|
const { chipiSDK } = useChipiContext();
|
|
628
|
+
const queryClient = reactQuery.useQueryClient();
|
|
599
629
|
const mutation = reactQuery.useMutation({
|
|
600
630
|
mutationFn: async (input) => {
|
|
601
631
|
const { wallet, oldEncryptKey, externalUserId, bearerToken } = input;
|
|
@@ -617,10 +647,27 @@ function useMigrateWalletToPasskey() {
|
|
|
617
647
|
decryptedPrivateKey,
|
|
618
648
|
passkeyResult.encryptKey
|
|
619
649
|
);
|
|
650
|
+
const updateResult = await chipiSDK.wallets.updateWalletEncryption(
|
|
651
|
+
{
|
|
652
|
+
externalUserId,
|
|
653
|
+
newEncryptedPrivateKey,
|
|
654
|
+
publicKey: wallet.publicKey
|
|
655
|
+
},
|
|
656
|
+
bearerToken
|
|
657
|
+
);
|
|
658
|
+
if (updateResult?.success === false) {
|
|
659
|
+
throw new Error("Backend rejected wallet encryption update");
|
|
660
|
+
}
|
|
620
661
|
const updatedWallet = {
|
|
621
662
|
...wallet,
|
|
622
663
|
encryptedPrivateKey: newEncryptedPrivateKey
|
|
623
664
|
};
|
|
665
|
+
queryClient.invalidateQueries({
|
|
666
|
+
queryKey: ["chipi-wallet", externalUserId]
|
|
667
|
+
});
|
|
668
|
+
queryClient.invalidateQueries({
|
|
669
|
+
queryKey: ["wallet", externalUserId]
|
|
670
|
+
});
|
|
624
671
|
return {
|
|
625
672
|
success: true,
|
|
626
673
|
wallet: updatedWallet,
|
|
@@ -670,31 +717,40 @@ function useUpdateWalletEncryption() {
|
|
|
670
717
|
reset: mutation.reset
|
|
671
718
|
};
|
|
672
719
|
}
|
|
673
|
-
function useTransfer() {
|
|
720
|
+
function useTransfer(config) {
|
|
674
721
|
const { chipiSDK, passkeyAdapter } = useChipiContext();
|
|
675
722
|
const mutation = reactQuery.useMutation({
|
|
676
723
|
mutationFn: async (input) => {
|
|
677
724
|
let encryptKey = input.params.encryptKey;
|
|
725
|
+
let walletForTransfer = input.params.wallet;
|
|
678
726
|
if (input.params.usePasskey) {
|
|
679
727
|
if (!input.params.externalUserId) {
|
|
680
728
|
throw new Error("externalUserId is required when usePasskey is true");
|
|
681
729
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
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.");
|
|
696
753
|
}
|
|
697
|
-
throw new Error("Failed to authenticate with passkey");
|
|
698
754
|
}
|
|
699
755
|
}
|
|
700
756
|
if (!encryptKey) {
|
|
@@ -708,6 +764,7 @@ function useTransfer() {
|
|
|
708
764
|
return chipiSDK.transfer({
|
|
709
765
|
params: {
|
|
710
766
|
...transferParams,
|
|
767
|
+
wallet: walletForTransfer,
|
|
711
768
|
amount: String(transferParams.amount),
|
|
712
769
|
encryptKey
|
|
713
770
|
},
|
|
@@ -930,6 +987,31 @@ function useGetTransactionStatus(input) {
|
|
|
930
987
|
fetchTransactionStatus
|
|
931
988
|
};
|
|
932
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
|
+
}
|
|
933
1015
|
function usePurchaseSku() {
|
|
934
1016
|
const { chipiSDK } = useChipiContext();
|
|
935
1017
|
const mutation = reactQuery.useMutation({
|
|
@@ -1552,6 +1634,7 @@ exports.useMigrateWalletToPasskey = useMigrateWalletToPasskey;
|
|
|
1552
1634
|
exports.usePurchaseSku = usePurchaseSku;
|
|
1553
1635
|
exports.useRecordSendTransaction = useRecordSendTransaction;
|
|
1554
1636
|
exports.useRevokeSessionKey = useRevokeSessionKey;
|
|
1637
|
+
exports.useSyncOnChainTransfers = useSyncOnChainTransfers;
|
|
1555
1638
|
exports.useTransfer = useTransfer;
|
|
1556
1639
|
exports.useUpdateWalletEncryption = useUpdateWalletEncryption;
|
|
1557
1640
|
exports.useX402Payment = useX402Payment;
|