import { Address } from '@aragon/connect-types' ; import { providers as ethersProviders , utils as ethersUtils } from 'ethers' ; import { ErrorInvalidLocation } from '../errors' ; export const ANY_ENTITY = '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF' ; export function addressesEqual ( first , second ) { first = first && first . toLowerCase ( ) ; second = second && second . toLowerCase ( ) ; return first === second ; } export function includesAddress ( arr , address ) { return arr . some ( ( a ) => addressesEqual ( a , address ) ) ; } export function isAddress ( address ) { return ethersUtils . isAddress ( address ) ; } export async function resolveAddress ( ethersProvider , location ) { const isLocationAddress = isAddress ( location ) ; const address = isLocationAddress ? location : await ethersProvider . resolveName ( location ) ; if ( ! isAddress ( address ) ) { throw new ErrorInvalidLocation ( isLocationAddress ? `The address (${ address }) is not valid.` : `The ENS domain (${ location }) doesn’t seem to resolve to an address.` ) ; } return address ; }