@eduarte/chc 0.1.2 → 0.1.4

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 (2) hide show
  1. package/package.json +1 -1
  2. package/pkg/index.js +11 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eduarte/chc",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
package/pkg/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import initWasmModule from './ccu_history_crypto.js';
1
+ import initWasmModule from './chc.js';
2
2
 
3
3
  const XTEA_NONCE_BYTES = 8;
4
4
  const ALGORITHM = 'xtea-ctr-v1';
@@ -113,13 +113,17 @@ async function maybeDecompress(bytes, compression) {
113
113
  if (typeof DecompressionStream === 'undefined') {
114
114
  throw new Error('DecompressionStream is unavailable in current runtime.');
115
115
  }
116
+ if (bytes.length < 2 || bytes[0] !== 0x1f || bytes[1] !== 0x8b) {
117
+ throw new Error('Decrypted payload is not gzip data. Check build-time key and backend key consistency.');
118
+ }
116
119
 
117
- const stream = new DecompressionStream('gzip');
118
- const writer = stream.writable.getWriter();
119
- await writer.write(bytes);
120
- await writer.close();
121
-
122
- return new Uint8Array(await new Response(stream.readable).arrayBuffer());
120
+ try {
121
+ const sourceStream = new Blob([bytes]).stream();
122
+ const decompressedStream = sourceStream.pipeThrough(new DecompressionStream('gzip'));
123
+ return new Uint8Array(await new Response(decompressedStream).arrayBuffer());
124
+ } catch (error) {
125
+ throw new Error(`Failed to decompress gzip payload: ${error instanceof Error ? error.message : String(error)}`);
126
+ }
123
127
  }
124
128
 
125
129
  function decodeBase64Url(value) {