2015-11-19 19:49:51 +00:00
|
|
|
if (typeof Buffer === 'undefined') {
|
|
|
|
global.Buffer = require('buffer').Buffer
|
|
|
|
}
|
|
|
|
|
|
|
|
var {
|
|
|
|
RNRandomBytes
|
|
|
|
} = require('react-native').NativeModules
|
|
|
|
|
2015-11-19 20:02:11 +00:00
|
|
|
export default function randomBytes (length, cb) {
|
2015-11-19 19:49:51 +00:00
|
|
|
if (!cb) throw new Error('synchronous API not supported')
|
|
|
|
|
|
|
|
RNRandomBytes.randomBytes(length, function (err, base64String) {
|
|
|
|
if (err) cb(err)
|
|
|
|
else cb(null, new Buffer(base64String, 'base64'))
|
|
|
|
})
|
|
|
|
}
|