jfrery-zama commited on
Commit
b63a234
Β·
unverified Β·
1 Parent(s): 61f72fb

add clear keys from storage

Browse files
Files changed (2) hide show
  1. index.html +18 -1
  2. wasm-demo.js +26 -0
index.html CHANGED
@@ -227,6 +227,22 @@
227
  cursor: not-allowed;
228
  }
229
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  .status {
231
  font-size: 1.2rem;
232
  color: var(--black);
@@ -397,9 +413,10 @@
397
  <p id="keygenStatus" class="status" aria-live="polite">Generate new keys and send them to the server (requires a 130MB upload). Keys can then be loaded (instantly).</p>
398
  <span id="keygenSpin" class="loader" hidden aria-label="Generating keys"></span>
399
  </div>
400
- <div style="display:flex; gap:var(--spacing-unit); margin-top:auto">
401
  <button id="btnKeygen" class="btn" aria-describedby="keygenStatus">πŸ”‘ Generate new keys</button>
402
  <button id="btnLoadSaved" class="btn" aria-describedby="keygenStatus">πŸ—οΈ Load saved keys</button>
 
403
  </div>
404
  </div>
405
  </section>
 
227
  cursor: not-allowed;
228
  }
229
 
230
+ .btn-discrete {
231
+ background: transparent;
232
+ border: 1px solid var(--grey-200);
233
+ min-width: auto;
234
+ padding: calc(var(--spacing-unit) * 1) calc(var(--spacing-unit) * 1.5);
235
+ font-size: 0.9rem;
236
+ opacity: 0.7;
237
+ transition: all 0.2s ease;
238
+ }
239
+
240
+ .btn-discrete:hover:not(:disabled) {
241
+ background: var(--grey-100);
242
+ opacity: 1;
243
+ border-color: var(--grey-300);
244
+ }
245
+
246
  .status {
247
  font-size: 1.2rem;
248
  color: var(--black);
 
413
  <p id="keygenStatus" class="status" aria-live="polite">Generate new keys and send them to the server (requires a 130MB upload). Keys can then be loaded (instantly).</p>
414
  <span id="keygenSpin" class="loader" hidden aria-label="Generating keys"></span>
415
  </div>
416
+ <div style="display:flex; gap:var(--spacing-unit); margin-top:auto; flex-wrap: wrap;">
417
  <button id="btnKeygen" class="btn" aria-describedby="keygenStatus">πŸ”‘ Generate new keys</button>
418
  <button id="btnLoadSaved" class="btn" aria-describedby="keygenStatus">πŸ—οΈ Load saved keys</button>
419
+ <button id="btnDeleteKeys" class="btn btn-discrete" aria-describedby="keygenStatus">πŸ—‘οΈ Delete saved keys</button>
420
  </div>
421
  </div>
422
  </section>
wasm-demo.js CHANGED
@@ -43,6 +43,7 @@ function base64ToUint8(base64) {
43
  function getSavedKeys() { return JSON.parse(localStorage.getItem(KEYS_STORAGE_KEY) || '{}'); }
44
  function saveKeys(map) { localStorage.setItem(KEYS_STORAGE_KEY, JSON.stringify(map)); }
45
  function saveKeyset(uid, b64){ const m = getSavedKeys(); m[uid] = b64; saveKeys(m); }
 
46
 
47
  const $ = id => document.getElementById(id);
48
  const enable = (id, ok=true) => $(id).disabled = !ok;
@@ -177,6 +178,31 @@ $('btnLoadSaved').onclick = async () => {
177
  }
178
  };
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  // Add example text buttons
181
  $('btnWatermarked').onclick = () => {
182
  $('tokenInput').value = 'watermarking is useful for a variety of reasons like authentication, privacy';
 
43
  function getSavedKeys() { return JSON.parse(localStorage.getItem(KEYS_STORAGE_KEY) || '{}'); }
44
  function saveKeys(map) { localStorage.setItem(KEYS_STORAGE_KEY, JSON.stringify(map)); }
45
  function saveKeyset(uid, b64){ const m = getSavedKeys(); m[uid] = b64; saveKeys(m); }
46
+ function clearAllKeys() { localStorage.removeItem(KEYS_STORAGE_KEY); }
47
 
48
  const $ = id => document.getElementById(id);
49
  const enable = (id, ok=true) => $(id).disabled = !ok;
 
178
  }
179
  };
180
 
181
+ $('btnDeleteKeys').onclick = async () => {
182
+ const saved = getSavedKeys();
183
+ const ids = Object.keys(saved);
184
+
185
+ if (!ids.length) {
186
+ alert('No saved keys found on this machine.');
187
+ return;
188
+ }
189
+
190
+ const confirmed = confirm(
191
+ `Are you sure you want to delete all saved keys?\n\nThis will remove ${ids.length} saved key set(s):\n${ids.join('\n')}\n\nThis action cannot be undone.`
192
+ );
193
+
194
+ if (confirmed) {
195
+ try {
196
+ clearAllKeys();
197
+ console.log('[Main] All saved keys deleted');
198
+ alert('All saved keys have been deleted.');
199
+ } catch (err) {
200
+ console.error('[Main] Failed to delete keys:', err);
201
+ alert(`Failed to delete keys: ${err.message}`);
202
+ }
203
+ }
204
+ };
205
+
206
  // Add example text buttons
207
  $('btnWatermarked').onclick = () => {
208
  $('tokenInput').value = 'watermarking is useful for a variety of reasons like authentication, privacy';