Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtsukino committed Nov 4, 2024
1 parent 421b618 commit 0e8b310
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 7 deletions.
29 changes: 28 additions & 1 deletion src/entries/Background/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import browser, { storage } from 'webextension-polyfill';
import { OffscreenActionTypes } from '../Offscreen/types';
import { getMaxRecv, getMaxSent, getRendezvousApi } from '../../utils/storage';
import { SidePanelActionTypes } from '../SidePanel/types';
import { Transcript } from 'tlsn-js';
import { VerifierOutput } from 'tlsn-wasm';

const state: {
clientId: string;
Expand Down Expand Up @@ -279,6 +281,18 @@ export const connectSession = async () => {
}
case 'proof_request_end': {
const { pluginHash, proof } = message.params;
const transcript = new Transcript({
sent: proof.transcript.sent,
recv: proof.transcript.recv,
});

state.presentation = {
sent: transcript.sent(),
recv: transcript.recv(),
};

pushToRedux(setP2PPresentation(state.presentation));

browser.runtime.sendMessage({
type: OffscreenActionTypes.end_p2p_proof_request,
data: {
Expand Down Expand Up @@ -512,9 +526,22 @@ export const startProofRequest = async (pluginHash: string) => {

export const endProofRequest = async (data: {
pluginHash: string;
proof: any;
proof: VerifierOutput;
}) => {
const transcript = new Transcript({
sent: data.proof.transcript.sent,
recv: data.proof.transcript.recv,
});

state.presentation = {
sent: transcript.sent(),
recv: transcript.recv(),
};

pushToRedux(setP2PPresentation(state.presentation));

const { socket, clientId, pairing } = state;

if (socket && clientId && pairing) {
socket.send(
bufferify({
Expand Down
4 changes: 1 addition & 3 deletions src/entries/Offscreen/Offscreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ const Offscreen = () => {
await waitForEvent(OffscreenActionTypes.prover_setup);

verifier.verify().then((res) => {
console.log(res);

browser.runtime.sendMessage({
type: BackgroundActiontype.proof_request_end,
data: {
Expand Down Expand Up @@ -279,7 +277,7 @@ const Offscreen = () => {
OffscreenActionTypes.end_p2p_proof_request,
);
await prover.reveal(commit);
console.log(await endRequest);
await endRequest;
})();
break;
}
Expand Down
55 changes: 53 additions & 2 deletions src/pages/PeerToPeer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { sha256 } from '../../utils/misc';
import { openSidePanel } from '../../entries/utils';
import { SidePanelActionTypes } from '../../entries/SidePanel/types';
import { verify } from 'tlsn-js-v5';
import ProofViewer from '../ProofViewer';

export function P2PHome(): ReactElement {
const clientId = useClientId();
Expand Down Expand Up @@ -235,11 +236,26 @@ function IncomingProof({
accept: () => void;
isProving: boolean;
}) {
const presentation = useP2PPresentation();
const [showingTranscript, showTranscript] = useState(false);

if (isProving) {
return (
<>
{presentation && showingTranscript && (
<Modal
className="h-full m-0 rounded-none"
onClose={() => showTranscript(false)}
>
<ProofViewer
className="h-full"
sent={presentation.sent}
recv={presentation.recv}
/>
</Modal>
)}
<div className="font-semibold text-orange-500">
Proving to your peer...
{presentation ? 'Proving Completed' : 'Proving to your peer...'}
</div>
<Plugin
className="w-full bg-white !cursor-default hover:!bg-white active:!bg-white hover:!border-slate-300"
Expand All @@ -248,6 +264,15 @@ function IncomingProof({
onClick={() => null}
unremovable
/>
<div className="flex flex-row gap-2">
<button
className="button button--primary"
onClick={() => showTranscript(true)}
disabled={!presentation}
>
View
</button>
</div>
</>
);
}
Expand Down Expand Up @@ -285,18 +310,44 @@ function OutgoingProof({
outgoingPluginHash: string;
cancel: () => void;
}) {
const presentation = useP2PPresentation();
const [showingTranscript, showTranscript] = useState(false);

if (isVerifying) {
return (
<>
{presentation && showingTranscript && (
<Modal
className="h-full m-0 rounded-none"
onClose={() => showTranscript(false)}
>
<ProofViewer
className="h-full"
sent={presentation.sent}
recv={presentation.recv}
/>
</Modal>
)}
<div className="font-semibold text-orange-500">
Verifying with your peer...
{presentation
? 'Verification Completed'
: 'Verifying with your peer...'}
</div>
<Plugin
className="w-full bg-white !cursor-default hover:!bg-white active:!bg-white hover:!border-slate-300"
hash={outgoingPluginHash}
onClick={() => null}
unremovable
/>
<div className="flex flex-row gap-2">
<button
className="button button--primary"
onClick={() => showTranscript(true)}
disabled={!presentation}
>
View
</button>
</div>
</>
);
}
Expand Down
9 changes: 8 additions & 1 deletion src/pages/ProofViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import c from 'classnames';
import { useRequestHistory } from '../../reducers/history';
import Icon from '../../components/Icon';
import { download } from '../../utils/misc';
import classNames from 'classnames';

export default function ProofViewer(props?: {
className?: string;
recv?: string;
sent?: string;
}): ReactElement {
Expand All @@ -20,7 +22,12 @@ export default function ProofViewer(props?: {
const [tab, setTab] = useState('sent');

return (
<div className="flex flex-col w-full py-2 gap-2 flex-grow">
<div
className={classNames(
'flex flex-col w-full py-2 gap-2 flex-grow',
props?.className,
)}
>
<div className="flex flex-col px-2">
<div className="flex flex-row gap-2 items-center">
<Icon
Expand Down

0 comments on commit 0e8b310

Please sign in to comment.