import { Err , Ok , Result } from './prelude.js' ; import { getAddress as parseAddress } from '@ethersproject/address' ; import { arrayify as parseHexString } from '@ethersproject/bytes' ; import { keccak256 } from '@ethersproject/keccak256' ; export class AccountID { constructor ( public readonly id ) { } static aurora ( ) { return new AccountID ( 'aurora' ) ; } static parse ( id ? ) { return Ok ( new AccountID ( id ! ) ) ; } toString ( ) { return this . id ; } toAddress ( ) { return Address . parse ( keccak256 ( Buffer . from ( this . id ) ) . slice ( 26 , 66 ) ) . unwrap ( ) ; } } export class Address { static ZERO = `0x${ '00' . repeat ( 20 ) }` ; protected constructor ( public readonly id ) { } static zero ( ) { return new Address ( Address . ZERO ) ; } static parse ( id ? ) { try { return Ok ( new Address ( parseAddress ( id ! ) ) ) ; } catch ( error ) { return Err ( error . message ) ; } } isZero ( ) { return this . id === Address . ZERO ; } toString ( ) { return this . id ; } toBytes ( ) { return parseHexString ( this . id ) ; } }