neozipkit 0.8.0 → 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/NEOZIP_APPNOTE.md +527 -0
- package/README.md +57 -21
- package/WHATS_NEW.md +146 -0
- package/dist/browser/ZipkitBrowser.d.ts.map +1 -1
- package/dist/browser/ZipkitBrowser.js +4 -6
- package/dist/browser/ZipkitBrowser.js.map +1 -1
- package/dist/browser/zstd-browser-shim.d.ts +28 -0
- package/dist/browser/zstd-browser-shim.d.ts.map +1 -0
- package/dist/browser/zstd-browser-shim.js +66 -0
- package/dist/browser/zstd-browser-shim.js.map +1 -0
- package/dist/browser-esm/index.js +2110 -41755
- package/dist/browser-esm/index.js.map +4 -4
- package/dist/browser-umd/index.js +2110 -41755
- package/dist/browser-umd/index.js.map +4 -4
- package/dist/browser-umd/index.min.js +3 -21
- package/dist/core/ZipCompress.d.ts +2 -7
- package/dist/core/ZipCompress.d.ts.map +1 -1
- package/dist/core/ZipCompress.js +57 -33
- package/dist/core/ZipCompress.js.map +1 -1
- package/dist/core/ZipDecompress.d.ts +1 -3
- package/dist/core/ZipDecompress.d.ts.map +1 -1
- package/dist/core/ZipDecompress.js +27 -17
- package/dist/core/ZipDecompress.js.map +1 -1
- package/dist/core/ZipEntry.d.ts +6 -0
- package/dist/core/ZipEntry.d.ts.map +1 -1
- package/dist/core/ZipEntry.js +7 -1
- package/dist/core/ZipEntry.js.map +1 -1
- package/dist/core/Zipkit.d.ts +43 -11
- package/dist/core/Zipkit.d.ts.map +1 -1
- package/dist/core/Zipkit.js +106 -63
- package/dist/core/Zipkit.js.map +1 -1
- package/dist/core/components/HashCalculator.d.ts +22 -1
- package/dist/core/components/HashCalculator.d.ts.map +1 -1
- package/dist/core/components/HashCalculator.js +49 -6
- package/dist/core/components/HashCalculator.js.map +1 -1
- package/dist/core/components/Util.d.ts +3 -4
- package/dist/core/components/Util.d.ts.map +1 -1
- package/dist/core/components/Util.js +10 -8
- package/dist/core/components/Util.js.map +1 -1
- package/dist/core/constants/Headers.d.ts +1 -3
- package/dist/core/constants/Headers.d.ts.map +1 -1
- package/dist/core/constants/Headers.js +14 -5
- package/dist/core/constants/Headers.js.map +1 -1
- package/dist/core/constants/MetaPaths.d.ts +38 -0
- package/dist/core/constants/MetaPaths.d.ts.map +1 -0
- package/dist/core/constants/MetaPaths.js +79 -0
- package/dist/core/constants/MetaPaths.js.map +1 -0
- package/dist/core/encryption/AesCrypto.d.ts +55 -11
- package/dist/core/encryption/AesCrypto.d.ts.map +1 -1
- package/dist/core/encryption/AesCrypto.js +223 -68
- package/dist/core/encryption/AesCrypto.js.map +1 -1
- package/dist/core/encryption/index.d.ts +1 -1
- package/dist/core/encryption/index.d.ts.map +1 -1
- package/dist/core/encryption/index.js +3 -1
- package/dist/core/encryption/index.js.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +14 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/merkle/MerkleRoot.d.ts +109 -0
- package/dist/core/merkle/MerkleRoot.d.ts.map +1 -0
- package/dist/core/merkle/MerkleRoot.js +275 -0
- package/dist/core/merkle/MerkleRoot.js.map +1 -0
- package/dist/core/version.js +1 -1
- package/dist/node/LegacyZstd.d.ts +67 -0
- package/dist/node/LegacyZstd.d.ts.map +1 -0
- package/dist/node/LegacyZstd.js +209 -0
- package/dist/node/LegacyZstd.js.map +1 -0
- package/dist/node/ZipCompressNode.d.ts +9 -7
- package/dist/node/ZipCompressNode.d.ts.map +1 -1
- package/dist/node/ZipCompressNode.js +105 -75
- package/dist/node/ZipCompressNode.js.map +1 -1
- package/dist/node/ZipDecompressNode.d.ts +7 -3
- package/dist/node/ZipDecompressNode.d.ts.map +1 -1
- package/dist/node/ZipDecompressNode.js +68 -56
- package/dist/node/ZipDecompressNode.js.map +1 -1
- package/dist/node/ZipkitNode.d.ts +23 -0
- package/dist/node/ZipkitNode.d.ts.map +1 -1
- package/dist/node/ZipkitNode.js +195 -41
- package/dist/node/ZipkitNode.js.map +1 -1
- package/dist/node/ZstdNode.d.ts +39 -0
- package/dist/node/ZstdNode.d.ts.map +1 -0
- package/dist/node/ZstdNode.js +171 -0
- package/dist/node/ZstdNode.js.map +1 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +11 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +4 -3
- package/src/browser/ZipkitBrowser.ts +4 -6
- package/src/browser/zstd-browser-shim.ts +76 -0
- package/src/core/ZipCompress.ts +71 -42
- package/src/core/ZipDecompress.ts +35 -18
- package/src/core/ZipEntry.ts +8 -1
- package/src/core/Zipkit.ts +149 -76
- package/src/core/components/HashCalculator.ts +58 -6
- package/src/core/components/Util.ts +16 -7
- package/src/core/constants/Headers.ts +14 -4
- package/src/core/constants/MetaPaths.ts +86 -0
- package/src/core/encryption/AesCrypto.ts +265 -86
- package/src/core/encryption/index.ts +1 -1
- package/src/core/index.ts +14 -0
- package/src/core/merkle/MerkleRoot.ts +312 -0
- package/src/core/version.ts +1 -1
- package/src/node/LegacyZstd.ts +270 -0
- package/src/node/ZipCompressNode.ts +127 -84
- package/src/node/ZipDecompressNode.ts +93 -67
- package/src/node/ZipkitNode.ts +230 -42
- package/src/node/ZstdNode.ts +155 -0
- package/src/node/index.ts +10 -0
- package/dist/core/ZstdManager.d.ts +0 -56
- package/dist/core/ZstdManager.d.ts.map +0 -1
- package/dist/core/ZstdManager.js +0 -144
- package/dist/core/ZstdManager.js.map +0 -1
- package/src/core/ZstdManager.ts +0 -165
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
//
|
|
14
14
|
// Extra field 0x9901 (11 bytes):
|
|
15
15
|
// [header ID (2)] [data size (2)] [vendor version (2)] [vendor ID (2)] [strength (1)] [real method (2)]
|
|
16
|
+
//
|
|
17
|
+
// Streaming helpers (AesEncryptor / AesDecryptor) keep only a 16-byte CTR block in
|
|
18
|
+
// flight so Node create/extract can chunk large AE-1/AE-2 entries.
|
|
16
19
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
20
|
if (k2 === undefined) k2 = k;
|
|
18
21
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -47,12 +50,192 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
47
50
|
};
|
|
48
51
|
})();
|
|
49
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.AesCrypto = void 0;
|
|
53
|
+
exports.AesCrypto = exports.AesDecryptor = exports.AesEncryptor = void 0;
|
|
51
54
|
const crypto = __importStar(require("crypto"));
|
|
52
55
|
const Headers_1 = require("../constants/Headers");
|
|
53
56
|
const COMPOSITE_KEY_LENGTH = 2 * Headers_1.AES256_KEY_SIZE + Headers_1.AES256_PWD_VERIFY_SIZE; // 66 bytes
|
|
54
57
|
const PBKDF2_ITERATIONS = 1000;
|
|
55
58
|
const AES_BLOCK_SIZE = 16;
|
|
59
|
+
/** Little-endian AES-CTR keystream (WinZip counter starts at 1). */
|
|
60
|
+
class AesCtrEngine {
|
|
61
|
+
constructor(aesKey) {
|
|
62
|
+
this.aesKey = aesKey;
|
|
63
|
+
this.counter = Buffer.alloc(AES_BLOCK_SIZE);
|
|
64
|
+
this.counter[0] = 1;
|
|
65
|
+
this.keystream = this.encryptCounter();
|
|
66
|
+
this.ksPos = 0;
|
|
67
|
+
}
|
|
68
|
+
process(data) {
|
|
69
|
+
if (data.length === 0) {
|
|
70
|
+
return Buffer.alloc(0);
|
|
71
|
+
}
|
|
72
|
+
const result = Buffer.alloc(data.length);
|
|
73
|
+
for (let i = 0; i < data.length; i++) {
|
|
74
|
+
if (this.ksPos >= AES_BLOCK_SIZE) {
|
|
75
|
+
AesCtrEngine.incrementCounterLE(this.counter);
|
|
76
|
+
this.keystream = this.encryptCounter();
|
|
77
|
+
this.ksPos = 0;
|
|
78
|
+
}
|
|
79
|
+
result[i] = data[i] ^ this.keystream[this.ksPos++];
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
encryptCounter() {
|
|
84
|
+
const cipher = crypto.createCipheriv('aes-256-ecb', this.aesKey, null);
|
|
85
|
+
cipher.setAutoPadding(false);
|
|
86
|
+
return cipher.update(this.counter);
|
|
87
|
+
}
|
|
88
|
+
static incrementCounterLE(counter) {
|
|
89
|
+
for (let i = 0; i < AES_BLOCK_SIZE; i++) {
|
|
90
|
+
if (counter[i] === 255) {
|
|
91
|
+
counter[i] = 0;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
counter[i]++;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Streaming AE-1/AE-2 encryptor for ZIP entry payloads.
|
|
102
|
+
*
|
|
103
|
+
* Usage: `header()` once → `update(compressedChunk)` repeatedly → `finish()` for HMAC.
|
|
104
|
+
*/
|
|
105
|
+
class AesEncryptor {
|
|
106
|
+
constructor(password) {
|
|
107
|
+
this.headerSent = false;
|
|
108
|
+
this.finished = false;
|
|
109
|
+
this.salt = crypto.randomBytes(Headers_1.AES256_SALT_SIZE);
|
|
110
|
+
this.keys = AesCrypto.deriveKeys(password, this.salt);
|
|
111
|
+
this.ctr = new AesCtrEngine(this.keys.aesKey);
|
|
112
|
+
this.hmac = crypto.createHmac('sha1', this.keys.hmacKey);
|
|
113
|
+
}
|
|
114
|
+
/** salt (16) + password verifier (2). Write before any ciphertext. */
|
|
115
|
+
header() {
|
|
116
|
+
if (this.finished) {
|
|
117
|
+
throw new Error('AesEncryptor already finished');
|
|
118
|
+
}
|
|
119
|
+
this.headerSent = true;
|
|
120
|
+
return Buffer.concat([this.salt, this.keys.passwordVerifier]);
|
|
121
|
+
}
|
|
122
|
+
/** Encrypt one compressed-data chunk; updates HMAC over ciphertext. */
|
|
123
|
+
update(plain) {
|
|
124
|
+
if (this.finished) {
|
|
125
|
+
throw new Error('AesEncryptor already finished');
|
|
126
|
+
}
|
|
127
|
+
if (!this.headerSent) {
|
|
128
|
+
throw new Error('AesEncryptor.header() must be called before update()');
|
|
129
|
+
}
|
|
130
|
+
if (plain.length === 0) {
|
|
131
|
+
return Buffer.alloc(0);
|
|
132
|
+
}
|
|
133
|
+
const cipher = this.ctr.process(plain);
|
|
134
|
+
this.hmac.update(cipher);
|
|
135
|
+
return cipher;
|
|
136
|
+
}
|
|
137
|
+
/** Final 10-byte authentication code. */
|
|
138
|
+
finish() {
|
|
139
|
+
if (this.finished) {
|
|
140
|
+
throw new Error('AesEncryptor already finished');
|
|
141
|
+
}
|
|
142
|
+
if (!this.headerSent) {
|
|
143
|
+
throw new Error('AesEncryptor.header() must be called before finish()');
|
|
144
|
+
}
|
|
145
|
+
this.finished = true;
|
|
146
|
+
return this.hmac.digest().subarray(0, Headers_1.AES_AUTH_CODE_SIZE);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.AesEncryptor = AesEncryptor;
|
|
150
|
+
/**
|
|
151
|
+
* Streaming AE-1/AE-2 decryptor. `compressedSize` is the full ZIP payload length
|
|
152
|
+
* (salt + verifier + ciphertext + auth), as stored in the local/central header.
|
|
153
|
+
*/
|
|
154
|
+
class AesDecryptor {
|
|
155
|
+
constructor(password, compressedSize) {
|
|
156
|
+
this.keys = null;
|
|
157
|
+
this.ctr = null;
|
|
158
|
+
this.hmac = null;
|
|
159
|
+
this.headerBuf = Buffer.alloc(0);
|
|
160
|
+
this.authBuf = Buffer.alloc(0);
|
|
161
|
+
this.headerDone = false;
|
|
162
|
+
this.verified = false;
|
|
163
|
+
if (compressedSize < Headers_1.AES_OVERHEAD) {
|
|
164
|
+
throw new Error('AES decryption failed: payload too short');
|
|
165
|
+
}
|
|
166
|
+
this.password = password;
|
|
167
|
+
this.cipherLen = compressedSize - Headers_1.AES_OVERHEAD;
|
|
168
|
+
this.remainingCipher = this.cipherLen;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Feed the next archive chunk. Returns decrypted compressed bytes
|
|
172
|
+
* (empty while still reading salt/verifier).
|
|
173
|
+
*/
|
|
174
|
+
push(chunk) {
|
|
175
|
+
let data = chunk;
|
|
176
|
+
if (!this.headerDone) {
|
|
177
|
+
this.headerBuf = Buffer.concat([this.headerBuf, data]);
|
|
178
|
+
const need = Headers_1.AES256_SALT_SIZE + Headers_1.AES256_PWD_VERIFY_SIZE;
|
|
179
|
+
if (this.headerBuf.length < need) {
|
|
180
|
+
return Buffer.alloc(0);
|
|
181
|
+
}
|
|
182
|
+
const salt = this.headerBuf.subarray(0, Headers_1.AES256_SALT_SIZE);
|
|
183
|
+
const storedVerifier = this.headerBuf.subarray(Headers_1.AES256_SALT_SIZE, need);
|
|
184
|
+
this.keys = AesCrypto.deriveKeys(this.password, salt);
|
|
185
|
+
if (!this.keys.passwordVerifier.equals(storedVerifier)) {
|
|
186
|
+
throw new Error('AES decryption failed: wrong password');
|
|
187
|
+
}
|
|
188
|
+
this.ctr = new AesCtrEngine(this.keys.aesKey);
|
|
189
|
+
this.hmac = crypto.createHmac('sha1', this.keys.hmacKey);
|
|
190
|
+
this.headerDone = true;
|
|
191
|
+
data = this.headerBuf.subarray(need);
|
|
192
|
+
this.headerBuf = Buffer.alloc(0);
|
|
193
|
+
}
|
|
194
|
+
if (data.length === 0) {
|
|
195
|
+
return Buffer.alloc(0);
|
|
196
|
+
}
|
|
197
|
+
const cipherTake = Math.min(data.length, this.remainingCipher);
|
|
198
|
+
const cipherPart = data.subarray(0, cipherTake);
|
|
199
|
+
const rest = data.subarray(cipherTake);
|
|
200
|
+
if (rest.length > 0) {
|
|
201
|
+
this.authBuf = Buffer.concat([this.authBuf, rest]);
|
|
202
|
+
}
|
|
203
|
+
if (cipherPart.length === 0) {
|
|
204
|
+
this.tryVerify();
|
|
205
|
+
return Buffer.alloc(0);
|
|
206
|
+
}
|
|
207
|
+
this.hmac.update(cipherPart);
|
|
208
|
+
const plain = this.ctr.process(cipherPart);
|
|
209
|
+
this.remainingCipher -= cipherPart.length;
|
|
210
|
+
this.tryVerify();
|
|
211
|
+
return plain;
|
|
212
|
+
}
|
|
213
|
+
/** Ensure ciphertext is complete and HMAC verified. */
|
|
214
|
+
end() {
|
|
215
|
+
if (this.remainingCipher > 0) {
|
|
216
|
+
throw new Error('AES decryption failed: truncated ciphertext');
|
|
217
|
+
}
|
|
218
|
+
this.tryVerify();
|
|
219
|
+
if (!this.verified) {
|
|
220
|
+
throw new Error('AES decryption failed: missing authentication code');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
tryVerify() {
|
|
224
|
+
if (this.verified || this.remainingCipher > 0 || !this.hmac) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (this.authBuf.length < Headers_1.AES_AUTH_CODE_SIZE) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const stored = this.authBuf.subarray(0, Headers_1.AES_AUTH_CODE_SIZE);
|
|
231
|
+
const calculated = this.hmac.digest().subarray(0, Headers_1.AES_AUTH_CODE_SIZE);
|
|
232
|
+
if (!calculated.equals(stored)) {
|
|
233
|
+
throw new Error('AES decryption failed: authentication code mismatch (data corrupted or tampered)');
|
|
234
|
+
}
|
|
235
|
+
this.verified = true;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.AesDecryptor = AesDecryptor;
|
|
56
239
|
/**
|
|
57
240
|
* WinZip AES-256 encryption/decryption for ZIP files.
|
|
58
241
|
*
|
|
@@ -73,19 +256,31 @@ class AesCrypto {
|
|
|
73
256
|
passwordVerifier: compositeKey.subarray(2 * Headers_1.AES256_KEY_SIZE),
|
|
74
257
|
};
|
|
75
258
|
}
|
|
259
|
+
/** Create a streaming AE-1/AE-2 encryptor. */
|
|
260
|
+
static createEncryptor(password) {
|
|
261
|
+
return new AesEncryptor(password);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Create a streaming AE-1/AE-2 decryptor.
|
|
265
|
+
* @param compressedSize Full payload size including salt, verifier, and auth code.
|
|
266
|
+
*/
|
|
267
|
+
static createDecryptor(password, compressedSize) {
|
|
268
|
+
return new AesDecryptor(password, compressedSize);
|
|
269
|
+
}
|
|
76
270
|
/**
|
|
77
271
|
* Encrypt compressed data using WinZip AES-256.
|
|
78
272
|
*
|
|
79
273
|
* @returns Buffer: salt(16) + verifier(2) + encryptedData + hmac(10)
|
|
80
274
|
*/
|
|
81
275
|
static encryptBuffer(entry, compressedData, password) {
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
276
|
+
void entry;
|
|
277
|
+
const enc = AesCrypto.createEncryptor(password);
|
|
278
|
+
const parts = [enc.header()];
|
|
279
|
+
if (compressedData.length > 0) {
|
|
280
|
+
parts.push(enc.update(compressedData));
|
|
281
|
+
}
|
|
282
|
+
parts.push(enc.finish());
|
|
283
|
+
return Buffer.concat(parts);
|
|
89
284
|
}
|
|
90
285
|
/**
|
|
91
286
|
* Decrypt AES-256 encrypted data from a ZIP entry.
|
|
@@ -96,64 +291,25 @@ class AesCrypto {
|
|
|
96
291
|
* @returns Decrypted (compressed) data
|
|
97
292
|
*/
|
|
98
293
|
static decryptBuffer(entry, fullPayload, password) {
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (!keys.passwordVerifier.equals(storedVerifier)) {
|
|
105
|
-
throw new Error('AES decryption failed: wrong password');
|
|
106
|
-
}
|
|
107
|
-
const hmac = crypto.createHmac('sha1', keys.hmacKey);
|
|
108
|
-
hmac.update(encryptedData);
|
|
109
|
-
const calculatedAuthCode = hmac.digest().subarray(0, Headers_1.AES_AUTH_CODE_SIZE);
|
|
110
|
-
if (!calculatedAuthCode.equals(storedAuthCode)) {
|
|
111
|
-
throw new Error('AES decryption failed: authentication code mismatch (data corrupted or tampered)');
|
|
112
|
-
}
|
|
113
|
-
return AesCrypto.aesCtrProcess(keys.aesKey, encryptedData);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* AES-CTR encrypt/decrypt with WinZip's little-endian counter.
|
|
117
|
-
*
|
|
118
|
-
* WinZip uses a counter that starts at 1 and increments in little-endian byte order.
|
|
119
|
-
* Node's built-in aes-256-ctr uses big-endian counter increment, so we process
|
|
120
|
-
* block-by-block with an explicit LE counter to match the WinZip format.
|
|
121
|
-
*/
|
|
122
|
-
static aesCtrProcess(aesKey, data) {
|
|
123
|
-
if (data.length === 0) {
|
|
124
|
-
return Buffer.alloc(0);
|
|
125
|
-
}
|
|
126
|
-
const result = Buffer.alloc(data.length);
|
|
127
|
-
const counter = Buffer.alloc(AES_BLOCK_SIZE);
|
|
128
|
-
counter[0] = 1; // LE counter starts at 1
|
|
129
|
-
let offset = 0;
|
|
130
|
-
while (offset < data.length) {
|
|
131
|
-
// Encrypt the counter block to get keystream
|
|
132
|
-
const cipher = crypto.createCipheriv('aes-256-ecb', aesKey, null);
|
|
133
|
-
cipher.setAutoPadding(false);
|
|
134
|
-
const keystream = cipher.update(counter);
|
|
135
|
-
const blockLen = Math.min(AES_BLOCK_SIZE, data.length - offset);
|
|
136
|
-
for (let i = 0; i < blockLen; i++) {
|
|
137
|
-
result[offset + i] = data[offset + i] ^ keystream[i];
|
|
138
|
-
}
|
|
139
|
-
offset += blockLen;
|
|
140
|
-
AesCrypto.incrementCounterLE(counter);
|
|
141
|
-
}
|
|
142
|
-
return result;
|
|
294
|
+
void entry;
|
|
295
|
+
const dec = AesCrypto.createDecryptor(password, fullPayload.length);
|
|
296
|
+
const out = dec.push(fullPayload);
|
|
297
|
+
dec.end();
|
|
298
|
+
return out;
|
|
143
299
|
}
|
|
144
300
|
/**
|
|
145
|
-
*
|
|
301
|
+
* Decrypt an async chunk stream (Node extract path).
|
|
302
|
+
* Yields decrypted compressed chunks; verifies HMAC when the stream ends.
|
|
146
303
|
*/
|
|
147
|
-
static
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
counter[i]++;
|
|
154
|
-
break;
|
|
304
|
+
static async *decryptStream(password, compressedSize, encryptedStream) {
|
|
305
|
+
const dec = AesCrypto.createDecryptor(password, compressedSize);
|
|
306
|
+
for await (const chunk of encryptedStream) {
|
|
307
|
+
const plain = dec.push(chunk);
|
|
308
|
+
if (plain.length > 0) {
|
|
309
|
+
yield plain;
|
|
155
310
|
}
|
|
156
311
|
}
|
|
312
|
+
dec.end();
|
|
157
313
|
}
|
|
158
314
|
/**
|
|
159
315
|
* Build the WinZip AES extra data field (0x9901).
|
|
@@ -164,19 +320,18 @@ class AesCrypto {
|
|
|
164
320
|
*/
|
|
165
321
|
static buildAesExtraField(realMethod, vendorVersion = 1) {
|
|
166
322
|
const buf = Buffer.alloc(Headers_1.AES_EXTRA_FIELD_SIZE);
|
|
167
|
-
buf.writeUInt16LE(Headers_1.HDR_ID.AES, 0);
|
|
168
|
-
buf.writeUInt16LE(7, 2);
|
|
169
|
-
buf.writeUInt16LE(vendorVersion, 4);
|
|
170
|
-
buf.writeUInt16LE(0x4541, 6); //
|
|
171
|
-
buf.writeUInt8(0x03, 8); //
|
|
172
|
-
buf.writeUInt16LE(realMethod, 9);
|
|
323
|
+
buf.writeUInt16LE(Headers_1.HDR_ID.AES, 0);
|
|
324
|
+
buf.writeUInt16LE(7, 2);
|
|
325
|
+
buf.writeUInt16LE(vendorVersion, 4);
|
|
326
|
+
buf.writeUInt16LE(0x4541, 6); // "AE"
|
|
327
|
+
buf.writeUInt8(0x03, 8); // AES-256
|
|
328
|
+
buf.writeUInt16LE(realMethod, 9);
|
|
173
329
|
return buf;
|
|
174
330
|
}
|
|
175
331
|
/**
|
|
176
332
|
* Parse the AES extra data field (0x9901) from a buffer.
|
|
177
333
|
*
|
|
178
334
|
* @param data - 7-byte data portion of the extra field (without header ID and size)
|
|
179
|
-
* @returns Parsed AES extra field values
|
|
180
335
|
*/
|
|
181
336
|
static parseAesExtraField(data) {
|
|
182
337
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AesCrypto.js","sourceRoot":"","sources":["../../../src/core/encryption/AesCrypto.ts"],"names":[],"mappings":";AAAA,yCAAyC;AACzC,wDAAwD;AACxD,yDAAyD;AACzD,yCAAyC;AACzC,oEAAoE;AACpE,oFAAoF;AACpF,EAAE;AACF,0DAA0D;AAC1D,EAAE;AACF,mCAAmC;AACnC,4FAA4F;AAC5F,EAAE;AACF,iCAAiC;AACjC,0GAA0G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"AesCrypto.js","sourceRoot":"","sources":["../../../src/core/encryption/AesCrypto.ts"],"names":[],"mappings":";AAAA,yCAAyC;AACzC,wDAAwD;AACxD,yDAAyD;AACzD,yCAAyC;AACzC,oEAAoE;AACpE,oFAAoF;AACpF,EAAE;AACF,0DAA0D;AAC1D,EAAE;AACF,mCAAmC;AACnC,4FAA4F;AAC5F,EAAE;AACF,iCAAiC;AACjC,0GAA0G;AAC1G,EAAE;AACF,mFAAmF;AACnF,mEAAmE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEnE,+CAAiC;AAEjC,kDAQ8B;AAE9B,MAAM,oBAAoB,GAAG,CAAC,GAAG,yBAAe,GAAG,gCAAsB,CAAC,CAAC,WAAW;AACtF,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAC/B,MAAM,cAAc,GAAG,EAAE,CAAC;AAQ1B,oEAAoE;AACpE,MAAM,YAAY;IAMhB,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,cAAc,EAAE,CAA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AAE,IAAI,CAAC,CAAC,CAAC,CAAC;YAC/C,kBAAkB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;YACrC,aAAa,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;SACpC,CAAC;IACJ,CAAC;CACF;AAzHD,8BAyHC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Supports traditional ZIP encryption (PKZIP compatible)
|
|
5
5
|
*/
|
|
6
6
|
export { ZipCrypto, crc32, crc32update } from './ZipCrypto';
|
|
7
|
-
export { AesCrypto } from './AesCrypto';
|
|
7
|
+
export { AesCrypto, AesEncryptor, AesDecryptor } from './AesCrypto';
|
|
8
8
|
export { NeoCrypto, NEO_CRYPTO_ALGORITHM_AES256_V1 } from './NeoCrypto';
|
|
9
9
|
export { EncryptionManager } from './Manager';
|
|
10
10
|
export { EncryptionMethod, EncryptionOptions, EncryptionResult, DecryptionResult, EncryptionProvider } from './types';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/encryption/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/encryption/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,SAAS,CAAC"}
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* Supports traditional ZIP encryption (PKZIP compatible)
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.EncryptionMethod = exports.EncryptionManager = exports.NEO_CRYPTO_ALGORITHM_AES256_V1 = exports.NeoCrypto = exports.AesCrypto = exports.crc32update = exports.crc32 = exports.ZipCrypto = void 0;
|
|
8
|
+
exports.EncryptionMethod = exports.EncryptionManager = exports.NEO_CRYPTO_ALGORITHM_AES256_V1 = exports.NeoCrypto = exports.AesDecryptor = exports.AesEncryptor = exports.AesCrypto = exports.crc32update = exports.crc32 = exports.ZipCrypto = void 0;
|
|
9
9
|
var ZipCrypto_1 = require("./ZipCrypto");
|
|
10
10
|
Object.defineProperty(exports, "ZipCrypto", { enumerable: true, get: function () { return ZipCrypto_1.ZipCrypto; } });
|
|
11
11
|
Object.defineProperty(exports, "crc32", { enumerable: true, get: function () { return ZipCrypto_1.crc32; } });
|
|
12
12
|
Object.defineProperty(exports, "crc32update", { enumerable: true, get: function () { return ZipCrypto_1.crc32update; } });
|
|
13
13
|
var AesCrypto_1 = require("./AesCrypto");
|
|
14
14
|
Object.defineProperty(exports, "AesCrypto", { enumerable: true, get: function () { return AesCrypto_1.AesCrypto; } });
|
|
15
|
+
Object.defineProperty(exports, "AesEncryptor", { enumerable: true, get: function () { return AesCrypto_1.AesEncryptor; } });
|
|
16
|
+
Object.defineProperty(exports, "AesDecryptor", { enumerable: true, get: function () { return AesCrypto_1.AesDecryptor; } });
|
|
15
17
|
var NeoCrypto_1 = require("./NeoCrypto");
|
|
16
18
|
Object.defineProperty(exports, "NeoCrypto", { enumerable: true, get: function () { return NeoCrypto_1.NeoCrypto; } });
|
|
17
19
|
Object.defineProperty(exports, "NEO_CRYPTO_ALGORITHM_AES256_V1", { enumerable: true, get: function () { return NeoCrypto_1.NEO_CRYPTO_ALGORITHM_AES256_V1; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/encryption/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,yCAA4D;AAAnD,sGAAA,SAAS,OAAA;AAAE,kGAAA,KAAK,OAAA;AAAE,wGAAA,WAAW,OAAA;AACtC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/encryption/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,yCAA4D;AAAnD,sGAAA,SAAS,OAAA;AAAE,kGAAA,KAAK,OAAA;AAAE,wGAAA,WAAW,OAAA;AACtC,yCAAoE;AAA3D,sGAAA,SAAS,OAAA;AAAE,yGAAA,YAAY,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC9C,yCAAwE;AAA/D,sGAAA,SAAS,OAAA;AAAE,2HAAA,8BAA8B,OAAA;AAClD,qCAA8C;AAArC,4GAAA,iBAAiB,OAAA;AAC1B,iCAMiB;AALf,yGAAA,gBAAgB,OAAA"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -15,11 +15,13 @@ export { default as HashCalculator, HashCalculator as HashCalculatorClass } from
|
|
|
15
15
|
export * from './components/Util';
|
|
16
16
|
export * from './components/Support';
|
|
17
17
|
export { ProgressTracker } from './components/ProgressTracker';
|
|
18
|
+
export * from './merkle/MerkleRoot';
|
|
18
19
|
export { EncryptionManager } from './encryption/Manager';
|
|
19
20
|
export { ZipCrypto, crc32, crc32update, sha256 } from './encryption/ZipCrypto';
|
|
20
21
|
export type { EncryptionMethod, EncryptionOptions, EncryptionResult, DecryptionResult, EncryptionProvider } from './encryption/types';
|
|
21
22
|
export * from '../types';
|
|
22
23
|
export * from './constants/Headers';
|
|
24
|
+
export { META_TOKEN_NZIP, META_TOKEN_NZIP_LEGACY, META_TS_SUBMIT_NZIP, META_TIMESTAMP_NZIP, META_TS_SUBMIT_OTS, META_TIMESTAMP_OTS, META_MANIFEST_JSON, asciiPathEqualsIgnoreCase, isMetaInfPath, isReservedMetaPath, findReservedMetaEntry, } from './constants/MetaPaths';
|
|
23
25
|
export * from './constants/Errors';
|
|
24
26
|
export * from './version';
|
|
25
27
|
export { Logger, configureLoggerFromEnvironment } from './components/Logger';
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACvE,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EACV,WAAW,EACX,UAAU,EACV,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AACnB,eAAe,MAAM,CAAC;AAGtB,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,cAAc,IAAI,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAC/G,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,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|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
22
|
};
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.configureLoggerFromEnvironment = exports.Logger = exports.sha256 = exports.crc32update = exports.crc32 = exports.ZipCrypto = exports.EncryptionManager = exports.ProgressTracker = exports.HashCalculatorClass = exports.HashCalculator = exports.ZipCopy = exports.ZipCompress = void 0;
|
|
24
|
+
exports.configureLoggerFromEnvironment = exports.Logger = exports.findReservedMetaEntry = exports.isReservedMetaPath = exports.isMetaInfPath = exports.asciiPathEqualsIgnoreCase = exports.META_MANIFEST_JSON = exports.META_TIMESTAMP_OTS = exports.META_TS_SUBMIT_OTS = exports.META_TIMESTAMP_NZIP = exports.META_TS_SUBMIT_NZIP = exports.META_TOKEN_NZIP_LEGACY = exports.META_TOKEN_NZIP = exports.sha256 = exports.crc32update = exports.crc32 = exports.ZipCrypto = exports.EncryptionManager = exports.ProgressTracker = exports.HashCalculatorClass = exports.HashCalculator = exports.ZipCopy = exports.ZipCompress = void 0;
|
|
25
25
|
// Core ZIP classes
|
|
26
26
|
const Zipkit_1 = __importDefault(require("./Zipkit"));
|
|
27
27
|
__exportStar(require("./Zipkit"), exports);
|
|
@@ -39,6 +39,7 @@ __exportStar(require("./components/Util"), exports);
|
|
|
39
39
|
__exportStar(require("./components/Support"), exports);
|
|
40
40
|
var ProgressTracker_1 = require("./components/ProgressTracker");
|
|
41
41
|
Object.defineProperty(exports, "ProgressTracker", { enumerable: true, get: function () { return ProgressTracker_1.ProgressTracker; } });
|
|
42
|
+
__exportStar(require("./merkle/MerkleRoot"), exports);
|
|
42
43
|
// Encryption functionality
|
|
43
44
|
var Manager_1 = require("./encryption/Manager");
|
|
44
45
|
Object.defineProperty(exports, "EncryptionManager", { enumerable: true, get: function () { return Manager_1.EncryptionManager; } });
|
|
@@ -50,6 +51,18 @@ Object.defineProperty(exports, "sha256", { enumerable: true, get: function () {
|
|
|
50
51
|
// Types and constants
|
|
51
52
|
__exportStar(require("../types"), exports);
|
|
52
53
|
__exportStar(require("./constants/Headers"), exports);
|
|
54
|
+
var MetaPaths_1 = require("./constants/MetaPaths");
|
|
55
|
+
Object.defineProperty(exports, "META_TOKEN_NZIP", { enumerable: true, get: function () { return MetaPaths_1.META_TOKEN_NZIP; } });
|
|
56
|
+
Object.defineProperty(exports, "META_TOKEN_NZIP_LEGACY", { enumerable: true, get: function () { return MetaPaths_1.META_TOKEN_NZIP_LEGACY; } });
|
|
57
|
+
Object.defineProperty(exports, "META_TS_SUBMIT_NZIP", { enumerable: true, get: function () { return MetaPaths_1.META_TS_SUBMIT_NZIP; } });
|
|
58
|
+
Object.defineProperty(exports, "META_TIMESTAMP_NZIP", { enumerable: true, get: function () { return MetaPaths_1.META_TIMESTAMP_NZIP; } });
|
|
59
|
+
Object.defineProperty(exports, "META_TS_SUBMIT_OTS", { enumerable: true, get: function () { return MetaPaths_1.META_TS_SUBMIT_OTS; } });
|
|
60
|
+
Object.defineProperty(exports, "META_TIMESTAMP_OTS", { enumerable: true, get: function () { return MetaPaths_1.META_TIMESTAMP_OTS; } });
|
|
61
|
+
Object.defineProperty(exports, "META_MANIFEST_JSON", { enumerable: true, get: function () { return MetaPaths_1.META_MANIFEST_JSON; } });
|
|
62
|
+
Object.defineProperty(exports, "asciiPathEqualsIgnoreCase", { enumerable: true, get: function () { return MetaPaths_1.asciiPathEqualsIgnoreCase; } });
|
|
63
|
+
Object.defineProperty(exports, "isMetaInfPath", { enumerable: true, get: function () { return MetaPaths_1.isMetaInfPath; } });
|
|
64
|
+
Object.defineProperty(exports, "isReservedMetaPath", { enumerable: true, get: function () { return MetaPaths_1.isReservedMetaPath; } });
|
|
65
|
+
Object.defineProperty(exports, "findReservedMetaEntry", { enumerable: true, get: function () { return MetaPaths_1.findReservedMetaEntry; } });
|
|
53
66
|
__exportStar(require("./constants/Errors"), exports);
|
|
54
67
|
__exportStar(require("./version"), exports);
|
|
55
68
|
// Logger utility
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;AAEH,mBAAmB;AACnB,sDAA8B;AAC9B,2CAAyB;AACzB,6CAA2B;AAC3B,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AAGpB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAOhB,kBAAe,gBAAM,CAAC;AAEtB,oBAAoB;AACpB,8DAA+G;AAAtG,iIAAA,OAAO,OAAkB;AAAE,qHAAA,cAAc,OAAuB;AACzE,oDAAkC;AAClC,uDAAqC;AACrC,gEAA+D;AAAtD,kHAAA,eAAe,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;AAEH,mBAAmB;AACnB,sDAA8B;AAC9B,2CAAyB;AACzB,6CAA2B;AAC3B,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AAGpB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAOhB,kBAAe,gBAAM,CAAC;AAEtB,oBAAoB;AACpB,8DAA+G;AAAtG,iIAAA,OAAO,OAAkB;AAAE,qHAAA,cAAc,OAAuB;AACzE,oDAAkC;AAClC,uDAAqC;AACrC,gEAA+D;AAAtD,kHAAA,eAAe,OAAA;AACxB,sDAAoC;AAEpC,2BAA2B;AAC3B,gDAAyD;AAAhD,4GAAA,iBAAiB,OAAA;AAC1B,oDAA+E;AAAtE,sGAAA,SAAS,OAAA;AAAE,kGAAA,KAAK,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,mGAAA,MAAM,OAAA;AAG9C,sBAAsB;AACtB,2CAAyB;AACzB,sDAAoC;AACpC,mDAY+B;AAX7B,4GAAA,eAAe,OAAA;AACf,mHAAA,sBAAsB,OAAA;AACtB,gHAAA,mBAAmB,OAAA;AACnB,gHAAA,mBAAmB,OAAA;AACnB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,sHAAA,yBAAyB,OAAA;AACzB,0GAAA,aAAa,OAAA;AACb,+GAAA,kBAAkB,OAAA;AAClB,kHAAA,qBAAqB,OAAA;AAEvB,qDAAmC;AACnC,4CAA0B;AAE1B,iBAAiB;AACjB,8CAA6E;AAApE,gGAAA,MAAM,OAAA;AAAE,wHAAA,8BAA8B,OAAA"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/** Merkle algorithms defined in NEOZIP_APPNOTE.md §6. */
|
|
2
|
+
export type MerkleAlgorithm = 'v0' | 'v1';
|
|
3
|
+
export interface MerkleContentEntry {
|
|
4
|
+
/** Central-directory path (UTF-8 string as stored or as known to the writer). */
|
|
5
|
+
path: string;
|
|
6
|
+
/**
|
|
7
|
+
* Uncompressed payload bytes (same bytes hashed into Extra Field 0x014E).
|
|
8
|
+
* Required for **v1** leaves when `merkleLeafV1` is absent. Optional for **v0** when `contentSha256` is set.
|
|
9
|
+
*/
|
|
10
|
+
content?: Buffer | Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Bare SHA-256 of uncompressed payload (= Extra Field 0x014E), hex or 32-byte Buffer.
|
|
13
|
+
* Used as v0 leaf; for v1 this alone is **not** a leaf (see APPNOTE §6.3).
|
|
14
|
+
*/
|
|
15
|
+
contentSha256?: string | Buffer;
|
|
16
|
+
/**
|
|
17
|
+
* Precomputed APPNOTE §6.3 v1 leaf: SHA-256(0x00 ‖ uncompressed_bytes), hex or 32-byte Buffer.
|
|
18
|
+
* Produced in the same streaming pass as `contentSha256` (create/extract via HashCalculator).
|
|
19
|
+
* Preferred for v1 when present — no second content read.
|
|
20
|
+
*/
|
|
21
|
+
merkleLeafV1?: string | Buffer;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Normalize a ZIP entry path for v1 leaf ordering (APPNOTE §6.3):
|
|
25
|
+
* POSIX separators, strip leading `./` and `/`, Unicode NFC, UTF-8 byte order when compared.
|
|
26
|
+
*/
|
|
27
|
+
export declare function normalizeMerklePath(path: string): string;
|
|
28
|
+
/** Bare content digest (= 0x014E value). */
|
|
29
|
+
export declare function contentDigest(content: Buffer | Uint8Array): Buffer;
|
|
30
|
+
/**
|
|
31
|
+
* v0 leaf: SHA-256(uncompressed bytes) — same as Extra Field 0x014E.
|
|
32
|
+
*/
|
|
33
|
+
export declare function leafHashV0(contentOrDigest: Buffer | Uint8Array, isDigest?: boolean): Buffer;
|
|
34
|
+
/**
|
|
35
|
+
* v1 leaf: SHA-256(0x00 ‖ uncompressed_bytes).
|
|
36
|
+
* Must not be confused with the bare 0x014E digest (APPNOTE §6.3).
|
|
37
|
+
*/
|
|
38
|
+
export declare function leafHashV1(content: Buffer | Uint8Array): Buffer;
|
|
39
|
+
/**
|
|
40
|
+
* Parent node hashes.
|
|
41
|
+
* v0: SHA-256(H_left ‖ H_right) — order preserved, no pair sorting.
|
|
42
|
+
* v1: SHA-256(0x01 ‖ H_left ‖ H_right).
|
|
43
|
+
*/
|
|
44
|
+
export declare function parentHash(left: Buffer, right: Buffer, algorithm: MerkleAlgorithm): Buffer;
|
|
45
|
+
/**
|
|
46
|
+
* Fold an ordered list of leaf hashes into a single root (hex lowercase).
|
|
47
|
+
* Odd-count rule:
|
|
48
|
+
* - v0: duplicate last leaf (Bitcoin-style)
|
|
49
|
+
* - v1: promote last node unhashed (RFC 6962–style)
|
|
50
|
+
*/
|
|
51
|
+
export declare function merkleRootFromLeaves(leaves: Buffer[], algorithm: MerkleAlgorithm): string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Compute archive Merkle root per APPNOTE §6 from content entries
|
|
54
|
+
* (caller already excluded META-INF/** if desired).
|
|
55
|
+
*
|
|
56
|
+
* @returns lowercase hex root, or null if no usable leaves
|
|
57
|
+
*/
|
|
58
|
+
export declare function computeArchiveMerkleRoot(entries: MerkleContentEntry[], algorithm?: MerkleAlgorithm): string | null;
|
|
59
|
+
/**
|
|
60
|
+
* Build v0 root from path + bare content digests only (0x014E extras).
|
|
61
|
+
* Path order: central-directory bytes as stored (no NFC / strip).
|
|
62
|
+
*/
|
|
63
|
+
export declare function computeMerkleRootV0FromDigests(entries: Array<{
|
|
64
|
+
path: string;
|
|
65
|
+
sha256: string | Buffer;
|
|
66
|
+
}>): string | null;
|
|
67
|
+
/**
|
|
68
|
+
* Build v1 root from path + uncompressed payloads (APPNOTE §6.3).
|
|
69
|
+
* Paths are normalized before sorting.
|
|
70
|
+
*/
|
|
71
|
+
export declare function computeMerkleRootV1FromContents(entries: Array<{
|
|
72
|
+
path: string;
|
|
73
|
+
content: Buffer | Uint8Array;
|
|
74
|
+
}>): string | null;
|
|
75
|
+
/**
|
|
76
|
+
* Build v1 root from path + precomputed domain-separated leaves (APPNOTE §6.3).
|
|
77
|
+
* Prefer this after create/extract when HashCalculator produced merkleLeafV1 in one stream pass.
|
|
78
|
+
*/
|
|
79
|
+
export declare function computeMerkleRootV1FromLeaves(entries: Array<{
|
|
80
|
+
path: string;
|
|
81
|
+
merkleLeafV1: string | Buffer;
|
|
82
|
+
}>): string | null;
|
|
83
|
+
/**
|
|
84
|
+
* Verify a declared root (APPNOTE §6.4): try v1 first (when content or leaves available),
|
|
85
|
+
* then v0 digests. Returns which algorithm matched, or null on failure.
|
|
86
|
+
*
|
|
87
|
+
* When only bare 0x014E digests are available, only v0 can match APPNOTE correctly.
|
|
88
|
+
* Pass `merkleLeafV1` or content for full v1 verification without re-hashing from scratch
|
|
89
|
+
* when leaves were computed in the decompress stream.
|
|
90
|
+
*/
|
|
91
|
+
export declare function matchMerkleRoot(entries: MerkleContentEntry[], declaredRoot: string): {
|
|
92
|
+
algorithm: MerkleAlgorithm;
|
|
93
|
+
security: 'high' | 'legacy';
|
|
94
|
+
} | null;
|
|
95
|
+
declare const _default: {
|
|
96
|
+
normalizeMerklePath: typeof normalizeMerklePath;
|
|
97
|
+
contentDigest: typeof contentDigest;
|
|
98
|
+
leafHashV0: typeof leafHashV0;
|
|
99
|
+
leafHashV1: typeof leafHashV1;
|
|
100
|
+
parentHash: typeof parentHash;
|
|
101
|
+
merkleRootFromLeaves: typeof merkleRootFromLeaves;
|
|
102
|
+
computeArchiveMerkleRoot: typeof computeArchiveMerkleRoot;
|
|
103
|
+
computeMerkleRootV0FromDigests: typeof computeMerkleRootV0FromDigests;
|
|
104
|
+
computeMerkleRootV1FromContents: typeof computeMerkleRootV1FromContents;
|
|
105
|
+
computeMerkleRootV1FromLeaves: typeof computeMerkleRootV1FromLeaves;
|
|
106
|
+
matchMerkleRoot: typeof matchMerkleRoot;
|
|
107
|
+
};
|
|
108
|
+
export default _default;
|
|
109
|
+
//# sourceMappingURL=MerkleRoot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MerkleRoot.d.ts","sourceRoot":"","sources":["../../../src/core/merkle/MerkleRoot.ts"],"names":[],"mappings":"AAQA,yDAAyD;AACzD,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1C,MAAM,WAAW,kBAAkB;IACjC,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAC9B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC;AAwBD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYxD;AAQD,4CAA4C;AAC5C,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAElE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,eAAe,EAAE,MAAM,GAAG,UAAU,EAAE,QAAQ,UAAQ,GAAG,MAAM,CAGzF;AAED;;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