The Routing ISM allows usage of different ISMs based on the context of the message being received .
In the context of Ciphertext Routing ISM. Based on the message type it checks whether it is a normal cross chain message or requires Ciphertext to be fetched from an offchain server and accordingly calls the Multisig ISM or the CCIP-read ISM.
Usage
Modification on sender contract
The message being dispatched must be prepended with uint8before the message data.
To Use CCIP Read ISM -The uint8 value should be zero (0) if CCIP-read ISM needs to be used to fetch ciphertext. followed by the hash of ciphertext needed to be fetched from offchain.
abi.encode(uint8(0),Ciphertext_Hash, arbitrary data)
To use normal message passing - The uint8 value should be one (1).
abi.encode(uint8(1), arbitrary data)
Modification on recipient Contract at inco
The logic necessary to execute any functionality other than CCIP needs to be written in the handle function. However if the CCIP ism is being used another handler called handleWithCiphertext needs to be written. as per the standard defined here.
so the code snippet will look something like this
// SPDX-License-Identifier: UNLICENSEDpragmasolidity ^0.8.19;import {IMailbox} from"@hyperlane-xyz/core/contracts/interfaces/IMailbox.sol";import {IPostDispatchHook} from"@hyperlane-xyz/core/contracts/interfaces/hooks/IPostDispatchHook.sol";import {IInterchainSecurityModule} from"@hyperlane-xyz/core/contracts/interfaces/IInterchainSecurityModule.sol";import {Address} from"@openzeppelin/contracts/utils/Address.sol";import {OwnableUpgradeable} from"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";contractCipherTextProcessorisOwnableUpgradeable{ IInterchainSecurityModule public interchainSecurityModule;functionsetInterchainSecurityModule(address_module) public { interchainSecurityModule =IInterchainSecurityModule(_module); }eventhandled (bytes32hash);address mailbox; // address of mailbox contractaddresspublic ISM;constructor(address_mailbox,address_interchainSecurityModule) { mailbox = _mailbox; ISM=_interchainSecurityModule;//Sets CCIP read ISM as ISM to be usedsetInterchainSecurityModule(_interchainSecurityModule); }// Modifier so that only mailbox can call particular functionsmodifieronlyMailbox() {require( msg.sender == mailbox,"Only mailbox can call this function !!!" ); _; }modifieronlyISM() {require( msg.sender == ISM,"Only mailbox can call this function !!!" ); _; }// Handle general message passing here i.e when uint8 value is 1functionhandle( uint32_origin,bytes32_sender,bytesmemory_body)externalonlyMailbox { (uint8 handler)= abi.decode(_body, (uint8));if(handler==1) {// Logic to handle and decode general message passing }emithandled(committedHash); }//**************************************************************************//*************************************************************************// Necessary function to be implemented with no changes as it is called by ISM with metadatafunctionhandleWithCiphertext( uint32_origin,bytes32_sender,bytesmemory_message)externalonlyISM { (bytesmemory message,bytesmemory ciphertext)=abi.decode(_message,(bytes,bytes)); (bytes32 committedHash)= abi.decode(message, (bytes32));//rest of function logic }//**************************************************************************}