@otim/sdk-server 0.0.2 → 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 +25 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -47
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +16 -47
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +17 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -7
- 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",
|
|
@@ -142,7 +143,7 @@ var OtimAccount = class {
|
|
|
142
143
|
/**
|
|
143
144
|
* Otim Client for server-side blockchain operations.
|
|
144
145
|
*
|
|
145
|
-
* Provides access to authentication, configuration, delegation, and
|
|
146
|
+
* Provides access to activity, authentication, configuration, delegation, and
|
|
146
147
|
* orchestration services.
|
|
147
148
|
* The client must be initialized before use by calling the init() method.
|
|
148
149
|
|
|
@@ -152,6 +153,7 @@ var OtimServerClient = class {
|
|
|
152
153
|
_defineProperty(this, "apiClient", void 0);
|
|
153
154
|
_defineProperty(this, "account", void 0);
|
|
154
155
|
_defineProperty(this, "context", void 0);
|
|
156
|
+
_defineProperty(this, "activity", void 0);
|
|
155
157
|
_defineProperty(this, "auth", void 0);
|
|
156
158
|
_defineProperty(this, "config", void 0);
|
|
157
159
|
_defineProperty(this, "delegation", void 0);
|
|
@@ -162,6 +164,7 @@ var OtimServerClient = class {
|
|
|
162
164
|
...(0, __otim_sdk_core_account.isApiAccountConfig)(config) ? { sessionToken: config.apiKey } : {}
|
|
163
165
|
});
|
|
164
166
|
this.account = new OtimAccount(config);
|
|
167
|
+
this.activity = new __otim_sdk_core_clients.ActivityClient(this.apiClient);
|
|
165
168
|
this.auth = new __otim_sdk_core_clients.AuthClient(this.apiClient, this.account, this.context);
|
|
166
169
|
this.config = new __otim_sdk_core_clients.ConfigClient(this.apiClient);
|
|
167
170
|
this.delegation = new __otim_sdk_core_clients.DelegationClient(this.apiClient);
|
|
@@ -183,23 +186,33 @@ var OtimServerClient = class {
|
|
|
183
186
|
//#endregion
|
|
184
187
|
//#region src/client/create-server-client.ts
|
|
185
188
|
function createOtimServerClient(config) {
|
|
186
|
-
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({
|
|
187
191
|
type: __otim_sdk_core_account.ServerAccountType.Api,
|
|
188
192
|
appId: config.appId,
|
|
189
193
|
privateKey: config.privateKey,
|
|
190
194
|
publicKey: config.publicKey,
|
|
191
195
|
apiKey: config.apiKey,
|
|
192
|
-
environment: config.environment
|
|
196
|
+
environment: config.environment,
|
|
197
|
+
chains: config.chains,
|
|
198
|
+
defaultChain: config.defaultChain
|
|
193
199
|
});
|
|
194
|
-
|
|
200
|
+
return new OtimServerClient({
|
|
195
201
|
type: __otim_sdk_core_account.ServerAccountType.PrivateKey,
|
|
196
202
|
privateKey: config.privateKey,
|
|
197
|
-
environment: config.environment
|
|
203
|
+
environment: config.environment,
|
|
204
|
+
chains: config.chains,
|
|
205
|
+
defaultChain: config.defaultChain
|
|
198
206
|
});
|
|
199
|
-
throw new Error("Invalid Otim Server Client configuration");
|
|
200
207
|
}
|
|
201
208
|
|
|
202
209
|
//#endregion
|
|
210
|
+
Object.defineProperty(exports, 'ActivityClient', {
|
|
211
|
+
enumerable: true,
|
|
212
|
+
get: function () {
|
|
213
|
+
return __otim_sdk_core_clients.ActivityClient;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
203
216
|
Object.defineProperty(exports, 'AuthClient', {
|
|
204
217
|
enumerable: true,
|
|
205
218
|
get: function () {
|
|
@@ -231,17 +244,17 @@ Object.defineProperty(exports, 'OrchestrationClient', {
|
|
|
231
244
|
}
|
|
232
245
|
});
|
|
233
246
|
exports.OtimServerClient = OtimServerClient;
|
|
234
|
-
Object.defineProperty(exports, '
|
|
247
|
+
Object.defineProperty(exports, 'chains', {
|
|
235
248
|
enumerable: true,
|
|
236
249
|
get: function () {
|
|
237
|
-
return
|
|
250
|
+
return __otim_utils_chains.allSupportedChains;
|
|
238
251
|
}
|
|
239
252
|
});
|
|
240
|
-
|
|
253
|
+
exports.createOtimServerClient = createOtimServerClient;
|
|
254
|
+
Object.defineProperty(exports, 'preparePaymentRequest', {
|
|
241
255
|
enumerable: true,
|
|
242
256
|
get: function () {
|
|
243
|
-
return
|
|
257
|
+
return __otim_sdk_core_clients.preparePaymentRequest;
|
|
244
258
|
}
|
|
245
259
|
});
|
|
246
|
-
exports.createOtimServerClient = createOtimServerClient;
|
|
247
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","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 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 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 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.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,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,SA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,SAAO,KAAK,QAAQ,YAAY,EAAE,SAAS,CAAC;;;;;;;;;;;;;;ACjFhD,IAAa,mBAAb,MAA8B;CAU5B,YAAY,QAA6B;wBATxB;wBACA;wBACA;wBAER;wBACA;wBACA;wBACA;AAGP,OAAK,2DAA8B,OAAO;AAC1C,OAAK,YAAY,sBAAsB;GACrC,aAAa,OAAO;GACpB,mDAAuB,OAAO,GAAG,EAAE,cAAc,OAAO,QAAQ,GAAG,EAAE;GACtE,CAAC;AAEF,OAAK,UAAU,IAAI,YAAY,OAAO;AAEtC,OAAK,OAAO,IAAIC,mCAAW,KAAK,WAAW,KAAK,SAAS,KAAK,QAAQ;AACtE,OAAK,SAAS,IAAIC,qCAAa,KAAK,UAAU;AAC9C,OAAK,aAAa,IAAIC,yCAAiB,KAAK,UAAU;AACtD,OAAK,gBAAgB,IAAIC,4CACvB,KAAK,WACL,KAAK,SACL,KAAK,QACN;;;;;;;;;;CAWH,MAAM,OAAsB;AAC1B,QAAM,KAAK,QAAQ,YAAY;;;;;;ACRnC,SAAgB,uBAAuB,QAMlB;AACnB,KAAI,OAAO,SAAS,OAAO,cAAc,OAAO,aAAa,OAAO,OAClE,QAAO,IAAI,iBAAiB;EAC1B,MAAMC,0CAAkB;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,MAAMA,0CAAkB;EACxB,YAAY,OAAO;EACnB,aAAa,OAAO;EACrB,CAAC;AAGJ,OAAM,IAAI,MAAM,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;;AAGxC,SAAO;GACP;AAEF,QAAO,IAAIC,2BAAU,EAAE,UAAU,CAAC;;;;;ACnDpC,SAAgB,cACd,OACA,cACiC;AACjC,KAAI,UAAU,QAAQ,UAAU,OAC9B,OAAM,IAAI,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACajC,M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Y,sBAAsB;GACrC,aAAa,OAAO;GACpB,mDAAuB,OAAO,GAAG,EAAE,cAAc,OAAO,QAAQ,GAAG,EAAE;GACtE,CAAC;AAEF,OAAK,UAAU,IAAI,YAAY,OAAO;AAEtC,OAAK,WAAW,IAAIC,uCAAe,KAAK,UAAU;AAClD,OAAK,OAAO,IAAIC,mCAAW,KAAK,WAAW,KAAK,SAAS,KAAK,QAAQ;AACtE,OAAK,SAAS,IAAIC,qCAAa,KAAK,UAAU;AAC9C,OAAK,aAAa,IAAIC,yCAAiB,KAAK,UAAU;AACtD,OAAK,gBAAgB,IAAIC,4CACvB,KAAK,WACL,KAAK,SACL,KAAK,QACN;;;;;;;;;;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,MAAMC,0CAAkB;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,MAAMA,0CAAkB;EACxB,YAAY,OAAO;EACnB,aAAa,OAAO;EACpB,QAAQ,OAAO;EACf,cAAc,OAAO;EACtB,CAAC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ApiAccountConfig, 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
|
|
@@ -9,7 +9,7 @@ import { allSupportedChains as chains } from "@otim/utils/chains";
|
|
|
9
9
|
/**
|
|
10
10
|
* Otim Client for server-side blockchain operations.
|
|
11
11
|
*
|
|
12
|
-
* Provides access to authentication, configuration, delegation, and
|
|
12
|
+
* Provides access to activity, authentication, configuration, delegation, and
|
|
13
13
|
* orchestration services.
|
|
14
14
|
* The client must be initialized before use by calling the init() method.
|
|
15
15
|
|
|
@@ -18,6 +18,7 @@ declare class OtimServerClient {
|
|
|
18
18
|
private readonly apiClient;
|
|
19
19
|
private readonly account;
|
|
20
20
|
private readonly context;
|
|
21
|
+
readonly activity: ActivityClient$1;
|
|
21
22
|
readonly auth: AuthClient$1;
|
|
22
23
|
readonly config: ConfigClient$1;
|
|
23
24
|
readonly delegation: DelegationClient$1;
|
|
@@ -35,54 +36,22 @@ declare class OtimServerClient {
|
|
|
35
36
|
}
|
|
36
37
|
//#endregion
|
|
37
38
|
//#region src/client/create-server-client.d.ts
|
|
38
|
-
|
|
39
|
-
* Creates an Otim Client for server-side blockchain operations.
|
|
40
|
-
*
|
|
41
|
-
* @param config - Configuration with private key only
|
|
42
|
-
* @returns Configured Otim Client instance
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* import { Environment } from '@otim/sdk';
|
|
47
|
-
*
|
|
48
|
-
* const client = createOtimServerClient({
|
|
49
|
-
* privateKey: '0x...',
|
|
50
|
-
* environment: Environment.Production,
|
|
51
|
-
* });
|
|
52
|
-
* await client.init();
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
declare function createOtimServerClient(config: {
|
|
56
|
-
privateKey: `0x${string}`;
|
|
39
|
+
interface BaseClientConfig {
|
|
57
40
|
environment?: Environment$1;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* import { Environment } from '@otim/sdk';
|
|
68
|
-
*
|
|
69
|
-
* const client = createOtimServerClient({
|
|
70
|
-
* appId: 'your-app-id',
|
|
71
|
-
* privateKey: '0x...',
|
|
72
|
-
* publicKey: 'your-public-key',
|
|
73
|
-
* apiKey: 'your-api-key',
|
|
74
|
-
* environment: Environment.Production,
|
|
75
|
-
* });
|
|
76
|
-
* await client.init();
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
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 {
|
|
80
48
|
appId: string;
|
|
81
49
|
privateKey: `0x${string}`;
|
|
82
50
|
publicKey: string;
|
|
83
51
|
apiKey?: string;
|
|
84
|
-
|
|
85
|
-
|
|
52
|
+
}
|
|
53
|
+
declare function createOtimServerClient(config: PrivateKeyClientConfig): OtimServerClient;
|
|
54
|
+
declare function createOtimServerClient(config: ApiClientConfig): OtimServerClient;
|
|
86
55
|
//#endregion
|
|
87
|
-
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 };
|
|
88
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":";;;;;;;;;;;;;
|
|
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
|
|
|
@@ -9,7 +9,7 @@ import { OtimServerClientContext } from "@otim/sdk-core/context";
|
|
|
9
9
|
/**
|
|
10
10
|
* Otim Client for server-side blockchain operations.
|
|
11
11
|
*
|
|
12
|
-
* Provides access to authentication, configuration, delegation, and
|
|
12
|
+
* Provides access to activity, authentication, configuration, delegation, and
|
|
13
13
|
* orchestration services.
|
|
14
14
|
* The client must be initialized before use by calling the init() method.
|
|
15
15
|
|
|
@@ -18,6 +18,7 @@ declare class OtimServerClient {
|
|
|
18
18
|
private readonly apiClient;
|
|
19
19
|
private readonly account;
|
|
20
20
|
private readonly context;
|
|
21
|
+
readonly activity: ActivityClient$1;
|
|
21
22
|
readonly auth: AuthClient$1;
|
|
22
23
|
readonly config: ConfigClient$1;
|
|
23
24
|
readonly delegation: DelegationClient$1;
|
|
@@ -35,54 +36,22 @@ declare class OtimServerClient {
|
|
|
35
36
|
}
|
|
36
37
|
//#endregion
|
|
37
38
|
//#region src/client/create-server-client.d.ts
|
|
38
|
-
|
|
39
|
-
* Creates an Otim Client for server-side blockchain operations.
|
|
40
|
-
*
|
|
41
|
-
* @param config - Configuration with private key only
|
|
42
|
-
* @returns Configured Otim Client instance
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* import { Environment } from '@otim/sdk';
|
|
47
|
-
*
|
|
48
|
-
* const client = createOtimServerClient({
|
|
49
|
-
* privateKey: '0x...',
|
|
50
|
-
* environment: Environment.Production,
|
|
51
|
-
* });
|
|
52
|
-
* await client.init();
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
declare function createOtimServerClient(config: {
|
|
56
|
-
privateKey: `0x${string}`;
|
|
39
|
+
interface BaseClientConfig {
|
|
57
40
|
environment?: Environment$1;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* import { Environment } from '@otim/sdk';
|
|
68
|
-
*
|
|
69
|
-
* const client = createOtimServerClient({
|
|
70
|
-
* appId: 'your-app-id',
|
|
71
|
-
* privateKey: '0x...',
|
|
72
|
-
* publicKey: 'your-public-key',
|
|
73
|
-
* apiKey: 'your-api-key',
|
|
74
|
-
* environment: Environment.Production,
|
|
75
|
-
* });
|
|
76
|
-
* await client.init();
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
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 {
|
|
80
48
|
appId: string;
|
|
81
49
|
privateKey: `0x${string}`;
|
|
82
50
|
publicKey: string;
|
|
83
51
|
apiKey?: string;
|
|
84
|
-
|
|
85
|
-
|
|
52
|
+
}
|
|
53
|
+
declare function createOtimServerClient(config: PrivateKeyClientConfig): OtimServerClient;
|
|
54
|
+
declare function createOtimServerClient(config: ApiClientConfig): OtimServerClient;
|
|
86
55
|
//#endregion
|
|
87
|
-
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 };
|
|
88
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":";;;;;;;;;;;;;
|
|
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 { 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",
|
|
@@ -142,7 +143,7 @@ var OtimAccount = class {
|
|
|
142
143
|
/**
|
|
143
144
|
* Otim Client for server-side blockchain operations.
|
|
144
145
|
*
|
|
145
|
-
* Provides access to authentication, configuration, delegation, and
|
|
146
|
+
* Provides access to activity, authentication, configuration, delegation, and
|
|
146
147
|
* orchestration services.
|
|
147
148
|
* The client must be initialized before use by calling the init() method.
|
|
148
149
|
|
|
@@ -152,6 +153,7 @@ var OtimServerClient = class {
|
|
|
152
153
|
_defineProperty(this, "apiClient", void 0);
|
|
153
154
|
_defineProperty(this, "account", void 0);
|
|
154
155
|
_defineProperty(this, "context", void 0);
|
|
156
|
+
_defineProperty(this, "activity", void 0);
|
|
155
157
|
_defineProperty(this, "auth", void 0);
|
|
156
158
|
_defineProperty(this, "config", void 0);
|
|
157
159
|
_defineProperty(this, "delegation", void 0);
|
|
@@ -162,6 +164,7 @@ var OtimServerClient = class {
|
|
|
162
164
|
...isApiAccountConfig(config) ? { sessionToken: config.apiKey } : {}
|
|
163
165
|
});
|
|
164
166
|
this.account = new OtimAccount(config);
|
|
167
|
+
this.activity = new ActivityClient$1(this.apiClient);
|
|
165
168
|
this.auth = new AuthClient$1(this.apiClient, this.account, this.context);
|
|
166
169
|
this.config = new ConfigClient$1(this.apiClient);
|
|
167
170
|
this.delegation = new DelegationClient$1(this.apiClient);
|
|
@@ -183,22 +186,26 @@ var OtimServerClient = class {
|
|
|
183
186
|
//#endregion
|
|
184
187
|
//#region src/client/create-server-client.ts
|
|
185
188
|
function createOtimServerClient(config) {
|
|
186
|
-
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({
|
|
187
191
|
type: ServerAccountType.Api,
|
|
188
192
|
appId: config.appId,
|
|
189
193
|
privateKey: config.privateKey,
|
|
190
194
|
publicKey: config.publicKey,
|
|
191
195
|
apiKey: config.apiKey,
|
|
192
|
-
environment: config.environment
|
|
196
|
+
environment: config.environment,
|
|
197
|
+
chains: config.chains,
|
|
198
|
+
defaultChain: config.defaultChain
|
|
193
199
|
});
|
|
194
|
-
|
|
200
|
+
return new OtimServerClient({
|
|
195
201
|
type: ServerAccountType.PrivateKey,
|
|
196
202
|
privateKey: config.privateKey,
|
|
197
|
-
environment: config.environment
|
|
203
|
+
environment: config.environment,
|
|
204
|
+
chains: config.chains,
|
|
205
|
+
defaultChain: config.defaultChain
|
|
198
206
|
});
|
|
199
|
-
throw new Error("Invalid Otim Server Client configuration");
|
|
200
207
|
}
|
|
201
208
|
|
|
202
209
|
//#endregion
|
|
203
|
-
export { AuthClient, ConfigClient, DelegationClient, Environment, OrchestrationClient, OtimServerClient,
|
|
210
|
+
export { ActivityClient, AuthClient, ConfigClient, DelegationClient, Environment, OrchestrationClient, OtimServerClient, chains, createOtimServerClient, preparePaymentRequest };
|
|
204
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","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 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 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 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.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;EACvB,UAAU;EACV;EACD,CAAC;AAEF,QAAO,EACL,cAAc,SAAS,QAAQ,YAAY,KAAK,EACjD;;AAGH,MAAM,2BAC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KAAK,WACL,KAAK,SACL,KAAK,QACN;;;;;;;;;;CAWH,MAAM,OAAsB;AAC1B,QAAM,KAAK,QAAQ,YAAY;;;;;;ACRnC,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.environ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AsC;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",
|
|
@@ -58,12 +61,12 @@
|
|
|
58
61
|
"tsdown": "^0.16.5",
|
|
59
62
|
"typescript-eslint": "^8.47.0",
|
|
60
63
|
"vitest": "^4.0.10",
|
|
61
|
-
"@otim/
|
|
62
|
-
"@otim/
|
|
64
|
+
"@otim/eslint-config": "0.0.1",
|
|
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",
|