This Document will explain what and how security features are implemented in AnuraOS.
In Anura, when coding in a cryptographic/security sensitive context, we replace Math.random()
with our own function cryptoRandom()
. cryptoRandom()
is a direct replacement for Math.random()
and the two are fully interchangeable. If you would like to implement cryptoRandom()
you can use the following steps(for TypeScript):
npm install @types/node
import * as crypto from "crypto";
to the head of whatever file in which you would like to replace Math.random()
function cryptoRandom() {
const typedArray = new Uint8Array(1);
const randomValue = crypto.getRandomValues(typedArray)[0];
const randomFloat = randomValue / Math.pow(2, 8);
return randomFloat;
}
Math.random()
anywhere in your code with cryptoRandom()
.