Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
6ad620d6
Unverified
Commit
6ad620d6
authored
Jun 14, 2022
by
s7v7nislands
Committed by
GitHub
Jun 14, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/ethkey: use accounts.TextHash (#25069)
parent
1cf58c7b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
19 deletions
+7
-19
message.go
cmd/ethkey/message.go
+3
-2
utils.go
cmd/ethkey/utils.go
+0
-13
signed_data.go
signer/core/signed_data.go
+4
-4
No files found.
cmd/ethkey/message.go
View file @
6ad620d6
...
...
@@ -21,6 +21,7 @@ import (
"fmt"
"os"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -68,7 +69,7 @@ To sign a message contained in a file, use the --msgfile flag.
utils
.
Fatalf
(
"Error decrypting key: %v"
,
err
)
}
signature
,
err
:=
crypto
.
Sign
(
sign
Hash
(
message
),
key
.
PrivateKey
)
signature
,
err
:=
crypto
.
Sign
(
accounts
.
Text
Hash
(
message
),
key
.
PrivateKey
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to sign message: %v"
,
err
)
}
...
...
@@ -113,7 +114,7 @@ It is possible to refer to a file containing the message.`,
utils
.
Fatalf
(
"Signature encoding is not hexadecimal: %v"
,
err
)
}
recoveredPubkey
,
err
:=
crypto
.
SigToPub
(
sign
Hash
(
message
),
signature
)
recoveredPubkey
,
err
:=
crypto
.
SigToPub
(
accounts
.
Text
Hash
(
message
),
signature
)
if
err
!=
nil
||
recoveredPubkey
==
nil
{
utils
.
Fatalf
(
"Signature verification failed: %v"
,
err
)
}
...
...
cmd/ethkey/utils.go
View file @
6ad620d6
...
...
@@ -23,7 +23,6 @@ import (
"strings"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/crypto"
"gopkg.in/urfave/cli.v1"
)
...
...
@@ -46,18 +45,6 @@ func getPassphrase(ctx *cli.Context, confirmation bool) string {
return
utils
.
GetPassPhrase
(
""
,
confirmation
)
}
// signHash is a helper function that calculates a hash for the given message
// that can be safely used to calculate a signature from.
//
// The hash is calculated as
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
//
// This gives context to the signed message and prevents signing of transactions.
func
signHash
(
data
[]
byte
)
[]
byte
{
msg
:=
fmt
.
Sprintf
(
"
\x19
Ethereum Signed Message:
\n
%d%s"
,
len
(
data
),
data
)
return
crypto
.
Keccak256
([]
byte
(
msg
))
}
// mustPrintJSON prints the JSON encoding of the given object and
// exits the program with an error message when the marshaling fails.
func
mustPrintJSON
(
jsonObject
interface
{})
{
...
...
signer/core/signed_data.go
View file @
6ad620d6
...
...
@@ -169,7 +169,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
req
=
&
SignDataRequest
{
ContentType
:
mediaType
,
Rawdata
:
cliqueRlp
,
Messages
:
messages
,
Hash
:
sighash
}
default
:
// also case TextPlain.Mime:
// Calculates an Ethereum ECDSA signature for:
// hash = keccak256("\x19
${byteVersion}
Ethereum Signed Message:\n${message length}${message}")
// hash = keccak256("\x19Ethereum Signed Message:\n${message length}${message}")
// We expect it to be a string
if
stringData
,
ok
:=
data
.
(
string
);
!
ok
{
return
nil
,
useEthereumV
,
fmt
.
Errorf
(
"input for text/plain must be an hex-encoded string"
)
...
...
@@ -194,7 +194,7 @@ func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType
return
req
,
useEthereumV
,
nil
}
// SignText
With
Validator signs the given message which can be further recovered
// SignTextValidator signs the given message which can be further recovered
// with the given validator.
// hash = keccak256("\x19\x00"${address}${data}).
func
SignTextValidator
(
validatorData
apitypes
.
ValidatorData
)
(
hexutil
.
Bytes
,
string
)
{
...
...
@@ -271,11 +271,11 @@ func (api *SignerAPI) EcRecover(ctx context.Context, data hexutil.Bytes, sig hex
//
// Note, this function is compatible with eth_sign and personal_sign. As such it recovers
// the address of:
// hash = keccak256("\x19
${byteVersion}
Ethereum Signed Message:\n${message length}${message}")
// hash = keccak256("\x19Ethereum Signed Message:\n${message length}${message}")
// addr = ecrecover(hash, signature)
//
// Note, the signature must conform to the secp256k1 curve R, S and V values, where
// the V value must be
be
27 or 28 for legacy reasons.
// the V value must be 27 or 28 for legacy reasons.
//
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecRecover
if
len
(
sig
)
!=
65
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment