Files
libsignal/node/ts/zkgroup/auth/ClientZkAuthOperations.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

75 lines
2.3 KiB
TypeScript

//
// Copyright 2020-2022 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
import { randomBytes } from 'node:crypto';
import * as Native from '../../Native.js';
import { RANDOM_LENGTH } from '../internal/Constants.js';
import ServerPublicParams from '../ServerPublicParams.js';
import AuthCredentialPresentation from './AuthCredentialPresentation.js';
import AuthCredentialWithPni from './AuthCredentialWithPni.js';
import AuthCredentialWithPniResponse from './AuthCredentialWithPniResponse.js';
import GroupSecretParams from '../groups/GroupSecretParams.js';
import { Aci, Pni } from '../../Address.js';
export default class ClientZkAuthOperations {
serverPublicParams: ServerPublicParams;
constructor(serverPublicParams: ServerPublicParams) {
this.serverPublicParams = serverPublicParams;
}
/**
* Produces the AuthCredentialWithPni from a server-generated AuthCredentialWithPniResponse.
*
* @param redemptionTime - This is provided by the server as an integer, and should be passed through directly.
*/
receiveAuthCredentialWithPniAsServiceId(
aci: Aci,
pni: Pni,
redemptionTime: number,
authCredentialResponse: AuthCredentialWithPniResponse
): AuthCredentialWithPni {
return new AuthCredentialWithPni(
Native.ServerPublicParams_ReceiveAuthCredentialWithPniAsServiceId(
this.serverPublicParams,
aci.getServiceIdFixedWidthBinary(),
pni.getServiceIdFixedWidthBinary(),
redemptionTime,
authCredentialResponse.getContents()
)
);
}
createAuthCredentialWithPniPresentation(
groupSecretParams: GroupSecretParams,
authCredential: AuthCredentialWithPni
): AuthCredentialPresentation {
const random = randomBytes(RANDOM_LENGTH);
return this.createAuthCredentialWithPniPresentationWithRandom(
random,
groupSecretParams,
authCredential
);
}
createAuthCredentialWithPniPresentationWithRandom(
random: Uint8Array,
groupSecretParams: GroupSecretParams,
authCredential: AuthCredentialWithPni
): AuthCredentialPresentation {
return new AuthCredentialPresentation(
Native.ServerPublicParams_CreateAuthCredentialWithPniPresentationDeterministic(
this.serverPublicParams,
random,
groupSecretParams.getContents(),
authCredential.getContents()
)
);
}
}