Git Product home page Git Product logo

http-prover's Introduction

Prover SDK

The Prover SDK is a Rust library for interacting with the Prover service. It provides functionality for authentication, proving, and error handling.

Generating access keys

Before using the prover key has to be authorized by the prover operator. To generate the key use:

cargo run --bin keygen

It will output 2 keys.

  • send the public key to the prover operator
  • pass the private key to the sdk to use it.

Using in code

First parse a private key corresponding to an authorized public key.

ProverAccessKey::from_hex_string(
    "0xf91350db1ca372b54376b519be8bf73a7bbbbefc4ffe169797bc3f5ea2dec740",
)
.unwrap()

Then construct an instance with

let prover_url = Url::parse("http://localhost:3000").unwrap();
let sdk = ProverSDK::new(key, prover_url).await?;

Then you can use below to prove an execution

let data = load_cairo1(PathBuf::from("../prover/resources/input_cairo1.json")).await?;
let proof = sdk.prove_cairo1(data).await;

Operating a prover

To run the sdk first make sure prover/authorized_keys.json contains your public_key.

Run the following command in your terminal:

cargo run -p prover -- --jwt-secret-key <ENV_VAR_JWT_SECRET_KEY> --message-expiration-time <MESSAGE_EXPIRATION_TIME> --session-expiration-time <SESSION_EXPIRATION_TIME> --authorized-keys <AUTHORIZED_KEY>,<ANOTHER_KEY>

Alternatively use the flag --authorized-keys-path authorized_keys.json instead of --authorized-keys to load keys from a json file. It needs to have the format below

["<AUTHORIZED_KEY>", "<ANOTHER_KEY>"]

Note: Tests from the sdk lib.rs file should be run separately.

Using sdk

Run command below to generate keys. Pass the public key to operator, after he includes it to the prover you will be able to use sdk.

cargo run --bin keygen

Usage

To use the SDK, follow these steps:

Authenticate with the Prover service using your private key and the authentication URL:

#[tokio::main]
async fn main() -> Result<(), ProverSdkErrors> {
    let private_key_hex : String= env::var("PRIVATE_KEY")?;
    let url_auth =  "http://localhost:3000/auth";
    let url_prover = "http://localhost:3000/prove/cairo1";

    let result = ProverSDK::new(url_auth, url_prover)
        .auth(&private_key_hex)
        .await?;

    // Handle authentication result
    Ok(())
}

Use the SDK to prove data:

#[tokio::main]
async fn main() -> Result<(), ProverSdkErrors> {
    // Authentication code goes here...

    let sdk = result.build()?;
    let data = read_json_file("resources/input.json").await?;
    let proof = sdk.prove(data).await?;

    // Handle proof result
    Ok(())
}

Handle errors using the provided error types:

#[tokio::main]
async fn main() -> Result<(), ProverSdkErrors> {
    // Authentication code goes here...

    let result = ProverSDK::new(url_auth, url_prover)
        .auth(&private_key_hex)
        .await;

    match result {
        Ok(sdk) => {
            // Continue with SDK usage...
        }
        Err(err) => {
            // Handle authentication error
            println!("Authentication failed: {}", err);
        }
    }

    Ok(())
}

http-prover's People

Contributors

matzayonc avatar chudkowsky avatar adampalkowski avatar neotheprogramist avatar steebchen avatar piniom avatar glihm avatar

Watchers

Lucian avatar Yun avatar clicksave avatar Tarrence van As avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.