@@ -3,19 +3,20 @@ import * as Comlink from 'comlink';
33import { OffscreenActionTypes } from './types' ;
44import {
55 NotaryServer ,
6- Prover as _Prover ,
7- NotarizedSession as _NotarizedSession ,
8- TlsProof as _TlsProof ,
6+ Prover as TProver ,
7+ Presentation as TPresentation ,
8+ Transcript ,
99} from 'tlsn-js' ;
1010import { verify } from 'tlsn-js-v5' ;
1111
1212import { urlify } from '../../utils/misc' ;
1313import { BackgroundActiontype } from '../Background/rpc' ;
1414import browser from 'webextension-polyfill' ;
15- import { Proof , ProofV1 } from '../../utils/types' ;
15+ import { PresentationJSON } from '../../utils/types' ;
16+ import { PresentationJSON as PresentationJSONa7 } from 'tlsn-js/build/types' ;
1617import { Method } from 'tlsn-js/wasm/pkg' ;
1718
18- const { init, Prover, NotarizedSession , TlsProof } : any = Comlink . wrap (
19+ const { init, Prover, Presentation } : any = Comlink . wrap (
1920 new Worker ( new URL ( './worker.ts' , import . meta. url ) ) ,
2021) ;
2122
@@ -111,7 +112,7 @@ const Offscreen = () => {
111112 }
112113 case BackgroundActiontype . verify_prove_request : {
113114 ( async ( ) => {
114- const proof : Proof = request . data . proof ;
115+ const proof : PresentationJSON = request . data . proof ;
115116 const result : { sent : string ; recv : string } =
116117 await verifyProof ( proof ) ;
117118
@@ -194,7 +195,7 @@ async function createProof(options: {
194195 id : string ;
195196 secretHeaders : string [ ] ;
196197 secretResps : string [ ] ;
197- } ) : Promise < ProofV1 > {
198+ } ) : Promise < PresentationJSONa7 > {
198199 const {
199200 url,
200201 method = 'GET' ,
@@ -211,7 +212,7 @@ async function createProof(options: {
211212
212213 const hostname = urlify ( url ) ?. hostname || '' ;
213214 const notary = NotaryServer . from ( notaryUrl ) ;
214- const prover : _Prover = await new Prover ( {
215+ const prover : TProver = await new Prover ( {
215216 id,
216217 serverDns : hostname ,
217218 maxSentData,
@@ -260,24 +261,21 @@ async function createProof(options: {
260261 ) ,
261262 } ;
262263
263- const session : _NotarizedSession = await new NotarizedSession (
264- await prover . notarize ( commit ) ,
265- ) ;
266-
267- const proofHex = await session . proof ( commit ) ;
268- const proof : ProofV1 = {
269- version : '1.0' ,
270- meta : {
271- notaryUrl,
272- websocketProxyUrl,
273- } ,
274- data : proofHex ,
275- } ;
276- return proof ;
264+ const notarizationOutputs = await prover . notarize ( commit ) ;
265+
266+ const presentation = ( await new Presentation ( {
267+ attestationHex : notarizationOutputs . attestation ,
268+ secretsHex : notarizationOutputs . secrets ,
269+ notaryUrl : notarizationOutputs . notaryUrl ,
270+ websocketProxyUrl : notarizationOutputs . websocketProxyUrl ,
271+ reveal : commit ,
272+ } ) ) as TPresentation ;
273+ const presentationJSON = await presentation . json ( ) ;
274+ return presentationJSON ;
277275}
278276
279277async function verifyProof (
280- proof : Proof ,
278+ proof : PresentationJSON ,
281279) : Promise < { sent : string ; recv : string } > {
282280 let result : { sent : string ; recv : string } ;
283281
@@ -286,12 +284,17 @@ async function verifyProof(
286284 result = await verify ( proof ) ;
287285 break ;
288286 }
289- case '1.0' : {
290- const tlsProof : _TlsProof = await new TlsProof ( proof . data ) ;
291- result = await tlsProof . verify ( {
292- typ : 'P256' ,
293- key : await NotaryServer . from ( proof . meta . notaryUrl ) . publicKey ( ) ,
287+ case '0.1.0-alpha.7' : {
288+ const presentation : TPresentation = await new Presentation ( proof . data ) ;
289+ const verifierOutput = await presentation . verify ( ) ;
290+ const transcript = new Transcript ( {
291+ sent : verifierOutput . transcript . sent ,
292+ recv : verifierOutput . transcript . recv ,
294293 } ) ;
294+ result = {
295+ sent : transcript . sent ( ) ,
296+ recv : transcript . recv ( ) ,
297+ } ;
295298 break ;
296299 }
297300 }
0 commit comments