import { Address , PublicKey } from '../../crypto' ; import RestClient from '../../network/rest/restClient' ; import { DDOAttribute } from '../../transaction/ddo' ; import { Transaction } from '../../transaction/transaction' ; import { makeNativeContractTx } from '../../transaction/transactionUtils' ; import { hexstr2str , str2hexstr } from '../../utils' ; import { buildNativeCodeScript } from '../abi/nativeVmParamsBuilder' ; import Struct from '../abi/struct' ; import Group from './ontid/group' ; import { serializeSigners , Signer } from './ontid/signer' ; /**
 * Address of ONT ID contract
 */ export const ONTID_CONTRACT = '0000000000000000000000000000000000000003' ; /**
 * Method names in ONT ID contract
 */ const ONTID_METHOD = { regIDWithPublicKey : 'regIDWithPublicKey' , regIdWithController : 'regIDWithController' , revokeID : 'revokeID' , removeController : 'removeController' , revokeIDByController : 'revokeIDByController' , regIDWithAttributes : 'regIDWithAttributes' , addAttributes : 'addAttributes' , removeAttribute : 'removeAttribute' , addAttributesByController : 'addAttributesByController' , removeAttributeByController : 'removeAttributeByController' , addAttributesByIndex : 'addAttributesByIndex' , removeAttributeByIndex : 'removeAttributeByIndex' , getAttributes : 'getAttributes' , getDDO : 'getDDO' , addKey : 'addKey' , setRecovery : 'setRecovery' , updateRecovery : 'updateRecovery' , addKeyByController : 'addKeyByController' , addKeyByRecovery : 'addKeyByRecovery' , addKeyByIndex : 'addKeyByIndex' , removeKeyByRecovery : 'removeKeyByRecovery' , removeKeyByController : 'removeKeyByController' , removeKeyByIndex : 'removeKeyByIndex' , removeKey : 'removeKey' , getPublicKeys : 'getPublicKeysJson' , addRecovery : 'addRecovery' , changeRecovery : 'changeRecovery' , getKeyState : 'getKeyState' , setKeyAccess : 'setKeyAccess' , addNewAuthKey : 'addNewAuthKey' , removeAuthKey : 'removeAuthKey' , addNewAuthKeyByRecovery : 'addNewAuthKeyByRecovery' , removeAuthKeyByRecovery : 'removeAuthKeyByRecovery' , addNewAuthKeyByController : 'addNewAuthKeyByController' , removeAuthKeyByController : 'removeAuthKeyByController' , setAuthKeyByController : 'setAuthKeyByController' , addService : 'addService' , updateService : 'updateService' , removeService : 'removeService' , addContext : 'addContext' , removeContext : 'removeContext' , getDocument : 'getDocumentJson' , getService : 'getServiceJson' , getController : 'getControllerJson' , verifySignature : 'verifySignature' , verifyController : 'verifyController' } ; param ontid param publicKey param gasPrice param gasLimit param payer export function buildRegIDWithPublicKeyTx ( ontid , publicKey , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . regIDWithPublicKey ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const struct = new Struct ( ) ; struct . add ( ontid , publicKey . serializeHex ( ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param publicKey param gasPrice param gasLimit param payer export function buildRegisterOntidTx ( ontid , publicKey , gasPrice , gasLimit , payer ? ) { return buildRegIDWithPublicKeyTx ( ontid , publicKey , gasPrice , gasLimit , payer ) ; } param ontid param controllers param signers param gasPrice param gasLimit param payer export function buildRegIdWithMultiControllerTx ( ontid , controllers , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . regIdWithController ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , controllers . serialize ( ) , serializeSigners ( signers ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param index param gasPrice param gasLimit param payer export function buildMakeRevokeIdTx ( ontid , index , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . revokeID ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , index ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param signers param gasPrice param gasLimit param payer export function buildRevokeIdByMultiController ( ontid , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . revokeIDByController ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , serializeSigners ( signers ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param index param gasPrice param gasLimit param payer export function buildRemoveControllerTx ( ontid , index , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeController ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , index ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param attributes param publicKey param gasPrice param gasLimit param payer export function buildRegIdWithAttributesTx ( ontid , attributes , publicKey , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . regIDWithAttributes ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const struct = new Struct ( ) ; const attrLen = attributes . length ; struct . add ( ontid , publicKey . serializeHex ( ) , attrLen ) ; for ( const a of attributes ) { const key = str2hexstr ( a . key ) ; const type = str2hexstr ( a . type ) ; const value = str2hexstr ( a . value ) ; struct . add ( key , type , value ) ; } const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param attributes param publicKey param gasPrice param gasLimit param payer export function buildAddAttributeTx ( ontid , attributes , publicKey , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addAttributes ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const struct = new Struct ( ) ; struct . add ( ontid , attributes . length ) ; for ( const a of attributes ) { const key = str2hexstr ( a . key ) ; const type = str2hexstr ( a . type ) ; const value = str2hexstr ( a . value ) ; struct . add ( key , type , value ) ; } struct . list . push ( publicKey . serializeHex ( ) ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param key param publicKey param gasPrice param gasLimit param payer export function buildRemoveAttributeTx ( ontid , key , publicKey , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeAttribute ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const struct = new Struct ( ) ; struct . add ( ontid , str2hexstr ( key ) , publicKey . serializeHex ( ) ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid export function buildGetAttributesTx ( ontid ) { const method = ONTID_METHOD . getAttributes ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const struct = new Struct ( ) ; struct . add ( ontid ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) ) ; return tx ; } param ontid param attributes param signers param gasPrice param gasLimit param payer export function buildAddAttributesByMultiControllerTx ( ontid , attributes , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addAttributesByController ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , attributes . length ) ; for ( const a of attributes ) { const key = str2hexstr ( a . key ) ; const type = str2hexstr ( a . type ) ; const value = str2hexstr ( a . value ) ; struct . add ( key , type , value ) ; } struct . add ( serializeSigners ( signers ) ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param attributes param index param gasPrice param gasLimit param payer export function buildAddAttributesByIndexTx ( ontid , attributes , index , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addAttributesByIndex ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , attributes . length ) ; for ( const a of attributes ) { const key = str2hexstr ( a . key ) ; const type = str2hexstr ( a . type ) ; const value = str2hexstr ( a . value ) ; struct . add ( key , type , value ) ; } struct . add ( index ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param key param signers param gasPrice param gasLimit param payer export function buildRemoveAttributeByMultiControllerTx ( ontid , key , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeAttributeByController ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , str2hexstr ( key ) ) ; struct . add ( serializeSigners ( signers ) ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param key param index param gasPrice param gasLimit param payer export function buildRemoveAttributeByIndexTx ( ontid , key , index , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeAttributeByIndex ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , str2hexstr ( key ) ) ; struct . add ( index ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid export function buildGetDDOTx ( ontid ) { const method = ONTID_METHOD . getDDO ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const struct = new Struct ( ) ; struct . add ( ontid ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) ) ; return tx ; } param ontid param newPk param userKey param controller param gasPrice param gasLimit param payer export function buildAddPubKeyTx ( ontid , newPk , userKey , controller , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addKey ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const p1 = ontid ; const p2 = newPk . serializeHex ( ) ; const p3 = userKey . serializeHex ( ) ; const struct = new Struct ( ) ; struct . add ( p1 , p2 , p3 ) ; struct . add ( str2hexstr ( controller ) ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param newPk param signers param controller param gasPrice param gasLimit param payer export function buildAddKeyByMultiControllerTx ( ontid , newPk , signers , controller , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addKeyByController ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const p1 = ontid ; const p2 = newPk . serializeHex ( ) ; const struct = new Struct ( ) ; struct . add ( p1 , p2 , serializeSigners ( signers ) ) ; if ( controller ) { struct . add ( str2hexstr ( controller ) ) ; } const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param newPk param index param gasPrice param gasLimit param payer export function buildAddKeyByIndexTx ( ontid , newPk , index , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addKeyByIndex ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const p1 = ontid ; const p2 = newPk . serializeHex ( ) ; const struct = new Struct ( ) ; struct . add ( p1 , p2 , index ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param newPk param index param gasPrice param gasLimit param payer export function buildRemoveKeyByIndexTx ( ontid , newPk , index , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeKeyByIndex ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const p1 = ontid ; const p2 = newPk . serializeHex ( ) ; const struct = new Struct ( ) ; struct . add ( p1 , p2 , index ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param newRecovery param index param gasPrice param gasLimit param payer export function buildSetRecoveryTx ( ontid , newRecovery , index , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . setRecovery ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , newRecovery . serialize ( ) , index ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param recovery param signers param gasPrice param gasLimit param payer export function buildUpdateRecoveryTx ( ontid , recovery , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . updateRecovery ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , recovery . serialize ( ) , serializeSigners ( signers ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param newPk param signers param gasPrice param gasLimit param payer export function buildAddKeyByRecoveryTx ( ontid , newPk , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addKeyByRecovery ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , newPk . serializeHex ( ) , serializeSigners ( signers ) ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param pubkeyIndex param signers param gasPrice param gasLimit param payer export function buildRemoveKeyByRecoveryTx ( ontid , pubkeyIndex , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeKeyByRecovery ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , pubkeyIndex , serializeSigners ( signers ) ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param pubkeyIndex param signers param gasPrice param gasLimit param payer export function buildRemoveKeyByMultiControllerTx ( ontid , pubkeyIndex , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeKeyByController ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , pubkeyIndex , serializeSigners ( signers ) ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param pk2Remove param Pk param gasPrice param gasLimit param payer export function buildRemovePubKeyTx ( ontid , pk2Remove , pk , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeKey ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const p1 = ontid ; const p2 = pk2Remove . serializeHex ( ) ; const p3 = pk . serializeHex ( ) ; const struct = new Struct ( ) ; struct . add ( p1 , p2 , p3 ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid export function buildGetPublicKeysTx ( ontid ) { const method = ONTID_METHOD . getPublicKeys ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const struct = new Struct ( ) ; struct . add ( ontid ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) ) ; return tx ; } param ontid param pkId export function buildGetPublicKeyStateTx ( ontid , pkId ) { const method = ONTID_METHOD . getKeyState ; if ( ontid . substr ( 0 , 3 ) === 'did' ) { ontid = str2hexstr ( ontid ) ; } const struct = new Struct ( ) ; struct . add ( ontid , pkId ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) ) ; return tx ; } param ontid param pubkey param controller param signIndex param gasPrice param gasLimit param payer export function buildAddNewAuthKeyTx ( ontid , pubkey , controller , signIndex , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addNewAuthKey ; const struct1 = new Struct ( ) ; struct1 . add ( pubkey . serializeHex ( ) , str2hexstr ( controller ) ) ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , struct1 , signIndex ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param index param signIndex param gasPrice param gasLimit param payer export function buildRemoveAuthKeyTx ( ontid , index , signIndex , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeAuthKey ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , index , signIndex ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param pubkey param controller param signers param gasPrice param gasLimit param payer export function buildAddNewAuthKeyByRecoveryTx ( ontid , pubkey , controller , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addNewAuthKeyByRecovery ; const struct1 = new Struct ( ) ; struct1 . add ( pubkey . serializeHex ( ) , str2hexstr ( controller ) ) ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , struct1 , serializeSigners ( signers ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param index param signers param gasPrice param gasLimit param payer export function buildRemoveAuthKeyByRecoveryTx ( ontid , index , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeAuthKeyByRecovery ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , index , serializeSigners ( signers ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param pubkey param controller param signers param gasPrice param gasLimit param payer export function buildAddNewAuthKeyByControllerTx ( ontid , pubkey , controller , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addNewAuthKeyByController ; const struct1 = new Struct ( ) ; struct1 . add ( pubkey . serializeHex ( ) , str2hexstr ( controller ) ) ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , struct1 , serializeSigners ( signers ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param index param signers param gasPrice param gasLimit param payer export function buildRemoveAuthKeyByControllerTx ( ontid , index , signers , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeAuthKeyByController ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , index , serializeSigners ( signers ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param serviceId param type param serviceEndpoint param index param gasPrice param gasLimit param payer export function buildAddServiceTx ( ontid , serviceId , type , serviceEndpoint , pkIndex , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addService ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , str2hexstr ( serviceId ) , str2hexstr ( type ) , str2hexstr ( serviceEndpoint ) , pkIndex ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param serviceId param type param serviceEndpoint param pkIndex param gasPrice param gasLimit param payer export function buildUpdateServiceTx ( ontid , serviceId , type , serviceEndpoint , pkIndex , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . updateService ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , str2hexstr ( serviceId ) , str2hexstr ( type ) , str2hexstr ( serviceEndpoint ) , pkIndex ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param serviceId param pkIndex param gasLimit param gasPrice param payer export function buildRemoveServiceTx ( ontid , serviceId , pkIndex , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . removeService ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , str2hexstr ( serviceId ) , pkIndex ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param context param pkIndex param gasPrice param gasLimit param payer export function buildAddContextTx ( ontid , context , pkIndex , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addContext ; const struct = new Struct ( ) ; const contexts = context . map ( ( item ) => str2hexstr ( item ) ) ; struct . add ( str2hexstr ( ontid ) ) ; struct . add ( contexts . length ) ; contexts . forEach ( ( item ) => struct . add ( item ) ) ; struct . add ( pkIndex ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param context param pkIndex param gasPrice param gasLimit param payer export function buildRemoveContextTx ( ontid , context , pkIndex , gasPrice , gasLimit , payer ? ) { const method = ONTID_METHOD . addContext ; const struct = new Struct ( ) ; const contexts = context . map ( ( item ) => str2hexstr ( item ) ) ; struct . add ( str2hexstr ( ontid ) ) ; struct . add ( contexts . length ) ; contexts . forEach ( ( item ) => struct . add ( item ) ) ; struct . add ( pkIndex ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , gasPrice , gasLimit , payer ) ; return tx ; } param ontid param keyIndex export function buildVerifySignatureTx ( ontid , keyIndex ) { const method = ONTID_METHOD . verifySignature ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , keyIndex ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , '0' , '0' ) ; return tx ; } param ontid param signers export function buildVerifyMultiControllerTx ( ontid , signers ) { const method = ONTID_METHOD . verifyController ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , serializeSigners ( signers ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , '0' , '0' ) ; return tx ; } param ontid param signers export function buildGetServiceTx ( ontid , serviceId ) { const method = ONTID_METHOD . getService ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) , str2hexstr ( serviceId ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , '0' , '0' ) ; return tx ; } param ontid export function buildGetControllerTx ( ontid ) { const method = ONTID_METHOD . getController ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , '0' , '0' ) ; return tx ; } param ontid export function buildGetDocumentTx ( ontid ) { const method = ONTID_METHOD . getDocument ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , '0' , '0' ) ; return tx ; } export interface DocumentPubKey { id : string ; type : string ; controller : string ; publicKeyHex : string ; } export interface Document { '@context' : [ string ] ; id : string ; publicKey : [ DocumentPubKey ] ; authentication : [ string ] ; controller : string | null ; recovery : string | null ; service : [ any ] ; attribute : [ DDOAttribute ] | null ; created : number ; updated : number ; proof : string ; } export async function getDocumentJson ( ontid , restNode ) { const method = ONTID_METHOD . getDocument ; const struct = new Struct ( ) ; struct . add ( str2hexstr ( ontid ) ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( method , params , new Address ( ONTID_CONTRACT ) , '0' , '0' ) ; const restClient = new RestClient ( restNode ) ; const res = await restClient . sendRawTransaction ( tx . serialize ( ) , true ) ; const str = hexstr2str ( res . Result . Result ) ; const obj = JSON . parse ( str ) ; return obj ; }