Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/wallet-lib/docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- [`.fromSeed()`](wallet/fromSeed.md)
- [`.generateNewWalletId()`](wallet/generateNewWalletId.md)
- [`.getAccount()`](wallet/getAccount.md)
- [`.dumpStorage()`](wallet/dumpStorage.md)
- Identities
- [`new Identities()`](identities/Identities.md)
- [`.getIdentityHDKeyByIndex()`](identities/getIdentityHDKeyByIndex.md)
Expand Down
15 changes: 15 additions & 0 deletions packages/wallet-lib/docs/wallet/dumpStorage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**Usage**: `wallet.dumpStorage([opts])`
**Description**: Method dumps the state of the storage in JSON format

**Warning**: Storage dump may contain sensitive data.
Please, do not share the output of this function for `mainnet` wallets.

Parameters:

| parameters | type | required | Description |
|------------------------|-----------|----------------| ---------------------------------------------------------- |
| **opts.log** | Boolean | no | Indicates whether storage should be logged in the console |

Returns : {String}


9 changes: 9 additions & 0 deletions packages/wallet-lib/src/types/Wallet/Wallet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ export declare class Wallet {
generateNewWalletId():string;
getAccount(accOptions?: Account.Options): Promise<Account>;
sweepWallet(): Promise<Account>

/**
* <b>Warning:</b> Storage dump may contain sensitive data.
* Please, do not share the output of this function for mainnet wallets.
* @param options
*/
dumpStorage(options?: {
log: boolean
}): string;
}

declare interface DAPIClientOptions {
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-lib/src/types/Wallet/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,6 @@ Wallet.prototype.getAccount = require('./methods/getAccount');
Wallet.prototype.generateNewWalletId = generateNewWalletId;
Wallet.prototype.exportWallet = require('./methods/exportWallet');
Wallet.prototype.sweepWallet = require('./methods/sweepWallet');
Wallet.prototype.dumpStorage = require('./methods/dumpStorage');

module.exports = Wallet;
29 changes: 29 additions & 0 deletions packages/wallet-lib/src/types/Wallet/methods/dumpStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const logger = require('../../../logger');

const defaultOptions = {
log: false,
};

/**
* Dumps storage on user's demand
*
* @param options - dumping options
* @return {string} - Returns JSON string of the wallet store
*/
function dumpStorage(options) {
const dumpOptions = options !== null && typeof options === 'object'
? Object.assign(defaultOptions, options)
: defaultOptions;
const storageDump = JSON.stringify(this.storage.store);

if (dumpOptions.log) {
// Add a linebreak to the log message for the ease of copying of the
// truncated log from the browser consoles
// (the text from the buffer then can be directly pasted to the JSON parser)
logger.info('Dumping wallet storage\n', storageDump);
}

return storageDump;
}

module.exports = dumpStorage;