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 95a7923 commit 41f03cd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 42 deletions.
12 changes: 7 additions & 5 deletions intents/intent.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions intents/intent.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct IntentDataSignTypedData
- network: string
- wallet: string
- typedData: any
+ go.field.type = *ethcoder.TypedData

struct IntentDataFeeOptions
- network: string
Expand Down
60 changes: 29 additions & 31 deletions intents/intent_data_sign_712_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,13 @@ package intents

import (
"bytes"
"encoding/json"
"fmt"
"math/big"

"github.com/0xsequence/ethkit/ethcoder"
"github.com/0xsequence/ethkit/go-ethereum/common"
"github.com/0xsequence/go-sequence"
)

func (p *IntentDataSignTypedData) UnmarshalJSON(data []byte) error {
type Raw struct {
Network string `json:"network"`
Wallet string `json:"wallet"`
TypedData json.RawMessage `json:"typedData"`
}

dec := json.NewDecoder(bytes.NewReader(data))
var raw Raw
if err := dec.Decode(&raw); err != nil {
return err
}

typedData, err := ethcoder.TypedDataFromJSON(string(raw.TypedData))
if err != nil {
return err
}

p.Network = raw.Network
p.Wallet = raw.Wallet
p.TypedData = typedData
return nil
}

func (p *IntentDataSignTypedData) chainID() (*big.Int, error) {
n, ok := sequence.ParseHexOrDec(p.Network)
if !ok {
Expand All @@ -44,12 +18,12 @@ func (p *IntentDataSignTypedData) chainID() (*big.Int, error) {
}

func (p *IntentDataSignTypedData) message() ([]byte, error) {
typedData, ok := p.TypedData.(*ethcoder.TypedData)
if !ok {
return nil, fmt.Errorf("typedData field is not a valid typed data object")
}
// typedData, ok := p.TypedData.(*ethcoder.TypedData)
// if !ok {
// return nil, fmt.Errorf("typedData field is not a valid typed data object")
// }

_, encodedMessage, err := typedData.Encode()
_, encodedMessage, err := p.TypedData.Encode()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -81,3 +55,27 @@ func (p *IntentDataSignTypedData) IsValidInterpretation(subdigest common.Hash) b

return bytes.Equal(selfSubDigest, subdigest[:])
}

// func (p *IntentDataSignTypedData) UnmarshalJSON(data []byte) error {
// type Raw struct {
// Network string `json:"network"`
// Wallet string `json:"wallet"`
// TypedData json.RawMessage `json:"typedData"`
// }

// dec := json.NewDecoder(bytes.NewReader(data))
// var raw Raw
// if err := dec.Decode(&raw); err != nil {
// return err
// }

// typedData, err := ethcoder.TypedDataFromJSON(string(raw.TypedData))
// if err != nil {
// return err
// }

// p.Network = raw.Network
// p.Wallet = raw.Wallet
// p.TypedData = typedData
// return nil
// }
7 changes: 1 addition & 6 deletions intents/intent_data_sign_712_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"
"time"

"github.com/0xsequence/ethkit/ethcoder"
"github.com/0xsequence/ethkit/ethwallet"
"github.com/0xsequence/ethkit/go-ethereum/common"
"github.com/0xsequence/go-sequence"
Expand Down Expand Up @@ -79,15 +78,11 @@ func TestRecoverTypedDataIntent(t *testing.T) {
intentTyped, err := NewIntentTypedFromIntent[IntentDataSignTypedData](intent)
require.NoError(t, err)

typedData, ok := intentTyped.Data.TypedData.(*ethcoder.TypedData)
require.True(t, ok)
require.NotNil(t, typedData)

signers := intent.Signers()
require.Equal(t, 1, len(signers))
require.Equal(t, "0x"+common.Bytes2Hex(append([]byte{0x00}, wallet.Address().Bytes()...)), signers[0])

messageDigest, err := typedData.EncodeDigest()
messageDigest, err := intentTyped.Data.TypedData.EncodeDigest()
require.NoError(t, err)
require.NotNil(t, messageDigest)

Expand Down

0 comments on commit 41f03cd

Please sign in to comment.