@serveryyswys/node.operit 0.0.0-stage → 0.1.2

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 (123) hide show
  1. package/BUILTINS.json +233 -0
  2. package/DESIGN.md +513 -0
  3. package/LICENSE +674 -0
  4. package/README.md +301 -2
  5. package/dist/assert/strict.d.ts +2 -0
  6. package/dist/assert/strict.js +7 -0
  7. package/dist/assert.d.ts +3 -0
  8. package/dist/assert.js +483 -0
  9. package/dist/buffer.d.ts +60 -0
  10. package/dist/buffer.js +524 -0
  11. package/dist/child_process.d.ts +56 -0
  12. package/dist/child_process.js +371 -0
  13. package/dist/constants.d.ts +2 -0
  14. package/dist/constants.js +19 -0
  15. package/dist/crypto.d.ts +76 -0
  16. package/dist/crypto.js +312 -0
  17. package/dist/dns/promises.d.ts +34 -0
  18. package/dist/dns/promises.js +190 -0
  19. package/dist/dns.d.ts +88 -0
  20. package/dist/dns.js +259 -0
  21. package/dist/events.d.ts +40 -0
  22. package/dist/events.js +237 -0
  23. package/dist/fs/promises.d.ts +159 -0
  24. package/dist/fs/promises.js +129 -0
  25. package/dist/fs.d.ts +221 -0
  26. package/dist/fs.js +944 -0
  27. package/dist/http.d.ts +92 -0
  28. package/dist/http.js +319 -0
  29. package/dist/https.d.ts +296 -0
  30. package/dist/https.js +50 -0
  31. package/dist/index.d.ts +2422 -0
  32. package/dist/index.js +57 -0
  33. package/dist/lib/bridge.d.ts +60 -0
  34. package/dist/lib/bridge.js +205 -0
  35. package/dist/lib/bytes.d.ts +20 -0
  36. package/dist/lib/bytes.js +239 -0
  37. package/dist/lib/child-process-types.d.ts +45 -0
  38. package/dist/lib/child-process-types.js +2 -0
  39. package/dist/lib/cwd.d.ts +2 -0
  40. package/dist/lib/cwd.js +32 -0
  41. package/dist/lib/deep-equal.d.ts +3 -0
  42. package/dist/lib/deep-equal.js +223 -0
  43. package/dist/lib/deflate.d.ts +2 -0
  44. package/dist/lib/deflate.js +234 -0
  45. package/dist/lib/dns-driver.d.ts +14 -0
  46. package/dist/lib/dns-driver.js +85 -0
  47. package/dist/lib/dns-types.d.ts +22 -0
  48. package/dist/lib/dns-types.js +2 -0
  49. package/dist/lib/errors.d.ts +48 -0
  50. package/dist/lib/errors.js +424 -0
  51. package/dist/lib/fs-driver.d.ts +70 -0
  52. package/dist/lib/fs-driver.js +364 -0
  53. package/dist/lib/fs-env.d.ts +30 -0
  54. package/dist/lib/fs-env.js +157 -0
  55. package/dist/lib/fs-types.d.ts +19 -0
  56. package/dist/lib/fs-types.js +2 -0
  57. package/dist/lib/hashes.d.ts +27 -0
  58. package/dist/lib/hashes.js +432 -0
  59. package/dist/lib/http-driver.d.ts +30 -0
  60. package/dist/lib/http-driver.js +72 -0
  61. package/dist/lib/http-types.d.ts +18 -0
  62. package/dist/lib/http-types.js +2 -0
  63. package/dist/lib/inflate.d.ts +6 -0
  64. package/dist/lib/inflate.js +284 -0
  65. package/dist/lib/path-types.d.ts +37 -0
  66. package/dist/lib/path-types.js +2 -0
  67. package/dist/lib/paths.d.ts +8 -0
  68. package/dist/lib/paths.js +106 -0
  69. package/dist/lib/perf-hooks-types.d.ts +18 -0
  70. package/dist/lib/perf-hooks-types.js +2 -0
  71. package/dist/lib/process-driver.d.ts +31 -0
  72. package/dist/lib/process-driver.js +102 -0
  73. package/dist/lib/punycode.d.ts +8 -0
  74. package/dist/lib/punycode.js +179 -0
  75. package/dist/lib/stream-types.d.ts +29 -0
  76. package/dist/lib/stream-types.js +2 -0
  77. package/dist/lib/timers-types.d.ts +18 -0
  78. package/dist/lib/timers-types.js +2 -0
  79. package/dist/lib/url-search-params.d.ts +26 -0
  80. package/dist/lib/url-search-params.js +281 -0
  81. package/dist/lib/url-types.d.ts +44 -0
  82. package/dist/lib/url-types.js +2 -0
  83. package/dist/lib/url-whatwg.d.ts +78 -0
  84. package/dist/lib/url-whatwg.js +857 -0
  85. package/dist/lib/zlib-types.d.ts +12 -0
  86. package/dist/lib/zlib-types.js +2 -0
  87. package/dist/module.d.ts +8 -0
  88. package/dist/module.js +72 -0
  89. package/dist/os.d.ts +80 -0
  90. package/dist/os.js +247 -0
  91. package/dist/path/posix.d.ts +2 -0
  92. package/dist/path/posix.js +7 -0
  93. package/dist/path/win32.d.ts +2 -0
  94. package/dist/path/win32.js +10 -0
  95. package/dist/path.d.ts +3 -0
  96. package/dist/path.js +1222 -0
  97. package/dist/perf_hooks.d.ts +36 -0
  98. package/dist/perf_hooks.js +144 -0
  99. package/dist/process.d.ts +69 -0
  100. package/dist/process.js +230 -0
  101. package/dist/querystring.d.ts +15 -0
  102. package/dist/querystring.js +209 -0
  103. package/dist/stream/promises.d.ts +5 -0
  104. package/dist/stream/promises.js +10 -0
  105. package/dist/stream.d.ts +84 -0
  106. package/dist/stream.js +875 -0
  107. package/dist/string_decoder.d.ts +15 -0
  108. package/dist/string_decoder.js +237 -0
  109. package/dist/timers/promises.d.ts +19 -0
  110. package/dist/timers/promises.js +74 -0
  111. package/dist/timers.d.ts +21 -0
  112. package/dist/timers.js +41 -0
  113. package/dist/tty.d.ts +9 -0
  114. package/dist/tty.js +25 -0
  115. package/dist/unsupported.d.ts +12 -0
  116. package/dist/unsupported.js +17 -0
  117. package/dist/url.d.ts +28 -0
  118. package/dist/url.js +486 -0
  119. package/dist/util.d.ts +74 -0
  120. package/dist/util.js +515 -0
  121. package/dist/zlib.d.ts +88 -0
  122. package/dist/zlib.js +371 -0
  123. package/package.json +29 -4
@@ -0,0 +1,432 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HASHES = void 0;
4
+ exports.resolveAlgorithm = resolveAlgorithm;
5
+ exports.hashNames = hashNames;
6
+ exports.hmac = hmac;
7
+ exports.pbkdf2 = pbkdf2;
8
+ exports.toHex = toHex;
9
+ // ------------------------------------------------------------------ md5
10
+ const MD5_SHIFTS = [
11
+ 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
12
+ 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
13
+ 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
14
+ 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
15
+ ];
16
+ const MD5_K = (function buildMd5K() {
17
+ const table = new Uint32Array(64);
18
+ for (let i = 0; i < 64; i += 1) {
19
+ table[i] = Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296) >>> 0;
20
+ }
21
+ return table;
22
+ })();
23
+ function rotateLeft(value, bits) {
24
+ return ((value << bits) | (value >>> (32 - bits))) >>> 0;
25
+ }
26
+ function paddedMessage(bytes, blockSize, lengthSize, bigEndianLength) {
27
+ const bitLength = bytes.length * 8;
28
+ let total = bytes.length + 1;
29
+ while (total % blockSize !== blockSize - lengthSize) {
30
+ total += 1;
31
+ }
32
+ const out = new Uint8Array(total + lengthSize);
33
+ out.set(bytes);
34
+ out[bytes.length] = 0x80;
35
+ if (bigEndianLength) {
36
+ if (lengthSize === 8) {
37
+ const high = Math.floor(bitLength / 4294967296);
38
+ writeUint32BE(out, total, high >>> 0);
39
+ writeUint32BE(out, total + 4, bitLength >>> 0);
40
+ }
41
+ else {
42
+ writeUint32BE(out, total, 0);
43
+ writeUint32BE(out, total + 4, 0);
44
+ writeUint32BE(out, total + 8, Math.floor(bitLength / 4294967296) >>> 0);
45
+ writeUint32BE(out, total + 12, bitLength >>> 0);
46
+ }
47
+ }
48
+ else {
49
+ writeUint32LE(out, total, bitLength >>> 0);
50
+ writeUint32LE(out, total + 4, Math.floor(bitLength / 4294967296) >>> 0);
51
+ }
52
+ return out;
53
+ }
54
+ function writeUint32BE(target, offset, value) {
55
+ target[offset] = (value >>> 24) & 255;
56
+ target[offset + 1] = (value >>> 16) & 255;
57
+ target[offset + 2] = (value >>> 8) & 255;
58
+ target[offset + 3] = value & 255;
59
+ }
60
+ function writeUint32LE(target, offset, value) {
61
+ target[offset] = value & 255;
62
+ target[offset + 1] = (value >>> 8) & 255;
63
+ target[offset + 2] = (value >>> 16) & 255;
64
+ target[offset + 3] = (value >>> 24) & 255;
65
+ }
66
+ function readUint32BE(source, offset) {
67
+ return ((source[offset] << 24) | (source[offset + 1] << 16) | (source[offset + 2] << 8) | source[offset + 3]) >>> 0;
68
+ }
69
+ function readUint32LE(source, offset) {
70
+ return (source[offset] | (source[offset + 1] << 8) | (source[offset + 2] << 16) | (source[offset + 3] << 24)) >>> 0;
71
+ }
72
+ function md5(bytes) {
73
+ const message = paddedMessage(bytes, 64, 8, false);
74
+ let a0 = 0x67452301;
75
+ let b0 = 0xefcdab89;
76
+ let c0 = 0x98badcfe;
77
+ let d0 = 0x10325476;
78
+ for (let chunk = 0; chunk < message.length; chunk += 64) {
79
+ const words = new Uint32Array(16);
80
+ for (let i = 0; i < 16; i += 1) {
81
+ words[i] = readUint32LE(message, chunk + i * 4);
82
+ }
83
+ let a = a0;
84
+ let b = b0;
85
+ let c = c0;
86
+ let d = d0;
87
+ for (let i = 0; i < 64; i += 1) {
88
+ let f;
89
+ let g;
90
+ if (i < 16) {
91
+ f = (b & c) | (~b & d);
92
+ g = i;
93
+ }
94
+ else if (i < 32) {
95
+ f = (d & b) | (~d & c);
96
+ g = (5 * i + 1) % 16;
97
+ }
98
+ else if (i < 48) {
99
+ f = b ^ c ^ d;
100
+ g = (3 * i + 5) % 16;
101
+ }
102
+ else {
103
+ f = c ^ (b | ~d);
104
+ g = (7 * i) % 16;
105
+ }
106
+ f = (f + a + MD5_K[i] + words[g]) >>> 0;
107
+ a = d;
108
+ d = c;
109
+ c = b;
110
+ b = (b + rotateLeft(f, MD5_SHIFTS[i])) >>> 0;
111
+ }
112
+ a0 = (a0 + a) >>> 0;
113
+ b0 = (b0 + b) >>> 0;
114
+ c0 = (c0 + c) >>> 0;
115
+ d0 = (d0 + d) >>> 0;
116
+ }
117
+ const out = new Uint8Array(16);
118
+ writeUint32LE(out, 0, a0);
119
+ writeUint32LE(out, 4, b0);
120
+ writeUint32LE(out, 8, c0);
121
+ writeUint32LE(out, 12, d0);
122
+ return out;
123
+ }
124
+ // ------------------------------------------------------------------ sha1
125
+ function sha1(bytes) {
126
+ const message = paddedMessage(bytes, 64, 8, true);
127
+ let h0 = 0x67452301;
128
+ let h1 = 0xefcdab89;
129
+ let h2 = 0x98badcfe;
130
+ let h3 = 0x10325476;
131
+ let h4 = 0xc3d2e1f0;
132
+ for (let chunk = 0; chunk < message.length; chunk += 64) {
133
+ const w = new Uint32Array(80);
134
+ for (let i = 0; i < 16; i += 1) {
135
+ w[i] = readUint32BE(message, chunk + i * 4);
136
+ }
137
+ for (let i = 16; i < 80; i += 1) {
138
+ w[i] = rotateLeft(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
139
+ }
140
+ let a = h0;
141
+ let b = h1;
142
+ let c = h2;
143
+ let d = h3;
144
+ let e = h4;
145
+ for (let i = 0; i < 80; i += 1) {
146
+ let f;
147
+ let k;
148
+ if (i < 20) {
149
+ f = (b & c) | (~b & d);
150
+ k = 0x5a827999;
151
+ }
152
+ else if (i < 40) {
153
+ f = b ^ c ^ d;
154
+ k = 0x6ed9eba1;
155
+ }
156
+ else if (i < 60) {
157
+ f = (b & c) | (b & d) | (c & d);
158
+ k = 0x8f1bbcdc;
159
+ }
160
+ else {
161
+ f = b ^ c ^ d;
162
+ k = 0xca62c1d6;
163
+ }
164
+ const temp = (rotateLeft(a, 5) + f + e + k + w[i]) >>> 0;
165
+ e = d;
166
+ d = c;
167
+ c = rotateLeft(b, 30);
168
+ b = a;
169
+ a = temp;
170
+ }
171
+ h0 = (h0 + a) >>> 0;
172
+ h1 = (h1 + b) >>> 0;
173
+ h2 = (h2 + c) >>> 0;
174
+ h3 = (h3 + d) >>> 0;
175
+ h4 = (h4 + e) >>> 0;
176
+ }
177
+ const out = new Uint8Array(20);
178
+ writeUint32BE(out, 0, h0);
179
+ writeUint32BE(out, 4, h1);
180
+ writeUint32BE(out, 8, h2);
181
+ writeUint32BE(out, 12, h3);
182
+ writeUint32BE(out, 16, h4);
183
+ return out;
184
+ }
185
+ // ------------------------------------------------------------------ sha256 / sha224
186
+ const SHA256_K = [
187
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
188
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
189
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
190
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
191
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
192
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
193
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
194
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
195
+ ];
196
+ function sha256Core(bytes, iv, outLength) {
197
+ const message = paddedMessage(bytes, 64, 8, true);
198
+ const h = iv.slice();
199
+ const w = new Uint32Array(64);
200
+ for (let chunk = 0; chunk < message.length; chunk += 64) {
201
+ for (let i = 0; i < 16; i += 1) {
202
+ w[i] = readUint32BE(message, chunk + i * 4);
203
+ }
204
+ for (let i = 16; i < 64; i += 1) {
205
+ const s0 = rotateRight32(w[i - 15], 7) ^ rotateRight32(w[i - 15], 18) ^ (w[i - 15] >>> 3);
206
+ const s1 = rotateRight32(w[i - 2], 17) ^ rotateRight32(w[i - 2], 19) ^ (w[i - 2] >>> 10);
207
+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
208
+ }
209
+ let a = h[0];
210
+ let b = h[1];
211
+ let c = h[2];
212
+ let d = h[3];
213
+ let e = h[4];
214
+ let f = h[5];
215
+ let g = h[6];
216
+ let hh = h[7];
217
+ for (let i = 0; i < 64; i += 1) {
218
+ const s1 = rotateRight32(e, 6) ^ rotateRight32(e, 11) ^ rotateRight32(e, 25);
219
+ const ch = (e & f) ^ (~e & g);
220
+ const temp1 = (hh + s1 + ch + SHA256_K[i] + w[i]) >>> 0;
221
+ const s0 = rotateRight32(a, 2) ^ rotateRight32(a, 13) ^ rotateRight32(a, 22);
222
+ const maj = (a & b) ^ (a & c) ^ (b & c);
223
+ const temp2 = (s0 + maj) >>> 0;
224
+ hh = g;
225
+ g = f;
226
+ f = e;
227
+ e = (d + temp1) >>> 0;
228
+ d = c;
229
+ c = b;
230
+ b = a;
231
+ a = (temp1 + temp2) >>> 0;
232
+ }
233
+ h[0] = (h[0] + a) >>> 0;
234
+ h[1] = (h[1] + b) >>> 0;
235
+ h[2] = (h[2] + c) >>> 0;
236
+ h[3] = (h[3] + d) >>> 0;
237
+ h[4] = (h[4] + e) >>> 0;
238
+ h[5] = (h[5] + f) >>> 0;
239
+ h[6] = (h[6] + g) >>> 0;
240
+ h[7] = (h[7] + hh) >>> 0;
241
+ }
242
+ const out = new Uint8Array(outLength);
243
+ for (let i = 0; i < outLength / 4; i += 1) {
244
+ writeUint32BE(out, i * 4, h[i]);
245
+ }
246
+ return out;
247
+ }
248
+ function rotateRight32(value, bits) {
249
+ return ((value >>> bits) | (value << (32 - bits))) >>> 0;
250
+ }
251
+ function sha256(bytes) {
252
+ return sha256Core(bytes, [
253
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
254
+ 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
255
+ ], 32);
256
+ }
257
+ function sha224(bytes) {
258
+ return sha256Core(bytes, [
259
+ 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
260
+ 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
261
+ ], 28);
262
+ }
263
+ // ------------------------------------------------------------------ sha512 / sha384
264
+ const SHA512_K = [
265
+ 0x428a2f98d728ae22n, 0x7137449123ef65cdn, 0xb5c0fbcfec4d3b2fn, 0xe9b5dba58189dbbcn,
266
+ 0x3956c25bf348b538n, 0x59f111f1b605d019n, 0x923f82a4af194f9bn, 0xab1c5ed5da6d8118n,
267
+ 0xd807aa98a3030242n, 0x12835b0145706fben, 0x243185be4ee4b28cn, 0x550c7dc3d5ffb4e2n,
268
+ 0x72be5d74f27b896fn, 0x80deb1fe3b1696b1n, 0x9bdc06a725c71235n, 0xc19bf174cf692694n,
269
+ 0xe49b69c19ef14ad2n, 0xefbe4786384f25e3n, 0x0fc19dc68b8cd5b5n, 0x240ca1cc77ac9c65n,
270
+ 0x2de92c6f592b0275n, 0x4a7484aa6ea6e483n, 0x5cb0a9dcbd41fbd4n, 0x76f988da831153b5n,
271
+ 0x983e5152ee66dfabn, 0xa831c66d2db43210n, 0xb00327c898fb213fn, 0xbf597fc7beef0ee4n,
272
+ 0xc6e00bf33da88fc2n, 0xd5a79147930aa725n, 0x06ca6351e003826fn, 0x142929670a0e6e70n,
273
+ 0x27b70a8546d22ffcn, 0x2e1b21385c26c926n, 0x4d2c6dfc5ac42aedn, 0x53380d139d95b3dfn,
274
+ 0x650a73548baf63den, 0x766a0abb3c77b2a8n, 0x81c2c92e47edaee6n, 0x92722c851482353bn,
275
+ 0xa2bfe8a14cf10364n, 0xa81a664bbc423001n, 0xc24b8b70d0f89791n, 0xc76c51a30654be30n,
276
+ 0xd192e819d6ef5218n, 0xd69906245565a910n, 0xf40e35855771202an, 0x106aa07032bbd1b8n,
277
+ 0x19a4c116b8d2d0c8n, 0x1e376c085141ab53n, 0x2748774cdf8eeb99n, 0x34b0bcb5e19b48a8n,
278
+ 0x391c0cb3c5c95a63n, 0x4ed8aa4ae3418acbn, 0x5b9cca4f7763e373n, 0x682e6ff3d6b2b8a3n,
279
+ 0x748f82ee5defb2fcn, 0x78a5636f43172f60n, 0x84c87814a1f0ab72n, 0x8cc702081a6439ecn,
280
+ 0x90befffa23631e28n, 0xa4506cebde82bde9n, 0xbef9a3f7b2c67915n, 0xc67178f2e372532bn,
281
+ 0xca273eceea26619cn, 0xd186b8c721c0c207n, 0xeada7dd6cde0eb1en, 0xf57d4f7fee6ed178n,
282
+ 0x06f067aa72176fban, 0x0a637dc5a2c898a6n, 0x113f9804bef90daen, 0x1b710b35131c471bn,
283
+ 0x28db77f523047d84n, 0x32caab7b40c72493n, 0x3c9ebe0a15c9bebcn, 0x431d67c49c100d4cn,
284
+ 0x4cc5d4becb3e42b6n, 0x597f299cfc657e2an, 0x5fcb6fab3ad6faecn, 0x6c44198c4a475817n
285
+ ];
286
+ const MASK64 = 0xffffffffffffffffn;
287
+ function rotateRight64(value, bits) {
288
+ return ((value >> bits) | (value << (64n - bits))) & MASK64;
289
+ }
290
+ function readUint64BE(source, offset) {
291
+ let out = 0n;
292
+ for (let i = 0; i < 8; i += 1) {
293
+ out = (out << 8n) | BigInt(source[offset + i]);
294
+ }
295
+ return out;
296
+ }
297
+ function sha512Core(bytes, iv, outLength) {
298
+ const message = paddedMessage(bytes, 128, 16, true);
299
+ const h = iv.slice();
300
+ const w = new Array(80);
301
+ for (let chunk = 0; chunk < message.length; chunk += 128) {
302
+ for (let i = 0; i < 16; i += 1) {
303
+ w[i] = readUint64BE(message, chunk + i * 8);
304
+ }
305
+ for (let i = 16; i < 80; i += 1) {
306
+ const s0 = rotateRight64(w[i - 15], 1n) ^ rotateRight64(w[i - 15], 8n) ^ (w[i - 15] >> 7n);
307
+ const s1 = rotateRight64(w[i - 2], 19n) ^ rotateRight64(w[i - 2], 61n) ^ (w[i - 2] >> 6n);
308
+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) & MASK64;
309
+ }
310
+ let a = h[0];
311
+ let b = h[1];
312
+ let c = h[2];
313
+ let d = h[3];
314
+ let e = h[4];
315
+ let f = h[5];
316
+ let g = h[6];
317
+ let hh = h[7];
318
+ for (let i = 0; i < 80; i += 1) {
319
+ const s1 = rotateRight64(e, 14n) ^ rotateRight64(e, 18n) ^ rotateRight64(e, 41n);
320
+ const ch = (e & f) ^ (~e & g & MASK64);
321
+ const temp1 = (hh + s1 + ch + SHA512_K[i] + w[i]) & MASK64;
322
+ const s0 = rotateRight64(a, 28n) ^ rotateRight64(a, 34n) ^ rotateRight64(a, 39n);
323
+ const maj = (a & b) ^ (a & c) ^ (b & c);
324
+ const temp2 = (s0 + maj) & MASK64;
325
+ hh = g;
326
+ g = f;
327
+ f = e;
328
+ e = (d + temp1) & MASK64;
329
+ d = c;
330
+ c = b;
331
+ b = a;
332
+ a = (temp1 + temp2) & MASK64;
333
+ }
334
+ h[0] = (h[0] + a) & MASK64;
335
+ h[1] = (h[1] + b) & MASK64;
336
+ h[2] = (h[2] + c) & MASK64;
337
+ h[3] = (h[3] + d) & MASK64;
338
+ h[4] = (h[4] + e) & MASK64;
339
+ h[5] = (h[5] + f) & MASK64;
340
+ h[6] = (h[6] + g) & MASK64;
341
+ h[7] = (h[7] + hh) & MASK64;
342
+ }
343
+ const out = new Uint8Array(outLength);
344
+ for (let i = 0; i < outLength / 8; i += 1) {
345
+ let word = h[i];
346
+ for (let b = 7; b >= 0; b -= 1) {
347
+ out[i * 8 + b] = Number(word & 0xffn);
348
+ word >>= 8n;
349
+ }
350
+ }
351
+ return out;
352
+ }
353
+ function sha512(bytes) {
354
+ return sha512Core(bytes, [
355
+ 0x6a09e667f3bcc908n, 0xbb67ae8584caa73bn, 0x3c6ef372fe94f82bn, 0xa54ff53a5f1d36f1n,
356
+ 0x510e527fade682d1n, 0x9b05688c2b3e6c1fn, 0x1f83d9abfb41bd6bn, 0x5be0cd19137e2179n
357
+ ], 64);
358
+ }
359
+ function sha384(bytes) {
360
+ return sha512Core(bytes, [
361
+ 0xcbbb9d5dc1059ed8n, 0x629a292a367cd507n, 0x9159015a3070dd17n, 0x152fecd8f70e5939n,
362
+ 0x67332667ffc00b31n, 0x8eb44a8768581511n, 0xdb0c2e0d64f98fa7n, 0x47b5481dbefa4fa4n
363
+ ], 48);
364
+ }
365
+ // ------------------------------------------------------------------ 注册表与 HMAC
366
+ exports.HASHES = {
367
+ md5: { name: 'md5', blockSize: 64, digestLength: 16, compute: md5 },
368
+ sha1: { name: 'sha1', blockSize: 64, digestLength: 20, compute: sha1 },
369
+ sha224: { name: 'sha224', blockSize: 64, digestLength: 28, compute: sha224 },
370
+ sha256: { name: 'sha256', blockSize: 64, digestLength: 32, compute: sha256 },
371
+ sha384: { name: 'sha384', blockSize: 128, digestLength: 48, compute: sha384 },
372
+ sha512: { name: 'sha512', blockSize: 128, digestLength: 64, compute: sha512 }
373
+ };
374
+ /** 把 Node 的算法别名(大小写、连字符、sha-256 之类)归一到注册表的键。 */
375
+ function resolveAlgorithm(name) {
376
+ const normalized = String(name).toLowerCase().replace(/-/g, '');
377
+ const spec = exports.HASHES[normalized];
378
+ if (spec === undefined) {
379
+ const error = new Error('Digest method not supported: ' + String(name));
380
+ error.code = 'ERR_CRYPTO_INVALID_DIGEST';
381
+ throw error;
382
+ }
383
+ return spec;
384
+ }
385
+ function hashNames() {
386
+ return Object.keys(exports.HASHES);
387
+ }
388
+ /** HMAC(RFC 2104)。 */
389
+ function hmac(spec, key, message) {
390
+ let normalizedKey = key;
391
+ if (normalizedKey.length > spec.blockSize) {
392
+ normalizedKey = spec.compute(normalizedKey);
393
+ }
394
+ const inner = new Uint8Array(spec.blockSize + message.length);
395
+ const outer = new Uint8Array(spec.blockSize + spec.digestLength);
396
+ for (let i = 0; i < spec.blockSize; i += 1) {
397
+ const byte = i < normalizedKey.length ? normalizedKey[i] : 0;
398
+ inner[i] = byte ^ 0x36;
399
+ outer[i] = byte ^ 0x5c;
400
+ }
401
+ inner.set(message, spec.blockSize);
402
+ outer.set(spec.compute(inner), spec.blockSize);
403
+ return spec.compute(outer);
404
+ }
405
+ /** PBKDF2(RFC 2898),基于 HMAC。 */
406
+ function pbkdf2(spec, password, salt, iterations, keyLength) {
407
+ const blocks = Math.ceil(keyLength / spec.digestLength);
408
+ const out = new Uint8Array(blocks * spec.digestLength);
409
+ const saltBlock = new Uint8Array(salt.length + 4);
410
+ saltBlock.set(salt);
411
+ for (let block = 1; block <= blocks; block += 1) {
412
+ writeUint32BE(saltBlock, salt.length, block);
413
+ let current = hmac(spec, password, saltBlock);
414
+ const accumulated = current.slice();
415
+ for (let round = 1; round < iterations; round += 1) {
416
+ current = hmac(spec, password, current);
417
+ for (let i = 0; i < accumulated.length; i += 1) {
418
+ accumulated[i] ^= current[i];
419
+ }
420
+ }
421
+ out.set(accumulated, (block - 1) * spec.digestLength);
422
+ }
423
+ return out.slice(0, keyLength);
424
+ }
425
+ function toHex(bytes) {
426
+ const digits = '0123456789abcdef';
427
+ let out = '';
428
+ for (let i = 0; i < bytes.length; i += 1) {
429
+ out += digits.charAt(bytes[i] >> 4) + digits.charAt(bytes[i] & 15);
430
+ }
431
+ return out;
432
+ }
@@ -0,0 +1,30 @@
1
+ export interface HttpRequestSpec {
2
+ url: string;
3
+ method: string;
4
+ headers: Record<string, string>;
5
+ body?: string;
6
+ }
7
+ export interface HttpHostResponse {
8
+ url: string;
9
+ statusCode: number;
10
+ statusMessage: string;
11
+ headers: Record<string, string>;
12
+ contentType: string;
13
+ content: string;
14
+ contentBase64: string | null;
15
+ size: number;
16
+ }
17
+ export interface HttpDriver {
18
+ /** 返回的是**未校验**的宿主返回值,交给 normalizeResponse 校验成 HttpHostResponse。 */
19
+ request(spec: HttpRequestSpec): Promise<unknown>;
20
+ }
21
+ /** 宿主注入点:桌面测试用,传 null 恢复为走 toolCall 的默认实现。 */
22
+ export declare function setDriver(next: HttpDriver | null): void;
23
+ /**
24
+ * 把宿主返回的对象校验成 HttpHostResponse;形状不对就明确报错,不做静默兜底。
25
+ *
26
+ * 这一步必须对**所有**驱动都跑(包括测试注入的),所以由 http.ts 在 send() 里调用,
27
+ * 而不是只放在默认驱动里 —— 否则注入的驱动会绕开校验。
28
+ */
29
+ export declare function normalizeResponse(raw: unknown): HttpHostResponse;
30
+ export declare function getDriver(): HttpDriver;
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setDriver = setDriver;
4
+ exports.normalizeResponse = normalizeResponse;
5
+ exports.getDriver = getDriver;
6
+ let driver = null;
7
+ /** 宿主注入点:桌面测试用,传 null 恢复为走 toolCall 的默认实现。 */
8
+ function setDriver(next) {
9
+ driver = next;
10
+ }
11
+ function hostToolCall() {
12
+ const global = globalThis;
13
+ if (typeof global.toolCall !== 'function') {
14
+ throw new Error('node.operit: 宿主没有提供 toolCall,http 请求无法发出。');
15
+ }
16
+ return global.toolCall;
17
+ }
18
+ /**
19
+ * 把宿主返回的对象校验成 HttpHostResponse;形状不对就明确报错,不做静默兜底。
20
+ *
21
+ * 这一步必须对**所有**驱动都跑(包括测试注入的),所以由 http.ts 在 send() 里调用,
22
+ * 而不是只放在默认驱动里 —— 否则注入的驱动会绕开校验。
23
+ */
24
+ function normalizeResponse(raw) {
25
+ if (raw === null || typeof raw !== 'object') {
26
+ throw new Error('node.operit: http_request 的返回值不是对象,无法解释为 HTTP 响应。');
27
+ }
28
+ const value = raw;
29
+ if (typeof value.statusCode !== 'number') {
30
+ throw new Error('node.operit: http_request 的返回值缺少 statusCode 字段。');
31
+ }
32
+ const headers = {};
33
+ if (value.headers !== null && typeof value.headers === 'object') {
34
+ const source = value.headers;
35
+ for (const key of Object.keys(source)) {
36
+ headers[key] = String(source[key]);
37
+ }
38
+ }
39
+ return {
40
+ url: typeof value.url === 'string' ? value.url : '',
41
+ statusCode: value.statusCode,
42
+ statusMessage: typeof value.statusMessage === 'string' ? value.statusMessage : '',
43
+ headers: headers,
44
+ contentType: typeof value.contentType === 'string' ? value.contentType : '',
45
+ content: typeof value.content === 'string' ? value.content : '',
46
+ contentBase64: typeof value.contentBase64 === 'string' ? value.contentBase64 : null,
47
+ size: typeof value.size === 'number' ? value.size : 0
48
+ };
49
+ }
50
+ function createHostDriver() {
51
+ return {
52
+ request(spec) {
53
+ const params = {
54
+ url: spec.url,
55
+ method: spec.method
56
+ };
57
+ if (Object.keys(spec.headers).length > 0) {
58
+ params.headers = JSON.stringify(spec.headers);
59
+ }
60
+ if (spec.body !== undefined) {
61
+ params.body = spec.body;
62
+ }
63
+ return hostToolCall()('http_request', params);
64
+ }
65
+ };
66
+ }
67
+ function getDriver() {
68
+ if (driver === null) {
69
+ driver = createHostDriver();
70
+ }
71
+ return driver;
72
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * http / https 的公开类型。
3
+ *
4
+ * 独立成文件的原因与其他 types 文件相同:http.ts 用 `export =` 导出模块本体,
5
+ * 无法再导出类型,而 https.ts 与 index.ts 都需要能命名它。
6
+ */
7
+ export interface RequestOptions {
8
+ protocol?: string;
9
+ host?: string;
10
+ hostname?: string;
11
+ port?: string | number;
12
+ path?: string;
13
+ method?: string;
14
+ headers?: Record<string, string>;
15
+ auth?: string;
16
+ href?: string;
17
+ timeout?: number;
18
+ }
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ /** 解压 raw DEFLATE 数据。 */
2
+ export declare function inflateRaw(data: Uint8Array, start: number, end: number): Uint8Array;
3
+ /** gzip 的 CRC-32(IEEE 802.3)。 */
4
+ export declare function crc32(data: Uint8Array, start: number, end: number): number;
5
+ /** zlib 的 Adler-32。 */
6
+ export declare function adler32(data: Uint8Array, start: number, end: number): number;