import { Amino , Type } from "@chainapsis/ts-amino" ; const { Field , DefineType } = Amino ; import bech32 from "bech32" ; @ DefineType ( ) export class Address { public static fromBech32 ( prefix , bech32Addr ) { const { prefix : b32Prefix , words } = bech32 . decode ( bech32Addr ) ; if ( b32Prefix !== prefix ) { throw new Error ( "Prefix doesn't match" ) ; } return new Address ( bech32 . fromWords ( words ) ) ; } @ Field . Array ( 0 , { type : Type . Uint8 } ) private address : Uint8Array ; constructor ( address ) { this . address = address ; } public toBech32 ( prefix ) { const words = bech32 . toWords ( Buffer . from ( this . address ) as any ) ; return bech32 . encode ( prefix , words ) ; } public toBytes ( ) { return new Uint8Array ( this . address ) ; } } export interface PubKey { toAddress ( ) : Address ; returns toBytes ( ) : Uint8Array ; returns serialize ( ) : Uint8Array ; verify ( msg , sig ) : boolean ; equals ( pubKey ) : boolean ; } export interface PrivKey { returns toBytes ( ) : Uint8Array ; returns serialize ( ) : Uint8Array ; sign ( msg ) : Uint8Array ; toPubKey ( ) : PubKey ; equals ( privKey ) : boolean ; }