@diviswap/sdk 1.7.27 → 1.8.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.
- package/LICENSE +1 -1
- package/README.md +73 -82
- package/bin/create-diviswap-app.js +5 -5
- package/dist/cli/index.js +438 -185
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +302 -178
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +302 -178
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +260 -183
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +260 -183
- package/dist/react/index.mjs.map +1 -1
- package/dist/{wallet-DZymADRo.d.mts → wallet-Ca1U51kT.d.mts} +1 -1
- package/dist/{wallet-DZymADRo.d.ts → wallet-Ca1U51kT.d.ts} +1 -1
- package/package.json +98 -97
- package/src/cli/templates/index.ts +86 -54
- package/src/cli/templates/shared/client.ts +65 -65
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 || {
|
|
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(
|
|
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 || {
|
|
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(
|
|
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(
|
|
210
|
-
|
|
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) {
|
|
@@ -232,7 +248,7 @@ var PayeesModule = class {
|
|
|
232
248
|
}
|
|
233
249
|
/**
|
|
234
250
|
* Create a new payee (bank account)
|
|
235
|
-
*
|
|
251
|
+
*
|
|
236
252
|
* @example
|
|
237
253
|
* ```typescript
|
|
238
254
|
* // Bank account
|
|
@@ -243,7 +259,7 @@ var PayeesModule = class {
|
|
|
243
259
|
* accountType: 'checking',
|
|
244
260
|
* setAsDefault: true
|
|
245
261
|
* });
|
|
246
|
-
*
|
|
262
|
+
*
|
|
247
263
|
* // Debit card
|
|
248
264
|
* const debitCard = await diviswap.payees.create({
|
|
249
265
|
* nickname: 'My Debit Card',
|
|
@@ -263,7 +279,9 @@ var PayeesModule = class {
|
|
|
263
279
|
let response;
|
|
264
280
|
if (data.accountType === "debit_card") {
|
|
265
281
|
if (!data.debitCard) {
|
|
266
|
-
throw new Error(
|
|
282
|
+
throw new Error(
|
|
283
|
+
"Debit card information is required for debit_card account type"
|
|
284
|
+
);
|
|
267
285
|
}
|
|
268
286
|
response = await this.client.post("/api/v1/payees", {
|
|
269
287
|
name: data.nickname,
|
|
@@ -277,7 +295,9 @@ var PayeesModule = class {
|
|
|
277
295
|
});
|
|
278
296
|
} else {
|
|
279
297
|
if (!data.accountNumber || !data.routingNumber) {
|
|
280
|
-
throw new Error(
|
|
298
|
+
throw new Error(
|
|
299
|
+
"Account number and routing number are required for bank accounts"
|
|
300
|
+
);
|
|
281
301
|
}
|
|
282
302
|
response = await this.client.post("/api/v1/payees", {
|
|
283
303
|
name: data.nickname,
|
|
@@ -294,7 +314,7 @@ var PayeesModule = class {
|
|
|
294
314
|
}
|
|
295
315
|
/**
|
|
296
316
|
* List all payees
|
|
297
|
-
*
|
|
317
|
+
*
|
|
298
318
|
* @example
|
|
299
319
|
* ```typescript
|
|
300
320
|
* const payees = await diviswap.payees.list();
|
|
@@ -302,7 +322,9 @@ var PayeesModule = class {
|
|
|
302
322
|
* ```
|
|
303
323
|
*/
|
|
304
324
|
async list() {
|
|
305
|
-
const response = await this.client.get("/api/v1/users/payees", {
|
|
325
|
+
const response = await this.client.get("/api/v1/users/payees", {
|
|
326
|
+
useApiKey: false
|
|
327
|
+
});
|
|
306
328
|
return this.parsePayeesResponse(response);
|
|
307
329
|
}
|
|
308
330
|
parsePayeesResponse(response) {
|
|
@@ -335,7 +357,7 @@ var PayeesModule = class {
|
|
|
335
357
|
}
|
|
336
358
|
/**
|
|
337
359
|
* Get a specific payee
|
|
338
|
-
*
|
|
360
|
+
*
|
|
339
361
|
* @example
|
|
340
362
|
* ```typescript
|
|
341
363
|
* const payee = await diviswap.payees.get('payee-id');
|
|
@@ -351,22 +373,26 @@ var PayeesModule = class {
|
|
|
351
373
|
}
|
|
352
374
|
/**
|
|
353
375
|
* Set a payee as default
|
|
354
|
-
*
|
|
376
|
+
*
|
|
355
377
|
* @example
|
|
356
378
|
* ```typescript
|
|
357
379
|
* await diviswap.payees.setDefault('payee-id');
|
|
358
380
|
* ```
|
|
359
381
|
*/
|
|
360
382
|
async setDefault(payeeId) {
|
|
361
|
-
const response = await this.client.put(
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
383
|
+
const response = await this.client.put(
|
|
384
|
+
"/api/v1/users/payees",
|
|
385
|
+
{
|
|
386
|
+
payeeId,
|
|
387
|
+
setAsDefault: true
|
|
388
|
+
},
|
|
389
|
+
{ useApiKey: false }
|
|
390
|
+
);
|
|
365
391
|
return this.transformPayee(response);
|
|
366
392
|
}
|
|
367
393
|
/**
|
|
368
394
|
* Delete a payee
|
|
369
|
-
*
|
|
395
|
+
*
|
|
370
396
|
* @example
|
|
371
397
|
* ```typescript
|
|
372
398
|
* await diviswap.payees.delete('payee-id');
|
|
@@ -380,7 +406,7 @@ var PayeesModule = class {
|
|
|
380
406
|
}
|
|
381
407
|
/**
|
|
382
408
|
* Get verification status of a payee
|
|
383
|
-
*
|
|
409
|
+
*
|
|
384
410
|
* @example
|
|
385
411
|
* ```typescript
|
|
386
412
|
* const status = await diviswap.payees.getVerificationStatus('payee-id');
|
|
@@ -388,11 +414,13 @@ var PayeesModule = class {
|
|
|
388
414
|
* ```
|
|
389
415
|
*/
|
|
390
416
|
async getVerificationStatus(_payeeId) {
|
|
391
|
-
throw new Error(
|
|
417
|
+
throw new Error(
|
|
418
|
+
"Payee verification status endpoint not available in v1 API yet"
|
|
419
|
+
);
|
|
392
420
|
}
|
|
393
421
|
/**
|
|
394
422
|
* Verify a payee with micro-deposit amounts
|
|
395
|
-
*
|
|
423
|
+
*
|
|
396
424
|
* @example
|
|
397
425
|
* ```typescript
|
|
398
426
|
* const result = await diviswap.payees.verify('payee-id', {
|
|
@@ -402,11 +430,13 @@ var PayeesModule = class {
|
|
|
402
430
|
* ```
|
|
403
431
|
*/
|
|
404
432
|
async verify(_payeeId, _data) {
|
|
405
|
-
throw new Error(
|
|
433
|
+
throw new Error(
|
|
434
|
+
"Payee verification endpoint not available in v1 API yet"
|
|
435
|
+
);
|
|
406
436
|
}
|
|
407
437
|
/**
|
|
408
438
|
* Get the default payee
|
|
409
|
-
*
|
|
439
|
+
*
|
|
410
440
|
* @example
|
|
411
441
|
* ```typescript
|
|
412
442
|
* const defaultPayee = await diviswap.payees.getDefault();
|
|
@@ -465,19 +495,19 @@ var CHAIN_ID_TO_NAME = {
|
|
|
465
495
|
84532: "base-sepolia"
|
|
466
496
|
};
|
|
467
497
|
var CHAIN_NAME_TO_ID = {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
498
|
+
ethereum: 1,
|
|
499
|
+
eth: 1,
|
|
500
|
+
goerli: 5,
|
|
501
|
+
sepolia: 11155111,
|
|
502
|
+
polygon: 137,
|
|
503
|
+
matic: 137,
|
|
504
|
+
mumbai: 80001,
|
|
505
|
+
base: 8453,
|
|
476
506
|
"base-goerli": 84531,
|
|
477
507
|
"base-sepolia": 84532,
|
|
478
|
-
|
|
508
|
+
solana: 999999,
|
|
479
509
|
// Solana mainnet (custom ID for database compatibility)
|
|
480
|
-
|
|
510
|
+
sol: 999999
|
|
481
511
|
};
|
|
482
512
|
var STABLECOIN_ADDRESSES = {
|
|
483
513
|
ethereum: {
|
|
@@ -528,7 +558,9 @@ var TransactionsModule = class {
|
|
|
528
558
|
const chainName = normalizedChain === "eth" ? "ethereum" : normalizedChain === "matic" ? "polygon" : normalizedChain;
|
|
529
559
|
const address = this.depositAddresses[chainName];
|
|
530
560
|
if (!address || address === "0x..." || address.includes("TODO")) {
|
|
531
|
-
throw new Error(
|
|
561
|
+
throw new Error(
|
|
562
|
+
`Deposit address not configured for chain: ${chain}. Please contact support.`
|
|
563
|
+
);
|
|
532
564
|
}
|
|
533
565
|
return address;
|
|
534
566
|
}
|
|
@@ -550,7 +582,7 @@ var TransactionsModule = class {
|
|
|
550
582
|
}
|
|
551
583
|
/**
|
|
552
584
|
* Create an onramp transaction (fiat to crypto)
|
|
553
|
-
*
|
|
585
|
+
*
|
|
554
586
|
* @example
|
|
555
587
|
* ```typescript
|
|
556
588
|
* const transaction = await diviswap.transactions.onramp({
|
|
@@ -561,7 +593,7 @@ var TransactionsModule = class {
|
|
|
561
593
|
* chain: 'ethereum'
|
|
562
594
|
* });
|
|
563
595
|
* ```
|
|
564
|
-
*
|
|
596
|
+
*
|
|
565
597
|
* @throws {Error} If user is not KYC approved
|
|
566
598
|
*/
|
|
567
599
|
async onramp(_data) {
|
|
@@ -603,9 +635,7 @@ var TransactionsModule = class {
|
|
|
603
635
|
*/
|
|
604
636
|
async offramp(data) {
|
|
605
637
|
if (!data.txHash || data.txHash.trim() === "") {
|
|
606
|
-
throw new Error(
|
|
607
|
-
"txHash is required for offramp transactions."
|
|
608
|
-
);
|
|
638
|
+
throw new Error("txHash is required for offramp transactions.");
|
|
609
639
|
}
|
|
610
640
|
const payload = {
|
|
611
641
|
payee_id: data.payeeId,
|
|
@@ -654,9 +684,7 @@ var TransactionsModule = class {
|
|
|
654
684
|
*/
|
|
655
685
|
async offrampTest(data) {
|
|
656
686
|
if (!data.txHash || data.txHash.trim() === "") {
|
|
657
|
-
throw new Error(
|
|
658
|
-
"txHash is required for offramp transactions."
|
|
659
|
-
);
|
|
687
|
+
throw new Error("txHash is required for offramp transactions.");
|
|
660
688
|
}
|
|
661
689
|
const payload = {
|
|
662
690
|
payee_id: data.payeeId,
|
|
@@ -678,12 +706,12 @@ var TransactionsModule = class {
|
|
|
678
706
|
}
|
|
679
707
|
/**
|
|
680
708
|
* List transactions with optional filters
|
|
681
|
-
*
|
|
709
|
+
*
|
|
682
710
|
* @example
|
|
683
711
|
* ```typescript
|
|
684
712
|
* // Get all transactions
|
|
685
713
|
* const allTransactions = await diviswap.transactions.list();
|
|
686
|
-
*
|
|
714
|
+
*
|
|
687
715
|
* // Get only completed onramp transactions
|
|
688
716
|
* const completedOnramps = await diviswap.transactions.list({
|
|
689
717
|
* type: 'onramp',
|
|
@@ -721,7 +749,7 @@ var TransactionsModule = class {
|
|
|
721
749
|
}
|
|
722
750
|
/**
|
|
723
751
|
* Get a specific transaction by ID
|
|
724
|
-
*
|
|
752
|
+
*
|
|
725
753
|
* @example
|
|
726
754
|
* ```typescript
|
|
727
755
|
* const transaction = await diviswap.transactions.get('transaction-id');
|
|
@@ -738,7 +766,7 @@ var TransactionsModule = class {
|
|
|
738
766
|
}
|
|
739
767
|
/**
|
|
740
768
|
* Get fee estimate for a transaction
|
|
741
|
-
*
|
|
769
|
+
*
|
|
742
770
|
* @example
|
|
743
771
|
* ```typescript
|
|
744
772
|
* const estimate = await diviswap.transactions.estimateFees({
|
|
@@ -754,7 +782,7 @@ var TransactionsModule = class {
|
|
|
754
782
|
}
|
|
755
783
|
/**
|
|
756
784
|
* Get recent transactions (convenience method)
|
|
757
|
-
*
|
|
785
|
+
*
|
|
758
786
|
* @example
|
|
759
787
|
* ```typescript
|
|
760
788
|
* const recentTransactions = await diviswap.transactions.getRecent(10);
|
|
@@ -765,7 +793,7 @@ var TransactionsModule = class {
|
|
|
765
793
|
}
|
|
766
794
|
/**
|
|
767
795
|
* Get transaction statistics
|
|
768
|
-
*
|
|
796
|
+
*
|
|
769
797
|
* @example
|
|
770
798
|
* ```typescript
|
|
771
799
|
* const stats = await diviswap.transactions.getStats();
|
|
@@ -774,21 +802,24 @@ var TransactionsModule = class {
|
|
|
774
802
|
*/
|
|
775
803
|
async getStats() {
|
|
776
804
|
const transactions = await this.list();
|
|
777
|
-
const stats = transactions.reduce(
|
|
778
|
-
acc
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
805
|
+
const stats = transactions.reduce(
|
|
806
|
+
(acc, tx) => {
|
|
807
|
+
acc.totalTransactions++;
|
|
808
|
+
acc.totalVolume += tx.amount || 0;
|
|
809
|
+
if (tx.status === "pending" || tx.status === "processing") {
|
|
810
|
+
acc.pendingTransactions++;
|
|
811
|
+
} else if (tx.status === "completed") {
|
|
812
|
+
acc.completedTransactions++;
|
|
813
|
+
}
|
|
814
|
+
return acc;
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
totalTransactions: 0,
|
|
818
|
+
totalVolume: 0,
|
|
819
|
+
pendingTransactions: 0,
|
|
820
|
+
completedTransactions: 0
|
|
784
821
|
}
|
|
785
|
-
|
|
786
|
-
}, {
|
|
787
|
-
totalTransactions: 0,
|
|
788
|
-
totalVolume: 0,
|
|
789
|
-
pendingTransactions: 0,
|
|
790
|
-
completedTransactions: 0
|
|
791
|
-
});
|
|
822
|
+
);
|
|
792
823
|
return stats;
|
|
793
824
|
}
|
|
794
825
|
/**
|
|
@@ -810,11 +841,11 @@ var KycModule = class {
|
|
|
810
841
|
}
|
|
811
842
|
/**
|
|
812
843
|
* Get current compliance status including KYC and KYB
|
|
813
|
-
*
|
|
844
|
+
*
|
|
814
845
|
* @example
|
|
815
846
|
* ```typescript
|
|
816
847
|
* const status = await diviswap.kyc.getComplianceStatus();
|
|
817
|
-
*
|
|
848
|
+
*
|
|
818
849
|
* if (!status.canTransact) {
|
|
819
850
|
* if (status.nextStep === 'COMPLETE_KYC') {
|
|
820
851
|
* // Redirect to KYC flow
|
|
@@ -839,19 +870,21 @@ var KycModule = class {
|
|
|
839
870
|
kycMetadata: kycData?.metadata
|
|
840
871
|
};
|
|
841
872
|
} catch (error) {
|
|
842
|
-
throw new Error(
|
|
873
|
+
throw new Error(
|
|
874
|
+
`Failed to get compliance status: ${error.message}`
|
|
875
|
+
);
|
|
843
876
|
}
|
|
844
877
|
}
|
|
845
878
|
/**
|
|
846
879
|
* Start KYC verification session (opens Sumsub widget)
|
|
847
|
-
*
|
|
880
|
+
*
|
|
848
881
|
* @example
|
|
849
882
|
* ```typescript
|
|
850
883
|
* const session = await diviswap.kyc.startKycSession();
|
|
851
|
-
*
|
|
884
|
+
*
|
|
852
885
|
* // Redirect user to session URL
|
|
853
886
|
* window.location.href = session.sessionUrl;
|
|
854
|
-
*
|
|
887
|
+
*
|
|
855
888
|
* // Or embed in iframe
|
|
856
889
|
* const iframe = document.createElement('iframe');
|
|
857
890
|
* iframe.src = session.sessionUrl;
|
|
@@ -862,7 +895,7 @@ var KycModule = class {
|
|
|
862
895
|
}
|
|
863
896
|
/**
|
|
864
897
|
* Submit KYC documents programmatically
|
|
865
|
-
*
|
|
898
|
+
*
|
|
866
899
|
* @example
|
|
867
900
|
* ```typescript
|
|
868
901
|
* // Convert file to base64
|
|
@@ -872,10 +905,10 @@ var KycModule = class {
|
|
|
872
905
|
* reader.onload = () => resolve(reader.result as string);
|
|
873
906
|
* reader.onerror = reject;
|
|
874
907
|
* });
|
|
875
|
-
*
|
|
908
|
+
*
|
|
876
909
|
* const frontImage = await toBase64(frontFile);
|
|
877
910
|
* const backImage = await toBase64(backFile);
|
|
878
|
-
*
|
|
911
|
+
*
|
|
879
912
|
* await diviswap.kyc.submitDocuments({
|
|
880
913
|
* type: 'DRIVERS_LICENSE',
|
|
881
914
|
* frontImage,
|
|
@@ -888,13 +921,15 @@ var KycModule = class {
|
|
|
888
921
|
throw new ValidationError("Front image is required");
|
|
889
922
|
}
|
|
890
923
|
if (["DRIVERS_LICENSE", "ID_CARD"].includes(documents.type) && !documents.backImage) {
|
|
891
|
-
throw new ValidationError(
|
|
924
|
+
throw new ValidationError(
|
|
925
|
+
`Back image is required for ${documents.type}`
|
|
926
|
+
);
|
|
892
927
|
}
|
|
893
928
|
throw new Error("KYC documents endpoint not available in v1 API yet");
|
|
894
929
|
}
|
|
895
930
|
/**
|
|
896
931
|
* Submit personal information for KYC
|
|
897
|
-
*
|
|
932
|
+
*
|
|
898
933
|
* @example
|
|
899
934
|
* ```typescript
|
|
900
935
|
* await diviswap.kyc.submitPersonalInfo({
|
|
@@ -923,18 +958,25 @@ var KycModule = class {
|
|
|
923
958
|
throw new ValidationError("Complete address is required");
|
|
924
959
|
}
|
|
925
960
|
try {
|
|
926
|
-
const response = await this.client.post(
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
961
|
+
const response = await this.client.post(
|
|
962
|
+
"/api/v1/kyc/personal-info",
|
|
963
|
+
{
|
|
964
|
+
first_name: info.firstName,
|
|
965
|
+
last_name: info.lastName,
|
|
966
|
+
dob: info.dateOfBirth,
|
|
967
|
+
country: info.address.country,
|
|
968
|
+
...info.phone && { phone: info.phone },
|
|
969
|
+
...info.address.street && {
|
|
970
|
+
address: info.address.street
|
|
971
|
+
},
|
|
972
|
+
...info.address.city && { city: info.address.city },
|
|
973
|
+
...info.address.state && { state: info.address.state },
|
|
974
|
+
...info.address.postalCode && {
|
|
975
|
+
postal_code: info.address.postalCode
|
|
976
|
+
},
|
|
977
|
+
...info.ssn && { ssn: info.ssn }
|
|
978
|
+
}
|
|
979
|
+
);
|
|
938
980
|
return response;
|
|
939
981
|
} catch (error) {
|
|
940
982
|
throw new Error(`Failed to submit KYC info: ${error.message}`);
|
|
@@ -942,7 +984,7 @@ var KycModule = class {
|
|
|
942
984
|
}
|
|
943
985
|
/**
|
|
944
986
|
* Check if user can transact (convenience method)
|
|
945
|
-
*
|
|
987
|
+
*
|
|
946
988
|
* @example
|
|
947
989
|
* ```typescript
|
|
948
990
|
* const canTransact = await diviswap.kyc.canTransact();
|
|
@@ -957,7 +999,7 @@ var KycModule = class {
|
|
|
957
999
|
}
|
|
958
1000
|
/**
|
|
959
1001
|
* Check if KYC is approved
|
|
960
|
-
*
|
|
1002
|
+
*
|
|
961
1003
|
* @example
|
|
962
1004
|
* ```typescript
|
|
963
1005
|
* const isApproved = await diviswap.kyc.isKycApproved();
|
|
@@ -969,7 +1011,7 @@ var KycModule = class {
|
|
|
969
1011
|
}
|
|
970
1012
|
/**
|
|
971
1013
|
* Check if KYB is approved (for business accounts)
|
|
972
|
-
*
|
|
1014
|
+
*
|
|
973
1015
|
* @example
|
|
974
1016
|
* ```typescript
|
|
975
1017
|
* const isBusinessApproved = await diviswap.kyc.isKybApproved();
|
|
@@ -981,7 +1023,7 @@ var KycModule = class {
|
|
|
981
1023
|
}
|
|
982
1024
|
/**
|
|
983
1025
|
* Get rejection reasons if KYC/KYB was rejected
|
|
984
|
-
*
|
|
1026
|
+
*
|
|
985
1027
|
* @example
|
|
986
1028
|
* ```typescript
|
|
987
1029
|
* const reasons = await diviswap.kyc.getRejectionReasons();
|
|
@@ -1000,13 +1042,13 @@ var KycModule = class {
|
|
|
1000
1042
|
}
|
|
1001
1043
|
/**
|
|
1002
1044
|
* Wait for KYC approval (polling)
|
|
1003
|
-
*
|
|
1045
|
+
*
|
|
1004
1046
|
* @example
|
|
1005
1047
|
* ```typescript
|
|
1006
1048
|
* // Start KYC session
|
|
1007
1049
|
* const session = await diviswap.kyc.startKycSession();
|
|
1008
1050
|
* window.open(session.sessionUrl);
|
|
1009
|
-
*
|
|
1051
|
+
*
|
|
1010
1052
|
* // Wait for approval (polls every 5 seconds for up to 10 minutes)
|
|
1011
1053
|
* try {
|
|
1012
1054
|
* await diviswap.kyc.waitForApproval();
|
|
@@ -1026,7 +1068,9 @@ var KycModule = class {
|
|
|
1026
1068
|
return status;
|
|
1027
1069
|
}
|
|
1028
1070
|
if (status.kycStatus === "REJECTED") {
|
|
1029
|
-
throw new Error(
|
|
1071
|
+
throw new Error(
|
|
1072
|
+
`KYC rejected: ${status.kycMetadata?.rejectLabels?.join(", ") || "Unknown reason"}`
|
|
1073
|
+
);
|
|
1030
1074
|
}
|
|
1031
1075
|
attempts++;
|
|
1032
1076
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
@@ -1057,9 +1101,12 @@ var FeesModule = class {
|
|
|
1057
1101
|
*/
|
|
1058
1102
|
async setFee(data) {
|
|
1059
1103
|
if (data.userId) {
|
|
1060
|
-
await this.client.put(
|
|
1061
|
-
|
|
1062
|
-
|
|
1104
|
+
await this.client.put(
|
|
1105
|
+
`/api/v1/partner/users/${data.userId}/fee`,
|
|
1106
|
+
{
|
|
1107
|
+
percentage: data.percentage
|
|
1108
|
+
}
|
|
1109
|
+
);
|
|
1063
1110
|
return {
|
|
1064
1111
|
integratorFeePercentage: data.percentage,
|
|
1065
1112
|
baseFeePercentage: 1.5,
|
|
@@ -1111,10 +1158,13 @@ var FeesModule = class {
|
|
|
1111
1158
|
* ```
|
|
1112
1159
|
*/
|
|
1113
1160
|
async calculateFees(params) {
|
|
1114
|
-
const response = await this.client.post(
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1161
|
+
const response = await this.client.post(
|
|
1162
|
+
"/api/v1/partner/fees/calculate",
|
|
1163
|
+
{
|
|
1164
|
+
amount: params.amount,
|
|
1165
|
+
user_id: params.userId
|
|
1166
|
+
}
|
|
1167
|
+
);
|
|
1118
1168
|
return {
|
|
1119
1169
|
amount: response.amount,
|
|
1120
1170
|
baseFee: response.base_fee,
|
|
@@ -1160,7 +1210,7 @@ var AddressesModule = class {
|
|
|
1160
1210
|
}
|
|
1161
1211
|
/**
|
|
1162
1212
|
* Get all addresses for the authenticated user
|
|
1163
|
-
*
|
|
1213
|
+
*
|
|
1164
1214
|
* @example
|
|
1165
1215
|
* ```typescript
|
|
1166
1216
|
* const addresses = await diviswap.addresses.list();
|
|
@@ -1173,7 +1223,7 @@ var AddressesModule = class {
|
|
|
1173
1223
|
}
|
|
1174
1224
|
/**
|
|
1175
1225
|
* Create a new crypto address for the user
|
|
1176
|
-
*
|
|
1226
|
+
*
|
|
1177
1227
|
* @example
|
|
1178
1228
|
* ```typescript
|
|
1179
1229
|
* const address = await diviswap.addresses.create({
|
|
@@ -1194,7 +1244,7 @@ var AddressesModule = class {
|
|
|
1194
1244
|
}
|
|
1195
1245
|
/**
|
|
1196
1246
|
* Set a specific address as the default for its chain
|
|
1197
|
-
*
|
|
1247
|
+
*
|
|
1198
1248
|
* @example
|
|
1199
1249
|
* ```typescript
|
|
1200
1250
|
* await diviswap.addresses.setDefault({
|
|
@@ -1208,7 +1258,7 @@ var AddressesModule = class {
|
|
|
1208
1258
|
}
|
|
1209
1259
|
/**
|
|
1210
1260
|
* Delete a crypto address
|
|
1211
|
-
*
|
|
1261
|
+
*
|
|
1212
1262
|
* @example
|
|
1213
1263
|
* ```typescript
|
|
1214
1264
|
* await diviswap.addresses.delete({
|
|
@@ -1222,7 +1272,7 @@ var AddressesModule = class {
|
|
|
1222
1272
|
}
|
|
1223
1273
|
/**
|
|
1224
1274
|
* Get addresses for a specific chain
|
|
1225
|
-
*
|
|
1275
|
+
*
|
|
1226
1276
|
* @example
|
|
1227
1277
|
* ```typescript
|
|
1228
1278
|
* const ethAddresses = await diviswap.addresses.getByChain(1);
|
|
@@ -1236,7 +1286,7 @@ var AddressesModule = class {
|
|
|
1236
1286
|
}
|
|
1237
1287
|
/**
|
|
1238
1288
|
* Get the default address for a specific chain
|
|
1239
|
-
*
|
|
1289
|
+
*
|
|
1240
1290
|
* @example
|
|
1241
1291
|
* ```typescript
|
|
1242
1292
|
* const defaultEthAddress = await diviswap.addresses.getDefault(1);
|
|
@@ -1246,11 +1296,13 @@ var AddressesModule = class {
|
|
|
1246
1296
|
async getDefault(chainIdOrName) {
|
|
1247
1297
|
const chainId = typeof chainIdOrName === "string" ? CHAIN_IDS[chainIdOrName] : chainIdOrName;
|
|
1248
1298
|
const addresses = await this.list();
|
|
1249
|
-
return addresses.find(
|
|
1299
|
+
return addresses.find(
|
|
1300
|
+
(addr) => addr.chain_id === chainId && addr.is_default
|
|
1301
|
+
) || null;
|
|
1250
1302
|
}
|
|
1251
1303
|
/**
|
|
1252
1304
|
* Check if an address exists for the user
|
|
1253
|
-
*
|
|
1305
|
+
*
|
|
1254
1306
|
* @example
|
|
1255
1307
|
* ```typescript
|
|
1256
1308
|
* const exists = await diviswap.addresses.exists({
|
|
@@ -1268,7 +1320,7 @@ var AddressesModule = class {
|
|
|
1268
1320
|
/**
|
|
1269
1321
|
* Automatically track a wallet connection
|
|
1270
1322
|
* This is the main method for automatic address tracking
|
|
1271
|
-
*
|
|
1323
|
+
*
|
|
1272
1324
|
* @example
|
|
1273
1325
|
* ```typescript
|
|
1274
1326
|
* // When user connects wallet
|
|
@@ -1304,7 +1356,7 @@ var AddressesModule = class {
|
|
|
1304
1356
|
}
|
|
1305
1357
|
/**
|
|
1306
1358
|
* Auto-track multiple wallet connections (useful for multi-chain wallets)
|
|
1307
|
-
*
|
|
1359
|
+
*
|
|
1308
1360
|
* @example
|
|
1309
1361
|
* ```typescript
|
|
1310
1362
|
* // When user connects a multi-chain wallet
|
|
@@ -1322,7 +1374,10 @@ var AddressesModule = class {
|
|
|
1322
1374
|
const address = await this.trackWallet(connection);
|
|
1323
1375
|
results.push(address);
|
|
1324
1376
|
} catch (error) {
|
|
1325
|
-
console.error(
|
|
1377
|
+
console.error(
|
|
1378
|
+
`Failed to track wallet for chain ${connection.chainId}:`,
|
|
1379
|
+
error
|
|
1380
|
+
);
|
|
1326
1381
|
}
|
|
1327
1382
|
}
|
|
1328
1383
|
return results;
|
|
@@ -1381,10 +1436,13 @@ var WebhooksModule = class {
|
|
|
1381
1436
|
* ```
|
|
1382
1437
|
*/
|
|
1383
1438
|
async setConfigForPartner(partnerId, data) {
|
|
1384
|
-
const response = await this.client.put(
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1439
|
+
const response = await this.client.put(
|
|
1440
|
+
`/api/v1/partners/${partnerId}/webhook`,
|
|
1441
|
+
{
|
|
1442
|
+
webhook_url: data.webhook_url,
|
|
1443
|
+
webhook_secret: data.webhook_secret
|
|
1444
|
+
}
|
|
1445
|
+
);
|
|
1388
1446
|
return response;
|
|
1389
1447
|
}
|
|
1390
1448
|
/**
|
|
@@ -1398,14 +1456,18 @@ var WebhooksModule = class {
|
|
|
1398
1456
|
* ```
|
|
1399
1457
|
*/
|
|
1400
1458
|
async getConfig() {
|
|
1401
|
-
const response = await this.client.get(
|
|
1459
|
+
const response = await this.client.get(
|
|
1460
|
+
"/api/v1/partner/webhook"
|
|
1461
|
+
);
|
|
1402
1462
|
return response;
|
|
1403
1463
|
}
|
|
1404
1464
|
/**
|
|
1405
1465
|
* Get webhook config for a specific partner (user-owned)
|
|
1406
1466
|
*/
|
|
1407
1467
|
async getConfigForPartner(partnerId) {
|
|
1408
|
-
const response = await this.client.get(
|
|
1468
|
+
const response = await this.client.get(
|
|
1469
|
+
`/api/v1/partners/${partnerId}/webhook`
|
|
1470
|
+
);
|
|
1409
1471
|
return response;
|
|
1410
1472
|
}
|
|
1411
1473
|
/**
|
|
@@ -1582,7 +1644,10 @@ var TokenManager = class {
|
|
|
1582
1644
|
this.refreshPromise = refreshCallback(refreshToken);
|
|
1583
1645
|
try {
|
|
1584
1646
|
const newTokenData = await this.refreshPromise;
|
|
1585
|
-
this.setTokens(
|
|
1647
|
+
this.setTokens(
|
|
1648
|
+
newTokenData.accessToken,
|
|
1649
|
+
newTokenData.refreshToken || refreshToken
|
|
1650
|
+
);
|
|
1586
1651
|
return newTokenData.accessToken;
|
|
1587
1652
|
} finally {
|
|
1588
1653
|
this.refreshPromise = null;
|
|
@@ -1626,7 +1691,7 @@ var PartnerAuth = class {
|
|
|
1626
1691
|
].join("\n");
|
|
1627
1692
|
const signature = crypto.createHmac("sha256", this.credentials.secretKey).update(canonical).digest("base64");
|
|
1628
1693
|
const headers = {
|
|
1629
|
-
|
|
1694
|
+
Authorization: `HMAC ${this.credentials.keyId}:${signature}:${timestamp}:${nonce}`,
|
|
1630
1695
|
"X-Client-Id": this.credentials.keyId
|
|
1631
1696
|
};
|
|
1632
1697
|
if (this.credentials.customerId) {
|
|
@@ -1648,7 +1713,7 @@ var PartnerAuth = class {
|
|
|
1648
1713
|
*/
|
|
1649
1714
|
generateJWT(options = {}) {
|
|
1650
1715
|
const {
|
|
1651
|
-
audience = "api.
|
|
1716
|
+
audience = "api.diviswap.com",
|
|
1652
1717
|
expiresIn = 300,
|
|
1653
1718
|
// 5 minutes max
|
|
1654
1719
|
scopes = []
|
|
@@ -1663,13 +1728,21 @@ var PartnerAuth = class {
|
|
|
1663
1728
|
// Expiration (max 5 minutes)
|
|
1664
1729
|
iat: now,
|
|
1665
1730
|
// Issued at
|
|
1666
|
-
...this.credentials.customerId && {
|
|
1667
|
-
|
|
1731
|
+
...this.credentials.customerId && {
|
|
1732
|
+
sub: this.credentials.customerId
|
|
1733
|
+
},
|
|
1734
|
+
...this.credentials.customerEmail && {
|
|
1735
|
+
email: this.credentials.customerEmail
|
|
1736
|
+
},
|
|
1668
1737
|
...scopes.length > 0 && { scope: scopes }
|
|
1669
1738
|
};
|
|
1670
1739
|
const header = { alg: "HS256", typ: "JWT" };
|
|
1671
|
-
const encodedHeader = Buffer.from(JSON.stringify(header)).toString(
|
|
1672
|
-
|
|
1740
|
+
const encodedHeader = Buffer.from(JSON.stringify(header)).toString(
|
|
1741
|
+
"base64url"
|
|
1742
|
+
);
|
|
1743
|
+
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString(
|
|
1744
|
+
"base64url"
|
|
1745
|
+
);
|
|
1673
1746
|
const signature = crypto.createHmac("sha256", this.credentials.secretKey).update(`${encodedHeader}.${encodedPayload}`).digest("base64url");
|
|
1674
1747
|
return `${encodedHeader}.${encodedPayload}.${signature}`;
|
|
1675
1748
|
}
|
|
@@ -1708,51 +1781,63 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1708
1781
|
*/
|
|
1709
1782
|
static fromUserConfig(config, useLocalStorage = true) {
|
|
1710
1783
|
const baseUrl = config.apiUrl || this.getDefaultApiUrl(config.environment || "production");
|
|
1711
|
-
return new _UnifiedApiClient(
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1784
|
+
return new _UnifiedApiClient(
|
|
1785
|
+
{
|
|
1786
|
+
baseUrl,
|
|
1787
|
+
timeout: config.timeout || 3e4,
|
|
1788
|
+
debug: config.debug || false,
|
|
1789
|
+
mode: "user",
|
|
1790
|
+
apiKey: config.apiKey,
|
|
1791
|
+
clientId: config.clientId
|
|
1792
|
+
},
|
|
1793
|
+
useLocalStorage
|
|
1794
|
+
);
|
|
1719
1795
|
}
|
|
1720
1796
|
/**
|
|
1721
1797
|
* Create client from partner config
|
|
1722
1798
|
*/
|
|
1723
1799
|
static fromPartnerConfig(config, useLocalStorage = true) {
|
|
1724
1800
|
const baseUrl = config.apiUrl || this.getDefaultApiUrl(config.environment || "production");
|
|
1725
|
-
return new _UnifiedApiClient(
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1801
|
+
return new _UnifiedApiClient(
|
|
1802
|
+
{
|
|
1803
|
+
baseUrl,
|
|
1804
|
+
timeout: config.timeout || 3e4,
|
|
1805
|
+
debug: config.debug || false,
|
|
1806
|
+
mode: "partner",
|
|
1807
|
+
keyId: config.keyId,
|
|
1808
|
+
secretKey: config.secretKey,
|
|
1809
|
+
authMethod: config.authMethod || "hmac",
|
|
1810
|
+
customerId: config.customerId,
|
|
1811
|
+
customerEmail: config.customerEmail
|
|
1812
|
+
},
|
|
1813
|
+
useLocalStorage
|
|
1814
|
+
);
|
|
1736
1815
|
}
|
|
1737
1816
|
/**
|
|
1738
1817
|
* Create client from any config (auto-detect mode)
|
|
1739
1818
|
*/
|
|
1740
1819
|
static fromConfig(config, useLocalStorage = true) {
|
|
1741
1820
|
if ("mode" in config && config.mode === "partner" || "keyId" in config && "secretKey" in config) {
|
|
1742
|
-
return this.fromPartnerConfig(
|
|
1821
|
+
return this.fromPartnerConfig(
|
|
1822
|
+
config,
|
|
1823
|
+
useLocalStorage
|
|
1824
|
+
);
|
|
1743
1825
|
} else {
|
|
1744
|
-
return this.fromUserConfig(
|
|
1826
|
+
return this.fromUserConfig(
|
|
1827
|
+
config,
|
|
1828
|
+
useLocalStorage
|
|
1829
|
+
);
|
|
1745
1830
|
}
|
|
1746
1831
|
}
|
|
1747
1832
|
static getDefaultApiUrl(environment) {
|
|
1748
1833
|
switch (environment) {
|
|
1749
1834
|
case "production":
|
|
1750
1835
|
case "sandbox":
|
|
1751
|
-
return "https://api.
|
|
1836
|
+
return "https://api.diviswap.com";
|
|
1752
1837
|
case "development":
|
|
1753
|
-
return "https://dev-api.
|
|
1838
|
+
return "https://dev-api.diviswap.com";
|
|
1754
1839
|
default:
|
|
1755
|
-
return "https://api.
|
|
1840
|
+
return "https://api.diviswap.com";
|
|
1756
1841
|
}
|
|
1757
1842
|
}
|
|
1758
1843
|
/**
|
|
@@ -1818,7 +1903,14 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1818
1903
|
* Make authenticated API request
|
|
1819
1904
|
*/
|
|
1820
1905
|
async request(options) {
|
|
1821
|
-
const {
|
|
1906
|
+
const {
|
|
1907
|
+
method,
|
|
1908
|
+
path,
|
|
1909
|
+
body,
|
|
1910
|
+
headers = {},
|
|
1911
|
+
useApiKey = false,
|
|
1912
|
+
skipAuth = false
|
|
1913
|
+
} = options;
|
|
1822
1914
|
const url = `${this.config.baseUrl}${path}`;
|
|
1823
1915
|
const requestHeaders = {
|
|
1824
1916
|
"Content-Type": "application/json",
|
|
@@ -1834,7 +1926,10 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1834
1926
|
}
|
|
1835
1927
|
try {
|
|
1836
1928
|
const controller = new AbortController();
|
|
1837
|
-
const timeoutId = setTimeout(
|
|
1929
|
+
const timeoutId = setTimeout(
|
|
1930
|
+
() => controller.abort(),
|
|
1931
|
+
this.config.timeout
|
|
1932
|
+
);
|
|
1838
1933
|
if (this.config.debug) {
|
|
1839
1934
|
console.log(`[Diviswap SDK] ${method} ${url}`);
|
|
1840
1935
|
}
|
|
@@ -1853,7 +1948,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1853
1948
|
responseData = responseText;
|
|
1854
1949
|
}
|
|
1855
1950
|
if (this.config.debug) {
|
|
1856
|
-
console.log(
|
|
1951
|
+
console.log(
|
|
1952
|
+
`[Diviswap SDK] Response ${response.status}: ${responseText.substring(0, 500)}`
|
|
1953
|
+
);
|
|
1857
1954
|
}
|
|
1858
1955
|
if (!response.ok) {
|
|
1859
1956
|
await this.handleErrorResponse(response, responseData);
|
|
@@ -1874,7 +1971,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1874
1971
|
*/
|
|
1875
1972
|
async addPartnerAuth(method, path, body, headers) {
|
|
1876
1973
|
if (!this.partnerAuth) {
|
|
1877
|
-
throw new AuthenticationError(
|
|
1974
|
+
throw new AuthenticationError(
|
|
1975
|
+
"Partner authentication not configured"
|
|
1976
|
+
);
|
|
1878
1977
|
}
|
|
1879
1978
|
const bodyString = body ? JSON.stringify(body) : "";
|
|
1880
1979
|
const urlParts = path.split("?");
|
|
@@ -1882,7 +1981,7 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1882
1981
|
const queryString = urlParts.length > 1 ? urlParts[1] : "";
|
|
1883
1982
|
if (this.config.authMethod === "jwt") {
|
|
1884
1983
|
const jwt = this.partnerAuth.generateJWT({
|
|
1885
|
-
audience: "api.
|
|
1984
|
+
audience: "api.diviswap.com",
|
|
1886
1985
|
expiresIn: 300
|
|
1887
1986
|
});
|
|
1888
1987
|
headers["Authorization"] = `Bearer ${jwt}`;
|
|
@@ -1907,7 +2006,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1907
2006
|
headers["X-TIMESTAMP"] = Math.floor(Date.now() / 1e3).toString();
|
|
1908
2007
|
headers["X-API-Key"] = this.config.apiKey;
|
|
1909
2008
|
if (!useApiKey) {
|
|
1910
|
-
const accessToken = await this.tokenManager.getValidAccessToken(
|
|
2009
|
+
const accessToken = await this.tokenManager.getValidAccessToken(
|
|
2010
|
+
this.refreshCallback
|
|
2011
|
+
);
|
|
1911
2012
|
if (accessToken) {
|
|
1912
2013
|
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
1913
2014
|
}
|
|
@@ -1965,7 +2066,10 @@ var _Diviswap = class _Diviswap {
|
|
|
1965
2066
|
this.apiClient = UnifiedApiClient.fromConfig(config, useLocalStorage);
|
|
1966
2067
|
this.auth = new AuthModule(this.apiClient);
|
|
1967
2068
|
this.payees = new PayeesModule(this.apiClient);
|
|
1968
|
-
this.transactions = new TransactionsModule(
|
|
2069
|
+
this.transactions = new TransactionsModule(
|
|
2070
|
+
this.apiClient,
|
|
2071
|
+
config.environment || "sandbox"
|
|
2072
|
+
);
|
|
1969
2073
|
this.kyc = new KycModule(this.apiClient);
|
|
1970
2074
|
this.fees = new FeesModule(this.apiClient);
|
|
1971
2075
|
this.addresses = new AddressesModule(this.apiClient);
|
|
@@ -1997,7 +2101,9 @@ var _Diviswap = class _Diviswap {
|
|
|
1997
2101
|
*/
|
|
1998
2102
|
static getInstance() {
|
|
1999
2103
|
if (!_Diviswap.instance) {
|
|
2000
|
-
throw new ConfigurationError(
|
|
2104
|
+
throw new ConfigurationError(
|
|
2105
|
+
"Diviswap SDK not initialized. Call Diviswap.init() first."
|
|
2106
|
+
);
|
|
2001
2107
|
}
|
|
2002
2108
|
return _Diviswap.instance;
|
|
2003
2109
|
}
|
|
@@ -2012,7 +2118,9 @@ var _Diviswap = class _Diviswap {
|
|
|
2012
2118
|
* @deprecated Configuration updates require re-initialization. Call Diviswap.reset() then Diviswap.init() with new config.
|
|
2013
2119
|
*/
|
|
2014
2120
|
updateConfig(_config) {
|
|
2015
|
-
throw new ConfigurationError(
|
|
2121
|
+
throw new ConfigurationError(
|
|
2122
|
+
"Configuration updates require re-initialization. Call Diviswap.reset() then Diviswap.init() with new config."
|
|
2123
|
+
);
|
|
2016
2124
|
}
|
|
2017
2125
|
/**
|
|
2018
2126
|
* Get current configuration (excluding sensitive data)
|
|
@@ -2034,7 +2142,7 @@ var _Diviswap = class _Diviswap {
|
|
|
2034
2142
|
* const token = await diviswap.getAccessToken();
|
|
2035
2143
|
* if (token) {
|
|
2036
2144
|
* // Use token for custom API calls
|
|
2037
|
-
* fetch('https://api.
|
|
2145
|
+
* fetch('https://api.diviswap.com/custom-endpoint', {
|
|
2038
2146
|
* headers: { 'Authorization': `Bearer ${token}` }
|
|
2039
2147
|
* });
|
|
2040
2148
|
* }
|
|
@@ -2085,25 +2193,39 @@ var _Diviswap = class _Diviswap {
|
|
|
2085
2193
|
if (isPartnerMode) {
|
|
2086
2194
|
const partnerConfig = config;
|
|
2087
2195
|
if (!partnerConfig.keyId) {
|
|
2088
|
-
throw new ConfigurationError(
|
|
2196
|
+
throw new ConfigurationError(
|
|
2197
|
+
"Partner keyId is required for partner authentication"
|
|
2198
|
+
);
|
|
2089
2199
|
}
|
|
2090
2200
|
if (!partnerConfig.secretKey) {
|
|
2091
|
-
throw new ConfigurationError(
|
|
2201
|
+
throw new ConfigurationError(
|
|
2202
|
+
"Partner secretKey is required for partner authentication"
|
|
2203
|
+
);
|
|
2092
2204
|
}
|
|
2093
2205
|
if (partnerConfig.authMethod && !["hmac", "jwt"].includes(partnerConfig.authMethod)) {
|
|
2094
|
-
throw new ConfigurationError(
|
|
2206
|
+
throw new ConfigurationError(
|
|
2207
|
+
'Invalid authMethod. Must be either "hmac" or "jwt"'
|
|
2208
|
+
);
|
|
2095
2209
|
}
|
|
2096
2210
|
} else {
|
|
2097
2211
|
const userConfig = config;
|
|
2098
2212
|
if (!userConfig.apiKey) {
|
|
2099
|
-
throw new ConfigurationError(
|
|
2213
|
+
throw new ConfigurationError(
|
|
2214
|
+
"API Key is required for user authentication"
|
|
2215
|
+
);
|
|
2100
2216
|
}
|
|
2101
2217
|
if (!userConfig.clientId) {
|
|
2102
|
-
throw new ConfigurationError(
|
|
2218
|
+
throw new ConfigurationError(
|
|
2219
|
+
"Client ID is required for user authentication"
|
|
2220
|
+
);
|
|
2103
2221
|
}
|
|
2104
2222
|
}
|
|
2105
|
-
if (config.environment && !["production", "sandbox", "development"].includes(
|
|
2106
|
-
|
|
2223
|
+
if (config.environment && !["production", "sandbox", "development"].includes(
|
|
2224
|
+
config.environment
|
|
2225
|
+
)) {
|
|
2226
|
+
throw new ConfigurationError(
|
|
2227
|
+
"Invalid environment. Must be one of: production, sandbox, development"
|
|
2228
|
+
);
|
|
2107
2229
|
}
|
|
2108
2230
|
}
|
|
2109
2231
|
};
|
|
@@ -2278,7 +2400,9 @@ var _WalletTracker = class _WalletTracker {
|
|
|
2278
2400
|
* Get chain name from chain ID
|
|
2279
2401
|
*/
|
|
2280
2402
|
getChainName(chainId) {
|
|
2281
|
-
const builtInChain = Object.entries(CHAIN_IDS).find(
|
|
2403
|
+
const builtInChain = Object.entries(CHAIN_IDS).find(
|
|
2404
|
+
([_, id]) => id === chainId
|
|
2405
|
+
)?.[0];
|
|
2282
2406
|
if (builtInChain) return builtInChain;
|
|
2283
2407
|
return this.config.customChains?.[chainId];
|
|
2284
2408
|
}
|