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

feat(web3): supports signMessage, add login example after connecting #631

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jeasonstudio
Copy link
Collaborator

几个变化:

  • signMessage 作为一个比较常用的方法签名,添加到了 UniversalWeb3ProviderInterface 类型上,理论上其他链的 Provider 都应该实现这个方法(solana 可以看下 @gin-lsl
  • 目前通过 onConnected 回调添加了连接钱包后登陆的流程示例,需要考虑下怎么默认集成到组件(或 web3-wagmi)中

Copy link

changeset-bot bot commented Mar 12, 2024

🦋 Changeset detected

Latest commit: 5e61456

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@ant-design/web3-common Minor
@ant-design/web3-wagmi Minor
@ant-design/web3 Patch
@ant-design/web3-assets Patch
@ant-design/web3-solana Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
ant-design-web3 ✅ Ready (Inspect) Visit Preview Mar 12, 2024 8:39am

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 22.22222% with 21 lines in your changes are missing coverage. Please review.

Project coverage is 99.87%. Comparing base (6eaee12) to head (5e61456).

Files Patch % Lines
...kages/wagmi/src/wagmi-provider/config-provider.tsx 22.22% 21 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #631      +/-   ##
===========================================
- Coverage   100.00%   99.87%   -0.13%     
===========================================
  Files          649      649              
  Lines        17428    17455      +27     
  Branches      1053     1053              
===========================================
+ Hits         17428    17434       +6     
- Misses           0       21      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Mar 12, 2024

@jeasonstudio jeasonstudio marked this pull request as draft March 12, 2024 08:39
@yutingzhao1991
Copy link
Collaborator

我感觉 signMessage 内置进去好像也没太大必要,现在 UniversalAPI 里面的方法都是组件内部要用到的。

签名的功能基于 onConnected 里面直接调用 wagmi 的方法就可以了,提供一个 Demo 就很实用。

如果真的要内置的话应该是组件内有需求再内置,比如说很多 DApp 登录经常都需要签名来做验证,可能我们支持下:

<Connector requireSignMessage={{
  message: 'xxxx',
  requestCheckResult: async () => {
    // 请求后端检查签名,种 cookie
    return true;
  },
}} />

我的建议就是先提供一个 Demo,至于要不要内置可能要调研一下现在的 DApp 的具体需求场景,设计上可能也要做支持,比如连接后但是没有签名验证应该怎么显示?

@jeasonstudio
Copy link
Collaborator Author

我感觉 signMessage 内置进去好像也没太大必要,现在 UniversalAPI 里面的方法都是组件内部要用到的。

签名的功能基于 onConnected 里面直接调用 wagmi 的方法就可以了,提供一个 Demo 就很实用。

如果真的要内置的话应该是组件内有需求再内置,比如说很多 DApp 登录经常都需要签名来做验证,可能我们支持下:

<Connector requireSignMessage={{
  message: 'xxxx',
  requestCheckResult: async () => {
    // 请求后端检查签名,种 cookie
    return true;
  },
}} />

我的建议就是先提供一个 Demo,至于要不要内置可能要调研一下现在的 DApp 的具体需求场景,设计上可能也要做支持,比如连接后但是没有签名验证应该怎么显示?

我倒是觉得连接+登陆是需要作为一个内置功能来提供的,dapp 只要有后端,基本就需要用到 sign message 来登陆,目前见到的很多 dapp 也用到了 siwe,比如 https://mirror.xyz/

@@ -86,6 +86,12 @@ Ant Design Web3 内置了对 [TokenPocket](https://www.tokenpocket.pro/) 的支

<code src="./demos/web3modal.tsx"></code>

## 登陆
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其实好像 登录 的用法更多。 登陆感觉少见
image

@@ -86,6 +86,12 @@ Ant Design Web3 内置了对 [TokenPocket](https://www.tokenpocket.pro/) 的支

<code src="./demos/web3modal.tsx"></code>

## 登陆

连接钱包后通过 `onConnected` 回调签名用户信息完成登陆。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

@thinkasany
Copy link
Collaborator

  1. 覆盖一下单测
    image
  2. 标题似乎可以加个 feat: xxx

@yutingzhao1991
Copy link
Collaborator

我感觉 signMessage 内置进去好像也没太大必要,现在 UniversalAPI 里面的方法都是组件内部要用到的。
签名的功能基于 onConnected 里面直接调用 wagmi 的方法就可以了,提供一个 Demo 就很实用。
如果真的要内置的话应该是组件内有需求再内置,比如说很多 DApp 登录经常都需要签名来做验证,可能我们支持下:

<Connector requireSignMessage={{
  message: 'xxxx',
  requestCheckResult: async () => {
    // 请求后端检查签名,种 cookie
    return true;
  },
}} />

我的建议就是先提供一个 Demo,至于要不要内置可能要调研一下现在的 DApp 的具体需求场景,设计上可能也要做支持,比如连接后但是没有签名验证应该怎么显示?

我倒是觉得连接+登陆是需要作为一个内置功能来提供的,dapp 只要有后端,基本就需要用到 sign message 来登陆,目前见到的很多 dapp 也用到了 siwe,比如 https://mirror.xyz/

那就内置掉,看看 API 怎么设计好。

@gin-lsl
Copy link
Collaborator

gin-lsl commented Mar 13, 2024

Solana 生态标准也有个 signMessage 方法。除了这个,还有个新的 signIn 方法。按照标准这两个方法都会被注入到 window.solana 上面。

这里有个介绍区别的文章:https://phantom.app/learn/developers/sign-in-with-solana

如果要适配的话,是要用 signMessage 吗?

@gin-lsl
Copy link
Collaborator

gin-lsl commented Mar 13, 2024

这个 signIn 感觉是对标你之前提到的 swie 的?

@yutingzhao1991
Copy link
Collaborator

这个 signIn 感觉是对标你之前提到的 swie 的?

看上去是,应该是两个功能。一个是签名,一个是基于 solana 账号登录,不过后者应该也会用到签名。

@jeasonstudio
Copy link
Collaborator Author

这个 signIn 感觉是对标你之前提到的 swie 的?

对的,这个 signIn 对应的就是以太坊 rpc 的 eth_signTypedData_v4,功能上对应 siwe。这么看下来可能默认提供两种登录模式更好一些:原始的 signMessage 方式(适配几乎所有链)、sign-in-with-somechain 高级模式。

@jeasonstudio jeasonstudio changed the title provider 支持 signMessage 签名、wagmi 添加连接钱包后登陆示例 feat(web3): supports signMessage, add login example after connecting Mar 26, 2024
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

Successfully merging this pull request may close these issues.

None yet

4 participants