tlsn-js
v0.1.0-alpha.12.0
Published
![MIT licensed][mit-badge] ![Apache licensed][apache-badge]
Readme
tlsn-js
NPM modules for proving and verifying using TLSNotary in the browser.
[!IMPORTANT]
tlsn-jsis developed specifically for browser environments and does not work in Node.js.
[!IMPORTANT] The primary goal of
tlsn-jsis to support the development of the TLSNotary browser extension.
Please do not treat this as a public API (yet).
License
This repository is licensed under either:
...at your option.
Examples
tlsn-js can be used in several modes depending on your use case.
The ./demo folder contains three demos:
react-ts-webpack: Create an attestation with a Notary and render the result.interactive-demo: Prove data interactively to a Verifier.web-to-web-p2p: Prove data between two browser peers.
Running a Local WebSocket Proxy
In the demos, we attest data from https://raw.githubusercontent.com. Since browsers do not support raw TCP connections, a WebSocket proxy is required:
Install wstcp:
| Tool | Command | | ------ | ----------------------------- | | cargo |
cargo install wstcp| | brew |brew install wstcp| | source | https://github.com/sile/wstcp |Run a WebSocket proxy for
https://raw.githubusercontent.com:wstcp --bind-addr 127.0.0.1:55688 raw.githubusercontent.com:443
Install as NPM Package
npm install tlsn-jsDevelopment
This library wraps the tlsn-wasm module.
To work on both tlsn-wasm and tlsn-js locally, update package.json:
"tlsn-wasm": "./tlsn-wasm/pkg"Then build tlsn-wasm:
npm run build:wasmNext:
npm install
npm run testℹ️ To switch back to the npm-published version of
tlsn-wasm, delete or resetpackage-lock.jsonto remove the local path reference.
Build for NPM
npm install
npm run buildTesting
Testing is slightly complex due to the need for browser-based workers.
- Tests live in the
test/directory. - The
tests/directory contains a Playwright test runner that opens a Chromium browser and runs the actual test page.
Some tests require a running Notary. You can start one via Docker:
npm run notaryAdding a New tlsn-js Test
Create a
new-test.spec.tsfile in thetest/directory.Add your spec file to the
entryobject inwebpack.web.dev.config.js.Create a corresponding
new-test.spec.tsfile in theplaywright-test/directory.Add an
expect()call for it intests/test.spec.ts.
Testing the Demos
Playwright is also used to test the demos.
npm install
npm run testView tests in the browser:
npx playwright test --uiDebug tests:
npx playwright test --debug
