@rizzxdc/baileys 8.0.10 → 8.1.0

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 (220) hide show
  1. package/LICENSE +4 -2
  2. package/README.md +107 -245
  3. package/WAProto/index.d.ts +15795 -0
  4. package/WAProto/index.js +25587 -4867
  5. package/lib/Defaults/index.d.ts +147 -0
  6. package/lib/Defaults/index.js +134 -104
  7. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  8. package/lib/Signal/Group/ciphertext-message.js +9 -11
  9. package/lib/Signal/Group/group-session-builder.d.ts +8 -0
  10. package/lib/Signal/Group/group-session-builder.js +5 -8
  11. package/lib/Signal/Group/group_cipher.d.ts +11 -0
  12. package/lib/Signal/Group/group_cipher.js +72 -75
  13. package/lib/Signal/Group/index.d.ts +12 -0
  14. package/lib/Signal/Group/index.js +11 -13
  15. package/lib/Signal/Group/keyhelper.d.ts +7 -0
  16. package/lib/Signal/Group/keyhelper.js +11 -14
  17. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  18. package/lib/Signal/Group/sender-chain-key.js +23 -26
  19. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  20. package/lib/Signal/Group/sender-key-distribution-message.js +58 -61
  21. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  22. package/lib/Signal/Group/sender-key-message.js +61 -64
  23. package/lib/Signal/Group/sender-key-name.d.ts +12 -0
  24. package/lib/Signal/Group/sender-key-name.js +39 -44
  25. package/lib/Signal/Group/sender-key-record.d.ts +13 -0
  26. package/lib/Signal/Group/sender-key-record.js +35 -38
  27. package/lib/Signal/Group/sender-key-state.d.ts +17 -0
  28. package/lib/Signal/Group/sender-key-state.js +76 -79
  29. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  30. package/lib/Signal/Group/sender-message-key.js +23 -26
  31. package/lib/Signal/libsignal.d.ts +55 -0
  32. package/lib/Signal/libsignal.js +414 -308
  33. package/lib/Signal/lid-mapping.d.ts +21 -0
  34. package/lib/Signal/lid-mapping.js +270 -149
  35. package/lib/Socket/Client/index.d.ts +3 -0
  36. package/lib/Socket/Client/index.js +2 -4
  37. package/lib/Socket/Client/types.d.ts +6 -0
  38. package/lib/Socket/Client/types.js +8 -11
  39. package/lib/Socket/Client/websocket.d.ts +13 -0
  40. package/lib/Socket/Client/websocket.js +51 -50
  41. package/lib/Socket/business.d.ts +395 -0
  42. package/lib/Socket/business.js +357 -355
  43. package/lib/Socket/chats.d.ts +137 -0
  44. package/lib/Socket/chats.js +1195 -867
  45. package/lib/Socket/communities.d.ts +562 -0
  46. package/lib/Socket/communities.js +416 -398
  47. package/lib/Socket/dugong.js +8 -1
  48. package/lib/Socket/groups.d.ts +286 -0
  49. package/lib/Socket/groups.js +336 -301
  50. package/lib/Socket/index.d.ts +530 -0
  51. package/lib/Socket/index.js +8 -13
  52. package/lib/Socket/messages-recv.d.ts +334 -0
  53. package/lib/Socket/messages-recv.js +1729 -1121
  54. package/lib/Socket/messages-send.d.ts +330 -0
  55. package/lib/Socket/messages-send.js +684 -462
  56. package/lib/Socket/mex.d.ts +2 -0
  57. package/lib/Socket/mex.js +36 -40
  58. package/lib/Socket/newsletter.d.ts +284 -0
  59. package/lib/Socket/newsletter.js +247 -237
  60. package/lib/Socket/socket.d.ts +61 -0
  61. package/lib/Socket/socket.js +968 -790
  62. package/lib/Store/index.d.ts +4 -0
  63. package/lib/Store/index.js +4 -6
  64. package/lib/Store/make-cache-manager-store.js +2 -2
  65. package/lib/Store/make-in-memory-store.d.ts +63 -0
  66. package/lib/Store/make-in-memory-store.js +414 -284
  67. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  68. package/lib/Store/make-ordered-dictionary.js +75 -76
  69. package/lib/Store/object-repository.d.ts +11 -0
  70. package/lib/Store/object-repository.js +21 -23
  71. package/lib/Types/Auth.d.ts +2 -0
  72. package/lib/Types/Auth.js +0 -2
  73. package/lib/Types/Bussines.d.ts +2 -0
  74. package/lib/Types/Bussines.js +0 -2
  75. package/lib/Types/Call.d.ts +2 -0
  76. package/lib/Types/Call.js +0 -2
  77. package/lib/Types/Chat.d.ts +2 -0
  78. package/lib/Types/Chat.js +5 -7
  79. package/lib/Types/Contact.d.ts +2 -0
  80. package/lib/Types/Contact.js +0 -2
  81. package/lib/Types/Events.d.ts +2 -0
  82. package/lib/Types/Events.js +1 -3
  83. package/lib/Types/GroupMetadata.d.ts +2 -0
  84. package/lib/Types/GroupMetadata.js +0 -2
  85. package/lib/Types/Label.d.ts +3 -0
  86. package/lib/Types/Label.js +21 -22
  87. package/lib/Types/LabelAssociation.d.ts +3 -0
  88. package/lib/Types/LabelAssociation.js +3 -4
  89. package/lib/Types/Message.d.ts +12 -0
  90. package/lib/Types/Message.js +11 -6
  91. package/lib/Types/Mex.d.ts +3 -0
  92. package/lib/Types/Mex.js +38 -0
  93. package/lib/Types/Product.d.ts +2 -0
  94. package/lib/Types/Product.js +0 -2
  95. package/lib/Types/RichType.d.ts +3 -0
  96. package/lib/Types/RichType.js +22 -0
  97. package/lib/Types/Signal.d.ts +2 -0
  98. package/lib/Types/Signal.js +1 -3
  99. package/lib/Types/Socket.d.ts +2 -0
  100. package/lib/Types/Socket.js +1 -4
  101. package/lib/Types/State.d.ts +6 -0
  102. package/lib/Types/State.js +52 -8
  103. package/lib/Types/USync.d.ts +2 -0
  104. package/lib/Types/USync.js +1 -3
  105. package/lib/Types/index.d.ts +14 -0
  106. package/lib/Types/index.js +22 -25
  107. package/lib/Utils/auth-utils.d.ts +58 -0
  108. package/lib/Utils/auth-utils.js +285 -203
  109. package/lib/Utils/browser-utils.d.ts +9 -0
  110. package/lib/Utils/browser-utils.js +21 -19
  111. package/lib/Utils/business.d.ts +50 -0
  112. package/lib/Utils/business.js +206 -209
  113. package/lib/Utils/chat-utils.d.ts +409 -0
  114. package/lib/Utils/chat-utils.js +825 -706
  115. package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
  116. package/lib/Utils/companion-reg-client-utils.js +39 -0
  117. package/lib/Utils/crypto.d.ts +40 -0
  118. package/lib/Utils/crypto.js +88 -101
  119. package/lib/Utils/decode-wa-message.d.ts +84 -0
  120. package/lib/Utils/decode-wa-message.js +287 -238
  121. package/lib/Utils/event-buffer.d.ts +13 -0
  122. package/lib/Utils/event-buffer.js +602 -509
  123. package/lib/Utils/generics.d.ts +64 -0
  124. package/lib/Utils/generics.js +334 -295
  125. package/lib/Utils/history.d.ts +76 -0
  126. package/lib/Utils/history.js +125 -79
  127. package/lib/Utils/identity-change-handler.d.ts +14 -0
  128. package/lib/Utils/identity-change-handler.js +49 -0
  129. package/lib/Utils/index.d.ts +25 -0
  130. package/lib/Utils/index.js +25 -21
  131. package/lib/Utils/link-preview.d.ts +13 -0
  132. package/lib/Utils/link-preview.js +73 -70
  133. package/lib/Utils/logger.d.ts +3 -0
  134. package/lib/Utils/logger.js +1 -4
  135. package/lib/Utils/lt-hash.d.ts +7 -0
  136. package/lib/Utils/lt-hash.js +7 -45
  137. package/lib/Utils/make-mutex.d.ts +7 -0
  138. package/lib/Utils/make-mutex.js +27 -31
  139. package/lib/Utils/message-retry-manager.d.ts +80 -0
  140. package/lib/Utils/message-retry-manager.js +165 -14
  141. package/lib/Utils/messages-media.d.ts +137 -0
  142. package/lib/Utils/messages-media.js +768 -572
  143. package/lib/Utils/messages.d.ts +46 -0
  144. package/lib/Utils/messages.js +1082 -130
  145. package/lib/Utils/noise-handler.d.ts +21 -0
  146. package/lib/Utils/noise-handler.js +191 -135
  147. package/lib/Utils/offline-node-processor.d.ts +10 -0
  148. package/lib/Utils/offline-node-processor.js +39 -0
  149. package/lib/Utils/pre-key-manager.d.ts +26 -0
  150. package/lib/Utils/pre-key-manager.js +96 -76
  151. package/lib/Utils/process-message.d.ts +84 -0
  152. package/lib/Utils/process-message.js +718 -311
  153. package/lib/Utils/reporting-utils.d.ts +13 -0
  154. package/lib/Utils/reporting-utils.js +257 -0
  155. package/lib/Utils/rich-message-utils.d.ts +49 -0
  156. package/lib/Utils/rich-message-utils.js +257 -0
  157. package/lib/Utils/signal.d.ts +83 -0
  158. package/lib/Utils/signal.js +174 -135
  159. package/lib/Utils/stanza-ack.d.ts +17 -0
  160. package/lib/Utils/stanza-ack.js +37 -0
  161. package/lib/Utils/sync-action-utils.d.ts +3 -0
  162. package/lib/Utils/sync-action-utils.js +48 -0
  163. package/lib/Utils/tc-token-utils.d.ts +30 -0
  164. package/lib/Utils/tc-token-utils.js +162 -0
  165. package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
  166. package/lib/Utils/use-multi-file-auth-state.js +104 -95
  167. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  168. package/lib/Utils/use-single-file-auth-state.js +108 -0
  169. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  170. package/lib/Utils/use-sqlite-auth-state.js +108 -0
  171. package/lib/Utils/validate-connection.d.ts +44 -0
  172. package/lib/Utils/validate-connection.js +182 -180
  173. package/lib/WABinary/constants.d.ts +62 -0
  174. package/lib/WABinary/constants.js +1455 -1292
  175. package/lib/WABinary/decode.d.ts +10 -0
  176. package/lib/WABinary/decode.js +249 -228
  177. package/lib/WABinary/encode.d.ts +3 -0
  178. package/lib/WABinary/encode.js +207 -206
  179. package/lib/WABinary/generic-utils.d.ts +77 -0
  180. package/lib/WABinary/generic-utils.js +135 -99
  181. package/lib/WABinary/index.d.ts +6 -0
  182. package/lib/WABinary/index.js +5 -7
  183. package/lib/WABinary/jid-utils.d.ts +29 -0
  184. package/lib/WABinary/jid-utils.js +80 -78
  185. package/lib/WABinary/types.d.ts +2 -0
  186. package/lib/WABinary/types.js +1 -3
  187. package/lib/WAM/BinaryInfo.d.ts +8 -0
  188. package/lib/WAM/BinaryInfo.js +7 -9
  189. package/lib/WAM/constants.d.ts +34927 -0
  190. package/lib/WAM/constants.js +22847 -22848
  191. package/lib/WAM/encode.d.ts +2 -0
  192. package/lib/WAM/encode.js +129 -134
  193. package/lib/WAM/index.d.ts +4 -0
  194. package/lib/WAM/index.js +3 -5
  195. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
  196. package/lib/WAUSync/Protocols/USyncContactProtocol.js +48 -27
  197. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  198. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -48
  199. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  200. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -26
  201. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  202. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -35
  203. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  204. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  205. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  206. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +46 -49
  207. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
  208. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +23 -25
  209. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  210. package/lib/WAUSync/Protocols/index.js +5 -6
  211. package/lib/WAUSync/USyncQuery.d.ts +21 -0
  212. package/lib/WAUSync/USyncQuery.js +92 -85
  213. package/lib/WAUSync/USyncUser.d.ts +17 -0
  214. package/lib/WAUSync/USyncUser.js +28 -22
  215. package/lib/WAUSync/index.d.ts +4 -0
  216. package/lib/WAUSync/index.js +3 -5
  217. package/lib/index.d.ts +12 -0
  218. package/lib/index.js +31 -19
  219. package/package.json +12 -6
  220. package/lib/Types/Newsletter.js +0 -33
@@ -1,52 +1,47 @@
1
- //=======================================================//
2
1
  function isNull(str) {
3
- return str === null || str === "";
2
+ return str === null || str === '';
4
3
  }
5
- //=======================================================//
6
4
  function intValue(num) {
7
- const MAX_VALUE = 0x7fffffff;
8
- const MIN_VALUE = -0x80000000;
9
- if (num > MAX_VALUE || num < MIN_VALUE) {
10
- return num & 0xffffffff;
11
- }
12
- return num;
5
+ const MAX_VALUE = 0x7fffffff;
6
+ const MIN_VALUE = -0x80000000;
7
+ if (num > MAX_VALUE || num < MIN_VALUE) {
8
+ return num & 0xffffffff;
9
+ }
10
+ return num;
13
11
  }
14
- //=======================================================//
15
12
  function hashCode(strKey) {
16
- let hash = 0;
17
- if (!isNull(strKey)) {
18
- for (let i = 0; i < strKey.length; i++) {
19
- hash = hash * 31 + strKey.charCodeAt(i);
20
- hash = intValue(hash);
21
- }
22
- }
23
- return hash;
13
+ let hash = 0;
14
+ if (!isNull(strKey)) {
15
+ for (let i = 0; i < strKey.length; i++) {
16
+ hash = hash * 31 + strKey.charCodeAt(i);
17
+ hash = intValue(hash);
18
+ }
19
+ }
20
+ return hash;
24
21
  }
25
- //=======================================================//
26
22
  export class SenderKeyName {
27
- constructor(groupId, sender) {
28
- this.groupId = groupId;
29
- this.sender = sender;
30
- }
31
- getGroupId() {
32
- return this.groupId;
33
- }
34
- getSender() {
35
- return this.sender;
36
- }
37
- serialize() {
38
- return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
39
- }
40
- toString() {
41
- return this.serialize();
42
- }
43
- equals(other) {
44
- if (other === null)
45
- return false;
46
- return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
47
- }
48
- hashCode() {
49
- return hashCode(this.groupId) ^ hashCode(this.sender.toString());
50
- }
23
+ constructor(groupId, sender) {
24
+ this.groupId = groupId;
25
+ this.sender = sender;
26
+ }
27
+ getGroupId() {
28
+ return this.groupId;
29
+ }
30
+ getSender() {
31
+ return this.sender;
32
+ }
33
+ serialize() {
34
+ return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
35
+ }
36
+ toString() {
37
+ return this.serialize();
38
+ }
39
+ equals(other) {
40
+ if (other === null)
41
+ return false;
42
+ return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
43
+ }
44
+ hashCode() {
45
+ return hashCode(this.groupId) ^ hashCode(this.sender.toString());
46
+ }
51
47
  }
52
- //=======================================================//
@@ -0,0 +1,13 @@
1
+ export class SenderKeyRecord {
2
+ static deserialize(data: any): SenderKeyRecord;
3
+ constructor(serialized: any);
4
+ MAX_STATES: number;
5
+ senderKeyStates: SenderKeyState[];
6
+ isEmpty(): boolean;
7
+ getSenderKeyState(keyId: any): SenderKeyState | undefined;
8
+ addSenderKeyState(id: any, iteration: any, chainKey: any, signatureKey: any): void;
9
+ setSenderKeyState(id: any, iteration: any, chainKey: any, keyPair: any): void;
10
+ serialize(): any[];
11
+ }
12
+ import { SenderKeyState } from './sender-key-state.js';
13
+ //# sourceMappingURL=sender-key-record.d.ts.map
@@ -1,43 +1,40 @@
1
- //=======================================================//
2
- import { SenderKeyState } from "./sender-key-state.js";
3
- import { BufferJSON } from "../../Utils/generics.js";
4
- //=======================================================//
1
+ import { BufferJSON } from '../../Utils/generics.js';
2
+ import { SenderKeyState } from './sender-key-state.js';
5
3
  export class SenderKeyRecord {
6
- constructor(serialized) {
7
- this.MAX_STATES = 5;
8
- this.senderKeyStates = [];
9
- if (serialized) {
10
- for (const structure of serialized) {
11
- this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure));
12
- }
4
+ constructor(serialized) {
5
+ this.MAX_STATES = 5;
6
+ this.senderKeyStates = [];
7
+ if (serialized) {
8
+ for (const structure of serialized) {
9
+ this.senderKeyStates.push(new SenderKeyState(null, null, null, null, null, null, structure));
10
+ }
11
+ }
13
12
  }
14
- }
15
- isEmpty() {
16
- return this.senderKeyStates.length === 0;
17
- }
18
- getSenderKeyState(keyId) {
19
- if (keyId === undefined && this.senderKeyStates.length) {
20
- return this.senderKeyStates[this.senderKeyStates.length - 1];
13
+ isEmpty() {
14
+ return this.senderKeyStates.length === 0;
21
15
  }
22
- return this.senderKeyStates.find(state => state.getKeyId() === keyId);
23
- }
24
- addSenderKeyState(id, iteration, chainKey, signatureKey) {
25
- this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey));
26
- if (this.senderKeyStates.length > this.MAX_STATES) {
27
- this.senderKeyStates.shift();
16
+ getSenderKeyState(keyId) {
17
+ if (keyId === undefined && this.senderKeyStates.length) {
18
+ return this.senderKeyStates[this.senderKeyStates.length - 1];
19
+ }
20
+ return this.senderKeyStates.find(state => state.getKeyId() === keyId);
21
+ }
22
+ addSenderKeyState(id, iteration, chainKey, signatureKey) {
23
+ this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, null, signatureKey));
24
+ if (this.senderKeyStates.length > this.MAX_STATES) {
25
+ this.senderKeyStates.shift();
26
+ }
27
+ }
28
+ setSenderKeyState(id, iteration, chainKey, keyPair) {
29
+ this.senderKeyStates.length = 0;
30
+ this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair));
31
+ }
32
+ serialize() {
33
+ return this.senderKeyStates.map(state => state.getStructure());
34
+ }
35
+ static deserialize(data) {
36
+ const str = Buffer.from(data).toString('utf-8');
37
+ const parsed = JSON.parse(str, BufferJSON.reviver);
38
+ return new SenderKeyRecord(parsed);
28
39
  }
29
- }
30
- setSenderKeyState(id, iteration, chainKey, keyPair) {
31
- this.senderKeyStates.length = 0;
32
- this.senderKeyStates.push(new SenderKeyState(id, iteration, chainKey, keyPair));
33
- }
34
- serialize() {
35
- return this.senderKeyStates.map(state => state.getStructure());
36
- }
37
- static deserialize(data) {
38
- const str = Buffer.from(data).toString("utf-8");
39
- const parsed = JSON.parse(str, BufferJSON.reviver);
40
- return new SenderKeyRecord(parsed);
41
- }
42
40
  }
43
- //=======================================================//
@@ -0,0 +1,17 @@
1
+ export class SenderKeyState {
2
+ constructor(id: any, iteration: any, chainKey: any, signatureKeyPair: any, signatureKeyPublic: any, signatureKeyPrivate: any, senderKeyStateStructure: any);
3
+ MAX_MESSAGE_KEYS: number;
4
+ senderKeyStateStructure: any;
5
+ getKeyId(): any;
6
+ getSenderChainKey(): SenderChainKey;
7
+ setSenderChainKey(chainKey: any): void;
8
+ getSigningKeyPublic(): any;
9
+ getSigningKeyPrivate(): any;
10
+ hasSenderMessageKey(iteration: any): any;
11
+ addSenderMessageKey(senderMessageKey: any): void;
12
+ removeSenderMessageKey(iteration: any): SenderMessageKey | null;
13
+ getStructure(): any;
14
+ }
15
+ import { SenderChainKey } from './sender-chain-key.js';
16
+ import { SenderMessageKey } from './sender-message-key.js';
17
+ //# sourceMappingURL=sender-key-state.d.ts.map
@@ -1,86 +1,83 @@
1
- //=======================================================//
2
- import { SenderMessageKey } from "./sender-message-key.js";
3
- import { SenderChainKey } from "./sender-chain-key.js";
4
- //=======================================================//
1
+ import { SenderChainKey } from './sender-chain-key.js';
2
+ import { SenderMessageKey } from './sender-message-key.js';
5
3
  export class SenderKeyState {
6
- constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
7
- this.MAX_MESSAGE_KEYS = 2000;
8
- if (senderKeyStateStructure) {
9
- this.senderKeyStateStructure = {
10
- ...senderKeyStateStructure,
11
- senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
12
- ? senderKeyStateStructure.senderMessageKeys
13
- : []
14
- };
4
+ constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
5
+ this.MAX_MESSAGE_KEYS = 2000;
6
+ if (senderKeyStateStructure) {
7
+ this.senderKeyStateStructure = {
8
+ ...senderKeyStateStructure,
9
+ senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys)
10
+ ? senderKeyStateStructure.senderMessageKeys
11
+ : []
12
+ };
13
+ }
14
+ else {
15
+ if (signatureKeyPair) {
16
+ signatureKeyPublic = signatureKeyPair.public;
17
+ signatureKeyPrivate = signatureKeyPair.private;
18
+ }
19
+ this.senderKeyStateStructure = {
20
+ senderKeyId: id || 0,
21
+ senderChainKey: {
22
+ iteration: iteration || 0,
23
+ seed: Buffer.from(chainKey || [])
24
+ },
25
+ senderSigningKey: {
26
+ public: Buffer.from(signatureKeyPublic || []),
27
+ private: Buffer.from(signatureKeyPrivate || [])
28
+ },
29
+ senderMessageKeys: []
30
+ };
31
+ }
15
32
  }
16
- else {
17
- if (signatureKeyPair) {
18
- signatureKeyPublic = signatureKeyPair.public;
19
- signatureKeyPrivate = signatureKeyPair.private;
20
- }
21
- this.senderKeyStateStructure = {
22
- senderKeyId: id || 0,
23
- senderChainKey: {
24
- iteration: iteration || 0,
25
- seed: Buffer.from(chainKey || [])
26
- },
27
- senderSigningKey: {
28
- public: Buffer.from(signatureKeyPublic || []),
29
- private: Buffer.from(signatureKeyPrivate || [])
30
- },
31
- senderMessageKeys: []
32
- };
33
+ getKeyId() {
34
+ return this.senderKeyStateStructure.senderKeyId;
33
35
  }
34
- }
35
- getKeyId() {
36
- return this.senderKeyStateStructure.senderKeyId;
37
- }
38
- getSenderChainKey() {
39
- return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
40
- }
41
- setSenderChainKey(chainKey) {
42
- this.senderKeyStateStructure.senderChainKey = {
43
- iteration: chainKey.getIteration(),
44
- seed: chainKey.getSeed()
45
- };
46
- }
47
- getSigningKeyPublic() {
48
- const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public);
49
- if (publicKey.length === 32) {
50
- const fixed = Buffer.alloc(33);
51
- fixed[0] = 0x05;
52
- publicKey.copy(fixed, 1);
53
- return fixed;
36
+ getSenderChainKey() {
37
+ return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
54
38
  }
55
- return publicKey;
56
- }
57
- getSigningKeyPrivate() {
58
- const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
59
- return Buffer.from(privateKey || []);
60
- }
61
- hasSenderMessageKey(iteration) {
62
- return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
63
- }
64
- addSenderMessageKey(senderMessageKey) {
65
- this.senderKeyStateStructure.senderMessageKeys.push({
66
- iteration: senderMessageKey.getIteration(),
67
- seed: senderMessageKey.getSeed()
68
- });
69
- if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
70
- this.senderKeyStateStructure.senderMessageKeys.shift();
39
+ setSenderChainKey(chainKey) {
40
+ this.senderKeyStateStructure.senderChainKey = {
41
+ iteration: chainKey.getIteration(),
42
+ seed: chainKey.getSeed()
43
+ };
71
44
  }
72
- }
73
- removeSenderMessageKey(iteration) {
74
- const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
75
- if (index !== -1) {
76
- const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
77
- this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
78
- return new SenderMessageKey(messageKey.iteration, messageKey.seed);
45
+ getSigningKeyPublic() {
46
+ const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public);
47
+ if (publicKey.length === 32) {
48
+ const fixed = Buffer.alloc(33);
49
+ fixed[0] = 0x05;
50
+ publicKey.copy(fixed, 1);
51
+ return fixed;
52
+ }
53
+ return publicKey;
54
+ }
55
+ getSigningKeyPrivate() {
56
+ const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
57
+ return Buffer.from(privateKey || []);
58
+ }
59
+ hasSenderMessageKey(iteration) {
60
+ return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
61
+ }
62
+ addSenderMessageKey(senderMessageKey) {
63
+ this.senderKeyStateStructure.senderMessageKeys.push({
64
+ iteration: senderMessageKey.getIteration(),
65
+ seed: senderMessageKey.getSeed()
66
+ });
67
+ if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
68
+ this.senderKeyStateStructure.senderMessageKeys.shift();
69
+ }
70
+ }
71
+ removeSenderMessageKey(iteration) {
72
+ const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
73
+ if (index !== -1) {
74
+ const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
75
+ this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
76
+ return new SenderMessageKey(messageKey.iteration, messageKey.seed);
77
+ }
78
+ return null;
79
+ }
80
+ getStructure() {
81
+ return this.senderKeyStateStructure;
79
82
  }
80
- return null;
81
- }
82
- getStructure() {
83
- return this.senderKeyStateStructure;
84
- }
85
83
  }
86
- //=======================================================//
@@ -0,0 +1,12 @@
1
+ export class SenderMessageKey {
2
+ constructor(iteration: any, seed: any);
3
+ iv: any;
4
+ cipherKey: any;
5
+ iteration: any;
6
+ seed: any;
7
+ getIteration(): any;
8
+ getIv(): any;
9
+ getCipherKey(): any;
10
+ getSeed(): any;
11
+ }
12
+ //# sourceMappingURL=sender-message-key.d.ts.map
@@ -1,28 +1,25 @@
1
- //=======================================================//
2
- import { deriveSecrets } from "@skycodee/libsignal/src/crypto.js";
3
- //=======================================================//
1
+ import { deriveSecrets } from 'libsignal/src/crypto.js';
4
2
  export class SenderMessageKey {
5
- constructor(iteration, seed) {
6
- const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from("WhisperGroup"));
7
- const keys = new Uint8Array(32);
8
- keys.set(new Uint8Array(derivative[0].slice(16)));
9
- keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
10
- this.iv = Buffer.from(derivative[0].slice(0, 16));
11
- this.cipherKey = Buffer.from(keys.buffer);
12
- this.iteration = iteration;
13
- this.seed = seed;
14
- }
15
- getIteration() {
16
- return this.iteration;
17
- }
18
- getIv() {
19
- return this.iv;
20
- }
21
- getCipherKey() {
22
- return this.cipherKey;
23
- }
24
- getSeed() {
25
- return this.seed;
26
- }
3
+ constructor(iteration, seed) {
4
+ const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
5
+ const keys = new Uint8Array(32);
6
+ keys.set(new Uint8Array(derivative[0].slice(16)));
7
+ keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
8
+ this.iv = Buffer.from(derivative[0].slice(0, 16));
9
+ this.cipherKey = Buffer.from(keys.buffer);
10
+ this.iteration = iteration;
11
+ this.seed = seed;
12
+ }
13
+ getIteration() {
14
+ return this.iteration;
15
+ }
16
+ getIv() {
17
+ return this.iv;
18
+ }
19
+ getCipherKey() {
20
+ return this.cipherKey;
21
+ }
22
+ getSeed() {
23
+ return this.seed;
24
+ }
27
25
  }
28
- //=======================================================//
@@ -0,0 +1,55 @@
1
+ export function makeLibSignalRepository(auth: any, logger: any, pnToLIDFunc: any): {
2
+ decryptGroupMessage({ group, authorJid, msg }: {
3
+ group: any;
4
+ authorJid: any;
5
+ msg: any;
6
+ }): any;
7
+ processSenderKeyDistributionMessage({ item, authorJid }: {
8
+ item: any;
9
+ authorJid: any;
10
+ }): Promise<any>;
11
+ decryptMessage({ jid, type, ciphertext }: {
12
+ jid: any;
13
+ type: any;
14
+ ciphertext: any;
15
+ }): Promise<any>;
16
+ encryptMessage({ jid, data }: {
17
+ jid: any;
18
+ data: any;
19
+ }): Promise<any>;
20
+ encryptGroupMessage({ group, meId, data }: {
21
+ group: any;
22
+ meId: any;
23
+ data: any;
24
+ }): Promise<any>;
25
+ getSenderKeyDistributionMessage({ group, meId }: {
26
+ group: any;
27
+ meId: any;
28
+ }): Promise<any>;
29
+ hasSenderKey({ group, meId }: {
30
+ group: any;
31
+ meId: any;
32
+ }): Promise<boolean>;
33
+ getSessionInfo(jid: any): Promise<{
34
+ baseKey: Uint8Array<any>;
35
+ registrationId: number;
36
+ } | null>;
37
+ injectE2ESession({ jid, session }: {
38
+ jid: any;
39
+ session: any;
40
+ }): Promise<any>;
41
+ jidToSignalProtocolAddress(jid: any): any;
42
+ lidMapping: LIDMappingStore;
43
+ validateSession(jid: any): Promise<{
44
+ exists: boolean;
45
+ reason: string;
46
+ } | {
47
+ exists: boolean;
48
+ reason?: undefined;
49
+ }>;
50
+ deleteSession(jids: any): Promise<any>;
51
+ close(): void;
52
+ migrateSession(fromJid: any, toJid: any): Promise<any>;
53
+ };
54
+ import { LIDMappingStore } from './lid-mapping.js';
55
+ //# sourceMappingURL=libsignal.d.ts.map