INNER CODE UNIT · JavaScript
hexToArrayBuffer
codedogQBY/ReadAny · packages/app-expo/index.js:23
function hexToArrayBuffer(hex) {
const normalized = hex.trim();
const bytes = new Uint8Array(normalized.length / 2);
for (let i = 0; i < normalized.length; i += 2) {
bytes[i / 2] = Number.parseInt(normalized.slice(i, i + 2), 16);
}
return bytes.buffer;
}
function resolveDigestAlgorithm(algorithm) {
const name = typeof algorithm === "string" ? algorithm : algorithm?.name;
switch ((name || "").toUpperCase()) {
case "SHA-1":
return ExpoCrypto.CryptoDigestAlgorithm.SHA1;
case "SHA-256":
return ExpoCrypto.CryptoDigestAlgorithm.SHA256;
default:
throw new Error(`Unsupported digest algorithm: ${String(name || algorithm)}`);