@layerzerolabs/lz-proof-utility
TypeScript icon, indicating that this package has built-in type declarations

3.0.17 • Public • Published

@layerzerolabs/lz-proof-utility

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.

Features

  • 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.

Installation

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

Usage

Proof Generation

getReceiptProof

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}`)
})

getFeatherProof

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}`)

Parameter Encoding

encodeParams

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}`)

State-Sync Handling

getPolygonStateSyncTxHash

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}`)

Utility Functions

buffer2hex

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}`)

Readme

Keywords

none

Package Sidebar

Install

npm i @layerzerolabs/lz-proof-utility

Weekly Downloads

369

Version

3.0.17

License

BUSL-1.1

Unpacked Size

145 kB

Total Files

9

Last publish

Collaborators

  • layerzero-bot