diff --git a/signer/core/apitypes/types.go b/signer/core/apitypes/types.go index 9034e7e9ca..bf7518f6ff 100644 --- a/signer/core/apitypes/types.go +++ b/signer/core/apitypes/types.go @@ -826,10 +826,10 @@ func formatPrimitiveValue(encType string, encValue interface{}) (string, error) return fmt.Sprintf("%t", boolValue), nil } case "bytes", "string": - return fmt.Sprintf("%s", encValue), nil + return stringifyPrimitive(encType, encValue) } if strings.HasPrefix(encType, "bytes") { - return fmt.Sprintf("%s", encValue), nil + return stringifyPrimitive(encType, encValue) } if strings.HasPrefix(encType, "uint") || strings.HasPrefix(encType, "int") { if b, err := parseInteger(encType, encValue); err != nil { @@ -841,6 +841,21 @@ func formatPrimitiveValue(encType string, encValue interface{}) (string, error) return "", fmt.Errorf("unhandled type %v", encType) } +func stringifyPrimitive(encType string, encValue interface{}) (string, error) { + switch v := encValue.(type) { + case string: + return v, nil + case []byte: + return string(v), nil + case hexutil.Bytes: + return v.String(), nil + case fmt.Stringer: + return v.String(), nil + default: + return "", fmt.Errorf("could not format value %v as %s", encValue, encType) + } +} + // validate checks if the types object is conformant to the specs func (t Types) validate() error { for typeKey, typeArr := range t {