@agentdock/crypto 0.0.60 → 0.0.61
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/aes.d.ts +7 -1
- package/dist/aes.js +1 -1
- package/package.json +3 -2
package/dist/aes.d.ts
CHANGED
|
@@ -4,12 +4,18 @@
|
|
|
4
4
|
* Bundle format:
|
|
5
5
|
* version (1 byte) | nonce (12 bytes) | ciphertext + authTag
|
|
6
6
|
*
|
|
7
|
-
* - version:
|
|
7
|
+
* - version: 0 = plaintext JSON, 1 = gzip-compressed JSON (see below)
|
|
8
8
|
* - nonce: 12-byte IV for AES-GCM
|
|
9
9
|
* - ciphertext + authTag: Web Crypto API returns these concatenated
|
|
10
10
|
* (authTag is the last 16 bytes)
|
|
11
11
|
*
|
|
12
12
|
* Data is JSON-serialized before encryption and JSON-parsed after decryption.
|
|
13
|
+
*
|
|
14
|
+
* Compression: before encryption the JSON bytes are gzipped; the smaller of
|
|
15
|
+
* {compressed, original} is encrypted, and the version byte records which one
|
|
16
|
+
* (1 = compressed, 0 = original). Small payloads that gzip would grow stay at
|
|
17
|
+
* version 0. Legacy (pre-compression) bundles are always version 0, so old data
|
|
18
|
+
* decrypts unchanged with no migration.
|
|
13
19
|
*/
|
|
14
20
|
/**
|
|
15
21
|
* Encrypt arbitrary JSON-serializable data with AES-256-GCM.
|
package/dist/aes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{getRandomBytes as
|
|
1
|
+
"use strict";import{gzipSync as w,gunzipSync as A}from"fflate";import{getRandomBytes as _}from"./random.js";const E=0,g=1,s=12,d=16,m=1+s+d,f=104857600,N=32;export async function encryptAesGcm(t,e){h(e);const n=new TextEncoder().encode(JSON.stringify(t)),o=w(n,{level:1}),i=o.length<n.length,a=i?g:E,l=i?o:n,r=_(s),p=await S(e,["encrypt"]),c=await globalThis.crypto.subtle.encrypt({name:"AES-GCM",iv:r},p,l),u=new Uint8Array(c),y=new Uint8Array(1+s+u.length);return y[0]=a,y.set(r,1),y.set(u,1+s),y}export async function decryptAesGcm(t,e){if(h(e),t.length<m)return null;const n=t[0];if(n!==E&&n!==g)return null;const o=t.slice(1,1+s),i=t.slice(1+s);try{const a=await S(e,["decrypt"]),l=await globalThis.crypto.subtle.decrypt({name:"AES-GCM",iv:o},a,i);let r;if(n===g){const c=new Uint8Array(l);if(c.length>=4&&new DataView(c.buffer,c.byteOffset+c.length-4,4).getUint32(0,!0)>f||(r=A(c),r.length>f))return null}else r=new Uint8Array(l);const p=new TextDecoder().decode(r);return JSON.parse(p)}catch{return null}}async function S(t,e){return globalThis.crypto.subtle.importKey("raw",t,"AES-GCM",!1,[...e])}function h(t){if(t.length!==N)throw new Error(`AES-256-GCM requires a 32-byte key, got ${t.length} bytes`)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentdock/crypto",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61",
|
|
4
4
|
"description": "E2E encryption for AgentDock — AES-256-GCM, key derivation, Web Crypto API",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "CCPark",
|
|
@@ -22,8 +22,9 @@
|
|
|
22
22
|
"registry": "https://registry.npmjs.org"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"fflate": "^0.8.3",
|
|
25
26
|
"tweetnacl": "^1.0.3",
|
|
26
|
-
"@agentdock/wire": "0.0.
|
|
27
|
+
"@agentdock/wire": "0.0.61"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@vitest/coverage-v8": "^3.0.0",
|