tinyhmacmd5 0.2.1 → 0.2.2-es2026
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/README.md +17 -17
- package/browser.min.js +1 -1
- package/main.js +4 -9
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@ English | [中文](README-zh.md)
|
|
|
2
2
|
|
|
3
3
|
# Tiny HMAC MD5
|
|
4
4
|
|
|
5
|
-
A tiny and reliable HMAC-MD5 implementation for JavaScript: [`browser.min.js`](browser.min.js) is only **
|
|
5
|
+
A tiny and reliable HMAC-MD5 implementation for JavaScript: [`browser.min.js`](browser.min.js) is only **951 bytes**.
|
|
6
6
|
|
|
7
7
|
- **Input type**: `string` (UTF‑8), `Uint8Array` or `Uint8ClampedArray`
|
|
8
8
|
- **Output type**: hex `string` or bytes `Uint8Array`
|
|
@@ -42,7 +42,7 @@ You can also use other package managers (e.g. `pnpm` or `yarn`) in place of `npm
|
|
|
42
42
|
See https://www.jsdelivr.com/package/npm/tinyhmacmd5
|
|
43
43
|
|
|
44
44
|
```html
|
|
45
|
-
<script src="https://cdn.jsdelivr.net/npm/tinyhmacmd5"></script>
|
|
45
|
+
<script src="https://cdn.jsdelivr.net/npm/tinyhmacmd5@es2026"></script>
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
It will define the `md5` function using `var`.
|
|
@@ -50,7 +50,7 @@ It will define the `md5` function using `var`.
|
|
|
50
50
|
### UNPKG
|
|
51
51
|
|
|
52
52
|
```html
|
|
53
|
-
<script src="https://unpkg.com/tinyhmacmd5"></script>
|
|
53
|
+
<script src="https://unpkg.com/tinyhmacmd5@es2026"></script>
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
It will define the `md5` function using `var`.
|
|
@@ -141,22 +141,22 @@ md5(data)
|
|
|
141
141
|
|
|
142
142
|
## Runtime Environment
|
|
143
143
|
|
|
144
|
-
Environments that support [
|
|
144
|
+
Environments that support [`Uint8Array.prototype.toHex()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex) :
|
|
145
145
|
|
|
146
146
|
- Desktop
|
|
147
|
-
- Chrome ≥
|
|
148
|
-
- Edge ≥
|
|
149
|
-
- Firefox ≥
|
|
150
|
-
- Opera ≥
|
|
151
|
-
- Safari ≥
|
|
147
|
+
- Chrome ≥ 140 (2025-09-02)
|
|
148
|
+
- Edge ≥ 140 (2025-09-05)
|
|
149
|
+
- Firefox ≥ 133 (2024-11-26)
|
|
150
|
+
- Opera ≥ 124 (2025-11-13)
|
|
151
|
+
- Safari ≥ 18.2 (2024-12-11)
|
|
152
152
|
- Mobile
|
|
153
|
-
- Chrome Android ≥
|
|
154
|
-
- Firefox for Android ≥
|
|
155
|
-
- Opera Android ≥
|
|
156
|
-
- Safari on iOS ≥
|
|
157
|
-
- Samsung Browser
|
|
158
|
-
- WebView Android ≥
|
|
159
|
-
- WebView on iOS ≥
|
|
153
|
+
- Chrome Android ≥ 140 (2025-09-02)
|
|
154
|
+
- Firefox for Android ≥ 133 (2024-11-26)
|
|
155
|
+
- Opera Android ≥ 92 (2025-10-08)
|
|
156
|
+
- Safari on iOS ≥ 18.2 (2024-12-11)
|
|
157
|
+
- Samsung Browser ×
|
|
158
|
+
- WebView Android ≥ 140 (2025-09-02)
|
|
159
|
+
- WebView on iOS ≥ 18.2 (2024-12-11)
|
|
160
160
|
|
|
161
161
|
Not recommended for use in environments that support `node:crypto`, as `node:crypto` already provides HMAC-MD5.
|
|
162
162
|
|
|
@@ -178,7 +178,7 @@ During the adaptation, I discovered that `blueimp-md5` did not correctly handle
|
|
|
178
178
|
|
|
179
179
|
I also found that using `Array` to process inputs over 512 MiB could throw a `RangeError`, so I replaced it with `Int32Array`.
|
|
180
180
|
|
|
181
|
-
I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (
|
|
181
|
+
I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (951 bytes) while also improving reliability.
|
|
182
182
|
|
|
183
183
|
Maybe not many people care about saving just a few KB, but `tinyhmacmd5` exists precisely to "explore the unknown".
|
|
184
184
|
|
package/browser.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
/*! npmjs.com/tinyhmacmd5 */{let r=[],
|
|
1
|
+
/*! npmjs.com/tinyhmacmd5 */{let r=[],e=0,n=Math,t=n.floor,o=r=>16*t((r+72)/64),f=(e,n,f=0,a=o(n),l=1732584193,c=271733878,d,h,i=[l,~c,~l,c],u=[...i])=>{for(e[a-1]=0|n/2**29,e[t(n/4)]|=128<<(e[a-2]=n<<3);f<e.length;){for(a=0;a<64;)i[h&=3]=0|((c=0|i[h]+r[a]+(l=i[3&++h],c=i[3&++h],d=i[3&++h],(n=a>>4<<2)?n>4?n>8?c^(l|~d):l^c^d:l&d|c&~d:l&c|~l&d)+(0|e[f+(a*(29521>>n)+(1296>>n)&15)]))<<(d="',16%).4$+07&*/5".charCodeAt(3&a++|n))|c>>>64-d)+l;for(;h;f+=4)u[--h]=i[h]=0|u[h]+i[h]}return i},a=(r,e,n=("string"==typeof r?r=(new TextEncoder).encode(r):r).length,t=new Int32Array(o(4*e+n)),f=0)=>{for(;f<n;)t[e++]=r[f++]|r[f++]<<8|r[f++]<<16|r[f++]<<24;return[t,n]};for(var md5=(r,e,n)=>{var t=16,o=null!=e,[l,c]=a(r,o*t),d=[],h=new Uint8Array(t);if(o){let[r,n]=a(e,0);for(n>64&&(r=f(r,n));t;)d[--t]=1785358954^(l[t]=909522486^r[t]);t=16,l=d.concat(f(l,64+c)),c=80}for(l=f(l,c);t;)h[--t]=l[t>>2]>>8*t;return n?h:h.toHex()};e<64;)r[e]=0|2**32*n.abs(n.sin(++e))}
|
package/main.js
CHANGED
|
@@ -131,8 +131,7 @@ var md5 = (data, key, raw) => {
|
|
|
131
131
|
/** @type {*} */
|
|
132
132
|
var temp = []
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
var out = raw ? new Uint8Array(i) : ''
|
|
134
|
+
var out = new Uint8Array(i)
|
|
136
135
|
|
|
137
136
|
if (hasKey) {
|
|
138
137
|
// HMAC
|
|
@@ -152,15 +151,11 @@ var md5 = (data, key, raw) => {
|
|
|
152
151
|
bdata = wordsMD5(bdata, dataByteLen)
|
|
153
152
|
|
|
154
153
|
// words to bytes or hex
|
|
155
|
-
for (; i;
|
|
156
|
-
|
|
157
|
-
? out[i] = temp
|
|
158
|
-
: out = (temp >> 4 && '') + temp.toString(16) + out
|
|
159
|
-
) {
|
|
160
|
-
temp = bdata[--i >> 2] >> i * 8 & 0xff
|
|
154
|
+
for (; i;) {
|
|
155
|
+
out[--i] = bdata[i >> 2] >> i * 8
|
|
161
156
|
}
|
|
162
157
|
|
|
163
|
-
return out
|
|
158
|
+
return raw ? out : out.toHex()
|
|
164
159
|
}
|
|
165
160
|
|
|
166
161
|
for (; i < 64;) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinyhmacmd5",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only
|
|
3
|
+
"version": "0.2.2-es2026",
|
|
4
|
+
"description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only 951 bytes.",
|
|
5
5
|
"author": "bddjr",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"typescript": "^7.0.2"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
|
-
"build": "tsc && node scripts/build.mjs && es-check
|
|
63
|
+
"build": "tsc && node scripts/build.mjs && es-check es2026 --module --checkFeatures main.js browser.min.js",
|
|
64
64
|
"build:unchanged": "node scripts/build-unchanged.mjs",
|
|
65
65
|
"test": "pnpm build && pnpm test:only",
|
|
66
66
|
"test:only": "node scripts/test.mjs",
|