Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function destringifyValue(v, t){
if (t == 'string') return v;
else if (t == 'number') return parseFloat(v);
else if (t == 'boolean'){
v = v.toLowerCase();
if (!(v == 'true' || v == 'false')) throw new RangeError('Invalid stringified boolean value: ' + v);
return v == 'true' ? true : false;
} else if (t == 'date'){
return new Date(parseInt(v));
} else if (t == 'buffer') return libsodium.from_base64(v);
else if (t == 'object') return JSON.parse(v);
else throw new TypeError('Unsupported type: ' + t);
}
export function fromBase64(str: b64string): Uint8Array {
if (typeof str !== 'string')
throw new TypeError('"str" is not a string');
return sodium.from_base64(str);
}
function fromB64URLSafe(str) {
if (!(typeof str === 'string')) { throw new TypeError('Can only decode string'); }
return Buffer.from(sodium.from_base64(str, sodium.base64_variants.URLSAFE_NO_PADDING));
}
constructor(key) {
this.key = sodium.from_base64(key, sodium.base64_variants.URLSAFE_NO_PADDING);
}
function b64dec (input) {
return sodium.from_base64(input, sodium.base64_variants.URLSAFE)
}