Skip to content

Latest commit

 

History

History
72 lines (47 loc) · 2.16 KB

README.md

File metadata and controls

72 lines (47 loc) · 2.16 KB

How to use zknotary-verifier

This directory contains a Node.js example application that demonstrates how to use the zknotary-verify npm package.

Prerequisites

  • Node.js
  • npm

File Structure

  • index.js: This is the main application file.
  • package.json: This file contains the list of npm dependencies for the application. Among these dependencies we have zknotary-verifier and zknotary-parsers.

Setup

  1. Install the dependencies:
npm install
  1. Run the application
node index.js

Usage

This application demonstrates how to use the zknotary-verifier npm package in a Node.js application.

It takes two inputs:

  • A generic proof of notarization generated by TLSNotary in JSON format.
  • The Notary's public key as a pem file.

First, we need to import the zknotary-verifier package which contains the WebAssembly code that does the actual verification of the proof. We also import the zknotary-parsers package, which provides a utility to parse the text output of the verifier according to specific rules depending on the nature of the notarization. In this particular example, the sample proof corresponds to the notarization of a session with the Twitter API, so we import the Twitter parser.

import * as wasm from "zknotary-verifier";
import { twitter } from "zknotary-parsers";

To learn more about the zknotary-parsers package, please refer to its README file.

Then, we read both the sample proof in JSON format as well as the Notary's public key:

const proof_json = await readFile("./sample_proof.json");
const notary_pubkey = await readFile("./notary.pub");

Finally we execute the verify() function passing as arguments the proof and the public key. We then send to the console the result of the parsing:

try {
  const result = wasm.verify(proof_json, notary_pubkey);
  const parsedData = twitter.parse(result);
  console.log(JSON.stringify(parsedData, null, 2));
} catch (e) {
  console.error("Verification failed:", e);
}

Contributing

Contributions are welcome. Please submit a pull request or create an issue to discuss the changes you want to make.

License

Apache