import * as blakejs from 'blakejs' ; import { TezosLanguageUtil } from '../TezosLanguageUtil' ; import { TezosNodeReader } from '../TezosNodeReader' ; /**
 *
 */ export namespace TezosContractUtils { param server param address export async function verifyDestination ( server , address , expected ) { const contract = await TezosNodeReader . getAccountForBlock ( server , 'head' , address ) ; if ( ! ! ! contract . script ) { throw new Error ( `No code found at ${ address }` ) ; } const k = Buffer . from ( blakejs . blake2s ( JSON . stringify ( contract . script . code ) , null , 16 ) ) . toString ( 'hex' ) ; if ( k !== expected ) { throw new Error ( `Contract code hash "${ k }" doesn't match expected ${ expected }` ) ; } return true ; } param script export function verifyScript ( script , expected ) { const k = Buffer . from ( blakejs . blake2s ( TezosLanguageUtil . preProcessMichelsonScript ( script ) . join ( '\n' ) , null , 16 ) ) . toString ( 'hex' ) ; if ( k !== expected ) { throw new Error ( `Contract code hash "${ k }" doesn't match expected ${ expected }` ) ; } return true ; } export function clearRPCOperationGroupHash ( hash ) { return hash . replace ( /\"/g , '' ) . replace ( /\n/ , '' ) ; } }