Bug: Invalid V in signature with eth_sign (#728)
* Fix invalid V with metamask/ledger * DONT FORGET TO REVERT BEFORE MERGING: test deployment * DONT FORGET TO REVERT BEFORE MERGING 2: test deployment * Revert "DONT FORGET TO REVERT BEFORE MERGING 2: test deployment" This reverts commit 8331f2a78f7fc8f53eb893899f16edd8238c68ff. * Revert "DONT FORGET TO REVERT BEFORE MERGING: test deployment" This reverts commit 03b81e31820ce4fe078a7131c2f0caa2af4870ac.
This commit is contained in:
parent
aa2a386690
commit
94a56d2ebd
|
@ -53,7 +53,28 @@ export const getEthSigner = async ({
|
|||
return
|
||||
}
|
||||
|
||||
resolve(signature.result.replace(EMPTY_DATA, ''))
|
||||
const sig = signature.result.replace(EMPTY_DATA, '')
|
||||
let sigV = parseInt(sig.slice(-2), 16)
|
||||
|
||||
// Metamask with ledger returns v = 01, this is not valid for ethereum
|
||||
// For ethereum valid V is 27 or 28
|
||||
// In case V = 0 or 01 we add it to 27 and then add 4
|
||||
// Adding 4 is required to make signature valid for safe contracts:
|
||||
// https://gnosis-safe.readthedocs.io/en/latest/contracts/signatures.html#eth-sign-signature
|
||||
switch (sigV) {
|
||||
case 0:
|
||||
case 1:
|
||||
sigV += 31
|
||||
break
|
||||
case 27:
|
||||
case 28:
|
||||
sigV += 4
|
||||
break
|
||||
default:
|
||||
throw new Error('Invalid signature')
|
||||
}
|
||||
|
||||
resolve(sig.slice(0, -2) + sigV.toString(16))
|
||||
},
|
||||
)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue