Skip to content
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
4 changes: 2 additions & 2 deletions modules/express/src/clientRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function handleLogin(req: ExpressApiRouteRequest<'express.login', 'post'>) {
return req.bitgo.authenticate(body);
}

function handleDecrypt(req: express.Request) {
function handleDecrypt(req: ExpressApiRouteRequest<'express.decrypt', 'post'>) {
return {
decrypted: req.bitgo.decrypt(req.body),
};
Expand Down Expand Up @@ -1563,7 +1563,7 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
// auth
router.post('express.login', [prepareBitGo(config), typedPromiseWrapper(handleLogin)]);

app.post('/api/v[12]/decrypt', parseBody, prepareBitGo(config), promiseWrapper(handleDecrypt));
router.post('express.decrypt', [prepareBitGo(config), typedPromiseWrapper(handleDecrypt)]);
app.post('/api/v[12]/encrypt', parseBody, prepareBitGo(config), promiseWrapper(handleEncrypt));
app.post('/api/v[12]/verifyaddress', parseBody, prepareBitGo(config), promiseWrapper(handleVerifyAddress));
app.post(
Expand Down
27 changes: 27 additions & 0 deletions modules/express/src/typedRoutes/api/common/decrypt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as t from 'io-ts';
import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http';
import { BitgoExpressError } from '../../schemas/error';

export const DecryptRequestBody = {
input: t.string,
password: optional(t.string),
};

/**
* Decrypt
*
* @operationId express.decrypt
*/
export const PostDecrypt = httpRoute({
path: '/api/v[12]/decrypt',
method: 'POST',
request: httpRequest({
body: DecryptRequestBody,
}),
response: {
200: t.type({
decrypted: t.string,
}),
404: BitgoExpressError,
},
});
4 changes: 4 additions & 0 deletions modules/express/src/typedRoutes/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as express from 'express';
import { GetPing } from './common/ping';
import { GetPingExpress } from './common/pingExpress';
import { PostLogin } from './common/login';
import { PostDecrypt } from './common/decrypt';

export const ExpressApi = apiSpec({
'express.ping': {
Expand All @@ -16,6 +17,9 @@ export const ExpressApi = apiSpec({
'express.login': {
post: PostLogin,
},
'express.decrypt': {
post: PostDecrypt,
},
});

export type ExpressApi = typeof ExpressApi;
Expand Down
14 changes: 14 additions & 0 deletions modules/express/test/unit/typedRoutes/decode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as assert from 'assert';
import * as t from 'io-ts';
import { DecryptRequestBody } from '../../../src/typedRoutes/api/common/decrypt';
import { LoginRequest } from '../../../src/typedRoutes/api/common/login';

export function assertDecode<T>(codec: t.Type<T, unknown>, input: unknown): T {
Expand All @@ -25,4 +26,17 @@ describe('io-ts decode tests', function () {
password: 'password',
});
});
it('express.decrypt', function () {
// input is required field
assert.throws(() =>
assertDecode(t.type(DecryptRequestBody), {
password: 'hello',
})
);

assertDecode(t.type(DecryptRequestBody), {
input: 'input',
password: 'password',
});
});
});