Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should generate a serialised JSON format', async () => {
const pre_key_id = 72;
const [identity_key_pair, pre_key] = await Promise.all([
Proteus.keys.IdentityKeyPair.new(),
Proteus.keys.PreKey.new(pre_key_id),
]);
const public_identity_key = identity_key_pair.public_key;
const pre_key_bundle = Proteus.keys.PreKeyBundle.new(public_identity_key, pre_key);
const serialised_pre_key_bundle_json = pre_key_bundle.serialised_json();
expect(serialised_pre_key_bundle_json.id).toBe(pre_key_id);
const serialised_array_buffer_view = sodium.from_base64(
serialised_pre_key_bundle_json.key,
sodium.base64_variants.ORIGINAL,
);
const serialised_array_buffer = serialised_array_buffer_view.buffer;
const deserialised_pre_key_bundle = Proteus.keys.PreKeyBundle.deserialise(serialised_array_buffer);
expect(deserialised_pre_key_bundle.public_key).toEqual(pre_key_bundle.public_key);
});
});
export const base64ToArray = async (base64: string): Promise => {
await sodium.ready;
return sodium.from_base64(stripDataUri(base64), sodium.base64_variants.ORIGINAL);
};
export async function from_base64_url_nopad(s: string) {
await sodium.ready;
return sodium.from_base64(s, sodium.base64_variants.URLSAFE_NO_PADDING);
}
const parsePasswordResetToken = (b64token) => {
const buf = sodium.from_base64(b64token);
const string = sodium.to_string(buf);
return JSON.parse(string);
};
export async function from_base64_url(s: string) {
await sodium.ready;
return sodium.from_base64(s, sodium.base64_variants.URLSAFE);
}