ooxml-core 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +1 -0
  2. package/dist/digest/algorithm-names.d.ts +20 -0
  3. package/dist/digest/algorithm-names.d.ts.map +1 -0
  4. package/dist/digest/base64.d.ts +8 -0
  5. package/dist/digest/base64.d.ts.map +1 -0
  6. package/dist/digest/digest.d.ts +13 -0
  7. package/dist/digest/digest.d.ts.map +1 -0
  8. package/dist/digest/index.cjs +594 -0
  9. package/dist/digest/index.d.ts +8 -0
  10. package/dist/digest/index.d.ts.map +1 -0
  11. package/dist/digest/index.mjs +581 -0
  12. package/dist/digest/password-hash.d.ts +30 -0
  13. package/dist/digest/password-hash.d.ts.map +1 -0
  14. package/dist/digest/sha1.d.ts +3 -0
  15. package/dist/digest/sha1.d.ts.map +1 -0
  16. package/dist/digest/sha256.d.ts +10 -0
  17. package/dist/digest/sha256.d.ts.map +1 -0
  18. package/dist/digest/sha512.d.ts +5 -0
  19. package/dist/digest/sha512.d.ts.map +1 -0
  20. package/dist/docx/block-parser.d.ts.map +1 -1
  21. package/dist/docx/embedded.cjs +131 -54
  22. package/dist/docx/embedded.mjs +131 -54
  23. package/dist/docx/equation.d.ts +8 -0
  24. package/dist/docx/equation.d.ts.map +1 -0
  25. package/dist/docx/index.cjs +131 -54
  26. package/dist/docx/index.mjs +131 -54
  27. package/dist/docx/layout/adapter.d.ts.map +1 -1
  28. package/dist/docx/layout/index.cjs +3 -1
  29. package/dist/docx/layout/index.mjs +3 -1
  30. package/dist/docx/load/index.cjs +133 -56
  31. package/dist/docx/load/index.mjs +133 -56
  32. package/dist/docx/model-run.d.ts +5 -0
  33. package/dist/docx/model-run.d.ts.map +1 -1
  34. package/dist/docx/parse-revisions.d.ts.map +1 -1
  35. package/dist/docx/parse-table.d.ts.map +1 -1
  36. package/dist/docx/write-inline.d.ts.map +1 -1
  37. package/dist/docx/write-table-margins.d.ts +5 -0
  38. package/dist/docx/write-table-margins.d.ts.map +1 -0
  39. package/dist/docx/write-table-properties.d.ts +3 -1
  40. package/dist/docx/write-table-properties.d.ts.map +1 -1
  41. package/dist/docx/write-table.d.ts.map +1 -1
  42. package/dist/index.cjs +598 -0
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.mjs +598 -1
  46. package/dist/visio/cell-formula.d.ts +9 -0
  47. package/dist/visio/cell-formula.d.ts.map +1 -0
  48. package/dist/visio/edit-commands.d.ts +33 -0
  49. package/dist/visio/edit-commands.d.ts.map +1 -0
  50. package/dist/visio/edit-geometry-admission.d.ts +10 -0
  51. package/dist/visio/edit-geometry-admission.d.ts.map +1 -0
  52. package/dist/visio/edit-geometry.d.ts +3 -0
  53. package/dist/visio/edit-geometry.d.ts.map +1 -0
  54. package/dist/visio/edit-recalculate-index.d.ts +25 -0
  55. package/dist/visio/edit-recalculate-index.d.ts.map +1 -0
  56. package/dist/visio/edit-recalculate.d.ts +11 -0
  57. package/dist/visio/edit-recalculate.d.ts.map +1 -0
  58. package/dist/visio/edit-scope.d.ts +5 -0
  59. package/dist/visio/edit-scope.d.ts.map +1 -0
  60. package/dist/visio/edit.d.ts +4 -8
  61. package/dist/visio/edit.d.ts.map +1 -1
  62. package/dist/visio/formula-evaluate.d.ts +10 -0
  63. package/dist/visio/formula-evaluate.d.ts.map +1 -0
  64. package/dist/visio/formula-theme.d.ts +2 -0
  65. package/dist/visio/formula-theme.d.ts.map +1 -0
  66. package/dist/visio/formula.d.ts +52 -0
  67. package/dist/visio/formula.d.ts.map +1 -0
  68. package/dist/visio/index.cjs +1605 -232
  69. package/dist/visio/index.d.ts +2 -1
  70. package/dist/visio/index.d.ts.map +1 -1
  71. package/dist/visio/index.mjs +1601 -233
  72. package/dist/xlsx/edit/history.d.ts +1 -1
  73. package/dist/xlsx/edit/history.d.ts.map +1 -1
  74. package/dist/xlsx/edit/index.d.ts +1 -1
  75. package/dist/xlsx/edit/index.d.ts.map +1 -1
  76. package/dist/xlsx/edit/protection.d.ts +18 -6
  77. package/dist/xlsx/edit/protection.d.ts.map +1 -1
  78. package/dist/xlsx/edit/types.d.ts +2 -2
  79. package/dist/xlsx/index.cjs +671 -28
  80. package/dist/xlsx/index.mjs +670 -29
  81. package/dist/xlsx/load/index.cjs +56 -19
  82. package/dist/xlsx/load/index.mjs +56 -19
  83. package/dist/xlsx/model.d.ts +21 -0
  84. package/dist/xlsx/model.d.ts.map +1 -1
  85. package/dist/xlsx/read/load.d.ts.map +1 -1
  86. package/dist/xlsx/read/password-hash.d.ts +15 -0
  87. package/dist/xlsx/read/password-hash.d.ts.map +1 -0
  88. package/dist/xlsx/read/sheet-props.d.ts.map +1 -1
  89. package/dist/xlsx/read/workbook-part.d.ts +3 -1
  90. package/dist/xlsx/read/workbook-part.d.ts.map +1 -1
  91. package/dist/xlsx/write/password-hash.d.ts +8 -0
  92. package/dist/xlsx/write/password-hash.d.ts.map +1 -0
  93. package/dist/xlsx/write/sheet-props.d.ts.map +1 -1
  94. package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
  95. package/package.json +6 -1
package/README.md CHANGED
@@ -43,6 +43,7 @@ import { xml, opc } from 'ooxml-core'; // or by namespace (shared building block
43
43
  | `color` | Hex, RGB, HSL and linear colour primitives, OOXML percent and angle parsing. |
44
44
  | `geometry` | DrawingML preset shapes, connection sites, clip paths, callouts and boolean shape operations. |
45
45
  | `diagram` | SmartArt (DiagramML), format-neutral: data model, layout/colour/quick-style parts, the cached `dsp:drawing` shape tree, relationship resolution and a loader. Used by `docx`; `pptx` re-imports its parsers. |
46
+ | `digest` | Synchronous pure-TypeScript SHA-1, SHA-256, SHA-384 and SHA-512, ECMA-376 digest name normalisation (`SHA-512`, `SHA512`, `sha_512`, ...) and the agile password hash Office protection elements store (`hashPassword`, `verifyPasswordHash`). No Web Crypto, so it works on `http://`. Used by `xlsx` sheet and workbook protection. |
46
47
  | `collab` | Format-neutral real-time collaboration on Yjs: session and provider lifecycle, awareness/presence, transport-neutral sync (WebSocket, in-memory, any byte channel), update codecs, ordering helpers, asset sync and the product adapter seam. See `docs/collab-area.md`. |
47
48
  | `docx` | WordprocessingML: model, parser, preserving serializer, editing, validation. Also `/docx/embedded`. `/docx/layout` is the DOM-free pagination engine (an approximation of Word, not parity) and `/docx/load` detects and loads DOCX and legacy .doc (ole2 inlined). |
48
49
  | `pptx` | PresentationML: model, parser, serializer, editing, charts, SmartArt, converters, CLI, signatures. Subpaths `/pptx/converter`, `/pptx/cli`, `/pptx/signature-node`. |
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Canonical spellings of the hash algorithm names ECMA-376 lets a password verifier name.
3
+ *
4
+ * The `algorithmName` attributes (`sheetProtection`, `workbookProtection`, `p:modifyVerifier`,
5
+ * `w:writeProtection`, ...) are free-form strings: ECMA-376 gives `"SHA-512"` and `"SHA512"`,
6
+ * and hyphen-less, lower-case or underscored forms (`"sha1"`, `"sha_512"`, `"ripemd160"`) occur
7
+ * in the wild. Normalising once means every caller agrees on one spelling.
8
+ *
9
+ * Ported from the pptx area's `src/pptx/core/utils/digests/algorithm-names.ts`.
10
+ */
11
+ /** The hash algorithm names ECMA-376 password verifiers use and this module recognises. */
12
+ export type DigestAlgorithmName = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' | 'MD2' | 'MD4' | 'MD5' | 'RIPEMD-128' | 'RIPEMD-160' | 'WHIRLPOOL';
13
+ /** The algorithms {@link digestSync} computes (the others are recognised but not implemented). */
14
+ export type SupportedDigestName = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
15
+ /**
16
+ * Normalises `name` to a {@link DigestAlgorithmName}, or `undefined` when it names an algorithm
17
+ * this module does not recognise.
18
+ */
19
+ export declare function normalizeDigestAlgorithmName(name: string): DigestAlgorithmName | undefined;
20
+ //# sourceMappingURL=algorithm-names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"algorithm-names.d.ts","sourceRoot":"","sources":["../../src/digest/algorithm-names.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,2FAA2F;AAC3F,MAAM,MAAM,mBAAmB,GAC5B,OAAO,GACP,SAAS,GACT,SAAS,GACT,SAAS,GACT,KAAK,GACL,KAAK,GACL,KAAK,GACL,YAAY,GACZ,YAAY,GACZ,WAAW,CAAC;AAEf,kGAAkG;AAClG,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAgB9E;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAG1F"}
@@ -0,0 +1,8 @@
1
+ /** Encodes `bytes` as padded base64. */
2
+ export declare function encodeBase64(bytes: Uint8Array): string;
3
+ /**
4
+ * Decodes base64, ignoring white space and tolerating missing padding. Returns `undefined` for
5
+ * anything malformed (characters outside the alphabet, misplaced padding, an impossible length).
6
+ */
7
+ export declare function decodeBase64(text: string): Uint8Array | undefined;
8
+ //# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/digest/base64.ts"],"names":[],"mappings":"AAMA,wCAAwC;AACxC,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAYtD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAoBjE"}
@@ -0,0 +1,13 @@
1
+ /** A synchronous hash function over bytes. */
2
+ export type DigestFunction = (data: Uint8Array) => Uint8Array;
3
+ /**
4
+ * The synchronous digest function for `name` (any spelling {@link normalizeDigestAlgorithmName}
5
+ * accepts), or `undefined` when it is not one this module computes.
6
+ */
7
+ export declare function digestFunction(name: string): DigestFunction | undefined;
8
+ /**
9
+ * The digest of `data` under `name` (SHA-1, SHA-256, SHA-384 or SHA-512, in any ECMA-376
10
+ * spelling), or `undefined` for an algorithm this module does not compute.
11
+ */
12
+ export declare function digestSync(name: string, data: Uint8Array): Uint8Array | undefined;
13
+ //# sourceMappingURL=digest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../../src/digest/digest.ts"],"names":[],"mappings":"AAKA,8CAA8C;AAC9C,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,CAAC;AAS9D;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAGvE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,CAEjF"}
@@ -0,0 +1,594 @@
1
+ 'use strict';
2
+
3
+ // src/digest/algorithm-names.ts
4
+ var CANONICAL_BY_LOOKUP_KEY = {
5
+ SHA1: "SHA-1",
6
+ SHA256: "SHA-256",
7
+ SHA384: "SHA-384",
8
+ SHA512: "SHA-512",
9
+ MD2: "MD2",
10
+ MD4: "MD4",
11
+ MD5: "MD5",
12
+ RIPEMD128: "RIPEMD-128",
13
+ RIPEMD160: "RIPEMD-160",
14
+ WHIRLPOOL: "WHIRLPOOL"
15
+ };
16
+ function normalizeDigestAlgorithmName(name) {
17
+ const key = name.toUpperCase().replace(/[-_\s]/g, "");
18
+ return Object.hasOwn(CANONICAL_BY_LOOKUP_KEY, key) ? CANONICAL_BY_LOOKUP_KEY[key] : void 0;
19
+ }
20
+
21
+ // src/digest/base64.ts
22
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
23
+ var VALUES = new Map([...ALPHABET].map((char, index) => [char, index]));
24
+ function encodeBase64(bytes) {
25
+ let out = "";
26
+ for (let i = 0; i < bytes.length; i += 3) {
27
+ const a = bytes[i];
28
+ const b = bytes[i + 1];
29
+ const c = bytes[i + 2];
30
+ const n = a << 16 | (b ?? 0) << 8 | (c ?? 0);
31
+ out += ALPHABET[n >> 18] + ALPHABET[n >> 12 & 63];
32
+ out += b === void 0 ? "=" : ALPHABET[n >> 6 & 63];
33
+ out += c === void 0 ? "=" : ALPHABET[n & 63];
34
+ }
35
+ return out;
36
+ }
37
+ function decodeBase64(text) {
38
+ const compact = text.replace(/\s+/g, "");
39
+ const body = compact.replace(/={1,2}$/, "");
40
+ if (body.length % 4 === 1) return void 0;
41
+ if (compact.length !== body.length && compact.length % 4 !== 0) return void 0;
42
+ const out = new Uint8Array(Math.floor(body.length * 3 / 4));
43
+ let bits = 0;
44
+ let buffer = 0;
45
+ let index = 0;
46
+ for (const char of body) {
47
+ const value = VALUES.get(char);
48
+ if (value === void 0) return void 0;
49
+ buffer = (buffer << 6 | value) & 16777215;
50
+ bits += 6;
51
+ if (bits >= 8) {
52
+ bits -= 8;
53
+ out[index++] = buffer >> bits & 255;
54
+ }
55
+ }
56
+ return out;
57
+ }
58
+
59
+ // src/digest/sha256.ts
60
+ var K = new Uint32Array([
61
+ 1116352408,
62
+ 1899447441,
63
+ 3049323471,
64
+ 3921009573,
65
+ 961987163,
66
+ 1508970993,
67
+ 2453635748,
68
+ 2870763221,
69
+ 3624381080,
70
+ 310598401,
71
+ 607225278,
72
+ 1426881987,
73
+ 1925078388,
74
+ 2162078206,
75
+ 2614888103,
76
+ 3248222580,
77
+ 3835390401,
78
+ 4022224774,
79
+ 264347078,
80
+ 604807628,
81
+ 770255983,
82
+ 1249150122,
83
+ 1555081692,
84
+ 1996064986,
85
+ 2554220882,
86
+ 2821834349,
87
+ 2952996808,
88
+ 3210313671,
89
+ 3336571891,
90
+ 3584528711,
91
+ 113926993,
92
+ 338241895,
93
+ 666307205,
94
+ 773529912,
95
+ 1294757372,
96
+ 1396182291,
97
+ 1695183700,
98
+ 1986661051,
99
+ 2177026350,
100
+ 2456956037,
101
+ 2730485921,
102
+ 2820302411,
103
+ 3259730800,
104
+ 3345764771,
105
+ 3516065817,
106
+ 3600352804,
107
+ 4094571909,
108
+ 275423344,
109
+ 430227734,
110
+ 506948616,
111
+ 659060556,
112
+ 883997877,
113
+ 958139571,
114
+ 1322822218,
115
+ 1537002063,
116
+ 1747873779,
117
+ 1955562222,
118
+ 2024104815,
119
+ 2227730452,
120
+ 2361852424,
121
+ 2428436474,
122
+ 2756734187,
123
+ 3204031479,
124
+ 3329325298
125
+ ]);
126
+ var IV = [
127
+ 1779033703,
128
+ 3144134277,
129
+ 1013904242,
130
+ 2773480762,
131
+ 1359893119,
132
+ 2600822924,
133
+ 528734635,
134
+ 1541459225
135
+ ];
136
+ var W = new Uint32Array(64);
137
+ var rotr = (x, n) => x >>> n | x << 32 - n;
138
+ function compress(h, view, offset) {
139
+ for (let i = 0; i < 16; i++) W[i] = view.getUint32(offset + i * 4);
140
+ for (let i = 16; i < 64; i++) {
141
+ const a2 = W[i - 15];
142
+ const b2 = W[i - 2];
143
+ const s0 = rotr(a2, 7) ^ rotr(a2, 18) ^ a2 >>> 3;
144
+ const s1 = rotr(b2, 17) ^ rotr(b2, 19) ^ b2 >>> 10;
145
+ W[i] = W[i - 16] + s0 + W[i - 7] + s1 >>> 0;
146
+ }
147
+ let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], k = h[7];
148
+ for (let i = 0; i < 64; i++) {
149
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
150
+ const ch = e & f ^ ~e & g;
151
+ const t1 = k + S1 + ch + K[i] + W[i] >>> 0;
152
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
153
+ const maj = a & b ^ a & c ^ b & c;
154
+ const t2 = S0 + maj >>> 0;
155
+ k = g;
156
+ g = f;
157
+ f = e;
158
+ e = d + t1 >>> 0;
159
+ d = c;
160
+ c = b;
161
+ b = a;
162
+ a = t1 + t2 >>> 0;
163
+ }
164
+ h[0] = h[0] + a >>> 0;
165
+ h[1] = h[1] + b >>> 0;
166
+ h[2] = h[2] + c >>> 0;
167
+ h[3] = h[3] + d >>> 0;
168
+ h[4] = h[4] + e >>> 0;
169
+ h[5] = h[5] + f >>> 0;
170
+ h[6] = h[6] + g >>> 0;
171
+ h[7] = h[7] + k >>> 0;
172
+ }
173
+ function pad64(data) {
174
+ const padded = new Uint8Array(Math.ceil((data.length + 9) / 64) * 64);
175
+ padded.set(data);
176
+ padded[data.length] = 128;
177
+ const bits = data.length * 8;
178
+ const view = new DataView(padded.buffer);
179
+ view.setUint32(padded.length - 8, Math.floor(bits / 4294967296));
180
+ view.setUint32(padded.length - 4, bits >>> 0);
181
+ return view;
182
+ }
183
+ function wordsOut(h) {
184
+ const out = new Uint8Array(h.length * 4);
185
+ const view = new DataView(out.buffer);
186
+ for (let i = 0; i < h.length; i++) view.setUint32(i * 4, h[i]);
187
+ return out;
188
+ }
189
+ function sha256(data) {
190
+ const h = new Uint32Array(IV);
191
+ const view = pad64(data);
192
+ for (let offset = 0; offset < view.byteLength; offset += 64) compress(h, view, offset);
193
+ return wordsOut(h);
194
+ }
195
+
196
+ // src/digest/sha1.ts
197
+ var W2 = new Uint32Array(80);
198
+ var rotl = (x, n) => x << n | x >>> 32 - n;
199
+ function compress2(h, view, offset) {
200
+ for (let i = 0; i < 16; i++) W2[i] = view.getUint32(offset + i * 4);
201
+ for (let i = 16; i < 80; i++) W2[i] = rotl(W2[i - 3] ^ W2[i - 8] ^ W2[i - 14] ^ W2[i - 16], 1);
202
+ let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4];
203
+ for (let i = 0; i < 80; i++) {
204
+ let f;
205
+ let k;
206
+ if (i < 20) {
207
+ f = b & c | ~b & d;
208
+ k = 1518500249;
209
+ } else if (i < 40) {
210
+ f = b ^ c ^ d;
211
+ k = 1859775393;
212
+ } else if (i < 60) {
213
+ f = b & c | b & d | c & d;
214
+ k = 2400959708;
215
+ } else {
216
+ f = b ^ c ^ d;
217
+ k = 3395469782;
218
+ }
219
+ const t = rotl(a, 5) + f + e + k + W2[i] >>> 0;
220
+ e = d;
221
+ d = c;
222
+ c = rotl(b, 30) >>> 0;
223
+ b = a;
224
+ a = t;
225
+ }
226
+ h[0] = h[0] + a >>> 0;
227
+ h[1] = h[1] + b >>> 0;
228
+ h[2] = h[2] + c >>> 0;
229
+ h[3] = h[3] + d >>> 0;
230
+ h[4] = h[4] + e >>> 0;
231
+ }
232
+ function sha1(data) {
233
+ const h = new Uint32Array([1732584193, 4023233417, 2562383102, 271733878, 3285377520]);
234
+ const view = pad64(data);
235
+ for (let offset = 0; offset < view.byteLength; offset += 64) compress2(h, view, offset);
236
+ return wordsOut(h);
237
+ }
238
+
239
+ // src/digest/sha512.ts
240
+ var K2 = new Uint32Array([
241
+ 1116352408,
242
+ 3609767458,
243
+ 1899447441,
244
+ 602891725,
245
+ 3049323471,
246
+ 3964484399,
247
+ 3921009573,
248
+ 2173295548,
249
+ 961987163,
250
+ 4081628472,
251
+ 1508970993,
252
+ 3053834265,
253
+ 2453635748,
254
+ 2937671579,
255
+ 2870763221,
256
+ 3664609560,
257
+ 3624381080,
258
+ 2734883394,
259
+ 310598401,
260
+ 1164996542,
261
+ 607225278,
262
+ 1323610764,
263
+ 1426881987,
264
+ 3590304994,
265
+ 1925078388,
266
+ 4068182383,
267
+ 2162078206,
268
+ 991336113,
269
+ 2614888103,
270
+ 633803317,
271
+ 3248222580,
272
+ 3479774868,
273
+ 3835390401,
274
+ 2666613458,
275
+ 4022224774,
276
+ 944711139,
277
+ 264347078,
278
+ 2341262773,
279
+ 604807628,
280
+ 2007800933,
281
+ 770255983,
282
+ 1495990901,
283
+ 1249150122,
284
+ 1856431235,
285
+ 1555081692,
286
+ 3175218132,
287
+ 1996064986,
288
+ 2198950837,
289
+ 2554220882,
290
+ 3999719339,
291
+ 2821834349,
292
+ 766784016,
293
+ 2952996808,
294
+ 2566594879,
295
+ 3210313671,
296
+ 3203337956,
297
+ 3336571891,
298
+ 1034457026,
299
+ 3584528711,
300
+ 2466948901,
301
+ 113926993,
302
+ 3758326383,
303
+ 338241895,
304
+ 168717936,
305
+ 666307205,
306
+ 1188179964,
307
+ 773529912,
308
+ 1546045734,
309
+ 1294757372,
310
+ 1522805485,
311
+ 1396182291,
312
+ 2643833823,
313
+ 1695183700,
314
+ 2343527390,
315
+ 1986661051,
316
+ 1014477480,
317
+ 2177026350,
318
+ 1206759142,
319
+ 2456956037,
320
+ 344077627,
321
+ 2730485921,
322
+ 1290863460,
323
+ 2820302411,
324
+ 3158454273,
325
+ 3259730800,
326
+ 3505952657,
327
+ 3345764771,
328
+ 106217008,
329
+ 3516065817,
330
+ 3606008344,
331
+ 3600352804,
332
+ 1432725776,
333
+ 4094571909,
334
+ 1467031594,
335
+ 275423344,
336
+ 851169720,
337
+ 430227734,
338
+ 3100823752,
339
+ 506948616,
340
+ 1363258195,
341
+ 659060556,
342
+ 3750685593,
343
+ 883997877,
344
+ 3785050280,
345
+ 958139571,
346
+ 3318307427,
347
+ 1322822218,
348
+ 3812723403,
349
+ 1537002063,
350
+ 2003034995,
351
+ 1747873779,
352
+ 3602036899,
353
+ 1955562222,
354
+ 1575990012,
355
+ 2024104815,
356
+ 1125592928,
357
+ 2227730452,
358
+ 2716904306,
359
+ 2361852424,
360
+ 442776044,
361
+ 2428436474,
362
+ 593698344,
363
+ 2756734187,
364
+ 3733110249,
365
+ 3204031479,
366
+ 2999351573,
367
+ 3329325298,
368
+ 3815920427,
369
+ 3391569614,
370
+ 3928383900,
371
+ 3515267271,
372
+ 566280711,
373
+ 3940187606,
374
+ 3454069534,
375
+ 4118630271,
376
+ 4000239992,
377
+ 116418474,
378
+ 1914138554,
379
+ 174292421,
380
+ 2731055270,
381
+ 289380356,
382
+ 3203993006,
383
+ 460393269,
384
+ 320620315,
385
+ 685471733,
386
+ 587496836,
387
+ 852142971,
388
+ 1086792851,
389
+ 1017036298,
390
+ 365543100,
391
+ 1126000580,
392
+ 2618297676,
393
+ 1288033470,
394
+ 3409855158,
395
+ 1501505948,
396
+ 4234509866,
397
+ 1607167915,
398
+ 987167468,
399
+ 1816402316,
400
+ 1246189591
401
+ ]);
402
+ var IV_512 = [
403
+ 1779033703,
404
+ 4089235720,
405
+ 3144134277,
406
+ 2227873595,
407
+ 1013904242,
408
+ 4271175723,
409
+ 2773480762,
410
+ 1595750129,
411
+ 1359893119,
412
+ 2917565137,
413
+ 2600822924,
414
+ 725511199,
415
+ 528734635,
416
+ 4215389547,
417
+ 1541459225,
418
+ 327033209
419
+ ];
420
+ var IV_384 = [
421
+ 3418070365,
422
+ 3238371032,
423
+ 1654270250,
424
+ 914150663,
425
+ 2438529370,
426
+ 812702999,
427
+ 355462360,
428
+ 4144912697,
429
+ 1731405415,
430
+ 4290775857,
431
+ 2394180231,
432
+ 1750603025,
433
+ 3675008525,
434
+ 1694076839,
435
+ 1203062813,
436
+ 3204075428
437
+ ];
438
+ var W3 = new Uint32Array(160);
439
+ function compress3(h, data, offset) {
440
+ for (let i = 0; i < 32; i++) {
441
+ const o = offset + i * 4;
442
+ W3[i] = (data[o] << 24 | data[o + 1] << 16 | data[o + 2] << 8 | data[o + 3]) >>> 0;
443
+ }
444
+ for (let i = 16; i < 80; i++) {
445
+ const xh = W3[(i - 15) * 2];
446
+ const xl = W3[(i - 15) * 2 + 1];
447
+ const s0h = (xh >>> 1 | xl << 31) ^ (xh >>> 8 | xl << 24) ^ xh >>> 7;
448
+ const s0l = (xl >>> 1 | xh << 31) ^ (xl >>> 8 | xh << 24) ^ (xl >>> 7 | xh << 25);
449
+ const yh = W3[(i - 2) * 2];
450
+ const yl = W3[(i - 2) * 2 + 1];
451
+ const s1h = (yh >>> 19 | yl << 13) ^ (yl >>> 29 | yh << 3) ^ yh >>> 6;
452
+ const s1l = (yl >>> 19 | yh << 13) ^ (yh >>> 29 | yl << 3) ^ (yl >>> 6 | yh << 26);
453
+ let lo = (s0l >>> 0) + (s1l >>> 0) + W3[(i - 7) * 2 + 1] + W3[(i - 16) * 2 + 1];
454
+ const hi = s0h + s1h + W3[(i - 7) * 2] + W3[(i - 16) * 2] + Math.floor(lo / 4294967296);
455
+ lo >>>= 0;
456
+ W3[i * 2] = hi >>> 0;
457
+ W3[i * 2 + 1] = lo;
458
+ }
459
+ let ah = h[0], al = h[1], bh = h[2], bl = h[3], ch = h[4], cl = h[5], dh = h[6], dl = h[7];
460
+ let eh = h[8], el = h[9], fh = h[10], fl = h[11], gh = h[12], gl = h[13], hh = h[14], hl = h[15];
461
+ for (let i = 0; i < 80; i++) {
462
+ const S1h = (eh >>> 14 | el << 18) ^ (eh >>> 18 | el << 14) ^ (el >>> 9 | eh << 23);
463
+ const S1l = (el >>> 14 | eh << 18) ^ (el >>> 18 | eh << 14) ^ (eh >>> 9 | el << 23);
464
+ const chh = eh & fh ^ ~eh & gh;
465
+ const chl = el & fl ^ ~el & gl;
466
+ let t1l = (hl >>> 0) + (S1l >>> 0) + (chl >>> 0) + K2[i * 2 + 1] + W3[i * 2 + 1];
467
+ const t1h = hh + S1h + chh + K2[i * 2] + W3[i * 2] + Math.floor(t1l / 4294967296);
468
+ t1l >>>= 0;
469
+ const S0h = (ah >>> 28 | al << 4) ^ (al >>> 2 | ah << 30) ^ (al >>> 7 | ah << 25);
470
+ const S0l = (al >>> 28 | ah << 4) ^ (ah >>> 2 | al << 30) ^ (ah >>> 7 | al << 25);
471
+ const majh = ah & bh ^ ah & ch ^ bh & ch;
472
+ const majl = al & bl ^ al & cl ^ bl & cl;
473
+ let t2l = (S0l >>> 0) + (majl >>> 0);
474
+ const t2h = S0h + majh + Math.floor(t2l / 4294967296);
475
+ t2l >>>= 0;
476
+ hh = gh;
477
+ hl = gl;
478
+ gh = fh;
479
+ gl = fl;
480
+ fh = eh;
481
+ fl = el;
482
+ let nl = (dl >>> 0) + t1l;
483
+ eh = dh + t1h + Math.floor(nl / 4294967296) >>> 0;
484
+ el = nl >>> 0;
485
+ dh = ch;
486
+ dl = cl;
487
+ ch = bh;
488
+ cl = bl;
489
+ bh = ah;
490
+ bl = al;
491
+ nl = t1l + t2l;
492
+ ah = t1h + t2h + Math.floor(nl / 4294967296) >>> 0;
493
+ al = nl >>> 0;
494
+ }
495
+ const add = (i, xh, xl) => {
496
+ const lo = (h[i + 1] >>> 0) + (xl >>> 0);
497
+ h[i] = h[i] + xh + Math.floor(lo / 4294967296) >>> 0;
498
+ h[i + 1] = lo >>> 0;
499
+ };
500
+ add(0, ah, al);
501
+ add(2, bh, bl);
502
+ add(4, ch, cl);
503
+ add(6, dh, dl);
504
+ add(8, eh, el);
505
+ add(10, fh, fl);
506
+ add(12, gh, gl);
507
+ add(14, hh, hl);
508
+ }
509
+ function digest64(data, iv, bytes) {
510
+ const h = new Uint32Array(iv);
511
+ const padded = new Uint8Array(Math.ceil((data.length + 17) / 128) * 128);
512
+ padded.set(data);
513
+ padded[data.length] = 128;
514
+ const bits = data.length * 8;
515
+ const view = new DataView(padded.buffer);
516
+ view.setUint32(padded.length - 8, Math.floor(bits / 4294967296));
517
+ view.setUint32(padded.length - 4, bits >>> 0);
518
+ for (let offset = 0; offset < padded.length; offset += 128) compress3(h, padded, offset);
519
+ const out = new Uint8Array(bytes);
520
+ const outView = new DataView(out.buffer);
521
+ for (let i = 0; i < bytes / 4; i++) outView.setUint32(i * 4, h[i]);
522
+ return out;
523
+ }
524
+ var sha512 = (data) => digest64(data, IV_512, 64);
525
+ var sha384 = (data) => digest64(data, IV_384, 48);
526
+
527
+ // src/digest/digest.ts
528
+ var DIGESTS = {
529
+ "SHA-1": sha1,
530
+ "SHA-256": sha256,
531
+ "SHA-384": sha384,
532
+ "SHA-512": sha512
533
+ };
534
+ function digestFunction(name) {
535
+ const canonical = normalizeDigestAlgorithmName(name);
536
+ return canonical && canonical in DIGESTS ? DIGESTS[canonical] : void 0;
537
+ }
538
+ function digestSync(name, data) {
539
+ return digestFunction(name)?.(data);
540
+ }
541
+
542
+ // src/digest/password-hash.ts
543
+ var MAX_SPIN_COUNT = 1e7;
544
+ var validSpinCount = (spinCount) => spinCount === void 0 || Number.isInteger(spinCount) && spinCount >= 0 && spinCount <= MAX_SPIN_COUNT;
545
+ function spin(password, salt, spinCount, digest) {
546
+ const input = new Uint8Array(salt.length + password.length * 2);
547
+ input.set(salt);
548
+ for (let i = 0; i < password.length; i++) {
549
+ const code = password.charCodeAt(i);
550
+ input[salt.length + i * 2] = code & 255;
551
+ input[salt.length + i * 2 + 1] = code >> 8;
552
+ }
553
+ let value = digest(input);
554
+ const buffer = new Uint8Array(value.length + 4);
555
+ const view = new DataView(buffer.buffer);
556
+ for (let i = 0; i < spinCount; i++) {
557
+ buffer.set(value);
558
+ view.setUint32(value.length, i, true);
559
+ value = digest(buffer);
560
+ }
561
+ return value;
562
+ }
563
+ function hashBytes(password, { algorithmName, saltValue, spinCount }) {
564
+ const digest = digestFunction(algorithmName);
565
+ const salt = decodeBase64(saltValue);
566
+ if (!digest || !salt || !validSpinCount(spinCount)) return void 0;
567
+ return spin(password, salt, spinCount ?? 0, digest);
568
+ }
569
+ function hashPassword(password, options) {
570
+ const bytes = hashBytes(password, options);
571
+ return bytes && encodeBase64(bytes);
572
+ }
573
+ function verifyPasswordHash(password, hash) {
574
+ if (!digestFunction(hash.algorithmName)) return void 0;
575
+ const expected = decodeBase64(hash.hashValue);
576
+ const actual = expected && hashBytes(password, hash);
577
+ if (!expected || !actual || actual.length !== expected.length) return false;
578
+ let difference = 0;
579
+ for (let i = 0; i < actual.length; i++) difference |= actual[i] ^ expected[i];
580
+ return difference === 0;
581
+ }
582
+
583
+ exports.MAX_SPIN_COUNT = MAX_SPIN_COUNT;
584
+ exports.decodeBase64 = decodeBase64;
585
+ exports.digestFunction = digestFunction;
586
+ exports.digestSync = digestSync;
587
+ exports.encodeBase64 = encodeBase64;
588
+ exports.hashPassword = hashPassword;
589
+ exports.normalizeDigestAlgorithmName = normalizeDigestAlgorithmName;
590
+ exports.sha1 = sha1;
591
+ exports.sha256 = sha256;
592
+ exports.sha384 = sha384;
593
+ exports.sha512 = sha512;
594
+ exports.verifyPasswordHash = verifyPasswordHash;
@@ -0,0 +1,8 @@
1
+ export { normalizeDigestAlgorithmName, type DigestAlgorithmName, type SupportedDigestName, } from './algorithm-names.js';
2
+ export { decodeBase64, encodeBase64 } from './base64.js';
3
+ export { digestFunction, digestSync, type DigestFunction } from './digest.js';
4
+ export { MAX_SPIN_COUNT, hashPassword, verifyPasswordHash, type PasswordHash, } from './password-hash.js';
5
+ export { sha1 } from './sha1.js';
6
+ export { sha256 } from './sha256.js';
7
+ export { sha384, sha512 } from './sha512.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/digest/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,4BAA4B,EAC5B,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EACN,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,KAAK,YAAY,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}