@wener/utils 1.1.23 → 1.1.24
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/dist/LICENSE.txt +1 -135
- package/dist/cjs/index.cjs +6 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/servers/node-fetch.cjs +1 -1
- package/dist/cjs/servers/node-fetch.cjs.map +1 -1
- package/dist/esm/index.js +12 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/servers/node-fetch.js +1 -1
- package/dist/esm/servers/node-fetch.js.map +1 -1
- package/dist/system/index.js +6 -6
- package/dist/system/index.js.map +1 -1
- package/dist/system/servers/node-fetch.js +1 -1
- package/dist/system/servers/node-fetch.js.map +1 -1
- package/lib/crypto/hashing.js +53 -12
- package/lib/crypto/hashing.js.map +1 -1
- package/lib/index.js +1 -1
- package/package.json +5 -4
- package/src/crypto/hashing.test.ts +40 -2
- package/src/crypto/hashing.ts +95 -11
- package/src/fetch/types.ts +4 -1
- package/src/index.ts +1 -1
- package/dist/cjs/index-69020bc5.js +0 -13
- package/dist/cjs/index-69020bc5.js.map +0 -1
- package/dist/esm/index-f9528fde.js +0 -13
- package/dist/esm/index-f9528fde.js.map +0 -1
- package/dist/system/index-a2917815.js +0 -13
- package/dist/system/index-a2917815.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
System.register(["../getGlobalThis-8951eb0e.js"],function(F,f){"use strict";var u;return{setters:[function(
|
|
1
|
+
System.register(["../getGlobalThis-8951eb0e.js"],function(F,f){"use strict";var u;return{setters:[function(c){u=c.g}],execute:function(){F({createFetchWithProxyByNodeFetch:g,polyfillFetch:c});function c(o){if("fetch"in globalThis)return!1;if(o){const{default:t,Response:i,Headers:e,Request:s,AbortError:n,FetchError:a,FormData:r,Blob:h,File:l}=o;return Object.assign(globalThis,{fetch:t,Response:i,Headers:e,Request:s,AbortError:n,FetchError:a,FormData:r,Blob:h,File:l}),!0}return f.import("node-fetch").then(t=>c(t))}function g({proxy:o,fetch:t}={}){const i=u();if(!o)return t||i.fetch;let e;const s=i.Request;let n,a;return async(r,h)=>{if(!e){const{default:l}=await f.import("https-proxy-agent");e=l(o)}return n||({Request:n,default:a}=await f.import("node-fetch")),t||=a,r instanceof s?t(new s(r,{agent:e})):r instanceof n?t(new n(r,{agent:e})):t(r,{...h,agent:e})}}}}});
|
|
2
2
|
//# sourceMappingURL=node-fetch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-fetch.js","sources":["../../../src/servers/polyfill/polyfillFetch.ts","../../../src/servers/fetch/createFetchWithProxyByNodeFetch.ts"],"sourcesContent":["import type { MaybePromise } from '../../asyncs/MaybePromise';\n\nexport function polyfillFetch(nodeFetch: typeof import('node-fetch')): boolean;\nexport function polyfillFetch(nodeFetch?: undefined): Promise<boolean>;\nexport function polyfillFetch(nodeFetch?: typeof import('node-fetch')): MaybePromise<boolean> {\n if ('fetch' in globalThis) {\n return false;\n }\n // sync mode\n if (nodeFetch) {\n const { default: fetch, Response, Headers, Request, AbortError, FetchError, FormData, Blob, File } = nodeFetch;\n Object.assign(globalThis, {\n fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n });\n // abort controller\n return true;\n }\n return import('node-fetch').then((v) => polyfillFetch(v));\n}\n","import { type FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../isomorphics/getGlobalThis';\n\nexport function createFetchWithProxyByNodeFetch({\n proxy,\n fetch,\n}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {\n const globalThis = getGlobalThis();\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n\n let agent: any;\n const Request = globalThis.Request;\n let NodeRequest: any;\n let NodeFetch: any;\n return async (url, init?: RequestInit) => {\n if (!agent) {\n const { default: createHttpsProxyAgent } = await import('https-proxy-agent');\n agent = (createHttpsProxyAgent as any)(proxy);\n }\n\n // node-fetch 才可以,node v18 fetch 不支持\n if (!NodeRequest) {\n ({ Request: NodeRequest, default: NodeFetch } = await import('node-fetch'));\n }\n\n fetch ||= NodeFetch;\n\n if (url instanceof Request) {\n return (fetch as any)(new Request(url, { agent } as any));\n }\n if ((url as any) instanceof NodeRequest) {\n return (fetch as any)(new NodeRequest(url, { agent } as any));\n }\n return (fetch as any)(url, {\n ...init,\n agent,\n } as any);\n };\n}\n"],"names":["polyfillFetch","nodeFetch","fetch","Response","Headers","Request","AbortError","FetchError","FormData","Blob","File","module","v","createFetchWithProxyByNodeFetch","proxy","globalThis","getGlobalThis","agent","NodeRequest","NodeFetch","url","init","createHttpsProxyAgent"
|
|
1
|
+
{"version":3,"file":"node-fetch.js","sources":["../../../src/servers/polyfill/polyfillFetch.ts","../../../src/servers/fetch/createFetchWithProxyByNodeFetch.ts"],"sourcesContent":["import type { MaybePromise } from '../../asyncs/MaybePromise';\n\nexport function polyfillFetch(nodeFetch: typeof import('node-fetch')): boolean;\nexport function polyfillFetch(nodeFetch?: undefined): Promise<boolean>;\nexport function polyfillFetch(nodeFetch?: typeof import('node-fetch')): MaybePromise<boolean> {\n if ('fetch' in globalThis) {\n return false;\n }\n // sync mode\n if (nodeFetch) {\n const { default: fetch, Response, Headers, Request, AbortError, FetchError, FormData, Blob, File } = nodeFetch;\n Object.assign(globalThis, {\n fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n });\n // abort controller\n return true;\n }\n return import('node-fetch').then((v) => polyfillFetch(v));\n}\n","import { type FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../isomorphics/getGlobalThis';\n\nexport function createFetchWithProxyByNodeFetch({\n proxy,\n fetch,\n}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {\n const globalThis = getGlobalThis();\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n\n let agent: any;\n const Request = globalThis.Request;\n let NodeRequest: any;\n let NodeFetch: any;\n return async (url, init?: RequestInit) => {\n if (!agent) {\n const { default: createHttpsProxyAgent } = await import('https-proxy-agent');\n agent = (createHttpsProxyAgent as any)(proxy);\n }\n\n // node-fetch 才可以,node v18 fetch 不支持\n if (!NodeRequest) {\n ({ Request: NodeRequest, default: NodeFetch } = await import('node-fetch'));\n }\n\n fetch ||= NodeFetch;\n\n if (url instanceof Request) {\n return (fetch as any)(new Request(url, { agent } as any));\n }\n if ((url as any) instanceof NodeRequest) {\n return (fetch as any)(new NodeRequest(url, { agent } as any));\n }\n return (fetch as any)(url, {\n ...init,\n agent,\n } as any);\n };\n}\n"],"names":["polyfillFetch","nodeFetch","fetch","Response","Headers","Request","AbortError","FetchError","FormData","Blob","File","module","v","createFetchWithProxyByNodeFetch","proxy","globalThis","getGlobalThis","agent","NodeRequest","NodeFetch","url","init","createHttpsProxyAgent"],"mappings":"gMAIO,CAASA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAcC,CAAgE,CAAA,CAC5F,GAAI,CAAW,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACb,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAGT,CAAIA,CAAAA,CAAAA,CAAAA,CAAW,CACb,CAAM,CAAA,CAAA,CAAA,CAAA,CAAE,CAASC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAO,CAAAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAU,QAAAC,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAC,EAAS,CAAAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAY,WAAAC,CAAY,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,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,CAAUiB,CAAAA,CAAAA,CAAAA,CAAAA,CAENC,CAAef,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CACTH,CAAc,CAAA,CAAA,CAAA,CAAA,CAAIG,EAAQe,CAAK,CAAA,CAAE,CAAAH,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAM,CAAQ,CAAC,EAErDG,CAAuBF,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAClBhB,CAAc,CAAA,CAAA,CAAA,CAAA,CAAIgB,CAAYE,CAAAA,CAAAA,CAAK,CAAE,CAAAH,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAM,CAAQ,CAAC,CAEtDf,CAAAA,CAAAA,CAAckB,EAAK,CACzB,CAAA,CAAA,CAAGC,CACH,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAAJ,CACF,CAAQ,CACV,CACF;"}
|
package/lib/crypto/hashing.js
CHANGED
|
@@ -1,24 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ArrayBuffers } from '../io/ArrayBuffers.js';
|
|
2
|
+
|
|
3
|
+
function sha1(s, o) {
|
|
4
|
+
return digestOf("SHA-1", s, o);
|
|
3
5
|
}
|
|
4
|
-
function sha256(s) {
|
|
5
|
-
return digestOf("SHA-256", s);
|
|
6
|
+
function sha256(s, o) {
|
|
7
|
+
return digestOf("SHA-256", s, o);
|
|
6
8
|
}
|
|
7
|
-
function sha384(s) {
|
|
8
|
-
return digestOf("SHA-384", s);
|
|
9
|
+
function sha384(s, o) {
|
|
10
|
+
return digestOf("SHA-384", s, o);
|
|
9
11
|
}
|
|
10
|
-
function sha512(s) {
|
|
11
|
-
return digestOf("SHA-512", s);
|
|
12
|
+
function sha512(s, o) {
|
|
13
|
+
return digestOf("SHA-512", s, o);
|
|
12
14
|
}
|
|
13
|
-
function digestOf(a, s) {
|
|
14
|
-
|
|
15
|
+
function digestOf(a, s, o) {
|
|
16
|
+
let buffer = crypto.subtle.digest(a, binaryOf(s));
|
|
17
|
+
return o ? buffer.then((v) => encode(v, o)) : o;
|
|
15
18
|
}
|
|
16
|
-
function
|
|
19
|
+
function binaryOf(s) {
|
|
17
20
|
if (typeof s === "string") {
|
|
18
21
|
return new TextEncoder().encode(s);
|
|
19
22
|
}
|
|
20
23
|
return s;
|
|
21
24
|
}
|
|
25
|
+
function encode(buf, o) {
|
|
26
|
+
if (o) {
|
|
27
|
+
switch (o) {
|
|
28
|
+
case "hex":
|
|
29
|
+
case "base64":
|
|
30
|
+
return ArrayBuffers.toString(buf, o);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return buf;
|
|
34
|
+
}
|
|
35
|
+
async function hmac(hash, key, data, o) {
|
|
36
|
+
let ck = key instanceof CryptoKey ? key : await crypto.subtle.importKey(
|
|
37
|
+
"raw",
|
|
38
|
+
binaryOf(key),
|
|
39
|
+
{
|
|
40
|
+
name: "HMAC",
|
|
41
|
+
hash: {
|
|
42
|
+
name: normalizeHash(hash)
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
false,
|
|
46
|
+
["sign"]
|
|
47
|
+
);
|
|
48
|
+
let buffer = await crypto.subtle.sign(
|
|
49
|
+
{
|
|
50
|
+
name: "HMAC",
|
|
51
|
+
hash: {
|
|
52
|
+
name: hash
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
ck,
|
|
56
|
+
binaryOf(data)
|
|
57
|
+
);
|
|
58
|
+
return encode(buffer, o);
|
|
59
|
+
}
|
|
60
|
+
function normalizeHash(hash) {
|
|
61
|
+
return hash.replace(/^sha/i, "SHA-");
|
|
62
|
+
}
|
|
22
63
|
|
|
23
|
-
export { sha1, sha256, sha384, sha512 };
|
|
64
|
+
export { hmac, sha1, sha256, sha384, sha512 };
|
|
24
65
|
//# sourceMappingURL=hashing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hashing.js","sources":["../../src/crypto/hashing.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"hashing.js","sources":["../../src/crypto/hashing.ts"],"sourcesContent":["import { ArrayBuffers } from '../io/ArrayBuffers';\n\nexport function sha1(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha1(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha1(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-1', s, o);\n}\n\nexport function sha256(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha256(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha256(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-256', s, o);\n}\n\nexport function sha384(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha384(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha384(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-384', s, o);\n}\n\nexport function sha512(s: BinaryLike, o?: undefined): Promise<Buffer>;\nexport function sha512(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;\n\nexport function sha512(s: BinaryLike, o?: DigestOptions) {\n return digestOf('SHA-512', s, o);\n}\n\nfunction digestOf(a: string, s: BinaryLike, o?: DigestOptions) {\n let buffer = crypto.subtle.digest(a, binaryOf(s));\n return o ? buffer.then((v) => encode(v, o)) : o;\n}\n\nexport type DigestOptions =\n | 'hex'\n | 'base64'\n | {\n encoding: 'hex' | 'base64';\n };\n\ntype BinaryLike = string | BufferSource;\n\nfunction binaryOf(s: BinaryLike) {\n // ArrayBuffer, TypedArray, DataView\n if (typeof s === 'string') {\n return new TextEncoder().encode(s);\n }\n return s;\n}\n\nfunction encode(buf: BufferSource, o?: DigestOptions) {\n if (o) {\n switch (o) {\n case 'hex':\n case 'base64':\n return ArrayBuffers.toString(buf, o);\n }\n }\n return buf;\n}\n\ntype StringEncoding = 'hex' | 'base64';\ntype IsStringCoding<T> = T extends StringEncoding ? true : T extends { encoding: StringEncoding } ? true : false;\n\nexport function hmac<O extends DigestOptions>(\n hash: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' | 'sha1' | 'sha256' | 'sha384' | 'sha512',\n key: BinaryLike | CryptoKey,\n data: BinaryLike,\n o?: O,\n): Promise<IsStringCoding<O> extends true ? string : Buffer>;\n\nexport async function hmac(\n hash: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' | 'sha1' | 'sha256' | 'sha384' | 'sha512',\n key: BinaryLike | CryptoKey,\n data: BinaryLike,\n o?: DigestOptions,\n) {\n let ck =\n key instanceof CryptoKey\n ? key\n : await crypto.subtle.importKey(\n 'raw',\n binaryOf(key),\n {\n name: 'HMAC',\n hash: {\n name: normalizeHash(hash),\n },\n },\n false,\n ['sign'],\n );\n let buffer = await crypto.subtle.sign(\n {\n name: 'HMAC',\n hash: {\n name: hash,\n },\n },\n ck,\n binaryOf(data),\n );\n\n return encode(buffer, o);\n}\n\nfunction normalizeHash(hash: string) {\n return hash.replace(/^sha/i, 'SHA-');\n}\n"],"names":[],"mappings":";;AAKgB,SAAA,IAAA,CAAK,GAAe,CAAmB,EAAA;AACrD,EAAO,OAAA,QAAA,CAAS,OAAS,EAAA,CAAA,EAAG,CAAC,CAAA,CAAA;AAC/B,CAAA;AAKgB,SAAA,MAAA,CAAO,GAAe,CAAmB,EAAA;AACvD,EAAO,OAAA,QAAA,CAAS,SAAW,EAAA,CAAA,EAAG,CAAC,CAAA,CAAA;AACjC,CAAA;AAKgB,SAAA,MAAA,CAAO,GAAe,CAAmB,EAAA;AACvD,EAAO,OAAA,QAAA,CAAS,SAAW,EAAA,CAAA,EAAG,CAAC,CAAA,CAAA;AACjC,CAAA;AAKgB,SAAA,MAAA,CAAO,GAAe,CAAmB,EAAA;AACvD,EAAO,OAAA,QAAA,CAAS,SAAW,EAAA,CAAA,EAAG,CAAC,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AAA,CAAO,MAAO,CAAA,IAAA;AAAA,IAC/B;AAAA,MACE,IAAM,EAAA,MAAA;AAAA,MACN,IAAM,EAAA;AAAA,QACJ,IAAM,EAAA,IAAA;AAAA,OACR;AAAA,KACF;AAAA,IACA,EAAA;AAAA,IACA,SAAS,IAAI,CAAA;AAAA,GACf,CAAA;AAEA,EAAO,OAAA,MAAA,CAAO,QAAQ,CAAC,CAAA,CAAA;AACzB,CAAA;AAEA,SAAS,cAAc,IAAc,EAAA;AACnC,EAAO,OAAA,IAAA,CAAK,OAAQ,CAAA,OAAA,EAAS,MAAM,CAAA,CAAA;AACrC;;;;"}
|
package/lib/index.js
CHANGED
|
@@ -47,7 +47,7 @@ export { getGlobalThis } from './isomorphics/getGlobalThis.js';
|
|
|
47
47
|
export { structuredClone } from './isomorphics/structuredClone.js';
|
|
48
48
|
export { randomUUID } from './crypto/randomUUID.js';
|
|
49
49
|
export { getRandomValues } from './crypto/getRandomValues.js';
|
|
50
|
-
export { sha1, sha256, sha384, sha512 } from './crypto/hashing.js';
|
|
50
|
+
export { hmac, sha1, sha256, sha384, sha512 } from './crypto/hashing.js';
|
|
51
51
|
export { md5 } from './crypto/md5.js';
|
|
52
52
|
export { hex } from './crypto/base.js';
|
|
53
53
|
export { createULID, isULID, parseULID, ulid } from './crypto/ulid.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wener/utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Utils for daily use",
|
|
6
6
|
"repository": {
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/lodash": "^4.14.
|
|
43
|
-
"@types/ws": "^8.5.
|
|
42
|
+
"@types/lodash": "^4.14.200",
|
|
43
|
+
"@types/ws": "^8.5.8",
|
|
44
44
|
"https-proxy-agent": "^7.0.2",
|
|
45
45
|
"lodash": "^4.17.21",
|
|
46
46
|
"node-fetch": "^3.3.2",
|
|
47
|
-
"undici": "^5.
|
|
47
|
+
"undici": "^5.27.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"registry": "https://registry.npmjs.org",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"jsdom",
|
|
65
65
|
"node-fetch",
|
|
66
66
|
"ws",
|
|
67
|
+
"https-proxy-agent",
|
|
67
68
|
"undici"
|
|
68
69
|
]
|
|
69
70
|
},
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assert, beforeAll, expect, test } from 'vitest';
|
|
2
|
+
import { ArrayBuffers } from '../io/ArrayBuffers';
|
|
2
3
|
import { polyfillCrypto } from '../servers/polyfill/polyfillCrypto';
|
|
3
4
|
import { isUUID } from '../validations/isUUID';
|
|
4
5
|
import { hex } from './base';
|
|
5
|
-
import { sha1, sha256, sha384, sha512 } from './hashing';
|
|
6
|
+
import { hmac, sha1, sha256, sha384, sha512 } from './hashing';
|
|
6
7
|
import { md5 } from './md5';
|
|
7
8
|
import { _randomUUID } from './randomUUID';
|
|
8
9
|
|
|
@@ -12,6 +13,11 @@ beforeAll(async () => {
|
|
|
12
13
|
|
|
13
14
|
test('sha', async () => {
|
|
14
15
|
expect(hex(await sha1(''))).toBe('da39a3ee5e6b4b0d3255bfef95601890afd80709');
|
|
16
|
+
expect(await sha1('', 'hex')).toBe('da39a3ee5e6b4b0d3255bfef95601890afd80709');
|
|
17
|
+
expect(ArrayBuffers.toString(await sha1(''), 'base64')).toBe('2jmj7l5rSw0yVb/vlWAYkK/YBwk=');
|
|
18
|
+
expect(await sha1('', 'base64')).toBe('2jmj7l5rSw0yVb/vlWAYkK/YBwk=');
|
|
19
|
+
|
|
20
|
+
expect(await sha1('', 'hex')).toBe('da39a3ee5e6b4b0d3255bfef95601890afd80709');
|
|
15
21
|
expect(hex(await sha1('abc'))).toBe('a9993e364706816aba3e25717850c26c9cd0d89d');
|
|
16
22
|
expect(hex(await sha256(''))).toBe('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
|
|
17
23
|
expect(hex(await sha384(''))).toBe(
|
|
@@ -29,3 +35,35 @@ test('randomUUID', () => {
|
|
|
29
35
|
expect(isUUID(_randomUUID())).toBeTruthy();
|
|
30
36
|
}
|
|
31
37
|
});
|
|
38
|
+
|
|
39
|
+
test('hmac', async () => {
|
|
40
|
+
let key = await crypto.subtle.importKey(
|
|
41
|
+
'raw',
|
|
42
|
+
new TextEncoder().encode('YourAccessKeySecret'),
|
|
43
|
+
{
|
|
44
|
+
name: 'HMAC',
|
|
45
|
+
hash: {
|
|
46
|
+
name: 'SHA-256',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
false,
|
|
50
|
+
['sign', 'verify'],
|
|
51
|
+
);
|
|
52
|
+
const out = hex(
|
|
53
|
+
await crypto.subtle.sign(
|
|
54
|
+
{
|
|
55
|
+
name: 'HMAC',
|
|
56
|
+
hash: {
|
|
57
|
+
name: 'SHA-256',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
key,
|
|
61
|
+
new TextEncoder().encode(''),
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
console.log(out);
|
|
65
|
+
const { createHmac } = await import('node:crypto');
|
|
66
|
+
let fromNode = createHmac('sha256', 'YourAccessKeySecret').update('').digest('hex');
|
|
67
|
+
assert.equal(out, fromNode);
|
|
68
|
+
assert.equal(out, await hmac('sha256', 'YourAccessKeySecret', '', 'hex'));
|
|
69
|
+
});
|
package/src/crypto/hashing.ts
CHANGED
|
@@ -1,27 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ArrayBuffers } from '../io/ArrayBuffers';
|
|
2
|
+
|
|
3
|
+
export function sha1(s: BinaryLike, o?: undefined): Promise<Buffer>;
|
|
4
|
+
export function sha1(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
|
|
5
|
+
|
|
6
|
+
export function sha1(s: BinaryLike, o?: DigestOptions) {
|
|
7
|
+
return digestOf('SHA-1', s, o);
|
|
3
8
|
}
|
|
4
9
|
|
|
5
|
-
export function sha256(s:
|
|
6
|
-
|
|
10
|
+
export function sha256(s: BinaryLike, o?: undefined): Promise<Buffer>;
|
|
11
|
+
export function sha256(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
|
|
12
|
+
|
|
13
|
+
export function sha256(s: BinaryLike, o?: DigestOptions) {
|
|
14
|
+
return digestOf('SHA-256', s, o);
|
|
7
15
|
}
|
|
8
16
|
|
|
9
|
-
export function sha384(s:
|
|
10
|
-
|
|
17
|
+
export function sha384(s: BinaryLike, o?: undefined): Promise<Buffer>;
|
|
18
|
+
export function sha384(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
|
|
19
|
+
|
|
20
|
+
export function sha384(s: BinaryLike, o?: DigestOptions) {
|
|
21
|
+
return digestOf('SHA-384', s, o);
|
|
11
22
|
}
|
|
12
23
|
|
|
13
|
-
export function sha512(s:
|
|
14
|
-
|
|
24
|
+
export function sha512(s: BinaryLike, o?: undefined): Promise<Buffer>;
|
|
25
|
+
export function sha512(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
|
|
26
|
+
|
|
27
|
+
export function sha512(s: BinaryLike, o?: DigestOptions) {
|
|
28
|
+
return digestOf('SHA-512', s, o);
|
|
15
29
|
}
|
|
16
30
|
|
|
17
|
-
function digestOf(a: string, s:
|
|
18
|
-
|
|
31
|
+
function digestOf(a: string, s: BinaryLike, o?: DigestOptions) {
|
|
32
|
+
let buffer = crypto.subtle.digest(a, binaryOf(s));
|
|
33
|
+
return o ? buffer.then((v) => encode(v, o)) : o;
|
|
19
34
|
}
|
|
20
35
|
|
|
21
|
-
|
|
36
|
+
export type DigestOptions =
|
|
37
|
+
| 'hex'
|
|
38
|
+
| 'base64'
|
|
39
|
+
| {
|
|
40
|
+
encoding: 'hex' | 'base64';
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type BinaryLike = string | BufferSource;
|
|
44
|
+
|
|
45
|
+
function binaryOf(s: BinaryLike) {
|
|
22
46
|
// ArrayBuffer, TypedArray, DataView
|
|
23
47
|
if (typeof s === 'string') {
|
|
24
48
|
return new TextEncoder().encode(s);
|
|
25
49
|
}
|
|
26
50
|
return s;
|
|
27
51
|
}
|
|
52
|
+
|
|
53
|
+
function encode(buf: BufferSource, o?: DigestOptions) {
|
|
54
|
+
if (o) {
|
|
55
|
+
switch (o) {
|
|
56
|
+
case 'hex':
|
|
57
|
+
case 'base64':
|
|
58
|
+
return ArrayBuffers.toString(buf, o);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return buf;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type StringEncoding = 'hex' | 'base64';
|
|
65
|
+
type IsStringCoding<T> = T extends StringEncoding ? true : T extends { encoding: StringEncoding } ? true : false;
|
|
66
|
+
|
|
67
|
+
export function hmac<O extends DigestOptions>(
|
|
68
|
+
hash: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' | 'sha1' | 'sha256' | 'sha384' | 'sha512',
|
|
69
|
+
key: BinaryLike | CryptoKey,
|
|
70
|
+
data: BinaryLike,
|
|
71
|
+
o?: O,
|
|
72
|
+
): Promise<IsStringCoding<O> extends true ? string : Buffer>;
|
|
73
|
+
|
|
74
|
+
export async function hmac(
|
|
75
|
+
hash: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' | 'sha1' | 'sha256' | 'sha384' | 'sha512',
|
|
76
|
+
key: BinaryLike | CryptoKey,
|
|
77
|
+
data: BinaryLike,
|
|
78
|
+
o?: DigestOptions,
|
|
79
|
+
) {
|
|
80
|
+
let ck =
|
|
81
|
+
key instanceof CryptoKey
|
|
82
|
+
? key
|
|
83
|
+
: await crypto.subtle.importKey(
|
|
84
|
+
'raw',
|
|
85
|
+
binaryOf(key),
|
|
86
|
+
{
|
|
87
|
+
name: 'HMAC',
|
|
88
|
+
hash: {
|
|
89
|
+
name: normalizeHash(hash),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
false,
|
|
93
|
+
['sign'],
|
|
94
|
+
);
|
|
95
|
+
let buffer = await crypto.subtle.sign(
|
|
96
|
+
{
|
|
97
|
+
name: 'HMAC',
|
|
98
|
+
hash: {
|
|
99
|
+
name: hash,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
ck,
|
|
103
|
+
binaryOf(data),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return encode(buffer, o);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function normalizeHash(hash: string) {
|
|
110
|
+
return hash.replace(/^sha/i, 'SHA-');
|
|
111
|
+
}
|
package/src/fetch/types.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -85,7 +85,7 @@ export { structuredClone } from './isomorphics/structuredClone';
|
|
|
85
85
|
// crypto
|
|
86
86
|
export { randomUUID } from './crypto/randomUUID';
|
|
87
87
|
export { getRandomValues } from './crypto/getRandomValues';
|
|
88
|
-
export { sha1, sha256, sha384, sha512 } from './crypto/hashing';
|
|
88
|
+
export { sha1, sha256, sha384, sha512, hmac, type DigestOptions } from './crypto/hashing';
|
|
89
89
|
export { md5 } from './crypto/md5';
|
|
90
90
|
export { hex } from './crypto/base';
|
|
91
91
|
export { isULID, createULID, ulid, parseULID } from './crypto/ulid';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";var oe=require("net"),se=require("tls"),ie=require("assert"),ce=require("tty"),ue=require("util"),ae=require("os"),L=require("http"),fe=require("https"),h=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},E={},j={exports:{}},R={exports:{}},I,D;function le(){if(D)return I;D=1;var n=1e3,t=n*60,o=t*60,e=o*24,a=e*7,d=e*365.25;I=function(i,s){s=s||{};var r=typeof i;if(r==="string"&&i.length>0)return l(i);if(r==="number"&&isFinite(i))return s.long?u(i):p(i);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(i))};function l(i){if(i=String(i),!(i.length>100)){var s=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(i);if(s){var r=parseFloat(s[1]),f=(s[2]||"ms").toLowerCase();switch(f){case"years":case"year":case"yrs":case"yr":case"y":return r*d;case"weeks":case"week":case"w":return r*a;case"days":case"day":case"d":return r*e;case"hours":case"hour":case"hrs":case"hr":case"h":return r*o;case"minutes":case"minute":case"mins":case"min":case"m":return r*t;case"seconds":case"second":case"secs":case"sec":case"s":return r*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function p(i){var s=Math.abs(i);return s>=e?Math.round(i/e)+"d":s>=o?Math.round(i/o)+"h":s>=t?Math.round(i/t)+"m":s>=n?Math.round(i/n)+"s":i+"ms"}function u(i){var s=Math.abs(i);return s>=e?c(i,s,e,"day"):s>=o?c(i,s,o,"hour"):s>=t?c(i,s,t,"minute"):s>=n?c(i,s,n,"second"):i+" ms"}function c(i,s,r,f){var C=s>=r*1.5;return Math.round(i/r)+" "+f+(C?"s":"")}return I}var T,H;function U(){if(H)return T;H=1;function n(t){e.debug=e,e.default=e,e.coerce=c,e.disable=l,e.enable=d,e.enabled=p,e.humanize=le(),e.destroy=i,Object.keys(t).forEach(s=>{e[s]=t[s]}),e.names=[],e.skips=[],e.formatters={};function o(s){let r=0;for(let f=0;f<s.length;f++)r=(r<<5)-r+s.charCodeAt(f),r|=0;return e.colors[Math.abs(r)%e.colors.length]}e.selectColor=o;function e(s){let r,f=null,C,g;function v(...y){if(!v.enabled)return;const b=v,m=Number(new Date),F=m-(r||m);b.diff=F,b.prev=r,b.curr=m,r=m,y[0]=e.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let _=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(O,re)=>{if(O==="%%")return"%";_++;const B=e.formatters[re];if(typeof B=="function"){const ne=y[_];O=B.call(b,ne),y.splice(_,1),_--}return O}),e.formatArgs.call(b,y),(b.log||e.log).apply(b,y)}return v.namespace=s,v.useColors=e.useColors(),v.color=e.selectColor(s),v.extend=a,v.destroy=e.destroy,Object.defineProperty(v,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(C!==e.namespaces&&(C=e.namespaces,g=e.enabled(s)),g),set:y=>{f=y}}),typeof e.init=="function"&&e.init(v),v}function a(s,r){const f=e(this.namespace+(typeof r>"u"?":":r)+s);return f.log=this.log,f}function d(s){e.save(s),e.namespaces=s,e.names=[],e.skips=[];let r;const f=(typeof s=="string"?s:"").split(/[\s,]+/),C=f.length;for(r=0;r<C;r++)f[r]&&(s=f[r].replace(/\*/g,".*?"),s[0]==="-"?e.skips.push(new RegExp("^"+s.slice(1)+"$")):e.names.push(new RegExp("^"+s+"$")))}function l(){const s=[...e.names.map(u),...e.skips.map(u).map(r=>"-"+r)].join(",");return e.enable(""),s}function p(s){if(s[s.length-1]==="*")return!0;let r,f;for(r=0,f=e.skips.length;r<f;r++)if(e.skips[r].test(s))return!1;for(r=0,f=e.names.length;r<f;r++)if(e.names[r].test(s))return!0;return!1}function u(s){return s.toString().substring(2,s.toString().length-2).replace(/\.\*\?$/,"*")}function c(s){return s instanceof Error?s.stack||s.message:s}function i(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return e.enable(e.load()),e}return T=n,T}var G;function de(){return G||(G=1,function(n,t){t.formatArgs=e,t.save=a,t.load=d,t.useColors=o,t.storage=l(),t.destroy=(()=>{let u=!1;return()=>{u||(u=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function o(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function e(u){if(u[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+u[0]+(this.useColors?"%c ":" ")+"+"+n.exports.humanize(this.diff),!this.useColors)return;const c="color: "+this.color;u.splice(1,0,c,"color: inherit");let i=0,s=0;u[0].replace(/%[a-zA-Z%]/g,r=>{r!=="%%"&&(i++,r==="%c"&&(s=i))}),u.splice(s,0,c)}t.log=console.debug||console.log||(()=>{});function a(u){try{u?t.storage.setItem("debug",u):t.storage.removeItem("debug")}catch{}}function d(){let u;try{u=t.storage.getItem("debug")}catch{}return!u&&typeof process<"u"&&"env"in process&&(u=process.env.DEBUG),u}function l(){try{return localStorage}catch{}}n.exports=U()(t);const{formatters:p}=n.exports;p.j=function(u){try{return JSON.stringify(u)}catch(c){return"[UnexpectedJSONParseError]: "+c.message}}}(R,R.exports)),R.exports}var A={exports:{}},N,z;function pe(){return z||(z=1,N=(n,t)=>{t=t||process.argv;const o=n.startsWith("-")?"":n.length===1?"-":"--",e=t.indexOf(o+n),a=t.indexOf("--");return e!==-1&&(a===-1?!0:e<a)}),N}var q,V;function he(){if(V)return q;V=1;const n=ae,t=pe(),o=process.env;let e;t("no-color")||t("no-colors")||t("color=false")?e=!1:(t("color")||t("colors")||t("color=true")||t("color=always"))&&(e=!0),"FORCE_COLOR"in o&&(e=o.FORCE_COLOR.length===0||parseInt(o.FORCE_COLOR,10)!==0);function a(p){return p===0?!1:{level:p,hasBasic:!0,has256:p>=2,has16m:p>=3}}function d(p){if(e===!1)return 0;if(t("color=16m")||t("color=full")||t("color=truecolor"))return 3;if(t("color=256"))return 2;if(p&&!p.isTTY&&e!==!0)return 0;const u=e?1:0;if(process.platform==="win32"){const c=n.release().split(".");return Number(process.versions.node.split(".")[0])>=8&&Number(c[0])>=10&&Number(c[2])>=10586?Number(c[2])>=14931?3:2:1}if("CI"in o)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI"].some(c=>c in o)||o.CI_NAME==="codeship"?1:u;if("TEAMCITY_VERSION"in o)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(o.TEAMCITY_VERSION)?1:0;if(o.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in o){const c=parseInt((o.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(o.TERM_PROGRAM){case"iTerm.app":return c>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(o.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(o.TERM)||"COLORTERM"in o?1:(o.TERM==="dumb",u)}function l(p){const u=d(p);return a(u)}return q={supportsColor:l,stdout:l(process.stdout),stderr:l(process.stderr)},q}var J;function Ce(){return J||(J=1,function(n,t){const o=ce,e=ue;t.init=i,t.log=p,t.formatArgs=d,t.save=u,t.load=c,t.useColors=a,t.destroy=e.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."),t.colors=[6,2,3,4,5,1];try{const r=he();r&&(r.stderr||r).level>=2&&(t.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}t.inspectOpts=Object.keys(process.env).filter(r=>/^debug_/i.test(r)).reduce((r,f)=>{const C=f.substring(6).toLowerCase().replace(/_([a-z])/g,(v,y)=>y.toUpperCase());let g=process.env[f];return/^(yes|on|true|enabled)$/i.test(g)?g=!0:/^(no|off|false|disabled)$/i.test(g)?g=!1:g==="null"?g=null:g=Number(g),r[C]=g,r},{});function a(){return"colors"in t.inspectOpts?!!t.inspectOpts.colors:o.isatty(process.stderr.fd)}function d(r){const{namespace:f,useColors:C}=this;if(C){const g=this.color,v="\x1B[3"+(g<8?g:"8;5;"+g),y=` ${v};1m${f} \x1B[0m`;r[0]=y+r[0].split(`
|
|
2
|
-
`).join(`
|
|
3
|
-
`+y),r.push(v+"m+"+n.exports.humanize(this.diff)+"\x1B[0m")}else r[0]=l()+f+" "+r[0]}function l(){return t.inspectOpts.hideDate?"":new Date().toISOString()+" "}function p(...r){return process.stderr.write(e.format(...r)+`
|
|
4
|
-
`)}function u(r){r?process.env.DEBUG=r:delete process.env.DEBUG}function c(){return process.env.DEBUG}function i(r){r.inspectOpts={};const f=Object.keys(t.inspectOpts);for(let C=0;C<f.length;C++)r.inspectOpts[f[C]]=t.inspectOpts[f[C]]}n.exports=U()(t);const{formatters:s}=n.exports;s.o=function(r){return this.inspectOpts.colors=this.useColors,e.inspect(r,this.inspectOpts).split(`
|
|
5
|
-
`).map(f=>f.trim()).join(" ")},s.O=function(r){return this.inspectOpts.colors=this.useColors,e.inspect(r,this.inspectOpts)}}(A,A.exports)),A.exports}typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?j.exports=de():j.exports=Ce();var Y=j.exports,W={},w={},ge=h&&h.__createBinding||(Object.create?function(n,t,o,e){e===void 0&&(e=o);var a=Object.getOwnPropertyDescriptor(t,o);(!a||("get"in a?!t.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(n,e,a)}:function(n,t,o,e){e===void 0&&(e=o),n[e]=t[o]}),ye=h&&h.__setModuleDefault||(Object.create?function(n,t){Object.defineProperty(n,"default",{enumerable:!0,value:t})}:function(n,t){n.default=t}),Z=h&&h.__importStar||function(n){if(n&&n.__esModule)return n;var t={};if(n!=null)for(var o in n)o!=="default"&&Object.prototype.hasOwnProperty.call(n,o)&&ge(t,n,o);return ye(t,n),t};Object.defineProperty(w,"__esModule",{value:!0}),w.req=w.json=w.toBuffer=void 0;const ve=Z(L),be=Z(fe);async function K(n){let t=0;const o=[];for await(const e of n)t+=e.length,o.push(e);return Buffer.concat(o,t)}w.toBuffer=K;async function me(n){const o=(await K(n)).toString("utf8");try{return JSON.parse(o)}catch(e){const a=e;throw a.message+=` (input: ${o})`,a}}w.json=me;function _e(n,t={}){const e=((typeof n=="string"?n:n.href).startsWith("https:")?be:ve).request(n,t),a=new Promise((d,l)=>{e.once("response",d).once("error",l).end()});return e.then=a.then.bind(a),e}w.req=_e,function(n){var t=h&&h.__createBinding||(Object.create?function(u,c,i,s){s===void 0&&(s=i);var r=Object.getOwnPropertyDescriptor(c,i);(!r||("get"in r?!c.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return c[i]}}),Object.defineProperty(u,s,r)}:function(u,c,i,s){s===void 0&&(s=i),u[s]=c[i]}),o=h&&h.__setModuleDefault||(Object.create?function(u,c){Object.defineProperty(u,"default",{enumerable:!0,value:c})}:function(u,c){u.default=c}),e=h&&h.__importStar||function(u){if(u&&u.__esModule)return u;var c={};if(u!=null)for(var i in u)i!=="default"&&Object.prototype.hasOwnProperty.call(u,i)&&t(c,u,i);return o(c,u),c},a=h&&h.__exportStar||function(u,c){for(var i in u)i!=="default"&&!Object.prototype.hasOwnProperty.call(c,i)&&t(c,u,i)};Object.defineProperty(n,"__esModule",{value:!0}),n.Agent=void 0;const d=e(L);a(w,n);const l=Symbol("AgentBaseInternalState");class p extends d.Agent{constructor(c){super(c),this[l]={}}isSecureEndpoint(c){if(c){if(typeof c.secureEndpoint=="boolean")return c.secureEndpoint;if(typeof c.protocol=="string")return c.protocol==="https:"}const{stack:i}=new Error;return typeof i!="string"?!1:i.split(`
|
|
6
|
-
`).some(s=>s.indexOf("(https.js:")!==-1||s.indexOf("node:https:")!==-1)}createSocket(c,i,s){const r={...i,secureEndpoint:this.isSecureEndpoint(i)};Promise.resolve().then(()=>this.connect(c,r)).then(f=>{if(f instanceof d.Agent)return f.addRequest(c,r);this[l].currentSocket=f,super.createSocket(c,i,s)},s)}createConnection(){const c=this[l].currentSocket;if(this[l].currentSocket=void 0,!c)throw new Error("No socket was returned in the `connect()` function");return c}get defaultPort(){return this[l].defaultPort??(this.protocol==="https:"?443:80)}set defaultPort(c){this[l]&&(this[l].defaultPort=c)}get protocol(){return this[l].protocol??(this.isSecureEndpoint()?"https:":"http:")}set protocol(c){this[l]&&(this[l].protocol=c)}}n.Agent=p}(W);var S={},Oe=h&&h.__importDefault||function(n){return n&&n.__esModule?n:{default:n}};Object.defineProperty(S,"__esModule",{value:!0}),S.parseProxyResponse=void 0;const we=Oe(Y),M=(0,we.default)("https-proxy-agent:parse-proxy-response");function Fe(n){return new Promise((t,o)=>{let e=0;const a=[];function d(){const i=n.read();i?c(i):n.once("readable",d)}function l(){n.removeListener("end",p),n.removeListener("error",u),n.removeListener("readable",d)}function p(){l(),M("onend"),o(new Error("Proxy connection ended before receiving CONNECT response"))}function u(i){l(),M("onerror %o",i),o(i)}function c(i){a.push(i),e+=i.length;const s=Buffer.concat(a,e),r=s.indexOf(`\r
|
|
7
|
-
\r
|
|
8
|
-
`);if(r===-1){M("have not received end of HTTP headers yet..."),d();return}const f=s.slice(0,r).toString("ascii").split(`\r
|
|
9
|
-
`),C=f.shift();if(!C)return n.destroy(),o(new Error("No header received from proxy CONNECT response"));const g=C.split(" "),v=+g[1],y=g.slice(2).join(" "),b={};for(const m of f){if(!m)continue;const F=m.indexOf(":");if(F===-1)return n.destroy(),o(new Error(`Invalid header from proxy CONNECT response: "${m}"`));const _=m.slice(0,F).toLowerCase(),$=m.slice(F+1).trimStart(),O=b[_];typeof O=="string"?b[_]=[O,$]:Array.isArray(O)?O.push($):b[_]=$}M("got proxy server response: %o %o",C,b),l(),t({connect:{statusCode:v,statusText:y,headers:b},buffered:s})}n.on("error",u),n.on("end",p),d()})}S.parseProxyResponse=Fe;var Pe=h&&h.__createBinding||(Object.create?function(n,t,o,e){e===void 0&&(e=o);var a=Object.getOwnPropertyDescriptor(t,o);(!a||("get"in a?!t.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(n,e,a)}:function(n,t,o,e){e===void 0&&(e=o),n[e]=t[o]}),xe=h&&h.__setModuleDefault||(Object.create?function(n,t){Object.defineProperty(n,"default",{enumerable:!0,value:t})}:function(n,t){n.default=t}),k=h&&h.__importStar||function(n){if(n&&n.__esModule)return n;var t={};if(n!=null)for(var o in n)o!=="default"&&Object.prototype.hasOwnProperty.call(n,o)&&Pe(t,n,o);return xe(t,n),t},Q=h&&h.__importDefault||function(n){return n&&n.__esModule?n:{default:n}};Object.defineProperty(E,"__esModule",{value:!0}),E.HttpsProxyAgent=void 0;const P=k(oe),X=k(se),$e=Q(ie),Ee=Q(Y),Re=W,Ae=S,x=(0,Ee.default)("https-proxy-agent");class ee extends Re.Agent{constructor(t,o){super(o),this.options={path:void 0},this.proxy=typeof t=="string"?new URL(t):t,this.proxyHeaders=(o==null?void 0:o.headers)??{},x("Creating new HttpsProxyAgent instance: %o",this.proxy.href);const e=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,""),a=this.proxy.port?parseInt(this.proxy.port,10):this.proxy.protocol==="https:"?443:80;this.connectOpts={ALPNProtocols:["http/1.1"],...o?te(o,"headers"):null,host:e,port:a}}async connect(t,o){const{proxy:e}=this;if(!o.host)throw new TypeError('No "host" provided');let a;if(e.protocol==="https:"){x("Creating `tls.Socket`: %o",this.connectOpts);const r=this.connectOpts.servername||this.connectOpts.host;a=X.connect({...this.connectOpts,servername:r&&P.isIP(r)?void 0:r})}else x("Creating `net.Socket`: %o",this.connectOpts),a=P.connect(this.connectOpts);const d=typeof this.proxyHeaders=="function"?this.proxyHeaders():{...this.proxyHeaders},l=P.isIPv6(o.host)?`[${o.host}]`:o.host;let p=`CONNECT ${l}:${o.port} HTTP/1.1\r
|
|
10
|
-
`;if(e.username||e.password){const r=`${decodeURIComponent(e.username)}:${decodeURIComponent(e.password)}`;d["Proxy-Authorization"]=`Basic ${Buffer.from(r).toString("base64")}`}d.Host=`${l}:${o.port}`,d["Proxy-Connection"]||(d["Proxy-Connection"]=this.keepAlive?"Keep-Alive":"close");for(const r of Object.keys(d))p+=`${r}: ${d[r]}\r
|
|
11
|
-
`;const u=(0,Ae.parseProxyResponse)(a);a.write(`${p}\r
|
|
12
|
-
`);const{connect:c,buffered:i}=await u;if(t.emit("proxyConnect",c),this.emit("proxyConnect",c,t),c.statusCode===200){if(t.once("socket",Se),o.secureEndpoint){x("Upgrading socket connection to TLS");const r=o.servername||o.host;return X.connect({...te(o,"host","path","port"),socket:a,servername:P.isIP(r)?void 0:r})}return a}a.destroy();const s=new P.Socket({writable:!1});return s.readable=!0,t.once("socket",r=>{x("Replaying proxy buffer for failed request"),(0,$e.default)(r.listenerCount("data")>0),r.push(i),r.push(null)}),s}}ee.protocols=["http","https"],E.HttpsProxyAgent=ee;function Se(n){n.resume()}function te(n,...t){const o={};let e;for(e in n)t.includes(e)||(o[e]=n[e]);return o}var Me=Object.freeze({__proto__:null,default:E});exports.index=Me;
|
|
13
|
-
//# sourceMappingURL=index-69020bc5.js.map
|