2022-06-15 01:15:33 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-04-04 21:39:52 +00:00
|
|
|
import type { Net } from '@signalapp/libsignal-client';
|
2022-06-15 01:15:33 +00:00
|
|
|
import type { connection as WebSocket } from 'websocket';
|
|
|
|
|
|
|
|
import * as Bytes from '../../Bytes';
|
|
|
|
import { CDSISocket } from './CDSISocket';
|
|
|
|
import type { CDSSocketManagerBaseOptionsType } from './CDSSocketManagerBase';
|
|
|
|
import { CDSSocketManagerBase } from './CDSSocketManagerBase';
|
|
|
|
|
|
|
|
export type CDSIOptionsType = Readonly<{
|
|
|
|
mrenclave: string;
|
|
|
|
}> &
|
|
|
|
CDSSocketManagerBaseOptionsType;
|
|
|
|
|
|
|
|
export class CDSI extends CDSSocketManagerBase<CDSISocket, CDSIOptionsType> {
|
|
|
|
private readonly mrenclave: Buffer;
|
|
|
|
|
2024-04-04 21:39:52 +00:00
|
|
|
constructor(libsignalNet: Net.Net, options: CDSIOptionsType) {
|
|
|
|
super(libsignalNet, options);
|
2022-06-15 01:15:33 +00:00
|
|
|
|
|
|
|
this.mrenclave = Buffer.from(Bytes.fromHex(options.mrenclave));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override getSocketUrl(): string {
|
|
|
|
const { mrenclave } = this.options;
|
|
|
|
|
|
|
|
return `${this.options.url}/v1/${mrenclave}/discovery`;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override createSocket(socket: WebSocket): CDSISocket {
|
|
|
|
return new CDSISocket({
|
|
|
|
logger: this.logger,
|
|
|
|
socket,
|
|
|
|
mrenclave: this.mrenclave,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|