Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function to_base64(d: string | Uint8Array) {
await sodium.ready;
return sodium.to_base64(d, sodium.base64_variants.ORIGINAL);
}
export async function to_base64_url(d: string | Uint8Array) {
await sodium.ready;
return sodium.to_base64(d, sodium.base64_variants.URLSAFE);
}
export const arrayToBase64 = async (array: ArrayBuffer | Uint8Array): Promise => {
await sodium.ready;
return sodium.to_base64(new Uint8Array(array), sodium.base64_variants.ORIGINAL);
};
const generatePasswordResetToken = ({ userId, secret }) => {
const asString = JSON.stringify({ userId, secret });
const buf = sodium.from_string(asString);
return sodium.to_base64(buf);
};