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);
});
});
serialised_json(): SerialisedJSON {
return {
id: this.prekey_id,
key: sodium.to_base64(new Uint8Array(this.serialise()), sodium.base64_variants.ORIGINAL),
};
}
serialised_json(): SerialisedJSON {
return {
id: this.prekey_id,
key: sodium.to_base64(new Uint8Array(this.serialise()), sodium.base64_variants.ORIGINAL),
};
}
export async function to_base64_url_nopad(d: string | Uint8Array) {
await sodium.ready;
return sodium.to_base64(d, sodium.base64_variants.URLSAFE_NO_PADDING);
}
return rand(sec).then((bytes) => {
return done(null, sodium.to_base64(bytes, sodium.base64_variants.URLSAFE_NO_PADDING));
}).catch((err) => { return done(err); })
}
export const arrayToMd5Base64 = async (array: Uint8Array): Promise => {
await sodium.ready;
const md5Hash = JsMD5.arrayBuffer(array);
return sodium.to_base64(new Uint8Array(md5Hash), sodium.base64_variants.ORIGINAL);
};