fix(wasm): change commit_sent to commit_recv (#23)

* fix(wasm): change commit_sent to commit_recv

* fix: fix tests (alpha4)

* test: Test redactions

* fix: skip puppeteer chrome install

* chore: fix linter

---------

Co-authored-by: Hendrik Eeckhaut <hendrik@eeckhaut.org>
This commit is contained in:
tsukino
2024-02-22 10:54:35 -05:00
committed by GitHub
parent 9eeb1914af
commit bc93d4e46b
14 changed files with 14777 additions and 59 deletions

View File

@@ -6,6 +6,9 @@ on:
pull_request:
branches: [ main ]
env:
PUPPETEER_SKIP_DOWNLOAD: true
jobs:
build:

View File

@@ -9,6 +9,7 @@ on:
env:
LOCAL: true
HEADLESS: true
PUPPETEER_SKIP_DOWNLOAD: true
jobs:
build:

1
.gitignore vendored
View File

@@ -5,7 +5,6 @@ wasm-pack.log
node_modules/
.idea/
.DS_Store
pnpm-lock.yaml
build/
dev-build/
test-build/

View File

@@ -2,7 +2,7 @@ import React, { ReactElement, useCallback, useEffect, useState } from 'react';
import { createRoot } from 'react-dom/client';
import { prove, verify } from 'tlsn-js';
import { Proof } from 'tlsn-js/build/types';
import { Watch } from 'react-loader-spinner'
import { Watch } from 'react-loader-spinner';
const container = document.getElementById('root');
const root = createRoot(container!);
@@ -47,40 +47,41 @@ function App(): ReactElement {
</button>
<div>
<b>Proof: </b>
{!processing && !proof
? <i>not started</i>
: !proof
? <>
Proving data from swapi...
<Watch
visible={true}
height="40"
width="40"
radius="48"
color="#000000"
ariaLabel="watch-loading"
wrapperStyle={{}}
wrapperClass=""
/>
Open <i>Developer tools</i> to follow progress
</>
: <>
<details>
<summary>View Proof</summary>
<pre>{JSON.stringify(proof, null, 2)}</pre>
</details>
</>
}
{!processing && !proof ? (
<i>not started</i>
) : !proof ? (
<>
Proving data from swapi...
<Watch
visible={true}
height="40"
width="40"
radius="48"
color="#000000"
ariaLabel="watch-loading"
wrapperStyle={{}}
wrapperClass=""
/>
Open <i>Developer tools</i> to follow progress
</>
) : (
<>
<details>
<summary>View Proof</summary>
<pre>{JSON.stringify(proof, null, 2)}</pre>
</details>
</>
)}
</div>
<div>
<b>Verification: </b>
{!proof
? <i>not started</i>
: !result
? <i>verifying</i>
: <pre>{JSON.stringify(result, null, 2)}</pre>
}
{!proof ? (
<i>not started</i>
) : !result ? (
<i>verifying</i>
) : (
<pre>{JSON.stringify(result, null, 2)}</pre>
)}
</div>
</div>
);

View File

@@ -1,6 +1,6 @@
var webpack = require('webpack'),
path = require("path"),
CopyWebpackPlugin = require("copy-webpack-plugin"),
path = require('path'),
CopyWebpackPlugin = require('copy-webpack-plugin'),
HtmlWebpackPlugin = require('html-webpack-plugin');
const ASSET_PATH = process.env.ASSET_PATH || '/';
@@ -80,8 +80,8 @@ var options = {
new CopyWebpackPlugin({
patterns: [
{
from: "node_modules/tlsn-js/build",
to: path.join(__dirname, "build"),
from: 'node_modules/tlsn-js/build',
to: path.join(__dirname, 'build'),
force: true,
},
],

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "tlsn-js",
"version": "v0.1.0-alpha.3-rc2",
"version": "v0.1.0-alpha.4",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "tlsn-js",
"version": "v0.1.0-alpha.3-rc2",
"version": "v0.1.0-alpha.4",
"license": "ISC",
"dependencies": {
"comlink": "^4.4.1"

8495
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -6,12 +6,16 @@ export interface Proof {
export interface Session {
header: Header;
server_name: ServerName;
signature: Signature;
handshake_data_decommitment: HandshakeDataDecommitment;
session_info: SessionInfo;
}
export interface HandshakeDataDecommitment {
export interface SessionInfo {
server_name: ServerName;
handshake_decommitment: HandshakeDecommitment;
}
export interface HandshakeDecommitment {
nonce: number[];
data: Data;
}
@@ -25,7 +29,7 @@ export interface Data {
export interface ServerCERTDetails {
cert_chain: Array<number[]>;
ocsp_response: any[];
ocsp_response: number[];
scts: null;
}

File diff suppressed because one or more lines are too long

View File

@@ -2,10 +2,12 @@ import { prove, verify } from '../src';
(async function () {
try {
// @ts-ignore
console.log('test start');
console.time('prove');
const proof = await prove('https://swapi.dev/api/people/1', {
method: 'GET',
headers: { secret: 'test_secret' },
maxTranscriptSize: 16384,
notaryUrl: process.env.LOCAL
? 'http://localhost:7047'
@@ -13,6 +15,8 @@ import { prove, verify } from '../src';
websocketProxyUrl: process.env.LOCAL
? 'ws://localhost:55688'
: 'wss://notary.pse.dev/proxy?token=swapi.dev',
secretHeaders: ['test_secret'],
secretResps: ['blond', 'fair'],
});
console.timeEnd('prove');

View File

@@ -5,23 +5,14 @@ import simple_proof_redacted from './assets/simple_proof_redacted.json';
try {
const pem = `-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBv36FI4ZFszJa0DQFJ3wWCXvVLFr\ncRzMG5kaTeHGoSzDu6cFqx3uEWYpFGo6C0EOUgf+mEgbktLrXocv5yHzKg==\n-----END PUBLIC KEY-----`;
const proof = {
notaryUrl: 'http://localhost:7047',
...simple_proof_redacted,
notaryUrl: 'http://localhost:7047',
};
console.log(proof);
console.time('verify');
const result = await verify(proof, pem);
console.timeEnd('verify');
// assert(result.serverName === 'example.com');
// assert(
// result.sent.includes(
// 'user-agent: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
// ),
// );
// assert(result.sent.includes('<h1>XXXXXXXXXXXXXX</h1'));
console.log(result);
// @ts-ignore
document.getElementById('simple-verify').textContent =
JSON.stringify(result);

View File

@@ -12,8 +12,12 @@
<script>
global = globalThis //<- this should be enough
</script>
<div id="full-integration-swapi"></div>
<div id="simple-verify"></div>
<div>Testing "full-integration-swapi":
<div id="full-integration-swapi"></div>
</div>
<div>Testing "simple-verify":
<div id="simple-verify"></div>
</div>
</body>
</html>

View File

@@ -31,12 +31,22 @@ describe('tlsn-js test suite', function () {
it('should prove and verify swapi.dev', async function () {
const content = await check('full-integration-swapi');
const result = safeParseJson(content);
assert(result);
assert(result.sent.includes('host: swapi.dev'));
assert(result.sent.includes('secret: XXXXXXXXXXX'));
assert(result.recv.includes('Luke Skywalker'));
assert(result.recv.includes('"hair_color":"XXXXX"'));
assert(result.recv.includes('"skin_color":"XXXX"'));
});
it('should verify', async function () {
const content = await check('simple-verify');
const result = safeParseJson(content);
assert(
result.sent.includes(
'user-agent: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
),
);
assert(result.recv.includes('<h1>XXXXXXXXXXXXXX</h1>'));
assert(result);
});
});
@@ -48,7 +58,7 @@ async function check(testId: string): Promise<string> {
return check(testId);
}
function safeParseJson(data: string): string | null {
function safeParseJson(data: string): any | null {
try {
return JSON.parse(data);
} catch (e) {

View File

@@ -414,7 +414,7 @@ pub async fn prover(
recv_private_ranges.iter().try_for_each(|range| {
builder
.commit_sent(range)
.commit_recv(range)
.map_err(|e| {
JsValue::from_str(&format!("Error committing recv private range: {:?}", e))
})