Fix generation of signatures from tx confirmations

This commit is contained in:
Germán Martínez 2019-11-21 13:09:31 +01:00
parent c79df89e76
commit 88d0453168
1 changed files with 16 additions and 7 deletions

View File

@ -31,18 +31,27 @@ export const generateSignaturesFromTxConfirmations = (
) => {
// The constant parts need to be sorted so that the recovered signers are sorted ascending
// (natural order) by address (not checksummed).
let confirmedAdresses = confirmations.map((conf) => conf.owner.address)
const confirmationsMap = confirmations.reduce((map, obj) => {
map[obj.owner.address] = obj // eslint-disable-line no-param-reassign
return map
}, {})
if (preApprovingOwner) {
confirmedAdresses = confirmedAdresses.push(preApprovingOwner)
confirmationsMap[preApprovingOwner] = { owner: preApprovingOwner }
}
let sigs = '0x'
confirmedAdresses.sort().forEach((addr) => {
Object.keys(confirmationsMap).sort().forEach((addr) => {
const conf = confirmationsMap[addr]
if (conf.signature) {
sigs += conf.signature.slice(2)
} else {
// https://gnosis-safe.readthedocs.io/en/latest/contracts/signatures.html#pre-validated-signatures
sigs += `000000000000000000000000${addr.replace(
'0x',
'',
)}000000000000000000000000000000000000000000000000000000000000000001`
}
})
return sigs
}