UNPKG

1.09 kBJavaScriptView Raw
1/**
2 * Random Number Generator
3 * =======================
4 *
5 * Random numbers are important in bitcoin primarily for generating private
6 * keys. It is also important for creating signatures if you are using a random
7 * value of k, but Yours Bitcoin defaults to using deterministic k. That means
8 * computing a random private key, or a random seed for use in Bip39 or Bip32,
9 * is the primary use of the random number generator. Note that the simplicity
10 * of this class is extremely carefully considered. It is easy to audit that
11 * this code runs node's randomBytes function. It is also easy to audit that
12 * the randomBytes method is correctly interpreted as
13 * window.crypto.getRandomValues when this code is browserified by browserify,
14 * and thus also works correctly in the browser. We deliberately do not do
15 * anything else to this random number in order to minimize possible errors in
16 * this absolutely critical code.
17 */
18'use strict'
19
20import randomBytes from 'randombytes'
21
22class Random {}
23
24Random.getRandomBuffer = function (size) {
25 return randomBytes(size)
26}
27
28export { Random }