mirror of
https://github.com/signalapp/libsignal.git
synced 2026-04-25 17:25:18 +02:00
This allows the file to be checked by tsc, which would have caught some of the missing type aliases sooner (now added to Native.ts.in). Strictly speaking the behavior is slightly different: we have returned to exporting many items individually instead of collecting them on a single object. Co-authored-by: Alex Bakon <akonradi@signal.org>
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
//
|
|
// Copyright 2023 Signal Messenger, LLC.
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import ByteArray from '../internal/ByteArray.js';
|
|
import * as Native from '../../Native.js';
|
|
|
|
import GenericServerSecretParams from '../GenericServerSecretParams.js';
|
|
import BackupLevel from './BackupLevel.js';
|
|
import BackupCredentialType from './BackupCredentialType.js';
|
|
|
|
export default class BackupAuthCredentialPresentation extends ByteArray {
|
|
private readonly __type?: never;
|
|
|
|
constructor(contents: Uint8Array) {
|
|
super(contents, Native.BackupAuthCredentialPresentation_CheckValidContents);
|
|
}
|
|
|
|
verify(
|
|
serverParams: GenericServerSecretParams,
|
|
now: Date = new Date()
|
|
): void {
|
|
Native.BackupAuthCredentialPresentation_Verify(
|
|
this.contents,
|
|
Math.floor(now.getTime() / 1000),
|
|
serverParams.contents
|
|
);
|
|
}
|
|
|
|
getBackupId(): Uint8Array {
|
|
return Native.BackupAuthCredentialPresentation_GetBackupId(this.contents);
|
|
}
|
|
|
|
getBackupLevel(): BackupLevel {
|
|
const n: number = Native.BackupAuthCredentialPresentation_GetBackupLevel(
|
|
this.contents
|
|
);
|
|
if (!(n in BackupLevel)) {
|
|
throw new TypeError(`Invalid BackupLevel ${n}`);
|
|
}
|
|
return n;
|
|
}
|
|
|
|
getType(): BackupCredentialType {
|
|
const n: number = Native.BackupAuthCredentialPresentation_GetType(
|
|
this.contents
|
|
);
|
|
if (!(n in BackupCredentialType)) {
|
|
throw new TypeError(`Invalid BackupCredentialType ${n}`);
|
|
}
|
|
return n;
|
|
}
|
|
}
|