@cordystackx/cordy_minikit 3.0.10 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -8
- package/dist/client/authTypes.d.ts +13 -0
- package/dist/client/authTypes.d.ts.map +1 -0
- package/dist/client/authTypes.js +1 -0
- package/dist/client/cons.d.ts +31 -0
- package/dist/client/cons.d.ts.map +1 -0
- package/dist/client/cons.js +63 -0
- package/dist/client/consRuntime.d.ts +5 -0
- package/dist/client/consRuntime.d.ts.map +1 -0
- package/dist/client/consRuntime.js +32 -0
- package/dist/client/transfer.d.ts.map +1 -1
- package/dist/client/transfer.js +11 -0
- package/dist/client/useConsSession.d.ts +3 -0
- package/dist/client/useConsSession.d.ts.map +1 -0
- package/dist/client/useConsSession.js +36 -0
- package/dist/client.d.ts +3 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/client__provider.d.ts +2 -1
- package/dist/client__provider.d.ts.map +1 -1
- package/dist/client__provider.js +4 -2
- package/dist/components/Connect_wallet_bt.d.ts.map +1 -1
- package/dist/components/Connect_wallet_bt.js +2 -10
- package/dist/components/UI_Comp.d.ts.map +1 -1
- package/dist/components/UI_Comp.js +118 -4
- package/dist/config/walletConfig.d.ts.map +1 -1
- package/dist/config/walletConfig.js +17 -1
- package/dist/controllers/DisConnect.d.ts.map +1 -1
- package/dist/controllers/DisConnect.js +8 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/package.json +4 -1
- package/dist/server/cons.d.ts +67 -0
- package/dist/server/cons.d.ts.map +1 -0
- package/dist/server/cons.js +383 -0
- package/dist/server/jwt.d.ts +0 -17
- package/dist/server/jwt.d.ts.map +1 -1
- package/dist/server/jwt.js +1 -35
- package/dist/server.d.ts +3 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/wagmi__providers.d.ts +11 -1
- package/dist/wagmi__providers.d.ts.map +1 -1
- package/dist/wagmi__providers.js +98 -11
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<img src="https://raw.githubusercontent.com/cordyStackX/cordy_minikit_official/21cb17b5569b79b29545da80da33d82625e26c7b/assets/cordy-logo.svg" alt="Cordy Minikit logo" width="160" />
|
|
3
3
|
<h1>Cordy Minikit</h1>
|
|
4
|
-
<p>Typed Web3 toolkit for EVM and Stellar
|
|
4
|
+
<p>Typed Web3 toolkit for EVM and Stellar wallet access, server-verified sign-in, balances, transfers, swaps, and bridges.</p>
|
|
5
5
|
</div>
|
|
6
6
|
|
|
7
7
|
## Configuration highlights
|
|
@@ -54,8 +54,8 @@ belong under `evm["<chainId>"]`; bridge directions and contract details belong
|
|
|
54
54
|
under `bridge.routes[]`.
|
|
55
55
|
|
|
56
56
|
<p align="center">
|
|
57
|
-
<a href="https://badge.socket.dev/npm/package/@cordystackx/cordy_minikit/3.
|
|
58
|
-
<img src="https://badge.socket.dev/npm/package/@cordystackx/cordy_minikit/3.
|
|
57
|
+
<a href="https://badge.socket.dev/npm/package/@cordystackx/cordy_minikit/3.1.1">
|
|
58
|
+
<img src="https://badge.socket.dev/npm/package/@cordystackx/cordy_minikit/3.1.1" alt="Socket Badge" />
|
|
59
59
|
</a>
|
|
60
60
|
</p>
|
|
61
61
|
|
|
@@ -85,15 +85,16 @@ npm install @cordystackx/cordy_minikit
|
|
|
85
85
|
pnpm add @cordystackx/cordy_minikit
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
## 3.
|
|
88
|
+
## Version 3.1.1 documentation
|
|
89
89
|
|
|
90
90
|
Read the complete documentation in the [`docs/` folder](./docs/README.md):
|
|
91
91
|
|
|
92
92
|
- [Documentation index](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/README.md)
|
|
93
93
|
- [Environment configuration](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/environment.md)
|
|
94
|
-
- [3.
|
|
94
|
+
- [3.1.1 API reference](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/api.md)
|
|
95
95
|
- [3.0.0 migration guide](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/migration-3.0.0.md)
|
|
96
96
|
- [Provider and wallet UI setup](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/setup.md)
|
|
97
|
+
- [Use Cordy functions in your app](https://github.com/cordyStackX/cordy_minikit_official/blob/main/docs/recipes.md)
|
|
97
98
|
|
|
98
99
|
## Current API
|
|
99
100
|
|
|
@@ -106,21 +107,23 @@ const transfer = await cordy.transfer("1", recipient);
|
|
|
106
107
|
await cordy.cons_disconnect();
|
|
107
108
|
```
|
|
108
109
|
|
|
109
|
-
The current 3.
|
|
110
|
+
The current 3.1.1 API is:
|
|
110
111
|
|
|
111
112
|
- `cordy.configure({ assets })`
|
|
112
113
|
- `cordy.cons_verify()`
|
|
113
114
|
- `cordy.cons_disconnect()`
|
|
115
|
+
- `useConsSession()`
|
|
116
|
+
- `createCordyServer()` from `@cordystackx/cordy_minikit/server`
|
|
114
117
|
- `cordy.transfer()`
|
|
115
118
|
- `cordy.balance()`
|
|
116
119
|
- `cordy.swap(amount, from, to, tolerancePercent?, options?)`
|
|
117
120
|
- `cordy.bridge(amount, from, to, recipient, options?)`
|
|
118
121
|
|
|
119
|
-
`
|
|
122
|
+
With `cons_session={true}`, `ConnectWalletBT` requests a wallet signature, verifies SIWE (EVM) or SEP-10 (Stellar) through your server, and navigates only after verification succeeds. Mount the SDK server handler and configure it with `createCordyServer()`; the SDK never reads environment variables. `cordy.cons_verify()` and `useConsSession()` read the resulting server session, while `cordy.cons_disconnect()` clears the session and disconnects wallets. See the [authentication guide](./docs/api.md#server-authentication). Keep signing keys in server-only environment variables and never pass them to client components.
|
|
120
123
|
|
|
121
124
|
## Bridge API
|
|
122
125
|
|
|
123
|
-
`cordy.bridge()` is a supported API in 3.0.
|
|
126
|
+
`cordy.bridge()` is a supported API in 3.1.0. Configure routes in `assets.bridge.routes`; pass `{ routeId }` when more than one route is configured. The demo includes BOT Chain Testnet ↔ Sepolia and BOT Chain Testnet ↔ BNB Testnet validator routes, plus Stellar Testnet ↔ Sepolia CCTP for USDC. EVM validator delivery is asynchronous; CCTP completes through attestation and destination mint. See the [bridge route configuration](./docs/environment.md#bridge-routes), [API example](./docs/api.md#cordybridgeamount-from-to-recipient-options), and [Use Cordy functions in your app](./docs/recipes.md).
|
|
124
127
|
|
|
125
128
|
`cordy.swap(amount, from, to, tolerancePercent?, options?)` is available for configured EVM and Stellar assets. EVM networks can configure a V2 `swapRouterAddress`, V3 `swapV3` router and QuoterV2, or both. The default `auto` mode compares configured quotes; use `{ version: "v2" }` or `{ version: "v3" }` to choose explicitly. Pass `feeTiers: [500, 3000]` in the options to override the configured V3 tiers for one call; with `version: "auto"`, V2 is still compared against only those selected V3 tiers. The tiers `500`, `3000`, and `10000` correspond to pool fees of 0.05%, 0.30%, and 1.00%. Every network needs compatible deployments, fee tiers, token addresses, and available liquidity. Native EVM swaps also need `wrappedNativeTokenAddress`. Stellar swaps use Horizon strict-send path payments and require a live liquidity path. The tolerance argument is a percentage: `1` means 1% tolerance, and omission defaults to 1%.
|
|
126
129
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ConsSignedResult = {
|
|
2
|
+
chain: "evm";
|
|
3
|
+
address: `0x${string}`;
|
|
4
|
+
network: "testnet" | "public";
|
|
5
|
+
signature: `0x${string}`;
|
|
6
|
+
message: string;
|
|
7
|
+
} | {
|
|
8
|
+
chain: "stellar";
|
|
9
|
+
address: string;
|
|
10
|
+
network: "testnet" | "public";
|
|
11
|
+
signedXdr: string;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=authTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authTypes.d.ts","sourceRoot":"","sources":["../../client/authTypes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACxB;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,SAAS,GAAG,QAAQ,CAAC;IAAC,SAAS,EAAE,KAAK,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAClH;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,SAAS,GAAG,QAAQ,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { configureCordyAssets, cordy_balance, cordy_bridge, cordy_swap, cordy_transfer } from "./transfer";
|
|
2
|
+
export type ConsVerifyResult = {
|
|
3
|
+
success: boolean;
|
|
4
|
+
authenticated: boolean;
|
|
5
|
+
address?: string;
|
|
6
|
+
chain?: "evm" | "stellar";
|
|
7
|
+
message?: string;
|
|
8
|
+
};
|
|
9
|
+
export type ConsSessionResult = {
|
|
10
|
+
loading: boolean;
|
|
11
|
+
authenticated: boolean;
|
|
12
|
+
address?: string;
|
|
13
|
+
chain?: "evm" | "stellar";
|
|
14
|
+
};
|
|
15
|
+
export type ConsDisconnectResult = {
|
|
16
|
+
success: boolean;
|
|
17
|
+
walletDisconnected: boolean;
|
|
18
|
+
error?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function cons_verify(): Promise<ConsVerifyResult>;
|
|
21
|
+
export declare function cons_disconnect(): Promise<ConsDisconnectResult>;
|
|
22
|
+
export declare const cordy: {
|
|
23
|
+
configure: typeof configureCordyAssets;
|
|
24
|
+
cons_verify: typeof cons_verify;
|
|
25
|
+
cons_disconnect: typeof cons_disconnect;
|
|
26
|
+
balance: typeof cordy_balance;
|
|
27
|
+
transfer: typeof cordy_transfer;
|
|
28
|
+
swap: typeof cordy_swap;
|
|
29
|
+
bridge: typeof cordy_bridge;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=cons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cons.d.ts","sourceRoot":"","sources":["../../client/cons.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG3G,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAKF,wBAAsB,WAAW,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAc7D;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,oBAAoB,CAAC,CA6BrE;AAED,eAAO,MAAM,KAAK;;;;;;;;CAQjB,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { configureCordyAssets, cordy_balance, cordy_bridge, cordy_swap, cordy_transfer } from "./transfer";
|
|
3
|
+
import { getConsUrl } from "./consRuntime";
|
|
4
|
+
const STELLAR_WALLET_STORAGE_KEY = "cordy_minikit_stellar_wallet";
|
|
5
|
+
const ACTIVE_WALLET_SESSION_KEY = "cordy_minikit_active_wallet_session";
|
|
6
|
+
export async function cons_verify() {
|
|
7
|
+
try {
|
|
8
|
+
const response = await fetch(getConsUrl("session"), { credentials: "same-origin", cache: "no-store" });
|
|
9
|
+
const body = await response.json();
|
|
10
|
+
return {
|
|
11
|
+
success: response.ok && body?.success === true,
|
|
12
|
+
authenticated: response.ok && body?.success === true,
|
|
13
|
+
...(typeof body?.address === "string" ? { address: body.address } : {}),
|
|
14
|
+
...(body?.chain === "evm" || body?.chain === "stellar" ? { chain: body.chain } : {}),
|
|
15
|
+
...(typeof body?.message === "string" ? { message: body.message } : {}),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return { success: false, authenticated: false, message: "Could not check the authentication session." };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export async function cons_disconnect() {
|
|
23
|
+
let serverCleared = false;
|
|
24
|
+
let walletDisconnected = false;
|
|
25
|
+
let message;
|
|
26
|
+
try {
|
|
27
|
+
const response = await fetch(getConsUrl("disconnect"), { method: "POST", credentials: "same-origin" });
|
|
28
|
+
const body = await response.json().catch(() => null);
|
|
29
|
+
serverCleared = response.ok && body?.success === true;
|
|
30
|
+
if (!serverCleared)
|
|
31
|
+
message = typeof body?.message === "string" ? body.message : "Could not clear the server session.";
|
|
32
|
+
else if (typeof window !== "undefined")
|
|
33
|
+
window.dispatchEvent(new Event("cordy:cons-session-cleared"));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
message = "Could not reach the server to clear the session.";
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const { disconnect } = await import("wagmi/actions");
|
|
40
|
+
const { getActiveWagmiConfig } = await import("../config/walletConfig");
|
|
41
|
+
const config = getActiveWagmiConfig();
|
|
42
|
+
const connections = Array.from(config.state.connections.values());
|
|
43
|
+
for (const connection of connections)
|
|
44
|
+
await disconnect(config, { connector: connection.connector });
|
|
45
|
+
window.localStorage.removeItem(STELLAR_WALLET_STORAGE_KEY);
|
|
46
|
+
window.localStorage.removeItem(ACTIVE_WALLET_SESSION_KEY);
|
|
47
|
+
window.dispatchEvent(new Event("cordy:disconnect-stellar-wallet"));
|
|
48
|
+
walletDisconnected = true;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
message = message ?? "Wallet disconnect failed.";
|
|
52
|
+
}
|
|
53
|
+
return { success: serverCleared && walletDisconnected, walletDisconnected, ...(message ? { error: message } : {}) };
|
|
54
|
+
}
|
|
55
|
+
export const cordy = {
|
|
56
|
+
configure: configureCordyAssets,
|
|
57
|
+
cons_verify,
|
|
58
|
+
cons_disconnect,
|
|
59
|
+
balance: cordy_balance,
|
|
60
|
+
transfer: cordy_transfer,
|
|
61
|
+
swap: cordy_swap,
|
|
62
|
+
bridge: cordy_bridge,
|
|
63
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function setConsPath(path?: string): void;
|
|
2
|
+
export declare function getConsPath(): string;
|
|
3
|
+
export declare function getConsUrl(action: "challenge" | "verify" | "disconnect" | "session", base?: string): string;
|
|
4
|
+
export declare function requestConsDisconnect(base?: string): Promise<boolean>;
|
|
5
|
+
//# sourceMappingURL=consRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consRuntime.d.ts","sourceRoot":"","sources":["../../client/consRuntime.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAU/C;AAED,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,EAAE,IAAI,SAAiB,GAAG,MAAM,CAEnH;AAED,wBAAsB,qBAAqB,CAAC,IAAI,SAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAUnF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const DEFAULT_CONS_PATH = "/services/cons";
|
|
2
|
+
let activeConsPath = DEFAULT_CONS_PATH;
|
|
3
|
+
export function setConsPath(path) {
|
|
4
|
+
if (path === undefined) {
|
|
5
|
+
activeConsPath = DEFAULT_CONS_PATH;
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const normalized = path.trim().replace(/\/+$/, "");
|
|
9
|
+
if (!normalized.startsWith("/") || normalized.startsWith("//") || /[?#\\]/.test(normalized)) {
|
|
10
|
+
throw new Error('ProvidersClientWrapper: "consPath" must be a same-origin path such as "/services/cons".');
|
|
11
|
+
}
|
|
12
|
+
activeConsPath = normalized;
|
|
13
|
+
}
|
|
14
|
+
export function getConsPath() {
|
|
15
|
+
return activeConsPath;
|
|
16
|
+
}
|
|
17
|
+
export function getConsUrl(action, base = activeConsPath) {
|
|
18
|
+
return `${base}/${action}`;
|
|
19
|
+
}
|
|
20
|
+
export async function requestConsDisconnect(base = activeConsPath) {
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetch(getConsUrl("disconnect", base), { method: "POST", credentials: "same-origin" });
|
|
23
|
+
const body = await response.json().catch(() => null);
|
|
24
|
+
const success = response.ok && body?.success === true;
|
|
25
|
+
if (success && typeof window !== "undefined")
|
|
26
|
+
window.dispatchEvent(new Event("cordy:cons-session-cleared"));
|
|
27
|
+
return success;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../../client/transfer.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,iBAAiB,EAAgF,MAAM,iBAAiB,CAAC;AAEvI,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,C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EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,CAuD5B;AAsID,gFAAgF;AAChF,wBAAsB,aAAa,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAYlG;AAySD,yEAAyE;AACzE,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,gBAAgB,SAAiC,EACjD,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAW1B;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,iBAAiB,CAAA;CAAE,GAAG,IAAI,CAE5E;AAED,2EAA2E;AAC3E,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAa9B"}
|
package/dist/client/transfer.js
CHANGED
|
@@ -512,6 +512,17 @@ async function transferEvm(amount, recipient, requestedSymbol) {
|
|
|
512
512
|
const chainId = Number(chain.chainId);
|
|
513
513
|
requireConfiguredEvmNetwork(configuredAssets, chainId, chain.name);
|
|
514
514
|
const tokenConfig = resolveEvmAsset(requestedSymbol, chainId, chain.name);
|
|
515
|
+
if (tokenConfig?.type === "native") {
|
|
516
|
+
const signer = await provider.getSigner(connection.accounts[0]);
|
|
517
|
+
const transaction = await signer.sendTransaction({
|
|
518
|
+
to: recipient,
|
|
519
|
+
value: parseUnits(amount, tokenConfig.decimals),
|
|
520
|
+
});
|
|
521
|
+
const receipt = await transaction.wait();
|
|
522
|
+
if (!receipt || receipt.status !== 1)
|
|
523
|
+
throw new Error("Native EVM transfer did not complete successfully.");
|
|
524
|
+
return { success: true, asset: tokenConfig.symbol, network: "evm", transactionHash: receipt.hash || transaction.hash };
|
|
525
|
+
}
|
|
515
526
|
const contractAddress = tokenConfig?.contractAddress || "";
|
|
516
527
|
if (!contractAddress) {
|
|
517
528
|
throw new Error(`No ${requestedSymbol || "default"} EVM token configured. Add it to the asset JSON.`);
|
|
@@ -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/
|
|
2
|
-
export type { ConsDisconnectResult, ConsSessionResult, ConsVerifyResult } from "./client/
|
|
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
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
|
package/dist/client.d.ts.map
CHANGED
|
@@ -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,
|
|
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/
|
|
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;
|
|
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"}
|
package/dist/client__provider.js
CHANGED
|
@@ -5,13 +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, }) {
|
|
13
14
|
if (assets)
|
|
14
15
|
configureCordyAssets({ assets });
|
|
16
|
+
setConsPath(consPath);
|
|
15
17
|
const walletConfig = useMemo(() => {
|
|
16
18
|
const networks = assets?.networks ?? [];
|
|
17
19
|
if (networks.length === 0)
|
|
@@ -31,5 +33,5 @@ export default function ProvidersClientWrapper({ children, assets, }) {
|
|
|
31
33
|
return getConfig(customChains, { walletConnectProjectId: assets?.walletConnectProjectId });
|
|
32
34
|
}, [assets?.networks, assets?.walletConnectProjectId]);
|
|
33
35
|
useEffect(() => setActiveWagmiConfig(walletConfig), [walletConfig]);
|
|
34
|
-
return _jsx(WalletProviders, { config: walletConfig, children: children });
|
|
36
|
+
return _jsx(WalletProviders, { config: walletConfig, consPath: consPath, children: children });
|
|
35
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connect_wallet_bt.d.ts","sourceRoot":"","sources":["../../components/Connect_wallet_bt.tsx"],"names":[],"mappings":"
|
|
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,15 +1,13 @@
|
|
|
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
9
|
export default function ConnectWalletBT({ className, cons_session = false, navigate, }) {
|
|
11
|
-
const
|
|
12
|
-
const { openModal, closeModal } = useWalletModal();
|
|
10
|
+
const { openModal } = useWalletModal();
|
|
13
11
|
const { stellarWallet, setStellarWallet } = useStellarWallet();
|
|
14
12
|
const { isConnected, address } = useAccount();
|
|
15
13
|
const [balance, setBalance] = useState("");
|
|
@@ -23,12 +21,6 @@ export default function ConnectWalletBT({ className, cons_session = false, navig
|
|
|
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
|
-
useEffect(() => {
|
|
27
|
-
if (cons_session && navigate && walletConnected) {
|
|
28
|
-
closeModal();
|
|
29
|
-
router.replace(navigate);
|
|
30
|
-
}
|
|
31
|
-
}, [closeModal, cons_session, navigate, router, walletConnected]);
|
|
32
24
|
useEffect(() => {
|
|
33
25
|
if (cons_session || !isConnected || !address)
|
|
34
26
|
return;
|
|
@@ -75,7 +67,7 @@ export default function ConnectWalletBT({ className, cons_session = false, navig
|
|
|
75
67
|
window.addEventListener(STELLAR_BALANCE_REFRESH_EVENT, handler);
|
|
76
68
|
return () => window.removeEventListener(STELLAR_BALANCE_REFRESH_EVENT, handler);
|
|
77
69
|
}, [cons_session, setStellarWallet, stellarWallet.address]);
|
|
78
|
-
return (_jsx("button", { className: className, onClick: () => openModal({ consSession: cons_session }), "data-cons-session": cons_session ? "enabled" : undefined, type: "button", children: cons_session
|
|
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":"
|
|
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 {
|
|
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, consSession } = 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,6 +35,113 @@ 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);
|
|
39
|
+
useEffect(() => {
|
|
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]);
|
|
31
145
|
useEffect(() => {
|
|
32
146
|
if (!consSession && isConnected && address)
|
|
33
147
|
void Get_Balance();
|
|
@@ -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 })] }), !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) })] }), 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] }) }));
|
|
@@ -92,5 +206,5 @@ export default function UI_Comp() {
|
|
|
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;
|
|
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"}
|