Skip to content

Commit 910c1f9

Browse files
committed
Improved readme
1 parent f224543 commit 910c1f9

File tree

1 file changed

+83
-33
lines changed

1 file changed

+83
-33
lines changed

readme.md

Lines changed: 83 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
1-
![MIT licensed][mit-badge]
1+
![MIT licensed][mit-badge]
22
![Apache licensed][apache-badge]
33

4-
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
4+
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
55
[apache-badge]: https://img.shields.io/github/license/saltstack/salt
66

77
# tlsn-js
88

9-
NPM Modules for proving and verifying using TLSNotary in the browser.
10-
11-
The prover requires a [notary-server](https://github.com/tlsnotary/notary-server) and a websocket proxy.
9+
NPM modules for proving and verifying using TLSNotary in the browser.
1210

1311
> [!IMPORTANT]
14-
> The primary purpose of `tlsn-js` is to support the development of the [TLSNotary browser extension](https://github.com/tlsnotary/tlsn-extension/).
15-
> **Please do not treat this as a public API (yet).**
12+
> `tlsn-js` is developed specifically for **browser environments** and does **not** work in Node.js.
1613
1714
> [!IMPORTANT]
18-
> `tlsn-js` is developed for the usage of TLSNotary **in the Browser**. This module does not work in `nodejs`.
15+
> The primary goal of `tlsn-js` is to support the development of the [TLSNotary browser extension](https://github.com/tlsnotary/tlsn-extension/).
16+
> **Please do not treat this as a public API (yet).**
1917
2018
## License
21-
This repository is licensed under either of
19+
20+
This repository is licensed under either:
2221

2322
- [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
24-
- [MIT license](http://opensource.org/licenses/MIT)
23+
- [MIT License](http://opensource.org/licenses/MIT)
2524

26-
at your option.
25+
...at your option.
2726

2827
## Examples
2928

30-
`tlsn-js` can be used in many different modes, depending on your use case.
29+
`tlsn-js` can be used in several modes depending on your use case.
3130

32-
The `./demo` folder contains three demos of `tlsn-js`:
31+
The `./demo` folder contains three demos:
3332

34-
* `react-ts-webpack`: create an attestation with a Notary and render the result.
35-
* `interactive-demo`: prove data interactively to a Verifier.
36-
* `web-to-web-p2p`: prove data between two peers, in the browser.
33+
- `react-ts-webpack`: Create an attestation with a Notary and render the result.
34+
- `interactive-demo`: Prove data interactively to a Verifier.
35+
- `web-to-web-p2p`: Prove data between two browser peers.
3736

38-
## Running a local websocket proxy
37+
## Running a Local WebSocket Proxy
3938

40-
In the demos, we attest data from `https://raw.githubusercontent.com`. Because the browser does not allow for TCP connections, you need to set up a websocket proxy:
39+
In the demos, we attest data from `https://raw.githubusercontent.com`. Since browsers do not support raw TCP connections, a WebSocket proxy is required:
4140

4241
1. Install [wstcp](https://github.com/sile/wstcp):
4342

@@ -47,33 +46,42 @@ In the demos, we attest data from `https://raw.githubusercontent.com`. Because t
4746
| brew | `brew install wstcp` |
4847
| source | https://github.com/sile/wstcp |
4948

50-
2. Run a websocket proxy for `https://raw.githubusercontent.com`:
51-
```sh
52-
wstcp --bind-addr 127.0.0.1:55688 raw.githubusercontent.com:443
53-
```
49+
2. Run a WebSocket proxy for `https://raw.githubusercontent.com`:
50+
51+
```sh
52+
wstcp --bind-addr 127.0.0.1:55688 raw.githubusercontent.com:443
53+
```
54+
5455
## Install as NPM Package
5556

5657
```sh
5758
npm install tlsn-js
5859
```
5960

60-
# Development
61+
## Development
6162

62-
This library is a JS wrapper for `tlsn-wasm`.
63+
This library wraps the `tlsn-wasm` module.
6364

64-
To work on `tlsn-wasm` and `tlsn-js` at the same time, replace the "tlsn-wasm" dependency in `package.json` with:
65+
To work on both `tlsn-wasm` and `tlsn-js` locally, update `package.json`:
66+
67+
```json
68+
"tlsn-wasm": "./tlsn-wasm/pkg"
6569
```
66-
"tlsn-wasm": "./tlsn-wasm/pkg"
70+
71+
Then build `tlsn-wasm`:
72+
73+
```sh
74+
npm run build:wasm
6775
```
68-
and run `npm run build:wasm` to build `tlsn-wasm` locally.
6976

70-
Next, run:
77+
Next:
78+
7179
```sh
7280
npm install
7381
npm run test
7482
```
7583

76-
Note: if you want to switch back to a build with the version from npm, make sure to reset/remove `package-lock.json`, or it will keep using the local link.
84+
> ℹ️ To switch back to the npm-published version of `tlsn-wasm`, delete or reset `package-lock.json` to remove the local path reference.
7785

7886
## Build for NPM
7987

@@ -82,9 +90,51 @@ npm install
8290
npm run build
8391
```
8492

85-
## Adding a new test
86-
1. Create a new `new-test.spec.ts` file in the `test/` directory.
87-
2. Add your spec file to the entry object in `webpack.web.dev.config.js`.
88-
3. Add a new `div` block to `test/test.ejs` like this: `<div>Testing "new-test":<div id="new-test"></div></div>`. The `div` id must be the same as the filename.
93+
## Testing
94+
95+
Testing is slightly complex due to the need for browser-based workers.
96+
97+
- Tests live in the `test/` directory.
98+
- The `tests/` directory contains a Playwright test runner that opens a Chromium browser and runs the actual test page.
99+
100+
Some tests require a running Notary. You can start one via Docker:
101+
102+
```sh
103+
npm run notary
104+
```
105+
106+
### Adding a New `tlsn-js` Test
107+
108+
1. Create a `new-test.spec.ts` file in the `test/` directory.
109+
2. Add your spec file to the `entry` object in `webpack.web.dev.config.js`.
110+
3. Update `test/test.ejs` with a block like:
111+
112+
```html
113+
<div>
114+
Testing "new-test":
115+
<div id="new-test" data-testid="new-test"></div>
116+
</div>
117+
```
118+
119+
The `div` ID must match the filename.
120+
121+
4. Add an `expect()` call for it in `tests/test.spec.ts`.
122+
123+
### Testing the Demos
124+
125+
Playwright is also used to test the demos.
126+
127+
```sh
128+
npm install
129+
npm run test
130+
```
89131
132+
- View tests in the browser:
133+
```sh
134+
npx playwright test --ui
135+
```
90136
137+
- Debug tests:
138+
```sh
139+
npx playwright test --debug
140+
```

0 commit comments

Comments
 (0)