MCPcopy Create free account
hub / github.com/bitpay/bitcore / importWallet

Function importWallet

packages/bitcore-cli/src/commands/import.ts:8–37  ·  view source on GitHub ↗
(args: CommonArgs)

Source from the content-addressed store, hash-verified

6import type { CommonArgs } from '../../types/cli';
7
8export async function importWallet(args: CommonArgs) {
9 const { wallet } = args;
10 const replaceTilde = str => str.startsWith('~') ? str.replace('~', os.homedir()) : str;
11
12 const filename = await prompt.text({
13 message: 'Enter filename to import:',
14 initialValue: `~/${wallet.name}-export.json`,
15 validate: (value) => {
16 value = value.trim();
17 if (!value) return 'Filename is required';
18 value = replaceTilde(value);
19 if (!fs.existsSync(value)) {
20 return 'File does not exist: ' + value;
21 }
22 return; // valid value
23 }
24 });
25 if (prompt.isCancel(filename)) {
26 throw new UserCancelled();
27 }
28
29 const importPassword = await getPassword('File decryption password:', { hidden: true });
30
31 await wallet.import({
32 filename: replaceTilde(filename),
33 importPassword
34 });
35
36 prompt.log.success(`Wallet ${wallet.name} imported successfully!`);
37};

Callers

nothing calls this directly

Calls 3

getPasswordFunction · 0.90
replaceTildeFunction · 0.70
importMethod · 0.65

Tested by

no test coverage detected