diff --git a/pkg/eip712/typed_data_v4.go b/pkg/eip712/typed_data_v4.go index 02fac454..cc6b642e 100644 --- a/pkg/eip712/typed_data_v4.go +++ b/pkg/eip712/typed_data_v4.go @@ -1,4 +1,4 @@ -// Copyright © 2023 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -223,6 +223,11 @@ func encodeData(ctx context.Context, typeName string, v interface{}, allTypes Ty return encoded, nil } +// HashStruct allows hashing of an individual structure, without the EIP-712 domain +func HashStruct(ctx context.Context, typeName string, v interface{}, allTypes TypeSet) (result ethtypes.HexBytes0xPrefix, err error) { + return hashStruct(ctx, typeName, v, allTypes, "") +} + func hashStruct(ctx context.Context, typeName string, v interface{}, allTypes TypeSet, breadcrumbs string) (result ethtypes.HexBytes0xPrefix, err error) { encoded, err := encodeData(ctx, typeName, v, allTypes, breadcrumbs) if err != nil { diff --git a/pkg/eip712/typed_data_v4_test.go b/pkg/eip712/typed_data_v4_test.go index e3e7381c..645bac4a 100644 --- a/pkg/eip712/typed_data_v4_test.go +++ b/pkg/eip712/typed_data_v4_test.go @@ -82,6 +82,10 @@ func TestMessage_ExampleFromEIP712Spec(t *testing.T) { ed, err := EncodeTypedDataV4(ctx, &p) assert.NoError(t, err) assert.Equal(t, "0xde26f53b35dd5ffdc13f8297e5cc7bbcb1a04bf33803bd2bf4a45eb251360cb8", ed.String()) + + hs, err := HashStruct(ctx, p.PrimaryType, p.Message, p.Types) + assert.NoError(t, err) + assert.Equal(t, "0xc52c0ee5d84264471806290a3f2c4cecfc5490626bf912d01f240d7a274b371e", hs.String()) } func TestMessage_EmptyMessage(t *testing.T) {