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
1 change: 1 addition & 0 deletions modules/express/src/clientRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,7 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
router.post('express.login', [prepareBitGo(config), typedPromiseWrapper(handleLogin)]);

router.post('express.decrypt', [prepareBitGo(config), typedPromiseWrapper(handleDecrypt)]);
router.post('express.v1.encrypt', [prepareBitGo(config), typedPromiseWrapper(handleEncrypt)]);
router.post('express.encrypt', [prepareBitGo(config), typedPromiseWrapper(handleEncrypt)]);
router.post('express.verifyaddress', [prepareBitGo(config), typedPromiseWrapper(handleVerifyAddress)]);
router.post('express.v1.calculateminerfeeinfo', [
Expand Down
8 changes: 6 additions & 2 deletions modules/express/src/typedRoutes/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { GetPing } from './common/ping';
import { GetPingExpress } from './common/pingExpress';
import { PostLogin } from './common/login';
import { PostDecrypt } from './common/decrypt';
import { PostEncrypt } from './common/encrypt';
import { PostV1Encrypt } from './v1/encrypt';
import { PostV2Encrypt } from './v2/encrypt';
import { PostVerifyAddress } from './common/verifyAddress';
import { PostV1CalculateMinerFeeInfo } from './v1/calculateMinerFeeInfo';
import { PostV2CalculateMinerFeeInfo } from './v2/calculateMinerFeeInfo';
Expand Down Expand Up @@ -87,8 +88,11 @@ export const ExpressDecryptApiSpec = apiSpec({
});

export const ExpressEncryptApiSpec = apiSpec({
'express.v1.encrypt': {
post: PostV1Encrypt,
},
'express.encrypt': {
post: PostEncrypt,
post: PostV2Encrypt,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http';
import { BitgoExpressError } from '../../schemas/error';

export const EncryptRequestBody = {
/** Plaintext message which should be encrypted */
input: t.string,
/** Password which should be used to encrypt message */
password: optional(t.string),
adata: optional(t.string),
};

/**
* Encrypt
* Encrypt message (v1)
*
* @operationId express.encrypt
* @tag express
* Symmetrically encrypt an arbitrary message with provided password
*
* @operationId express.v1.encrypt
* @tag Express
* @private
*/
export const PostEncrypt = httpRoute({
path: '/api/v[12]/encrypt',
export const PostV1Encrypt = httpRoute({
path: '/api/v1/encrypt',
method: 'POST',
request: httpRequest({
body: EncryptRequestBody,
Expand Down
27 changes: 27 additions & 0 deletions modules/express/src/typedRoutes/api/v2/encrypt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as t from 'io-ts';
import { httpRoute, httpRequest } from '@api-ts/io-ts-http';
import { BitgoExpressError } from '../../schemas/error';
import { EncryptRequestBody } from '../v1/encrypt';

/**
* Encrypt message
*
* Symmetrically encrypt an arbitrary message with provided password
*
* @operationId express.encrypt
* @tag Express
* @public
*/
export const PostV2Encrypt = httpRoute({
path: '/api/v2/encrypt',
method: 'POST',
request: httpRequest({
body: EncryptRequestBody,
}),
response: {
200: t.type({
encrypted: t.string,
}),
404: BitgoExpressError,
},
});
2 changes: 1 addition & 1 deletion modules/express/test/unit/typedRoutes/decode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'assert';
import * as t from 'io-ts';
import { DecryptRequestBody } from '../../../src/typedRoutes/api/common/decrypt';
import { EncryptRequestBody } from '../../../src/typedRoutes/api/common/encrypt';
import { EncryptRequestBody } from '../../../src/typedRoutes/api/v1/encrypt';
import { LoginRequest } from '../../../src/typedRoutes/api/common/login';
import { VerifyAddressBody } from '../../../src/typedRoutes/api/common/verifyAddress';
import { VerifyAddressV2Body, VerifyAddressV2Params } from '../../../src/typedRoutes/api/v2/verifyAddress';
Expand Down
52 changes: 35 additions & 17 deletions modules/express/test/unit/typedRoutes/encrypt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as assert from 'assert';
import * as t from 'io-ts';
import { EncryptRequestBody, PostEncrypt } from '../../../src/typedRoutes/api/common/encrypt';
import { EncryptRequestBody, PostV1Encrypt } from '../../../src/typedRoutes/api/v1/encrypt';
import { PostV2Encrypt } from '../../../src/typedRoutes/api/v2/encrypt';
import { assertDecode } from './common';
import 'should';
import 'should-http';
Expand Down Expand Up @@ -92,7 +93,7 @@ describe('Encrypt codec tests', function () {
});

describe('EncryptResponse', function () {
const EncryptResponse = PostEncrypt.response[200];
const EncryptResponse = PostV1Encrypt.response[200];

it('should validate response with required field', function () {
const validResponse = {
Expand Down Expand Up @@ -139,24 +140,41 @@ describe('Encrypt codec tests', function () {
});
});

describe('PostEncrypt route definition', function () {
describe('PostV1Encrypt route definition', function () {
it('should have the correct path', function () {
assert.strictEqual(PostEncrypt.path, '/api/v[12]/encrypt');
assert.strictEqual(PostV1Encrypt.path, '/api/v1/encrypt');
});

it('should have the correct HTTP method', function () {
assert.strictEqual(PostEncrypt.method, 'POST');
assert.strictEqual(PostV1Encrypt.method, 'POST');
});

it('should have the correct request configuration', function () {
// Verify the route is configured with a request property
assert.ok(PostEncrypt.request);
assert.ok(PostV1Encrypt.request);
});

it('should have the correct response types', function () {
// Check that the response object has the expected status codes
assert.ok(PostEncrypt.response[200]);
assert.ok(PostEncrypt.response[404]);
assert.ok(PostV1Encrypt.response[200]);
assert.ok(PostV1Encrypt.response[404]);
});
});

describe('PostV2Encrypt route definition', function () {
it('should have the correct path', function () {
assert.strictEqual(PostV2Encrypt.path, '/api/v2/encrypt');
});

it('should have the correct HTTP method', function () {
assert.strictEqual(PostV2Encrypt.method, 'POST');
});

it('should have the correct request configuration', function () {
assert.ok(PostV2Encrypt.request);
});

it('should have the correct response types', function () {
assert.ok(PostV2Encrypt.response[200]);
assert.ok(PostV2Encrypt.response[404]);
});
});

Expand Down Expand Up @@ -191,7 +209,7 @@ describe('Encrypt codec tests', function () {
result.body.should.have.property('encrypted');
assert.strictEqual(result.body.encrypted, mockEncryptResponse);

const decodedResponse = assertDecode(PostEncrypt.response[200], result.body);
const decodedResponse = assertDecode(PostV1Encrypt.response[200], result.body);
assert.strictEqual(decodedResponse.encrypted, mockEncryptResponse);
});

Expand All @@ -213,7 +231,7 @@ describe('Encrypt codec tests', function () {
result.body.should.have.property('encrypted');
assert.strictEqual(result.body.encrypted, mockEncryptResponse);

const decodedResponse = assertDecode(PostEncrypt.response[200], result.body);
const decodedResponse = assertDecode(PostV2Encrypt.response[200], result.body);
assert.strictEqual(decodedResponse.encrypted, mockEncryptResponse);
});

Expand All @@ -235,7 +253,7 @@ describe('Encrypt codec tests', function () {
assert.strictEqual(result.status, 200);
assert.strictEqual(result.body.encrypted, mockEncryptResponse);

const decodedResponse = assertDecode(PostEncrypt.response[200], result.body);
const decodedResponse = assertDecode(PostV1Encrypt.response[200], result.body);
assert.strictEqual(decodedResponse.encrypted, mockEncryptResponse);
});

Expand All @@ -257,7 +275,7 @@ describe('Encrypt codec tests', function () {
assert.strictEqual(result.status, 200);
assert.strictEqual(result.body.encrypted, mockEncryptResponse);

const decodedResponse = assertDecode(PostEncrypt.response[200], result.body);
const decodedResponse = assertDecode(PostV2Encrypt.response[200], result.body);
assert.strictEqual(decodedResponse.encrypted, mockEncryptResponse);
});

Expand All @@ -279,7 +297,7 @@ describe('Encrypt codec tests', function () {
assert.strictEqual(result.status, 200);
assert.strictEqual(result.body.encrypted, mockLongEncrypted);

const decodedResponse = assertDecode(PostEncrypt.response[200], result.body);
const decodedResponse = assertDecode(PostV1Encrypt.response[200], result.body);
assert.strictEqual(decodedResponse.encrypted, mockLongEncrypted);
});

Expand All @@ -300,7 +318,7 @@ describe('Encrypt codec tests', function () {
assert.strictEqual(result.status, 200);
assert.strictEqual(result.body.encrypted, mockEncryptResponse);

const decodedResponse = assertDecode(PostEncrypt.response[200], result.body);
const decodedResponse = assertDecode(PostV2Encrypt.response[200], result.body);
assert.ok(decodedResponse);
});

Expand All @@ -321,7 +339,7 @@ describe('Encrypt codec tests', function () {
assert.strictEqual(result.status, 200);
assert.strictEqual(result.body.encrypted, mockEncryptResponse);

const decodedResponse = assertDecode(PostEncrypt.response[200], result.body);
const decodedResponse = assertDecode(PostV1Encrypt.response[200], result.body);
assert.ok(decodedResponse);
});
});
Expand Down
Loading