diff --git a/cmd/clef/audit.log b/cmd/clef/audit.log new file mode 100644 index 0000000000..c5b542d9b0 --- /dev/null +++ b/cmd/clef/audit.log @@ -0,0 +1 @@ +t=2018-10-13T05:03:16-0700 lvl=info msg=Configured api=signer audit log=audit.log diff --git a/interfaces.go b/interfaces.go index 03ac99e3e1..c6850cdbe0 100644 --- a/interfaces.go +++ b/interfaces.go @@ -208,9 +208,4 @@ type GasEstimator interface { // pending state. type PendingStateEventer interface { SubscribePendingTransactions(ctx context.Context, ch chan<- *types.Transaction) (Subscription, error) -} - -// TypedData is the standard for EIP-712 signed data. -type TypedData struct { - Hash *common.Hash `json:"hash"` -} +} \ No newline at end of file diff --git a/signer/core/api.go b/signer/core/api.go index 603fcc2e91..3453dbacc8 100644 --- a/signer/core/api.go +++ b/signer/core/api.go @@ -21,7 +21,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto/sha3" "io/ioutil" @@ -668,39 +667,6 @@ func SignDataWithValidator(data []byte) ([]byte, string) { return crypto.Keccak256([]byte(msg)), msg } -// TypedData represents a request to create a new filter. -type TypedData ethereum.TypedData - -// SignStructuredData signs the given message according to EIP712. -// -// https://github.com/ethereum/EIPs/issues/712 -// -// If the format "\x19\x46" ‖ domainSeparator ‖ hashStruct(message)` is not respected, -// an error is returned -func (api *SignerAPI) SignStructuredData(ctx context.Context, data TypedData) (hexutil.Bytes, error) { - fmt.Println("data", data) - fmt.Println("data.Hash", data.Hash) - return common.Hex2Bytes("0xdeadbeef"), nil -} - -// UnmarshalJSON sets *args fields with given data. -func (args *TypedData) UnmarshalJSON(data []byte) error { - type input struct { - Hash *common.Hash `json:"hash"` - } - - var raw input - if err := json.Unmarshal(data, &raw); err != nil { - return err - } - - if raw.Hash != nil { - args.Hash = raw.Hash - } - - return nil -} - // SignDataPlain is a helper function that calculates a hash for the given message that can be // safely used to calculate a signature from. // diff --git a/signer/core/apiv2.go b/signer/core/apiv2.go new file mode 100644 index 0000000000..4f3e737300 --- /dev/null +++ b/signer/core/apiv2.go @@ -0,0 +1,56 @@ +package core + +import ( + "context" + "fmt" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "math/big" +) + +type TypedData struct { + Types map[string] interface{} `json:"types"` + PrimaryType string `json:"primaryType"` + Domain EIP712Domain `json:"domain"` + Message map[string] interface{} `json:"message"` +} + +type EIP712Domain struct { + Name string `json:"name"` + Version string `json:"version"` + ChainId big.Int `json:"chainId"` + VerifyingContract common.Address `json:"verifyingContract"` + Salt hexutil.Bytes `json:"salt"` +} + +// Typed data according to EIP712 +// +// If the format "\x19\x46" ‖ domainSeparator ‖ hashStruct(message)` is not respected, +// an error is returned +func (api *SignerAPI) SignStructuredData(ctx context.Context, data TypedData) (hexutil.Bytes, error) { + fmt.Println("data", data) + fmt.Println("data.PrimaryType", data.PrimaryType) + return common.Hex2Bytes("0xdeadbeef"), nil +} + +// TypedData represents a request to create a new filter. +// Same as ethereum.FilterQuery but with UnmarshalJSON() method. +//type TypedData ethereum.TypedData + +// UnmarshalJSON sets *args fields with given data. +//func (args *TypedData) UnmarshalJSON(data []byte) error { +// type input struct { +// Hash *common.Hash `json:"hash"` +// } +// +// var raw input +// if err := json.Unmarshal(data, &raw); err != nil { +// return err +// } +// +// if raw.Hash != nil { +// args.Hash = raw.Hash +// } +// +// return nil +//} \ No newline at end of file diff --git a/signer/core/apiv2.goz b/signer/core/apiv2.goz deleted file mode 100644 index 87716a8736..0000000000 --- a/signer/core/apiv2.goz +++ /dev/null @@ -1,57 +0,0 @@ -package core - -import ( - "context" - "encoding/json" - "fmt" - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" -) - -//type TypedData struct { - //Types map[string] interface{} `json:"types"` - //PrimaryType *big.Int `json:"primaryType"` - //Domain EIP712Domain `json:"domain"` - //Message map[string] interface{} `json:"message"` -//} - -//type EIP712Domain struct { -// Name string `json:"name"` -// Version string `json:"version"` -// ChainId big.Int `json:"chainId"` -// VerifyingContract common.Address `json:"verifyingContract"` -// Salt hexutil.Bytes `json:"salt"` -//} - -// TypedData represents a request to create a new filter. -// Same as ethereum.FilterQuery but with UnmarshalJSON() method. -type TypedData ethereum.TypedData - -// Typed data according to EIP712 -// -// If the format "\x19\x46" ‖ domainSeparator ‖ hashStruct(message)` is not respected, -// an error is returned -func (api *SignerAPI) SignStructuredData(ctx context.Context, data TypedData) (hexutil.Bytes, error) { - fmt.Println("data", data) - fmt.Println("data.Hash", data.Hash) - return common.Hex2Bytes("0xdeadbeef"), nil -} - -// UnmarshalJSON sets *args fields with given data. -func (args *TypedData) UnmarshalJSON(data []byte) error { - type input struct { - Hash *common.Hash `json:"hash"` - } - - var raw input - if err := json.Unmarshal(data, &raw); err != nil { - return err - } - - if raw.Hash != nil { - args.Hash = raw.Hash - } - - return nil -} \ No newline at end of file diff --git a/signer/core/auditlog.go b/signer/core/auditlog.go index 93b165568f..e80635ed02 100644 --- a/signer/core/auditlog.go +++ b/signer/core/auditlog.go @@ -73,7 +73,7 @@ func (l *AuditLogger) SignData(ctx context.Context, contentType string, addr com func (l *AuditLogger) SignStructuredData(ctx context.Context, data TypedData) (hexutil.Bytes, error) { l.log.Info("SignStructuredData", "type", "request", "metadata", MetadataFromContext(ctx).String(), "addr", "data", data) - b, e := l.api.SignStructuredData(ctx, TypedData{}) + b, e := l.api.SignStructuredData(ctx, data) l.log.Info("SignStructuredData", "type", "response", "data", common.Bytes2Hex(b), "error", e) return b, e }