|
| 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 | +/** |
| 6 | + * Path parameters for pending approval endpoint |
| 7 | + */ |
| 8 | +export const PendingApprovalParams = { |
| 9 | + /** Coin identifier (e.g., 'btc', 'eth', 'tbtc') */ |
| 10 | + coin: t.string, |
| 11 | + /** Pending approval ID */ |
| 12 | + id: t.string, |
| 13 | +} as const; |
| 14 | + |
| 15 | +/** |
| 16 | + * Request body for approving or rejecting a pending approval |
| 17 | + */ |
| 18 | +export const PendingApprovalRequestBody = { |
| 19 | + /** State of the approval: 'approved' to approve, omit or 'rejected' to reject */ |
| 20 | + state: optional(t.string), |
| 21 | + /** Wallet passphrase for decrypting user keys during transaction signing */ |
| 22 | + walletPassphrase: optional(t.string), |
| 23 | + /** One-time password for 2FA verification */ |
| 24 | + otp: optional(t.string), |
| 25 | + /** Transaction hex to use instead of the original transaction */ |
| 26 | + tx: optional(t.string), |
| 27 | + /** Private key in string form as an alternative to wallet passphrase */ |
| 28 | + xprv: optional(t.string), |
| 29 | + /** If true, returns information about pending transactions without approving */ |
| 30 | + previewPendingTxs: optional(t.boolean), |
| 31 | + /** Alternative ID for the pending approval */ |
| 32 | + pendingApprovalId: optional(t.string), |
| 33 | +} as const; |
| 34 | + |
| 35 | +/** |
| 36 | + * Pending approval state enum |
| 37 | + */ |
| 38 | +export const PendingApprovalState = t.union([ |
| 39 | + t.literal('pending'), |
| 40 | + t.literal('awaitingSignature'), |
| 41 | + t.literal('pendingBitGoAdminApproval'), |
| 42 | + t.literal('pendingIdVerification'), |
| 43 | + t.literal('pendingCustodianApproval'), |
| 44 | + t.literal('pendingFinalApproval'), |
| 45 | + t.literal('approved'), |
| 46 | + t.literal('processing'), |
| 47 | + t.literal('rejected'), |
| 48 | +]); |
| 49 | + |
| 50 | +/** |
| 51 | + * Pending approval type enum |
| 52 | + */ |
| 53 | +export const PendingApprovalType = t.union([ |
| 54 | + t.literal('userChangeRequest'), |
| 55 | + t.literal('transactionRequest'), |
| 56 | + t.literal('policyRuleRequest'), |
| 57 | + t.literal('updateApprovalsRequiredRequest'), |
| 58 | + t.literal('transactionRequestFull'), |
| 59 | +]); |
| 60 | + |
| 61 | +/** |
| 62 | + * Build parameters for transaction request |
| 63 | + * Allows any additional properties beyond the known 'type' field |
| 64 | + */ |
| 65 | +export const BuildParams = t.intersection([ |
| 66 | + t.partial({ |
| 67 | + /** Transaction type (e.g., fanout, consolidate) */ |
| 68 | + type: t.union([t.literal('fanout'), t.literal('consolidate')]), |
| 69 | + }), |
| 70 | + t.UnknownRecord, |
| 71 | +]); |
| 72 | + |
| 73 | +/** |
| 74 | + * Transaction request info within pending approval |
| 75 | + */ |
| 76 | +export const TransactionRequestInfo = t.intersection([ |
| 77 | + t.type({ |
| 78 | + /** Coin-specific transaction parameters */ |
| 79 | + coinSpecific: t.UnknownRecord, |
| 80 | + /** Transaction recipients */ |
| 81 | + recipients: t.unknown, |
| 82 | + /** Build parameters for the transaction */ |
| 83 | + buildParams: BuildParams, |
| 84 | + }), |
| 85 | + t.partial({ |
| 86 | + /** Source wallet ID for the transaction */ |
| 87 | + sourceWallet: t.string, |
| 88 | + }), |
| 89 | +]); |
| 90 | + |
| 91 | +/** |
| 92 | + * Pending approval information structure |
| 93 | + */ |
| 94 | +export const PendingApprovalInfo = t.intersection([ |
| 95 | + t.type({ |
| 96 | + /** Type of pending approval */ |
| 97 | + type: PendingApprovalType, |
| 98 | + }), |
| 99 | + t.partial({ |
| 100 | + /** Transaction request details (if type is transactionRequest) */ |
| 101 | + transactionRequest: TransactionRequestInfo, |
| 102 | + }), |
| 103 | +]); |
| 104 | + |
| 105 | +/** |
| 106 | + * Pending approval data response |
| 107 | + * Both approve and reject return the same structure |
| 108 | + */ |
| 109 | +export const PendingApprovalResponse = t.intersection([ |
| 110 | + t.type({ |
| 111 | + /** Pending approval unique identifier */ |
| 112 | + id: t.string, |
| 113 | + /** Current state of the pending approval */ |
| 114 | + state: PendingApprovalState, |
| 115 | + /** User ID of the pending approval creator */ |
| 116 | + creator: t.string, |
| 117 | + /** Pending approval information and details */ |
| 118 | + info: PendingApprovalInfo, |
| 119 | + }), |
| 120 | + t.partial({ |
| 121 | + /** Wallet ID if this is a wallet-level approval */ |
| 122 | + wallet: t.string, |
| 123 | + /** Enterprise ID if this is an enterprise-level approval */ |
| 124 | + enterprise: t.string, |
| 125 | + /** Number of approvals required for this pending approval */ |
| 126 | + approvalsRequired: t.number, |
| 127 | + /** Transaction request ID associated with this pending approval */ |
| 128 | + txRequestId: t.string, |
| 129 | + }), |
| 130 | +]); |
| 131 | + |
| 132 | +/** |
| 133 | + * Update Pending Approval |
| 134 | + * Approve or reject a pending approval by its ID. |
| 135 | + * Supports transaction approvals, policy rule changes, and user change requests. |
| 136 | + * |
| 137 | + * @operationId express.v2.pendingapprovals |
| 138 | + * @tag express |
| 139 | + */ |
| 140 | +export const PutV2PendingApproval = httpRoute({ |
| 141 | + path: '/api/v2/{coin}/pendingapprovals/{id}', |
| 142 | + method: 'PUT', |
| 143 | + request: httpRequest({ |
| 144 | + params: PendingApprovalParams, |
| 145 | + body: PendingApprovalRequestBody, |
| 146 | + }), |
| 147 | + response: { |
| 148 | + /** Successfully updated pending approval */ |
| 149 | + 200: PendingApprovalResponse, |
| 150 | + /** Bad request or validation error */ |
| 151 | + 400: BitgoExpressError, |
| 152 | + }, |
| 153 | +}); |
0 commit comments