@otim/sdk-server 0.0.3 → 0.0.4-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +16 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -46
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +14 -46
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +14 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -5
- package/dist/.tsbuildinfo +0 -1
package/dist/index.cjs
CHANGED
|
@@ -86,12 +86,13 @@ function _defineProperty(e, r, t) {
|
|
|
86
86
|
|
|
87
87
|
//#endregion
|
|
88
88
|
//#region src/client/server-account.ts
|
|
89
|
+
const TURNKEY_API_URL = "https://api.turnkey.com";
|
|
89
90
|
const createApiAccount = async (config) => {
|
|
90
91
|
const stamper = new __turnkey_api_key_stamper.ApiKeyStamper({
|
|
91
92
|
apiPublicKey: config.publicKey,
|
|
92
93
|
apiPrivateKey: config.privateKey
|
|
93
94
|
});
|
|
94
|
-
const client = new __turnkey_http.TurnkeyClient({ baseUrl:
|
|
95
|
+
const client = new __turnkey_http.TurnkeyClient({ baseUrl: TURNKEY_API_URL }, stamper);
|
|
95
96
|
const account = await (0, __turnkey_viem.createAccount)({
|
|
96
97
|
organizationId: config.appId,
|
|
97
98
|
signWith: "0xB54c8E6f303627f392884412ED2C84fFaF4779CA",
|
|
@@ -185,20 +186,24 @@ var OtimServerClient = class {
|
|
|
185
186
|
//#endregion
|
|
186
187
|
//#region src/client/create-server-client.ts
|
|
187
188
|
function createOtimServerClient(config) {
|
|
188
|
-
if (config.
|
|
189
|
+
if (config.chains.length === 0) throw new Error("At least one chain must be provided");
|
|
190
|
+
if ("appId" in config && config.publicKey && config.apiKey) return new OtimServerClient({
|
|
189
191
|
type: __otim_sdk_core_account.ServerAccountType.Api,
|
|
190
192
|
appId: config.appId,
|
|
191
193
|
privateKey: config.privateKey,
|
|
192
194
|
publicKey: config.publicKey,
|
|
193
195
|
apiKey: config.apiKey,
|
|
194
|
-
environment: config.environment
|
|
196
|
+
environment: config.environment,
|
|
197
|
+
chains: config.chains,
|
|
198
|
+
defaultChain: config.defaultChain
|
|
195
199
|
});
|
|
196
|
-
|
|
200
|
+
return new OtimServerClient({
|
|
197
201
|
type: __otim_sdk_core_account.ServerAccountType.PrivateKey,
|
|
198
202
|
privateKey: config.privateKey,
|
|
199
|
-
environment: config.environment
|
|
203
|
+
environment: config.environment,
|
|
204
|
+
chains: config.chains,
|
|
205
|
+
defaultChain: config.defaultChain
|
|
200
206
|
});
|
|
201
|
-
throw new Error("Invalid Otim Server Client configuration");
|
|
202
207
|
}
|
|
203
208
|
|
|
204
209
|
//#endregion
|
|
@@ -239,17 +244,17 @@ Object.defineProperty(exports, 'OrchestrationClient', {
|
|
|
239
244
|
}
|
|
240
245
|
});
|
|
241
246
|
exports.OtimServerClient = OtimServerClient;
|
|
242
|
-
Object.defineProperty(exports, '
|
|
247
|
+
Object.defineProperty(exports, 'chains', {
|
|
243
248
|
enumerable: true,
|
|
244
249
|
get: function () {
|
|
245
|
-
return
|
|
250
|
+
return __otim_utils_chains.allSupportedChains;
|
|
246
251
|
}
|
|
247
252
|
});
|
|
248
|
-
|
|
253
|
+
exports.createOtimServerClient = createOtimServerClient;
|
|
254
|
+
Object.defineProperty(exports, 'preparePaymentRequest', {
|
|
249
255
|
enumerable: true,
|
|
250
256
|
get: function () {
|
|
251
|
-
return
|
|
257
|
+
return __otim_sdk_core_clients.preparePaymentRequest;
|
|
252
258
|
}
|
|
253
259
|
});
|
|
254
|
-
exports.createOtimServerClient = createOtimServerClient;
|
|
255
260
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Environment","APIClient","ApiKeyStamper","TurnkeyClient","env","ServerAccountType","exhaustiveCheck: never","config: ServerAccountConfig","ActivityClient","AuthClient","ConfigClient","DelegationClient","OrchestrationClient","ServerAccountType"],"sources":["../src/client/api-client.ts","../src/client/utils/asserts.ts","../src/client/server-account.ts","../src/client/server-client.ts","../src/client/create-server-client.ts"],"sourcesContent":["import type { CreateInstanceParameters } from \"@otim/utils/api\";\nimport type { Optional } from \"@otim/utils/helpers\";\n\nimport { Environment, getApiUrl } from \"@otim/sdk-core/config\";\nimport { APIClient, createInstance } from \"@otim/utils/api\";\n\nexport interface CreateServerAPIClientOptions\n extends Omit<CreateInstanceParameters, \"baseURL\"> {\n sessionToken?: Optional<string>;\n environment?: Environment;\n}\n\n/**\n * Creates an API client for server-side requests.\n *\n * Configures the base URL and authentication headers for API communication.\n *\n * @param config - Optional configuration for the API client\n * @returns Configured API client instance\n *\n * @internal\n */\nexport const createServerAPIClient = (\n config?: CreateServerAPIClientOptions,\n) => {\n const {\n sessionToken,\n environment = Environment.Sandbox,\n ...restConfig\n } = config ?? {};\n\n const instance = createInstance({\n baseURL: getApiUrl(environment),\n ...restConfig,\n });\n\n instance.interceptors.request.use(async (requestConfig) => {\n if (sessionToken) {\n requestConfig.headers = requestConfig.headers ?? {};\n\n // If the session token does not start with \"Bearer \", add it.\n const authorizationToken = sessionToken.startsWith(\"Bearer \")\n ? sessionToken\n : `Bearer ${sessionToken}`;\n\n requestConfig.headers.Authorization = authorizationToken;\n }\n\n return requestConfig;\n });\n\n return new APIClient({ instance });\n};\n","export function assertDefined<T>(\n value: T,\n errorMessage: string,\n): asserts value is NonNullable<T> {\n if (value === null || value === undefined) {\n throw new Error(errorMessage);\n }\n}\n","import type {\n ApiAccountConfig,\n OtimAccountSignMessageArgs,\n OtimAccount as OtimAccountType,\n PrivateKeyAccountConfig,\n ServerAccountConfig,\n} from \"@otim/sdk-core/account\";\nimport type { Nullable } from \"@otim/utils/helpers\";\nimport type { Hex } from \"viem\";\n\nimport { ServerAccountType } from \"@otim/sdk-core/account\";\nimport { env, getTurnkeyApiUrl } from \"@otim/sdk-core/config\";\nimport { ApiKeyStamper } from \"@turnkey/api-key-stamper\";\nimport { TurnkeyClient } from \"@turnkey/http\";\nimport { createAccount } from \"@turnkey/viem\";\nimport { privateKeyToAccount } from \"viem/accounts\";\n\nimport { assertDefined } from \"./utils/asserts\";\n\ntype PrimitiveAccount = {\n signMessage: (args: {\n message: string | { raw: Hex | Uint8Array };\n }) => Promise<Hex>;\n};\n\nconst createApiAccount = async (\n config: ApiAccountConfig,\n): Promise<PrimitiveAccount> => {\n const stamper = new ApiKeyStamper({\n apiPublicKey: config.publicKey,\n apiPrivateKey: config.privateKey,\n });\n\n const client = new TurnkeyClient(\n {\n baseUrl: getTurnkeyApiUrl(env.ENVIRONMENT),\n },\n stamper,\n );\n\n const account = await createAccount({\n organizationId: config.appId,\n signWith: \"0xB54c8E6f303627f392884412ED2C84fFaF4779CA\",\n client,\n });\n\n return {\n signMessage: (args) => account.signMessage(args),\n };\n};\n\nconst createPrivateKeyAccount = (\n config: PrivateKeyAccountConfig,\n): PrimitiveAccount => {\n const account = privateKeyToAccount(config.privateKey);\n\n return {\n signMessage: (args) => account.signMessage(args),\n };\n};\n\nconst initializeAccount = async (\n config: ServerAccountConfig,\n): Promise<PrimitiveAccount> => {\n switch (config.type) {\n case ServerAccountType.Api:\n return createApiAccount(config);\n case ServerAccountType.PrivateKey:\n return createPrivateKeyAccount(config);\n default: {\n const exhaustiveCheck: never = config;\n throw new Error(\n `Unsupported account type: \"${(exhaustiveCheck as ServerAccountConfig).type}\". Supported types are: ${Object.values(ServerAccountType).join(\", \")}`,\n );\n }\n }\n};\n\n/**\n * Server-side account implementation for signing operations.\n *\n * Supports both private key and API authentication methods.\n *\n * @internal\n */\nexport class OtimAccount implements OtimAccountType {\n private account: Nullable<PrimitiveAccount> = null;\n private initialized = false;\n\n constructor(private readonly config: ServerAccountConfig) {}\n\n async initialize(): Promise<void> {\n if (this.initialized) {\n throw new Error(\n \"Account already initialized. The initialize() method should only be called once.\",\n );\n }\n\n this.account = await initializeAccount(this.config);\n this.initialized = true;\n }\n\n async signMessage({ message }: OtimAccountSignMessageArgs) {\n assertDefined(\n this.account,\n \"Account not initialized. Call initialize() before using signMessage().\",\n );\n return this.account.signMessage({ message });\n }\n}\n","import type { ServerAccountConfig } from \"@otim/sdk-core/account\";\nimport type { OtimServerClientContext } from \"@otim/sdk-core/context\";\nimport type { APIClient } from \"@otim/utils/api\";\n\nimport {\n createClientContext,\n isApiAccountConfig,\n} from \"@otim/sdk-core/account\";\nimport {\n ActivityClient,\n AuthClient,\n ConfigClient,\n DelegationClient,\n OrchestrationClient,\n} from \"@otim/sdk-core/clients\";\n\nimport { createServerAPIClient } from \"./api-client\";\nimport { OtimAccount } from \"./server-account\";\n\n/**\n * Otim Client for server-side blockchain operations.\n *\n * Provides access to activity, authentication, configuration, delegation, and\n * orchestration services.\n * The client must be initialized before use by calling the init() method.\n\n */\nexport class OtimServerClient {\n private readonly apiClient: APIClient;\n private readonly account: OtimAccount;\n private readonly context: OtimServerClientContext;\n\n readonly activity: ActivityClient;\n readonly auth: AuthClient;\n readonly config: ConfigClient;\n readonly delegation: DelegationClient;\n readonly orchestration: OrchestrationClient;\n\n constructor(config: ServerAccountConfig) {\n this.context = createClientContext(config);\n this.apiClient = createServerAPIClient({\n environment: config.environment,\n ...(isApiAccountConfig(config) ? { sessionToken: config.apiKey } : {}),\n });\n\n this.account = new OtimAccount(config);\n\n this.activity = new ActivityClient(this.apiClient);\n this.auth = new AuthClient(this.apiClient, this.account, this.context);\n this.config = new ConfigClient(this.apiClient);\n this.delegation = new DelegationClient(this.apiClient);\n this.orchestration = new OrchestrationClient(\n this.apiClient,\n this.account,\n this.context,\n );\n }\n\n /**\n * Initializes the Otim Client.\n *\n * This method must be called before using any other client methods.\n * It sets up the authentication account and prepares the client for use.\n *\n * @throws {Error} If the account is already initialized\n */\n async init(): Promise<void> {\n await this.account.initialize();\n }\n}\n","import type { Environment } from \"@otim/sdk-core/config\";\n\nimport { ServerAccountType } from \"@otim/sdk-core/account\";\n\nimport { OtimServerClient } from \"./server-client\";\n\n/**\n * Creates an Otim Client for server-side blockchain operations.\n *\n * @param config - Configuration with private key only\n * @returns Configured Otim Client instance\n *\n * @example\n * ```typescript\n * import { Environment } from '@otim/sdk';\n *\n * const client = createOtimServerClient({\n * privateKey: '0x...',\n * environment: Environment.Production,\n * });\n * await client.init();\n * ```\n */\nexport function createOtimServerClient(config: {\n privateKey: `0x${string}`;\n environment?: Environment;\n}): OtimServerClient;\n\n/**\n * Creates an Otim Client for server-side operations with API authentication.\n *\n * @param config - Configuration with API credentials\n * @returns Configured Otim Client instance\n *\n * @example\n * ```typescript\n * import { Environment } from '@otim/sdk';\n *\n * const client = createOtimServerClient({\n * appId: 'your-app-id',\n * privateKey: '0x...',\n * publicKey: 'your-public-key',\n * apiKey: 'your-api-key',\n * environment: Environment.Production,\n * });\n * await client.init();\n * ```\n */\nexport function createOtimServerClient(config: {\n appId: string;\n privateKey: `0x${string}`;\n publicKey: string;\n apiKey?: string;\n environment?: Environment;\n}): OtimServerClient;\n\nexport function createOtimServerClient(config: {\n privateKey?: `0x${string}`;\n publicKey?: string;\n apiKey?: string;\n appId?: string;\n environment?: Environment;\n}): OtimServerClient {\n if (config.appId && config.privateKey && config.publicKey && config.apiKey) {\n return new OtimServerClient({\n type: ServerAccountType.Api,\n appId: config.appId,\n privateKey: config.privateKey,\n publicKey: config.publicKey,\n apiKey: config.apiKey,\n environment: config.environment,\n });\n }\n\n if (config.privateKey) {\n return new OtimServerClient({\n type: ServerAccountType.PrivateKey,\n privateKey: config.privateKey,\n environment: config.environment,\n });\n }\n\n throw new Error(\"Invalid Otim Server Client configuration\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,yBACX,WACG;CACH,MAAM,EACJ,cACA,cAAcA,mCAAY,SAC1B,GAAG,eACD,UAAU,EAAE;CAEhB,MAAM,gDAA0B;EAC9B,+CAAmB,YAAY;EAC/B,GAAG;EACJ,CAAC;AAEF,UAAS,aAAa,QAAQ,I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2CAA2C"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Environment","APIClient","ApiKeyStamper","TurnkeyClient","ServerAccountType","exhaustiveCheck: never","config: ServerAccountConfig","ActivityClient","AuthClient","ConfigClient","DelegationClient","OrchestrationClient","ServerAccountType"],"sources":["../src/client/api-client.ts","../src/client/utils/asserts.ts","../src/client/server-account.ts","../src/client/server-client.ts","../src/client/create-server-client.ts"],"sourcesContent":["import type { CreateInstanceParameters } from \"@otim/utils/api\";\nimport type { Optional } from \"@otim/utils/helpers\";\n\nimport { Environment, getApiUrl } from \"@otim/sdk-core/config\";\nimport { APIClient, createInstance } from \"@otim/utils/api\";\n\nexport interface CreateServerAPIClientOptions\n extends Omit<CreateInstanceParameters, \"baseURL\"> {\n sessionToken?: Optional<string>;\n environment?: Environment;\n}\n\n/**\n * Creates an API client for server-side requests.\n *\n * Configures the base URL and authentication headers for API communication.\n *\n * @param config - Optional configuration for the API client\n * @returns Configured API client instance\n *\n * @internal\n */\nexport const createServerAPIClient = (\n config?: CreateServerAPIClientOptions,\n) => {\n const {\n sessionToken,\n environment = Environment.Sandbox,\n ...restConfig\n } = config ?? {};\n\n const instance = createInstance({\n baseURL: getApiUrl(environment),\n ...restConfig,\n });\n\n instance.interceptors.request.use(async (requestConfig) => {\n if (sessionToken) {\n requestConfig.headers = requestConfig.headers ?? {};\n\n // If the session token does not start with \"Bearer \", add it.\n const authorizationToken = sessionToken.startsWith(\"Bearer \")\n ? sessionToken\n : `Bearer ${sessionToken}`;\n\n requestConfig.headers.Authorization = authorizationToken;\n }\n\n return requestConfig;\n });\n\n return new APIClient({ instance });\n};\n","export function assertDefined<T>(\n value: T,\n errorMessage: string,\n): asserts value is NonNullable<T> {\n if (value === null || value === undefined) {\n throw new Error(errorMessage);\n }\n}\n","import type {\n ApiAccountConfig,\n OtimAccountSignMessageArgs,\n OtimAccount as OtimAccountType,\n PrivateKeyAccountConfig,\n ServerAccountConfig,\n} from \"@otim/sdk-core/account\";\nimport type { Nullable } from \"@otim/utils/helpers\";\nimport type { Hex } from \"viem\";\n\nimport { ServerAccountType } from \"@otim/sdk-core/account\";\nimport { ApiKeyStamper } from \"@turnkey/api-key-stamper\";\nimport { TurnkeyClient } from \"@turnkey/http\";\nimport { createAccount } from \"@turnkey/viem\";\nimport { privateKeyToAccount } from \"viem/accounts\";\n\nimport { assertDefined } from \"./utils/asserts\";\n\nconst TURNKEY_API_URL = \"https://api.turnkey.com\";\n\ntype PrimitiveAccount = {\n signMessage: (args: {\n message: string | { raw: Hex | Uint8Array };\n }) => Promise<Hex>;\n};\n\nconst createApiAccount = async (\n config: ApiAccountConfig,\n): Promise<PrimitiveAccount> => {\n const stamper = new ApiKeyStamper({\n apiPublicKey: config.publicKey,\n apiPrivateKey: config.privateKey,\n });\n\n const client = new TurnkeyClient({ baseUrl: TURNKEY_API_URL }, stamper);\n\n const account = await createAccount({\n organizationId: config.appId,\n signWith: \"0xB54c8E6f303627f392884412ED2C84fFaF4779CA\",\n client,\n });\n\n return {\n signMessage: (args) => account.signMessage(args),\n };\n};\n\nconst createPrivateKeyAccount = (\n config: PrivateKeyAccountConfig,\n): PrimitiveAccount => {\n const account = privateKeyToAccount(config.privateKey);\n\n return {\n signMessage: (args) => account.signMessage(args),\n };\n};\n\nconst initializeAccount = async (\n config: ServerAccountConfig,\n): Promise<PrimitiveAccount> => {\n switch (config.type) {\n case ServerAccountType.Api:\n return createApiAccount(config);\n case ServerAccountType.PrivateKey:\n return createPrivateKeyAccount(config);\n default: {\n const exhaustiveCheck: never = config;\n throw new Error(\n `Unsupported account type: \"${(exhaustiveCheck as ServerAccountConfig).type}\". Supported types are: ${Object.values(ServerAccountType).join(\", \")}`,\n );\n }\n }\n};\n\n/**\n * Server-side account implementation for signing operations.\n *\n * Supports both private key and API authentication methods.\n *\n * @internal\n */\nexport class OtimAccount implements OtimAccountType {\n private account: Nullable<PrimitiveAccount> = null;\n private initialized = false;\n\n constructor(private readonly config: ServerAccountConfig) {}\n\n async initialize(): Promise<void> {\n if (this.initialized) {\n throw new Error(\n \"Account already initialized. The initialize() method should only be called once.\",\n );\n }\n\n this.account = await initializeAccount(this.config);\n this.initialized = true;\n }\n\n async signMessage({ message }: OtimAccountSignMessageArgs) {\n assertDefined(\n this.account,\n \"Account not initialized. Call initialize() before using signMessage().\",\n );\n return this.account.signMessage({ message });\n }\n}\n","import type { ServerAccountConfig } from \"@otim/sdk-core/account\";\nimport type { OtimServerClientContext } from \"@otim/sdk-core/context\";\nimport type { APIClient } from \"@otim/utils/api\";\n\nimport {\n createClientContext,\n isApiAccountConfig,\n} from \"@otim/sdk-core/account\";\nimport {\n ActivityClient,\n AuthClient,\n ConfigClient,\n DelegationClient,\n OrchestrationClient,\n} from \"@otim/sdk-core/clients\";\n\nimport { createServerAPIClient } from \"./api-client\";\nimport { OtimAccount } from \"./server-account\";\n\n/**\n * Otim Client for server-side blockchain operations.\n *\n * Provides access to activity, authentication, configuration, delegation, and\n * orchestration services.\n * The client must be initialized before use by calling the init() method.\n\n */\nexport class OtimServerClient {\n private readonly apiClient: APIClient;\n private readonly account: OtimAccount;\n private readonly context: OtimServerClientContext;\n\n readonly activity: ActivityClient;\n readonly auth: AuthClient;\n readonly config: ConfigClient;\n readonly delegation: DelegationClient;\n readonly orchestration: OrchestrationClient;\n\n constructor(config: ServerAccountConfig) {\n this.context = createClientContext(config);\n this.apiClient = createServerAPIClient({\n environment: config.environment,\n ...(isApiAccountConfig(config) ? { sessionToken: config.apiKey } : {}),\n });\n\n this.account = new OtimAccount(config);\n\n this.activity = new ActivityClient(this.apiClient);\n this.auth = new AuthClient(this.apiClient, this.account, this.context);\n this.config = new ConfigClient(this.apiClient);\n this.delegation = new DelegationClient(this.apiClient);\n this.orchestration = new OrchestrationClient(\n this.apiClient,\n this.account,\n this.context,\n );\n }\n\n /**\n * Initializes the Otim Client.\n *\n * This method must be called before using any other client methods.\n * It sets up the authentication account and prepares the client for use.\n *\n * @throws {Error} If the account is already initialized\n */\n async init(): Promise<void> {\n await this.account.initialize();\n }\n}\n","import type { Chain } from \"@otim/sdk-core/account\";\nimport type { Environment } from \"@otim/sdk-core/config\";\n\nimport { ServerAccountType } from \"@otim/sdk-core/account\";\n\nimport { OtimServerClient } from \"./server-client\";\n\ninterface BaseClientConfig {\n environment?: Environment;\n chains: Chain[];\n defaultChain?: Chain;\n}\n\ninterface PrivateKeyClientConfig extends BaseClientConfig {\n privateKey: `0x${string}`;\n}\n\ninterface ApiClientConfig extends BaseClientConfig {\n appId: string;\n privateKey: `0x${string}`;\n publicKey: string;\n apiKey?: string;\n}\n\nexport function createOtimServerClient(\n config: PrivateKeyClientConfig,\n): OtimServerClient;\nexport function createOtimServerClient(\n config: ApiClientConfig,\n): OtimServerClient;\nexport function createOtimServerClient(\n config: PrivateKeyClientConfig | ApiClientConfig,\n): OtimServerClient {\n if (config.chains.length === 0) {\n throw new Error(\"At least one chain must be provided\");\n }\n\n if (\"appId\" in config && config.publicKey && config.apiKey) {\n return new OtimServerClient({\n type: ServerAccountType.Api,\n appId: config.appId,\n privateKey: config.privateKey,\n publicKey: config.publicKey,\n apiKey: config.apiKey,\n environment: config.environment,\n chains: config.chains,\n defaultChain: config.defaultChain,\n });\n }\n\n return new OtimServerClient({\n type: ServerAccountType.PrivateKey,\n privateKey: config.privateKey,\n environment: config.environment,\n chains: config.chains,\n defaultChain: config.defaultChain,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,yBACX,WACG;CACH,MAAM,EACJ,cACA,cAAcA,mCAAY,SAC1B,GAAG,eACD,UAAU,EAAE;CAEhB,MAAM,gDAA0B;EAC9B,+CAAmB,YAAY;EAC/B,GAAG;EACJ,CAAC;AAEF,UAAS,aAAa,QAAQ,IAAI,OAAO,kBAAkB;AACzD,MAAI,cAAc;AAChB,iBAAc,UAAU,cAAc,WAAW,EAAE;GAGnD,MAAM,qBAAqB,aAAa,WAAW,UAAU,GACzD,eACA,UAAU;AAEd,iBAAc,QAAQ,gBAAgB;;AA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ountConfig, OtimAccount, PrivateKeyAccountConfig, ServerAccountConfig, ServerAccountConfig as ServerAccountConfig$1, ServerAccountType } from "@otim/sdk-core/account";
|
|
1
|
+
import { ApiAccountConfig, Chain, Chain as Chain$1, OtimAccount, PrivateKeyAccountConfig, ServerAccountConfig, ServerAccountConfig as ServerAccountConfig$1, ServerAccountType } from "@otim/sdk-core/account";
|
|
2
2
|
import { Environment, Environment as Environment$1, EnvironmentType } from "@otim/sdk-core/config";
|
|
3
3
|
import { OtimServerClientContext } from "@otim/sdk-core/context";
|
|
4
|
-
import {
|
|
4
|
+
import { ActivityClient, ActivityClient as ActivityClient$1, AuthClient, AuthClient as AuthClient$1, ConfigClient, ConfigClient as ConfigClient$1, CreatePaymentRequestResponse, DelegationClient, DelegationClient as DelegationClient$1, OrchestrationClient, OrchestrationClient as OrchestrationClient$1, PreparePaymentRequestParams, PreparedPaymentRequest, preparePaymentRequest } from "@otim/sdk-core/clients";
|
|
5
5
|
import { allSupportedChains as chains } from "@otim/utils/chains";
|
|
6
6
|
|
|
7
7
|
//#region src/client/server-client.d.ts
|
|
@@ -36,54 +36,22 @@ declare class OtimServerClient {
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/client/create-server-client.d.ts
|
|
39
|
-
|
|
40
|
-
* Creates an Otim Client for server-side blockchain operations.
|
|
41
|
-
*
|
|
42
|
-
* @param config - Configuration with private key only
|
|
43
|
-
* @returns Configured Otim Client instance
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* import { Environment } from '@otim/sdk';
|
|
48
|
-
*
|
|
49
|
-
* const client = createOtimServerClient({
|
|
50
|
-
* privateKey: '0x...',
|
|
51
|
-
* environment: Environment.Production,
|
|
52
|
-
* });
|
|
53
|
-
* await client.init();
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
declare function createOtimServerClient(config: {
|
|
57
|
-
privateKey: `0x${string}`;
|
|
39
|
+
interface BaseClientConfig {
|
|
58
40
|
environment?: Environment$1;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* import { Environment } from '@otim/sdk';
|
|
69
|
-
*
|
|
70
|
-
* const client = createOtimServerClient({
|
|
71
|
-
* appId: 'your-app-id',
|
|
72
|
-
* privateKey: '0x...',
|
|
73
|
-
* publicKey: 'your-public-key',
|
|
74
|
-
* apiKey: 'your-api-key',
|
|
75
|
-
* environment: Environment.Production,
|
|
76
|
-
* });
|
|
77
|
-
* await client.init();
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
declare function createOtimServerClient(config: {
|
|
41
|
+
chains: Chain$1[];
|
|
42
|
+
defaultChain?: Chain$1;
|
|
43
|
+
}
|
|
44
|
+
interface PrivateKeyClientConfig extends BaseClientConfig {
|
|
45
|
+
privateKey: `0x${string}`;
|
|
46
|
+
}
|
|
47
|
+
interface ApiClientConfig extends BaseClientConfig {
|
|
81
48
|
appId: string;
|
|
82
49
|
privateKey: `0x${string}`;
|
|
83
50
|
publicKey: string;
|
|
84
51
|
apiKey?: string;
|
|
85
|
-
|
|
86
|
-
|
|
52
|
+
}
|
|
53
|
+
declare function createOtimServerClient(config: PrivateKeyClientConfig): OtimServerClient;
|
|
54
|
+
declare function createOtimServerClient(config: ApiClientConfig): OtimServerClient;
|
|
87
55
|
//#endregion
|
|
88
|
-
export {
|
|
56
|
+
export { ActivityClient, type ApiAccountConfig, AuthClient, type Chain, ConfigClient, type CreatePaymentRequestResponse, DelegationClient, Environment, type EnvironmentType, OrchestrationClient, type OtimAccount, OtimServerClient, type OtimServerClientContext, type PreparePaymentRequestParams, type PreparedPaymentRequest, type PrivateKeyAccountConfig, type ServerAccountConfig, type ServerAccountType, chains, createOtimServerClient, preparePaymentRequest };
|
|
89
57
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/client/server-client.ts","../src/client/create-server-client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AA2BA;;;AAOmB,cAPN,gBAAA,CAOM;EACI,iBAAA,SAAA;EACG,iBAAA,OAAA;EAEJ,iBAAA,OAAA;EA4BN,SAAA,QAAA,EAlCK,gBAkCL;EAAO,SAAA,IAAA,EAjCN,YAiCM;mBAhCJ;uBACI;0BACG;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/client/server-client.ts","../src/client/create-server-client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AA2BA;;;AAOmB,cAPN,gBAAA,CAOM;EACI,iBAAA,SAAA;EACG,iBAAA,OAAA;EAEJ,iBAAA,OAAA;EA4BN,SAAA,QAAA,EAlCK,gBAkCL;EAAO,SAAA,IAAA,EAjCN,YAiCM;mBAhCJ;uBACI;0BACG;EC7BhB,WAAA,CAAA,MAAA,ED+BY,qBC/BI;EACV;;;;AAEM;AAGmC;AAWzD;AAGA;UDuCgB;;;;UC3DN,gBAAA;gBACM;UACN;iBACO;ADiBjB;UCdU,sBAAA,SAA+B,gBDmBpB,CAAA;EACJ,UAAA,EAAA,KAAA,MAAA,EAAA;;UChBP,eAAA,SAAwB,gBDkBX,CAAA;EACG,KAAA,EAAA,MAAA;EAEJ,UAAA,EAAA,KAAA,MAAA,EAAA;EA4BN,SAAA,EAAA,MAAA;EAAO,MAAA,CAAA,EAAA,MAAA;;iBC1CP,sBAAA,SACN,yBACP;iBACa,sBAAA,SACN,kBACP"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Environment, Environment as Environment$1, EnvironmentType } from "@otim/sdk-core/config";
|
|
2
|
-
import {
|
|
3
|
-
import { ApiAccountConfig, OtimAccount, PrivateKeyAccountConfig, ServerAccountConfig, ServerAccountConfig as ServerAccountConfig$1, ServerAccountType } from "@otim/sdk-core/account";
|
|
2
|
+
import { ActivityClient, ActivityClient as ActivityClient$1, AuthClient, AuthClient as AuthClient$1, ConfigClient, ConfigClient as ConfigClient$1, CreatePaymentRequestResponse, DelegationClient, DelegationClient as DelegationClient$1, OrchestrationClient, OrchestrationClient as OrchestrationClient$1, PreparePaymentRequestParams, PreparedPaymentRequest, preparePaymentRequest } from "@otim/sdk-core/clients";
|
|
3
|
+
import { ApiAccountConfig, Chain, Chain as Chain$1, OtimAccount, PrivateKeyAccountConfig, ServerAccountConfig, ServerAccountConfig as ServerAccountConfig$1, ServerAccountType } from "@otim/sdk-core/account";
|
|
4
4
|
import { allSupportedChains as chains } from "@otim/utils/chains";
|
|
5
5
|
import { OtimServerClientContext } from "@otim/sdk-core/context";
|
|
6
6
|
|
|
@@ -36,54 +36,22 @@ declare class OtimServerClient {
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
//#region src/client/create-server-client.d.ts
|
|
39
|
-
|
|
40
|
-
* Creates an Otim Client for server-side blockchain operations.
|
|
41
|
-
*
|
|
42
|
-
* @param config - Configuration with private key only
|
|
43
|
-
* @returns Configured Otim Client instance
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* import { Environment } from '@otim/sdk';
|
|
48
|
-
*
|
|
49
|
-
* const client = createOtimServerClient({
|
|
50
|
-
* privateKey: '0x...',
|
|
51
|
-
* environment: Environment.Production,
|
|
52
|
-
* });
|
|
53
|
-
* await client.init();
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
declare function createOtimServerClient(config: {
|
|
57
|
-
privateKey: `0x${string}`;
|
|
39
|
+
interface BaseClientConfig {
|
|
58
40
|
environment?: Environment$1;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* import { Environment } from '@otim/sdk';
|
|
69
|
-
*
|
|
70
|
-
* const client = createOtimServerClient({
|
|
71
|
-
* appId: 'your-app-id',
|
|
72
|
-
* privateKey: '0x...',
|
|
73
|
-
* publicKey: 'your-public-key',
|
|
74
|
-
* apiKey: 'your-api-key',
|
|
75
|
-
* environment: Environment.Production,
|
|
76
|
-
* });
|
|
77
|
-
* await client.init();
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
declare function createOtimServerClient(config: {
|
|
41
|
+
chains: Chain$1[];
|
|
42
|
+
defaultChain?: Chain$1;
|
|
43
|
+
}
|
|
44
|
+
interface PrivateKeyClientConfig extends BaseClientConfig {
|
|
45
|
+
privateKey: `0x${string}`;
|
|
46
|
+
}
|
|
47
|
+
interface ApiClientConfig extends BaseClientConfig {
|
|
81
48
|
appId: string;
|
|
82
49
|
privateKey: `0x${string}`;
|
|
83
50
|
publicKey: string;
|
|
84
51
|
apiKey?: string;
|
|
85
|
-
|
|
86
|
-
|
|
52
|
+
}
|
|
53
|
+
declare function createOtimServerClient(config: PrivateKeyClientConfig): OtimServerClient;
|
|
54
|
+
declare function createOtimServerClient(config: ApiClientConfig): OtimServerClient;
|
|
87
55
|
//#endregion
|
|
88
|
-
export {
|
|
56
|
+
export { ActivityClient, type ApiAccountConfig, AuthClient, type Chain, ConfigClient, type CreatePaymentRequestResponse, DelegationClient, Environment, type EnvironmentType, OrchestrationClient, type OtimAccount, OtimServerClient, type OtimServerClientContext, type PreparePaymentRequestParams, type PreparedPaymentRequest, type PrivateKeyAccountConfig, type ServerAccountConfig, type ServerAccountType, chains, createOtimServerClient, preparePaymentRequest };
|
|
89
57
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/client/server-client.ts","../src/client/create-server-client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AA2BA;;;AAOmB,cAPN,gBAAA,CAOM;EACI,iBAAA,SAAA;EACG,iBAAA,OAAA;EAEJ,iBAAA,OAAA;EA4BN,SAAA,QAAA,EAlCK,gBAkCL;EAAO,SAAA,IAAA,EAjCN,YAiCM;mBAhCJ;uBACI;0BACG;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/client/server-client.ts","../src/client/create-server-client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AA2BA;;;AAOmB,cAPN,gBAAA,CAOM;EACI,iBAAA,SAAA;EACG,iBAAA,OAAA;EAEJ,iBAAA,OAAA;EA4BN,SAAA,QAAA,EAlCK,gBAkCL;EAAO,SAAA,IAAA,EAjCN,YAiCM;mBAhCJ;uBACI;0BACG;EC7BhB,WAAA,CAAA,MAAA,ED+BY,qBC/BI;EACV;;;;AAEM;AAGmC;AAWzD;AAGA;UDuCgB;;;;UC3DN,gBAAA;gBACM;UACN;iBACO;ADiBjB;UCdU,sBAAA,SAA+B,gBDmBpB,CAAA;EACJ,UAAA,EAAA,KAAA,MAAA,EAAA;;UChBP,eAAA,SAAwB,gBDkBX,CAAA;EACG,KAAA,EAAA,MAAA;EAEJ,UAAA,EAAA,KAAA,MAAA,EAAA;EA4BN,SAAA,EAAA,MAAA;EAAO,MAAA,CAAA,EAAA,MAAA;;iBC1CP,sBAAA,SACN,yBACP;iBACa,sBAAA,SACN,kBACP"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Environment, Environment as Environment$1,
|
|
2
|
-
import { ActivityClient, ActivityClient as ActivityClient$1, AuthClient, AuthClient as AuthClient$1, ConfigClient, ConfigClient as ConfigClient$1, DelegationClient, DelegationClient as DelegationClient$1, OrchestrationClient, OrchestrationClient as OrchestrationClient$1,
|
|
1
|
+
import { Environment, Environment as Environment$1, getApiUrl } from "@otim/sdk-core/config";
|
|
2
|
+
import { ActivityClient, ActivityClient as ActivityClient$1, AuthClient, AuthClient as AuthClient$1, ConfigClient, ConfigClient as ConfigClient$1, DelegationClient, DelegationClient as DelegationClient$1, OrchestrationClient, OrchestrationClient as OrchestrationClient$1, preparePaymentRequest } from "@otim/sdk-core/clients";
|
|
3
3
|
import { ServerAccountType, createClientContext, isApiAccountConfig } from "@otim/sdk-core/account";
|
|
4
4
|
import { APIClient, createInstance } from "@otim/utils/api";
|
|
5
5
|
import { ApiKeyStamper } from "@turnkey/api-key-stamper";
|
|
@@ -86,12 +86,13 @@ function _defineProperty(e, r, t) {
|
|
|
86
86
|
|
|
87
87
|
//#endregion
|
|
88
88
|
//#region src/client/server-account.ts
|
|
89
|
+
const TURNKEY_API_URL = "https://api.turnkey.com";
|
|
89
90
|
const createApiAccount = async (config) => {
|
|
90
91
|
const stamper = new ApiKeyStamper({
|
|
91
92
|
apiPublicKey: config.publicKey,
|
|
92
93
|
apiPrivateKey: config.privateKey
|
|
93
94
|
});
|
|
94
|
-
const client = new TurnkeyClient({ baseUrl:
|
|
95
|
+
const client = new TurnkeyClient({ baseUrl: TURNKEY_API_URL }, stamper);
|
|
95
96
|
const account = await createAccount({
|
|
96
97
|
organizationId: config.appId,
|
|
97
98
|
signWith: "0xB54c8E6f303627f392884412ED2C84fFaF4779CA",
|
|
@@ -185,22 +186,26 @@ var OtimServerClient = class {
|
|
|
185
186
|
//#endregion
|
|
186
187
|
//#region src/client/create-server-client.ts
|
|
187
188
|
function createOtimServerClient(config) {
|
|
188
|
-
if (config.
|
|
189
|
+
if (config.chains.length === 0) throw new Error("At least one chain must be provided");
|
|
190
|
+
if ("appId" in config && config.publicKey && config.apiKey) return new OtimServerClient({
|
|
189
191
|
type: ServerAccountType.Api,
|
|
190
192
|
appId: config.appId,
|
|
191
193
|
privateKey: config.privateKey,
|
|
192
194
|
publicKey: config.publicKey,
|
|
193
195
|
apiKey: config.apiKey,
|
|
194
|
-
environment: config.environment
|
|
196
|
+
environment: config.environment,
|
|
197
|
+
chains: config.chains,
|
|
198
|
+
defaultChain: config.defaultChain
|
|
195
199
|
});
|
|
196
|
-
|
|
200
|
+
return new OtimServerClient({
|
|
197
201
|
type: ServerAccountType.PrivateKey,
|
|
198
202
|
privateKey: config.privateKey,
|
|
199
|
-
environment: config.environment
|
|
203
|
+
environment: config.environment,
|
|
204
|
+
chains: config.chains,
|
|
205
|
+
defaultChain: config.defaultChain
|
|
200
206
|
});
|
|
201
|
-
throw new Error("Invalid Otim Server Client configuration");
|
|
202
207
|
}
|
|
203
208
|
|
|
204
209
|
//#endregion
|
|
205
|
-
export { ActivityClient, AuthClient, ConfigClient, DelegationClient, Environment, OrchestrationClient, OtimServerClient,
|
|
210
|
+
export { ActivityClient, AuthClient, ConfigClient, DelegationClient, Environment, OrchestrationClient, OtimServerClient, chains, createOtimServerClient, preparePaymentRequest };
|
|
206
211
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["Environment","exhaustiveCheck: never","config: ServerAccountConfig","ActivityClient","AuthClient","ConfigClient","DelegationClient","OrchestrationClient"],"sources":["../src/client/api-client.ts","../src/client/utils/asserts.ts","../src/client/server-account.ts","../src/client/server-client.ts","../src/client/create-server-client.ts"],"sourcesContent":["import type { CreateInstanceParameters } from \"@otim/utils/api\";\nimport type { Optional } from \"@otim/utils/helpers\";\n\nimport { Environment, getApiUrl } from \"@otim/sdk-core/config\";\nimport { APIClient, createInstance } from \"@otim/utils/api\";\n\nexport interface CreateServerAPIClientOptions\n extends Omit<CreateInstanceParameters, \"baseURL\"> {\n sessionToken?: Optional<string>;\n environment?: Environment;\n}\n\n/**\n * Creates an API client for server-side requests.\n *\n * Configures the base URL and authentication headers for API communication.\n *\n * @param config - Optional configuration for the API client\n * @returns Configured API client instance\n *\n * @internal\n */\nexport const createServerAPIClient = (\n config?: CreateServerAPIClientOptions,\n) => {\n const {\n sessionToken,\n environment = Environment.Sandbox,\n ...restConfig\n } = config ?? {};\n\n const instance = createInstance({\n baseURL: getApiUrl(environment),\n ...restConfig,\n });\n\n instance.interceptors.request.use(async (requestConfig) => {\n if (sessionToken) {\n requestConfig.headers = requestConfig.headers ?? {};\n\n // If the session token does not start with \"Bearer \", add it.\n const authorizationToken = sessionToken.startsWith(\"Bearer \")\n ? sessionToken\n : `Bearer ${sessionToken}`;\n\n requestConfig.headers.Authorization = authorizationToken;\n }\n\n return requestConfig;\n });\n\n return new APIClient({ instance });\n};\n","export function assertDefined<T>(\n value: T,\n errorMessage: string,\n): asserts value is NonNullable<T> {\n if (value === null || value === undefined) {\n throw new Error(errorMessage);\n }\n}\n","import type {\n ApiAccountConfig,\n OtimAccountSignMessageArgs,\n OtimAccount as OtimAccountType,\n PrivateKeyAccountConfig,\n ServerAccountConfig,\n} from \"@otim/sdk-core/account\";\nimport type { Nullable } from \"@otim/utils/helpers\";\nimport type { Hex } from \"viem\";\n\nimport { ServerAccountType } from \"@otim/sdk-core/account\";\nimport { env, getTurnkeyApiUrl } from \"@otim/sdk-core/config\";\nimport { ApiKeyStamper } from \"@turnkey/api-key-stamper\";\nimport { TurnkeyClient } from \"@turnkey/http\";\nimport { createAccount } from \"@turnkey/viem\";\nimport { privateKeyToAccount } from \"viem/accounts\";\n\nimport { assertDefined } from \"./utils/asserts\";\n\ntype PrimitiveAccount = {\n signMessage: (args: {\n message: string | { raw: Hex | Uint8Array };\n }) => Promise<Hex>;\n};\n\nconst createApiAccount = async (\n config: ApiAccountConfig,\n): Promise<PrimitiveAccount> => {\n const stamper = new ApiKeyStamper({\n apiPublicKey: config.publicKey,\n apiPrivateKey: config.privateKey,\n });\n\n const client = new TurnkeyClient(\n {\n baseUrl: getTurnkeyApiUrl(env.ENVIRONMENT),\n },\n stamper,\n );\n\n const account = await createAccount({\n organizationId: config.appId,\n signWith: \"0xB54c8E6f303627f392884412ED2C84fFaF4779CA\",\n client,\n });\n\n return {\n signMessage: (args) => account.signMessage(args),\n };\n};\n\nconst createPrivateKeyAccount = (\n config: PrivateKeyAccountConfig,\n): PrimitiveAccount => {\n const account = privateKeyToAccount(config.privateKey);\n\n return {\n signMessage: (args) => account.signMessage(args),\n };\n};\n\nconst initializeAccount = async (\n config: ServerAccountConfig,\n): Promise<PrimitiveAccount> => {\n switch (config.type) {\n case ServerAccountType.Api:\n return createApiAccount(config);\n case ServerAccountType.PrivateKey:\n return createPrivateKeyAccount(config);\n default: {\n const exhaustiveCheck: never = config;\n throw new Error(\n `Unsupported account type: \"${(exhaustiveCheck as ServerAccountConfig).type}\". Supported types are: ${Object.values(ServerAccountType).join(\", \")}`,\n );\n }\n }\n};\n\n/**\n * Server-side account implementation for signing operations.\n *\n * Supports both private key and API authentication methods.\n *\n * @internal\n */\nexport class OtimAccount implements OtimAccountType {\n private account: Nullable<PrimitiveAccount> = null;\n private initialized = false;\n\n constructor(private readonly config: ServerAccountConfig) {}\n\n async initialize(): Promise<void> {\n if (this.initialized) {\n throw new Error(\n \"Account already initialized. The initialize() method should only be called once.\",\n );\n }\n\n this.account = await initializeAccount(this.config);\n this.initialized = true;\n }\n\n async signMessage({ message }: OtimAccountSignMessageArgs) {\n assertDefined(\n this.account,\n \"Account not initialized. Call initialize() before using signMessage().\",\n );\n return this.account.signMessage({ message });\n }\n}\n","import type { ServerAccountConfig } from \"@otim/sdk-core/account\";\nimport type { OtimServerClientContext } from \"@otim/sdk-core/context\";\nimport type { APIClient } from \"@otim/utils/api\";\n\nimport {\n createClientContext,\n isApiAccountConfig,\n} from \"@otim/sdk-core/account\";\nimport {\n ActivityClient,\n AuthClient,\n ConfigClient,\n DelegationClient,\n OrchestrationClient,\n} from \"@otim/sdk-core/clients\";\n\nimport { createServerAPIClient } from \"./api-client\";\nimport { OtimAccount } from \"./server-account\";\n\n/**\n * Otim Client for server-side blockchain operations.\n *\n * Provides access to activity, authentication, configuration, delegation, and\n * orchestration services.\n * The client must be initialized before use by calling the init() method.\n\n */\nexport class OtimServerClient {\n private readonly apiClient: APIClient;\n private readonly account: OtimAccount;\n private readonly context: OtimServerClientContext;\n\n readonly activity: ActivityClient;\n readonly auth: AuthClient;\n readonly config: ConfigClient;\n readonly delegation: DelegationClient;\n readonly orchestration: OrchestrationClient;\n\n constructor(config: ServerAccountConfig) {\n this.context = createClientContext(config);\n this.apiClient = createServerAPIClient({\n environment: config.environment,\n ...(isApiAccountConfig(config) ? { sessionToken: config.apiKey } : {}),\n });\n\n this.account = new OtimAccount(config);\n\n this.activity = new ActivityClient(this.apiClient);\n this.auth = new AuthClient(this.apiClient, this.account, this.context);\n this.config = new ConfigClient(this.apiClient);\n this.delegation = new DelegationClient(this.apiClient);\n this.orchestration = new OrchestrationClient(\n this.apiClient,\n this.account,\n this.context,\n );\n }\n\n /**\n * Initializes the Otim Client.\n *\n * This method must be called before using any other client methods.\n * It sets up the authentication account and prepares the client for use.\n *\n * @throws {Error} If the account is already initialized\n */\n async init(): Promise<void> {\n await this.account.initialize();\n }\n}\n","import type { Environment } from \"@otim/sdk-core/config\";\n\nimport { ServerAccountType } from \"@otim/sdk-core/account\";\n\nimport { OtimServerClient } from \"./server-client\";\n\n/**\n * Creates an Otim Client for server-side blockchain operations.\n *\n * @param config - Configuration with private key only\n * @returns Configured Otim Client instance\n *\n * @example\n * ```typescript\n * import { Environment } from '@otim/sdk';\n *\n * const client = createOtimServerClient({\n * privateKey: '0x...',\n * environment: Environment.Production,\n * });\n * await client.init();\n * ```\n */\nexport function createOtimServerClient(config: {\n privateKey: `0x${string}`;\n environment?: Environment;\n}): OtimServerClient;\n\n/**\n * Creates an Otim Client for server-side operations with API authentication.\n *\n * @param config - Configuration with API credentials\n * @returns Configured Otim Client instance\n *\n * @example\n * ```typescript\n * import { Environment } from '@otim/sdk';\n *\n * const client = createOtimServerClient({\n * appId: 'your-app-id',\n * privateKey: '0x...',\n * publicKey: 'your-public-key',\n * apiKey: 'your-api-key',\n * environment: Environment.Production,\n * });\n * await client.init();\n * ```\n */\nexport function createOtimServerClient(config: {\n appId: string;\n privateKey: `0x${string}`;\n publicKey: string;\n apiKey?: string;\n environment?: Environment;\n}): OtimServerClient;\n\nexport function createOtimServerClient(config: {\n privateKey?: `0x${string}`;\n publicKey?: string;\n apiKey?: string;\n appId?: string;\n environment?: Environment;\n}): OtimServerClient {\n if (config.appId && config.privateKey && config.publicKey && config.apiKey) {\n return new OtimServerClient({\n type: ServerAccountType.Api,\n appId: config.appId,\n privateKey: config.privateKey,\n publicKey: config.publicKey,\n apiKey: config.apiKey,\n environment: config.environment,\n });\n }\n\n if (config.privateKey) {\n return new OtimServerClient({\n type: ServerAccountType.PrivateKey,\n privateKey: config.privateKey,\n environment: config.environment,\n });\n }\n\n throw new Error(\"Invalid Otim Server Client configuration\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,yBACX,WACG;CACH,MAAM,EACJ,cACA,cAAcA,cAAY,SAC1B,GAAG,eACD,UAAU,EAAE;CAEhB,MAAM,WAAW,eAAe;EAC9B,SAAS,UAAU,YAAY;EAC/B,GAAG;EACJ,CAAC;AAEF,UAAS,aAAa,QAAQ,IAAI,OAAO,kBAAkB;AACzD,MAAI,cAAc;AAChB,iBAAc,UAAU,cAAc,WAAW,EAAE;GAGnD,MAAM,qBAAqB,aAAa,WAAW,UAAU,GACzD,eACA,UAAU;AAEd,iBAAc,QAAQ,gBAAgB;;AAGxC,SAAO;GACP;AAEF,QAAO,IAAI,UAAU,EAAE,UAAU,CAAC;;;;;ACnDpC,SAAgB,cACd,OACA,cACiC;AACjC,KAAI,UAAU,QAAQ,UAAU,OAC9B,OAAM,IAAI,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACoBjC,MAAM,mBAAmB,OACvB,WAC8B;CAC9B,MAAM,UAAU,IAAI,cAAc;EAChC,cAAc,OAAO;EACrB,eAAe,OAAO;EACvB,CAAC;CAEF,MAAM,SAAS,IAAI,cACjB,EACE,SAAS,iBAAiB,IAAI,YAAY,EAC3C,EACD,QACD;CAED,MAAM,UAAU,MAAM,cAAc;EAClC,gBAAgB,OAAO;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AAK,SAAS,KAAK,QAAQ;AACtE,OAAK,SAAS,IAAIC,eAAa,KAAK,UAAU;AAC9C,OAAK,aAAa,IAAIC,mBAAiB,KAAK,UAAU;AACtD,OAAK,gBAAgB,IAAIC,sBACvB,KAAK,WACL,KAAK,SACL,KAAK,QACN;;;;;;;;;;CAWH,MAAM,OAAsB;AAC1B,QAAM,KAAK,QAAQ,YAAY;;;;;;ACXnC,SAAgB,uBAAuB,QAMlB;AACnB,KAAI,OAAO,SAAS,OAAO,cAAc,OAAO,aAAa,OAAO,OAClE,QAAO,IAAI,iBAAiB;EAC1B,MAAM,kBAAkB;EACxB,OAAO,OAAO;EACd,YAAY,OAAO;EACnB,WAAW,OAAO;EAClB,QAAQ,OAAO;EACf,aAAa,OAAO;EACrB,CAAC;AAGJ,KAAI,OAAO,WACT,QAAO,IAAI,iBAAiB;EAC1B,MAAM,kBAAkB;EACxB,YAAY,OAAO;EACnB,aAAa,OAAO;EACrB,CAAC;AAGJ,OAAM,IAAI,MAAM,2CAA2C"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["Environment","exhaustiveCheck: never","config: ServerAccountConfig","ActivityClient","AuthClient","ConfigClient","DelegationClient","OrchestrationClient"],"sources":["../src/client/api-client.ts","../src/client/utils/asserts.ts","../src/client/server-account.ts","../src/client/server-client.ts","../src/client/create-server-client.ts"],"sourcesContent":["import type { CreateInstanceParameters } from \"@otim/utils/api\";\nimport type { Optional } from \"@otim/utils/helpers\";\n\nimport { Environment, getApiUrl } from \"@otim/sdk-core/config\";\nimport { APIClient, createInstance } from \"@otim/utils/api\";\n\nexport interface CreateServerAPIClientOptions\n extends Omit<CreateInstanceParameters, \"baseURL\"> {\n sessionToken?: Optional<string>;\n environment?: Environment;\n}\n\n/**\n * Creates an API client for server-side requests.\n *\n * Configures the base URL and authentication headers for API communication.\n *\n * @param config - Optional configuration for the API client\n * @returns Configured API client instance\n *\n * @internal\n */\nexport const createServerAPIClient = (\n config?: CreateServerAPIClientOptions,\n) => {\n const {\n sessionToken,\n environment = Environment.Sandbox,\n ...restConfig\n } = config ?? {};\n\n const instance = createInstance({\n baseURL: getApiUrl(environment),\n ...restConfig,\n });\n\n instance.interceptors.request.use(async (requestConfig) => {\n if (sessionToken) {\n requestConfig.headers = requestConfig.headers ?? {};\n\n // If the session token does not start with \"Bearer \", add it.\n const authorizationToken = sessionToken.startsWith(\"Bearer \")\n ? sessionToken\n : `Bearer ${sessionToken}`;\n\n requestConfig.headers.Authorization = authorizationToken;\n }\n\n return requestConfig;\n });\n\n return new APIClient({ instance });\n};\n","export function assertDefined<T>(\n value: T,\n errorMessage: string,\n): asserts value is NonNullable<T> {\n if (value === null || value === undefined) {\n throw new Error(errorMessage);\n }\n}\n","import type {\n ApiAccountConfig,\n OtimAccountSignMessageArgs,\n OtimAccount as OtimAccountType,\n PrivateKeyAccountConfig,\n ServerAccountConfig,\n} from \"@otim/sdk-core/account\";\nimport type { Nullable } from \"@otim/utils/helpers\";\nimport type { Hex } from \"viem\";\n\nimport { ServerAccountType } from \"@otim/sdk-core/account\";\nimport { ApiKeyStamper } from \"@turnkey/api-key-stamper\";\nimport { TurnkeyClient } from \"@turnkey/http\";\nimport { createAccount } from \"@turnkey/viem\";\nimport { privateKeyToAccount } from \"viem/accounts\";\n\nimport { assertDefined } from \"./utils/asserts\";\n\nconst TURNKEY_API_URL = \"https://api.turnkey.com\";\n\ntype PrimitiveAccount = {\n signMessage: (args: {\n message: string | { raw: Hex | Uint8Array };\n }) => Promise<Hex>;\n};\n\nconst createApiAccount = async (\n config: ApiAccountConfig,\n): Promise<PrimitiveAccount> => {\n const stamper = new ApiKeyStamper({\n apiPublicKey: config.publicKey,\n apiPrivateKey: config.privateKey,\n });\n\n const client = new TurnkeyClient({ baseUrl: TURNKEY_API_URL }, stamper);\n\n const account = await createAccount({\n organizationId: config.appId,\n signWith: \"0xB54c8E6f303627f392884412ED2C84fFaF4779CA\",\n client,\n });\n\n return {\n signMessage: (args) => account.signMessage(args),\n };\n};\n\nconst createPrivateKeyAccount = (\n config: PrivateKeyAccountConfig,\n): PrimitiveAccount => {\n const account = privateKeyToAccount(config.privateKey);\n\n return {\n signMessage: (args) => account.signMessage(args),\n };\n};\n\nconst initializeAccount = async (\n config: ServerAccountConfig,\n): Promise<PrimitiveAccount> => {\n switch (config.type) {\n case ServerAccountType.Api:\n return createApiAccount(config);\n case ServerAccountType.PrivateKey:\n return createPrivateKeyAccount(config);\n default: {\n const exhaustiveCheck: never = config;\n throw new Error(\n `Unsupported account type: \"${(exhaustiveCheck as ServerAccountConfig).type}\". Supported types are: ${Object.values(ServerAccountType).join(\", \")}`,\n );\n }\n }\n};\n\n/**\n * Server-side account implementation for signing operations.\n *\n * Supports both private key and API authentication methods.\n *\n * @internal\n */\nexport class OtimAccount implements OtimAccountType {\n private account: Nullable<PrimitiveAccount> = null;\n private initialized = false;\n\n constructor(private readonly config: ServerAccountConfig) {}\n\n async initialize(): Promise<void> {\n if (this.initialized) {\n throw new Error(\n \"Account already initialized. The initialize() method should only be called once.\",\n );\n }\n\n this.account = await initializeAccount(this.config);\n this.initialized = true;\n }\n\n async signMessage({ message }: OtimAccountSignMessageArgs) {\n assertDefined(\n this.account,\n \"Account not initialized. Call initialize() before using signMessage().\",\n );\n return this.account.signMessage({ message });\n }\n}\n","import type { ServerAccountConfig } from \"@otim/sdk-core/account\";\nimport type { OtimServerClientContext } from \"@otim/sdk-core/context\";\nimport type { APIClient } from \"@otim/utils/api\";\n\nimport {\n createClientContext,\n isApiAccountConfig,\n} from \"@otim/sdk-core/account\";\nimport {\n ActivityClient,\n AuthClient,\n ConfigClient,\n DelegationClient,\n OrchestrationClient,\n} from \"@otim/sdk-core/clients\";\n\nimport { createServerAPIClient } from \"./api-client\";\nimport { OtimAccount } from \"./server-account\";\n\n/**\n * Otim Client for server-side blockchain operations.\n *\n * Provides access to activity, authentication, configuration, delegation, and\n * orchestration services.\n * The client must be initialized before use by calling the init() method.\n\n */\nexport class OtimServerClient {\n private readonly apiClient: APIClient;\n private readonly account: OtimAccount;\n private readonly context: OtimServerClientContext;\n\n readonly activity: ActivityClient;\n readonly auth: AuthClient;\n readonly config: ConfigClient;\n readonly delegation: DelegationClient;\n readonly orchestration: OrchestrationClient;\n\n constructor(config: ServerAccountConfig) {\n this.context = createClientContext(config);\n this.apiClient = createServerAPIClient({\n environment: config.environment,\n ...(isApiAccountConfig(config) ? { sessionToken: config.apiKey } : {}),\n });\n\n this.account = new OtimAccount(config);\n\n this.activity = new ActivityClient(this.apiClient);\n this.auth = new AuthClient(this.apiClient, this.account, this.context);\n this.config = new ConfigClient(this.apiClient);\n this.delegation = new DelegationClient(this.apiClient);\n this.orchestration = new OrchestrationClient(\n this.apiClient,\n this.account,\n this.context,\n );\n }\n\n /**\n * Initializes the Otim Client.\n *\n * This method must be called before using any other client methods.\n * It sets up the authentication account and prepares the client for use.\n *\n * @throws {Error} If the account is already initialized\n */\n async init(): Promise<void> {\n await this.account.initialize();\n }\n}\n","import type { Chain } from \"@otim/sdk-core/account\";\nimport type { Environment } from \"@otim/sdk-core/config\";\n\nimport { ServerAccountType } from \"@otim/sdk-core/account\";\n\nimport { OtimServerClient } from \"./server-client\";\n\ninterface BaseClientConfig {\n environment?: Environment;\n chains: Chain[];\n defaultChain?: Chain;\n}\n\ninterface PrivateKeyClientConfig extends BaseClientConfig {\n privateKey: `0x${string}`;\n}\n\ninterface ApiClientConfig extends BaseClientConfig {\n appId: string;\n privateKey: `0x${string}`;\n publicKey: string;\n apiKey?: string;\n}\n\nexport function createOtimServerClient(\n config: PrivateKeyClientConfig,\n): OtimServerClient;\nexport function createOtimServerClient(\n config: ApiClientConfig,\n): OtimServerClient;\nexport function createOtimServerClient(\n config: PrivateKeyClientConfig | ApiClientConfig,\n): OtimServerClient {\n if (config.chains.length === 0) {\n throw new Error(\"At least one chain must be provided\");\n }\n\n if (\"appId\" in config && config.publicKey && config.apiKey) {\n return new OtimServerClient({\n type: ServerAccountType.Api,\n appId: config.appId,\n privateKey: config.privateKey,\n publicKey: config.publicKey,\n apiKey: config.apiKey,\n environment: config.environment,\n chains: config.chains,\n defaultChain: config.defaultChain,\n });\n }\n\n return new OtimServerClient({\n type: ServerAccountType.PrivateKey,\n privateKey: config.privateKey,\n environment: config.environment,\n chains: config.chains,\n defaultChain: config.defaultChain,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,yBACX,WACG;CACH,MAAM,EACJ,cACA,cAAcA,cAAY,SAC1B,GAAG,eACD,UAAU,EAAE;CAEhB,MAAM,WAAW,eAAe;EAC9B,SAAS,UAAU,YAAY;EAC/B,GAAG;EACJ,CAAC;AAEF,UAAS,aAAa,QAAQ,IAAI,OAAO,kBAAkB;AACzD,MAAI,cAAc;AAChB,iBAAc,UAAU,cAAc,WAAW,EAAE;GAGnD,MAAM,qBAAqB,aAAa,WAAW,UAAU,GACzD,eACA,UAAU;AAEd,iBAAc,QAAQ,gBAAgB;;AAGxC,SAAO;GACP;AAEF,QAAO,IAAI,UAAU,EAAE,UAAU,CAAC;;;;;ACnDpC,SAAgB,cACd,OACA,cACiC;AACjC,KAAI,UAAU,QAAQ,UAAU,OAC9B,OAAM,IAAI,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACajC,MAAM,kBAAkB;AAQxB,MAAM,mBAAmB,OACvB,WAC8B;CAC9B,MAAM,UAAU,IAAI,cAAc;EAChC,cAAc,OAAO;EACrB,eAAe,OAAO;EACvB,CAAC;CAEF,MAAM,SAAS,IAAI,cAAc,EAAE,SAAS,iBAAiB,EAAE,QAAQ;CAEvE,MAAM,UAAU,MAAM,cAAc;EAClC,gBAAgB,OAAO;EACvB,UAAU;EACV;EACD,CAAC;AAEF,QAAO,EACL,cAAc,SAAS,QAAQ,YAAY,KAAK,EACjD;;AAGH,MAAM,2BACJ,WACqB;CACrB,MAAM,UAAU,oBAAoB,OAAO,WAAW;AAEtD,QAAO,EACL,cAAc,SAAS,QAAQ,YAAY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;;;;CAWH,MAAM,OAAsB;AAC1B,QAAM,KAAK,QAAQ,YAAY;;;;;;ACrCnC,SAAgB,uBACd,QACkB;AAClB,KAAI,OAAO,OAAO,WAAW,EAC3B,OAAM,IAAI,MAAM,sCAAsC;AAGxD,KAAI,WAAW,UAAU,OAAO,aAAa,OAAO,OAClD,QAAO,IAAI,iBAAiB;EAC1B,MAAM,kBAAkB;EACxB,OAAO,OAAO;EACd,YAAY,OAAO;EACnB,WAAW,OAAO;EAClB,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,cAAc,OAAO;EACtB,CAAC;AAGJ,QAAO,IAAI,iBAAiB;EAC1B,MAAM,kBAAkB;EACxB,YAAY,OAAO;EACnB,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,cAAc,OAAO;EACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@otim/sdk-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-alpha.0",
|
|
4
4
|
"description": "Otim's TypeScript SDK for blockchain automation and smart contract interactions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -47,6 +47,9 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
49
49
|
"@playwright/test": "^1.56.1",
|
|
50
|
+
"@turnkey/api-key-stamper": "^0.5.0",
|
|
51
|
+
"@turnkey/http": "^3.15.0",
|
|
52
|
+
"@turnkey/viem": "^0.14.13",
|
|
50
53
|
"@types/adm-zip": "^0.5.7",
|
|
51
54
|
"@types/node": "^24.10.1",
|
|
52
55
|
"@types/node-fetch": "^2.6.13",
|
|
@@ -62,8 +65,8 @@
|
|
|
62
65
|
"@otim/typescript-config": "0.0.0"
|
|
63
66
|
},
|
|
64
67
|
"dependencies": {
|
|
65
|
-
"@otim/turnkey": "0.0.
|
|
66
|
-
"@otim/utils": "0.0.
|
|
68
|
+
"@otim/turnkey": "0.0.3",
|
|
69
|
+
"@otim/utils": "0.0.3",
|
|
67
70
|
"@t3-oss/env-core": "^0.13.8",
|
|
68
71
|
"@testing-library/user-event": "^14.6.1",
|
|
69
72
|
"@turnkey/api-key-stamper": "^0.5.0",
|
|
@@ -78,7 +81,7 @@
|
|
|
78
81
|
"viem": "^2.39.3",
|
|
79
82
|
"ws": "^8.18.3",
|
|
80
83
|
"zod": "^4.1.12",
|
|
81
|
-
"@otim/sdk-core": "0.0.
|
|
84
|
+
"@otim/sdk-core": "0.0.4-alpha.0"
|
|
82
85
|
},
|
|
83
86
|
"peerDependencies": {
|
|
84
87
|
"@wagmi/core": "2.x",
|
|
@@ -96,6 +99,9 @@
|
|
|
96
99
|
"engines": {
|
|
97
100
|
"node": ">=18.0.0"
|
|
98
101
|
},
|
|
102
|
+
"publishConfig": {
|
|
103
|
+
"access": "public"
|
|
104
|
+
},
|
|
99
105
|
"scripts": {
|
|
100
106
|
"build": "tsdown",
|
|
101
107
|
"dev": "tsdown --watch",
|
|
@@ -106,7 +112,7 @@
|
|
|
106
112
|
"check-types": "tsc --noEmit",
|
|
107
113
|
"check-exports": "attw --pack . --format=table --ignore-rules=no-resolution untyped-resolution fallback-condition || true",
|
|
108
114
|
"clean": "rm -rf dist",
|
|
109
|
-
"ci": "pnpm run lint:check && pnpm run
|
|
115
|
+
"ci": "pnpm run lint:check && pnpm run build && pnpm run check-exports",
|
|
110
116
|
"test": "vitest run",
|
|
111
117
|
"test:watch": "vitest --watch",
|
|
112
118
|
"test:coverage": "vitest run --coverage",
|