Skip to content

Commit d44f2c5

Browse files
feat(express): migrating to typed router
Typed router for signtx api Ticket: WP-5407
1 parent 23503ec commit d44f2c5

File tree

4 files changed

+395
-7
lines changed

4 files changed

+395
-7
lines changed

modules/express/src/clientRoutes.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function handleCreateTransaction(req: express.Request) {
203203
* @deprecated
204204
* @param req
205205
*/
206-
function handleSignTransaction(req: express.Request) {
206+
function handleSignTransaction(req: ExpressApiRouteRequest<'express.v1.wallet.signTransaction', 'post'>) {
207207
return req.bitgo
208208
.wallets()
209209
.get({ id: req.params.id })
@@ -1588,12 +1588,8 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
15881588
prepareBitGo(config),
15891589
promiseWrapper(handleCreateTransaction)
15901590
);
1591-
app.post(
1592-
'/api/v1/wallet/:id/signtransaction',
1593-
parseBody,
1594-
prepareBitGo(config),
1595-
promiseWrapper(handleSignTransaction)
1596-
);
1591+
1592+
router.post('express.v1.wallet.signTransaction', [prepareBitGo(config), typedPromiseWrapper(handleSignTransaction)]);
15971593

15981594
app.post('/api/v1/wallet/:id/simpleshare', parseBody, prepareBitGo(config), promiseWrapper(handleShareWallet));
15991595
router.post('express.v1.wallet.acceptShare', [prepareBitGo(config), typedPromiseWrapper(handleAcceptShare)]);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { PostVerifyAddress } from './common/verifyAddress';
1010
import { PostAcceptShare } from './v1/acceptShare';
1111
import { PostSimpleCreate } from './v1/simpleCreate';
1212
import { PutPendingApproval } from './v1/pendingApproval';
13+
import { PostSignTransaction } from './v1/signTransaction';
14+
1315
export const ExpressApi = apiSpec({
1416
'express.ping': {
1517
get: GetPing,
@@ -35,6 +37,9 @@ export const ExpressApi = apiSpec({
3537
'express.v1.pendingapprovals': {
3638
put: PutPendingApproval,
3739
},
40+
'express.v1.wallet.signTransaction': {
41+
post: PostSignTransaction,
42+
},
3843
});
3944

4045
export type ExpressApi = typeof ExpressApi;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as t from 'io-ts';
2+
import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http';
3+
import { BitgoExpressError } from '../../schemas/error';
4+
5+
export const signTransactionRequestParams = {
6+
/** ID of the wallet */
7+
id: t.string,
8+
};
9+
10+
export const signTransactionRequestBody = {
11+
/** Serialized form of the transaction in hex */
12+
transactionHex: t.string,
13+
/** array of unspent information, where each unspent is a chainPath
14+
and redeemScript with the same index as the inputs in the
15+
transactionHex */
16+
unspents: t.array(t.any),
17+
/** Keychain containing the xprv to sign with */
18+
keychain: t.intersection([
19+
t.type({
20+
xprv: t.string,
21+
}),
22+
t.record(t.string, t.any),
23+
]),
24+
/** For legacy safe wallets, the private key string */
25+
signingKey: t.string,
26+
/** extra verification of signatures (which are always verified server-side) (defaults to global config) */
27+
validate: optional(t.boolean),
28+
};
29+
30+
/**
31+
* signTransaction
32+
* Sign a previously created transaction with a keychain
33+
*
34+
* @operationId express.v1.wallet.signTransaction
35+
*/
36+
export const PostSignTransaction = httpRoute({
37+
path: '/api/v1/wallet/{id}/signtransaction',
38+
method: 'POST',
39+
request: httpRequest({
40+
params: signTransactionRequestParams,
41+
body: signTransactionRequestBody,
42+
}),
43+
response: {
44+
/** Successfully accepted wallet share */
45+
200: t.UnknownRecord,
46+
/** Error response */
47+
400: BitgoExpressError,
48+
},
49+
});

0 commit comments

Comments
 (0)