@wener/utils 1.1.10 → 1.1.11
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/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/system/index.js +2 -2
- package/dist/system/index.js.map +1 -1
- package/lib/crypto/getNodeCrypto.js +17 -0
- package/lib/crypto/getNodeCrypto.js.map +1 -0
- package/lib/crypto/getRandomValues.js +3 -11
- package/lib/crypto/getRandomValues.js.map +1 -1
- package/package.json +1 -1
- package/src/crypto/getNodeCrypto.ts +17 -0
- package/src/crypto/getRandomValues.ts +2 -15
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
let nodeCrypto;
|
|
2
|
+
if (typeof window === "undefined") {
|
|
3
|
+
try {
|
|
4
|
+
if (typeof require === "undefined") {
|
|
5
|
+
void import('crypto').then((v) => nodeCrypto = v.default);
|
|
6
|
+
} else {
|
|
7
|
+
nodeCrypto = require("crypto");
|
|
8
|
+
}
|
|
9
|
+
} catch (e) {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function getNodeCrypto() {
|
|
13
|
+
return nodeCrypto;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { getNodeCrypto };
|
|
17
|
+
//# sourceMappingURL=getNodeCrypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNodeCrypto.js","sources":["../../src/crypto/getNodeCrypto.ts"],"sourcesContent":["let nodeCrypto: Awaited<typeof import('node:crypto')>;\n// globalThis.process?.release?.name\n\n// avoid process.browser\nif (typeof window === 'undefined') {\n try {\n // avoid `node:` UnhandledSchemeError https://github.com/vercel/next.js/issues/28774\n if (typeof require === 'undefined') {\n void import('crypto').then((v) => (nodeCrypto = v.default));\n } else {\n nodeCrypto = require('crypto');\n }\n } catch (e) {}\n}\nexport function getNodeCrypto() {\n return nodeCrypto;\n}\n"],"names":[],"mappings":"AAAA,IAAI,UAAA,CAAA;AAIJ,IAAI,OAAO,WAAW,WAAa,EAAA;AACjC,EAAI,IAAA;AAEF,IAAI,IAAA,OAAO,YAAY,WAAa,EAAA;AAClC,MAAK,KAAA,OAAO,QAAQ,CAAE,CAAA,IAAA,CAAK,CAAC,CAAO,KAAA,UAAA,GAAa,EAAE,OAAQ,CAAA,CAAA;AAAA,KACrD,MAAA;AACL,MAAA,UAAA,GAAa,QAAQ,QAAQ,CAAA,CAAA;AAAA,KAC/B;AAAA,WACO,CAAP,EAAA;AAAA,GAAW;AACf,CAAA;AACO,SAAS,aAAgB,GAAA;AAC9B,EAAO,OAAA,UAAA,CAAA;AACT;;;;"}
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
try {
|
|
4
|
-
if (typeof require === "undefined") {
|
|
5
|
-
void import('node:crypto').then((v) => nodeCrypto = v.default);
|
|
6
|
-
} else {
|
|
7
|
-
nodeCrypto = require("node:crypto");
|
|
8
|
-
}
|
|
9
|
-
} catch (e) {
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
import { getNodeCrypto } from './getNodeCrypto.js';
|
|
2
|
+
|
|
12
3
|
let getRandomValues = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) || globalThis.msCrypto?.getRandomValues?.bind(globalThis.msCrypto) || _getRandomValues;
|
|
13
4
|
function _getRandomValues(buf) {
|
|
5
|
+
const nodeCrypto = getNodeCrypto();
|
|
14
6
|
if (nodeCrypto?.webcrypto?.getRandomValues) {
|
|
15
7
|
getRandomValues = nodeCrypto?.webcrypto?.getRandomValues?.bind(nodeCrypto?.webcrypto);
|
|
16
8
|
return nodeCrypto.webcrypto.getRandomValues(buf);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRandomValues.js","sources":["../../src/crypto/getRandomValues.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport type { TypedArray } from '../io/ArrayBuffers';\
|
|
1
|
+
{"version":3,"file":"getRandomValues.js","sources":["../../src/crypto/getRandomValues.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport type { TypedArray } from '../io/ArrayBuffers';\nimport { getNodeCrypto } from './getNodeCrypto';\n\nexport let getRandomValues: <T extends Exclude<TypedArray, Float32Array | Float64Array>>(typedArray: T) => T =\n globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) ||\n (globalThis as any).msCrypto?.getRandomValues?.bind((globalThis as any).msCrypto) ||\n _getRandomValues;\n\nfunction _getRandomValues<T extends Exclude<TypedArray, Float32Array | Float64Array>>(buf: T) {\n const nodeCrypto = getNodeCrypto();\n if (nodeCrypto?.webcrypto?.getRandomValues) {\n getRandomValues = nodeCrypto?.webcrypto?.getRandomValues?.bind(nodeCrypto?.webcrypto);\n return nodeCrypto.webcrypto.getRandomValues(buf);\n }\n if (nodeCrypto?.randomBytes) {\n if (!(buf instanceof Uint8Array)) {\n throw new TypeError('expected Uint8Array');\n }\n if (buf.length > 65536) {\n const e: any = new Error();\n e.code = 22;\n e.message = `Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (${buf.length}) exceeds the number of bytes of entropy available via this API (65536).`;\n e.name = 'QuotaExceededError';\n throw e;\n }\n const bytes = nodeCrypto.randomBytes(buf.length);\n buf.set(bytes);\n return buf;\n }\n throw new Error('[getRandomValues]: No secure random number generator available.');\n}\n"],"names":[],"mappings":";;AAIO,IAAI,eACT,GAAA,UAAA,CAAW,MAAQ,EAAA,eAAA,EAAiB,KAAK,UAAW,CAAA,MAAM,CACzD,IAAA,UAAA,CAAmB,QAAU,EAAA,eAAA,EAAiB,IAAM,CAAA,UAAA,CAAmB,QAAQ,CAChF,IAAA,iBAAA;AAEF,SAAS,iBAA6E,GAAQ,EAAA;AAC5F,EAAA,MAAM,aAAa,aAAc,EAAA,CAAA;AACjC,EAAI,IAAA,UAAA,EAAY,WAAW,eAAiB,EAAA;AAC1C,IAAA,eAAA,GAAkB,UAAY,EAAA,SAAA,EAAW,eAAiB,EAAA,IAAA,CAAK,YAAY,SAAS,CAAA,CAAA;AACpF,IAAO,OAAA,UAAA,CAAW,SAAU,CAAA,eAAA,CAAgB,GAAG,CAAA,CAAA;AAAA,GACjD;AACA,EAAA,IAAI,YAAY,WAAa,EAAA;AAC3B,IAAI,IAAA,EAAE,eAAe,UAAa,CAAA,EAAA;AAChC,MAAM,MAAA,IAAI,UAAU,qBAAqB,CAAA,CAAA;AAAA,KAC3C;AACA,IAAI,IAAA,GAAA,CAAI,SAAS,KAAO,EAAA;AACtB,MAAM,MAAA,CAAA,GAAS,IAAI,KAAM,EAAA,CAAA;AACzB,MAAA,CAAA,CAAE,IAAO,GAAA,EAAA,CAAA;AACT,MAAE,CAAA,CAAA,OAAA,GAAU,uFAAuF,GAAI,CAAA,MAAA,CAAA,wEAAA,CAAA,CAAA;AACvG,MAAA,CAAA,CAAE,IAAO,GAAA,oBAAA,CAAA;AACT,MAAM,MAAA,CAAA,CAAA;AAAA,KACR;AACA,IAAA,MAAM,KAAQ,GAAA,UAAA,CAAW,WAAY,CAAA,GAAA,CAAI,MAAM,CAAA,CAAA;AAC/C,IAAA,GAAA,CAAI,IAAI,KAAK,CAAA,CAAA;AACb,IAAO,OAAA,GAAA,CAAA;AAAA,GACT;AACA,EAAM,MAAA,IAAI,MAAM,iEAAiE,CAAA,CAAA;AACnF;;;;"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
let nodeCrypto: Awaited<typeof import('node:crypto')>;
|
|
2
|
+
// globalThis.process?.release?.name
|
|
3
|
+
|
|
4
|
+
// avoid process.browser
|
|
5
|
+
if (typeof window === 'undefined') {
|
|
6
|
+
try {
|
|
7
|
+
// avoid `node:` UnhandledSchemeError https://github.com/vercel/next.js/issues/28774
|
|
8
|
+
if (typeof require === 'undefined') {
|
|
9
|
+
void import('crypto').then((v) => (nodeCrypto = v.default));
|
|
10
|
+
} else {
|
|
11
|
+
nodeCrypto = require('crypto');
|
|
12
|
+
}
|
|
13
|
+
} catch (e) {}
|
|
14
|
+
}
|
|
15
|
+
export function getNodeCrypto() {
|
|
16
|
+
return nodeCrypto;
|
|
17
|
+
}
|
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
2
2
|
import type { TypedArray } from '../io/ArrayBuffers';
|
|
3
|
-
|
|
4
|
-
let nodeCrypto: Awaited<typeof import('node:crypto')>;
|
|
5
|
-
// globalThis.process?.release?.name
|
|
6
|
-
|
|
7
|
-
// avoid process.browser
|
|
8
|
-
if (typeof window === 'undefined') {
|
|
9
|
-
try {
|
|
10
|
-
// UnhandledSchemeError https://github.com/vercel/next.js/issues/28774
|
|
11
|
-
if (typeof require === 'undefined') {
|
|
12
|
-
void import('node:crypto').then((v) => (nodeCrypto = v.default));
|
|
13
|
-
} else {
|
|
14
|
-
nodeCrypto = require('node:crypto');
|
|
15
|
-
}
|
|
16
|
-
} catch (e) {}
|
|
17
|
-
}
|
|
3
|
+
import { getNodeCrypto } from './getNodeCrypto';
|
|
18
4
|
|
|
19
5
|
export let getRandomValues: <T extends Exclude<TypedArray, Float32Array | Float64Array>>(typedArray: T) => T =
|
|
20
6
|
globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) ||
|
|
@@ -22,6 +8,7 @@ export let getRandomValues: <T extends Exclude<TypedArray, Float32Array | Float6
|
|
|
22
8
|
_getRandomValues;
|
|
23
9
|
|
|
24
10
|
function _getRandomValues<T extends Exclude<TypedArray, Float32Array | Float64Array>>(buf: T) {
|
|
11
|
+
const nodeCrypto = getNodeCrypto();
|
|
25
12
|
if (nodeCrypto?.webcrypto?.getRandomValues) {
|
|
26
13
|
getRandomValues = nodeCrypto?.webcrypto?.getRandomValues?.bind(nodeCrypto?.webcrypto);
|
|
27
14
|
return nodeCrypto.webcrypto.getRandomValues(buf);
|