Spaces:
Running
Running
first commit
Browse files- concrete-ml-extensions-wasm/concrete_ml_extensions_wasm.d.ts +50 -0
- concrete-ml-extensions-wasm/concrete_ml_extensions_wasm.js +453 -0
- concrete-ml-extensions-wasm/concrete_ml_extensions_wasm_bg.wasm +3 -0
- concrete-ml-extensions-wasm/concrete_ml_extensions_wasm_bg.wasm.d.ts +16 -0
- concrete-ml-extensions-wasm/package.json +18 -0
- encrypt-worker.js +42 -0
- favicon.ico +0 -0
- index.html +439 -19
- keygen-worker.js +18 -0
- wasm-demo.js +227 -0
concrete-ml-extensions-wasm/concrete_ml_extensions_wasm.d.ts
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* tslint:disable */
|
2 |
+
/* eslint-disable */
|
3 |
+
export function start(): void;
|
4 |
+
export function keygen_radix_u64_wasm(): any;
|
5 |
+
export function encrypt_serialize_u64_radix_flat_wasm(value_flat_js: BigUint64Array, client_key_ser_js: Uint8Array): Uint8Array;
|
6 |
+
export function decrypt_serialized_u64_radix_flat_wasm(encrypted_data_js: Uint8Array, client_key_ser_js: Uint8Array): BigUint64Array;
|
7 |
+
export class JsSeeder {
|
8 |
+
private constructor();
|
9 |
+
free(): void;
|
10 |
+
}
|
11 |
+
|
12 |
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
13 |
+
|
14 |
+
export interface InitOutput {
|
15 |
+
readonly memory: WebAssembly.Memory;
|
16 |
+
readonly __wbg_jsseeder_free: (a: number, b: number) => void;
|
17 |
+
readonly start: () => void;
|
18 |
+
readonly keygen_radix_u64_wasm: () => [number, number, number];
|
19 |
+
readonly encrypt_serialize_u64_radix_flat_wasm: (a: any, b: any) => [number, number, number];
|
20 |
+
readonly decrypt_serialized_u64_radix_flat_wasm: (a: any, b: any) => [number, number, number];
|
21 |
+
readonly __wbindgen_exn_store: (a: number) => void;
|
22 |
+
readonly __externref_table_alloc: () => number;
|
23 |
+
readonly __wbindgen_export_2: WebAssembly.Table;
|
24 |
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
25 |
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
26 |
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
27 |
+
readonly __externref_table_dealloc: (a: number) => void;
|
28 |
+
readonly __wbindgen_start: () => void;
|
29 |
+
}
|
30 |
+
|
31 |
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
32 |
+
/**
|
33 |
+
* Instantiates the given `module`, which can either be bytes or
|
34 |
+
* a precompiled `WebAssembly.Module`.
|
35 |
+
*
|
36 |
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
37 |
+
*
|
38 |
+
* @returns {InitOutput}
|
39 |
+
*/
|
40 |
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
44 |
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
45 |
+
*
|
46 |
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
47 |
+
*
|
48 |
+
* @returns {Promise<InitOutput>}
|
49 |
+
*/
|
50 |
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
concrete-ml-extensions-wasm/concrete_ml_extensions_wasm.js
ADDED
@@ -0,0 +1,453 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
let wasm;
|
2 |
+
|
3 |
+
function addToExternrefTable0(obj) {
|
4 |
+
const idx = wasm.__externref_table_alloc();
|
5 |
+
wasm.__wbindgen_export_2.set(idx, obj);
|
6 |
+
return idx;
|
7 |
+
}
|
8 |
+
|
9 |
+
function handleError(f, args) {
|
10 |
+
try {
|
11 |
+
return f.apply(this, args);
|
12 |
+
} catch (e) {
|
13 |
+
const idx = addToExternrefTable0(e);
|
14 |
+
wasm.__wbindgen_exn_store(idx);
|
15 |
+
}
|
16 |
+
}
|
17 |
+
|
18 |
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
19 |
+
|
20 |
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
21 |
+
|
22 |
+
let cachedUint8ArrayMemory0 = null;
|
23 |
+
|
24 |
+
function getUint8ArrayMemory0() {
|
25 |
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
26 |
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
27 |
+
}
|
28 |
+
return cachedUint8ArrayMemory0;
|
29 |
+
}
|
30 |
+
|
31 |
+
function getStringFromWasm0(ptr, len) {
|
32 |
+
ptr = ptr >>> 0;
|
33 |
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
34 |
+
}
|
35 |
+
|
36 |
+
let WASM_VECTOR_LEN = 0;
|
37 |
+
|
38 |
+
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
39 |
+
|
40 |
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
41 |
+
? function (arg, view) {
|
42 |
+
return cachedTextEncoder.encodeInto(arg, view);
|
43 |
+
}
|
44 |
+
: function (arg, view) {
|
45 |
+
const buf = cachedTextEncoder.encode(arg);
|
46 |
+
view.set(buf);
|
47 |
+
return {
|
48 |
+
read: arg.length,
|
49 |
+
written: buf.length
|
50 |
+
};
|
51 |
+
});
|
52 |
+
|
53 |
+
function passStringToWasm0(arg, malloc, realloc) {
|
54 |
+
|
55 |
+
if (realloc === undefined) {
|
56 |
+
const buf = cachedTextEncoder.encode(arg);
|
57 |
+
const ptr = malloc(buf.length, 1) >>> 0;
|
58 |
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
59 |
+
WASM_VECTOR_LEN = buf.length;
|
60 |
+
return ptr;
|
61 |
+
}
|
62 |
+
|
63 |
+
let len = arg.length;
|
64 |
+
let ptr = malloc(len, 1) >>> 0;
|
65 |
+
|
66 |
+
const mem = getUint8ArrayMemory0();
|
67 |
+
|
68 |
+
let offset = 0;
|
69 |
+
|
70 |
+
for (; offset < len; offset++) {
|
71 |
+
const code = arg.charCodeAt(offset);
|
72 |
+
if (code > 0x7F) break;
|
73 |
+
mem[ptr + offset] = code;
|
74 |
+
}
|
75 |
+
|
76 |
+
if (offset !== len) {
|
77 |
+
if (offset !== 0) {
|
78 |
+
arg = arg.slice(offset);
|
79 |
+
}
|
80 |
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
81 |
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
82 |
+
const ret = encodeString(arg, view);
|
83 |
+
|
84 |
+
offset += ret.written;
|
85 |
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
86 |
+
}
|
87 |
+
|
88 |
+
WASM_VECTOR_LEN = offset;
|
89 |
+
return ptr;
|
90 |
+
}
|
91 |
+
|
92 |
+
let cachedDataViewMemory0 = null;
|
93 |
+
|
94 |
+
function getDataViewMemory0() {
|
95 |
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
96 |
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
97 |
+
}
|
98 |
+
return cachedDataViewMemory0;
|
99 |
+
}
|
100 |
+
|
101 |
+
function isLikeNone(x) {
|
102 |
+
return x === undefined || x === null;
|
103 |
+
}
|
104 |
+
|
105 |
+
export function start() {
|
106 |
+
wasm.start();
|
107 |
+
}
|
108 |
+
|
109 |
+
function takeFromExternrefTable0(idx) {
|
110 |
+
const value = wasm.__wbindgen_export_2.get(idx);
|
111 |
+
wasm.__externref_table_dealloc(idx);
|
112 |
+
return value;
|
113 |
+
}
|
114 |
+
/**
|
115 |
+
* @returns {any}
|
116 |
+
*/
|
117 |
+
export function keygen_radix_u64_wasm() {
|
118 |
+
const ret = wasm.keygen_radix_u64_wasm();
|
119 |
+
if (ret[2]) {
|
120 |
+
throw takeFromExternrefTable0(ret[1]);
|
121 |
+
}
|
122 |
+
return takeFromExternrefTable0(ret[0]);
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* @param {BigUint64Array} value_flat_js
|
127 |
+
* @param {Uint8Array} client_key_ser_js
|
128 |
+
* @returns {Uint8Array}
|
129 |
+
*/
|
130 |
+
export function encrypt_serialize_u64_radix_flat_wasm(value_flat_js, client_key_ser_js) {
|
131 |
+
const ret = wasm.encrypt_serialize_u64_radix_flat_wasm(value_flat_js, client_key_ser_js);
|
132 |
+
if (ret[2]) {
|
133 |
+
throw takeFromExternrefTable0(ret[1]);
|
134 |
+
}
|
135 |
+
return takeFromExternrefTable0(ret[0]);
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* @param {Uint8Array} encrypted_data_js
|
140 |
+
* @param {Uint8Array} client_key_ser_js
|
141 |
+
* @returns {BigUint64Array}
|
142 |
+
*/
|
143 |
+
export function decrypt_serialized_u64_radix_flat_wasm(encrypted_data_js, client_key_ser_js) {
|
144 |
+
const ret = wasm.decrypt_serialized_u64_radix_flat_wasm(encrypted_data_js, client_key_ser_js);
|
145 |
+
if (ret[2]) {
|
146 |
+
throw takeFromExternrefTable0(ret[1]);
|
147 |
+
}
|
148 |
+
return takeFromExternrefTable0(ret[0]);
|
149 |
+
}
|
150 |
+
|
151 |
+
const JsSeederFinalization = (typeof FinalizationRegistry === 'undefined')
|
152 |
+
? { register: () => {}, unregister: () => {} }
|
153 |
+
: new FinalizationRegistry(ptr => wasm.__wbg_jsseeder_free(ptr >>> 0, 1));
|
154 |
+
|
155 |
+
export class JsSeeder {
|
156 |
+
|
157 |
+
__destroy_into_raw() {
|
158 |
+
const ptr = this.__wbg_ptr;
|
159 |
+
this.__wbg_ptr = 0;
|
160 |
+
JsSeederFinalization.unregister(this);
|
161 |
+
return ptr;
|
162 |
+
}
|
163 |
+
|
164 |
+
free() {
|
165 |
+
const ptr = this.__destroy_into_raw();
|
166 |
+
wasm.__wbg_jsseeder_free(ptr, 0);
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
async function __wbg_load(module, imports) {
|
171 |
+
if (typeof Response === 'function' && module instanceof Response) {
|
172 |
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
173 |
+
try {
|
174 |
+
return await WebAssembly.instantiateStreaming(module, imports);
|
175 |
+
|
176 |
+
} catch (e) {
|
177 |
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
178 |
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
179 |
+
|
180 |
+
} else {
|
181 |
+
throw e;
|
182 |
+
}
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
const bytes = await module.arrayBuffer();
|
187 |
+
return await WebAssembly.instantiate(bytes, imports);
|
188 |
+
|
189 |
+
} else {
|
190 |
+
const instance = await WebAssembly.instantiate(module, imports);
|
191 |
+
|
192 |
+
if (instance instanceof WebAssembly.Instance) {
|
193 |
+
return { instance, module };
|
194 |
+
|
195 |
+
} else {
|
196 |
+
return instance;
|
197 |
+
}
|
198 |
+
}
|
199 |
+
}
|
200 |
+
|
201 |
+
function __wbg_get_imports() {
|
202 |
+
const imports = {};
|
203 |
+
imports.wbg = {};
|
204 |
+
imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
|
205 |
+
const ret = arg0.buffer;
|
206 |
+
return ret;
|
207 |
+
};
|
208 |
+
imports.wbg.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) {
|
209 |
+
const ret = arg0.call(arg1);
|
210 |
+
return ret;
|
211 |
+
}, arguments) };
|
212 |
+
imports.wbg.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) {
|
213 |
+
const ret = arg0.call(arg1, arg2);
|
214 |
+
return ret;
|
215 |
+
}, arguments) };
|
216 |
+
imports.wbg.__wbg_crypto_ed58b8e10a292839 = function(arg0) {
|
217 |
+
const ret = arg0.crypto;
|
218 |
+
return ret;
|
219 |
+
};
|
220 |
+
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
221 |
+
let deferred0_0;
|
222 |
+
let deferred0_1;
|
223 |
+
try {
|
224 |
+
deferred0_0 = arg0;
|
225 |
+
deferred0_1 = arg1;
|
226 |
+
console.error(getStringFromWasm0(arg0, arg1));
|
227 |
+
} finally {
|
228 |
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
229 |
+
}
|
230 |
+
};
|
231 |
+
imports.wbg.__wbg_getRandomValues_bcb4912f16000dc4 = function() { return handleError(function (arg0, arg1) {
|
232 |
+
arg0.getRandomValues(arg1);
|
233 |
+
}, arguments) };
|
234 |
+
imports.wbg.__wbg_getTime_46267b1c24877e30 = function(arg0) {
|
235 |
+
const ret = arg0.getTime();
|
236 |
+
return ret;
|
237 |
+
};
|
238 |
+
imports.wbg.__wbg_length_65df9cd7c58180b2 = function(arg0) {
|
239 |
+
const ret = arg0.length;
|
240 |
+
return ret;
|
241 |
+
};
|
242 |
+
imports.wbg.__wbg_length_a446193dc22c12f8 = function(arg0) {
|
243 |
+
const ret = arg0.length;
|
244 |
+
return ret;
|
245 |
+
};
|
246 |
+
imports.wbg.__wbg_msCrypto_0a36e2ec3a343d26 = function(arg0) {
|
247 |
+
const ret = arg0.msCrypto;
|
248 |
+
return ret;
|
249 |
+
};
|
250 |
+
imports.wbg.__wbg_new0_f788a2397c7ca929 = function() {
|
251 |
+
const ret = new Date();
|
252 |
+
return ret;
|
253 |
+
};
|
254 |
+
imports.wbg.__wbg_new_405e22f390576ce2 = function() {
|
255 |
+
const ret = new Object();
|
256 |
+
return ret;
|
257 |
+
};
|
258 |
+
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
|
259 |
+
const ret = new Error();
|
260 |
+
return ret;
|
261 |
+
};
|
262 |
+
imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) {
|
263 |
+
const ret = new Uint8Array(arg0);
|
264 |
+
return ret;
|
265 |
+
};
|
266 |
+
imports.wbg.__wbg_new_e5efeb1e59f0eb60 = function(arg0) {
|
267 |
+
const ret = new BigUint64Array(arg0);
|
268 |
+
return ret;
|
269 |
+
};
|
270 |
+
imports.wbg.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
|
271 |
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
272 |
+
return ret;
|
273 |
+
};
|
274 |
+
imports.wbg.__wbg_newwithbyteoffsetandlength_095d65baacc373dd = function(arg0, arg1, arg2) {
|
275 |
+
const ret = new BigUint64Array(arg0, arg1 >>> 0, arg2 >>> 0);
|
276 |
+
return ret;
|
277 |
+
};
|
278 |
+
imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
|
279 |
+
const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
|
280 |
+
return ret;
|
281 |
+
};
|
282 |
+
imports.wbg.__wbg_newwithlength_a381634e90c276d4 = function(arg0) {
|
283 |
+
const ret = new Uint8Array(arg0 >>> 0);
|
284 |
+
return ret;
|
285 |
+
};
|
286 |
+
imports.wbg.__wbg_node_02999533c4ea02e3 = function(arg0) {
|
287 |
+
const ret = arg0.node;
|
288 |
+
return ret;
|
289 |
+
};
|
290 |
+
imports.wbg.__wbg_process_5c1d670bc53614b8 = function(arg0) {
|
291 |
+
const ret = arg0.process;
|
292 |
+
return ret;
|
293 |
+
};
|
294 |
+
imports.wbg.__wbg_randomFillSync_ab2cfe79ebbf2740 = function() { return handleError(function (arg0, arg1) {
|
295 |
+
arg0.randomFillSync(arg1);
|
296 |
+
}, arguments) };
|
297 |
+
imports.wbg.__wbg_require_79b1e9274cde3c87 = function() { return handleError(function () {
|
298 |
+
const ret = module.require;
|
299 |
+
return ret;
|
300 |
+
}, arguments) };
|
301 |
+
imports.wbg.__wbg_set_5882e5672c74f0b1 = function(arg0, arg1, arg2) {
|
302 |
+
arg0.set(arg1, arg2 >>> 0);
|
303 |
+
};
|
304 |
+
imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
|
305 |
+
arg0.set(arg1, arg2 >>> 0);
|
306 |
+
};
|
307 |
+
imports.wbg.__wbg_set_bb8cecf6a62b9f46 = function() { return handleError(function (arg0, arg1, arg2) {
|
308 |
+
const ret = Reflect.set(arg0, arg1, arg2);
|
309 |
+
return ret;
|
310 |
+
}, arguments) };
|
311 |
+
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
312 |
+
const ret = arg1.stack;
|
313 |
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
314 |
+
const len1 = WASM_VECTOR_LEN;
|
315 |
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
316 |
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
317 |
+
};
|
318 |
+
imports.wbg.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() {
|
319 |
+
const ret = typeof global === 'undefined' ? null : global;
|
320 |
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
321 |
+
};
|
322 |
+
imports.wbg.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() {
|
323 |
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
324 |
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
325 |
+
};
|
326 |
+
imports.wbg.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() {
|
327 |
+
const ret = typeof self === 'undefined' ? null : self;
|
328 |
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
329 |
+
};
|
330 |
+
imports.wbg.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
|
331 |
+
const ret = typeof window === 'undefined' ? null : window;
|
332 |
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
333 |
+
};
|
334 |
+
imports.wbg.__wbg_subarray_aa9065fa9dc5df96 = function(arg0, arg1, arg2) {
|
335 |
+
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
336 |
+
return ret;
|
337 |
+
};
|
338 |
+
imports.wbg.__wbg_versions_c71aa1626a93e0a1 = function(arg0) {
|
339 |
+
const ret = arg0.versions;
|
340 |
+
return ret;
|
341 |
+
};
|
342 |
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
343 |
+
const table = wasm.__wbindgen_export_2;
|
344 |
+
const offset = table.grow(4);
|
345 |
+
table.set(0, undefined);
|
346 |
+
table.set(offset + 0, undefined);
|
347 |
+
table.set(offset + 1, null);
|
348 |
+
table.set(offset + 2, true);
|
349 |
+
table.set(offset + 3, false);
|
350 |
+
;
|
351 |
+
};
|
352 |
+
imports.wbg.__wbindgen_is_function = function(arg0) {
|
353 |
+
const ret = typeof(arg0) === 'function';
|
354 |
+
return ret;
|
355 |
+
};
|
356 |
+
imports.wbg.__wbindgen_is_object = function(arg0) {
|
357 |
+
const val = arg0;
|
358 |
+
const ret = typeof(val) === 'object' && val !== null;
|
359 |
+
return ret;
|
360 |
+
};
|
361 |
+
imports.wbg.__wbindgen_is_string = function(arg0) {
|
362 |
+
const ret = typeof(arg0) === 'string';
|
363 |
+
return ret;
|
364 |
+
};
|
365 |
+
imports.wbg.__wbindgen_is_undefined = function(arg0) {
|
366 |
+
const ret = arg0 === undefined;
|
367 |
+
return ret;
|
368 |
+
};
|
369 |
+
imports.wbg.__wbindgen_memory = function() {
|
370 |
+
const ret = wasm.memory;
|
371 |
+
return ret;
|
372 |
+
};
|
373 |
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
374 |
+
const ret = getStringFromWasm0(arg0, arg1);
|
375 |
+
return ret;
|
376 |
+
};
|
377 |
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
378 |
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
379 |
+
};
|
380 |
+
|
381 |
+
return imports;
|
382 |
+
}
|
383 |
+
|
384 |
+
function __wbg_init_memory(imports, memory) {
|
385 |
+
|
386 |
+
}
|
387 |
+
|
388 |
+
function __wbg_finalize_init(instance, module) {
|
389 |
+
wasm = instance.exports;
|
390 |
+
__wbg_init.__wbindgen_wasm_module = module;
|
391 |
+
cachedDataViewMemory0 = null;
|
392 |
+
cachedUint8ArrayMemory0 = null;
|
393 |
+
|
394 |
+
|
395 |
+
wasm.__wbindgen_start();
|
396 |
+
return wasm;
|
397 |
+
}
|
398 |
+
|
399 |
+
function initSync(module) {
|
400 |
+
if (wasm !== undefined) return wasm;
|
401 |
+
|
402 |
+
|
403 |
+
if (typeof module !== 'undefined') {
|
404 |
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
405 |
+
({module} = module)
|
406 |
+
} else {
|
407 |
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
408 |
+
}
|
409 |
+
}
|
410 |
+
|
411 |
+
const imports = __wbg_get_imports();
|
412 |
+
|
413 |
+
__wbg_init_memory(imports);
|
414 |
+
|
415 |
+
if (!(module instanceof WebAssembly.Module)) {
|
416 |
+
module = new WebAssembly.Module(module);
|
417 |
+
}
|
418 |
+
|
419 |
+
const instance = new WebAssembly.Instance(module, imports);
|
420 |
+
|
421 |
+
return __wbg_finalize_init(instance, module);
|
422 |
+
}
|
423 |
+
|
424 |
+
async function __wbg_init(module_or_path) {
|
425 |
+
if (wasm !== undefined) return wasm;
|
426 |
+
|
427 |
+
|
428 |
+
if (typeof module_or_path !== 'undefined') {
|
429 |
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
430 |
+
({module_or_path} = module_or_path)
|
431 |
+
} else {
|
432 |
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
433 |
+
}
|
434 |
+
}
|
435 |
+
|
436 |
+
if (typeof module_or_path === 'undefined') {
|
437 |
+
module_or_path = new URL('concrete_ml_extensions_wasm_bg.wasm', import.meta.url);
|
438 |
+
}
|
439 |
+
const imports = __wbg_get_imports();
|
440 |
+
|
441 |
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
442 |
+
module_or_path = fetch(module_or_path);
|
443 |
+
}
|
444 |
+
|
445 |
+
__wbg_init_memory(imports);
|
446 |
+
|
447 |
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
448 |
+
|
449 |
+
return __wbg_finalize_init(instance, module);
|
450 |
+
}
|
451 |
+
|
452 |
+
export { initSync };
|
453 |
+
export default __wbg_init;
|
concrete-ml-extensions-wasm/concrete_ml_extensions_wasm_bg.wasm
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:72865b90bc2f6d5d84aa51046f5ba3d948aad234fa2b949bd4d993904b93b5e1
|
3 |
+
size 873767
|
concrete-ml-extensions-wasm/concrete_ml_extensions_wasm_bg.wasm.d.ts
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* tslint:disable */
|
2 |
+
/* eslint-disable */
|
3 |
+
export const memory: WebAssembly.Memory;
|
4 |
+
export const __wbg_jsseeder_free: (a: number, b: number) => void;
|
5 |
+
export const start: () => void;
|
6 |
+
export const keygen_radix_u64_wasm: () => [number, number, number];
|
7 |
+
export const encrypt_serialize_u64_radix_flat_wasm: (a: any, b: any) => [number, number, number];
|
8 |
+
export const decrypt_serialized_u64_radix_flat_wasm: (a: any, b: any) => [number, number, number];
|
9 |
+
export const __wbindgen_exn_store: (a: number) => void;
|
10 |
+
export const __externref_table_alloc: () => number;
|
11 |
+
export const __wbindgen_export_2: WebAssembly.Table;
|
12 |
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
13 |
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
14 |
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
15 |
+
export const __externref_table_dealloc: (a: number) => void;
|
16 |
+
export const __wbindgen_start: () => void;
|
concrete-ml-extensions-wasm/package.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "concrete-ml-extensions",
|
3 |
+
"type": "module",
|
4 |
+
"description": "Private matrix multiplication library using fully homomorphic encryption",
|
5 |
+
"version": "0.1.9",
|
6 |
+
"license": "BSD-3-Clause-Clear",
|
7 |
+
"files": [
|
8 |
+
"concrete_ml_extensions_wasm_bg.wasm",
|
9 |
+
"concrete_ml_extensions_wasm.js",
|
10 |
+
"concrete_ml_extensions_wasm.d.ts"
|
11 |
+
],
|
12 |
+
"main": "concrete_ml_extensions_wasm.js",
|
13 |
+
"homepage": "https://zama.ai",
|
14 |
+
"types": "concrete_ml_extensions_wasm.d.ts",
|
15 |
+
"sideEffects": [
|
16 |
+
"./snippets/*"
|
17 |
+
]
|
18 |
+
}
|
encrypt-worker.js
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import initWasm, { encrypt_serialize_u64_radix_flat_wasm } from './concrete-ml-extensions-wasm/concrete_ml_extensions_wasm.js';
|
2 |
+
|
3 |
+
let clientKey;
|
4 |
+
let wasmInitialized = false;
|
5 |
+
|
6 |
+
self.onmessage = async function(e) {
|
7 |
+
if (e.data.type === 'init') {
|
8 |
+
try {
|
9 |
+
await initWasm();
|
10 |
+
wasmInitialized = true;
|
11 |
+
clientKey = e.data.clientKey;
|
12 |
+
console.log(`[Encrypt] Client key loaded: ${clientKey.length} bytes`);
|
13 |
+
self.postMessage({ type: 'ready' });
|
14 |
+
} catch (error) {
|
15 |
+
console.error('[Encrypt] WASM initialization failed:', error.message);
|
16 |
+
self.postMessage({ type: 'error', error: `WASM initialization failed: ${error.message}` });
|
17 |
+
}
|
18 |
+
} else if (e.data.type === 'encrypt') {
|
19 |
+
if (!wasmInitialized) {
|
20 |
+
console.error('[Encrypt] Attempted encryption before WASM initialization');
|
21 |
+
self.postMessage({ type: 'error', error: 'WASM not initialized' });
|
22 |
+
return;
|
23 |
+
}
|
24 |
+
try {
|
25 |
+
const tokenIds = e.data.tokenIds;
|
26 |
+
console.log(`[Encrypt] Starting encryption for ${tokenIds.length} token IDs`);
|
27 |
+
|
28 |
+
// Convert token IDs to BigUint64Array for FHE encryption
|
29 |
+
const bigArr = new BigUint64Array(tokenIds.map(id => BigInt(id)));
|
30 |
+
console.log(`[Encrypt] Token array size: ${bigArr.length} tokens`);
|
31 |
+
|
32 |
+
console.log('[Encrypt] Performing encryption...');
|
33 |
+
const result = encrypt_serialize_u64_radix_flat_wasm(bigArr, clientKey);
|
34 |
+
console.log(`[Encrypt] Encryption completed: ${result.length} bytes`);
|
35 |
+
|
36 |
+
self.postMessage({ type: 'success', result });
|
37 |
+
} catch (error) {
|
38 |
+
console.error('[Encrypt] Encryption failed:', error.message);
|
39 |
+
self.postMessage({ type: 'error', error: error.message });
|
40 |
+
}
|
41 |
+
}
|
42 |
+
};
|
favicon.ico
ADDED
|
index.html
CHANGED
@@ -1,19 +1,439 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
6 |
+
<title>FHE SynthID Detector</title>
|
7 |
+
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
8 |
+
|
9 |
+
<style>
|
10 |
+
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap');
|
11 |
+
|
12 |
+
:root {
|
13 |
+
--yellow: #ffd200;
|
14 |
+
--black: #000;
|
15 |
+
--white: #fff;
|
16 |
+
--grey-050: #f9f9f9;
|
17 |
+
--grey-200: #e0e0e0;
|
18 |
+
--container-max: 1200px;
|
19 |
+
--shadow-sm: 0 2px 4px rgba(0,0,0,0.06);
|
20 |
+
--spacing-unit: 8px;
|
21 |
+
}
|
22 |
+
|
23 |
+
/* reset */
|
24 |
+
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
|
25 |
+
body {
|
26 |
+
font-family: 'Space Grotesk', sans-serif;
|
27 |
+
background: var(--yellow);
|
28 |
+
color: var(--black);
|
29 |
+
line-height: 1.5;
|
30 |
+
font-weight: 400;
|
31 |
+
}
|
32 |
+
|
33 |
+
/* navbar */
|
34 |
+
.navbar {
|
35 |
+
display: flex;
|
36 |
+
justify-content: space-between;
|
37 |
+
align-items: center;
|
38 |
+
padding: calc(var(--spacing-unit) * 3) calc(var(--spacing-unit) * 4);
|
39 |
+
max-width: var(--container-max);
|
40 |
+
margin-inline: auto;
|
41 |
+
}
|
42 |
+
.logo {
|
43 |
+
font-size: 2rem;
|
44 |
+
font-weight: 700;
|
45 |
+
letter-spacing: -0.02em;
|
46 |
+
}
|
47 |
+
.contact-btn {
|
48 |
+
border: 2px solid var(--black);
|
49 |
+
background: transparent;
|
50 |
+
color: var(--black);
|
51 |
+
padding: calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 3);
|
52 |
+
border-radius: 8px;
|
53 |
+
font-size: 1rem;
|
54 |
+
font-weight: 600;
|
55 |
+
font-family: 'Space Grotesk', sans-serif;
|
56 |
+
cursor: pointer;
|
57 |
+
transition: all .2s ease;
|
58 |
+
}
|
59 |
+
.contact-btn:hover {
|
60 |
+
background: var(--black);
|
61 |
+
color: var(--yellow);
|
62 |
+
transform: translateY(-1px);
|
63 |
+
}
|
64 |
+
|
65 |
+
/* hero */
|
66 |
+
.hero {
|
67 |
+
display: grid;
|
68 |
+
gap: calc(var(--spacing-unit) * 6);
|
69 |
+
align-items: center;
|
70 |
+
max-width: var(--container-max);
|
71 |
+
margin: calc(var(--spacing-unit) * 4) auto calc(var(--spacing-unit) * 10);
|
72 |
+
padding-inline: calc(var(--spacing-unit) * 4);
|
73 |
+
grid-template-columns: 1fr 1fr;
|
74 |
+
}
|
75 |
+
.hero h1 {
|
76 |
+
font-size: clamp(2.5rem, 5vw, 4rem);
|
77 |
+
font-weight: 700;
|
78 |
+
margin-bottom: calc(var(--spacing-unit) * 3);
|
79 |
+
letter-spacing: -0.03em;
|
80 |
+
line-height: 1.1;
|
81 |
+
}
|
82 |
+
.hero p {
|
83 |
+
font-size: 1.25rem;
|
84 |
+
max-width: 45ch;
|
85 |
+
font-weight: 400;
|
86 |
+
line-height: 1.5;
|
87 |
+
}
|
88 |
+
|
89 |
+
.hero-diagram {
|
90 |
+
background: var(--white);
|
91 |
+
border: 2px solid var(--black);
|
92 |
+
border-radius: 16px;
|
93 |
+
padding: calc(var(--spacing-unit) * 4);
|
94 |
+
box-shadow: 8px 8px 0 var(--black);
|
95 |
+
width: 100%;
|
96 |
+
min-height: 400px;
|
97 |
+
display: flex;
|
98 |
+
align-items: center;
|
99 |
+
justify-content: center;
|
100 |
+
}
|
101 |
+
.hero-diagram .mermaid {
|
102 |
+
max-width: 100%;
|
103 |
+
font-family: 'Space Grotesk', sans-serif;
|
104 |
+
}
|
105 |
+
|
106 |
+
/* wizard */
|
107 |
+
main {
|
108 |
+
max-width: var(--container-max);
|
109 |
+
margin: 0 auto calc(var(--spacing-unit) * 12);
|
110 |
+
padding: 0 calc(var(--spacing-unit) * 4);
|
111 |
+
}
|
112 |
+
|
113 |
+
.section-title {
|
114 |
+
font-size: 2.5rem;
|
115 |
+
font-weight: 700;
|
116 |
+
margin-bottom: calc(var(--spacing-unit) * 6);
|
117 |
+
text-align: center;
|
118 |
+
letter-spacing: -0.02em;
|
119 |
+
}
|
120 |
+
|
121 |
+
.cards-wrapper {
|
122 |
+
display: grid;
|
123 |
+
gap: calc(var(--spacing-unit) * 3);
|
124 |
+
grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr));
|
125 |
+
}
|
126 |
+
|
127 |
+
.card {
|
128 |
+
background: var(--white);
|
129 |
+
border: 2px solid var(--black);
|
130 |
+
border-radius: 16px;
|
131 |
+
box-shadow: 6px 6px 0 var(--black);
|
132 |
+
padding: calc(var(--spacing-unit) * 4);
|
133 |
+
min-height: 280px;
|
134 |
+
display: flex;
|
135 |
+
flex-direction: column;
|
136 |
+
transition: transform 0.2s ease;
|
137 |
+
}
|
138 |
+
|
139 |
+
.card:hover {
|
140 |
+
transform: translate(-2px, -2px);
|
141 |
+
box-shadow: 8px 8px 0 var(--black);
|
142 |
+
}
|
143 |
+
|
144 |
+
.card h2 {
|
145 |
+
margin-bottom: calc(var(--spacing-unit) * 3);
|
146 |
+
font-size: 1.5rem;
|
147 |
+
font-weight: 700;
|
148 |
+
letter-spacing: -0.01em;
|
149 |
+
height: 30px;
|
150 |
+
}
|
151 |
+
|
152 |
+
.card-content {
|
153 |
+
flex: 1;
|
154 |
+
display: flex;
|
155 |
+
flex-direction: column;
|
156 |
+
gap: calc(var(--spacing-unit) * 2);
|
157 |
+
}
|
158 |
+
|
159 |
+
.controls {
|
160 |
+
display: flex;
|
161 |
+
align-items: center;
|
162 |
+
gap: calc(var(--spacing-unit) * 1.5);
|
163 |
+
min-height: 40px;
|
164 |
+
}
|
165 |
+
|
166 |
+
textarea {
|
167 |
+
width: 100%;
|
168 |
+
padding: calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 2);
|
169 |
+
border: 2px solid var(--black);
|
170 |
+
border-radius: 8px;
|
171 |
+
font-family: 'Space Grotesk', sans-serif;
|
172 |
+
font-size: 1rem;
|
173 |
+
resize: vertical;
|
174 |
+
background: var(--white);
|
175 |
+
min-height: 60px;
|
176 |
+
transition: all 0.2s ease;
|
177 |
+
font-weight: 500;
|
178 |
+
}
|
179 |
+
|
180 |
+
textarea:focus {
|
181 |
+
outline: none;
|
182 |
+
transform: translate(-2px, -2px);
|
183 |
+
box-shadow: 4px 4px 0 var(--black);
|
184 |
+
}
|
185 |
+
|
186 |
+
.btn {
|
187 |
+
border: 2px solid var(--black);
|
188 |
+
background: var(--yellow);
|
189 |
+
color: var(--black);
|
190 |
+
font-weight: 600;
|
191 |
+
padding: calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 3);
|
192 |
+
min-width: 160px;
|
193 |
+
font-size: 1rem;
|
194 |
+
font-family: 'Space Grotesk', sans-serif;
|
195 |
+
border-radius: 8px;
|
196 |
+
cursor: pointer;
|
197 |
+
transition: all .2s ease;
|
198 |
+
display: inline-flex;
|
199 |
+
align-items: center;
|
200 |
+
justify-content: center;
|
201 |
+
gap: calc(var(--spacing-unit) * 1);
|
202 |
+
white-space: nowrap;
|
203 |
+
letter-spacing: -0.01em;
|
204 |
+
}
|
205 |
+
.btn:hover:not(:disabled) {
|
206 |
+
background: var(--black);
|
207 |
+
color: var(--yellow);
|
208 |
+
transform: translateY(-2px);
|
209 |
+
}
|
210 |
+
.btn:disabled {
|
211 |
+
opacity: .5;
|
212 |
+
cursor: not-allowed;
|
213 |
+
}
|
214 |
+
|
215 |
+
.status {
|
216 |
+
font-size: 1rem;
|
217 |
+
color: var(--black);
|
218 |
+
flex: 1;
|
219 |
+
font-weight: 500;
|
220 |
+
}
|
221 |
+
|
222 |
+
.loader {
|
223 |
+
width: 20px;
|
224 |
+
height: 20px;
|
225 |
+
border: 3px solid transparent;
|
226 |
+
border-top: 3px solid var(--black);
|
227 |
+
border-right: 3px solid var(--black);
|
228 |
+
border-radius: 50%;
|
229 |
+
animation: spin 1s linear infinite;
|
230 |
+
flex-shrink: 0;
|
231 |
+
}
|
232 |
+
@keyframes spin { to { transform: rotate(360deg);} }
|
233 |
+
|
234 |
+
#encIcon {
|
235 |
+
font-size: 1.25rem;
|
236 |
+
flex-shrink: 0;
|
237 |
+
}
|
238 |
+
|
239 |
+
footer {
|
240 |
+
font-size: 1rem;
|
241 |
+
text-align: center;
|
242 |
+
padding: calc(var(--spacing-unit) * 6) calc(var(--spacing-unit) * 2);
|
243 |
+
color: var(--black);
|
244 |
+
font-weight: 500;
|
245 |
+
}
|
246 |
+
|
247 |
+
.visually-hidden { position: absolute !important; height: 1px; width: 1px; overflow: hidden; clip: rect(1px,1px,1px,1px); white-space: nowrap; }
|
248 |
+
|
249 |
+
/* Result styling */
|
250 |
+
#decResult {
|
251 |
+
font-family: 'Space Grotesk', sans-serif;
|
252 |
+
padding: calc(var(--spacing-unit) * 2);
|
253 |
+
background: var(--grey-050);
|
254 |
+
border: 2px solid var(--black);
|
255 |
+
border-radius: 8px;
|
256 |
+
min-height: 48px;
|
257 |
+
display: flex;
|
258 |
+
align-items: center;
|
259 |
+
font-weight: 600;
|
260 |
+
font-size: 1.1rem;
|
261 |
+
}
|
262 |
+
|
263 |
+
#decResult:not(:empty) {
|
264 |
+
color: var(--black);
|
265 |
+
}
|
266 |
+
|
267 |
+
/* Responsive adjustments */
|
268 |
+
@media (max-width: 968px) {
|
269 |
+
.hero {
|
270 |
+
grid-template-columns: 1fr;
|
271 |
+
gap: calc(var(--spacing-unit) * 4);
|
272 |
+
}
|
273 |
+
|
274 |
+
.hero-diagram {
|
275 |
+
min-height: 300px;
|
276 |
+
}
|
277 |
+
}
|
278 |
+
|
279 |
+
@media (max-width: 768px) {
|
280 |
+
.cards-wrapper {
|
281 |
+
gap: calc(var(--spacing-unit) * 2);
|
282 |
+
}
|
283 |
+
|
284 |
+
.card {
|
285 |
+
padding: calc(var(--spacing-unit) * 3);
|
286 |
+
box-shadow: 4px 4px 0 var(--black);
|
287 |
+
}
|
288 |
+
|
289 |
+
.btn {
|
290 |
+
min-width: 140px;
|
291 |
+
padding: calc(var(--spacing-unit) * 1.25) calc(var(--spacing-unit) * 2.5);
|
292 |
+
}
|
293 |
+
|
294 |
+
.hero h1 {
|
295 |
+
font-size: 2.5rem;
|
296 |
+
}
|
297 |
+
|
298 |
+
.section-title {
|
299 |
+
font-size: 2rem;
|
300 |
+
}
|
301 |
+
}
|
302 |
+
</style>
|
303 |
+
|
304 |
+
<!-- external scripts -->
|
305 |
+
<script type="module" src="https://belladoreai.github.io/llama3-tokenizer-js/bundle/llama3-tokenizer-with-baked-data.js"></script>
|
306 |
+
<script type="module">
|
307 |
+
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10.9.0/+esm';
|
308 |
+
mermaid.initialize({
|
309 |
+
startOnLoad: true,
|
310 |
+
theme: 'base',
|
311 |
+
themeVariables: {
|
312 |
+
primaryColor: '#ffd200',
|
313 |
+
primaryTextColor: '#000',
|
314 |
+
lineColor: '#000',
|
315 |
+
tertiaryColor: '#fff',
|
316 |
+
fontFamily: 'Space Grotesk'
|
317 |
+
}
|
318 |
+
});
|
319 |
+
</script>
|
320 |
+
</head>
|
321 |
+
<body>
|
322 |
+
<!-- Navbar -->
|
323 |
+
<nav class="navbar">
|
324 |
+
<div class="logo">ZAMA</div>
|
325 |
+
<button class="contact-btn">Contact us</button>
|
326 |
+
</nav>
|
327 |
+
|
328 |
+
<!-- Hero -->
|
329 |
+
<header class="hero" role="banner">
|
330 |
+
<div class="hero-copy">
|
331 |
+
<h1>FHE SynthID Detector</h1>
|
332 |
+
<p>Private, end-to-end detection using fully homomorphic encryption.</p>
|
333 |
+
</div>
|
334 |
+
|
335 |
+
<div class="hero-diagram">
|
336 |
+
<pre class="mermaid">
|
337 |
+
sequenceDiagram
|
338 |
+
participant User🧑💻
|
339 |
+
participant Browser🔐
|
340 |
+
participant RustServer🦀
|
341 |
+
|
342 |
+
User🧑💻->>Browser🔐: 1️⃣ Generate keys
|
343 |
+
Browser🔐->>Browser🔐: TFHE keygen (WASM)
|
344 |
+
Browser🔐->>RustServer🦀: 2️⃣ /handshake (server_key_b64)
|
345 |
+
RustServer🦀->>Browser🔐: UID (uuid-v4)
|
346 |
+
|
347 |
+
User🧑💻->>Browser🔐: 3️⃣ Enter text
|
348 |
+
Browser🔐->>Browser🔐: Tokenise ◁ HF tokenizer
|
349 |
+
Browser🔐->>Browser🔐: Encrypt tokens (WASM)
|
350 |
+
Browser🔐->>RustServer🦀: 4️⃣ /detect (uid, ciphertext_b64)
|
351 |
+
RustServer🦀->>RustServer🦀: FHE SynthID detect
|
352 |
+
RustServer🦀->>Browser🔐: Encrypted result_b64
|
353 |
+
Browser🔐->>Browser🔐: Decrypt result (WASM)
|
354 |
+
Browser🔐-->>User🧑💻: flag / score / g
|
355 |
+
</pre>
|
356 |
+
</div>
|
357 |
+
</header>
|
358 |
+
|
359 |
+
<!-- Wizard Steps -->
|
360 |
+
<main>
|
361 |
+
<h2 class="section-title">How it works</h2>
|
362 |
+
<div class="cards-wrapper">
|
363 |
+
<!-- 1 Keys -->
|
364 |
+
<section class="card" aria-labelledby="step1">
|
365 |
+
<h2 id="step1">1. Keys</h2>
|
366 |
+
<div class="card-content">
|
367 |
+
<div class="controls" style="margin-top: 0;">
|
368 |
+
<p id="keygenStatus" class="status" aria-live="polite">Ready to generate keys</p>
|
369 |
+
<span id="keygenSpin" class="loader" hidden aria-label="Generating keys"></span>
|
370 |
+
</div>
|
371 |
+
<div style="margin-top: auto;">
|
372 |
+
<button id="btnKeygen" class="btn" aria-describedby="keygenStatus">🔑 Generate keys</button>
|
373 |
+
</div>
|
374 |
+
</div>
|
375 |
+
</section>
|
376 |
+
|
377 |
+
<!-- 2 Encrypt -->
|
378 |
+
<section class="card" aria-labelledby="step2">
|
379 |
+
<h2 id="step2">2. Encrypt text</h2>
|
380 |
+
<div class="card-content">
|
381 |
+
<div class="controls">
|
382 |
+
<p id="tokenizerStatus" class="status" aria-live="polite" style="display: none;">Loading tokenizer...</p>
|
383 |
+
<span id="tokenizerSpin" class="loader" hidden aria-label="Loading tokenizer"></span>
|
384 |
+
</div>
|
385 |
+
<label for="tokenInput" class="visually-hidden">Text to encrypt</label>
|
386 |
+
<textarea id="tokenInput" rows="2" placeholder="Enter text to encrypt" autocomplete="off"></textarea>
|
387 |
+
<div class="controls" style="margin-top: auto;">
|
388 |
+
<button id="btnEncrypt" class="btn" disabled>🛡️ Encrypt</button>
|
389 |
+
<span id="encryptSpin" class="loader" hidden aria-label="Encrypting"></span>
|
390 |
+
<span id="encIcon" hidden aria-label="Encrypted">🔒</span>
|
391 |
+
</div>
|
392 |
+
</div>
|
393 |
+
</section>
|
394 |
+
|
395 |
+
<!-- 3 Send -->
|
396 |
+
<section class="card" aria-labelledby="step3">
|
397 |
+
<h2 id="step3">3. Send to server</h2>
|
398 |
+
<div class="card-content">
|
399 |
+
<div>
|
400 |
+
<p id="srvStatus" class="status" aria-live="polite">Waiting for encrypted data...</p>
|
401 |
+
<p id="srvComputing" class="status" aria-live="polite" hidden>Server computing...</p>
|
402 |
+
</div>
|
403 |
+
<div class="controls" style="margin-top: auto;">
|
404 |
+
<button id="btnSend" class="btn" disabled>📡 Send</button>
|
405 |
+
<span id="spin" class="loader" hidden aria-label="Working"></span>
|
406 |
+
</div>
|
407 |
+
</div>
|
408 |
+
</section>
|
409 |
+
|
410 |
+
<!-- 4 Result -->
|
411 |
+
<section class="card" aria-labelledby="step4">
|
412 |
+
<h2 id="step4">4. Result</h2>
|
413 |
+
<div class="card-content">
|
414 |
+
<label for="encResult" class="visually-hidden">Encrypted result bytes</label>
|
415 |
+
<textarea id="encResult" rows="1" readonly placeholder="Encrypted result will appear here"></textarea>
|
416 |
+
<p id="decResult" aria-live="polite" style="flex: 1;"></p>
|
417 |
+
<div class="controls" style="margin-top: auto;">
|
418 |
+
<button id="btnDecrypt" class="btn" disabled>🔓 Decrypt</button>
|
419 |
+
</div>
|
420 |
+
</div>
|
421 |
+
</section>
|
422 |
+
</div>
|
423 |
+
</main>
|
424 |
+
|
425 |
+
<footer>© 2025 Zama — Demo only, not for production use.</footer>
|
426 |
+
|
427 |
+
<script type="module" src="wasm-demo.js"></script>
|
428 |
+
<script>
|
429 |
+
// Since the tokenizer loads automatically and there's no explicit loading status in the JS,
|
430 |
+
// we'll hide the tokenizer status message on page load
|
431 |
+
window.addEventListener('DOMContentLoaded', () => {
|
432 |
+
const tokenizerStatus = document.getElementById('tokenizerStatus');
|
433 |
+
if (tokenizerStatus) {
|
434 |
+
tokenizerStatus.style.display = 'none';
|
435 |
+
}
|
436 |
+
});
|
437 |
+
</script>
|
438 |
+
</body>
|
439 |
+
</html>
|
keygen-worker.js
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import initWasm, { keygen_radix_u64_wasm } from './concrete-ml-extensions-wasm/concrete_ml_extensions_wasm.js';
|
2 |
+
|
3 |
+
self.onmessage = async function(e) {
|
4 |
+
try {
|
5 |
+
await initWasm();
|
6 |
+
|
7 |
+
console.log('[Keygen] Starting key generation...');
|
8 |
+
const result = await keygen_radix_u64_wasm();
|
9 |
+
console.log('[Keygen] Key generation completed successfully');
|
10 |
+
console.log(`[Keygen] Generated client key size: ${result.clientKey.length} bytes`);
|
11 |
+
console.log(`[Keygen] Generated server key size: ${result.serverKey.length} bytes`);
|
12 |
+
|
13 |
+
self.postMessage({ type: 'success', result });
|
14 |
+
} catch (error) {
|
15 |
+
console.error('[Keygen] Key generation failed:', error.message);
|
16 |
+
self.postMessage({ type: 'error', error: error.message });
|
17 |
+
}
|
18 |
+
};
|
wasm-demo.js
ADDED
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import initWasm, {
|
2 |
+
decrypt_serialized_u64_radix_flat_wasm
|
3 |
+
} from './concrete-ml-extensions-wasm/concrete_ml_extensions_wasm.js';
|
4 |
+
|
5 |
+
const SERVER = 'https://backend-server.com';
|
6 |
+
|
7 |
+
let clientKey, serverKey;
|
8 |
+
let encTokens;
|
9 |
+
let encServerResult;
|
10 |
+
let keygenWorker;
|
11 |
+
let encryptWorker;
|
12 |
+
let sessionUid;
|
13 |
+
|
14 |
+
// Memory-efficient base64 encoding for large Uint8Array
|
15 |
+
function uint8ToBase64(uint8) {
|
16 |
+
return new Promise((resolve, reject) => {
|
17 |
+
const blob = new Blob([uint8]);
|
18 |
+
const reader = new FileReader();
|
19 |
+
reader.onload = function () {
|
20 |
+
const base64 = reader.result.split(',')[1];
|
21 |
+
resolve(base64);
|
22 |
+
};
|
23 |
+
reader.onerror = reject;
|
24 |
+
reader.readAsDataURL(blob);
|
25 |
+
});
|
26 |
+
}
|
27 |
+
|
28 |
+
const $ = id => document.getElementById(id);
|
29 |
+
const enable = (id, ok=true) => $(id).disabled = !ok;
|
30 |
+
const show = (id, visible=true) => $(id).hidden = !visible;
|
31 |
+
|
32 |
+
// Hide all spinners immediately
|
33 |
+
show('keygenSpin', false);
|
34 |
+
show('spin', false);
|
35 |
+
show('encIcon', false);
|
36 |
+
show('tokenizerSpin', false);
|
37 |
+
|
38 |
+
// Initialize WASM
|
39 |
+
(async () => {
|
40 |
+
try {
|
41 |
+
console.log('[Main] Initializing WASM module...');
|
42 |
+
await initWasm();
|
43 |
+
console.log('[Main] WASM module initialized successfully');
|
44 |
+
|
45 |
+
// Initialize the keygen worker
|
46 |
+
keygenWorker = new Worker(new URL('./keygen-worker.js', import.meta.url), { type: 'module' });
|
47 |
+
keygenWorker.onmessage = async function(e) {
|
48 |
+
if (e.data.type === 'success') {
|
49 |
+
const res = e.data.result;
|
50 |
+
console.log('[Main] Key generation successful');
|
51 |
+
console.log(`[Main] Client key size: ${res.clientKey.length} bytes`);
|
52 |
+
console.log(`[Main] Server key size: ${res.serverKey.length} bytes`);
|
53 |
+
clientKey = res.clientKey; serverKey = res.serverKey;
|
54 |
+
$('keygenStatus').textContent = 'keys generated ✓';
|
55 |
+
enable('btnEncrypt');
|
56 |
+
|
57 |
+
// Initialize encryption worker
|
58 |
+
encryptWorker = new Worker(new URL('./encrypt-worker.js', import.meta.url), { type: 'module' });
|
59 |
+
encryptWorker.onmessage = function(e) {
|
60 |
+
if (e.data.type === 'ready') {
|
61 |
+
console.log('[Main] Encryption worker ready');
|
62 |
+
} else if (e.data.type === 'success') {
|
63 |
+
encTokens = e.data.result;
|
64 |
+
console.log(`[Main] Encryption completed: ${encTokens.length} bytes`);
|
65 |
+
show('encryptSpin', false);
|
66 |
+
show('encIcon', true);
|
67 |
+
enable('btnEncrypt', true);
|
68 |
+
enable('btnSend');
|
69 |
+
} else if (e.data.type === 'error') {
|
70 |
+
console.error('[Main] Encryption error:', e.data.error);
|
71 |
+
show('encryptSpin', false);
|
72 |
+
enable('btnEncrypt', true);
|
73 |
+
alert(`Encryption failed: ${e.data.error}`);
|
74 |
+
}
|
75 |
+
};
|
76 |
+
|
77 |
+
// Initialize the worker with the client key
|
78 |
+
encryptWorker.postMessage({ type: 'init', clientKey });
|
79 |
+
|
80 |
+
console.log('[Main] Encoding server key to base64...');
|
81 |
+
const serverKeyB64 = await uint8ToBase64(serverKey);
|
82 |
+
console.log(`[Main] Server key base64 size: ${serverKeyB64.length} bytes`);
|
83 |
+
const handshakeResponse = await fetch(`${SERVER}/handshake`, {
|
84 |
+
method:'POST',
|
85 |
+
headers:{'Content-Type':'application/json'},
|
86 |
+
body: JSON.stringify({
|
87 |
+
server_key_b64: serverKeyB64
|
88 |
+
})
|
89 |
+
});
|
90 |
+
|
91 |
+
if (!handshakeResponse.ok) {
|
92 |
+
const errorText = await handshakeResponse.text();
|
93 |
+
throw new Error(`Server handshake failed: ${handshakeResponse.status} ${errorText}`);
|
94 |
+
}
|
95 |
+
|
96 |
+
const { uid } = await handshakeResponse.json();
|
97 |
+
sessionUid = uid;
|
98 |
+
console.log('[Main] Server handshake successful');
|
99 |
+
} else {
|
100 |
+
console.error('[Main] Key generation error:', e.data.error);
|
101 |
+
$('keygenStatus').textContent = `Error generating keys: ${e.data.error}`;
|
102 |
+
}
|
103 |
+
show('keygenSpin', false);
|
104 |
+
};
|
105 |
+
} catch (e) {
|
106 |
+
console.error('[Main] Failed to initialize WASM module:', e);
|
107 |
+
$('keygenStatus').textContent = `Initialization Error: ${e.message}`;
|
108 |
+
throw e;
|
109 |
+
}
|
110 |
+
})();
|
111 |
+
|
112 |
+
$('btnKeygen').onclick = async () => {
|
113 |
+
if ($('keygenSpin').hidden === false) {
|
114 |
+
console.log('[Main] Keygen already in progress, ignoring click');
|
115 |
+
return;
|
116 |
+
}
|
117 |
+
show('keygenSpin', true);
|
118 |
+
$('keygenStatus').textContent = 'generating…';
|
119 |
+
try {
|
120 |
+
keygenWorker.postMessage({});
|
121 |
+
} catch (e) {
|
122 |
+
console.error('[Main] Key generation error:', e);
|
123 |
+
$('keygenStatus').textContent = `Error generating keys: ${e.message}`;
|
124 |
+
show('keygenSpin', false);
|
125 |
+
}
|
126 |
+
};
|
127 |
+
|
128 |
+
$('btnEncrypt').onclick = async () => {
|
129 |
+
const text = $('tokenInput').value.trim();
|
130 |
+
if (!text) {
|
131 |
+
console.error('[Main] No text provided for tokenization/encryption');
|
132 |
+
alert('Please enter text to encrypt.');
|
133 |
+
return;
|
134 |
+
}
|
135 |
+
if (!encryptWorker) {
|
136 |
+
console.error('[Main] Encryption worker not initialized');
|
137 |
+
alert('Encryption worker is not ready. Please generate keys first.');
|
138 |
+
return;
|
139 |
+
}
|
140 |
+
|
141 |
+
show('encryptSpin', true);
|
142 |
+
show('encIcon', false);
|
143 |
+
enable('btnEncrypt', false);
|
144 |
+
|
145 |
+
try {
|
146 |
+
console.log('[Main] Tokenizing text:', text);
|
147 |
+
const tokenIds = llama3Tokenizer.encode(text);
|
148 |
+
console.log('[Main] Token IDs:', tokenIds);
|
149 |
+
|
150 |
+
encryptWorker.postMessage({ type: 'encrypt', tokenIds });
|
151 |
+
} catch (error) {
|
152 |
+
console.error('[Main] Tokenization or encryption initiation error:', error);
|
153 |
+
show('encryptSpin', false);
|
154 |
+
enable('btnEncrypt', true);
|
155 |
+
alert(`Error during tokenization/encryption: ${error.message}`);
|
156 |
+
}
|
157 |
+
};
|
158 |
+
|
159 |
+
$('btnSend').onclick = async () => {
|
160 |
+
if ($('spin').hidden === false) {
|
161 |
+
console.log('[Main] Send already in progress, ignoring click');
|
162 |
+
return;
|
163 |
+
}
|
164 |
+
show('encIcon', false);
|
165 |
+
show('spin', true);
|
166 |
+
$('srvStatus').textContent = 'Preparing request…';
|
167 |
+
$('srvComputing').hidden = true;
|
168 |
+
const startTime = performance.now();
|
169 |
+
try {
|
170 |
+
const ciphertext_b64 = await uint8ToBase64(encTokens);
|
171 |
+
|
172 |
+
$('srvStatus').textContent = 'Sending…';
|
173 |
+
console.log('[Main] Sending request to server...');
|
174 |
+
const response = await fetch(`${SERVER}/detect`, {
|
175 |
+
method:'POST',
|
176 |
+
headers:{'Content-Type':'application/json'},
|
177 |
+
body: JSON.stringify({
|
178 |
+
uid: sessionUid,
|
179 |
+
ciphertext_b64
|
180 |
+
})
|
181 |
+
});
|
182 |
+
|
183 |
+
console.log(`[Main] Server response status: ${response.status}`);
|
184 |
+
if (!response.ok) {
|
185 |
+
const errorText = await response.text();
|
186 |
+
throw new Error(`Server error: ${response.status} ${errorText}`);
|
187 |
+
}
|
188 |
+
|
189 |
+
$('srvStatus').textContent = '✓ sent';
|
190 |
+
$('srvComputing').hidden = false;
|
191 |
+
|
192 |
+
const {result_b64} = await response.json();
|
193 |
+
const endTime = performance.now();
|
194 |
+
const duration = ((endTime - startTime) / 1000).toFixed(2);
|
195 |
+
console.log(`[Main] Server request completed in ${duration}s`);
|
196 |
+
console.log('[Main] Processing server response...');
|
197 |
+
encServerResult = Uint8Array.from(atob(result_b64), c=>c.charCodeAt(0));
|
198 |
+
console.log(`[Main] Received encrypted result: ${encServerResult.length} bytes`);
|
199 |
+
$('encResult').value = `(${encServerResult.length} B)`;
|
200 |
+
$('srvComputing').hidden = true;
|
201 |
+
$('srvStatus').textContent = `✓ received (${duration}s)`;
|
202 |
+
enable('btnDecrypt');
|
203 |
+
} catch (e) {
|
204 |
+
const endTime = performance.now();
|
205 |
+
const duration = ((endTime - startTime) / 1000).toFixed(2);
|
206 |
+
console.error(`[Main] Server request failed after ${duration}s:`, e);
|
207 |
+
$('srvComputing').hidden = true;
|
208 |
+
$('srvStatus').textContent = `Server error: ${e.message} (${duration}s)`;
|
209 |
+
} finally {
|
210 |
+
show('spin', false);
|
211 |
+
}
|
212 |
+
};
|
213 |
+
|
214 |
+
$('btnDecrypt').onclick = () => {
|
215 |
+
try {
|
216 |
+
console.log('[Main] Starting decryption...');
|
217 |
+
const dec = decrypt_serialized_u64_radix_flat_wasm(encServerResult, clientKey);
|
218 |
+
const [flag, score_scaled, total_g] = Array.from(dec);
|
219 |
+
const score = (Number(score_scaled) / 1e6).toFixed(6);
|
220 |
+
console.log('[Main] Decryption successful');
|
221 |
+
console.log(`[Main] Result - flag: ${flag}, score: ${score}, total_g: ${total_g}`);
|
222 |
+
$('decResult').textContent = `flag=${flag}, score=${score}, total_g=${total_g}`;
|
223 |
+
} catch (e) {
|
224 |
+
console.error('[Main] Decryption error:', e);
|
225 |
+
$('decResult').textContent = `Error decrypting result: ${e.message}`;
|
226 |
+
}
|
227 |
+
};
|