GithubHelp home page GithubHelp logo

client's Introduction

Witness Client

Features

Witness Client: A client for interacting with Witness.

  • Fetch-based client built on OpenAPI specification
  • Supports customizing fetch function for different environments
  • Configurable with API key and custom RPC URL
  • Verifies proofs against the chain

Usage

bun add @witnessco/client
import { WitnessClient } from '@witnessco/client'

// Instantiate a new client, default params should suffice for now.
const witness = new WitnessClient()

// Unique string, so we get an unseen leafHash.
const sampleString = `Check the chain! @ ${Date.now()}`
const leafHash = witness.hash(sampleString)

console.log(`Posting leaf hash ${leafHash}`)
await witness.postLeaf(leafHash)
console.log('Waiting for onchain inclusion (may take up to 10min)')
await witness.waitForCheckpointedLeafHash(leafHash)

// Get the timestamp for the leaf.
const timestamp = await witness.getTimestampForLeafHash(leafHash)
console.log(`Leaf ${leafHash} was timestamped at ${timestamp}`)

// Get and verify proof.
const proof = await witness.getProofForLeafHash(leafHash)
const verified = await witness.verifyProofChain(proof)
console.log(`Proof verified: ${verified}`)

See this repl for a live example.

Contract Deployments

Canonical deployments for Witness.sol are available as follows:

Chain ID Deployment Address
Mainnet (1) 0x0000000e143f453f45B2E1cCaDc0f3CE21c2F06a
Base (8453) 0x0000000e143f453f45B2E1cCaDc0f3CE21c2F06a
Optimism (10) 0x0000000e143f453f45B2E1cCaDc0f3CE21c2F06a
Sepolia (11155111) 0x00000008bcf12Eeb9E4162687D6D251f0F4e7FC2
Base Sepolia (84532) 0x0000000159C8253802551eEaf8b475db1A50d712
Optimism Sepolia (11155420) 0x0000000a3fa5CFe56b202F376cCa7334c93aEB8b
Arbitrum Sepolia (421614) 0x00000006399970c8bdad606abD03b1712974E4eA
Gnosis Chiado (10200) 0x000000031C0d9df77F390CED953219E561B67089

See the contracts-core repo for more details.

More Info

See docs.witness.co for more background on Witness, or the contracts-core repo for more details on the contracts.

Built With

client's People

Contributors

0xosprey avatar github-actions[bot] avatar mw2000 avatar sina-wit avatar sinasab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

client's Issues

postLeafAndGetTimestamp sometimes crashes

It seems like the server sometimes replies with an error page <!DOCTYPE html>..., which postLeafAndGetTimestamp in WitnessClient doesn't handle, and a SyntaxError is thrown to the application.

Steps to reproduce (happens maybe 1 out of 1000 calls or so):

const witness = new WitnessClient(process.env.WITNESS_API_KEY);
const leafHash = witness.hash("...");
let timestamp = await witness.postLeafAndGetTimestamp(leafHash);

Result:

undefined:1
<!DOCTYPE html>
^

SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
    at JSON.parse (<anonymous>)
    at parseJSONFromBytes (node:internal/deps/undici/undici:5584:19)
    at successSteps (node:internal/deps/undici/undici:5555:27)
    at fullyReadBody (node:internal/deps/undici/undici:1665:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async specConsumeBody (node:internal/deps/undici/undici:5564:7)
    at async w.getLatestOnchainCheckpoint (/home/olof_andersson/dkim-lookup/dkim-lookup-app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@witnessco/client/dist/index.cjs:1:10868)
    at async w.waitForCheckpointedLeafHash (/home/olof_andersson/dkim-lookup/dkim-lookup-app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@witnessco/client/dist/index.cjs:1:8828)
    at async w.postLeafAndGetTimestamp (/home/olof_andersson/dkim-lookup/dkim-lookup-app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@witnessco/client/dist/index.cjs:1:9550)
    at async generateWitness (/home/olof_andersson/dkim-lookup/dkim-lookup-app/src/lib/generateWitness.ts:2:1306)

getProofForLeafHash crashes when rate limit is reached

When the rate limit hits, getProofForLeafHash in WitnessClient doesn't handle the error response from the server, and a SyntaxError is thrown to the application.

Steps to reproduce (happens when the rate limit is reached):

const witness = new WitnessClient(process.env.WITNESS_API_KEY);
const leafHash = witness.hash("...");
const proof = await witness.getProofForLeafHash(leafHash);

Result:

undefined:1
local_rate_limited
^

SyntaxError: Unexpected token 'l', "local_rate_limited" is not valid JSON
    at JSON.parse (<anonymous>)
    at parseJSONFromBytes (node:internal/deps/undici/undici:5329:19)
    at successSteps (node:internal/deps/undici/undici:5300:27)
    at fullyReadBody (node:internal/deps/undici/undici:1447:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async specConsumeBody (node:internal/deps/undici/undici:5309:7)
    at async w.getProofForLeafHash (/home/olof/checkout/zk/dkim-lookup/dkim-lookup-app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@witnessco/client/dist/index.cjs:1:11722)
    at generateWitness (/home/olof/checkout/zk/dkim-lookup/dkim-lookup-app/src/lib/generateWitness.ts:19:16)

TypeError in WitnessClient constructor

I just updated to Witness 0.4.1 and it seems there is now a new crash when instantiating WitnessClient.

Versions:
@witnessco/client: 0.4.1
viem: 2.10.8

Steps:
new WitnessClient(process.env.WITNESS_API_KEY);

Result:

TypeError: (0 , w.default) is not a function
    at A (/home/olof/checkout/zk/dkim-lookup/dkim-lookup-app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@witnessco/client/dist/index.cjs:1:9126)
    at new k (/home/olof/checkout/zk/dkim-lookup/dkim-lookup-app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@witnessco/client/dist/index.cjs:1:9649)
    at generateWitness (/home/olof/checkout/zk/dkim-lookup/dkim-lookup-app/src/lib/generateWitness.ts:8:18)
    at <anonymous> (/home/olof/checkout/zk/dkim-lookup/dkim-lookup-app/src/lib/utils_server.ts:70:3)
    at Array.forEach (<anonymous>)
    at addDomainSelectorPair (/home/olof/checkout/zk/dkim-lookup/dkim-lookup-app/src/lib/utils_server.ts:69:17)
    at process_line (/home/olof/checkout/zk/dkim-lookup/dkim-lookup-app/scripts/add_dsps.ts:13:15)
    at main (/home/olof/checkout/zk/dkim-lookup/dkim-lookup-app/scripts/add_dsps.ts:34:4)

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.