-
Notifications
You must be signed in to change notification settings - Fork 8
/
client_loader.ts
38 lines (32 loc) · 1.02 KB
/
client_loader.ts
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
import fs from "fs";
import path from "path";
import { env } from "process";
import { GridClient } from "../src";
const os = require("os");
const network = env.NETWORK;
const mnemonic = env.MNEMONIC;
const storeSecret = env.STORE_SECRET;
const ssh_key = fs.readFileSync(os.homedir() + "/.ssh/id_ed25519.pub", "utf-8");
let config;
if (!network || !mnemonic || !ssh_key) {
console.log("Credentials not all found in env variables. Loading all credentials from default config.json...");
config = JSON.parse(fs.readFileSync(path.join(__dirname, "./config.json"), "utf-8"));
} else {
console.log("Credentials loaded from env variables...");
config = {
network: network,
mnemonic: mnemonic,
storeSecret: storeSecret,
ssh_key: ssh_key,
};
}
async function getClient(): Promise<GridClient> {
const gridClient = new GridClient({
network: config.network,
mnemonic: config.mnemonic,
storeSecret: config.storeSecret,
});
await gridClient.connect();
return gridClient;
}
export { config, getClient };