import { BigNumber , bigNumberify , joinSignature , recoverAddress , Signature } from "ethers/utils" ; import { JSON_STRINGIFY_SPACE } from "../constants" ; import { getCreate2MultisigAddress } from "./create2-address" ; export { getCreate2MultisigAddress } ; export function getFirstElementInListNotEqualTo ( test , list ) { return list . filter ( x => x !== test ) [ 0 ] ; } export function timeout ( ms ) { return new Promise ( resolve => setTimeout ( resolve , ms ) ) ; } export const wait = ( ms ) => new Promise ( r => setTimeout ( r , ms ) ) ; export const bigNumberifyJson = ( json ) => JSON . parse ( JSON . stringify ( json ) , ( key , val ) => ( val && val [ "_hex" ] ? bigNumberify ( val ) : val ) ) ; 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 ) ) ; } export function prettyPrintObject ( object ) { return JSON . stringify ( object , null , JSON_STRINGIFY_SPACE ) ; }