phucsd's picture
Deploy GitHub commit 1aa2e3555f9cd297eaf994af95fb4d10c5b1aff1
ad2afbf verified
Raw History Blame Contribute Delete
489 Bytes
export function decodeApplicationKey(encoded: string): Uint8Array {
if (!/^[A-Za-z0-9_-]+$/.test(encoded)) {
throw new Error("OLOKA_APP_KEY must be unpadded base64url");
}
const decoded = Buffer.from(encoded, "base64url");
if (decoded.length !== 32) {
throw new Error("OLOKA_APP_KEY must decode to exactly 32 bytes");
}
if (decoded.toString("base64url") !== encoded) {
throw new Error("OLOKA_APP_KEY must use canonical unpadded base64url");
}
return decoded;
}