From f565c399e39e0943df4b00da8058d3e596bbea1c Mon Sep 17 00:00:00 2001 From: discountry Date: Fri, 3 Oct 2025 03:25:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20LighterSigner=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8CbaseUrl=20=E5=8F=98=E4=B8=BA?= =?UTF-8?q?=E5=8F=AF=E9=80=89=E4=BB=A5=E6=94=AF=E6=8C=81=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E5=92=8C=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/exchanges/lighter/signer.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/exchanges/lighter/signer.ts b/src/exchanges/lighter/signer.ts index 9162381..db479dc 100644 --- a/src/exchanges/lighter/signer.ts +++ b/src/exchanges/lighter/signer.ts @@ -7,7 +7,7 @@ export interface LighterSignerConfig { accountIndex: number | bigint; chainId: number; apiKeys: Record; - baseUrl: string; + baseUrl?: string; // optional for offline signing/tests } interface BaseSignOptions { @@ -142,14 +142,12 @@ export class LighterSigner { private readonly ready: Promise; constructor(config: LighterSignerConfig) { - if (!config.baseUrl) { - throw new Error("LighterSigner requires baseUrl for signer bridge"); - } this.accountIndex = typeof config.accountIndex === "number" ? BigInt(Math.trunc(config.accountIndex)) : config.accountIndex; this.chainId = config.chainId >>> 0; - this.baseUrl = config.baseUrl; + // Default to localhost to allow offline signing in tests + this.baseUrl = config.baseUrl ?? "http://localhost"; const entries = Object.entries(config.apiKeys ?? {}); if (!entries.length) { @@ -157,15 +155,19 @@ export class LighterSigner { } this.defaultKeyIndex = Number(entries[0]![0]); - this.bridge = new PythonSignerBridge(resolveScriptPath()); + const bridge = new PythonSignerBridge(resolveScriptPath()); + this.bridge = bridge; + const baseUrl = this.baseUrl; + const chainId = this.chainId; + const accountIndexStr = this.accountIndex.toString(); this.ready = (async () => { for (const [index, key] of entries) { - await this.bridge.call("create_client", { + await bridge.call("create_client", { apiKeyIndex: Number(index), privateKey: key, - baseUrl: this.baseUrl, - chainId: this.chainId, - accountIndex: this.accountIndex.toString(), + baseUrl, + chainId, + accountIndex: accountIndexStr, }); } })();