From d6385ebc4ad5e794bda1477918ebdfe0452c6526 Mon Sep 17 00:00:00 2001 From: Codetrauma Date: Tue, 25 Mar 2025 09:51:25 -0700 Subject: [PATCH] feat: alpha.8 update --- package-lock.json | 53 ++++++++++++++++++++++++++++----------- package.json | 3 ++- web/utils/index.tsx | 49 +++++++++++++++++++++++++++++++++--- web/utils/types/types.tsx | 4 +-- webpack.web.config.js | 5 ++++ 5 files changed, 93 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index acd6a42..069c6fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,8 +40,9 @@ "redux-thunk": "^2.4.2", "stream": "^0.0.2", "tailwindcss": "^3.3.3", - "tlsn-js": "0.1.0-alpha.7.1", + "tlsn-js": "0.1.0-alpha.8", "tlsn-js-v5": "npm:tlsn-js@0.1.0-alpha.5.4", + "tlsn-js-v7": "npm:tlsn-js@0.1.0-alpha.7.2", "ws": "^8.16.0" }, "devDependencies": { @@ -22462,12 +22463,12 @@ } }, "node_modules/tlsn-js": { - "version": "0.1.0-alpha.7.1", - "resolved": "https://registry.npmjs.org/tlsn-js/-/tlsn-js-0.1.0-alpha.7.1.tgz", - "integrity": "sha512-EWdRp1VQBfdre8jehJgmDjtDvt01ZL1JWbcscctnFTLIIwMYS7IBxU07UYG0NMZFXeTE8PlrUDEVwEl1+vla+g==", + "version": "0.1.0-alpha.8", + "resolved": "https://registry.npmjs.org/tlsn-js/-/tlsn-js-0.1.0-alpha.8.tgz", + "integrity": "sha512-2xHhn/RkJey+sw+Xu3AgUj6S+iEvWKXhwcAEOKzs6rNOyK3ZanAOaPpVgPWyT/FlPfZlagcDuDITnThgbqQkOA==", "license": "ISC", "dependencies": { - "tlsn-wasm": "^0.1.0-alpha.7.2" + "tlsn-wasm": "^0.1.0-alpha.8" }, "engines": { "node": ">= 16.20.2" @@ -22485,10 +22486,24 @@ "node": ">= 16.20.2" } }, - "node_modules/tlsn-wasm": { + "node_modules/tlsn-js-v7": { + "name": "tlsn-js", "version": "0.1.0-alpha.7.2", - "resolved": "https://registry.npmjs.org/tlsn-wasm/-/tlsn-wasm-0.1.0-alpha.7.2.tgz", - "integrity": "sha512-NzrDfOxmFtMHDb4lmMsx6RaS6F+IVXEHxK0zow8jpnx+NryuJ+qnp4380Lq0uj61w/Yuq+yzOhzFe6Bpeo59dA==" + "resolved": "https://registry.npmjs.org/tlsn-js/-/tlsn-js-0.1.0-alpha.7.2.tgz", + "integrity": "sha512-G7xUog+HtDMRhw0fIRX9loUI6eUC9/4J+P0AzjBzpf8+8LAd3i8XgMkpqF8LqLUk5/vIm1b+ZakDYeCNMMiBeQ==", + "license": "ISC", + "dependencies": { + "tlsn-wasm": "^0.1.0-alpha.7.2" + }, + "engines": { + "node": ">= 16.20.2" + } + }, + "node_modules/tlsn-wasm": { + "version": "0.1.0-alpha.8", + "resolved": "https://registry.npmjs.org/tlsn-wasm/-/tlsn-wasm-0.1.0-alpha.8.tgz", + "integrity": "sha512-5Jakx7asg9BX+7owfNsLPTnRdI2uVug11sJ0hh0509w1dHJHAHQ2oi4i7PupACHKDlS/iQL3UNTv6vK6+QKctw==", + "license": "MIT OR Apache-2.0" }, "node_modules/tmpl": { "version": "1.0.5", @@ -40320,11 +40335,11 @@ "optional": true }, "tlsn-js": { - "version": "0.1.0-alpha.7.1", - "resolved": "https://registry.npmjs.org/tlsn-js/-/tlsn-js-0.1.0-alpha.7.1.tgz", - "integrity": "sha512-EWdRp1VQBfdre8jehJgmDjtDvt01ZL1JWbcscctnFTLIIwMYS7IBxU07UYG0NMZFXeTE8PlrUDEVwEl1+vla+g==", + "version": "0.1.0-alpha.8", + "resolved": "https://registry.npmjs.org/tlsn-js/-/tlsn-js-0.1.0-alpha.8.tgz", + "integrity": "sha512-2xHhn/RkJey+sw+Xu3AgUj6S+iEvWKXhwcAEOKzs6rNOyK3ZanAOaPpVgPWyT/FlPfZlagcDuDITnThgbqQkOA==", "requires": { - "tlsn-wasm": "^0.1.0-alpha.7.2" + "tlsn-wasm": "^0.1.0-alpha.8" } }, "tlsn-js-v5": { @@ -40335,10 +40350,18 @@ "comlink": "^4.4.1" } }, + "tlsn-js-v7": { + "version": "npm:tlsn-js@0.1.0-alpha.7.2", + "resolved": "https://registry.npmjs.org/tlsn-js/-/tlsn-js-0.1.0-alpha.7.2.tgz", + "integrity": "sha512-G7xUog+HtDMRhw0fIRX9loUI6eUC9/4J+P0AzjBzpf8+8LAd3i8XgMkpqF8LqLUk5/vIm1b+ZakDYeCNMMiBeQ==", + "requires": { + "tlsn-wasm": "^0.1.0-alpha.7.2" + } + }, "tlsn-wasm": { - "version": "0.1.0-alpha.7.2", - "resolved": "https://registry.npmjs.org/tlsn-wasm/-/tlsn-wasm-0.1.0-alpha.7.2.tgz", - "integrity": "sha512-NzrDfOxmFtMHDb4lmMsx6RaS6F+IVXEHxK0zow8jpnx+NryuJ+qnp4380Lq0uj61w/Yuq+yzOhzFe6Bpeo59dA==" + "version": "0.1.0-alpha.8", + "resolved": "https://registry.npmjs.org/tlsn-wasm/-/tlsn-wasm-0.1.0-alpha.8.tgz", + "integrity": "sha512-5Jakx7asg9BX+7owfNsLPTnRdI2uVug11sJ0hh0509w1dHJHAHQ2oi4i7PupACHKDlS/iQL3UNTv6vK6+QKctw==" }, "tmpl": { "version": "1.0.5", diff --git a/package.json b/package.json index 563e0d2..3d0a542 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,8 @@ "redux-thunk": "^2.4.2", "stream": "^0.0.2", "tailwindcss": "^3.3.3", - "tlsn-js": "0.1.0-alpha.7.1", + "tlsn-js": "0.1.0-alpha.8", + "tlsn-js-v7": "npm:tlsn-js@0.1.0-alpha.7.2", "tlsn-js-v5": "npm:tlsn-js@0.1.0-alpha.5.4", "ws": "^8.16.0" }, diff --git a/web/utils/index.tsx b/web/utils/index.tsx index 06f608f..42a4f02 100644 --- a/web/utils/index.tsx +++ b/web/utils/index.tsx @@ -1,5 +1,6 @@ import React, { ReactElement, useRef } from 'react'; import { Attestation, AttestedData } from './types/types'; +import * as Comlink from 'comlink'; export const readFileAsync = (file: File): Promise => { return new Promise((resolve, reject) => { @@ -85,13 +86,29 @@ export function download(filename: string, content: string) { } let tlsnInitPromise: Promise | null = null; +// async function initTlsnJs() { +// if (tlsnInitPromise) return tlsnInitPromise; +// const { promise, resolve } = defer(); +// tlsnInitPromise = promise; + +// const { default: init } = await import('tlsn-js'); +// await init(); +// resolve(); +// } + async function initTlsnJs() { if (tlsnInitPromise) return tlsnInitPromise; const { promise, resolve } = defer(); tlsnInitPromise = promise; - const { default: init } = await import('tlsn-js'); - await init(); + if (typeof Worker !== 'undefined') { + const worker = new Worker(new URL('./worker.ts', import.meta.url)); + const { init }: any = Comlink.wrap(worker); + await init(); + } else { + const { default: init } = await import('tlsn-js'); + await init(); + } resolve(); } @@ -118,7 +135,7 @@ export async function verify( }; } case '0.1.0-alpha.7': { - const { Presentation, Transcript } = await import('tlsn-js'); + const { Presentation, Transcript } = await import('tlsn-js-v7'); const tlsProof = new Presentation(attestation.data); const data = await tlsProof.verify(); const transcript = new Transcript({ @@ -143,6 +160,32 @@ export async function verify( verifierKey: verifyingKey, }; } + case '0.1.0-alpha.8': { + const { Presentation, Transcript } = await import('tlsn-js'); + const tlsProof = new Presentation(attestation.data); + const data = await tlsProof.verify(); + const transcript = new Transcript({ + sent: data.transcript.sent, + recv: data.transcript.recv, + }); + const vk = await tlsProof.verifyingKey(); + const verifyingKey = Buffer.from(vk.data).toString('hex'); + const notaryUrl = convertNotaryWsToHttp(attestation.meta.notaryUrl); + const publicKey = await new NotaryServer(notaryUrl) + .publicKey() + .catch(() => ''); + + return { + version: '0.1.0-alpha.8', + sent: transcript.sent(), + recv: transcript.recv(), + time: data.connection_info.time, + notaryUrl: notaryUrl, + notaryKey: publicKey, + websocketProxyUrl: attestation.meta.websocketProxyUrl, + verifierKey: verifyingKey, + }; + } } throw new Error('Invalid Proof'); diff --git a/web/utils/types/types.tsx b/web/utils/types/types.tsx index 626d936..5cd018b 100644 --- a/web/utils/types/types.tsx +++ b/web/utils/types/types.tsx @@ -1,5 +1,5 @@ export interface AttestedData { - version: '0.1.0-alpha.7' | '0.1.0-alpha.5'; + version: '0.1.0-alpha.8' | '0.1.0-alpha.7' | '0.1.0-alpha.5'; time: number; sent: string; recv: string; @@ -17,7 +17,7 @@ export type AttestationV0 = { }; export type AttestationV1 = { - version: '0.1.0-alpha.7'; + version: '0.1.0-alpha.8' | '0.1.0-alpha.7'; data: string; meta: { notaryUrl: string; diff --git a/webpack.web.config.js b/webpack.web.config.js index 6a6be37..e48742b 100755 --- a/webpack.web.config.js +++ b/webpack.web.config.js @@ -150,6 +150,11 @@ var options = { to: path.join(__dirname, "build", "ui"), force: true, }, + { + from: "node_modules/tlsn-js-v7/build", + to: path.join(__dirname, "build", "ui"), + force: true, + }, { from: "node_modules/tlsn-js/build", to: path.join(__dirname, "build", "ui"),