@otim/sdk-server 0.0.1

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 ADDED
@@ -0,0 +1,247 @@
1
+ let __otim_sdk_core_config = require("@otim/sdk-core/config");
2
+ let __otim_sdk_core_clients = require("@otim/sdk-core/clients");
3
+ let __otim_sdk_core_account = require("@otim/sdk-core/account");
4
+ let __otim_utils_api = require("@otim/utils/api");
5
+ let __turnkey_api_key_stamper = require("@turnkey/api-key-stamper");
6
+ let __turnkey_http = require("@turnkey/http");
7
+ let __turnkey_viem = require("@turnkey/viem");
8
+ let viem_accounts = require("viem/accounts");
9
+ let __otim_utils_chains = require("@otim/utils/chains");
10
+
11
+ //#region src/client/api-client.ts
12
+ /**
13
+ * Creates an API client for server-side requests.
14
+ *
15
+ * Configures the base URL and authentication headers for API communication.
16
+ *
17
+ * @param config - Optional configuration for the API client
18
+ * @returns Configured API client instance
19
+ *
20
+ * @internal
21
+ */
22
+ const createServerAPIClient = (config) => {
23
+ const { sessionToken, environment = __otim_sdk_core_config.Environment.Sandbox, ...restConfig } = config ?? {};
24
+ const instance = (0, __otim_utils_api.createInstance)({
25
+ baseURL: (0, __otim_sdk_core_config.getApiUrl)(environment),
26
+ ...restConfig
27
+ });
28
+ instance.interceptors.request.use(async (requestConfig) => {
29
+ if (sessionToken) {
30
+ requestConfig.headers = requestConfig.headers ?? {};
31
+ const authorizationToken = sessionToken.startsWith("Bearer ") ? sessionToken : `Bearer ${sessionToken}`;
32
+ requestConfig.headers.Authorization = authorizationToken;
33
+ }
34
+ return requestConfig;
35
+ });
36
+ return new __otim_utils_api.APIClient({ instance });
37
+ };
38
+
39
+ //#endregion
40
+ //#region src/client/utils/asserts.ts
41
+ function assertDefined(value, errorMessage) {
42
+ if (value === null || value === void 0) throw new Error(errorMessage);
43
+ }
44
+
45
+ //#endregion
46
+ //#region \0@oxc-project+runtime@0.97.0/helpers/typeof.js
47
+ function _typeof(o) {
48
+ "@babel/helpers - typeof";
49
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
50
+ return typeof o$1;
51
+ } : function(o$1) {
52
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
53
+ }, _typeof(o);
54
+ }
55
+
56
+ //#endregion
57
+ //#region \0@oxc-project+runtime@0.97.0/helpers/toPrimitive.js
58
+ function toPrimitive(t, r) {
59
+ if ("object" != _typeof(t) || !t) return t;
60
+ var e = t[Symbol.toPrimitive];
61
+ if (void 0 !== e) {
62
+ var i = e.call(t, r || "default");
63
+ if ("object" != _typeof(i)) return i;
64
+ throw new TypeError("@@toPrimitive must return a primitive value.");
65
+ }
66
+ return ("string" === r ? String : Number)(t);
67
+ }
68
+
69
+ //#endregion
70
+ //#region \0@oxc-project+runtime@0.97.0/helpers/toPropertyKey.js
71
+ function toPropertyKey(t) {
72
+ var i = toPrimitive(t, "string");
73
+ return "symbol" == _typeof(i) ? i : i + "";
74
+ }
75
+
76
+ //#endregion
77
+ //#region \0@oxc-project+runtime@0.97.0/helpers/defineProperty.js
78
+ function _defineProperty(e, r, t) {
79
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
80
+ value: t,
81
+ enumerable: !0,
82
+ configurable: !0,
83
+ writable: !0
84
+ }) : e[r] = t, e;
85
+ }
86
+
87
+ //#endregion
88
+ //#region src/client/server-account.ts
89
+ const createApiAccount = async (config) => {
90
+ const stamper = new __turnkey_api_key_stamper.ApiKeyStamper({
91
+ apiPublicKey: config.publicKey,
92
+ apiPrivateKey: config.privateKey
93
+ });
94
+ const client = new __turnkey_http.TurnkeyClient({ baseUrl: (0, __otim_sdk_core_config.getTurnkeyApiUrl)(__otim_sdk_core_config.env.ENVIRONMENT) }, stamper);
95
+ const account = await (0, __turnkey_viem.createAccount)({
96
+ organizationId: config.appId,
97
+ signWith: "0xB54c8E6f303627f392884412ED2C84fFaF4779CA",
98
+ client
99
+ });
100
+ return { signMessage: (args) => account.signMessage(args) };
101
+ };
102
+ const createPrivateKeyAccount = (config) => {
103
+ const account = (0, viem_accounts.privateKeyToAccount)(config.privateKey);
104
+ return { signMessage: (args) => account.signMessage(args) };
105
+ };
106
+ const initializeAccount = async (config) => {
107
+ switch (config.type) {
108
+ case __otim_sdk_core_account.ServerAccountType.Api: return createApiAccount(config);
109
+ case __otim_sdk_core_account.ServerAccountType.PrivateKey: return createPrivateKeyAccount(config);
110
+ default: {
111
+ const exhaustiveCheck = config;
112
+ throw new Error(`Unsupported account type: "${exhaustiveCheck.type}". Supported types are: ${Object.values(__otim_sdk_core_account.ServerAccountType).join(", ")}`);
113
+ }
114
+ }
115
+ };
116
+ /**
117
+ * Server-side account implementation for signing operations.
118
+ *
119
+ * Supports both private key and API authentication methods.
120
+ *
121
+ * @internal
122
+ */
123
+ var OtimAccount = class {
124
+ constructor(config) {
125
+ this.config = config;
126
+ _defineProperty(this, "account", null);
127
+ _defineProperty(this, "initialized", false);
128
+ }
129
+ async initialize() {
130
+ if (this.initialized) throw new Error("Account already initialized. The initialize() method should only be called once.");
131
+ this.account = await initializeAccount(this.config);
132
+ this.initialized = true;
133
+ }
134
+ async signMessage({ message }) {
135
+ assertDefined(this.account, "Account not initialized. Call initialize() before using signMessage().");
136
+ return this.account.signMessage({ message });
137
+ }
138
+ };
139
+
140
+ //#endregion
141
+ //#region src/client/server-client.ts
142
+ /**
143
+ * Otim Client for server-side blockchain operations.
144
+ *
145
+ * Provides access to authentication, configuration, delegation, and
146
+ * orchestration services.
147
+ * The client must be initialized before use by calling the init() method.
148
+
149
+ */
150
+ var OtimServerClient = class {
151
+ constructor(config) {
152
+ _defineProperty(this, "apiClient", void 0);
153
+ _defineProperty(this, "account", void 0);
154
+ _defineProperty(this, "context", void 0);
155
+ _defineProperty(this, "auth", void 0);
156
+ _defineProperty(this, "config", void 0);
157
+ _defineProperty(this, "delegation", void 0);
158
+ _defineProperty(this, "orchestration", void 0);
159
+ this.context = (0, __otim_sdk_core_account.createClientContext)(config);
160
+ this.apiClient = createServerAPIClient({
161
+ environment: config.environment,
162
+ ...(0, __otim_sdk_core_account.isApiAccountConfig)(config) ? { sessionToken: config.apiKey } : {}
163
+ });
164
+ this.account = new OtimAccount(config);
165
+ this.auth = new __otim_sdk_core_clients.AuthClient(this.apiClient, this.account, this.context);
166
+ this.config = new __otim_sdk_core_clients.ConfigClient(this.apiClient);
167
+ this.delegation = new __otim_sdk_core_clients.DelegationClient(this.apiClient);
168
+ this.orchestration = new __otim_sdk_core_clients.OrchestrationClient(this.apiClient, this.account, this.context);
169
+ }
170
+ /**
171
+ * Initializes the Otim Client.
172
+ *
173
+ * This method must be called before using any other client methods.
174
+ * It sets up the authentication account and prepares the client for use.
175
+ *
176
+ * @throws {Error} If the account is already initialized
177
+ */
178
+ async init() {
179
+ await this.account.initialize();
180
+ }
181
+ };
182
+
183
+ //#endregion
184
+ //#region src/client/create-server-client.ts
185
+ function createOtimServerClient(config) {
186
+ if (config.appId && config.privateKey && config.publicKey && config.apiKey) return new OtimServerClient({
187
+ type: __otim_sdk_core_account.ServerAccountType.Api,
188
+ appId: config.appId,
189
+ privateKey: config.privateKey,
190
+ publicKey: config.publicKey,
191
+ apiKey: config.apiKey,
192
+ environment: config.environment
193
+ });
194
+ if (config.privateKey) return new OtimServerClient({
195
+ type: __otim_sdk_core_account.ServerAccountType.PrivateKey,
196
+ privateKey: config.privateKey,
197
+ environment: config.environment
198
+ });
199
+ throw new Error("Invalid Otim Server Client configuration");
200
+ }
201
+
202
+ //#endregion
203
+ Object.defineProperty(exports, 'AuthClient', {
204
+ enumerable: true,
205
+ get: function () {
206
+ return __otim_sdk_core_clients.AuthClient;
207
+ }
208
+ });
209
+ Object.defineProperty(exports, 'ConfigClient', {
210
+ enumerable: true,
211
+ get: function () {
212
+ return __otim_sdk_core_clients.ConfigClient;
213
+ }
214
+ });
215
+ Object.defineProperty(exports, 'DelegationClient', {
216
+ enumerable: true,
217
+ get: function () {
218
+ return __otim_sdk_core_clients.DelegationClient;
219
+ }
220
+ });
221
+ Object.defineProperty(exports, 'Environment', {
222
+ enumerable: true,
223
+ get: function () {
224
+ return __otim_sdk_core_config.Environment;
225
+ }
226
+ });
227
+ Object.defineProperty(exports, 'OrchestrationClient', {
228
+ enumerable: true,
229
+ get: function () {
230
+ return __otim_sdk_core_clients.OrchestrationClient;
231
+ }
232
+ });
233
+ exports.OtimServerClient = OtimServerClient;
234
+ Object.defineProperty(exports, 'PaymentRequestsClient', {
235
+ enumerable: true,
236
+ get: function () {
237
+ return __otim_sdk_core_clients.PaymentRequestsClient;
238
+ }
239
+ });
240
+ Object.defineProperty(exports, 'chains', {
241
+ enumerable: true,
242
+ get: function () {
243
+ return __otim_utils_chains.allSupportedChains;
244
+ }
245
+ });
246
+ exports.createOtimServerClient = createOtimServerClient;
247
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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":"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"}
@@ -0,0 +1,88 @@
1
+ import { ApiAccountConfig, OtimAccount, PrivateKeyAccountConfig, ServerAccountConfig, ServerAccountConfig as ServerAccountConfig$1, ServerAccountType } from "@otim/sdk-core/account";
2
+ import { Environment, Environment as Environment$1, EnvironmentType } from "@otim/sdk-core/config";
3
+ import { OtimServerClientContext } from "@otim/sdk-core/context";
4
+ import { ActivatePaymentRequestParams, AuthClient, AuthClient as AuthClient$1, ConfigClient, ConfigClient as ConfigClient$1, CreatePaymentRequestParameters, CreatePaymentRequestResponse, DelegationClient, DelegationClient as DelegationClient$1, OrchestrationClient, OrchestrationClient as OrchestrationClient$1, PaymentRequestsClient } from "@otim/sdk-core/clients";
5
+ import { allSupportedChains as chains } from "@otim/utils/chains";
6
+
7
+ //#region src/client/server-client.d.ts
8
+
9
+ /**
10
+ * Otim Client for server-side blockchain operations.
11
+ *
12
+ * Provides access to authentication, configuration, delegation, and
13
+ * orchestration services.
14
+ * The client must be initialized before use by calling the init() method.
15
+
16
+ */
17
+ declare class OtimServerClient {
18
+ private readonly apiClient;
19
+ private readonly account;
20
+ private readonly context;
21
+ readonly auth: AuthClient$1;
22
+ readonly config: ConfigClient$1;
23
+ readonly delegation: DelegationClient$1;
24
+ readonly orchestration: OrchestrationClient$1;
25
+ constructor(config: ServerAccountConfig$1);
26
+ /**
27
+ * Initializes the Otim Client.
28
+ *
29
+ * This method must be called before using any other client methods.
30
+ * It sets up the authentication account and prepares the client for use.
31
+ *
32
+ * @throws {Error} If the account is already initialized
33
+ */
34
+ init(): Promise<void>;
35
+ }
36
+ //#endregion
37
+ //#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}`;
57
+ environment?: Environment$1;
58
+ }): OtimServerClient;
59
+ /**
60
+ * Creates an Otim Client for server-side operations with API authentication.
61
+ *
62
+ * @param config - Configuration with API credentials
63
+ * @returns Configured Otim Client instance
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: {
80
+ appId: string;
81
+ privateKey: `0x${string}`;
82
+ publicKey: string;
83
+ apiKey?: string;
84
+ environment?: Environment$1;
85
+ }): OtimServerClient;
86
+ //#endregion
87
+ export { type ActivatePaymentRequestParams, type ApiAccountConfig, AuthClient, ConfigClient, type CreatePaymentRequestParameters, type CreatePaymentRequestResponse, DelegationClient, Environment, type EnvironmentType, OrchestrationClient, type OtimAccount, OtimServerClient, type OtimServerClientContext, PaymentRequestsClient, type PrivateKeyAccountConfig, type ServerAccountConfig, type ServerAccountType, chains, createOtimServerClient };
88
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/client/server-client.ts","../src/client/create-server-client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AA0BA;;;AAOuB,cAPV,gBAAA,CAOU;EACG,iBAAA,SAAA;EAEJ,iBAAA,OAAA;EA2BN,iBAAA,OAAA;EAAO,SAAA,IAAA,EAhCN,YAgCM;mBA/BJ;uBACI;0BACG;ECXV,WAAA,CAAA,MAAA,EDaM,qBCXN;EAuBA;;;;;;;;UDeA;;;;;;;;;AArChB;;;;;;;;;;;ACHA;AAyBgB,iBAzBA,sBAAA,CA8BA,MAAA,EACZ;;gBA7BY;IACZ;;;;;;;;;;;;;;;;;;;;;iBAsBY,sBAAA;;;;;gBAKA;IACZ"}
@@ -0,0 +1,88 @@
1
+ import { Environment, Environment as Environment$1, EnvironmentType } from "@otim/sdk-core/config";
2
+ import { ActivatePaymentRequestParams, AuthClient, AuthClient as AuthClient$1, ConfigClient, ConfigClient as ConfigClient$1, CreatePaymentRequestParameters, CreatePaymentRequestResponse, DelegationClient, DelegationClient as DelegationClient$1, OrchestrationClient, OrchestrationClient as OrchestrationClient$1, PaymentRequestsClient } from "@otim/sdk-core/clients";
3
+ import { ApiAccountConfig, OtimAccount, PrivateKeyAccountConfig, ServerAccountConfig, ServerAccountConfig as ServerAccountConfig$1, ServerAccountType } from "@otim/sdk-core/account";
4
+ import { allSupportedChains as chains } from "@otim/utils/chains";
5
+ import { OtimServerClientContext } from "@otim/sdk-core/context";
6
+
7
+ //#region src/client/server-client.d.ts
8
+
9
+ /**
10
+ * Otim Client for server-side blockchain operations.
11
+ *
12
+ * Provides access to authentication, configuration, delegation, and
13
+ * orchestration services.
14
+ * The client must be initialized before use by calling the init() method.
15
+
16
+ */
17
+ declare class OtimServerClient {
18
+ private readonly apiClient;
19
+ private readonly account;
20
+ private readonly context;
21
+ readonly auth: AuthClient$1;
22
+ readonly config: ConfigClient$1;
23
+ readonly delegation: DelegationClient$1;
24
+ readonly orchestration: OrchestrationClient$1;
25
+ constructor(config: ServerAccountConfig$1);
26
+ /**
27
+ * Initializes the Otim Client.
28
+ *
29
+ * This method must be called before using any other client methods.
30
+ * It sets up the authentication account and prepares the client for use.
31
+ *
32
+ * @throws {Error} If the account is already initialized
33
+ */
34
+ init(): Promise<void>;
35
+ }
36
+ //#endregion
37
+ //#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}`;
57
+ environment?: Environment$1;
58
+ }): OtimServerClient;
59
+ /**
60
+ * Creates an Otim Client for server-side operations with API authentication.
61
+ *
62
+ * @param config - Configuration with API credentials
63
+ * @returns Configured Otim Client instance
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: {
80
+ appId: string;
81
+ privateKey: `0x${string}`;
82
+ publicKey: string;
83
+ apiKey?: string;
84
+ environment?: Environment$1;
85
+ }): OtimServerClient;
86
+ //#endregion
87
+ export { type ActivatePaymentRequestParams, type ApiAccountConfig, AuthClient, ConfigClient, type CreatePaymentRequestParameters, type CreatePaymentRequestResponse, DelegationClient, Environment, type EnvironmentType, OrchestrationClient, type OtimAccount, OtimServerClient, type OtimServerClientContext, PaymentRequestsClient, type PrivateKeyAccountConfig, type ServerAccountConfig, type ServerAccountType, chains, createOtimServerClient };
88
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/client/server-client.ts","../src/client/create-server-client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AA0BA;;;AAOuB,cAPV,gBAAA,CAOU;EACG,iBAAA,SAAA;EAEJ,iBAAA,OAAA;EA2BN,iBAAA,OAAA;EAAO,SAAA,IAAA,EAhCN,YAgCM;mBA/BJ;uBACI;0BACG;ECXV,WAAA,CAAA,MAAA,EDaM,qBCXN;EAuBA;;;;;;;;UDeA;;;;;;;;;AArChB;;;;;;;;;;;ACHA;AAyBgB,iBAzBA,sBAAA,CA8BA,MAAA,EACZ;;gBA7BY;IACZ;;;;;;;;;;;;;;;;;;;;;iBAsBY,sBAAA;;;;;gBAKA;IACZ"}
package/dist/index.mjs ADDED
@@ -0,0 +1,204 @@
1
+ import { Environment, Environment as Environment$1, env, getApiUrl, getTurnkeyApiUrl } from "@otim/sdk-core/config";
2
+ import { AuthClient, AuthClient as AuthClient$1, ConfigClient, ConfigClient as ConfigClient$1, DelegationClient, DelegationClient as DelegationClient$1, OrchestrationClient, OrchestrationClient as OrchestrationClient$1, PaymentRequestsClient } from "@otim/sdk-core/clients";
3
+ import { ServerAccountType, createClientContext, isApiAccountConfig } from "@otim/sdk-core/account";
4
+ import { APIClient, createInstance } from "@otim/utils/api";
5
+ import { ApiKeyStamper } from "@turnkey/api-key-stamper";
6
+ import { TurnkeyClient } from "@turnkey/http";
7
+ import { createAccount } from "@turnkey/viem";
8
+ import { privateKeyToAccount } from "viem/accounts";
9
+ import { allSupportedChains as chains } from "@otim/utils/chains";
10
+
11
+ //#region src/client/api-client.ts
12
+ /**
13
+ * Creates an API client for server-side requests.
14
+ *
15
+ * Configures the base URL and authentication headers for API communication.
16
+ *
17
+ * @param config - Optional configuration for the API client
18
+ * @returns Configured API client instance
19
+ *
20
+ * @internal
21
+ */
22
+ const createServerAPIClient = (config) => {
23
+ const { sessionToken, environment = Environment$1.Sandbox, ...restConfig } = config ?? {};
24
+ const instance = createInstance({
25
+ baseURL: getApiUrl(environment),
26
+ ...restConfig
27
+ });
28
+ instance.interceptors.request.use(async (requestConfig) => {
29
+ if (sessionToken) {
30
+ requestConfig.headers = requestConfig.headers ?? {};
31
+ const authorizationToken = sessionToken.startsWith("Bearer ") ? sessionToken : `Bearer ${sessionToken}`;
32
+ requestConfig.headers.Authorization = authorizationToken;
33
+ }
34
+ return requestConfig;
35
+ });
36
+ return new APIClient({ instance });
37
+ };
38
+
39
+ //#endregion
40
+ //#region src/client/utils/asserts.ts
41
+ function assertDefined(value, errorMessage) {
42
+ if (value === null || value === void 0) throw new Error(errorMessage);
43
+ }
44
+
45
+ //#endregion
46
+ //#region \0@oxc-project+runtime@0.97.0/helpers/typeof.js
47
+ function _typeof(o) {
48
+ "@babel/helpers - typeof";
49
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
50
+ return typeof o$1;
51
+ } : function(o$1) {
52
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
53
+ }, _typeof(o);
54
+ }
55
+
56
+ //#endregion
57
+ //#region \0@oxc-project+runtime@0.97.0/helpers/toPrimitive.js
58
+ function toPrimitive(t, r) {
59
+ if ("object" != _typeof(t) || !t) return t;
60
+ var e = t[Symbol.toPrimitive];
61
+ if (void 0 !== e) {
62
+ var i = e.call(t, r || "default");
63
+ if ("object" != _typeof(i)) return i;
64
+ throw new TypeError("@@toPrimitive must return a primitive value.");
65
+ }
66
+ return ("string" === r ? String : Number)(t);
67
+ }
68
+
69
+ //#endregion
70
+ //#region \0@oxc-project+runtime@0.97.0/helpers/toPropertyKey.js
71
+ function toPropertyKey(t) {
72
+ var i = toPrimitive(t, "string");
73
+ return "symbol" == _typeof(i) ? i : i + "";
74
+ }
75
+
76
+ //#endregion
77
+ //#region \0@oxc-project+runtime@0.97.0/helpers/defineProperty.js
78
+ function _defineProperty(e, r, t) {
79
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
80
+ value: t,
81
+ enumerable: !0,
82
+ configurable: !0,
83
+ writable: !0
84
+ }) : e[r] = t, e;
85
+ }
86
+
87
+ //#endregion
88
+ //#region src/client/server-account.ts
89
+ const createApiAccount = async (config) => {
90
+ const stamper = new ApiKeyStamper({
91
+ apiPublicKey: config.publicKey,
92
+ apiPrivateKey: config.privateKey
93
+ });
94
+ const client = new TurnkeyClient({ baseUrl: getTurnkeyApiUrl(env.ENVIRONMENT) }, stamper);
95
+ const account = await createAccount({
96
+ organizationId: config.appId,
97
+ signWith: "0xB54c8E6f303627f392884412ED2C84fFaF4779CA",
98
+ client
99
+ });
100
+ return { signMessage: (args) => account.signMessage(args) };
101
+ };
102
+ const createPrivateKeyAccount = (config) => {
103
+ const account = privateKeyToAccount(config.privateKey);
104
+ return { signMessage: (args) => account.signMessage(args) };
105
+ };
106
+ const initializeAccount = async (config) => {
107
+ switch (config.type) {
108
+ case ServerAccountType.Api: return createApiAccount(config);
109
+ case ServerAccountType.PrivateKey: return createPrivateKeyAccount(config);
110
+ default: {
111
+ const exhaustiveCheck = config;
112
+ throw new Error(`Unsupported account type: "${exhaustiveCheck.type}". Supported types are: ${Object.values(ServerAccountType).join(", ")}`);
113
+ }
114
+ }
115
+ };
116
+ /**
117
+ * Server-side account implementation for signing operations.
118
+ *
119
+ * Supports both private key and API authentication methods.
120
+ *
121
+ * @internal
122
+ */
123
+ var OtimAccount = class {
124
+ constructor(config) {
125
+ this.config = config;
126
+ _defineProperty(this, "account", null);
127
+ _defineProperty(this, "initialized", false);
128
+ }
129
+ async initialize() {
130
+ if (this.initialized) throw new Error("Account already initialized. The initialize() method should only be called once.");
131
+ this.account = await initializeAccount(this.config);
132
+ this.initialized = true;
133
+ }
134
+ async signMessage({ message }) {
135
+ assertDefined(this.account, "Account not initialized. Call initialize() before using signMessage().");
136
+ return this.account.signMessage({ message });
137
+ }
138
+ };
139
+
140
+ //#endregion
141
+ //#region src/client/server-client.ts
142
+ /**
143
+ * Otim Client for server-side blockchain operations.
144
+ *
145
+ * Provides access to authentication, configuration, delegation, and
146
+ * orchestration services.
147
+ * The client must be initialized before use by calling the init() method.
148
+
149
+ */
150
+ var OtimServerClient = class {
151
+ constructor(config) {
152
+ _defineProperty(this, "apiClient", void 0);
153
+ _defineProperty(this, "account", void 0);
154
+ _defineProperty(this, "context", void 0);
155
+ _defineProperty(this, "auth", void 0);
156
+ _defineProperty(this, "config", void 0);
157
+ _defineProperty(this, "delegation", void 0);
158
+ _defineProperty(this, "orchestration", void 0);
159
+ this.context = createClientContext(config);
160
+ this.apiClient = createServerAPIClient({
161
+ environment: config.environment,
162
+ ...isApiAccountConfig(config) ? { sessionToken: config.apiKey } : {}
163
+ });
164
+ this.account = new OtimAccount(config);
165
+ this.auth = new AuthClient$1(this.apiClient, this.account, this.context);
166
+ this.config = new ConfigClient$1(this.apiClient);
167
+ this.delegation = new DelegationClient$1(this.apiClient);
168
+ this.orchestration = new OrchestrationClient$1(this.apiClient, this.account, this.context);
169
+ }
170
+ /**
171
+ * Initializes the Otim Client.
172
+ *
173
+ * This method must be called before using any other client methods.
174
+ * It sets up the authentication account and prepares the client for use.
175
+ *
176
+ * @throws {Error} If the account is already initialized
177
+ */
178
+ async init() {
179
+ await this.account.initialize();
180
+ }
181
+ };
182
+
183
+ //#endregion
184
+ //#region src/client/create-server-client.ts
185
+ function createOtimServerClient(config) {
186
+ if (config.appId && config.privateKey && config.publicKey && config.apiKey) return new OtimServerClient({
187
+ type: ServerAccountType.Api,
188
+ appId: config.appId,
189
+ privateKey: config.privateKey,
190
+ publicKey: config.publicKey,
191
+ apiKey: config.apiKey,
192
+ environment: config.environment
193
+ });
194
+ if (config.privateKey) return new OtimServerClient({
195
+ type: ServerAccountType.PrivateKey,
196
+ privateKey: config.privateKey,
197
+ environment: config.environment
198
+ });
199
+ throw new Error("Invalid Otim Server Client configuration");
200
+ }
201
+
202
+ //#endregion
203
+ export { AuthClient, ConfigClient, DelegationClient, Environment, OrchestrationClient, OtimServerClient, PaymentRequestsClient, chains, createOtimServerClient };
204
+ //# sourceMappingURL=index.mjs.map