Skip to content

Commit

Permalink
fix: typed message with wrong domain name (#417)
Browse files Browse the repository at this point in the history
Co-authored-by: Carmen Irene Cabrera Rodríguez <49727740+cicr99@users.noreply.github.com>
  • Loading branch information
fico308 and cicr99 authored Oct 20, 2023
1 parent 364beae commit 13df8a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions typed/typed.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func NewTypedData(types map[string]TypeDef, pType string, dom Domain) (td TypedD
return td, nil
}

// (ref: https://github.com/0xs34n/starknet.js/blob/767021a203ac0b9cdb282eb6d63b33bfd7614858/src/utils/typedData/index.ts#L166)
// (ref: https://github.com/starknet-io/starknet.js/blob/d7bfc37ede85448e0a55ee4efe65200ff2c45f91/src/utils/typedData.ts#L249)
func (td TypedData) GetMessageHash(account *big.Int, msg TypedMessage, sc curve.StarkCurve) (hash *big.Int, err error) {
elements := []*big.Int{utils.UTF8StrToBig("Starknet Message")}
elements := []*big.Int{utils.UTF8StrToBig("StarkNet Message")}

domEnc, err := td.GetTypedMessageHash("StarknetDomain", td.Domain, sc)
domEnc, err := td.GetTypedMessageHash("StarkNetDomain", td.Domain, sc)
if err != nil {
return hash, fmt.Errorf("could not hash domain: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions typed/typed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func (mail Mail) FmtDefinitionEncoding(field string) (fmtEnc []*big.Int) {
func MockTypedData() (ttd TypedData) {
exampleTypes := make(map[string]TypeDef)
domDefs := []Definition{{"name", "felt"}, {"version", "felt"}, {"chainId", "felt"}}
exampleTypes["StarknetDomain"] = TypeDef{Definitions: domDefs}
exampleTypes["StarkNetDomain"] = TypeDef{Definitions: domDefs}
mailDefs := []Definition{{"from", "Person"}, {"to", "Person"}, {"contents", "felt"}}
exampleTypes["Mail"] = TypeDef{Definitions: mailDefs}
persDefs := []Definition{{"name", "felt"}, {"wallet", "felt"}}
exampleTypes["Person"] = TypeDef{Definitions: persDefs}

dm := Domain{
Name: "Starknet Mail",
Name: "StarkNet Mail",
Version: "1",
ChainId: "1",
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func BenchmarkGetMessageHash(b *testing.B) {
func TestGeneral_GetDomainHash(t *testing.T) {
ttd := MockTypedData()

hash, err := ttd.GetTypedMessageHash("StarknetDomain", ttd.Domain, curve.Curve)
hash, err := ttd.GetTypedMessageHash("StarkNetDomain", ttd.Domain, curve.Curve)
if err != nil {
t.Errorf("Could not hash message: %v\n", err)
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestGeneral_GetTypedMessageHash(t *testing.T) {
func TestGeneral_GetTypeHash(t *testing.T) {
tdd := MockTypedData()

hash, err := tdd.GetTypeHash("StarknetDomain")
hash, err := tdd.GetTypeHash("StarkNetDomain")
if err != nil {
t.Errorf("error enccoding type %v\n", err)
}
Expand All @@ -152,7 +152,7 @@ func TestGeneral_GetTypeHash(t *testing.T) {
t.Errorf("type hash: %v does not match expected %v\n", utils.BigToHex(hash), exp)
}

enc := tdd.Types["StarknetDomain"]
enc := tdd.Types["StarkNetDomain"]
if utils.BigToHex(enc.Encoding) != exp {
t.Errorf("type hash: %v does not match expected %v\n", utils.BigToHex(hash), exp)
}
Expand Down

0 comments on commit 13df8a0

Please sign in to comment.