-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): format javascript code using prettier
- Loading branch information
Showing
11 changed files
with
754 additions
and
637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
const presets = [ | ||
[ | ||
"@babel/preset-env", | ||
] | ||
]; | ||
const presets = [["@babel/preset-env"]]; | ||
|
||
module.exports = { presets }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,121 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<title>TFHE-RS Web Wasm Demo</title> | ||
<body> | ||
<style> | ||
.loader { | ||
border: 16px solid #f3f3f3; /* Light grey */ | ||
border-top: 16px solid #3498db; /* Blue */ | ||
border-radius: 50%; | ||
width: 120px; | ||
height: 120px; | ||
animation: spin 2s linear infinite; | ||
} | ||
<style> | ||
.loader { | ||
border: 16px solid #f3f3f3; /* Light grey */ | ||
border-top: 16px solid #3498db; /* Blue */ | ||
border-radius: 50%; | ||
width: 120px; | ||
height: 120px; | ||
animation: spin 2s linear infinite; | ||
} | ||
|
||
@keyframes spin { | ||
0% { transform: rotate(0deg); } | ||
100% { transform: rotate(360deg); } | ||
} | ||
</style> | ||
@keyframes spin { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
</style> | ||
|
||
<div> | ||
<input type="button" id="publicKeyTest" value="Public Key Test" disabled /> | ||
<input type="button" id="compressedPublicKeyTest" value="Compressed Public Key Test" disabled /> | ||
<div> | ||
<input type="button" id="publicKeyTest" value="Public Key Test" disabled /> | ||
<input | ||
type="button" | ||
id="compressedPublicKeyTest" | ||
value="Compressed Public Key Test" | ||
disabled | ||
/> | ||
|
||
<input type="button" id="compactPublicKeyTest32BitSmall" value="Compact Public Key Test 32 Bits Small" disabled /> | ||
<input type="button" id="compactPublicKeyTest32BitBig" value="Compact Public Key Test 32 Bits Big" disabled /> | ||
<input | ||
type="button" | ||
id="compactPublicKeyTest32BitSmall" | ||
value="Compact Public Key Test 32 Bits Small" | ||
disabled | ||
/> | ||
<input | ||
type="button" | ||
id="compactPublicKeyTest32BitBig" | ||
value="Compact Public Key Test 32 Bits Big" | ||
disabled | ||
/> | ||
|
||
<input type="button" id="compactPublicKeyTest256BitSmall" value="Compact Public Key Test 256 Bits Small" disabled /> | ||
<input type="button" id="compactPublicKeyTest256BitBig" value="Compact Public Key Test 256 Bits Big" disabled /> | ||
<input | ||
type="button" | ||
id="compactPublicKeyTest256BitSmall" | ||
value="Compact Public Key Test 256 Bits Small" | ||
disabled | ||
/> | ||
<input | ||
type="button" | ||
id="compactPublicKeyTest256BitBig" | ||
value="Compact Public Key Test 256 Bits Big" | ||
disabled | ||
/> | ||
|
||
<input type="button" id="compressedCompactPublicKeyTest256BitSmall" value="Compressed Compact Public Key Test 256 Bits Small" disabled /> | ||
<input type="button" id="compressedCompactPublicKeyTest256BitBig" value="Compressed Compact Public Key Test 256 Bits Big" disabled /> | ||
<input | ||
type="button" | ||
id="compressedCompactPublicKeyTest256BitSmall" | ||
value="Compressed Compact Public Key Test 256 Bits Small" | ||
disabled | ||
/> | ||
<input | ||
type="button" | ||
id="compressedCompactPublicKeyTest256BitBig" | ||
value="Compressed Compact Public Key Test 256 Bits Big" | ||
disabled | ||
/> | ||
|
||
<input type="checkbox" id="testSuccess" disabled> | ||
<label for="testSuccess"> TestSuccess </label><br> | ||
<input type="checkbox" id="testSuccess" disabled /> | ||
<label for="testSuccess"> TestSuccess </label><br /> | ||
|
||
<input type="button" id="compactPublicKeyBench32BitSmall" value="Compact Public Key Bench 32 Bits Small" disabled /> | ||
<input type="button" id="compactPublicKeyBench32BitBig" value="Compact Public Key Bench 32 Bits Big" disabled /> | ||
<input | ||
type="button" | ||
id="compactPublicKeyBench32BitSmall" | ||
value="Compact Public Key Bench 32 Bits Small" | ||
disabled | ||
/> | ||
<input | ||
type="button" | ||
id="compactPublicKeyBench32BitBig" | ||
value="Compact Public Key Bench 32 Bits Big" | ||
disabled | ||
/> | ||
|
||
<input type="button" id="compactPublicKeyBench256BitSmall" value="Compact Public Key Bench 256 Bits Small" disabled /> | ||
<input type="button" id="compactPublicKeyBench256BitBig" value="Compact Public Key Bench 256 Bits Big" disabled /> | ||
<input | ||
type="button" | ||
id="compactPublicKeyBench256BitSmall" | ||
value="Compact Public Key Bench 256 Bits Small" | ||
disabled | ||
/> | ||
<input | ||
type="button" | ||
id="compactPublicKeyBench256BitBig" | ||
value="Compact Public Key Bench 256 Bits Big" | ||
disabled | ||
/> | ||
|
||
<input type="button" id="compressedServerKeyBenchMessage1Carry1" value="Compressed Server Key Bench 1_1" disabled /> | ||
<input type="button" id="compressedServerKeyBenchMessage2Carry2" value="Compressed Server Key Bench 2_2" disabled /> | ||
<input | ||
type="button" | ||
id="compressedServerKeyBenchMessage1Carry1" | ||
value="Compressed Server Key Bench 1_1" | ||
disabled | ||
/> | ||
<input | ||
type="button" | ||
id="compressedServerKeyBenchMessage2Carry2" | ||
value="Compressed Server Key Bench 2_2" | ||
disabled | ||
/> | ||
|
||
<input type="text" id="benchmarkResults" disabled> | ||
<label for="benchmarkResults"> BenchmarkResults </label><br> | ||
<input type="text" id="benchmarkResults" disabled /> | ||
<label for="benchmarkResults"> BenchmarkResults </label><br /> | ||
|
||
<div id="loader" class="loader" hidden></div> | ||
</div> | ||
<div id="loader" class="loader" hidden></div> | ||
</div> | ||
|
||
<script type="module" src="index.js"></script> | ||
<script type="module" src="index.js"></script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,85 @@ | ||
import { threads } from 'wasm-feature-detect'; | ||
import * as Comlink from 'comlink'; | ||
|
||
import { threads } from "wasm-feature-detect"; | ||
import * as Comlink from "comlink"; | ||
|
||
function setButtonsDisabledState(buttonIds, state) { | ||
for (let id of buttonIds) { | ||
let btn = document.getElementById(id); | ||
if (btn) { | ||
btn.disabled = state; | ||
} | ||
for (let id of buttonIds) { | ||
let btn = document.getElementById(id); | ||
if (btn) { | ||
btn.disabled = state; | ||
} | ||
} | ||
} | ||
|
||
async function setup() { | ||
let supportsThreads = await threads() | ||
if (!supportsThreads) { | ||
console.error("This browser does not support threads") | ||
return | ||
} | ||
let supportsThreads = await threads(); | ||
if (!supportsThreads) { | ||
console.error("This browser does not support threads"); | ||
return; | ||
} | ||
|
||
const worker = new Worker( | ||
new URL("worker.js", import.meta.url), | ||
{type: 'module'} | ||
); | ||
const demos = await Comlink.wrap(worker).demos; | ||
const worker = new Worker(new URL("worker.js", import.meta.url), { | ||
type: "module", | ||
}); | ||
const demos = await Comlink.wrap(worker).demos; | ||
|
||
const demoNames = [ | ||
'publicKeyTest', | ||
'compressedPublicKeyTest', | ||
'compactPublicKeyTest32BitBig', | ||
'compactPublicKeyTest32BitSmall', | ||
'compactPublicKeyTest256BitBig', | ||
'compactPublicKeyTest256BitSmall', | ||
'compressedCompactPublicKeyTest256BitBig', | ||
'compressedCompactPublicKeyTest256BitSmall', | ||
'compactPublicKeyBench32BitBig', | ||
'compactPublicKeyBench32BitSmall', | ||
'compactPublicKeyBench256BitBig', | ||
'compactPublicKeyBench256BitSmall', | ||
'compressedServerKeyBenchMessage1Carry1', | ||
'compressedServerKeyBenchMessage2Carry2', | ||
] | ||
const demoNames = [ | ||
"publicKeyTest", | ||
"compressedPublicKeyTest", | ||
"compactPublicKeyTest32BitBig", | ||
"compactPublicKeyTest32BitSmall", | ||
"compactPublicKeyTest256BitBig", | ||
"compactPublicKeyTest256BitSmall", | ||
"compressedCompactPublicKeyTest256BitBig", | ||
"compressedCompactPublicKeyTest256BitSmall", | ||
"compactPublicKeyBench32BitBig", | ||
"compactPublicKeyBench32BitSmall", | ||
"compactPublicKeyBench256BitBig", | ||
"compactPublicKeyBench256BitSmall", | ||
"compressedServerKeyBenchMessage1Carry1", | ||
"compressedServerKeyBenchMessage2Carry2", | ||
]; | ||
|
||
function setupBtn(id) { | ||
// Handlers are named in the same way as buttons. | ||
let fn = demos[id]; | ||
function setupBtn(id) { | ||
// Handlers are named in the same way as buttons. | ||
let fn = demos[id]; | ||
|
||
let button = document.getElementById(id); | ||
if (button === null) { | ||
console.error("button with id: ", id , "not found") | ||
return null; | ||
} | ||
let button = document.getElementById(id); | ||
if (button === null) { | ||
console.error("button with id: ", id, "not found"); | ||
return null; | ||
} | ||
|
||
// Assign onclick handler + enable the button. | ||
Object.assign(button, { | ||
onclick: async () => { | ||
document.getElementById("loader").hidden = false | ||
document.getElementById("testSuccess").checked = false | ||
setButtonsDisabledState(demoNames, true); | ||
// Assign onclick handler + enable the button. | ||
Object.assign(button, { | ||
onclick: async () => { | ||
document.getElementById("loader").hidden = false; | ||
document.getElementById("testSuccess").checked = false; | ||
setButtonsDisabledState(demoNames, true); | ||
|
||
console.log("Running: ", id) | ||
try { | ||
let results = await fn() | ||
document.getElementById("testSuccess").checked = true | ||
if (results !== undefined) { | ||
document.getElementById("benchmarkResults").value = JSON.stringify(results); | ||
} | ||
} catch (error) { | ||
console.error(`Test Failed: ${error}`) | ||
document.getElementById("testSuccess").checked = false | ||
} | ||
document.getElementById("loader").hidden = true | ||
setButtonsDisabledState(demoNames, false); | ||
}, | ||
disabled: false | ||
}); | ||
console.log("Running: ", id); | ||
try { | ||
let results = await fn(); | ||
document.getElementById("testSuccess").checked = true; | ||
if (results !== undefined) { | ||
document.getElementById("benchmarkResults").value = | ||
JSON.stringify(results); | ||
} | ||
} catch (error) { | ||
console.error(`Test Failed: ${error}`); | ||
document.getElementById("testSuccess").checked = false; | ||
} | ||
document.getElementById("loader").hidden = true; | ||
setButtonsDisabledState(demoNames, false); | ||
}, | ||
disabled: false, | ||
}); | ||
|
||
return button; | ||
} | ||
return button; | ||
} | ||
|
||
for (let demo of demoNames) { | ||
setupBtn(demo) | ||
} | ||
for (let demo of demoNames) { | ||
setupBtn(demo); | ||
} | ||
} | ||
|
||
|
||
setup() | ||
setup(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
const secs = 60 | ||
const secs = 60; | ||
|
||
const config = { | ||
verbose: true, | ||
testTimeout: secs * 1000, | ||
testTimeout: secs * 1000, | ||
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|js?|tsx?|ts?)$", | ||
transform: { | ||
"^.+\\.jsx?$": "babel-jest", | ||
"^.+\\.mjs$": "babel-jest", | ||
}, | ||
testPathIgnorePatterns: ["<rootDir>/build/", "<rootDir>/node_modules/"], | ||
moduleFileExtensions: ["js", "jsx", "mjs"] | ||
moduleFileExtensions: ["js", "jsx", "mjs"], | ||
}; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
"headers": [ | ||
{ | ||
"source": "**/*.@(js|html)", | ||
"headers": [ | ||
{ "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" }, | ||
{ "key": "Cross-Origin-Opener-Policy", "value": "same-origin" } | ||
] | ||
} | ||
] | ||
} | ||
"headers": [ | ||
{ | ||
"source": "**/*.@(js|html)", | ||
"headers": [ | ||
{ "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" }, | ||
{ "key": "Cross-Origin-Opener-Policy", "value": "same-origin" } | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.