@joclaim/tls 0.2.0 → 0.3.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.
- package/lib/crypto/index.js +10 -1
- package/package.json +2 -2
package/lib/crypto/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
// Provide a browser-compatible default for randomBytes
|
|
2
|
+
// so basic operations work even without explicit setCryptoImplementation()
|
|
3
|
+
const browserFallback = {};
|
|
4
|
+
if (typeof globalThis !== 'undefined' && globalThis.crypto?.getRandomValues) {
|
|
5
|
+
browserFallback.randomBytes = (length) => {
|
|
6
|
+
const buffer = new Uint8Array(length);
|
|
7
|
+
return globalThis.crypto.getRandomValues(buffer);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export const crypto = { ...browserFallback };
|
|
2
11
|
export function setCryptoImplementation(impl) {
|
|
3
12
|
Object.assign(crypto, impl);
|
|
4
13
|
}
|
package/package.json
CHANGED