@diviswap/sdk 1.8.0 → 1.9.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/index.mjs CHANGED
@@ -52,7 +52,7 @@ var AuthModule = class {
52
52
  }
53
53
  /**
54
54
  * Register a new user
55
- *
55
+ *
56
56
  * @example
57
57
  * ```typescript
58
58
  * const { user, accessToken } = await diviswap.auth.register({
@@ -99,16 +99,22 @@ var AuthModule = class {
99
99
  const authResponse = {
100
100
  accessToken: response.access_token || response.accessToken,
101
101
  refreshToken: response.refresh_token || response.refreshToken,
102
- user: response.user || { id: response.user_id || response.id, email: data.email }
102
+ user: response.user || {
103
+ id: response.user_id || response.id,
104
+ email: data.email
105
+ }
103
106
  };
104
107
  if (authResponse.accessToken) {
105
- this.client.setTokens(authResponse.accessToken, authResponse.refreshToken);
108
+ this.client.setTokens(
109
+ authResponse.accessToken,
110
+ authResponse.refreshToken
111
+ );
106
112
  }
107
113
  return authResponse;
108
114
  }
109
115
  /**
110
116
  * Login an existing user
111
- *
117
+ *
112
118
  * @example
113
119
  * ```typescript
114
120
  * const { user, accessToken } = await diviswap.auth.login({
@@ -127,22 +133,28 @@ var AuthModule = class {
127
133
  const authResponse = {
128
134
  accessToken: response.access_token || response.accessToken,
129
135
  refreshToken: response.refresh_token || response.refreshToken,
130
- user: response.user || { id: response.user_id || response.id, email: credentials.email }
136
+ user: response.user || {
137
+ id: response.user_id || response.id,
138
+ email: credentials.email
139
+ }
131
140
  };
132
141
  if (authResponse.accessToken) {
133
- this.client.setTokens(authResponse.accessToken, authResponse.refreshToken);
142
+ this.client.setTokens(
143
+ authResponse.accessToken,
144
+ authResponse.refreshToken
145
+ );
134
146
  }
135
147
  return authResponse;
136
148
  }
137
149
  /**
138
150
  * Get current user profile
139
- *
151
+ *
140
152
  * @example
141
153
  * ```typescript
142
154
  * const user = await diviswap.auth.getProfile();
143
155
  * console.log(user.email, user.kycStatus);
144
156
  * ```
145
- *
157
+ *
146
158
  * Note: This endpoint is not yet available in the v1 API
147
159
  */
148
160
  async getProfile() {
@@ -150,7 +162,7 @@ var AuthModule = class {
150
162
  }
151
163
  /**
152
164
  * Update user profile
153
- *
165
+ *
154
166
  * @example
155
167
  * ```typescript
156
168
  * const updatedUser = await diviswap.auth.updateProfile({
@@ -158,7 +170,7 @@ var AuthModule = class {
158
170
  * lastName: 'Smith'
159
171
  * });
160
172
  * ```
161
- *
173
+ *
162
174
  * Note: This endpoint is not yet available in the v1 API
163
175
  */
164
176
  async updateProfile(_data) {
@@ -166,12 +178,12 @@ var AuthModule = class {
166
178
  }
167
179
  /**
168
180
  * Request password reset
169
- *
181
+ *
170
182
  * @example
171
183
  * ```typescript
172
184
  * await diviswap.auth.requestPasswordReset('user@example.com');
173
185
  * ```
174
- *
186
+ *
175
187
  * Note: This endpoint is not yet available in the v1 API
176
188
  */
177
189
  async requestPasswordReset(_email) {
@@ -179,12 +191,12 @@ var AuthModule = class {
179
191
  }
180
192
  /**
181
193
  * Set new password with reset token
182
- *
194
+ *
183
195
  * @example
184
196
  * ```typescript
185
197
  * await diviswap.auth.setPassword('reset-token', 'new-secure-password');
186
198
  * ```
187
- *
199
+ *
188
200
  * Note: This endpoint is not yet available in the v1 API
189
201
  */
190
202
  async setPassword(_token, _password) {
@@ -192,7 +204,7 @@ var AuthModule = class {
192
204
  }
193
205
  /**
194
206
  * Logout current user
195
- *
207
+ *
196
208
  * @example
197
209
  * ```typescript
198
210
  * await diviswap.auth.logout();
@@ -206,8 +218,12 @@ var AuthModule = class {
206
218
  * @deprecated Use diviswap.kyc.getComplianceStatus() instead
207
219
  */
208
220
  async getComplianceStatus() {
209
- console.warn("auth.getComplianceStatus() is deprecated. Use kyc.getComplianceStatus() instead.");
210
- throw new Error("Compliance status endpoint not available in v1 API yet");
221
+ console.warn(
222
+ "auth.getComplianceStatus() is deprecated. Use kyc.getComplianceStatus() instead."
223
+ );
224
+ throw new Error(
225
+ "Compliance status endpoint not available in v1 API yet"
226
+ );
211
227
  }
212
228
  /**
213
229
  * Check if user is authenticated
@@ -217,7 +233,7 @@ var AuthModule = class {
217
233
  }
218
234
  /**
219
235
  * Refresh access token (internal)
220
- *
236
+ *
221
237
  * Note: This endpoint is not yet available in the v1 API
222
238
  */
223
239
  async refreshToken(_refreshToken) {
@@ -230,12 +246,28 @@ var PayeesModule = class {
230
246
  constructor(client) {
231
247
  this.client = client;
232
248
  }
249
+ /**
250
+ * Validate ABA routing number checksum
251
+ */
252
+ validateRoutingNumber(routing) {
253
+ if (routing.length !== 9 || !/^\d{9}$/.test(routing)) {
254
+ return false;
255
+ }
256
+ const d = routing.split("").map(Number);
257
+ const checksum = 3 * (d[0] + d[3] + d[6]) + 7 * (d[1] + d[4] + d[7]) + 1 * (d[2] + d[5] + d[8]);
258
+ return checksum % 10 === 0;
259
+ }
260
+ /**
261
+ * Validate account number format
262
+ */
263
+ validateAccountNumber(account) {
264
+ return /^\d{4,17}$/.test(account);
265
+ }
233
266
  /**
234
267
  * Create a new payee (bank account)
235
- *
268
+ *
236
269
  * @example
237
270
  * ```typescript
238
- * // Bank account
239
271
  * const bankAccount = await diviswap.payees.create({
240
272
  * nickname: 'My Checking',
241
273
  * accountNumber: '123456789',
@@ -243,50 +275,32 @@ var PayeesModule = class {
243
275
  * accountType: 'checking',
244
276
  * setAsDefault: true
245
277
  * });
246
- *
247
- * // Debit card
248
- * const debitCard = await diviswap.payees.create({
249
- * nickname: 'My Debit Card',
250
- * accountType: 'debit_card',
251
- * debitCard: {
252
- * number: '4111111111111111',
253
- * expirationMonth: '12',
254
- * expirationYear: '2025',
255
- * cvv: '123'
256
- * },
257
- * setAsDefault: false
258
- * });
259
278
  * ```
260
279
  */
261
280
  async create(data) {
262
281
  try {
263
- let response;
264
- if (data.accountType === "debit_card") {
265
- if (!data.debitCard) {
266
- throw new Error("Debit card information is required for debit_card account type");
267
- }
268
- response = await this.client.post("/api/v1/payees", {
269
- name: data.nickname,
270
- debit_card: {
271
- number: data.debitCard.number,
272
- expiration_month: data.debitCard.expirationMonth,
273
- expiration_year: data.debitCard.expirationYear,
274
- cvv: data.debitCard.cvv
275
- },
276
- set_as_default: data.setAsDefault || false
277
- });
278
- } else {
279
- if (!data.accountNumber || !data.routingNumber) {
280
- throw new Error("Account number and routing number are required for bank accounts");
281
- }
282
- response = await this.client.post("/api/v1/payees", {
283
- name: data.nickname,
284
- account_number: data.accountNumber,
285
- routing_number: data.routingNumber,
286
- type: (data.accountType || "checking").toUpperCase(),
287
- set_as_default: data.setAsDefault || false
288
- });
282
+ if (!data.accountNumber || !data.routingNumber) {
283
+ throw new Error(
284
+ "Account number and routing number are required for bank accounts"
285
+ );
286
+ }
287
+ if (!this.validateRoutingNumber(data.routingNumber)) {
288
+ throw new Error(
289
+ "Invalid routing number. Please provide a valid 9-digit ABA routing number."
290
+ );
291
+ }
292
+ if (!this.validateAccountNumber(data.accountNumber)) {
293
+ throw new Error(
294
+ "Invalid account number. Must be 4-17 digits with no letters or special characters."
295
+ );
289
296
  }
297
+ const response = await this.client.post("/api/v1/payees", {
298
+ name: data.nickname,
299
+ account_number: data.accountNumber,
300
+ routing_number: data.routingNumber,
301
+ type: (data.accountType || "checking").toUpperCase(),
302
+ set_as_default: data.setAsDefault || false
303
+ });
290
304
  return this.transformPayee(response);
291
305
  } catch (error) {
292
306
  throw new Error(`Failed to create payee: ${error.message}`);
@@ -294,7 +308,7 @@ var PayeesModule = class {
294
308
  }
295
309
  /**
296
310
  * List all payees
297
- *
311
+ *
298
312
  * @example
299
313
  * ```typescript
300
314
  * const payees = await diviswap.payees.list();
@@ -302,7 +316,9 @@ var PayeesModule = class {
302
316
  * ```
303
317
  */
304
318
  async list() {
305
- const response = await this.client.get("/api/v1/users/payees", { useApiKey: false });
319
+ const response = await this.client.get("/api/v1/users/payees", {
320
+ useApiKey: false
321
+ });
306
322
  return this.parsePayeesResponse(response);
307
323
  }
308
324
  parsePayeesResponse(response) {
@@ -335,7 +351,7 @@ var PayeesModule = class {
335
351
  }
336
352
  /**
337
353
  * Get a specific payee
338
- *
354
+ *
339
355
  * @example
340
356
  * ```typescript
341
357
  * const payee = await diviswap.payees.get('payee-id');
@@ -351,22 +367,26 @@ var PayeesModule = class {
351
367
  }
352
368
  /**
353
369
  * Set a payee as default
354
- *
370
+ *
355
371
  * @example
356
372
  * ```typescript
357
373
  * await diviswap.payees.setDefault('payee-id');
358
374
  * ```
359
375
  */
360
376
  async setDefault(payeeId) {
361
- const response = await this.client.put("/api/v1/users/payees", {
362
- payeeId,
363
- setAsDefault: true
364
- }, { useApiKey: false });
377
+ const response = await this.client.put(
378
+ "/api/v1/users/payees",
379
+ {
380
+ payeeId,
381
+ setAsDefault: true
382
+ },
383
+ { useApiKey: false }
384
+ );
365
385
  return this.transformPayee(response);
366
386
  }
367
387
  /**
368
388
  * Delete a payee
369
- *
389
+ *
370
390
  * @example
371
391
  * ```typescript
372
392
  * await diviswap.payees.delete('payee-id');
@@ -380,7 +400,7 @@ var PayeesModule = class {
380
400
  }
381
401
  /**
382
402
  * Get verification status of a payee
383
- *
403
+ *
384
404
  * @example
385
405
  * ```typescript
386
406
  * const status = await diviswap.payees.getVerificationStatus('payee-id');
@@ -388,11 +408,13 @@ var PayeesModule = class {
388
408
  * ```
389
409
  */
390
410
  async getVerificationStatus(_payeeId) {
391
- throw new Error("Payee verification status endpoint not available in v1 API yet");
411
+ throw new Error(
412
+ "Payee verification status endpoint not available in v1 API yet"
413
+ );
392
414
  }
393
415
  /**
394
416
  * Verify a payee with micro-deposit amounts
395
- *
417
+ *
396
418
  * @example
397
419
  * ```typescript
398
420
  * const result = await diviswap.payees.verify('payee-id', {
@@ -402,11 +424,13 @@ var PayeesModule = class {
402
424
  * ```
403
425
  */
404
426
  async verify(_payeeId, _data) {
405
- throw new Error("Payee verification endpoint not available in v1 API yet");
427
+ throw new Error(
428
+ "Payee verification endpoint not available in v1 API yet"
429
+ );
406
430
  }
407
431
  /**
408
432
  * Get the default payee
409
- *
433
+ *
410
434
  * @example
411
435
  * ```typescript
412
436
  * const defaultPayee = await diviswap.payees.getDefault();
@@ -465,19 +489,19 @@ var CHAIN_ID_TO_NAME = {
465
489
  84532: "base-sepolia"
466
490
  };
467
491
  var CHAIN_NAME_TO_ID = {
468
- "ethereum": 1,
469
- "eth": 1,
470
- "goerli": 5,
471
- "sepolia": 11155111,
472
- "polygon": 137,
473
- "matic": 137,
474
- "mumbai": 80001,
475
- "base": 8453,
492
+ ethereum: 1,
493
+ eth: 1,
494
+ goerli: 5,
495
+ sepolia: 11155111,
496
+ polygon: 137,
497
+ matic: 137,
498
+ mumbai: 80001,
499
+ base: 8453,
476
500
  "base-goerli": 84531,
477
501
  "base-sepolia": 84532,
478
- "solana": 999999,
502
+ solana: 999999,
479
503
  // Solana mainnet (custom ID for database compatibility)
480
- "sol": 999999
504
+ sol: 999999
481
505
  };
482
506
  var STABLECOIN_ADDRESSES = {
483
507
  ethereum: {
@@ -528,7 +552,9 @@ var TransactionsModule = class {
528
552
  const chainName = normalizedChain === "eth" ? "ethereum" : normalizedChain === "matic" ? "polygon" : normalizedChain;
529
553
  const address = this.depositAddresses[chainName];
530
554
  if (!address || address === "0x..." || address.includes("TODO")) {
531
- throw new Error(`Deposit address not configured for chain: ${chain}. Please contact support.`);
555
+ throw new Error(
556
+ `Deposit address not configured for chain: ${chain}. Please contact support.`
557
+ );
532
558
  }
533
559
  return address;
534
560
  }
@@ -550,7 +576,7 @@ var TransactionsModule = class {
550
576
  }
551
577
  /**
552
578
  * Create an onramp transaction (fiat to crypto)
553
- *
579
+ *
554
580
  * @example
555
581
  * ```typescript
556
582
  * const transaction = await diviswap.transactions.onramp({
@@ -561,7 +587,7 @@ var TransactionsModule = class {
561
587
  * chain: 'ethereum'
562
588
  * });
563
589
  * ```
564
- *
590
+ *
565
591
  * @throws {Error} If user is not KYC approved
566
592
  */
567
593
  async onramp(_data) {
@@ -603,9 +629,7 @@ var TransactionsModule = class {
603
629
  */
604
630
  async offramp(data) {
605
631
  if (!data.txHash || data.txHash.trim() === "") {
606
- throw new Error(
607
- "txHash is required for offramp transactions."
608
- );
632
+ throw new Error("txHash is required for offramp transactions.");
609
633
  }
610
634
  const payload = {
611
635
  payee_id: data.payeeId,
@@ -654,9 +678,7 @@ var TransactionsModule = class {
654
678
  */
655
679
  async offrampTest(data) {
656
680
  if (!data.txHash || data.txHash.trim() === "") {
657
- throw new Error(
658
- "txHash is required for offramp transactions."
659
- );
681
+ throw new Error("txHash is required for offramp transactions.");
660
682
  }
661
683
  const payload = {
662
684
  payee_id: data.payeeId,
@@ -678,12 +700,12 @@ var TransactionsModule = class {
678
700
  }
679
701
  /**
680
702
  * List transactions with optional filters
681
- *
703
+ *
682
704
  * @example
683
705
  * ```typescript
684
706
  * // Get all transactions
685
707
  * const allTransactions = await diviswap.transactions.list();
686
- *
708
+ *
687
709
  * // Get only completed onramp transactions
688
710
  * const completedOnramps = await diviswap.transactions.list({
689
711
  * type: 'onramp',
@@ -721,7 +743,7 @@ var TransactionsModule = class {
721
743
  }
722
744
  /**
723
745
  * Get a specific transaction by ID
724
- *
746
+ *
725
747
  * @example
726
748
  * ```typescript
727
749
  * const transaction = await diviswap.transactions.get('transaction-id');
@@ -738,7 +760,7 @@ var TransactionsModule = class {
738
760
  }
739
761
  /**
740
762
  * Get fee estimate for a transaction
741
- *
763
+ *
742
764
  * @example
743
765
  * ```typescript
744
766
  * const estimate = await diviswap.transactions.estimateFees({
@@ -754,7 +776,7 @@ var TransactionsModule = class {
754
776
  }
755
777
  /**
756
778
  * Get recent transactions (convenience method)
757
- *
779
+ *
758
780
  * @example
759
781
  * ```typescript
760
782
  * const recentTransactions = await diviswap.transactions.getRecent(10);
@@ -765,7 +787,7 @@ var TransactionsModule = class {
765
787
  }
766
788
  /**
767
789
  * Get transaction statistics
768
- *
790
+ *
769
791
  * @example
770
792
  * ```typescript
771
793
  * const stats = await diviswap.transactions.getStats();
@@ -774,21 +796,24 @@ var TransactionsModule = class {
774
796
  */
775
797
  async getStats() {
776
798
  const transactions = await this.list();
777
- const stats = transactions.reduce((acc, tx) => {
778
- acc.totalTransactions++;
779
- acc.totalVolume += tx.amount || 0;
780
- if (tx.status === "pending" || tx.status === "processing") {
781
- acc.pendingTransactions++;
782
- } else if (tx.status === "completed") {
783
- acc.completedTransactions++;
799
+ const stats = transactions.reduce(
800
+ (acc, tx) => {
801
+ acc.totalTransactions++;
802
+ acc.totalVolume += tx.amount || 0;
803
+ if (tx.status === "pending" || tx.status === "processing") {
804
+ acc.pendingTransactions++;
805
+ } else if (tx.status === "completed") {
806
+ acc.completedTransactions++;
807
+ }
808
+ return acc;
809
+ },
810
+ {
811
+ totalTransactions: 0,
812
+ totalVolume: 0,
813
+ pendingTransactions: 0,
814
+ completedTransactions: 0
784
815
  }
785
- return acc;
786
- }, {
787
- totalTransactions: 0,
788
- totalVolume: 0,
789
- pendingTransactions: 0,
790
- completedTransactions: 0
791
- });
816
+ );
792
817
  return stats;
793
818
  }
794
819
  /**
@@ -810,11 +835,11 @@ var KycModule = class {
810
835
  }
811
836
  /**
812
837
  * Get current compliance status including KYC and KYB
813
- *
838
+ *
814
839
  * @example
815
840
  * ```typescript
816
841
  * const status = await diviswap.kyc.getComplianceStatus();
817
- *
842
+ *
818
843
  * if (!status.canTransact) {
819
844
  * if (status.nextStep === 'COMPLETE_KYC') {
820
845
  * // Redirect to KYC flow
@@ -839,19 +864,21 @@ var KycModule = class {
839
864
  kycMetadata: kycData?.metadata
840
865
  };
841
866
  } catch (error) {
842
- throw new Error(`Failed to get compliance status: ${error.message}`);
867
+ throw new Error(
868
+ `Failed to get compliance status: ${error.message}`
869
+ );
843
870
  }
844
871
  }
845
872
  /**
846
873
  * Start KYC verification session (opens Sumsub widget)
847
- *
874
+ *
848
875
  * @example
849
876
  * ```typescript
850
877
  * const session = await diviswap.kyc.startKycSession();
851
- *
878
+ *
852
879
  * // Redirect user to session URL
853
880
  * window.location.href = session.sessionUrl;
854
- *
881
+ *
855
882
  * // Or embed in iframe
856
883
  * const iframe = document.createElement('iframe');
857
884
  * iframe.src = session.sessionUrl;
@@ -862,7 +889,7 @@ var KycModule = class {
862
889
  }
863
890
  /**
864
891
  * Submit KYC documents programmatically
865
- *
892
+ *
866
893
  * @example
867
894
  * ```typescript
868
895
  * // Convert file to base64
@@ -872,10 +899,10 @@ var KycModule = class {
872
899
  * reader.onload = () => resolve(reader.result as string);
873
900
  * reader.onerror = reject;
874
901
  * });
875
- *
902
+ *
876
903
  * const frontImage = await toBase64(frontFile);
877
904
  * const backImage = await toBase64(backFile);
878
- *
905
+ *
879
906
  * await diviswap.kyc.submitDocuments({
880
907
  * type: 'DRIVERS_LICENSE',
881
908
  * frontImage,
@@ -888,13 +915,15 @@ var KycModule = class {
888
915
  throw new ValidationError("Front image is required");
889
916
  }
890
917
  if (["DRIVERS_LICENSE", "ID_CARD"].includes(documents.type) && !documents.backImage) {
891
- throw new ValidationError(`Back image is required for ${documents.type}`);
918
+ throw new ValidationError(
919
+ `Back image is required for ${documents.type}`
920
+ );
892
921
  }
893
922
  throw new Error("KYC documents endpoint not available in v1 API yet");
894
923
  }
895
924
  /**
896
925
  * Submit personal information for KYC
897
- *
926
+ *
898
927
  * @example
899
928
  * ```typescript
900
929
  * await diviswap.kyc.submitPersonalInfo({
@@ -923,18 +952,25 @@ var KycModule = class {
923
952
  throw new ValidationError("Complete address is required");
924
953
  }
925
954
  try {
926
- const response = await this.client.post("/api/v1/kyc/personal-info", {
927
- first_name: info.firstName,
928
- last_name: info.lastName,
929
- dob: info.dateOfBirth,
930
- country: info.address.country,
931
- ...info.phone && { phone: info.phone },
932
- ...info.address.street && { address: info.address.street },
933
- ...info.address.city && { city: info.address.city },
934
- ...info.address.state && { state: info.address.state },
935
- ...info.address.postalCode && { postal_code: info.address.postalCode },
936
- ...info.ssn && { ssn: info.ssn }
937
- });
955
+ const response = await this.client.post(
956
+ "/api/v1/kyc/personal-info",
957
+ {
958
+ first_name: info.firstName,
959
+ last_name: info.lastName,
960
+ dob: info.dateOfBirth,
961
+ country: info.address.country,
962
+ ...info.phone && { phone: info.phone },
963
+ ...info.address.street && {
964
+ address: info.address.street
965
+ },
966
+ ...info.address.city && { city: info.address.city },
967
+ ...info.address.state && { state: info.address.state },
968
+ ...info.address.postalCode && {
969
+ postal_code: info.address.postalCode
970
+ },
971
+ ...info.ssn && { ssn: info.ssn }
972
+ }
973
+ );
938
974
  return response;
939
975
  } catch (error) {
940
976
  throw new Error(`Failed to submit KYC info: ${error.message}`);
@@ -942,7 +978,7 @@ var KycModule = class {
942
978
  }
943
979
  /**
944
980
  * Check if user can transact (convenience method)
945
- *
981
+ *
946
982
  * @example
947
983
  * ```typescript
948
984
  * const canTransact = await diviswap.kyc.canTransact();
@@ -957,7 +993,7 @@ var KycModule = class {
957
993
  }
958
994
  /**
959
995
  * Check if KYC is approved
960
- *
996
+ *
961
997
  * @example
962
998
  * ```typescript
963
999
  * const isApproved = await diviswap.kyc.isKycApproved();
@@ -969,7 +1005,7 @@ var KycModule = class {
969
1005
  }
970
1006
  /**
971
1007
  * Check if KYB is approved (for business accounts)
972
- *
1008
+ *
973
1009
  * @example
974
1010
  * ```typescript
975
1011
  * const isBusinessApproved = await diviswap.kyc.isKybApproved();
@@ -981,7 +1017,7 @@ var KycModule = class {
981
1017
  }
982
1018
  /**
983
1019
  * Get rejection reasons if KYC/KYB was rejected
984
- *
1020
+ *
985
1021
  * @example
986
1022
  * ```typescript
987
1023
  * const reasons = await diviswap.kyc.getRejectionReasons();
@@ -1000,13 +1036,13 @@ var KycModule = class {
1000
1036
  }
1001
1037
  /**
1002
1038
  * Wait for KYC approval (polling)
1003
- *
1039
+ *
1004
1040
  * @example
1005
1041
  * ```typescript
1006
1042
  * // Start KYC session
1007
1043
  * const session = await diviswap.kyc.startKycSession();
1008
1044
  * window.open(session.sessionUrl);
1009
- *
1045
+ *
1010
1046
  * // Wait for approval (polls every 5 seconds for up to 10 minutes)
1011
1047
  * try {
1012
1048
  * await diviswap.kyc.waitForApproval();
@@ -1026,7 +1062,9 @@ var KycModule = class {
1026
1062
  return status;
1027
1063
  }
1028
1064
  if (status.kycStatus === "REJECTED") {
1029
- throw new Error(`KYC rejected: ${status.kycMetadata?.rejectLabels?.join(", ") || "Unknown reason"}`);
1065
+ throw new Error(
1066
+ `KYC rejected: ${status.kycMetadata?.rejectLabels?.join(", ") || "Unknown reason"}`
1067
+ );
1030
1068
  }
1031
1069
  attempts++;
1032
1070
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
@@ -1057,9 +1095,12 @@ var FeesModule = class {
1057
1095
  */
1058
1096
  async setFee(data) {
1059
1097
  if (data.userId) {
1060
- await this.client.put(`/api/v1/partner/users/${data.userId}/fee`, {
1061
- percentage: data.percentage
1062
- });
1098
+ await this.client.put(
1099
+ `/api/v1/partner/users/${data.userId}/fee`,
1100
+ {
1101
+ percentage: data.percentage
1102
+ }
1103
+ );
1063
1104
  return {
1064
1105
  integratorFeePercentage: data.percentage,
1065
1106
  baseFeePercentage: 1.5,
@@ -1111,10 +1152,13 @@ var FeesModule = class {
1111
1152
  * ```
1112
1153
  */
1113
1154
  async calculateFees(params) {
1114
- const response = await this.client.post("/api/v1/partner/fees/calculate", {
1115
- amount: params.amount,
1116
- user_id: params.userId
1117
- });
1155
+ const response = await this.client.post(
1156
+ "/api/v1/partner/fees/calculate",
1157
+ {
1158
+ amount: params.amount,
1159
+ user_id: params.userId
1160
+ }
1161
+ );
1118
1162
  return {
1119
1163
  amount: response.amount,
1120
1164
  baseFee: response.base_fee,
@@ -1160,7 +1204,7 @@ var AddressesModule = class {
1160
1204
  }
1161
1205
  /**
1162
1206
  * Get all addresses for the authenticated user
1163
- *
1207
+ *
1164
1208
  * @example
1165
1209
  * ```typescript
1166
1210
  * const addresses = await diviswap.addresses.list();
@@ -1173,7 +1217,7 @@ var AddressesModule = class {
1173
1217
  }
1174
1218
  /**
1175
1219
  * Create a new crypto address for the user
1176
- *
1220
+ *
1177
1221
  * @example
1178
1222
  * ```typescript
1179
1223
  * const address = await diviswap.addresses.create({
@@ -1194,7 +1238,7 @@ var AddressesModule = class {
1194
1238
  }
1195
1239
  /**
1196
1240
  * Set a specific address as the default for its chain
1197
- *
1241
+ *
1198
1242
  * @example
1199
1243
  * ```typescript
1200
1244
  * await diviswap.addresses.setDefault({
@@ -1208,7 +1252,7 @@ var AddressesModule = class {
1208
1252
  }
1209
1253
  /**
1210
1254
  * Delete a crypto address
1211
- *
1255
+ *
1212
1256
  * @example
1213
1257
  * ```typescript
1214
1258
  * await diviswap.addresses.delete({
@@ -1222,7 +1266,7 @@ var AddressesModule = class {
1222
1266
  }
1223
1267
  /**
1224
1268
  * Get addresses for a specific chain
1225
- *
1269
+ *
1226
1270
  * @example
1227
1271
  * ```typescript
1228
1272
  * const ethAddresses = await diviswap.addresses.getByChain(1);
@@ -1236,7 +1280,7 @@ var AddressesModule = class {
1236
1280
  }
1237
1281
  /**
1238
1282
  * Get the default address for a specific chain
1239
- *
1283
+ *
1240
1284
  * @example
1241
1285
  * ```typescript
1242
1286
  * const defaultEthAddress = await diviswap.addresses.getDefault(1);
@@ -1246,11 +1290,13 @@ var AddressesModule = class {
1246
1290
  async getDefault(chainIdOrName) {
1247
1291
  const chainId = typeof chainIdOrName === "string" ? CHAIN_IDS[chainIdOrName] : chainIdOrName;
1248
1292
  const addresses = await this.list();
1249
- return addresses.find((addr) => addr.chain_id === chainId && addr.is_default) || null;
1293
+ return addresses.find(
1294
+ (addr) => addr.chain_id === chainId && addr.is_default
1295
+ ) || null;
1250
1296
  }
1251
1297
  /**
1252
1298
  * Check if an address exists for the user
1253
- *
1299
+ *
1254
1300
  * @example
1255
1301
  * ```typescript
1256
1302
  * const exists = await diviswap.addresses.exists({
@@ -1268,7 +1314,7 @@ var AddressesModule = class {
1268
1314
  /**
1269
1315
  * Automatically track a wallet connection
1270
1316
  * This is the main method for automatic address tracking
1271
- *
1317
+ *
1272
1318
  * @example
1273
1319
  * ```typescript
1274
1320
  * // When user connects wallet
@@ -1304,7 +1350,7 @@ var AddressesModule = class {
1304
1350
  }
1305
1351
  /**
1306
1352
  * Auto-track multiple wallet connections (useful for multi-chain wallets)
1307
- *
1353
+ *
1308
1354
  * @example
1309
1355
  * ```typescript
1310
1356
  * // When user connects a multi-chain wallet
@@ -1322,7 +1368,10 @@ var AddressesModule = class {
1322
1368
  const address = await this.trackWallet(connection);
1323
1369
  results.push(address);
1324
1370
  } catch (error) {
1325
- console.error(`Failed to track wallet for chain ${connection.chainId}:`, error);
1371
+ console.error(
1372
+ `Failed to track wallet for chain ${connection.chainId}:`,
1373
+ error
1374
+ );
1326
1375
  }
1327
1376
  }
1328
1377
  return results;
@@ -1381,10 +1430,13 @@ var WebhooksModule = class {
1381
1430
  * ```
1382
1431
  */
1383
1432
  async setConfigForPartner(partnerId, data) {
1384
- const response = await this.client.put(`/api/v1/partners/${partnerId}/webhook`, {
1385
- webhook_url: data.webhook_url,
1386
- webhook_secret: data.webhook_secret
1387
- });
1433
+ const response = await this.client.put(
1434
+ `/api/v1/partners/${partnerId}/webhook`,
1435
+ {
1436
+ webhook_url: data.webhook_url,
1437
+ webhook_secret: data.webhook_secret
1438
+ }
1439
+ );
1388
1440
  return response;
1389
1441
  }
1390
1442
  /**
@@ -1398,14 +1450,18 @@ var WebhooksModule = class {
1398
1450
  * ```
1399
1451
  */
1400
1452
  async getConfig() {
1401
- const response = await this.client.get("/api/v1/partner/webhook");
1453
+ const response = await this.client.get(
1454
+ "/api/v1/partner/webhook"
1455
+ );
1402
1456
  return response;
1403
1457
  }
1404
1458
  /**
1405
1459
  * Get webhook config for a specific partner (user-owned)
1406
1460
  */
1407
1461
  async getConfigForPartner(partnerId) {
1408
- const response = await this.client.get(`/api/v1/partners/${partnerId}/webhook`);
1462
+ const response = await this.client.get(
1463
+ `/api/v1/partners/${partnerId}/webhook`
1464
+ );
1409
1465
  return response;
1410
1466
  }
1411
1467
  /**
@@ -1582,7 +1638,10 @@ var TokenManager = class {
1582
1638
  this.refreshPromise = refreshCallback(refreshToken);
1583
1639
  try {
1584
1640
  const newTokenData = await this.refreshPromise;
1585
- this.setTokens(newTokenData.accessToken, newTokenData.refreshToken || refreshToken);
1641
+ this.setTokens(
1642
+ newTokenData.accessToken,
1643
+ newTokenData.refreshToken || refreshToken
1644
+ );
1586
1645
  return newTokenData.accessToken;
1587
1646
  } finally {
1588
1647
  this.refreshPromise = null;
@@ -1626,7 +1685,7 @@ var PartnerAuth = class {
1626
1685
  ].join("\n");
1627
1686
  const signature = crypto.createHmac("sha256", this.credentials.secretKey).update(canonical).digest("base64");
1628
1687
  const headers = {
1629
- "Authorization": `HMAC ${this.credentials.keyId}:${signature}:${timestamp}:${nonce}`,
1688
+ Authorization: `HMAC ${this.credentials.keyId}:${signature}:${timestamp}:${nonce}`,
1630
1689
  "X-Client-Id": this.credentials.keyId
1631
1690
  };
1632
1691
  if (this.credentials.customerId) {
@@ -1648,7 +1707,7 @@ var PartnerAuth = class {
1648
1707
  */
1649
1708
  generateJWT(options = {}) {
1650
1709
  const {
1651
- audience = "api.liberex.sv",
1710
+ audience = "api.diviswap.com",
1652
1711
  expiresIn = 300,
1653
1712
  // 5 minutes max
1654
1713
  scopes = []
@@ -1663,13 +1722,21 @@ var PartnerAuth = class {
1663
1722
  // Expiration (max 5 minutes)
1664
1723
  iat: now,
1665
1724
  // Issued at
1666
- ...this.credentials.customerId && { sub: this.credentials.customerId },
1667
- ...this.credentials.customerEmail && { email: this.credentials.customerEmail },
1725
+ ...this.credentials.customerId && {
1726
+ sub: this.credentials.customerId
1727
+ },
1728
+ ...this.credentials.customerEmail && {
1729
+ email: this.credentials.customerEmail
1730
+ },
1668
1731
  ...scopes.length > 0 && { scope: scopes }
1669
1732
  };
1670
1733
  const header = { alg: "HS256", typ: "JWT" };
1671
- const encodedHeader = Buffer.from(JSON.stringify(header)).toString("base64url");
1672
- const encodedPayload = Buffer.from(JSON.stringify(payload)).toString("base64url");
1734
+ const encodedHeader = Buffer.from(JSON.stringify(header)).toString(
1735
+ "base64url"
1736
+ );
1737
+ const encodedPayload = Buffer.from(JSON.stringify(payload)).toString(
1738
+ "base64url"
1739
+ );
1673
1740
  const signature = crypto.createHmac("sha256", this.credentials.secretKey).update(`${encodedHeader}.${encodedPayload}`).digest("base64url");
1674
1741
  return `${encodedHeader}.${encodedPayload}.${signature}`;
1675
1742
  }
@@ -1708,51 +1775,63 @@ var UnifiedApiClient = class _UnifiedApiClient {
1708
1775
  */
1709
1776
  static fromUserConfig(config, useLocalStorage = true) {
1710
1777
  const baseUrl = config.apiUrl || this.getDefaultApiUrl(config.environment || "production");
1711
- return new _UnifiedApiClient({
1712
- baseUrl,
1713
- timeout: config.timeout || 3e4,
1714
- debug: config.debug || false,
1715
- mode: "user",
1716
- apiKey: config.apiKey,
1717
- clientId: config.clientId
1718
- }, useLocalStorage);
1778
+ return new _UnifiedApiClient(
1779
+ {
1780
+ baseUrl,
1781
+ timeout: config.timeout || 3e4,
1782
+ debug: config.debug || false,
1783
+ mode: "user",
1784
+ apiKey: config.apiKey,
1785
+ clientId: config.clientId
1786
+ },
1787
+ useLocalStorage
1788
+ );
1719
1789
  }
1720
1790
  /**
1721
1791
  * Create client from partner config
1722
1792
  */
1723
1793
  static fromPartnerConfig(config, useLocalStorage = true) {
1724
1794
  const baseUrl = config.apiUrl || this.getDefaultApiUrl(config.environment || "production");
1725
- return new _UnifiedApiClient({
1726
- baseUrl,
1727
- timeout: config.timeout || 3e4,
1728
- debug: config.debug || false,
1729
- mode: "partner",
1730
- keyId: config.keyId,
1731
- secretKey: config.secretKey,
1732
- authMethod: config.authMethod || "hmac",
1733
- customerId: config.customerId,
1734
- customerEmail: config.customerEmail
1735
- }, useLocalStorage);
1795
+ return new _UnifiedApiClient(
1796
+ {
1797
+ baseUrl,
1798
+ timeout: config.timeout || 3e4,
1799
+ debug: config.debug || false,
1800
+ mode: "partner",
1801
+ keyId: config.keyId,
1802
+ secretKey: config.secretKey,
1803
+ authMethod: config.authMethod || "hmac",
1804
+ customerId: config.customerId,
1805
+ customerEmail: config.customerEmail
1806
+ },
1807
+ useLocalStorage
1808
+ );
1736
1809
  }
1737
1810
  /**
1738
1811
  * Create client from any config (auto-detect mode)
1739
1812
  */
1740
1813
  static fromConfig(config, useLocalStorage = true) {
1741
1814
  if ("mode" in config && config.mode === "partner" || "keyId" in config && "secretKey" in config) {
1742
- return this.fromPartnerConfig(config, useLocalStorage);
1815
+ return this.fromPartnerConfig(
1816
+ config,
1817
+ useLocalStorage
1818
+ );
1743
1819
  } else {
1744
- return this.fromUserConfig(config, useLocalStorage);
1820
+ return this.fromUserConfig(
1821
+ config,
1822
+ useLocalStorage
1823
+ );
1745
1824
  }
1746
1825
  }
1747
1826
  static getDefaultApiUrl(environment) {
1748
1827
  switch (environment) {
1749
1828
  case "production":
1750
1829
  case "sandbox":
1751
- return "https://api.liberex.sv";
1830
+ return "https://api.diviswap.com";
1752
1831
  case "development":
1753
- return "https://dev-api.liberex.sv";
1832
+ return "https://dev-api.diviswap.com";
1754
1833
  default:
1755
- return "https://api.liberex.sv";
1834
+ return "https://api.diviswap.com";
1756
1835
  }
1757
1836
  }
1758
1837
  /**
@@ -1818,7 +1897,14 @@ var UnifiedApiClient = class _UnifiedApiClient {
1818
1897
  * Make authenticated API request
1819
1898
  */
1820
1899
  async request(options) {
1821
- const { method, path, body, headers = {}, useApiKey = false, skipAuth = false } = options;
1900
+ const {
1901
+ method,
1902
+ path,
1903
+ body,
1904
+ headers = {},
1905
+ useApiKey = false,
1906
+ skipAuth = false
1907
+ } = options;
1822
1908
  const url = `${this.config.baseUrl}${path}`;
1823
1909
  const requestHeaders = {
1824
1910
  "Content-Type": "application/json",
@@ -1834,7 +1920,10 @@ var UnifiedApiClient = class _UnifiedApiClient {
1834
1920
  }
1835
1921
  try {
1836
1922
  const controller = new AbortController();
1837
- const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
1923
+ const timeoutId = setTimeout(
1924
+ () => controller.abort(),
1925
+ this.config.timeout
1926
+ );
1838
1927
  if (this.config.debug) {
1839
1928
  console.log(`[Diviswap SDK] ${method} ${url}`);
1840
1929
  }
@@ -1853,7 +1942,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
1853
1942
  responseData = responseText;
1854
1943
  }
1855
1944
  if (this.config.debug) {
1856
- console.log(`[Diviswap SDK] Response ${response.status}: ${responseText.substring(0, 500)}`);
1945
+ console.log(
1946
+ `[Diviswap SDK] Response ${response.status}: ${responseText.substring(0, 500)}`
1947
+ );
1857
1948
  }
1858
1949
  if (!response.ok) {
1859
1950
  await this.handleErrorResponse(response, responseData);
@@ -1874,7 +1965,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
1874
1965
  */
1875
1966
  async addPartnerAuth(method, path, body, headers) {
1876
1967
  if (!this.partnerAuth) {
1877
- throw new AuthenticationError("Partner authentication not configured");
1968
+ throw new AuthenticationError(
1969
+ "Partner authentication not configured"
1970
+ );
1878
1971
  }
1879
1972
  const bodyString = body ? JSON.stringify(body) : "";
1880
1973
  const urlParts = path.split("?");
@@ -1882,7 +1975,7 @@ var UnifiedApiClient = class _UnifiedApiClient {
1882
1975
  const queryString = urlParts.length > 1 ? urlParts[1] : "";
1883
1976
  if (this.config.authMethod === "jwt") {
1884
1977
  const jwt = this.partnerAuth.generateJWT({
1885
- audience: "api.liberex.sv",
1978
+ audience: "api.diviswap.com",
1886
1979
  expiresIn: 300
1887
1980
  });
1888
1981
  headers["Authorization"] = `Bearer ${jwt}`;
@@ -1907,7 +2000,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
1907
2000
  headers["X-TIMESTAMP"] = Math.floor(Date.now() / 1e3).toString();
1908
2001
  headers["X-API-Key"] = this.config.apiKey;
1909
2002
  if (!useApiKey) {
1910
- const accessToken = await this.tokenManager.getValidAccessToken(this.refreshCallback);
2003
+ const accessToken = await this.tokenManager.getValidAccessToken(
2004
+ this.refreshCallback
2005
+ );
1911
2006
  if (accessToken) {
1912
2007
  headers["Authorization"] = `Bearer ${accessToken}`;
1913
2008
  }
@@ -1965,7 +2060,10 @@ var _Diviswap = class _Diviswap {
1965
2060
  this.apiClient = UnifiedApiClient.fromConfig(config, useLocalStorage);
1966
2061
  this.auth = new AuthModule(this.apiClient);
1967
2062
  this.payees = new PayeesModule(this.apiClient);
1968
- this.transactions = new TransactionsModule(this.apiClient, config.environment || "sandbox");
2063
+ this.transactions = new TransactionsModule(
2064
+ this.apiClient,
2065
+ config.environment || "sandbox"
2066
+ );
1969
2067
  this.kyc = new KycModule(this.apiClient);
1970
2068
  this.fees = new FeesModule(this.apiClient);
1971
2069
  this.addresses = new AddressesModule(this.apiClient);
@@ -1997,7 +2095,9 @@ var _Diviswap = class _Diviswap {
1997
2095
  */
1998
2096
  static getInstance() {
1999
2097
  if (!_Diviswap.instance) {
2000
- throw new ConfigurationError("Diviswap SDK not initialized. Call Diviswap.init() first.");
2098
+ throw new ConfigurationError(
2099
+ "Diviswap SDK not initialized. Call Diviswap.init() first."
2100
+ );
2001
2101
  }
2002
2102
  return _Diviswap.instance;
2003
2103
  }
@@ -2012,7 +2112,9 @@ var _Diviswap = class _Diviswap {
2012
2112
  * @deprecated Configuration updates require re-initialization. Call Diviswap.reset() then Diviswap.init() with new config.
2013
2113
  */
2014
2114
  updateConfig(_config) {
2015
- throw new ConfigurationError("Configuration updates require re-initialization. Call Diviswap.reset() then Diviswap.init() with new config.");
2115
+ throw new ConfigurationError(
2116
+ "Configuration updates require re-initialization. Call Diviswap.reset() then Diviswap.init() with new config."
2117
+ );
2016
2118
  }
2017
2119
  /**
2018
2120
  * Get current configuration (excluding sensitive data)
@@ -2034,7 +2136,7 @@ var _Diviswap = class _Diviswap {
2034
2136
  * const token = await diviswap.getAccessToken();
2035
2137
  * if (token) {
2036
2138
  * // Use token for custom API calls
2037
- * fetch('https://api.liberex.sv/custom-endpoint', {
2139
+ * fetch('https://api.diviswap.com/custom-endpoint', {
2038
2140
  * headers: { 'Authorization': `Bearer ${token}` }
2039
2141
  * });
2040
2142
  * }
@@ -2085,25 +2187,39 @@ var _Diviswap = class _Diviswap {
2085
2187
  if (isPartnerMode) {
2086
2188
  const partnerConfig = config;
2087
2189
  if (!partnerConfig.keyId) {
2088
- throw new ConfigurationError("Partner keyId is required for partner authentication");
2190
+ throw new ConfigurationError(
2191
+ "Partner keyId is required for partner authentication"
2192
+ );
2089
2193
  }
2090
2194
  if (!partnerConfig.secretKey) {
2091
- throw new ConfigurationError("Partner secretKey is required for partner authentication");
2195
+ throw new ConfigurationError(
2196
+ "Partner secretKey is required for partner authentication"
2197
+ );
2092
2198
  }
2093
2199
  if (partnerConfig.authMethod && !["hmac", "jwt"].includes(partnerConfig.authMethod)) {
2094
- throw new ConfigurationError('Invalid authMethod. Must be either "hmac" or "jwt"');
2200
+ throw new ConfigurationError(
2201
+ 'Invalid authMethod. Must be either "hmac" or "jwt"'
2202
+ );
2095
2203
  }
2096
2204
  } else {
2097
2205
  const userConfig = config;
2098
2206
  if (!userConfig.apiKey) {
2099
- throw new ConfigurationError("API Key is required for user authentication");
2207
+ throw new ConfigurationError(
2208
+ "API Key is required for user authentication"
2209
+ );
2100
2210
  }
2101
2211
  if (!userConfig.clientId) {
2102
- throw new ConfigurationError("Client ID is required for user authentication");
2212
+ throw new ConfigurationError(
2213
+ "Client ID is required for user authentication"
2214
+ );
2103
2215
  }
2104
2216
  }
2105
- if (config.environment && !["production", "sandbox", "development"].includes(config.environment)) {
2106
- throw new ConfigurationError("Invalid environment. Must be one of: production, sandbox, development");
2217
+ if (config.environment && !["production", "sandbox", "development"].includes(
2218
+ config.environment
2219
+ )) {
2220
+ throw new ConfigurationError(
2221
+ "Invalid environment. Must be one of: production, sandbox, development"
2222
+ );
2107
2223
  }
2108
2224
  }
2109
2225
  };
@@ -2278,7 +2394,9 @@ var _WalletTracker = class _WalletTracker {
2278
2394
  * Get chain name from chain ID
2279
2395
  */
2280
2396
  getChainName(chainId) {
2281
- const builtInChain = Object.entries(CHAIN_IDS).find(([_, id]) => id === chainId)?.[0];
2397
+ const builtInChain = Object.entries(CHAIN_IDS).find(
2398
+ ([_, id]) => id === chainId
2399
+ )?.[0];
2282
2400
  if (builtInChain) return builtInChain;
2283
2401
  return this.config.customChains?.[chainId];
2284
2402
  }