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

【需求的提案】通过以太坊钱包的签名登录 #14

Open
frankwei98 opened this issue Apr 29, 2019 · 0 comments
Open

【需求的提案】通过以太坊钱包的签名登录 #14

frankwei98 opened this issue Apr 29, 2019 · 0 comments
Assignees

Comments

@frankwei98
Copy link

frankwei98 commented Apr 29, 2019

这个问题与 smart-signature/MATATAKI_FE_Mobile#326 联动

我跑不了后端的开发环境,也不太熟悉 eggjs,所以只能提 issue 了

==================分割=====================

我在前端部分测试了以太坊的签名,现在打算让后端接入使用以太坊签名登录后端的功能

通过签名本身与签名的数据,来获取签署人的地址的过程大概是这个样子:

// 引入 eth-sig-util 来处理以太坊相关的签名
const ethSigUtil = require("eth-sig-util");

// 和小岛讨论过,暂定无需防御 replay attack,以太坊没有用户名机制,就这样应该OK了?
const typedData = [
        {
          type: "string", // Any valid solidity type
          name: "Action", // Any string label you want
          value: "Login" // The value to sign
        }
];
// 通过 typedData 和 signature recover 签署人地址
const recoveredAddress =  ethSigUtil.recoverTypedSignature({
        data: typedData,
        sig: signature
});

if (address === recoveredAddress) {
  // 后续逻辑
} else {
// 后续逻辑
}

typedData?

签名的对象是格式化的数据,用户看起来比单纯的字符串更直观

image

如果有什么不足之处,欢迎讨论

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

2 participants