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

feat(root): add support for node 18 #3758

Merged
merged 9 commits into from
Jul 26, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [16.x, 18.x]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_package_updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [16.x, 18.x]

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions DEVELOPERS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Requirements

- yarn version 1 (classic)
- node version >=16 and <17
- node version >=16 and <19

# Installing

Expand Down Expand Up @@ -180,7 +180,7 @@ Engines should be set to the following:
```json
{
"engines": {
"node": ">=16 <17",
"node": ">=16 <19",
"npm": ">=3.10.10"
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ BitGoJS currently provides support for the following Node versions per package.j

```
"engines": {
"node": ">=16 <17",
"node": ">=16 <19",
"npm": ">=3.10.10"
}
```
Expand Down
2 changes: 1 addition & 1 deletion modules/abstract-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "BitGo SDK Team <[email protected]>",
"license": "MIT",
"engines": {
"node": ">=16 <17"
"node": ">=16 <19"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion modules/abstract-eth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "BitGo SDK Team <[email protected]>",
"license": "MIT",
"engines": {
"node": ">=16 <17"
"node": ">=16 <19"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion modules/abstract-utxo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "BitGo SDK Team <[email protected]>",
"license": "MIT",
"engines": {
"node": ">=16 <17"
"node": ">=16 <19"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion modules/account-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"author": "BitGo SDK Team <[email protected]>",
"license": "ISC",
"engines": {
"node": ">=16 <17"
"node": ">=16 <19"
},
"dependencies": {
"@bitgo/sdk-coin-algo": "^1.3.27",
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"license": "Apache-2.0",
"engines": {
"node": ">=16 <17",
"node": ">=16 <19",
"npm": ">=3.10.10"
},
"scripts": {
Expand Down
70 changes: 51 additions & 19 deletions modules/bitgo/test/v2/unit/internal/blsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import * as nock from 'nock';
import * as should from 'should';
import * as openpgp from 'openpgp';

import { TestBitGo } from '@bitgo/sdk-test';
import { BitGo } from '../../../../src/bitgo';
import { TestableBG, TestBitGo } from '@bitgo/sdk-test';
import { BitGo } from '../../../../src';
import { BlsUtils, common, IBlsKeyPair, Keychain } from '@bitgo/sdk-core';
import assert = require('assert');
import { Eth2 } from '@bitgo/sdk-coin-eth2';

describe('BLS Utils:', async function () {
const bitgo: any = TestBitGo.decorate(BitGo, { env: 'mock' });
const bitgo: TestableBG & BitGo = TestBitGo.decorate(BitGo, { env: 'mock' });
bitgo.initializeTestVars();
const eth2 = bitgo.coin('eth2');
const eth2: Eth2 = bitgo.coin('eth2') as Eth2;
let bgUrl: string;
let blsUtils: BlsUtils;
let bitgoKeyShare;
Expand All @@ -35,15 +36,22 @@ describe('BLS Utils:', async function () {
},
};

nock('https://bitgo.fakeurl').persist().get('/api/v1/client/constants').reply(200, { ttl: 3600, constants });
// TODO(WP-346): sdk-test mocks conflict so we can't use persist
nock(bitgo.microservicesUrl('')).get('/api/v1/client/constants').times(3).reply(200, { ttl: 3600, constants });

bgUrl = common.Environments[bitgo.getEnv()].uri;
blsUtils = new BlsUtils(bitgo, eth2);
});

it('should generate BLS-DKG key chains', async function () {
const userKeyShare = eth2.generateKeyPair();
const backupKeyShare = eth2.generateKeyPair();
const userKeyShare: IBlsKeyPair = {
...eth2.generateKeyPair(),
chaincode: '0',
};
const backupKeyShare: IBlsKeyPair = {
...eth2.generateKeyPair(),
chaincode: '0',
};
const userGpgKey = await openpgp.generateKey({
userIDs: [
{
Expand Down Expand Up @@ -94,12 +102,12 @@ describe('BLS Utils:', async function () {
const backupSigningMaterial = {
userShare: {
pub: userKeyShare.pub,
priv: userKeyShare.secretShares[1],
priv: userKeyShare.secretShares![1],
chaincode: userKeyShare.chaincode,
},
backupShare: {
pub: backupKeyShare.pub,
priv: backupKeyShare.secretShares[1],
priv: backupKeyShare.secretShares![1],
chaincode: backupKeyShare.chaincode,
seed: backupKeyShare.seed,
},
Expand All @@ -118,8 +126,8 @@ describe('BLS Utils:', async function () {
const enterprise = 'enterprise';
const originalPasscodeEncryptionCode = 'originalPasscodeEncryptionCode';

const userKeyShare = eth2.generateKeyPair();
const backupKeyShare = eth2.generateKeyPair();
const userKeyShare: IBlsKeyPair = { ...eth2.generateKeyPair(), chaincode: '0' };
const backupKeyShare: IBlsKeyPair = { ...eth2.generateKeyPair(), chaincode: '0' };
const userGpgKey = await openpgp.generateKey({
userIDs: [
{
Expand Down Expand Up @@ -177,12 +185,12 @@ describe('BLS Utils:', async function () {
const backupSigningMaterial = {
userShare: {
pub: userKeyShare.pub,
priv: userKeyShare.secretShares[1],
priv: userKeyShare.secretShares![1],
chaincode: userKeyShare.chaincode,
},
backupShare: {
pub: backupKeyShare.pub,
priv: backupKeyShare.secretShares[1],
priv: backupKeyShare.secretShares![1],
chaincode: backupKeyShare.chaincode,
seed: backupKeyShare.seed,
},
Expand All @@ -198,8 +206,8 @@ describe('BLS Utils:', async function () {
});

it('should fail to generate BLS-DKG key chains', async function () {
const userKeyShare = eth2.generateKeyPair();
const backupKeyShare = eth2.generateKeyPair();
const userKeyShare: IBlsKeyPair = { ...eth2.generateKeyPair(), chaincode: '0' };
const backupKeyShare: IBlsKeyPair = { ...eth2.generateKeyPair(), chaincode: '0' };
const userGpgKey = await openpgp.generateKey({
userIDs: [
{
Expand Down Expand Up @@ -228,17 +236,41 @@ describe('BLS Utils:', async function () {
bitgoKeychain.should.deepEqual(nockedBitGoKeychain);

await blsUtils
.createUserKeychain(userGpgKey, userKeyShare, eth2.generateKeyPair(), bitgoKeychain, 'passphrase')
.createUserKeychain(
userGpgKey,
userKeyShare,
{ ...eth2.generateKeyPair(), chaincode: '0' },
bitgoKeychain,
'passphrase'
)
.should.be.rejectedWith('Failed to create user keychain - commonKeychains do not match.');
await blsUtils
.createUserKeychain(userGpgKey, eth2.generateKeyPair(), backupKeyShare, bitgoKeychain, 'passphrase')
.createUserKeychain(
userGpgKey,
{ ...eth2.generateKeyPair(), chaincode: '0' },
backupKeyShare,
bitgoKeychain,
'passphrase'
)
.should.be.rejectedWith('Failed to create user keychain - commonKeychains do not match.');

await blsUtils
.createBackupKeychain(backupGpgKey, eth2.generateKeyPair(), backupKeyShare, bitgoKeychain, 'passphrase')
.createBackupKeychain(
backupGpgKey,
{ ...eth2.generateKeyPair(), chaincode: '0' },
backupKeyShare,
bitgoKeychain,
'passphrase'
)
.should.be.rejectedWith('Failed to create backup keychain - commonKeychains do not match.');
await blsUtils
.createBackupKeychain(backupGpgKey, userKeyShare, eth2.generateKeyPair(), bitgoKeychain, 'passphrase')
.createBackupKeychain(
backupGpgKey,
userKeyShare,
{ ...eth2.generateKeyPair(), chaincode: '0' },
bitgoKeychain,
'passphrase'
)
.should.be.rejectedWith('Failed to create backup keychain - commonKeychains do not match.');
});

Expand Down
13 changes: 8 additions & 5 deletions modules/bitgo/test/v2/unit/internal/tssUtils/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ExchangeCommitmentResponse, SignatureShareRecord } from '@bitgo/sdk-core';
import * as nock from 'nock';
import * as _ from 'lodash';

export async function nockSendTxRequest(params: {
coin: string;
Expand All @@ -25,7 +26,7 @@ export async function nockSendSignatureShare(
return nock('https://bitgo.fakeurl')
.persist(true)
.post(`/api/v2/wallet/${params.walletId}/txrequests/${params.txRequestId + transactions}/signatureshares`)
.reply(status, status === 200 ? params.signatureShare : { error: 'some error' });
.reply(status, status === 200 ? (params.signatureShare as nock.Body) : ({ error: 'some error' } as nock.Body));
}

export async function nockSendSignatureShareWithResponse(
Expand All @@ -41,7 +42,7 @@ export async function nockSendSignatureShareWithResponse(
const transactions = getRoute(params.tssType);
return nock('https://bitgo.fakeurl')
.post(`/api/v2/wallet/${params.walletId}/txrequests/${params.txRequestId + transactions}/signatureshares`)
.reply(status, status === 200 ? params.response : { error: 'some error' });
.reply(status, status === 200 ? (params.response as Body) : ({ error: 'some error' } as nock.Body));
}

export async function nockDeleteSignatureShare(
Expand All @@ -60,8 +61,10 @@ export async function nockCreateTxRequest(params: {
response: unknown;
}): Promise<nock.Scope> {
return nock('https://bitgo.fakeurl')
.post(`/api/v2/wallet/${params.walletId}/txrequests`, params.requestBody)
.reply(200, params.response);
.post(`/api/v2/wallet/${params.walletId}/txrequests`, (body) => {
return _.isEqual(body, params.requestBody);
})
.reply(200, params.response as nock.Body);
}

export async function nockGetTxRequest(params: {
Expand All @@ -73,7 +76,7 @@ export async function nockGetTxRequest(params: {
return nock('https://bitgo.fakeurl')
.persist(true)
.get(`/api/v2/wallet/${params.walletId}/txrequests?txRequestIds=${params.txRequestId}&latest=true`)
.reply(200, params.response);
.reply(200, params.response as nock.Body);
}

export async function nockExchangeCommitments(params: {
Expand Down
8 changes: 6 additions & 2 deletions modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ describe('TSS Ecdsa Utils:', async function () {

bgUrl = common.Environments[bitgo.getEnv()].uri;

nock(bgUrl).persist().get('/api/v1/client/constants').reply(200, { ttl: 3600, constants });
// TODO(WP-346): sdk-test mocks conflict so we can't use persist
nock(bgUrl).get('/api/v1/client/constants').times(15).reply(200, { ttl: 3600, constants });

const nockPromises = [
nockBitgoKeychain({
Expand Down Expand Up @@ -1236,7 +1237,10 @@ describe('TSS Ecdsa Utils:', async function () {
});

function nockGetBitgoChallenges(response: unknown): nock.Scope {
return nock(bgUrl).get(`/api/v2/tss/ecdsa/challenges`).times(1).reply(200, response);
return nock(bgUrl)
.get(`/api/v2/tss/ecdsa/challenges`)
.times(1)
.reply(() => [200, response]);
}

it('succeeds for valid bitgo proofs', async function () {
Expand Down
3 changes: 2 additions & 1 deletion modules/bitgo/test/v2/unit/internal/tssUtils/eddsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ describe('TSS Utils:', async function () {

bgUrl = common.Environments[bitgo.getEnv()].uri;

nock(bgUrl).persist().get('/api/v1/client/constants').reply(200, { ttl: 3600, constants });
// TODO(WP-346): sdk-test mocks conflict so we can't use persist
nock(bgUrl).get('/api/v1/client/constants').times(23).reply(200, { ttl: 3600, constants });

const walletData = {
id: '5b34252f1bf349930e34020a00000000',
Expand Down
11 changes: 10 additions & 1 deletion modules/bitgo/test/v2/unit/unspents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ describe('Verify string type is used for value of unspent', function () {
function matchMinMaxValue(minValue: string, maxValue: string): boolean {
return minValue === '1' && maxValue === highPrecisionBigInt.toString();
}
function assertIsString(val: unknown): asserts val is string {
if (typeof val !== 'string') {
throw new Error('Expected string');
}
}

describe('unspents APIs with string type minValue and maxValue', function () {
after(function () {
Expand Down Expand Up @@ -78,6 +83,8 @@ describe('Verify string type is used for value of unspent', function () {
const maximumSpendableScope = nock(bgUrl)
.get(`/api/v2/${wallet.coin()}/wallet/${wallet.id()}/maximumSpendable`)
.query((queryParams) => {
assertIsString(queryParams.minValue);
assertIsString(queryParams.maxValue);
return matchMinMaxValue(queryParams.minValue, queryParams.maxValue);
})
.reply(200, {});
Expand All @@ -97,7 +104,9 @@ describe('Verify string type is used for value of unspent', function () {
const unspentsScope = nock(bgUrl)
.get(`/api/v2/${wallet.coin()}/wallet/${wallet.id()}/unspents`)
.query((queryParams) => {
return matchMinMaxValue(queryParams.minValue, queryParams.maxValue);
assertIsString(queryParams.minValue);
assertIsString(queryParams.maxValue);
return matchMinMaxValue(queryParams.minValue as string, queryParams.maxValue);
})
.reply(200, {});

Expand Down
29 changes: 16 additions & 13 deletions modules/bitgo/test/v2/unit/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,12 +1107,12 @@ describe('V2 Wallet:', function () {
const txRequestNock = nock(bgUrl)
.post(`/api/v2/${hbarWallet.coin()}/wallet/${hbarWallet.id()}/tx/build`)
.reply((uri, body) => {
const params = JSON.parse(body);
const params = body as any;
params.recipients.length.should.equal(1);
params.recipients[0].tokenName.should.equal('thbar:usdc');
params.type.should.equal('enabletoken');
should.not.exist(params.enableTokens);
return params;
return [200, params];
});
await hbarWallet.buildTokenEnablements(params);
txRequestNock.isDone().should.equal(true);
Expand Down Expand Up @@ -1242,21 +1242,24 @@ describe('V2 Wallet:', function () {
const txRequestNock = nock(bgUrl)
.post(`/api/v2/wallet/${solWallet.id()}/txrequests`)
.reply((url, body) => {
const bodyParams = JSON.parse(body);
const bodyParams = body as any;
bodyParams.intent.intentType.should.equal('enableToken');
bodyParams.intent.recipients.length.should.equal(0);
bodyParams.intent.enableTokens.should.deepEqual(params.enableTokens);
return {
apiVersion: 'full',
transactions: [
{
unsignedTx: {
serializedTxHex: 'fake transaction',
feeInfo: 'fake fee info',
return [
200,
{
apiVersion: 'full',
transactions: [
{
unsignedTx: {
serializedTxHex: 'fake transaction',
feeInfo: 'fake fee info',
},
},
},
],
};
],
},
];
});
await solWallet.buildTokenEnablements(params);
txRequestNock.isDone().should.equal(true);
Expand Down
Loading
Loading