-
Notifications
You must be signed in to change notification settings - Fork 0
Wp 46222/add api ts #5
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
Conversation
9cf361d to
41827fb
Compare
8373ee9 to
72f943b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a declarative API layer for Master Express mode using @api-ts/express-wrapper, updates the wallet generation flow to match the new handler signature, and adds OpenAPI definitions.
- Refactor
masterExpressApp.tsto use a spec-driven router and handlers (handlePingEnclavedExpress,handleGenerateWallet). - Add
masterExpressApi.tsdefinitions and generatemasterExpressApi.openapi.json. - Migrate on-prem wallet generation logic in
generateWallet.tsand adjust endpoint paths and type casts.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/types.ts | Updated comment for MasterExpress API settings |
| src/masterExpressApp.ts | Refactored routes to use api-ts wrapper, added new handlers |
| src/masterExpressApi.ts | Defined io-ts types and HTTP routes spec for MasterExpressApi |
| src/masterExpressApi.openapi.json | Generated OpenAPI spec from TypeScript definitions |
| src/masterBitgoExpress/generateWallet.ts | Migrated handleGenerateWalletOnPrem signature and implementation |
| src/masterBitgoExpress/enclavedExpressClient.ts | Updated independent keychain endpoint path |
| src/errors.ts | Refined error comment for API response error class |
| src/config.ts | Aligned config comments for MasterExpress API settings |
| package.json | Added scripts/deps for API generation and express-wrapper |
| cert.key | Added SSL key for testing |
Comments suppressed due to low confidence (7)
src/masterExpressApi.ts:82
- The TODO for filling out the full response type indicates an incomplete API specification; please define the full WalletGenerateResponse schema for better API contract clarity.
// TODO: Fill out full response type
src/errors.ts:20
- [nitpick] The class comment suggests ApiResponseError is only for MasterExpressApi responses, but it may be used more broadly; consider generalizing the comment or renaming for consistency.
* Error for MasterExpressApi responses
src/masterExpressApi.ts:58
- [nitpick] The constant
enclavedPingResponseuses lowercase naming while other response types use PascalCase; consider renaming toEnclavedPingResponsefor consistency.
export const enclavedPingResponse = t.type({
src/masterExpressApp.ts:166
- New route handler
handlePingEnclavedExpresslacks accompanying unit or integration tests; please add tests to cover its success and error paths.
const handlePingEnclavedExpress = async () => {
src/masterExpressApp.ts:172
- The code uses POST for the enclaved express ping endpoint, but the ping API likely expects a GET request; please verify and revert to GET if necessary.
.post(`${cfg.enclavedExpressUrl}/ping`)
src/masterExpressApp.ts:251
- These console.log calls expose sensitive configuration (including SSL certificates) and are not ideal for production; please remove them or replace with appropriate debugLogger usage and avoid logging secrets.
console.log('SSL Enabled:', cfg.enableSSL);
package.json:18
- The script uses
openapi-generator, but the installed package is@api-ts/openapi-generatorwhich may provide a different CLI command; please verify and correct the script to use the correct generator binary.
"generate-openapi": "npx openapi-generator ./src/masterExpressApi.ts > src/masterExpressApi.openapi.json"
| }; | ||
|
|
||
| return { ...result, wallet: result.wallet.toJSON() }; | ||
| return result as unknown as WalletWithKeychains; |
Copilot
AI
Jun 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This double type cast (unknown to WalletWithKeychains) weakens type safety; consider updating the SDK types or refining the return type to avoid the unknown cast.
| return result as unknown as WalletWithKeychains; | |
| return result; |
72f943b to
5948e2d
Compare
pranavjain97
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall nice work on converting these to api-ts. Should be super helpful in the future!
cert.key
Outdated
| mmrPvk+Fofxm52+BBmhPMREi3Xu/nc+oGoB2fe+1DLm4rg529ka4GfmjErsYJ1ip | ||
| fg+TBM6j4D+W1pyPmPFTXjL16MGg0zYFcIcuaZBmD1WP1Ojz2uZt5WaPsapuXTi/ | ||
| rkA/bbzrGAE65dSaZDx58k0= | ||
| -----END PRIVATE KEY----- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this for? we already have the test cert's
| debugLogger('Creating independent keychain for coin: %s', this.coin); | ||
| const { body: keychain } = await superagent | ||
| .post(`${this.url}/api/${this.coin}/key/independent`) | ||
| .post(`${this.url}/${this.coin}/key/independentKey`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is /key/independent after based on vivian's API TDD review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will update
| export type GenerateWalletOnPremParams = { | ||
| coin: string; | ||
| label: string; | ||
| enterprise?: string; | ||
| multisigType?: string; | ||
| isDistributedCustody?: boolean; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also might need walletVersion and gasPrice for ETH. Can be added later
|
|
||
| const enclavedExpressClient = createEnclavedExpressClient(req.params.coin); | ||
| export async function handleGenerateWalletOnPrem({ | ||
| bitGo, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| bitGo, | |
| bitgo, |
| }; | ||
|
|
||
| return { ...result, wallet: result.wallet.toJSON() }; | ||
| return result as unknown as WalletWithKeychains; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to cast as unknown? we lose the type safety here
| @@ -0,0 +1,300 @@ | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is auto-generated correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah
| // TODO: Fill out full response type | ||
| export const WalletGenerateRequest = { | ||
| label: t.string, | ||
| enterprise: t.string, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missing fields here. Also, if we have this, why is export type GenerateWalletOnPremParams also needed?
src/masterExpressApi.ts
Outdated
| body: { | ||
| label: t.string, | ||
| enterprise: t.string, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the 3rd place the generate wallet req is typed separately, should be using WalletGenerateRequest
| }; | ||
|
|
||
| // Add a new handler for wallet generation | ||
| const handleGenerateWallet: ServiceFunction<typeof GenerateWalletRequest> = async ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird to have two handlers for 1 API. Can we merge this with handleGenerateWalletOnPrem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree two handlers is weird but I think the break up of the function makes sense. One would be to validate the request and the second would be to actually perform the orchestration of calls to generate the wallet?
5948e2d to
35515b8
Compare
Pull request was converted to draft
No description provided.