@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.
- package/package.json +1 -1
- package/pkg/index.js +11 -7
package/package.json
CHANGED
package/pkg/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import initWasmModule from './
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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) {
|