sketchmark 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +0 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -84
- package/dist/index.js.map +1 -1
- package/dist/sketchmark.iife.js +0 -85
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -5243,89 +5243,6 @@ class EventEmitter {
|
|
|
5243
5243
|
}
|
|
5244
5244
|
}
|
|
5245
5245
|
|
|
5246
|
-
// ============================================================
|
|
5247
|
-
// sketchmark — Encrypted sharing
|
|
5248
|
-
// Diagram DSL is encrypted in the browser.
|
|
5249
|
-
// The server stores an opaque blob it cannot read.
|
|
5250
|
-
// The decryption key lives only in the URL fragment (#key=...).
|
|
5251
|
-
// ============================================================
|
|
5252
|
-
const WORKER_URL = 'https://sketchmark.anmism.workers.dev';
|
|
5253
|
-
// ── Crypto helpers ────────────────────────────────────────
|
|
5254
|
-
async function generateKey() {
|
|
5255
|
-
return crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, // extractable so we can export to URL
|
|
5256
|
-
['encrypt', 'decrypt']);
|
|
5257
|
-
}
|
|
5258
|
-
async function keyToBase64(key) {
|
|
5259
|
-
const raw = await crypto.subtle.exportKey('raw', key);
|
|
5260
|
-
return btoa(String.fromCharCode(...new Uint8Array(raw)));
|
|
5261
|
-
}
|
|
5262
|
-
async function base64ToKey(b64) {
|
|
5263
|
-
const raw = Uint8Array.from(atob(b64), c => c.charCodeAt(0));
|
|
5264
|
-
return crypto.subtle.importKey('raw', raw, { name: 'AES-GCM' }, false, // not extractable on the receiving end
|
|
5265
|
-
['decrypt']);
|
|
5266
|
-
}
|
|
5267
|
-
// ── Encrypt ───────────────────────────────────────────────
|
|
5268
|
-
async function encryptDSL(dsl, key) {
|
|
5269
|
-
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
5270
|
-
const encoded = new TextEncoder().encode(dsl);
|
|
5271
|
-
const encrypted = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, encoded);
|
|
5272
|
-
// prepend iv to the blob: [ iv (12 bytes) | ciphertext ]
|
|
5273
|
-
const result = new Uint8Array(12 + encrypted.byteLength);
|
|
5274
|
-
result.set(iv, 0);
|
|
5275
|
-
result.set(new Uint8Array(encrypted), 12);
|
|
5276
|
-
return result;
|
|
5277
|
-
}
|
|
5278
|
-
// ── Decrypt ───────────────────────────────────────────────
|
|
5279
|
-
async function decryptBlob(blob, key) {
|
|
5280
|
-
const iv = blob.slice(0, 12);
|
|
5281
|
-
const ciphertext = blob.slice(12);
|
|
5282
|
-
const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, ciphertext);
|
|
5283
|
-
return new TextDecoder().decode(decrypted);
|
|
5284
|
-
}
|
|
5285
|
-
// ── Public API ────────────────────────────────────────────
|
|
5286
|
-
/**
|
|
5287
|
-
* Encrypt DSL, upload to worker, return shareable URL.
|
|
5288
|
-
* The URL fragment (#key=...) never reaches the server.
|
|
5289
|
-
*/
|
|
5290
|
-
async function shareDiagram(dsl) {
|
|
5291
|
-
const key = await generateKey();
|
|
5292
|
-
const blob = await encryptDSL(dsl, key);
|
|
5293
|
-
const keyB64 = await keyToBase64(key);
|
|
5294
|
-
const res = await fetch(`${WORKER_URL}/api/blob`, {
|
|
5295
|
-
method: 'POST',
|
|
5296
|
-
headers: { 'Content-Type': 'application/octet-stream' },
|
|
5297
|
-
body: blob.buffer,
|
|
5298
|
-
});
|
|
5299
|
-
if (!res.ok)
|
|
5300
|
-
throw new Error(`Upload failed: ${res.status}`);
|
|
5301
|
-
const { id } = await res.json();
|
|
5302
|
-
// key goes into the fragment — browser never sends this to any server
|
|
5303
|
-
return `${window.location.origin}/playground.html?s=${id}#key=${keyB64}`;
|
|
5304
|
-
}
|
|
5305
|
-
/**
|
|
5306
|
-
* Read ?s= and #key= from the current URL, fetch + decrypt the diagram.
|
|
5307
|
-
* Returns null if no share params found.
|
|
5308
|
-
*/
|
|
5309
|
-
async function loadSharedDiagram() {
|
|
5310
|
-
const params = new URLSearchParams(window.location.search);
|
|
5311
|
-
const id = params.get('s');
|
|
5312
|
-
if (!id)
|
|
5313
|
-
return null;
|
|
5314
|
-
// key is in the fragment — parse manually, not via URLSearchParams
|
|
5315
|
-
// (URLSearchParams on hash strips the #)
|
|
5316
|
-
const fragment = window.location.hash.slice(1);
|
|
5317
|
-
const keyMatch = fragment.match(/key=([^&]+)/);
|
|
5318
|
-
if (!keyMatch)
|
|
5319
|
-
return null;
|
|
5320
|
-
const keyB64 = keyMatch[1];
|
|
5321
|
-
const res = await fetch(`${WORKER_URL}/api/blob/${id}`);
|
|
5322
|
-
if (!res.ok)
|
|
5323
|
-
throw new Error('Diagram not found or expired');
|
|
5324
|
-
const blob = await res.arrayBuffer();
|
|
5325
|
-
const key = await base64ToKey(keyB64);
|
|
5326
|
-
return decryptBlob(blob, key);
|
|
5327
|
-
}
|
|
5328
|
-
|
|
5329
5246
|
// ============================================================
|
|
5330
5247
|
// sketchmark — Public API
|
|
5331
5248
|
// ============================================================
|
|
@@ -5417,7 +5334,6 @@ exports.layout = layout;
|
|
|
5417
5334
|
exports.lerp = lerp;
|
|
5418
5335
|
exports.listThemes = listThemes;
|
|
5419
5336
|
exports.loadFont = loadFont;
|
|
5420
|
-
exports.loadSharedDiagram = loadSharedDiagram;
|
|
5421
5337
|
exports.markdownMap = markdownMap;
|
|
5422
5338
|
exports.nodeMap = nodeMap;
|
|
5423
5339
|
exports.parse = parse;
|
|
@@ -5428,7 +5344,6 @@ exports.renderToCanvas = renderToCanvas;
|
|
|
5428
5344
|
exports.renderToSVG = renderToSVG;
|
|
5429
5345
|
exports.resolveFont = resolveFont;
|
|
5430
5346
|
exports.resolvePalette = resolvePalette;
|
|
5431
|
-
exports.shareDiagram = shareDiagram;
|
|
5432
5347
|
exports.sleep = sleep;
|
|
5433
5348
|
exports.svgToPNGDataURL = svgToPNGDataURL;
|
|
5434
5349
|
exports.svgToString = svgToString;
|