mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Solved the auditlog issue
This commit is contained in:
parent
ed5f7f3b14
commit
1478b88947
6 changed files with 59 additions and 98 deletions
1
cmd/clef/audit.log
Normal file
1
cmd/clef/audit.log
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
t=2018-10-13T05:03:16-0700 lvl=info msg=Configured api=signer audit log=audit.log
|
||||||
|
|
@ -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"`
|
|
||||||
}
|
|
||||||
|
|
@ -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
56
signer/core/apiv2.go
Normal 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
|
||||||
|
//}
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue