-
Notifications
You must be signed in to change notification settings - Fork 44
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
feat(PSDK-670): Support external wallet imports, wallet imports from CDP Python SDK #347
Changes from all commits
3691fc0
603df2d
3087585
3edd499
4b94116
6d6da23
d8de91c
fc7e978
026f9dd
3496294
283c81f
b0e08ab
460927b
5b1fdbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,7 +226,7 @@ export type WalletAPIClient = { | |
* List wallets belonging to the user. | ||
* | ||
* @param limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. | ||
* @param page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param page - A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param options - Override http request option. | ||
* @throws {APIError} If the request fails. | ||
* @throws {RequiredError} If the required parameter is not provided. | ||
|
@@ -358,7 +358,7 @@ export type AddressAPIClient = { | |
* @param walletId - The ID of the wallet the address belongs to. | ||
* @param addressId - The onchain address of the address to sign the payload with. | ||
* @param limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. | ||
* @param page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param page - A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param options - Axios request options. | ||
* @throws {APIError} If the request fails. | ||
*/ | ||
|
@@ -380,7 +380,7 @@ export type ExternalAddressAPIClient = { | |
* | ||
* @param networkId - The ID of the blockchain network | ||
* @param addressId - The ID of the address to fetch the balance for | ||
* @param page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param page - A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param options - Override http request option. | ||
* @throws {APIError} If the request fails. | ||
*/ | ||
|
@@ -812,14 +812,87 @@ export enum FundOperationStatus { | |
} | ||
|
||
/** | ||
* The Wallet Data type definition. | ||
* The data required to recreate a Wallet. | ||
* Interface representing wallet data, with support for both camelCase and snake_case | ||
* property names for compatibility with older versions of the Python SDK. | ||
*/ | ||
export type WalletData = { | ||
walletId: string; | ||
export interface WalletData { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious on reasoning to convert this from a |
||
/** | ||
* The CDP wallet ID in either camelCase or snake_case format, but not both. | ||
*/ | ||
walletId?: string; | ||
wallet_id?: string; | ||
Comment on lines
+819
to
+823
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One option to try to enforce mutual exclusivity is to use type WalletData = {
walletId: string;
wallet_id?: never;
} | {
walletId?: never;
wallet_id: string;
}
const walletData: WalletData = {
walletId: '123',
wallet_id: '123'
} Now TypeScript will error with a message:
Admittedly, the error message could be clearer, but it's difficult to customize the message without reaching for a type validation library like Zod, which might be overkill here. |
||
|
||
/** | ||
* The wallet seed | ||
*/ | ||
seed: string; | ||
|
||
/** | ||
* The network ID in either camelCase or snake_case format, but not both. | ||
*/ | ||
networkId?: string; | ||
}; | ||
network_id?: string; | ||
} | ||
|
||
/** | ||
* Type guard to check if data matches the appropriate WalletData format. | ||
* WalletData must have: | ||
* - exactly one of (walletId or wallet_id) | ||
* - at most one of (networkId or network_id) | ||
* - a seed | ||
* | ||
* @param data - The data to check | ||
* @returns True if data matches the appropriate WalletData format | ||
*/ | ||
export function isWalletData(data: unknown): data is WalletData { | ||
if (typeof data !== "object" || data === null) { | ||
return false; | ||
} | ||
|
||
const { walletId, wallet_id, networkId, network_id, seed } = data as WalletData; | ||
|
||
// Check that exactly one of walletId or wallet_id is present (but not both) | ||
const hasWalletId = typeof walletId === "string"; | ||
const hasWalletSnakeId = typeof wallet_id === "string"; | ||
if (!(hasWalletId !== hasWalletSnakeId)) { | ||
return false; | ||
} | ||
|
||
// Check that at most one of networkId or network_id is present (but not both) | ||
const hasNetworkId = typeof networkId === "string"; | ||
const hasNetworkSnakeId = typeof network_id === "string"; | ||
if (hasNetworkId && hasNetworkSnakeId) { | ||
return false; | ||
} | ||
|
||
// Check that seed is present and is a string | ||
return typeof seed === "string"; | ||
} | ||
|
||
/** | ||
* Interface representing a BIP-39 mnemonic seed phrase. | ||
*/ | ||
export interface MnemonicSeedPhrase { | ||
/** | ||
* The BIP-39 mnemonic seed phrase (12, 15, 18, 21, or 24 words) | ||
*/ | ||
mnemonicPhrase: string; | ||
} | ||
|
||
/** | ||
* Type guard to check if data matches the MnemonicSeedPhrase format. | ||
* | ||
* @param data - The data to check | ||
* @returns True if data matches the MnemonicSeedPhrase format | ||
*/ | ||
export function isMnemonicSeedPhrase(data: unknown): data is MnemonicSeedPhrase { | ||
if (typeof data !== "object" || data === null) { | ||
return false; | ||
} | ||
|
||
const { mnemonicPhrase } = data as MnemonicSeedPhrase; | ||
return typeof mnemonicPhrase === "string"; | ||
} | ||
|
||
/** | ||
* The Seed Data type definition. | ||
|
@@ -854,6 +927,7 @@ export enum ServerSignerStatus { | |
* Options for creating a Wallet. | ||
*/ | ||
export type WalletCreateOptions = { | ||
seed?: string; | ||
networkId?: string; | ||
timeoutSeconds?: number; | ||
intervalSeconds?: number; | ||
|
@@ -1147,7 +1221,7 @@ export interface WebhookApiClient { | |
* | ||
* @summary List webhooks | ||
* @param {number} [limit] - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. | ||
* @param {string} [page] - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param {string} [page] - A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param {*} [options] - Override http request option. | ||
* @throws {RequiredError} | ||
*/ | ||
|
@@ -1182,7 +1256,7 @@ export interface BalanceHistoryApiClient { | |
* @param addressId - The ID of the address to fetch the historical balance for. | ||
* @param assetId - The symbol of the asset to fetch the historical balance for. | ||
* @param limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. | ||
* @param page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param page - A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param options - Override http request option. | ||
* @throws {RequiredError} | ||
*/ | ||
|
@@ -1204,7 +1278,7 @@ export interface TransactionHistoryApiClient { | |
* @param networkId - The ID of the blockchain network | ||
* @param addressId - The ID of the address to fetch transactions for. | ||
* @param limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. | ||
* @param page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param page - A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param options - Override http request option. | ||
* @throws {RequiredError} | ||
*/ | ||
|
@@ -1446,7 +1520,7 @@ export interface FundOperationApiClient { | |
* @param walletId - The ID of the wallet the address belongs to. | ||
* @param addressId - The ID of the address to list fund operations for. | ||
* @param limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. | ||
* @param page - A cursor for pagination across multiple pages of results. Don\'t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param page - A cursor for pagination across multiple pages of results. Don't include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results. | ||
* @param options - Axios request options | ||
* @throws {APIError} If the request fails | ||
*/ | ||
|
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.
We'll move these around as we prep the release, but we'll have a separate heading for "Address" and "Deprecated"