Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function stringifyValue(v){
var tv = typeof v;
if (tv == 'string') return v;
else if (tv == 'number' || tv == 'boolean') return v.toString();
else if (v instanceof Date) return v.getTime().toString();
else if (v instanceof Uint8Array) return libsodium.to_base64(v);
else if (tv == 'object') return JSON.stringify(v);
else {
console.log(v);
console.log(JSON.stringify(v));
throw new TypeError('Cannot stringifyValue() of type ' + tv);
}
}
return promise.then((pieces) => {
let metadata = {
header: sodium.to_base64(header, sodium.base64_variants.ORIGINAL_NO_PADDING),
encryptedMetadata: sodium.to_base64(metadataEncrypted, sodium.base64_variants.ORIGINAL_NO_PADDING),
};
return {
pieces,
metadata,
key: sodium.to_base64(key, sodium.base64_variants.URLSAFE_NO_PADDING),
};
});
});
export function toBase64(bytes: Uint8Array): b64string {
if (!(bytes instanceof Uint8Array))
throw new TypeError('"bytes" is not a Uint8Array');
return sodium.to_base64(bytes);
}