-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.ts
117 lines (106 loc) · 3.03 KB
/
common.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import {
EnvironmentName,
Environments,
} from "@bitgo/sdk-core";
import { string, option, Type } from "cmd-ts";
export const accessTokenFlag = option({
type: string,
defaultValue: () => {
const accessToken = process.env.ACCESS_TOKEN;
if (!accessToken) {
throw new Error("ACCESS_TOKEN env var not set");
}
return accessToken;
},
long: "accessToken",
short: "a",
description:
"BitGo user account access token. If not provided, the env var ACCESS_TOKEN will be used.",
});
export const passwordFlag = option({
type: string,
long: "walletPassword",
short: "p",
description: "The wallet passphrase for the wallet associated to walletId.",
});
export const walletIdFlag = option({
type: string,
defaultValue: () => {
const walletId = process.env.WALLET_ID;
if (!walletId) {
throw new Error("WALLET_ID env var not set");
}
return walletId;
},
long: "walletId",
short: "w",
description:
"BitGo wallet id. If not provided, the env var WALLET_ID will be used.",
});
export const recoveryDestinationFlag = option({
type: string,
defaultValue: () => {
const dest = process.env.RECOVERY_DESTINATION;
if (!dest) {
throw new Error("RECOVERY_DESTINATION env var not set");
}
return dest;
},
long: "destination",
short: "d",
description:
"Recovery destination. If not provided, the env var RECOVERY_DESTINATION will be used.",
});
export const blockChairApiKeyFlag = option({
type: string,
defaultValue: () => {
const apiKey = process.env.BLOCK_CHAIR_API_KEY;
if (!apiKey) {
throw new Error("BLOCK_CHAIR_API_KEY env var not set");
}
return apiKey;
},
long: "blockChairApiKey",
short: "blockChairApiKey",
description:
"Recovery destination. If not provided, the env var BLOCK_CHAIR_API_KEY will be used.",
});
export const keyTypes = ["user", "backup"] as const;
export type KeyType = (typeof keyTypes)[number];
export const KeyTypeDecoder: Type<string, KeyType> = {
async from(str: string): Promise<KeyType> {
if (!keyTypes.includes(str as KeyType)) {
throw new Error(`invalid keyType ${str}`);
}
return str as KeyType;
},
};
export const keyTypeFlag = option({
type: KeyTypeDecoder,
long: "keyType",
short: "k",
defaultValue: () => keyTypes[0],
description: "Wether to verify user or backup key.",
});
export const envDecoder: Type<string, EnvironmentName> = {
async from(str: string): Promise<EnvironmentName> {
if (Environments[str as keyof typeof Environments] !== undefined) {
return str as EnvironmentName;
}
throw new Error(`invalid environment ${str}`);
},
};
export const envFlag = option({
type: envDecoder,
long: "env",
short: "e",
defaultValue: () => {
const envStr = process.env.BITGO_ENV;
if (Environments[envStr as keyof typeof Environments] !== undefined) {
return envStr as EnvironmentName;
}
throw new Error("BITGO_ENV env var not set");
},
description:
"BitGo environment. If not provided, the env var BITGO_ENV will be used.",
});