MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / secureRandomString

Function secureRandomString

packages/ui-default/utils/base.ts:25–33  ·  view source on GitHub ↗
(digit = 32, dict = defaultDict)

Source from the content-addressed store, hash-verified

23const defaultDict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
24
25export function secureRandomString(digit = 32, dict = defaultDict) {
26 let result = '';
27 const crypto = window.crypto || (window as any).msCrypto;
28 if (!crypto?.getRandomValues) throw new Error('crypto.getRandomValues not supported');
29 const array = new Uint32Array(digit);
30 crypto.getRandomValues(array);
31 for (let i = 0; i < digit; i++) result += dict[array[i] % dict.length];
32 return result;
33}
34
35type Substitution = string | number | { templateRaw: true, html: string };
36

Callers 1

enableTfaFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected