Skip to content

Commit

Permalink
chore(root): add noImplicitThis to tsconfig.json
Browse files Browse the repository at this point in the history
Without fixing errors in v1 code or tests.

Ticket: BG-48796
  • Loading branch information
Darius Parvin committed May 27, 2022
1 parent 40bc412 commit 0d881c2
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 3 deletions.
4 changes: 2 additions & 2 deletions modules/account-lib/src/coin/sol/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function isValidBlockId(hash: string): boolean {
/** @inheritdoc */
export function isValidPrivateKey(prvKey: string | Uint8Array): boolean {
try {
const key: Uint8Array = typeof prvKey === 'string' ? this.base58ToUint8Array(prvKey) : prvKey;
const key: Uint8Array = typeof prvKey === 'string' ? base58ToUint8Array(prvKey) : prvKey;
return !!Keypair.fromSecretKey(key);
} catch (e) {
return false;
Expand Down Expand Up @@ -88,7 +88,7 @@ export function isValidSignature(signature: string): boolean {
/** @inheritdoc */
// TransactionId are the first signature on a Transaction
export function isValidTransactionId(txId: string): boolean {
return this.isValidSignature(txId);
return isValidSignature(txId);
}

/**
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { common } from '@bitgo/sdk-core';
// Constructor
//
const Blockchain = function (bitgo) {
// @ts-expect-error - no implicit this
this.bitgo = bitgo;
};

Expand Down
3 changes: 3 additions & 0 deletions modules/bitgo/src/keychains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ try {
// Constructor
//
const Keychains = function (bitgo) {
// @ts-expect-error - no implicit this
this.bitgo = bitgo;
};

Expand Down Expand Up @@ -194,8 +195,10 @@ Keychains.prototype.list = function (params, callback) {
Keychains.prototype.updatePassword = function (params, callback) {
return co(function *coUpdatePassword() {
common.validateParams(params, ['oldPassword', 'newPassword'], [], callback);
// @ts-expect-error - no implicit this
const encrypted = yield this.bitgo.post(this.bitgo.url('/user/encrypted')).result();
const newKeychains = {};
// @ts-expect-error - no implicit this
const self = this;
_.forOwn((encrypted as any).keychains, function keychainsForOwn(oldEncryptedXprv, xpub) {
try {
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/src/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { common } from '@bitgo/sdk-core';
// Constructor
//
const Markets = function (bitgo) {
// @ts-expect-error - no implicit this
this.bitgo = bitgo;
};

Expand Down
3 changes: 3 additions & 0 deletions modules/bitgo/src/pendingapproval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import * as _ from 'lodash';
// Constructor
//
const PendingApproval = function (bitgo, pendingApproval, wallet) {
// @ts-expect-error - no implicit this
this.bitgo = bitgo;
// @ts-expect-error - no implicit this
this.pendingApproval = pendingApproval;
// @ts-expect-error - no implicit this
this.wallet = wallet;
};

Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/src/pendingapprovals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const PendingApproval = require('./pendingapproval');
// Constructor
//
const PendingApprovals = function (bitgo) {
// @ts-expect-error - no implicit this
this.bitgo = bitgo;
};

Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/src/travelRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface Recipient {
// Constructor
//
const TravelRule = function (bitgo) {
// @ts-expect-error - no implicit this
this.bitgo = bitgo;
};

Expand Down
24 changes: 24 additions & 0 deletions modules/bitgo/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ const request = require('superagent');
// Constructor
//
const Wallet = function (bitgo, wallet) {
// @ts-expect-error - no implicit this
(this.bitgo as any) = bitgo;
// @ts-expect-error - no implicit this
this.wallet = wallet;
// @ts-expect-error - no implicit this
this.keychains = [];

if (wallet.private) {
// @ts-expect-error - no implicit this
this.keychains = wallet.private.keychains;
}
};
Expand Down Expand Up @@ -430,8 +434,11 @@ Wallet.prototype.refresh = function (params, callback) {
return co(function *() {
// when set to true, gpk returns the private data of safe wallets
const query = _.extend({}, _.pick(params, ['gpk']));
// @ts-expect-error - no implicit this
const res = yield this.bitgo.get(this.url()).query(query).result();
// @ts-expect-error - no implicit this
this.wallet = res;
// @ts-expect-error - no implicit this
return this;
}).call(this).asCallback(callback);
};
Expand Down Expand Up @@ -844,6 +851,7 @@ Wallet.prototype.getEncryptedUserKeychain = function (params, callback) {
return co(function *() {
params = params || {};
common.validateParams(params, [], [], callback);
// @ts-expect-error - no implicit this
const self = this;

const tryKeyChain = co(function *(index) {
Expand Down Expand Up @@ -1063,6 +1071,7 @@ Wallet.prototype.confirmInviteAndShareWallet = function (params, callback) {
return self.shareWallet(options);
})
.then(function () {
// @ts-expect-error - no implicit this
return this.bitgo.put(this.bitgo.url('/walletinvite/' + params.walletInviteId));
})
.nodeify(callback);
Expand Down Expand Up @@ -1302,6 +1311,7 @@ Wallet.prototype.accelerateTransaction = function accelerateTransaction(params,

while (uncoveredChildFee > 0 && additionalUnspents.length < maxUnspents) {
// try to get enough unspents to cover the rest of the child fee
// @ts-expect-error - no implicit this
const unspents = (yield this.unspents({
minConfirms: 1,
target: uncoveredChildFee,
Expand Down Expand Up @@ -1449,6 +1459,7 @@ Wallet.prototype.accelerateTransaction = function accelerateTransaction(params,
throw Error('Expecting positive integer for parameter: maxAdditionalUnspents');
}

// @ts-expect-error - no implicit this
const parentTx = yield this.getTransaction({ id: params.transactionID });
if (parentTx.confirmations > 0) {
throw new Error(`Transaction ${params.transactionID} is already confirmed and cannot be accelerated`);
Expand Down Expand Up @@ -1476,6 +1487,7 @@ Wallet.prototype.accelerateTransaction = function accelerateTransaction(params,
// find the unspent corresponding to this particular output
// TODO: is there a better way to get this unspent?
// TODO: The best we can do here is set minSize = maxSize = outputToUse.value
// @ts-expect-error - no implicit this
const unspentsResult = yield this.unspents({
minSize: outputToUse.value,
maxSize: outputToUse.value,
Expand Down Expand Up @@ -1534,6 +1546,7 @@ Wallet.prototype.accelerateTransaction = function accelerateTransaction(params,

// try to get the min change size from the server, otherwise default to 0.1 BTC
// TODO: minChangeSize is not currently a constant defined on the client and should be added
// @ts-expect-error - no implicit this
const minChangeSize = this.bitgo.getConstants().minChangeSize || 1e7;

if (outputToUse.value < childFee + minChangeSize) {
Expand All @@ -1554,6 +1567,7 @@ Wallet.prototype.accelerateTransaction = function accelerateTransaction(params,
// sanity check the fee rate we're paying for the combined tx
// to make sure it's under the max fee rate. Only the child tx
// can break this limit, but the combined tx shall not
// @ts-expect-error - no implicit this
const maxFeeRate = this.bitgo.getConstants().maxFeeRate;
const childVSize = estimateTxVSize(childInputs);
const combinedVSize = childVSize + parentVSize;
Expand All @@ -1570,10 +1584,13 @@ Wallet.prototype.accelerateTransaction = function accelerateTransaction(params,
// and such zero-output transactions are forbidden by the Bitcoin protocol,
// so we need at least a single recipient for the change which won't be pruned.
const changeAmount = _.sumBy(unspentsToUse, (unspent) => unspent.value) - childFee;
// @ts-expect-error - no implicit this
const changeChain = this.getChangeChain({});
// @ts-expect-error - no implicit this
const changeAddress = yield this.createAddress({ chain: changeChain });

// create the child tx and broadcast
// @ts-expect-error - no implicit this
const tx = yield this.createAndSignTransaction({
unspents: unspentsToUse,
recipients: [{
Expand All @@ -1598,6 +1615,7 @@ Wallet.prototype.accelerateTransaction = function accelerateTransaction(params,
tx.ignoreMaxFeeRate = true;
}

// @ts-expect-error - no implicit this
return this.sendTransaction(tx);
}).call(this).asCallback(callback);
};
Expand Down Expand Up @@ -1637,6 +1655,7 @@ Wallet.prototype.createAndSignTransaction = function (params, callback) {
throw new Error('invalid argument for instant - boolean expected');
}

// @ts-expect-error - no implicit this
const transaction = (yield this.createTransaction(params)) as any;
const fee = transaction.fee;
const feeRate = transaction.feeRate;
Expand All @@ -1647,23 +1666,28 @@ Wallet.prototype.createAndSignTransaction = function (params, callback) {

// Sign the transaction
try {
// @ts-expect-error - no implicit this
const keychain = yield this.getAndPrepareSigningKeychain(params);
transaction.keychain = keychain;
} catch (e) {
if (e.code !== 'no_encrypted_keychain_on_wallet') {
throw e;
}
// this might be a safe wallet, so let's retrieve the private key info
// @ts-expect-error - no implicit this
yield this.refresh({ gpk: true });
// @ts-expect-error - no implicit this
const safeUserKey = _.get(this.wallet, 'private.userPrivKey');
if (_.isString(safeUserKey) && _.isString(params.walletPassphrase)) {
// @ts-expect-error - no implicit this
transaction.signingKey = this.bitgo.decrypt({ password: params.walletPassphrase, input: safeUserKey });
} else {
throw e;
}
}

transaction.feeSingleKeyWIF = params.feeSingleKeyWIF;
// @ts-expect-error - no implicit this
const result = yield this.signTransaction(transaction);
return _.extend(result, {
fee,
Expand Down
2 changes: 2 additions & 0 deletions modules/bitgo/src/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Wallet = require('./wallet');
// Constructor
//
const Wallets = function (bitgo) {
// @ts-expect-error - no implicit this
this.bitgo = bitgo;
};

Expand Down Expand Up @@ -147,6 +148,7 @@ Wallets.prototype.resendShareInvite = function (params, callback) {
common.validateParams(params, ['walletShareId'], [], callback);

const urlParts = params.walletShareId + '/resendemail';
// @ts-expect-error - no implicit this
return this.bitgo.post(this.bitgo.url('/walletshare/' + urlParts))
.result();
}).call(this).asCallback(callback);
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/test/lib/test_bitgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ BitGo.prototype.nockEthWallet = function () {

const oldFetchConstants = BitGoAPI.prototype.fetchConstants;
BitGoAPI.prototype.fetchConstants = function () {
// @ts-expect-error - no implicit this
nock(this._baseUrl)
.get('/api/v1/client/constants')
.reply(200, { ttl: 3600, constants: {} });
Expand Down
3 changes: 3 additions & 0 deletions modules/bitgo/test/v2/fixtures/trading/affirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ export default {
payload: '{"version":"1.1.1","accountId":"5cf940969449412d00f53b4c55fc2139","nonceHold":"djTPc0eRtQixTviodw1iJQ==","nonceSettle":"Wemw9X+iFcwsRFV3nJebxA==","amounts":[{"accountId":"5cf940a49449412d00f53b8f7392f7c0","sendCurrency":"ofctbtc","sendSubtotal":"500","sendAmount":"500","receiveCurrency":"ofctusd","receiveAmount":"555"},{"accountId":"5cf940969449412d00f53b4c55fc2139","sendCurrency":"ofctusd","sendSubtotal":"555","sendAmount":"555","receiveCurrency":"ofctbtc","receiveAmount":"500"}]}',
},
updateAffirmation: function (status) {
// @ts-expect-error - 'status' is specified more than once, so this usage will be overwritten.
const affirmation = { status, ...this.singleAffirmation };
if (status !== AffirmationStatus.AFFIRMED) {
// @ts-expect-error - The operand of a 'delete' operator must be optional.
delete affirmation.payload;
// @ts-expect-error - The operand of a 'delete' operator must be optional.
delete affirmation.signature;
}
return affirmation;
Expand Down
3 changes: 3 additions & 0 deletions modules/bitgo/test/v2/lib/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import { Assertion } from 'should';

Assertion.add('calledOnceWith', function (...args) {
// @ts-expect-error - no implicit this
this.params = { operator: 'to be called once with' };

// @ts-expect-error - no implicit this
this.obj.should.have.been.calledOnce();
// @ts-expect-error - no implicit this
this.obj.should.have.been.calledWith(...args);
});
2 changes: 2 additions & 0 deletions modules/bitgo/test/v2/unit/coins/abstractEthCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,13 @@ describe('ETH-like coins', () => {

it('Should not throw when verifying valid addresses', function () {
// FIXME(BG-43225): not implemented
// @ts-expect-error - no implicit this
this.skip();
});

it('Should throw when verifying invalid addresses', function () {
// FIXME(BG-43225): not implemented
// @ts-expect-error - no implicit this
this.skip();
});
});
Expand Down
3 changes: 2 additions & 1 deletion modules/bitgo/test/v2/unit/coins/eth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('Ethereum 2.0', function () {

it('should generate keypair without seed', function () {
// FIXME(BG-47812): this test is flaky
// @ts-expect-error - no implicit this
this.skip();
const localBaseCoin = bitgo.coin('teth2');
const keyPair = localBaseCoin.generateKeyPair();
Expand All @@ -66,7 +67,7 @@ describe('Ethereum 2.0', function () {
const userKeyPair = basecoin.generateKeyPair();
const backupKeyPair = basecoin.generateKeyPair();
const walletKeyPair = basecoin.generateKeyPair();

const message = 'hello world';
const userKey = basecoin.aggregateShares({
pubShares: [userKeyPair.pub, backupKeyPair.pub, walletKeyPair.pub],
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/test/v2/unit/coins/utxo/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ function run(coin: AbstractUtxoCoin, inputScripts: InputScriptType[]) {

it('have valid signatures for full-signed transaction', function () {
if (!fullSign) {
// @ts-expect-error - no implicit this
return this.skip();
}
assert(transactionStages.fullSignedUserBackup && transactionStages.fullSignedUserBitGo);
Expand Down
3 changes: 3 additions & 0 deletions modules/express/test/lib/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import { Assertion } from 'should';

Assertion.add('calledOnceWith', function (...args) {
// @ts-expect-error - no implicit this
this.params = { operator: 'to be called once with' };

// @ts-expect-error - no implicit this
this.obj.should.have.been.calledOnce();
// @ts-expect-error - no implicit this
this.obj.should.have.been.calledWith(...args);
});

1 change: 1 addition & 0 deletions modules/utxo-lib/test/fixtures_thirdparty/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function testFixture<T>(
callback: (this: Mocha.Context, data: T) => void
): void {
it(filename, async function () {
// @ts-expect-error - no implicit this
callback.call(this, await readJSON(network, filename));
});
}
Expand Down
1 change: 1 addition & 0 deletions modules/utxo-lib/test/integration_local_rpc/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function runTestParse(protocol: Protocol, txType: FixtureTxType, scriptType: Scr

if (scriptType === 'p2tr') {
// TODO implement verifySignature for p2tr
// @ts-expect-error - no implicit this
this.skip();
}

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lib": ["dom", "es2019"],
"module": "commonjs",
"noFallthroughCasesInSwitch": true,
"noImplicitThis": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strictBindCallApply": true,
Expand Down

0 comments on commit 0d881c2

Please sign in to comment.