{"version":3,"file":"aes-sealed.cjs","names":["ensureUint8Array"],"sources":["../../../src/common/crypto/aes-sealed.ts"],"sourcesContent":["import { ensureUint8Array } from '../data/bin'\n\nconst AES_GCM_TAG_LENGTH_BITS = 128\n\nexport async function encryptAesGcm(data: Uint8Array, key: CryptoKey, authenticating: Uint8Array = new Uint8Array()): Promise<Uint8Array> {\n  const iv = crypto.getRandomValues(new Uint8Array(12)) // AES-GCM requires a 12-byte IV\n  const encrypted = await crypto.subtle.encrypt(\n    {\n      name: 'AES-GCM',\n      iv,\n      tagLength: AES_GCM_TAG_LENGTH_BITS,\n      additionalData: ensureUint8Array(authenticating),\n    },\n    key,\n    ensureUint8Array(data),\n  )\n\n  const encryptedArray = new Uint8Array(encrypted)\n  const combined = new Uint8Array(iv.length + encryptedArray.length)\n  combined.set(iv)\n  combined.set(encryptedArray, iv.length)\n  return combined\n}\n\nexport async function decryptAesGcm(data: Uint8Array, key: CryptoKey, authenticating: Uint8Array = new Uint8Array()): Promise<Uint8Array> {\n  const iv = ensureUint8Array(data.slice(0, 12)) // nonce is the first 12 bytes\n  const encrypted = ensureUint8Array(data.slice(12)) // ciphertext and tag of 128 bits\n  const decrypted = await crypto.subtle.decrypt({\n    name: 'AES-GCM',\n    iv,\n    tagLength: AES_GCM_TAG_LENGTH_BITS,\n    additionalData: ensureUint8Array(authenticating),\n  }, key, encrypted)\n  return new Uint8Array(decrypted)\n}\n"],"mappings":";;;;AAEA,MAAM,0BAA0B;AAEhC,eAAsB,cAAc,MAAkB,KAAgB,iBAA6B,IAAI,YAAY,EAAuB;CACxI,MAAM,KAAK,OAAO,gBAAgB,IAAI,WAAW,GAAG,CAAC;CACrD,MAAM,YAAY,MAAM,OAAO,OAAO,QACpC;EACE,MAAM;EACN;EACA,WAAW;EACX,gBAAgBA,6BAAiB,eAAe;EACjD,EACD,KACAA,6BAAiB,KAAK,CACvB;CAED,MAAM,iBAAiB,IAAI,WAAW,UAAU;CAChD,MAAM,WAAW,IAAI,WAAW,GAAG,SAAS,eAAe,OAAO;AAClE,UAAS,IAAI,GAAG;AAChB,UAAS,IAAI,gBAAgB,GAAG,OAAO;AACvC,QAAO;;AAGT,eAAsB,cAAc,MAAkB,KAAgB,iBAA6B,IAAI,YAAY,EAAuB;CACxI,MAAM,KAAKA,6BAAiB,KAAK,MAAM,GAAG,GAAG,CAAC;CAC9C,MAAM,YAAYA,6BAAiB,KAAK,MAAM,GAAG,CAAC;CAClD,MAAM,YAAY,MAAM,OAAO,OAAO,QAAQ;EAC5C,MAAM;EACN;EACA,WAAW;EACX,gBAAgBA,6BAAiB,eAAe;EACjD,EAAE,KAAK,UAAU;AAClB,QAAO,IAAI,WAAW,UAAU"}