The LayerZero Proof Utility package provides a set of essential utilities and modules to facilitate the generation and verification of proofs for various blockchain networks. It includes functions for generating receipt proofs, encoding parameters, and handling state-sync transactions.
- Proof Generation: Functions for generating receipt proofs and feather proofs.
- Parameter Encoding: Functions for encoding proof parameters.
- State-Sync Handling: Functions for handling state-sync transactions in Polygon blocks.
To install the LayerZero Proof Utility package, you can use npm or yarn:
npm install @layerzerolabs/lz-proof-utility
or
yarn add @layerzerolabs/lz-proof-utility
Retrieves the receipt proof based on the provided parameters.
import { getReceiptProof } from "@layerzerolabs/lz-proof-utility"
const network = "mainnet"
const block = { /* block object */ }
const transactionReceipts = [ /* array of transaction receipts */ ]
const transactionIndex = 0
const outboundProofType = 1 // MPT
const utilsVersion = 1 // V1
getReceiptProof(network, block, transactionReceipts, transactionIndex, outboundProofType, utilsVersion).then((proof) => {
console.log(`Receipt Proof: ${proof}`)
})
Generates a feather proof based on the utility version.
import { getFeatherProof } from "@layerzerolabs/lz-proof-utility"
const utilsVersion = 1 // V1
const emitterAddress = "0x1234567890abcdef1234567890abcdef12345678"
const packetPayload = "0xabcdef"
const proof = getFeatherProof(utilsVersion, emitterAddress, packetPayload)
console.log(`Feather Proof: ${proof.proof}`)
Encodes the parameters for the proof.
import { encodeParams } from "@layerzerolabs/lz-proof-utility"
const proof = { /* proof object */ }
const outboundProofType = 1 // MPT
const utilsVersion = 1 // V1
const logIndex = 0
const srcEndpointId = 1
const encodedParams = encodeParams(proof, outboundProofType, utilsVersion, logIndex, srcEndpointId)
console.log(`Encoded Params: ${encodedParams}`)
Returns the transaction hash for the state-sync receipt in a Polygon block.
import { getPolygonStateSyncTxHash } from "@layerzerolabs/lz-proof-utility"
const block = { /* block object */ }
const txHash = getPolygonStateSyncTxHash(block)
console.log(`State-Sync Tx Hash: ${txHash}`)
Converts a buffer to a hex string.
import { buffer2hex } from "@layerzerolabs/lz-proof-utility"
const buffer = Buffer.from("example")
const hexString = buffer2hex(buffer)
console.log(`Hex String: ${hexString}`)