@otim/sdk-core 0.0.0-alpha-20251204003947
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/LICENSE +201 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/abi-DW6AS0eM.d.mts +339 -0
- package/dist/abi-DW6AS0eM.d.mts.map +1 -0
- package/dist/abi-OUq-mx1W.d.cts +339 -0
- package/dist/abi-OUq-mx1W.d.cts.map +1 -0
- package/dist/account/index.cjs +7 -0
- package/dist/account/index.d.cts +5 -0
- package/dist/account/index.d.mts +5 -0
- package/dist/account/index.mjs +3 -0
- package/dist/account-CRvC_dXT.cjs +61 -0
- package/dist/account-CRvC_dXT.cjs.map +1 -0
- package/dist/account-D1NVta26.mjs +31 -0
- package/dist/account-D1NVta26.mjs.map +1 -0
- package/dist/authorization-6anhDdQX.d.cts +210 -0
- package/dist/authorization-6anhDdQX.d.cts.map +1 -0
- package/dist/authorization-DnNpWjxB.d.mts +210 -0
- package/dist/authorization-DnNpWjxB.d.mts.map +1 -0
- package/dist/clients/index.cjs +8 -0
- package/dist/clients/index.d.cts +3 -0
- package/dist/clients/index.d.mts +3 -0
- package/dist/clients/index.mjs +3 -0
- package/dist/clients-BCyzdTLc.cjs +260 -0
- package/dist/clients-BCyzdTLc.cjs.map +1 -0
- package/dist/clients-Bn4BUElo.mjs +225 -0
- package/dist/clients-Bn4BUElo.mjs.map +1 -0
- package/dist/config/index.cjs +10 -0
- package/dist/config/index.d.cts +3 -0
- package/dist/config/index.d.mts +3 -0
- package/dist/config/index.mjs +3 -0
- package/dist/config-C_nc1DXn.mjs +67 -0
- package/dist/config-C_nc1DXn.mjs.map +1 -0
- package/dist/config-CjGpscVk.cjs +114 -0
- package/dist/config-CjGpscVk.cjs.map +1 -0
- package/dist/context/index.cjs +5 -0
- package/dist/context/index.d.cts +5 -0
- package/dist/context/index.d.mts +5 -0
- package/dist/context/index.mjs +3 -0
- package/dist/context-B-Wcmhb3.cjs +38 -0
- package/dist/context-B-Wcmhb3.cjs.map +1 -0
- package/dist/context-uTye69B0.mjs +20 -0
- package/dist/context-uTye69B0.mjs.map +1 -0
- package/dist/index-BQMXYh9N.d.cts +14 -0
- package/dist/index-BQMXYh9N.d.cts.map +1 -0
- package/dist/index-C5c51xs0.d.mts +51 -0
- package/dist/index-C5c51xs0.d.mts.map +1 -0
- package/dist/index-C8H-BPGH.d.cts +51 -0
- package/dist/index-C8H-BPGH.d.cts.map +1 -0
- package/dist/index-Ce_qYSJj.d.cts +90 -0
- package/dist/index-Ce_qYSJj.d.cts.map +1 -0
- package/dist/index-CiyyA-wd.d.mts +90 -0
- package/dist/index-CiyyA-wd.d.mts.map +1 -0
- package/dist/index-CnjY7cyS.d.mts +14 -0
- package/dist/index-CnjY7cyS.d.mts.map +1 -0
- package/dist/index-DWE1xfOE.d.mts +23 -0
- package/dist/index-DWE1xfOE.d.mts.map +1 -0
- package/dist/index-D_7CTJDl.d.mts +27 -0
- package/dist/index-D_7CTJDl.d.mts.map +1 -0
- package/dist/index-GSspyLr3.d.cts +23 -0
- package/dist/index-GSspyLr3.d.cts.map +1 -0
- package/dist/index-lW-Oor1B.d.cts +27 -0
- package/dist/index-lW-Oor1B.d.cts.map +1 -0
- package/dist/index.cjs +32 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +7 -0
- package/dist/rpc-BDoNl1Sp.d.cts +6885 -0
- package/dist/rpc-BDoNl1Sp.d.cts.map +1 -0
- package/dist/rpc-CygBD_f7.d.mts +6885 -0
- package/dist/rpc-CygBD_f7.d.mts.map +1 -0
- package/dist/utils/index.cjs +6 -0
- package/dist/utils/index.d.cts +4 -0
- package/dist/utils/index.d.mts +4 -0
- package/dist/utils/index.mjs +3 -0
- package/dist/utils-CVQFvsfl.cjs +104 -0
- package/dist/utils-CVQFvsfl.cjs.map +1 -0
- package/dist/utils-DziAHBiz.mjs +81 -0
- package/dist/utils-DziAHBiz.mjs.map +1 -0
- package/package.json +162 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
let __otim_utils_helpers = require("@otim/utils/helpers");
|
|
2
|
+
let __otim_sdk_core_config = require("@otim/sdk-core/config");
|
|
3
|
+
let __otim_sdk_core_context = require("@otim/sdk-core/context");
|
|
4
|
+
let __otim_utils_chains = require("@otim/utils/chains");
|
|
5
|
+
let __otim_utils_payments = require("@otim/utils/payments");
|
|
6
|
+
let __otim_utils_schemas = require("@otim/utils/schemas");
|
|
7
|
+
let viem = require("viem");
|
|
8
|
+
let __otim_turnkey_signing = require("@otim/turnkey/signing");
|
|
9
|
+
let viem_accounts = require("viem/accounts");
|
|
10
|
+
let __otim_sdk_core_account = require("@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
|
+
(0, __otim_sdk_core_context.assertRequiresAuth)(this.context);
|
|
32
|
+
const message = (0, __otim_sdk_core_config.createLoginSiweMessage)(address, Date.now().toString());
|
|
33
|
+
const vrsParsedSignature = (0, __otim_utils_helpers.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/payment-signer.ts
|
|
77
|
+
async function createPaymentSigner(params) {
|
|
78
|
+
const { context, buildResponse, publicClient, delegateAddressMap } = params;
|
|
79
|
+
if ((0, __otim_sdk_core_account.isApiAccountConfig)(context.config)) return new __otim_turnkey_signing.UnifiedPaymentSigner({
|
|
80
|
+
buildResponse,
|
|
81
|
+
signingService: new __otim_turnkey_signing.ApiKeyClientSigningService(context.config.publicKey, context.config.privateKey),
|
|
82
|
+
publicClient,
|
|
83
|
+
delegateAddressMap
|
|
84
|
+
}).signAll();
|
|
85
|
+
const walletClient = (0, viem.createWalletClient)({
|
|
86
|
+
account: (0, viem_accounts.privateKeyToAccount)(context.config.privateKey),
|
|
87
|
+
transport: (0, viem.http)()
|
|
88
|
+
});
|
|
89
|
+
return new __otim_turnkey_signing.UnifiedPaymentSigner({
|
|
90
|
+
buildResponse,
|
|
91
|
+
signingService: __otim_turnkey_signing.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(preparedRequest) {
|
|
106
|
+
(0, __otim_sdk_core_context.assertServerContext)(this.context);
|
|
107
|
+
const { payload, chainId } = preparedRequest;
|
|
108
|
+
const buildResponse = await this.buildAndEnhancePaymentRequest(payload);
|
|
109
|
+
await this.activate(buildResponse, chainId);
|
|
110
|
+
return {
|
|
111
|
+
requestId: buildResponse.requestId,
|
|
112
|
+
ephemeralWalletAddress: buildResponse.ephemeralWalletAddress
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async getDetails(request) {
|
|
116
|
+
return this.apiClient.payments.getPaymentRequestDetails(request);
|
|
117
|
+
}
|
|
118
|
+
async list(request) {
|
|
119
|
+
return this.apiClient.payments.getPaymentRequests(request);
|
|
120
|
+
}
|
|
121
|
+
async activate(buildResponse, settlementChainId) {
|
|
122
|
+
const publicClient = this.createPublicClient(settlementChainId);
|
|
123
|
+
const instructions = [...buildResponse.completionInstructions, ...buildResponse.instructions];
|
|
124
|
+
const delegateAddressMap = await this.fetchDelegateAddresses(instructions);
|
|
125
|
+
const { signedAuthorization, completionInstructions, instructions: signedInstructions } = await createPaymentSigner({
|
|
126
|
+
context: this.context,
|
|
127
|
+
buildResponse,
|
|
128
|
+
publicClient,
|
|
129
|
+
delegateAddressMap
|
|
130
|
+
});
|
|
131
|
+
await this.apiClient.payments.newPaymentRequest({
|
|
132
|
+
requestId: buildResponse.requestId,
|
|
133
|
+
signedAuthorization,
|
|
134
|
+
completionInstructions,
|
|
135
|
+
instructions: signedInstructions
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async buildAndEnhancePaymentRequest(payload) {
|
|
139
|
+
const actionNames = (0, __otim_utils_payments.extractActionNamesMap)(payload.completionInstructions, payload.instructions);
|
|
140
|
+
return (0, __otim_utils_payments.addActionNamesToInstructions)((await this.apiClient.payments.buildPaymentRequest(payload)).data, actionNames);
|
|
141
|
+
}
|
|
142
|
+
createPublicClient(chainId) {
|
|
143
|
+
const chain = (0, __otim_utils_chains.getChainById)(chainId);
|
|
144
|
+
if (!chain) throw new Error(`Chain with id ${chainId} not found`);
|
|
145
|
+
return (0, viem.createPublicClient)({
|
|
146
|
+
chain,
|
|
147
|
+
transport: (0, viem.http)()
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
async fetchDelegateAddresses(instructions) {
|
|
151
|
+
const chainIds = Array.from(new Set(instructions.map((instruction) => instruction.chainId)));
|
|
152
|
+
const addresses = await Promise.all(chainIds.map(async (chainId) => {
|
|
153
|
+
const response = await this.apiClient.config.getDelegateAddress({ chainId });
|
|
154
|
+
return [chainId, __otim_utils_schemas.hexStringSchema.parse(response.data.otimDelegateAddress)];
|
|
155
|
+
}));
|
|
156
|
+
return new Map(addresses);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/clients/helpers/prepare-payment-request.ts
|
|
162
|
+
function validateAndGetTokenAddress(chainId, token) {
|
|
163
|
+
const tokenAddress = (0, __otim_utils_chains.getTokenAddress)(chainId, token);
|
|
164
|
+
if (!tokenAddress) throw new Error(`Token ${token} not supported on chain ${chainId}`);
|
|
165
|
+
if (!(0, __otim_utils_chains.getTokenMetadata)(token)) throw new Error(`Token ${token} metadata not found`);
|
|
166
|
+
return __otim_utils_schemas.hexStringSchema.parse(tokenAddress);
|
|
167
|
+
}
|
|
168
|
+
function buildMetadataFromParams(params) {
|
|
169
|
+
const { token, amount, recipient, note, dueDate, customMetadata } = params;
|
|
170
|
+
const baseMetadata = (0, __otim_utils_payments.buildPaymentMetadata)({
|
|
171
|
+
tokenSymbol: token,
|
|
172
|
+
amountInUSD: amount,
|
|
173
|
+
fromAccountAddress: recipient,
|
|
174
|
+
note,
|
|
175
|
+
dueDate,
|
|
176
|
+
hasInvoiceMetadata: false
|
|
177
|
+
});
|
|
178
|
+
return customMetadata ? {
|
|
179
|
+
...baseMetadata,
|
|
180
|
+
...customMetadata
|
|
181
|
+
} : baseMetadata;
|
|
182
|
+
}
|
|
183
|
+
function createPayload(params) {
|
|
184
|
+
const { chainId, recipient, amount, payer, metadata, feeTokenAddress, maxRuns } = params;
|
|
185
|
+
const chainTokenConfigs = (0, __otim_utils_payments.createChainTokenConfigs)(Object.values(__otim_utils_chains.supportedChains.mainnet).flatMap((chain) => (0, __otim_utils_chains.getChainTokens)(chain.id)));
|
|
186
|
+
return (0, __otim_utils_payments.createComprehensivePaymentRequest)({
|
|
187
|
+
settlementChainId: chainId,
|
|
188
|
+
recipient,
|
|
189
|
+
amount: amount.toString(),
|
|
190
|
+
ephemeralWalletAddress: recipient,
|
|
191
|
+
chainTokenConfigs,
|
|
192
|
+
payerAddress: payer ?? null,
|
|
193
|
+
metadata,
|
|
194
|
+
feeToken: feeTokenAddress,
|
|
195
|
+
maxRuns
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function preparePaymentRequest(params) {
|
|
199
|
+
const { chainId, token = "USDC", recipient, amount, payer, note, dueDate, metadata: customMetadata, maxRuns } = params;
|
|
200
|
+
if (dueDate) (0, __otim_utils_helpers.validateIso8601Date)(dueDate);
|
|
201
|
+
const feeTokenAddress = validateAndGetTokenAddress(chainId, token);
|
|
202
|
+
return {
|
|
203
|
+
payload: createPayload({
|
|
204
|
+
chainId,
|
|
205
|
+
recipient,
|
|
206
|
+
amount,
|
|
207
|
+
payer,
|
|
208
|
+
metadata: buildMetadataFromParams({
|
|
209
|
+
token,
|
|
210
|
+
amount,
|
|
211
|
+
recipient,
|
|
212
|
+
note,
|
|
213
|
+
dueDate,
|
|
214
|
+
customMetadata
|
|
215
|
+
}),
|
|
216
|
+
feeTokenAddress,
|
|
217
|
+
maxRuns
|
|
218
|
+
}),
|
|
219
|
+
chainId
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
//#endregion
|
|
224
|
+
Object.defineProperty(exports, 'ActivityClient', {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
get: function () {
|
|
227
|
+
return ActivityClient;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
Object.defineProperty(exports, 'AuthClient', {
|
|
231
|
+
enumerable: true,
|
|
232
|
+
get: function () {
|
|
233
|
+
return AuthClient;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(exports, 'ConfigClient', {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
get: function () {
|
|
239
|
+
return ConfigClient;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
Object.defineProperty(exports, 'DelegationClient', {
|
|
243
|
+
enumerable: true,
|
|
244
|
+
get: function () {
|
|
245
|
+
return DelegationClient;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
Object.defineProperty(exports, 'OrchestrationClient', {
|
|
249
|
+
enumerable: true,
|
|
250
|
+
get: function () {
|
|
251
|
+
return OrchestrationClient;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
Object.defineProperty(exports, 'preparePaymentRequest', {
|
|
255
|
+
enumerable: true,
|
|
256
|
+
get: function () {
|
|
257
|
+
return preparePaymentRequest;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
//# sourceMappingURL=clients-BCyzdTLc.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clients-BCyzdTLc.cjs","names":["apiClient: APIClient","apiClient: APIClient","account: OtimAccount","context: OtimClientContext","apiClient: APIClient","apiClient: APIClient","UnifiedPaymentSigner","ApiKeyClientSigningService","ServerWalletSigningService","apiClient: APIClient","account: OtimAccount","context: OtimServerClientContext","hexStringSchema","hexStringSchema","supportedChains"],"sources":["../src/clients/activity.ts","../src/clients/auth.ts","../src/clients/config.ts","../src/clients/delegation.ts","../src/clients/helpers/payment-signer.ts","../src/clients/orchestration.ts","../src/clients/helpers/prepare-payment-request.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 CreatePaymentSignerParams {\n context: OtimServerClientContext;\n buildResponse: PaymentResponseWithActionNames;\n publicClient: PublicClient;\n delegateAddressMap: Map<number, Address>;\n}\n\ntype CreatePaymentSignerResult = Awaited<\n ReturnType<UnifiedPaymentSigner[\"signAll\"]>\n>;\n\nexport async function createPaymentSigner(\n params: CreatePaymentSignerParams,\n): Promise<CreatePaymentSignerResult> {\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 { 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 { createPaymentSigner } from \"./helpers/payment-signer\";\nimport type { PreparedPaymentRequest } from \"./helpers/prepare-payment-request\";\n\nexport type { PreparedPaymentRequest } from \"./helpers/prepare-payment-request\";\n\nexport interface CreatePaymentRequestResponse {\n requestId: string;\n ephemeralWalletAddress: Address;\n}\n\ntype PaymentInstruction =\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 preparedRequest: PreparedPaymentRequest,\n ): Promise<CreatePaymentRequestResponse> {\n assertServerContext(this.context);\n\n const { payload, chainId } = preparedRequest;\n\n const buildResponse = await this.buildAndEnhancePaymentRequest(payload);\n await this.activate(buildResponse, chainId);\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 createPaymentSigner({\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 buildAndEnhancePaymentRequest(\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: PaymentInstruction[],\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 { PaymentRequestBuildRequest } from \"@otim/utils/api\";\nimport 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 {\n getChainTokens,\n getTokenAddress,\n getTokenMetadata,\n supportedChains,\n} from \"@otim/utils/chains\";\nimport { validateIso8601Date } from \"@otim/utils/helpers\";\nimport {\n buildPaymentMetadata,\n createChainTokenConfigs,\n createComprehensivePaymentRequest,\n} from \"@otim/utils/payments\";\nimport { hexStringSchema } from \"@otim/utils/schemas\";\n\nexport interface PreparePaymentRequestParams {\n amount: number;\n chainId: SupportedChainId;\n recipient: Address;\n token?: \"USDC\" | \"USDT\";\n payer?: Nullable<Address>;\n dueDate?: string;\n metadata?: PaymentRequestMetadata;\n note?: string;\n maxRuns?: number;\n}\n\nexport interface PreparedPaymentRequest {\n payload: PaymentRequestBuildRequest;\n chainId: number;\n}\n\nfunction validateAndGetTokenAddress(chainId: number, token: string): Address {\n const tokenAddress = getTokenAddress(chainId, token);\n if (!tokenAddress) {\n throw new Error(`Token ${token} not supported on chain ${chainId}`);\n }\n\n const tokenMetadata = getTokenMetadata(token);\n if (!tokenMetadata) {\n throw new Error(`Token ${token} metadata not found`);\n }\n\n return hexStringSchema.parse(tokenAddress);\n}\n\nfunction buildMetadataFromParams(params: {\n token: string;\n amount: number;\n recipient: Address;\n note?: string;\n dueDate?: string;\n customMetadata?: PaymentRequestMetadata;\n}): PaymentRequestMetadata {\n const { token, amount, recipient, note, dueDate, customMetadata } = params;\n\n const baseMetadata = buildPaymentMetadata({\n tokenSymbol: token,\n amountInUSD: amount,\n fromAccountAddress: recipient,\n note,\n dueDate,\n hasInvoiceMetadata: false,\n });\n\n return customMetadata ? { ...baseMetadata, ...customMetadata } : baseMetadata;\n}\n\nfunction createPayload(params: {\n chainId: number;\n recipient: Address;\n amount: number;\n payer?: Address | null;\n metadata: PaymentRequestMetadata;\n feeTokenAddress: Address;\n maxRuns?: number;\n}): PaymentRequestBuildRequest {\n const {\n chainId,\n recipient,\n amount,\n payer,\n metadata,\n feeTokenAddress,\n maxRuns,\n } = params;\n\n const tokens = Object.values(supportedChains.mainnet).flatMap((chain) =>\n getChainTokens(chain.id),\n );\n\n const chainTokenConfigs = createChainTokenConfigs(tokens);\n\n return createComprehensivePaymentRequest({\n settlementChainId: chainId,\n recipient,\n amount: amount.toString(),\n ephemeralWalletAddress: recipient,\n chainTokenConfigs,\n payerAddress: payer ?? null,\n metadata,\n feeToken: feeTokenAddress,\n maxRuns,\n });\n}\n\nexport function preparePaymentRequest(\n params: PreparePaymentRequestParams,\n): PreparedPaymentRequest {\n const {\n chainId,\n token = \"USDC\",\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 feeTokenAddress = validateAndGetTokenAddress(chainId, token);\n const metadata = buildMetadataFromParams({\n token,\n amount,\n recipient,\n note,\n dueDate,\n customMetadata,\n });\n\n const payload = createPayload({\n chainId,\n recipient,\n amount,\n payer,\n metadata,\n feeTokenAddress,\n maxRuns,\n });\n\n return { payload, chainId };\n}\n"],"mappings":";;;;;;;;;;;;AA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OAAOC,oCAAgB,QAAQ,CAAC,SAAS,kDAC9C,MAAM,GAAG,CACzB,CAEwD;AAEzD,qEAAyC;EACvC,mBAAmB;EACnB;EACA,QAAQ,OAAO,UAAU;EACzB,wBAAwB;EACxB;EACA,cAAc,SAAS;EACvB;EACA,UAAU;EACV;EACD,CAAC;;AAGJ,SAAgB,sBACd,QACwB;CACxB,MAAM,EACJ,SACA,QAAQ,QACR,WACA,QACA,OACA,MACA,SACA,UAAU,gBACV,YACE;AAEJ,KAAI,QACF,+CAAoB,QAAQ;CAG9B,MAAM,kBAAkB,2BAA2B,SAAS,MAAM;AAoBlE,QAAO;EAAE,SAVO,cAAc;GAC5B;GACA;GACA;GACA;GACA,UAde,wBAAwB;IACvC;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;GAQA;GACA;GACD,CAAC;EAEgB;EAAS"}
|
|
@@ -0,0 +1,225 @@
|
|
|
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, getChainTokens, getTokenAddress, getTokenMetadata, supportedChains } from "@otim/utils/chains";
|
|
5
|
+
import { addActionNamesToInstructions, buildPaymentMetadata, createChainTokenConfigs, createComprehensivePaymentRequest, 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/payment-signer.ts
|
|
77
|
+
async function createPaymentSigner(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(preparedRequest) {
|
|
106
|
+
assertServerContext(this.context);
|
|
107
|
+
const { payload, chainId } = preparedRequest;
|
|
108
|
+
const buildResponse = await this.buildAndEnhancePaymentRequest(payload);
|
|
109
|
+
await this.activate(buildResponse, chainId);
|
|
110
|
+
return {
|
|
111
|
+
requestId: buildResponse.requestId,
|
|
112
|
+
ephemeralWalletAddress: buildResponse.ephemeralWalletAddress
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async getDetails(request) {
|
|
116
|
+
return this.apiClient.payments.getPaymentRequestDetails(request);
|
|
117
|
+
}
|
|
118
|
+
async list(request) {
|
|
119
|
+
return this.apiClient.payments.getPaymentRequests(request);
|
|
120
|
+
}
|
|
121
|
+
async activate(buildResponse, settlementChainId) {
|
|
122
|
+
const publicClient = this.createPublicClient(settlementChainId);
|
|
123
|
+
const instructions = [...buildResponse.completionInstructions, ...buildResponse.instructions];
|
|
124
|
+
const delegateAddressMap = await this.fetchDelegateAddresses(instructions);
|
|
125
|
+
const { signedAuthorization, completionInstructions, instructions: signedInstructions } = await createPaymentSigner({
|
|
126
|
+
context: this.context,
|
|
127
|
+
buildResponse,
|
|
128
|
+
publicClient,
|
|
129
|
+
delegateAddressMap
|
|
130
|
+
});
|
|
131
|
+
await this.apiClient.payments.newPaymentRequest({
|
|
132
|
+
requestId: buildResponse.requestId,
|
|
133
|
+
signedAuthorization,
|
|
134
|
+
completionInstructions,
|
|
135
|
+
instructions: signedInstructions
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async buildAndEnhancePaymentRequest(payload) {
|
|
139
|
+
const actionNames = extractActionNamesMap(payload.completionInstructions, payload.instructions);
|
|
140
|
+
return addActionNamesToInstructions((await this.apiClient.payments.buildPaymentRequest(payload)).data, actionNames);
|
|
141
|
+
}
|
|
142
|
+
createPublicClient(chainId) {
|
|
143
|
+
const chain = getChainById(chainId);
|
|
144
|
+
if (!chain) throw new Error(`Chain with id ${chainId} not found`);
|
|
145
|
+
return createPublicClient({
|
|
146
|
+
chain,
|
|
147
|
+
transport: http()
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
async fetchDelegateAddresses(instructions) {
|
|
151
|
+
const chainIds = Array.from(new Set(instructions.map((instruction) => instruction.chainId)));
|
|
152
|
+
const addresses = await Promise.all(chainIds.map(async (chainId) => {
|
|
153
|
+
const response = await this.apiClient.config.getDelegateAddress({ chainId });
|
|
154
|
+
return [chainId, hexStringSchema.parse(response.data.otimDelegateAddress)];
|
|
155
|
+
}));
|
|
156
|
+
return new Map(addresses);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/clients/helpers/prepare-payment-request.ts
|
|
162
|
+
function validateAndGetTokenAddress(chainId, token) {
|
|
163
|
+
const tokenAddress = getTokenAddress(chainId, token);
|
|
164
|
+
if (!tokenAddress) throw new Error(`Token ${token} not supported on chain ${chainId}`);
|
|
165
|
+
if (!getTokenMetadata(token)) throw new Error(`Token ${token} metadata not found`);
|
|
166
|
+
return hexStringSchema.parse(tokenAddress);
|
|
167
|
+
}
|
|
168
|
+
function buildMetadataFromParams(params) {
|
|
169
|
+
const { token, amount, recipient, note, dueDate, customMetadata } = params;
|
|
170
|
+
const baseMetadata = buildPaymentMetadata({
|
|
171
|
+
tokenSymbol: token,
|
|
172
|
+
amountInUSD: amount,
|
|
173
|
+
fromAccountAddress: recipient,
|
|
174
|
+
note,
|
|
175
|
+
dueDate,
|
|
176
|
+
hasInvoiceMetadata: false
|
|
177
|
+
});
|
|
178
|
+
return customMetadata ? {
|
|
179
|
+
...baseMetadata,
|
|
180
|
+
...customMetadata
|
|
181
|
+
} : baseMetadata;
|
|
182
|
+
}
|
|
183
|
+
function createPayload(params) {
|
|
184
|
+
const { chainId, recipient, amount, payer, metadata, feeTokenAddress, maxRuns } = params;
|
|
185
|
+
const chainTokenConfigs = createChainTokenConfigs(Object.values(supportedChains.mainnet).flatMap((chain) => getChainTokens(chain.id)));
|
|
186
|
+
return createComprehensivePaymentRequest({
|
|
187
|
+
settlementChainId: chainId,
|
|
188
|
+
recipient,
|
|
189
|
+
amount: amount.toString(),
|
|
190
|
+
ephemeralWalletAddress: recipient,
|
|
191
|
+
chainTokenConfigs,
|
|
192
|
+
payerAddress: payer ?? null,
|
|
193
|
+
metadata,
|
|
194
|
+
feeToken: feeTokenAddress,
|
|
195
|
+
maxRuns
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function preparePaymentRequest(params) {
|
|
199
|
+
const { chainId, token = "USDC", recipient, amount, payer, note, dueDate, metadata: customMetadata, maxRuns } = params;
|
|
200
|
+
if (dueDate) validateIso8601Date(dueDate);
|
|
201
|
+
const feeTokenAddress = validateAndGetTokenAddress(chainId, token);
|
|
202
|
+
return {
|
|
203
|
+
payload: createPayload({
|
|
204
|
+
chainId,
|
|
205
|
+
recipient,
|
|
206
|
+
amount,
|
|
207
|
+
payer,
|
|
208
|
+
metadata: buildMetadataFromParams({
|
|
209
|
+
token,
|
|
210
|
+
amount,
|
|
211
|
+
recipient,
|
|
212
|
+
note,
|
|
213
|
+
dueDate,
|
|
214
|
+
customMetadata
|
|
215
|
+
}),
|
|
216
|
+
feeTokenAddress,
|
|
217
|
+
maxRuns
|
|
218
|
+
}),
|
|
219
|
+
chainId
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
//#endregion
|
|
224
|
+
export { AuthClient as a, ConfigClient as i, OrchestrationClient as n, ActivityClient as o, DelegationClient as r, preparePaymentRequest as t };
|
|
225
|
+
//# sourceMappingURL=clients-Bn4BUElo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clients-Bn4BUElo.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/payment-signer.ts","../src/clients/orchestration.ts","../src/clients/helpers/prepare-payment-request.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 CreatePaymentSignerParams {\n context: OtimServerClientContext;\n buildResponse: PaymentResponseWithActionNames;\n publicClient: PublicClient;\n delegateAddressMap: Map<number, Address>;\n}\n\ntype CreatePaymentSignerResult = Awaited<\n ReturnType<UnifiedPaymentSigner[\"signAll\"]>\n>;\n\nexport async function createPaymentSigner(\n params: CreatePaymentSignerParams,\n): Promise<CreatePaymentSignerResult> {\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 { 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 { createPaymentSigner } from \"./helpers/payment-signer\";\nimport type { PreparedPaymentRequest } from \"./helpers/prepare-payment-request\";\n\nexport type { PreparedPaymentRequest } from \"./helpers/prepare-payment-request\";\n\nexport interface CreatePaymentRequestResponse {\n requestId: string;\n ephemeralWalletAddress: Address;\n}\n\ntype PaymentInstruction =\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 preparedRequest: PreparedPaymentRequest,\n ): Promise<CreatePaymentRequestResponse> {\n assertServerContext(this.context);\n\n const { payload, chainId } = preparedRequest;\n\n const buildResponse = await this.buildAndEnhancePaymentRequest(payload);\n await this.activate(buildResponse, chainId);\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 createPaymentSigner({\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 buildAndEnhancePaymentRequest(\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: PaymentInstruction[],\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 { PaymentRequestBuildRequest } from \"@otim/utils/api\";\nimport 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 {\n getChainTokens,\n getTokenAddress,\n getTokenMetadata,\n supportedChains,\n} from \"@otim/utils/chains\";\nimport { validateIso8601Date } from \"@otim/utils/helpers\";\nimport {\n buildPaymentMetadata,\n createChainTokenConfigs,\n createComprehensivePaymentRequest,\n} from \"@otim/utils/payments\";\nimport { hexStringSchema } from \"@otim/utils/schemas\";\n\nexport interface PreparePaymentRequestParams {\n amount: number;\n chainId: SupportedChainId;\n recipient: Address;\n token?: \"USDC\" | \"USDT\";\n payer?: Nullable<Address>;\n dueDate?: string;\n metadata?: PaymentRequestMetadata;\n note?: string;\n maxRuns?: number;\n}\n\nexport interface PreparedPaymentRequest {\n payload: PaymentRequestBuildRequest;\n chainId: number;\n}\n\nfunction validateAndGetTokenAddress(chainId: number, token: string): Address {\n const tokenAddress = getTokenAddress(chainId, token);\n if (!tokenAddress) {\n throw new Error(`Token ${token} not supported on chain ${chainId}`);\n }\n\n const tokenMetadata = getTokenMetadata(token);\n if (!tokenMetadata) {\n throw new Error(`Token ${token} metadata not found`);\n }\n\n return hexStringSchema.parse(tokenAddress);\n}\n\nfunction buildMetadataFromParams(params: {\n token: string;\n amount: number;\n recipient: Address;\n note?: string;\n dueDate?: string;\n customMetadata?: PaymentRequestMetadata;\n}): PaymentRequestMetadata {\n const { token, amount, recipient, note, dueDate, customMetadata } = params;\n\n const baseMetadata = buildPaymentMetadata({\n tokenSymbol: token,\n amountInUSD: amount,\n fromAccountAddress: recipient,\n note,\n dueDate,\n hasInvoiceMetadata: false,\n });\n\n return customMetadata ? { ...baseMetadata, ...customMetadata } : baseMetadata;\n}\n\nfunction createPayload(params: {\n chainId: number;\n recipient: Address;\n amount: number;\n payer?: Address | null;\n metadata: PaymentRequestMetadata;\n feeTokenAddress: Address;\n maxRuns?: number;\n}): PaymentRequestBuildRequest {\n const {\n chainId,\n recipient,\n amount,\n payer,\n metadata,\n feeTokenAddress,\n maxRuns,\n } = params;\n\n const tokens = Object.values(supportedChains.mainnet).flatMap((chain) =>\n getChainTokens(chain.id),\n );\n\n const chainTokenConfigs = createChainTokenConfigs(tokens);\n\n return createComprehensivePaymentRequest({\n settlementChainId: chainId,\n recipient,\n amount: amount.toString(),\n ephemeralWalletAddress: recipient,\n chainTokenConfigs,\n payerAddress: payer ?? null,\n metadata,\n feeToken: feeTokenAddress,\n maxRuns,\n });\n}\n\nexport function preparePaymentRequest(\n params: PreparePaymentRequestParams,\n): PreparedPaymentRequest {\n const {\n chainId,\n token = \"USDC\",\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 feeTokenAddress = validateAndGetTokenAddress(chainId, token);\n const metadata = buildMetadataFromParams({\n token,\n amount,\n recipient,\n note,\n dueDate,\n customMetadata,\n });\n\n const payload = createPayload({\n chainId,\n recipient,\n amount,\n payer,\n metadata,\n feeTokenAddress,\n maxRuns,\n });\n\n return { payload, chainId };\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;EAEhC,MAAM,UAAU,uBAAuB,SAAS,KAAK,KAAK,CAAC,UAAU,CAAC;EAEtE,MAAM,qBAAqB,oBADT,MAAM,KAAK,QAAQ,YAAY,EAAE,SAAS,CAAC,CACJ;AAOzD,UALiB,MAAM,KAAK,UAAU,KAAK,MAAM;GAC/C,MAAM;GACN,WAAW;GACZ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;GACA,UAde,wBAAwB;IACvC;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;GAQA;GACA;GACD,CAAC;EAEgB;EAAS"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const require_config = require('../config-CjGpscVk.cjs');
|
|
2
|
+
|
|
3
|
+
exports.Environment = require_config.Environment;
|
|
4
|
+
exports.SIWE_CHAIN_ID = require_config.SIWE_CHAIN_ID;
|
|
5
|
+
exports.SIWE_VERSION = require_config.SIWE_VERSION;
|
|
6
|
+
exports.createLoginSiweMessage = require_config.createLoginSiweMessage;
|
|
7
|
+
exports.env = require_config.env;
|
|
8
|
+
exports.getApiUrl = require_config.getApiUrl;
|
|
9
|
+
exports.getTurnkeyApiUrl = require_config.getTurnkeyApiUrl;
|
|
10
|
+
exports.isEnvironment = require_config.isEnvironment;
|
|
@@ -0,0 +1,3 @@
|
|
|
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 };
|
|
@@ -0,0 +1,3 @@
|
|
|
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 };
|
|
@@ -0,0 +1,3 @@
|
|
|
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 };
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|