Skip to content

Commit 42ff946

Browse files
committed
node: Enforce @typescript-eslint/method-signature-style
1 parent 3af0c15 commit 42ff946

File tree

9 files changed

+101
-92
lines changed

9 files changed

+101
-92
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ v0.82.0
22

33
- Node: migrate libsignal-client to the ECMAScript module format (from CommonJS).
44

5+
- Node: interfaces now use property notation for method requirements, which TypeScript can check more strictly.
6+
57
- net: Direct connections to the Signal servers will be tried as a fallback if connecting through an HTTP or SOCKS proxy fails or takes too long.

node/Native.d.ts

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,80 +64,83 @@ enum IdentityChange {
6464
}
6565

6666
type IdentityKeyStore = {
67-
_getIdentityKey(): Promise<PrivateKey>;
68-
_getLocalRegistrationId(): Promise<number>;
69-
_saveIdentity(name: ProtocolAddress, key: PublicKey): Promise<IdentityChange>;
70-
_isTrustedIdentity(
67+
_getIdentityKey: () => Promise<PrivateKey>;
68+
_getLocalRegistrationId: () => Promise<number>;
69+
_saveIdentity: (
70+
name: ProtocolAddress,
71+
key: PublicKey
72+
) => Promise<IdentityChange>;
73+
_isTrustedIdentity: (
7174
name: ProtocolAddress,
7275
key: PublicKey,
7376
sending: boolean
74-
): Promise<boolean>;
75-
_getIdentity(name: ProtocolAddress): Promise<PublicKey | null>;
77+
) => Promise<boolean>;
78+
_getIdentity: (name: ProtocolAddress) => Promise<PublicKey | null>;
7679
};
7780

7881
type SessionStore = {
79-
_saveSession(addr: ProtocolAddress, record: SessionRecord): Promise<void>;
80-
_getSession(addr: ProtocolAddress): Promise<SessionRecord | null>;
82+
_saveSession: (addr: ProtocolAddress, record: SessionRecord) => Promise<void>;
83+
_getSession: (addr: ProtocolAddress) => Promise<SessionRecord | null>;
8184
};
8285

8386
type PreKeyStore = {
84-
_savePreKey(preKeyId: number, record: PreKeyRecord): Promise<void>;
85-
_getPreKey(preKeyId: number): Promise<PreKeyRecord>;
86-
_removePreKey(preKeyId: number): Promise<void>;
87+
_savePreKey: (preKeyId: number, record: PreKeyRecord) => Promise<void>;
88+
_getPreKey: (preKeyId: number) => Promise<PreKeyRecord>;
89+
_removePreKey: (preKeyId: number) => Promise<void>;
8790
};
8891

8992
type SignedPreKeyStore = {
90-
_saveSignedPreKey(
93+
_saveSignedPreKey: (
9194
signedPreKeyId: number,
9295
record: SignedPreKeyRecord
93-
): Promise<void>;
94-
_getSignedPreKey(signedPreKeyId: number): Promise<SignedPreKeyRecord>;
96+
) => Promise<void>;
97+
_getSignedPreKey: (signedPreKeyId: number) => Promise<SignedPreKeyRecord>;
9598
};
9699

97100
type KyberPreKeyStore = {
98-
_saveKyberPreKey(
101+
_saveKyberPreKey: (
99102
kyberPreKeyId: number,
100103
record: KyberPreKeyRecord
101-
): Promise<void>;
102-
_getKyberPreKey(kyberPreKeyId: number): Promise<KyberPreKeyRecord>;
103-
_markKyberPreKeyUsed(
104+
) => Promise<void>;
105+
_getKyberPreKey: (kyberPreKeyId: number) => Promise<KyberPreKeyRecord>;
106+
_markKyberPreKeyUsed: (
104107
kyberPreKeyId: number,
105108
signedPreKeyId: number,
106109
baseKey: PublicKey
107-
): Promise<void>;
110+
) => Promise<void>;
108111
};
109112

110113
type SenderKeyStore = {
111-
_saveSenderKey(
114+
_saveSenderKey: (
112115
sender: ProtocolAddress,
113116
distributionId: Uuid,
114117
record: SenderKeyRecord
115-
): Promise<void>;
116-
_getSenderKey(
118+
) => Promise<void>;
119+
_getSenderKey: (
117120
sender: ProtocolAddress,
118121
distributionId: Uuid
119-
): Promise<SenderKeyRecord | null>;
122+
) => Promise<SenderKeyRecord | null>;
120123
};
121124

122125
type InputStream = {
123-
_read(amount: number): Promise<Uint8Array>;
124-
_skip(amount: number): Promise<void>;
126+
_read: (amount: number) => Promise<Uint8Array>;
127+
_skip: (amount: number) => Promise<void>;
125128
};
126129

127130
type SyncInputStream = Uint8Array;
128131

129132
type ChatListener = {
130-
_incoming_message(
133+
_incoming_message: (
131134
envelope: Uint8Array,
132135
timestamp: number,
133136
ack: ServerMessageAck
134-
): void;
135-
_queue_empty(): void;
136-
_received_alerts(alerts: string[]): void;
137-
_connection_interrupted(
137+
) => void;
138+
_queue_empty: () => void;
139+
_received_alerts: (alerts: string[]) => void;
140+
_connection_interrupted: (
138141
// A LibSignalError or null, but not naming the type to avoid circular import dependencies.
139142
reason: Error | null
140-
): void;
143+
) => void;
141144
};
142145

143146
type ChallengeOption = 'pushChallenge' | 'captcha';

node/eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const config = defineConfig(
9898
'@typescript-eslint/consistent-type-assertions': 'error',
9999
'@typescript-eslint/explicit-module-boundary-types': 'error',
100100
'@typescript-eslint/restrict-template-expressions': 'off',
101+
'@typescript-eslint/method-signature-style': 'error',
101102
'jsdoc/check-access': 'error',
102103
'jsdoc/check-alignment': 'error',
103104
'jsdoc/check-line-alignment': 'error',

node/ts/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,16 @@ export class KEMKeyPair {
237237

238238
/** The public information contained in a {@link SignedPreKeyRecord} */
239239
export type SignedPublicPreKey = {
240-
id(): number;
241-
publicKey(): PublicKey;
242-
signature(): Uint8Array;
240+
id: () => number;
241+
publicKey: () => PublicKey;
242+
signature: () => Uint8Array;
243243
};
244244

245245
/** The public information contained in a {@link KyberPreKeyRecord} */
246246
export type SignedKyberPublicPreKey = {
247-
id(): number;
248-
publicKey(): KEMPublicKey;
249-
signature(): Uint8Array;
247+
id: () => number;
248+
publicKey: () => KEMPublicKey;
249+
signature: () => Uint8Array;
250250
};
251251

252252
export class PreKeyBundle {
@@ -1320,7 +1320,7 @@ export class SealedSenderDecryptionResult {
13201320
}
13211321

13221322
export interface CiphertextMessageConvertible {
1323-
asCiphertextMessage(): CiphertextMessage;
1323+
asCiphertextMessage: () => CiphertextMessage;
13241324
}
13251325

13261326
export class CiphertextMessage {

node/ts/net/Chat.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface ConnectionEventsListener {
4141
* closures. If the closure was not due to a deliberate disconnect, the error
4242
* will be provided.
4343
*/
44-
onConnectionInterrupted(cause: LibSignalError | null): void;
44+
onConnectionInterrupted: (cause: LibSignalError | null) => void;
4545
}
4646

4747
export interface ChatServiceListener extends ConnectionEventsListener {
@@ -53,26 +53,26 @@ export interface ChatServiceListener extends ConnectionEventsListener {
5353
* If `ack`'s `send` method is not called, the server will leave this message in the message
5454
* queue and attempt to deliver it again in the future.
5555
*/
56-
onIncomingMessage(
56+
onIncomingMessage: (
5757
envelope: Uint8Array,
5858
timestamp: number,
5959
ack: ChatServerMessageAck
60-
): void;
60+
) => void;
6161

6262
/**
6363
* Called when the server indicates that there are no further messages in the message queue.
6464
*
6565
* Note that further messages may still be delivered; this merely indicates that all messages that
6666
* were in the queue *when the connection was established* have been delivered.
6767
*/
68-
onQueueEmpty(): void;
68+
onQueueEmpty: () => void;
6969

7070
/**
7171
* Called when the server has alerts for the current device.
7272
*
7373
* In practice this happens as part of the connecting process.
7474
*/
75-
onReceivedAlerts?(alerts: string[]): void;
75+
onReceivedAlerts?: (alerts: string[]) => void;
7676
}
7777

7878
/**
@@ -86,20 +86,20 @@ export type ChatConnection = {
8686
* Initiates termination of the underlying connection to the Chat Service. After the service is
8787
* disconnected, it cannot be used again.
8888
*/
89-
disconnect(): Promise<void>;
89+
disconnect: () => Promise<void>;
9090

9191
/**
9292
* Sends request to the Chat service.
9393
*/
94-
fetch(
94+
fetch: (
9595
chatRequest: ChatRequest,
9696
options?: RequestOptions
97-
): Promise<Native.ChatResponse>;
97+
) => Promise<Native.ChatResponse>;
9898

9999
/**
100100
* Information about the connection to the Chat service.
101101
*/
102-
connectionInfo(): ConnectionInfo;
102+
connectionInfo: () => ConnectionInfo;
103103
};
104104

105105
export interface ConnectionInfo {
@@ -438,8 +438,8 @@ function makeNativeChatListener(
438438
);
439439
}
440440
},
441-
_connection_interrupted(cause: LibSignalError | null): void {
442-
listener.onConnectionInterrupted(cause);
441+
_connection_interrupted(cause: Error | null): void {
442+
listener.onConnectionInterrupted(cause as LibSignalError);
443443
},
444444
};
445445
}

node/ts/net/KeyTransparency.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import {
2424
* used by the {@link Client}.
2525
*/
2626
export interface Store {
27-
getLastDistinguishedTreeHead(): Promise<Uint8Array | null>;
28-
setLastDistinguishedTreeHead(
27+
getLastDistinguishedTreeHead: () => Promise<Uint8Array | null>;
28+
setLastDistinguishedTreeHead: (
2929
bytes: Readonly<Uint8Array> | null
30-
): Promise<void>;
30+
) => Promise<void>;
3131

32-
getAccountData(aci: Aci): Promise<Uint8Array | null>;
33-
setAccountData(aci: Aci, bytes: Readonly<Uint8Array>): Promise<void>;
32+
getAccountData: (aci: Aci) => Promise<Uint8Array | null>;
33+
setAccountData: (aci: Aci, bytes: Readonly<Uint8Array>) => Promise<void>;
3434
}
3535

3636
/**
@@ -146,11 +146,11 @@ export interface Client {
146146
* @throws {IoError} if an error occurred while communicating with the
147147
* server.
148148
* */
149-
search(
149+
search: (
150150
request: Request,
151151
store: Store,
152152
options?: Readonly<Options>
153-
): Promise<void>;
153+
) => Promise<void>;
154154

155155
/**
156156
* Perform a monitor operation for an account previously searched for.
@@ -182,11 +182,11 @@ export interface Client {
182182
* @throws {IoError} if an error occurred while communicating with the
183183
* server.
184184
*/
185-
monitor(
185+
monitor: (
186186
request: MonitorRequest,
187187
store: Store,
188188
options?: Readonly<Options>
189-
): Promise<void>;
189+
) => Promise<void>;
190190
}
191191

192192
export class ClientImpl implements Client {

node/ts/net/chat/UnauthUsernamesService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ export interface UnauthUsernamesService {
2525
* Throws / completes with failure only if the request can't be completed, potentially including
2626
* if the hash is structurally invalid.
2727
*/
28-
lookUpUsernameHash(
28+
lookUpUsernameHash: (
2929
request: {
3030
hash: Uint8Array;
3131
},
3232
options?: RequestOptions
33-
): Promise<Aci | null>;
33+
) => Promise<Aci | null>;
3434
}
3535

3636
UnauthenticatedChatConnection.prototype.lookUpUsernameHash = async function (

node/ts/test/MessageBackupTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('OnlineBackupValidator', () => {
215215
// Here we override that `read` member with one that always produces a Uint8Array,
216216
// for more convenient use in the test. Note that this is unchecked.
217217
type ReadableUsingUint8Array = Omit<Readable, 'read'> & {
218-
read(size: number): Uint8Array;
218+
read: (size: number) => Uint8Array;
219219
};
220220
const input: ReadableUsingUint8Array = new Readable();
221221
input.push(exampleBackup);

0 commit comments

Comments
 (0)