mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-26 08:55:56 +01:00
Use random.js in abstract-hd-electrum-wallet.js
This commit is contained in:
parent
d6c8e3ab4d
commit
f594e2bb3a
1 changed files with 3 additions and 23 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue