one
Version:
One is a React framework for web, iOS, and Android apps.
1 lines • 2.49 kB
Source Map (JSON)
{"version":3,"file":"digest-api.js","names":[],"sources":["esm/platform/crypto/digest-api.js"],"sourcesContent":["import { bytesToBase64, bytesToHex, utf8Encode } from \"./bytes\";\nimport { bufferSourceRange } from \"./digest\";\nconst DIGEST_ALGORITHMS = [\n \"MD5\",\n \"SHA-1\",\n \"SHA-256\",\n \"SHA-384\",\n \"SHA-512\"\n];\nfunction assertDigestAlgorithm(algorithm, verb) {\n if (!DIGEST_ALGORITHMS.includes(algorithm)) {\n throw new Error(\n `${verb}: unknown algorithm ${JSON.stringify(algorithm)}. Expected one of: ${DIGEST_ALGORITHMS.join(\", \")}`\n );\n }\n}\nfunction createDigestApi(source) {\n async function digest(algorithm, data) {\n assertDigestAlgorithm(algorithm, \"Crypto.digest\");\n const { buffer, offset, length } = bufferSourceRange(data, \"Crypto.digest\");\n return source(algorithm, buffer, offset, length);\n }\n async function digestString(algorithm, data, options = {}) {\n assertDigestAlgorithm(algorithm, \"Crypto.digestString\");\n if (typeof data !== \"string\") {\n throw new TypeError(\"Crypto.digestString: data must be a string\");\n }\n const encoding = options?.encoding ?? \"hex\";\n if (encoding !== \"hex\" && encoding !== \"base64\") {\n throw new Error(`Crypto.digestString: encoding must be 'hex' or 'base64'`);\n }\n const bytes = utf8Encode(data);\n const hashed = new Uint8Array(await source(algorithm, bytes.buffer, 0, bytes.length));\n return encoding === \"base64\" ? bytesToBase64(hashed) : bytesToHex(hashed);\n }\n return { digest, digestString };\n}\nexport {\n DIGEST_ALGORITHMS,\n assertDigestAlgorithm,\n createDigestApi\n};\n//# sourceMappingURL=digest-api.js.map\n"],"mappings":";;;;AAEA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;AACF;AACA,SAAS,sBAAsB,WAAW,MAAM;CAC9C,IAAI,CAAC,kBAAkB,SAAS,SAAS,GAAG;EAC1C,MAAM,IAAI,MACR,GAAG,KAAK,sBAAsB,KAAK,UAAU,SAAS,EAAE,qBAAqB,kBAAkB,KAAK,IAAI,GAC1G;CACF;AACF;AACA,SAAS,gBAAgB,QAAQ;CAC/B,eAAe,OAAO,WAAW,MAAM;EACrC,sBAAsB,WAAW,eAAe;EAChD,MAAM,EAAE,QAAQ,QAAQ,WAAW,kBAAkB,MAAM,eAAe;EAC1E,OAAO,OAAO,WAAW,QAAQ,QAAQ,MAAM;CACjD;CACA,eAAe,aAAa,WAAW,MAAM,UAAU,CAAC,GAAG;EACzD,sBAAsB,WAAW,qBAAqB;EACtD,IAAI,OAAO,SAAS,UAAU;GAC5B,MAAM,IAAI,UAAU,4CAA4C;EAClE;EACA,MAAM,WAAW,SAAS,YAAY;EACtC,IAAI,aAAa,SAAS,aAAa,UAAU;GAC/C,MAAM,IAAI,MAAM,yDAAyD;EAC3E;EACA,MAAM,QAAQ,WAAW,IAAI;EAC7B,MAAM,SAAS,IAAI,WAAW,MAAM,OAAO,WAAW,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC;EACpF,OAAO,aAAa,WAAW,cAAc,MAAM,IAAI,WAAW,MAAM;CAC1E;CACA,OAAO;EAAE;EAAQ;CAAa;AAChC"}