SDK Server type revamp + wallet account creation helper#1225
SDK Server type revamp + wallet account creation helper#1225
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ce3d616:
|
b7cb610 to
7769ccd
Compare
5d51533 to
2f4d42d
Compare
| to: string; | ||
| caip2: string; | ||
| caip2: | ||
| | "eip155:1" |
There was a problem hiding this comment.
can we define this set as its own type? can help us DRY things up a bit. and if/when we do so, it might be useful to also add the plain english EVM network (e.g. mainnet, sepolia, etc)
There was a problem hiding this comment.
This is unfortunately a flaw with how the EthSendRawTransactionIntent proto is defined
Could try making an internal type for this case specifically though
There was a problem hiding this comment.
Pull request overview
This PR migrates @turnkey/sdk-server from its local generated API types to the shared @turnkey/sdk-types package, and adds a helper to generate wallet account creation params from address formats while avoiding path/index conflicts.
Changes:
- Switch
@turnkey/sdk-serverSDK client + public exports to use@turnkey/sdk-typesinstead ofsrc/__generated__/sdk_api_types.ts(which is removed). - Update
@turnkey/sdk-typescodegen to emit string literal unions for Swaggerenumfields (instead of plainstring). - Add
generateWalletAccountsFromAddressFormat,createWalletAccountFromAddressFormat, andaddressFormatConfigtosdk-server.
Reviewed changes
Copilot reviewed 12 out of 16 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds workspace link for @turnkey/sdk-types dependency. |
| packages/sdk-types/src/generated/types.ts | Regenerates types with enum-backed string literal unions (e.g., request type, CAIP-2 values). |
| packages/sdk-types/scripts/codegen.js | Updates swagger-to-TS mapping for string enums to emit "A" | "B" unions. |
| packages/sdk-server/src/turnkey-helpers.ts | Migrates helper types to @turnkey/sdk-types and adds wallet account generation helpers/config. |
| packages/sdk-server/src/index.ts | Swaps SDK API type imports to @turnkey/sdk-types and exports new helpers. |
| packages/sdk-server/src/types/base.ts | Replaces local HTTP-generated types with @turnkey/sdk-types (e.g., activity/user/email customization). |
| packages/sdk-server/src/generated/sdk_api_types.ts | Removes sdk-server’s locally generated API types file. |
| packages/sdk-server/src/generated/sdk-client-base.ts | Updates client base to reference @turnkey/sdk-types and internal base types. |
| packages/sdk-server/scripts/codegen.js | Stops generating sdk_api_types.ts; updates generated client imports to use @turnkey/sdk-types. |
| packages/sdk-server/package.json | Adds @turnkey/sdk-types dependency. |
| packages/sdk-react/src/components/auth/Auth.tsx | Casts customAccounts to v1WalletAccountParams[] for server calls after type migration. |
| packages/react-wallet-kit/src/providers/client/Provider.tsx | Casts caip2 to the narrowed union type when constructing EthTransaction. |
| packages/core/src/types/method-types/shared.ts | Narrows caip2 fields to specific supported CAIP-2 literal unions for ETH/Solana types. |
| .changeset/tall-olives-wonder.md | Declares @turnkey/sdk-types release for enum typing changes. |
| .changeset/metal-planets-tan.md | Declares @turnkey/sdk-server patch for the new wallet account helper. |
| .changeset/huge-sloths-dream.md | Declares @turnkey/sdk-server major for switching to @turnkey/sdk-types. |
Files not reviewed (4)
- packages/sdk-server/src/generated/sdk-client-base.ts: Language not supported
- packages/sdk-server/src/generated/sdk_api_types.ts: Language not supported
- packages/sdk-types/src/generated/types.ts: Language not supported
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| TurnkeyRequestError, | ||
| } from "./__types__/base"; |
| curve: "CURVE_SECP256K1", | ||
| pathFormat: "PATH_FORMAT_BIP32", | ||
| path: `m/44'/60'/${pathIndex}'/0/0`, | ||
| addressFormat: "ADDRESS_FORMAT_ETHEREUM", | ||
| }; | ||
| } as v1WalletAccount; |
| export const DEFAULT_XRP_ACCOUNTS: v1WalletAccountParams[] = [ | ||
| defaultXrpAccountAtIndex(0), | ||
| ]; |
| const walletAccount = addressFormatConfig[addressFormat]?.defaultAccounts; | ||
| if (!walletAccount) { | ||
| throw new Error(`Unsupported address format: ${addressFormat}`); | ||
| } | ||
|
|
||
| if (walletAccount[0]) { | ||
| return walletAccount[0]; | ||
| } | ||
|
|
||
| throw new Error( | ||
| `No default accounts defined for address format: ${addressFormat}`, | ||
| ); |
| * | ||
| * ```ts | ||
| * // Example usage: | ||
| * import { addressFormatConfig } from "@turnkey/sdk-core"; |
| "@turnkey/sdk-types": minor | ||
| --- | ||
|
|
||
| Fixed nested enums in types, now generates the enum values rather than generating them as strings |
.changeset/metal-planets-tan.md
Outdated
| "@turnkey/sdk-server": patch | ||
| --- | ||
|
|
||
| Added the `generateWalletAccountsFromAddressFormat` helper which takes in an array of address formats as well as an array of the current wallet accounts within the wallet and returns a list of path format deduped `WalletAccountParams` |
There was a problem hiding this comment.
returns a list of path format deduped
WalletAccountParams
can we generalize this and say
deduped `WalletAccountParams`
?
| export type EmailCustomization = TurnkeyApiTypes["v1EmailCustomizationParams"]; | ||
| /** @internal */ | ||
| export type TActivityStatus = v1ActivityStatus; | ||
| /** @internal */ |
There was a problem hiding this comment.
tiny nit: can we add a newline above just to keep spacing consistent?
alternatively, we can keep one /** @internal */, and have everything under it be implicitly internal (can have it apply to this whole section of exports)
There was a problem hiding this comment.
Unfortunately the JS docs only apply to the type below it 😞
| export type TActivityResponse = v1ActivityResponse; | ||
|
|
||
| /** @internal */ | ||
| export type TSignedRequest = { |
There was a problem hiding this comment.
I see some of these exports in packages/core/src as well; any plans to dedupe? perhaps by exporting from sdk-types?
There was a problem hiding this comment.
Good call out, can definitely move some these there
1f0493c to
583c8cb
Compare
…wapped out sdk-server's generated types for types found in sdk-types
…tyStatus out of core, now pulls from sdk-types
d1ed73a to
ce3d616
Compare
Summary & Motivation
@turnkey/sdk-serverhas been using its own generated types for the sdk client for a while, we've recently introduced a types package with readable generated types which we are switching@turnkey/sdk-serverover to.v1WalletAccountParamsfor easy wallet account generation.How I Tested These Changes
Did you add a changeset?