From 9364b324d3f77ec3e0155df59064ea4fdcc8c232 Mon Sep 17 00:00:00 2001 From: Paul Berg Date: Fri, 9 Nov 2018 21:00:07 +0200 Subject: [PATCH] Added alphabetical sorting to type dependencies --- signer/core/signed_data.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/signer/core/signed_data.go b/signer/core/signed_data.go index 95454acfdc..9566c80569 100644 --- a/signer/core/signed_data.go +++ b/signer/core/signed_data.go @@ -24,6 +24,7 @@ import ( "math/big" "mime" "reflect" + "sort" "strconv" "strings" "unicode" @@ -329,13 +330,9 @@ func (typedData *TypedData) Dependencies(primaryType string, found []string) []s func (typedData *TypedData) EncodeType(primaryType string) hexutil.Bytes { // Get dependencies primary first, then alphabetical deps := typedData.Dependencies(primaryType, []string{}) - for i, dep := range deps { - if dep == primaryType { - deps = append(deps[:i], deps[i+1:]...) - break - } - } - deps = append([]string{primaryType}, deps...) + slicedDeps := deps[1:] + sort.Strings(slicedDeps) + deps = append([]string{primaryType}, slicedDeps...) // Format as a string with fields var buffer bytes.Buffer