简体   繁体   English

通过 MetaMask 连接验证用户是否是 NFT 的所有者? 确保连接用户的公共 eth 地址与 NFT 的相同?

[英]Verify user is owner of an NFT via MetaMask connection? Make sure connected users public eth address is the same as of the NFT?

I need to verify on my own domain/server the user which has connected his MetaMask wallet is the owner of a specific NFT in order to allow him special functions?我需要在我自己的域/服务器上验证连接了他的 MetaMask 钱包的用户是特定 NFT 的所有者,以便允许他使用特殊功能? Basically, I want to give the user access to an area that only the owner of this NFS would have.基本上,我想让用户访问只有这个 NFS 的所有者才能拥有的区域。

My original NFT is sold in opensea but I can't use the opensea hidden-area option to just give the user a hidden password since the next owner (after reselling) and the old owner would have the same password and old owners could still access like this.我原来的 NFT 在 opensea 出售,但我不能使用 opensea 隐藏区域选项给用户一个隐藏密码,因为下一个所有者(转售后)和旧所有者将拥有相同的密码并且旧所有者仍然可以访问像这样。 But I need that only the current owner has access.但我需要只有当前所有者才能访问。

My user/visiter can already connect with MetaMask at my own domain and I get the public ETH address of the active account but since this is only javascript and my backend is PHP I can't just post the MetaMask info to my PHP backend since this would be easy to trick/hack.我的用户/访问者已经可以在我自己的域中与 MetaMask 连接,并且我获得了活动帐户的公共 ETH 地址,但由于这只是 javascript 而我的后端是 PHP,我不能只将 MetaMask 信息发布到我的 PHP 后端,因为这很容易被欺骗/破解。

How can I make sure the current connected MetaMask Account is the same as the NFT owner (which I know) and allow to access a URL only for this user?如何确保当前连接的 MetaMask 帐户与 NFT 所有者(我知道)相同,并只允许该用户访问 URL?

My current state is that the user connects his MetaMask and I use opensea API to check who is currently the owner of the NFT.我目前的状态是用户连接了他的 MetaMask,我使用 opensea API 检查当前谁是 NFT 的所有者。 I can compare both eth addresses but the flaw in this is obviously that I use ajax to send the MetaMask public address to my backend which is only for testing since this is of course zero save!我可以比较两个 eth 地址,但其中的缺陷显然是我使用 ajax 将 MetaMask 公共地址发送到我的后端,这仅用于测试,因为这当然是零保存!

Thank you in advance for any idea, help, tip I can get.提前感谢您的任何想法,帮助,我能得到的小费。

PS: My backend is PHP PS:我的后端是 PHP

After hours and days of researching, I found a solution that works for me.经过数小时和数天的研究,我找到了一个适合我的解决方案。

Here are the needed steps.这是所需的步骤。

  1. Use the MetaMask API to let the user connect with your site.使用 MetaMask API 让用户连接到您的站点。 This is pretty easy and good explained in the MetaMask API.这在 MetaMask API 中非常简单且很好地解释了。
  2. Once you want to verify the MetaMask owner is the legit owner of an NFT you need first query OpenSea (or another place) the current owner of the NFT.一旦您想验证 MetaMask 所有者是 NFT 的合法所有者,您需要首先查询 OpenSea(或其他地方)NFT 的当前所有者。 In my case, I use the OpenSea API for my specific NFTs.就我而言,我将 OpenSea API 用于我的特定 NFT。 Once you got the owner you are ready to verify.获得所有者后,您就可以进行验证了。
  3. On your site you need to ask the user to sign a custom message with MetaMask.在您的网站上,您需要要求用户使用 MetaMask 签署自定义消息。 There are different options to do that.有不同的选择可以做到这一点。 More about this here: MetaMask Signing .更多关于这里的信息: MetaMask 签名 I send for example a short text message with a unique code that I first created in my PHP Backend.例如,我发送一条简短的文本消息,其中包含我首先在我的 PHP 后端创建的唯一代码。 Doing that I also save the code and custom message into my MySQL.这样做我还将代码和自定义消息保存到我的 MySQL 中。
  4. Once the user has signed you get the signing code which you can send back to your PHP backend via ajax etc. without a problem.用户签名后,您将获得签名代码,您可以通过 ajax 等将其发送回您的 PHP 后端,而不会出现问题。 Only the owner of the Account which you requested in the signing code is able to sign with the correct account.只有您在签名代码中请求的帐户所有者才能使用正确的帐户进行签名。
  5. Once you got the signing code in your PHP Backend you can use Fast Elliptic Curve Cryptography in PHP and php-ecrecover to check the code against the unique code you created before and the message the user signed.在 PHP 后端获得签名代码后,您可以使用 PHP 中的快速椭圆曲线密码术和php-ecrecover来对照您之前创建的唯一代码和用户签名的消息检查代码。 As a response, you get the Signer Account ETH Address and you are ready to compare.作为响应,您将获得签名者帐户的 ETH 地址并准备进行比较。 If the Signers ETH Address is the same as the NFT owner you are ready to go and you can consider the signer the owner of the NFT.如果签名者 ETH 地址与 NFT 所有者相同,您就可以开始了,您可以将签名者视为 NFT 的所有者。

I believe this is safe to use but I am not an expert on that.我相信这可以安全使用,但我不是这方面的专家。 In my case, this only authorize an NFT owner for a certain closed area in my community page and there are not really high risks involved but maybe somebody raises some security thoughts on that.就我而言,这仅授权 NFT 所有者对我的社区页面中的某个封闭区域进行授权,并没有涉及到真正的高风险,但也许有人对此提出了一些安全想法。 However, I found that other NFT pages and even Opensea work similarly.但是,我发现其他 NFT 页面甚至 Opensea 的工作方式类似。

I hope this points someone in the right direction, I lost quite some time figuring this out because most solutions are Node.js etc. but not with PHP backends.我希望这为某人指明了正确的方向,因为大多数解决方案都是 Node.js 等,但不是 PHP 后端,所以我花了很多时间弄清楚这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过网络连接以编程方式验证Windows用户 - How to programatically verify Windows User via a network connection 如何允许用户将其个人资料设为私有或公开? - How to allow users to make their profiles private or public? 在 PHP 中通过电子邮件验证用户 - verify a user via e-mail in PHP 如何结束用户会话并确保用户已注销? - How to end the user session and make sure that the user is logged out? 如何唯一标识具有相同外部IP地址的用户? - How to uniquely identify users with the same external IP address? 如何确保只有在用户登录后才能访问EJB服务? - How to make sure that an EJB service is only accesible if an user is logged in? 如何确保用户在aspnet core 2.0中完成他们的个人资料? - How to make sure a user completes their profile in aspnet core 2.0? 如何使用Authlogic确保用户属于特定模型? - How can I make sure Users belong to a particular model using Authlogic? 如何在SignedIn中使用户保持连接并在ReactJS上进行用户注销 - How can I make user stay connected once SignedIn and make user Signout on ReactJS 允许使用电子邮件地址登录,同时允许多个用户使用相同的电子邮 - Allowing login with email address while allowing multiple users with same email address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM