11import React , { ReactElement , useRef } from 'react' ;
22import { Attestation , AttestedData } from './types/types' ;
3+ import * as Comlink from 'comlink' ;
4+ import { convertNotaryWsToHttp } from '../../utils/url' ;
5+ const { init, Presentation } : any = Comlink . wrap (
6+ new Worker ( new URL ( './worker.ts' , import . meta. url ) ) ,
7+ ) ;
38
49export const readFileAsync = ( file : File ) : Promise < string > => {
510 return new Promise ( ( resolve , reject ) => {
@@ -89,8 +94,6 @@ async function initTlsnJs() {
8994 if ( tlsnInitPromise ) return tlsnInitPromise ;
9095 const { promise, resolve } = defer ( ) ;
9196 tlsnInitPromise = promise ;
92-
93- const { default : init } = await import ( 'tlsn-js' ) ;
9497 await init ( ) ;
9598 resolve ( ) ;
9699}
@@ -117,9 +120,11 @@ export async function verify(
117120 notaryKey : key ,
118121 } ;
119122 }
120- case '0.1.0-alpha.7' : {
121- const { Presentation, Transcript } = await import ( 'tlsn-js' ) ;
122- const tlsProof = new Presentation ( attestation . data ) ;
123+ case '0.1.0-alpha.7' :
124+ case '0.1.0-alpha.8' :
125+ case '0.1.0-alpha.9' :
126+ const { Transcript } = await import ( 'tlsn-js' ) ;
127+ const tlsProof = await new Presentation ( attestation . data ) ;
123128 const data = await tlsProof . verify ( ) ;
124129 const transcript = new Transcript ( {
125130 sent : data . transcript . sent ,
@@ -133,7 +138,7 @@ export async function verify(
133138 . catch ( ( ) => '' ) ;
134139
135140 return {
136- version : '0.1.0-alpha.7' ,
141+ version : attestation . version ,
137142 sent : transcript . sent ( ) ,
138143 recv : transcript . recv ( ) ,
139144 time : data . connection_info . time ,
@@ -142,21 +147,11 @@ export async function verify(
142147 websocketProxyUrl : attestation . meta . websocketProxyUrl ,
143148 verifierKey : verifyingKey ,
144149 } ;
145- }
146150 }
147151
148152 throw new Error ( 'Invalid Proof' ) ;
149153}
150154
151- export function convertNotaryWsToHttp ( notaryWs : string ) {
152- const { protocol, pathname, hostname, port } = new URL ( notaryWs ) ;
153- const p = protocol === 'wss:' ? 'https:' : 'http:' ;
154- const pt = port ? `:${ port } ` : '' ;
155- const path = pathname === '/' ? '' : pathname . replace ( '/notarize' , '' ) ;
156- const h = hostname === 'localhost' ? '127.0.0.1' : hostname ;
157- return p + '//' + h + pt + path ;
158- }
159-
160155function defer ( ) : {
161156 promise : Promise < any > ;
162157 resolve : ( args ?: any ) => any ;
0 commit comments