ell-bail 1.2.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 (198) hide show
  1. package/README.md +116 -0
  2. package/WAProto/index.js +130309 -0
  3. package/engine-requirements.js +11 -0
  4. package/lib/Defaults/baileys-version.json +3 -0
  5. package/lib/Defaults/index.d.ts +53 -0
  6. package/lib/Defaults/index.js +130 -0
  7. package/lib/Defaults/phonenumber-mcc.json +223 -0
  8. package/lib/KeyDB/BinarySearch.js +18 -0
  9. package/lib/KeyDB/KeyedDB.js +164 -0
  10. package/lib/KeyDB/index.js +2 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  12. package/lib/Signal/Group/ciphertext-message.js +15 -0
  13. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  14. package/lib/Signal/Group/group-session-builder.js +64 -0
  15. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  16. package/lib/Signal/Group/group_cipher.js +96 -0
  17. package/lib/Signal/Group/index.d.ts +11 -0
  18. package/lib/Signal/Group/index.js +57 -0
  19. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  20. package/lib/Signal/Group/keyhelper.js +55 -0
  21. package/lib/Signal/Group/queue-job.d.ts +1 -0
  22. package/lib/Signal/Group/queue-job.js +57 -0
  23. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  24. package/lib/Signal/Group/sender-chain-key.js +34 -0
  25. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  26. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  27. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  28. package/lib/Signal/Group/sender-key-message.js +69 -0
  29. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  30. package/lib/Signal/Group/sender-key-name.js +51 -0
  31. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  32. package/lib/Signal/Group/sender-key-record.js +53 -0
  33. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  34. package/lib/Signal/Group/sender-key-state.js +99 -0
  35. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  36. package/lib/Signal/Group/sender-message-key.js +29 -0
  37. package/lib/Signal/Group/x +1 -0
  38. package/lib/Signal/libsignal.d.ts +3 -0
  39. package/lib/Signal/libsignal.js +174 -0
  40. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  41. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  42. package/lib/Socket/Client/index.d.ts +3 -0
  43. package/lib/Socket/Client/index.js +19 -0
  44. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  45. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  46. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  47. package/lib/Socket/Client/web-socket-client.js +62 -0
  48. package/lib/Socket/business.d.ts +171 -0
  49. package/lib/Socket/business.js +260 -0
  50. package/lib/Socket/chats.d.ts +80 -0
  51. package/lib/Socket/chats.js +864 -0
  52. package/lib/Socket/groups.d.ts +115 -0
  53. package/lib/Socket/groups.js +316 -0
  54. package/lib/Socket/index.d.ts +173 -0
  55. package/lib/Socket/index.js +10 -0
  56. package/lib/Socket/luxu.d.ts +251 -0
  57. package/lib/Socket/luxu.js +550 -0
  58. package/lib/Socket/messages-recv.d.ts +161 -0
  59. package/lib/Socket/messages-recv.js +1152 -0
  60. package/lib/Socket/messages-send.d.ts +149 -0
  61. package/lib/Socket/messages-send.js +1002 -0
  62. package/lib/Socket/newsletter.d.ts +236 -0
  63. package/lib/Socket/newsletter.js +236 -0
  64. package/lib/Socket/registration.d.ts +268 -0
  65. package/lib/Socket/registration.js +789 -0
  66. package/lib/Socket/socket.d.ts +43 -0
  67. package/lib/Socket/socket.js +630 -0
  68. package/lib/Socket/usync.d.ts +36 -0
  69. package/lib/Socket/usync.js +70 -0
  70. package/lib/Store/index.d.ts +3 -0
  71. package/lib/Store/index.js +10 -0
  72. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  73. package/lib/Store/make-cache-manager-store.js +83 -0
  74. package/lib/Store/make-in-memory-store.d.ts +118 -0
  75. package/lib/Store/make-in-memory-store.js +427 -0
  76. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  77. package/lib/Store/make-ordered-dictionary.js +81 -0
  78. package/lib/Store/object-repository.d.ts +10 -0
  79. package/lib/Store/object-repository.js +27 -0
  80. package/lib/Types/Auth.d.ts +110 -0
  81. package/lib/Types/Auth.js +2 -0
  82. package/lib/Types/Call.d.ts +13 -0
  83. package/lib/Types/Call.js +2 -0
  84. package/lib/Types/Chat.d.ts +102 -0
  85. package/lib/Types/Chat.js +4 -0
  86. package/lib/Types/Contact.d.ts +19 -0
  87. package/lib/Types/Contact.js +2 -0
  88. package/lib/Types/Events.d.ts +157 -0
  89. package/lib/Types/Events.js +2 -0
  90. package/lib/Types/GroupMetadata.d.ts +55 -0
  91. package/lib/Types/GroupMetadata.js +2 -0
  92. package/lib/Types/Label.d.ts +35 -0
  93. package/lib/Types/Label.js +27 -0
  94. package/lib/Types/LabelAssociation.d.ts +29 -0
  95. package/lib/Types/LabelAssociation.js +9 -0
  96. package/lib/Types/Message.d.ts +273 -0
  97. package/lib/Types/Message.js +9 -0
  98. package/lib/Types/Newsletter.d.ts +92 -0
  99. package/lib/Types/Newsletter.js +32 -0
  100. package/lib/Types/Product.d.ts +78 -0
  101. package/lib/Types/Product.js +2 -0
  102. package/lib/Types/Signal.d.ts +57 -0
  103. package/lib/Types/Signal.js +2 -0
  104. package/lib/Types/Socket.d.ts +111 -0
  105. package/lib/Types/Socket.js +2 -0
  106. package/lib/Types/State.d.ts +27 -0
  107. package/lib/Types/State.js +2 -0
  108. package/lib/Types/USync.d.ts +25 -0
  109. package/lib/Types/USync.js +2 -0
  110. package/lib/Types/index.d.ts +57 -0
  111. package/lib/Types/index.js +42 -0
  112. package/lib/Utils/auth-utils.d.ts +18 -0
  113. package/lib/Utils/auth-utils.js +211 -0
  114. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  115. package/lib/Utils/baileys-event-stream.js +63 -0
  116. package/lib/Utils/business.d.ts +22 -0
  117. package/lib/Utils/business.js +234 -0
  118. package/lib/Utils/chat-utils.d.ts +71 -0
  119. package/lib/Utils/chat-utils.js +729 -0
  120. package/lib/Utils/crypto.d.ts +41 -0
  121. package/lib/Utils/crypto.js +168 -0
  122. package/lib/Utils/decode-wa-message.d.ts +19 -0
  123. package/lib/Utils/decode-wa-message.js +198 -0
  124. package/lib/Utils/event-buffer.d.ts +35 -0
  125. package/lib/Utils/event-buffer.js +514 -0
  126. package/lib/Utils/generics.d.ts +93 -0
  127. package/lib/Utils/generics.js +397 -0
  128. package/lib/Utils/history.d.ts +15 -0
  129. package/lib/Utils/history.js +96 -0
  130. package/lib/Utils/index.d.ts +17 -0
  131. package/lib/Utils/index.js +33 -0
  132. package/lib/Utils/link-preview.d.ts +21 -0
  133. package/lib/Utils/link-preview.js +93 -0
  134. package/lib/Utils/logger.d.ts +4 -0
  135. package/lib/Utils/logger.js +7 -0
  136. package/lib/Utils/lt-hash.d.ts +12 -0
  137. package/lib/Utils/lt-hash.js +51 -0
  138. package/lib/Utils/make-mutex.d.ts +7 -0
  139. package/lib/Utils/make-mutex.js +43 -0
  140. package/lib/Utils/messages-media.d.ts +116 -0
  141. package/lib/Utils/messages-media.js +731 -0
  142. package/lib/Utils/messages.d.ts +77 -0
  143. package/lib/Utils/messages.js +775 -0
  144. package/lib/Utils/noise-handler.d.ts +21 -0
  145. package/lib/Utils/noise-handler.js +155 -0
  146. package/lib/Utils/process-message.d.ts +41 -0
  147. package/lib/Utils/process-message.js +321 -0
  148. package/lib/Utils/signal.d.ts +32 -0
  149. package/lib/Utils/signal.js +153 -0
  150. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  151. package/lib/Utils/use-multi-file-auth-state.js +80 -0
  152. package/lib/Utils/validate-connection.d.ts +11 -0
  153. package/lib/Utils/validate-connection.js +205 -0
  154. package/lib/WABinary/constants.d.ts +27 -0
  155. package/lib/WABinary/constants.js +40 -0
  156. package/lib/WABinary/decode.d.ts +7 -0
  157. package/lib/WABinary/decode.js +252 -0
  158. package/lib/WABinary/encode.d.ts +3 -0
  159. package/lib/WABinary/encode.js +228 -0
  160. package/lib/WABinary/generic-utils.d.ts +16 -0
  161. package/lib/WABinary/generic-utils.js +198 -0
  162. package/lib/WABinary/index.d.ts +5 -0
  163. package/lib/WABinary/index.js +21 -0
  164. package/lib/WABinary/jid-utils.d.ts +31 -0
  165. package/lib/WABinary/jid-utils.js +62 -0
  166. package/lib/WABinary/types.d.ts +18 -0
  167. package/lib/WABinary/types.js +2 -0
  168. package/lib/WAM/BinaryInfo.d.ts +17 -0
  169. package/lib/WAM/BinaryInfo.js +13 -0
  170. package/lib/WAM/constants.d.ts +38 -0
  171. package/lib/WAM/constants.js +15350 -0
  172. package/lib/WAM/encode.d.ts +3 -0
  173. package/lib/WAM/encode.js +155 -0
  174. package/lib/WAM/index.d.ts +3 -0
  175. package/lib/WAM/index.js +19 -0
  176. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  177. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  178. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  179. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  180. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  181. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  182. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  183. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  184. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  185. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  186. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  187. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  188. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  189. package/lib/WAUSync/Protocols/index.js +20 -0
  190. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  191. package/lib/WAUSync/USyncQuery.js +89 -0
  192. package/lib/WAUSync/USyncUser.d.ts +12 -0
  193. package/lib/WAUSync/USyncUser.js +26 -0
  194. package/lib/WAUSync/index.d.ts +3 -0
  195. package/lib/WAUSync/index.js +19 -0
  196. package/lib/index.d.ts +11 -0
  197. package/lib/index.js +33 -0
  198. package/package.json +96 -0
@@ -0,0 +1,11 @@
1
+ const major = parseInt(process.versions.node.split('.')[0], 10);
2
+
3
+
4
+ if (major < 20) {
5
+ console.error(
6
+ `\n❌ This package requires Node.js 20+ to run reliably.\n` +
7
+ ` You are using Node.js ${process.versions.node}.\n` +
8
+ ` Please upgrade to Node.js 20+ to proceed.\n`
9
+ );
10
+ process.exit(1);
11
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "version": [2, 3000, 1023223821]
3
+ }
@@ -0,0 +1,53 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { proto } from '../../WAProto';
4
+ import type { MediaType, SocketConfig } from '../Types';
5
+ export declare const UNAUTHORIZED_CODES: number[];
6
+ export declare const DEFAULT_ORIGIN = "https://web.whatsapp.com";
7
+ export declare const DEF_CALLBACK_PREFIX = "CB:";
8
+ export declare const DEF_TAG_PREFIX = "TAG:";
9
+ export declare const PHONE_CONNECTION_CB = "CB:Pong";
10
+ export declare const WA_DEFAULT_EPHEMERAL: number;
11
+ export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
12
+ export declare const DICT_VERSION = 2;
13
+ export declare const KEY_BUNDLE_TYPE: Buffer;
14
+ export declare const NOISE_WA_HEADER: Buffer;
15
+ /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
16
+ export declare const URL_REGEX: RegExp;
17
+ export declare const WA_CERT_DETAILS: {
18
+ SERIAL: number;
19
+ };
20
+ export declare const PROCESSABLE_HISTORY_TYPES: proto.Message.HistorySyncNotification.HistorySyncType[];
21
+ export declare const DEFAULT_CONNECTION_CONFIG: SocketConfig;
22
+ export declare const MEDIA_PATH_MAP: {
23
+ [T in MediaType]?: string;
24
+ };
25
+ export declare const MEDIA_HKDF_KEY_MAPPING: {
26
+ audio: string;
27
+ document: string;
28
+ gif: string;
29
+ image: string;
30
+ ppic: string;
31
+ product: string;
32
+ ptt: string;
33
+ sticker: string;
34
+ video: string;
35
+ 'thumbnail-document': string;
36
+ 'thumbnail-image': string;
37
+ 'thumbnail-video': string;
38
+ 'thumbnail-link': string;
39
+ 'md-msg-hist': string;
40
+ 'md-app-state': string;
41
+ 'product-catalog-image': string;
42
+ 'payment-bg-image': string;
43
+ ptv: string;
44
+ };
45
+ export declare const MEDIA_KEYS: ("ppic" | "product" | "image" | "video" | "sticker" | "audio" | "gif" | "ptt" | "thumbnail-document" | "thumbnail-image" | "thumbnail-link" | "thumbnail-video" | "md-app-state" | "md-msg-hist" | "document" | "product-catalog-image" | "payment-bg-image" | "ptv")[];
46
+ export declare const MIN_PREKEY_COUNT = 5;
47
+ export declare const INITIAL_PREKEY_COUNT = 30;
48
+ export declare const DEFAULT_CACHE_TTLS: {
49
+ SIGNAL_STORE: number;
50
+ MSG_RETRY: number;
51
+ CALL_OFFER: number;
52
+ USER_DEVICES: number;
53
+ };
@@ -0,0 +1,130 @@
1
+ var __importDefault = this && this.__importDefault || function (a) {
2
+ return a && a.__esModule ? a : { "default": a }
3
+ };
4
+
5
+ Object.defineProperty(exports, "__esModule", { value: !0 });
6
+
7
+ exports.DEFAULT_CACHE_TTLS =
8
+ exports.INITIAL_PREKEY_COUNT =
9
+ exports.MIN_PREKEY_COUNT =
10
+ exports.MEDIA_KEYS =
11
+ exports.MEDIA_HKDF_KEY_MAPPING =
12
+ exports.MEDIA_PATH_MAP =
13
+ exports.DEFAULT_CONNECTION_CONFIG =
14
+ exports.PROCESSABLE_HISTORY_TYPES =
15
+ exports.WA_CERT_DETAILS =
16
+ exports.URL_REGEX =
17
+ exports.NOISE_WA_HEADER =
18
+ exports.KEY_BUNDLE_TYPE =
19
+ exports.DICT_VERSION =
20
+ exports.NOISE_MODE =
21
+ exports.WA_DEFAULT_EPHEMERAL =
22
+ exports.PHONE_CONNECTION_CB =
23
+ exports.DEF_TAG_PREFIX =
24
+ exports.DEF_CALLBACK_PREFIX =
25
+ exports.DEFAULT_ORIGIN =
26
+ exports.UNAUTHORIZED_CODES =
27
+ void 0;
28
+
29
+ const WAProto_1 = require("../../WAProto"),
30
+ libsignal_1 = require("../Signal/libsignal"),
31
+ Utils_1 = require("../Utils"),
32
+ logger_1 = __importDefault(require("../Utils/logger")),
33
+ baileys_version_json_1 = require("./baileys-version.json");
34
+
35
+ exports.UNAUTHORIZED_CODES = [401, 403, 419];
36
+ exports.DEFAULT_ORIGIN = "https://web.whatsapp.com";
37
+ exports.DEF_CALLBACK_PREFIX = "CB:";
38
+ exports.DEF_TAG_PREFIX = "TAG:";
39
+ exports.PHONE_CONNECTION_CB = "CB:Pong";
40
+ exports.WA_DEFAULT_EPHEMERAL = 604800;
41
+ exports.NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00";
42
+ exports.DICT_VERSION = 2;
43
+ exports.KEY_BUNDLE_TYPE = Buffer.from([5]);
44
+ exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]);
45
+
46
+ exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
47
+ exports.WA_CERT_DETAILS = { SERIAL: 0 };
48
+
49
+ exports.PROCESSABLE_HISTORY_TYPES = [
50
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
51
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
52
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
53
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
54
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
55
+ ];
56
+
57
+ exports.DEFAULT_CONNECTION_CONFIG = {
58
+ version: baileys_version_json_1.version,
59
+ browser: Utils_1.Browsers.ubuntu("Chrome"),
60
+ waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
61
+ connectTimeoutMs: 2E4,
62
+ keepAliveIntervalMs: 3E4,
63
+ logger: logger_1.default.child({ class: "baileys" }),
64
+ printQRInTerminal: !1,
65
+ emitOwnEvents: !0,
66
+ defaultQueryTimeoutMs: 6E4,
67
+ customUploadHosts: [],
68
+ retryRequestDelayMs: 250,
69
+ maxMsgRetryCount: 5,
70
+ fireInitQueries: !0,
71
+ auth: void 0,
72
+ markOnlineOnConnect: !0,
73
+ syncFullHistory: !1,
74
+ patchMessageBeforeSending: a => a,
75
+ shouldSyncHistoryMessage: () => !0,
76
+ shouldIgnoreJid: () => !1,
77
+ linkPreviewImageThumbnailWidth: 192,
78
+ transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3E3 },
79
+ generateHighQualityLinkPreview: !1,
80
+ options: {},
81
+ appStateMacVerification: { patch: !1, snapshot: !1 },
82
+ countryCode: "US",
83
+ getMessage: async () => { },
84
+ cachedGroupMetadata: async () => { },
85
+ makeSignalRepository: libsignal_1.makeLibSignalRepository
86
+ };
87
+
88
+ exports.MEDIA_PATH_MAP = {
89
+ image: "/mms/image",
90
+ video: "/mms/video",
91
+ document: "/mms/document",
92
+ audio: "/mms/audio",
93
+ sticker: "/mms/image",
94
+ "thumbnail-link": "/mms/image",
95
+ "product-catalog-image": "/product/image",
96
+ "md-app-state": "",
97
+ "md-msg-hist": "/mms/md-app-state"
98
+ };
99
+
100
+ exports.MEDIA_HKDF_KEY_MAPPING = {
101
+ audio: "Audio",
102
+ document: "Document",
103
+ gif: "Video",
104
+ image: "Image",
105
+ ppic: "",
106
+ product: "Image",
107
+ ptt: "Audio",
108
+ sticker: "Image",
109
+ video: "Video",
110
+ "thumbnail-document": "Document Thumbnail",
111
+ "thumbnail-image": "Image Thumbnail",
112
+ "thumbnail-video": "Video Thumbnail",
113
+ "thumbnail-link": "Link Thumbnail",
114
+ "md-msg-hist": "History",
115
+ "md-app-state": "App State",
116
+ "product-catalog-image": "",
117
+ "payment-bg-image": "Payment Background",
118
+ ptv: "Video"
119
+ };
120
+
121
+ exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
122
+ exports.MIN_PREKEY_COUNT = 5;
123
+ exports.INITIAL_PREKEY_COUNT = 30;
124
+
125
+ exports.DEFAULT_CACHE_TTLS = {
126
+ SIGNAL_STORE: 300,
127
+ MSG_RETRY: 3600,
128
+ CALL_OFFER: 300,
129
+ USER_DEVICES: 300
130
+ };
@@ -0,0 +1,223 @@
1
+ {
2
+ "93": 412,
3
+ "355": 276,
4
+ "213": 603,
5
+ "1-684": 544,
6
+ "376": 213,
7
+ "244": 631,
8
+ "1-264": 365,
9
+ "1-268": 344,
10
+ "54": 722,
11
+ "374": 283,
12
+ "297": 363,
13
+ "61": 505,
14
+ "43": 232,
15
+ "994": 400,
16
+ "1-242": 364,
17
+ "973": 426,
18
+ "880": 470,
19
+ "1-246": 342,
20
+ "375": 257,
21
+ "32": 206,
22
+ "501": 702,
23
+ "229": 616,
24
+ "1-441": 350,
25
+ "975": 402,
26
+ "591": 736,
27
+ "387": 218,
28
+ "267": 652,
29
+ "55": 724,
30
+ "1-284": 348,
31
+ "673": 528,
32
+ "359": 284,
33
+ "226": 613,
34
+ "257": 642,
35
+ "855": 456,
36
+ "237": 624,
37
+ "238": 625,
38
+ "1-345": 346,
39
+ "236": 623,
40
+ "235": 622,
41
+ "56": 730,
42
+ "86": 454,
43
+ "57": 732,
44
+ "269": 654,
45
+ "682": 548,
46
+ "506": 712,
47
+ "385": 219,
48
+ "53": 368,
49
+ "357": 280,
50
+ "420": 230,
51
+ "243": 630,
52
+ "45": 238,
53
+ "253": 638,
54
+ "1-767": 366,
55
+ "1-809": 370,
56
+ "1-849": 370,
57
+ "1-829": 370,
58
+ "593": 740,
59
+ "20": 602,
60
+ "503": 706,
61
+ "240": 627,
62
+ "291": 657,
63
+ "372": 248,
64
+ "251": 636,
65
+ "500": 750,
66
+ "298": 288,
67
+ "679": 542,
68
+ "358": 244,
69
+ "33": 208,
70
+ "689": 547,
71
+ "241": 628,
72
+ "220": 607,
73
+ "995": 282,
74
+ "49": 262,
75
+ "233": 620,
76
+ "350": 266,
77
+ "30": 202,
78
+ "299": 290,
79
+ "1-473": 352,
80
+ "1-671": 535,
81
+ "502": 704,
82
+ "224": 537,
83
+ "592": 738,
84
+ "509": 372,
85
+ "504": 708,
86
+ "852": 454,
87
+ "36": 216,
88
+ "354": 274,
89
+ "91": 404,
90
+ "62": 510,
91
+ "98": 432,
92
+ "964": 418,
93
+ "353": 234,
94
+ "972": 425,
95
+ "39": 222,
96
+ "225": 612,
97
+ "1-876": 338,
98
+ "81": 440,
99
+ "962": 416,
100
+ "254": 639,
101
+ "686": 545,
102
+ "383": 221,
103
+ "965": 419,
104
+ "371": 247,
105
+ "961": 415,
106
+ "266": 651,
107
+ "231": 618,
108
+ "218": 606,
109
+ "423": 295,
110
+ "370": 246,
111
+ "352": 270,
112
+ "389": 294,
113
+ "261": 646,
114
+ "265": 650,
115
+ "60": 502,
116
+ "960": 472,
117
+ "223": 610,
118
+ "356": 278,
119
+ "692": 551,
120
+ "222": 609,
121
+ "230": 617,
122
+ "52": 334,
123
+ "691": 550,
124
+ "373": 259,
125
+ "377": 212,
126
+ "976": 428,
127
+ "382": 297,
128
+ "1-664": 354,
129
+ "212": 604,
130
+ "258": 643,
131
+ "95": 414,
132
+ "264": 649,
133
+ "674": 536,
134
+ "977": 429,
135
+ "31": 204,
136
+ "687": 546,
137
+ "64": 530,
138
+ "505": 710,
139
+ "227": 614,
140
+ "234": 621,
141
+ "683": 555,
142
+ "1-670": 534,
143
+ "47": 242,
144
+ "968": 226,
145
+ "92": 410,
146
+ "680": 552,
147
+ "970": 423,
148
+ "507": 714,
149
+ "675": 537,
150
+ "595": 744,
151
+ "51": 716,
152
+ "63": 515,
153
+ "48": 260,
154
+ "351": 268,
155
+ "1-787, 1-939": 330,
156
+ "974": 427,
157
+ "242": 630,
158
+ "40": 226,
159
+ "7": 250,
160
+ "250": 635,
161
+ "290": 658,
162
+ "1-869": 356,
163
+ "1-758": 358,
164
+ "508": 308,
165
+ "1-784": 360,
166
+ "685": 544,
167
+ "378": 292,
168
+ "239": 626,
169
+ "966": 420,
170
+ "221": 608,
171
+ "381": 220,
172
+ "248": 633,
173
+ "232": 619,
174
+ "65": 525,
175
+ "386": 293,
176
+ "677": 540,
177
+ "27": 655,
178
+ "211": 659,
179
+ "34": 214,
180
+ "94": 413,
181
+ "249": 634,
182
+ "597": 746,
183
+ "268": 653,
184
+ "46": 240,
185
+ "41": 228,
186
+ "963": 417,
187
+ "886": 466,
188
+ "992": 436,
189
+ "255": 640,
190
+ "66": 520,
191
+ "228": 615,
192
+ "690": 554,
193
+ "676": 539,
194
+ "1-868": 374,
195
+ "216": 605,
196
+ "90": 286,
197
+ "993": 438,
198
+ "1-649": 376,
199
+ "688": 553,
200
+ "1-340": 332,
201
+ "256": 641,
202
+ "380": 255,
203
+ "971": 424,
204
+ "44": 234,
205
+ "1": 310,
206
+ "598": 748,
207
+ "998": 434,
208
+ "678": 541,
209
+ "379": 225,
210
+ "58": 734,
211
+ "681": 543,
212
+ "967": 421,
213
+ "260": 645,
214
+ "263": 648,
215
+ "670": 514,
216
+ "245": 632,
217
+ "856": 457,
218
+ "599": 362,
219
+ "850": 467,
220
+ "262": 647,
221
+ "82": 450,
222
+ "84": 452
223
+ }
@@ -0,0 +1,18 @@
1
+ export default function binarySearch(array, predicate) {
2
+ let low = 0;
3
+ let high = array.length;
4
+ if (array.length === 0) return low;
5
+ if (predicate(array[low]) < 0) return low - 1;
6
+ else if (predicate(array[low]) === 0) return low;
7
+ const maxPred = predicate(array[high - 1]);
8
+ if (maxPred > 0) return high;
9
+ else if (maxPred === 0) return high - 1;
10
+ while (low !== high) {
11
+ const mid = low + Math.floor((high - low) / 2);
12
+ const pred = predicate(array[mid]);
13
+ if (pred < 0) high = mid;
14
+ else if (pred > 0) low = mid + 1;
15
+ else return mid;
16
+ }
17
+ return low;
18
+ }
@@ -0,0 +1,164 @@
1
+ import binarySearch from './BinarySearch.js';
2
+ export default class KeyedDB {
3
+ constructor(key, id) {
4
+ this.key = key;
5
+ this.idGetter = id || (v => this.key.key(v).toString());
6
+ this.dict = {};
7
+ this.array = [];
8
+ }
9
+ get length() {
10
+ return this.array.length;
11
+ }
12
+ get first() {
13
+ return this.array[0];
14
+ }
15
+ get last() {
16
+ return this.array[this.array.length - 1];
17
+ }
18
+ toJSON() {
19
+ return this.array;
20
+ }
21
+ insert(...values) {
22
+ values.forEach(v => this._insertSingle(v));
23
+ }
24
+ upsert(...values) {
25
+ const updates = [];
26
+ values.forEach(v => {
27
+ if (!v) return;
28
+ const deleted = this.deleteById(this.idGetter(v), false);
29
+ this._insertSingle(v);
30
+ deleted && updates.push(v);
31
+ });
32
+ return updates;
33
+ }
34
+ insertIfAbsent(...values) {
35
+ const insertions = [];
36
+ values.forEach(v => {
37
+ if (!v) return;
38
+ const presentValue = this.get(this.idGetter(v));
39
+ if (presentValue) return;
40
+ const presentKey = this.firstIndex(v);
41
+ if (this.array[presentKey] && this.key.key(this.array[presentKey]) === this.key.key(v)) return;
42
+ this.insert(v);
43
+ insertions.push(v);
44
+ });
45
+ return insertions;
46
+ }
47
+ deleteById(id, assertPresent = true) {
48
+ const value = this.get(id);
49
+ if (!value) {
50
+ if (assertPresent) throw new Error(`Value not found`);
51
+ return;
52
+ }
53
+ return this.delete(value);
54
+ }
55
+ delete(value) {
56
+ const index = this.firstIndex(value);
57
+ if (index < 0 || index >= this.array.length || this.key.key(value) !== this.key.key(this.array[index])) {
58
+ return null;
59
+ }
60
+ delete this.dict[this.idGetter(value)];
61
+ return this.array.splice(index, 1)[0];
62
+ }
63
+ slice(start, end) {
64
+ const db = new KeyedDB(this.key, this.idGetter);
65
+ db.array = this.array.slice(start, end);
66
+ db.array.forEach(item => db.dict[this.idGetter(item)] = item);
67
+ return db;
68
+ }
69
+ clear() {
70
+ this.array = [];
71
+ this.dict = {};
72
+ }
73
+ get(id) {
74
+ return this.dict[id];
75
+ }
76
+ all() {
77
+ return this.array;
78
+ }
79
+ update(id, update) {
80
+ const value = this.get(id);
81
+ if (value) {
82
+ const idx = this.firstIndex(value);
83
+ if (idx >= 0 && idx < this.array.length && this.idGetter(this.array[idx]) === id) {
84
+ const oldKey = this.key.key(value);
85
+ update(value);
86
+ const newKey = this.key.key(value);
87
+ if (newKey !== oldKey) {
88
+ delete this.dict[id];
89
+ this.array.splice(idx, 1);
90
+ this._insertSingle(value);
91
+ return 2;
92
+ }
93
+ return 1;
94
+ }
95
+ }
96
+ }
97
+ updateKey(value, update) {
98
+ return this.update(this.idGetter(value), update);
99
+ }
100
+ filter(predicate) {
101
+ const db = new KeyedDB(this.key, this.idGetter);
102
+ db.array = this.array.filter((value, index) => {
103
+ if (predicate(value, index)) {
104
+ db.dict[this.idGetter(value)] = value;
105
+ return true;
106
+ }
107
+ });
108
+ return db;
109
+ }
110
+ paginatedByValue(value, limit, predicate, mode = 'after') {
111
+ return this.paginated(value && this.key.key(value), limit, predicate, mode);
112
+ }
113
+ paginated(cursor, limit, predicate, mode = 'after') {
114
+ let index = mode === 'after' ? 0 : this.array.length;
115
+ if (cursor !== null && typeof cursor !== 'undefined') {
116
+ index = binarySearch(this.array, v => this.key.compare(cursor, this.key.key(v)));
117
+ if (index < 0) index = 0;
118
+ if (this.key.key(this.array[index]) === cursor) index += (mode === 'after' ? 1 : 0);
119
+ }
120
+ return this.filtered(index, limit, mode, predicate);
121
+ }
122
+ _insertSingle(value) {
123
+ if (!value) throw new Error('falsey value');
124
+ const valueID = this.idGetter(value);
125
+ if (this.get(valueID)) throw new Error('duplicate ID being inserted: ' + valueID);
126
+
127
+ if (this.array.length > 0) {
128
+ const index = this.firstIndex(value);
129
+ if (index >= this.array.length) this.array.push(value);
130
+ else if (index < 0) this.array.unshift(value);
131
+ else if (this.key.key(value) !== this.key.key(this.array[index])) this.array.splice(index, 0, value);
132
+ else throw new Error(`duplicate key: ${this.key.key(value)}, inserting: ${valueID}, present: ${this.idGetter(this.array[index])}`);
133
+ } else {
134
+ this.array.push(value);
135
+ }
136
+ this.dict[valueID] = value;
137
+ }
138
+ filtered(start, count, mode, predicate) {
139
+ let arr;
140
+ if (mode === 'after') {
141
+ if (predicate) {
142
+ arr = [];
143
+ for (let item of this.array.slice(start)) {
144
+ predicate(item, start + arr.length) && arr.push(item);
145
+ if (arr.length >= count) break;
146
+ }
147
+ } else arr = this.array.slice(start, start + count);
148
+ } else if (mode === 'before') {
149
+ if (predicate) {
150
+ arr = [];
151
+ for (let i = start - 1; i >= 0; i--) {
152
+ let item = this.array[i];
153
+ predicate(item, start + arr.length) && arr.unshift(item);
154
+ if (arr.length >= count) break;
155
+ }
156
+ } else arr = this.array.slice(Math.max(start - count, 0), start);
157
+ }
158
+ return arr;
159
+ }
160
+ firstIndex(value) {
161
+ const valueKey = this.key.key(value);
162
+ return binarySearch(this.array, v => this.key.compare(valueKey, this.key.key(v)));
163
+ }
164
+ }
@@ -0,0 +1,2 @@
1
+ export * from './BinarySearch.js';
2
+ export * from './KeyedDB.js';
@@ -0,0 +1,9 @@
1
+ export declare class CiphertextMessage {
2
+ readonly UNSUPPORTED_VERSION: number;
3
+ readonly CURRENT_VERSION: number;
4
+ readonly WHISPER_TYPE: number;
5
+ readonly PREKEY_TYPE: number;
6
+ readonly SENDERKEY_TYPE: number;
7
+ readonly SENDERKEY_DISTRIBUTION_TYPE: number;
8
+ readonly ENCRYPTED_MESSAGE_OVERHEAD: number;
9
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CiphertextMessage = void 0;
4
+ class CiphertextMessage {
5
+ constructor() {
6
+ this.UNSUPPORTED_VERSION = 1;
7
+ this.CURRENT_VERSION = 3;
8
+ this.WHISPER_TYPE = 2;
9
+ this.PREKEY_TYPE = 3;
10
+ this.SENDERKEY_TYPE = 4;
11
+ this.SENDERKEY_DISTRIBUTION_TYPE = 5;
12
+ this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
13
+ }
14
+ }
15
+ exports.CiphertextMessage = CiphertextMessage;
@@ -0,0 +1,14 @@
1
+ import { SenderKeyDistributionMessage } from './sender-key-distribution-message';
2
+ import { SenderKeyName } from './sender-key-name';
3
+ import { SenderKeyRecord } from './sender-key-record';
4
+ interface SenderKeyStore {
5
+ loadSenderKey(senderKeyName: SenderKeyName): Promise<SenderKeyRecord>;
6
+ storeSenderKey(senderKeyName: SenderKeyName, record: SenderKeyRecord): Promise<void>;
7
+ }
8
+ export declare class GroupSessionBuilder {
9
+ private readonly senderKeyStore;
10
+ constructor(senderKeyStore: SenderKeyStore);
11
+ process(senderKeyName: SenderKeyName, senderKeyDistributionMessage: SenderKeyDistributionMessage): Promise<void>;
12
+ create(senderKeyName: SenderKeyName): Promise<SenderKeyDistributionMessage>;
13
+ }
14
+ export {};