验证 C++ 中的 Phantom 签名服务器
我正在构建一个使用 Phantom 钱包登录的在线游戏。我的服务器是用 C++ 编写的,我想在那里进行签名验证。客户端和服务器之间的连接是发送 JSON 的套接字连接。
对于客户端,我浏览了 Phantom 文档。我检索了字符串形式的公钥和 uint8array 形式的签名,示例值:
- 公钥:“26qv4GCcx98RihuK3c4T6ozB3J7L6VwCuFVc7Ta2A3Uo”
- 签名: [141,47,223,197,8,57,72,178,113,62,233,50,47,234,39,143,169,82,59,190,214,185,25,227,94,68,209,118,231,120,66,224,24 1,241,168,128,56,63,80,41,219,202,17,191,214,185,91,178,55 ,126,194,152,157,173,248,212,89,126,128,157,168,119,244,6]
我发现Solana使用了ED25519签名,并且我还找到了实现该算法的这个网站。在尝试多个不同的条目对消息进行签名后,我意识到签名始终包含可以显示的字符。因此我的第一个问题是,为什么我的签名中有无效字符(无法显示)?具有上述签名的示例:“�/���9H�q>�2/�'��R;�ֹ��^D�v�xB�����8?P)����ֹ[ �7~�����Y~���w��"。
关于服务器端,我找到了一些库来验证签名:
但经过多次尝试,我找不到任何成功验证方法的有效集合(消息、公钥和签名) int crypto_sign_open( byte *m,word64 *mlen,const byte *sm,word64 n,const byte *pk)
因此,我的大问题是,如何验证这个签名?我没有找到验证 Phantom 签名的正确示例,尤其是在 Javascript 之外的其他语言中。
预先感谢您的帮助!
I'm building a online game with a Phantom wallet login. My server is written in C++ and I want to make the signature verification there. The connection between client and server is a socket connection sending JSON.
For the client side, I went through the Phantom documentation. I retrieved the public key as a string and the signature as a uint8array, example values:
- public key: "26qv4GCcx98RihuK3c4T6ozB3J7L6VwCuFVc7Ta2A3Uo"
- signature: [141,47,223,197,8,57,72,178,113,62,233,50,47,234,39,143,169,82,59,190,214,185,25,227,94,68,209,118,231,120,66,224,241,241,168,128,56,63,80,41,219,202,17,191,214,185,91,178,55,126,194,152,157,173,248,212,89,126,128,157,168,119,244,6]
I found that Solana uses ED25519 signature, and I also found this website that implements the algorithm. And after trying multiple different entries to sign a message, I realized that the signature always contains characters that can be displayed. Therefore my first question is, why are there invalid characters (unable to be displayed) in my signature ? Example with the above signature: "�/���9H�q>�2/�'��R;�ֹ��^D�v�xB�����8?P)����ֹ[�7~�����Y~���w��".
Concerning the server side, I found some libraries to verify the signature:
But after multiple attempts, I could not find any valid set (message, public key and signature) that succeed the verification method int crypto_sign_open(byte *m,word64 *mlen,const byte *sm,word64 n,const byte *pk)
Therefore, my big question is, how do I verify this signature ? I did not find a proper example verifying a Phantom signature, especially in another language than Javascript.
Thank you in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于成功验证了这个签名。我的第一个错误是,对于 ED25519 签名,公钥必须是 32 字节。然而,Phantom 公钥包含 44 个字节。我发现一篇文章其中的答案之一表示 44 字节的公钥需要以 58 为基数进行解码,从而得到 32 字节的密钥。
其次,在服务器中,验证签名的方法不正确。事实上,正确的一个是:int crypto_sign_verify_detached(const unsigned char *sig, const unsigned char *m, unsigned long long mlen, const unsigned char *pk)。该方法在此处进行了描述。
通过这两个更改,验证工作完美!
I finally succeed verifying this signature. My first mistake was that, for ED25519 signature, the public key has to be 32 bytes. However, the Phantom public key contains 44 bytes. I found a post for which one of the answers says that the 44 bytes public key needs to be decoded in base 58 that gives us a 32 bytes key.
Secondly, in the server, the method to use to verify the signature was not the right one. Indeed the right one is:
int crypto_sign_verify_detached(const unsigned char *sig, const unsigned char *m, unsigned long long mlen, const unsigned char *pk)
. The method is described here.With these two changes, the verification works perfectly!