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

Method save

packages/bitcore-cli/src/wallet.ts:302–324  ·  view source on GitHub ↗
(opts?: { encryptAll?: boolean })

Source from the content-addressed store, hash-verified

300 }
301
302 async save(opts?: { encryptAll?: boolean }) {
303 const { encryptAll } = opts || {};
304 try {
305 if (!this.#walletData) {
306 throw new Error('No wallet data to save. Wallet not created or loaded');
307 }
308 let data: WalletData | EncryptionTypes.IEncrypted = { key: this.#walletData.key?.toObj(), credentials: this.#walletData.credentials.toObj() };
309 if (encryptAll) {
310 const password = await getPassword('Enter password to encrypt:', { minLength: 6 });
311 await prompt.password({
312 message: 'Confirm password:',
313 mask: '*',
314 validate: (val) => val === password ? undefined : 'Passwords do not match'
315 });
316
317 data = Encryption.encryptWithPassword(JSON.stringify(data), password, WALLET_ENCRYPTION_OPTS);
318 }
319 await this.storage.save(JSON.stringify(data));
320 return;
321 } catch (err) {
322 Utils.die(err);
323 }
324 }
325
326 async export(args: {
327 filename: string;

Callers 4

createMethod · 0.95
createFromTssMethod · 0.95
loadMethod · 0.95
importMethod · 0.95

Calls 5

getPasswordFunction · 0.90
encryptWithPasswordMethod · 0.80
dieMethod · 0.80
saveMethod · 0.65
toObjMethod · 0.45

Tested by

no test coverage detected