UNPKG

@hyperlane-xyz/sdk

Version:

The official SDK for the Hyperlane Network

73 lines 2.43 kB
import { BigNumber, utils } from 'ethers'; import { z } from 'zod'; import { addressToBytes32, fromHexString, toHexString, } from '@hyperlane-xyz/utils'; import { ZHash } from '../../metadata/customZodTypes.js'; export function encodeIcaCalls(calls, salt) { return (salt + utils.defaultAbiCoder .encode(['tuple(bytes32 to,uint256 value,bytes data)[]'], [ calls.map((c) => ({ to: addressToBytes32(c.to), value: c.value || 0, data: c.data, })), ]) .slice(2)); } export function normalizeCalls(calls) { return calls.map((call) => ({ to: addressToBytes32(call.to), value: BigNumber.from(call.value || 0), data: call.data, })); } export function commitmentFromIcaCalls(calls, salt) { return utils.keccak256(encodeIcaCalls(calls, salt)); } /** * Format of REVEAL message: * [ 0: 1] MessageType.REVEAL (uint8) * [ 1: 33] ICA ISM (bytes32) * [ 33: 65] Commitment (bytes32) */ export function commitmentFromRevealMessage(message) { const messageBuffer = fromHexString(message); // Validate minimum length (65 bytes: 1 byte type + 32 bytes ISM + 32 bytes commitment) if (messageBuffer.length < 65) { throw new Error(`Invalid reveal message: expected at least 65 bytes, got ${messageBuffer.length} bytes`); } // Extract commitment from bytes 33-65 (32 bytes) const commitment = messageBuffer.subarray(33, 65); return toHexString(commitment); } const PostCallsBaseSchema = z.object({ calls: z .array(z.object({ to: ZHash, data: z.string(), value: z.string().optional(), })) .min(1), relayers: z.array(ZHash), salt: ZHash, ismOverride: ZHash.optional(), originDomain: z.number(), }); // Legacy shape: ICA derived from dispatch tx receipt events const PostCallsLegacySchema = PostCallsBaseSchema.extend({ commitmentDispatchTx: ZHash, }); // New shape: ICA derived directly from destination + owner const PostCallsIcaSchema = PostCallsBaseSchema.extend({ destinationDomain: z.number(), owner: ZHash, userSalt: ZHash.optional(), }); export const PostCallsSchema = z.union([ PostCallsIcaSchema, PostCallsLegacySchema, ]); export function isPostCallsIca(data) { return 'destinationDomain' in data && 'owner' in data; } //# sourceMappingURL=icaCalls.js.map