Compare commits

...

3 Commits

Author SHA1 Message Date
Codetrauma
104457d2c6 feat: pass verifier and notary api urls to prover 2025-05-20 14:43:24 +02:00
Codetrauma
d20441b553 fix: wip 2025-05-20 11:10:17 +02:00
Codetrauma
f955ab7fd5 feat: making changes to runPlugins with the interactive verifier 2025-05-20 11:03:14 +02:00
4 changed files with 95 additions and 16 deletions

View File

@@ -1032,17 +1032,53 @@ async function handleRunPluginByURLRequest(request: BackgroundAction) {
});
const defer = deferredPromise();
const { origin, position, url, params } = request.data;
const {
origin,
position,
url,
params,
skipConfirmation,
verifierApiUrl,
proxyApiUrl,
headers,
} = request.data;
if (skipConfirmation) {
try {
browser.runtime.onMessage.addListener(async (req: any) => {
if (req.type !== SidePanelActionTypes.execute_plugin_response) return;
if (req.data.url !== url) return;
if (req.data.error) defer.reject(req.data.error);
if (req.data.proof) defer.resolve(req.data.proof);
});
const now = Date.now();
const id = charwise.encode(now).toString('hex');
await browser.runtime.sendMessage({
type: OffscreenActionTypes.create_prover_request,
data: {
id,
url,
params,
headers,
verifierApiUrl,
proxyApiUrl,
maxRecvData: await getMaxRecv(),
maxSentData: await getMaxSent(),
},
});
return defer.promise;
} catch (error) {
defer.reject(error);
return defer.promise;
}
}
// const plugin = await getPluginByHash(hash);
// const config = await getPluginConfigByHash(hash);
let isUserClose = true;
// if (!plugin || !config) {
// defer.reject(new Error('plugin not found.'));
// return defer.promise;
// }
const { popup, tab } = await openPopup(
`run-plugin-approval?url=${url}&origin=${encodeURIComponent(origin)}&favIconUrl=${encodeURIComponent(currentTab?.favIconUrl || '')}&params=${encodeURIComponent(JSON.stringify(params) || '')}`,
position.left,

View File

@@ -44,6 +44,27 @@ class TLSN {
return resp;
}
async runPluginWithVerifier(
url: string,
verifierOptions: {
verifierApiUrl: string;
proxyApiUrl: string;
headers?: { [key: string]: string };
},
params?: Record<string, string>,
) {
const resp = await client.call(ContentScriptTypes.run_plugin_by_url, {
url,
params,
skipConfirmation: true, // Signal to skip confirmation window
verifierApiUrl: verifierOptions.verifierApiUrl,
proxyApiUrl: verifierOptions.proxyApiUrl,
headers: verifierOptions.headers,
});
return resp;
}
}
const connect = async () => {

View File

@@ -1,5 +1,14 @@
import { deferredPromise, PromiseResolvers } from '../../utils/promise';
export interface RunPluginByUrlData {
url: string;
params?: Record<string, string>;
skipConfirmation?: boolean;
verifierApiUrl?: string;
proxyApiUrl?: string;
headers?: { [key: string]: string };
}
export enum ContentScriptTypes {
notarize = 'tlsn/cs/notarize',
run_plugin_by_url = 'tlsn/cs/run_plugin_by_url',

View File

@@ -24,6 +24,7 @@ import {
setNotaryRequestError,
setNotaryRequestStatus,
} from '../Background/db';
import { getNotaryApi, getProxyApi } from '../../utils/storage';
const { init, Prover, Presentation, Verifier }: any = Comlink.wrap(
new Worker(new URL('./worker.ts', import.meta.url)),
@@ -452,8 +453,9 @@ async function createProof(options: {
async function createProver(options: {
url: string;
notaryUrl: string;
websocketProxyUrl: string;
verifierApiUrl?: string;
proxyApiUrl?: string;
notaryUrl?: string;
method?: Method;
headers?: {
[name: string]: string;
@@ -470,13 +472,13 @@ async function createProver(options: {
body,
maxSentData,
maxRecvData,
notaryUrl,
websocketProxyUrl,
verifierApiUrl,
proxyApiUrl,
id,
} = options;
const hostname = urlify(url)?.hostname || '';
const notary = NotaryServer.from(notaryUrl);
try {
const prover: TProver = await handleProgress(
id,
@@ -494,8 +496,17 @@ async function createProver(options: {
const sessionUrl = await handleProgress(
id,
RequestProgress.GettingSession,
() => notary.sessionUrl(maxSentData, maxRecvData),
'Error getting session from Notary',
async () => {
if (verifierApiUrl) {
return verifierApiUrl;
} else {
const notary = NotaryServer.from(
options.notaryUrl || (await getNotaryApi()),
);
return notary.sessionUrl(maxSentData, maxRecvData);
}
},
'Error getting session from Verifier/Notary',
);
await handleProgress(
@@ -505,11 +516,13 @@ async function createProver(options: {
'Error setting up prover',
);
const proxyUrl = proxyApiUrl || (await getProxyApi());
await handleProgress(
id,
RequestProgress.SendingRequest,
() =>
prover.sendRequest(websocketProxyUrl + `?token=${hostname}`, {
prover.sendRequest(proxyUrl + `?token=${hostname}`, {
url,
method,
headers,