Skip to content

Commit 70b736d

Browse files
rohanjadvanimat-if
andauthored
feat(cli): Add wallet:encrypt (#5327)
* feat(cli): Add `wallet:encrypt` * Update ironfish-cli/src/commands/wallet/encrypt.ts Co-authored-by: mat-if <[email protected]> --------- Co-authored-by: mat-if <[email protected]>
1 parent 7088bfd commit 70b736d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4+
import { RpcRequestError } from '@ironfish/sdk'
5+
import { Flags } from '@oclif/core'
6+
import { IronfishCommand } from '../../command'
7+
import { RemoteFlags } from '../../flags'
8+
import { inputPrompt } from '../../ui'
9+
10+
export class EncryptCommand extends IronfishCommand {
11+
static hidden = true
12+
13+
static description = 'encrypt accounts in the wallet'
14+
15+
static flags = {
16+
...RemoteFlags,
17+
passphrase: Flags.string({
18+
description: 'Passphrase to encrypt the wallet with',
19+
}),
20+
}
21+
22+
async start(): Promise<void> {
23+
const { flags } = await this.parse(EncryptCommand)
24+
25+
const client = await this.connectRpc()
26+
27+
const response = await client.wallet.getAccountsStatus()
28+
if (response.content.encrypted) {
29+
this.log('Wallet is already encrypted')
30+
this.exit(1)
31+
}
32+
33+
let passphrase = flags.passphrase
34+
if (!passphrase) {
35+
passphrase = await inputPrompt('Enter a passphrase to encrypt the wallet', true)
36+
}
37+
38+
try {
39+
await client.wallet.encrypt({
40+
passphrase,
41+
})
42+
} catch (e) {
43+
if (e instanceof RpcRequestError) {
44+
this.log('Wallet encryption failed')
45+
this.exit(1)
46+
}
47+
48+
throw e
49+
}
50+
51+
this.log('Encrypted the wallet')
52+
}
53+
}

0 commit comments

Comments
 (0)