|
| 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 | +import { ShareState, ShareWalletKeychain } from '../../schemas/wallet'; |
| 5 | + |
| 6 | +/** |
| 7 | + * Path parameters for sharing a wallet |
| 8 | + */ |
| 9 | +export const ShareWalletParams = { |
| 10 | + /** Coin ticker / chain identifier */ |
| 11 | + coin: t.string, |
| 12 | + /** Wallet ID */ |
| 13 | + id: t.string, |
| 14 | +} as const; |
| 15 | + |
| 16 | +/** |
| 17 | + * Request body for sharing a wallet |
| 18 | + */ |
| 19 | +export const ShareWalletBody = { |
| 20 | + /** Recipient email address */ |
| 21 | + email: t.string, |
| 22 | + /** Permissions string, e.g., "view,spend" */ |
| 23 | + permissions: t.string, |
| 24 | + /** Wallet passphrase used to derive shared key when needed */ |
| 25 | + walletPassphrase: optional(t.string), |
| 26 | + /** Optional message to include with the share */ |
| 27 | + message: optional(t.string), |
| 28 | + /** If true, allows sharing without a keychain */ |
| 29 | + reshare: optional(t.boolean), |
| 30 | + /** If true, skips sharing the wallet keychain with the recipient */ |
| 31 | + skipKeychain: optional(t.boolean), |
| 32 | + /** If true, suppresses email notification to the recipient */ |
| 33 | + disableEmail: optional(t.boolean), |
| 34 | +} as const; |
| 35 | + |
| 36 | +/** |
| 37 | + * Response for sharing a wallet |
| 38 | + */ |
| 39 | +export const ShareWalletResponse200 = t.intersection([ |
| 40 | + t.type({ |
| 41 | + /** Wallet share id */ |
| 42 | + id: t.string, |
| 43 | + /** Coin of the wallet */ |
| 44 | + coin: t.string, |
| 45 | + /** Wallet id */ |
| 46 | + wallet: t.string, |
| 47 | + /** Id of the sharer */ |
| 48 | + fromUser: t.string, |
| 49 | + /** Id of the recipient */ |
| 50 | + toUser: t.string, |
| 51 | + /** Comma-separated list of privileges for wallet */ |
| 52 | + permissions: t.string, |
| 53 | + }), |
| 54 | + t.partial({ |
| 55 | + /** Wallet label */ |
| 56 | + walletLabel: t.string, |
| 57 | + /** User-readable message */ |
| 58 | + message: t.string, |
| 59 | + /** Share state */ |
| 60 | + state: ShareState, |
| 61 | + /** Enterprise id, if applicable */ |
| 62 | + enterprise: t.string, |
| 63 | + /** Pending approval id, if one was generated */ |
| 64 | + pendingApprovalId: t.string, |
| 65 | + /** Included if shared with spend permission */ |
| 66 | + keychain: ShareWalletKeychain, |
| 67 | + }), |
| 68 | +]); |
| 69 | + |
| 70 | +export const ShareWalletResponse = { |
| 71 | + 200: ShareWalletResponse200, |
| 72 | + 400: BitgoExpressError, |
| 73 | +} as const; |
| 74 | + |
| 75 | +/** |
| 76 | + * Share this wallet with another BitGo user. |
| 77 | + * |
| 78 | + * @operationId express.v2.wallet.share |
| 79 | + */ |
| 80 | +export const PostShareWallet = httpRoute({ |
| 81 | + path: '/api/v2/{coin}/wallet/{id}/share', |
| 82 | + method: 'POST', |
| 83 | + request: httpRequest({ |
| 84 | + params: ShareWalletParams, |
| 85 | + body: ShareWalletBody, |
| 86 | + }), |
| 87 | + response: ShareWalletResponse, |
| 88 | +}); |
0 commit comments