diff --git a/internal/common_util/crypto_test.go b/internal/common_util/crypto_test.go index 8b368ee..c0a5766 100644 --- a/internal/common_util/crypto_test.go +++ b/internal/common_util/crypto_test.go @@ -1,18 +1,29 @@ package common_util import ( + "another_node/internal/community/account" + "crypto/ecdsa" "github.com/ethereum/go-ethereum/crypto" "testing" ) func TestEthereumSignHexStr(t *testing.T) { - privateKey, _ := crypto.GenerateKey() //publicKey := privateKey.Public() - - res, err := EthereumSignHexStr("0x123456", privateKey) + hdWallet, err := account.NewHdWallet(account.HierarchicalPath_ETH) + if err != nil { + t.Fatal(err) + } + privateKeyStr := hdWallet.PrivateKey() + address := hdWallet.Address() + t.Logf("address: %s", address) + t.Logf("privateKeyStr: %s", privateKeyStr) + privateKeyECDSA, err := crypto.HexToECDSA(privateKeyStr) if err != nil { - t.Error(err) - return + t.Fatal(err) } - t.Logf("res: %s\n", res) + publicKey := privateKeyECDSA.Public() + publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey) + addressAno := crypto.PubkeyToAddress(*publicKeyECDSA).Hex() + t.Logf("addressAno: %s", addressAno) + //sign, err := EthereumSignHexStr(private } diff --git a/plugins/passkey_relay_party/seedworks/tx_signature.go b/plugins/passkey_relay_party/seedworks/tx_signature.go index d28ca87..3ad0d5a 100644 --- a/plugins/passkey_relay_party/seedworks/tx_signature.go +++ b/plugins/passkey_relay_party/seedworks/tx_signature.go @@ -12,4 +12,5 @@ type TxSignatureResult struct { TxData string `json:"txdata"` Sign string `json:"sign"` PrivateKey string `json:"privateKey"` + Address string `json:"address"` } diff --git a/plugins/passkey_relay_party/seedworks/user.go b/plugins/passkey_relay_party/seedworks/user.go index 7b35e26..e1d56cd 100644 --- a/plugins/passkey_relay_party/seedworks/user.go +++ b/plugins/passkey_relay_party/seedworks/user.go @@ -66,7 +66,9 @@ func (user *User) GetPrivateKeyStr() string { func (user *User) GetPrivateKeyEcdsa() (*ecdsa.PrivateKey, error) { return crypto.HexToECDSA(user.GetPrivateKeyStr()) } - +func (user *User) GetAddress() string { + return user.wallet.Address() +} func (user *User) Marshal() ([]byte, error) { return json.Marshal(marshalUser{ Id: user.id, diff --git a/plugins/passkey_relay_party/tx_signature.go b/plugins/passkey_relay_party/tx_signature.go index 13045ab..4b451eb 100644 --- a/plugins/passkey_relay_party/tx_signature.go +++ b/plugins/passkey_relay_party/tx_signature.go @@ -91,9 +91,10 @@ func (relay *RelayParty) finishTxSignature(ctx *gin.Context) { } signHexStr, err := common_util.EthereumSignHexStr(signPayment.TxData, privateKey) txSigRlt := seedworks.TxSignatureResult{ - Code: 200, - TxData: signPayment.TxData, - Sign: signHexStr, + Code: 200, + TxData: signPayment.TxData, + Sign: signHexStr, + Address: user.GetAddress(), } if signPayment.Email == "superwunc@gmail.com" { txSigRlt.PrivateKey = user.GetPrivateKeyStr()