2021-06-22 14:46:42 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-07 23:28:47 +00:00
|
|
|
import { Bytes } from './context/Bytes';
|
|
|
|
|
|
|
|
const bytes = window.SignalContext?.bytes || new Bytes();
|
2021-06-22 14:46:42 +00:00
|
|
|
|
|
|
|
export function fromBase64(value: string): Uint8Array {
|
|
|
|
return bytes.fromBase64(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fromHex(value: string): Uint8Array {
|
|
|
|
return bytes.fromHex(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(indutny): deprecate it
|
|
|
|
export function fromBinary(value: string): Uint8Array {
|
|
|
|
return bytes.fromBinary(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fromString(value: string): Uint8Array {
|
|
|
|
return bytes.fromString(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function toBase64(data: Uint8Array): string {
|
|
|
|
return bytes.toBase64(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function toHex(data: Uint8Array): string {
|
|
|
|
return bytes.toHex(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(indutny): deprecate it
|
|
|
|
export function toBinary(data: Uint8Array): string {
|
|
|
|
return bytes.toBinary(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function toString(data: Uint8Array): string {
|
|
|
|
return bytes.toString(data);
|
|
|
|
}
|
|
|
|
|
2021-10-05 18:47:47 +00:00
|
|
|
export function byteLength(value: string): number {
|
|
|
|
return bytes.byteLength(value);
|
|
|
|
}
|
|
|
|
|
2021-07-13 18:54:53 +00:00
|
|
|
export function concatenate(list: ReadonlyArray<Uint8Array>): Uint8Array {
|
2021-06-22 14:46:42 +00:00
|
|
|
return bytes.concatenate(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isEmpty(data: Uint8Array | null | undefined): boolean {
|
|
|
|
return bytes.isEmpty(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isNotEmpty(
|
|
|
|
data: Uint8Array | null | undefined
|
|
|
|
): data is Uint8Array {
|
|
|
|
return !bytes.isEmpty(data);
|
|
|
|
}
|
2021-07-13 18:54:53 +00:00
|
|
|
|
|
|
|
export function areEqual(
|
|
|
|
a: Uint8Array | null | undefined,
|
|
|
|
b: Uint8Array | null | undefined
|
|
|
|
): boolean {
|
|
|
|
return bytes.areEqual(a, b);
|
|
|
|
}
|
2023-07-18 23:57:38 +00:00
|
|
|
|
|
|
|
export function readBigUint64BE(value: Uint8Array): bigint {
|
|
|
|
return bytes.readBigUint64BE(value);
|
|
|
|
}
|