I m trying to save my private key in a keystore v3 json format but when I try to encrypt it using the following methods:
myNewAccount.encrypt('########')
rsk.accounts.encrypt('the-private-key', '########')
They both give the following error:
Uncaught Error: value parameter should be a number or string.
Trying a slightly different approach,
rsk.accounts.encrypt('the-private-key', '########')
and I get a different error
Uncaught Error: options.n should be number and has value of 2048, 4096, 8192 or 16384
I even tried passing options as third argument to the encrypt function but the same error:
rsk3.accounts.encrypt('the-private-key', '#######', { kdf: 'pbkdf2', n: 4096, salt, iv, uuid })
error -> Uncaught Error: value parameter should be a number or string
What am I doing wrong? Here is how I create and use the account :
const account = rsk.accounts.create(rsk.utils.randomHex(32).toString('hex'))
rsk.accounts.wallet.add(account)
If you wish to use an existing private key:
(1)
new ethers.Wallet(privateKey)Reference: https://docs.ethers.io/v5/single-page/#/v5/api/signer/-%23-Wallet-constructor
(2)
Wallet.encrypt(password)Reference: https://docs.ethers.io/v5/single-page/#/v5/api/signer/-%23-Wallet-encrypt
If you wish to generate a new private key:
(1)
ethers.Wallet.createRandom()Reference: https://docs.ethers.io/v5/single-page/#/v5/api/signer/-%23-Wallet-createRandom
(2)
Wallet.encrypt(password)Reference: https://docs.ethers.io/v5/single-page/#/v5/api/signer/-%23-Wallet-encrypt