forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto.ts
More file actions
34 lines (31 loc) · 1.01 KB
/
Copy pathcrypto.ts
File metadata and controls
34 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Polyfill: crypto.getRandomValues
*
* Required by uuid generation in CopilotKit. Uses Math.random — NOT
* cryptographically secure. For secure randomness, install
* react-native-get-random-values before this polyfill.
*
* Skipped if crypto.getRandomValues is already defined.
*
* Usage:
* import "@copilotkit/react-native/polyfills/crypto";
*/
export {};
const g = globalThis as Record<string, unknown>;
if (typeof g.crypto === "undefined") {
g.crypto = {};
}
const cryptoObj = g.crypto as Record<string, unknown>;
if (!cryptoObj.getRandomValues) {
console.warn(
"[CopilotKit] Installing non-cryptographic crypto.getRandomValues polyfill (Math.random). " +
"This is NOT secure for cryptographic operations. Install 'react-native-get-random-values' " +
"for a secure implementation.",
);
cryptoObj.getRandomValues = function (array: Uint8Array): Uint8Array {
for (let i = 0; i < array.length; i++) {
array[i] = Math.floor(Math.random() * 256);
}
return array;
};
}