Skip to content

Commit ce55bc8

Browse files
refactor(express): splits decrpt into v1 and v2
TICKET: WCI-184
1 parent 566b55f commit ce55bc8

6 files changed

Lines changed: 74 additions & 21 deletions

File tree

modules/express/src/clientRoutes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,7 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
17001700
// auth
17011701
router.post('express.login', [prepareBitGo(config), typedPromiseWrapper(handleLogin)]);
17021702

1703+
router.post('express.v1.decrypt', [prepareBitGo(config), typedPromiseWrapper(handleDecrypt)]);
17031704
router.post('express.decrypt', [prepareBitGo(config), typedPromiseWrapper(handleDecrypt)]);
17041705
router.post('express.encrypt', [prepareBitGo(config), typedPromiseWrapper(handleEncrypt)]);
17051706
router.post('express.verifyaddress', [prepareBitGo(config), typedPromiseWrapper(handleVerifyAddress)]);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import * as express from 'express';
55
import { GetPing } from './common/ping';
66
import { GetPingExpress } from './common/pingExpress';
77
import { PostLogin } from './common/login';
8-
import { PostDecrypt } from './common/decrypt';
8+
import { PostV1Decrypt } from './v1/decrypt';
9+
import { PostV2Decrypt } from './v2/decrypt';
910
import { PostEncrypt } from './common/encrypt';
1011
import { PostVerifyAddress } from './common/verifyAddress';
1112
import { PostV1CalculateMinerFeeInfo } from './v1/calculateMinerFeeInfo';
@@ -81,8 +82,11 @@ export const ExpressLoginApiSpec = apiSpec({
8182
});
8283

8384
export const ExpressDecryptApiSpec = apiSpec({
85+
'express.v1.decrypt': {
86+
post: PostV1Decrypt,
87+
},
8488
'express.decrypt': {
85-
post: PostDecrypt,
89+
post: PostV2Decrypt,
8690
},
8791
});
8892

modules/express/src/typedRoutes/api/common/decrypt.ts renamed to modules/express/src/typedRoutes/api/v1/decrypt.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http';
33
import { BitgoExpressError } from '../../schemas/error';
44

55
export const DecryptRequestBody = {
6+
/** Ciphertext to decrypt */
67
input: t.string,
8+
/** Key which is used for decryption */
79
password: optional(t.string),
810
};
911

1012
/**
11-
* Decrypt
13+
* Decrypt (v1)
1214
*
13-
* @operationId express.decrypt
15+
* Decrypts an encrypted string using the provided password.
16+
*
17+
* @operationId express.v1.decrypt
1418
* @tag express
1519
*/
16-
export const PostDecrypt = httpRoute({
17-
path: '/api/v[12]/decrypt',
20+
export const PostV1Decrypt = httpRoute({
21+
path: '/api/v1/decrypt',
1822
method: 'POST',
1923
request: httpRequest({
2024
body: DecryptRequestBody,
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+
import { DecryptRequestBody } from '../v1/decrypt';
5+
6+
/**
7+
* Decrypt
8+
*
9+
* Decrypt a ciphertext generated by encrypt route with provided password
10+
*
11+
* @operationId express.decrypt
12+
* @tag express
13+
*/
14+
export const PostV2Decrypt = httpRoute({
15+
path: '/api/v2/decrypt',
16+
method: 'POST',
17+
request: httpRequest({
18+
body: DecryptRequestBody,
19+
}),
20+
response: {
21+
200: t.type({
22+
decrypted: t.string,
23+
}),
24+
404: BitgoExpressError,
25+
},
26+
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as assert from 'assert';
22
import * as t from 'io-ts';
3-
import { DecryptRequestBody } from '../../../src/typedRoutes/api/common/decrypt';
3+
import { DecryptRequestBody } from '../../../src/typedRoutes/api/v1/decrypt';
44
import { EncryptRequestBody } from '../../../src/typedRoutes/api/common/encrypt';
55
import { LoginRequest } from '../../../src/typedRoutes/api/common/login';
66
import { VerifyAddressBody } from '../../../src/typedRoutes/api/common/verifyAddress';

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as assert from 'assert';
22
import * as t from 'io-ts';
3-
import { DecryptRequestBody, PostDecrypt } from '../../../src/typedRoutes/api/common/decrypt';
3+
import { DecryptRequestBody, PostV1Decrypt } from '../../../src/typedRoutes/api/v1/decrypt';
4+
import { PostV2Decrypt } from '../../../src/typedRoutes/api/v2/decrypt';
45
import { assertDecode } from './common';
56
import 'should';
67
import 'should-http';
@@ -65,7 +66,7 @@ describe('Decrypt codec tests', function () {
6566
});
6667

6768
describe('DecryptResponse', function () {
68-
const DecryptResponse = PostDecrypt.response[200];
69+
const DecryptResponse = PostV1Decrypt.response[200];
6970

7071
it('should validate response with required field', function () {
7172
const validResponse = {
@@ -112,24 +113,41 @@ describe('Decrypt codec tests', function () {
112113
});
113114
});
114115

115-
describe('PostDecrypt route definition', function () {
116+
describe('PostV1Decrypt route definition', function () {
116117
it('should have the correct path', function () {
117-
assert.strictEqual(PostDecrypt.path, '/api/v[12]/decrypt');
118+
assert.strictEqual(PostV1Decrypt.path, '/api/v1/decrypt');
118119
});
119120

120121
it('should have the correct HTTP method', function () {
121-
assert.strictEqual(PostDecrypt.method, 'POST');
122+
assert.strictEqual(PostV1Decrypt.method, 'POST');
122123
});
123124

124125
it('should have the correct request configuration', function () {
125-
// Verify the route is configured with a request property
126-
assert.ok(PostDecrypt.request);
126+
assert.ok(PostV1Decrypt.request);
127127
});
128128

129129
it('should have the correct response types', function () {
130-
// Check that the response object has the expected status codes
131-
assert.ok(PostDecrypt.response[200]);
132-
assert.ok(PostDecrypt.response[404]);
130+
assert.ok(PostV1Decrypt.response[200]);
131+
assert.ok(PostV1Decrypt.response[404]);
132+
});
133+
});
134+
135+
describe('PostV2Decrypt route definition', function () {
136+
it('should have the correct path', function () {
137+
assert.strictEqual(PostV2Decrypt.path, '/api/v2/decrypt');
138+
});
139+
140+
it('should have the correct HTTP method', function () {
141+
assert.strictEqual(PostV2Decrypt.method, 'POST');
142+
});
143+
144+
it('should have the correct request configuration', function () {
145+
assert.ok(PostV2Decrypt.request);
146+
});
147+
148+
it('should have the correct response types', function () {
149+
assert.ok(PostV2Decrypt.response[200]);
150+
assert.ok(PostV2Decrypt.response[404]);
133151
});
134152
});
135153

@@ -164,7 +182,7 @@ describe('Decrypt codec tests', function () {
164182
result.body.should.have.property('decrypted');
165183
assert.strictEqual(result.body.decrypted, mockDecryptResponse);
166184

167-
const decodedResponse = assertDecode(PostDecrypt.response[200], result.body);
185+
const decodedResponse = assertDecode(PostV1Decrypt.response[200], result.body);
168186
assert.strictEqual(decodedResponse.decrypted, mockDecryptResponse);
169187
});
170188

@@ -186,7 +204,7 @@ describe('Decrypt codec tests', function () {
186204
result.body.should.have.property('decrypted');
187205
assert.strictEqual(result.body.decrypted, mockDecryptResponse);
188206

189-
const decodedResponse = assertDecode(PostDecrypt.response[200], result.body);
207+
const decodedResponse = assertDecode(PostV2Decrypt.response[200], result.body);
190208
assert.strictEqual(decodedResponse.decrypted, mockDecryptResponse);
191209
});
192210

@@ -208,7 +226,7 @@ describe('Decrypt codec tests', function () {
208226
assert.strictEqual(result.status, 200);
209227
assert.strictEqual(result.body.decrypted, mockLongDecrypted);
210228

211-
const decodedResponse = assertDecode(PostDecrypt.response[200], result.body);
229+
const decodedResponse = assertDecode(PostV1Decrypt.response[200], result.body);
212230
assert.strictEqual(decodedResponse.decrypted, mockLongDecrypted);
213231
});
214232

@@ -229,7 +247,7 @@ describe('Decrypt codec tests', function () {
229247
assert.strictEqual(result.status, 200);
230248
assert.strictEqual(result.body.decrypted, mockDecryptResponse);
231249

232-
const decodedResponse = assertDecode(PostDecrypt.response[200], result.body);
250+
const decodedResponse = assertDecode(PostV2Decrypt.response[200], result.body);
233251
assert.ok(decodedResponse);
234252
});
235253
});

0 commit comments

Comments
 (0)