MCPcopy
hub / github.com/tiagozip/cap / randomHex

Function randomHex

server/index.js:95–109  ·  view source on GitHub ↗

* Generates a cryptographically secure random hex string of given length * * @param {number} bytesCount * @returns {Promise } Deterministic hex string generated from the seed

(bytesCount)

Source from the content-addressed store, hash-verified

93 * @returns {Promise<string>} Deterministic hex string generated from the seed
94 */
95async function randomHex(bytesCount) {
96 if (crypto.getRandomValues) {
97 const bytes = new Uint8Array(bytesCount);
98 crypto.getRandomValues(bytes);
99
100 return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
101 }
102
103 return new Promise((resolve, reject) => {
104 crypto.randomBytes(bytesCount, (err, buf) => {
105 if (err) return reject(err);
106 resolve(buf.toString("hex"));
107 });
108 });
109}
110
111/**
112 * Calculates a SHA256 hash of a given string

Callers 2

createChallengeMethod · 0.85
redeemChallengeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected