mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 15:04:50 +01:00
Move random.js module to blue_modules/crypto.js
This commit is contained in:
parent
9c5321b622
commit
71d8e329b8
2 changed files with 22 additions and 24 deletions
22
blue_modules/crypto.js
Normal file
22
blue_modules/crypto.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* @fileOverview wrap a secure native random number generator
|
||||
*/
|
||||
|
||||
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 number of bytes of randomness
|
||||
* @return {undefined}
|
||||
*/
|
||||
exports.randomBytes = (size, callback) => {
|
||||
RNRandomBytes.randomBytes(size, (err, bytes) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
callback(null, Buffer.from(bytes, 'base64'));
|
||||
}
|
||||
});
|
||||
};
|
24
random.js
24
random.js
|
@ -1,24 +0,0 @@
|
|||
/**
|
||||
* @fileOverview wrap a secure native random number generator
|
||||
*/
|
||||
|
||||
import { NativeModules } from 'react-native';
|
||||
|
||||
const { RNRandomBytes } = NativeModules;
|
||||
|
||||
/**
|
||||
* Generate cryptographically secure random bytes using native api.
|
||||
* @param {number} size The number of bytes of randomness
|
||||
* @return {Promise<Buffer>} The random bytes
|
||||
*/
|
||||
export async function randomBytes(size) {
|
||||
return new Promise((resolve, reject) => {
|
||||
RNRandomBytes.randomBytes(size, (err, bytes) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(Buffer.from(bytes, 'base64'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Reference in a new issue