Skip to content

clealabs/stwo-cairo-ts

Repository files navigation

S-two Cairo TS npm npm downloads Build status

This is a Typescript library compatible with cairo-prove. It targets modern browsers supporting the Memory64 WebAssembly feature.

Installation

npm i stwo-cairo

Server settings

All responses from your app must send these headers to satisfy the browser security requirements for SharedArrayBuffer:

Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin

Usage

Executing and generating a proof of execution for a compiled Cairo program:

import { init, execute, containsPedersenBuiltin, prove } from "stwo-cairo";

init(); // optional: call this on page load

const executable = "..."; // Cairo executable JSON string
const args = [1n, 2n]; // arguments for the program

const prover_input = await execute(executable, ...args); // the execution trace
const with_pedersen = containsPedersenBuiltin(prover_input); // for the verifier
const proof = await prove(prover_input); // the generated Cairo proof

Verifying a proof:

import { verify } from "stwo-cairo";

const verdict = await verify(proof, with_pedersen); // whether the proof is valid

Development

Build the rust Wasm package

Make sure you have rust installed on your computer and run:

pnpm run build:wasm

Run tests

pnpm run test:browser

About

A Typescript library for stwo-cairo using Wasm64

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors