From fb4c81b8514396627e3943bf38a0a44238cf8fea Mon Sep 17 00:00:00 2001 From: tsukino <87639218+0xtsukino@users.noreply.github.com> Date: Tue, 29 Oct 2024 05:08:55 -0400 Subject: [PATCH 1/6] fix: throw error when installilng duplicate pluign (#111) --- src/entries/Background/rpc.ts | 5 +++++ src/pages/Home/index.tsx | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/entries/Background/rpc.ts b/src/entries/Background/rpc.ts index 3f9ccc94..ea95fd1f 100644 --- a/src/entries/Background/rpc.ts +++ b/src/entries/Background/rpc.ts @@ -921,6 +921,11 @@ async function handleInstallPluginRequest(request: BackgroundAction) { try { const hex = Buffer.from(arrayBuffer).toString('hex'); const hash = await addPlugin(hex); + + if (!hash) { + throw new Error('Plugin already exist.'); + } + await addPluginConfig(hash!, config); await addPluginMetadata(hash!, { ...metadata, diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index 139dc34d..1bf1cc47 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -20,8 +20,6 @@ import { usePluginConfig, usePluginHashes, } from '../../reducers/plugins'; -import { PluginConfig } from '../../utils/misc'; -import { getPluginConfigByHash } from '../../entries/Background/db'; import { fetchPluginHashes } from '../../utils/rpc'; import DefaultPluginIcon from '../../assets/img/default-plugin-icon.png'; @@ -212,6 +210,8 @@ function PluginIcon({ hash }: { hash: string }) { onPluginClick(); }, [onPluginClick, config]); + if (!config) return null; + return ( + ); + } else if (completed) { btnContent = ( + + +
+
+ No proofs history +
+
+ + ); +} + +function ClientStatus() { + const clientId = useClientId(); + const error = useP2PError(); + const pairId = usePairId(); + const [incomingPairingRequest] = useIncomingPairingRequests(); + const [outgoingPairingRequest] = useOutgoingPairingRequests(); + + let body = null; + + if (!clientId) { + body = ; + } else if (pairId) { + body = ; + } else if (!incomingPairingRequest && !outgoingPairingRequest) { + body = ; + } else if (incomingPairingRequest) { + body = ; + } else if (outgoingPairingRequest) { + body = ; + } + + return ( +
+ {body} + {error && {error}} +
+ ); +} + +function Paired() { + const pairId = usePairId(); + const clientId = useClientId(); + const [incomingProofRequest] = useIncomingProofRequests(); + const [outgoingPluginHash] = useOutgoingProofRequests(); + const [incomingPluginHash, setIncomingPluginHash] = useState(''); + const [showingModal, showModal] = useState(false); + const isProving = useP2PProving(); + const isVerifying = useP2PVerifying(); + const presentation = useP2PPresentation(); + + useEffect(() => { + (async () => { + if (!incomingProofRequest) { + setIncomingPluginHash(''); + return; + } + const hash = await sha256(incomingProofRequest); + setIncomingPluginHash(hash); + })(); + }, [incomingProofRequest]); + + useEffect(() => { + showModal(false); + }, [outgoingPluginHash]); + + const accept = useCallback(async () => { + if (incomingPluginHash) { + await openSidePanel(); + + browser.runtime.sendMessage({ + type: SidePanelActionTypes.run_p2p_plugin_request, + data: { + pluginHash: incomingPluginHash, + plugin: incomingProofRequest, + }, + }); + + acceptProofRequest(incomingPluginHash); + + window.close(); + } + }, [incomingPluginHash, incomingProofRequest, clientId]); + + const reject = useCallback(() => { + if (incomingPluginHash) rejectProofRequest(incomingPluginHash); + }, [incomingPluginHash]); + + const cancel = useCallback(() => { + if (outgoingPluginHash) cancelProofRequest(outgoingPluginHash); + }, [outgoingPluginHash]); + + let body; + + if (incomingPluginHash) { + body = ( + + ); + } else if (outgoingPluginHash) { + body = ( + + ); + } else { + body = ( + + ); + } + + return ( +
+ {showingModal && showModal(false)} />} +
+ Paired with + {pairId} +
+ {body} +
+ ); +} + +function IncomingProof({ + incomingPluginHash, + incomingProofRequest, + reject, + accept, + isProving, +}: { + incomingPluginHash: string; + incomingProofRequest: string; + reject: () => void; + accept: () => void; + isProving: boolean; +}) { + const presentation = useP2PPresentation(); + const [showingTranscript, showTranscript] = useState(false); + + if (isProving) { + return ( + <> + {presentation && showingTranscript && ( + showTranscript(false)} + > + + + )} +
+ {presentation ? 'Proving Completed' : 'Proving to your peer...'} +
+ null} + unremovable + /> +
+ +
+ + ); + } + + return ( + <> +
+ Your peer is requesting the following proof: +
+ null} + unremovable + /> +
+ + +
+ + ); +} + +function OutgoingProof({ + outgoingPluginHash, + cancel, + isVerifying, +}: { + isVerifying: boolean; + outgoingPluginHash: string; + cancel: () => void; +}) { + const presentation = useP2PPresentation(); + const [showingTranscript, showTranscript] = useState(false); + + if (isVerifying) { + return ( + <> + {presentation && showingTranscript && ( + showTranscript(false)} + > + + + )} +
+ {presentation + ? 'Verification Completed' + : 'Verifying with your peer...'} +
+ null} + unremovable + /> +
+ +
+ + ); + } + + return ( + <> +
+ Sent request for following proof: +
+ null} + unremovable + /> + + + ); +} + +function PluginListModal({ onClose }: { onClose: () => void }) { + const onRequestProof = useCallback(async (hash: string) => { + requestProofByHash(hash); + }, []); + return ( + + Choose a plugin to continue + + + ); +} + +function IncomingRequest() { + const [incomingRequest] = useIncomingPairingRequests(); + + const accept = useCallback(() => { + if (incomingRequest) acceptPairRequest(incomingRequest); + }, [incomingRequest]); + + const reject = useCallback(() => { + if (incomingRequest) rejectPairRequest(incomingRequest); + }, [incomingRequest]); + + return ( +
+
+ {incomingRequest} + wants to pair with you. +
+
+ + +
+
+ ); +} + +function OutgoingRequest() { + const [outgoingRequest] = useOutgoingPairingRequests(); + + const cancel = useCallback(() => { + if (outgoingRequest) { + cancelPairRequest(outgoingRequest); + } + }, [outgoingRequest]); + + return ( +
+ + + + Awaiting response from + {outgoingRequest} + ... + + + +
+ ); +} + +function ClientNotStarted() { + return ( +
+ Client has not started + +
+ ); +} + +function PendingConnection() { + const dispatch = useDispatch(); + const [target, setTarget] = useState(''); + + const onSend = useCallback(() => { + dispatch(setP2PError('')); + sendPairRequest(target); + }, [target]); + + const onChange = useCallback((e: ChangeEvent) => { + dispatch(setP2PError('')); + setTarget(e.target.value); + }, []); + + return ( +
+
+ +
+ Waiting for pairing request... +
+
+
or
+
+ + +
+
+ ); +} diff --git a/src/pages/ProofViewer/index.tsx b/src/pages/ProofViewer/index.tsx index bda20e4f..62655785 100644 --- a/src/pages/ProofViewer/index.tsx +++ b/src/pages/ProofViewer/index.tsx @@ -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 { @@ -20,7 +22,12 @@ export default function ProofViewer(props?: { const [tab, setTab] = useState('sent'); return ( -
+
; diff --git a/src/reducers/p2p.ts b/src/reducers/p2p.ts new file mode 100644 index 00000000..03fb150b --- /dev/null +++ b/src/reducers/p2p.ts @@ -0,0 +1,375 @@ +import { useSelector } from 'react-redux'; +import { AppRootState } from './index'; +import deepEqual from 'fast-deep-equal'; +import browser from 'webextension-polyfill'; +import { BackgroundActiontype } from '../entries/Background/rpc'; + +enum ActionType { + '/p2p/setConnected' = '/p2p/setConnected', + '/p2p/setClientId' = '/p2p/setClientId', + '/p2p/setPairing' = '/p2p/setPairing', + '/p2p/setError' = '/p2p/setError', + '/p2p/appendIncomingPairingRequest' = '/p2p/appendIncomingPairingRequest', + '/p2p/appendOutgoingPairingRequest' = '/p2p/appendOutgoingPairingRequest', + '/p2p/setIncomingPairingRequest' = '/p2p/setIncomingPairingRequest', + '/p2p/setOutgoingPairingRequest' = '/p2p/setOutgoingPairingRequest', + '/p2p/appendIncomingProofRequest' = '/p2p/appendIncomingProofRequest', + '/p2p/appendOutgoingProofRequest' = '/p2p/appendOutgoingProofRequest', + '/p2p/setIncomingProofRequest' = '/p2p/setIncomingProofRequest', + '/p2p/setOutgoingProofRequest' = '/p2p/setOutgoingProofRequest', + '/p2p/setIsProving' = '/p2p/setIsProving', + '/p2p/setIsVerifying' = '/p2p/setIsVerifying', + '/p2p/setPresentation' = '/p2p/setPresentation', +} + +type Action = { + type: ActionType; + payload?: payload; + error?: boolean; + meta?: any; +}; + +type State = { + clientId: string; + pairing: string; + connected: boolean; + error: string; + incomingPairingRequests: string[]; + outgoingPairingRequests: string[]; + incomingProofRequests: string[]; + outgoingProofRequests: string[]; + isProving: boolean; + isVerifying: boolean; + presentation: null | { + sent: string; + recv: string; + }; +}; + +export type RequestProofMessage = { + to: string; + from: string; + id: number; + text?: undefined; +}; + +const initialState: State = { + clientId: '', + pairing: '', + error: '', + connected: false, + incomingPairingRequests: [], + outgoingPairingRequests: [], + incomingProofRequests: [], + outgoingProofRequests: [], + isProving: false, + isVerifying: false, + presentation: null, +}; + +export const fetchP2PState = async () => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.get_p2p_state, + }); +}; + +export const connectRendezvous = () => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.connect_rendezvous, + }); +}; + +export const disconnectRendezvous = () => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.disconnect_rendezvous, + }); +}; + +export const setConnected = (connected = false) => ({ + type: ActionType['/p2p/setConnected'], + payload: connected, +}); + +export const setClientId = (clientId: string) => ({ + type: ActionType['/p2p/setClientId'], + payload: clientId, +}); + +export const setPairing = (clientId: string) => ({ + type: ActionType['/p2p/setPairing'], + payload: clientId, +}); + +export const appendIncomingPairingRequests = (peerId: string) => ({ + type: ActionType['/p2p/appendIncomingPairingRequest'], + payload: peerId, +}); + +export const appendIncomingProofRequests = (peerId: string) => ({ + type: ActionType['/p2p/appendIncomingProofRequest'], + payload: peerId, +}); + +export const appendOutgoingPairingRequests = (peerId: string) => ({ + type: ActionType['/p2p/appendOutgoingPairingRequest'], + payload: peerId, +}); + +export const appendOutgoingProofRequest = (peerId: string) => ({ + type: ActionType['/p2p/appendOutgoingProofRequest'], + payload: peerId, +}); + +export const setIncomingPairingRequest = (peerIds: string[]) => ({ + type: ActionType['/p2p/setIncomingPairingRequest'], + payload: peerIds, +}); + +export const setOutgoingPairingRequest = (peerIds: string[]) => ({ + type: ActionType['/p2p/setOutgoingPairingRequest'], + payload: peerIds, +}); + +export const setIncomingProofRequest = (peerIds: string[]) => ({ + type: ActionType['/p2p/setIncomingProofRequest'], + payload: peerIds, +}); + +export const setOutgoingProofRequest = (peerIds: string[]) => ({ + type: ActionType['/p2p/setOutgoingProofRequest'], + payload: peerIds, +}); + +export const setP2PError = (error: string) => ({ + type: ActionType['/p2p/setError'], + payload: error, +}); + +export const setIsProving = (proving: boolean) => ({ + type: ActionType['/p2p/setIsProving'], + payload: proving, +}); + +export const setIsVerifying = (verifying: boolean) => ({ + type: ActionType['/p2p/setIsVerifying'], + payload: verifying, +}); + +export const setP2PPresentation = ( + presentation: null | { sent: string; recv: string }, +) => ({ + type: ActionType['/p2p/setPresentation'], + payload: presentation, +}); + +export const requestProofByHash = (pluginHash: string) => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.request_p2p_proof_by_hash, + data: pluginHash, + }); +}; + +export const sendPairRequest = async (targetId: string) => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.send_pair_request, + data: targetId, + }); +}; + +export const cancelPairRequest = async (targetId: string) => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.cancel_pair_request, + data: targetId, + }); +}; + +export const acceptPairRequest = async (targetId: string) => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.accept_pair_request, + data: targetId, + }); +}; + +export const rejectPairRequest = async (targetId: string) => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.reject_pair_request, + data: targetId, + }); +}; + +export const cancelProofRequest = async (plughinHash: string) => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.cancel_proof_request, + data: plughinHash, + }); +}; + +export const acceptProofRequest = async (plughinHash: string) => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.accept_proof_request, + data: plughinHash, + }); +}; + +export const rejectProofRequest = async (plughinHash: string) => { + return browser.runtime.sendMessage({ + type: BackgroundActiontype.reject_proof_request, + data: plughinHash, + }); +}; + +export default function p2p(state = initialState, action: Action): State { + switch (action.type) { + case ActionType['/p2p/setConnected']: + return { + ...state, + connected: action.payload, + }; + case ActionType['/p2p/setClientId']: + return { + ...state, + clientId: action.payload, + }; + case ActionType['/p2p/setPairing']: + return { + ...state, + pairing: action.payload, + }; + case ActionType['/p2p/appendIncomingPairingRequest']: + return { + ...state, + incomingPairingRequests: [ + ...new Set(state.incomingPairingRequests.concat(action.payload)), + ], + }; + case ActionType['/p2p/appendOutgoingPairingRequest']: + return { + ...state, + outgoingPairingRequests: [ + ...new Set(state.outgoingPairingRequests.concat(action.payload)), + ], + }; + case ActionType['/p2p/setIncomingPairingRequest']: + return { + ...state, + incomingPairingRequests: action.payload, + }; + case ActionType['/p2p/setOutgoingPairingRequest']: + return { + ...state, + outgoingPairingRequests: action.payload, + }; + case ActionType['/p2p/appendIncomingProofRequest']: + return { + ...state, + incomingProofRequests: [ + ...new Set(state.incomingProofRequests.concat(action.payload)), + ], + }; + case ActionType['/p2p/appendOutgoingProofRequest']: + return { + ...state, + outgoingProofRequests: [ + ...new Set(state.outgoingProofRequests.concat(action.payload)), + ], + }; + case ActionType['/p2p/setIncomingProofRequest']: + return { + ...state, + incomingProofRequests: action.payload, + }; + case ActionType['/p2p/setOutgoingProofRequest']: + return { + ...state, + outgoingProofRequests: action.payload, + }; + case ActionType['/p2p/setError']: + return { + ...state, + error: action.payload, + }; + case ActionType['/p2p/setIsProving']: + return { + ...state, + isProving: action.payload, + }; + case ActionType['/p2p/setIsVerifying']: + return { + ...state, + isVerifying: action.payload, + }; + case ActionType['/p2p/setPresentation']: + return { + ...state, + presentation: action.payload, + }; + default: + return state; + } +} + +export function useClientId() { + return useSelector((state: AppRootState) => { + return state.p2p.clientId; + }, deepEqual); +} + +export function useConnected() { + return useSelector((state: AppRootState) => { + return state.p2p.connected; + }, deepEqual); +} + +export function usePairId(): string { + return useSelector((state: AppRootState) => { + return state.p2p.pairing; + }, deepEqual); +} + +export function useIncomingPairingRequests(): string[] { + return useSelector((state: AppRootState) => { + return state.p2p.incomingPairingRequests; + }, deepEqual); +} + +export function useOutgoingPairingRequests(): string[] { + return useSelector((state: AppRootState) => { + return state.p2p.outgoingPairingRequests; + }, deepEqual); +} + +export function useIncomingProofRequests(): string[] { + return useSelector((state: AppRootState) => { + return state.p2p.incomingProofRequests; + }, deepEqual); +} + +export function useOutgoingProofRequests(): string[] { + return useSelector((state: AppRootState) => { + return state.p2p.outgoingProofRequests; + }, deepEqual); +} + +export function useP2PError(): string { + return useSelector((state: AppRootState) => { + return state.p2p.error; + }, deepEqual); +} + +export function useP2PVerifying(): boolean { + return useSelector((state: AppRootState) => { + return state.p2p.isVerifying; + }, deepEqual); +} + +export function useP2PProving(): boolean { + return useSelector((state: AppRootState) => { + return state.p2p.isProving; + }, deepEqual); +} + +export function useP2PPresentation(): null | { sent: string; recv: string } { + return useSelector((state: AppRootState) => { + return state.p2p.presentation; + }, deepEqual); +} diff --git a/src/reducers/plugins.tsx b/src/reducers/plugins.tsx index 7fa12461..8b77f6c7 100644 --- a/src/reducers/plugins.tsx +++ b/src/reducers/plugins.tsx @@ -6,6 +6,8 @@ import { getPluginConfigByHash } from '../entries/Background/db'; import { PluginConfig } from '../utils/misc'; import { runPlugin } from '../utils/rpc'; import browser from 'webextension-polyfill'; +import { openSidePanel } from '../entries/utils'; +import { SidePanelActionTypes } from '../entries/SidePanel/types'; enum ActionType { '/plugin/addPlugin' = '/plugin/addPlugin', @@ -70,17 +72,18 @@ export const usePluginConfig = (hash: string) => { export const useOnPluginClick = (hash: string) => { return useCallback(async () => { - await runPlugin(hash, 'start'); + await browser.storage.local.set({ plugin_hash: hash }); - const [tab] = await browser.tabs.query({ - active: true, - currentWindow: true, - }); + await openSidePanel(); - await browser.storage.local.set({ plugin_hash: hash }); + browser.runtime.sendMessage({ + type: SidePanelActionTypes.execute_plugin_request, + data: { + pluginHash: hash, + }, + }); - // @ts-ignore - if (chrome.sidePanel) await chrome.sidePanel.open({ tabId: tab.id }); + await runPlugin(hash, 'start'); window.close(); }, [hash]); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 56324872..94473ae0 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,5 +1,6 @@ export const EXPLORER_API = 'https://explorer.tlsnotary.org'; export const NOTARY_API = 'https://notary.pse.dev/v0.1.0-alpha.7'; +export const RENDEZVOUS_API = 'wss://explorer.tlsnotary.org'; export const NOTARY_PROXY = 'wss://notary.pse.dev/proxy'; export const MAX_RECV = 16384; export const MAX_SENT = 4096; diff --git a/src/utils/misc.ts b/src/utils/misc.ts index df9a5b48..0a66be91 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -1,5 +1,6 @@ import { BackgroundActiontype, + handleExecP2PPluginProver, handleExecPluginProver, RequestLog, } from '../entries/Background/rpc'; @@ -148,6 +149,10 @@ const VALID_HOST_FUNCS: { [name: string]: string } = { export const makePlugin = async ( arrayBuffer: ArrayBuffer, config?: PluginConfig, + meta?: { + p2p: boolean; + clientId: string; + }, ) => { const module = await WebAssembly.compile(arrayBuffer); const [tab] = await browser.tabs.query({ active: true, currentWindow: true }); @@ -201,22 +206,37 @@ export const makePlugin = async ( (async () => { const { getSecretResponse, body: reqBody } = params; - handleExecPluginProver({ - type: BackgroundActiontype.execute_plugin_prover, - data: { - ...params, - body: reqBody, - getSecretResponseFn: async (body: string) => { - return new Promise((resolve) => { - setTimeout(async () => { - const out = await plugin.call(getSecretResponse, body); - resolve(JSON.parse(out.string())); - }, 0); - }); + if (meta?.p2p) { + const pluginHex = Buffer.from(arrayBuffer).toString('hex'); + handleExecP2PPluginProver({ + type: BackgroundActiontype.execute_p2p_plugin_prover, + data: { + ...params, + pluginHash: await sha256(pluginHex), + pluginHex, + body: reqBody, + now, + clientId: meta.clientId, }, - now, - }, - }); + }); + } else { + handleExecPluginProver({ + type: BackgroundActiontype.execute_plugin_prover, + data: { + ...params, + body: reqBody, + getSecretResponseFn: async (body: string) => { + return new Promise((resolve) => { + setTimeout(async () => { + const out = await plugin.call(getSecretResponse, body); + resolve(JSON.parse(out.string())); + }, 0); + }); + }, + now, + }, + }); + } })(); return context.store(`${id}`); diff --git a/src/utils/plugins.tsx b/src/utils/plugins.tsx index 4cd8f9bc..5d163e4e 100644 --- a/src/utils/plugins.tsx +++ b/src/utils/plugins.tsx @@ -13,7 +13,7 @@ export const HostFunctionsDescriptions: { ); }, notarize: ({ notaryUrls, proxyUrls }) => { - const notaries = ['default notary'].concat(notaryUrls || []); + const notaries = ['default notary', 'your peer'].concat(notaryUrls || []); const proxies = ['default proxy'].concat(proxyUrls || []); return ( diff --git a/src/utils/rpc.ts b/src/utils/rpc.ts index a41e749f..205b4a34 100644 --- a/src/utils/rpc.ts +++ b/src/utils/rpc.ts @@ -38,7 +38,12 @@ export async function fetchPluginConfigByHash( }); } -export async function runPlugin(hash: string, method: string, params?: string) { +export async function runPlugin( + hash: string, + method: string, + params?: string, + meta?: any, +) { return browser.runtime.sendMessage({ type: BackgroundActiontype.run_plugin, data: { @@ -46,5 +51,6 @@ export async function runPlugin(hash: string, method: string, params?: string) { method, params, }, + meta, }); } diff --git a/src/utils/storage.ts b/src/utils/storage.ts index 691a1237..d00d4fee 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -1,11 +1,13 @@ import { LoggingLevel } from 'tlsn-js'; import { MAX_RECV, MAX_SENT, NOTARY_API, NOTARY_PROXY } from './constants'; +import { RENDEZVOUS_API } from './constants'; export const NOTARY_API_LS_KEY = 'notary-api'; export const PROXY_API_LS_KEY = 'proxy-api'; export const MAX_SENT_LS_KEY = 'max-sent'; export const MAX_RECEIVED_LS_KEY = 'max-received'; export const LOGGING_FILTER_KEY = 'logging-filter-2'; +export const RENDEZVOUS_API_LS_KEY = 'rendezvous-api'; export async function set(key: string, value: string) { return chrome.storage.sync.set({ [key]: value }); @@ -37,3 +39,7 @@ export async function getProxyApi() { export async function getLoggingFilter(): Promise { return await get(LOGGING_FILTER_KEY, 'Info'); } + +export async function getRendezvousApi(): Promise { + return await get(RENDEZVOUS_API_LS_KEY, RENDEZVOUS_API); +} From ed3e797bad8a8ee3619cdd31118084c84b38a06f Mon Sep 17 00:00:00 2001 From: tsukino <87639218+0xtsukino@users.noreply.github.com> Date: Fri, 8 Nov 2024 02:55:31 -0500 Subject: [PATCH 5/6] fix: send correct message on plugin execution using content script (#116) * fix: send correct message on plugin execution using content script * fix: get plugins filter logic and run plugin message timing on content script --- src/entries/Background/db.ts | 14 ++++++++++---- src/pages/GetPluginsApproval/index.tsx | 2 +- src/pages/RunPluginApproval/index.tsx | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/entries/Background/db.ts b/src/entries/Background/db.ts index 4677e03b..1b2b760d 100644 --- a/src/entries/Background/db.ts +++ b/src/entries/Background/db.ts @@ -234,10 +234,16 @@ export async function getPlugins(): Promise< ret.push({ ...config, hash, - metadata: metadata || { - filePath: '', - origin: '', - }, + metadata: metadata + ? { + ...metadata, + hash, + } + : { + filePath: '', + origin: '', + hash, + }, }); } } diff --git a/src/pages/GetPluginsApproval/index.tsx b/src/pages/GetPluginsApproval/index.tsx index f6e45091..8ed2e0d2 100644 --- a/src/pages/GetPluginsApproval/index.tsx +++ b/src/pages/GetPluginsApproval/index.tsx @@ -58,7 +58,7 @@ export function GetPluginsApproval(): ReactElement { }); setResult(res); })(); - }, [url, filterMetadata]); + }, [url, JSON.stringify(filterMetadata)]); return ( { + if (request.type === SidePanelActionTypes.panel_opened) { + browser.runtime.onMessage.removeListener(listener); + resolve(); + } + }; + + browser.runtime.onMessage.addListener(listener); + // @ts-ignore if (chrome.sidePanel) await chrome.sidePanel.open({ tabId: tab.id }); + await promise; + + browser.runtime.sendMessage({ + type: SidePanelActionTypes.execute_plugin_request, + data: { + pluginHash: hash, + }, + }); + browser.runtime.sendMessage({ type: BackgroundActiontype.run_plugin_response, data: true, From 4c908d06115e7fd85b5aa543e14c616a9fd8c229 Mon Sep 17 00:00:00 2001 From: tsukino <87639218+0xtsukino@users.noreply.github.com> Date: Fri, 8 Nov 2024 02:56:57 -0500 Subject: [PATCH 6/6] chore: version pump (#117) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c2ab6e08..30095085 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tlsn-extension", - "version": "0.1.0.700", + "version": "0.1.0.702", "license": "MIT", "repository": { "type": "git",