import * as chai from "chai" ; import { solidity } from "ethereum-waffle" ; import { BigNumber , joinSignature , recoverAddress , Signature } from "ethers/utils" ; export const expect = chai . use ( solidity ) . expect ; param signatures export function signaturesToBytes ( ... signatures ) { return signatures . map ( joinSignature ) . map ( s => s . substr ( 2 ) ) . reduce ( ( acc , v ) => acc + v , "0x" ) ; } param signatures export function sortSignaturesBySignerAddress ( digest , signatures ) { const ret = signatures . slice ( ) ; ret . sort ( ( sigA , sigB ) => { const addrA = recoverAddress ( digest , signaturesToBytes ( sigA ) ) ; const addrB = recoverAddress ( digest , signaturesToBytes ( sigB ) ) ; return new BigNumber ( addrA ) . lt ( addrB ) ? - 1 : 1 ; } ) ; return ret ; } param signatures export function signaturesToBytesSortedBySignerAddress ( digest , ... signatures ) { return signaturesToBytes ( ... sortSignaturesBySignerAddress ( digest , signatures ) ) ; }