Skip to content

Conversation

@mohammadalfaiyazbitgo
Copy link
Contributor

No description provided.

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo force-pushed the WP-4593-add-bitgo-generate-wallet branch 2 times, most recently from 9cf361d to 41827fb Compare June 2, 2025 19:34
Base automatically changed from WP-4593-add-bitgo-generate-wallet to master June 2, 2025 20:01
@mohammadalfaiyazbitgo mohammadalfaiyazbitgo force-pushed the WP-46222/add-api-ts branch 4 times, most recently from 8373ee9 to 72f943b Compare June 3, 2025 19:05
Copy link

Copilot AI left a 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.ts to use a spec-driven router and handlers (handlePingEnclavedExpress, handleGenerateWallet).
  • Add masterExpressApi.ts definitions and generate masterExpressApi.openapi.json.
  • Migrate on-prem wallet generation logic in generateWallet.ts and 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 enclavedPingResponse uses lowercase naming while other response types use PascalCase; consider renaming to EnclavedPingResponse for consistency.
export const enclavedPingResponse = t.type({

src/masterExpressApp.ts:166

  • New route handler handlePingEnclavedExpress lacks 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-generator which 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;
Copy link

Copilot AI Jun 3, 2025

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.

Suggested change
return result as unknown as WalletWithKeychains;
return result;

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@pranavjain97 pranavjain97 left a 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-----
Copy link
Contributor

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`)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update

Comment on lines 14 to 18
export type GenerateWalletOnPremParams = {
coin: string;
label: string;
enterprise?: string;
multisigType?: string;
isDistributedCustody?: boolean;
};
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bitGo,
bitgo,

};

return { ...result, wallet: result.wallet.toJSON() };
return result as unknown as WalletWithKeychains;
Copy link
Contributor

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 @@
{
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah

Comment on lines 82 to 87
// TODO: Fill out full response type
export const WalletGenerateRequest = {
label: t.string,
enterprise: t.string,
};
Copy link
Contributor

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?

Comment on lines 113 to 116
body: {
label: t.string,
enterprise: t.string,
},
Copy link
Contributor

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 ({
Copy link
Contributor

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?

Copy link
Contributor Author

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?

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo marked this pull request as draft June 4, 2025 15:38
auto-merge was automatically disabled June 4, 2025 15:38

Pull request was converted to draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants