Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wallet-manager): change password #598

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .changeset/stupid-baboons-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/wallet-manager": minor
---

feat(wallet-manager): change password method
12 changes: 12 additions & 0 deletions packages/wallet-manager/src/wallet-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,16 @@ describe('Wallet Manager', () => {
walletManager.exportVault(1);
}).toThrow();
});

it('Change password', async () => {
const { walletManager, password } = await setupWallet({
type: 'mnemonic',
secret: WalletManagerSpec.mnemonic,
});

const newPassword = 'foo12345678';
await walletManager.changePassword(newPassword, password);

expect(walletManager.unlock(newPassword)).resolves.not.toThrow();
});
});
8 changes: 8 additions & 0 deletions packages/wallet-manager/src/wallet-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ export class WalletManager extends EventEmitter {
this.emit('unlock');
}

async changePassword(newPassphrase: string, oldPassphrase: string) {
await this.unlock(oldPassphrase);
this.#passphrase = newPassphrase;
this.#isLocked = false;
await this.saveState();
await this.lock();
}

/**
* Retrieve and decrypt WalletManager state from storage
*/
Expand Down