Skip to content

Commit

Permalink
feat: add auto relayer url init
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansonhkg committed Jan 29, 2024
1 parent 0acdcfc commit 81ecbc5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
13 changes: 11 additions & 2 deletions e2e-nodejs/0_manual-tests/test-relayer-mint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -70,7 +80,6 @@ export async function main() {
const litAuthClient = new LitAuthClient({
litNodeClient,
litRelayConfig: {
relayUrl: 'https://manzano-relayer.getlit.dev',
relayApiKey: '...',
},
debug: true,
Expand Down
41 changes: 41 additions & 0 deletions packages/lit-auth-client/src/lib/lit-auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 81ecbc5

Please sign in to comment.