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

Method export

packages/bitcore-cli/src/wallet.ts:326–360  ·  view source on GitHub ↗
(args: {
    filename: string;
    exportPassword?: string;
    readOnly?: boolean;
  })

Source from the content-addressed store, hash-verified

324 }
325
326 async export(args: {
327 filename: string;
328 exportPassword?: string;
329 readOnly?: boolean;
330 }) {
331 const { filename, exportPassword, readOnly } = args;
332 if (!this.#walletData) {
333 throw new Error('No wallet data to save. Wallet not created or loaded');
334 }
335
336 let key: TssKey.TssKey | KeyType | undefined;
337 if (!readOnly) {
338 if (this.#walletData.key instanceof TssKey.TssKey) {
339 key = new TssKey.TssKey(this.#walletData.key.toObj());
340 } else {
341 key = new Key({ seedType: 'object', seedData: this.#walletData.key.toObj() });
342 }
343
344 if (key.isPrivKeyEncrypted() || (key as TssKey.TssKey).isKeyChainEncrypted?.()) {
345 const walletPassword = await getPassword('Unlock wallet:');
346 key.decrypt(walletPassword);
347 }
348 }
349
350 let data: any = { key: key?.toObj(), credentials: this.#walletData.credentials.toObj() };
351 if (exportPassword != null) {
352 data = Encryption.encryptWithPassword(data, exportPassword, WALLET_ENCRYPTION_OPTS);
353 }
354
355 const pathname = path.dirname(filename);
356 if (!fs.existsSync(pathname)) {
357 fs.mkdirSync(pathname, { recursive: true });
358 }
359 return fs.promises.writeFile(filename, JSON.stringify(data));
360 }
361
362 async import(args: {
363 filename: string;

Callers

nothing calls this directly

Calls 6

getPasswordFunction · 0.90
isPrivKeyEncryptedMethod · 0.80
isKeyChainEncryptedMethod · 0.80
encryptWithPasswordMethod · 0.80
toObjMethod · 0.45
decryptMethod · 0.45

Tested by

no test coverage detected