@x4r1s3/baileys 0.0.0-stage → 1.0.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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1262 -2
  3. package/SECURITY.md +47 -0
  4. package/WAProto/V +1 -0
  5. package/WAProto/WAProto.proto +8892 -0
  6. package/WAProto/index.d.ts +104128 -0
  7. package/WAProto/index.js +334920 -0
  8. package/assets/rolling-circle.svg +133 -0
  9. package/assets/x4r1s3-banner.svg +32 -0
  10. package/engine-requirements.js +27 -0
  11. package/lib/Builders/A2UI.js +245 -0
  12. package/lib/Builders/AIRich.js +179 -0
  13. package/lib/Builders/Button.js +108 -0
  14. package/lib/Builders/CFC.js +284 -0
  15. package/lib/Builders/Carousel.js +81 -0
  16. package/lib/Call/THIRD_PARTY_LICENSE.txt +21 -0
  17. package/lib/Call/audio-feeder.mjs +179 -0
  18. package/lib/Call/audio-recorder.mjs +250 -0
  19. package/lib/Call/fetch-wasm-resources.mjs +104 -0
  20. package/lib/Call/index.mjs +680 -0
  21. package/lib/Call/relay-transport.mjs +563 -0
  22. package/lib/Call/signaling.mjs +641 -0
  23. package/lib/Call/types.mjs +17 -0
  24. package/lib/Call/video-feeder.mjs +94 -0
  25. package/lib/Call/wasm-engine.mjs +1372 -0
  26. package/lib/Call/worker-bootstrap.mjs +1042 -0
  27. package/lib/Defaults/ban-checker.js +56 -0
  28. package/lib/Defaults/index.js +170 -0
  29. package/lib/Signal/Group/ciphertext-message.js +23 -0
  30. package/lib/Signal/Group/group-session-builder.js +41 -0
  31. package/lib/Signal/Group/group_cipher.js +93 -0
  32. package/lib/Signal/Group/index.js +23 -0
  33. package/lib/Signal/Group/keyhelper.js +29 -0
  34. package/lib/Signal/Group/sender-chain-key.js +37 -0
  35. package/lib/Signal/Group/sender-key-distribution-message.js +74 -0
  36. package/lib/Signal/Group/sender-key-message.js +77 -0
  37. package/lib/Signal/Group/sender-key-name.js +59 -0
  38. package/lib/Signal/Group/sender-key-record.js +52 -0
  39. package/lib/Signal/Group/sender-key-state.js +95 -0
  40. package/lib/Signal/Group/sender-message-key.js +37 -0
  41. package/lib/Signal/libsignal.js +440 -0
  42. package/lib/Signal/lid-mapping.js +292 -0
  43. package/lib/Socket/Client/index.js +14 -0
  44. package/lib/Socket/Client/types.js +22 -0
  45. package/lib/Socket/Client/websocket.js +65 -0
  46. package/lib/Socket/aigroups.js +327 -0
  47. package/lib/Socket/ban-checker.js +165 -0
  48. package/lib/Socket/business.js +419 -0
  49. package/lib/Socket/chats.js +1921 -0
  50. package/lib/Socket/communities.js +443 -0
  51. package/lib/Socket/graphql.js +911 -0
  52. package/lib/Socket/groups.js +561 -0
  53. package/lib/Socket/index.js +49 -0
  54. package/lib/Socket/interactive-handler.js +612 -0
  55. package/lib/Socket/interop.js +575 -0
  56. package/lib/Socket/managed-account.js +220 -0
  57. package/lib/Socket/messages-recv.js +2191 -0
  58. package/lib/Socket/messages-send.js +4104 -0
  59. package/lib/Socket/mex.js +53 -0
  60. package/lib/Socket/newsletter.js +291 -0
  61. package/lib/Socket/privacy.js +458 -0
  62. package/lib/Socket/registration.js +440 -0
  63. package/lib/Socket/socket.js +1029 -0
  64. package/lib/Socket/status-actions.js +287 -0
  65. package/lib/Socket/username.js +241 -0
  66. package/lib/Store/index.js +16 -0
  67. package/lib/Store/make-cache-manager-store.js +101 -0
  68. package/lib/Store/make-in-memory-store.js +432 -0
  69. package/lib/Store/make-ordered-dictionary.js +90 -0
  70. package/lib/Store/object-repository.js +35 -0
  71. package/lib/Types/Auth.js +13 -0
  72. package/lib/Types/Bussines.js +13 -0
  73. package/lib/Types/Call.js +13 -0
  74. package/lib/Types/Chat.js +19 -0
  75. package/lib/Types/Contact.js +13 -0
  76. package/lib/Types/Events.js +13 -0
  77. package/lib/Types/GroupMetadata.js +13 -0
  78. package/lib/Types/Label.js +36 -0
  79. package/lib/Types/LabelAssociation.js +18 -0
  80. package/lib/Types/Message.js +30 -0
  81. package/lib/Types/Mex.js +53 -0
  82. package/lib/Types/Product.js +13 -0
  83. package/lib/Types/RichType.js +34 -0
  84. package/lib/Types/Signal.js +13 -0
  85. package/lib/Types/Socket.js +14 -0
  86. package/lib/Types/State.js +60 -0
  87. package/lib/Types/USync.js +13 -0
  88. package/lib/Types/index.js +37 -0
  89. package/lib/Utils/auth-utils.js +313 -0
  90. package/lib/Utils/ban-checker.js +48 -0
  91. package/lib/Utils/bot-capabilities.js +96 -0
  92. package/lib/Utils/bot-planning-replay.js +177 -0
  93. package/lib/Utils/browser-utils.js +40 -0
  94. package/lib/Utils/business.js +242 -0
  95. package/lib/Utils/c2582.js +147 -0
  96. package/lib/Utils/chat-utils.js +905 -0
  97. package/lib/Utils/companion-reg-client-utils.js +44 -0
  98. package/lib/Utils/consumer-application.js +114 -0
  99. package/lib/Utils/crypto.js +129 -0
  100. package/lib/Utils/decode-wa-message.js +496 -0
  101. package/lib/Utils/direct-chat-theme.js +164 -0
  102. package/lib/Utils/event-buffer.js +601 -0
  103. package/lib/Utils/experimental-proto.js +206 -0
  104. package/lib/Utils/games/miniapp.js +17 -0
  105. package/lib/Utils/games/slot-machine.js +270 -0
  106. package/lib/Utils/games/website-preview.js +306 -0
  107. package/lib/Utils/generics.js +402 -0
  108. package/lib/Utils/group-history.js +68 -0
  109. package/lib/Utils/group-wallpaper.js +168 -0
  110. package/lib/Utils/history.js +162 -0
  111. package/lib/Utils/identity-change-handler.js +60 -0
  112. package/lib/Utils/index.js +61 -0
  113. package/lib/Utils/jid-display-normalization.js +221 -0
  114. package/lib/Utils/link-preview.js +96 -0
  115. package/lib/Utils/logger.js +14 -0
  116. package/lib/Utils/lt-hash.js +19 -0
  117. package/lib/Utils/make-mutex.js +44 -0
  118. package/lib/Utils/message-composer.js +709 -0
  119. package/lib/Utils/message-inspect.js +79 -0
  120. package/lib/Utils/message-retry-manager.js +253 -0
  121. package/lib/Utils/message-security.js +167 -0
  122. package/lib/Utils/messages-media.js +1027 -0
  123. package/lib/Utils/messages.js +2467 -0
  124. package/lib/Utils/meta-ai-msmsg.js +215 -0
  125. package/lib/Utils/meta-compositing.js +239 -0
  126. package/lib/Utils/native-flow.js +158 -0
  127. package/lib/Utils/newsletter-live-update-utils.js +74 -0
  128. package/lib/Utils/newsletter-status-utils.js +152 -0
  129. package/lib/Utils/noise-handler.js +212 -0
  130. package/lib/Utils/offline-node-processor.js +51 -0
  131. package/lib/Utils/poll-manager.js +206 -0
  132. package/lib/Utils/portable-compat.js +12 -0
  133. package/lib/Utils/pre-key-manager.js +117 -0
  134. package/lib/Utils/process-message.js +610 -0
  135. package/lib/Utils/reporting-utils.js +269 -0
  136. package/lib/Utils/rich-message-utils.js +2841 -0
  137. package/lib/Utils/scheduled-message.js +107 -0
  138. package/lib/Utils/signal.js +212 -0
  139. package/lib/Utils/source-grep.js +57 -0
  140. package/lib/Utils/stanza-ack.js +49 -0
  141. package/lib/Utils/sticker-annotation.js +87 -0
  142. package/lib/Utils/sync-action-utils.js +59 -0
  143. package/lib/Utils/tc-token-utils.js +174 -0
  144. package/lib/Utils/use-multi-file-auth-state.js +132 -0
  145. package/lib/Utils/use-single-file-auth-state.js +108 -0
  146. package/lib/Utils/use-sqlite-auth-state.js +120 -0
  147. package/lib/Utils/validate-connection.js +220 -0
  148. package/lib/Utils/view-once-utils.js +218 -0
  149. package/lib/Utils/voip-rekey.js +32 -0
  150. package/lib/Utils/website-preview.js +27 -0
  151. package/lib/Utils/welcome-flow.js +228 -0
  152. package/lib/Utils/x4r1s3.js +144 -0
  153. package/lib/WABinary/constants.js +1475 -0
  154. package/lib/WABinary/decode.js +273 -0
  155. package/lib/WABinary/encode.js +231 -0
  156. package/lib/WABinary/generic-utils.js +242 -0
  157. package/lib/WABinary/index.js +17 -0
  158. package/lib/WABinary/jid-utils.js +107 -0
  159. package/lib/WABinary/types.js +13 -0
  160. package/lib/WAM/BinaryInfo.js +21 -0
  161. package/lib/WAM/constants.js +22864 -0
  162. package/lib/WAM/encode.js +161 -0
  163. package/lib/WAM/index.js +15 -0
  164. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +108 -0
  165. package/lib/WAUSync/Protocols/USyncContactProtocol.js +68 -0
  166. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
  167. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +38 -0
  168. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +82 -0
  169. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +40 -0
  170. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +37 -0
  171. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
  172. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +46 -0
  173. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +36 -0
  174. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -0
  175. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +40 -0
  176. package/lib/WAUSync/Protocols/index.js +24 -0
  177. package/lib/WAUSync/USyncQuery.js +213 -0
  178. package/lib/WAUSync/USyncUser.js +66 -0
  179. package/lib/WAUSync/index.js +15 -0
  180. package/lib/antiban.cjs +4726 -0
  181. package/lib/index.d.ts +1285 -0
  182. package/lib/index.js +30 -0
  183. package/package.json +125 -4
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Utils/companion-reg-client-utils.js
5
+ * About: Companion reg client utils module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: CompanionWebClientType, getCompanionWebClientType, getCompanionPlatformId, buildPairingQRData
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ export const CompanionWebClientType = {
14
+ UNKNOWN: 0,
15
+ CHROME: 1,
16
+ EDGE: 2,
17
+ FIREFOX: 3,
18
+ IE: 4,
19
+ OPERA: 5,
20
+ SAFARI: 6,
21
+ ELECTRON: 7,
22
+ UWP: 8,
23
+ OTHER_WEB_CLIENT: 9
24
+ };
25
+ const BROWSER_TO_COMPANION_WEB_CLIENT = {
26
+ Chrome: CompanionWebClientType.CHROME,
27
+ Edge: CompanionWebClientType.EDGE,
28
+ Firefox: CompanionWebClientType.FIREFOX,
29
+ IE: CompanionWebClientType.IE,
30
+ Opera: CompanionWebClientType.OPERA,
31
+ Safari: CompanionWebClientType.SAFARI
32
+ };
33
+ export const getCompanionWebClientType = ([os, browserName]) => {
34
+ if (browserName === 'Desktop') {
35
+ return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON;
36
+ }
37
+ return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT;
38
+ };
39
+ export const getCompanionPlatformId = (browser) => {
40
+ return getCompanionWebClientType(browser).toString();
41
+ };
42
+ export const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
43
+ return [ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(',');
44
+ };
@@ -0,0 +1,114 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Utils/consumer-application.js
5
+ * About: Consumer application module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: decodeConsumerApplication, consumerApplicationToMessage
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ import { proto } from '../../WAProto/index.js';
14
+
15
+ export const decodeConsumerApplication = (buffer) => {
16
+ if (!Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array)) {
17
+ throw new TypeError('decodeConsumerApplication: buffer must be Buffer or Uint8Array');
18
+ }
19
+ return proto.ConsumerApplication.decode(buffer);
20
+ };
21
+
22
+ const textOf = mt => (mt && typeof mt.text === 'string' ? mt.text : undefined);
23
+
24
+ const mapContent = (content) => {
25
+ if (!content) return null;
26
+ switch (content.content) {
27
+ case 'messageText':
28
+ return { conversation: textOf(content.messageText) ?? '' };
29
+ case 'extendedTextMessage': {
30
+ const e = content.extendedTextMessage;
31
+ return {
32
+ extendedTextMessage: {
33
+ text: textOf(e.text),
34
+ matchedText: e.matchedText,
35
+ canonicalUrl: e.canonicalUrl,
36
+ description: e.description,
37
+ title: e.title
38
+ }
39
+ };
40
+ }
41
+ case 'imageMessage':
42
+ return {
43
+ imageMessage: { mediaPayload: content.imageMessage.image, caption: textOf(content.imageMessage.caption) }
44
+ };
45
+ case 'videoMessage':
46
+ return {
47
+ videoMessage: { mediaPayload: content.videoMessage.video, caption: textOf(content.videoMessage.caption) }
48
+ };
49
+ case 'audioMessage':
50
+ return { audioMessage: { mediaPayload: content.audioMessage.audio, ptt: content.audioMessage.ptt } };
51
+ case 'documentMessage':
52
+ return {
53
+ documentMessage: { mediaPayload: content.documentMessage.document, fileName: content.documentMessage.fileName }
54
+ };
55
+ case 'stickerMessage':
56
+ return { stickerMessage: { mediaPayload: content.stickerMessage.sticker } };
57
+ case 'contactMessage':
58
+ return { contactMessage: { mediaPayload: content.contactMessage.contact } };
59
+ case 'contactsArrayMessage':
60
+ return {
61
+ contactsArrayMessage: {
62
+ displayName: content.contactsArrayMessage.displayName,
63
+ contacts: content.contactsArrayMessage.contacts || []
64
+ }
65
+ };
66
+ case 'locationMessage': {
67
+ const loc = content.locationMessage.location || {};
68
+ return {
69
+ locationMessage: {
70
+ degreesLatitude: loc.degreesLatitude,
71
+ degreesLongitude: loc.degreesLongitude,
72
+ name: loc.name
73
+ }
74
+ };
75
+ }
76
+ case 'liveLocationMessage': {
77
+ const loc = content.liveLocationMessage.location || {};
78
+ return {
79
+ liveLocationMessage: {
80
+ degreesLatitude: loc.degreesLatitude,
81
+ degreesLongitude: loc.degreesLongitude,
82
+ caption: textOf(content.liveLocationMessage.caption)
83
+ }
84
+ };
85
+ }
86
+ case 'reactionMessage':
87
+ return { reactionMessage: content.reactionMessage };
88
+ default:
89
+ return null;
90
+ }
91
+ };
92
+
93
+ export const consumerApplicationToMessage = (app) => {
94
+ const payload = app?.payload;
95
+ if (!payload) return null;
96
+ switch (payload.payload) {
97
+ case 'content':
98
+ return mapContent(payload.content);
99
+ case 'applicationData': {
100
+ const ad = payload.applicationData;
101
+ if (ad?.applicationContent === 'revoke' && ad.revoke?.key) {
102
+ return {
103
+ protocolMessage: {
104
+ key: ad.revoke.key,
105
+ type: proto.Message.ProtocolMessage.Type.REVOKE
106
+ }
107
+ };
108
+ }
109
+ return null;
110
+ }
111
+ default:
112
+ return null;
113
+ }
114
+ };
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Utils/crypto.js
5
+ * About: Crypto module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: generateSignalPubKey, Curve, signedKeyPair, aesEncryptGCM, aesDecryptGCM, aesEncryptCTR, aesDecryptCTR, aesDecrypt; …
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from 'crypto';
14
+ import * as curve from 'libsignal/src/curve.js';
15
+ import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
16
+ export { md5, hkdf } from 'whatsapp-rust-bridge';
17
+ // insure browser & node compatibility
18
+ const { subtle } = globalThis.crypto;
19
+ /** prefix version byte to the pub keys, required for some curve crypto functions */
20
+ export const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey]);
21
+ export const Curve = {
22
+ generateKeyPair: () => {
23
+ const { pubKey, privKey } = curve.generateKeyPair();
24
+ return {
25
+ private: Buffer.from(privKey),
26
+ // remove version byte
27
+ public: Buffer.from(pubKey.slice(1))
28
+ };
29
+ },
30
+ sharedKey: (privateKey, publicKey) => {
31
+ const shared = curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
32
+ return Buffer.from(shared);
33
+ },
34
+ sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
35
+ verify: (pubKey, message, signature) => {
36
+ try {
37
+ curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
38
+ return true;
39
+ }
40
+ catch (error) {
41
+ return false;
42
+ }
43
+ }
44
+ };
45
+ export const signedKeyPair = (identityKeyPair, keyId) => {
46
+ const preKey = Curve.generateKeyPair();
47
+ const pubKey = generateSignalPubKey(preKey.public);
48
+ const signature = Curve.sign(identityKeyPair.private, pubKey);
49
+ return { keyPair: preKey, signature, keyId };
50
+ };
51
+ const GCM_TAG_LENGTH = 128 >> 3;
52
+ /**
53
+ * encrypt AES 256 GCM;
54
+ * where the tag tag is suffixed to the ciphertext
55
+ * */
56
+ export function aesEncryptGCM(plaintext, key, iv, additionalData) {
57
+ const cipher = createCipheriv('aes-256-gcm', key, iv);
58
+ cipher.setAAD(additionalData);
59
+ return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
60
+ }
61
+ /**
62
+ * decrypt AES 256 GCM;
63
+ * where the auth tag is suffixed to the ciphertext
64
+ * */
65
+ export function aesDecryptGCM(ciphertext, key, iv, additionalData) {
66
+ const decipher = createDecipheriv('aes-256-gcm', key, iv);
67
+ // decrypt additional adata
68
+ const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
69
+ const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
70
+ // set additional data
71
+ decipher.setAAD(additionalData);
72
+ decipher.setAuthTag(tag);
73
+ return Buffer.concat([decipher.update(enc), decipher.final()]);
74
+ }
75
+ export function aesEncryptCTR(plaintext, key, iv) {
76
+ const cipher = createCipheriv('aes-256-ctr', key, iv);
77
+ return Buffer.concat([cipher.update(plaintext), cipher.final()]);
78
+ }
79
+ export function aesDecryptCTR(ciphertext, key, iv) {
80
+ const decipher = createDecipheriv('aes-256-ctr', key, iv);
81
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
82
+ }
83
+ /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
84
+ export function aesDecrypt(buffer, key) {
85
+ return aesDecryptWithIV(buffer.subarray(16), key, buffer.subarray(0, 16));
86
+ }
87
+ /** decrypt AES 256 CBC */
88
+ export function aesDecryptWithIV(buffer, key, IV) {
89
+ const aes = createDecipheriv('aes-256-cbc', key, IV);
90
+ return Buffer.concat([aes.update(buffer), aes.final()]);
91
+ }
92
+ // encrypt AES 256 CBC; where a random IV is prefixed to the buffer
93
+ export function aesEncrypt(buffer, key) {
94
+ const IV = randomBytes(16);
95
+ const aes = createCipheriv('aes-256-cbc', key, IV);
96
+ return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
97
+ }
98
+ // encrypt AES 256 CBC with a given IV
99
+ export function aesEncrypWithIV(buffer, key, IV) {
100
+ const aes = createCipheriv('aes-256-cbc', key, IV);
101
+ return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
102
+ }
103
+ // sign HMAC using SHA 256
104
+ export function hmacSign(buffer, key, variant = 'sha256') {
105
+ return createHmac(variant, key).update(buffer).digest();
106
+ }
107
+ export function sha256(buffer) {
108
+ return createHash('sha256').update(buffer).digest();
109
+ }
110
+ export async function derivePairingCodeKey(pairingCode, salt) {
111
+ // Convert inputs to formats Web Crypto API can work with
112
+ const encoder = new TextEncoder();
113
+ const pairingCodeBuffer = encoder.encode(pairingCode);
114
+ const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
115
+ // Import the pairing code as key material
116
+ const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, [
117
+ 'deriveBits'
118
+ ]);
119
+ // Derive bits using PBKDF2 with the same parameters
120
+ // 2 << 16 = 131,072 iterations
121
+ const derivedBits = await subtle.deriveBits({
122
+ name: 'PBKDF2',
123
+ salt: saltBuffer,
124
+ iterations: 2 << 16,
125
+ hash: 'SHA-256'
126
+ }, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
127
+ );
128
+ return Buffer.from(derivedBits);
129
+ }