@otim/sdk-core 0.0.6 → 0.0.10
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/.tsbuildinfo +1 -1
- package/dist/account/index.cjs +1 -1
- package/dist/{account-CRvC_dXT.cjs → account-Bwm5PTcc.cjs} +3 -8
- package/dist/account-Bwm5PTcc.cjs.map +1 -0
- package/dist/clients/index.cjs +4 -1
- package/dist/{clients-xn1jUwXu.cjs → clients-CeCv_iST.cjs} +64 -29
- package/dist/clients-CeCv_iST.cjs.map +1 -0
- package/dist/config/index.cjs +1 -1
- package/dist/{config-CjGpscVk.cjs → config-BrvU6CD_.cjs} +2 -2
- package/dist/{config-CjGpscVk.cjs.map → config-BrvU6CD_.cjs.map} +1 -1
- package/dist/context/index.cjs +1 -1
- package/dist/{context-B-Wcmhb3.cjs → context-DK5bXjx4.cjs} +1 -1
- package/dist/{context-B-Wcmhb3.cjs.map → context-DK5bXjx4.cjs.map} +1 -1
- package/dist/index.cjs +18 -9
- package/dist/signing/index.cjs +10 -0
- package/dist/signing-BaJMYH0K.cjs +1096 -0
- package/dist/signing-BaJMYH0K.cjs.map +1 -0
- package/dist/utils/index.cjs +5 -5
- package/dist/{utils-CVQFvsfl.cjs → vrs-Do0jfo3H.cjs} +1 -1
- package/dist/vrs-Do0jfo3H.cjs.map +1 -0
- package/package.json +17 -5
- package/dist/abi-DW6AS0eM.d.mts +0 -339
- package/dist/abi-DW6AS0eM.d.mts.map +0 -1
- package/dist/abi-OUq-mx1W.d.cts +0 -339
- package/dist/abi-OUq-mx1W.d.cts.map +0 -1
- package/dist/account/index.d.cts +0 -5
- package/dist/account/index.d.mts +0 -5
- package/dist/account/index.mjs +0 -3
- package/dist/account-CRvC_dXT.cjs.map +0 -1
- package/dist/account-D1NVta26.mjs +0 -31
- package/dist/account-D1NVta26.mjs.map +0 -1
- package/dist/authorization-6anhDdQX.d.cts +0 -210
- package/dist/authorization-6anhDdQX.d.cts.map +0 -1
- package/dist/authorization-DnNpWjxB.d.mts +0 -210
- package/dist/authorization-DnNpWjxB.d.mts.map +0 -1
- package/dist/clients/index.d.cts +0 -3
- package/dist/clients/index.d.mts +0 -3
- package/dist/clients/index.mjs +0 -3
- package/dist/clients-I_vhy7eF.mjs +0 -214
- package/dist/clients-I_vhy7eF.mjs.map +0 -1
- package/dist/clients-xn1jUwXu.cjs.map +0 -1
- package/dist/config/index.d.cts +0 -3
- package/dist/config/index.d.mts +0 -3
- package/dist/config/index.mjs +0 -3
- package/dist/config-C_nc1DXn.mjs +0 -67
- package/dist/config-C_nc1DXn.mjs.map +0 -1
- package/dist/context/index.d.cts +0 -5
- package/dist/context/index.d.mts +0 -5
- package/dist/context/index.mjs +0 -3
- package/dist/context-uTye69B0.mjs +0 -20
- package/dist/context-uTye69B0.mjs.map +0 -1
- package/dist/index-BQMXYh9N.d.cts +0 -14
- package/dist/index-BQMXYh9N.d.cts.map +0 -1
- package/dist/index-C5c51xs0.d.mts +0 -51
- package/dist/index-C5c51xs0.d.mts.map +0 -1
- package/dist/index-C8H-BPGH.d.cts +0 -51
- package/dist/index-C8H-BPGH.d.cts.map +0 -1
- package/dist/index-CBQ5I-Uz.d.cts +0 -103
- package/dist/index-CBQ5I-Uz.d.cts.map +0 -1
- package/dist/index-CnjY7cyS.d.mts +0 -14
- package/dist/index-CnjY7cyS.d.mts.map +0 -1
- package/dist/index-D8OoAxEI.d.mts +0 -103
- package/dist/index-D8OoAxEI.d.mts.map +0 -1
- package/dist/index-DWE1xfOE.d.mts +0 -23
- package/dist/index-DWE1xfOE.d.mts.map +0 -1
- package/dist/index-D_7CTJDl.d.mts +0 -27
- package/dist/index-D_7CTJDl.d.mts.map +0 -1
- package/dist/index-GSspyLr3.d.cts +0 -23
- package/dist/index-GSspyLr3.d.cts.map +0 -1
- package/dist/index-lW-Oor1B.d.cts +0 -27
- package/dist/index-lW-Oor1B.d.cts.map +0 -1
- package/dist/index.d.cts +0 -9
- package/dist/index.d.mts +0 -9
- package/dist/index.mjs +0 -7
- package/dist/rpc-BDoNl1Sp.d.cts +0 -6885
- package/dist/rpc-BDoNl1Sp.d.cts.map +0 -1
- package/dist/rpc-CygBD_f7.d.mts +0 -6885
- package/dist/rpc-CygBD_f7.d.mts.map +0 -1
- package/dist/utils/index.d.cts +0 -4
- package/dist/utils/index.d.mts +0 -4
- package/dist/utils/index.mjs +0 -3
- package/dist/utils-CVQFvsfl.cjs.map +0 -1
- package/dist/utils-DziAHBiz.mjs +0 -81
- package/dist/utils-DziAHBiz.mjs.map +0 -1
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { parseSignatureToVRS, validateIso8601Date } from "@otim/utils/helpers";
|
|
2
|
-
import { createLoginSiweMessage } from "@otim/sdk-core/config";
|
|
3
|
-
import { assertRequiresAuth, assertServerContext } from "@otim/sdk-core/context";
|
|
4
|
-
import { getChainById } from "@otim/utils/chains";
|
|
5
|
-
import { addActionNamesToInstructions, buildPaymentMetadata, extractActionNamesMap } from "@otim/utils/payments";
|
|
6
|
-
import { hexStringSchema } from "@otim/utils/schemas";
|
|
7
|
-
import { createPublicClient, createWalletClient, http } from "viem";
|
|
8
|
-
import { ApiKeyClientSigningService, ServerWalletSigningService, UnifiedPaymentSigner } from "@otim/turnkey/signing";
|
|
9
|
-
import { privateKeyToAccount } from "viem/accounts";
|
|
10
|
-
import { isApiAccountConfig } from "@otim/sdk-core/account";
|
|
11
|
-
|
|
12
|
-
//#region src/clients/activity.ts
|
|
13
|
-
var ActivityClient = class {
|
|
14
|
-
constructor(apiClient) {
|
|
15
|
-
this.apiClient = apiClient;
|
|
16
|
-
}
|
|
17
|
-
async getInstructionActivity(request) {
|
|
18
|
-
return (await this.apiClient.activity.getInstructionActivity(request)).data;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/clients/auth.ts
|
|
24
|
-
var AuthClient = class {
|
|
25
|
-
constructor(apiClient, account, context) {
|
|
26
|
-
this.apiClient = apiClient;
|
|
27
|
-
this.account = account;
|
|
28
|
-
this.context = context;
|
|
29
|
-
}
|
|
30
|
-
async login({ address }) {
|
|
31
|
-
assertRequiresAuth(this.context);
|
|
32
|
-
const message = createLoginSiweMessage(address, Date.now().toString());
|
|
33
|
-
const vrsParsedSignature = parseSignatureToVRS(await this.account.signMessage({ message }));
|
|
34
|
-
return (await this.apiClient.auth.login({
|
|
35
|
-
siwe: message,
|
|
36
|
-
signature: vrsParsedSignature
|
|
37
|
-
})).data;
|
|
38
|
-
}
|
|
39
|
-
async getCurrentUser() {
|
|
40
|
-
return (await this.apiClient.auth.me()).data;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/clients/config.ts
|
|
46
|
-
var ConfigClient = class {
|
|
47
|
-
constructor(apiClient) {
|
|
48
|
-
this.apiClient = apiClient;
|
|
49
|
-
}
|
|
50
|
-
async getMaxPriorityFeeEstimate({ chainId }) {
|
|
51
|
-
return (await this.apiClient.config.getMaxPriorityFeePerGasEstimate({ chainId })).data;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region src/clients/delegation.ts
|
|
57
|
-
var DelegationClient = class {
|
|
58
|
-
constructor(apiClient) {
|
|
59
|
-
this.apiClient = apiClient;
|
|
60
|
-
}
|
|
61
|
-
async getDelegateAddress({ chainId }) {
|
|
62
|
-
return (await this.apiClient.config.getDelegateAddress({ chainId })).data;
|
|
63
|
-
}
|
|
64
|
-
async getDelegationStatus(options) {
|
|
65
|
-
return (await this.apiClient.account.getDelegationStatus({
|
|
66
|
-
address: options.address,
|
|
67
|
-
chainId: options.chainId
|
|
68
|
-
})).data;
|
|
69
|
-
}
|
|
70
|
-
async createDelegation(delegationRequest) {
|
|
71
|
-
await this.apiClient.account.createDelegation(delegationRequest);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/clients/helpers/settlement-signer.ts
|
|
77
|
-
async function createSettlementSigner(params) {
|
|
78
|
-
const { context, buildResponse, publicClient, delegateAddressMap } = params;
|
|
79
|
-
if (isApiAccountConfig(context.config)) return new UnifiedPaymentSigner({
|
|
80
|
-
buildResponse,
|
|
81
|
-
signingService: new ApiKeyClientSigningService(context.config.publicKey, context.config.privateKey),
|
|
82
|
-
publicClient,
|
|
83
|
-
delegateAddressMap
|
|
84
|
-
}).signAll();
|
|
85
|
-
const walletClient = createWalletClient({
|
|
86
|
-
account: privateKeyToAccount(context.config.privateKey),
|
|
87
|
-
transport: http()
|
|
88
|
-
});
|
|
89
|
-
return new UnifiedPaymentSigner({
|
|
90
|
-
buildResponse,
|
|
91
|
-
signingService: ServerWalletSigningService.fromViemWallet(walletClient),
|
|
92
|
-
publicClient,
|
|
93
|
-
delegateAddressMap
|
|
94
|
-
}).signAll();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
//#endregion
|
|
98
|
-
//#region src/clients/orchestration.ts
|
|
99
|
-
var OrchestrationClient = class {
|
|
100
|
-
constructor(apiClient, account, context) {
|
|
101
|
-
this.apiClient = apiClient;
|
|
102
|
-
this.account = account;
|
|
103
|
-
this.context = context;
|
|
104
|
-
}
|
|
105
|
-
async create(preparedSettlement) {
|
|
106
|
-
assertServerContext(this.context);
|
|
107
|
-
const buildResponse = (await this.apiClient.payments.buildSettlementOrchestration(preparedSettlement)).data;
|
|
108
|
-
await this.activate(buildResponse, preparedSettlement.settlementChain);
|
|
109
|
-
return {
|
|
110
|
-
requestId: buildResponse.requestId,
|
|
111
|
-
ephemeralWalletAddress: buildResponse.ephemeralWalletAddress
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
async createRaw(payload, config) {
|
|
115
|
-
assertServerContext(this.context);
|
|
116
|
-
const { settlementChainId, activate = true } = config;
|
|
117
|
-
const buildResponse = await this.buildAndEnhanceSettlement(payload);
|
|
118
|
-
if (!activate) return buildResponse;
|
|
119
|
-
await this.activate(buildResponse, settlementChainId);
|
|
120
|
-
return {
|
|
121
|
-
requestId: buildResponse.requestId,
|
|
122
|
-
ephemeralWalletAddress: buildResponse.ephemeralWalletAddress
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
async getDetails(request) {
|
|
126
|
-
return this.apiClient.payments.getPaymentRequestDetails(request);
|
|
127
|
-
}
|
|
128
|
-
async list(request) {
|
|
129
|
-
return this.apiClient.payments.getPaymentRequests(request);
|
|
130
|
-
}
|
|
131
|
-
async activate(buildResponse, settlementChainId) {
|
|
132
|
-
const publicClient = this.createPublicClient(settlementChainId);
|
|
133
|
-
const instructions = [...buildResponse.completionInstructions, ...buildResponse.instructions];
|
|
134
|
-
const delegateAddressMap = await this.fetchDelegateAddresses(instructions);
|
|
135
|
-
const { signedAuthorization, completionInstructions, instructions: signedInstructions } = await createSettlementSigner({
|
|
136
|
-
context: this.context,
|
|
137
|
-
buildResponse,
|
|
138
|
-
publicClient,
|
|
139
|
-
delegateAddressMap
|
|
140
|
-
});
|
|
141
|
-
await this.apiClient.payments.newPaymentRequest({
|
|
142
|
-
requestId: buildResponse.requestId,
|
|
143
|
-
signedAuthorization,
|
|
144
|
-
completionInstructions,
|
|
145
|
-
instructions: signedInstructions
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
async buildAndEnhanceSettlement(payload) {
|
|
149
|
-
const actionNames = extractActionNamesMap(payload.completionInstructions, payload.instructions);
|
|
150
|
-
return addActionNamesToInstructions((await this.apiClient.payments.buildPaymentRequest(payload)).data, actionNames);
|
|
151
|
-
}
|
|
152
|
-
createPublicClient(chainId) {
|
|
153
|
-
const chain = getChainById(chainId);
|
|
154
|
-
if (!chain) throw new Error(`Chain with id ${chainId} not found`);
|
|
155
|
-
return createPublicClient({
|
|
156
|
-
chain,
|
|
157
|
-
transport: http()
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
async fetchDelegateAddresses(instructions) {
|
|
161
|
-
const chainIds = Array.from(new Set(instructions.map((instruction) => instruction.chainId)));
|
|
162
|
-
const addresses = await Promise.all(chainIds.map(async (chainId) => {
|
|
163
|
-
const response = await this.apiClient.config.getDelegateAddress({ chainId });
|
|
164
|
-
return [chainId, hexStringSchema.parse(response.data.otimDelegateAddress)];
|
|
165
|
-
}));
|
|
166
|
-
return new Map(addresses);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
//#endregion
|
|
171
|
-
//#region src/clients/helpers/prepare-settlement.ts
|
|
172
|
-
function buildMetadataFromParams(params) {
|
|
173
|
-
const { amount, recipient, token, note, dueDate, customMetadata } = params;
|
|
174
|
-
const metadataWithToken = {
|
|
175
|
-
...buildPaymentMetadata({
|
|
176
|
-
tokenSymbol: "",
|
|
177
|
-
amountInUSD: amount,
|
|
178
|
-
fromAccountAddress: recipient,
|
|
179
|
-
note,
|
|
180
|
-
dueDate,
|
|
181
|
-
hasInvoiceMetadata: false
|
|
182
|
-
}),
|
|
183
|
-
token
|
|
184
|
-
};
|
|
185
|
-
return customMetadata ? {
|
|
186
|
-
...metadataWithToken,
|
|
187
|
-
...customMetadata
|
|
188
|
-
} : metadataWithToken;
|
|
189
|
-
}
|
|
190
|
-
function prepareSettlement(params) {
|
|
191
|
-
const { chainId, token, acceptedTokens, recipient, amount, payer, note, dueDate, metadata: customMetadata, maxRuns } = params;
|
|
192
|
-
if (dueDate) validateIso8601Date(dueDate);
|
|
193
|
-
return {
|
|
194
|
-
acceptedTokens,
|
|
195
|
-
settlementChain: chainId,
|
|
196
|
-
settlementToken: token,
|
|
197
|
-
settlementAmount: amount,
|
|
198
|
-
recipientAddress: recipient,
|
|
199
|
-
metadata: buildMetadataFromParams({
|
|
200
|
-
amount,
|
|
201
|
-
recipient,
|
|
202
|
-
token,
|
|
203
|
-
note,
|
|
204
|
-
dueDate,
|
|
205
|
-
customMetadata
|
|
206
|
-
}),
|
|
207
|
-
payerAddress: payer ?? null,
|
|
208
|
-
maxRuns
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
//#endregion
|
|
213
|
-
export { AuthClient as a, ConfigClient as i, OrchestrationClient as n, ActivityClient as o, DelegationClient as r, prepareSettlement as t };
|
|
214
|
-
//# sourceMappingURL=clients-I_vhy7eF.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients-I_vhy7eF.mjs","names":["apiClient: APIClient","apiClient: APIClient","account: OtimAccount","context: OtimClientContext","apiClient: APIClient","apiClient: APIClient","apiClient: APIClient","account: OtimAccount","context: OtimServerClientContext"],"sources":["../src/clients/activity.ts","../src/clients/auth.ts","../src/clients/config.ts","../src/clients/delegation.ts","../src/clients/helpers/settlement-signer.ts","../src/clients/orchestration.ts","../src/clients/helpers/prepare-settlement.ts"],"sourcesContent":["import type {\n APIClient,\n GetInstructionActivityRequest,\n GetInstructionActivityResponse,\n} from \"@otim/utils/api\";\n\nexport class ActivityClient {\n constructor(private readonly apiClient: APIClient) {}\n\n async getInstructionActivity(\n request: GetInstructionActivityRequest,\n ): Promise<GetInstructionActivityResponse> {\n const response =\n await this.apiClient.activity.getInstructionActivity(request);\n\n return response.data;\n }\n}\n","import type { OtimAccount } from \"@otim/sdk-core/account\";\nimport type { OtimClientContext } from \"@otim/sdk-core/context\";\nimport type { APIClient, AuthLoginResponse, MeResponse } from \"@otim/utils/api\";\nimport type { Address } from \"viem\";\n\nimport { parseSignatureToVRS } from \"@otim/utils/helpers\";\n\nimport { createLoginSiweMessage } from \"@otim/sdk-core/config\";\nimport { assertRequiresAuth } from \"@otim/sdk-core/context\";\n\nexport interface LoginOptions {\n address: Address;\n}\n\nexport class AuthClient {\n constructor(\n private readonly apiClient: APIClient,\n private readonly account: OtimAccount,\n private readonly context: OtimClientContext,\n ) {}\n\n async login({ address }: LoginOptions): Promise<AuthLoginResponse> {\n assertRequiresAuth(this.context);\n\n const message = createLoginSiweMessage(address, Date.now().toString());\n const signature = await this.account.signMessage({ message });\n const vrsParsedSignature = parseSignatureToVRS(signature);\n\n const response = await this.apiClient.auth.login({\n siwe: message,\n signature: vrsParsedSignature,\n });\n\n return response.data;\n }\n\n async getCurrentUser(): Promise<MeResponse> {\n const response = await this.apiClient.auth.me();\n return response.data;\n }\n}\n","import type {\n APIClient,\n GetMaxPriorityFeePerGasEstimateRequest,\n GetMaxPriorityFeePerGasEstimateResponse,\n} from \"@otim/utils/api\";\n\nexport class ConfigClient {\n constructor(private readonly apiClient: APIClient) {}\n\n async getMaxPriorityFeeEstimate({\n chainId,\n }: GetMaxPriorityFeePerGasEstimateRequest): Promise<GetMaxPriorityFeePerGasEstimateResponse> {\n const response =\n await this.apiClient.config.getMaxPriorityFeePerGasEstimate({ chainId });\n\n return response.data;\n }\n}\n","import type {\n APIClient,\n DelegationCreateRequest,\n DelegationStatusRequest,\n DelegationStatusResponse,\n GetDelegateAddressRequest,\n GetDelegateAddressResponse,\n} from \"@otim/utils/api\";\n\nexport class DelegationClient {\n constructor(private readonly apiClient: APIClient) {}\n\n async getDelegateAddress({\n chainId,\n }: GetDelegateAddressRequest): Promise<GetDelegateAddressResponse> {\n const response = await this.apiClient.config.getDelegateAddress({\n chainId,\n });\n\n return response.data;\n }\n\n async getDelegationStatus(\n options: DelegationStatusRequest,\n ): Promise<DelegationStatusResponse> {\n const response = await this.apiClient.account.getDelegationStatus({\n address: options.address,\n chainId: options.chainId,\n });\n\n return response.data;\n }\n\n async createDelegation(\n delegationRequest: DelegationCreateRequest,\n ): Promise<void> {\n await this.apiClient.account.createDelegation(delegationRequest);\n }\n}\n","import type { OtimServerClientContext } from \"@otim/sdk-core/context\";\nimport type { PaymentResponseWithActionNames } from \"@otim/utils/payments\";\nimport type { Address } from \"@otim/utils/schemas\";\nimport type { PublicClient } from \"viem\";\n\nimport {\n ApiKeyClientSigningService,\n ServerWalletSigningService,\n UnifiedPaymentSigner,\n} from \"@otim/turnkey/signing\";\nimport { createWalletClient, http } from \"viem\";\nimport { privateKeyToAccount } from \"viem/accounts\";\n\nimport { isApiAccountConfig } from \"@otim/sdk-core/account\";\n\nexport interface CreateSettlementSignerParams {\n context: OtimServerClientContext;\n buildResponse: PaymentResponseWithActionNames;\n publicClient: PublicClient;\n delegateAddressMap: Map<number, Address>;\n}\n\ntype CreateSettlementSignerResult = Awaited<\n ReturnType<UnifiedPaymentSigner[\"signAll\"]>\n>;\n\nexport async function createSettlementSigner(\n params: CreateSettlementSignerParams,\n): Promise<CreateSettlementSignerResult> {\n const { context, buildResponse, publicClient, delegateAddressMap } = params;\n\n if (isApiAccountConfig(context.config)) {\n const signingService = new ApiKeyClientSigningService(\n context.config.publicKey,\n context.config.privateKey,\n );\n\n const signer = new UnifiedPaymentSigner({\n buildResponse,\n signingService,\n publicClient,\n delegateAddressMap,\n });\n\n return signer.signAll();\n }\n\n const account = privateKeyToAccount(context.config.privateKey);\n const walletClient = createWalletClient({\n account,\n transport: http(),\n });\n\n const signingService =\n ServerWalletSigningService.fromViemWallet(walletClient);\n\n const signer = new UnifiedPaymentSigner({\n buildResponse,\n signingService,\n publicClient,\n delegateAddressMap,\n });\n\n return signer.signAll();\n}\n","import type { PreparedSettlement } from \"./helpers/prepare-settlement\";\nimport type { OtimAccount } from \"@otim/sdk-core/account\";\nimport type { OtimServerClientContext } from \"@otim/sdk-core/context\";\nimport type {\n APIClient,\n GetPaymentRequestsRequest,\n GetPaymentRequestsResponse,\n PaginatedServiceResponse,\n PaymentRequestBuildRequest,\n PaymentRequestDetailsRequest,\n PaymentRequestDetailsResponse,\n ServiceResponse,\n} from \"@otim/utils/api\";\nimport type { PaymentResponseWithActionNames } from \"@otim/utils/payments\";\nimport type { Address } from \"@otim/utils/schemas\";\nimport type { PublicClient } from \"viem\";\n\nimport { getChainById } from \"@otim/utils/chains\";\nimport {\n addActionNamesToInstructions,\n extractActionNamesMap,\n} from \"@otim/utils/payments\";\nimport { hexStringSchema } from \"@otim/utils/schemas\";\nimport { createPublicClient, http } from \"viem\";\n\nimport { assertServerContext } from \"@otim/sdk-core/context\";\n\nimport { createSettlementSigner } from \"./helpers/settlement-signer\";\n\nexport type { PreparedSettlement } from \"./helpers/prepare-settlement\";\n\nexport interface CreateSettlementResponse {\n requestId: string;\n ephemeralWalletAddress: Address;\n}\n\nexport interface CreateRawConfig {\n settlementChainId: number;\n activate?: boolean;\n}\n\ntype SettlementInstruction =\n PaymentResponseWithActionNames[\"completionInstructions\"][number];\n\nexport class OrchestrationClient {\n constructor(\n private readonly apiClient: APIClient,\n private readonly account: OtimAccount,\n private readonly context: OtimServerClientContext,\n ) {}\n\n async create(\n preparedSettlement: PreparedSettlement,\n ): Promise<CreateSettlementResponse> {\n assertServerContext(this.context);\n\n const response =\n await this.apiClient.payments.buildSettlementOrchestration(\n preparedSettlement,\n );\n const buildResponse = response.data;\n\n await this.activate(buildResponse, preparedSettlement.settlementChain);\n\n return {\n requestId: buildResponse.requestId,\n ephemeralWalletAddress: buildResponse.ephemeralWalletAddress,\n };\n }\n\n async createRaw(\n payload: PaymentRequestBuildRequest,\n config: CreateRawConfig,\n ): Promise<CreateSettlementResponse | PaymentResponseWithActionNames> {\n assertServerContext(this.context);\n\n const { settlementChainId, activate = true } = config;\n const buildResponse = await this.buildAndEnhanceSettlement(payload);\n\n if (!activate) {\n return buildResponse;\n }\n\n await this.activate(buildResponse, settlementChainId);\n\n return {\n requestId: buildResponse.requestId,\n ephemeralWalletAddress: buildResponse.ephemeralWalletAddress,\n };\n }\n\n async getDetails(\n request: PaymentRequestDetailsRequest,\n ): Promise<ServiceResponse<PaymentRequestDetailsResponse>> {\n return this.apiClient.payments.getPaymentRequestDetails(request);\n }\n\n async list(\n request: GetPaymentRequestsRequest,\n ): Promise<PaginatedServiceResponse<GetPaymentRequestsResponse>> {\n return this.apiClient.payments.getPaymentRequests(request);\n }\n\n private async activate(\n buildResponse: PaymentResponseWithActionNames,\n settlementChainId: number,\n ): Promise<void> {\n const publicClient = this.createPublicClient(settlementChainId);\n\n const instructions = [\n ...buildResponse.completionInstructions,\n ...buildResponse.instructions,\n ];\n\n const delegateAddressMap = await this.fetchDelegateAddresses(instructions);\n\n const {\n signedAuthorization,\n completionInstructions,\n instructions: signedInstructions,\n } = await createSettlementSigner({\n context: this.context,\n buildResponse,\n publicClient,\n delegateAddressMap,\n });\n\n await this.apiClient.payments.newPaymentRequest({\n requestId: buildResponse.requestId,\n signedAuthorization,\n completionInstructions,\n instructions: signedInstructions,\n });\n }\n\n private async buildAndEnhanceSettlement(\n payload: PaymentRequestBuildRequest,\n ): Promise<PaymentResponseWithActionNames> {\n const actionNames = extractActionNamesMap(\n payload.completionInstructions,\n payload.instructions,\n );\n\n const response = await this.apiClient.payments.buildPaymentRequest(payload);\n\n return addActionNamesToInstructions(response.data, actionNames);\n }\n\n private createPublicClient(chainId: number): PublicClient {\n const chain = getChainById(chainId);\n if (!chain) {\n throw new Error(`Chain with id ${chainId} not found`);\n }\n\n return createPublicClient({ chain, transport: http() });\n }\n\n private async fetchDelegateAddresses(\n instructions: SettlementInstruction[],\n ): Promise<Map<number, Address>> {\n const chainIds = Array.from(\n new Set(instructions.map((instruction) => instruction.chainId)),\n );\n\n const addresses = await Promise.all(\n chainIds.map(async (chainId) => {\n const response = await this.apiClient.config.getDelegateAddress({\n chainId,\n });\n const address = hexStringSchema.parse(\n response.data.otimDelegateAddress,\n );\n return [chainId, address] as const;\n }),\n );\n\n return new Map(addresses);\n }\n}\n","import type { SupportedChainId } from \"@otim/utils/chains\";\nimport type { Nullable } from \"@otim/utils/helpers\";\nimport type { PaymentRequestMetadata } from \"@otim/utils/payments\";\nimport type { Address } from \"@otim/utils/schemas\";\n\nimport { validateIso8601Date } from \"@otim/utils/helpers\";\nimport { buildPaymentMetadata } from \"@otim/utils/payments\";\n\nexport interface PrepareSettlementParams {\n amount: number;\n chainId: SupportedChainId;\n recipient: Address;\n token: Address;\n acceptedTokens: Record<number, Address[]>;\n payer?: Nullable<Address>;\n dueDate?: string;\n metadata?: PaymentRequestMetadata;\n note?: string;\n maxRuns?: number;\n}\n\nexport interface PreparedSettlement {\n acceptedTokens: Record<number, Address[]>;\n settlementChain: number;\n settlementToken: Address;\n settlementAmount: number;\n recipientAddress: Address;\n metadata: Record<string, unknown>;\n payerAddress?: Address | null;\n dueDate?: string;\n maxRuns?: number;\n}\n\nfunction buildMetadataFromParams(params: {\n amount: number;\n recipient: Address;\n token: Address;\n note?: string;\n dueDate?: string;\n customMetadata?: PaymentRequestMetadata;\n}): PaymentRequestMetadata {\n const { amount, recipient, token, note, dueDate, customMetadata } = params;\n\n const baseMetadata = buildPaymentMetadata({\n tokenSymbol: \"\",\n amountInUSD: amount,\n fromAccountAddress: recipient,\n note,\n dueDate,\n hasInvoiceMetadata: false,\n });\n\n const metadataWithToken = { ...baseMetadata, token };\n\n return customMetadata\n ? { ...metadataWithToken, ...customMetadata }\n : metadataWithToken;\n}\n\nexport function prepareSettlement(\n params: PrepareSettlementParams,\n): PreparedSettlement {\n const {\n chainId,\n token,\n acceptedTokens,\n recipient,\n amount,\n payer,\n note,\n dueDate,\n metadata: customMetadata,\n maxRuns,\n } = params;\n\n if (dueDate) {\n validateIso8601Date(dueDate);\n }\n\n const metadata = buildMetadataFromParams({\n amount,\n recipient,\n token,\n note,\n dueDate,\n customMetadata,\n });\n\n return {\n acceptedTokens,\n settlementChain: chainId,\n settlementToken: token,\n settlementAmount: amount,\n recipientAddress: recipient,\n metadata,\n payerAddress: payer ?? null,\n maxRuns,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAMA,IAAa,iBAAb,MAA4B;CAC1B,YAAY,AAAiBA,WAAsB;EAAtB;;CAE7B,MAAM,uBACJ,SACyC;AAIzC,UAFE,MAAM,KAAK,UAAU,SAAS,uBAAuB,QAAQ,EAE/C;;;;;;ACDpB,IAAa,aAAb,MAAwB;CACtB,YACE,AAAiBC,WACjB,AAAiBC,SACjB,AAAiBC,SACjB;EAHiB;EACA;EACA;;CAGnB,MAAM,MAAM,EAAE,WAAqD;AACjE,qBAAmB,KAAK,QAAQ;EAEh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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients-xn1jUwXu.cjs","names":["apiClient: APIClient","apiClient: APIClient","account: OtimAccount","context: OtimClientContext","apiClient: APIClient","apiClient: APIClient","UnifiedPaymentSigner","ApiKeyClientSigningService","ServerWalletSigningService","apiClient: APIClient","account: OtimAccount","context: OtimServerClientContext","hexStringSchema"],"sources":["../src/clients/activity.ts","../src/clients/auth.ts","../src/clients/config.ts","../src/clients/delegation.ts","../src/clients/helpers/settlement-signer.ts","../src/clients/orchestration.ts","../src/clients/helpers/prepare-settlement.ts"],"sourcesContent":["import type {\n APIClient,\n GetInstructionActivityRequest,\n GetInstructionActivityResponse,\n} from \"@otim/utils/api\";\n\nexport class ActivityClient {\n constructor(private readonly apiClient: APIClient) {}\n\n async getInstructionActivity(\n request: GetInstructionActivityRequest,\n ): Promise<GetInstructionActivityResponse> {\n const response =\n await this.apiClient.activity.getInstructionActivity(request);\n\n return response.data;\n }\n}\n","import type { OtimAccount } from \"@otim/sdk-core/account\";\nimport type { OtimClientContext } from \"@otim/sdk-core/context\";\nimport type { APIClient, AuthLoginResponse, MeResponse } from \"@otim/utils/api\";\nimport type { Address } from \"viem\";\n\nimport { parseSignatureToVRS } from \"@otim/utils/helpers\";\n\nimport { createLoginSiweMessage } from \"@otim/sdk-core/config\";\nimport { assertRequiresAuth } from \"@otim/sdk-core/context\";\n\nexport interface LoginOptions {\n address: Address;\n}\n\nexport class AuthClient {\n constructor(\n private readonly apiClient: APIClient,\n private readonly account: OtimAccount,\n private readonly context: OtimClientContext,\n ) {}\n\n async login({ address }: LoginOptions): Promise<AuthLoginResponse> {\n assertRequiresAuth(this.context);\n\n const message = createLoginSiweMessage(address, Date.now().toString());\n const signature = await this.account.signMessage({ message });\n const vrsParsedSignature = parseSignatureToVRS(signature);\n\n const response = await this.apiClient.auth.login({\n siwe: message,\n signature: vrsParsedSignature,\n });\n\n return response.data;\n }\n\n async getCurrentUser(): Promise<MeResponse> {\n const response = await this.apiClient.auth.me();\n return response.data;\n }\n}\n","import type {\n APIClient,\n GetMaxPriorityFeePerGasEstimateRequest,\n GetMaxPriorityFeePerGasEstimateResponse,\n} from \"@otim/utils/api\";\n\nexport class ConfigClient {\n constructor(private readonly apiClient: APIClient) {}\n\n async getMaxPriorityFeeEstimate({\n chainId,\n }: GetMaxPriorityFeePerGasEstimateRequest): Promise<GetMaxPriorityFeePerGasEstimateResponse> {\n const response =\n await this.apiClient.config.getMaxPriorityFeePerGasEstimate({ chainId });\n\n return response.data;\n }\n}\n","import type {\n APIClient,\n DelegationCreateRequest,\n DelegationStatusRequest,\n DelegationStatusResponse,\n GetDelegateAddressRequest,\n GetDelegateAddressResponse,\n} from \"@otim/utils/api\";\n\nexport class DelegationClient {\n constructor(private readonly apiClient: APIClient) {}\n\n async getDelegateAddress({\n chainId,\n }: GetDelegateAddressRequest): Promise<GetDelegateAddressResponse> {\n const response = await this.apiClient.config.getDelegateAddress({\n chainId,\n });\n\n return response.data;\n }\n\n async getDelegationStatus(\n options: DelegationStatusRequest,\n ): Promise<DelegationStatusResponse> {\n const response = await this.apiClient.account.getDelegationStatus({\n address: options.address,\n chainId: options.chainId,\n });\n\n return response.data;\n }\n\n async createDelegation(\n delegationRequest: DelegationCreateRequest,\n ): Promise<void> {\n await this.apiClient.account.createDelegation(delegationRequest);\n }\n}\n","import type { OtimServerClientContext } from \"@otim/sdk-core/context\";\nimport type { PaymentResponseWithActionNames } from \"@otim/utils/payments\";\nimport type { Address } from \"@otim/utils/schemas\";\nimport type { PublicClient } from \"viem\";\n\nimport {\n ApiKeyClientSigningService,\n ServerWalletSigningService,\n UnifiedPaymentSigner,\n} from \"@otim/turnkey/signing\";\nimport { createWalletClient, http } from \"viem\";\nimport { privateKeyToAccount } from \"viem/accounts\";\n\nimport { isApiAccountConfig } from \"@otim/sdk-core/account\";\n\nexport interface CreateSettlementSignerParams {\n context: OtimServerClientContext;\n buildResponse: PaymentResponseWithActionNames;\n publicClient: PublicClient;\n delegateAddressMap: Map<number, Address>;\n}\n\ntype CreateSettlementSignerResult = Awaited<\n ReturnType<UnifiedPaymentSigner[\"signAll\"]>\n>;\n\nexport async function createSettlementSigner(\n params: CreateSettlementSignerParams,\n): Promise<CreateSettlementSignerResult> {\n const { context, buildResponse, publicClient, delegateAddressMap } = params;\n\n if (isApiAccountConfig(context.config)) {\n const signingService = new ApiKeyClientSigningService(\n context.config.publicKey,\n context.config.privateKey,\n );\n\n const signer = new UnifiedPaymentSigner({\n buildResponse,\n signingService,\n publicClient,\n delegateAddressMap,\n });\n\n return signer.signAll();\n }\n\n const account = privateKeyToAccount(context.config.privateKey);\n const walletClient = createWalletClient({\n account,\n transport: http(),\n });\n\n const signingService =\n ServerWalletSigningService.fromViemWallet(walletClient);\n\n const signer = new UnifiedPaymentSigner({\n buildResponse,\n signingService,\n publicClient,\n delegateAddressMap,\n });\n\n return signer.signAll();\n}\n","import type { PreparedSettlement } from \"./helpers/prepare-settlement\";\nimport type { OtimAccount } from \"@otim/sdk-core/account\";\nimport type { OtimServerClientContext } from \"@otim/sdk-core/context\";\nimport type {\n APIClient,\n GetPaymentRequestsRequest,\n GetPaymentRequestsResponse,\n PaginatedServiceResponse,\n PaymentRequestBuildRequest,\n PaymentRequestDetailsRequest,\n PaymentRequestDetailsResponse,\n ServiceResponse,\n} from \"@otim/utils/api\";\nimport type { PaymentResponseWithActionNames } from \"@otim/utils/payments\";\nimport type { Address } from \"@otim/utils/schemas\";\nimport type { PublicClient } from \"viem\";\n\nimport { getChainById } from \"@otim/utils/chains\";\nimport {\n addActionNamesToInstructions,\n extractActionNamesMap,\n} from \"@otim/utils/payments\";\nimport { hexStringSchema } from \"@otim/utils/schemas\";\nimport { createPublicClient, http } from \"viem\";\n\nimport { assertServerContext } from \"@otim/sdk-core/context\";\n\nimport { createSettlementSigner } from \"./helpers/settlement-signer\";\n\nexport type { PreparedSettlement } from \"./helpers/prepare-settlement\";\n\nexport interface CreateSettlementResponse {\n requestId: string;\n ephemeralWalletAddress: Address;\n}\n\nexport interface CreateRawConfig {\n settlementChainId: number;\n activate?: boolean;\n}\n\ntype SettlementInstruction =\n PaymentResponseWithActionNames[\"completionInstructions\"][number];\n\nexport class OrchestrationClient {\n constructor(\n private readonly apiClient: APIClient,\n private readonly account: OtimAccount,\n private readonly context: OtimServerClientContext,\n ) {}\n\n async create(\n preparedSettlement: PreparedSettlement,\n ): Promise<CreateSettlementResponse> {\n assertServerContext(this.context);\n\n const response =\n await this.apiClient.payments.buildSettlementOrchestration(\n preparedSettlement,\n );\n const buildResponse = response.data;\n\n await this.activate(buildResponse, preparedSettlement.settlementChain);\n\n return {\n requestId: buildResponse.requestId,\n ephemeralWalletAddress: buildResponse.ephemeralWalletAddress,\n };\n }\n\n async createRaw(\n payload: PaymentRequestBuildRequest,\n config: CreateRawConfig,\n ): Promise<CreateSettlementResponse | PaymentResponseWithActionNames> {\n assertServerContext(this.context);\n\n const { settlementChainId, activate = true } = config;\n const buildResponse = await this.buildAndEnhanceSettlement(payload);\n\n if (!activate) {\n return buildResponse;\n }\n\n await this.activate(buildResponse, settlementChainId);\n\n return {\n requestId: buildResponse.requestId,\n ephemeralWalletAddress: buildResponse.ephemeralWalletAddress,\n };\n }\n\n async getDetails(\n request: PaymentRequestDetailsRequest,\n ): Promise<ServiceResponse<PaymentRequestDetailsResponse>> {\n return this.apiClient.payments.getPaymentRequestDetails(request);\n }\n\n async list(\n request: GetPaymentRequestsRequest,\n ): Promise<PaginatedServiceResponse<GetPaymentRequestsResponse>> {\n return this.apiClient.payments.getPaymentRequests(request);\n }\n\n private async activate(\n buildResponse: PaymentResponseWithActionNames,\n settlementChainId: number,\n ): Promise<void> {\n const publicClient = this.createPublicClient(settlementChainId);\n\n const instructions = [\n ...buildResponse.completionInstructions,\n ...buildResponse.instructions,\n ];\n\n const delegateAddressMap = await this.fetchDelegateAddresses(instructions);\n\n const {\n signedAuthorization,\n completionInstructions,\n instructions: signedInstructions,\n } = await createSettlementSigner({\n context: this.context,\n buildResponse,\n publicClient,\n delegateAddressMap,\n });\n\n await this.apiClient.payments.newPaymentRequest({\n requestId: buildResponse.requestId,\n signedAuthorization,\n completionInstructions,\n instructions: signedInstructions,\n });\n }\n\n private async buildAndEnhanceSettlement(\n payload: PaymentRequestBuildRequest,\n ): Promise<PaymentResponseWithActionNames> {\n const actionNames = extractActionNamesMap(\n payload.completionInstructions,\n payload.instructions,\n );\n\n const response = await this.apiClient.payments.buildPaymentRequest(payload);\n\n return addActionNamesToInstructions(response.data, actionNames);\n }\n\n private createPublicClient(chainId: number): PublicClient {\n const chain = getChainById(chainId);\n if (!chain) {\n throw new Error(`Chain with id ${chainId} not found`);\n }\n\n return createPublicClient({ chain, transport: http() });\n }\n\n private async fetchDelegateAddresses(\n instructions: SettlementInstruction[],\n ): Promise<Map<number, Address>> {\n const chainIds = Array.from(\n new Set(instructions.map((instruction) => instruction.chainId)),\n );\n\n const addresses = await Promise.all(\n chainIds.map(async (chainId) => {\n const response = await this.apiClient.config.getDelegateAddress({\n chainId,\n });\n const address = hexStringSchema.parse(\n response.data.otimDelegateAddress,\n );\n return [chainId, address] as const;\n }),\n );\n\n return new Map(addresses);\n }\n}\n","import type { SupportedChainId } from \"@otim/utils/chains\";\nimport type { Nullable } from \"@otim/utils/helpers\";\nimport type { PaymentRequestMetadata } from \"@otim/utils/payments\";\nimport type { Address } from \"@otim/utils/schemas\";\n\nimport { validateIso8601Date } from \"@otim/utils/helpers\";\nimport { buildPaymentMetadata } from \"@otim/utils/payments\";\n\nexport interface PrepareSettlementParams {\n amount: number;\n chainId: SupportedChainId;\n recipient: Address;\n token: Address;\n acceptedTokens: Record<number, Address[]>;\n payer?: Nullable<Address>;\n dueDate?: string;\n metadata?: PaymentRequestMetadata;\n note?: string;\n maxRuns?: number;\n}\n\nexport interface PreparedSettlement {\n acceptedTokens: Record<number, Address[]>;\n settlementChain: number;\n settlementToken: Address;\n settlementAmount: number;\n recipientAddress: Address;\n metadata: Record<string, unknown>;\n payerAddress?: Address | null;\n dueDate?: string;\n maxRuns?: number;\n}\n\nfunction buildMetadataFromParams(params: {\n amount: number;\n recipient: Address;\n token: Address;\n note?: string;\n dueDate?: string;\n customMetadata?: PaymentRequestMetadata;\n}): PaymentRequestMetadata {\n const { amount, recipient, token, note, dueDate, customMetadata } = params;\n\n const baseMetadata = buildPaymentMetadata({\n tokenSymbol: \"\",\n amountInUSD: amount,\n fromAccountAddress: recipient,\n note,\n dueDate,\n hasInvoiceMetadata: false,\n });\n\n const metadataWithToken = { ...baseMetadata, token };\n\n return customMetadata\n ? { ...metadataWithToken, ...customMetadata }\n : metadataWithToken;\n}\n\nexport function prepareSettlement(\n params: PrepareSettlementParams,\n): PreparedSettlement {\n const {\n chainId,\n token,\n acceptedTokens,\n recipient,\n amount,\n payer,\n note,\n dueDate,\n metadata: customMetadata,\n maxRuns,\n } = params;\n\n if (dueDate) {\n validateIso8601Date(dueDate);\n }\n\n const metadata = buildMetadataFromParams({\n amount,\n recipient,\n token,\n note,\n dueDate,\n customMetadata,\n });\n\n return {\n acceptedTokens,\n settlementChain: chainId,\n settlementToken: token,\n settlementAmount: amount,\n recipientAddress: recipient,\n metadata,\n payerAddress: payer ?? null,\n maxRuns,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAMA,IAAa,iBAAb,MAA4B;CAC1B,YAAY,AAAiBA,WAAsB;EAAtB;;CAE7B,MAAM,uBACJ,SACyC;AAIzC,UAFE,MAAM,KAAK,UAAU,SAAS,uBAAuB,QAAQ,EAE/C;;;;;;ACDpB,IAAa,aAAb,MAAwB;CACtB,YACE,AAAiBC,WACjB,AAAiBC,SACjB,AAAiBC,SACjB;EAHiB;EACA;EACA;;CAGnB,MAAM,MAAM,EAAE,WAAqD;AACjE,kDAAmB,KAAK,QAAQ;EAEhC,MAAM,6DAAiC,SAAS,KAAK,KAAK,CAAC,UAAU,CAAC;EAEtE,MAAM,mEADY,MAAM,KAAK,QAAQ,YAAY,EAAE,SAAS,CAAC,CACJ;AAOzD,UALiB,MAAM,KAAK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AAM,IAAI,MAAM,iBAAiB,QAAQ,YAAY;AAGvD,sCAA0B;GAAE;GAAO,2BAAiB;GAAE,CAAC;;CAGzD,MAAc,uBACZ,cAC+B;EAC/B,MAAM,WAAW,MAAM,KACrB,IAAI,IAAI,aAAa,KAAK,gBAAgB,YAAY,QAAQ,CAAC,CAChE;EAED,MAAM,YAAY,MAAM,QAAQ,IAC9B,SAAS,IAAI,OAAO,YAAY;GAC9B,MAAM,WAAW,MAAM,KAAK,UAAU,OAAO,mBAAmB,EAC9D,SACD,CAAC;AAIF,UAAO,CAAC,SAHQC,qCAAgB,MAC9B,SAAS,KAAK,oBACf,CACwB;IACzB,CACH;AAED,SAAO,IAAI,IAAI,UAAU;;;;;;AC/I7B,SAAS,wBAAwB,QAON;CACzB,MAAM,EAAE,QAAQ,WAAW,OAAO,MAAM,SAAS,mBAAmB;CAWpE,MAAM,oBAAoB;EAAE,mDATc;GACxC,aAAa;GACb,aAAa;GACb,oBAAoB;GACpB;GACA;GACA,oBAAoB;GACrB,CAAC;EAE2C;EAAO;AAEpD,QAAO,iBACH;EAAE,GAAG;EAAmB,GAAG;EAAgB,GAC3C;;AAGN,SAAgB,kBACd,QACoB;CACpB,MAAM,EACJ,SACA,OACA,gBACA,WACA,QACA,OACA,MACA,SACA,UAAU,gBACV,YACE;AAEJ,KAAI,QACF,+CAAoB,QAAQ;AAY9B,QAAO;EACL;EACA,iBAAiB;EACjB,iBAAiB;EACjB,kBAAkB;EAClB,kBAAkB;EAClB,UAfe,wBAAwB;GACvC;GACA;GACA;GACA;GACA;GACA;GACD,CAAC;EASA,cAAc,SAAS;EACvB;EACD"}
|
package/dist/config/index.d.cts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import "../abi-OUq-mx1W.cjs";
|
|
2
|
-
import { a as env, c as isEnvironment, i as Environment, n as SIWE_VERSION, o as getApiUrl, r as createLoginSiweMessage, s as getTurnkeyApiUrl, t as SIWE_CHAIN_ID } from "../index-lW-Oor1B.cjs";
|
|
3
|
-
export { Environment, Environment as EnvironmentType, SIWE_CHAIN_ID, SIWE_VERSION, createLoginSiweMessage, env, getApiUrl, getTurnkeyApiUrl, isEnvironment };
|
package/dist/config/index.d.mts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import "../abi-DW6AS0eM.mjs";
|
|
2
|
-
import { a as env, c as isEnvironment, i as Environment, n as SIWE_VERSION, o as getApiUrl, r as createLoginSiweMessage, s as getTurnkeyApiUrl, t as SIWE_CHAIN_ID } from "../index-D_7CTJDl.mjs";
|
|
3
|
-
export { Environment, Environment as EnvironmentType, SIWE_CHAIN_ID, SIWE_VERSION, createLoginSiweMessage, env, getApiUrl, getTurnkeyApiUrl, isEnvironment };
|
package/dist/config/index.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { a as env, c as isEnvironment, i as Environment, n as SIWE_VERSION, o as getApiUrl, r as createLoginSiweMessage, s as getTurnkeyApiUrl, t as SIWE_CHAIN_ID } from "../config-C_nc1DXn.mjs";
|
|
2
|
-
|
|
3
|
-
export { Environment, SIWE_CHAIN_ID, SIWE_VERSION, createLoginSiweMessage, env, getApiUrl, getTurnkeyApiUrl, isEnvironment };
|
package/dist/config-C_nc1DXn.mjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { createEnv } from "@t3-oss/env-core";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { createSiweMessage } from "viem/siwe";
|
|
4
|
-
|
|
5
|
-
//#region src/config/env.ts
|
|
6
|
-
const Environment = {
|
|
7
|
-
Sandbox: "sandbox",
|
|
8
|
-
Production: "production"
|
|
9
|
-
};
|
|
10
|
-
const isEnvironment = (value) => Object.values(Environment).includes(value);
|
|
11
|
-
const environmentValues = Object.values(Environment);
|
|
12
|
-
const API_URLS = {
|
|
13
|
-
[Environment.Sandbox]: "https://dev-cwnvii2d-api.otim.dev",
|
|
14
|
-
[Environment.Production]: "https://api.otim.com"
|
|
15
|
-
};
|
|
16
|
-
const TURNKEY_API_URLS = {
|
|
17
|
-
[Environment.Sandbox]: "https://api.turnkey.com",
|
|
18
|
-
[Environment.Production]: "https://api.turnkey.com"
|
|
19
|
-
};
|
|
20
|
-
const getApiUrl = (environment) => {
|
|
21
|
-
return API_URLS[environment];
|
|
22
|
-
};
|
|
23
|
-
const getTurnkeyApiUrl = (environment) => {
|
|
24
|
-
return TURNKEY_API_URLS[environment];
|
|
25
|
-
};
|
|
26
|
-
const env = createEnv({
|
|
27
|
-
server: {
|
|
28
|
-
ENVIRONMENT: z.enum(environmentValues).default(Environment.Sandbox),
|
|
29
|
-
ENABLE_MSW: z.coerce.boolean().default(false),
|
|
30
|
-
CI: z.coerce.boolean().default(false)
|
|
31
|
-
},
|
|
32
|
-
client: {},
|
|
33
|
-
clientPrefix: "",
|
|
34
|
-
runtimeEnv: {
|
|
35
|
-
ENVIRONMENT: process.env.ENVIRONMENT,
|
|
36
|
-
ENABLE_MSW: process.env.ENABLE_MSW,
|
|
37
|
-
CI: process.env.CI
|
|
38
|
-
},
|
|
39
|
-
onValidationError: (error) => {
|
|
40
|
-
console.error("❌ Invalid environment variables:", error);
|
|
41
|
-
throw new Error("Invalid environment variables");
|
|
42
|
-
},
|
|
43
|
-
skipValidation: process.env.SKIP_ENV_VALIDATION === "true"
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/config/app.ts
|
|
48
|
-
/**
|
|
49
|
-
* SIWE default configuration.
|
|
50
|
-
*/
|
|
51
|
-
const SIWE_CHAIN_ID = 0;
|
|
52
|
-
const SIWE_VERSION = "1";
|
|
53
|
-
const createLoginSiweMessage = (address, nonce) => {
|
|
54
|
-
return createSiweMessage({
|
|
55
|
-
address,
|
|
56
|
-
chainId: SIWE_CHAIN_ID,
|
|
57
|
-
nonce,
|
|
58
|
-
domain: "otim.com",
|
|
59
|
-
uri: "https://app.otim.com",
|
|
60
|
-
statement: `Welcome to Otim! By signing in, you accept the Otim Terms and Conditions (https://otim.com/tac). This request will not trigger a blockchain transaction or cost any gas fees.`,
|
|
61
|
-
version: SIWE_VERSION
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
export { env as a, isEnvironment as c, Environment as i, SIWE_VERSION as n, getApiUrl as o, createLoginSiweMessage as r, getTurnkeyApiUrl as s, SIWE_CHAIN_ID as t };
|
|
67
|
-
//# sourceMappingURL=config-C_nc1DXn.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-C_nc1DXn.mjs","names":["API_URLS: Record<Environment, string>","TURNKEY_API_URLS: Record<Environment, string>"],"sources":["../src/config/env.ts","../src/config/app.ts"],"sourcesContent":["import { createEnv } from \"@t3-oss/env-core\";\nimport { z } from \"zod\";\n\nexport const Environment = {\n Sandbox: \"sandbox\",\n Production: \"production\",\n} as const;\nexport type Environment = (typeof Environment)[keyof typeof Environment];\n\nexport const isEnvironment = (value: string): value is Environment =>\n Object.values(Environment).includes(value as Environment);\n\nexport const environmentValues = Object.values(Environment) as [\n Environment,\n ...Environment[],\n];\n\nexport const API_URLS: Record<Environment, string> = {\n [Environment.Sandbox]: \"https://dev-cwnvii2d-api.otim.dev\",\n [Environment.Production]: \"https://api.otim.com\",\n};\n\nexport const TURNKEY_API_URLS: Record<Environment, string> = {\n [Environment.Sandbox]: \"https://api.turnkey.com\",\n [Environment.Production]: \"https://api.turnkey.com\",\n};\n\nexport const getApiUrl = (environment: Environment): string => {\n return API_URLS[environment];\n};\n\nexport const getTurnkeyApiUrl = (environment: Environment): string => {\n return TURNKEY_API_URLS[environment];\n};\n\nexport const env = createEnv({\n server: {\n ENVIRONMENT: z.enum(environmentValues).default(Environment.Sandbox),\n\n ENABLE_MSW: z.coerce.boolean().default(false),\n\n CI: z.coerce.boolean().default(false),\n },\n\n client: {},\n\n clientPrefix: \"\",\n\n runtimeEnv: {\n ENVIRONMENT: process.env.ENVIRONMENT,\n\n ENABLE_MSW: process.env.ENABLE_MSW,\n\n CI: process.env.CI,\n },\n\n onValidationError: (error) => {\n // eslint-disable-next-line no-console\n console.error(\"❌ Invalid environment variables:\", error);\n throw new Error(\"Invalid environment variables\");\n },\n\n // skip validation of environment variables (should be false in most cases)\n skipValidation: process.env.SKIP_ENV_VALIDATION === \"true\",\n});\n","import type { Address } from \"viem\";\n\nimport { createSiweMessage } from \"viem/siwe\";\n\n/**\n * SIWE default configuration.\n */\nexport const SIWE_CHAIN_ID = 0;\nexport const SIWE_VERSION = \"1\";\n\nexport const createLoginSiweMessage = (\n address: Address,\n nonce: string,\n): string => {\n return createSiweMessage({\n address,\n chainId: SIWE_CHAIN_ID,\n nonce,\n domain: \"otim.com\",\n uri: \"https://app.otim.com\",\n statement: `Welcome to Otim! By signing in, you accept the Otim Terms and Conditions (https://otim.com/tac). This request will not trigger a blockchain transaction or cost any gas fees.`,\n version: SIWE_VERSION,\n });\n};\n"],"mappings":";;;;;AAGA,MAAa,cAAc;CACzB,SAAS;CACT,YAAY;CACb;AAGD,MAAa,iBAAiB,UAC5B,OAAO,OAAO,YAAY,CAAC,SAAS,MAAqB;AAE3D,MAAa,oBAAoB,OAAO,OAAO,YAAY;AAK3D,MAAaA,WAAwC;EAClD,YAAY,UAAU;EACtB,YAAY,aAAa;CAC3B;AAED,MAAaC,mBAAgD;EAC1D,YAAY,UAAU;EACtB,YAAY,aAAa;CAC3B;AAED,MAAa,aAAa,gBAAqC;AAC7D,QAAO,SAAS;;AAGlB,MAAa,oBAAoB,gBAAqC;AACpE,QAAO,iBAAiB;;AAG1B,MAAa,MAAM,UAAU;CAC3B,QAAQ;EACN,aAAa,EAAE,KAAK,kBAAkB,CAAC,QAAQ,YAAY,QAAQ;EAEnE,YAAY,EAAE,OAAO,SAAS,CAAC,QAAQ,MAAM;EAE7C,IAAI,EAAE,OAAO,SAAS,CAAC,QAAQ,MAAM;EACtC;CAED,QAAQ,EAAE;CAEV,cAAc;CAEd,YAAY;EACV,aAAa,QAAQ,IAAI;EAEzB,YAAY,QAAQ,IAAI;EAExB,IAAI,QAAQ,IAAI;EACjB;CAED,oBAAoB,UAAU;AAE5B,UAAQ,MAAM,oCAAoC,MAAM;AACxD,QAAM,IAAI,MAAM,gCAAgC;;CAIlD,gBAAgB,QAAQ,IAAI,wBAAwB;CACrD,CAAC;;;;;;;ACzDF,MAAa,gBAAgB;AAC7B,MAAa,eAAe;AAE5B,MAAa,0BACX,SACA,UACW;AACX,QAAO,kBAAkB;EACvB;EACA,SAAS;EACT;EACA,QAAQ;EACR,KAAK;EACL,WAAW;EACX,SAAS;EACV,CAAC"}
|
package/dist/context/index.d.cts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import "../abi-OUq-mx1W.cjs";
|
|
2
|
-
import "../rpc-BDoNl1Sp.cjs";
|
|
3
|
-
import "../authorization-6anhDdQX.cjs";
|
|
4
|
-
import { a as OtimReactClientContext, i as OtimClientContext, n as assertRequiresAuth, o as OtimServerClientContext, r as assertServerContext, t as isServerContext } from "../index-GSspyLr3.cjs";
|
|
5
|
-
export { OtimClientContext, OtimReactClientContext, OtimServerClientContext, assertRequiresAuth, assertServerContext, isServerContext };
|
package/dist/context/index.d.mts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import "../abi-DW6AS0eM.mjs";
|
|
2
|
-
import "../rpc-CygBD_f7.mjs";
|
|
3
|
-
import "../authorization-DnNpWjxB.mjs";
|
|
4
|
-
import { a as OtimReactClientContext, i as OtimClientContext, n as assertRequiresAuth, o as OtimServerClientContext, r as assertServerContext, t as isServerContext } from "../index-DWE1xfOE.mjs";
|
|
5
|
-
export { OtimClientContext, OtimReactClientContext, OtimServerClientContext, assertRequiresAuth, assertServerContext, isServerContext };
|
package/dist/context/index.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/context/asserts.ts
|
|
2
|
-
function isServerContext$1(context) {
|
|
3
|
-
return "usesApiKeyAuth" in context;
|
|
4
|
-
}
|
|
5
|
-
function assertRequiresAuth(context) {
|
|
6
|
-
if (isServerContext$1(context) && context.usesApiKeyAuth) throw new Error("Method not allowed. Api key authentication does not require user login.");
|
|
7
|
-
}
|
|
8
|
-
function assertServerContext(context) {
|
|
9
|
-
if (!isServerContext$1(context)) throw new Error("Method only supported in server context");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/context/helpers.ts
|
|
14
|
-
const isServerContext = (context) => {
|
|
15
|
-
return "usesApiKeyAuth" in context;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
export { assertRequiresAuth as n, assertServerContext as r, isServerContext as t };
|
|
20
|
-
//# sourceMappingURL=context-uTye69B0.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-uTye69B0.mjs","names":["isServerContext"],"sources":["../src/context/asserts.ts","../src/context/helpers.ts"],"sourcesContent":["import type { OtimClientContext, OtimServerClientContext } from \"./types\";\n\nfunction isServerContext(\n context: OtimClientContext,\n): context is OtimServerClientContext {\n return \"usesApiKeyAuth\" in context;\n}\n\nexport function assertRequiresAuth(context: OtimClientContext): void {\n if (isServerContext(context) && context.usesApiKeyAuth) {\n throw new Error(\n \"Method not allowed. Api key authentication does not require user login.\",\n );\n }\n}\n\nexport function assertServerContext(\n context: OtimClientContext,\n): asserts context is OtimServerClientContext {\n if (!isServerContext(context)) {\n throw new Error(\"Method only supported in server context\");\n }\n}\n","import type { OtimClientContext, OtimServerClientContext } from \"./types\";\n\nexport const isServerContext = (\n context: OtimClientContext,\n): context is OtimServerClientContext => {\n return \"usesApiKeyAuth\" in context;\n};\n"],"mappings":";AAEA,SAASA,kBACP,SACoC;AACpC,QAAO,oBAAoB;;AAG7B,SAAgB,mBAAmB,SAAkC;AACnE,KAAIA,kBAAgB,QAAQ,IAAI,QAAQ,eACtC,OAAM,IAAI,MACR,0EACD;;AAIL,SAAgB,oBACd,SAC4C;AAC5C,KAAI,CAACA,kBAAgB,QAAQ,CAC3B,OAAM,IAAI,MAAM,0CAA0C;;;;;AClB9D,MAAa,mBACX,YACuC;AACvC,QAAO,oBAAoB"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { t as Authorization } from "./authorization-6anhDdQX.cjs";
|
|
2
|
-
import { EIP2098Signature, VRS } from "@otim/utils/schemas";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/rlp.d.ts
|
|
5
|
-
declare const normalizeYParityValue: (value: number | bigint | string | undefined | null) => 0 | 1;
|
|
6
|
-
declare function createRlpEncodedAuthorization(authorization: Authorization): `0x${string}`;
|
|
7
|
-
declare function createRlpEncodedAuthorization(chainId: number, delegateAddress: string, nonce: number, yParity: number | bigint, r: `0x${string}`, s: `0x${string}`): `0x${string}`;
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/utils/vrs.d.ts
|
|
10
|
-
declare const createEIP2098Signature: (vrs: VRS) => EIP2098Signature;
|
|
11
|
-
declare const parseSignatureToVRS: (signature: string) => VRS;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { normalizeYParityValue as i, parseSignatureToVRS as n, createRlpEncodedAuthorization as r, createEIP2098Signature as t };
|
|
14
|
-
//# sourceMappingURL=index-BQMXYh9N.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-BQMXYh9N.d.cts","names":[],"sources":["../src/utils/rlp.ts","../src/utils/vrs.ts"],"sourcesContent":[],"mappings":";;;;cAuBa;iBAkCG,6BAAA,gBACC;iBAED,6BAAA;;;cCrBH,8BAA+B,QAAM;cAkBrC,4CAA2C"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { t as Chain } from "./rpc-CygBD_f7.mjs";
|
|
2
|
-
import { c as Hex } from "./authorization-DnNpWjxB.mjs";
|
|
3
|
-
import { Environment } from "@otim/sdk-core/config";
|
|
4
|
-
import { OtimServerClientContext } from "@otim/sdk-core/context";
|
|
5
|
-
|
|
6
|
-
//#region src/account/types.d.ts
|
|
7
|
-
declare const ServerAccountType: {
|
|
8
|
-
readonly PrivateKey: "privateKey";
|
|
9
|
-
readonly Api: "api";
|
|
10
|
-
};
|
|
11
|
-
type ServerAccountType = (typeof ServerAccountType)[keyof typeof ServerAccountType];
|
|
12
|
-
declare const AccountType: {
|
|
13
|
-
readonly PrivateKey: "privateKey";
|
|
14
|
-
readonly Api: "api";
|
|
15
|
-
};
|
|
16
|
-
type AccountType = (typeof AccountType)[keyof typeof AccountType];
|
|
17
|
-
type OtimAccountSignMessageArgs = {
|
|
18
|
-
message: string | {
|
|
19
|
-
raw: Hex | Uint8Array;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
interface OtimAccount {
|
|
23
|
-
initialize(): Promise<void>;
|
|
24
|
-
signMessage(args: OtimAccountSignMessageArgs): Promise<Hex>;
|
|
25
|
-
}
|
|
26
|
-
interface BaseAccountConfig {
|
|
27
|
-
environment?: Environment;
|
|
28
|
-
chains: Chain[];
|
|
29
|
-
defaultChain?: Chain;
|
|
30
|
-
}
|
|
31
|
-
interface ApiAccountConfig extends BaseAccountConfig {
|
|
32
|
-
type: typeof ServerAccountType.Api;
|
|
33
|
-
appId: string;
|
|
34
|
-
privateKey: string;
|
|
35
|
-
publicKey: string;
|
|
36
|
-
apiKey?: string;
|
|
37
|
-
}
|
|
38
|
-
interface PrivateKeyAccountConfig extends BaseAccountConfig {
|
|
39
|
-
type: typeof ServerAccountType.PrivateKey;
|
|
40
|
-
privateKey: `0x${string}`;
|
|
41
|
-
}
|
|
42
|
-
type ServerAccountConfig = ApiAccountConfig | PrivateKeyAccountConfig;
|
|
43
|
-
type AccountConfig = ServerAccountConfig;
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/account/helpers.d.ts
|
|
46
|
-
declare function isApiAccountConfig(config: ServerAccountConfig): config is ApiAccountConfig;
|
|
47
|
-
declare function isPrivateKeyAccountConfig(config: ServerAccountConfig): config is PrivateKeyAccountConfig;
|
|
48
|
-
declare function createClientContext(config: ServerAccountConfig): OtimServerClientContext;
|
|
49
|
-
//#endregion
|
|
50
|
-
export { AccountType as a, OtimAccountSignMessageArgs as c, ServerAccountType as d, AccountConfig as i, PrivateKeyAccountConfig as l, isApiAccountConfig as n, ApiAccountConfig as o, isPrivateKeyAccountConfig as r, OtimAccount as s, createClientContext as t, ServerAccountConfig as u };
|
|
51
|
-
//# sourceMappingURL=index-C5c51xs0.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-C5c51xs0.d.mts","names":[],"sources":["../src/account/types.ts","../src/account/helpers.ts"],"sourcesContent":[],"mappings":";;;;;;cAGa;;;;AAAA,KAID,iBAAA,GADF,CAAA,OAEA,iBAFA,CAAA,CAAA,MAAA,OAEgC,iBAFhC,CAAA;AACE,cAGC,WAHgB,EAAA;EAGhB,SAAA,UAEH,EAAA,YAAA;EACE,SAAA,GAAA,EAAW,KAAA;AAEvB,CAAA;AAIiB,KANL,WAAA,GAMgB,CAAA,OANM,WAMN,CAAA,CAAA,MAAA,OANgC,WAMhC,CAAA;AACZ,KALJ,0BAAA,GAKI;EACI,OAAA,EAAA,MAAA,GAAA;IAAqC,GAAA,EAL9B,GAK8B,GALxB,UAKwB;EAAR,CAAA;CAAO;AAG9C,UALO,WAAA,CAKU;EACX,UAAA,EAAA,EALA,OAKA,CAAA,IAAA,CAAA;EACN,WAAA,CAAA,IAAA,EALU,0BAKV,CAAA,EALuC,OAKvC,CAL+C,GAK/C,CAAA;;UAFA,iBAAA,CAGY;EAGL,WAAA,CAAA,EALD,WAKkB;EAQjB,MAAA,EAZP,KAYO,EAAA;EAKL,YAAA,CAAA,EAhBK,KAgBL;AAEZ;UAfiB,gBAAA,SAAyB;eAC3B,iBAAA,CAAkB;;ECtBjB,UAAA,EAAA,MAAA;EAMA,SAAA,EAAA,MAAA;EAMA,MAAA,CAAA,EAAA,MAAA;;UDiBC,uBAAA,SAAgC;eAClC,iBAAA,CAAkB;;;KAIrB,mBAAA,GAAsB,mBAAmB;KAEzC,aAAA,GAAgB;;;iBCpCZ,kBAAA,SACN,gCACG;iBAIG,yBAAA,SACN,gCACG;iBAIG,mBAAA,SACN,sBACP"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { t as Chain } from "./rpc-BDoNl1Sp.cjs";
|
|
2
|
-
import { c as Hex } from "./authorization-6anhDdQX.cjs";
|
|
3
|
-
import { Environment } from "@otim/sdk-core/config";
|
|
4
|
-
import { OtimServerClientContext } from "@otim/sdk-core/context";
|
|
5
|
-
|
|
6
|
-
//#region src/account/types.d.ts
|
|
7
|
-
declare const ServerAccountType: {
|
|
8
|
-
readonly PrivateKey: "privateKey";
|
|
9
|
-
readonly Api: "api";
|
|
10
|
-
};
|
|
11
|
-
type ServerAccountType = (typeof ServerAccountType)[keyof typeof ServerAccountType];
|
|
12
|
-
declare const AccountType: {
|
|
13
|
-
readonly PrivateKey: "privateKey";
|
|
14
|
-
readonly Api: "api";
|
|
15
|
-
};
|
|
16
|
-
type AccountType = (typeof AccountType)[keyof typeof AccountType];
|
|
17
|
-
type OtimAccountSignMessageArgs = {
|
|
18
|
-
message: string | {
|
|
19
|
-
raw: Hex | Uint8Array;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
interface OtimAccount {
|
|
23
|
-
initialize(): Promise<void>;
|
|
24
|
-
signMessage(args: OtimAccountSignMessageArgs): Promise<Hex>;
|
|
25
|
-
}
|
|
26
|
-
interface BaseAccountConfig {
|
|
27
|
-
environment?: Environment;
|
|
28
|
-
chains: Chain[];
|
|
29
|
-
defaultChain?: Chain;
|
|
30
|
-
}
|
|
31
|
-
interface ApiAccountConfig extends BaseAccountConfig {
|
|
32
|
-
type: typeof ServerAccountType.Api;
|
|
33
|
-
appId: string;
|
|
34
|
-
privateKey: string;
|
|
35
|
-
publicKey: string;
|
|
36
|
-
apiKey?: string;
|
|
37
|
-
}
|
|
38
|
-
interface PrivateKeyAccountConfig extends BaseAccountConfig {
|
|
39
|
-
type: typeof ServerAccountType.PrivateKey;
|
|
40
|
-
privateKey: `0x${string}`;
|
|
41
|
-
}
|
|
42
|
-
type ServerAccountConfig = ApiAccountConfig | PrivateKeyAccountConfig;
|
|
43
|
-
type AccountConfig = ServerAccountConfig;
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/account/helpers.d.ts
|
|
46
|
-
declare function isApiAccountConfig(config: ServerAccountConfig): config is ApiAccountConfig;
|
|
47
|
-
declare function isPrivateKeyAccountConfig(config: ServerAccountConfig): config is PrivateKeyAccountConfig;
|
|
48
|
-
declare function createClientContext(config: ServerAccountConfig): OtimServerClientContext;
|
|
49
|
-
//#endregion
|
|
50
|
-
export { AccountType as a, OtimAccountSignMessageArgs as c, ServerAccountType as d, AccountConfig as i, PrivateKeyAccountConfig as l, isApiAccountConfig as n, ApiAccountConfig as o, isPrivateKeyAccountConfig as r, OtimAccount as s, createClientContext as t, ServerAccountConfig as u };
|
|
51
|
-
//# sourceMappingURL=index-C8H-BPGH.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-C8H-BPGH.d.cts","names":[],"sources":["../src/account/types.ts","../src/account/helpers.ts"],"sourcesContent":[],"mappings":";;;;;;cAGa;;;;AAAA,KAID,iBAAA,GADF,CAAA,OAEA,iBAFA,CAAA,CAAA,MAAA,OAEgC,iBAFhC,CAAA;AACE,cAGC,WAHgB,EAAA;EAGhB,SAAA,UAEH,EAAA,YAAA;EACE,SAAA,GAAA,EAAW,KAAA;AAEvB,CAAA;AAIiB,KANL,WAAA,GAMgB,CAAA,OANM,WAMN,CAAA,CAAA,MAAA,OANgC,WAMhC,CAAA;AACZ,KALJ,0BAAA,GAKI;EACI,OAAA,EAAA,MAAA,GAAA;IAAqC,GAAA,EAL9B,GAK8B,GALxB,UAKwB;EAAR,CAAA;CAAO;AAG9C,UALO,WAAA,CAKU;EACX,UAAA,EAAA,EALA,OAKA,CAAA,IAAA,CAAA;EACN,WAAA,CAAA,IAAA,EALU,0BAKV,CAAA,EALuC,OAKvC,CAL+C,GAK/C,CAAA;;UAFA,iBAAA,CAGY;EAGL,WAAA,CAAA,EALD,WAKkB;EAQjB,MAAA,EAZP,KAYO,EAAA;EAKL,YAAA,CAAA,EAhBK,KAgBL;AAEZ;UAfiB,gBAAA,SAAyB;eAC3B,iBAAA,CAAkB;;ECtBjB,UAAA,EAAA,MAAA;EAMA,SAAA,EAAA,MAAA;EAMA,MAAA,CAAA,EAAA,MAAA;;UDiBC,uBAAA,SAAgC;eAClC,iBAAA,CAAkB;;;KAIrB,mBAAA,GAAsB,mBAAmB;KAEzC,aAAA,GAAgB;;;iBCpCZ,kBAAA,SACN,gCACG;iBAIG,yBAAA,SACN,gCACG;iBAIG,mBAAA,SACN,sBACP"}
|