Skip to content
Open
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
408 changes: 342 additions & 66 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@bitgo-beta/abstract-cosmos": "1.0.1-beta.1905",
"@bitgo-beta/abstract-eth": "1.0.2-beta.2150",
"@bitgo-beta/abstract-utxo": "1.1.1-beta.2153",
"@bitgo-beta/sdk-api": "1.10.1-beta.1920",
"@bitgo-beta/sdk-api": "1.10.1-beta.1923",
"@bitgo-beta/sdk-coin-ada": "2.3.14-beta.1918",
"@bitgo-beta/sdk-coin-algo": "2.8.9-beta.398",
"@bitgo-beta/sdk-coin-apt": "1.0.1-beta.1360",
Expand Down Expand Up @@ -101,7 +101,7 @@
"@bitgo-beta/sdk-coin-zec": "1.1.1-beta.2144",
"@bitgo-beta/sdk-coin-zeta": "1.0.1-beta.1836",
"@bitgo-beta/sdk-coin-zketh": "1.0.1-beta.1700",
"@bitgo-beta/sdk-core": "8.2.1-beta.1925",
"@bitgo-beta/sdk-core": "8.2.1-beta.1928",
"@bitgo-beta/sdk-lib-mpc": "8.2.0-beta.1924",
"@bitgo-beta/statics": "15.1.1-beta.1939",
"@bitgo/wasm-miniscript": "2.0.0-beta.7",
Expand All @@ -122,7 +122,7 @@
"zod": "^3.25.48"
},
"overrides": {
"@bitgo-beta/sdk-core": "8.2.1-beta.1925",
"@bitgo-beta/sdk-core": "8.2.1-beta.1928",
"@bitgo-beta/statics": "15.1.1-beta.1939",
"elliptic": "^6.6.1",
"expo": "^48.0.0",
Expand Down Expand Up @@ -155,9 +155,10 @@
"lodash": "^4.18.0",
"fast-uri": "^3.1.4",
"shell-quote": "^1.9.0",
"brace-expansion@1": "^1.1.16",
"brace-expansion@1": "^5.0.8",
"brace-expansion@2": "^2.1.2",
"brace-expansion@5": "^5.0.7",
"brace-expansion@5": "^5.0.8",
"postcss": ">=8.5.18",
"js-yaml@3": "^3.15.0",
"js-yaml@4": "^4.3.0"
},
Expand Down
79 changes: 54 additions & 25 deletions src/__tests__/api/master/generateWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import nock from 'nock';
import sinon from 'sinon';
import { app as expressApp } from '../../../masterBitGoExpressApp';
import { AppMode, MasterExpressConfig, TlsMode } from '../../../shared/types';
import { Environments } from '@bitgo-beta/sdk-core';
import { BitgoMpcGpgPubKeys, Environments } from '@bitgo-beta/sdk-core';
import { BitGoAPI } from '@bitgo-beta/sdk-api';
import * as middleware from '../../../shared/middleware';
import { BitGoRequest } from '../../../types/request';
Expand Down Expand Up @@ -64,6 +64,10 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
const ecdsaCoin = 'hteth';
const accessToken = 'test-token';

// The SDK parses BitGo's GPG keys and rejects anything that is not a known BitGo MPC key
const bitgoMpcv1GpgKey = BitgoMpcGpgPubKeys.getBitgoMpcGpgPubKey('test', 'onprem', 'mpcv1');
const bitgoMpcv2GpgKey = BitgoMpcGpgPubKeys.getBitgoMpcGpgPubKey('test', 'onprem', 'mpcv2');

// Valid BIP32 extended public keys required by the SDK's isValidPub check
const validUserPub =
'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8';
Expand Down Expand Up @@ -352,7 +356,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
nock(bitgoApiUrl)
.persist()
.get('/api/v1/client/constants')
.reply(200, { constants: { mpc: { bitgoPublicKey: 'test-bitgo-public-key' } } });
.reply(200, { constants: { mpc: { bitgoPublicKey: bitgoMpcv1GpgKey } } });
const backupBitgo = new BitGoAPI({ env: 'test' });
const configWithBackup = makeConfig({ advancedWalletManagerBackupUrl: backupAwmUrl });

Expand All @@ -369,7 +373,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
const userInitNock = nock(advancedWalletManagerUrl)
.post(`/api/${eddsaCoin}/mpc/key/initialize`, {
source: 'user',
bitgoGpgPub: 'test-bitgo-public-key',
bitgoGpgPub: bitgoMpcv1GpgKey,
})
.reply(200, {
encryptedDataKey: 'key',
Expand All @@ -389,7 +393,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
const backupInitNock = nock(backupAwmUrl)
.post(`/api/${eddsaCoin}/mpc/key/initialize`, {
source: 'backup',
bitgoGpgPub: 'test-bitgo-public-key',
bitgoGpgPub: bitgoMpcv1GpgKey,
counterPartyGpgPub: 'user-key',
})
.reply(200, {
Expand Down Expand Up @@ -538,7 +542,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
.post(`/api/v2/${eddsaCoin}/key`, {
commonKeychain: 'commonKeychain',
source: 'user',
type: 'tss',
keyType: 'tss',
})
.reply(200, {
id: 'user-key-id',
Expand Down Expand Up @@ -602,7 +606,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
const addBackupKeyNock = nock(bitgoApiUrl)
.post(`/api/v2/${eddsaCoin}/key`, {
source: 'backup',
type: 'tss',
keyType: 'tss',
commonKeychain: 'commonKeychain',
})
.reply(200, {
Expand Down Expand Up @@ -651,12 +655,12 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
nock(bitgoApiUrl)
.persist()
.get('/api/v1/client/constants')
.reply(200, { constants: { mpc: { bitgoPublicKey: 'test-bitgo-public-key' } } });
.reply(200, { constants: { mpc: { bitgoPublicKey: bitgoMpcv1GpgKey } } });

const userInitNock = nock(advancedWalletManagerUrl)
.post(`/api/${eddsaCoin}/mpc/key/initialize`, {
source: 'user',
bitgoGpgPub: 'test-bitgo-public-key',
bitgoGpgPub: bitgoMpcv1GpgKey,
})
.reply(200, {
encryptedDataKey: 'key',
Expand All @@ -675,7 +679,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
const backupInitNock = nock(advancedWalletManagerUrl)
.post(`/api/${eddsaCoin}/mpc/key/initialize`, {
source: 'backup',
bitgoGpgPub: 'test-bitgo-public-key',
bitgoGpgPub: bitgoMpcv1GpgKey,
counterPartyGpgPub: 'user-key',
})
.reply(200, {
Expand Down Expand Up @@ -822,7 +826,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
.post(`/api/v2/${eddsaCoin}/key`, {
commonKeychain: 'commonKeychain',
source: 'user',
type: 'tss',
keyType: 'tss',
})
.reply(200, {
id: 'id',
Expand Down Expand Up @@ -884,7 +888,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
const addBackupKeyNock = nock(bitgoApiUrl)
.post(`/api/v2/${eddsaCoin}/key`, {
source: 'backup',
type: 'tss',
keyType: 'tss',
commonKeychain: 'commonKeychain',
})
.reply(200, {
Expand All @@ -899,7 +903,6 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
label: 'test_wallet',
enterprise: 'test_enterprise',
multisigType: 'tss',
coin: eddsaCoin,
m: 2,
n: 3,
keys: ['id', 'id', 'id'],
Expand Down Expand Up @@ -990,7 +993,18 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
nock(bitgoApiUrl)
.persist()
.get('/api/v1/client/constants')
.reply(200, { constants: { mpc: { bitgoMPCv2PublicKey: 'test-bitgo-public-key' } } });
.reply(200, { constants: { mpc: { bitgoMPCv2PublicKey: bitgoMpcv2GpgKey } } });
// The SDK resolves BitGo's MPCv2 GPG key and the enterprise's wallet creation settings itself
const tssPubkeyNock = nock(bitgoApiUrl)
.get(`/api/v2/${ecdsaCoin}/tss/pubkey`)
.query({ enterpriseId: 'test-enterprise' })
.reply(200, { mpcv2PublicKey: bitgoMpcv2GpgKey });

const tssSettingsNock = nock(bitgoApiUrl)
.get('/api/v2/tss/settings')
.reply(200, {
coinSettings: { eth: { walletCreationSettings: { multiSigTypeVersion: 'MPCv2' } } },
});
const backupBitgo = new BitGoAPI({ env: 'test' });
const configWithBackup = makeConfig({ advancedWalletManagerBackupUrl: backupAwmUrl });

Expand Down Expand Up @@ -1027,7 +1041,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
encryptedDataKey: 'key',
encryptedData: 'data',
round: 1,
bitgoGpgPub: 'test-bitgo-public-key',
bitgoGpgPub: bitgoMpcv2GpgKey,
counterPartyGpgPub: 'test-backup-public-key',
})
.reply(200, {
Expand All @@ -1046,7 +1060,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
encryptedDataKey: 'key',
encryptedData: 'data',
round: 1,
bitgoGpgPub: 'test-bitgo-public-key',
bitgoGpgPub: bitgoMpcv2GpgKey,
counterPartyGpgPub: 'test-user-public-key',
})
.reply(200, {
Expand Down Expand Up @@ -1527,7 +1541,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
.post(`/api/v2/${ecdsaCoin}/key`, {
commonKeychain: 'commonKeychain',
source: 'user',
type: 'tss',
keyType: 'tss',
isMPCv2: true,
})
.reply(200, { id: 'user-key-id', source: 'user', type: 'tss' });
Expand All @@ -1536,7 +1550,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
.post(`/api/v2/${ecdsaCoin}/key`, {
commonKeychain: 'commonKeychain',
source: 'backup',
type: 'tss',
keyType: 'tss',
isMPCv2: true,
})
.reply(200, { id: 'backup-key-id', source: 'backup', type: 'tss' });
Expand All @@ -1545,7 +1559,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
.post(`/api/v2/${ecdsaCoin}/key`, {
commonKeychain: 'commonKeychain',
source: 'bitgo',
type: 'tss',
keyType: 'tss',
isMPCv2: true,
})
.reply(200, {
Expand Down Expand Up @@ -1595,6 +1609,8 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
backupRound4Nock.done();
backupFinalizeNock.done();
// Verify BitGo API calls
tssPubkeyNock.done();
tssSettingsNock.done();
bitgoRound1And2Nock.done();
bitgoRound3Nock.done();
bitgoRound4Nock.done();
Expand All @@ -1608,7 +1624,18 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
nock(bitgoApiUrl)
.persist()
.get('/api/v1/client/constants')
.reply(200, { constants: { mpc: { bitgoMPCv2PublicKey: 'test-bitgo-public-key' } } });
.reply(200, { constants: { mpc: { bitgoMPCv2PublicKey: bitgoMpcv2GpgKey } } });
// The SDK resolves BitGo's MPCv2 GPG key and the enterprise's wallet creation settings itself
const tssPubkeyNock = nock(bitgoApiUrl)
.get(`/api/v2/${ecdsaCoin}/tss/pubkey`)
.query({ enterpriseId: 'test-enterprise' })
.reply(200, { mpcv2PublicKey: bitgoMpcv2GpgKey });

const tssSettingsNock = nock(bitgoApiUrl)
.get('/api/v2/tss/settings')
.reply(200, {
coinSettings: { eth: { walletCreationSettings: { multiSigTypeVersion: 'MPCv2' } } },
});

// init round
const userInitNock = nock(advancedWalletManagerUrl)
Expand Down Expand Up @@ -1637,7 +1664,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
encryptedDataKey: 'key',
encryptedData: 'data',
round: 1,
bitgoGpgPub: 'test-bitgo-public-key',
bitgoGpgPub: bitgoMpcv2GpgKey,
counterPartyGpgPub: 'test-backup-public-key',
})
.reply(200, {
Expand All @@ -1659,7 +1686,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
encryptedDataKey: 'key',
encryptedData: 'data',
round: 1,
bitgoGpgPub: 'test-bitgo-public-key',
bitgoGpgPub: bitgoMpcv2GpgKey,
counterPartyGpgPub: 'test-user-public-key',
})
.reply(200, {
Expand Down Expand Up @@ -2143,7 +2170,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
.post(`/api/v2/${ecdsaCoin}/key`, {
commonKeychain: 'commonKeychain',
source: 'user',
type: 'tss',
keyType: 'tss',
isMPCv2: true,
})
.reply(200, { id: 'user-key-id', source: 'user', type: 'tss' });
Expand All @@ -2152,7 +2179,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
.post(`/api/v2/${ecdsaCoin}/key`, {
commonKeychain: 'commonKeychain',
source: 'backup',
type: 'tss',
keyType: 'tss',
isMPCv2: true,
})
.reply(200, { id: 'backup-key-id', source: 'backup', type: 'tss' });
Expand All @@ -2161,7 +2188,7 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
.post(`/api/v2/${ecdsaCoin}/key`, {
commonKeychain: 'commonKeychain',
source: 'bitgo',
type: 'tss',
keyType: 'tss',
isMPCv2: true,
})
.reply(200, {
Expand All @@ -2179,10 +2206,10 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
label: 'test-wallet', // ?
enterprise: 'test-enterprise',
multisigType: 'tss',
coin: ecdsaCoin,
m: 2,
n: 3,
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
walletVersion: 5,
type: 'advanced',
})
.reply(200, {
Expand Down Expand Up @@ -2254,6 +2281,8 @@ describe('POST /api/v1/:coin/advancedwallet/generate', () => {
backupInitNock.done();
userRound1Nock.done();
backupRound1Nock.done();
tssPubkeyNock.done();
tssSettingsNock.done();
bitgoRound1And2Nock.done();
userRound2Nock.done();
backupRound2Nock.done();
Expand Down
Loading
Loading