|
| 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 verifying if an address belongs to a wallet |
| 7 | + */ |
| 8 | +export const IsWalletAddressParams = { |
| 9 | + /** Coin ticker / chain identifier */ |
| 10 | + coin: t.string, |
| 11 | + /** The ID of the wallet */ |
| 12 | + id: t.string, |
| 13 | +} as const; |
| 14 | + |
| 15 | +/** |
| 16 | + * Keychain codec for address verification |
| 17 | + * Supports both BIP32 wallets (need ethAddress) and TSS/MPC wallets (need commonKeychain) |
| 18 | + */ |
| 19 | +export const KeychainCodec = t.intersection([ |
| 20 | + // Required field |
| 21 | + t.type({ |
| 22 | + pub: t.string, |
| 23 | + }), |
| 24 | + // Optional fields for different wallet types |
| 25 | + t.partial({ |
| 26 | + /** Ethereum address (required for BIP32 wallet base address verification: V1, V2, V4) */ |
| 27 | + ethAddress: t.string, |
| 28 | + /** Common keychain (required for TSS/MPC wallets: V3, V5, V6) */ |
| 29 | + commonKeychain: t.string, |
| 30 | + }), |
| 31 | +]); |
| 32 | + |
| 33 | +/** |
| 34 | + * Request body for verifying if an address belongs to a wallet |
| 35 | + */ |
| 36 | +export const IsWalletAddressBody = { |
| 37 | + /** The address to verify */ |
| 38 | + address: t.string, |
| 39 | + /** Keychains for verification */ |
| 40 | + keychains: t.array(KeychainCodec), |
| 41 | + /** Base address of the wallet */ |
| 42 | + baseAddress: optional(t.string), |
| 43 | + /** Wallet version */ |
| 44 | + walletVersion: optional(t.number), |
| 45 | + /** Address index for TSS/MPC wallet derivation */ |
| 46 | + index: optional(t.union([t.number, t.string])), |
| 47 | + /** Coin-specific address data */ |
| 48 | + coinSpecific: optional( |
| 49 | + t.partial({ |
| 50 | + /** Forwarder version */ |
| 51 | + forwarderVersion: t.number, |
| 52 | + /** Salt for CREATE2 address derivation */ |
| 53 | + salt: t.string, |
| 54 | + /** Fee address for v4 forwarders */ |
| 55 | + feeAddress: t.string, |
| 56 | + /** Base address (alternative to top-level baseAddress) */ |
| 57 | + baseAddress: t.string, |
| 58 | + }) |
| 59 | + ), |
| 60 | + /** Implied forwarder version */ |
| 61 | + impliedForwarderVersion: optional(t.number), |
| 62 | + /** Format for the address */ |
| 63 | + format: optional(t.string), |
| 64 | + /** Root address for coins that use root address */ |
| 65 | + rootAddress: optional(t.string), |
| 66 | +} as const; |
| 67 | + |
| 68 | +/** |
| 69 | + * Response for verifying if an address belongs to a wallet |
| 70 | + */ |
| 71 | +export const IsWalletAddressResponse = { |
| 72 | + 200: t.boolean, |
| 73 | + 400: BitgoExpressError, |
| 74 | +} as const; |
| 75 | + |
| 76 | +/** |
| 77 | + * Verify if an address belongs to a wallet |
| 78 | + * |
| 79 | + * This endpoint verifies whether a given address belongs to the specified wallet. |
| 80 | + * It performs cryptographic verification, checking address derivation |
| 81 | + * against wallet keychains and configuration. |
| 82 | + * |
| 83 | + * Returns `true` if the address belongs to the wallet, `false` otherwise. |
| 84 | + * Throws an error if verification fails or parameters are invalid. |
| 85 | + * |
| 86 | + * To verify a baseAddress, set the `baseAddress` and `address` to the base address of the wallet. |
| 87 | + * |
| 88 | + * **Limitations:** |
| 89 | + * - Forwarder v0: Cannot verify (nonce not stored). Returns `true` without verification. |
| 90 | + * |
| 91 | + * @operationId express.v2.wallet.isWalletAddress |
| 92 | + * @tag Express |
| 93 | + */ |
| 94 | +export const PostIsWalletAddress = httpRoute({ |
| 95 | + path: '/api/v2/{coin}/wallet/{id}/iswalletaddress', |
| 96 | + method: 'POST', |
| 97 | + request: httpRequest({ |
| 98 | + params: IsWalletAddressParams, |
| 99 | + body: IsWalletAddressBody, |
| 100 | + }), |
| 101 | + response: IsWalletAddressResponse, |
| 102 | +}); |
0 commit comments