@cavos/kit 0.0.1 → 0.0.3
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/README.md +113 -42
- package/dist/Cavos-BH2_tOQ2.d.mts +994 -0
- package/dist/Cavos-BH2_tOQ2.d.ts +994 -0
- package/dist/chunk-BNGLH3Q3.mjs +2777 -0
- package/dist/chunk-BNGLH3Q3.mjs.map +1 -0
- package/dist/index.d.mts +156 -242
- package/dist/index.d.ts +156 -242
- package/dist/index.js +1989 -151
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +42 -5
- package/dist/react/index.d.ts +42 -5
- package/dist/react/index.js +1786 -86
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +48 -7
- package/dist/react/index.mjs.map +1 -1
- package/package.json +4 -1
- package/dist/chunk-XWBX2ZIO.mjs +0 -1061
- package/dist/chunk-XWBX2ZIO.mjs.map +0 -1
- package/dist/constants-C530TZFF.d.mts +0 -89
- package/dist/constants-C530TZFF.d.ts +0 -89
package/dist/react/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CavosAuth, HttpRecoveryClient, Cavos, generateRecoveryCode } from '../chunk-
|
|
1
|
+
import { CavosAuth, HttpRecoveryClient, Cavos, generateRecoveryCode, CavosSolana } from '../chunk-BNGLH3Q3.mjs';
|
|
2
2
|
import { createContext, useState, useRef, useEffect, useCallback, useContext } from 'react';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
|
|
@@ -791,7 +791,7 @@ function CavosProvider({ config, modal, children }) {
|
|
|
791
791
|
const closeModal = useCallback(() => setModalOpen(false), []);
|
|
792
792
|
const clearAuthError = useCallback(() => setAuthError(null), []);
|
|
793
793
|
const resendDeviceApproval = useCallback(async () => {
|
|
794
|
-
if (!identity || !cavos || !cavos.pendingRequestId) return;
|
|
794
|
+
if (!identity || !cavos || cavos.chain !== "starknet" || !cavos.pendingRequestId) return;
|
|
795
795
|
const backendUrl = configRef.current.authBackendUrl ?? "https://cavos.xyz";
|
|
796
796
|
if (!configRef.current.appId) return;
|
|
797
797
|
const recovery = new HttpRecoveryClient({ baseUrl: backendUrl, appId: configRef.current.appId });
|
|
@@ -805,22 +805,24 @@ function CavosProvider({ config, modal, children }) {
|
|
|
805
805
|
const connect = useCallback(async (id) => {
|
|
806
806
|
setWalletStatus({ ...INITIAL_STATUS, isDeploying: true });
|
|
807
807
|
const c = await Cavos.connect({
|
|
808
|
+
chain: configRef.current.chain ?? "starknet",
|
|
808
809
|
network: configRef.current.network,
|
|
809
810
|
identity: id,
|
|
810
811
|
appSalt: configRef.current.appSalt,
|
|
811
|
-
paymasterApiKey: configRef.current.paymasterApiKey,
|
|
812
|
+
...configRef.current.paymasterApiKey ? { paymasterApiKey: configRef.current.paymasterApiKey } : {},
|
|
812
813
|
...configRef.current.appId ? { appId: configRef.current.appId } : {},
|
|
813
814
|
...configRef.current.authBackendUrl ? { backendUrl: configRef.current.authBackendUrl } : {},
|
|
814
815
|
...configRef.current.rpcUrl ? { rpcUrl: configRef.current.rpcUrl } : {}
|
|
815
816
|
});
|
|
816
817
|
setCavos(c);
|
|
817
818
|
setIdentity(id);
|
|
819
|
+
const pendingRequestId = c.chain === "starknet" ? c.pendingRequestId : null;
|
|
818
820
|
setWalletStatus({
|
|
819
821
|
isDeploying: false,
|
|
820
822
|
isReady: c.status === "ready",
|
|
821
823
|
needsDeviceApproval: c.status === "needs-device-approval",
|
|
822
|
-
awaitingApproval: c.status === "needs-device-approval" && !!
|
|
823
|
-
pendingRequestId
|
|
824
|
+
awaitingApproval: c.status === "needs-device-approval" && !!pendingRequestId,
|
|
825
|
+
pendingRequestId
|
|
824
826
|
});
|
|
825
827
|
modal?.onSuccess?.(c.address);
|
|
826
828
|
return c;
|
|
@@ -876,15 +878,41 @@ function CavosProvider({ config, modal, children }) {
|
|
|
876
878
|
}, [auth, connect]);
|
|
877
879
|
const execute = useCallback(async (calls) => {
|
|
878
880
|
if (!cavos) throw new Error("Not logged in");
|
|
881
|
+
if (cavos.chain !== "starknet") {
|
|
882
|
+
throw new Error(
|
|
883
|
+
"kit: useCavos().execute(calls) is Starknet-only. On Solana use the `wallet` handle: wallet.execute(amount, dest)."
|
|
884
|
+
);
|
|
885
|
+
}
|
|
879
886
|
return cavos.execute(calls);
|
|
880
887
|
}, [cavos]);
|
|
881
888
|
const addSigner = useCallback(
|
|
882
889
|
async (pubkey) => {
|
|
883
890
|
if (!cavos) throw new Error("Not logged in");
|
|
891
|
+
if (cavos.chain !== "starknet") {
|
|
892
|
+
throw new Error("kit: addSigner via useCavos() is Starknet-only; use the `wallet` handle on Solana.");
|
|
893
|
+
}
|
|
884
894
|
return cavos.addSigner(pubkey);
|
|
885
895
|
},
|
|
886
896
|
[cavos]
|
|
887
897
|
);
|
|
898
|
+
const enrollPasskey = useCallback(
|
|
899
|
+
async (passkey, params) => {
|
|
900
|
+
if (!cavos) throw new Error("Not logged in");
|
|
901
|
+
return cavos.enrollPasskey(passkey, params);
|
|
902
|
+
},
|
|
903
|
+
[cavos]
|
|
904
|
+
);
|
|
905
|
+
const approveThisDeviceWithPasskey = useCallback(
|
|
906
|
+
async (passkey, submit) => {
|
|
907
|
+
if (!cavos) throw new Error("Not logged in");
|
|
908
|
+
if (cavos.chain === "starknet") {
|
|
909
|
+
return cavos.approveThisDeviceWithPasskey({ passkey, ...submit ? { submit } : {} });
|
|
910
|
+
}
|
|
911
|
+
const transactionHash = await cavos.approveThisDeviceWithPasskey(passkey);
|
|
912
|
+
return { transactionHash };
|
|
913
|
+
},
|
|
914
|
+
[cavos]
|
|
915
|
+
);
|
|
888
916
|
const setupRecovery = useCallback(async () => {
|
|
889
917
|
if (!cavos) throw new Error("Not logged in");
|
|
890
918
|
const code = generateRecoveryCode();
|
|
@@ -896,12 +924,21 @@ function CavosProvider({ config, modal, children }) {
|
|
|
896
924
|
setAuthError(null);
|
|
897
925
|
setWalletStatus({ ...INITIAL_STATUS, isDeploying: true });
|
|
898
926
|
try {
|
|
899
|
-
const
|
|
927
|
+
const chain = configRef.current.chain ?? "starknet";
|
|
928
|
+
const c = chain === "solana" ? await CavosSolana.recover({
|
|
929
|
+
code,
|
|
930
|
+
identity,
|
|
931
|
+
network: configRef.current.network === "mainnet" ? "solana-mainnet" : "solana-devnet",
|
|
932
|
+
appSalt: configRef.current.appSalt,
|
|
933
|
+
...configRef.current.appId ? { appId: configRef.current.appId } : {},
|
|
934
|
+
...configRef.current.authBackendUrl ? { backendUrl: configRef.current.authBackendUrl } : {},
|
|
935
|
+
...configRef.current.rpcUrl ? { rpcUrl: configRef.current.rpcUrl } : {}
|
|
936
|
+
}) : await Cavos.recover({
|
|
900
937
|
code,
|
|
901
938
|
identity,
|
|
902
939
|
network: configRef.current.network,
|
|
903
940
|
appSalt: configRef.current.appSalt,
|
|
904
|
-
paymasterApiKey: configRef.current.paymasterApiKey,
|
|
941
|
+
paymasterApiKey: configRef.current.paymasterApiKey ?? "",
|
|
905
942
|
...configRef.current.appId ? { appId: configRef.current.appId } : {},
|
|
906
943
|
...configRef.current.authBackendUrl ? { backendUrl: configRef.current.authBackendUrl } : {},
|
|
907
944
|
...configRef.current.rpcUrl ? { rpcUrl: configRef.current.rpcUrl } : {}
|
|
@@ -954,6 +991,8 @@ function CavosProvider({ config, modal, children }) {
|
|
|
954
991
|
closeModal,
|
|
955
992
|
isAuthenticated: !!cavos,
|
|
956
993
|
user: identity ? { userId: identity.userId, email: identity.email, provider: identity.provider } : null,
|
|
994
|
+
chain: config.chain ?? "starknet",
|
|
995
|
+
wallet: cavos,
|
|
957
996
|
address: cavos?.address ?? null,
|
|
958
997
|
walletStatus,
|
|
959
998
|
isLoading,
|
|
@@ -966,6 +1005,8 @@ function CavosProvider({ config, modal, children }) {
|
|
|
966
1005
|
handleCallback,
|
|
967
1006
|
execute,
|
|
968
1007
|
addSigner,
|
|
1008
|
+
enrollPasskey,
|
|
1009
|
+
approveThisDeviceWithPasskey,
|
|
969
1010
|
resendDeviceApproval,
|
|
970
1011
|
setupRecovery,
|
|
971
1012
|
recover,
|