Files
libsignal/node/ts/net/chat/UnauthUsernamesService.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

56 lines
1.5 KiB
TypeScript

//
// Copyright 2025 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
import { Buffer } from 'node:buffer';
import * as Native from '../../Native.js';
import { Aci } from '../../Address.js';
import { RequestOptions, UnauthenticatedChatConnection } from '../Chat.js';
// For documentation
import type * as usernames from '../../usernames.js';
declare module '../Chat' {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface UnauthenticatedChatConnection extends UnauthUsernamesService {}
}
export interface UnauthUsernamesService {
/**
* Looks up a username hash on the service, like that computed by {@link usernames.hash}.
*
* Returns the corresponding account's ACI, or `null` if the username doesn't correspond to an
* account.
*
* Throws / completes with failure only if the request can't be completed, potentially including
* if the hash is structurally invalid.
*/
lookUpUsernameHash: (
request: {
hash: Uint8Array;
},
options?: RequestOptions
) => Promise<Aci | null>;
}
UnauthenticatedChatConnection.prototype.lookUpUsernameHash = async function (
{
hash,
}: {
hash: Uint8Array;
},
options?: RequestOptions
): Promise<Aci | null> {
const response = await this._asyncContext.makeCancellable(
options?.abortSignal,
Native.UnauthenticatedChatConnection_look_up_username_hash(
this._asyncContext,
this._chatService,
Buffer.from(hash)
)
);
return response ? Aci.fromUuidBytes(response) : null;
};