Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate with alpha.7 #102

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6,224 changes: 3,160 additions & 3,064 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tlsn-extension",
"version": "0.1.0.6",
"version": "0.1.0.700",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -38,7 +38,7 @@
"redux-logger": "^3.0.6",
"redux-thunk": "^2.4.2",
"tailwindcss": "^3.3.3",
"tlsn-js": "0.1.0-alpha.6.2",
"tlsn-js": "0.1.0-alpha.7.1",
"tlsn-js-v5": "npm:[email protected]"
},
"devDependencies": {
Expand Down
14 changes: 10 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/entries/Content/content.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ContentScriptTypes, RPCClient } from './rpc';
import { RequestHistory } from '../Background/rpc';
import { PluginConfig, PluginMetadata } from '../../utils/misc';
import { Proof } from '../../utils/types';
import { PresentationJSON } from '../../utils/types';

const client = new RPCClient();

Expand All @@ -27,7 +27,7 @@ class TLSN {
return resp || [];
}

async getProof(id: string): Promise<Proof | null> {
async getProof(id: string): Promise<PresentationJSON | null> {
const resp = await client.call(ContentScriptTypes.get_proof, {
id,
});
Expand All @@ -52,7 +52,7 @@ class TLSN {
[k: string]: string;
};
},
): Promise<Proof> {
): Promise<PresentationJSON> {
const resp = await client.call(ContentScriptTypes.notarize, {
url,
method: requestOptions?.method,
Expand Down
59 changes: 31 additions & 28 deletions src/entries/Offscreen/Offscreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ import * as Comlink from 'comlink';
import { OffscreenActionTypes } from './types';
import {
NotaryServer,
Prover as _Prover,
NotarizedSession as _NotarizedSession,
TlsProof as _TlsProof,
Prover as TProver,
Presentation as TPresentation,
Transcript,
} from 'tlsn-js';
import { verify } from 'tlsn-js-v5';

import { urlify } from '../../utils/misc';
import { BackgroundActiontype } from '../Background/rpc';
import browser from 'webextension-polyfill';
import { Proof, ProofV1 } from '../../utils/types';
import { PresentationJSON } from '../../utils/types';
import { PresentationJSON as PresentationJSONa7 } from 'tlsn-js/build/types';
import { Method } from 'tlsn-js/wasm/pkg';

const { init, Prover, NotarizedSession, TlsProof }: any = Comlink.wrap(
const { init, Prover, Presentation }: any = Comlink.wrap(
new Worker(new URL('./worker.ts', import.meta.url)),
);

Expand Down Expand Up @@ -111,7 +112,7 @@ const Offscreen = () => {
}
case BackgroundActiontype.verify_prove_request: {
(async () => {
const proof: Proof = request.data.proof;
const proof: PresentationJSON = request.data.proof;
const result: { sent: string; recv: string } =
await verifyProof(proof);

Expand Down Expand Up @@ -194,7 +195,7 @@ async function createProof(options: {
id: string;
secretHeaders: string[];
secretResps: string[];
}): Promise<ProofV1> {
}): Promise<PresentationJSONa7> {
const {
url,
method = 'GET',
Expand All @@ -211,7 +212,7 @@ async function createProof(options: {

const hostname = urlify(url)?.hostname || '';
const notary = NotaryServer.from(notaryUrl);
const prover: _Prover = await new Prover({
const prover: TProver = await new Prover({
id,
serverDns: hostname,
maxSentData,
Expand Down Expand Up @@ -260,24 +261,21 @@ async function createProof(options: {
),
};

const session: _NotarizedSession = await new NotarizedSession(
await prover.notarize(commit),
);

const proofHex = await session.proof(commit);
const proof: ProofV1 = {
version: '1.0',
meta: {
notaryUrl,
websocketProxyUrl,
},
data: proofHex,
};
return proof;
const notarizationOutputs = await prover.notarize(commit);

const presentation = (await new Presentation({
attestationHex: notarizationOutputs.attestation,
secretsHex: notarizationOutputs.secrets,
notaryUrl: notarizationOutputs.notaryUrl,
websocketProxyUrl: notarizationOutputs.websocketProxyUrl,
reveal: commit,
})) as TPresentation;
const presentationJSON = await presentation.json();
return presentationJSON;
}

async function verifyProof(
proof: Proof,
proof: PresentationJSON,
): Promise<{ sent: string; recv: string }> {
let result: { sent: string; recv: string };

Expand All @@ -286,12 +284,17 @@ async function verifyProof(
result = await verify(proof);
break;
}
case '1.0': {
const tlsProof: _TlsProof = await new TlsProof(proof.data);
result = await tlsProof.verify({
typ: 'P256',
key: await NotaryServer.from(proof.meta.notaryUrl).publicKey(),
case '0.1.0-alpha.7': {
const presentation: TPresentation = await new Presentation(proof.data);
const verifierOutput = await presentation.verify();
const transcript = new Transcript({
sent: verifierOutput.transcript.sent,
recv: verifierOutput.transcript.recv,
});
result = {
sent: transcript.sent(),
recv: transcript.recv(),
};
break;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/entries/Offscreen/worker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as Comlink from 'comlink';
import init, { Prover, NotarizedSession, TlsProof } from 'tlsn-js';
import init, { Prover, Presentation } from 'tlsn-js';

Comlink.expose({
init,
Prover,
NotarizedSession,
TlsProof,
Presentation,
});
2 changes: 1 addition & 1 deletion src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function getMaxRecv() {
}

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

export async function getProxyApi() {
Expand Down
16 changes: 4 additions & 12 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
export type Proof = ProofV0 | ProofV1;
import { PresentationJSON as PresentationJSONa7 } from 'tlsn-js/build/types';

export type ProofV0 = {
export type PresentationJSON = PresentationJSONa5 | PresentationJSONa7;

export type PresentationJSONa5 = {
version?: undefined;
session: any;
substrings: any;
notaryUrl: string;
};

export type ProofV1 = {
version: '1.0';
data: string;
meta: {
notaryUrl: string;
websocketProxyUrl: string;
pluginUrl?: string;
};
};
3 changes: 3 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ var options = {
loader: "sass-loader",
options: {
sourceMap: true,
sassOptions: {
silenceDeprecations: ["legacy-js-api"],
}
},
},
],
Expand Down
Loading