How to use the getRandomValues function from crypto

Find comprehensive JavaScript crypto.getRandomValues code examples handpicked from public code repositorys.

878
879
880
881
882
883
884
885
886

// Amount
const AMOUNT = new BigNumber(Math.round(Math.random() * Number.MAX_SAFE_INTEGER));

// Identifier
const IDENTIFIER = new Identifier(Common.toHexString(Common.mergeArrays([new Uint8Array([Math.round(Math.random() * Identifier.MAX_DEPTH)]), crypto.getRandomValues(new Uint8Array(Identifier.MAX_DEPTH * Uint32Array["BYTES_PER_ELEMENT"]))])));

// Log amount
console.log("Using amount: " + AMOUNT.toFixed());
fork icon5
star icon3
watch icon3

+ 17 other calls in file

25
26
27
28
29
30
31
32
33
34
35
36
  return ('0' + dec.toString(16)).substr(-2);
}


function generateRandomString() {
    const array = new Uint32Array(56 / 2);
    crypto.getRandomValues(array);
    return Array.from(array, dec2hex).join('');
}


module.exports = { generatePKCE };
fork icon0
star icon0
watch icon0

193
194
195
196
197
198
199
200
201
202
203
    }
});


When('{string} create new profile', async function (issuerName) {
    var random_num = new Uint8Array(10); // 2048 = number length in bits
    crypto.getRandomValues(random_num);
    let profileName = random_num.toString(36).substring(7);
    const created = clientCreatesProfile(
        scenarioContext,
        issuerName,
fork icon0
star icon0
watch icon0