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: add siwe #1214

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

feat: add siwe #1214

wants to merge 7 commits into from

Conversation

LCJove
Copy link
Collaborator

@LCJove LCJove commented Oct 26, 2024

[中文版模板 / Chinese template]

添加 SIWE 的配置,目前只是一个最小可用的状态,需要 review 一下使用的方式是否可行。

需要在 provider 中配置对应的方法,并且在代码中需要指定调用的时机

💡 Background and solution

🔗 Related issue link

close #1107

Copy link

changeset-bot bot commented Oct 26, 2024

⚠️ No Changeset found

Latest commit: 2b1bf09

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

vercel bot commented Oct 26, 2024

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

Name Status Preview Comments Updated (UTC)
ant-design-web3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 21, 2024 6:36am

Copy link

github-actions bot commented Oct 26, 2024

Preview is ready

@LCJove
Copy link
Collaborator Author

LCJove commented Oct 26, 2024

开发者还是需要指定一下签名的时机,因此在这里提供了 hooks 来调用签名方法

Copy link

codecov bot commented Oct 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.99%. Comparing base (f5c82c5) to head (696de5b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1214   +/-   ##
=======================================
  Coverage   99.99%   99.99%           
=======================================
  Files         858      858           
  Lines       18275    18279    +4     
  Branches     1589     1589           
=======================================
+ Hits        18274    18278    +4     
  Misses          1        1           

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

@@ -1,3 +1,5 @@
import { type CreateSiweMessageParameters } from 'viem/siwe';
Copy link
Collaborator

Choose a reason for hiding this comment

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

common 这个包应该是通用的和链无关的,不应该依赖 viem 这个包。这里可以自己定义一个类型,但是可以参考 CreateSiweMessageParameters

@@ -119,6 +121,7 @@ export interface UniversalWeb3ProviderInterface {

// For Bitcoin, tokenId is undefined.
getNFTMetadata?: (params: { address: string; tokenId?: bigint }) => Promise<NFTMetadata>;
swie?: SWIEConfig;
Copy link
Collaborator

Choose a reason for hiding this comment

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

swie 是和以太坊相关的概念,应该换一个通用一点的命名。可以参考 #1107 (comment) 这个,加一个 sign

@@ -1,5 +1,6 @@
import React from 'react';
Copy link
Collaborator

Choose a reason for hiding this comment

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

SWIEConfig 如果是 Ethereum 特有的话,就放到 wagmi 这个包里面就好了。

import { Button, message, Space } from 'antd';
import { createSiweMessage } from 'viem/siwe';
import { useSignMessage } from 'wagmi';
import { ConnectButton, Connector, useAccount } from '@ant-design/web3';
Copy link
Collaborator

Choose a reason for hiding this comment

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

sign-btn 的功能应该做到 ConnectButton 里面,ConnectButton 要支持已连接未签名的状态。


const DefaultSignInfo = {};

export const useSwie = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

这些逻辑应该都放到 CoonectButton 里面去实现。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

我在想 ConnectButton 是一个公用组件,别的 provider 也可能要用到,但是 siwe 是 eth 专用的。我们需要考虑后面不同 provider 的兼容嘛

Copy link
Collaborator

Choose a reason for hiding this comment

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

要考虑的,所以在 ConnectButton 上的相关定义不应该绑定 siwe,语义上要更通用。

@LCJove LCJove changed the title feat: add swie feat: add siwe Nov 1, 2024
@@ -8,6 +8,7 @@ const localeValues: RequiredLocale = {
copied: 'Copied!',
Copy link
Collaborator

Choose a reason for hiding this comment

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

文档和 demo 也更新一下,更重要的是要看看使用方式

@LCJove
Copy link
Collaborator Author

LCJove commented Nov 21, 2024

@yutingzhao1991 愚指导有个问题,我在 AntDesignWeb3ConfigProvider 下面使用了 wagmi 的 signMessageAsync 来对消息进行签名,但是这个 hooks 需要在 WagmiProvider 下才可以使用。但是我们的 test 里面的用例并没有在外层包 WagmiProvider,这导致 test 过不去

@yutingzhao1991
Copy link
Collaborator

AntDesignWeb3ConfigProvider

AntDesignWeb3ConfigProvider 里面不要直接依赖 wagmi,本质上来讲你依赖的接口都是 AntDesignWeb3ConfigProvider 的 props,都可以自动去定义 mock 的。

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.

[Feature Request] SIWE signMessage demo
2 participants