Skip to content

Commit

Permalink
fix Signature bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-yl-sh committed Jul 19, 2024
1 parent 0b922dd commit 58b8116
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
23 changes: 17 additions & 6 deletions internal/common_util/crypto_test.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions plugins/passkey_relay_party/seedworks/tx_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ type TxSignatureResult struct {
TxData string `json:"txdata"`
Sign string `json:"sign"`
PrivateKey string `json:"privateKey"`
Address string `json:"address"`
}
4 changes: 3 additions & 1 deletion plugins/passkey_relay_party/seedworks/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions plugins/passkey_relay_party/tx_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 58b8116

Please sign in to comment.