@agent-link/server 0.1.0

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.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Browser-compatible encryption utilities using TweetNaCl and Pako from CDN.
3
+ * Requires: nacl, nacl.util (tweetnacl-util), and pako globals.
4
+ */
5
+
6
+ const COMPRESS_THRESHOLD = 512;
7
+
8
+ export function encrypt(data, key) {
9
+ const nonce = nacl.randomBytes(24);
10
+ const jsonStr = JSON.stringify(data);
11
+
12
+ let message;
13
+ let compressed = false;
14
+
15
+ if (jsonStr.length > COMPRESS_THRESHOLD) {
16
+ message = pako.gzip(jsonStr);
17
+ compressed = true;
18
+ } else {
19
+ message = nacl.util.decodeUTF8(jsonStr);
20
+ }
21
+
22
+ const encrypted = nacl.secretbox(message, nonce, key);
23
+ const result = {
24
+ n: nacl.util.encodeBase64(nonce),
25
+ c: nacl.util.encodeBase64(encrypted),
26
+ };
27
+ if (compressed) result.z = true;
28
+ return result;
29
+ }
30
+
31
+ export function decrypt(encrypted, key) {
32
+ try {
33
+ const nonce = nacl.util.decodeBase64(encrypted.n);
34
+ const ciphertext = nacl.util.decodeBase64(encrypted.c);
35
+ const decrypted = nacl.secretbox.open(ciphertext, nonce, key);
36
+ if (!decrypted) return null;
37
+
38
+ if (encrypted.z) {
39
+ const decompressed = pako.ungzip(decrypted, { to: 'string' });
40
+ return JSON.parse(decompressed);
41
+ } else {
42
+ return JSON.parse(nacl.util.encodeUTF8(decrypted));
43
+ }
44
+ } catch (err) {
45
+ console.error('[Decrypt] Failed:', err.message);
46
+ return null;
47
+ }
48
+ }
49
+
50
+ export function isEncrypted(msg) {
51
+ return msg && typeof msg === 'object' && typeof msg.n === 'string' && typeof msg.c === 'string';
52
+ }
53
+
54
+ export function decodeKey(encodedKey) {
55
+ return nacl.util.decodeBase64(encodedKey);
56
+ }
package/web/index.html ADDED
@@ -0,0 +1,31 @@
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.0">
6
+ <title>AgentLink</title>
7
+ <link rel="stylesheet" href="/style.css">
8
+ <link id="hljs-theme" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
9
+ <script>
10
+ // Apply saved theme immediately to prevent flash
11
+ (function() {
12
+ var t = localStorage.getItem('agentlink-theme') || 'dark';
13
+ document.documentElement.setAttribute('data-theme', t);
14
+ var link = document.getElementById('hljs-theme');
15
+ if (link) link.href = t === 'light'
16
+ ? 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css'
17
+ : 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css';
18
+ })();
19
+ </script>
20
+ <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
21
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.1/marked.min.js"></script>
22
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
23
+ <script src="https://cdn.jsdelivr.net/npm/tweetnacl@1.0.3/nacl-fast.min.js"></script>
24
+ <script src="https://cdn.jsdelivr.net/npm/tweetnacl-util@0.15.1/nacl-util.min.js"></script>
25
+ <script src="https://cdn.jsdelivr.net/npm/pako@2.1.0/dist/pako.min.js"></script>
26
+ </head>
27
+ <body>
28
+ <div id="app"></div>
29
+ <script type="module" src="/app.js"></script>
30
+ </body>
31
+ </html>