cilantro-react 0.1.1 → 0.1.2
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/index.d.mts +57 -24
- package/dist/index.d.ts +57 -24
- package/dist/index.js +190 -126
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +184 -119
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -63,6 +63,7 @@ __export(index_exports, {
|
|
|
63
63
|
useSignerSelection: () => useSignerSelection,
|
|
64
64
|
useSigners: () => useSigners,
|
|
65
65
|
useSignersForSelectedWallet: () => useSignersForSelectedWallet,
|
|
66
|
+
useSignersRaw: () => useSignersRaw,
|
|
66
67
|
useTransactionSigning: () => useTransactionSigning,
|
|
67
68
|
useWalletAddress: () => useWalletAddress,
|
|
68
69
|
useWallets: () => useWallets
|
|
@@ -263,25 +264,34 @@ function CilantroAuthProvider({
|
|
|
263
264
|
const login = async (usernameOrEmail, password) => {
|
|
264
265
|
try {
|
|
265
266
|
const result = await (0, import_auth.login)({ usernameOrEmail, password });
|
|
266
|
-
const
|
|
267
|
-
if (!
|
|
268
|
-
const jwt =
|
|
269
|
-
const userType =
|
|
267
|
+
const data = result && typeof result === "object" && "data" in result ? result.data : void 0;
|
|
268
|
+
if (!data?.jwt) throw new Error("No JWT token received from server");
|
|
269
|
+
const jwt = data.jwt;
|
|
270
|
+
const userType = data.userType;
|
|
270
271
|
setToken(jwt);
|
|
271
272
|
setSdkAuth(jwt);
|
|
272
273
|
if (typeof window !== "undefined") {
|
|
273
274
|
localStorage.setItem(jwtStorageKey, jwt);
|
|
274
275
|
document.cookie = `cilantro_jwt=${jwt}; path=/; max-age=${60 * 60 * 24 * 7}`;
|
|
275
276
|
}
|
|
276
|
-
|
|
277
|
-
const
|
|
277
|
+
if (data.user && typeof data.user === "object") {
|
|
278
|
+
const u = data.user;
|
|
278
279
|
setUser({
|
|
279
|
-
username:
|
|
280
|
-
email:
|
|
281
|
-
userType: userType ??
|
|
280
|
+
username: u.username,
|
|
281
|
+
email: u.email,
|
|
282
|
+
userType: userType ?? u.userType
|
|
282
283
|
});
|
|
283
|
-
}
|
|
284
|
-
|
|
284
|
+
} else {
|
|
285
|
+
try {
|
|
286
|
+
const payload = JSON.parse(atob(jwt.split(".")[1]));
|
|
287
|
+
setUser({
|
|
288
|
+
username: payload.username,
|
|
289
|
+
email: payload.email,
|
|
290
|
+
userType: userType ?? payload.userType
|
|
291
|
+
});
|
|
292
|
+
} catch {
|
|
293
|
+
setUser({ userType });
|
|
294
|
+
}
|
|
285
295
|
}
|
|
286
296
|
onLoginSuccess?.();
|
|
287
297
|
} catch (error) {
|
|
@@ -364,12 +374,12 @@ function WalletProvider({ children, storageKey = DEFAULT_STORAGE_KEY }) {
|
|
|
364
374
|
setSelectedWallet(wallet);
|
|
365
375
|
} else {
|
|
366
376
|
setSelectedWallet(wallets[0]);
|
|
367
|
-
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallets[0].id);
|
|
377
|
+
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallets[0].id ?? wallets[0].walletId);
|
|
368
378
|
}
|
|
369
379
|
} else {
|
|
370
380
|
if (wallets.length > 0) {
|
|
371
381
|
setSelectedWallet(wallets[0]);
|
|
372
|
-
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallets[0].id);
|
|
382
|
+
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallets[0].id ?? wallets[0].walletId);
|
|
373
383
|
}
|
|
374
384
|
}
|
|
375
385
|
} else if (wallets.length === 0) {
|
|
@@ -383,19 +393,13 @@ function WalletProvider({ children, storageKey = DEFAULT_STORAGE_KEY }) {
|
|
|
383
393
|
if (token) setSdkAuth(token);
|
|
384
394
|
const result = await (0, import_wallet.findAll)();
|
|
385
395
|
const walletsList = extractResponseData(result) ?? [];
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
walletAddress: w.walletAddress ?? w.address ?? "",
|
|
394
|
-
chain: w.chain ?? "solana",
|
|
395
|
-
active: w.active !== false,
|
|
396
|
-
...w
|
|
397
|
-
};
|
|
398
|
-
}) : [];
|
|
396
|
+
const list = Array.isArray(walletsList) ? walletsList : [];
|
|
397
|
+
const formattedWallets = list.map((w) => ({
|
|
398
|
+
...w,
|
|
399
|
+
id: w.walletId,
|
|
400
|
+
address: w.walletAddress,
|
|
401
|
+
active: w.isActive
|
|
402
|
+
}));
|
|
399
403
|
setWallets(formattedWallets);
|
|
400
404
|
} catch (error) {
|
|
401
405
|
console.error("Failed to load wallets:", error);
|
|
@@ -408,7 +412,7 @@ function WalletProvider({ children, storageKey = DEFAULT_STORAGE_KEY }) {
|
|
|
408
412
|
const wallet = wallets.find((w) => w.id === walletId || w.walletId === walletId);
|
|
409
413
|
if (wallet) {
|
|
410
414
|
setSelectedWallet(wallet);
|
|
411
|
-
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallet.id);
|
|
415
|
+
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallet.id ?? wallet.walletId);
|
|
412
416
|
}
|
|
413
417
|
};
|
|
414
418
|
const refreshWallets = async () => {
|
|
@@ -651,6 +655,52 @@ function useSigners(options = {}) {
|
|
|
651
655
|
return { signers, isLoading, error, refresh };
|
|
652
656
|
}
|
|
653
657
|
|
|
658
|
+
// src/hooks/useSignersRaw.ts
|
|
659
|
+
var import_react5 = require("react");
|
|
660
|
+
var import_wallet3 = require("cilantro-sdk/wallet");
|
|
661
|
+
function useSignersRaw(options = {}) {
|
|
662
|
+
const { walletId } = options;
|
|
663
|
+
const { token } = useCilantroAuth();
|
|
664
|
+
const [signersRaw, setSignersRaw] = (0, import_react5.useState)(null);
|
|
665
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
666
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
667
|
+
const load = (0, import_react5.useCallback)(async () => {
|
|
668
|
+
if (!walletId) {
|
|
669
|
+
setSignersRaw(null);
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
setIsLoading(true);
|
|
673
|
+
setError(null);
|
|
674
|
+
try {
|
|
675
|
+
if (token) setSdkAuth(token);
|
|
676
|
+
const result = await (0, import_wallet3.listSigners)(walletId);
|
|
677
|
+
setSignersRaw(result);
|
|
678
|
+
} catch (err) {
|
|
679
|
+
setSignersRaw(null);
|
|
680
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
681
|
+
} finally {
|
|
682
|
+
setIsLoading(false);
|
|
683
|
+
}
|
|
684
|
+
}, [walletId, token]);
|
|
685
|
+
(0, import_react5.useEffect)(() => {
|
|
686
|
+
if (!walletId) {
|
|
687
|
+
setSignersRaw(null);
|
|
688
|
+
setError(null);
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
load();
|
|
692
|
+
}, [walletId, load]);
|
|
693
|
+
const refresh = (0, import_react5.useCallback)(async () => {
|
|
694
|
+
if (walletId) await load();
|
|
695
|
+
}, [walletId, load]);
|
|
696
|
+
return {
|
|
697
|
+
signersRaw: walletId ? signersRaw : null,
|
|
698
|
+
isLoading,
|
|
699
|
+
error,
|
|
700
|
+
refresh
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
|
|
654
704
|
// src/hooks/useSignersForSelectedWallet.ts
|
|
655
705
|
function useSignersForSelectedWallet(options = {}) {
|
|
656
706
|
const { walletId: walletIdOverride } = options;
|
|
@@ -660,28 +710,21 @@ function useSignersForSelectedWallet(options = {}) {
|
|
|
660
710
|
}
|
|
661
711
|
|
|
662
712
|
// src/hooks/useDelegatedKeys.ts
|
|
663
|
-
var
|
|
713
|
+
var import_react6 = require("react");
|
|
664
714
|
var import_delegated_keys = require("cilantro-sdk/delegated-keys");
|
|
665
715
|
function normalizeKeys(list) {
|
|
666
|
-
return list.
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
name: k.name,
|
|
670
|
-
publicKey: String(k.publicKey ?? ""),
|
|
671
|
-
permissions: k.permissions ?? {},
|
|
672
|
-
isActive: k.isActive !== false,
|
|
673
|
-
createdAt: k.createdAt,
|
|
674
|
-
expiresAt: k.expiresAt,
|
|
675
|
-
...k
|
|
716
|
+
return list.map((k) => ({
|
|
717
|
+
...k,
|
|
718
|
+
id: k.delegatedKeyId
|
|
676
719
|
}));
|
|
677
720
|
}
|
|
678
721
|
function useDelegatedKeys(options = {}) {
|
|
679
722
|
const { walletId, filterActive = true } = options;
|
|
680
723
|
const { token } = useCilantroAuth();
|
|
681
|
-
const [keys, setKeys] = (0,
|
|
682
|
-
const [isLoading, setIsLoading] = (0,
|
|
683
|
-
const [error, setError] = (0,
|
|
684
|
-
const loadKeys = (0,
|
|
724
|
+
const [keys, setKeys] = (0, import_react6.useState)([]);
|
|
725
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
726
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
727
|
+
const loadKeys = (0, import_react6.useCallback)(async () => {
|
|
685
728
|
if (!walletId) {
|
|
686
729
|
setKeys([]);
|
|
687
730
|
return;
|
|
@@ -693,12 +736,16 @@ function useDelegatedKeys(options = {}) {
|
|
|
693
736
|
const result = await (0, import_delegated_keys.findAll)(walletId);
|
|
694
737
|
const keysData = extractResponseData(result) ?? [];
|
|
695
738
|
const list = Array.isArray(keysData) ? keysData : [];
|
|
696
|
-
|
|
739
|
+
const valid = list.filter(
|
|
740
|
+
(k) => k != null && typeof k === "object" && "delegatedKeyId" in k
|
|
741
|
+
);
|
|
742
|
+
let loaded = normalizeKeys(valid);
|
|
697
743
|
if (filterActive) {
|
|
698
744
|
const now = Date.now();
|
|
699
745
|
loaded = loaded.filter((key) => {
|
|
700
746
|
if (!key.isActive) return false;
|
|
701
|
-
const
|
|
747
|
+
const raw = key.expiresAt;
|
|
748
|
+
const exp = raw != null && (typeof raw === "string" || typeof raw === "number") ? new Date(raw).getTime() : null;
|
|
702
749
|
return exp === null || exp > now;
|
|
703
750
|
});
|
|
704
751
|
}
|
|
@@ -710,17 +757,17 @@ function useDelegatedKeys(options = {}) {
|
|
|
710
757
|
setIsLoading(false);
|
|
711
758
|
}
|
|
712
759
|
}, [walletId, token, filterActive]);
|
|
713
|
-
(0,
|
|
760
|
+
(0, import_react6.useEffect)(() => {
|
|
714
761
|
loadKeys();
|
|
715
762
|
}, [loadKeys]);
|
|
716
|
-
const refresh = (0,
|
|
763
|
+
const refresh = (0, import_react6.useCallback)(async () => {
|
|
717
764
|
if (walletId) await loadKeys();
|
|
718
765
|
}, [walletId, loadKeys]);
|
|
719
766
|
return { keys, isLoading, error, refresh };
|
|
720
767
|
}
|
|
721
768
|
|
|
722
769
|
// src/hooks/useSignerSelection.ts
|
|
723
|
-
var
|
|
770
|
+
var import_react7 = require("react");
|
|
724
771
|
function useSignerSelection(options = {}) {
|
|
725
772
|
const { walletId: walletIdOverride, signingMethod = "sdk-signer" } = options;
|
|
726
773
|
const { selectedWallet } = useWallets();
|
|
@@ -728,17 +775,17 @@ function useSignerSelection(options = {}) {
|
|
|
728
775
|
const { signers: availableSigners, isLoading: isLoadingSigners } = useSigners({
|
|
729
776
|
walletId: effectiveWalletId || null
|
|
730
777
|
});
|
|
731
|
-
const [selectedWalletId, setSelectedWalletId] = (0,
|
|
732
|
-
const [selectedSigner, setSelectedSigner] = (0,
|
|
733
|
-
(0,
|
|
778
|
+
const [selectedWalletId, setSelectedWalletId] = (0, import_react7.useState)(effectiveWalletId);
|
|
779
|
+
const [selectedSigner, setSelectedSigner] = (0, import_react7.useState)(null);
|
|
780
|
+
(0, import_react7.useEffect)(() => {
|
|
734
781
|
setSelectedWalletId(effectiveWalletId);
|
|
735
782
|
}, [effectiveWalletId]);
|
|
736
|
-
(0,
|
|
783
|
+
(0, import_react7.useEffect)(() => {
|
|
737
784
|
if (signingMethod !== "sdk-signer") {
|
|
738
785
|
setSelectedSigner(null);
|
|
739
786
|
}
|
|
740
787
|
}, [signingMethod]);
|
|
741
|
-
const reset = (0,
|
|
788
|
+
const reset = (0, import_react7.useCallback)(() => {
|
|
742
789
|
setSelectedWalletId("");
|
|
743
790
|
setSelectedSigner(null);
|
|
744
791
|
}, []);
|
|
@@ -754,7 +801,7 @@ function useSignerSelection(options = {}) {
|
|
|
754
801
|
}
|
|
755
802
|
|
|
756
803
|
// src/hooks/useCanSign.ts
|
|
757
|
-
var
|
|
804
|
+
var import_react8 = require("react");
|
|
758
805
|
function useCanSign(options = {}) {
|
|
759
806
|
const {
|
|
760
807
|
signingMethod = "sdk-signer",
|
|
@@ -764,7 +811,7 @@ function useCanSign(options = {}) {
|
|
|
764
811
|
const { token } = useCilantroAuth();
|
|
765
812
|
const { selectedWallet } = useWallets();
|
|
766
813
|
const { selectedSigner } = useSignerSelection({ signingMethod });
|
|
767
|
-
return (0,
|
|
814
|
+
return (0, import_react8.useMemo)(() => {
|
|
768
815
|
const hasToken = !!token;
|
|
769
816
|
const hasWallet = !!selectedWallet?.id || !!selectedWallet?.walletId;
|
|
770
817
|
const isSdkSigner = signingMethod === "sdk-signer";
|
|
@@ -789,7 +836,7 @@ function useCanSign(options = {}) {
|
|
|
789
836
|
}
|
|
790
837
|
|
|
791
838
|
// src/hooks/useMessageSigning.ts
|
|
792
|
-
var
|
|
839
|
+
var import_react9 = require("react");
|
|
793
840
|
|
|
794
841
|
// src/core/signer-signing/core.ts
|
|
795
842
|
var import_web3 = require("@solana/web3.js");
|
|
@@ -848,7 +895,7 @@ var import_helpers6 = require("cilantro-sdk/helpers");
|
|
|
848
895
|
var import_web32 = require("@solana/web3.js");
|
|
849
896
|
var import_helpers4 = require("cilantro-sdk/helpers");
|
|
850
897
|
var import_transactions = require("cilantro-sdk/transactions");
|
|
851
|
-
var
|
|
898
|
+
var import_wallet4 = require("cilantro-sdk/wallet");
|
|
852
899
|
async function createEmailSignerHelper(walletId, email) {
|
|
853
900
|
const trimmedEmail = email.trim();
|
|
854
901
|
if (!trimmedEmail) throw new Error("Email address is required");
|
|
@@ -865,7 +912,7 @@ async function createPhoneSignerHelper(walletId, phone) {
|
|
|
865
912
|
}
|
|
866
913
|
async function createExternalSignerHelper(walletId, address) {
|
|
867
914
|
if (!address.trim()) throw new Error("Wallet address is required");
|
|
868
|
-
return await (0,
|
|
915
|
+
return await (0, import_wallet4.createExternalWalletSigner)(walletId, { address: address.trim(), chain: "solana" });
|
|
869
916
|
}
|
|
870
917
|
async function registerPasskeySigner(walletId) {
|
|
871
918
|
if (!(0, import_helpers4.isWebAuthnSupported)()) throw new Error("WebAuthn is not supported in this browser");
|
|
@@ -909,9 +956,10 @@ async function signAndSendPasskeyTransaction(walletId, signerId, transaction, op
|
|
|
909
956
|
});
|
|
910
957
|
}
|
|
911
958
|
const unsignedTransaction = transaction.serialize({ verifySignatures: false }).toString("base64");
|
|
912
|
-
const authOptions = await (0,
|
|
913
|
-
|
|
914
|
-
|
|
959
|
+
const authOptions = await (0, import_wallet4.startPasskeyAuthentication)(
|
|
960
|
+
walletId,
|
|
961
|
+
{ credentialId: options?.credentialId }
|
|
962
|
+
);
|
|
915
963
|
const authData = extractResponseData(authOptions);
|
|
916
964
|
if (!authData) throw new Error("Failed to get authentication options");
|
|
917
965
|
const authDataValue = authData && typeof authData === "object" && "data" in authData ? authData.data : authData;
|
|
@@ -930,7 +978,10 @@ async function signAndSendPasskeyTransaction(walletId, signerId, transaction, op
|
|
|
930
978
|
};
|
|
931
979
|
const result = await (0, import_transactions.sendRawPasskeyTransaction)(dto);
|
|
932
980
|
const resultData = extractResponseData(result);
|
|
933
|
-
return {
|
|
981
|
+
return {
|
|
982
|
+
signature: resultData?.signature ?? "",
|
|
983
|
+
status: resultData?.status
|
|
984
|
+
};
|
|
934
985
|
}
|
|
935
986
|
|
|
936
987
|
// src/core/signer-signing/errors.ts
|
|
@@ -996,10 +1047,11 @@ async function signMessageWithSigner(walletId, signer, messageText) {
|
|
|
996
1047
|
validateSignerActive(signer, signerType);
|
|
997
1048
|
const storageOptions = getStorageOptions();
|
|
998
1049
|
try {
|
|
999
|
-
const
|
|
1050
|
+
const signatureBytes = await (0, import_helpers6.signWithEmailSigner)(walletId, signerId, message, storageOptions);
|
|
1000
1051
|
const keypair = await (0, import_helpers6.getEmailSignerKeypair)(walletId, signerId, storageOptions);
|
|
1001
1052
|
return {
|
|
1002
|
-
signature: Buffer.from(
|
|
1053
|
+
signature: Buffer.from(signatureBytes).toString("base64"),
|
|
1054
|
+
message: messageText,
|
|
1003
1055
|
publicKey: Buffer.from(keypair.publicKey).toString("hex"),
|
|
1004
1056
|
signerType: SIGNER_TYPES.EMAIL
|
|
1005
1057
|
};
|
|
@@ -1011,10 +1063,11 @@ async function signMessageWithSigner(walletId, signer, messageText) {
|
|
|
1011
1063
|
validateSignerActive(signer, signerType);
|
|
1012
1064
|
const storageOptions = getStorageOptions();
|
|
1013
1065
|
try {
|
|
1014
|
-
const
|
|
1066
|
+
const signatureBytes = await (0, import_helpers6.signWithPhoneSigner)(walletId, signerId, message, storageOptions);
|
|
1015
1067
|
const keypair = await (0, import_helpers6.getPhoneSignerKeypair)(walletId, signerId, storageOptions);
|
|
1016
1068
|
return {
|
|
1017
|
-
signature: Buffer.from(
|
|
1069
|
+
signature: Buffer.from(signatureBytes).toString("base64"),
|
|
1070
|
+
message: messageText,
|
|
1018
1071
|
publicKey: Buffer.from(keypair.publicKey).toString("hex"),
|
|
1019
1072
|
signerType: SIGNER_TYPES.PHONE
|
|
1020
1073
|
};
|
|
@@ -1024,8 +1077,10 @@ async function signMessageWithSigner(walletId, signer, messageText) {
|
|
|
1024
1077
|
}
|
|
1025
1078
|
if (signerType === SIGNER_TYPES.PASSKEY) {
|
|
1026
1079
|
const signResult = await signWithPasskey(walletId, signerId, messageText, { useBrowserAutofill: false });
|
|
1080
|
+
const signatureBase64 = Buffer.from(signResult.signature, "hex").toString("base64");
|
|
1027
1081
|
return {
|
|
1028
|
-
signature:
|
|
1082
|
+
signature: signatureBase64,
|
|
1083
|
+
message: messageText,
|
|
1029
1084
|
signerType: SIGNER_TYPES.PASSKEY,
|
|
1030
1085
|
signer: signResult.signer
|
|
1031
1086
|
};
|
|
@@ -1033,10 +1088,11 @@ async function signMessageWithSigner(walletId, signer, messageText) {
|
|
|
1033
1088
|
if (signerType === SIGNER_TYPES.EXTERNAL || signerType === SIGNER_TYPES.API_KEY) {
|
|
1034
1089
|
validateSignerActive(signer, signerType);
|
|
1035
1090
|
const storageOptions = getStorageOptions();
|
|
1036
|
-
const
|
|
1091
|
+
const signatureBytes = await (0, import_helpers6.signWithSigner)(walletId, signerId, signerType, message, storageOptions);
|
|
1037
1092
|
const keypair = await (0, import_helpers6.deriveSignerKeypair)(walletId, signerId, signerType, storageOptions);
|
|
1038
1093
|
return {
|
|
1039
|
-
signature: Buffer.from(
|
|
1094
|
+
signature: Buffer.from(signatureBytes).toString("base64"),
|
|
1095
|
+
message: messageText,
|
|
1040
1096
|
publicKey: Buffer.from(keypair.publicKey).toString("base64"),
|
|
1041
1097
|
signerType
|
|
1042
1098
|
};
|
|
@@ -1046,7 +1102,7 @@ async function signMessageWithSigner(walletId, signer, messageText) {
|
|
|
1046
1102
|
|
|
1047
1103
|
// src/core/signer-signing/transaction-signing.ts
|
|
1048
1104
|
var import_helpers7 = require("cilantro-sdk/helpers");
|
|
1049
|
-
var
|
|
1105
|
+
var import_wallet5 = require("cilantro-sdk/wallet");
|
|
1050
1106
|
|
|
1051
1107
|
// src/core/signer-signing/validation.ts
|
|
1052
1108
|
var import_web33 = require("@solana/web3.js");
|
|
@@ -1152,14 +1208,16 @@ async function signTransactionWithEmailOrPhone(walletId, signerId, signerType, u
|
|
|
1152
1208
|
);
|
|
1153
1209
|
}
|
|
1154
1210
|
async function submitSignedTransaction(walletId, signedTransactionBase64) {
|
|
1155
|
-
const submitResult = await (0,
|
|
1211
|
+
const submitResult = await (0, import_wallet5.submitTransaction)(walletId, {
|
|
1156
1212
|
signedTransaction: signedTransactionBase64
|
|
1157
1213
|
});
|
|
1158
1214
|
const resultData = extractResponseData(submitResult);
|
|
1159
1215
|
if (!resultData?.signature) throw new Error("Server did not return a transaction signature");
|
|
1216
|
+
const status = resultData.status ?? "pending";
|
|
1160
1217
|
return {
|
|
1161
1218
|
signature: resultData.signature,
|
|
1162
|
-
|
|
1219
|
+
status,
|
|
1220
|
+
confirmationStatus: status
|
|
1163
1221
|
};
|
|
1164
1222
|
}
|
|
1165
1223
|
async function handlePasskeyTransaction(walletId, signerId, transaction, connection) {
|
|
@@ -1172,7 +1230,7 @@ async function handlePasskeyTransaction(walletId, signerId, transaction, connect
|
|
|
1172
1230
|
const result = await signAndSendPasskeyTransaction(walletId, signerId, transaction, {
|
|
1173
1231
|
useBrowserAutofill: false
|
|
1174
1232
|
});
|
|
1175
|
-
let
|
|
1233
|
+
let status = "confirmed";
|
|
1176
1234
|
try {
|
|
1177
1235
|
await connection.confirmTransaction({
|
|
1178
1236
|
signature: result.signature,
|
|
@@ -1182,12 +1240,12 @@ async function handlePasskeyTransaction(walletId, signerId, transaction, connect
|
|
|
1182
1240
|
} catch (error) {
|
|
1183
1241
|
const errorMsg = extractErrorMessage(error);
|
|
1184
1242
|
if (errorMsg.includes("block height exceeded") || errorMsg.includes("expired") || errorMsg.includes("timeout")) {
|
|
1185
|
-
|
|
1243
|
+
status = "pending";
|
|
1186
1244
|
} else {
|
|
1187
1245
|
throw new Error(`Transaction confirmation failed: ${errorMsg}. Signature: ${result.signature}`);
|
|
1188
1246
|
}
|
|
1189
1247
|
}
|
|
1190
|
-
return { signature: result.signature, confirmationStatus };
|
|
1248
|
+
return { signature: result.signature, status, confirmationStatus: status };
|
|
1191
1249
|
}
|
|
1192
1250
|
async function handleEmailOrPhoneTransaction(walletId, signer, signerType, signerId, transaction) {
|
|
1193
1251
|
validateSignerActive(signer, signerType);
|
|
@@ -1299,24 +1357,17 @@ async function signAndSendTransactionWithSigner(walletId, signer, transaction, c
|
|
|
1299
1357
|
|
|
1300
1358
|
// src/core/signer-signing/wallet-data.ts
|
|
1301
1359
|
var import_web34 = require("@solana/web3.js");
|
|
1302
|
-
var
|
|
1360
|
+
var import_wallet6 = require("cilantro-sdk/wallet");
|
|
1303
1361
|
async function getWalletData(walletId) {
|
|
1304
|
-
const walletDataResponse = await (0,
|
|
1362
|
+
const walletDataResponse = await (0, import_wallet6.findOne)(walletId);
|
|
1305
1363
|
const walletData = extractResponseData(walletDataResponse);
|
|
1306
1364
|
if (!walletData) throw new Error("Wallet data is empty");
|
|
1307
|
-
const address = String(
|
|
1308
|
-
|
|
1309
|
-
).trim();
|
|
1310
|
-
if (!address) throw new Error(`No wallet address found. Available fields: ${Object.keys(walletData).join(", ")}`);
|
|
1365
|
+
const address = String(walletData.walletAddress ?? "").trim();
|
|
1366
|
+
if (!address) throw new Error("No wallet address found (walletAddress is empty).");
|
|
1311
1367
|
const walletPublicKey = new import_web34.PublicKey(address);
|
|
1312
|
-
const
|
|
1313
|
-
const adminPubkey = String(
|
|
1314
|
-
walletData.adminSignerPubkey ?? walletData.adminSigner ?? adminData?.publicKey ?? ""
|
|
1315
|
-
).trim();
|
|
1368
|
+
const adminPubkey = String(walletData.adminSignerPubkey ?? "").trim();
|
|
1316
1369
|
if (!adminPubkey) {
|
|
1317
|
-
throw new Error(
|
|
1318
|
-
`adminSignerPubkey not found in wallet data. Available fields: ${Object.keys(walletData).join(", ")}`
|
|
1319
|
-
);
|
|
1370
|
+
throw new Error("adminSignerPubkey not found in wallet data.");
|
|
1320
1371
|
}
|
|
1321
1372
|
const adminSignerPubkey = new import_web34.PublicKey(adminPubkey);
|
|
1322
1373
|
return { walletPublicKey, adminSignerPubkey };
|
|
@@ -1332,9 +1383,9 @@ function useMessageSigning(options) {
|
|
|
1332
1383
|
walletAdapterSignMessage,
|
|
1333
1384
|
walletAdapterPublicKey
|
|
1334
1385
|
} = options;
|
|
1335
|
-
const [messageText, setMessageText] = (0,
|
|
1336
|
-
const [signResultState, setSignResultState] = (0,
|
|
1337
|
-
const [isSigning, setIsSigning] = (0,
|
|
1386
|
+
const [messageText, setMessageText] = (0, import_react9.useState)("Hello, Solana!");
|
|
1387
|
+
const [signResultState, setSignResultState] = (0, import_react9.useState)({ status: "idle" });
|
|
1388
|
+
const [isSigning, setIsSigning] = (0, import_react9.useState)(false);
|
|
1338
1389
|
const handleSign = async () => {
|
|
1339
1390
|
setIsSigning(true);
|
|
1340
1391
|
setSignResultState({ status: "loading" });
|
|
@@ -1364,7 +1415,7 @@ function useMessageSigning(options) {
|
|
|
1364
1415
|
setSignResultState({
|
|
1365
1416
|
status: "success",
|
|
1366
1417
|
message: `Message signed successfully with ${signerType} signer!`,
|
|
1367
|
-
detail: {
|
|
1418
|
+
detail: { ...result }
|
|
1368
1419
|
});
|
|
1369
1420
|
} catch (error) {
|
|
1370
1421
|
const errorMsg = extractErrorMessage(error);
|
|
@@ -1392,7 +1443,7 @@ function useMessageSigning(options) {
|
|
|
1392
1443
|
}
|
|
1393
1444
|
|
|
1394
1445
|
// src/hooks/useTransactionSigning.ts
|
|
1395
|
-
var
|
|
1446
|
+
var import_react10 = require("react");
|
|
1396
1447
|
function useTransactionSigning(options) {
|
|
1397
1448
|
const {
|
|
1398
1449
|
token,
|
|
@@ -1403,9 +1454,9 @@ function useTransactionSigning(options) {
|
|
|
1403
1454
|
walletAdapterPublicKey,
|
|
1404
1455
|
connection
|
|
1405
1456
|
} = options;
|
|
1406
|
-
const [transactionResultState, setTransactionResultState] = (0,
|
|
1407
|
-
const [isSigningTransaction, setIsSigningTransaction] = (0,
|
|
1408
|
-
const [isSendingTransaction, setIsSendingTransaction] = (0,
|
|
1457
|
+
const [transactionResultState, setTransactionResultState] = (0, import_react10.useState)({ status: "idle" });
|
|
1458
|
+
const [isSigningTransaction, setIsSigningTransaction] = (0, import_react10.useState)(false);
|
|
1459
|
+
const [isSendingTransaction, setIsSendingTransaction] = (0, import_react10.useState)(false);
|
|
1409
1460
|
const signTransaction = async (transaction) => {
|
|
1410
1461
|
setIsSigningTransaction(true);
|
|
1411
1462
|
setTransactionResultState({ status: "loading" });
|
|
@@ -1483,6 +1534,7 @@ function useTransactionSigning(options) {
|
|
|
1483
1534
|
message: `Transaction sent with ${signerType} signer!`,
|
|
1484
1535
|
detail: {
|
|
1485
1536
|
signature: result.signature,
|
|
1537
|
+
status: result.status,
|
|
1486
1538
|
confirmationStatus: result.confirmationStatus,
|
|
1487
1539
|
explorerUrl: `https://solscan.io/tx/${result.signature}?cluster=devnet`
|
|
1488
1540
|
}
|
|
@@ -1617,8 +1669,9 @@ function WalletSelector(props) {
|
|
|
1617
1669
|
const effectiveValue = value ?? selectedWallet?.id ?? selectedWallet?.walletId ?? "";
|
|
1618
1670
|
const selected = wallets.find((w) => w.id === effectiveValue || w.walletId === effectiveValue) ?? selectedWallet;
|
|
1619
1671
|
const handleSelect = (wallet) => {
|
|
1620
|
-
|
|
1621
|
-
|
|
1672
|
+
const id = wallet.id ?? wallet.walletId;
|
|
1673
|
+
selectWallet(id);
|
|
1674
|
+
onWalletChange?.(id, wallet);
|
|
1622
1675
|
};
|
|
1623
1676
|
const handleValueChange = (id) => {
|
|
1624
1677
|
selectWallet(id);
|
|
@@ -1666,7 +1719,10 @@ function WalletSelector(props) {
|
|
|
1666
1719
|
}
|
|
1667
1720
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: cn(className, classNames?.root), "data-cilantro-wallet-selector": true, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Select, { value: effectiveValue || void 0, onValueChange: handleValueChange, disabled: isLoading, children: [
|
|
1668
1721
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SelectTrigger, { className: classNames?.trigger, "aria-label": "Select wallet", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SelectValue, { placeholder: isLoading ? "Loading..." : placeholder }) }),
|
|
1669
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SelectContent, { className: classNames?.content, children: wallets.map((w) =>
|
|
1722
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SelectContent, { className: classNames?.content, children: wallets.map((w) => {
|
|
1723
|
+
const id = w.id ?? w.walletId;
|
|
1724
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SelectItem, { value: id, className: classNames?.item, children: w.walletName || id }, id);
|
|
1725
|
+
}) })
|
|
1670
1726
|
] }) });
|
|
1671
1727
|
}
|
|
1672
1728
|
|
|
@@ -1802,10 +1858,11 @@ function DelegatedKeySelector(props) {
|
|
|
1802
1858
|
filterActive
|
|
1803
1859
|
});
|
|
1804
1860
|
const onSelect = (key) => {
|
|
1805
|
-
|
|
1861
|
+
const id = key.id ?? key.delegatedKeyId;
|
|
1862
|
+
onChange?.(id, key);
|
|
1806
1863
|
};
|
|
1807
1864
|
const handleValueChange = (id) => {
|
|
1808
|
-
const key = keys.find((k) => k.id === id) ?? null;
|
|
1865
|
+
const key = keys.find((k) => (k.id ?? k.delegatedKeyId) === id) ?? null;
|
|
1809
1866
|
onChange?.(id, key);
|
|
1810
1867
|
};
|
|
1811
1868
|
if (children) {
|
|
@@ -1844,7 +1901,13 @@ function DelegatedKeySelector(props) {
|
|
|
1844
1901
|
"aria-live": "polite",
|
|
1845
1902
|
children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: cn("text-sm text-muted-foreground", classNames?.message), children: "Loading delegated keys..." }) : error ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: cn("text-sm text-destructive", classNames?.message), role: "alert", children: error }) : keys.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: cn("text-sm text-muted-foreground", classNames?.message), children: "No delegated keys found." }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Select, { value: (value ?? "") || void 0, onValueChange: handleValueChange, children: [
|
|
1846
1903
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(SelectTrigger, { className: classNames?.trigger, "aria-label": "Select delegated key", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(SelectValue, { placeholder }) }),
|
|
1847
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(SelectContent, { className: classNames?.content, children: keys.map((k) =>
|
|
1904
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(SelectContent, { className: classNames?.content, children: keys.map((k) => {
|
|
1905
|
+
const id = k.id ?? k.delegatedKeyId;
|
|
1906
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(SelectItem, { value: id, className: classNames?.item, children: [
|
|
1907
|
+
k.publicKey.slice(0, 8),
|
|
1908
|
+
"..."
|
|
1909
|
+
] }, id);
|
|
1910
|
+
}) })
|
|
1848
1911
|
] })
|
|
1849
1912
|
}
|
|
1850
1913
|
);
|
|
@@ -2159,7 +2222,7 @@ function TransactionSigningForm({
|
|
|
2159
2222
|
}
|
|
2160
2223
|
|
|
2161
2224
|
// src/components/LoginForm.tsx
|
|
2162
|
-
var
|
|
2225
|
+
var import_react11 = require("react");
|
|
2163
2226
|
|
|
2164
2227
|
// src/ui/input.tsx
|
|
2165
2228
|
var React7 = __toESM(require("react"));
|
|
@@ -2195,9 +2258,9 @@ function LoginForm({
|
|
|
2195
2258
|
renderSwitchToRegister
|
|
2196
2259
|
}) {
|
|
2197
2260
|
const { login, isLoading } = useCilantroAuth();
|
|
2198
|
-
const [usernameOrEmail, setUsernameOrEmail] = (0,
|
|
2199
|
-
const [password, setPassword] = (0,
|
|
2200
|
-
const [error, setError] = (0,
|
|
2261
|
+
const [usernameOrEmail, setUsernameOrEmail] = (0, import_react11.useState)("");
|
|
2262
|
+
const [password, setPassword] = (0, import_react11.useState)("");
|
|
2263
|
+
const [error, setError] = (0, import_react11.useState)(null);
|
|
2201
2264
|
const handleSubmit = async (e) => {
|
|
2202
2265
|
e.preventDefault();
|
|
2203
2266
|
setError(null);
|
|
@@ -2277,7 +2340,7 @@ function LoginForm({
|
|
|
2277
2340
|
}
|
|
2278
2341
|
|
|
2279
2342
|
// src/components/RegisterForm.tsx
|
|
2280
|
-
var
|
|
2343
|
+
var import_react12 = require("react");
|
|
2281
2344
|
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2282
2345
|
function RegisterForm({
|
|
2283
2346
|
className,
|
|
@@ -2291,10 +2354,10 @@ function RegisterForm({
|
|
|
2291
2354
|
renderSwitchToLogin
|
|
2292
2355
|
}) {
|
|
2293
2356
|
const { register, isLoading } = useCilantroAuth();
|
|
2294
|
-
const [username, setUsername] = (0,
|
|
2295
|
-
const [email, setEmail] = (0,
|
|
2296
|
-
const [password, setPassword] = (0,
|
|
2297
|
-
const [error, setError] = (0,
|
|
2357
|
+
const [username, setUsername] = (0, import_react12.useState)("");
|
|
2358
|
+
const [email, setEmail] = (0, import_react12.useState)("");
|
|
2359
|
+
const [password, setPassword] = (0, import_react12.useState)("");
|
|
2360
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
2298
2361
|
const handleSubmit = async (e) => {
|
|
2299
2362
|
e.preventDefault();
|
|
2300
2363
|
setError(null);
|
|
@@ -2391,7 +2454,7 @@ function RegisterForm({
|
|
|
2391
2454
|
}
|
|
2392
2455
|
|
|
2393
2456
|
// src/components/AuthForm.tsx
|
|
2394
|
-
var
|
|
2457
|
+
var import_react13 = require("react");
|
|
2395
2458
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2396
2459
|
function AuthForm({
|
|
2397
2460
|
defaultMode = "login",
|
|
@@ -2410,12 +2473,12 @@ function AuthForm({
|
|
|
2410
2473
|
isActive = true
|
|
2411
2474
|
}) {
|
|
2412
2475
|
const { login, register, isLoading } = useCilantroAuth();
|
|
2413
|
-
const [mode, setMode] = (0,
|
|
2414
|
-
const [usernameOrEmail, setUsernameOrEmail] = (0,
|
|
2415
|
-
const [username, setUsername] = (0,
|
|
2416
|
-
const [email, setEmail] = (0,
|
|
2417
|
-
const [password, setPassword] = (0,
|
|
2418
|
-
const [error, setError] = (0,
|
|
2476
|
+
const [mode, setMode] = (0, import_react13.useState)(defaultMode);
|
|
2477
|
+
const [usernameOrEmail, setUsernameOrEmail] = (0, import_react13.useState)("");
|
|
2478
|
+
const [username, setUsername] = (0, import_react13.useState)("");
|
|
2479
|
+
const [email, setEmail] = (0, import_react13.useState)("");
|
|
2480
|
+
const [password, setPassword] = (0, import_react13.useState)("");
|
|
2481
|
+
const [error, setError] = (0, import_react13.useState)(null);
|
|
2419
2482
|
const isLogin = mode === "login";
|
|
2420
2483
|
const handleSubmit = async (e) => {
|
|
2421
2484
|
e.preventDefault();
|
|
@@ -2602,7 +2665,7 @@ function AuthGuard({
|
|
|
2602
2665
|
}
|
|
2603
2666
|
|
|
2604
2667
|
// src/components/AddSignerForm.tsx
|
|
2605
|
-
var
|
|
2668
|
+
var import_react14 = require("react");
|
|
2606
2669
|
|
|
2607
2670
|
// src/ui/dialog.tsx
|
|
2608
2671
|
var React8 = __toESM(require("react"));
|
|
@@ -2680,12 +2743,12 @@ function AddSignerForm({
|
|
|
2680
2743
|
classNames,
|
|
2681
2744
|
asDialog = true
|
|
2682
2745
|
}) {
|
|
2683
|
-
const [signerType, setSignerType] = (0,
|
|
2684
|
-
const [email, setEmail] = (0,
|
|
2685
|
-
const [phone, setPhone] = (0,
|
|
2686
|
-
const [address, setAddress] = (0,
|
|
2687
|
-
const [isSubmitting, setIsSubmitting] = (0,
|
|
2688
|
-
const [error, setError] = (0,
|
|
2746
|
+
const [signerType, setSignerType] = (0, import_react14.useState)(null);
|
|
2747
|
+
const [email, setEmail] = (0, import_react14.useState)("");
|
|
2748
|
+
const [phone, setPhone] = (0, import_react14.useState)("");
|
|
2749
|
+
const [address, setAddress] = (0, import_react14.useState)("");
|
|
2750
|
+
const [isSubmitting, setIsSubmitting] = (0, import_react14.useState)(false);
|
|
2751
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
2689
2752
|
const resetForm = () => {
|
|
2690
2753
|
setSignerType(null);
|
|
2691
2754
|
setEmail("");
|
|
@@ -2958,7 +3021,7 @@ function AddSignerForm({
|
|
|
2958
3021
|
}
|
|
2959
3022
|
|
|
2960
3023
|
// src/components/SignerList.tsx
|
|
2961
|
-
var
|
|
3024
|
+
var import_react15 = require("react");
|
|
2962
3025
|
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
2963
3026
|
function SignerList({
|
|
2964
3027
|
walletId,
|
|
@@ -2969,7 +3032,7 @@ function SignerList({
|
|
|
2969
3032
|
children
|
|
2970
3033
|
}) {
|
|
2971
3034
|
const { signers, isLoading, error, refresh } = useSigners({ walletId });
|
|
2972
|
-
const [addSignerOpen, setAddSignerOpen] = (0,
|
|
3035
|
+
const [addSignerOpen, setAddSignerOpen] = (0, import_react15.useState)(false);
|
|
2973
3036
|
const handleAddSuccess = () => {
|
|
2974
3037
|
refresh();
|
|
2975
3038
|
onSignerAdded?.();
|
|
@@ -3149,6 +3212,7 @@ function ThemeProvider({
|
|
|
3149
3212
|
useSignerSelection,
|
|
3150
3213
|
useSigners,
|
|
3151
3214
|
useSignersForSelectedWallet,
|
|
3215
|
+
useSignersRaw,
|
|
3152
3216
|
useTransactionSigning,
|
|
3153
3217
|
useWalletAddress,
|
|
3154
3218
|
useWallets
|