npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aligned-script

v0.0.1

Published

Aligned SDK in TypeScript

Downloads

4

Readme

Aligned TS is the TypeScript equivalent of the Aligned Layer Rust SDK.

Table of Contents

Getting Started

AlignedTS is the TypeScript equivalent of the Aligned Layer Rust SDK. It implements all the necessary communication with the Batcher, commitment of data verification data blobs and handles the Batchers response.

Installation Documentation

Build locally

In order to build this project locally, simply clone the repository and run

npm ci
npm run build
npm run test

API Reference

Your main interaction with the SDK will be the getAligned() function, which initiates a new instance of the SDK that you can use to interact with a Batcher.

const getAligned: (address?: string) => Aligned;

address?: string: (Websocket) address of the Batcher you want to interact with. Default: wss://batcher.alignedlayer.com returns Aligned: The Aligned SDK object, see below for more information.

getAligned() returns an object of Aligned, which you will use to interact with the Batcher and your verification data.

type Aligned = {
  submit: (
    verificationData: VerificationData,
    wallet: ethers.Wallet
  ) => Promise<AlignedVerificationData>;
  submitMultiple: (
    verificationData: Array<VerificationData>,
    wallet: ethers.Wallet
  ) => Promise<Array<AlignedVerificationData>>;
  verifyProofOnchain: (
    verificationData: AlignedVerificationData,
    chain: "devnet" | "holesky",
    provide: ethers.Provider
  ) => Promise<any>;
  getDefaultBatcherAddress: () => string;
  getCurrentBatcherAddress: () => string;
  setCurrentBatcherAddress: (address: string) => void;
  getExplorerLink: (batchMerkleRoot: Uint8Array) => string;
  getVerificationKeyCommitment: (vk: Buffer) => string;
};
submit: (verificationData: VerificationData, wallet: ethers.Wallet) =>
  Promise<AlignedVerificationData>;

Description: Submit verification data to the batcher, using a wallet to sign it. Returns verified data.

submitMultiple: (
  verificationData: Array<VerificationData>,
  wallet: ethers.Wallet
) => Promise<Array<AlignedVerificationData>>;

Description: Submits multiple verification data chunks, see submit() for more information.

verifyProofOnchain: (
  verificationData: AlignedVerificationData,
  chain: "devnet" | "holesky",
  provide: ethers.Provider
) => Promise<any>;

Description: Checks that your verification data has been verified on Ethereum. NOTE This function is still lacks parts of the implementation!

getDefaultBatcherAddress: () => string;

Description: Returns the default batcher (websocket) address.

getCurrentBatcherAddress: () => string;

Description: Returns the current batcher (websocket) address.

setCurrentBatcherAddress: (address: string) => void;

Description: Sets the current batcher (websocket) address.

getExplorerLink: (batchMerkleRoot: Uint8Array) => string;

Description: Given a Merkle root, returns the link to the Explorer of the batch that the data was verified in.

getVerificationKeyCommitment: (vk: Buffer) => string;

Description: Gets the commitment (Keccak256 hash) of a verification key.

Example

The verification data you want to send to the Batcher depends on the type of proof system. As an example, we are going to verify a SP1 proof. The example proof is available in the test_files folder.

First of all, import all the necessary functions and types.

import {
  ProvingSystemId,
  getAligned,
  Option,
  VerificationData,
} from "aligned-ts";

Secondly, we have to load the proof and ELF from our local file system, as well as specify some other parameters. Please note that the wallet private key in this case is a pre-funded Holeksy testnet private key!

const proof = fs.readFileSync("test_files/sp1/sp1_fibonacci.proof", null);
const elf = fs.readFileSync("test_files/sp1/sp1_fibonacci.elf", null);

const proofGeneratorAddress = "0x66f9664f97F2b50F62D13eA064982f936dE76657";
const wallet = new ethers.Wallet(
  "0x7d2647ad2e1f6c1dce5abe2b5c3b9c8ecfe959e40b989d531bbf6624ff1c62df"
);

After that, we can define the VerificationData object that we want to send:

let sp1Data: VerificationData = {
  provingSystem: ProvingSystemId.SP1, // the proving system, in this case SP1
  proof, // the proof
  publicInput: Option.None, // no public input in this case
  verificationKey: Option.None, // no verification key in this case
  vmProgramCode: Option.from(elf), // the vm program code (ELF)
  proofGeneratorAddress, // the proof generator address
};

Initiate the Aligned object:

const Alignment = getAligned();

and send the data to the batcher and wait for its response:

const alignedData = await Alignment.submit(sp1Data, wallet);
console.log(alignedData);

get the link to the explorer:

console.log(Alignment.getExplorerLink(alignedData[0].batchMerkleRoot));
// > https://explorer.alignedlayer.com/batches 0x065f95c19a9c0ccac97c482a864cab41db6a9d0b1652ccfad96d182df5d0ec73

For more examples take a look at the tests folder!