Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Dec 13, 2024
1 parent c2c6952 commit 933b997
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions ethcoder/typed_data_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ethcoder_test

import (
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -66,9 +65,8 @@ func TestTypedDataCase1(t *testing.T) {
VerifyingContract: &verifyingContract,
},
Message: map[string]interface{}{
"name": "Bob",
// "wallet": common.HexToAddress("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"), // NOTE: passing common.Address object works too
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
"name": "Bob",
"wallet": common.HexToAddress("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"),
},
}

Expand All @@ -80,25 +78,23 @@ func TestTypedDataCase1(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "0x0a94cf6625e5860fc4f330d75bcd0c3a4737957d2321d1a024540ab5320fe903", ethcoder.HexEncode(digest))

fmt.Println("===> digest", ethcoder.HexEncode(digest))
// fmt.Println("===> digest", ethcoder.HexEncode(digest))

// lets sign it..
wallet, err := ethwallet.NewWalletFromMnemonic("dose weasel clever culture letter volume endorse used harvest ripple circle install")
assert.NoError(t, err)

// TODO: this is wrong.. we need wallet.SignTypedData(digest).. or wallet.SignData(digest) wherre digest is fully encoded with prefix, etc.

ethSigedTypedData, err := wallet.SignMessage([]byte(digest))
ethSigedTypedData, encodedTypeData, err := wallet.SignTypedData(typedData)
ethSigedTypedDataHex := ethcoder.HexEncode(ethSigedTypedData)
assert.NoError(t, err)

assert.Equal(t,
"0x842ed2d5c3bf97c4977ee84e600fec7d0f9c5e21d4090b5035a3ea650ec6127d18053e4aafb631de26eb3fd5d61e4a6f2d6a106ee8e3d8d5cb0c4571d06798741b",
"0x07cc7c723b24733e11494438927012ec9b086e8edcb06022231710988ff7e54c45b0bb8911b1e06d322eb24b919f2a479e3062fee75ce57c1f7d7fc16c371fa81b",
ethSigedTypedDataHex,
)

// recover / validate signature
valid, err := ethwallet.ValidateEthereumSignature(wallet.Address().Hex(), digest, ethSigedTypedDataHex)
valid, err := ethwallet.ValidateEthereumSignature(wallet.Address().Hex(), encodedTypeData, ethSigedTypedDataHex)
assert.NoError(t, err)
assert.True(t, valid)
}
Expand Down Expand Up @@ -128,9 +124,8 @@ func TestTypedDataCase2(t *testing.T) {
VerifyingContract: &verifyingContract,
},
Message: map[string]interface{}{
"name": "Bob",
// "wallet": common.HexToAddress("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"), // NOTE: passing common.Address object works too
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
"name": "Bob",
"wallet": common.HexToAddress("0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"),
"count": uint8(4),
},
}
Expand All @@ -144,7 +139,6 @@ func TestTypedDataCase2(t *testing.T) {
assert.Equal(t, "0x2218fda59750be7bb9e5dfb2b49e4ec000dc2542862c5826f1fe980d6d727e95", ethcoder.HexEncode(digest))

// fmt.Println("===> digest", HexEncode(digest))

}

func TestTypedDataFromJSON(t *testing.T) {
Expand Down

0 comments on commit 933b997

Please sign in to comment.