@onyx-p/imlib-web 2.3.5 → 2.3.7

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.
package/index.esm.js CHANGED
@@ -7648,7 +7648,7 @@ function requireCryptoJs () {
7648
7648
  }
7649
7649
 
7650
7650
  var cryptoJsExports = requireCryptoJs();
7651
- var CryptoJS = /*@__PURE__*/getDefaultExportFromCjs(cryptoJsExports);
7651
+ var CryptoJS$1 = /*@__PURE__*/getDefaultExportFromCjs(cryptoJsExports);
7652
7652
 
7653
7653
  function getType(value) {
7654
7654
  return Object.prototype.toString.call(value).slice(8, -1);
@@ -7735,8 +7735,8 @@ const throttle = (fn, delay = 200) => {
7735
7735
  };
7736
7736
  };
7737
7737
 
7738
- const AesKey = CryptoJS.enc.Utf8.parse('skdjhfgc9829kslf');
7739
- const AesIv = CryptoJS.enc.Utf8.parse('qwdkshjf9838jsdf');
7738
+ const AesKey = CryptoJS$1.enc.Utf8.parse('skdjhfgc9829kslf');
7739
+ const AesIv = CryptoJS$1.enc.Utf8.parse('qwdkshjf9838jsdf');
7740
7740
  const isElectron = () => {
7741
7741
  return typeof process !== 'undefined' && typeof process.versions !== 'undefined' && !!process.versions.electron;
7742
7742
  };
@@ -7795,12 +7795,12 @@ const SecureStorageService = {
7795
7795
  return null;
7796
7796
  }
7797
7797
  if (isDef(value)) {
7798
- const encryptedHexStr = CryptoJS.enc.Hex.parse(value);
7799
- const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
7800
- const decrypt = CryptoJS.AES.decrypt(srcs, AesKey, {
7798
+ const encryptedHexStr = CryptoJS$1.enc.Hex.parse(value);
7799
+ const srcs = CryptoJS$1.enc.Base64.stringify(encryptedHexStr);
7800
+ const decrypt = CryptoJS$1.AES.decrypt(srcs, AesKey, {
7801
7801
  iv: AesIv
7802
7802
  });
7803
- value = decrypt.toString(CryptoJS.enc.Utf8);
7803
+ value = decrypt.toString(CryptoJS$1.enc.Utf8);
7804
7804
  }
7805
7805
  if (!isDef(value)) {
7806
7806
  return value;
@@ -7817,7 +7817,7 @@ const SecureStorageService = {
7817
7817
  this.remove(key);
7818
7818
  return;
7819
7819
  }
7820
- const encryptedData = CryptoJS.AES.encrypt(JSON.stringify(value), AesKey, {
7820
+ const encryptedData = CryptoJS$1.AES.encrypt(JSON.stringify(value), AesKey, {
7821
7821
  iv: AesIv
7822
7822
  });
7823
7823
  const encrytedStr = encryptedData.ciphertext.toString();
@@ -19554,18 +19554,18 @@ const aes256Encrypt = (message, secretKey) => {
19554
19554
  if (!notEmptyString(message)) {
19555
19555
  return '';
19556
19556
  }
19557
- const encryptedData = CryptoJS.AES.encrypt(message, CryptoJS.enc.Utf8.parse(secretKey.key), {
19558
- iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
19557
+ const encryptedData = CryptoJS$1.AES.encrypt(message, CryptoJS$1.enc.Utf8.parse(secretKey.key), {
19558
+ iv: isDef(secretKey.iv) ? CryptoJS$1.enc.Utf8.parse(secretKey.iv) : undefined
19559
19559
  });
19560
19560
  return Array.from(wordToUInt8Array(encryptedData.ciphertext.words)).map(byte => byte.toString(16).padStart(2, '0')).join('');
19561
19561
  };
19562
19562
  const aes256Decrypt = (cipherHex, secretKey) => {
19563
19563
  const cipherData = new Uint8Array(cipherHex.match(/.{1,2}/g)?.map(byte => parseInt(byte, 16)) || []);
19564
19564
  const srcs = window.btoa(String.fromCharCode(...cipherData));
19565
- const decrypt = CryptoJS.AES.decrypt(srcs, CryptoJS.enc.Utf8.parse(secretKey.key), {
19566
- iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
19565
+ const decrypt = CryptoJS$1.AES.decrypt(srcs, CryptoJS$1.enc.Utf8.parse(secretKey.key), {
19566
+ iv: isDef(secretKey.iv) ? CryptoJS$1.enc.Utf8.parse(secretKey.iv) : undefined
19567
19567
  });
19568
- return decrypt.toString(CryptoJS.enc.Utf8);
19568
+ return decrypt.toString(CryptoJS$1.enc.Utf8);
19569
19569
  };
19570
19570
  const wordToUInt8Array = wordArray => {
19571
19571
  const array = [];
@@ -20744,14 +20744,14 @@ class MessageCache {
20744
20744
  }
20745
20745
  generateEncryptKey(appKey, userId) {
20746
20746
  const saltedInput = `${this.SALT_PREFIX}${appKey}_${userId}${this.SALT_SUFFIX}`;
20747
- const keyMaterial = CryptoJS.SHA256(saltedInput).toString();
20747
+ const keyMaterial = CryptoJS$1.SHA256(saltedInput).toString();
20748
20748
  const iv = keyMaterial.substring(0, 16);
20749
20749
  const key = keyMaterial.substring(16, 48);
20750
- const additionalSalt = CryptoJS.SHA256(`${iv}:${this.SALT_PREFIX}:${userId}:${appKey}`).toString().substring(0, 8);
20751
- const finalKey = CryptoJS.PBKDF2(key, additionalSalt, {
20750
+ const additionalSalt = CryptoJS$1.SHA256(`${iv}:${this.SALT_PREFIX}:${userId}:${appKey}`).toString().substring(0, 8);
20751
+ const finalKey = CryptoJS$1.PBKDF2(key, additionalSalt, {
20752
20752
  keySize: 256 / 32,
20753
20753
  iterations: 1000,
20754
- hasher: CryptoJS.algo.SHA256
20754
+ hasher: CryptoJS$1.algo.SHA256
20755
20755
  }).toString();
20756
20756
  this.encryptKey = {
20757
20757
  key: finalKey.substring(0, 32),
@@ -28942,11 +28942,13 @@ async function createSendFunction(fileType, conversation, msgBody, hooks, sendOp
28942
28942
  }
28943
28943
  message1.content.user = msgBody.user;
28944
28944
  message1.content.extra = msgBody.extra;
28945
+ const encryptKey = generateEncryptKey();
28945
28946
  return internal_sendMessage(conversation, message1, sendOptions, {
28946
28947
  files,
28948
+ encryptKey: encryptKey,
28947
28949
  task: (message2, toBeUploadedFiles) => {
28948
28950
  return new Promise(resolve => {
28949
- imConfig.getUploader().upload(toBeUploadedFiles, {
28951
+ imConfig.getUploader().upload(toBeUploadedFiles, encryptKey, {
28950
28952
  onProgress: progress => hooks?.onProgress?.(progress),
28951
28953
  onError: () => {
28952
28954
  resolve({
@@ -28967,7 +28969,7 @@ async function createSendFunction(fileType, conversation, msgBody, hooks, sendOp
28967
28969
  });
28968
28970
  }
28969
28971
  async function internal_sendMessage(conversation, message, options, uploadOptions) {
28970
- const checkResult = await beforeSend(conversation, message, options);
28972
+ const checkResult = await beforeSend(conversation, message, options, uploadOptions);
28971
28973
  if (checkResult.code !== ErrorCode.SUCCESS || !checkResult.message || !checkResult.sentArgs) {
28972
28974
  return {
28973
28975
  code: checkResult.code
@@ -28995,7 +28997,7 @@ async function internal_sendMessage(conversation, message, options, uploadOption
28995
28997
  }
28996
28998
  return send(sentMessage, sentArgs);
28997
28999
  }
28998
- async function beforeSend(conversation, message, options) {
29000
+ async function beforeSend(conversation, message, options, uploadOptions) {
28999
29001
  const mediaAttribute = JSON.stringify(filterNullProperty(message.content));
29000
29002
  if (getByteLength(mediaAttribute) > MAX_MESSAGE_CONTENT_BYTES) {
29001
29003
  return {
@@ -29014,7 +29016,7 @@ async function beforeSend(conversation, message, options) {
29014
29016
  };
29015
29017
  if (options?.onSendBefore) {
29016
29018
  const receivedMessage = transSentAttrs2IReceivedMessage(message, sentArgs);
29017
- options.onSendBefore(receivedMessage);
29019
+ options.onSendBefore(receivedMessage, uploadOptions);
29018
29020
  }
29019
29021
  return {
29020
29022
  code: ErrorCode.SUCCESS,
@@ -29114,6 +29116,15 @@ async function saveSentMessage(receivedMessage, options) {
29114
29116
  logger.error('saveSentMessage -> ', error);
29115
29117
  }
29116
29118
  }
29119
+ function generateEncryptKey() {
29120
+ const data = new Uint8Array(16);
29121
+ for (let i = 0; i < 16; i++) {
29122
+ data[i] = 65 + Math.floor(Math.random() * 26);
29123
+ }
29124
+ const key = String.fromCharCode(...data);
29125
+ const md5Hash = CryptoJS.MD5(key).toString();
29126
+ return md5Hash;
29127
+ }
29117
29128
 
29118
29129
  class IMClient extends EventEmitter {
29119
29130
  options;
@@ -29222,11 +29233,7 @@ class IMClient extends EventEmitter {
29222
29233
  sendFileMessage = sendFileMessage$1;
29223
29234
  sendSightMessage = sendSightMessage$1;
29224
29235
  async recallMsg(conversation, options) {
29225
- const result = await sendRecallMessage(conversation, options);
29226
- if (result.code === ErrorCode.SUCCESS) {
29227
- MessageCache$1.get()?.removeMessagesByUId([options.messageUId]);
29228
- }
29229
- return result;
29236
+ return await sendRecallMessage(conversation, options);
29230
29237
  }
29231
29238
  async getRemoteHistoryMessages(conversation, options) {
29232
29239
  const timestamp = options.timestamp ?? '0';
@@ -30335,7 +30342,7 @@ const login = config => {
30335
30342
  return webSocketServer.request(0x30011011, {
30336
30343
  langCode: config.langCode,
30337
30344
  phoneNum: config.phone,
30338
- password: CryptoJS.SHA256(config.password).toString(),
30345
+ password: CryptoJS$1.SHA256(config.password).toString(),
30339
30346
  deviceType: 7,
30340
30347
  imei: '59bc678b-fe6d-4e67-87c6-b0692205134b',
30341
30348
  brand: 'Chrome',
package/index.umd.js CHANGED
@@ -7654,7 +7654,7 @@
7654
7654
  }
7655
7655
 
7656
7656
  var cryptoJsExports = requireCryptoJs();
7657
- var CryptoJS = /*@__PURE__*/getDefaultExportFromCjs(cryptoJsExports);
7657
+ var CryptoJS$1 = /*@__PURE__*/getDefaultExportFromCjs(cryptoJsExports);
7658
7658
 
7659
7659
  function getType(value) {
7660
7660
  return Object.prototype.toString.call(value).slice(8, -1);
@@ -7741,8 +7741,8 @@
7741
7741
  };
7742
7742
  };
7743
7743
 
7744
- const AesKey = CryptoJS.enc.Utf8.parse('skdjhfgc9829kslf');
7745
- const AesIv = CryptoJS.enc.Utf8.parse('qwdkshjf9838jsdf');
7744
+ const AesKey = CryptoJS$1.enc.Utf8.parse('skdjhfgc9829kslf');
7745
+ const AesIv = CryptoJS$1.enc.Utf8.parse('qwdkshjf9838jsdf');
7746
7746
  const isElectron = () => {
7747
7747
  return typeof process !== 'undefined' && typeof process.versions !== 'undefined' && !!process.versions.electron;
7748
7748
  };
@@ -7801,12 +7801,12 @@
7801
7801
  return null;
7802
7802
  }
7803
7803
  if (isDef(value)) {
7804
- const encryptedHexStr = CryptoJS.enc.Hex.parse(value);
7805
- const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
7806
- const decrypt = CryptoJS.AES.decrypt(srcs, AesKey, {
7804
+ const encryptedHexStr = CryptoJS$1.enc.Hex.parse(value);
7805
+ const srcs = CryptoJS$1.enc.Base64.stringify(encryptedHexStr);
7806
+ const decrypt = CryptoJS$1.AES.decrypt(srcs, AesKey, {
7807
7807
  iv: AesIv
7808
7808
  });
7809
- value = decrypt.toString(CryptoJS.enc.Utf8);
7809
+ value = decrypt.toString(CryptoJS$1.enc.Utf8);
7810
7810
  }
7811
7811
  if (!isDef(value)) {
7812
7812
  return value;
@@ -7823,7 +7823,7 @@
7823
7823
  this.remove(key);
7824
7824
  return;
7825
7825
  }
7826
- const encryptedData = CryptoJS.AES.encrypt(JSON.stringify(value), AesKey, {
7826
+ const encryptedData = CryptoJS$1.AES.encrypt(JSON.stringify(value), AesKey, {
7827
7827
  iv: AesIv
7828
7828
  });
7829
7829
  const encrytedStr = encryptedData.ciphertext.toString();
@@ -19560,18 +19560,18 @@
19560
19560
  if (!notEmptyString(message)) {
19561
19561
  return '';
19562
19562
  }
19563
- const encryptedData = CryptoJS.AES.encrypt(message, CryptoJS.enc.Utf8.parse(secretKey.key), {
19564
- iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
19563
+ const encryptedData = CryptoJS$1.AES.encrypt(message, CryptoJS$1.enc.Utf8.parse(secretKey.key), {
19564
+ iv: isDef(secretKey.iv) ? CryptoJS$1.enc.Utf8.parse(secretKey.iv) : undefined
19565
19565
  });
19566
19566
  return Array.from(wordToUInt8Array(encryptedData.ciphertext.words)).map(byte => byte.toString(16).padStart(2, '0')).join('');
19567
19567
  };
19568
19568
  const aes256Decrypt = (cipherHex, secretKey) => {
19569
19569
  const cipherData = new Uint8Array(cipherHex.match(/.{1,2}/g)?.map(byte => parseInt(byte, 16)) || []);
19570
19570
  const srcs = window.btoa(String.fromCharCode(...cipherData));
19571
- const decrypt = CryptoJS.AES.decrypt(srcs, CryptoJS.enc.Utf8.parse(secretKey.key), {
19572
- iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
19571
+ const decrypt = CryptoJS$1.AES.decrypt(srcs, CryptoJS$1.enc.Utf8.parse(secretKey.key), {
19572
+ iv: isDef(secretKey.iv) ? CryptoJS$1.enc.Utf8.parse(secretKey.iv) : undefined
19573
19573
  });
19574
- return decrypt.toString(CryptoJS.enc.Utf8);
19574
+ return decrypt.toString(CryptoJS$1.enc.Utf8);
19575
19575
  };
19576
19576
  const wordToUInt8Array = wordArray => {
19577
19577
  const array = [];
@@ -20750,14 +20750,14 @@
20750
20750
  }
20751
20751
  generateEncryptKey(appKey, userId) {
20752
20752
  const saltedInput = `${this.SALT_PREFIX}${appKey}_${userId}${this.SALT_SUFFIX}`;
20753
- const keyMaterial = CryptoJS.SHA256(saltedInput).toString();
20753
+ const keyMaterial = CryptoJS$1.SHA256(saltedInput).toString();
20754
20754
  const iv = keyMaterial.substring(0, 16);
20755
20755
  const key = keyMaterial.substring(16, 48);
20756
- const additionalSalt = CryptoJS.SHA256(`${iv}:${this.SALT_PREFIX}:${userId}:${appKey}`).toString().substring(0, 8);
20757
- const finalKey = CryptoJS.PBKDF2(key, additionalSalt, {
20756
+ const additionalSalt = CryptoJS$1.SHA256(`${iv}:${this.SALT_PREFIX}:${userId}:${appKey}`).toString().substring(0, 8);
20757
+ const finalKey = CryptoJS$1.PBKDF2(key, additionalSalt, {
20758
20758
  keySize: 256 / 32,
20759
20759
  iterations: 1000,
20760
- hasher: CryptoJS.algo.SHA256
20760
+ hasher: CryptoJS$1.algo.SHA256
20761
20761
  }).toString();
20762
20762
  this.encryptKey = {
20763
20763
  key: finalKey.substring(0, 32),
@@ -28948,11 +28948,13 @@
28948
28948
  }
28949
28949
  message1.content.user = msgBody.user;
28950
28950
  message1.content.extra = msgBody.extra;
28951
+ const encryptKey = generateEncryptKey();
28951
28952
  return internal_sendMessage(conversation, message1, sendOptions, {
28952
28953
  files,
28954
+ encryptKey: encryptKey,
28953
28955
  task: (message2, toBeUploadedFiles) => {
28954
28956
  return new Promise(resolve => {
28955
- imConfig.getUploader().upload(toBeUploadedFiles, {
28957
+ imConfig.getUploader().upload(toBeUploadedFiles, encryptKey, {
28956
28958
  onProgress: progress => hooks?.onProgress?.(progress),
28957
28959
  onError: () => {
28958
28960
  resolve({
@@ -28973,7 +28975,7 @@
28973
28975
  });
28974
28976
  }
28975
28977
  async function internal_sendMessage(conversation, message, options, uploadOptions) {
28976
- const checkResult = await beforeSend(conversation, message, options);
28978
+ const checkResult = await beforeSend(conversation, message, options, uploadOptions);
28977
28979
  if (checkResult.code !== exports.ErrorCode.SUCCESS || !checkResult.message || !checkResult.sentArgs) {
28978
28980
  return {
28979
28981
  code: checkResult.code
@@ -29001,7 +29003,7 @@
29001
29003
  }
29002
29004
  return send(sentMessage, sentArgs);
29003
29005
  }
29004
- async function beforeSend(conversation, message, options) {
29006
+ async function beforeSend(conversation, message, options, uploadOptions) {
29005
29007
  const mediaAttribute = JSON.stringify(filterNullProperty(message.content));
29006
29008
  if (getByteLength(mediaAttribute) > MAX_MESSAGE_CONTENT_BYTES) {
29007
29009
  return {
@@ -29020,7 +29022,7 @@
29020
29022
  };
29021
29023
  if (options?.onSendBefore) {
29022
29024
  const receivedMessage = transSentAttrs2IReceivedMessage(message, sentArgs);
29023
- options.onSendBefore(receivedMessage);
29025
+ options.onSendBefore(receivedMessage, uploadOptions);
29024
29026
  }
29025
29027
  return {
29026
29028
  code: exports.ErrorCode.SUCCESS,
@@ -29120,6 +29122,15 @@
29120
29122
  logger.error('saveSentMessage -> ', error);
29121
29123
  }
29122
29124
  }
29125
+ function generateEncryptKey() {
29126
+ const data = new Uint8Array(16);
29127
+ for (let i = 0; i < 16; i++) {
29128
+ data[i] = 65 + Math.floor(Math.random() * 26);
29129
+ }
29130
+ const key = String.fromCharCode(...data);
29131
+ const md5Hash = CryptoJS.MD5(key).toString();
29132
+ return md5Hash;
29133
+ }
29123
29134
 
29124
29135
  class IMClient extends EventEmitter {
29125
29136
  options;
@@ -29228,11 +29239,7 @@
29228
29239
  sendFileMessage = sendFileMessage$1;
29229
29240
  sendSightMessage = sendSightMessage$1;
29230
29241
  async recallMsg(conversation, options) {
29231
- const result = await sendRecallMessage(conversation, options);
29232
- if (result.code === exports.ErrorCode.SUCCESS) {
29233
- MessageCache$1.get()?.removeMessagesByUId([options.messageUId]);
29234
- }
29235
- return result;
29242
+ return await sendRecallMessage(conversation, options);
29236
29243
  }
29237
29244
  async getRemoteHistoryMessages(conversation, options) {
29238
29245
  const timestamp = options.timestamp ?? '0';
@@ -30341,7 +30348,7 @@
30341
30348
  return webSocketServer.request(0x30011011, {
30342
30349
  langCode: config.langCode,
30343
30350
  phoneNum: config.phone,
30344
- password: CryptoJS.SHA256(config.password).toString(),
30351
+ password: CryptoJS$1.SHA256(config.password).toString(),
30345
30352
  deviceType: 7,
30346
30353
  imei: '59bc678b-fe6d-4e67-87c6-b0692205134b',
30347
30354
  brand: 'Chrome',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onyx-p/imlib-web",
3
- "version": "2.3.5",
3
+ "version": "2.3.7",
4
4
  "main": "index.umd.js",
5
5
  "module": "index.esm.js",
6
6
  "types": "types/index.d.ts",
package/types/types.d.ts CHANGED
@@ -130,6 +130,10 @@ export type IPushConfig = {
130
130
  */
131
131
  pushData?: string;
132
132
  };
133
+ export interface IUploadMessageParams {
134
+ files: Blob[];
135
+ encryptKey: string;
136
+ }
133
137
  /**
134
138
  * 发送消息时的可选项信息
135
139
  */
@@ -137,7 +141,7 @@ export interface ISendMessageOptions {
137
141
  /**
138
142
  * 消息发送之前的回调
139
143
  */
140
- onSendBefore?: (message: IReceivedMessage) => void;
144
+ onSendBefore?: (message: IReceivedMessage, uploadOptions?: IUploadMessageParams) => void;
141
145
  /**
142
146
  * 重发消息时用到,重发消息的 messageId。
143
147
  * 当要重发消息时所有参数需与原始消息参数一致,messageId 必须存在。
@@ -178,7 +182,7 @@ export type IUploadCallback = {
178
182
  onError?: (reason: string) => void;
179
183
  };
180
184
  export interface IUploader {
181
- upload(files: Blob[], callback: IUploadCallback): void;
185
+ upload(files: Blob[], encryptKey: string, callback: IUploadCallback): void;
182
186
  cancel(): void;
183
187
  }
184
188
  /**