-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from MercuryWorkshop/docs
Added Security Blueprint explaining how to implement secure coding practices for Contributors.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Security Blueprint | ||
This Document will explain what and how security features are implemented in AnuraOS. | ||
|
||
|
||
|
||
## Secure Math | ||
|
||
In Anura, when coding in 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): | ||
|
||
1. If not already installed, run `npm install @types/node` | ||
2. Add `import * as crypto from "crypto";` to the head of whatever file in which you would like to replace `Math.random()` | ||
3. add the following function to your code: | ||
|
||
```ts | ||
function cryptoRandom() { | ||
const typedArray = new Uint8Array(1); | ||
const randomValue = crypto.getRandomValues(typedArray)[0]; | ||
const randomFloat = randomValue / Math.pow(2, 8); | ||
return randomFloat; | ||
} | ||
``` | ||
4. You can now replace `Math.random()` anywhere in your code with `cryptoRandom()`. | ||
|
||
## TODO |