MCPcopy Create free account
hub / github.com/ConsortiumAI/Consortium / randomKey

Function randomKey

packages/consortium-server/sources/utils/randomKey.ts:3–10  ·  view source on GitHub ↗
(prefix: string, length: number = 24)

Source from the content-addressed store, hash-verified

1import * as crypto from 'crypto';
2
3export function randomKey(prefix: string, length: number = 24): string {
4 while (true) {
5 const randomBytesBuffer = crypto.randomBytes(length * 2);
6 const normalized = randomBytesBuffer.toString('base64').replace(/[^a-zA-Z0-9]/g, '');
7 if (normalized.length < length) continue;
8 return `${prefix}_${normalized.slice(0, length)}`;
9 }
10}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected