Solved the auditlog issue

This commit is contained in:
Paul Berg 2018-10-13 05:04:06 -07:00 committed by Martin Holst Swende
parent f96a12b639
commit c960cf5df7
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
6 changed files with 59 additions and 98 deletions

1
cmd/clef/audit.log Normal file
View file

@ -0,0 +1 @@
t=2018-10-13T05:03:16-0700 lvl=info msg=Configured api=signer audit log=audit.log

View file

@ -208,9 +208,4 @@ type GasEstimator interface {
// pending state. // pending state.
type PendingStateEventer interface { type PendingStateEventer interface {
SubscribePendingTransactions(ctx context.Context, ch chan<- *types.Transaction) (Subscription, error) 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"`
}

View file

@ -21,7 +21,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/crypto/sha3"
"io/ioutil" "io/ioutil"
@ -671,39 +670,6 @@ func SignDataWithValidator(data []byte) ([]byte, string) {
return crypto.Keccak256([]byte(msg)), msg 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 // SignDataPlain is a helper function that calculates a hash for the given message that can be
// safely used to calculate a signature from. // safely used to calculate a signature from.
// //

56
signer/core/apiv2.go Normal file
View file

@ -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
//}

View file

@ -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
}

View file

@ -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) { func (l *AuditLogger) SignStructuredData(ctx context.Context, data TypedData) (hexutil.Bytes, error) {
l.log.Info("SignStructuredData", "type", "request", "metadata", MetadataFromContext(ctx).String(), l.log.Info("SignStructuredData", "type", "request", "metadata", MetadataFromContext(ctx).String(),
"addr", "data", data) "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) l.log.Info("SignStructuredData", "type", "response", "data", common.Bytes2Hex(b), "error", e)
return b, e return b, e
} }