minor refactor, cleanup

This commit is contained in:
Nystik
2026-03-11 22:08:30 +01:00
parent 2b9ebf1fbd
commit 9789be6d70
38 changed files with 259 additions and 379 deletions

View File

@@ -1,16 +1,14 @@
// Shim for crypto.randomBytes
// Uses Web Crypto API under the hood
export function randomBytes(size) {
const buf = new Uint8Array(size);
crypto.getRandomValues(buf);
// Add Buffer-like convenience methods
buf.toString = function(encoding) {
if (encoding === 'hex') {
return Array.from(this).map(b => b.toString(16).padStart(2, '0')).join('');
buf.toString = function (encoding) {
if (encoding === "hex") {
return Array.from(this)
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
}
if (encoding === 'base64') {
if (encoding === "base64") {
return btoa(String.fromCharCode(...this));
}
return new TextDecoder().decode(this);