1
Fork 0
mirror of https://github.com/diced/zipline.git synced 2025-04-11 23:31:17 -05:00

Merge branch 'trunk' into trunk

This commit is contained in:
dicedtomato 2025-03-28 15:19:47 -07:00 committed by GitHub
commit f4cee7dcf6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 30 additions and 25 deletions

View file

@ -4,8 +4,6 @@ import { randomCharacters } from './random';
const ALGORITHM = 'aes-256-cbc';
export { randomCharacters } from './random';
export function createKey(secret: string) {
const hash = crypto.createHash('sha256');
hash.update(secret);

View file

@ -5,19 +5,7 @@ import {
get,
} from '@github/webauthn-json/browser-ponyfill';
import { User } from './db/models/user';
function randomCharacters(length: number): string {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let result = '';
for (let i = 0; i !== length; ++i) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
import { randomCharacters } from './random';
export async function registerWeb(user: User) {
const cro = parseCreationOptionsFromJSON({

View file

@ -1,12 +1,29 @@
export function randomCharacters(length: number): string {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
const CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const CHARSET_LENGTH = CHARSET.length;
export function randomCharacters(length: number) {
const randomValues = new Uint8Array(length);
typeof crypto !== 'undefined' && crypto.getRandomValues
? crypto.getRandomValues(randomValues)
: // eslint-disable-next-line @typescript-eslint/no-require-imports
require('crypto').webcrypto.getRandomValues(randomValues);
let result = '';
for (let i = 0; i !== length; ++i) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
for (let i = 0; i < length; i++) {
result += CHARSET[randomValues[i] % CHARSET_LENGTH];
}
return result;
}
export function randomIndex(length: number) {
const randomValues = new Uint8Array(1);
typeof crypto !== 'undefined' && crypto.getRandomValues
? crypto.getRandomValues(randomValues)
: // eslint-disable-next-line @typescript-eslint/no-require-imports
require('crypto').webcrypto.getRandomValues(randomValues);
return randomValues[0] % length;
}

View file

@ -1,7 +1,7 @@
import dayjs from 'dayjs';
import { config } from '../config';
import { Config } from '../config/validate';
import { randomCharacters } from '../crypto';
import { randomCharacters } from '../random';
import { randomUUID } from 'crypto';
import { parse } from 'path';
import { randomWords } from './randomWords';

View file

@ -2,6 +2,7 @@ import { readFileSync } from 'fs';
import fallbackAdjectives from './wordlists/adjectives';
import fallbackAnimals from './wordlists/animals';
import { log } from '../logger';
import { randomIndex } from '../random';
const logger = log('random_words');
@ -33,10 +34,10 @@ export function randomWords(numAdjectives: number = 2, seperator: string = '-')
let words = '';
for (let i = 0; i !== numAdjectives; ++i) {
words += adjectives[Math.floor(Math.random() * adjectives.length)] + seperator;
words += adjectives[randomIndex(adjectives.length)] + seperator;
}
words += animals[Math.floor(Math.random() * animals.length)];
words += animals[randomIndex(animals.length)];
return words;
}

View file

@ -1,5 +1,5 @@
import { config } from '@/lib/config';
import { randomCharacters } from '@/lib/crypto';
import { randomCharacters } from '@/lib/random';
import { prisma } from '@/lib/db';
import { Invite, inviteInviterSelect } from '@/lib/db/models/invite';
import { log } from '@/lib/logger';

View file

@ -1,5 +1,6 @@
import { config } from '@/lib/config';
import { hashPassword, randomCharacters } from '@/lib/crypto';
import { hashPassword } from '@/lib/crypto';
import { randomCharacters } from '@/lib/random';
import { prisma } from '@/lib/db';
import { Url } from '@/lib/db/models/url';
import { log } from '@/lib/logger';