@cordystackx/cordy_minikit 3.0.6 → 3.1.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.
Files changed (71) hide show
  1. package/README.md +65 -12
  2. package/dist/client/authTypes.d.ts +13 -0
  3. package/dist/client/authTypes.d.ts.map +1 -0
  4. package/dist/client/authTypes.js +1 -0
  5. package/dist/client/cons.d.ts +31 -0
  6. package/dist/client/cons.d.ts.map +1 -0
  7. package/dist/client/cons.js +63 -0
  8. package/dist/client/consRuntime.d.ts +5 -0
  9. package/dist/client/consRuntime.d.ts.map +1 -0
  10. package/dist/client/consRuntime.js +32 -0
  11. package/dist/client/runtimeConfig.d.ts +51 -3
  12. package/dist/client/runtimeConfig.d.ts.map +1 -1
  13. package/dist/client/runtimeConfig.js +15 -1
  14. package/dist/client/transfer.d.ts +21 -5
  15. package/dist/client/transfer.d.ts.map +1 -1
  16. package/dist/client/transfer.js +423 -72
  17. package/dist/client/useConsSession.d.ts +3 -0
  18. package/dist/client/useConsSession.d.ts.map +1 -0
  19. package/dist/client/useConsSession.js +36 -0
  20. package/dist/client.d.ts +4 -3
  21. package/dist/client.d.ts.map +1 -1
  22. package/dist/client.js +2 -1
  23. package/dist/client__provider.d.ts +2 -1
  24. package/dist/client__provider.d.ts.map +1 -1
  25. package/dist/client__provider.js +6 -6
  26. package/dist/components/Connect_wallet_bt.d.ts +3 -3
  27. package/dist/components/Connect_wallet_bt.d.ts.map +1 -1
  28. package/dist/components/Connect_wallet_bt.js +12 -20
  29. package/dist/components/UI_Comp.d.ts.map +1 -1
  30. package/dist/components/UI_Comp.js +124 -10
  31. package/dist/config/walletConfig.d.ts.map +1 -1
  32. package/dist/config/walletConfig.js +17 -1
  33. package/dist/controllers/BridgeEvmWalletModal.d.ts +11 -0
  34. package/dist/controllers/BridgeEvmWalletModal.d.ts.map +1 -0
  35. package/dist/controllers/BridgeEvmWalletModal.js +154 -0
  36. package/dist/controllers/DisConnect.d.ts.map +1 -1
  37. package/dist/controllers/DisConnect.js +8 -1
  38. package/dist/controllers/Get_Balance.d.ts.map +1 -1
  39. package/dist/controllers/Get_Balance.js +3 -2
  40. package/dist/controllers/Transactions.js +2 -2
  41. package/dist/controllers/bridgeWalletSession.d.ts +13 -0
  42. package/dist/controllers/bridgeWalletSession.d.ts.map +1 -0
  43. package/dist/controllers/bridgeWalletSession.js +37 -0
  44. package/dist/controllers/cctpBridge.d.ts +6 -0
  45. package/dist/controllers/cctpBridge.d.ts.map +1 -0
  46. package/dist/controllers/cctpBridge.js +326 -0
  47. package/dist/controllers/index.d.ts +4 -0
  48. package/dist/controllers/index.d.ts.map +1 -1
  49. package/dist/controllers/index.js +2 -0
  50. package/dist/controllers/useBridgeEvmWallet.d.ts +23 -0
  51. package/dist/controllers/useBridgeEvmWallet.d.ts.map +1 -0
  52. package/dist/controllers/useBridgeEvmWallet.js +83 -0
  53. package/dist/css/UI_Comp/styles.module.css +10 -0
  54. package/dist/index.d.ts +4 -2
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +2 -1
  57. package/dist/package.json +11 -7
  58. package/dist/server/cons.d.ts +67 -0
  59. package/dist/server/cons.d.ts.map +1 -0
  60. package/dist/server/cons.js +383 -0
  61. package/dist/server/jwt.d.ts +0 -17
  62. package/dist/server/jwt.d.ts.map +1 -1
  63. package/dist/server/jwt.js +1 -35
  64. package/dist/server.d.ts +3 -2
  65. package/dist/server.d.ts.map +1 -1
  66. package/dist/server.js +2 -1
  67. package/dist/tsconfig.tsbuildinfo +1 -1
  68. package/dist/wagmi__providers.d.ts +13 -3
  69. package/dist/wagmi__providers.d.ts.map +1 -1
  70. package/dist/wagmi__providers.js +102 -15
  71. package/package.json +11 -7
@@ -0,0 +1,3 @@
1
+ import type { ConsSessionResult } from "./cons";
2
+ export declare function useConsSession(): ConsSessionResult;
3
+ //# sourceMappingURL=useConsSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConsSession.d.ts","sourceRoot":"","sources":["../../client/useConsSession.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAIhD,wBAAgB,cAAc,IAAI,iBAAiB,CAiClD"}
@@ -0,0 +1,36 @@
1
+ "use client";
2
+ import { useCallback, useEffect, useState } from "react";
3
+ import { getConsUrl } from "./consRuntime";
4
+ export function useConsSession() {
5
+ const [session, setSession] = useState({ loading: true, authenticated: false });
6
+ const refresh = useCallback(async () => {
7
+ try {
8
+ const response = await fetch(getConsUrl("session"), { credentials: "same-origin", cache: "no-store" });
9
+ const body = await response.json();
10
+ const authenticated = response.ok && body.success === true;
11
+ setSession({
12
+ loading: false,
13
+ authenticated,
14
+ ...(typeof body.address === "string" ? { address: body.address } : {}),
15
+ ...(body.chain === "evm" || body.chain === "stellar" ? { chain: body.chain } : {}),
16
+ });
17
+ if (authenticated && typeof window !== "undefined")
18
+ window.dispatchEvent(new Event("cordy:cons-session-active"));
19
+ }
20
+ catch {
21
+ setSession({ loading: false, authenticated: false });
22
+ }
23
+ }, []);
24
+ useEffect(() => {
25
+ void refresh();
26
+ const handleAuthenticated = () => { void refresh(); };
27
+ const handleCleared = () => setSession({ loading: false, authenticated: false });
28
+ window.addEventListener("cordy:cons-session-authenticated", handleAuthenticated);
29
+ window.addEventListener("cordy:cons-session-cleared", handleCleared);
30
+ return () => {
31
+ window.removeEventListener("cordy:cons-session-authenticated", handleAuthenticated);
32
+ window.removeEventListener("cordy:cons-session-cleared", handleCleared);
33
+ };
34
+ }, [refresh]);
35
+ return session;
36
+ }
package/dist/client.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export { cordy, cons_verify, cons_disconnect } from "./client/jwt";
2
- export type { ConsDisconnectResult, ConsSessionResult, ConsVerifyResult } from "./client/jwt";
1
+ export { cordy, cons_verify, cons_disconnect } from "./client/cons";
2
+ export type { ConsDisconnectResult, ConsSessionResult, ConsVerifyResult } from "./client/cons";
3
+ export { useConsSession } from "./client/useConsSession";
3
4
  export { configureCordyAssets, cordy_configure, cordy_bridge, cordy_swap, cordy_transfer } from "./client/transfer";
4
- export type { CordyAssetsConfig, CordyBridgeResult, CordyBridgeSide, CordyTransferOptions, CordyTransferResult, CordySwapResult, EvmAssetConfig, EvmNetworkConfig, StellarAssetConfig } from "./client/transfer";
5
+ export type { CordyAssetsConfig, CordyBridgeConfig, CordyBridgeNetworkConfig, CordyBridgeOptions, CordyBridgeRouteConfig, CordyBridgeResult, CordyBridgeSide, CordyTransferOptions, CordyTransferResult, CordySwapOptions, CordySwapResult, EvmAssetConfig, EvmAssetRegistry, EvmNetworkConfig, StellarAssetConfig } from "./client/transfer";
5
6
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE9F,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpH,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACpE,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC/F,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpH,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,eAAe,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/client.js CHANGED
@@ -1,2 +1,3 @@
1
- export { cordy, cons_verify, cons_disconnect } from "./client/jwt";
1
+ export { cordy, cons_verify, cons_disconnect } from "./client/cons";
2
+ export { useConsSession } from "./client/useConsSession";
2
3
  export { configureCordyAssets, cordy_configure, cordy_bridge, cordy_swap, cordy_transfer } from "./client/transfer";
@@ -1,7 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { type CordyAssetsConfig } from './client/transfer';
3
- export default function ProvidersClientWrapper({ children, assets, }: {
3
+ export default function ProvidersClientWrapper({ children, assets, consPath, }: {
4
4
  children: ReactNode;
5
5
  assets?: CordyAssetsConfig;
6
+ consPath?: string;
6
7
  }): import("react").JSX.Element;
7
8
  //# sourceMappingURL=client__provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client__provider.d.ts","sourceRoot":"","sources":["../client__provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAsB,MAAM,OAAO,CAAC;AACtD,OAAO,EAAwB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAUjF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,EAC7C,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B,+BAyBA"}
1
+ {"version":3,"file":"client__provider.d.ts","sourceRoot":"","sources":["../client__provider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAsB,MAAM,OAAO,CAAC;AACtD,OAAO,EAAwB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAWjF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,EAC7C,QAAQ,EACR,MAAM,EACN,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,+BAyBA"}
@@ -5,11 +5,15 @@ import { configureCordyAssets } from './client/transfer';
5
5
  import getConfig, { config as defaultConfig, setActiveWagmiConfig } from './config/walletConfig';
6
6
  import { defineChain } from 'viem';
7
7
  import dynamic from 'next/dynamic';
8
+ import { setConsPath } from './client/consRuntime';
8
9
  // Dynamically import WalletProviders with SSR disabled
9
10
  const WalletProviders = dynamic(() => import('./wagmi__providers'), {
10
11
  ssr: false,
11
12
  });
12
- export default function ProvidersClientWrapper({ children, assets, }) {
13
+ export default function ProvidersClientWrapper({ children, assets, consPath, }) {
14
+ if (assets)
15
+ configureCordyAssets({ assets });
16
+ setConsPath(consPath);
13
17
  const walletConfig = useMemo(() => {
14
18
  const networks = assets?.networks ?? [];
15
19
  if (networks.length === 0)
@@ -28,10 +32,6 @@ export default function ProvidersClientWrapper({ children, assets, }) {
28
32
  ]));
29
33
  return getConfig(customChains, { walletConnectProjectId: assets?.walletConnectProjectId });
30
34
  }, [assets?.networks, assets?.walletConnectProjectId]);
31
- useEffect(() => {
32
- if (assets)
33
- configureCordyAssets({ assets });
34
- }, [assets]);
35
35
  useEffect(() => setActiveWagmiConfig(walletConfig), [walletConfig]);
36
- return _jsx(WalletProviders, { config: walletConfig, children: children });
36
+ return _jsx(WalletProviders, { config: walletConfig, consPath: consPath, children: children });
37
37
  }
@@ -1,12 +1,12 @@
1
1
  type ConnectWalletBTProps = {
2
2
  className?: string;
3
3
  } & ({
4
- jwt_session: true;
4
+ cons_session: true;
5
5
  navigate: string;
6
6
  } | {
7
- jwt_session?: false;
7
+ cons_session?: false;
8
8
  navigate?: never;
9
9
  });
10
- export default function ConnectWalletBT({ className, jwt_session, navigate, }: ConnectWalletBTProps): import("react").JSX.Element;
10
+ export default function ConnectWalletBT({ className, cons_session, navigate, }: ConnectWalletBTProps): import("react").JSX.Element;
11
11
  export {};
12
12
  //# sourceMappingURL=Connect_wallet_bt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Connect_wallet_bt.d.ts","sourceRoot":"","sources":["../../components/Connect_wallet_bt.tsx"],"names":[],"mappings":"AAWA,KAAK,oBAAoB,GAAG;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,CACA;IAAE,WAAW,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,WAAW,CAAC,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,EAAE,KAAK,CAAA;CAAE,CAC5C,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,SAAS,EACT,WAAmB,EACnB,QAAQ,GACT,EAAE,oBAAoB,+BAuFtB"}
1
+ {"version":3,"file":"Connect_wallet_bt.d.ts","sourceRoot":"","sources":["../../components/Connect_wallet_bt.tsx"],"names":[],"mappings":"AAUA,KAAK,oBAAoB,GAAG;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,CACA;IAAE,YAAY,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,YAAY,CAAC,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,EAAE,KAAK,CAAA;CAAE,CAC7C,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,SAAS,EACT,YAAoB,EACpB,QAAQ,GACT,EAAE,oBAAoB,+BA+EtB"}
@@ -1,44 +1,36 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useEffect, useState } from "react";
4
- import { useRouter } from "next/navigation";
5
4
  import { useAccount } from "wagmi";
6
5
  import { getTokenBalance, loadStellarBalance } from "../controllers";
7
6
  import { useStellarWallet, useWalletModal } from "../wagmi__providers";
8
7
  // const ACTIVE_WALLET_SESSION_KEY = "cordy_minikit_active_wallet_session";
9
8
  const STELLAR_BALANCE_REFRESH_EVENT = "cordy:stellar-balance-updated";
10
- export default function ConnectWalletBT({ className, jwt_session = false, navigate, }) {
11
- const router = useRouter();
12
- const { openModal, closeModal } = useWalletModal();
9
+ export default function ConnectWalletBT({ className, cons_session = false, navigate, }) {
10
+ const { openModal } = useWalletModal();
13
11
  const { stellarWallet, setStellarWallet } = useStellarWallet();
14
12
  const { isConnected, address } = useAccount();
15
13
  const [balance, setBalance] = useState("");
16
14
  const [symbol, setSymbol] = useState("");
17
15
  const walletConnected = Boolean((isConnected && address) || stellarWallet.address);
18
- if (jwt_session !== Boolean(navigate)) {
19
- throw new Error('ConnectWalletBT: provide both "jwt_session={true}" and a "navigate" path, or neither.');
16
+ if (cons_session !== Boolean(navigate)) {
17
+ throw new Error('ConnectWalletBT: provide both "cons_session={true}" and a "navigate" path, or neither.');
20
18
  }
21
- if (jwt_session &&
19
+ if (cons_session &&
22
20
  navigate &&
23
21
  (!navigate.startsWith("/") || navigate.startsWith("//") || navigate.includes("\\"))) {
24
22
  throw new Error('ConnectWalletBT: "navigate" must be a safe internal path starting with "/".');
25
23
  }
26
24
  useEffect(() => {
27
- if (jwt_session && navigate && walletConnected) {
28
- closeModal();
29
- router.replace(navigate);
30
- }
31
- }, [closeModal, jwt_session, navigate, router, walletConnected]);
32
- useEffect(() => {
33
- if (jwt_session || !isConnected || !address)
25
+ if (cons_session || !isConnected || !address)
34
26
  return;
35
27
  void getTokenBalance(address).then(({ balance: nextBalance, symbol: nextSymbol }) => {
36
28
  setBalance(nextBalance);
37
29
  setSymbol(nextSymbol);
38
30
  });
39
- }, [address, isConnected, jwt_session]);
31
+ }, [address, isConnected, cons_session]);
40
32
  useEffect(() => {
41
- if (!stellarWallet.address || jwt_session)
33
+ if (!stellarWallet.address || cons_session)
42
34
  return;
43
35
  let active = true;
44
36
  void loadStellarBalance(stellarWallet.address)
@@ -58,9 +50,9 @@ export default function ConnectWalletBT({ className, jwt_session = false, naviga
58
50
  setStellarWallet((current) => ({ ...current, balance: "0" }));
59
51
  });
60
52
  return () => { active = false; };
61
- }, [jwt_session, setStellarWallet, stellarWallet.address]);
53
+ }, [cons_session, setStellarWallet, stellarWallet.address]);
62
54
  useEffect(() => {
63
- if (jwt_session || !stellarWallet.address)
55
+ if (cons_session || !stellarWallet.address)
64
56
  return;
65
57
  const handler = () => {
66
58
  void loadStellarBalance(stellarWallet.address).then((result) => {
@@ -74,8 +66,8 @@ export default function ConnectWalletBT({ className, jwt_session = false, naviga
74
66
  };
75
67
  window.addEventListener(STELLAR_BALANCE_REFRESH_EVENT, handler);
76
68
  return () => window.removeEventListener(STELLAR_BALANCE_REFRESH_EVENT, handler);
77
- }, [jwt_session, setStellarWallet, stellarWallet.address]);
78
- return (_jsx("button", { className: className, onClick: () => openModal({ jwtSession: jwt_session }), "data-jwt-session": jwt_session ? "enabled" : undefined, type: "button", children: jwt_session
69
+ }, [cons_session, setStellarWallet, stellarWallet.address]);
70
+ return (_jsx("button", { className: className, onClick: () => openModal({ consSession: cons_session, navigate }), "data-cons-session": cons_session ? "enabled" : undefined, type: "button", children: cons_session
79
71
  ? walletConnected ? "Connected" : "Connect Wallet"
80
72
  : isConnected
81
73
  ? `BAL ${balance} ${symbol}`
@@ -1 +1 @@
1
- {"version":3,"file":"UI_Comp.d.ts","sourceRoot":"","sources":["../../components/UI_Comp.tsx"],"names":[],"mappings":"AAuCA,MAAM,CAAC,OAAO,UAAU,OAAO,gCAkJ9B"}
1
+ {"version":3,"file":"UI_Comp.d.ts","sourceRoot":"","sources":["../../components/UI_Comp.tsx"],"names":[],"mappings":"AA4CA,MAAM,CAAC,OAAO,UAAU,OAAO,gCAwP9B"}
@@ -4,7 +4,12 @@ import { UI_Comp__css } from "../css";
4
4
  import { WalletButton, getTokenBalance, StellarWalletButton, loadStellarBalance, useDisconnectWallets } from "../controllers";
5
5
  import { useWalletModal, useStellarWallet } from "../wagmi__providers";
6
6
  import { useAccount } from "wagmi";
7
- import { useState, useEffect } from "react";
7
+ import { useSignMessage } from "wagmi";
8
+ import { useRouter } from "next/navigation";
9
+ import { signTransaction as freighterSignTransaction } from "@stellar/freighter-api";
10
+ import { WebAuth } from "@stellar/stellar-sdk";
11
+ import { createSiweMessage } from "viem/siwe";
12
+ import { useState, useEffect, useRef } from "react";
8
13
  import pkg from "../package.json";
9
14
  import links from "../config/links.json";
10
15
  const ACTIVE_WALLET_SESSION_KEY = "cordy_minikit_active_wallet_session";
@@ -17,9 +22,11 @@ function CordyLogo() {
17
22
  return (_jsxs("svg", { viewBox: "0 0 512 512", role: "img", "aria-label": "Cordy Minikit", children: [_jsxs("defs", { children: [_jsxs("linearGradient", { id: "cordy-logo-gradient", x1: "140", y1: "140", x2: "350", y2: "380", gradientUnits: "userSpaceOnUse", children: [_jsx("stop", { offset: "0", stopColor: "#F2F4F8" }), _jsx("stop", { offset: "1", stopColor: "#AEBBD6" })] }), _jsxs("linearGradient", { id: "cordy-star-gradient", x1: "307", y1: "218", x2: "383", y2: "294", gradientUnits: "userSpaceOnUse", children: [_jsx("stop", { offset: "0", stopColor: "#4F8CFF" }), _jsx("stop", { offset: "1", stopColor: "#5CE1E6" })] })] }), _jsx("rect", { width: "512", height: "512", rx: "112", fill: "#111214" }), _jsx("path", { d: "M355.6 172.4 A130 130 0 1 0 355.6 339.6 A105 105 0 1 1 355.6 172.4 Z", fill: "url(#cordy-logo-gradient)" }), _jsx("path", { d: "M345 218 Q345 256 383 256 Q345 256 345 294 Q345 256 307 256 Q345 256 345 218 Z", fill: "url(#cordy-star-gradient)" })] }));
18
23
  }
19
24
  export default function UI_Comp() {
20
- const { closeModal, jwtSession } = useWalletModal();
25
+ const { openModal, closeModal, consSession, consPath, navigate, setSignedResult, authError, setAuthError } = useWalletModal();
21
26
  const { stellarWallet, setStellarWallet } = useStellarWallet();
22
27
  const { isConnected, address, chain } = useAccount();
28
+ const { signMessageAsync } = useSignMessage();
29
+ const router = useRouter();
23
30
  const [loading, setLoading] = useState(false);
24
31
  const [errorMsg, setErrorMsg] = useState();
25
32
  const [balance, setBalance] = useState("");
@@ -28,14 +35,121 @@ export default function UI_Comp() {
28
35
  const [stellarError, setStellarError] = useState();
29
36
  const [selectedRoute, setSelectedRoute] = useState(null);
30
37
  const { disconnectEVM, disconnectStellar } = useDisconnectWallets();
38
+ const signingAttempt = useRef(null);
31
39
  useEffect(() => {
32
- if (!jwtSession && isConnected && address)
40
+ if (!consSession) {
41
+ signingAttempt.current = null;
42
+ return;
43
+ }
44
+ const stellarPreferred = selectedRoute === "stellar" ||
45
+ (typeof window !== "undefined" && window.localStorage.getItem(ACTIVE_WALLET_SESSION_KEY) === "stellar");
46
+ const useStellar = stellarPreferred && Boolean(stellarWallet.address);
47
+ const evmAddress = address;
48
+ const evmChain = chain;
49
+ if ((!useStellar && (!isConnected || !evmAddress || !evmChain)) || (useStellar && !stellarWallet.network))
50
+ return;
51
+ const account = useStellar ? stellarWallet.address : evmAddress;
52
+ const attemptKey = `${useStellar ? "stellar" : "evm"}:${account}`;
53
+ if (signingAttempt.current === attemptKey)
54
+ return;
55
+ signingAttempt.current = attemptKey;
56
+ setAuthError(undefined);
57
+ void (async () => {
58
+ try {
59
+ let signedPayload;
60
+ if (useStellar) {
61
+ const detectedNetwork = String(stellarWallet.network).toLowerCase();
62
+ if (detectedNetwork !== "testnet" && detectedNetwork !== "public") {
63
+ throw new Error("Freighter must be connected to Stellar Testnet or Public network.");
64
+ }
65
+ const networkName = detectedNetwork;
66
+ const host = window.location.host;
67
+ const challengeResponse = await fetch(`${consPath}/challenge`, {
68
+ method: "POST", credentials: "same-origin", headers: { "content-type": "application/json" },
69
+ body: JSON.stringify({ chain: "stellar", account, network: networkName }),
70
+ });
71
+ const challenge = await challengeResponse.json();
72
+ if (!challengeResponse.ok || challenge?.success !== true || challenge.chain !== "stellar") {
73
+ throw new Error(typeof challenge?.message === "string" ? challenge.message : "Could not get Stellar authentication challenge.");
74
+ }
75
+ if (typeof challenge.transaction !== "string" || typeof challenge.network_passphrase !== "string" || typeof challenge.server_account !== "string" || typeof challenge.home_domain !== "string" || typeof challenge.web_auth_domain !== "string") {
76
+ throw new Error("The server returned an incomplete Stellar challenge.");
77
+ }
78
+ if (challenge.home_domain !== host || challenge.web_auth_domain !== host)
79
+ throw new Error("The Stellar challenge domain does not match this app.");
80
+ const parsed = WebAuth.readChallengeTx(challenge.transaction, challenge.server_account, challenge.network_passphrase, host, host);
81
+ if (parsed.clientAccountID !== account)
82
+ throw new Error("The Stellar challenge account does not match the connected wallet.");
83
+ if (parsed.matchedHomeDomain !== host)
84
+ throw new Error("The Stellar challenge home domain does not match this app.");
85
+ const result = await freighterSignTransaction(challenge.transaction, { networkPassphrase: challenge.network_passphrase, address: account });
86
+ if (result.error)
87
+ throw new Error(result.error.message || "The Stellar challenge could not be signed.");
88
+ if (!result.signedTxXdr || result.signerAddress !== account)
89
+ throw new Error("Freighter returned a signature for a different account.");
90
+ signedPayload = { chain: "stellar", address: account, network: networkName, signedXdr: result.signedTxXdr };
91
+ }
92
+ else {
93
+ const network = evmChain.testnet ? "testnet" : "public";
94
+ const challengeResponse = await fetch(`${consPath}/challenge`, {
95
+ method: "POST", credentials: "same-origin", headers: { "content-type": "application/json" },
96
+ body: JSON.stringify({ chain: "evm", account, network }),
97
+ });
98
+ const challenge = await challengeResponse.json();
99
+ if (!challengeResponse.ok || challenge?.success !== true || challenge.chain !== "evm" || typeof challenge.nonce !== "string") {
100
+ throw new Error(typeof challenge?.message === "string" ? challenge.message : "Could not get EVM authentication challenge.");
101
+ }
102
+ const message = createSiweMessage({
103
+ domain: window.location.host,
104
+ address: evmAddress,
105
+ statement: "Sign in to Cordy Minikit.",
106
+ uri: window.location.origin,
107
+ version: "1",
108
+ chainId: evmChain.id,
109
+ nonce: challenge.nonce,
110
+ issuedAt: new Date(),
111
+ expirationTime: new Date(Date.now() + 5 * 60 * 1000),
112
+ });
113
+ const signature = await signMessageAsync({ message });
114
+ signedPayload = { chain: "evm", address: evmAddress, network, signature, message };
115
+ }
116
+ setSignedResult(signedPayload);
117
+ const verifyResponse = await fetch(`${consPath}/verify`, {
118
+ method: "POST", credentials: "same-origin", headers: { "content-type": "application/json" }, body: JSON.stringify(signedPayload),
119
+ });
120
+ const verifyBody = await verifyResponse.json().catch(() => ({}));
121
+ if (verifyResponse.ok && verifyBody?.success === true) {
122
+ window.dispatchEvent(new Event("cordy:cons-session-authenticated"));
123
+ closeModal();
124
+ if (navigate)
125
+ router.replace(navigate);
126
+ return;
127
+ }
128
+ throw new Error(typeof verifyBody?.message === "string" ? verifyBody.message : "Signature verification failed.");
129
+ }
130
+ catch (error) {
131
+ const message = error instanceof Error ? error.message : "Authentication signing failed.";
132
+ const stellarAttempt = attemptKey.startsWith("stellar:");
133
+ if (stellarAttempt)
134
+ await disconnectStellar();
135
+ else
136
+ await disconnectEVM();
137
+ openModal({ consSession: true, navigate });
138
+ setAuthError(message.toLowerCase().includes("reject") || message.toLowerCase().includes("denied")
139
+ ? "You rejected the signature request. The wallet was disconnected."
140
+ : `Could not complete wallet signing: ${message}`);
141
+ signingAttempt.current = null;
142
+ }
143
+ })();
144
+ }, [address, chain, closeModal, consPath, consSession, disconnectEVM, disconnectStellar, isConnected, navigate, openModal, router, selectedRoute, setAuthError, setSignedResult, signMessageAsync, stellarWallet.address, stellarWallet.network]);
145
+ useEffect(() => {
146
+ if (!consSession && isConnected && address)
33
147
  void Get_Balance();
34
- }, [isConnected, address, jwtSession]);
148
+ }, [isConnected, address, consSession]);
35
149
  useEffect(() => {
36
- if (!jwtSession && stellarWallet.address)
150
+ if (!consSession && stellarWallet.address)
37
151
  void loadStellarBalance(stellarWallet.address);
38
- }, [stellarWallet.address, jwtSession]);
152
+ }, [stellarWallet.address, consSession]);
39
153
  const Get_Balance = async () => {
40
154
  if (!address)
41
155
  return;
@@ -72,7 +186,7 @@ export default function UI_Comp() {
72
186
  const connectedBalance = isStellar
73
187
  ? stellarWallet.balance ? `${stellarWallet.balance} XLM` : "Loading balance…"
74
188
  : balance ? `${Number(balance).toFixed(4)} ${symbol}` : "Loading balance…";
75
- return (_jsx("div", { className: UI_Comp__css.container, children: _jsxs("section", { className: UI_Comp__css.connector, role: "dialog", "aria-modal": "true", "aria-labelledby": "wallet-modal-title", children: [_jsxs("header", { className: UI_Comp__css.modal_header, children: [_jsx("div", { className: UI_Comp__css.brand_mark, children: _jsx(CordyLogo, {}) }), _jsxs("div", { children: [_jsx("p", { className: UI_Comp__css.eyebrow, children: "CORDY MINIKIT" }), _jsx("h2", { id: "wallet-modal-title", children: "Wallet connected" })] }), _jsx("button", { className: UI_Comp__css.close_button, type: "button", onClick: closeModal, "aria-label": "Close wallet dialog", children: "\u00D7" })] }), _jsxs("div", { className: UI_Comp__css.connected_card, children: [_jsxs("div", { className: UI_Comp__css.connected_heading, children: [_jsx("span", { className: UI_Comp__css.connected_dot }), " ", isStellar ? "Stellar wallet" : "EVM wallet", _jsx("span", { className: UI_Comp__css.network_badge, children: connectedNetwork })] }), !jwtSession && _jsxs(_Fragment, { children: [_jsx("div", { className: UI_Comp__css.balance_value, children: connectedBalance }), _jsx("p", { className: UI_Comp__css.muted, children: isStellar ? "Native balance" : "Token balance" })] }), _jsxs("div", { className: UI_Comp__css.address_row, children: [_jsx("span", { children: "Address" }), _jsx("code", { title: connectedAddress || "", children: truncateAddress(connectedAddress, 12, 8) })] }), isStellar && stellarError && _jsx("p", { className: UI_Comp__css.error_message, role: "alert", children: stellarError })] }), _jsx("button", { className: UI_Comp__css.disconnect_button, type: "button", onClick: async () => { if (isStellar)
189
+ return (_jsx("div", { className: UI_Comp__css.container, children: _jsxs("section", { className: UI_Comp__css.connector, role: "dialog", "aria-modal": "true", "aria-labelledby": "wallet-modal-title", children: [_jsxs("header", { className: UI_Comp__css.modal_header, children: [_jsx("div", { className: UI_Comp__css.brand_mark, children: _jsx(CordyLogo, {}) }), _jsxs("div", { children: [_jsx("p", { className: UI_Comp__css.eyebrow, children: "CORDY MINIKIT" }), _jsx("h2", { id: "wallet-modal-title", children: "Wallet connected" })] }), _jsx("button", { className: UI_Comp__css.close_button, type: "button", onClick: closeModal, "aria-label": "Close wallet dialog", children: "\u00D7" })] }), _jsxs("div", { className: UI_Comp__css.connected_card, children: [_jsxs("div", { className: UI_Comp__css.connected_heading, children: [_jsx("span", { className: UI_Comp__css.connected_dot }), " ", isStellar ? "Stellar wallet" : "EVM wallet", _jsx("span", { className: UI_Comp__css.network_badge, children: connectedNetwork })] }), !consSession && _jsxs(_Fragment, { children: [_jsx("div", { className: UI_Comp__css.balance_value, children: connectedBalance }), _jsx("p", { className: UI_Comp__css.muted, children: isStellar ? "Native balance" : "Token balance" })] }), _jsxs("div", { className: UI_Comp__css.address_row, children: [_jsx("span", { children: "Address" }), _jsx("code", { title: connectedAddress || "", children: truncateAddress(connectedAddress, 12, 8) })] }), authError && _jsx("p", { className: UI_Comp__css.error_message, role: "status", children: authError }), isStellar && stellarError && _jsx("p", { className: UI_Comp__css.error_message, role: "alert", children: stellarError })] }), consSession && !authError && _jsx("p", { className: UI_Comp__css.loading_notice, role: "status", children: "Check your wallet and approve the sign-in request to confirm ownership. This signs a message only; it does not send a transaction." }), _jsx("button", { className: UI_Comp__css.disconnect_button, type: "button", onClick: async () => { if (isStellar)
76
190
  await disconnectStellar();
77
191
  else
78
192
  await disconnectEVM(); }, children: "Disconnect wallet" }), footer] }) }));
@@ -80,17 +194,17 @@ export default function UI_Comp() {
80
194
  const selectedWalletRoute = walletRoutes.find((route) => route.id === selectedRoute);
81
195
  return (_jsx("div", { className: UI_Comp__css.container, children: _jsxs("section", { className: UI_Comp__css.connector, role: "dialog", "aria-modal": "true", "aria-labelledby": "wallet-modal-title", "aria-describedby": "wallet-modal-description", children: [_jsxs("header", { className: UI_Comp__css.modal_header, children: [_jsx("div", { className: UI_Comp__css.brand_mark, children: _jsx(CordyLogo, {}) }), _jsxs("div", { children: [_jsxs("p", { className: UI_Comp__css.eyebrow, children: ["CORDY MINIKIT ", _jsx("span", { children: "\u00B7" }), " WALLET ACCESS"] }), _jsx("h2", { id: "wallet-modal-title", children: selectedWalletRoute?.title || "Choose a wallet" })] }), _jsx("button", { className: UI_Comp__css.close_button, type: "button", onClick: closeModal, "aria-label": "Close wallet dialog", children: "\u00D7" })] }), _jsx("p", { id: "wallet-modal-description", className: UI_Comp__css.modal_description, children: selectedWalletRoute ? selectedWalletRoute.subtitle : "Select how you want to connect." }), (loading || stellarLoading) && _jsxs("div", { className: UI_Comp__css.loading_notice, role: "status", children: [_jsx("span", { className: UI_Comp__css.spinner }), " Waiting for wallet approval\u2026"] }), !selectedRoute ? (_jsx("div", { className: UI_Comp__css.wallet_choices, role: "group", "aria-label": "Wallet connection options", children: walletRoutes.map((route) => (_jsxs("button", { type: "button", className: UI_Comp__css.wallet_choice, onClick: () => { setErrorMsg(undefined); setStellarError(undefined); setSelectedRoute(route.id); }, children: [_jsx("span", { className: `${UI_Comp__css.choice_icon} ${route.id === "stellar" ? UI_Comp__css.stellar_choice_icon : ""}`, "aria-hidden": "true", children: route.icon }), _jsxs("span", { className: UI_Comp__css.choice_copy, children: [_jsx("span", { className: UI_Comp__css.choice_title, children: route.title }), _jsx("span", { className: UI_Comp__css.choice_subtitle, children: route.subtitle })] }), _jsx("span", { className: UI_Comp__css.choice_hint, children: route.hint }), _jsx("svg", { className: UI_Comp__css.choice_chevron, "aria-hidden": "true", viewBox: "0 0 16 16", fill: "none", children: _jsx("path", { d: "m6 3 5 5-5 5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })] }, route.id))) })) : (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", className: UI_Comp__css.back_button, onClick: () => { setSelectedRoute(null); setErrorMsg(undefined); setStellarError(undefined); }, children: [_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 16 16", fill: "none", children: _jsx("path", { d: "M10 3 5 8l5 5M5 8h8", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }), "All connection options"] }), _jsxs("div", { className: UI_Comp__css.wallet_panel, children: [_jsx("p", { className: UI_Comp__css.panel_label, children: "AVAILABLE WALLETS" }), _jsxs("div", { className: UI_Comp__css.wallet_options, children: [selectedRoute === "browser-evm" && _jsx(WalletButton, { connectorGroup: "browser", onStatusChange: ({ isPending, error }) => { setLoading(isPending); setErrorMsg(error); } }), selectedRoute === "walletconnect" && _jsx(WalletButton, { connectorGroup: "walletconnect", onStatusChange: ({ isPending, error }) => { setLoading(isPending); setErrorMsg(error); } }), selectedRoute === "stellar" && _jsx(StellarWalletButton, { onConnect: (accountId) => {
82
196
  setStellarWallet((current) => ({ ...current, address: accountId }));
83
- if (!jwtSession)
197
+ if (!consSession)
84
198
  void handleLoadStellarBalance(accountId);
85
199
  }, onStatusChange: ({ isPending, error, address: accountId, network }) => {
86
200
  setStellarLoading(isPending);
87
201
  setStellarError(error);
88
202
  if (accountId) {
89
203
  setStellarWallet((current) => ({ ...current, address: accountId }));
90
- if (!jwtSession)
204
+ if (!consSession)
91
205
  void handleLoadStellarBalance(accountId);
92
206
  }
93
207
  if (network)
94
208
  setStellarWallet((current) => ({ ...current, network }));
95
- } })] }), _jsx("p", { className: UI_Comp__css.panel_note, children: selectedRoute === "walletconnect" ? "Scan the QR code with your mobile wallet to continue." : selectedRoute === "stellar" ? "Freighter will ask you to approve access to your Stellar account." : "Choose an installed browser wallet to continue." })] })] })), (errorMsg || stellarError) && _jsx("div", { className: UI_Comp__css.error_message, role: "alert", children: errorMsg || stellarError }), _jsxs("div", { className: UI_Comp__css.modal_footer, children: [_jsx("span", { children: "Connecting only shares your public wallet address." }), footer] })] }) }));
209
+ } })] }), _jsx("p", { className: UI_Comp__css.panel_note, children: selectedRoute === "walletconnect" ? "Scan the QR code with your mobile wallet to continue." : selectedRoute === "stellar" ? "Freighter will ask you to approve access to your Stellar account." : "Choose an installed browser wallet to continue." })] })] })), (errorMsg || stellarError || authError) && _jsx("div", { className: UI_Comp__css.error_message, role: "alert", children: errorMsg || stellarError || authError }), _jsxs("div", { className: UI_Comp__css.modal_footer, children: [_jsx("span", { children: "Connecting only shares your public wallet address." }), footer] })] }) }));
96
210
  }
@@ -1 +1 @@
1
- {"version":3,"file":"walletConfig.d.ts","sourceRoot":"","sources":["../../config/walletConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,YAAY,EAAE,MAAM,OAAO,CAAC;AAG3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAG1C,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAM,EACxC,OAAO,GAAE;IAAE,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAAO,GAChD,UAAU,CAAC,OAAO,YAAY,CAAC,CA2BjC;AAED,eAAO,MAAM,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAGN,CAAC;AAI9C,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,GAAG,IAAI,CAEtF;AAED,wBAAgB,oBAAoB,IAAI,UAAU,CAAC,OAAO,YAAY,CAAC,CAEtE;AAED,wBAAgB,0BAA0B,IAAI,OAAO,CAEpD"}
1
+ {"version":3,"file":"walletConfig.d.ts","sourceRoot":"","sources":["../../config/walletConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,YAAY,EAAE,MAAM,OAAO,CAAC;AAG3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAK1C,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAM,EACxC,OAAO,GAAE;IAAE,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAAO,GAChD,UAAU,CAAC,OAAO,YAAY,CAAC,CA0CjC;AAED,eAAO,MAAM,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAGN,CAAC;AAI9C,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,GAAG,IAAI,CAEtF;AAED,wBAAgB,oBAAoB,IAAI,UAAU,CAAC,OAAO,YAAY,CAAC,CAEtE;AAED,wBAAgB,0BAA0B,IAAI,OAAO,CAEpD"}
@@ -2,6 +2,7 @@ import { http, createConfig } from 'wagmi';
2
2
  import { mainnet, base, sepolia } from 'wagmi/chains';
3
3
  import { walletConnect, metaMask, coinbaseWallet } from 'wagmi/connectors';
4
4
  import { isEvmConfigReady } from '../client/runtimeConfig';
5
+ const configCache = new Map();
5
6
  export default function getConfig(customChains = {}, options = {}) {
6
7
  const uniqueChains = [...Object.values(customChains), mainnet, base, sepolia]
7
8
  .filter((chain, index, chains) => chains.findIndex((candidate) => candidate.id === chain.id) === index);
@@ -9,13 +10,26 @@ export default function getConfig(customChains = {}, options = {}) {
9
10
  if (!firstChain)
10
11
  throw new Error('At least one EVM chain must be configured.');
11
12
  const allChains = [firstChain, ...otherChains];
13
+ const cacheKey = JSON.stringify({
14
+ walletConnectProjectId: options.walletConnectProjectId ?? null,
15
+ chains: allChains.map(({ id, name, nativeCurrency, rpcUrls, blockExplorers }) => ({
16
+ id,
17
+ name,
18
+ nativeCurrency,
19
+ rpcUrls,
20
+ blockExplorers,
21
+ })),
22
+ });
23
+ const cachedConfig = configCache.get(cacheKey);
24
+ if (cachedConfig)
25
+ return cachedConfig;
12
26
  // Use the chain's RPC URL if available
13
27
  const transports = allChains.reduce((acc, chain) => {
14
28
  const rpcUrl = chain.rpcUrls?.default?.http?.[0];
15
29
  acc[chain.id] = rpcUrl ? http(rpcUrl) : http();
16
30
  return acc;
17
31
  }, {});
18
- return createConfig({
32
+ const nextConfig = createConfig({
19
33
  chains: allChains,
20
34
  connectors: [
21
35
  metaMask(),
@@ -26,6 +40,8 @@ export default function getConfig(customChains = {}, options = {}) {
26
40
  ],
27
41
  transports,
28
42
  });
43
+ configCache.set(cacheKey, nextConfig);
44
+ return nextConfig;
29
45
  }
30
46
  export const config = typeof window !== "undefined"
31
47
  ? getConfig()
@@ -0,0 +1,11 @@
1
+ export type BridgeEvmWalletModalProps = {
2
+ open?: boolean;
3
+ onClose?: () => void;
4
+ onConnected?: (address?: string) => void;
5
+ onConnectionError?: (error: string) => void;
6
+ targetChainName?: string;
7
+ title?: string;
8
+ note?: string;
9
+ };
10
+ export default function BridgeEvmWalletModal({ open: controlledOpen, onClose: controlledOnClose, onConnected, onConnectionError, targetChainName, title, note, }: BridgeEvmWalletModalProps): import("react").JSX.Element | null;
11
+ //# sourceMappingURL=BridgeEvmWalletModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BridgeEvmWalletModal.d.ts","sourceRoot":"","sources":["../../controllers/BridgeEvmWalletModal.tsx"],"names":[],"mappings":"AAiBA,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAwEF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAC3C,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,iBAAiB,EAC1B,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,KAAK,EACL,IAAI,GACL,EAAE,yBAAyB,sCAgH3B"}