import { Schema } from 'effect'; import { HexString } from './binary.js'; /** Current handle version byte, appended as the last byte of every handle. */ export declare const HANDLE_VERSION = 0; /** * Domain separators for handle derivation. Must be kept in sync with Solidity * (contracts/lightning/src/Types.sol) and Go (pkg/hostchain/handle.go). Prefixing every * keccak256 preimage with a unique constant string makes cross-derivation-path * collision resistance structural rather than incidental. */ export declare const SEP_INPUT_HANDLE = "inco/handle/input-handle"; export declare const SEP_INPUT_CONTEXT = "inco/handle/input-context"; export declare const SEP_OP_RESULT = "inco/handle/op-result"; export declare const SEP_ELIST_OP_RESULT = "inco/handle/elist-result"; export declare const BYTE_ELIST_ELEMENT_TYPE_INDEX = 29; /** * Map of ENCRYPTION type names to their integer identifiers. * * Keys provide a semantic interpretation over the underlying integral type. * For example, `ebool` interprets a `uint16` as a boolean, `ebytes64` interprets * a `uint512` as a 64-byte array, etc. */ export declare const handleTypes: Readonly<{ ebool: 0; euint4: 1; euint8: 2; euint16: 3; euint32: 4; euint64: 5; euint128: 6; euint160: 7; euint256: 8; ebytes64: 9; ebytes128: 10; ebytes256: 11; }>; /** Schema that validates a string is one of the known ENCRYPTION type names (e.g. `"ebool"`, `"euint256"`). */ export declare const HandleTypeName: Schema.SchemaClass<"ebool" | "euint4" | "euint8" | "euint16" | "euint32" | "euint64" | "euint128" | "euint160" | "euint256" | "ebytes64" | "ebytes128" | "ebytes256", "ebool" | "euint4" | "euint8" | "euint16" | "euint32" | "euint64" | "euint128" | "euint160" | "euint256" | "ebytes64" | "ebytes128" | "ebytes256", never>; /** A valid ENCRYPTION type name string (e.g. `"ebool"`, `"euint32"`, `"ebytes64"`). */ export type HandleTypeName = typeof HandleTypeName.Type; /** The typeof {@link handleTypes} — mapping from ENCRYPTION type names to integer IDs. */ export type HandleTypes = typeof handleTypes; /** Integer identifier of an ENCRYPTION type (0–11), corresponding to a {@link HandleTypeName}. */ export type TeeType = HandleTypes[keyof HandleTypes]; /** * Type guard that checks whether a number is a valid {@link TeeType} identifier. * @param value - The number to check. * @returns `true` if `value` is a known ENCRYPTION type integer (0–11). */ export declare function isTeeType(value: number): value is TeeType; /** Schema for the context required to compute a deterministic ENCRYPTION handle. */ export declare const InputContext: Schema.Struct<{ hostChainId: typeof Schema.BigInt; aclAddress: Schema.TemplateLiteral<`0x${string}`>; userAddress: Schema.TemplateLiteral<`0x${string}`>; contractAddress: Schema.TemplateLiteral<`0x${string}`>; version: typeof Schema.Number; inputType: typeof Schema.Number; }>; /** Context fields (chain ID, ACL address, user/contract addresses, version, on-chain inputType) used to derive a deterministic handle. */ export type InputContext = typeof InputContext.Type; /** * A 32-byte hex string representing an ENCRYPTION ciphertext handle. * * Format: `keccak_hash[0:29] || index_handle || handle_type || handle_version` * * @see pkg/hostchain/handle.md for the handle format spec. */ export type Handle = HexString; /** * Expected length of a handle in bytes. * Handle format: 29 bytes hash + 1 byte index + 1 byte type + 1 byte version = 32 bytes */ export declare const HANDLE_LENGTH_BYTES = 32; /** * Validates handle integrity by checking format, length, and version. * Matches the validation in Go's HandleFromBytes (pkg/hostchain/handle.go). * @param handle - The handle to validate * @throws Error if handle is malformed (wrong format, length, or unsupported version) */ export declare function validateHandle(handle: HexString): void; /** * Extracts the {@link TeeType} from byte 30 of a validated handle. * @param handle - A 32-byte hex handle string. * @returns The ENCRYPTION type identifier stored in the handle. * @throws If the handle is malformed or contains an invalid ENCRYPTION type. * @see pkg/hostchain/handle.md for the handle format spec. */ export declare function getHandleType(handle: HexString): TeeType; /** * Extracts the elist element {@link TeeType} from byte 29 of a validated handle. * @param handle - A 32-byte hex handle string for an elist. * @returns The ENCRYPTION type identifier of the elist elements. * @throws If the handle is malformed or contains an invalid ENCRYPTION type at byte 29. */ export declare function getEListElementType(handle: HexString): TeeType; /** * Computes the final handle for an input based on the ciphertext and the input context, matches the handle generation * in Go and Solidity. * * @param ciphertext Note this is different from the input which has the external handle prepended * @param indexHandle * @param handleType * @param handleVersion * @param context */ export declare function computeHandle({ ciphertext, indexHandle, handleType, handleVersion, context, }: { ciphertext: Uint8Array; indexHandle: number; handleType: TeeType; handleVersion: number; context: InputContext; }): Buffer; /** * Computes the Keccak-256 hash of an ABI-packed {@link InputContext}. * * The context is packed as: `"evm/" || SEP_INPUT_CONTEXT || HANDLE_VERSION || inputType || * chainId || aclAddress || userAddress || contractAddress || version`. * * @param context - The input context to hash. * @returns A 32-byte `Buffer` containing the Keccak-256 digest. */ export declare function hashInputContext(context: InputContext): Buffer;