Skip to content

Commit d47cf0d

Browse files
authored
feat: integrate with alpha.7 (#102)
1 parent 25f35d0 commit d47cf0d

File tree

9 files changed

+3216
-3117
lines changed

9 files changed

+3216
-3117
lines changed

package-lock.json

Lines changed: 3160 additions & 3064 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tlsn-extension",
3-
"version": "0.1.0.6",
3+
"version": "0.1.0.700",
44
"license": "MIT",
55
"repository": {
66
"type": "git",
@@ -38,7 +38,7 @@
3838
"redux-logger": "^3.0.6",
3939
"redux-thunk": "^2.4.2",
4040
"tailwindcss": "^3.3.3",
41-
"tlsn-js": "0.1.0-alpha.6.2",
41+
"tlsn-js": "0.1.0-alpha.7.1",
4242
"tlsn-js-v5": "npm:[email protected]"
4343
},
4444
"devDependencies": {

pnpm-lock.yaml

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/entries/Content/content.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ContentScriptTypes, RPCClient } from './rpc';
22
import { RequestHistory } from '../Background/rpc';
33
import { PluginConfig, PluginMetadata } from '../../utils/misc';
4-
import { Proof } from '../../utils/types';
4+
import { PresentationJSON } from '../../utils/types';
55

66
const client = new RPCClient();
77

@@ -27,7 +27,7 @@ class TLSN {
2727
return resp || [];
2828
}
2929

30-
async getProof(id: string): Promise<Proof | null> {
30+
async getProof(id: string): Promise<PresentationJSON | null> {
3131
const resp = await client.call(ContentScriptTypes.get_proof, {
3232
id,
3333
});
@@ -52,7 +52,7 @@ class TLSN {
5252
[k: string]: string;
5353
};
5454
},
55-
): Promise<Proof> {
55+
): Promise<PresentationJSON> {
5656
const resp = await client.call(ContentScriptTypes.notarize, {
5757
url,
5858
method: requestOptions?.method,

src/entries/Offscreen/Offscreen.tsx

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ import * as Comlink from 'comlink';
33
import { OffscreenActionTypes } from './types';
44
import {
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';
1010
import { verify } from 'tlsn-js-v5';
1111

1212
import { urlify } from '../../utils/misc';
1313
import { BackgroundActiontype } from '../Background/rpc';
1414
import 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';
1617
import { 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

279277
async 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
}

src/entries/Offscreen/worker.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import * as Comlink from 'comlink';
2-
import init, { Prover, NotarizedSession, TlsProof } from 'tlsn-js';
2+
import init, { Prover, Presentation } from 'tlsn-js';
33

44
Comlink.expose({
55
init,
66
Prover,
7-
NotarizedSession,
8-
TlsProof,
7+
Presentation,
98
});

src/utils/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function getMaxRecv() {
2626
}
2727

2828
export async function getNotaryApi() {
29-
return await get(NOTARY_API_LS_KEY, 'https://notary.pse.dev/v0.1.0-alpha.6');
29+
return await get(NOTARY_API_LS_KEY, 'https://notary.pse.dev/v0.1.0-alpha.7');
3030
}
3131

3232
export async function getProxyApi() {

src/utils/types.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
export type Proof = ProofV0 | ProofV1;
1+
import { PresentationJSON as PresentationJSONa7 } from 'tlsn-js/build/types';
22

3-
export type ProofV0 = {
3+
export type PresentationJSON = PresentationJSONa5 | PresentationJSONa7;
4+
5+
export type PresentationJSONa5 = {
46
version?: undefined;
57
session: any;
68
substrings: any;
79
notaryUrl: string;
810
};
9-
10-
export type ProofV1 = {
11-
version: '1.0';
12-
data: string;
13-
meta: {
14-
notaryUrl: string;
15-
websocketProxyUrl: string;
16-
pluginUrl?: string;
17-
};
18-
};

webpack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ var options = {
8383
loader: "sass-loader",
8484
options: {
8585
sourceMap: true,
86+
sassOptions: {
87+
silenceDeprecations: ["legacy-js-api"],
88+
}
8689
},
8790
},
8891
],

0 commit comments

Comments
 (0)