add github action

This commit is contained in:
0xtsukino
2023-08-24 19:46:29 -07:00
committed by tsukino
parent bc2b89f41d
commit 66fb4f4d19
8 changed files with 156 additions and 56 deletions

46
.github/workflows/build.yaml vendored Normal file
View File

@@ -0,0 +1,46 @@
name: build
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: Build
run: npm run build

46
.github/workflows/lint.yaml vendored Normal file
View File

@@ -0,0 +1,46 @@
name: lint
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: Lint
run: npm run lint

View File

@@ -4,3 +4,5 @@ wasm
tlsn
postcss.config.js
webpack.config.js
*.json
*.scss

View File

@@ -9,11 +9,10 @@
"scripts": {
"clone:tlsn": "git clone https://github.com/tlsnotary/tlsn",
"build:wasm": "wasm-pack build --target web wasm/prover",
"build": "node utils/build.js",
"dev": "node utils/webserver.js",
"build": "NODE_ENV=production node utils/build.js",
"dev": "NODE_ENV=development node utils/webserver.js",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prettier": "prettier --write '**/*.{js,jsx,ts,tsx,json,css,scss,md}'"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.4.2",

View File

@@ -20,10 +20,12 @@ const cache = new NodeCache({
});
chrome.tabs.onActivated.addListener((tabs) => {
RequestsLogs[tabs.tabId] = RequestsLogs[tabs.tabId] || new NodeCache({
stdTTL: 60 * 5, // default 5m TTL
maxKeys: 1000000,
});
RequestsLogs[tabs.tabId] =
RequestsLogs[tabs.tabId] ||
new NodeCache({
stdTTL: 60 * 5, // default 5m TTL
maxKeys: 1000000,
});
});
chrome.tabs.onRemoved.addListener((tab) => {
@@ -37,10 +39,12 @@ chrome.tabs.onRemoved.addListener((tab) => {
const { method, tabId, requestId } = details;
if (method !== 'OPTIONS') {
RequestsLogs[tabId] = RequestsLogs[tabId] || new NodeCache({
stdTTL: 60 * 5, // default 5m TTL
maxKeys: 1000000,
});
RequestsLogs[tabId] =
RequestsLogs[tabId] ||
new NodeCache({
stdTTL: 60 * 5, // default 5m TTL
maxKeys: 1000000,
});
const existing = RequestsLogs[tabId].get<RequestLog>(requestId);
RequestsLogs[tabId].set(requestId, {
...existing,
@@ -65,14 +69,16 @@ chrome.tabs.onRemoved.addListener((tab) => {
(details) => {
mutex.runExclusive(async () => {
const { method, requestBody, tabId, requestId } = details;
if (method === 'OPTIONS') return;
if (requestBody) {
RequestsLogs[tabId] = RequestsLogs[tabId] || new NodeCache({
stdTTL: 60 * 5, // default 5m TTL
maxKeys: 1000000,
});
RequestsLogs[tabId] =
RequestsLogs[tabId] ||
new NodeCache({
stdTTL: 60 * 5, // default 5m TTL
maxKeys: 1000000,
});
const existing = RequestsLogs[tabId].get<RequestLog>(requestId);
@@ -80,12 +86,13 @@ chrome.tabs.onRemoved.addListener((tab) => {
try {
RequestsLogs[details.tabId].set(requestId, {
...existing,
requestBody: Buffer.from(requestBody.raw[0].bytes).toString('utf-8'),
requestBody: Buffer.from(requestBody.raw[0].bytes).toString(
'utf-8',
),
});
} catch (e) {
console.error(e);
}
} else if (requestBody.formData) {
RequestsLogs[details.tabId].set(requestId, {
...existing,
@@ -104,14 +111,16 @@ chrome.tabs.onRemoved.addListener((tab) => {
chrome.webRequest.onResponseStarted.addListener(
(details) => {
mutex.runExclusive(async () => {
const { method, responseHeaders, tabId, requestId, } = details;
const { method, responseHeaders, tabId, requestId } = details;
if (method === 'OPTIONS') return;
RequestsLogs[tabId] = RequestsLogs[tabId] || new NodeCache({
stdTTL: 60 * 5, // default 5m TTL
maxKeys: 1000000,
});
RequestsLogs[tabId] =
RequestsLogs[tabId] ||
new NodeCache({
stdTTL: 60 * 5, // default 5m TTL
maxKeys: 1000000,
});
const existing = RequestsLogs[tabId].get<RequestLog>(requestId);
const newLog: RequestLog = {
@@ -150,7 +159,7 @@ chrome.tabs.onRemoved.addListener((tab) => {
const keys = RequestsLogs[request.data]?.keys() || [];
const data = keys.map((key) => RequestsLogs[request.data]?.get(key));
return sendResponse((data));
return sendResponse(data);
}
case BackgroundActiontype.clear_requests: {
RequestsLogs = {};

View File

@@ -1,4 +1,10 @@
import React, { MouseEventHandler, ReactElement, ReactNode, useCallback, useState } from 'react';
import React, {
MouseEventHandler,
ReactElement,
ReactNode,
useCallback,
useState,
} from 'react';
import Icon from '../../components/Icon';
import classNames from 'classnames';
import { useNavigate } from 'react-router';
@@ -32,9 +38,11 @@ export default function Home(): ReactElement {
History
</NavButton>
</div>
<div className='flex flex-col flex-nowrap justify-center items-center gap-2 bg-slate-100 border border-slate-200 p-2 mb-4'>
<div className='text-sm text-slate-300'><b>Dev</b></div>
<div className='flex flex-row flex-nowrap justify-center'>
<div className="flex flex-col flex-nowrap justify-center items-center gap-2 bg-slate-100 border border-slate-200 p-2 mb-4">
<div className="text-sm text-slate-300">
<b>Dev</b>
</div>
<div className="flex flex-row flex-nowrap justify-center">
<button
className="right-2 bg-primary/[0.9] text-white font-bold px-2 py-0.5 hover:bg-primary/[0.8] active:bg-primary"
onClick={async () => {
@@ -49,11 +57,7 @@ export default function Home(): ReactElement {
Notarize
</button>
</div>
{wasmRes && (
<div>
{wasmRes}
</div>
)}
{wasmRes && <div>{wasmRes}</div>}
</div>
{!suggestions.length && (
<div className="flex flex-col flex-nowrap">

View File

@@ -2,35 +2,30 @@ import React, { useEffect } from 'react';
import * as Comlink from 'comlink';
import { BackgroundActiontype } from '../Background/actionTypes';
const Offscreen = () => {
useEffect(() => {
(async function offscreenloaded() {
console.log('offscreen loaded - spawning worker from worker.ts');
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
switch (request.type) {
case BackgroundActiontype.test_wasm: {
const TLSN: any = Comlink.wrap(
new Worker(new URL('./worker.ts', import.meta.url)),
);
chrome.runtime.onMessage.addListener(
(request, sender, sendResponse) => {
switch (request.type) {
case BackgroundActiontype.test_wasm: {
const TLSN: any = Comlink.wrap(
new Worker(new URL('./worker.ts', import.meta.url)),
);
new TLSN().then(async (tlsn: any) => {
const data = await tlsn.prover();
sendResponse({ data });
});
new TLSN().then(async (tlsn: any) => {
const data = await tlsn.prover();
sendResponse({data});
});
break;
}
default:
break;
break;
}
return true;
},
);
default:
break;
}
return true;
});
})();
}, []);

View File

@@ -26,7 +26,6 @@ class TLSN {
console.log(e);
return e;
}
}
}