Files
libsignal/node/ts/zkgroup/groupsend/GroupSendFullToken.ts
Jordan Rose 85686caa01 node: Combine Native.js and .d.ts into Native.ts
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>
2025-10-15 17:50:37 -07:00

53 lines
1.5 KiB
TypeScript

//
// Copyright 2024 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
import ByteArray from '../internal/ByteArray.js';
import * as Native from '../../Native.js';
import { ServiceId } from '../../Address.js';
import GroupSendDerivedKeyPair from './GroupSendDerivedKeyPair.js';
// For docs
import type GroupSendEndorsement from './GroupSendEndorsement.js';
import type { VerificationFailedError } from '../../Errors.js';
/**
* A token representing a particular {@link GroupSendEndorsement}, along with the endorsement's
* expiration.
*
* Generated by {@link GroupSendToken#toFullToken}, and verified by the chat server.
*/
export default class GroupSendFullToken extends ByteArray {
constructor(contents: Uint8Array) {
super(contents, Native.GroupSendFullToken_CheckValidContents);
}
/** Gets the expiration embedded in the token. */
getExpiration(): Date {
return new Date(
1000 * Native.GroupSendFullToken_GetExpiration(this.contents)
);
}
/**
* Verifies that this token was generated from an endorsement of `userIds` by `keyPair`.
*
* The correct `keyPair` must be selected based on {@link #getExpiration}.
*
* @throws {VerificationFailedError} if the token is invalid.
*/
verify(
userIds: ServiceId[],
keyPair: GroupSendDerivedKeyPair,
now: Date = new Date()
): void {
Native.GroupSendFullToken_Verify(
this.contents,
ServiceId.toConcatenatedFixedWidthBinary(userIds),
Math.floor(now.getTime() / 1000),
keyPair.contents
);
}
}