Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@layerzerolabs/lz-foundation

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@layerzerolabs/lz-foundation

LayerZero Core Library

  • 3.0.27
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@layerzerolabs/lz-foundation

The LayerZero Foundation package provides essential functions and interfaces for chain interoperability. It includes utilities for signing, hashing, and managing key pairs.

Features

  • Address Utilities: Functions for manipulating addresses of different chains.
  • Base Utilities: General-purpose utility functions.
  • Signing: Sign messages and transactions using different algorithms.
  • Hashing: Compute various cryptographic hashes.
  • Key Management: Generate and manage key pairs.

Installation

To install the LayerZero Foundation package, you can use npm or yarn:

npm install @layerzerolabs/lz-foundation

or

yarn add @layerzerolabs/lz-foundation

Usage

Address Utilities

Gets the human-readable address.

import { aptos } from "@layerzerolabs/lz-foundation"

const address = "0x1234567890abcdef1234567890abcdef12345678"
const addr = aptos.Address.from(address)
const hr = addr.hr()
console.log(`human-readable address: ${hr}`)

Base Utilities

Encodes a string or Uint8Array to a base58 string.

import { base58 } from "@layerzerolabs/lz-foundation"

const msg = "hello"
const encode = base58.encode(msg)
console.log(`base58 encoded message: ${encode}`)

Hashing

Computes the Keccak-256 hash of the given message.

  • message: The input message to hash.
  • Returns: The Keccak-256 hash of the input message.
import { keccak_256 } from "@layerzerolabs/lz-foundation"

const message = "Hello, world!"
const hash = keccak_256(message)
console.log(`Keccak-256 Hash: ${Buffer.from(hash).toString("hex")}`)

Signing

Signs a hash using the specified signing algorithm.

  • hash: The hash to sign, must be 32 bytes long.
  • privateKey: The private key in hex format or Uint8Array.
  • algorithm: The signing algorithm to use.
  • Returns: A promise that resolves to the signature.
import { signHash, SignAlgorithm } from "@layerzerolabs/lz-foundation"

const hash = new Uint8Array(32) // Example hash
const privateKey = "0xYourPrivateKey"
const algorithm = SignAlgorithm.SECP256K1

signHash(hash, privateKey, algorithm).then((signature) => {
  console.log(`Signature: ${Buffer.from(signature).toString("hex")}`)
})

Key Management

Interface representing a key pair consisting of a private key and a public key.

  • privateKey: The private key as a Uint8Array.
  • publicKey: The public key as a Uint8Array.
import { KeyPair } from "@layerzerolabs/lz-foundation"

const keyPair: KeyPair = {
  privateKey: new Uint8Array(32), // Example private key
  publicKey: new Uint8Array(32), // Example public key
}

console.log(`Private Key: ${Buffer.from(keyPair.privateKey).toString("hex")}`)
console.log(`Public Key: ${Buffer.from(keyPair.publicKey).toString("hex")}`)

FAQs

Package last updated on 11 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc