@otim/sdk-core 0.0.3 → 0.0.4-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- 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 +1 -1
- package/dist/account/index.d.cts +5 -3
- package/dist/account/index.d.mts +5 -3
- package/dist/account/index.mjs +1 -1
- package/dist/{account-Bwm5PTcc.cjs → account-CRvC_dXT.cjs} +8 -3
- package/dist/account-CRvC_dXT.cjs.map +1 -0
- package/dist/{account-p4sxzIt3.mjs → account-D1NVta26.mjs} +8 -3
- 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 +2 -2
- package/dist/clients/index.d.cts +3 -3
- package/dist/clients/index.d.mts +3 -3
- package/dist/clients/index.mjs +2 -2
- package/dist/{clients-CVg-yW5b.cjs → clients-BCyzdTLc.cjs} +73 -127
- package/dist/clients-BCyzdTLc.cjs.map +1 -0
- package/dist/{clients-DnPvBXkX.mjs → clients-Bn4BUElo.mjs} +72 -126
- package/dist/clients-Bn4BUElo.mjs.map +1 -0
- package/dist/config/index.d.cts +2 -2
- package/dist/config/index.d.mts +2 -2
- package/dist/context/index.d.cts +4 -1
- package/dist/context/index.d.mts +4 -1
- package/dist/{index-DW_zBRKz.d.mts → index-BQMXYh9N.d.cts} +2 -13
- package/dist/index-BQMXYh9N.d.cts.map +1 -0
- package/dist/{index-B4fkcFy5.d.mts → index-C5c51xs0.d.mts} +5 -8
- package/dist/index-C5c51xs0.d.mts.map +1 -0
- package/dist/{index-DK-40z4V.d.cts → index-C8H-BPGH.d.cts} +5 -8
- package/dist/index-C8H-BPGH.d.cts.map +1 -0
- package/dist/{index-747pyuMH.d.mts → index-Ce_qYSJj.d.cts} +25 -38
- package/dist/index-Ce_qYSJj.d.cts.map +1 -0
- package/dist/{index-BH1YuouL.d.cts → index-CiyyA-wd.d.mts} +25 -38
- package/dist/index-CiyyA-wd.d.mts.map +1 -0
- package/dist/{index-BnP8vpJJ.d.cts → index-CnjY7cyS.d.mts} +2 -13
- package/dist/index-CnjY7cyS.d.mts.map +1 -0
- package/dist/{index-CcCMIBgF.d.mts → index-DWE1xfOE.d.mts} +4 -1
- package/dist/index-DWE1xfOE.d.mts.map +1 -0
- package/dist/{index-UnaahQgb.d.cts → index-D_7CTJDl.d.mts} +2 -2
- package/dist/{index-C4N2Xixk.d.mts.map → index-D_7CTJDl.d.mts.map} +1 -1
- package/dist/{index-C1HSAemv.d.cts → index-GSspyLr3.d.cts} +4 -1
- package/dist/index-GSspyLr3.d.cts.map +1 -0
- package/dist/{index-C4N2Xixk.d.mts → index-lW-Oor1B.d.cts} +2 -2
- package/dist/{index-UnaahQgb.d.cts.map → index-lW-Oor1B.d.cts.map} +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +9 -8
- package/dist/index.d.mts +9 -8
- package/dist/index.mjs +3 -3
- 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.d.cts +3 -3
- package/dist/utils/index.d.mts +3 -3
- package/package.json +3 -3
- package/dist/abi-Bd3X6gV9.d.mts +0 -154
- package/dist/abi-Bd3X6gV9.d.mts.map +0 -1
- package/dist/abi-CQuxrNCU.d.cts +0 -154
- package/dist/abi-CQuxrNCU.d.cts.map +0 -1
- package/dist/account-Bwm5PTcc.cjs.map +0 -1
- package/dist/account-p4sxzIt3.mjs.map +0 -1
- package/dist/clients-CVg-yW5b.cjs.map +0 -1
- package/dist/clients-DnPvBXkX.mjs.map +0 -1
- package/dist/index-747pyuMH.d.mts.map +0 -1
- package/dist/index-B4fkcFy5.d.mts.map +0 -1
- package/dist/index-BH1YuouL.d.cts.map +0 -1
- package/dist/index-BnP8vpJJ.d.cts.map +0 -1
- package/dist/index-C1HSAemv.d.cts.map +0 -1
- package/dist/index-CcCMIBgF.d.mts.map +0 -1
- package/dist/index-DK-40z4V.d.cts.map +0 -1
- package/dist/index-DW_zBRKz.d.mts.map +0 -1
- package/dist/misc-CX4pLJaA.d.mts +0 -42
- package/dist/misc-CX4pLJaA.d.mts.map +0 -1
- package/dist/misc-CpZxSPCP.d.cts +0 -42
- package/dist/misc-CpZxSPCP.d.cts.map +0 -1
|
@@ -95,46 +95,30 @@ async function createPaymentSigner(params) {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
//#endregion
|
|
98
|
-
//#region src/clients/
|
|
99
|
-
var
|
|
98
|
+
//#region src/clients/orchestration.ts
|
|
99
|
+
var OrchestrationClient = class {
|
|
100
100
|
constructor(apiClient, account, context) {
|
|
101
101
|
this.apiClient = apiClient;
|
|
102
102
|
this.account = account;
|
|
103
103
|
this.context = context;
|
|
104
104
|
}
|
|
105
|
-
async create(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const feeTokenAddress = this.validateAndGetTokenAddress(chainId, token);
|
|
109
|
-
const metadata = this.buildMetadata({
|
|
110
|
-
token,
|
|
111
|
-
amount,
|
|
112
|
-
recipient,
|
|
113
|
-
note,
|
|
114
|
-
dueDate,
|
|
115
|
-
customMetadata
|
|
116
|
-
});
|
|
117
|
-
const payload = this.createPayload({
|
|
118
|
-
chainId,
|
|
119
|
-
recipient,
|
|
120
|
-
amount,
|
|
121
|
-
payer,
|
|
122
|
-
metadata,
|
|
123
|
-
feeTokenAddress
|
|
124
|
-
});
|
|
105
|
+
async create(preparedRequest) {
|
|
106
|
+
(0, __otim_sdk_core_context.assertServerContext)(this.context);
|
|
107
|
+
const { payload, chainId } = preparedRequest;
|
|
125
108
|
const buildResponse = await this.buildAndEnhancePaymentRequest(payload);
|
|
126
|
-
await this.activate(
|
|
127
|
-
buildResponse,
|
|
128
|
-
settlementChainId: chainId
|
|
129
|
-
});
|
|
109
|
+
await this.activate(buildResponse, chainId);
|
|
130
110
|
return {
|
|
131
111
|
requestId: buildResponse.requestId,
|
|
132
112
|
ephemeralWalletAddress: buildResponse.ephemeralWalletAddress
|
|
133
113
|
};
|
|
134
114
|
}
|
|
135
|
-
async
|
|
136
|
-
|
|
137
|
-
|
|
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) {
|
|
138
122
|
const publicClient = this.createPublicClient(settlementChainId);
|
|
139
123
|
const instructions = [...buildResponse.completionInstructions, ...buildResponse.instructions];
|
|
140
124
|
const delegateAddressMap = await this.fetchDelegateAddresses(instructions);
|
|
@@ -151,41 +135,6 @@ var PaymentRequestsClient = class {
|
|
|
151
135
|
instructions: signedInstructions
|
|
152
136
|
});
|
|
153
137
|
}
|
|
154
|
-
validateAndGetTokenAddress(chainId, token) {
|
|
155
|
-
const tokenAddress = (0, __otim_utils_chains.getTokenAddress)(chainId, token);
|
|
156
|
-
if (!tokenAddress) throw new Error(`Token ${token} not supported on chain ${chainId}`);
|
|
157
|
-
if (!(0, __otim_utils_chains.getTokenMetadata)(token)) throw new Error(`Token ${token} metadata not found`);
|
|
158
|
-
return __otim_utils_schemas.hexStringSchema.parse(tokenAddress);
|
|
159
|
-
}
|
|
160
|
-
buildMetadata(params) {
|
|
161
|
-
const { token, amount, recipient, note, dueDate, customMetadata } = params;
|
|
162
|
-
const baseMetadata = (0, __otim_utils_payments.buildPaymentMetadata)({
|
|
163
|
-
tokenSymbol: token,
|
|
164
|
-
amountInUSD: amount,
|
|
165
|
-
fromAccountAddress: recipient,
|
|
166
|
-
note,
|
|
167
|
-
dueDate,
|
|
168
|
-
hasInvoiceMetadata: false
|
|
169
|
-
});
|
|
170
|
-
return customMetadata ? {
|
|
171
|
-
...baseMetadata,
|
|
172
|
-
...customMetadata
|
|
173
|
-
} : baseMetadata;
|
|
174
|
-
}
|
|
175
|
-
createPayload(params) {
|
|
176
|
-
const { chainId, recipient, amount, payer, metadata, feeTokenAddress } = params;
|
|
177
|
-
const chainTokenConfigs = (0, __otim_utils_payments.createChainTokenConfigs)(Object.values(__otim_utils_chains.supportedChains.mainnet).flatMap((chain) => (0, __otim_utils_chains.getChainTokens)(chain.id)));
|
|
178
|
-
return (0, __otim_utils_payments.createComprehensivePaymentRequest)({
|
|
179
|
-
settlementChainId: chainId,
|
|
180
|
-
recipient,
|
|
181
|
-
amount: amount.toString(),
|
|
182
|
-
ephemeralWalletAddress: recipient,
|
|
183
|
-
chainTokenConfigs,
|
|
184
|
-
payerAddress: payer ?? null,
|
|
185
|
-
metadata,
|
|
186
|
-
feeToken: feeTokenAddress
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
138
|
async buildAndEnhancePaymentRequest(payload) {
|
|
190
139
|
const actionNames = (0, __otim_utils_payments.extractActionNamesMap)(payload.completionInstructions, payload.instructions);
|
|
191
140
|
return (0, __otim_utils_payments.addActionNamesToInstructions)((await this.apiClient.payments.buildPaymentRequest(payload)).data, actionNames);
|
|
@@ -206,74 +155,71 @@ var PaymentRequestsClient = class {
|
|
|
206
155
|
}));
|
|
207
156
|
return new Map(addresses);
|
|
208
157
|
}
|
|
209
|
-
async getDetails(request) {
|
|
210
|
-
return this.apiClient.payments.getPaymentRequestDetails(request);
|
|
211
|
-
}
|
|
212
|
-
async listOutgoingPaymentRequests(request) {
|
|
213
|
-
return this.apiClient.payments.getOutgoingPaymentsList(request);
|
|
214
|
-
}
|
|
215
|
-
async listIncomingPaymentRequests(request) {
|
|
216
|
-
return this.apiClient.payments.getIncomingPaymentsList(request);
|
|
217
|
-
}
|
|
218
|
-
async list(request) {
|
|
219
|
-
return this.apiClient.payments.getPaymentRequests(request);
|
|
220
|
-
}
|
|
221
158
|
};
|
|
222
159
|
|
|
223
160
|
//#endregion
|
|
224
|
-
//#region
|
|
225
|
-
function
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
231
|
-
}, _typeof(o);
|
|
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);
|
|
232
167
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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;
|
|
245
182
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
+
});
|
|
252
197
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
+
};
|
|
263
221
|
}
|
|
264
222
|
|
|
265
|
-
//#endregion
|
|
266
|
-
//#region src/clients/orchestration.ts
|
|
267
|
-
var OrchestrationClient = class {
|
|
268
|
-
constructor(apiClient, account, context) {
|
|
269
|
-
this.apiClient = apiClient;
|
|
270
|
-
this.account = account;
|
|
271
|
-
this.context = context;
|
|
272
|
-
_defineProperty(this, "paymentRequests", void 0);
|
|
273
|
-
this.paymentRequests = new PaymentRequestsClient(apiClient, account, context);
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
|
|
277
223
|
//#endregion
|
|
278
224
|
Object.defineProperty(exports, 'ActivityClient', {
|
|
279
225
|
enumerable: true,
|
|
@@ -305,10 +251,10 @@ Object.defineProperty(exports, 'OrchestrationClient', {
|
|
|
305
251
|
return OrchestrationClient;
|
|
306
252
|
}
|
|
307
253
|
});
|
|
308
|
-
Object.defineProperty(exports, '
|
|
254
|
+
Object.defineProperty(exports, 'preparePaymentRequest', {
|
|
309
255
|
enumerable: true,
|
|
310
256
|
get: function () {
|
|
311
|
-
return
|
|
257
|
+
return preparePaymentRequest;
|
|
312
258
|
}
|
|
313
259
|
});
|
|
314
|
-
//# sourceMappingURL=clients-
|
|
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":";;;;;;;;;;;;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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A;GACA;GACA;GACA,UAde,wBAAwB;IACvC;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;GAQA;GACA;GACD,CAAC;EAEgB;EAAS"}
|
|
@@ -95,46 +95,30 @@ async function createPaymentSigner(params) {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
//#endregion
|
|
98
|
-
//#region src/clients/
|
|
99
|
-
var
|
|
98
|
+
//#region src/clients/orchestration.ts
|
|
99
|
+
var OrchestrationClient = class {
|
|
100
100
|
constructor(apiClient, account, context) {
|
|
101
101
|
this.apiClient = apiClient;
|
|
102
102
|
this.account = account;
|
|
103
103
|
this.context = context;
|
|
104
104
|
}
|
|
105
|
-
async create(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const feeTokenAddress = this.validateAndGetTokenAddress(chainId, token);
|
|
109
|
-
const metadata = this.buildMetadata({
|
|
110
|
-
token,
|
|
111
|
-
amount,
|
|
112
|
-
recipient,
|
|
113
|
-
note,
|
|
114
|
-
dueDate,
|
|
115
|
-
customMetadata
|
|
116
|
-
});
|
|
117
|
-
const payload = this.createPayload({
|
|
118
|
-
chainId,
|
|
119
|
-
recipient,
|
|
120
|
-
amount,
|
|
121
|
-
payer,
|
|
122
|
-
metadata,
|
|
123
|
-
feeTokenAddress
|
|
124
|
-
});
|
|
105
|
+
async create(preparedRequest) {
|
|
106
|
+
assertServerContext(this.context);
|
|
107
|
+
const { payload, chainId } = preparedRequest;
|
|
125
108
|
const buildResponse = await this.buildAndEnhancePaymentRequest(payload);
|
|
126
|
-
await this.activate(
|
|
127
|
-
buildResponse,
|
|
128
|
-
settlementChainId: chainId
|
|
129
|
-
});
|
|
109
|
+
await this.activate(buildResponse, chainId);
|
|
130
110
|
return {
|
|
131
111
|
requestId: buildResponse.requestId,
|
|
132
112
|
ephemeralWalletAddress: buildResponse.ephemeralWalletAddress
|
|
133
113
|
};
|
|
134
114
|
}
|
|
135
|
-
async
|
|
136
|
-
|
|
137
|
-
|
|
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) {
|
|
138
122
|
const publicClient = this.createPublicClient(settlementChainId);
|
|
139
123
|
const instructions = [...buildResponse.completionInstructions, ...buildResponse.instructions];
|
|
140
124
|
const delegateAddressMap = await this.fetchDelegateAddresses(instructions);
|
|
@@ -151,41 +135,6 @@ var PaymentRequestsClient = class {
|
|
|
151
135
|
instructions: signedInstructions
|
|
152
136
|
});
|
|
153
137
|
}
|
|
154
|
-
validateAndGetTokenAddress(chainId, token) {
|
|
155
|
-
const tokenAddress = getTokenAddress(chainId, token);
|
|
156
|
-
if (!tokenAddress) throw new Error(`Token ${token} not supported on chain ${chainId}`);
|
|
157
|
-
if (!getTokenMetadata(token)) throw new Error(`Token ${token} metadata not found`);
|
|
158
|
-
return hexStringSchema.parse(tokenAddress);
|
|
159
|
-
}
|
|
160
|
-
buildMetadata(params) {
|
|
161
|
-
const { token, amount, recipient, note, dueDate, customMetadata } = params;
|
|
162
|
-
const baseMetadata = buildPaymentMetadata({
|
|
163
|
-
tokenSymbol: token,
|
|
164
|
-
amountInUSD: amount,
|
|
165
|
-
fromAccountAddress: recipient,
|
|
166
|
-
note,
|
|
167
|
-
dueDate,
|
|
168
|
-
hasInvoiceMetadata: false
|
|
169
|
-
});
|
|
170
|
-
return customMetadata ? {
|
|
171
|
-
...baseMetadata,
|
|
172
|
-
...customMetadata
|
|
173
|
-
} : baseMetadata;
|
|
174
|
-
}
|
|
175
|
-
createPayload(params) {
|
|
176
|
-
const { chainId, recipient, amount, payer, metadata, feeTokenAddress } = params;
|
|
177
|
-
const chainTokenConfigs = createChainTokenConfigs(Object.values(supportedChains.mainnet).flatMap((chain) => getChainTokens(chain.id)));
|
|
178
|
-
return createComprehensivePaymentRequest({
|
|
179
|
-
settlementChainId: chainId,
|
|
180
|
-
recipient,
|
|
181
|
-
amount: amount.toString(),
|
|
182
|
-
ephemeralWalletAddress: recipient,
|
|
183
|
-
chainTokenConfigs,
|
|
184
|
-
payerAddress: payer ?? null,
|
|
185
|
-
metadata,
|
|
186
|
-
feeToken: feeTokenAddress
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
138
|
async buildAndEnhancePaymentRequest(payload) {
|
|
190
139
|
const actionNames = extractActionNamesMap(payload.completionInstructions, payload.instructions);
|
|
191
140
|
return addActionNamesToInstructions((await this.apiClient.payments.buildPaymentRequest(payload)).data, actionNames);
|
|
@@ -206,74 +155,71 @@ var PaymentRequestsClient = class {
|
|
|
206
155
|
}));
|
|
207
156
|
return new Map(addresses);
|
|
208
157
|
}
|
|
209
|
-
async getDetails(request) {
|
|
210
|
-
return this.apiClient.payments.getPaymentRequestDetails(request);
|
|
211
|
-
}
|
|
212
|
-
async listOutgoingPaymentRequests(request) {
|
|
213
|
-
return this.apiClient.payments.getOutgoingPaymentsList(request);
|
|
214
|
-
}
|
|
215
|
-
async listIncomingPaymentRequests(request) {
|
|
216
|
-
return this.apiClient.payments.getIncomingPaymentsList(request);
|
|
217
|
-
}
|
|
218
|
-
async list(request) {
|
|
219
|
-
return this.apiClient.payments.getPaymentRequests(request);
|
|
220
|
-
}
|
|
221
158
|
};
|
|
222
159
|
|
|
223
160
|
//#endregion
|
|
224
|
-
//#region
|
|
225
|
-
function
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
231
|
-
}, _typeof(o);
|
|
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);
|
|
232
167
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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;
|
|
245
182
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
+
});
|
|
252
197
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
+
};
|
|
263
221
|
}
|
|
264
222
|
|
|
265
223
|
//#endregion
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
constructor(apiClient, account, context) {
|
|
269
|
-
this.apiClient = apiClient;
|
|
270
|
-
this.account = account;
|
|
271
|
-
this.context = context;
|
|
272
|
-
_defineProperty(this, "paymentRequests", void 0);
|
|
273
|
-
this.paymentRequests = new PaymentRequestsClient(apiClient, account, context);
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
//#endregion
|
|
278
|
-
export { AuthClient as a, ConfigClient as i, PaymentRequestsClient as n, ActivityClient as o, DelegationClient as r, OrchestrationClient as t };
|
|
279
|
-
//# sourceMappingURL=clients-DnPvBXkX.mjs.map
|
|
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,Y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AmB;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,qBAAoB,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"}
|
package/dist/config/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../abi-
|
|
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-
|
|
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
3
|
export { Environment, Environment as EnvironmentType, SIWE_CHAIN_ID, SIWE_VERSION, createLoginSiweMessage, env, getApiUrl, getTurnkeyApiUrl, isEnvironment };
|
package/dist/config/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../abi-
|
|
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-
|
|
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
3
|
export { Environment, Environment as EnvironmentType, SIWE_CHAIN_ID, SIWE_VERSION, createLoginSiweMessage, env, getApiUrl, getTurnkeyApiUrl, isEnvironment };
|
package/dist/context/index.d.cts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import
|
|
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";
|
|
2
5
|
export { OtimClientContext, OtimReactClientContext, OtimServerClientContext, assertRequiresAuth, assertServerContext, isServerContext };
|
package/dist/context/index.d.mts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import
|
|
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";
|
|
2
5
|
export { OtimClientContext, OtimReactClientContext, OtimServerClientContext, assertRequiresAuth, assertServerContext, isServerContext };
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { n as Signature, r as ExactPartial } from "./misc-CX4pLJaA.mjs";
|
|
1
|
+
import { t as Authorization } from "./authorization-6anhDdQX.cjs";
|
|
3
2
|
import { EIP2098Signature, VRS } from "@otim/utils/schemas";
|
|
4
3
|
|
|
5
|
-
//#region ../../node_modules/.pnpm/viem@2.39.3_bufferutil@4.0.9_typescript@5.9.3_utf-8-validate@5.0.10_zod@4.1.12/node_modules/viem/_types/types/authorization.d.ts
|
|
6
|
-
type Authorization<uint32 = number, signed extends boolean = false> = {
|
|
7
|
-
/** Address of the contract to delegate to. */
|
|
8
|
-
address: Address$1;
|
|
9
|
-
/** Chain ID. */
|
|
10
|
-
chainId: uint32;
|
|
11
|
-
/** Nonce of the EOA to delegate to. */
|
|
12
|
-
nonce: uint32;
|
|
13
|
-
} & (signed extends true ? Signature<uint32> : ExactPartial<Signature<uint32>>);
|
|
14
|
-
//#endregion
|
|
15
4
|
//#region src/utils/rlp.d.ts
|
|
16
5
|
declare const normalizeYParityValue: (value: number | bigint | string | undefined | null) => 0 | 1;
|
|
17
6
|
declare function createRlpEncodedAuthorization(authorization: Authorization): `0x${string}`;
|
|
@@ -22,4 +11,4 @@ declare const createEIP2098Signature: (vrs: VRS) => EIP2098Signature;
|
|
|
22
11
|
declare const parseSignatureToVRS: (signature: string) => VRS;
|
|
23
12
|
//#endregion
|
|
24
13
|
export { normalizeYParityValue as i, parseSignatureToVRS as n, createRlpEncodedAuthorization as r, createEIP2098Signature as t };
|
|
25
|
-
//# sourceMappingURL=index-
|
|
14
|
+
//# sourceMappingURL=index-BQMXYh9N.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|