sauruspro-bail 0.0.0-stage → 5.0.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 (160) hide show
  1. package/README.md +128 -2
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +6754 -0
  4. package/WAProto/fix-imports.js +85 -0
  5. package/WAProto/index.d.ts +79257 -0
  6. package/WAProto/index.js +242946 -0
  7. package/docs/CHANGELOG.md +43 -0
  8. package/docs/NEWSLETTER-STATUS.md +120 -0
  9. package/docs/SPR.md +51 -0
  10. package/engine-requirements.js +10 -0
  11. package/lib/Defaults/index.js +135 -0
  12. package/lib/Signal/Group/ciphertext-message.js +12 -0
  13. package/lib/Signal/Group/group-session-builder.js +30 -0
  14. package/lib/Signal/Group/group_cipher.js +82 -0
  15. package/lib/Signal/Group/index.js +12 -0
  16. package/lib/Signal/Group/keyhelper.js +18 -0
  17. package/lib/Signal/Group/sender-chain-key.js +26 -0
  18. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  19. package/lib/Signal/Group/sender-key-message.js +66 -0
  20. package/lib/Signal/Group/sender-key-name.js +48 -0
  21. package/lib/Signal/Group/sender-key-record.js +41 -0
  22. package/lib/Signal/Group/sender-key-state.js +84 -0
  23. package/lib/Signal/Group/sender-message-key.js +26 -0
  24. package/lib/Signal/libsignal.js +431 -0
  25. package/lib/Signal/lid-mapping.js +277 -0
  26. package/lib/Socket/Client/index.js +3 -0
  27. package/lib/Socket/Client/types.js +11 -0
  28. package/lib/Socket/Client/websocket.js +54 -0
  29. package/lib/Socket/MessageBuilder.js +3729 -0
  30. package/lib/Socket/business.js +379 -0
  31. package/lib/Socket/chats.js +1198 -0
  32. package/lib/Socket/communities.js +431 -0
  33. package/lib/Socket/dinonic-handler.d.ts +27 -0
  34. package/lib/Socket/dinonic-handler.js +882 -0
  35. package/lib/Socket/graphql.js +716 -0
  36. package/lib/Socket/groups.js +374 -0
  37. package/lib/Socket/index.js +96 -0
  38. package/lib/Socket/interop.js +463 -0
  39. package/lib/Socket/luxu.js +387 -0
  40. package/lib/Socket/message-builder.js +556 -0
  41. package/lib/Socket/messages-recv.js +1942 -0
  42. package/lib/Socket/messages-send.js +1541 -0
  43. package/lib/Socket/mex.js +54 -0
  44. package/lib/Socket/newsletter.js +641 -0
  45. package/lib/Socket/privacy.js +318 -0
  46. package/lib/Socket/socket.js +1115 -0
  47. package/lib/Socket/username.js +236 -0
  48. package/lib/Store/index.js +10 -0
  49. package/lib/Store/keyed-db.js +108 -0
  50. package/lib/Store/make-cache-manager-store.js +85 -0
  51. package/lib/Store/make-in-memory-store.js +244 -0
  52. package/lib/Store/make-ordered-dictionary.js +75 -0
  53. package/lib/Store/object-repository.js +32 -0
  54. package/lib/Types/Auth.js +2 -0
  55. package/lib/Types/Bussines.js +2 -0
  56. package/lib/Types/Call.js +2 -0
  57. package/lib/Types/Chat.js +8 -0
  58. package/lib/Types/Contact.js +2 -0
  59. package/lib/Types/Events.js +2 -0
  60. package/lib/Types/GroupMetadata.js +2 -0
  61. package/lib/Types/Label.js +25 -0
  62. package/lib/Types/LabelAssociation.js +7 -0
  63. package/lib/Types/Message.js +11 -0
  64. package/lib/Types/Mex.js +111 -0
  65. package/lib/Types/Product.js +2 -0
  66. package/lib/Types/Signal.js +2 -0
  67. package/lib/Types/Socket.js +3 -0
  68. package/lib/Types/State.js +56 -0
  69. package/lib/Types/USync.js +2 -0
  70. package/lib/Types/index.js +26 -0
  71. package/lib/Utils/MessageBuilder.d.ts +215 -0
  72. package/lib/Utils/MessageBuilder.js +3991 -0
  73. package/lib/Utils/a2ui.d.ts +202 -0
  74. package/lib/Utils/a2ui.js +732 -0
  75. package/lib/Utils/airich-registry.js +3 -0
  76. package/lib/Utils/auth-utils.js +302 -0
  77. package/lib/Utils/baileys-event-stream.js +58 -0
  78. package/lib/Utils/bot-signature.d.ts +22 -0
  79. package/lib/Utils/bot-signature.js +124 -0
  80. package/lib/Utils/browser-utils.js +48 -0
  81. package/lib/Utils/business.js +231 -0
  82. package/lib/Utils/chat-utils.js +872 -0
  83. package/lib/Utils/companion-reg-client-utils.js +35 -0
  84. package/lib/Utils/crypto.js +118 -0
  85. package/lib/Utils/decode-wa-message.js +350 -0
  86. package/lib/Utils/dinonic-spr.d.ts +26 -0
  87. package/lib/Utils/dinonic-spr.js +521 -0
  88. package/lib/Utils/event-buffer.js +622 -0
  89. package/lib/Utils/extras.d.ts +449 -0
  90. package/lib/Utils/extras.js +1377 -0
  91. package/lib/Utils/generics.js +403 -0
  92. package/lib/Utils/history.js +134 -0
  93. package/lib/Utils/html-app.d.ts +39 -0
  94. package/lib/Utils/html-app.js +291 -0
  95. package/lib/Utils/identity-change-handler.js +50 -0
  96. package/lib/Utils/index.js +38 -0
  97. package/lib/Utils/link-preview.js +85 -0
  98. package/lib/Utils/logger.js +3 -0
  99. package/lib/Utils/lt-hash.js +8 -0
  100. package/lib/Utils/make-mutex.js +33 -0
  101. package/lib/Utils/message-composer.js +273 -0
  102. package/lib/Utils/message-retry-manager.js +265 -0
  103. package/lib/Utils/messages-media.js +870 -0
  104. package/lib/Utils/messages.js +1394 -0
  105. package/lib/Utils/metaai.d.ts +438 -0
  106. package/lib/Utils/metaai.js +911 -0
  107. package/lib/Utils/modern-messages.d.ts +150 -0
  108. package/lib/Utils/modern-messages.js +496 -0
  109. package/lib/Utils/native-flow.d.ts +14 -0
  110. package/lib/Utils/native-flow.js +118 -0
  111. package/lib/Utils/newsletter-status.d.ts +163 -0
  112. package/lib/Utils/newsletter-status.js +694 -0
  113. package/lib/Utils/noise-handler.js +201 -0
  114. package/lib/Utils/offline-node-processor.js +40 -0
  115. package/lib/Utils/payment-messages.d.ts +59 -0
  116. package/lib/Utils/payment-messages.js +156 -0
  117. package/lib/Utils/pre-key-manager.js +106 -0
  118. package/lib/Utils/process-message.js +630 -0
  119. package/lib/Utils/reporting-utils.js +258 -0
  120. package/lib/Utils/scheduled-message.d.ts +82 -0
  121. package/lib/Utils/scheduled-message.js +113 -0
  122. package/lib/Utils/signal.js +201 -0
  123. package/lib/Utils/stanza-ack.js +38 -0
  124. package/lib/Utils/status-stickers.d.ts +78 -0
  125. package/lib/Utils/status-stickers.js +261 -0
  126. package/lib/Utils/sticker.js +133 -0
  127. package/lib/Utils/sync-action-utils.js +49 -0
  128. package/lib/Utils/tc-token-utils.js +163 -0
  129. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  130. package/lib/Utils/use-sqlite-auth-state.js +162 -0
  131. package/lib/Utils/validate-connection.js +203 -0
  132. package/lib/WABinary/constants.js +1301 -0
  133. package/lib/WABinary/decode.js +262 -0
  134. package/lib/WABinary/encode.js +220 -0
  135. package/lib/WABinary/generic-utils.js +204 -0
  136. package/lib/WABinary/index.js +6 -0
  137. package/lib/WABinary/jid-utils.js +98 -0
  138. package/lib/WABinary/types.js +2 -0
  139. package/lib/WAM/BinaryInfo.js +10 -0
  140. package/lib/WAM/constants.js +22853 -0
  141. package/lib/WAM/encode.js +150 -0
  142. package/lib/WAM/index.js +4 -0
  143. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
  144. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  145. package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
  146. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  147. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  148. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +58 -0
  149. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  150. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  151. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +28 -0
  152. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
  153. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  154. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
  155. package/lib/WAUSync/Protocols/index.js +12 -0
  156. package/lib/WAUSync/USyncQuery.js +151 -0
  157. package/lib/WAUSync/USyncUser.js +56 -0
  158. package/lib/WAUSync/index.js +3 -0
  159. package/lib/index.js +67 -0
  160. package/package.json +147 -5
@@ -0,0 +1,66 @@
1
+ import { calculateSignature, verifySignature } from 'libsignal/src/curve.js';
2
+ import { proto } from '../../../WAProto/index.js';
3
+ import { CiphertextMessage } from './ciphertext-message.js';
4
+ export class SenderKeyMessage extends CiphertextMessage {
5
+ constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
6
+ super();
7
+ this.SIGNATURE_LENGTH = 64;
8
+ if (serialized) {
9
+ const version = serialized[0];
10
+ const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
11
+ const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
12
+ const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
13
+ this.serialized = serialized;
14
+ this.messageVersion = (version & 0xff) >> 4;
15
+ this.keyId = senderKeyMessage.id;
16
+ this.iteration = senderKeyMessage.iteration;
17
+ this.ciphertext =
18
+ typeof senderKeyMessage.ciphertext === 'string'
19
+ ? Buffer.from(senderKeyMessage.ciphertext, 'base64')
20
+ : senderKeyMessage.ciphertext;
21
+ this.signature = signature;
22
+ }
23
+ else {
24
+ const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
25
+ const ciphertextBuffer = Buffer.from(ciphertext);
26
+ const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
27
+ id: keyId,
28
+ iteration: iteration,
29
+ ciphertext: ciphertextBuffer
30
+ })).finish();
31
+ const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
32
+ this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
33
+ this.messageVersion = this.CURRENT_VERSION;
34
+ this.keyId = keyId;
35
+ this.iteration = iteration;
36
+ this.ciphertext = ciphertextBuffer;
37
+ this.signature = signature;
38
+ }
39
+ }
40
+ getKeyId() {
41
+ return this.keyId;
42
+ }
43
+ getIteration() {
44
+ return this.iteration;
45
+ }
46
+ getCipherText() {
47
+ return this.ciphertext;
48
+ }
49
+ verifySignature(signatureKey) {
50
+ const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
51
+ const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
52
+ const res = verifySignature(signatureKey, part1, part2);
53
+ if (!res)
54
+ throw new Error('Invalid signature!');
55
+ }
56
+ getSignature(signatureKey, serialized) {
57
+ return Buffer.from(calculateSignature(signatureKey, serialized));
58
+ }
59
+ serialize() {
60
+ return this.serialized;
61
+ }
62
+ getType() {
63
+ return 4;
64
+ }
65
+ }
66
+ //# sourceMappingURL=sender-key-message.js.map
@@ -0,0 +1,48 @@
1
+ function isNull(str) {
2
+ return str === null || str === '';
3
+ }
4
+ function intValue(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;
11
+ }
12
+ function hashCode(strKey) {
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;
21
+ }
22
+ export class SenderKeyName {
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
+ }
47
+ }
48
+ //# sourceMappingURL=sender-key-name.js.map
@@ -0,0 +1,41 @@
1
+ import { BufferJSON } from '../../Utils/generics.js';
2
+ import { SenderKeyState } from './sender-key-state.js';
3
+ export class SenderKeyRecord {
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
+ }
12
+ }
13
+ isEmpty() {
14
+ return this.senderKeyStates.length === 0;
15
+ }
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);
39
+ }
40
+ }
41
+ //# sourceMappingURL=sender-key-record.js.map
@@ -0,0 +1,84 @@
1
+ import { SenderChainKey } from './sender-chain-key.js';
2
+ import { SenderMessageKey } from './sender-message-key.js';
3
+ export class SenderKeyState {
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
+ }
32
+ }
33
+ getKeyId() {
34
+ return this.senderKeyStateStructure.senderKeyId;
35
+ }
36
+ getSenderChainKey() {
37
+ return new SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
38
+ }
39
+ setSenderChainKey(chainKey) {
40
+ this.senderKeyStateStructure.senderChainKey = {
41
+ iteration: chainKey.getIteration(),
42
+ seed: chainKey.getSeed()
43
+ };
44
+ }
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;
82
+ }
83
+ }
84
+ //# sourceMappingURL=sender-key-state.js.map
@@ -0,0 +1,26 @@
1
+ import { deriveSecrets } from 'libsignal/src/crypto.js';
2
+ export class SenderMessageKey {
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
+ }
25
+ }
26
+ //# sourceMappingURL=sender-message-key.js.map