{"version":3,"file":"auxiliary-files.cjs","sourceRoot":"","sources":["../src/auxiliary-files.ts"],"names":[],"mappings":";;;AAAA,mDAA4D;AAC5D,2CAAoE;AAEpE,yCAAwC;AACxC,+CAA4C;AAG5C;;;;;;GAMG;AACI,KAAK,UAAU,mBAAmB,CACvC,KAAa,EACb,QAA+B;IAE/B,oDAAoD;IACpD,IAAI,QAAQ,KAAK,iCAAqB,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,qCAAqC;IACrC,MAAM,OAAO,GAAG,MAAM,IAAA,qBAAY,EAAC,KAAK,CAAC,CAAC;IAC1C,IAAI,QAAQ,KAAK,iCAAqB,CAAC,IAAI,EAAE,CAAC;QAC5C,OAAO,IAAA,qBAAa,EAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC;AAC7B,CAAC;AAhBD,kDAgBC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,KAAoB;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAA,cAAM,EACJ,IAAI,CAAC,IAAI,GAAG,yBAAa,EACzB,+DAA+D,CAChE,CAAC;IACJ,CAAC;AACH,CAAC;AAPD,wDAOC","sourcesContent":["import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport { assert, bytesToHex, bytesToString } from '@metamask/utils';\n\nimport { decodeBase64 } from './base64';\nimport { MAX_FILE_SIZE } from './constants';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Re-encodes an auxiliary file if needed depending on the requested file encoding.\n *\n * @param value - The base64 value stored for the auxiliary file.\n * @param encoding - The chosen encoding.\n * @returns The file encoded in the requested encoding.\n */\nexport async function encodeAuxiliaryFile(\n  value: string,\n  encoding: AuxiliaryFileEncoding,\n) {\n  // Input is assumed to be the stored file in base64.\n  if (encoding === AuxiliaryFileEncoding.Base64) {\n    return value;\n  }\n\n  // TODO: Use @metamask/utils for this\n  const decoded = await decodeBase64(value);\n  if (encoding === AuxiliaryFileEncoding.Utf8) {\n    return bytesToString(decoded);\n  }\n\n  return bytesToHex(decoded);\n}\n\n/**\n * Validate that auxiliary files used by the Snap are within size limits.\n *\n * @param files - A list of auxiliary files.\n */\nexport function validateAuxiliaryFiles(files: VirtualFile[]) {\n  for (const file of files) {\n    assert(\n      file.size < MAX_FILE_SIZE,\n      'Static files required by the Snap must be smaller than 64 MB.',\n    );\n  }\n}\n"]}