import { PublicKey } from '../crypto' ; import { hexstr2str , str2VarBytes , StringReader } from '../utils' ; /**
 * Public key representation with recorded id from blockchain.
 *
 */ export class PublicKeyWithId { param hexstr static deserialize ( hexstr ) { const sr = new StringReader ( hexstr ) ; const result = [ ] ; while ( ! sr . isEmpty ( ) ) { const index = sr . readUint32 ( ) ; const data = sr . readNextBytes ( ) ; const p = new PublicKeyWithId ( ) ; p . id = index ; p . pk = PublicKey . deserializeHex ( new StringReader ( data ) ) ; result . push ( p ) ; } return result ; } /**
     * Id of the public key.
     *
     * Only numeric part is recorded. Full PublicKeyId will be constucted as follows:
     * <ONTID>#keys-<id>
     */ id : number ; pk : PublicKey ; } /**
 * Description attribute of ONT ID
 */ export class DDOAttribute { static deserialize ( hexstr ) { const sr = new StringReader ( hexstr ) ; const result = [ ] ; while ( ! sr . isEmpty ( ) ) { const key = hexstr2str ( sr . readNextBytes ( ) ) ; const type = hexstr2str ( sr . readNextBytes ( ) ) ; const value = hexstr2str ( sr . readNextBytes ( ) ) ; const d = new DDOAttribute ( ) ; d . key = key ; d . type = type ; d . value = value ; result . push ( d ) ; } return result ; } /**
     * Key of the attribute
     */ key : string ; /**
     * Type of the attribute
     */ type : string ; /**
     * Value of the attribute
     */ value : string ; /**
     * Serialize DDO to hex string
     */ serialize ( ) { let result = '' ; result += str2VarBytes ( this . key ) ; result += str2VarBytes ( this . type ) ; result += str2VarBytes ( this . value ) ; return result ; } } /**
 * Description object of ONT ID
 */ export class DDO { param hexstr static deserialize ( hexstr ) { const ss = new StringReader ( hexstr ) ; const ddo = new DDO ( ) ; const pkLen = ss . readNextLen ( ) ; if ( pkLen > 0 ) { ddo . publicKeys = PublicKeyWithId . deserialize ( ss . read ( pkLen ) ) ; } const attrLen = ss . readNextLen ( ) ; if ( attrLen > 0 ) { ddo . attributes = DDOAttribute . deserialize ( ss . read ( attrLen ) ) ; } const recoveryLen = ss . readNextLen ( ) ; if ( recoveryLen > 0 ) { ddo . recovery = ss . read ( recoveryLen ) ; } return ddo ; } /**
     * Array of public keys
     */ publicKeys : PublicKeyWithId [ ] = [ ] ; /**
     * Array of attributes
     */ attributes : DDOAttribute [ ] = [ ] ; /**
     * Recovery of DDO
     */ recovery : string = '' ; }