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
10 changes: 3 additions & 7 deletions modules/express/src/clientRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function handleCreateTransaction(req: express.Request) {
* @deprecated
* @param req
*/
function handleSignTransaction(req: express.Request) {
function handleSignTransaction(req: ExpressApiRouteRequest<'express.v1.wallet.signTransaction', 'post'>) {
return req.bitgo
.wallets()
.get({ id: req.params.id })
Expand Down Expand Up @@ -1588,12 +1588,8 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
prepareBitGo(config),
promiseWrapper(handleCreateTransaction)
);
app.post(
'/api/v1/wallet/:id/signtransaction',
parseBody,
prepareBitGo(config),
promiseWrapper(handleSignTransaction)
);

router.post('express.v1.wallet.signTransaction', [prepareBitGo(config), typedPromiseWrapper(handleSignTransaction)]);

app.post('/api/v1/wallet/:id/simpleshare', parseBody, prepareBitGo(config), promiseWrapper(handleShareWallet));
router.post('express.v1.wallet.acceptShare', [prepareBitGo(config), typedPromiseWrapper(handleAcceptShare)]);
Expand Down
5 changes: 5 additions & 0 deletions modules/express/src/typedRoutes/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { PostVerifyAddress } from './common/verifyAddress';
import { PostAcceptShare } from './v1/acceptShare';
import { PostSimpleCreate } from './v1/simpleCreate';
import { PutPendingApproval } from './v1/pendingApproval';
import { PostSignTransaction } from './v1/signTransaction';

export const ExpressApi = apiSpec({
'express.ping': {
get: GetPing,
Expand All @@ -35,6 +37,9 @@ export const ExpressApi = apiSpec({
'express.v1.pendingapprovals': {
put: PutPendingApproval,
},
'express.v1.wallet.signTransaction': {
post: PostSignTransaction,
},
});

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

export const signTransactionRequestParams = {
/** ID of the wallet */
id: t.string,
};

export const signTransactionRequestBody = {
/** Serialized form of the transaction in hex */
transactionHex: t.string,
/** array of unspent information, where each unspent is a chainPath
and redeemScript with the same index as the inputs in the
transactionHex */
unspents: t.array(t.any),
/** Keychain containing the xprv to sign with */
keychain: t.intersection([
t.type({
xprv: t.string,
}),
t.record(t.string, t.any),
]),
/** For legacy safe wallets, the private key string */
signingKey: t.string,
/** extra verification of signatures (which are always verified server-side) (defaults to global config) */
validate: optional(t.boolean),
};

/**
* signTransaction
* Sign a previously created transaction with a keychain
*
* @operationId express.v1.wallet.signTransaction
*/
export const PostSignTransaction = httpRoute({
path: '/api/v1/wallet/{id}/signtransaction',
method: 'POST',
request: httpRequest({
params: signTransactionRequestParams,
body: signTransactionRequestBody,
}),
response: {
/** Successfully accepted wallet share */
200: t.UnknownRecord,
/** Error response */
400: BitgoExpressError,
},
});
Loading