Skip to content

Commit 8b0817e

Browse files
authored
Merge pull request #134 from BitGo/WP-5983
feat(mbe, awm): uses advanced wallet type instead of onPrem subtype
2 parents 260d635 + 7360dde commit 8b0817e

13 files changed

+53
-73
lines changed

src/__tests__/api/master/accelerate.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ describe('POST /api/:coin/wallet/:walletId/accelerate', () => {
1616

1717
const mockWalletData = {
1818
id: walletId,
19-
type: 'cold',
20-
subType: 'onPrem',
19+
type: 'advanced',
2120
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
2221
coin: coin,
2322
label: 'Test Wallet',

src/__tests__/api/master/consolidate.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ describe('POST /api/:coin/wallet/:walletId/consolidate', () => {
1919

2020
const mockWalletData = (multisigType: 'onchain' | 'tss') => ({
2121
id: walletId,
22-
type: 'cold',
23-
subType: 'onPrem',
22+
type: 'advanced',
2423
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
2524
coin: coin,
2625
label: 'Test Wallet',

src/__tests__/api/master/consolidateUnspents.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ describe('POST /api/:coin/wallet/:walletId/consolidateunspents', () => {
1616

1717
const mockWalletData = {
1818
id: walletId,
19-
type: 'cold',
20-
subType: 'onPrem',
19+
type: 'advanced',
2120
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
2221
coin: coin,
2322
label: 'Test Wallet',

src/__tests__/api/master/generateWallet.test.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ describe('POST /api/:coin/wallet/generate', () => {
133133
m: 2,
134134
n: 3,
135135
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
136-
type: 'cold',
137-
subType: 'onPrem',
136+
type: 'advanced',
138137
})
139138
.matchHeader('any', () => true)
140139
.reply(200, {
@@ -183,8 +182,7 @@ describe('POST /api/:coin/wallet/generate', () => {
183182
},
184183
// optional-ish fields used in assertions
185184
multisigType: 'onchain',
186-
type: 'cold',
187-
subType: 'onPrem',
185+
type: 'advanced',
188186
});
189187

190188
const response = await agent
@@ -201,8 +199,7 @@ describe('POST /api/:coin/wallet/generate', () => {
201199
response.body.wallet.should.have.properties({
202200
id: 'new-wallet-id',
203201
multisigType: 'onchain',
204-
type: 'cold',
205-
subType: 'onPrem',
202+
type: 'advanced',
206203
});
207204
response.body.should.have.propertyByPath('userKeychain', 'pub').eql('xpub_user');
208205
response.body.should.have.propertyByPath('backupKeychain', 'pub').eql('xpub_backup');
@@ -474,8 +471,7 @@ describe('POST /api/:coin/wallet/generate', () => {
474471
m: 2,
475472
n: 3,
476473
keys: ['id', 'id', 'id'],
477-
type: 'cold',
478-
subType: 'onPrem',
474+
type: 'advanced',
479475
})
480476
.reply(200, {
481477
id: 'wallet-id',
@@ -530,8 +526,7 @@ describe('POST /api/:coin/wallet/generate', () => {
530526
coinSpecific: {},
531527
},
532528
multisigType: 'tss',
533-
type: 'cold',
534-
subType: 'onPrem',
529+
type: 'advanced',
535530
});
536531

537532
const response = await agent
@@ -1135,8 +1130,7 @@ describe('POST /api/:coin/wallet/generate', () => {
11351130
m: 2,
11361131
n: 3,
11371132
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
1138-
type: 'cold',
1139-
subType: 'onPrem',
1133+
type: 'advanced',
11401134
})
11411135
.reply(200, {
11421136
id: 'new-wallet-id',
@@ -1183,8 +1177,7 @@ describe('POST /api/:coin/wallet/generate', () => {
11831177
coinSpecific: {},
11841178
},
11851179
multisigType: 'tss',
1186-
type: 'cold',
1187-
subType: 'onPrem',
1180+
type: 'advanced',
11881181
});
11891182

11901183
const response = await agent
@@ -1201,8 +1194,7 @@ describe('POST /api/:coin/wallet/generate', () => {
12011194
response.body.wallet.should.have.properties({
12021195
id: 'new-wallet-id',
12031196
multisigType: 'tss',
1204-
type: 'cold',
1205-
subType: 'onPrem',
1197+
type: 'advanced',
12061198
});
12071199

12081200
// No need to check constantsNock since we're using sinon stub

src/__tests__/api/master/sendMany.test.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
5454
.matchHeader('any', () => true)
5555
.reply(200, {
5656
id: walletId,
57-
type: 'cold',
58-
subType: 'onPrem',
57+
type: 'advanced',
5958
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
6059
multisigType: 'onchain',
6160
});
@@ -144,8 +143,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
144143
.matchHeader('any', () => true)
145144
.reply(200, {
146145
id: walletId,
147-
type: 'cold',
148-
subType: 'onPrem',
146+
type: 'advanced',
149147
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
150148
});
151149

@@ -232,8 +230,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
232230
.matchHeader('any', () => true)
233231
.reply(200, {
234232
id: walletId,
235-
type: 'cold',
236-
subType: 'onPrem',
233+
type: 'advanced',
237234
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
238235
multisigType: 'tss',
239236
});
@@ -317,8 +314,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
317314
.matchHeader('any', () => true)
318315
.reply(200, {
319316
id: walletId,
320-
type: 'cold',
321-
subType: 'onPrem',
317+
type: 'advanced',
322318
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
323319
multisigType: 'tss',
324320
});
@@ -400,8 +396,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
400396
.matchHeader('any', () => true)
401397
.reply(200, {
402398
id: walletId,
403-
type: 'cold',
404-
subType: 'onPrem',
399+
type: 'advanced',
405400
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
406401
multisigType: 'tss',
407402
});
@@ -475,8 +470,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
475470
.matchHeader('any', () => true)
476471
.reply(200, {
477472
id: walletId,
478-
type: 'cold',
479-
subType: 'onPrem',
473+
type: 'advanced',
480474
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
481475
multisigType: 'tss',
482476
});
@@ -538,8 +532,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
538532
.matchHeader('any', () => true)
539533
.reply(200, {
540534
id: walletId,
541-
type: 'cold',
542-
subType: 'onPrem',
535+
type: 'advanced',
543536
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
544537
});
545538

@@ -607,8 +600,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
607600
.matchHeader('any', () => true)
608601
.reply(200, {
609602
id: walletId,
610-
type: 'cold',
611-
subType: 'onPrem',
603+
type: 'advanced',
612604
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
613605
});
614606

@@ -663,8 +655,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
663655
.matchHeader('any', () => true)
664656
.reply(200, {
665657
id: walletId,
666-
type: 'cold',
667-
subType: 'onPrem',
658+
type: 'advanced',
668659
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
669660
});
670661

@@ -721,8 +712,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
721712
.matchHeader('any', () => true)
722713
.reply(200, {
723714
id: walletId,
724-
type: 'cold',
725-
subType: 'onPrem',
715+
type: 'advanced',
726716
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
727717
});
728718

src/__tests__/api/master/signAndSendTxRequest.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ describe('POST /api/:coin/wallet/:walletId/txrequest/:txRequestId/signAndSend',
8080
.matchHeader('any', () => true)
8181
.reply(200, {
8282
id: walletId,
83-
type: 'cold',
84-
subType: 'onPrem',
83+
type: 'advanced',
8584
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
8685
multisigType: 'tss',
8786
coin: 'hteth',
@@ -176,8 +175,7 @@ describe('POST /api/:coin/wallet/:walletId/txrequest/:txRequestId/signAndSend',
176175
.matchHeader('any', () => true)
177176
.reply(200, {
178177
id: walletId,
179-
type: 'cold',
180-
subType: 'onPrem',
178+
type: 'advanced',
181179
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
182180
multisigType: 'tss',
183181
coin: 'hteth',
@@ -275,8 +273,7 @@ describe('POST /api/:coin/wallet/:walletId/txrequest/:txRequestId/signAndSend',
275273
.matchHeader('any', () => true)
276274
.reply(200, {
277275
id: walletId,
278-
type: 'cold',
279-
subType: 'onPrem',
276+
type: 'advanced',
280277
keys: ['user-key-id', 'backup-key-id', 'bitgo-key-id'],
281278
multisigType: 'tss',
282279
coin: 'tsol',

src/masterBitgoExpress/handlers/handleGenerateWallet.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ import coinFactory from '../../shared/coinFactory';
1616
import { BadRequestError } from '../../shared/errors';
1717

1818
/**
19-
* Request handler for generating a wallet on-premises.
19+
* Request handler for generating an advanced wallet.
2020
*/
21-
export async function handleGenerateWalletOnPrem(
21+
export async function handleGenerateWallet(
2222
req: MasterApiSpecRouteRequest<'v1.wallet.generate', 'post'>,
2323
) {
2424
const { multisigType } = req.decoded;
2525

2626
if (multisigType === 'tss') {
27-
return handleGenerateOnPremMpcWallet(req);
27+
return handleGenerateMpcWallet(req);
2828
}
2929

30-
return handleGenerateOnPremOnChainWallet(req);
30+
return handleGenerateOnChainWallet(req);
3131
}
3232

3333
/**
3434
* This route is used to generate a multisig wallet when advanced wallet manager is enabled
3535
*/
36-
async function handleGenerateOnPremOnChainWallet(
36+
async function handleGenerateOnChainWallet(
3737
req: MasterApiSpecRouteRequest<'v1.wallet.generate', 'post'>,
3838
) {
3939
const bitgo = req.bitgo;
@@ -46,17 +46,16 @@ async function handleGenerateOnPremOnChainWallet(
4646

4747
const { label, enterprise } = req.decoded;
4848

49-
// Create wallet parameters with type assertion to allow 'onprem' subtype
49+
// Create wallet parameters
5050
const walletParams = {
5151
...req.decoded,
5252
label: label,
5353
m: 2,
5454
n: 3,
5555
keys: [],
56-
type: 'cold',
57-
subType: 'onPrem',
56+
type: 'advanced',
5857
multisigType: 'onchain',
59-
} as unknown as SupplementGenerateWalletOptions; // TODO: Add onprem to the SDK subType and remove "unknown" type casting
58+
} as SupplementGenerateWalletOptions;
6059

6160
if (!_.isUndefined(enterprise)) {
6261
if (!_.isString(enterprise)) {
@@ -137,7 +136,7 @@ async function handleGenerateOnPremOnChainWallet(
137136
/**
138137
* Generates a MPC wallet
139138
*/
140-
async function handleGenerateOnPremMpcWallet(
139+
async function handleGenerateMpcWallet(
141140
req: MasterApiSpecRouteRequest<'v1.wallet.generate', 'post'>,
142141
) {
143142
const bitgo = req.bitgo;
@@ -163,8 +162,7 @@ async function handleGenerateOnPremMpcWallet(
163162
m: 2,
164163
n: 3,
165164
keys: [],
166-
type: 'cold',
167-
subType: 'onPrem' as SupplementGenerateWalletOptions['subType'],
165+
type: 'advanced',
168166
multisigType: 'tss',
169167
};
170168

src/masterBitgoExpress/handlers/handleRecoveryConsolidations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type RecoveryConsolidationResult = {
3434
};
3535

3636
// Handler for recovery from receive addresses (consolidation sweeps)
37-
export async function handleRecoveryConsolidationsOnPrem(
37+
export async function handleRecoveryConsolidations(
3838
req: MasterApiSpecRouteRequest<'v1.wallet.recoveryConsolidations', 'post'>,
3939
) {
4040
checkRecoveryMode(req.config as MasterExpressConfig);

src/masterBitgoExpress/handlers/handleSendMany.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ export async function handleSendMany(req: MasterApiSpecRouteRequest<'v1.wallet.s
8686
throw new NotFoundError(`Wallet ${walletId} not found`);
8787
}
8888

89-
if (wallet.type() !== 'cold' || wallet.subType() !== 'onPrem') {
90-
throw new NotFoundError('Wallet is not an on-prem wallet');
89+
if (
90+
wallet.type() !== 'advanced' &&
91+
!(wallet.type() === 'cold' && wallet.subType() === 'onPrem')
92+
) {
93+
throw new NotFoundError('Wallet is not an advanced wallet');
9194
}
9295

9396
const keyIdIndex = params.source === 'user' ? KeyIndices.USER : KeyIndices.BACKUP;

src/masterBitgoExpress/handlers/handleSignAndSendTxRequest.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ export async function handleSignAndSendTxRequest(
2020
throw new Error(`Wallet ${walletId} not found`);
2121
}
2222

23-
if (wallet.type() !== 'cold' || wallet.subType() !== 'onPrem') {
24-
throw new Error('Wallet is not an on-prem wallet');
23+
if (
24+
wallet.type() !== 'advanced' &&
25+
!(wallet.type() === 'cold' && wallet.subType() === 'onPrem')
26+
) {
27+
throw new Error('Wallet is not an advanced wallet');
2528
}
2629

2730
const keyIdIndex = params.source === 'user' ? KeyIndices.USER : KeyIndices.BACKUP;

0 commit comments

Comments
 (0)