mirror of
https://github.com/lux-tel/session-desktop.git
synced 2026-10-30 20:33:24 +00:00
31 lines
815 B
TypeScript
31 lines
815 B
TypeScript
import crypto from 'crypto';
|
|
import libsodiumwrappers from 'libsodium-wrappers-sumo';
|
|
|
|
export type LibSodiumWrappers = typeof libsodiumwrappers;
|
|
|
|
export type WithLibSodiumWrappers = {
|
|
sodium: LibSodiumWrappers;
|
|
};
|
|
|
|
export async function getSodiumRenderer(): Promise<LibSodiumWrappers> {
|
|
await libsodiumwrappers.ready;
|
|
return libsodiumwrappers;
|
|
}
|
|
|
|
export const sha256 = (s: string) => {
|
|
return crypto.createHash('sha256').update(s).digest('base64');
|
|
};
|
|
|
|
export const concatUInt8Array = (...args: Array<Uint8Array>): Uint8Array => {
|
|
const totalLength = args.reduce((acc, current) => acc + current.length, 0);
|
|
|
|
const concatted = new Uint8Array(totalLength);
|
|
let currentIndex = 0;
|
|
args.forEach(arr => {
|
|
concatted.set(arr, currentIndex);
|
|
currentIndex += arr.length;
|
|
});
|
|
|
|
return concatted;
|
|
};
|