import { arrayify , BytesLike , hexlify } from '@ethersproject/bytes' ; import { ethers } from 'ethers' ; export type Address = string ; param data returns export function canonizeId ( data ) { const buf = ethers . utils . arrayify ( data ) ; if ( buf . length > 32 ) { throw new Error ( 'Too long' ) ; } if ( buf . length !== 20 && buf . length != 32 ) { throw new Error ( 'bad input, expect address or bytes32' ) ; } return ethers . utils . zeroPad ( buf , 32 ) ; } param data returns throws export function evmId ( data ) { const u8a = arrayify ( data ) ; if ( u8a . length === 32 ) { return hexlify ( u8a . slice ( 12 , 32 ) ) ; } else if ( u8a . length === 20 ) { return hexlify ( u8a ) ; } else { throw new Error ( `Invalid id length. expected 20 or 32. Got ${ u8a . length }` ) ; } } param ms returns export function delay ( ms ) { return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ; }