mirror of
https://github.com/tlsnotary/tlsn-extension.git
synced 2026-01-08 20:48:03 -05:00
Compare commits
3 Commits
0.1.0.1200
...
add-verifi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
104457d2c6 | ||
|
|
d20441b553 | ||
|
|
f955ab7fd5 |
@@ -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 || '')}¶ms=${encodeURIComponent(JSON.stringify(params) || '')}`,
|
||||
position.left,
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user