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

关于Ethers中wallet加密解密过程在“微信小程序的手机端”的速度非常缓慢问题 #4

Open
Leecole opened this issue Dec 1, 2022 · 1 comment

Comments

@Leecole
Copy link

Leecole commented Dec 1, 2022

尊敬的作者,您好!
首先非常感谢平台提供的Ethers库,使得我个人非常便捷的开发web3相关原型;其次向您反馈两个问题,非常希望得到您的回复!

两个问题如下:
一、 Ethers库中钱包wallet加密成JSON串时,耗时有两种情况;1:网页端与微信小程序的模拟器均花费13s左右时间(属于正常现象);2:微信小程序手机体验钱包加密/解密过程时,花费至少5分钟以上(属于不正常现象)
二、Ethers库钱包wallet解密过程也是同“问题一”情况;

问题一源码:

//初始化 - 创建钱包
  initWallet() {
    let _this = this;
    let count = 0 
    console.time("时长");
    function callback(progress) { //加密进度条
      parseInt(progress * 100)
      // console.log("统计次数=", count++);
      _this.setData({ welletProcess: (progress * 100).toFixed(2)})
    };
    //  创建随机钱包
    let wallet = ethers.Wallet.createRandom();
    //  使用*密码password* 加密钱包生成加密的JSON钱包文件(keystore)
    wallet.encrypt(this.data.form.password2, callback).then( json => {
      console.timeEnd("时长");
      console.log("json=", json)
      wx.setStorage({key: "keystore",data: json})
      wx.setStorage({key: "password",data: _this.data.form.password2})
      wx.showModal({ title: '提示', content: '密码创建成功', showCancel: false, success (res) {
          if (res.confirm) {
            _this.doNavigate();
          } 
        }
      })
    })
  },

问题二源码:

loadMnemonic(data) {
    let _this = this;
    let json = JSON.parse(JSON.stringify(data)); //keystore
    let password = this.data.password;

    function callback(progress) { //钱包解密进度条
      _this.setData({ walletProgress: (progress * 100).toFixed(2) });
    }
    ethers.Wallet.fromEncryptedJson(json, password, callback).then(function (wallet) {
      _this.setData({ showTransition: false, showTransition1: false, privateKey: wallet.privateKey, address: wallet.address });
      wx.setStorage({key: "address", data: wallet.address});
      wx.setStorage({key: "privateKey", data: wallet.privateKey});
      _this.getSignature(); 
    }, err => {
      _this.setData({ isShowProgress: false })
      Notify('保管箱密码错误,请重新输入!');
    });
  },

Best Wishes~~

Email: [email protected]

@Leecole Leecole changed the title 关于Ethers中wallet加密解密过程和微信小程序的速度问题 关于Ethers中wallet加密解密过程在“微信小程序的手机端”的速度非常缓慢问题 Dec 1, 2022
@Leecole
Copy link
Author

Leecole commented Dec 8, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant