MCPcopy
hub / github.com/slopus/happy / decryptWithDataKey

Function decryptWithDataKey

packages/happy-agent/src/encryption.ts:101–117  ·  view source on GitHub ↗
(bundle: Uint8Array, dataKey: Uint8Array)

Source from the content-addressed store, hash-verified

99}
100
101export function decryptWithDataKey(bundle: Uint8Array, dataKey: Uint8Array): unknown | null {
102 if (bundle.length < 1 + 12 + 16) return null; // minimum: version + nonce + authTag
103 if (bundle[0] !== 0) return null; // only version 0
104
105 const nonce = bundle.slice(1, 13);
106 const authTag = bundle.slice(bundle.length - 16);
107 const ciphertext = bundle.slice(13, bundle.length - 16);
108
109 try {
110 const decipher = createDecipheriv('aes-256-gcm', dataKey, nonce);
111 decipher.setAuthTag(authTag);
112 const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
113 return JSON.parse(new TextDecoder().decode(decrypted));
114 } catch {
115 return null;
116 }
117}
118
119// --- Legacy TweetNaCl secretbox encryption ---
120

Callers 4

cli-smoke.test.tsFile · 0.90
decryptFieldFunction · 0.90
encryption.test.tsFile · 0.90
decryptFunction · 0.70

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected