forked from zahin-mohammad/recover-btc-with-backup-bitgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.ts
154 lines (142 loc) · 3.67 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import {
EnvironmentName,
Environments,
} from "@bitgo/sdk-core";
import {string, option, Type, optional} from "cmd-ts";
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: "i",
description: "The wallet id.",
});
export const passwordFlag = option({
type: string,
defaultValue: () => {
const password = process.env.WALLET_PASSCODE;
if (!password) {
throw new Error("WALLET_PASSCODE env var not set");
}
return password;
},
long: "walletPassword",
short: "p",
description: "The wallet passphrase for the wallet associated to walletId.",
});
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: "The access token to login to BitGo.",
});
export const oneTimePasscodeFlag = option({
type: optional(string),
long: "otp",
short: "o",
description: "The optional one-time passcode to login to BitGo. Only provide this if the token needs to be unlocked.",
});
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 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.",
});
export const userKeyFlag = option({
type: string,
defaultValue: () => {
const userKey = process.env.USER_KEY;
if (!userKey) {
throw new Error("USER_KEY env var not set");
}
return userKey;
},
long: "userKey",
short: "u",
description:
"Encrypted user private key (xprv)",
});
export const backupKeyFlag = option({
type: string,
defaultValue: () => {
const backupKey = process.env.BACKUP_KEY;
if (!backupKey) {
throw new Error("BACKUP_KEY env var not set");
}
return backupKey;
},
long: "backupKey",
short: "b",
description:
"Encrypted backup private key (xprv)",
});
export const recoveryBalanceFlag = option({
type: string,
defaultValue: () => {
const recoveryBalance = process.env.RECOVERY_BALANCE;
if (!recoveryBalance) {
throw new Error("RECOVERY_BALANCE env var not set");
}
return recoveryBalance;
},
long: "recoveryBalance",
short: "r",
description:
"Amount of coin to recover",
});
export const feeFlag = option({
type: string,
defaultValue: () => {
const fee = process.env.FEE;
if (!fee) {
throw new Error("FEE env var not set");
}
return fee;
},
long: "fee",
short: "f",
description:
"Recovery transaction on-chain fee",
});