@coin-voyage/shared 2.3.4 → 2.3.5-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,9 @@ import { type PayOrder, PayOrderMode } from "../types";
2
2
  import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, OrderStatusSocket, PaymentDetails, PaymentDetailsParams, PayOrderParams, PayOrderQuoteParams, RouteQuote, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, SwapQuoteResponse, UpdateWebhookRequest, WebhookResponse } from "../types/api";
3
3
  import { type APIEnvironment } from "./config";
4
4
  import { type APIResponse } from "./fetcher";
5
+ type Opts = {
6
+ headers?: Record<string, string>;
7
+ };
5
8
  export declare class ApiClient {
6
9
  private readonly apiKey;
7
10
  private readonly environment;
@@ -33,6 +36,7 @@ export declare class ApiClient {
33
36
  * Creates a PayOrder of type `DEPOSIT` with the provided parameters.
34
37
  *
35
38
  * @param {PayOrderParams} params - Parameters required to create a deposit PayOrder.
39
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
36
40
  * @returns {Promise<APIResponse<PayOrder>>} - The PayOrder object wrapped in an API response if the request is successful.
37
41
  *
38
42
  * @example
@@ -49,7 +53,7 @@ export declare class ApiClient {
49
53
  * console.log('Deposit PayOrder created:', data);
50
54
  * }
51
55
  */
52
- createDepositPayOrder(params: PayOrderParams): Promise<APIResponse<PayOrder>>;
56
+ createDepositPayOrder(params: PayOrderParams, opts?: Opts): Promise<APIResponse<PayOrder>>;
53
57
  /**
54
58
  * Creates a `SALE` PayOrder.
55
59
  *
@@ -59,6 +63,7 @@ export declare class ApiClient {
59
63
  *
60
64
  * @param {SalePayOrderParams} params - Params required to create a sale PayOrder.
61
65
  * @param {string} apiSecret - API secret used to generate the authorization signature.
66
+ * @param {Opts} [opts] - Optional parameters for the request.
62
67
  * @returns {Promise<APIResponse<PayOrder>>} - A PayOrder object wrapped in an API response if the request was successful.
63
68
  *
64
69
  * @example
@@ -89,7 +94,7 @@ export declare class ApiClient {
89
94
  * console.log('Sale PayOrder created:', response.data);
90
95
  * }
91
96
  */
92
- createSalePayOrder(params: PayOrderParams, apiSecret: string): Promise<APIResponse<PayOrder>>;
97
+ createSalePayOrder(params: PayOrderParams, apiSecret: string, opts?: Opts): Promise<APIResponse<PayOrder>>;
93
98
  /**
94
99
  * Creates a `REFUND` PayOrder.
95
100
  *
@@ -100,6 +105,7 @@ export declare class ApiClient {
100
105
  * @param {string} payOrderId - The unique identifier of the PayOrder to be refunded.
101
106
  * @param {PayOrderParams} params - Params required to create a refund PayOrder.
102
107
  * @param {string} apiSecret - API secret used to generate the authorization signature.
108
+ * @param {Opts} [opts] - Optional parameters for the request.
103
109
  * @returns {Promise<APIResponse<PayOrder>>} - A PayOrder object wrapped in an API response if the request was successful.
104
110
  *
105
111
  * @example
@@ -130,8 +136,8 @@ export declare class ApiClient {
130
136
  * console.log('Refund PayOrder created:', response.data);
131
137
  * }
132
138
  */
133
- createRefundPayOrder(payOrderId: string, params: PayOrderParams, apiSecret: string): Promise<APIResponse<PayOrder>>;
134
- createPayOrder(params: PayOrderParams, mode: PayOrderMode, signature?: string): Promise<APIResponse<PayOrder>>;
139
+ createRefundPayOrder(payOrderId: string, params: PayOrderParams, apiSecret: string, opts?: Opts): Promise<APIResponse<PayOrder>>;
140
+ createPayOrder(params: PayOrderParams, mode: PayOrderMode, signature?: string, opts?: Opts): Promise<APIResponse<PayOrder>>;
135
141
  /**
136
142
  * Generates a PayOrder Quote.
137
143
  *
@@ -140,6 +146,7 @@ export declare class ApiClient {
140
146
  *
141
147
  * @param {string} orderId - The unique identifier of the PayOrder for which the quote is requested.
142
148
  * @param {PayOrderQuoteParams} quoteParams - Contains `wallet_address`, `chain_type`, `chain_id`.
149
+ * @param {Opts} [opts] - Optional parameters for the request.
143
150
  * @returns {Promise<APIResponse<RouteQuote[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
144
151
  *
145
152
  * @example
@@ -155,7 +162,7 @@ export declare class ApiClient {
155
162
  * console.log('Available tokens:', response.data);
156
163
  * }
157
164
  */
158
- payOrderQuote(orderId: string, quoteParams: PayOrderQuoteParams): Promise<APIResponse<RouteQuote[]>>;
165
+ payOrderQuote(orderId: string, quoteParams: PayOrderQuoteParams, opts?: Opts): Promise<APIResponse<RouteQuote[]>>;
159
166
  /**
160
167
  * Retrieves payment details for a specific PayOrder.
161
168
  *
@@ -171,6 +178,7 @@ export declare class ApiClient {
171
178
  * @param {CurrencyBase} [params.source_currency] - (Optional) The source currency information.
172
179
  * @param {string} params.quote_id - (Optional) The quote ID for the PayOrder.
173
180
  * @param {string} params.refund_address - The address where funds will be refunded in case of a failed transaction.
181
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
174
182
  *
175
183
  * @returns {Promise<APIResponse<PaymentDetails>>} - The payment details object wrapped in an API response if the request is successful.
176
184
  *
@@ -185,93 +193,76 @@ export declare class ApiClient {
185
193
  * console.log('Payment details:', response.data);
186
194
  * }
187
195
  */
188
- payOrderPaymentDetails(params: PaymentDetailsParams): Promise<APIResponse<PaymentDetails>>;
189
- /**
190
- * Generates an authorization signature for API requests using HMAC-SHA256.
191
- *
192
- * ⚠️ **Warning:** This function should only be run on the server.
193
- * It uses the API secret, which must remain confidential. Running this
194
- * code in a client-side environment risks exposing sensitive information
195
- * to end users or malicious actors.
196
- *
197
- * This function creates a signed authorization string using HMAC-SHA256.
198
- * The signature is computed over: method + path + timestamp, using the secret as the HMAC key.
199
- *
200
- * @param {string} apiSecret - The API secret used as the HMAC key.
201
- * @param {string} method - The HTTP method (e.g., "POST", "GET").
202
- * @param {string} path - The request path (e.g., "/pay-orders").
203
- * @returns {string} - A formatted authorization string in the format:
204
- * `APIKey=<apiKey>,signature=<signature>,timestamp=<timestamp>`.
205
- *
206
- * @example
207
- * const apiSecret = 'yourApiSecret';
208
- * const authSignature = apiClient.generateAuthorizationSignature(apiSecret, 'POST', '/pay-orders');
209
- * console.log(authSignature);
210
- * // Example output:
211
- * // APIKey=yourApiKey,signature=a1b2c3d4...,timestamp=1737106896
212
- */
213
- generateAuthorizationSignature(apiSecret: string, method: string, path: string): string;
196
+ payOrderPaymentDetails(params: PaymentDetailsParams, opts?: Opts): Promise<APIResponse<PaymentDetails>>;
214
197
  /**
215
198
  * Retrieves the claimable fee balances for the authenticated organization.
216
199
  *
217
200
  * @param {string} apiSecret - API secret used to generate the authorization signature.
201
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
218
202
  * @returns {Promise<APIResponse<GetFeeBalancesResponse>>} - Fee balances wrapped in an API response.
219
203
  */
220
- getFeeBalances(apiSecret: string): Promise<APIResponse<GetFeeBalancesResponse>>;
204
+ getFeeBalances(apiSecret: string, opts?: Opts): Promise<APIResponse<GetFeeBalancesResponse>>;
221
205
  /**
222
206
  * Claims accrued fees for the authenticated organization.
223
207
  *
224
208
  * @param {ClaimFeesRequest} params - Parameters for claiming fees.
225
209
  * @param {string} apiSecret - API secret used to generate the authorization signature.
210
+ * @param {Opts} [opts] - Options for the request, such as additional headers.
226
211
  * @returns {Promise<APIResponse<ClaimFeesResponse>>} - Claim result wrapped in an API response.
227
212
  */
228
- claimFees(params: ClaimFeesRequest, apiSecret: string): Promise<APIResponse<ClaimFeesResponse>>;
213
+ claimFees(params: ClaimFeesRequest, apiSecret: string, opts?: Opts): Promise<APIResponse<ClaimFeesResponse>>;
229
214
  /**
230
215
  * Retrieves all webhooks for the authenticated organization.
231
216
  *
232
217
  * @param {string} apiSecret - API secret used to generate the authorization signature.
218
+ * @param {Opts} [opts] - Options for the request, such as additional headers.
233
219
  * @returns {Promise<APIResponse<WebhookResponse[]>>} - List of webhooks wrapped in an API response.
234
220
  */
235
- listWebhooks(apiSecret: string): Promise<APIResponse<WebhookResponse[]>>;
221
+ listWebhooks(apiSecret: string, opts?: Opts): Promise<APIResponse<WebhookResponse[]>>;
236
222
  /**
237
223
  * Creates a new webhook for the authenticated organization.
238
224
  *
239
225
  * @param {CreateWebhookRequest} params - Parameters for creating the webhook.
240
226
  * @param {string} apiSecret - API secret used to generate the authorization signature.
227
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
241
228
  * @returns {Promise<APIResponse<WebhookResponse>>} - Created webhook wrapped in an API response.
242
229
  */
243
- createWebhook(params: CreateWebhookRequest, apiSecret: string): Promise<APIResponse<WebhookResponse>>;
230
+ createWebhook(params: CreateWebhookRequest, apiSecret: string, opts?: Opts): Promise<APIResponse<WebhookResponse>>;
244
231
  /**
245
232
  * Updates an existing webhook for the authenticated organization.
246
233
  *
247
234
  * @param {string} webhookId - The unique identifier of the webhook to update.
248
235
  * @param {UpdateWebhookRequest} params - Parameters for updating the webhook.
249
236
  * @param {string} apiSecret - API secret used to generate the authorization signature.
237
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
250
238
  * @returns {Promise<APIResponse<WebhookResponse>>} - Updated webhook wrapped in an API response.
251
239
  */
252
- updateWebhook(webhookId: string, params: UpdateWebhookRequest, apiSecret: string): Promise<APIResponse<WebhookResponse>>;
240
+ updateWebhook(webhookId: string, params: UpdateWebhookRequest, apiSecret: string, opts?: Opts): Promise<APIResponse<WebhookResponse>>;
253
241
  /**
254
242
  * Deletes an existing webhook for the authenticated organization.
255
243
  *
256
244
  * @param {string} webhookId - The unique identifier of the webhook to delete.
257
245
  * @param {string} apiSecret - API secret used to generate the authorization signature.
246
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
258
247
  * @returns {Promise<APIResponse<void>>} - Empty response on success.
259
248
  */
260
- deleteWebhook(webhookId: string, apiSecret: string): Promise<APIResponse<void>>;
249
+ deleteWebhook(webhookId: string, apiSecret: string, opts?: Opts): Promise<APIResponse<void>>;
261
250
  /**
262
251
  * Gets a quote for swapping between two currencies.
263
252
  *
264
253
  * @param {SwapQuoteRequest} params - Parameters for the swap quote.
254
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
265
255
  * @returns {Promise<APIResponse<SwapQuoteResponse>>} - Swap quote wrapped in an API response.
266
256
  */
267
- swapQuote(params: SwapQuoteRequest): Promise<APIResponse<SwapQuoteResponse>>;
257
+ swapQuote(params: SwapQuoteRequest, opts?: Opts): Promise<APIResponse<SwapQuoteResponse>>;
268
258
  /**
269
259
  * Gets transaction data for executing a swap.
270
260
  *
271
261
  * @param {SwapDataRequest} params - Parameters for the swap data.
262
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
272
263
  * @returns {Promise<APIResponse<SwapDataResponse>>} - Swap data wrapped in an API response.
273
264
  */
274
- swapData(params: SwapDataRequest): Promise<APIResponse<SwapDataResponse>>;
265
+ swapData(params: SwapDataRequest, opts?: Opts): Promise<APIResponse<SwapDataResponse>>;
275
266
  /**
276
267
  * Opens a WebSocket connection to receive real-time order status events.
277
268
  *
@@ -287,4 +278,30 @@ export declare class ApiClient {
287
278
  * @returns {OrderStatusSocket} - Handle for subscribing, receiving messages, and closing the connection.
288
279
  */
289
280
  subscribeOrderStatus(): OrderStatusSocket;
281
+ /**
282
+ * Generates an authorization signature for API requests using HMAC-SHA256.
283
+ *
284
+ * ⚠️ **Warning:** This function should only be run on the server.
285
+ * It uses the API secret, which must remain confidential. Running this
286
+ * code in a client-side environment risks exposing sensitive information
287
+ * to end users or malicious actors.
288
+ *
289
+ * This function creates a signed authorization string using HMAC-SHA256.
290
+ * The signature is computed over: method + path + timestamp, using the secret as the HMAC key.
291
+ *
292
+ * @param {string} apiSecret - The API secret used as the HMAC key.
293
+ * @param {string} method - The HTTP method (e.g., "POST", "GET").
294
+ * @param {string} path - The request path (e.g., "/pay-orders").
295
+ * @returns {string} - A formatted authorization string in the format:
296
+ * `APIKey=<apiKey>,signature=<signature>,timestamp=<timestamp>`.
297
+ *
298
+ * @example
299
+ * const apiSecret = 'yourApiSecret';
300
+ * const authSignature = apiClient.generateAuthorizationSignature(apiSecret, 'POST', '/pay-orders');
301
+ * console.log(authSignature);
302
+ * // Example output:
303
+ * // APIKey=yourApiKey,signature=a1b2c3d4...,timestamp=1737106896
304
+ */
305
+ generateAuthorizationSignature(apiSecret: string, method: string, path: string): string;
290
306
  }
307
+ export {};
@@ -46,6 +46,7 @@ export class ApiClient {
46
46
  * Creates a PayOrder of type `DEPOSIT` with the provided parameters.
47
47
  *
48
48
  * @param {PayOrderParams} params - Parameters required to create a deposit PayOrder.
49
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
49
50
  * @returns {Promise<APIResponse<PayOrder>>} - The PayOrder object wrapped in an API response if the request is successful.
50
51
  *
51
52
  * @example
@@ -62,9 +63,9 @@ export class ApiClient {
62
63
  * console.log('Deposit PayOrder created:', data);
63
64
  * }
64
65
  */
65
- async createDepositPayOrder(params) {
66
+ async createDepositPayOrder(params, opts) {
66
67
  try {
67
- return this.createPayOrder(params, PayOrderMode.DEPOSIT);
68
+ return this.createPayOrder(params, PayOrderMode.DEPOSIT, undefined, opts);
68
69
  }
69
70
  catch (error) {
70
71
  return {
@@ -86,6 +87,7 @@ export class ApiClient {
86
87
  *
87
88
  * @param {SalePayOrderParams} params - Params required to create a sale PayOrder.
88
89
  * @param {string} apiSecret - API secret used to generate the authorization signature.
90
+ * @param {Opts} [opts] - Optional parameters for the request.
89
91
  * @returns {Promise<APIResponse<PayOrder>>} - A PayOrder object wrapped in an API response if the request was successful.
90
92
  *
91
93
  * @example
@@ -116,10 +118,10 @@ export class ApiClient {
116
118
  * console.log('Sale PayOrder created:', response.data);
117
119
  * }
118
120
  */
119
- async createSalePayOrder(params, apiSecret) {
121
+ async createSalePayOrder(params, apiSecret, opts) {
120
122
  try {
121
123
  const signature = this.generateAuthorizationSignature(apiSecret, "POST", "/pay-orders");
122
- return this.createPayOrder(params, PayOrderMode.SALE, signature);
124
+ return this.createPayOrder(params, PayOrderMode.SALE, signature, opts);
123
125
  }
124
126
  catch (error) {
125
127
  return {
@@ -142,6 +144,7 @@ export class ApiClient {
142
144
  * @param {string} payOrderId - The unique identifier of the PayOrder to be refunded.
143
145
  * @param {PayOrderParams} params - Params required to create a refund PayOrder.
144
146
  * @param {string} apiSecret - API secret used to generate the authorization signature.
147
+ * @param {Opts} [opts] - Optional parameters for the request.
145
148
  * @returns {Promise<APIResponse<PayOrder>>} - A PayOrder object wrapped in an API response if the request was successful.
146
149
  *
147
150
  * @example
@@ -172,7 +175,7 @@ export class ApiClient {
172
175
  * console.log('Refund PayOrder created:', response.data);
173
176
  * }
174
177
  */
175
- async createRefundPayOrder(payOrderId, params, apiSecret) {
178
+ async createRefundPayOrder(payOrderId, params, apiSecret, opts) {
176
179
  try {
177
180
  const result = zPayOrder.safeParse(params);
178
181
  if (!result.success) {
@@ -191,7 +194,7 @@ export class ApiClient {
191
194
  options: {
192
195
  method: "POST",
193
196
  body: JSON.stringify({ ...params }),
194
- headers: { Authorization: signature },
197
+ headers: { Authorization: signature, ...opts?.headers },
195
198
  },
196
199
  });
197
200
  }
@@ -206,7 +209,7 @@ export class ApiClient {
206
209
  };
207
210
  }
208
211
  }
209
- async createPayOrder(params, mode, signature) {
212
+ async createPayOrder(params, mode, signature, opts) {
210
213
  const result = zPayOrder.safeParse(params);
211
214
  if (!result.success) {
212
215
  throw new Error(result.error.issues.map((e) => e.message).join(", "));
@@ -225,7 +228,7 @@ export class ApiClient {
225
228
  options: {
226
229
  method: "POST",
227
230
  body: JSON.stringify({ mode, ...params }),
228
- headers: signature ? { Authorization: signature } : {},
231
+ headers: { ...(signature ? { Authorization: signature } : {}), ...opts?.headers },
229
232
  },
230
233
  });
231
234
  }
@@ -237,6 +240,7 @@ export class ApiClient {
237
240
  *
238
241
  * @param {string} orderId - The unique identifier of the PayOrder for which the quote is requested.
239
242
  * @param {PayOrderQuoteParams} quoteParams - Contains `wallet_address`, `chain_type`, `chain_id`.
243
+ * @param {Opts} [opts] - Optional parameters for the request.
240
244
  * @returns {Promise<APIResponse<RouteQuote[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
241
245
  *
242
246
  * @example
@@ -252,12 +256,13 @@ export class ApiClient {
252
256
  * console.log('Available tokens:', response.data);
253
257
  * }
254
258
  */
255
- async payOrderQuote(orderId, quoteParams) {
259
+ async payOrderQuote(orderId, quoteParams, opts) {
256
260
  return this.request({
257
261
  path: `/pay-orders/${orderId}/quote`,
258
262
  options: {
259
263
  method: "POST",
260
264
  body: JSON.stringify(quoteParams),
265
+ headers: opts?.headers,
261
266
  },
262
267
  });
263
268
  }
@@ -276,6 +281,7 @@ export class ApiClient {
276
281
  * @param {CurrencyBase} [params.source_currency] - (Optional) The source currency information.
277
282
  * @param {string} params.quote_id - (Optional) The quote ID for the PayOrder.
278
283
  * @param {string} params.refund_address - The address where funds will be refunded in case of a failed transaction.
284
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
279
285
  *
280
286
  * @returns {Promise<APIResponse<PaymentDetails>>} - The payment details object wrapped in an API response if the request is successful.
281
287
  *
@@ -290,47 +296,17 @@ export class ApiClient {
290
296
  * console.log('Payment details:', response.data);
291
297
  * }
292
298
  */
293
- async payOrderPaymentDetails(params) {
299
+ async payOrderPaymentDetails(params, opts) {
294
300
  const { payorder_id, ...rest } = params;
295
301
  return this.request({
296
302
  path: `/pay-orders/${payorder_id}/payment-details`,
297
303
  options: {
298
304
  method: "POST",
299
305
  body: JSON.stringify({ ...rest }),
306
+ headers: opts?.headers,
300
307
  },
301
308
  });
302
309
  }
303
- /**
304
- * Generates an authorization signature for API requests using HMAC-SHA256.
305
- *
306
- * ⚠️ **Warning:** This function should only be run on the server.
307
- * It uses the API secret, which must remain confidential. Running this
308
- * code in a client-side environment risks exposing sensitive information
309
- * to end users or malicious actors.
310
- *
311
- * This function creates a signed authorization string using HMAC-SHA256.
312
- * The signature is computed over: method + path + timestamp, using the secret as the HMAC key.
313
- *
314
- * @param {string} apiSecret - The API secret used as the HMAC key.
315
- * @param {string} method - The HTTP method (e.g., "POST", "GET").
316
- * @param {string} path - The request path (e.g., "/pay-orders").
317
- * @returns {string} - A formatted authorization string in the format:
318
- * `APIKey=<apiKey>,signature=<signature>,timestamp=<timestamp>`.
319
- *
320
- * @example
321
- * const apiSecret = 'yourApiSecret';
322
- * const authSignature = apiClient.generateAuthorizationSignature(apiSecret, 'POST', '/pay-orders');
323
- * console.log(authSignature);
324
- * // Example output:
325
- * // APIKey=yourApiKey,signature=a1b2c3d4...,timestamp=1737106896
326
- */
327
- generateAuthorizationSignature(apiSecret, method, path) {
328
- const timestamp = now();
329
- // Create HMAC-SHA256 signature over: method + path + timestamp
330
- const data = `${method}${path}${timestamp}`;
331
- const signature = createHmac("sha256", apiSecret).update(data).digest("hex");
332
- return `APIKey=${this.apiKey},signature=${signature},timestamp=${timestamp}`;
333
- }
334
310
  // ===================
335
311
  // Fee endpoints
336
312
  // ===================
@@ -338,15 +314,16 @@ export class ApiClient {
338
314
  * Retrieves the claimable fee balances for the authenticated organization.
339
315
  *
340
316
  * @param {string} apiSecret - API secret used to generate the authorization signature.
317
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
341
318
  * @returns {Promise<APIResponse<GetFeeBalancesResponse>>} - Fee balances wrapped in an API response.
342
319
  */
343
- async getFeeBalances(apiSecret) {
320
+ async getFeeBalances(apiSecret, opts) {
344
321
  const signature = this.generateAuthorizationSignature(apiSecret, "GET", "/fees/balance");
345
322
  return this.request({
346
323
  path: "/fees/balance",
347
324
  options: {
348
325
  method: "GET",
349
- headers: { Authorization: signature },
326
+ headers: { Authorization: signature, ...opts?.headers },
350
327
  },
351
328
  });
352
329
  }
@@ -355,16 +332,17 @@ export class ApiClient {
355
332
  *
356
333
  * @param {ClaimFeesRequest} params - Parameters for claiming fees.
357
334
  * @param {string} apiSecret - API secret used to generate the authorization signature.
335
+ * @param {Opts} [opts] - Options for the request, such as additional headers.
358
336
  * @returns {Promise<APIResponse<ClaimFeesResponse>>} - Claim result wrapped in an API response.
359
337
  */
360
- async claimFees(params, apiSecret) {
338
+ async claimFees(params, apiSecret, opts) {
361
339
  const signature = this.generateAuthorizationSignature(apiSecret, "POST", "/fees/claim");
362
340
  return this.request({
363
341
  path: "/fees/claim",
364
342
  options: {
365
343
  method: "POST",
366
344
  body: JSON.stringify(params),
367
- headers: { Authorization: signature },
345
+ headers: { Authorization: signature, ...opts?.headers },
368
346
  },
369
347
  });
370
348
  }
@@ -375,15 +353,16 @@ export class ApiClient {
375
353
  * Retrieves all webhooks for the authenticated organization.
376
354
  *
377
355
  * @param {string} apiSecret - API secret used to generate the authorization signature.
356
+ * @param {Opts} [opts] - Options for the request, such as additional headers.
378
357
  * @returns {Promise<APIResponse<WebhookResponse[]>>} - List of webhooks wrapped in an API response.
379
358
  */
380
- async listWebhooks(apiSecret) {
359
+ async listWebhooks(apiSecret, opts) {
381
360
  const signature = this.generateAuthorizationSignature(apiSecret, "GET", "/organizations/webhooks");
382
361
  return this.request({
383
362
  path: "/webhooks",
384
363
  options: {
385
364
  method: "GET",
386
- headers: { Authorization: signature },
365
+ headers: { Authorization: signature, ...opts?.headers },
387
366
  },
388
367
  });
389
368
  }
@@ -392,16 +371,17 @@ export class ApiClient {
392
371
  *
393
372
  * @param {CreateWebhookRequest} params - Parameters for creating the webhook.
394
373
  * @param {string} apiSecret - API secret used to generate the authorization signature.
374
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
395
375
  * @returns {Promise<APIResponse<WebhookResponse>>} - Created webhook wrapped in an API response.
396
376
  */
397
- async createWebhook(params, apiSecret) {
377
+ async createWebhook(params, apiSecret, opts) {
398
378
  const signature = this.generateAuthorizationSignature(apiSecret, "POST", "/webhooks");
399
379
  return this.request({
400
380
  path: "/webhooks",
401
381
  options: {
402
382
  method: "POST",
403
383
  body: JSON.stringify(params),
404
- headers: { Authorization: signature },
384
+ headers: { Authorization: signature, ...opts?.headers },
405
385
  },
406
386
  });
407
387
  }
@@ -411,16 +391,17 @@ export class ApiClient {
411
391
  * @param {string} webhookId - The unique identifier of the webhook to update.
412
392
  * @param {UpdateWebhookRequest} params - Parameters for updating the webhook.
413
393
  * @param {string} apiSecret - API secret used to generate the authorization signature.
394
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
414
395
  * @returns {Promise<APIResponse<WebhookResponse>>} - Updated webhook wrapped in an API response.
415
396
  */
416
- async updateWebhook(webhookId, params, apiSecret) {
397
+ async updateWebhook(webhookId, params, apiSecret, opts) {
417
398
  const signature = this.generateAuthorizationSignature(apiSecret, "PUT", `/webhooks/${webhookId}`);
418
399
  return this.request({
419
400
  path: `/webhooks/${webhookId}`,
420
401
  options: {
421
402
  method: "PUT",
422
403
  body: JSON.stringify(params),
423
- headers: { Authorization: signature },
404
+ headers: { Authorization: signature, ...opts?.headers },
424
405
  },
425
406
  });
426
407
  }
@@ -429,15 +410,16 @@ export class ApiClient {
429
410
  *
430
411
  * @param {string} webhookId - The unique identifier of the webhook to delete.
431
412
  * @param {string} apiSecret - API secret used to generate the authorization signature.
413
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
432
414
  * @returns {Promise<APIResponse<void>>} - Empty response on success.
433
415
  */
434
- async deleteWebhook(webhookId, apiSecret) {
416
+ async deleteWebhook(webhookId, apiSecret, opts) {
435
417
  const signature = this.generateAuthorizationSignature(apiSecret, "DELETE", `/webhooks/${webhookId}`);
436
418
  return this.request({
437
419
  path: `/webhooks/${webhookId}`,
438
420
  options: {
439
421
  method: "DELETE",
440
- headers: { Authorization: signature },
422
+ headers: { Authorization: signature, ...opts?.headers },
441
423
  },
442
424
  });
443
425
  }
@@ -448,14 +430,16 @@ export class ApiClient {
448
430
  * Gets a quote for swapping between two currencies.
449
431
  *
450
432
  * @param {SwapQuoteRequest} params - Parameters for the swap quote.
433
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
451
434
  * @returns {Promise<APIResponse<SwapQuoteResponse>>} - Swap quote wrapped in an API response.
452
435
  */
453
- async swapQuote(params) {
436
+ async swapQuote(params, opts) {
454
437
  return this.request({
455
438
  path: "/swap/quote",
456
439
  options: {
457
440
  method: "POST",
458
441
  body: JSON.stringify(params),
442
+ headers: opts?.headers,
459
443
  },
460
444
  });
461
445
  }
@@ -463,14 +447,16 @@ export class ApiClient {
463
447
  * Gets transaction data for executing a swap.
464
448
  *
465
449
  * @param {SwapDataRequest} params - Parameters for the swap data.
450
+ * @param {Opts} [opts] - Optional parameters for the request, such as additional headers.
466
451
  * @returns {Promise<APIResponse<SwapDataResponse>>} - Swap data wrapped in an API response.
467
452
  */
468
- async swapData(params) {
453
+ async swapData(params, opts) {
469
454
  return this.request({
470
455
  path: "/swap/data",
471
456
  options: {
472
457
  method: "POST",
473
458
  body: JSON.stringify(params),
459
+ headers: opts?.headers,
474
460
  },
475
461
  });
476
462
  }
@@ -552,4 +538,38 @@ export class ApiClient {
552
538
  },
553
539
  };
554
540
  }
541
+ // ===================
542
+ // Authentication
543
+ // ===================
544
+ /**
545
+ * Generates an authorization signature for API requests using HMAC-SHA256.
546
+ *
547
+ * ⚠️ **Warning:** This function should only be run on the server.
548
+ * It uses the API secret, which must remain confidential. Running this
549
+ * code in a client-side environment risks exposing sensitive information
550
+ * to end users or malicious actors.
551
+ *
552
+ * This function creates a signed authorization string using HMAC-SHA256.
553
+ * The signature is computed over: method + path + timestamp, using the secret as the HMAC key.
554
+ *
555
+ * @param {string} apiSecret - The API secret used as the HMAC key.
556
+ * @param {string} method - The HTTP method (e.g., "POST", "GET").
557
+ * @param {string} path - The request path (e.g., "/pay-orders").
558
+ * @returns {string} - A formatted authorization string in the format:
559
+ * `APIKey=<apiKey>,signature=<signature>,timestamp=<timestamp>`.
560
+ *
561
+ * @example
562
+ * const apiSecret = 'yourApiSecret';
563
+ * const authSignature = apiClient.generateAuthorizationSignature(apiSecret, 'POST', '/pay-orders');
564
+ * console.log(authSignature);
565
+ * // Example output:
566
+ * // APIKey=yourApiKey,signature=a1b2c3d4...,timestamp=1737106896
567
+ */
568
+ generateAuthorizationSignature(apiSecret, method, path) {
569
+ const timestamp = now();
570
+ // Create HMAC-SHA256 signature over: method + path + timestamp
571
+ const data = `${method}${path}${timestamp}`;
572
+ const signature = createHmac("sha256", apiSecret).update(data).digest("hex");
573
+ return `APIKey=${this.apiKey},signature=${signature},timestamp=${timestamp}`;
574
+ }
555
575
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coin-voyage/shared",
3
3
  "description": "Shared utilities for Coin Voyage",
4
- "version": "2.3.4",
4
+ "version": "2.3.5-beta.1",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {