mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
add personal_recover
This commit is contained in:
parent
85bfe8382d
commit
42a26000ea
2 changed files with 34 additions and 0 deletions
|
|
@ -312,6 +312,35 @@ func (s *PrivateAccountAPI) Sign(ctx context.Context, message string, addr commo
|
|||
return common.ToHex(signature), nil
|
||||
}
|
||||
|
||||
// recover returns the address for the account that was used to create the signature.
|
||||
//
|
||||
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_recover
|
||||
func (s *PrivateAccountAPI) Recover(ctx context.Context, message string, signature string) (common.Address, error) {
|
||||
var (
|
||||
sig = common.FromHex(signature)
|
||||
hash = crypto.Keccak256(common.FromHex(message))
|
||||
)
|
||||
|
||||
if len(sig) != 65 {
|
||||
return common.Address{}, fmt.Errorf("signature must be 65 bytes long")
|
||||
}
|
||||
|
||||
// see crypto.Ecrecover description
|
||||
if sig[64] == 27 || sig[64] == 28 {
|
||||
sig[64] -= 27
|
||||
}
|
||||
|
||||
rpk, err := crypto.Ecrecover(hash, sig)
|
||||
if err != nil {
|
||||
return common.Address{}, err
|
||||
}
|
||||
|
||||
pubKey := crypto.ToECDSAPub(rpk)
|
||||
recoveredAddr := crypto.PubkeyToAddress(*pubKey)
|
||||
|
||||
return recoveredAddr, nil
|
||||
}
|
||||
|
||||
// SignAndSendTransaction was renamed to SendTransaction. This method is deprecated
|
||||
// and will be removed in the future. It primary goal is to give clients time to update.
|
||||
func (s *PrivateAccountAPI) SignAndSendTransaction(ctx context.Context, args SendTxArgs, passwd string) (common.Hash, error) {
|
||||
|
|
|
|||
|
|
@ -434,6 +434,11 @@ web3._extend({
|
|||
call: 'personal_sign',
|
||||
params: 3,
|
||||
inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'recover',
|
||||
call: 'personal_recover',
|
||||
params: 2
|
||||
})
|
||||
]
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue