19 lines
634 B
JavaScript
19 lines
634 B
JavaScript
/**
|
|
* Полифилл crypto.getRandomValues для Node 16 (нужен Vite при сборке).
|
|
* Запуск: node -r ./scripts/crypto-polyfill.cjs node_modules/vite/bin/vite.js build
|
|
*/
|
|
const crypto = require('node:crypto');
|
|
function getRandomValues(buffer) {
|
|
if (!buffer) return buffer;
|
|
const bytes = crypto.randomBytes(buffer.length);
|
|
buffer.set(bytes);
|
|
return buffer;
|
|
}
|
|
if (typeof crypto.getRandomValues !== 'function') {
|
|
crypto.getRandomValues = getRandomValues;
|
|
}
|
|
if (typeof globalThis !== 'undefined') {
|
|
globalThis.crypto = globalThis.crypto || {};
|
|
globalThis.crypto.getRandomValues = getRandomValues;
|
|
}
|