@traiyani/chatsdk-react 1.0.3 → 1.0.5

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/README.md CHANGED
@@ -189,11 +189,23 @@ async function generateExternalGroupId(userId1, userId2, productId) {
189
189
  ? `${sorted[0]}_${sorted[1]}_product_${productId}`
190
190
  : `${sorted[0]}_${sorted[1]}`;
191
191
 
192
- const encoder = new TextEncoder();
193
- const data = encoder.encode(base);
194
- const hashBuffer = await crypto.subtle.digest('SHA-256', data);
195
- const hashArray = Array.from(new Uint8Array(hashBuffer));
196
- return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
192
+ return await hashString(base);
193
+ }
194
+
195
+ async function hashString(input) {
196
+ if (typeof crypto !== 'undefined' && crypto.subtle) {
197
+ const data = new TextEncoder().encode(input);
198
+ const hashBuffer = await crypto.subtle.digest('SHA-256', data);
199
+ return Array.from(new Uint8Array(hashBuffer))
200
+ .map(b => b.toString(16).padStart(2, '0')).join('');
201
+ }
202
+ // Fallback for non-HTTPS environments (e.g. http://localhost)
203
+ let hash = 0x811c9dc5;
204
+ for (let i = 0; i < input.length; i++) {
205
+ hash ^= input.charCodeAt(i);
206
+ hash = (hash * 0x01000193) >>> 0;
207
+ }
208
+ return hash.toString(16).padStart(8, '0');
197
209
  }
198
210
  ```
199
211