mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
Working on TypedData
This commit is contained in:
parent
0d20de1a70
commit
1414b3a814
4 changed files with 35 additions and 25 deletions
|
|
@ -1,11 +0,0 @@
|
|||
t=2018-10-10T14:45:26-0700 lvl=info msg=Configured api=signer audit log=audit.log
|
||||
t=2018-10-10T14:45:37-0700 lvl=info msg=SignStructuredData api=signer type=request metadata="{\"remote\":\"127.0.0.1:59942\",\"local\":\"localhost:8550\",\"scheme\":\"HTTP/1.1\",\"User-Agent\":\"PostmanRuntime/7.3.0\",\"Origin\":\"\"}" addr="0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826 [chksum ok]" data={PrimaryType:0x4d61696c}
|
||||
t=2018-10-10T14:45:37-0700 lvl=info msg=SignStructuredData api=signer type=response data= error=nil
|
||||
t=2018-10-10T14:45:55-0700 lvl=info msg=Configured api=signer audit log=audit.log
|
||||
t=2018-10-10T14:45:55-0700 lvl=info msg=SignStructuredData api=signer type=request metadata="{\"remote\":\"127.0.0.1:59956\",\"local\":\"localhost:8550\",\"scheme\":\"HTTP/1.1\",\"User-Agent\":\"PostmanRuntime/7.3.0\",\"Origin\":\"\"}" addr="0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826 [chksum ok]" data={PrimaryType:0x4d61696c}
|
||||
t=2018-10-10T14:46:18-0700 lvl=info msg=Configured api=signer audit log=audit.log
|
||||
t=2018-10-10T14:46:50-0700 lvl=info msg=SignStructuredData api=signer type=request metadata="{\"remote\":\"127.0.0.1:59967\",\"local\":\"localhost:8550\",\"scheme\":\"HTTP/1.1\",\"User-Agent\":\"PostmanRuntime/7.3.0\",\"Origin\":\"\"}" addr="0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826 [chksum ok]" data={PrimaryType:0x4d61696c}
|
||||
t=2018-10-10T14:51:32-0700 lvl=info msg=Configured api=signer audit log=audit.log
|
||||
t=2018-10-10T14:51:59-0700 lvl=info msg=SignStructuredData api=signer type=request metadata="{\"remote\":\"127.0.0.1:60000\",\"local\":\"localhost:8550\",\"scheme\":\"HTTP/1.1\",\"User-Agent\":\"PostmanRuntime/7.3.0\",\"Origin\":\"\"}" addr="0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826 [chksum ok]" data="{Hash:[226 140 80 200 149 243 254 73 125 193 200 45 83 189 176 154 4 204 167 86 220 130 208 11 170 238 116 129 150 85 62 148]}"
|
||||
t=2018-10-10T14:52:51-0700 lvl=info msg=Configured api=signer audit log=audit.log
|
||||
t=2018-10-10T14:52:56-0700 lvl=info msg=SignStructuredData api=signer type=request metadata="{\"remote\":\"127.0.0.1:60017\",\"local\":\"localhost:8550\",\"scheme\":\"HTTP/1.1\",\"User-Agent\":\"PostmanRuntime/7.3.0\",\"Origin\":\"\"}" addr="0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826 [chksum ok]" data="{Hash:[226 140 80 200 149 243 254 73 125 193 200 45 83 189 176 154 4 204 167 86 220 130 208 11 170 238 116 129 150 85 62 148]}"
|
||||
|
|
@ -21,6 +21,7 @@ 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"
|
||||
|
|
@ -53,7 +54,7 @@ type ExternalAPI interface {
|
|||
// SignData - request to sign the given data (plus prefix)
|
||||
SignData(ctx context.Context, contentType string, addr common.MixedcaseAddress, data hexutil.Bytes) (hexutil.Bytes, error)
|
||||
// SignStructuredData - request to sign the given structured data (plus prefix)
|
||||
SignStructuredData(ctx context.Context, addr common.MixedcaseAddress, data TypedData) (hexutil.Bytes, error)
|
||||
SignStructuredData(ctx context.Context, data TypedData) (hexutil.Bytes, error)
|
||||
// EcRecover - recover public key from given message and signature
|
||||
EcRecover(ctx context.Context, contentType string, data hexutil.Bytes, sig hexutil.Bytes) (common.Address, error)
|
||||
// Export - request to export an account
|
||||
|
|
@ -608,11 +609,6 @@ func (api *SignerAPI) DetermineSignatureFormat(contentType string, data hexutil.
|
|||
|
||||
sighash, msg := SignDataWithValidator(data)
|
||||
req = &SignDataRequest{Rawdata: data, Message: msg, Hash: sighash, ContentType: mediaType}
|
||||
case DataStructured.Mime:
|
||||
// Typed data according to EIP712
|
||||
|
||||
sighash, msg := SignDataStructured(data)
|
||||
req = &SignDataRequest{Rawdata: data, Message: msg, Hash: sighash, ContentType: mediaType}
|
||||
case DataPlain.Mime:
|
||||
// Sign calculates an Ethereum ECDSA signature for:
|
||||
// keccack256("\x19${byte version}Ethereum Signed Message:\n" + len(message) + message))
|
||||
|
|
@ -672,12 +668,37 @@ func SignDataWithValidator(data []byte) ([]byte, string) {
|
|||
return crypto.Keccak256([]byte(msg)), msg
|
||||
}
|
||||
|
||||
// SignDataStructured signs the given message according to EIP712.
|
||||
// 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
|
||||
func SignDataStructured(data []byte) ([]byte, string) {
|
||||
msg := "TODO"
|
||||
return crypto.Keccak256([]byte(msg)), msg
|
||||
//
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ type TypedData ethereum.TypedData
|
|||
//
|
||||
// If the format "\x19\x46" ‖ domainSeparator ‖ hashStruct(message)` is not respected,
|
||||
// an error is returned
|
||||
func (api *SignerAPI) SignStructuredData(ctx context.Context, addr common.MixedcaseAddress, data TypedData) (hexutil.Bytes, error) {
|
||||
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
|
||||
|
|
@ -70,10 +70,10 @@ func (l *AuditLogger) SignData(ctx context.Context, contentType string, addr com
|
|||
return b, e
|
||||
}
|
||||
|
||||
func (l *AuditLogger) SignStructuredData(ctx context.Context, addr common.MixedcaseAddress, 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(),
|
||||
"addr", addr.String(), "data", data)
|
||||
b, e := l.api.SignStructuredData(ctx, addr, TypedData{})
|
||||
"addr", "data", data)
|
||||
b, e := l.api.SignStructuredData(ctx, TypedData{})
|
||||
l.log.Info("SignStructuredData", "type", "response", "data", common.Bytes2Hex(b), "error", e)
|
||||
return b, e
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue