-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathkeys.ts
More file actions
33 lines (30 loc) · 849 Bytes
/
keys.ts
File metadata and controls
33 lines (30 loc) · 849 Bytes
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
/**
* Derive signer payment addresses from mnemonics using MeshWallet.
*/
export async function derivePaymentAddress(
mnemonic: string[],
networkId: 0 | 1,
): Promise<string> {
const { MeshWallet } = await import("@meshsdk/core");
const wallet = new MeshWallet({
networkId,
key: { type: "mnemonic", words: mnemonic },
});
await wallet.init();
return wallet.getChangeAddress();
}
export function requireEnv(name: string): string {
const value = process.env[name];
if (!value) {
throw new Error(`Missing required env var: ${name}`);
}
return value;
}
export function mnemonicFromEnv(envName: string): string[] {
const raw = requireEnv(envName);
const words = raw.trim().split(/\s+/);
if (words.length < 12) {
throw new Error(`${envName} must contain at least 12 mnemonic words`);
}
return words;
}