Skip to content

Commit 70d48ad

Browse files
committed
refactor: moved codecs and changed generate.ts->generateWallet.ts
TICKET: WP-5415
1 parent 9156c78 commit 70d48ad

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

modules/express/src/clientRoutes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ export async function handleV2OFCSignPayload(
639639
*/
640640
export async function handleV2GenerateWallet(req: ExpressApiRouteRequest<'express.wallet.generate', 'post'>) {
641641
const bitgo = req.bitgo;
642-
const coin = bitgo.coin(req.params.coin);
642+
const coin = bitgo.coin(req.decoded.coin);
643643
const result = await coin.wallets().generateWallet(req.body);
644644
if (req.query.includeKeychains === 'false') {
645645
return result.wallet.toJSON();

modules/express/src/typedRoutes/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { PostCreateAddress } from './v2/createAddress';
2626
import { PutFanoutUnspents } from './v1/fanoutUnspents';
2727
import { PostOfcSignPayload } from './v2/ofcSignPayload';
2828
import { PostWalletRecoverToken } from './v2/walletRecoverToken';
29-
import { PostGenerateWallet } from './v2/generate';
29+
import { PostGenerateWallet } from './v2/generateWallet';
3030

3131
export const ExpressApi = apiSpec({
3232
'express.ping': {

modules/express/src/typedRoutes/api/v2/generate.ts renamed to modules/express/src/typedRoutes/api/v2/generateWallet.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as t from 'io-ts';
22
import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http';
33
import { BitgoExpressError } from '../../schemas/error';
4-
import { UserKeychainCodec, BackupKeychainCodec, BitgoKeychainCodec } from '../../../wallet/codec';
4+
import { UserKeychainCodec, BackupKeychainCodec, BitgoKeychainCodec } from '../../schemas/keychain';
5+
import { multisigType, walletType } from '../../schemas/wallet';
56

67
/**
78
* Request body for wallet generation.
@@ -12,9 +13,9 @@ export const GenerateWalletBody = {
1213
/** Enterprise id. This is required for Ethereum wallets since they can only be created as part of an enterprise */
1314
enterprise: t.string,
1415
/** If absent, BitGo uses the default wallet type for the asset */
15-
multisigType: optional(t.union([t.literal('onchain'), t.literal('tss'), t.literal('blsdkg')])),
16+
multisigType: multisigType,
1617
/** The type of wallet, defined by key management and signing protocols. 'hot' and 'cold' are both self-managed wallets. If absent, defaults to 'hot' */
17-
type: optional(t.union([t.literal('hot'), t.literal('cold'), t.literal('custodial')])),
18+
type: walletType,
1819
/** Passphrase to be used to encrypt the user key on the wallet */
1920
passphrase: optional(t.string),
2021
/** User provided public key */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as t from 'io-ts';
2+
3+
export const multisigType = t.union([t.literal('onchain'), t.literal('tss'), t.literal('blsdkg')]);
4+
5+
export const walletType = t.union([t.literal('hot'), t.literal('cold'), t.literal('custodial')]);

modules/express/test/unit/clientRoutes/generateWallet.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import '../../lib/asserts';
99

1010
import { ExpressApiRouteRequest } from '../../../src/typedRoutes/api';
1111
import { handleV2GenerateWallet } from '../../../src/clientRoutes';
12-
import { GenerateWalletResponse } from '../../../src/typedRoutes/api/v2/generate';
12+
import { GenerateWalletResponse } from '../../../src/typedRoutes/api/v2/generateWallet';
1313

1414
describe('Generate Wallet', () => {
1515
let bitgo: TestBitGoAPI;
@@ -91,6 +91,7 @@ describe('Generate Wallet', () => {
9191
body: walletGenerateBody,
9292
decoded: {
9393
...walletGenerateBody,
94+
coin,
9495
},
9596
} as unknown as ExpressApiRouteRequest<'express.wallet.generate', 'post'>;
9697

@@ -105,6 +106,7 @@ describe('Generate Wallet', () => {
105106
body: walletGenerateBody,
106107
decoded: {
107108
...walletGenerateBody,
109+
coin,
108110
},
109111
} as unknown as ExpressApiRouteRequest<'express.wallet.generate', 'post'>;
110112

@@ -189,6 +191,7 @@ describe('Generate Wallet', () => {
189191
body: walletGenerateBody,
190192
decoded: {
191193
...walletGenerateBody,
194+
coin,
192195
},
193196
} as unknown as ExpressApiRouteRequest<'express.wallet.generate', 'post'>;
194197

0 commit comments

Comments
 (0)