diff --git a/e2e-nodejs/0_manual-tests/test-relayer-mint.mjs b/e2e-nodejs/0_manual-tests/test-relayer-mint.mjs index 14de1e3c8b..abb34520f9 100644 --- a/e2e-nodejs/0_manual-tests/test-relayer-mint.mjs +++ b/e2e-nodejs/0_manual-tests/test-relayer-mint.mjs @@ -47,9 +47,19 @@ async function getAuthSig(wallet, litNodeClient) { export async function main() { // ==================== Setup ==================== + if (!process.env.NETWORK) { + return fail(`NETWORK env var not set.`); + } + + if (!['cayenne', 'habanero', 'manzano'].includes(process.env.NETWORK)) { + return fail( + `Invalid NETWORK env var set. It has to be either 'manzano', 'habanero', or 'cayenne'` + ); + } + // -- setting up lit node client const litNodeClient = new LitNodeClient({ - litNetwork: 'manzano', + litNetwork: process.env.NETWORK, debug: true, checkNodeAttestation: true, storageProvider: { @@ -70,7 +80,6 @@ export async function main() { const litAuthClient = new LitAuthClient({ litNodeClient, litRelayConfig: { - relayUrl: 'https://manzano-relayer.getlit.dev', relayApiKey: '...', }, debug: true, diff --git a/packages/lit-auth-client/src/lib/lit-auth-client.ts b/packages/lit-auth-client/src/lib/lit-auth-client.ts index 36e7f9d126..6d32eefaec 100644 --- a/packages/lit-auth-client/src/lib/lit-auth-client.ts +++ b/packages/lit-auth-client/src/lib/lit-auth-client.ts @@ -62,6 +62,7 @@ export class LitAuthClient { this.providers = new Map(); bootstrapLogManager('auth-client'); this.debug = options?.debug ?? false; + // Check if custom relay object is provided if (options?.customRelay) { this.relay = options?.customRelay; @@ -86,6 +87,46 @@ export class LitAuthClient { }); } + // -- choose the correct relayer based on litNodeClient + // and if litRelayConfig.relayUrl is not set + if (!options?.litRelayConfig?.relayUrl) { + if (!options?.litRelayConfig?.relayApiKey) { + throw new Error( + '2 An API key is required to use the default Lit Relay server. Please provide either an API key or a custom relay server.' + ); + } + + const supportedNetworks = ['cayenne', 'habanero', 'manzano']; + + if (!supportedNetworks.includes(this.litNodeClient.config.litNetwork)) { + throw new Error( + `Unsupported litNetwork: ${ + this.litNodeClient.config.litNetwork + }. Supported networks are: ${supportedNetworks.join(', ')}` + ); + } + + let url; + + switch (this.litNodeClient.config.litNetwork) { + case 'cayenne': + url = 'https://relayer-server-staging-cayenne.getlit.dev'; + break; + case 'habanero': + url = 'https://habanero-relayer.getlit.dev'; + break; + case 'manzano': + url = 'https://manzano-relayer.getlit.dev'; + break; + } + + if (this.litNodeClient.config.litNetwork) + this.relay = new LitRelay({ + relayUrl: url, + relayApiKey: options?.litRelayConfig?.relayApiKey, + }); + } + // Set RPC URL this.rpcUrl = options?.rpcUrl || 'https://chain-rpc.litprotocol.com/http'; log('rpc url: ', this.rpcUrl);