signal-sdk 0.0.9 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +184 -61
  2. package/dist/MultiAccountManager.d.ts +149 -0
  3. package/dist/MultiAccountManager.js +320 -0
  4. package/dist/SignalBot.d.ts +1 -0
  5. package/dist/SignalBot.js +20 -2
  6. package/dist/SignalCli.d.ts +315 -16
  7. package/dist/SignalCli.js +880 -26
  8. package/dist/__tests__/MultiAccountManager.test.d.ts +4 -0
  9. package/dist/__tests__/MultiAccountManager.test.js +209 -0
  10. package/dist/__tests__/SignalBot.additional.test.d.ts +5 -0
  11. package/dist/__tests__/SignalBot.additional.test.js +353 -0
  12. package/dist/__tests__/SignalBot.test.js +5 -0
  13. package/dist/__tests__/SignalCli.advanced.test.d.ts +5 -0
  14. package/dist/__tests__/SignalCli.advanced.test.js +295 -0
  15. package/dist/__tests__/SignalCli.e2e.test.d.ts +5 -0
  16. package/dist/__tests__/SignalCli.e2e.test.js +240 -0
  17. package/dist/__tests__/SignalCli.integration.test.d.ts +5 -0
  18. package/dist/__tests__/SignalCli.integration.test.js +225 -0
  19. package/dist/__tests__/SignalCli.methods.test.d.ts +5 -0
  20. package/dist/__tests__/SignalCli.methods.test.js +556 -0
  21. package/dist/__tests__/SignalCli.parsing.test.d.ts +5 -0
  22. package/dist/__tests__/SignalCli.parsing.test.js +258 -0
  23. package/dist/__tests__/SignalCli.test.js +249 -13
  24. package/dist/__tests__/config.test.d.ts +5 -0
  25. package/dist/__tests__/config.test.js +252 -0
  26. package/dist/__tests__/errors.test.d.ts +5 -0
  27. package/dist/__tests__/errors.test.js +276 -0
  28. package/dist/__tests__/retry.test.d.ts +4 -0
  29. package/dist/__tests__/retry.test.js +123 -0
  30. package/dist/__tests__/validators.test.d.ts +4 -0
  31. package/dist/__tests__/validators.test.js +147 -0
  32. package/dist/config.d.ts +82 -0
  33. package/dist/config.js +116 -0
  34. package/dist/errors.d.ts +32 -0
  35. package/dist/errors.js +75 -0
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.js +7 -1
  38. package/dist/interfaces.d.ts +200 -10
  39. package/dist/interfaces.js +1 -1
  40. package/dist/retry.d.ts +56 -0
  41. package/dist/retry.js +152 -0
  42. package/dist/validators.d.ts +59 -0
  43. package/dist/validators.js +170 -0
  44. package/package.json +1 -1
@@ -1,12 +1,23 @@
1
- import { Message, Contact, GroupUpdateOptions, SendMessageOptions, ContactUpdateOptions, AccountConfiguration, Device, ReceiptType, StickerPack, IdentityKey, LinkingOptions, LinkingResult, MessageRequestResponseType, SendResponse, GroupInfo, RemoveContactOptions, UserStatusResult, PaymentNotificationData, StickerPackManifest, StickerPackUploadResult, RateLimitChallengeResult, ChangeNumberSession, UploadProgress } from './interfaces';
1
+ import { Message, Contact, GroupUpdateOptions, SendMessageOptions, ContactUpdateOptions, AccountConfiguration, Device, ReceiptType, StickerPack, IdentityKey, LinkingOptions, LinkingResult, MessageRequestResponseType, SendResponse, GroupInfo, RemoveContactOptions, UserStatusResult, PaymentNotificationData, StickerPackManifest, StickerPackUploadResult, RateLimitChallengeResult, ReceiveOptions, UploadProgress, PollCreateOptions, PollVoteOptions, PollTerminateOptions, GetAttachmentOptions, GetAvatarOptions, GetStickerOptions, UpdateAccountOptions, AccountUpdateResult, SendContactsOptions, ListGroupsOptions } from './interfaces';
2
2
  import { EventEmitter } from 'events';
3
+ import { SignalCliConfig } from './config';
3
4
  export declare class SignalCli extends EventEmitter {
4
5
  private signalCliPath;
5
6
  private account?;
6
7
  private cliProcess;
7
8
  private requestPromises;
8
- constructor(accountOrPath?: string, account?: string);
9
+ private config;
10
+ private logger;
11
+ private rateLimiter;
12
+ private reconnectAttempts;
13
+ private maxReconnectAttempts;
14
+ constructor(accountOrPath?: string, account?: string, config?: SignalCliConfig);
9
15
  connect(): Promise<void>;
16
+ private connectJsonRpc;
17
+ private connectUnixSocket;
18
+ private connectTcp;
19
+ private connectHttp;
20
+ private httpRequest;
10
21
  disconnect(): void;
11
22
  gracefulShutdown(): Promise<void>;
12
23
  private handleRpcResponse;
@@ -36,6 +47,55 @@ export declare class SignalCli extends EventEmitter {
36
47
  removePin(): Promise<void>;
37
48
  listIdentities(number?: string): Promise<IdentityKey[]>;
38
49
  trustIdentity(number: string, safetyNumber: string, verified?: boolean): Promise<void>;
50
+ /**
51
+ * Get the safety number for a specific contact.
52
+ * This is a helper method that extracts just the safety number from identity information.
53
+ *
54
+ * @param number - The phone number of the contact
55
+ * @returns The safety number string, or null if not found
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const safetyNumber = await signal.getSafetyNumber('+33123456789');
60
+ * console.log(`Safety number: ${safetyNumber}`);
61
+ * ```
62
+ */
63
+ getSafetyNumber(number: string): Promise<string | null>;
64
+ /**
65
+ * Verify a safety number for a contact.
66
+ * Checks if the provided safety number matches the stored one and marks it as trusted if it does.
67
+ *
68
+ * @param number - The phone number of the contact
69
+ * @param safetyNumber - The safety number to verify
70
+ * @returns True if the safety number matches and was trusted, false otherwise
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const verified = await signal.verifySafetyNumber('+33123456789', '123456 78901...');
75
+ * if (verified) {
76
+ * console.log('Safety number verified and trusted');
77
+ * } else {
78
+ * console.log('Safety number does not match!');
79
+ * }
80
+ * ```
81
+ */
82
+ verifySafetyNumber(number: string, safetyNumber: string): Promise<boolean>;
83
+ /**
84
+ * List all untrusted identities.
85
+ * Returns identities that have not been explicitly trusted.
86
+ *
87
+ * @returns Array of untrusted identity keys
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const untrusted = await signal.listUntrustedIdentities();
92
+ * console.log(`Found ${untrusted.length} untrusted identities`);
93
+ * untrusted.forEach(id => {
94
+ * console.log(`${id.number}: ${id.safetyNumber}`);
95
+ * });
96
+ * ```
97
+ */
98
+ listUntrustedIdentities(): Promise<IdentityKey[]>;
39
99
  link(deviceName?: string): Promise<string>;
40
100
  /**
41
101
  * Link a new device to an existing Signal account with QR code support.
@@ -57,6 +117,45 @@ export declare class SignalCli extends EventEmitter {
57
117
  createGroup(name: string, members: string[]): Promise<GroupInfo>;
58
118
  updateGroup(groupId: string, options: GroupUpdateOptions): Promise<void>;
59
119
  listGroups(): Promise<GroupInfo[]>;
120
+ /**
121
+ * Send group invite link to a recipient.
122
+ * Retrieves and sends the invitation link for a group.
123
+ *
124
+ * @param groupId - The group ID
125
+ * @param recipient - The recipient to send the invite link to
126
+ * @returns Send response
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * await signal.sendGroupInviteLink('groupId123==', '+33123456789');
131
+ * ```
132
+ */
133
+ sendGroupInviteLink(groupId: string, recipient: string): Promise<SendResponse>;
134
+ /**
135
+ * Set banned members for a group.
136
+ * Ban specific members from the group.
137
+ *
138
+ * @param groupId - The group ID
139
+ * @param members - Array of phone numbers to ban
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * await signal.setBannedMembers('groupId123==', ['+33111111111', '+33222222222']);
144
+ * ```
145
+ */
146
+ setBannedMembers(groupId: string, members: string[]): Promise<void>;
147
+ /**
148
+ * Reset group invite link.
149
+ * Invalidates the current group invite link and generates a new one.
150
+ *
151
+ * @param groupId - The group ID
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * await signal.resetGroupLink('groupId123==');
156
+ * ```
157
+ */
158
+ resetGroupLink(groupId: string): Promise<void>;
60
159
  listContacts(): Promise<Contact[]>;
61
160
  listDevices(): Promise<Device[]>;
62
161
  listAccounts(): Promise<string[]>;
@@ -75,6 +174,33 @@ export declare class SignalCli extends EventEmitter {
75
174
  * This method now calls gracefulShutdown() for backward compatibility.
76
175
  */
77
176
  stopDaemon(): void;
177
+ /**
178
+ * Receive messages from Signal with configurable options.
179
+ * This is the modern replacement for the deprecated receiveMessages().
180
+ *
181
+ * @param options - Options for receiving messages
182
+ * @returns Array of received messages
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * // Receive with default timeout
187
+ * const messages = await signal.receive();
188
+ *
189
+ * // Receive with custom options
190
+ * const messages = await signal.receive({
191
+ * timeout: 10,
192
+ * maxMessages: 5,
193
+ * ignoreAttachments: true,
194
+ * sendReadReceipts: true
195
+ * });
196
+ * ```
197
+ */
198
+ receive(options?: ReceiveOptions): Promise<Message[]>;
199
+ /**
200
+ * Parse a message envelope from signal-cli into a Message object.
201
+ * @private
202
+ */
203
+ private parseEnvelope;
78
204
  /**
79
205
  * Remove a contact from the contact list.
80
206
  * @param number - The phone number of the contact to remove
@@ -89,10 +215,22 @@ export declare class SignalCli extends EventEmitter {
89
215
  */
90
216
  getUserStatus(numbers?: string[], usernames?: string[]): Promise<UserStatusResult[]>;
91
217
  /**
92
- * Send a payment notification to a recipient.
93
- * @param recipient - Phone number or group ID to send the notification to
94
- * @param paymentData - Payment notification data including receipt
95
- * @returns Send response with timestamp and other details
218
+ * Send a payment notification to a recipient (MobileCoin).
219
+ * Sends a notification about a cryptocurrency payment made through Signal's MobileCoin integration.
220
+ *
221
+ * @param recipient - The phone number or group ID of the recipient
222
+ * @param paymentData - Payment notification data including receipt and optional note
223
+ * @returns Send result with timestamp
224
+ * @throws {Error} If receipt is invalid or sending fails
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * const receiptBlob = 'base64EncodedReceiptData...';
229
+ * await signal.sendPaymentNotification('+33612345678', {
230
+ * receipt: receiptBlob,
231
+ * note: 'Thanks for dinner!'
232
+ * });
233
+ * ```
96
234
  */
97
235
  sendPaymentNotification(recipient: string, paymentData: PaymentNotificationData): Promise<SendResponse>;
98
236
  /**
@@ -109,19 +247,27 @@ export declare class SignalCli extends EventEmitter {
109
247
  */
110
248
  submitRateLimitChallenge(challenge: string, captcha: string): Promise<RateLimitChallengeResult>;
111
249
  /**
112
- * Start the process of changing phone number.
113
- * @param newNumber - The new phone number to change to
114
- * @param voice - Whether to use voice verification instead of SMS
115
- * @param captcha - Captcha token if required
116
- * @returns Change number session information
250
+ * Start the phone number change process.
251
+ * Initiates SMS or voice verification for changing your account to a new phone number.
252
+ * After calling this, you must verify the new number with finishChangeNumber().
253
+ *
254
+ * @param newNumber - The new phone number in E164 format (e.g., "+33612345678")
255
+ * @param voice - Use voice verification instead of SMS (default: false)
256
+ * @param captcha - Optional captcha token if required
257
+ * @throws {Error} If not a primary device or rate limited
117
258
  */
118
- startChangeNumber(newNumber: string, voice?: boolean, captcha?: string): Promise<ChangeNumberSession>;
259
+ startChangeNumber(newNumber: string, voice?: boolean, captcha?: string): Promise<void>;
119
260
  /**
120
- * Finish the phone number change process with verification code.
121
- * @param verificationCode - The verification code received via SMS/voice
122
- * @param pin - Registration lock PIN if enabled
261
+ * Complete the phone number change process.
262
+ * Verifies the code received via SMS or voice and changes your account to the new number.
263
+ * Must be called after startChangeNumber().
264
+ *
265
+ * @param newNumber - The new phone number (same as startChangeNumber)
266
+ * @param verificationCode - The verification code received via SMS or voice
267
+ * @param pin - Optional registration lock PIN if one was set
268
+ * @throws {Error} If verification fails or incorrect PIN
123
269
  */
124
- finishChangeNumber(verificationCode: string, pin?: string): Promise<void>;
270
+ finishChangeNumber(newNumber: string, verificationCode: string, pin?: string): Promise<void>;
125
271
  /**
126
272
  * Enhanced send message with progress callback support.
127
273
  * @param recipient - Phone number or group ID
@@ -132,4 +278,157 @@ export declare class SignalCli extends EventEmitter {
132
278
  sendMessageWithProgress(recipient: string, message: string, options?: SendMessageOptions & {
133
279
  onProgress?: (progress: UploadProgress) => void;
134
280
  }): Promise<SendResponse>;
281
+ /**
282
+ * Send a poll create message to a recipient or group.
283
+ * @param options Poll creation options
284
+ * @returns Send response with timestamp
285
+ */
286
+ sendPollCreate(options: PollCreateOptions): Promise<SendResponse>;
287
+ /**
288
+ * Send a poll vote message to vote on a poll.
289
+ * @param recipient Recipient or group ID
290
+ * @param options Poll vote options
291
+ * @returns Send response with timestamp
292
+ */
293
+ sendPollVote(recipient: string, options: PollVoteOptions): Promise<SendResponse>;
294
+ /**
295
+ * Send a poll terminate message to close a poll.
296
+ * @param recipient Recipient or group ID
297
+ * @param options Poll terminate options
298
+ * @returns Send response with timestamp
299
+ */
300
+ sendPollTerminate(recipient: string, options: PollTerminateOptions): Promise<SendResponse>;
301
+ /**
302
+ * Update account information (device name, username, privacy settings).
303
+ * @param options Account update options
304
+ * @returns Account update result
305
+ */
306
+ updateAccount(options: UpdateAccountOptions): Promise<AccountUpdateResult>;
307
+ /**
308
+ * Set or update the username for this account.
309
+ * Helper method that wraps updateAccount() for simpler username management.
310
+ *
311
+ * @param username - The username to set (without discriminator)
312
+ * @returns Account update result with username and link
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * const result = await signal.setUsername('myusername');
317
+ * console.log(`Username: ${result.username}`);
318
+ * console.log(`Link: ${result.usernameLink}`);
319
+ * ```
320
+ */
321
+ setUsername(username: string): Promise<AccountUpdateResult>;
322
+ /**
323
+ * Delete the current username from this account.
324
+ * Helper method that wraps updateAccount() for simpler username deletion.
325
+ *
326
+ * @returns Account update result
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * const result = await signal.deleteUsername();
331
+ * if (result.success) {
332
+ * console.log('Username deleted successfully');
333
+ * }
334
+ * ```
335
+ */
336
+ deleteUsername(): Promise<AccountUpdateResult>;
337
+ /**
338
+ * Get raw attachment data as base64 string.
339
+ * @param options Attachment retrieval options
340
+ * @returns Base64 encoded attachment data
341
+ */
342
+ getAttachment(options: GetAttachmentOptions): Promise<string>;
343
+ /**
344
+ * Get raw avatar data as base64 string.
345
+ * @param options Avatar retrieval options
346
+ * @returns Base64 encoded avatar data
347
+ */
348
+ getAvatar(options: GetAvatarOptions): Promise<string>;
349
+ /**
350
+ * Get raw sticker data as base64 string.
351
+ * @param options Sticker retrieval options
352
+ * @returns Base64 encoded sticker data
353
+ */
354
+ getSticker(options: GetStickerOptions): Promise<string>;
355
+ /**
356
+ * Send contacts synchronization message to linked devices.
357
+ * @param options Contacts sync options
358
+ */
359
+ sendContacts(options?: SendContactsOptions): Promise<void>;
360
+ /**
361
+ * List groups with optional filtering and details.
362
+ * @param options List groups options
363
+ * @returns Array of group information
364
+ */
365
+ listGroupsDetailed(options?: ListGroupsOptions): Promise<GroupInfo[]>;
366
+ /**
367
+ * List all local accounts.
368
+ * @returns Array of account phone numbers
369
+ */
370
+ listAccountsDetailed(): Promise<Array<{
371
+ number: string;
372
+ name?: string;
373
+ uuid?: string;
374
+ }>>;
375
+ /**
376
+ * Extract profile information from a contact.
377
+ * Parses givenName, familyName, mobileCoinAddress from profile data.
378
+ *
379
+ * @param contact - The contact object to parse
380
+ * @returns Enhanced contact with extracted profile fields
381
+ *
382
+ * @example
383
+ * ```typescript
384
+ * const contacts = await signal.listContacts();
385
+ * const enriched = signal.parseContactProfile(contacts[0]);
386
+ * console.log(enriched.givenName, enriched.familyName);
387
+ * ```
388
+ */
389
+ parseContactProfile(contact: Contact): Contact;
390
+ /**
391
+ * Extract group membership details.
392
+ * Parses pendingMembers, bannedMembers, inviteLink from group data.
393
+ *
394
+ * @param group - The group info to parse
395
+ * @returns Enhanced group with extracted membership fields
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * const groups = await signal.listGroups();
400
+ * const enriched = signal.parseGroupDetails(groups[0]);
401
+ * console.log(enriched.pendingMembers, enriched.bannedMembers);
402
+ * ```
403
+ */
404
+ parseGroupDetails(group: GroupInfo): GroupInfo;
405
+ /**
406
+ * Get enriched contacts list with parsed profile information.
407
+ *
408
+ * @returns Array of contacts with full profile data
409
+ *
410
+ * @example
411
+ * ```typescript
412
+ * const contacts = await signal.getContactsWithProfiles();
413
+ * contacts.forEach(c => {
414
+ * console.log(`${c.givenName} ${c.familyName} - ${c.mobileCoinAddress}`);
415
+ * });
416
+ * ```
417
+ */
418
+ getContactsWithProfiles(): Promise<Contact[]>;
419
+ /**
420
+ * Get enriched groups list with parsed membership details.
421
+ *
422
+ * @param options - List groups options
423
+ * @returns Array of groups with full membership data
424
+ *
425
+ * @example
426
+ * ```typescript
427
+ * const groups = await signal.getGroupsWithDetails();
428
+ * groups.forEach(g => {
429
+ * console.log(`${g.name}: ${g.members.length} members, ${g.pendingMembers.length} pending`);
430
+ * });
431
+ * ```
432
+ */
433
+ getGroupsWithDetails(options?: ListGroupsOptions): Promise<GroupInfo[]>;
135
434
  }