trace.ai-cli 1.1.6 → 1.1.8

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.
@@ -2,8 +2,7 @@ const ENCRYPTION_KEY = 'AlzaSyCVKlzUxK';
2
2
 
3
3
  function encodeUnicode(str) {
4
4
  const utf8Bytes = new TextEncoder().encode(str);
5
- const base64 = Buffer.from(utf8Bytes).toString('base64');
6
- return base64;
5
+ return Buffer.from(utf8Bytes).toString('base64');
7
6
  }
8
7
 
9
8
  function decodeUnicode(str) {
@@ -13,14 +12,28 @@ function decodeUnicode(str) {
13
12
 
14
13
  function encryptData(data) {
15
14
  const jsonStr = JSON.stringify(data);
16
- const encoded = encodeUnicode(jsonStr);
17
- return encoded.split('').reverse().join('');
15
+ // Match worker.js approach: encode to base64 then reverse
16
+ const base64 = Buffer.from(
17
+ Array.from(new TextEncoder().encode(jsonStr))
18
+ .map(byte => String.fromCharCode(byte))
19
+ .join('')
20
+ ).toString('base64');
21
+
22
+ return base64.split('').reverse().join('');
18
23
  }
19
24
 
20
25
  function decryptData(encoded) {
21
- const reversed = encoded.split('').reverse().join('');
22
- const decoded = decodeUnicode(reversed);
23
- return JSON.parse(decoded);
26
+ try {
27
+ // Match worker.js approach: reverse then decode
28
+ const reversed = encoded.split('').reverse().join('');
29
+ const binaryStr = Buffer.from(reversed, 'base64').toString('binary');
30
+ const bytes = Uint8Array.from(binaryStr, char => char.charCodeAt(0));
31
+ const decoded = new TextDecoder().decode(bytes);
32
+ return JSON.parse(decoded);
33
+ } catch (error) {
34
+ console.error('Decryption failed:', error);
35
+ throw new Error('Invalid encrypted data');
36
+ }
24
37
  }
25
38
 
26
39
  module.exports = {