我试图以keystore v3 json格式保存私钥,但当我试图使用以下方法对其进行加密时:
myNewAccount.encrypt('########')rsk.accounts.encrypt('the-private-key', '########')它们都给出了以下错误:Uncaught Error: value parameter should be a number or string.
尝试一种稍微不同的方法,
rsk.accounts.encrypt('the-private-key', '########')我得到了一个不同的错误Uncaught Error: options.n should be number and has value of 2048, 4096, 8192 or 16384
我甚至尝试将选项作为第三个参数传递给encrypt函数,但同样的错误是:
rsk3.accounts.encrypt('the-private-key', '#######', { kdf: 'pbkdf2', n: 4096, salt, iv, uuid })误差-> Uncaught Error: value parameter should be a number or string
我做错了什么?下面是我创建和使用该帐户的方式:
const account = rsk.accounts.create(rsk.utils.randomHex(32).toString('hex'))
rsk.accounts.wallet.add(account)发布于 2022-09-21 02:47:42
如果您希望使用现有的私钥
(1) new ethers.Wallet(privateKey)
参考资料:https://docs.ethers.io/v5/single-page/#/v5/api/signer/-%23-Wallet-constructor
(2) Wallet.encrypt(password)
参考资料:https://docs.ethers.io/v5/single-page/#/v5/api/signer/-%23-Wallet-encrypt
// assuming you already have values set for `privateKey` and `password`
const wallet = new ethers.Wallet(privateKey); // (1)
const encryptedWalletJson = await wallet.encrypt(password); // (2)如果您希望生成一个新的私钥
(1) ethers.Wallet.createRandom()
参考资料:https://docs.ethers.io/v5/single-page/#/v5/api/signer/-%23-Wallet-createRandom
(2) Wallet.encrypt(password)
参考资料:https://docs.ethers.io/v5/single-page/#/v5/api/signer/-%23-Wallet-encrypt
// assuming you already have a value for `password`
const wallet = ethers.Wallet.createRandom(); // (1)
const encryptedWalletJson = await wallet.encrypt(password); // (2)https://stackoverflow.com/questions/73616540
复制相似问题