Use random.js in abstract-hd-electrum-wallet.js

This commit is contained in:
Tankred Hase 2020-05-01 08:37:28 +08:00
parent d6c8e3ab4d
commit f594e2bb3a
No known key found for this signature in database
GPG key ID: 8A9F1C42BFB264F6

View file

@ -1,7 +1,7 @@
import { NativeModules } from 'react-native';
import bip39 from 'bip39';
import BigNumber from 'bignumber.js';
import b58 from 'bs58check';
import { randomBytes } from '../random';
import { AbstractHDWallet } from './abstract-hd-wallet';
const bitcoin = require('bitcoinjs-lib');
const BlueElectrum = require('../BlueElectrum');
@ -10,8 +10,6 @@ const coinSelectAccumulative = require('coinselect/accumulative');
const coinSelectSplit = require('coinselect/split');
const reverse = require('buffer-reverse');
const { RNRandomBytes } = NativeModules;
/**
* Electrum - means that it utilizes Electrum protocol for blockchain data
*/
@ -72,26 +70,8 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
}
async generate() {
let that = this;
return new Promise(function(resolve) {
if (typeof RNRandomBytes === 'undefined') {
// CLI/CI environment
// crypto should be provided globally by test launcher
return crypto.randomBytes(32, (err, buf) => { // eslint-disable-line
if (err) throw err;
that.secret = bip39.entropyToMnemonic(buf.toString('hex'));
resolve();
});
}
// RN environment
RNRandomBytes.randomBytes(32, (err, bytes) => {
if (err) throw new Error(err);
let b = Buffer.from(bytes, 'base64').toString('hex');
that.secret = bip39.entropyToMnemonic(b);
resolve();
});
});
const buf = await randomBytes(32);
this.secret = bip39.entropyToMnemonic(buf.toString('hex'));
}
_getExternalWIFByIndex(index) {