pure-md5 0.1.14 → 0.2.1
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/LICENSE.md +21 -0
- package/README.md +274 -16
- package/dist/adapters/ie11.cjs +1 -0
- package/dist/adapters/ie11.d.cts +20 -0
- package/dist/adapters/ie11.d.ts +20 -0
- package/dist/adapters/ie11.js +1 -0
- package/dist/adapters/node.cjs +1 -0
- package/dist/adapters/node.d.cts +19 -0
- package/dist/adapters/node.d.ts +19 -0
- package/dist/adapters/node.js +1 -0
- package/dist/adapters/webcrypto.cjs +1 -0
- package/dist/adapters/webcrypto.d.cts +21 -0
- package/dist/adapters/webcrypto.d.ts +21 -0
- package/dist/adapters/webcrypto.js +1 -0
- package/dist/core/index.cjs +1 -0
- package/dist/core/index.d.cts +19 -0
- package/dist/core/index.d.ts +19 -0
- package/dist/core/index.js +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +84 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +1 -0
- package/dist/stream/adapter.cjs +1 -0
- package/dist/stream/adapter.d.cts +63 -0
- package/dist/stream/adapter.d.ts +63 -0
- package/dist/stream/adapter.js +1 -0
- package/dist/stream/fs-utils.cjs +1 -0
- package/dist/stream/fs-utils.d.cts +137 -0
- package/dist/stream/fs-utils.d.ts +137 -0
- package/dist/stream/fs-utils.js +1 -0
- package/dist/stream/index.cjs +1 -0
- package/dist/stream/index.d.cts +4 -0
- package/dist/stream/index.d.ts +4 -0
- package/dist/stream/index.js +1 -0
- package/dist/stream/light/index.cjs +1 -0
- package/dist/stream/light/index.d.cts +4 -0
- package/dist/stream/light/index.d.ts +4 -0
- package/dist/stream/light/index.js +1 -0
- package/dist/stream/md5-stream.cjs +1 -0
- package/dist/stream/md5-stream.d.cts +123 -0
- package/dist/stream/md5-stream.d.ts +123 -0
- package/dist/stream/md5-stream.js +1 -0
- package/dist/stream/whatwg-stream.cjs +1 -0
- package/dist/stream/whatwg-stream.d.cts +185 -0
- package/dist/stream/whatwg-stream.d.ts +185 -0
- package/dist/stream/whatwg-stream.js +1 -0
- package/dist/types-edGoGJ5V.d.cts +42 -0
- package/dist/types-edGoGJ5V.d.ts +42 -0
- package/dist/utils/detect.cjs +3 -0
- package/dist/utils/detect.d.cts +110 -0
- package/dist/utils/detect.d.ts +110 -0
- package/dist/utils/detect.js +1 -0
- package/package.json +76 -22
- package/pure-md5-0.2.0.tgz +0 -0
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/lib/index.js.map +0 -1
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 eustatos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,31 +1,289 @@
|
|
|
1
|
-
# pure-
|
|
1
|
+
# pure-md5 🎯
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://npmjs.org/package/pure-md5 "View this project on npm")
|
|
5
|
-
[](https://travis-ci.org/eustatos/pure-md5)
|
|
6
|
-
[](https://codecov.io/gh/eustatos/pure-md5)
|
|
7
|
-
[](https://codeclimate.com/github/eustatos/pure-md5/maintainability)
|
|
8
|
-
[](https://codeclimate.com/github/eustatos/pure-md5/test_coverage)
|
|
3
|
+
**A lightweight, zero-dependency JavaScript library for MD5 hashing with streaming support for large files.**
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
[](https://npmjs.org/package/pure-md5)
|
|
6
|
+
[](https://npmjs.org/package/pure-md5)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://github.com/eustatos/pure-md5/actions/workflows/npm-publish.yml)
|
|
9
|
+
[](https://codecov.io/gh/eustatos/pure-md5)
|
|
10
|
+
[](https://bundlephobia.com/result?p=pure-md5)
|
|
11
|
+
[](https://www.typescriptlang.org/)
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 🚀 Quick Start
|
|
16
|
+
|
|
17
|
+
### Install
|
|
11
18
|
|
|
12
19
|
```bash
|
|
13
|
-
npm install
|
|
20
|
+
npm install pure-md5
|
|
21
|
+
# or
|
|
22
|
+
yarn add pure-md5
|
|
23
|
+
# or
|
|
24
|
+
pnpm add pure-md5
|
|
14
25
|
```
|
|
15
26
|
|
|
16
|
-
|
|
27
|
+
### Basic Usage
|
|
17
28
|
|
|
18
29
|
```javascript
|
|
19
|
-
import {md5} from 'pure-md5';
|
|
30
|
+
import { md5 } from 'pure-md5';
|
|
20
31
|
|
|
21
|
-
const hash = md5('hello');
|
|
32
|
+
const hash = md5('hello');
|
|
33
|
+
console.log(hash); // "5d41402abc4b2a76b9719d911017c592"
|
|
22
34
|
```
|
|
23
35
|
|
|
24
|
-
###
|
|
36
|
+
### Streaming (Large Files)
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
import { createMD5Stream } from 'pure-md5';
|
|
40
|
+
import fs from 'fs';
|
|
41
|
+
|
|
42
|
+
const stream = createMD5Stream();
|
|
43
|
+
stream.on('md5', result => console.log('MD5:', result.digest));
|
|
44
|
+
|
|
45
|
+
fs.createReadStream('large-file.bin').pipe(stream);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## ✨ Features
|
|
51
|
+
|
|
52
|
+
- ⚡ **Zero Dependencies** - No external dependencies, ever
|
|
53
|
+
- 📦 **Tiny Bundle** - < 1KB gzipped
|
|
54
|
+
- 🎯 **Multiple APIs** - Simple, streaming, and promise-based
|
|
55
|
+
- 🦺 **TypeScript Ready** - Full type definitions included
|
|
56
|
+
- 🔌 **Adapter System** - Automatic detection (WebCrypto, Node.js, Pure JS)
|
|
57
|
+
- 📄 **File Hashing** - Stream large files with progress tracking
|
|
58
|
+
- 🌐 **Universal** - Works in Node.js and browsers
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 📚 Documentation
|
|
63
|
+
|
|
64
|
+
- [API Reference](#-api-reference)
|
|
65
|
+
- [Streaming API](STREAM_API.md)
|
|
66
|
+
- [Streaming Examples](STREAM_EXAMPLES.md)
|
|
67
|
+
- [Migration Guide](MIGRATION_GUIDE_STREAMS.md)
|
|
68
|
+
- [Troubleshooting](STREAM_TROUBLESHOOTING.md)
|
|
69
|
+
- [Benchmarks](STREAM_BENCHMARKS.md)
|
|
70
|
+
- [Contributing](#-contributing)
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🛠️ API Reference
|
|
75
|
+
|
|
76
|
+
### Basic MD5
|
|
77
|
+
|
|
78
|
+
#### `md5(message[, encoding])`
|
|
79
|
+
|
|
80
|
+
Compute MD5 hash of a string or buffer.
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
import { md5 } from 'pure-md5';
|
|
84
|
+
|
|
85
|
+
// String input
|
|
86
|
+
md5('hello'); // "5d41402abc4b2a76b9719d911017c592"
|
|
87
|
+
|
|
88
|
+
// Buffer input
|
|
89
|
+
md5(Buffer.from('hello')); // "5d41402abc4b2a76b9719d911017c592"
|
|
90
|
+
|
|
91
|
+
// Custom encoding
|
|
92
|
+
md5('hello', 'hex'); // "5d41402abc4b2a76b9719d911017c592"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Streaming API
|
|
96
|
+
|
|
97
|
+
#### `createMD5Stream()`
|
|
98
|
+
|
|
99
|
+
Create a new MD5Stream instance.
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
import { createMD5Stream } from 'pure-md5';
|
|
103
|
+
|
|
104
|
+
const stream = createMD5Stream();
|
|
105
|
+
stream.on('md5', result => {
|
|
106
|
+
console.log('MD5:', result.digest); // "5d41402abc4b2a76b9719d911017c592"
|
|
107
|
+
console.log('Bytes:', result.bytesProcessed); // 5
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### `pipeThroughMD5(source)`
|
|
112
|
+
|
|
113
|
+
Pipe a stream through MD5 hashing and get a promise.
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
import { pipeThroughMD5, fromReadable } from 'pure-md5';
|
|
117
|
+
|
|
118
|
+
const source = fromReadable(['hello', ' ', 'world']);
|
|
119
|
+
const result = await pipeThroughMD5(source);
|
|
120
|
+
console.log('MD5:', result.digest);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### `fromStream(stream)`
|
|
124
|
+
|
|
125
|
+
Convenience method to create a stream and get result.
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
import { fromStream } from 'pure-md5';
|
|
129
|
+
import fs from 'fs';
|
|
130
|
+
|
|
131
|
+
const { stream, result } = fromStream(fs.createReadStream('file.txt'));
|
|
132
|
+
result.then(r => console.log('MD5:', r.digest));
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### File System Utilities
|
|
136
|
+
|
|
137
|
+
#### `hashFile(filePath, options?)`
|
|
138
|
+
|
|
139
|
+
Hash a file asynchronously.
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
import { hashFile } from 'pure-md5';
|
|
143
|
+
|
|
144
|
+
const result = await hashFile('path/to/file.txt');
|
|
145
|
+
console.log('MD5:', result.digest);
|
|
146
|
+
console.log('Bytes:', result.bytesProcessed);
|
|
147
|
+
|
|
148
|
+
// With progress tracking
|
|
149
|
+
const progress = createProgressTracker(result.bytesProcessed, percent => {
|
|
150
|
+
console.log(`Progress: ${percent.toFixed(1)}%`);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const result = await hashFile('large-file.bin', { onProgress: progress });
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### `hashFileDigest(filePath)`
|
|
157
|
+
|
|
158
|
+
Hash a file and return only the digest.
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
import { hashFileDigest } from 'pure-md5';
|
|
162
|
+
|
|
163
|
+
const digest = await hashFileDigest('path/to/file.txt');
|
|
164
|
+
console.log('MD5:', digest);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### `hashFileSync(filePath)`
|
|
168
|
+
|
|
169
|
+
Hash a file synchronously (for small files).
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
import { hashFileSync } from 'pure-md5';
|
|
173
|
+
|
|
174
|
+
const digest = hashFileSync('small-file.txt');
|
|
175
|
+
console.log('MD5:', digest);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### `verifyFile(filePath, expectedDigest)`
|
|
179
|
+
|
|
180
|
+
Verify file integrity using MD5.
|
|
181
|
+
|
|
182
|
+
```javascript
|
|
183
|
+
import { verifyFile } from 'pure-md5';
|
|
184
|
+
|
|
185
|
+
const isVerified = await verifyFile('path/to/file.txt', '5d41402abc4b2a76b9719d911017c592');
|
|
186
|
+
console.log('Verified:', isVerified); // true or false
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### CDN Usage
|
|
25
190
|
|
|
26
191
|
```html
|
|
27
|
-
<script src="https://unpkg.com/pure-md5@latest/
|
|
192
|
+
<script src="https://unpkg.com/pure-md5@latest/dist/index.js"></script>
|
|
28
193
|
<script>
|
|
29
|
-
|
|
194
|
+
console.log(md5('hello')); // "5d41402abc4b2a76b9719d911017c592"
|
|
30
195
|
</script>
|
|
31
|
-
```
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## 📊 Comparison with Alternatives
|
|
201
|
+
|
|
202
|
+
| Feature | pure-md5 | crypto-js | js-md4 | Node.js crypto |
|
|
203
|
+
|---------|----------|-----------|--------|----------------|
|
|
204
|
+
| Bundle Size | <1KB | ~4KB | ~2KB | N/A |
|
|
205
|
+
| Dependencies | 0 | 0 | 0 | 0 |
|
|
206
|
+
| Streaming | ✅ | ❌ | ❌ | ✅ |
|
|
207
|
+
| Browser Support | ✅ | ✅ | ✅ | ❌ |
|
|
208
|
+
| TypeScript | ✅ | ❌ | ⚠️ | ❌ |
|
|
209
|
+
| Zero Config | ✅ | ✅ | ❌ | ✅ |
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 🔧 Configuration
|
|
214
|
+
|
|
215
|
+
### Node.js
|
|
216
|
+
|
|
217
|
+
```javascript
|
|
218
|
+
// Node.js adapter is auto-detected
|
|
219
|
+
import { md5 } from 'pure-md5';
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Browser
|
|
223
|
+
|
|
224
|
+
```javascript
|
|
225
|
+
// WebCrypto adapter is auto-detected
|
|
226
|
+
import { md5 } from 'pure-md5';
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Manual Adapter Selection
|
|
230
|
+
|
|
231
|
+
```javascript
|
|
232
|
+
import { md5 } from 'pure-md5/adapters/node';
|
|
233
|
+
// or
|
|
234
|
+
import { md5 } from 'pure-md5/adapters/webcrypto';
|
|
235
|
+
// or
|
|
236
|
+
import { md5 } from 'pure-md5/adapters/pure-js';
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 🤝 Contributing
|
|
242
|
+
|
|
243
|
+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
244
|
+
|
|
245
|
+
### Setup
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
git clone https://github.com/eustatos/pure-md5.git
|
|
249
|
+
cd pure-md5
|
|
250
|
+
npm install
|
|
251
|
+
npm test
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Running Tests
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
npm test # Run all tests
|
|
258
|
+
npm run coverage # Generate coverage report
|
|
259
|
+
npm run build:watch # Build in watch mode
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## 📄 License
|
|
265
|
+
|
|
266
|
+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## 💙 Support This Project
|
|
271
|
+
|
|
272
|
+
If you find this project helpful, please consider supporting it:
|
|
273
|
+
|
|
274
|
+
- ⭐ Star this repository
|
|
275
|
+
- 🐦 Tweet about it
|
|
276
|
+
- 💬 Share with your community
|
|
277
|
+
- 🍺 Buy me a coffee (coming soon)
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## 📚 Related Resources
|
|
282
|
+
|
|
283
|
+
- [MD5 on Wikipedia](https://en.wikipedia.org/wiki/MD5)
|
|
284
|
+
- [RFC 1321 - The MD5 Message-Digest Algorithm](https://www.ietf.org/rfc/rfc1321.txt)
|
|
285
|
+
- [Node.js crypto documentation](https://nodejs.org/api/crypto.html)
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
*Made with ❤️ by [Aleksandr Astashkin](https://github.com/eustatos)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var n=class{constructor(){this.name="ie11";this.version="1.0.0";}static isAvailable(){if(typeof window>"u")return false;let r=window;return typeof r.msCrypto<"u"&&typeof r.msCrypto.subtle<"u"&&typeof r.msCrypto.subtle.digest=="function"}async hash(r){let e=new TextEncoder().encode(r);return await this.hashBinary(e)}async hashBinary(r){let t=window,e=r instanceof Uint8Array?r.buffer:r,i=await t.msCrypto.subtle.digest("MD5",e);return this.bufferToHex(i)}bufferToHex(r){return Array.from(new Uint8Array(r)).map(t=>t.toString(16).padStart(2,"0")).join("")}update(r){throw new Error("msCrypto does not support streaming updates")}digest(r){throw new Error("msCrypto does not support streaming")}reset(){}};exports.IE11Backend=n;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { M as MD5Backend } from '../types-edGoGJ5V.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* IE11 msCrypto Backend
|
|
5
|
+
* Uses Internet Explorer 11 msCrypto API for MD5 hashing
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare class IE11Backend implements MD5Backend {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
static isAvailable(): boolean;
|
|
12
|
+
hash(data: string): Promise<string>;
|
|
13
|
+
hashBinary(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
14
|
+
private bufferToHex;
|
|
15
|
+
update(_data: string | ArrayBuffer | Uint8Array): void | Promise<void>;
|
|
16
|
+
digest(_encoding?: "hex" | "buffer"): string | Uint8Array | Promise<string | Uint8Array>;
|
|
17
|
+
reset(): void | Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { IE11Backend };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { M as MD5Backend } from '../types-edGoGJ5V.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* IE11 msCrypto Backend
|
|
5
|
+
* Uses Internet Explorer 11 msCrypto API for MD5 hashing
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare class IE11Backend implements MD5Backend {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
static isAvailable(): boolean;
|
|
12
|
+
hash(data: string): Promise<string>;
|
|
13
|
+
hashBinary(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
14
|
+
private bufferToHex;
|
|
15
|
+
update(_data: string | ArrayBuffer | Uint8Array): void | Promise<void>;
|
|
16
|
+
digest(_encoding?: "hex" | "buffer"): string | Uint8Array | Promise<string | Uint8Array>;
|
|
17
|
+
reset(): void | Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { IE11Backend };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{a as IE11Backend}from'../chunk-QB6MF5LD.js';import'../chunk-I7AUKTXE.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var n=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(r,t)=>(typeof require<"u"?require:r)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var i=class{constructor(){this.name="nodecrypto";this.version="1.0.0";}static isAvailable(){try{return typeof n("crypto").createHash=="function"}catch{return false}}hash(r){return n("crypto").createHash("md5").update(r).digest("hex")}async hashBinary(r){let t=n("crypto"),o=r instanceof Uint8Array?r:new Uint8Array(r);return t.createHash("md5").update(o).digest("hex")}update(r){}digest(r){throw new Error("Node crypto streaming not implemented")}reset(){}};exports.NodeCryptoBackend=i;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { M as MD5Backend } from '../types-edGoGJ5V.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Node.js Crypto Backend
|
|
5
|
+
* Uses Node.js native crypto module for MD5 hashing
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare class NodeCryptoBackend implements MD5Backend {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
static isAvailable(): boolean;
|
|
12
|
+
hash(data: string): string;
|
|
13
|
+
hashBinary(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
14
|
+
update(_data: string | ArrayBuffer | Uint8Array): void | Promise<void>;
|
|
15
|
+
digest(_encoding?: "hex" | "buffer"): string | Uint8Array | Promise<string | Uint8Array>;
|
|
16
|
+
reset(): void | Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { NodeCryptoBackend };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { M as MD5Backend } from '../types-edGoGJ5V.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Node.js Crypto Backend
|
|
5
|
+
* Uses Node.js native crypto module for MD5 hashing
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare class NodeCryptoBackend implements MD5Backend {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
static isAvailable(): boolean;
|
|
12
|
+
hash(data: string): string;
|
|
13
|
+
hashBinary(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
14
|
+
update(_data: string | ArrayBuffer | Uint8Array): void | Promise<void>;
|
|
15
|
+
digest(_encoding?: "hex" | "buffer"): string | Uint8Array | Promise<string | Uint8Array>;
|
|
16
|
+
reset(): void | Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { NodeCryptoBackend };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{a as NodeCryptoBackend}from'../chunk-XPYPJSJE.js';import'../chunk-I7AUKTXE.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var C="0123456789abcdef".split(""),p=C;function B(o){let n="";for(let m=0;m<4;m++)n+=p[o>>m*8+4&15]+p[o>>m*8&15];return n}function P(o){let n=o.length,m=new Array(n);for(let e=0;e<n;e++)m[e]=B(o[e]);return m.join("")}var g=P;function D(o,n){return o+n&4294967295}var c=D;function U(o,n,m,e,r){let t=r||c;return n=t(t(n,o),t(m,e)),n}function _(o,n,m,e){var t=(e||c)(o<<n|o>>>32-n,m);return t}function s(o,n,m,e,r,t,u){return n=U(o,n,e,t,u),_(n,r,m,u)}function h(o,n,m,e,r,t,u,i){return s(m&e|~m&r,n,m,t,u,i,o)}function y(o,n,m,e,r,t,u,i){return s(m&r|e&~r,n,m,t,u,i,o)}function A(o,n,m,e,r,t,u,i){return s(m^e^r,n,m,t,u,i,o)}function x(o,n,m,e,r,t,u,i){return s(e^(m|~r),n,m,t,u,i,o)}function j(o,n,m){typeof m>"u"&&(m=c);let e=o[0],r=o[1],t=o[2],u=o[3],i=h.bind(null,m);e=i(e,r,t,u,n[0],7,-680876936),u=i(u,e,r,t,n[1],12,-389564586),t=i(t,u,e,r,n[2],17,606105819),r=i(r,t,u,e,n[3],22,-1044525330),e=i(e,r,t,u,n[4],7,-176418897),u=i(u,e,r,t,n[5],12,1200080426),t=i(t,u,e,r,n[6],17,-1473231341),r=i(r,t,u,e,n[7],22,-45705983),e=i(e,r,t,u,n[8],7,1770035416),u=i(u,e,r,t,n[9],12,-1958414417),t=i(t,u,e,r,n[10],17,-42063),r=i(r,t,u,e,n[11],22,-1990404162),e=i(e,r,t,u,n[12],7,1804603682),u=i(u,e,r,t,n[13],12,-40341101),t=i(t,u,e,r,n[14],17,-1502002290),r=i(r,t,u,e,n[15],22,1236535329);let d=y.bind(null,m);e=d(e,r,t,u,n[1],5,-165796510),u=d(u,e,r,t,n[6],9,-1069501632),t=d(t,u,e,r,n[11],14,643717713),r=d(r,t,u,e,n[0],20,-373897302),e=d(e,r,t,u,n[5],5,-701558691),u=d(u,e,r,t,n[10],9,38016083),t=d(t,u,e,r,n[15],14,-660478335),r=d(r,t,u,e,n[4],20,-405537848),e=d(e,r,t,u,n[9],5,568446438),u=d(u,e,r,t,n[14],9,-1019803690),t=d(t,u,e,r,n[3],14,-187363961),r=d(r,t,u,e,n[8],20,1163531501),e=d(e,r,t,u,n[13],5,-1444681467),u=d(u,e,r,t,n[2],9,-51403784),t=d(t,u,e,r,n[7],14,1735328473),r=d(r,t,u,e,n[12],20,-1926607734);let b=A.bind(null,m);e=b(e,r,t,u,n[5],4,-378558),u=b(u,e,r,t,n[8],11,-2022574463),t=b(t,u,e,r,n[11],16,1839030562),r=b(r,t,u,e,n[14],23,-35309556),e=b(e,r,t,u,n[1],4,-1530992060),u=b(u,e,r,t,n[4],11,1272893353),t=b(t,u,e,r,n[7],16,-155497632),r=b(r,t,u,e,n[10],23,-1094730640),e=b(e,r,t,u,n[13],4,681279174),u=b(u,e,r,t,n[0],11,-358537222),t=b(t,u,e,r,n[3],16,-722521979),r=b(r,t,u,e,n[6],23,76029189),e=b(e,r,t,u,n[9],4,-640364487),u=b(u,e,r,t,n[12],11,-421815835),t=b(t,u,e,r,n[15],16,530742520),r=b(r,t,u,e,n[2],23,-995338651);let f=x.bind(null,m);e=f(e,r,t,u,n[0],6,-198630844),u=f(u,e,r,t,n[7],10,1126891415),t=f(t,u,e,r,n[14],15,-1416354905),r=f(r,t,u,e,n[5],21,-57434055),e=f(e,r,t,u,n[12],6,1700485571),u=f(u,e,r,t,n[3],10,-1894986606),t=f(t,u,e,r,n[10],15,-1051523),r=f(r,t,u,e,n[1],21,-2054922799),e=f(e,r,t,u,n[8],6,1873313359),u=f(u,e,r,t,n[15],10,-30611744),t=f(t,u,e,r,n[6],15,-1560198380),r=f(r,t,u,e,n[13],21,1309151649),e=f(e,r,t,u,n[4],6,-145523070),u=f(u,e,r,t,n[11],10,-1120210379),t=f(t,u,e,r,n[2],15,718787259),r=f(r,t,u,e,n[9],21,-343485551),o[0]=m(e,o[0]),o[1]=m(r,o[1]),o[2]=m(t,o[2]),o[3]=m(u,o[3]);}var l=j;function E(o){let n=[];for(let m=0;m<64;m+=4)n[m>>2]=(o.charCodeAt(m)||0)+((o.charCodeAt(m+1)||0)<<8)+((o.charCodeAt(m+2)||0)<<16)+((o.charCodeAt(m+3)||0)<<24);return n}var F=E;function I(o,n){let m=o.length,e=[1732584193,-271733879,-1732584194,271733878],r;for(r=64;r<=m;r+=64)l(e,F(o.substring(r-64,r)),n);o=o.substring(r-64);var t=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],u=o.length;for(r=0;r<u;r++)t[r>>2]|=(o.charCodeAt(r)&255)<<(r%4<<3);if(t[r>>2]|=128<<(r%4<<3),r>55)for(l(e,t,n),r=16;r--;)t[r]=0;return t[14]=m*8,l(e,t,n),e}var v=I;function a(o){return g(v(o,c))}var w=class{constructor(){this.name="webcrypto";this.version="1.0.0";}static isAvailable(){return typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.subtle.digest=="function"}async hash(n){return a(n)}async hashBinary(n){let m=n instanceof ArrayBuffer?new TextDecoder().decode(n):new TextDecoder().decode(n);return a(m)}update(n){throw new Error("Web Crypto API does not support streaming updates")}digest(n){throw new Error("Web Crypto API does not support streaming")}reset(){}};exports.WebCryptoBackend=w;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { M as MD5Backend } from '../types-edGoGJ5V.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Web Crypto API Backend
|
|
5
|
+
* Uses browser's native Web Crypto API for MD5 hashing
|
|
6
|
+
* Note: Web Crypto API does not support MD5 in most browsers, so this backend
|
|
7
|
+
* falls back to pure JS implementation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare class WebCryptoBackend implements MD5Backend {
|
|
11
|
+
name: string;
|
|
12
|
+
version: string;
|
|
13
|
+
static isAvailable(): boolean;
|
|
14
|
+
hash(data: string): Promise<string>;
|
|
15
|
+
hashBinary(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
16
|
+
update(_data: string | ArrayBuffer | Uint8Array): void | Promise<void>;
|
|
17
|
+
digest(_encoding?: "hex" | "buffer"): string | Uint8Array | Promise<string | Uint8Array>;
|
|
18
|
+
reset(): void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { WebCryptoBackend };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { M as MD5Backend } from '../types-edGoGJ5V.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Web Crypto API Backend
|
|
5
|
+
* Uses browser's native Web Crypto API for MD5 hashing
|
|
6
|
+
* Note: Web Crypto API does not support MD5 in most browsers, so this backend
|
|
7
|
+
* falls back to pure JS implementation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare class WebCryptoBackend implements MD5Backend {
|
|
11
|
+
name: string;
|
|
12
|
+
version: string;
|
|
13
|
+
static isAvailable(): boolean;
|
|
14
|
+
hash(data: string): Promise<string>;
|
|
15
|
+
hashBinary(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
16
|
+
update(_data: string | ArrayBuffer | Uint8Array): void | Promise<void>;
|
|
17
|
+
digest(_encoding?: "hex" | "buffer"): string | Uint8Array | Promise<string | Uint8Array>;
|
|
18
|
+
reset(): void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { WebCryptoBackend };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{a as WebCryptoBackend}from'../chunk-43QQAXLT.js';import'../chunk-Z4JB6DTM.js';import'../chunk-DFR4GYL3.js';import'../chunk-I7AUKTXE.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var B="0123456789abcdef".split(""),s=B;function j(m){let t="";for(let o=0;o<4;o++)t+=s[m>>o*8+4&15]+s[m>>o*8&15];return t}function v(m){let t=m.length,o=new Array(t);for(let r=0;r<t;r++)o[r]=j(m[r]);return o.join("")}var h=v;function w(m,t){return m+t&4294967295}var f=w;function _(m,t,o,r,n){let e=n||f;return t=e(e(t,m),e(o,r)),t}function q(m,t,o,r){var e=(r||f)(m<<t|m>>>32-t,o);return e}function p(m,t,o,r,n,e,u){return t=_(m,t,r,e,u),q(t,n,o,u)}function g(m,t,o,r,n,e,u,i){return p(o&r|~o&n,t,o,e,u,i,m)}function a(m,t,o,r,n,e,u,i){return p(o&n|r&~n,t,o,e,u,i,m)}function A(m,t,o,r,n,e,u,i){return p(o^r^n,t,o,e,u,i,m)}function x(m,t,o,r,n,e,u,i){return p(r^(o|~n),t,o,e,u,i,m)}function z(m,t,o){typeof o>"u"&&(o=f);let r=m[0],n=m[1],e=m[2],u=m[3],i=g.bind(null,o);r=i(r,n,e,u,t[0],7,-680876936),u=i(u,r,n,e,t[1],12,-389564586),e=i(e,u,r,n,t[2],17,606105819),n=i(n,e,u,r,t[3],22,-1044525330),r=i(r,n,e,u,t[4],7,-176418897),u=i(u,r,n,e,t[5],12,1200080426),e=i(e,u,r,n,t[6],17,-1473231341),n=i(n,e,u,r,t[7],22,-45705983),r=i(r,n,e,u,t[8],7,1770035416),u=i(u,r,n,e,t[9],12,-1958414417),e=i(e,u,r,n,t[10],17,-42063),n=i(n,e,u,r,t[11],22,-1990404162),r=i(r,n,e,u,t[12],7,1804603682),u=i(u,r,n,e,t[13],12,-40341101),e=i(e,u,r,n,t[14],17,-1502002290),n=i(n,e,u,r,t[15],22,1236535329);let b=a.bind(null,o);r=b(r,n,e,u,t[1],5,-165796510),u=b(u,r,n,e,t[6],9,-1069501632),e=b(e,u,r,n,t[11],14,643717713),n=b(n,e,u,r,t[0],20,-373897302),r=b(r,n,e,u,t[5],5,-701558691),u=b(u,r,n,e,t[10],9,38016083),e=b(e,u,r,n,t[15],14,-660478335),n=b(n,e,u,r,t[4],20,-405537848),r=b(r,n,e,u,t[9],5,568446438),u=b(u,r,n,e,t[14],9,-1019803690),e=b(e,u,r,n,t[3],14,-187363961),n=b(n,e,u,r,t[8],20,1163531501),r=b(r,n,e,u,t[13],5,-1444681467),u=b(u,r,n,e,t[2],9,-51403784),e=b(e,u,r,n,t[7],14,1735328473),n=b(n,e,u,r,t[12],20,-1926607734);let c=A.bind(null,o);r=c(r,n,e,u,t[5],4,-378558),u=c(u,r,n,e,t[8],11,-2022574463),e=c(e,u,r,n,t[11],16,1839030562),n=c(n,e,u,r,t[14],23,-35309556),r=c(r,n,e,u,t[1],4,-1530992060),u=c(u,r,n,e,t[4],11,1272893353),e=c(e,u,r,n,t[7],16,-155497632),n=c(n,e,u,r,t[10],23,-1094730640),r=c(r,n,e,u,t[13],4,681279174),u=c(u,r,n,e,t[0],11,-358537222),e=c(e,u,r,n,t[3],16,-722521979),n=c(n,e,u,r,t[6],23,76029189),r=c(r,n,e,u,t[9],4,-640364487),u=c(u,r,n,e,t[12],11,-421815835),e=c(e,u,r,n,t[15],16,530742520),n=c(n,e,u,r,t[2],23,-995338651);let d=x.bind(null,o);r=d(r,n,e,u,t[0],6,-198630844),u=d(u,r,n,e,t[7],10,1126891415),e=d(e,u,r,n,t[14],15,-1416354905),n=d(n,e,u,r,t[5],21,-57434055),r=d(r,n,e,u,t[12],6,1700485571),u=d(u,r,n,e,t[3],10,-1894986606),e=d(e,u,r,n,t[10],15,-1051523),n=d(n,e,u,r,t[1],21,-2054922799),r=d(r,n,e,u,t[8],6,1873313359),u=d(u,r,n,e,t[15],10,-30611744),e=d(e,u,r,n,t[6],15,-1560198380),n=d(n,e,u,r,t[13],21,1309151649),r=d(r,n,e,u,t[4],6,-145523070),u=d(u,r,n,e,t[11],10,-1120210379),e=d(e,u,r,n,t[2],15,718787259),n=d(n,e,u,r,t[9],21,-343485551),m[0]=o(r,m[0]),m[1]=o(n,m[1]),m[2]=o(e,m[2]),m[3]=o(u,m[3]);}var l=z;function D(m){let t=[];for(let o=0;o<64;o+=4)t[o>>2]=(m.charCodeAt(o)||0)+((m.charCodeAt(o+1)||0)<<8)+((m.charCodeAt(o+2)||0)<<16)+((m.charCodeAt(o+3)||0)<<24);return t}var y=D;function E(m,t){let o=m.length,r=[1732584193,-271733879,-1732584194,271733878],n;for(n=64;n<=o;n+=64)l(r,y(m.substring(n-64,n)),t);m=m.substring(n-64);var e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],u=m.length;for(n=0;n<u;n++)e[n>>2]|=(m.charCodeAt(n)&255)<<(n%4<<3);if(e[n>>2]|=128<<(n%4<<3),n>55)for(l(r,e,t),n=16;n--;)e[n]=0;return e[14]=o*8,l(r,e,t),r}var F=E;function G(m,t){let o=m.length,r=[1732584193,-271733879,-1732584194,271733878],n;for(n=64;n<=o;n+=64){let i=H(m,n-64);l(r,i,t);}let e=o-n+64,u=new Array(16).fill(0);for(let i=0;i<e;i++)u[i>>2]|=(m[o-e+i]&255)<<(i%4<<3);if(u[e>>2]|=128<<(e%4<<3),e>55){l(r,u,t);for(let i=0;i<16;i++)u[i]=0;}return u[14]=o*8,u[15]=0,l(r,u,t),r}function H(m,t){let o=[];for(let r=0;r<64;r+=4)o[r>>2]=(m[t+r]||0)+((m[t+r+1]||0)<<8)+((m[t+r+2]||0)<<16)+((m[t+r+3]||0)<<24);return o}var C=G;function k(m){return h(F(m,f))}function nn(m){return h(C(m,f))}exports.md5=k;exports.md5Buffer=nn;exports.md5Core=k;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core MD5 implementation - Pure JavaScript
|
|
3
|
+
* No dependencies, no environment detection
|
|
4
|
+
* This is the minimal, tree-shakeable core
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Compute MD5 hash of a string
|
|
8
|
+
* @param string - Input string to hash
|
|
9
|
+
* @returns MD5 hash as hex string
|
|
10
|
+
*/
|
|
11
|
+
declare function md5Core(string: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Compute MD5 hash of a Buffer
|
|
14
|
+
* @param buffer - Input Buffer to hash
|
|
15
|
+
* @returns MD5 hash as hex string
|
|
16
|
+
*/
|
|
17
|
+
declare function md5Buffer(buffer: Buffer): string;
|
|
18
|
+
|
|
19
|
+
export { md5Core as md5, md5Buffer, md5Core };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core MD5 implementation - Pure JavaScript
|
|
3
|
+
* No dependencies, no environment detection
|
|
4
|
+
* This is the minimal, tree-shakeable core
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Compute MD5 hash of a string
|
|
8
|
+
* @param string - Input string to hash
|
|
9
|
+
* @returns MD5 hash as hex string
|
|
10
|
+
*/
|
|
11
|
+
declare function md5Core(string: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Compute MD5 hash of a Buffer
|
|
14
|
+
* @param buffer - Input Buffer to hash
|
|
15
|
+
* @returns MD5 hash as hex string
|
|
16
|
+
*/
|
|
17
|
+
declare function md5Buffer(buffer: Buffer): string;
|
|
18
|
+
|
|
19
|
+
export { md5Core as md5, md5Buffer, md5Core };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{a as md5,b as md5Buffer,a as md5Core}from'../chunk-Z4JB6DTM.js';import'../chunk-DFR4GYL3.js';import'../chunk-I7AUKTXE.js';
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var stream=require('stream'),D=require('fs');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var D__default=/*#__PURE__*/_interopDefault(D);var N=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var Z="0123456789abcdef".split(""),O=Z;function ee(i){let e="";for(let n=0;n<4;n++)e+=O[i>>n*8+4&15]+O[i>>n*8&15];return e}function re(i){let e=i.length,n=new Array(e);for(let r=0;r<e;r++)n[r]=ee(i[r]);return n.join("")}var S=re;function te(i,e){return i+e&4294967295}var b=te;function ne(i,e,n,r,t){let s=t||b;return e=s(s(e,i),s(n,r)),e}function se(i,e,n,r){var s=(r||b)(i<<e|i>>>32-e,n);return s}function C(i,e,n,r,t,s,a){return e=ne(i,e,r,s,a),se(e,t,n,a)}function I(i,e,n,r,t,s,a,o){return C(n&r|~n&t,e,n,s,a,o,i)}function L(i,e,n,r,t,s,a,o){return C(n&t|r&~t,e,n,s,a,o,i)}function $(i,e,n,r,t,s,a,o){return C(n^r^t,e,n,s,a,o,i)}function _(i,e,n,r,t,s,a,o){return C(r^(n|~t),e,n,s,a,o,i)}function ie(i,e,n){typeof n>"u"&&(n=b);let r=i[0],t=i[1],s=i[2],a=i[3],o=I.bind(null,n);r=o(r,t,s,a,e[0],7,-680876936),a=o(a,r,t,s,e[1],12,-389564586),s=o(s,a,r,t,e[2],17,606105819),t=o(t,s,a,r,e[3],22,-1044525330),r=o(r,t,s,a,e[4],7,-176418897),a=o(a,r,t,s,e[5],12,1200080426),s=o(s,a,r,t,e[6],17,-1473231341),t=o(t,s,a,r,e[7],22,-45705983),r=o(r,t,s,a,e[8],7,1770035416),a=o(a,r,t,s,e[9],12,-1958414417),s=o(s,a,r,t,e[10],17,-42063),t=o(t,s,a,r,e[11],22,-1990404162),r=o(r,t,s,a,e[12],7,1804603682),a=o(a,r,t,s,e[13],12,-40341101),s=o(s,a,r,t,e[14],17,-1502002290),t=o(t,s,a,r,e[15],22,1236535329);let c=L.bind(null,n);r=c(r,t,s,a,e[1],5,-165796510),a=c(a,r,t,s,e[6],9,-1069501632),s=c(s,a,r,t,e[11],14,643717713),t=c(t,s,a,r,e[0],20,-373897302),r=c(r,t,s,a,e[5],5,-701558691),a=c(a,r,t,s,e[10],9,38016083),s=c(s,a,r,t,e[15],14,-660478335),t=c(t,s,a,r,e[4],20,-405537848),r=c(r,t,s,a,e[9],5,568446438),a=c(a,r,t,s,e[14],9,-1019803690),s=c(s,a,r,t,e[3],14,-187363961),t=c(t,s,a,r,e[8],20,1163531501),r=c(r,t,s,a,e[13],5,-1444681467),a=c(a,r,t,s,e[2],9,-51403784),s=c(s,a,r,t,e[7],14,1735328473),t=c(t,s,a,r,e[12],20,-1926607734);let u=$.bind(null,n);r=u(r,t,s,a,e[5],4,-378558),a=u(a,r,t,s,e[8],11,-2022574463),s=u(s,a,r,t,e[11],16,1839030562),t=u(t,s,a,r,e[14],23,-35309556),r=u(r,t,s,a,e[1],4,-1530992060),a=u(a,r,t,s,e[4],11,1272893353),s=u(s,a,r,t,e[7],16,-155497632),t=u(t,s,a,r,e[10],23,-1094730640),r=u(r,t,s,a,e[13],4,681279174),a=u(a,r,t,s,e[0],11,-358537222),s=u(s,a,r,t,e[3],16,-722521979),t=u(t,s,a,r,e[6],23,76029189),r=u(r,t,s,a,e[9],4,-640364487),a=u(a,r,t,s,e[12],11,-421815835),s=u(s,a,r,t,e[15],16,530742520),t=u(t,s,a,r,e[2],23,-995338651);let f=_.bind(null,n);r=f(r,t,s,a,e[0],6,-198630844),a=f(a,r,t,s,e[7],10,1126891415),s=f(s,a,r,t,e[14],15,-1416354905),t=f(t,s,a,r,e[5],21,-57434055),r=f(r,t,s,a,e[12],6,1700485571),a=f(a,r,t,s,e[3],10,-1894986606),s=f(s,a,r,t,e[10],15,-1051523),t=f(t,s,a,r,e[1],21,-2054922799),r=f(r,t,s,a,e[8],6,1873313359),a=f(a,r,t,s,e[15],10,-30611744),s=f(s,a,r,t,e[6],15,-1560198380),t=f(t,s,a,r,e[13],21,1309151649),r=f(r,t,s,a,e[4],6,-145523070),a=f(a,r,t,s,e[11],10,-1120210379),s=f(s,a,r,t,e[2],15,718787259),t=f(t,s,a,r,e[9],21,-343485551),i[0]=n(r,i[0]),i[1]=n(t,i[1]),i[2]=n(s,i[2]),i[3]=n(a,i[3]);}var m=ie;function ae(i){let e=[];for(let n=0;n<64;n+=4)e[n>>2]=(i.charCodeAt(n)||0)+((i.charCodeAt(n+1)||0)<<8)+((i.charCodeAt(n+2)||0)<<16)+((i.charCodeAt(n+3)||0)<<24);return e}var G=ae;function oe(i,e){let n=i.length,r=[1732584193,-271733879,-1732584194,271733878],t;for(t=64;t<=n;t+=64)m(r,G(i.substring(t-64,t)),e);i=i.substring(t-64);var s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=i.length;for(t=0;t<a;t++)s[t>>2]|=(i.charCodeAt(t)&255)<<(t%4<<3);if(s[t>>2]|=128<<(t%4<<3),t>55)for(m(r,s,e),t=16;t--;)s[t]=0;return s[14]=n*8,m(r,s,e),r}var z=oe;function ce(i,e){let n=i.length,r=[1732584193,-271733879,-1732584194,271733878],t;for(t=64;t<=n;t+=64){let o=ue(i,t-64);m(r,o,e);}let s=n-t+64,a=new Array(16).fill(0);for(let o=0;o<s;o++)a[o>>2]|=(i[n-s+o]&255)<<(o%4<<3);if(a[s>>2]|=128<<(s%4<<3),s>55){m(r,a,e);for(let o=0;o<16;o++)a[o]=0;}return a[14]=n*8,a[15]=0,m(r,a,e),r}function ue(i,e){let n=[];for(let r=0;r<64;r+=4)n[r>>2]=(i[e+r]||0)+((i[e+r+1]||0)<<8)+((i[e+r+2]||0)<<16)+((i[e+r+3]||0)<<24);return n}var K=ce;function l(i){return S(z(i,b))}function q(i){return S(K(i,b))}var g=class{constructor(){this.name="webcrypto";this.version="1.0.0";}static isAvailable(){return typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.subtle.digest=="function"}async hash(e){return l(e)}async hashBinary(e){let n=e instanceof ArrayBuffer?new TextDecoder().decode(e):new TextDecoder().decode(e);return l(n)}update(e){throw new Error("Web Crypto API does not support streaming updates")}digest(e){throw new Error("Web Crypto API does not support streaming")}reset(){}};var w=class{constructor(){this.name="nodecrypto";this.version="1.0.0";}static isAvailable(){try{return typeof N("crypto").createHash=="function"}catch{return false}}hash(e){return N("crypto").createHash("md5").update(e).digest("hex")}async hashBinary(e){let n=N("crypto"),r=e instanceof Uint8Array?e:new Uint8Array(e);return n.createHash("md5").update(r).digest("hex")}update(e){}digest(e){throw new Error("Node crypto streaming not implemented")}reset(){}};var B=class{constructor(){this.name="ie11";this.version="1.0.0";}static isAvailable(){if(typeof window>"u")return false;let e=window;return typeof e.msCrypto<"u"&&typeof e.msCrypto.subtle<"u"&&typeof e.msCrypto.subtle.digest=="function"}async hash(e){let r=new TextEncoder().encode(e);return await this.hashBinary(r)}async hashBinary(e){let n=window,r=e instanceof Uint8Array?e.buffer:e,t=await n.msCrypto.subtle.digest("MD5",r);return this.bufferToHex(t)}bufferToHex(e){return Array.from(new Uint8Array(e)).map(n=>n.toString(16).padStart(2,"0")).join("")}update(e){throw new Error("msCrypto does not support streaming updates")}digest(e){throw new Error("msCrypto does not support streaming")}reset(){}};var p=class i extends stream.Transform{constructor(n){super({readableObjectMode:false,writableObjectMode:false});this.initialMD5State=[1732584193,-271733879,-1732584194,271733878];this.bufferCapacity=64;this.buffer=new Uint8Array(this.bufferCapacity);this.add32=n?.add32||b,this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer};}_transform(n,r,t){try{let s=n,a=s.length;if(a===0){t();return}if(this.state.bufferLength>0){let u=this.state.bufferLength,f=64-u,h=Math.min(a,f);for(let d=0;d<h;d++)this.buffer[u+d]=s[d];if(this.state.bufferLength+=h,this.state.bufferLength===64&&this._processBufferBlock(),h===a){t();return}let y=a-h;for(let d=0;d<y;d++)s[d]=s[h+d];let v=Buffer.alloc(y);for(let d=0;d<y;d++)v[d]=s[d];s=v;}let o=Math.floor(s.length/64);for(let u=0;u<o;u++){let f=u*64,h=[];for(let y=0;y<16;y++){let v=f+y*4;h[y]=s[v]+(s[v+1]<<8)+(s[v+2]<<16)+(s[v+3]<<24);}m(this.state.state,h,this.add32),this.state.bytesProcessed+=64;}let c=s.length%64;if(c>0){this.buffer.length<c&&(this.buffer=new Uint8Array(c),this.state.buffer=this.buffer);for(let u=0;u<c;u++)this.buffer[u]=s[o*64+u];this.state.bufferLength=c;}t();}catch(s){t(s);}}_processBufferBlock(){let n=this.state.buffer,r=[];for(let t=0;t<16;t++){let s=t*4;r[t]=n[s]+(n[s+1]<<8)+(n[s+2]<<16)+(n[s+3]<<24);}m(this.state.state,r,this.add32),this.state.bytesProcessed+=64,this.state.bufferLength=0;}_flush(n){try{let{state:r,bufferLength:t,buffer:s}=this.state,a=new Array(16).fill(0);for(let c=0;c<t;c++)a[c>>2]|=(s[c]&255)<<(c%4<<3);if(a[t>>2]|=128<<(t%4<<3),t>55){m(r,a,this.add32);for(let c=0;c<16;c++)a[c]=0;}a[14]=(this.state.bytesProcessed+t)*8,a[15]=0,m(r,a,this.add32);let o=S(r);this.emit("md5",{digest:o,bytesProcessed:this.state.bytesProcessed+t}),n();}catch(r){n(r);}}getCurrentState(){return {state:[...this.state.state],bytesProcessed:this.state.bytesProcessed+this.state.bufferLength}}getBytesProcessed(){return this.state.bytesProcessed+this.state.bufferLength}reset(){this.state={state:[...this.initialMD5State],bytesProcessed:0,bufferLength:0,buffer:this.buffer},this.buffer=new Uint8Array(this.bufferCapacity),this.state.buffer=this.buffer,this.state.bufferLength=0;}static fromStream(n,r){let t=new i(r),s=E.call(t,n);return {stream:t,result:s}}};function R(i){return new p(i)}async function E(i){return new Promise((e,n)=>{let r=[];i.pipe(this).on("md5",t=>{r.push(t);}).on("error",n).on("finish",()=>{e(r[0]);});})}function j(i,e){let n=new p(e),r=E.call(n,i);return {stream:n,result:r}}var A=class{constructor(){this.name="stream";this.version="0.1.0";this.state=null;}initNodeStream(e){this.state={stream:e,type:"node"};}initWhatWGStream(e){this.state={stream:e,type:"whatwg"};}async hash(e){let n=new p;return (await new Promise((t,s)=>{n.on("md5",a=>t(a)).on("error",s).end(e);})).digest}async hashBinary(e){let n=new p,r;return e instanceof Uint8Array?r=Buffer.from(e):e instanceof ArrayBuffer?r=Buffer.from(new Uint8Array(e)):r=Buffer.from(e),(await new Promise((s,a)=>{n.on("md5",o=>s(o)).on("error",a).end(r);})).digest}update(e){if(!this.state)throw new Error("Stream backend not initialized. Call initNodeStream() or initWhatWGStream() first.");if(this.state.type==="node"){let n=this.state.stream,r;typeof e=="string"||e instanceof Uint8Array?r=Buffer.from(e):e instanceof ArrayBuffer?r=Buffer.from(new Uint8Array(e)):r=Buffer.from(e),n.write(r);}}digest(e){if(!this.state)throw new Error("Stream backend not initialized. Call initNodeStream() or initWhatWGStream() first.");if(this.state.type==="node"){let n=this.state.stream;return n.end(),new Promise((r,t)=>{n.on("md5",s=>{if(e==="buffer"){let a=s.digest,o=[];for(let c=0;c<a.length;c+=2)o.push(parseInt(a.substring(c,c+2),16));r(Buffer.from(o));}else r(s.digest);}).on("error",t);})}else return this.state.stream.getResult().then(r=>r.digest)}reset(){this.state&&this.state.type==="node"&&this.state.stream.reset();}static isAvailable(){return true}};var k=class{constructor(){this.name="purejs";this.version="0.1.0";this.state={data:"",finished:false};}hash(e){return l(e)}async hashBinary(e){let n=e instanceof ArrayBuffer?new TextDecoder().decode(e):new TextDecoder().decode(e);return l(n)}update(e){this.state.finished&&(this.state={data:"",finished:false}),e instanceof ArrayBuffer?this.state.data+=new TextDecoder().decode(e):e instanceof Uint8Array?this.state.data+=new TextDecoder().decode(e):this.state.data+=e;}digest(e){let n=l(this.state.data);return this.state.finished=true,e==="buffer"?this.hexToBuffer(n):n}reset(){this.state={data:"",finished:false};}static isAvailable(){return true}hexToBuffer(e){let n=[];for(let r=0;r<e.length;r+=2)n.push(parseInt(e.substring(r,r+2),16));return new Uint8Array(n)}};async function de(i){switch(i){case "webcrypto":let e=g.isAvailable();return {backend:"webcrypto",available:e,reason:e?void 0:"Web Crypto API not available"};case "nodecrypto":let n=w.isAvailable();return {backend:"nodecrypto",available:n,reason:n?void 0:"Node.js crypto not available"};case "ie11":let r=B.isAvailable();return {backend:"ie11",available:r,reason:r?void 0:"IE11 msCrypto not available"};case "purejs":return {backend:"purejs",available:true,reason:"Always available"};case "stream":let t=typeof process<"u"&&process.versions&&"node"in process.versions,s=typeof window<"u";return {backend:"stream",available:t||s,reason:t||s?void 0:"Streams not available"};default:return {backend:i||"unknown",available:false,reason:"Unknown backend"}}}async function x(){let i=["webcrypto","nodecrypto","ie11","purejs","stream"],e=[];for(let n of i){let{available:r}=await de(n);r&&e.push(n);}return e}var me=[{name:"nodecrypto",priority:1,description:"Node.js native crypto (fastest)"},{name:"webcrypto",priority:2,description:"Web Crypto API (fast, hardware accelerated)"},{name:"ie11",priority:3,description:"IE11 msCrypto (legacy)"},{name:"stream",priority:4,description:"Streaming backend (for large files and memory efficiency)"},{name:"purejs",priority:5,description:"Pure JavaScript (always available, slower)"}];function F(i){let e=[...me].sort((n,r)=>n.priority-r.priority);for(let{name:n}of e)if(i.includes(n))return n;return "purejs"}var M=class i{constructor(){}static getInstance(){return i.instance||(i.instance=new i),i.instance}async createBackendByName(e){switch(e){case "nodecrypto":return new w;case "webcrypto":return new g;case "ie11":return new B;case "stream":return new A;default:return new k}}async createBackend(e){let n=e||F(await x());return this.createBackendByName(n)}},le=M.getInstance(),P=class{constructor(e=["nodecrypto","webcrypto","stream","ie11","purejs"]){this.detector=M.getInstance(),this.fallbackOrder=e;}async execute(e){let n=[];for(let r of this.fallbackOrder)try{let t=await this.detector.createBackendByName(r),s=await e(t);return {success:!0,backend:r,data:s}}catch(t){if(n.push({backend:r,error:t}),r===this.fallbackOrder[this.fallbackOrder.length-1])return {success:false,backend:r,data:null,errors:n}}return {success:false,backend:"",data:null,errors:n}}async hash(e){return this.execute(async n=>n.hash(e))}async hashBinary(e){return this.execute(async n=>n.hashBinary(e))}async getBestBackend(){let e=await this.getAvailableBackends();return e.length===0?"purejs":e[0]}async getAvailableBackends(){let e=[];for(let n of this.fallbackOrder)try{await this.detector.createBackendByName(n),e.push(n);}catch{}return e}getMetrics(){return {}}},be=new P;async function pe(i,e={}){let n=new P;if(e.forceBackend)return (await n.detector.createBackendByName(e.forceBackend)).hash(i);if(e.fallback===false)return (await n.detector.createBackend()).hash(i);let r=await n.hash(i);if(r.success)return e.reportFallback&&r.backend!=="nodecrypto"&&r.backend!=="webcrypto"&&console.info(`MD5 used fallback backend: ${r.backend}`),r.data;let t=r.errors?r.errors.map(s=>`${s.backend}: ${s.error.message}`).join(", "):"All backends failed";throw new Error(`MD5 hash failed after all attempts: ${t}`)}var U=class{constructor(){this.metrics={nodecrypto:{success:0,fail:0},webcrypto:{success:0,fail:0},ie11:{success:0,fail:0},stream:{success:0,fail:0},purejs:{success:0,fail:0}};}recordSuccess(e){this.metrics[e]&&this.metrics[e].success++;}recordFail(e){this.metrics[e]&&this.metrics[e].fail++;}getMetrics(){return this.metrics}getSummary(){return `Total operations: ${Object.values(this.metrics).reduce((n,r)=>n+r.success+r.fail,0)}
|
|
2
|
+
`+Object.entries(this.metrics).map(([,n])=>`${n.success} success, ${n.fail} fail`).join(`
|
|
3
|
+
`)}reset(){Object.keys(this.metrics).forEach(e=>{this.metrics[e]={success:0,fail:0};});}},he=new U;async function W(i,e={}){if(typeof i!="string"||i.trim()==="")throw new Error("Invalid file path: must be a non-empty string");if(!D__default.default.existsSync(i))throw new Error(`File not found: ${i}`);let n;try{n=D__default.default.statSync(i);}catch(t){throw new Error(`Failed to access file ${i}: ${t.message}`)}if(!n.isFile())throw new Error(`Path is not a file: ${i}`);let r=D__default.default.createReadStream(i,{highWaterMark:e.chunkSize||64*1024});try{return await T(r,{onProgress:e.onProgress,totalSize:n.size})}finally{r.destroy();}}async function T(i,e={}){if(!i||typeof i.on!="function")throw new Error("Invalid readable stream: stream must have event listener support");let n=R(),r=0;return e.onProgress&&i.on("data",t=>{r+=t.length,e.onProgress?.(r);}),i.on("error",t=>{n.destroy(t);}),i.on("end",()=>{n.end();}),new Promise((t,s)=>{n.on("md5",a=>{t(a);}).on("error",a=>{s(a);}),i.pipe(n);})}async function J(i,e={}){return (await W(i,e)).digest}async function Y(i,e={}){return (await T(i,e)).digest}async function Q(i,e,n={}){return (await W(i,n)).digest.toLowerCase()===e.toLowerCase()}function V(i){if(typeof i!="string"||i.trim()==="")throw new Error("Invalid file path: must be a non-empty string");if(!D__default.default.existsSync(i))throw new Error(`File not found: ${i}`);let e;try{e=D__default.default.statSync(i);}catch(r){throw new Error(`Failed to access file ${i}: ${r.message}`)}if(!e.isFile())throw new Error(`Path is not a file: ${i}`);let n;try{n=D__default.default.readFileSync(i);}catch(r){throw new Error(`Failed to read file ${i}: ${r.message}`)}return q(n)}function X(i,e){let n=0;return r=>{if(i>0){let t=Math.min(100,r/i*100);Math.floor(t)!==Math.floor(n)&&(e(t),n=t);}}}Object.defineProperty(p,"fromStream",{value:j,writable:false,configurable:false});var H=class{constructor(){this.backend=null;this.backendName=null;}async hash(e){return (await this.getBackend()).hash(e)}async hashBinary(e){return (await this.getBackend()).hashBinary(e)}async getBackendName(){if(!this.backendName){let e=await x();this.backendName=F(e);}return this.backendName}static async getAvailableBackends(){return await x()}async useBackend(e){this.backend=await this.createBackendByName(e),this.backendName=e;}async createBackendByName(e){switch(e){case "nodecrypto":return new w;case "webcrypto":return new g;case "ie11":return new B;case "stream":return new A;default:return {hash:n=>l(n),hashBinary:async n=>l(n instanceof Uint8Array?new TextDecoder().decode(n):new TextDecoder().decode(new Uint8Array(n))),update:()=>{},digest:()=>"",reset:()=>{},name:"purejs",version:"0.1.0"}}}async getBackend(){if(this.backend)return this.backend;let e=await x(),n=F(e);return this.backend=await this.createBackendByName(n),this.backendName=n,this.backend}};function Ar(i){return l(i)}var ye=new H;async function xr(i){return ye.hash(i)}exports.BackendDetector=M;exports.FallbackManager=P;exports.IE11Backend=B;exports.MD5Stream=p;exports.MetricsCollector=U;exports.NodeCryptoBackend=w;exports.PureJSBackend=k;exports.WebCryptoBackend=g;exports.createMD5Stream=R;exports.createProgressTracker=X;exports.detector=le;exports.fallbackManager=be;exports.fromStream=j;exports.getAllAvailableBackends=x;exports.getBestAvailableBackend=F;exports.hashFile=W;exports.hashFileDigest=J;exports.hashFileStream=T;exports.hashFileStreamDigest=Y;exports.hashFileSync=V;exports.md5=Ar;exports.md5Adapter=ye;exports.md5Async=xr;exports.md5Core=l;exports.md5Original=l;exports.metrics=he;exports.pipeThroughMD5=E;exports.robustHash=pe;exports.verifyFile=Q;
|