Skip to content

Commit

Permalink
fix: update logging level to work with alpha6; update verify method i…
Browse files Browse the repository at this point in the history
…n background; add version to option page (#79)
  • Loading branch information
0xtsukino authored Aug 14, 2024
1 parent d15d021 commit 4c78625
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 78 deletions.
25 changes: 18 additions & 7 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"redux-logger": "^3.0.6",
"redux-thunk": "^2.4.2",
"tailwindcss": "^3.3.3",
"tlsn-jsV5.3": "npm:tlsn-js@0.1.0-alpha.5.3",
"tlsn-js": "0.1.0-alpha.6.1"
"tlsn-js": "0.1.0-alpha.6.2",
"tlsn-jsV5.3": "npm:tlsn-js@0.1.0-alpha.5.3"
},
"devDependencies": {
"@babel/core": "^7.20.12",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

8 changes: 4 additions & 4 deletions src/entries/Background/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export enum BackgroundActiontype {
get_plugins_response = 'get_plugins_response',
run_plugin_request = 'run_plugin_request',
run_plugin_response = 'run_plugin_response',
get_logging_level = 'get_logging_level',
}

export type BackgroundAction = {
Expand Down Expand Up @@ -188,6 +189,9 @@ export const initRPC = () => {
return handleGetPluginsRequest(request);
case BackgroundActiontype.run_plugin_request:
return handleRunPluginCSRequest(request);
case BackgroundActiontype.get_logging_level:
getLoggingFilter().then(sendResponse);
return true;
default:
break;
}
Expand Down Expand Up @@ -299,7 +303,6 @@ async function handleRetryProveReqest(
...req,
notaryUrl,
websocketProxyUrl,
loggingFilter: await getLoggingFilter(),
},
});

Expand Down Expand Up @@ -363,7 +366,6 @@ async function handleProveRequestStart(
websocketProxyUrl,
secretHeaders,
secretResps,
loggingFilter: await getLoggingFilter(),
},
});

Expand Down Expand Up @@ -428,7 +430,6 @@ async function runPluginProver(request: BackgroundAction, now = Date.now()) {
maxSentData,
secretHeaders,
secretResps,
loggingFilter: await getLoggingFilter(),
},
});
}
Expand Down Expand Up @@ -862,7 +863,6 @@ async function handleNotarizeRequest(request: BackgroundAction) {
websocketProxyUrl,
secretHeaders,
secretResps,
loggingFilter: await getLoggingFilter(),
},
});
} catch (e) {
Expand Down
19 changes: 11 additions & 8 deletions src/entries/Offscreen/Offscreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { urlify } from '../../utils/misc';
import { BackgroundActiontype } from '../Background/rpc';
import browser from 'webextension-polyfill';
import { Proof, ProofV1 } from '../../utils/types';
import { Method } from 'tlsn-js/wasm/pkg';

const { init, Prover, NotarizedSession, TlsProof }: any = Comlink.wrap(
new Worker(new URL('./worker.ts', import.meta.url)),
Expand All @@ -21,7 +22,10 @@ const { init, Prover, NotarizedSession, TlsProof }: any = Comlink.wrap(
const Offscreen = () => {
useEffect(() => {
(async () => {
await init({ loggingLevel: 'Info' });
const loggingLevel = await browser.runtime.sendMessage({
type: BackgroundActiontype.get_logging_level,
});
await init({ loggingLevel });
// @ts-ignore
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
switch (request.type) {
Expand Down Expand Up @@ -99,9 +103,8 @@ const Offscreen = () => {
}
case BackgroundActiontype.verify_proof: {
(async () => {
console.log('verify_proof', request.data);
// const result = await verify(request.data);
// sendResponse(result);
const result = await verifyProof(request.data);
sendResponse(result);
})();

return true;
Expand Down Expand Up @@ -181,8 +184,8 @@ async function createProof(options: {
url: string;
notaryUrl: string;
websocketProxyUrl: string;
method?: string;
headers: {
method?: Method;
headers?: {
[name: string]: string;
};
body?: any;
Expand All @@ -194,8 +197,8 @@ async function createProof(options: {
}): Promise<ProofV1> {
const {
url,
method,
headers,
method = 'GET',
headers = {},
body,
maxSentData,
maxRecvData,
Expand Down
16 changes: 7 additions & 9 deletions src/entries/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ import { getConnection } from '../Background/db';

const Popup = () => {
const dispatch = useDispatch();
const activeTab = useActiveTab();
const url = useActiveTabUrl();
const navigate = useNavigate();

const [showConnectionDetails, setShowConnectionDetails] = useState(false);

useEffect(() => {
(async () => {
const [tab] = await browser.tabs.query({
Expand Down Expand Up @@ -146,22 +142,24 @@ function AppConnectionLogo() {
className="absolute right-2 flex flex-nowrap flex-row items-center gap-1 justify-center w-fit cursor-pointer"
onClick={() => setShowConnectionDetails(true)}
>
<div className="flex flex-row relative bg-slate-500 border-[1px] border-black rounded-full">
<div className="flex flex-row relative bg-black border-[1px] border-black rounded-full">
{!!activeTab?.favIconUrl ? (
<img
src={activeTab?.favIconUrl}
className="h-5 rounded-full"
alt="logo"
/>
) : (
<Icon fa="fa-solid fa-globe" size={1.25} />
<Icon
fa="fa-solid fa-globe"
className="bg-white text-slate-400 rounded-full"
size={1.25}
/>
)}
<div
className={classNames(
'absolute right-[-2px] bottom-[-2px] rounded-full',
'absolute right-[-2px] bottom-[-2px] rounded-full h-[10px] w-[10px] border-[2px]',
{
'bg-green-500 h-[10px] w-[10px] border-[2px]':
activeTab?.favIconUrl,
'bg-green-500': connected,
'bg-slate-500': !connected,
},
Expand Down
9 changes: 8 additions & 1 deletion src/pages/History/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getNotaryRequest,
setNotaryRequestCid,
} from '../../entries/Background/db';
const charwise = require('charwise');

export default function History(): ReactElement {
const history = useHistoryOrder();
Expand Down Expand Up @@ -131,6 +132,12 @@ export function OneRequestHistory(props: {
{requestUrl?.pathname}
</div>
</div>
<div className="flex flex-row">
<div className="font-bold text-slate-400">Time:</div>
<div className="ml-2 text-slate-800">
{new Date(charwise.decode(props.requestId, 'hex')).toISOString()}
</div>
</div>
<div className="flex flex-row">
<div className="font-bold text-slate-400">Host:</div>
<div className="ml-2 text-slate-800">{requestUrl?.host}</div>
Expand All @@ -140,7 +147,7 @@ export function OneRequestHistory(props: {
<div className="ml-2 text-slate-800">{request?.notaryUrl}</div>
</div>
<div className="flex flex-row">
<div className="font-bold text-slate-400">TLS Proxy API: </div>
<div className="font-bold text-slate-400">TLS Proxy API:</div>
<div className="ml-2 text-slate-800">
{request?.websocketProxyUrl}
</div>
Expand Down
35 changes: 19 additions & 16 deletions src/pages/Options/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ import {
NOTARY_PROXY,
MAX_RECV,
MAX_SENT,
LOGGING_LEVEL_INFO,
LOGGING_LEVEL_NONE,
LOGGING_LEVEL_DEBUG,
LOGGING_LEVEL_TRACE,
} from '../../utils/constants';
import Modal, { ModalContent } from '../../components/Modal/Modal';
import browser from 'webextension-polyfill';
import { LoggingLevel } from 'tlsn-js';
import { version } from '../../../package.json';

export default function Options(): ReactElement {
const [notary, setNotary] = useState(NOTARY_API);
const [proxy, setProxy] = useState(NOTARY_PROXY);
const [maxSent, setMaxSent] = useState(MAX_SENT);
const [maxReceived, setMaxReceived] = useState(MAX_RECV);
const [loggingLevel, setLoggingLevel] = useState(LOGGING_LEVEL_INFO);
const [loggingLevel, setLoggingLevel] = useState<LoggingLevel>('Info');

const [dirty, setDirty] = useState(false);
const [shouldReload, setShouldReload] = useState(false);
Expand All @@ -50,7 +48,7 @@ export default function Options(): ReactElement {
setProxy((await getProxyApi()) || NOTARY_PROXY);
setMaxReceived((await getMaxRecv()) || MAX_RECV);
setMaxSent((await getMaxSent()) || MAX_SENT);
setLoggingLevel((await getLoggingFilter()) || LOGGING_LEVEL_INFO);
setLoggingLevel((await getLoggingFilter()) || 'Info');
})();
}, [advanced]);

Expand Down Expand Up @@ -170,7 +168,7 @@ function InputField(props: {

return (
<div className="flex flex-col flex-nowrap py-1 px-2 gap-2">
<div className="font-semibold">{label}</div>
<div className="font-semibold cursor-default">{label}</div>
<input
type={type}
className="input border"
Expand All @@ -194,6 +192,10 @@ function NormalOptions(props: {

return (
<div>
<div className="flex flex-col flex-nowrap py-1 px-2 gap-2 cursor-default">
<div className="font-semibold">Version</div>
<div className="input border bg-slate-100">{version}</div>
</div>
<InputField
label="Notary API"
placeholder="https://api.tlsnotary.org"
Expand All @@ -214,9 +216,9 @@ function NormalOptions(props: {
setDirty(true);
}}
/>
<div className="flex flex-col flex-nowrap py-1 px-2 gap-2">
<div className="flex flex-col flex-nowrap py-1 px-2 gap-2 cursor-default">
<div className="font-semibold">Explorer URL</div>
<div className="input border">{EXPLORER_API}</div>
<div className="input border bg-slate-100">{EXPLORER_API}</div>
</div>
</div>
);
Expand All @@ -225,12 +227,12 @@ function NormalOptions(props: {
function AdvancedOptions(props: {
maxSent: number;
maxReceived: number;
loggingLevel: string;
loggingLevel: LoggingLevel;
setShouldReload: (reload: boolean) => void;
setMaxSent: (value: number) => void;
setMaxReceived: (value: number) => void;
setDirty: (value: boolean) => void;
setLoggingLevel: (level: string) => void;
setLoggingLevel: (level: LoggingLevel) => void;
}) {
const {
maxSent,
Expand Down Expand Up @@ -270,16 +272,17 @@ function AdvancedOptions(props: {
<select
className="select !bg-white border !px-2 !py-1"
onChange={(e) => {
setLoggingLevel(e.target.value);
setLoggingLevel(e.target.value as LoggingLevel);
setDirty(true);
setShouldReload(true);
}}
value={loggingLevel}
>
<option value={LOGGING_LEVEL_NONE}>None</option>
<option value={LOGGING_LEVEL_INFO}>Info</option>
<option value={LOGGING_LEVEL_DEBUG}>Debug</option>
<option value={LOGGING_LEVEL_TRACE}>Trace</option>
<option value="Error">Error</option>
<option value="Warn">Warn</option>
<option value="Info">Info</option>
<option value="Debug">Debug</option>
<option value="Trace">Trace</option>
</select>
</div>
<div className="flex flex-row flex-nowrap justify-end gap-2 p-2"></div>
Expand Down
Loading

0 comments on commit 4c78625

Please sign in to comment.