How to use the crypto-browserify.getRandomValues function in crypto-browserify

To help you get started, we’ve selected a few crypto-browserify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github icon-project / icon-sdk-js / lib / module / crypto / index.js View on Github external
/* eslint-disable */
const crypto = require('crypto-browserify');

if (typeof navigator != 'undefined' && navigator.product == 'ReactNative') {
	// react-native
	crypto.getRandomValues = (buffer) => {
		for (let round = 0; round < 20; round++) {
			for (let i = 0; i < buffer.length; i++) {
				if (round) {
					buffer[i] ^= Math.trunc(256 * Math.random());
				} else {
					buffer[i] = Math.trunc(256 * Math.random());
				}
			}
		}
		return buffer;
	};
	crypto.randomBytes = (length) => {
		if (length <= 0 || length > 1024 || parseInt(String(length), 10) !== length) {
			throw new Error('invalid length');
		}
		const result = Buffer.from(new Uint8Array(length));