Skip to content

Commit eacbff8

Browse files
committed
feat(express): migrate verify address to typed routes
TICKET: WP-5399
1 parent b22bb38 commit eacbff8

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

modules/express/src/clientRoutes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function handleEncrypt(req: express.Request) {
106106
* @deprecated
107107
* @param req
108108
*/
109-
function handleVerifyAddress(req: express.Request) {
109+
function handleVerifyAddress(req: ExpressApiRouteRequest<'express.verifyaddress', 'post'>) {
110110
return {
111111
verified: req.bitgo.verifyAddress(req.body),
112112
};
@@ -1565,7 +1565,7 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
15651565

15661566
router.post('express.decrypt', [prepareBitGo(config), typedPromiseWrapper(handleDecrypt)]);
15671567
app.post('/api/v[12]/encrypt', parseBody, prepareBitGo(config), promiseWrapper(handleEncrypt));
1568-
app.post('/api/v[12]/verifyaddress', parseBody, prepareBitGo(config), promiseWrapper(handleVerifyAddress));
1568+
router.post('express.verifyaddress', [prepareBitGo(config), typedPromiseWrapper(handleVerifyAddress)]);
15691569
app.post(
15701570
'/api/v[12]/calculateminerfeeinfo',
15711571
parseBody,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as t from 'io-ts';
2+
import { httpRoute, httpRequest } from '@api-ts/io-ts-http';
3+
import { BitgoExpressError } from '../../schemas/error';
4+
5+
export const VerifyAddressBody = {
6+
address: t.string,
7+
};
8+
9+
/**
10+
* Verify Address
11+
*
12+
* @operationId express.verifyaddress
13+
*/
14+
export const PostVerifyAddress = httpRoute({
15+
path: '/api/v[12]/verifyaddress',
16+
method: 'POST',
17+
request: httpRequest({
18+
body: VerifyAddressBody,
19+
}),
20+
response: {
21+
200: t.type({
22+
verified: t.boolean,
23+
}),
24+
404: BitgoExpressError,
25+
},
26+
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { GetPing } from './common/ping';
66
import { GetPingExpress } from './common/pingExpress';
77
import { PostLogin } from './common/login';
88
import { PostDecrypt } from './common/decrypt';
9+
import { PostVerifyAddress } from './common/verifyAddress';
910

1011
export const ExpressApi = apiSpec({
1112
'express.ping': {
@@ -20,6 +21,9 @@ export const ExpressApi = apiSpec({
2021
'express.decrypt': {
2122
post: PostDecrypt,
2223
},
24+
'express.verifyaddress': {
25+
post: PostVerifyAddress,
26+
},
2327
});
2428

2529
export type ExpressApi = typeof ExpressApi;

modules/express/test/unit/typedRoutes/decode.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as assert from 'assert';
22
import * as t from 'io-ts';
33
import { DecryptRequestBody } from '../../../src/typedRoutes/api/common/decrypt';
44
import { LoginRequest } from '../../../src/typedRoutes/api/common/login';
5+
import { VerifyAddressBody } from '../../../src/typedRoutes/api/common/verifyAddress';
56

67
export function assertDecode<T>(codec: t.Type<T, unknown>, input: unknown): T {
78
const result = codec.decode(input);
@@ -39,4 +40,14 @@ describe('io-ts decode tests', function () {
3940
password: 'password',
4041
});
4142
});
43+
it('express.verifyaddress', function () {
44+
assert.throws(() =>
45+
assertDecode(t.type(VerifyAddressBody), {
46+
address: 1123,
47+
})
48+
);
49+
assertDecode(t.type(VerifyAddressBody), {
50+
address: 'some-address',
51+
});
52+
});
4253
});

0 commit comments

Comments
 (0)