mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Working on TypedData
This commit is contained in:
parent
adccccbb88
commit
ed5f7f3b14
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"
|
"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"
|
||||||
|
|
@ -52,7 +53,7 @@ type ExternalAPI interface {
|
||||||
// SignData - request to sign the given data (plus prefix)
|
// SignData - request to sign the given data (plus prefix)
|
||||||
SignData(ctx context.Context, contentType string, addr common.MixedcaseAddress, data hexutil.Bytes) (hexutil.Bytes, error)
|
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 - 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 - recover public key from given message and signature
|
||||||
EcRecover(ctx context.Context, contentType string, data hexutil.Bytes, sig hexutil.Bytes) (common.Address, error)
|
EcRecover(ctx context.Context, contentType string, data hexutil.Bytes, sig hexutil.Bytes) (common.Address, error)
|
||||||
// Export - request to export an account
|
// Export - request to export an account
|
||||||
|
|
@ -611,11 +612,6 @@ func (api *SignerAPI) DetermineSignatureFormat(contentType string, data hexutil.
|
||||||
|
|
||||||
sighash, msg := SignDataWithValidator(data)
|
sighash, msg := SignDataWithValidator(data)
|
||||||
req = &SignDataRequest{Rawdata: data, Message: msg, Hash: sighash, ContentType: mediaType}
|
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:
|
case DataPlain.Mime:
|
||||||
// Sign calculates an Ethereum ECDSA signature for:
|
// Sign calculates an Ethereum ECDSA signature for:
|
||||||
// keccack256("\x19${byte version}Ethereum Signed Message:\n" + len(message) + message))
|
// keccack256("\x19${byte version}Ethereum Signed Message:\n" + len(message) + message))
|
||||||
|
|
@ -675,12 +671,37 @@ func SignDataWithValidator(data []byte) ([]byte, string) {
|
||||||
return crypto.Keccak256([]byte(msg)), msg
|
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
|
// https://github.com/ethereum/EIPs/issues/712
|
||||||
func SignDataStructured(data []byte) ([]byte, string) {
|
//
|
||||||
msg := "TODO"
|
// If the format "\x19\x46" ‖ domainSeparator ‖ hashStruct(message)` is not respected,
|
||||||
return crypto.Keccak256([]byte(msg)), msg
|
// 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
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ type TypedData ethereum.TypedData
|
||||||
//
|
//
|
||||||
// If the format "\x19\x46" ‖ domainSeparator ‖ hashStruct(message)` is not respected,
|
// If the format "\x19\x46" ‖ domainSeparator ‖ hashStruct(message)` is not respected,
|
||||||
// an error is returned
|
// 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", data)
|
||||||
fmt.Println("data.Hash", data.Hash)
|
fmt.Println("data.Hash", data.Hash)
|
||||||
return common.Hex2Bytes("0xdeadbeef"), nil
|
return common.Hex2Bytes("0xdeadbeef"), nil
|
||||||
|
|
@ -70,10 +70,10 @@ func (l *AuditLogger) SignData(ctx context.Context, contentType string, addr com
|
||||||
return b, e
|
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(),
|
l.log.Info("SignStructuredData", "type", "request", "metadata", MetadataFromContext(ctx).String(),
|
||||||
"addr", addr.String(), "data", data)
|
"addr", "data", data)
|
||||||
b, e := l.api.SignStructuredData(ctx, addr, TypedData{})
|
b, e := l.api.SignStructuredData(ctx, TypedData{})
|
||||||
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