import { Bech32 } from "@iota/crypto.js" ; /**
 * Convert address to bech32.
 */ export class Bech32Helper { /**
     * The default human readable part of the bech32 addresses for mainnet, currently 'iota'.
     */ public static BECH32_DEFAULT_HRP_MAIN : string = "iota" ; /**
     * The default human readable part of the bech32 addresses for devnet, currently 'atoi'.
     */ public static BECH32_DEFAULT_HRP_DEV : string = "atoi" ; param addressType param addressBytes param humanReadablePart returns public static toBech32 ( addressType , addressBytes , humanReadablePart ) { const addressData = new Uint8Array ( 1 + addressBytes . length ) ; addressData [ 0 ] = addressType ; addressData . set ( addressBytes , 1 ) ; return Bech32 . encode ( humanReadablePart , addressData ) ; } param bech32Text param humanReadablePart returns public static fromBech32 ( bech32Text , humanReadablePart ) { const decoded = Bech32 . decode ( bech32Text ) ; if ( decoded ) { if ( decoded . humanReadablePart !== humanReadablePart ) { throw new Error ( `The hrp part of the address should be ${ humanReadablePart }, it is ${ decoded . humanReadablePart }` ) ; } if ( decoded . data . length === 0 ) { throw new Error ( "The data part of the address should be at least length 1, it is 0" ) ; } const addressType = decoded . data [ 0 ] ; const addressBytes = decoded . data . slice ( 1 ) ; return { addressType , addressBytes } ; } } param bech32Text param humanReadablePart returns public static matches ( bech32Text , humanReadablePart ) { return Bech32 . matches ( humanReadablePart , bech32Text ) ; } }