-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathenv.ts
More file actions
39 lines (35 loc) · 1.52 KB
/
env.ts
File metadata and controls
39 lines (35 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Gets RPC username from environment variable.
* @param networkName The network name (e.g., 'xrplevm_testnet', 'xrplevm_devnet')
* @returns The username if set, undefined otherwise
*/
export function getRpcUsername(networkName: string): string | undefined {
// Convert network name to uppercase and replace hyphens with underscores
// e.g., 'xrplevm_testnet' -> 'XRPLEVM_TESTNET'
const envKey = `${networkName.toUpperCase().replace(/-/g, "_")}_RPC_USERNAME`;
return process.env[envKey];
}
/**
* Gets RPC password from environment variable.
* @param networkName The network name (e.g., 'xrplevm_testnet', 'xrplevm_devnet')
* @returns The password if set, undefined otherwise
*/
export function getRpcPassword(networkName: string): string | undefined {
// Convert network name to uppercase and replace hyphens with underscores
// e.g., 'xrplevm_testnet' -> 'XRPLEVM_TESTNET'
const envKey = `${networkName.toUpperCase().replace(/-/g, "_")}_RPC_PASSWORD`;
return process.env[envKey];
}
/**
* Gets RPC credentials from environment variables.
* @param networkName The network name (e.g., 'xrplevm_testnet', 'xrplevm_devnet')
* @returns An object with username and password, or undefined if not set
*/
export function getRpcCredentials(networkName: string): { username: string; password: string } | undefined {
const username = getRpcUsername(networkName);
const password = getRpcPassword(networkName);
if (username && password) {
return { username, password };
}
return undefined;
}