Skip to content
Open
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 @@ -1702,6 +1702,7 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
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.v1.verifyaddress', [prepareBitGo(config), typedPromiseWrapper(handleVerifyAddress)]);
router.post('express.verifyaddress', [prepareBitGo(config), typedPromiseWrapper(handleVerifyAddress)]);
router.post('express.v1.calculateminerfeeinfo', [
prepareBitGo(config),
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 @@ -9,7 +9,8 @@ import { PostV1Decrypt } from './v1/decrypt';
import { PostV2Decrypt } from './v2/decrypt';
import { PostV1Encrypt } from './v1/encrypt';
import { PostV2Encrypt } from './v2/encrypt';
import { PostVerifyAddress } from './common/verifyAddress';
import { PostV1VerifyAddress } from './v1/verifyAddress';
import { PostV2VerifyAddress } from './v2/verifyAddress';
import { PostV1CalculateMinerFeeInfo } from './v1/calculateMinerFeeInfo';
import { PostV2CalculateMinerFeeInfo } from './v2/calculateMinerFeeInfo';
import { PostAcceptShare } from './v1/acceptShare';
Expand Down Expand Up @@ -101,8 +102,11 @@ export const ExpressEncryptApiSpec = apiSpec({
});

export const ExpressVerifyAddressApiSpec = apiSpec({
'express.v1.verifyaddress': {
post: PostV1VerifyAddress,
},
'express.verifyaddress': {
post: PostVerifyAddress,
post: PostV2VerifyAddress,
},
});

Expand Down
31 changes: 31 additions & 0 deletions modules/express/src/typedRoutes/api/v1/verifyAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as t from 'io-ts';
import { httpRoute, httpRequest } from '@api-ts/io-ts-http';
import { BitgoExpressError } from '../../schemas/error';

export const VerifyAddressBody = {
/** Address which should be verified for correct format */
address: t.string,
};

/**
* Verify Address (v1)
*
* Verify that a given address string is valid for any supported coin.
*
* @operationId express.v1.verifyaddress
* @tag Express
* @private
*/
export const PostV1VerifyAddress = httpRoute({
path: '/api/v1/verifyaddress',
method: 'POST',
request: httpRequest({
body: VerifyAddressBody,
}),
response: {
200: t.type({
verified: t.boolean,
}),
404: BitgoExpressError,
},
});
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as t from 'io-ts';
import { httpRoute, httpRequest } from '@api-ts/io-ts-http';
import { BitgoExpressError } from '../../schemas/error';

export const VerifyAddressBody = {
address: t.string,
};
import { VerifyAddressBody } from '../v1/verifyAddress';

/**
* Verify Address
*
* Verify that a given address string is valid for any supported coin.
*
* @operationId express.verifyaddress
* @tag express
* @tag Express
* @public
*/
export const PostVerifyAddress = httpRoute({
path: '/api/v[12]/verifyaddress',
export const PostV2VerifyAddress = httpRoute({
path: '/api/v2/verifyaddress',
method: 'POST',
request: httpRequest({
body: VerifyAddressBody,
Expand Down
2 changes: 1 addition & 1 deletion modules/express/test/unit/typedRoutes/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as t from 'io-ts';
import { DecryptRequestBody } from '../../../src/typedRoutes/api/v1/decrypt';
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 { VerifyAddressBody } from '../../../src/typedRoutes/api/v1/verifyAddress';
import { VerifyAddressV2Body, VerifyAddressV2Params } from '../../../src/typedRoutes/api/v2/verifyCoinAddress';
import { SimpleCreateRequestBody } from '../../../src/typedRoutes/api/v1/simpleCreate';
import { KeychainLocalRequestParams } from '../../../src/typedRoutes/api/v2/keychainLocal';
Expand Down
36 changes: 26 additions & 10 deletions modules/express/test/unit/typedRoutes/verifyAddress.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 { VerifyAddressBody, PostVerifyAddress } from '../../../src/typedRoutes/api/common/verifyAddress';
import { VerifyAddressBody, PostV1VerifyAddress } from '../../../src/typedRoutes/api/v1/verifyAddress';
import { PostV2VerifyAddress } from '../../../src/typedRoutes/api/v2/verifyAddress';
import { assertDecode } from './common';
import 'should';
import 'should-http';
Expand Down Expand Up @@ -40,7 +41,7 @@ describe('VerifyAddress codec tests', function () {
});

describe('VerifyAddressResponse', function () {
const VerifyAddressResponse = PostVerifyAddress.response[200];
const VerifyAddressResponse = PostV1VerifyAddress.response[200];

it('should validate response with verified=true', function () {
const validResponse = {
Expand Down Expand Up @@ -79,18 +80,33 @@ describe('VerifyAddress codec tests', function () {
});
});

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

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

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

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

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

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

Expand Down Expand Up @@ -122,7 +138,7 @@ describe('VerifyAddress codec tests', function () {
result.body.should.have.property('verified');
assert.strictEqual(result.body.verified, true);

const decodedResponse = assertDecode(PostVerifyAddress.response[200], result.body);
const decodedResponse = assertDecode(PostV1VerifyAddress.response[200], result.body);
assert.strictEqual(decodedResponse.verified, true);
});

Expand All @@ -142,7 +158,7 @@ describe('VerifyAddress codec tests', function () {
assert.strictEqual(result.status, 200);
assert.strictEqual(result.body.verified, true);

const decodedResponse = assertDecode(PostVerifyAddress.response[200], result.body);
const decodedResponse = assertDecode(PostV2VerifyAddress.response[200], result.body);
assert.strictEqual(decodedResponse.verified, true);
});

Expand All @@ -163,7 +179,7 @@ describe('VerifyAddress codec tests', function () {
result.body.should.have.property('verified');
assert.strictEqual(result.body.verified, false);

const decodedResponse = assertDecode(PostVerifyAddress.response[200], result.body);
const decodedResponse = assertDecode(PostV1VerifyAddress.response[200], result.body);
assert.strictEqual(decodedResponse.verified, false);
});

Expand Down
Loading