From 66f881a3931454c857d9d828afebdfadfe43290a Mon Sep 17 00:00:00 2001 From: Paul Berg Date: Mon, 5 Nov 2018 17:54:58 +0200 Subject: [PATCH] Added example RPC calls for account_signData and account_signTypedData --- cmd/clef/README.md | 8 ++++---- cmd/clef/extapi_changelog.md | 2 +- signer/core/signed_data.go | 17 ++--------------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/cmd/clef/README.md b/cmd/clef/README.md index be0e10747e..5e6f8661c7 100644 --- a/cmd/clef/README.md +++ b/cmd/clef/README.md @@ -350,15 +350,13 @@ Bash example: {"jsonrpc":"2.0","id":67,"result":{"raw":"0xf88380018203339407a565b7ed7d7a678680a4c162885bedbb695fe080a44401a6e4000000000000000000000000000000000000000000000000000000000000001226a0223a7c9bcf5531c99be5ea7082183816eb20cfe0bbc322e97cc5c7f71ab8b20ea02aadee6b34b45bb15bc42d9c09de4a6754e7000908da72d48cc7704971491663","tx":{"nonce":"0x0","gasPrice":"0x1","gas":"0x333","to":"0x07a565b7ed7d7a678680a4c162885bedbb695fe0","value":"0x0","input":"0x4401a6e40000000000000000000000000000000000000000000000000000000000000012","v":"0x26","r":"0x223a7c9bcf5531c99be5ea7082183816eb20cfe0bbc322e97cc5c7f71ab8b20e","s":"0x2aadee6b34b45bb15bc42d9c09de4a6754e7000908da72d48cc7704971491663","hash":"0xeba2df809e7a612a0a0d444ccfa5c839624bdc00dd29e3340d46df3870f8a30e"}}} ``` - ### account_signData #### Sign data Signs a chunk of data and returns the calculated signature. #### Arguments - - - content type [string]: type of data to sign + - content type [string]: type of signed data - `text/validator`: hex data with custom validator defined in a contract - `application/clique`: [clique](https://github.com/ethereum/EIPs/issues/225) headers - `text/plain`: simple hex data validated by `account_ecRecover` @@ -491,11 +489,13 @@ Response ### account_ecRecover #### Sign data +<<<<<<< HEAD +======= +>>>>>>> c72099670... Added example RPC calls for account_signData and account_signTypedData Derive the address from the account that was used to sign data with content type `text/plain` and the signature. #### Arguments - - content type [string]: type of signed data - data [data]: data that was signed - signature [data]: the signature to verify diff --git a/cmd/clef/extapi_changelog.md b/cmd/clef/extapi_changelog.md index a9ab42e5b5..7adc339605 100644 --- a/cmd/clef/extapi_changelog.md +++ b/cmd/clef/extapi_changelog.md @@ -8,7 +8,7 @@ The addition of `contentType` makes it possible to use the method for different * signing data with an intended validator (not yet implemented) * signing clique headers, * signing plain personal messages, -* The external method `account_signTypedData` [EIP-712](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md) and makes it possible to sign typed data. +* The external method `account_signTypedData` implements [EIP-712](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md) and makes it possible to sign typed data. #### 4.0.0 diff --git a/signer/core/signed_data.go b/signer/core/signed_data.go index b8dd636a87..532d2c99a5 100644 --- a/signer/core/signed_data.go +++ b/signer/core/signed_data.go @@ -175,7 +175,6 @@ func (api *SignerAPI) determineSignatureFormat(contentType string, addr common.M } sighash, msg := SignTextValidator(validatorData) req = &SignDataRequest{Rawdata: validatorData, Message: msg, Hash: sighash, ContentType: mediaType} - break case ApplicationClique.Mime: // Clique is the Ethereum PoA standard cliqueData, err := hexutil.Decode(data.(string)) @@ -192,7 +191,6 @@ func (api *SignerAPI) determineSignatureFormat(contentType string, addr common.M } msg := fmt.Sprintf("clique block %d [0x%x]", header.Number, header.Hash()) req = &SignDataRequest{Rawdata: cliqueData, Message: msg, Hash: sighash, ContentType: mediaType} - break case TextPlain.Mime: // Calculates an Ethereum ECDSA signature for: // hash = keccak256("\x19${byteVersion}Ethereum Signed Message:\n${message length}${message}") @@ -202,7 +200,6 @@ func (api *SignerAPI) determineSignatureFormat(contentType string, addr common.M } sighash, msg := SignTextPlain(plainData) req = &SignDataRequest{Rawdata: plainData, Message: msg, Hash: sighash, ContentType: mediaType} - break default: return nil, fmt.Errorf("content type '%s' not implemented for signing", contentType) } @@ -382,7 +379,6 @@ func (typedData *TypedData) EncodeData(primaryType string, data map[string]inter bytesValue = append(bytesValue, _byte) } primitiveEncValue = bytesValue - break case "bool": primitiveEncType = "uint256" var int64Val int64 @@ -390,11 +386,9 @@ func (typedData *TypedData) EncodeData(primaryType string, data map[string]inter int64Val = 1 } primitiveEncValue = abi.U256(big.NewInt(int64Val)) - break case "bytes", "string": primitiveEncType = "bytes32" primitiveEncValue = crypto.Keccak256(bytesValueOf(encValue)) - break default: if strings.HasPrefix(encType, "bytes") { encTypes = append(encTypes, "bytes32") @@ -404,15 +398,12 @@ func (typedData *TypedData) EncodeData(primaryType string, data map[string]inter for i := 0; i < 32-size; i++ { bytesValue = append(bytesValue, 0) } - for _, _byte := range encValue.(hexutil.Bytes) { - bytesValue = append(bytesValue, _byte) - } + bytesValue = append(bytesValue, encValue.(hexutil.Bytes)...) primitiveEncValue = bytesValue } else if strings.HasPrefix(encType, "uint") || strings.HasPrefix(encType, "int") { primitiveEncType = "uint256" primitiveEncValue = abi.U256(encValue.(*big.Int)) } - break } return primitiveEncType, primitiveEncValue } @@ -600,11 +591,7 @@ func isStandardTypeStr(encType string) bool { } // Reference types - if encType[len(encType)-1] == ']' { - return true - } - - return false + return encType[len(encType)-1] == ']' } // IsValid checks if the given domain is valid, i.e. contains at least