Skip to content

Commit 510b6f9

Browse files
authored
accounts/external: convert signature v value to 0/1 (#20997)
This fixes an issue with clef, which already transforms the signature to use the legacy 27/28 encoding. Fixes #20994
1 parent c43be6c commit 510b6f9

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎accounts/accounts.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ type Wallet interface {
129129
// about which fields or actions are needed. The user may retry by providing
130130
// the needed details via SignHashWithPassphrase, or by other means (e.g. unlock
131131
// the account in a keystore).
132+
//
133+
// This method should return the signature in 'canonical' format, with v 0 or 1
132134
SignText(account Account, text []byte) ([]byte, error)
133135

134136
// SignTextWithPassphrase is identical to Signtext, but also takes a password

‎accounts/external/backend.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,20 @@ func (api *ExternalSigner) SignData(account accounts.Account, mimeType string, d
175175
}
176176

177177
func (api *ExternalSigner) SignText(account accounts.Account, text []byte) ([]byte, error) {
178-
var res hexutil.Bytes
178+
var signature hexutil.Bytes
179179
var signAddress = common.NewMixedcaseAddress(account.Address)
180-
if err := api.client.Call(&res, "account_signData",
180+
if err := api.client.Call(&signature, "account_signData",
181181
accounts.MimetypeTextPlain,
182182
&signAddress, // Need to use the pointer here, because of how MarshalJSON is defined
183183
hexutil.Encode(text)); err != nil {
184184
return nil, err
185185
}
186-
return res, nil
186+
if signature[64] == 27 || signature[64] == 28 {
187+
// If clef is used as a backend, it may already have transformed
188+
// the signature to ethereum-type signature.
189+
signature[64] -= 27 // Transform V from Ethereum-legacy to 0/1
190+
}
191+
return signature, nil
187192
}
188193

189194
func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) {

0 commit comments

Comments
 (0)