-
Notifications
You must be signed in to change notification settings - Fork 300
feat(express): migrated update express wallet to typed routes #7095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
danielzhao122
merged 6 commits into
master
from
WP-5416-express-migrate-api-v2-coin-wallet-id-to-typed-route
Oct 21, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c47d741
feat(express): migrated update express wallet to typed routes
danielzhao122 44b48eb
refactor: handleUpdateLightningWalletCoinSpecific to work with api-ts
danielzhao122 ba305af
test(express): add supertests for wallet update
danielzhao122 7d34224
Merge remote-tracking branch 'origin/master' into WP-5416-express-mig…
danielzhao122 362b0f6
refactor: fleshed out the response codec and updated tests to reflect…
danielzhao122 e4f3b4c
Merge branch 'master' into WP-5416-express-migrate-api-v2-coin-wallet…
danielzhao122 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,13 @@ | ||
| import * as express from 'express'; | ||
| import { ApiResponseError } from '../errors'; | ||
| import { UpdateLightningWalletClientRequest, updateWalletCoinSpecific } from '@bitgo/abstract-lightning'; | ||
| import { decodeOrElse } from '@bitgo/sdk-core'; | ||
| import { updateWalletCoinSpecific } from '@bitgo/abstract-lightning'; | ||
| import { ExpressApiRouteRequest } from '../typedRoutes/api'; | ||
|
|
||
| export async function handleUpdateLightningWalletCoinSpecific(req: express.Request): Promise<unknown> { | ||
| export async function handleUpdateLightningWalletCoinSpecific( | ||
| req: ExpressApiRouteRequest<'express.wallet.update', 'put'> | ||
| ): Promise<unknown> { | ||
| const bitgo = req.bitgo; | ||
|
|
||
| const params = decodeOrElse( | ||
| 'UpdateLightningWalletClientRequest', | ||
| UpdateLightningWalletClientRequest, | ||
| req.body, | ||
| (_) => { | ||
| // DON'T throw errors from decodeOrElse. It could leak sensitive information. | ||
| throw new ApiResponseError('Invalid request body to update lightning wallet coin specific', 400); | ||
| } | ||
| ); | ||
| const coin = bitgo.coin(req.decoded.coin); | ||
| const wallet = await coin.wallets().get({ id: req.decoded.id, includeBalance: false }); | ||
|
|
||
| const coin = bitgo.coin(req.params.coin); | ||
| const wallet = await coin.wallets().get({ id: req.params.id, includeBalance: false }); | ||
|
|
||
| return await updateWalletCoinSpecific(wallet, params); | ||
| return await updateWalletCoinSpecific(wallet, req.decoded); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
modules/express/src/typedRoutes/api/v2/expressWalletUpdate.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import * as t from 'io-ts'; | ||
| import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http'; | ||
| import { BitgoExpressError } from '../../schemas/error'; | ||
| import { WalletResponse } from '../../schemas/wallet'; | ||
|
|
||
| /** | ||
| * Parameters for Express Wallet Update | ||
| */ | ||
| export const ExpressWalletUpdateParams = { | ||
| /** Coin ticker / chain identifier */ | ||
| coin: t.string, | ||
| /** Wallet ID */ | ||
| id: t.string, | ||
| } as const; | ||
|
|
||
| /** | ||
| * Request body for Express Wallet Update | ||
| */ | ||
| export const ExpressWalletUpdateBody = { | ||
| /** The host address of the lightning signer node. */ | ||
| signerHost: t.string, | ||
| /** The TLS certificate for the lighting signer node encoded to base64. */ | ||
| signerTlsCert: t.string, | ||
| /** (Optional) The signer macaroon for the lighting signer node. */ | ||
| signerMacaroon: optional(t.string), | ||
| /** The wallet passphrase (used locally to decrypt and sign). */ | ||
| passphrase: t.string, | ||
| } as const; | ||
|
|
||
| /** | ||
| * Response for Express Wallet Update | ||
| */ | ||
| export const ExpressWalletUpdateResponse = { | ||
| /** Updated Wallet - Returns the wallet with updated Lightning signer configuration */ | ||
| 200: WalletResponse, | ||
| /** Bad Request - Invalid parameters or missing required fields */ | ||
| 400: BitgoExpressError, | ||
| /** Forbidden - Insufficient permissions to update the wallet */ | ||
| 403: BitgoExpressError, | ||
| /** Not Found - Wallet not found or invalid coin type */ | ||
| 404: BitgoExpressError, | ||
| } as const; | ||
|
|
||
| /** | ||
| * Express - Update Wallet | ||
| * The express update wallet route is meant to be used for lightning (lnbtc/tlnbtc). | ||
| * For other coins, use the standard wallet update endpoint. | ||
| * | ||
| * @operationId express.wallet.update | ||
| */ | ||
| export const PutExpressWalletUpdate = httpRoute({ | ||
| path: '/express/api/v2/{coin}/wallet/{id}', | ||
| method: 'PUT', | ||
| request: httpRequest({ | ||
| params: ExpressWalletUpdateParams, | ||
| body: ExpressWalletUpdateBody, | ||
| }), | ||
| response: ExpressWalletUpdateResponse, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.