Skip to content

Commit d4fc262

Browse files
committed
Remove Node crypto dependency from sim
1 parent 995b432 commit d4fc262

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

package-lock.json

+30-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"@stylistic/eslint-plugin": "^4.0.1",
7272
"@types/better-sqlite3": "^7.6.2",
7373
"@types/cloud-env": "^0.2.2",
74-
"@types/node": "^14.18.63",
74+
"@types/node": "^18.19.76",
7575
"@types/node-static": "^0.7.7",
7676
"@types/nodemailer": "^6.4.4",
7777
"@types/pg": "^8.6.5",

sim/prng.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import { Chacha20 } from 'ts-chacha20';
1616
import { Utils } from '../lib/utils';
17-
import * as crypto from 'crypto';
1817

1918
export type PRNGSeed = `${'sodium' | 'gen5' | number},${string}`;
2019
export type SodiumRNGSeed = ['sodium', string];
@@ -209,9 +208,17 @@ export class SodiumRNG implements RNG {
209208
}
210209

211210
static generateSeed(): SodiumRNGSeed {
211+
const seed = new Uint32Array(4);
212+
// @ts-expect-error Web Crypto is available in Node
213+
crypto.getRandomValues(seed);
214+
// 32 bits each, 128 bits total (16 bytes)
215+
const strSeed = seed[0].toString(16).padStart(8, '0') +
216+
seed[1].toString(16).padStart(8, '0') +
217+
seed[2].toString(16).padStart(8, '0') +
218+
seed[3].toString(16).padStart(8, '0');
212219
return [
213220
'sodium',
214-
crypto.randomBytes(16).toString('hex'),
221+
strSeed,
215222
];
216223
}
217224
}

0 commit comments

Comments
 (0)