mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 09:50:15 +01:00
24 lines
719 B
JavaScript
24 lines
719 B
JavaScript
/**
|
|
* @fileOverview wraps a secure native random number generator.
|
|
* This module mimics the node crypto api and is intended to work in RN environment.
|
|
*/
|
|
|
|
const { NativeModules } = require('react-native');
|
|
const { RNRandomBytes } = NativeModules;
|
|
|
|
/**
|
|
* Generate cryptographically secure random bytes using native api.
|
|
* @param {number} size The number of bytes of randomness
|
|
* @param {function} callback The callback to return the bytes
|
|
* @return {Buffer} The random bytes
|
|
*/
|
|
exports.randomBytes = (size, callback) => {
|
|
RNRandomBytes.randomBytes(size, (err, bytes) => {
|
|
if (err) {
|
|
callback(err);
|
|
} else {
|
|
callback(null, Buffer.from(bytes, 'base64'));
|
|
}
|
|
});
|
|
};
|