Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usages of import * from crypto #779

Merged
merged 1 commit into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/core/src/bitgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import * as _ from 'lodash';
import * as url from 'url';
import * as querystring from 'querystring';
import * as config from './config';
import * as crypto from 'crypto';
import { createHmac, randomBytes } from 'crypto';
import * as debugLib from 'debug';
import { bytesToWord } from './v2/internal/internal';

Expand Down Expand Up @@ -733,7 +733,7 @@ export class BitGo {
* @returns {*} - the result of the HMAC operation
*/
calculateHMAC(key: string, message: string): string {
return crypto.createHmac('sha256', key).update(message).digest('hex');
return createHmac('sha256', key).update(message).digest('hex');
}

/**
Expand Down Expand Up @@ -895,8 +895,8 @@ export class BitGo {
encrypt(params: EncryptOptions = {}): string {
common.validateParams(params, ['input', 'password'], []);

const randomSalt = crypto.randomBytes(8);
const randomIV = crypto.randomBytes(16);
const randomSalt = randomBytes(8);
const randomIV = randomBytes(16);
const encryptOptions = {
iter: 10000,
ks: 256,
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/keychains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Copyright 2014, BitGo, Inc. All Rights Reserved.
//

import * as crypto from 'crypto';
import { randomBytes } from 'crypto';
import * as common from './common';
import { Util } from './v2/internal/util';
import * as bitcoin from 'bitgo-utxo-lib';
Expand Down Expand Up @@ -82,7 +82,7 @@ Keychains.prototype.create = function(params) {
// An extended private key has both a normal 256 bit private key and a 256
// bit chain code, both of which must be random. 512 bits is therefore the
// maximum entropy and gives us maximum security against cracking.
seed = crypto.randomBytes(512 / 8);
seed = randomBytes(512 / 8);
} else {
seed = params.seed;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/v2/coins/abstractEthLikeCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getBuilder, Eth } from '@bitgo/account-lib';
import * as Bluebird from 'bluebird';
import * as bitcoinMessage from 'bitcoinjs-message';
import * as bitgoUtxoLib from 'bitgo-utxo-lib';
import * as crypto from 'crypto';
import { randomBytes } from 'crypto';

import {
BaseCoin,
Expand Down Expand Up @@ -102,7 +102,7 @@ export abstract class AbstractEthLikeCoin extends BaseCoin {

generateKeyPair(seed?: Buffer): KeyPair {
if (!seed) {
seed = crypto.randomBytes(512 / 8);
seed = randomBytes(512 / 8);
}
const extendedKey = bitgoUtxoLib.HDNode.fromSeedBuffer(seed);
const xpub = extendedKey.neutered().toBase58();
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/v2/coins/abstractUtxoCoin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as bitcoin from 'bitgo-utxo-lib';
import * as bitcoinMessage from 'bitcoinjs-message';
import * as Bluebird from 'bluebird';
import * as crypto from 'crypto';
import { randomBytes } from 'crypto';
import * as request from 'superagent';
import * as _ from 'lodash';
import * as debugLib from 'debug';
Expand Down Expand Up @@ -1983,7 +1983,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
// An extended private key has both a normal 256 bit private key and a 256
// bit chain code, both of which must be random. 512 bits is therefore the
// maximum entropy and gives us maximum security against cracking.
seed = crypto.randomBytes(512 / 8);
seed = randomBytes(512 / 8);
}
const extendedKey = bitcoin.HDNode.fromSeedBuffer(seed);
const xpub = extendedKey.neutered().toBase58();
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/v2/coins/eos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '../baseCoin';
import { NodeCallback } from '../types';
import { BigNumber } from 'bignumber.js';
import * as crypto from 'crypto';
import { randomBytes } from 'crypto';
import { HDNode } from 'bitgo-utxo-lib';
import * as EosJs from 'eosjs';
import * as ecc from 'eosjs-ecc';
Expand Down Expand Up @@ -194,7 +194,7 @@ export class Eos extends BaseCoin {
// An extended private key has both a normal 256 bit private key and a 256
// bit chain code, both of which must be random. 512 bits is therefore the
// maximum entropy and gives us maximum security against cracking.
seed = crypto.randomBytes(512 / 8);
seed = randomBytes(512 / 8);
}
const extendedKey = HDNode.fromSeedBuffer(seed);
const xpub = extendedKey.neutered().toBase58();
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/v2/coins/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { BigNumber } from 'bignumber.js';
import * as utxoLib from 'bitgo-utxo-lib';
import * as Bluebird from 'bluebird';
import * as crypto from 'crypto';
import { randomBytes } from 'crypto';
import * as debugLib from 'debug';
import * as Keccak from 'keccak';
import * as _ from 'lodash';
Expand Down Expand Up @@ -1390,7 +1390,7 @@ export class Eth extends BaseCoin {
// An extended private key has both a normal 256 bit private key and a 256
// bit chain code, both of which must be random. 512 bits is therefore the
// maximum entropy and gives us maximum security against cracking.
seed = crypto.randomBytes(512 / 8);
seed = randomBytes(512 / 8);
}
const extendedKey = utxoLib.HDNode.fromSeedBuffer(seed);
const xpub = extendedKey.neutered().toBase58();
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/v2/coins/ofc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { BitGo } from '../../bitgo';
import { NodeCallback } from '../types';
import * as Bluebird from 'bluebird';
import * as crypto from 'crypto';
import { randomBytes } from 'crypto';
import * as bitGoUtxoLib from 'bitgo-utxo-lib';

export class Ofc extends BaseCoin {
Expand All @@ -38,7 +38,7 @@ export class Ofc extends BaseCoin {
// An extended private key has both a normal 256 bit private key and a 256
// bit chain code, both of which must be random. 512 bits is therefore the
// maximum entropy and gives us maximum security against cracking.
seed = crypto.randomBytes(512 / 8);
seed = randomBytes(512 / 8);
}
const extendedKey = bitGoUtxoLib.HDNode.fromSeedBuffer(seed);
const xpub = extendedKey.neutered().toBase58();
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/v2/coins/trx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @prettier
*/
import * as Bluebird from 'bluebird';
import * as crypto from 'crypto';
import { randomBytes } from 'crypto';
import { CoinFamily, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
const co = Bluebird.coroutine;
import * as bitgoAccountLib from '@bitgo/account-lib';
Expand Down Expand Up @@ -162,7 +162,7 @@ export class Trx extends BaseCoin {
if (!seed) {
// An extended private key has both a normal 256 bit private key and a 256 bit chain code, both of which must be
// random. 512 bits is therefore the maximum entropy and gives us maximum security against cracking.
seed = crypto.randomBytes(512 / 8);
seed = randomBytes(512 / 8);
}
const hd = HDNode.fromSeedBuffer(seed);
return {
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/v2/coins/xrp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber } from 'bignumber.js';
import { HDNode, ECPair } from 'bitgo-utxo-lib';
import * as Bluebird from 'bluebird';
import * as crypto from 'crypto';
import { randomBytes } from 'crypto';
import * as _ from 'lodash';
import * as url from 'url';
import * as querystring from 'querystring';
Expand Down Expand Up @@ -624,7 +624,7 @@ export class Xrp extends BaseCoin {
// An extended private key has both a normal 256 bit private key and a 256
// bit chain code, both of which must be random. 512 bits is therefore the
// maximum entropy and gives us maximum security against cracking.
seed = crypto.randomBytes(512 / 8);
seed = randomBytes(512 / 8);
}
const extendedKey = HDNode.fromSeedBuffer(seed);
const xpub = extendedKey.neutered().toBase58();
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/v2/internal/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import * as bitcoin from 'bitgo-utxo-lib';
import * as Big from 'big.js';
import * as _ from 'lodash';
import * as crypto from 'crypto';
import { randomBytes } from 'crypto';
import * as debugLib from 'debug';
import { EthereumLibraryUnavailableError } from '../../errors';
import { RequestTracer as IRequestTracer } from '../types';
Expand Down Expand Up @@ -37,7 +37,7 @@ export class RequestTracer implements IRequestTracer {
private _seq = 0;
private readonly _seed: Buffer;
constructor() {
this._seed = crypto.randomBytes(10);
this._seed = randomBytes(10);
}

inc() {
Expand Down
4 changes: 2 additions & 2 deletions modules/core/test/v2/unit/coins/algo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Promise from 'bluebird';
import * as crypto from 'crypto';
import { randomBytes } from 'crypto';
import * as algosdk from 'algosdk';
import 'should';

Expand Down Expand Up @@ -30,7 +30,7 @@ describe('ALGO:', function() {
});

it('should generate a keypair from seed', function() {
const seed = crypto.randomBytes(32);
const seed = randomBytes(32);
const keyPair = basecoin.generateKeyPair(seed);
keyPair.should.have.property('pub');
keyPair.should.have.property('prv');
Expand Down
4 changes: 2 additions & 2 deletions modules/core/test/v2/unit/coins/xlm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as should from 'should';
import * as crypto from 'crypto';
import { randomBytes } from 'crypto';
import * as stellar from 'stellar-sdk';
import * as Bluebird from 'bluebird';
import { Environments } from '../../../../src';
Expand Down Expand Up @@ -714,7 +714,7 @@ describe('XLM:', function() {
});

it('should generate a keypair from seed', function() {
const seed = crypto.randomBytes(32);
const seed = randomBytes(32);
const keyPair = basecoin.generateKeyPair(seed);
keyPair.should.have.property('pub');
keyPair.should.have.property('prv');
Expand Down