mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-04-29 12:10:24 +00:00
Initial commit of eigent-main
This commit is contained in:
commit
723df5a03e
1144 changed files with 103478 additions and 0 deletions
25
package/@stackframe/stack-shared/dist/esm/utils/crypto.js
vendored
Normal file
25
package/@stackframe/stack-shared/dist/esm/utils/crypto.js
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// src/utils/crypto.tsx
|
||||
import { encodeBase32 } from "./bytes";
|
||||
import { StackAssertionError } from "./errors";
|
||||
import { globalVar } from "./globals";
|
||||
function generateRandomValues(array) {
|
||||
if (!globalVar.crypto) {
|
||||
throw new StackAssertionError("Crypto API is not available in this environment. Are you using an old browser?");
|
||||
}
|
||||
if (!globalVar.crypto.getRandomValues) {
|
||||
throw new StackAssertionError("crypto.getRandomValues is not available in this environment. Are you using an old browser?");
|
||||
}
|
||||
return globalVar.crypto.getRandomValues(array);
|
||||
}
|
||||
function generateSecureRandomString(minBitsOfEntropy = 224) {
|
||||
const base32CharactersCount = Math.ceil(minBitsOfEntropy / 5);
|
||||
const bytesCount = Math.ceil(base32CharactersCount * 5 / 8);
|
||||
const randomBytes = generateRandomValues(new Uint8Array(bytesCount));
|
||||
const str = encodeBase32(randomBytes);
|
||||
return str.slice(str.length - base32CharactersCount).toLowerCase();
|
||||
}
|
||||
export {
|
||||
generateRandomValues,
|
||||
generateSecureRandomString
|
||||
};
|
||||
//# sourceMappingURL=crypto.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue