coming-chat / go-aptos-sdk 和 martian wallet 文本签名验证失败

hub500
发布于 阅读 580

martian wallet 执行的代码,在chrome控制台执行的

https://docs.martianwallet.xyz/docs/methods/sign-message

window.martian.signMessage("This is a sample message").then(function(a) { console.log(a);console.log(a['signature']) });

结果如下

{
    "address": false,
    "application": false,
    "chainId": false,
    "fullMessage": "APTOS",
    "prefix": "APTOS",
    "signature": "0x7294130c1f97c9a9036d68d4658029b896bf530a1fe91765e5a062f00e7f6d338a6fddee2854c0c1cf2fa9cd4dbdf0005e7bf858945128616ed5119e863f4200"
}

复制以上内容到golang中执行测试代码

https://github.com/coming-chat/go-aptos-sdk/blob/main/aptosaccount/account.go

package main

import (
	"fmt"

	"github.com/coming-chat/go-aptos/aptosaccount"
)

func main() {
	publicKey := []byte("0xdc2fb40d145d550e029dbc7f8c5b381625e1f936068051973472aa35affe9cca")
	message := []byte("This is a sample message")
	signature := []byte("0x7294130c1f97c9a9036d68d4658029b896bf530a1fe91765e5a062f00e7f6d338a6fddee2854c0c1cf2fa9cd4dbdf0005e7bf858945128616ed5119e863f4200")
	ok := aptosaccount.Verify(publicKey, message, signature)
	fmt.Println(ok) // false
}

go run main.go 的结果是false,期望得到的是 true的结果

是哪里错了的原因?求助

钱包信息

地址 0x4823b0cc094f84e0a4a2580d4421ce04a091cb74a935071b5f3c523a2d29c5e8

公钥 0xdc2fb40d145d550e029dbc7f8c5b381625e1f936068051973472aa35affe9cca

私钥 0x9853120980561732c39df0e84b0d37b6f23fc30ef13995c30c4e0a6f6a3085d4

1条评论
hub500
hub500
golang代码的问题 ``` package main import ( "encoding/hex" "fmt" "github.com/coming-chat/go-aptos/aptosaccount" ) func main() { publicKey, _ := hex.DecodeString("dc2fb40d145d550e029dbc7f8c5b381625e1f936068051973472aa35affe9cca") message := []byte("APTOS\nmessage: This is a sample message\nnonce: 12345") signature, _ := hex.DecodeString("7567acb2919b55b9a1b2aa385d9b6a49154217ee9f3f9f691053f58447e458fdc710fa9d4a5b49e57378e75d78777c016a7e7360bcc42d91a93c6ae9535fec0d") ok := aptosaccount.Verify(publicKey, message, signature) fmt.Println(ok) // true } ``` 前端返回的数据要转化 hex.DecodeString 和 去掉前缀 0x 问题就解决了
点赞 3
评论