From f34dc5e31417dd5241d520acfba4da298894095e Mon Sep 17 00:00:00 2001 From: Prithvish Baidya Date: Sat, 8 Feb 2025 07:04:48 +0530 Subject: [PATCH 1/4] build SDK --- sdk/src/Engine.ts | 3 + sdk/src/index.ts | 1 + sdk/src/services/BackendWalletService.ts | 24 ++-- sdk/src/services/ConfigurationService.ts | 24 +++- sdk/src/services/ContractEventsService.ts | 8 +- sdk/src/services/WalletCredentialsService.ts | 125 +++++++++++++++++++ sdk/src/services/WebhooksService.ts | 2 +- 7 files changed, 169 insertions(+), 18 deletions(-) create mode 100644 sdk/src/services/WalletCredentialsService.ts diff --git a/sdk/src/Engine.ts b/sdk/src/Engine.ts index 8a8e397a2..72dd69d95 100644 --- a/sdk/src/Engine.ts +++ b/sdk/src/Engine.ts @@ -30,6 +30,7 @@ import { MarketplaceOffersService } from './services/MarketplaceOffersService'; import { PermissionsService } from './services/PermissionsService'; import { RelayerService } from './services/RelayerService'; import { TransactionService } from './services/TransactionService'; +import { WalletCredentialsService } from './services/WalletCredentialsService'; import { WebhooksService } from './services/WebhooksService'; type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest; @@ -60,6 +61,7 @@ class EngineLogic { public readonly permissions: PermissionsService; public readonly relayer: RelayerService; public readonly transaction: TransactionService; + public readonly walletCredentials: WalletCredentialsService; public readonly webhooks: WebhooksService; public readonly request: BaseHttpRequest; @@ -101,6 +103,7 @@ class EngineLogic { this.permissions = new PermissionsService(this.request); this.relayer = new RelayerService(this.request); this.transaction = new TransactionService(this.request); + this.walletCredentials = new WalletCredentialsService(this.request); this.webhooks = new WebhooksService(this.request); } } diff --git a/sdk/src/index.ts b/sdk/src/index.ts index bb6705eab..9a6e7cda8 100644 --- a/sdk/src/index.ts +++ b/sdk/src/index.ts @@ -34,4 +34,5 @@ export { MarketplaceOffersService } from './services/MarketplaceOffersService'; export { PermissionsService } from './services/PermissionsService'; export { RelayerService } from './services/RelayerService'; export { TransactionService } from './services/TransactionService'; +export { WalletCredentialsService } from './services/WalletCredentialsService'; export { WebhooksService } from './services/WebhooksService'; diff --git a/sdk/src/services/BackendWalletService.ts b/sdk/src/services/BackendWalletService.ts index 7c25b097f..9be834083 100644 --- a/sdk/src/services/BackendWalletService.ts +++ b/sdk/src/services/BackendWalletService.ts @@ -17,13 +17,19 @@ export class BackendWalletService { * @throws ApiError */ public create( - requestBody?: { + requestBody?: ({ label?: string; + type?: ('local' | 'aws-kms' | 'gcp-kms' | 'smart:aws-kms' | 'smart:gcp-kms' | 'smart:local'); + } | { + label?: string; + type: ('circle' | 'smart:circle'); /** - * Type of new wallet to create. It is recommended to always provide this value. If not provided, the default wallet type will be used. + * If your engine is configured with a testnet API Key for Circle, you can only create testnet wallets and send testnet transactions. Enable this field for testnet wallets. NOTE: A production API Key cannot be used for testnet transactions, and a testnet API Key cannot be used for production transactions. See: https://developers.circle.com/w3s/sandbox-vs-production */ - type?: ('local' | 'aws-kms' | 'gcp-kms' | 'smart:aws-kms' | 'smart:gcp-kms' | 'smart:local'); - }, + isTestnet?: boolean; + credentialId: string; + walletSetId?: string; + }), ): CancelablePromise<{ result: { /** @@ -31,7 +37,7 @@ export class BackendWalletService { */ walletAddress: string; status: string; - type: ('local' | 'aws-kms' | 'gcp-kms' | 'smart:aws-kms' | 'smart:gcp-kms' | 'smart:local'); + type: ('local' | 'aws-kms' | 'gcp-kms' | 'smart:aws-kms' | 'smart:gcp-kms' | 'smart:local' | 'circle' | 'smart:circle'); }; }> { return this.httpRequest.request({ @@ -721,7 +727,7 @@ export class BackendWalletService { gasPrice?: string; data?: string; value?: string; - chainId?: number; + chainId: number; type?: number; accessList?: any; maxFeePerGas?: string; @@ -1032,7 +1038,7 @@ export class BackendWalletService { * @throws ApiError */ public resetNonces( - requestBody?: { + requestBody: { /** * The chain ID to reset nonces for. */ @@ -1041,6 +1047,10 @@ export class BackendWalletService { * The backend wallet address to reset nonces for. Omit to reset all backend wallets. */ walletAddress?: string; + /** + * Resync nonces to match the onchain transaction count for your backend wallets. (Default: true) + */ + syncOnchainNonces: boolean; }, ): CancelablePromise<{ result: { diff --git a/sdk/src/services/ConfigurationService.ts b/sdk/src/services/ConfigurationService.ts index 57b32942e..40de38b91 100644 --- a/sdk/src/services/ConfigurationService.ts +++ b/sdk/src/services/ConfigurationService.ts @@ -17,7 +17,7 @@ export class ConfigurationService { */ public getWalletsConfiguration(): CancelablePromise<{ result: { - type: ('local' | 'aws-kms' | 'gcp-kms' | 'smart:aws-kms' | 'smart:gcp-kms' | 'smart:local'); + type: ('local' | 'aws-kms' | 'gcp-kms' | 'smart:aws-kms' | 'smart:gcp-kms' | 'smart:local' | 'circle' | 'smart:circle'); awsAccessKeyId: (string | null); awsRegion: (string | null); gcpApplicationProjectId: (string | null); @@ -55,10 +55,12 @@ export class ConfigurationService { gcpKmsKeyRingId: string; gcpApplicationCredentialEmail: string; gcpApplicationCredentialPrivateKey: string; + } | { + circleApiKey: string; }), ): CancelablePromise<{ result: { - type: ('local' | 'aws-kms' | 'gcp-kms' | 'smart:aws-kms' | 'smart:gcp-kms' | 'smart:local'); + type: ('local' | 'aws-kms' | 'gcp-kms' | 'smart:aws-kms' | 'smart:gcp-kms' | 'smart:local' | 'circle' | 'smart:circle'); awsAccessKeyId: (string | null); awsRegion: (string | null); gcpApplicationProjectId: (string | null); @@ -329,7 +331,8 @@ export class ConfigurationService { */ public getAuthConfiguration(): CancelablePromise<{ result: { - domain: string; + authDomain: string; + mtlsCertificate: (string | null); }; }> { return this.httpRequest.request({ @@ -351,12 +354,21 @@ export class ConfigurationService { * @throws ApiError */ public updateAuthConfiguration( - requestBody: { - domain: string; + requestBody?: { + authDomain?: string; + /** + * Engine certificate used for outbound mTLS requests. Must provide the full certificate chain. + */ + mtlsCertificate?: string; + /** + * Engine private key used for outbound mTLS requests. + */ + mtlsPrivateKey?: string; }, ): CancelablePromise<{ result: { - domain: string; + authDomain: string; + mtlsCertificate: (string | null); }; }> { return this.httpRequest.request({ diff --git a/sdk/src/services/ContractEventsService.ts b/sdk/src/services/ContractEventsService.ts index a15c9eab8..d799dd2ec 100644 --- a/sdk/src/services/ContractEventsService.ts +++ b/sdk/src/services/ContractEventsService.ts @@ -23,8 +23,8 @@ export class ContractEventsService { public getAllEvents( chain: string, contractAddress: string, - fromBlock?: (number | string), - toBlock?: (number | string), + fromBlock?: (number | 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'), + toBlock?: (number | 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'), order?: ('asc' | 'desc'), ): CancelablePromise<{ result: Array>; @@ -63,8 +63,8 @@ export class ContractEventsService { contractAddress: string, requestBody: { eventName: string; - fromBlock?: (number | string); - toBlock?: (number | string); + fromBlock?: (number | 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'); + toBlock?: (number | 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'); order?: ('asc' | 'desc'); filters?: any; }, diff --git a/sdk/src/services/WalletCredentialsService.ts b/sdk/src/services/WalletCredentialsService.ts new file mode 100644 index 000000000..1ac32e4ab --- /dev/null +++ b/sdk/src/services/WalletCredentialsService.ts @@ -0,0 +1,125 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { CancelablePromise } from '../core/CancelablePromise'; +import type { BaseHttpRequest } from '../core/BaseHttpRequest'; + +export class WalletCredentialsService { + + constructor(public readonly httpRequest: BaseHttpRequest) {} + + /** + * Create wallet credentials + * Create a new set of wallet credentials. + * @param requestBody + * @returns any Default Response + * @throws ApiError + */ + public createWalletCredential( + requestBody: { + label: string; + type: 'circle'; + /** + * 32-byte hex string. If not provided, a random one will be generated. + */ + entitySecret?: string; + /** + * Whether this credential should be set as the default for its type. Only one credential can be default per type. + */ + isDefault?: boolean; + }, + ): CancelablePromise<{ + result: { + id: string; + type: string; + label: string; + isDefault: (boolean | null); + createdAt: string; + updatedAt: string; + }; + }> { + return this.httpRequest.request({ + method: 'POST', + url: '/wallet-credentials', + body: requestBody, + mediaType: 'application/json', + errors: { + 400: `Bad Request`, + 404: `Not Found`, + 500: `Internal Server Error`, + }, + }); + } + + /** + * Get all wallet credentials + * Get all wallet credentials with pagination. + * @param page Specify the page number. + * @param limit Specify the number of results to return per page. + * @returns any Default Response + * @throws ApiError + */ + public getAllWalletCredentials( + page: number = 1, + limit: number = 100, + ): CancelablePromise<{ + result: Array<{ + id: string; + type: string; + label: (string | null); + isDefault: (boolean | null); + createdAt: string; + updatedAt: string; + }>; + }> { + return this.httpRequest.request({ + method: 'GET', + url: '/wallet-credentials', + query: { + 'page': page, + 'limit': limit, + }, + errors: { + 400: `Bad Request`, + 404: `Not Found`, + 500: `Internal Server Error`, + }, + }); + } + + /** + * Get wallet credential + * Get a wallet credential by ID. + * @param id The ID of the wallet credential to get. + * @returns any Default Response + * @throws ApiError + */ + public getWalletCredential( + id: string, + ): CancelablePromise<{ + result: { + id: string; + type: string; + label: (string | null); + isDefault: boolean; + createdAt: string; + updatedAt: string; + deletedAt: (string | null); + }; + }> { + return this.httpRequest.request({ + method: 'GET', + url: '/wallet-credentials/{id}', + path: { + 'id': id, + }, + errors: { + 400: `Bad Request`, + 404: `Not Found`, + 500: `Internal Server Error`, + }, + }); + } + +} diff --git a/sdk/src/services/WebhooksService.ts b/sdk/src/services/WebhooksService.ts index 88604c53b..5e6a0b90a 100644 --- a/sdk/src/services/WebhooksService.ts +++ b/sdk/src/services/WebhooksService.ts @@ -38,7 +38,7 @@ export class WebhooksService { } /** - * Create a webhook + * Create webhook * Create a webhook to call when a specific Engine event occurs. * @param requestBody * @returns any Default Response From 7565b59582b0543a65b1b0136c3f00b3d1a3303c Mon Sep 17 00:00:00 2001 From: Prithvish Baidya Date: Sat, 8 Feb 2025 07:04:53 +0530 Subject: [PATCH 2/4] bump SDK --- sdk/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/package.json b/sdk/package.json index 19a522e9d..5cc6fa596 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@thirdweb-dev/engine", - "version": "0.0.18", + "version": "0.0.19", "main": "dist/thirdweb-dev-engine.cjs.js", "module": "dist/thirdweb-dev-engine.esm.js", "files": [ From 9a945db9a9ce14d201ca96f888be142ca133cad0 Mon Sep 17 00:00:00 2001 From: Prithvish Baidya Date: Sat, 8 Feb 2025 07:04:57 +0530 Subject: [PATCH 3/4] feature flag --- src/server/routes/system/health.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server/routes/system/health.ts b/src/server/routes/system/health.ts index 23672c92f..9a79eff09 100644 --- a/src/server/routes/system/health.ts +++ b/src/server/routes/system/health.ts @@ -12,7 +12,8 @@ type EngineFeature = | "CONTRACT_SUBSCRIPTIONS" | "IP_ALLOWLIST" | "HETEROGENEOUS_WALLET_TYPES" - | "SMART_BACKEND_WALLETS"; + | "SMART_BACKEND_WALLETS" + | "CREDENTIALS"; const ReplySchemaOk = Type.Object({ status: Type.String(), @@ -25,6 +26,7 @@ const ReplySchemaOk = Type.Object({ Type.Literal("IP_ALLOWLIST"), Type.Literal("HETEROGENEOUS_WALLET_TYPES"), Type.Literal("SMART_BACKEND_WALLETS"), + Type.Literal("CREDENTIALS"), ]), ), clientId: Type.String(), @@ -89,6 +91,7 @@ const getFeatures = (): EngineFeature[] => { "HETEROGENEOUS_WALLET_TYPES", "CONTRACT_SUBSCRIPTIONS", "SMART_BACKEND_WALLETS", + "CREDENTIALS", ]; if (env.ENABLE_KEYPAIR_AUTH) features.push("KEYPAIR_AUTH"); From 5e17231698167c15789aa55e70460d102ab729a6 Mon Sep 17 00:00:00 2001 From: Prithvish Baidya Date: Sat, 8 Feb 2025 07:20:33 +0530 Subject: [PATCH 4/4] update flag name --- src/server/routes/system/health.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server/routes/system/health.ts b/src/server/routes/system/health.ts index 9a79eff09..970c07954 100644 --- a/src/server/routes/system/health.ts +++ b/src/server/routes/system/health.ts @@ -13,7 +13,7 @@ type EngineFeature = | "IP_ALLOWLIST" | "HETEROGENEOUS_WALLET_TYPES" | "SMART_BACKEND_WALLETS" - | "CREDENTIALS"; + | "WALLET_CREDENTIALS"; const ReplySchemaOk = Type.Object({ status: Type.String(), @@ -26,7 +26,7 @@ const ReplySchemaOk = Type.Object({ Type.Literal("IP_ALLOWLIST"), Type.Literal("HETEROGENEOUS_WALLET_TYPES"), Type.Literal("SMART_BACKEND_WALLETS"), - Type.Literal("CREDENTIALS"), + Type.Literal("WALLET_CREDENTIALS"), ]), ), clientId: Type.String(), @@ -91,7 +91,7 @@ const getFeatures = (): EngineFeature[] => { "HETEROGENEOUS_WALLET_TYPES", "CONTRACT_SUBSCRIPTIONS", "SMART_BACKEND_WALLETS", - "CREDENTIALS", + "WALLET_CREDENTIALS", ]; if (env.ENABLE_KEYPAIR_AUTH) features.push("KEYPAIR_AUTH");