@diviswap/sdk 1.8.0 → 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.js
CHANGED
|
@@ -58,7 +58,7 @@ var AuthModule = class {
|
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* Register a new user
|
|
61
|
-
*
|
|
61
|
+
*
|
|
62
62
|
* @example
|
|
63
63
|
* ```typescript
|
|
64
64
|
* const { user, accessToken } = await diviswap.auth.register({
|
|
@@ -105,16 +105,22 @@ var AuthModule = class {
|
|
|
105
105
|
const authResponse = {
|
|
106
106
|
accessToken: response.access_token || response.accessToken,
|
|
107
107
|
refreshToken: response.refresh_token || response.refreshToken,
|
|
108
|
-
user: response.user || {
|
|
108
|
+
user: response.user || {
|
|
109
|
+
id: response.user_id || response.id,
|
|
110
|
+
email: data.email
|
|
111
|
+
}
|
|
109
112
|
};
|
|
110
113
|
if (authResponse.accessToken) {
|
|
111
|
-
this.client.setTokens(
|
|
114
|
+
this.client.setTokens(
|
|
115
|
+
authResponse.accessToken,
|
|
116
|
+
authResponse.refreshToken
|
|
117
|
+
);
|
|
112
118
|
}
|
|
113
119
|
return authResponse;
|
|
114
120
|
}
|
|
115
121
|
/**
|
|
116
122
|
* Login an existing user
|
|
117
|
-
*
|
|
123
|
+
*
|
|
118
124
|
* @example
|
|
119
125
|
* ```typescript
|
|
120
126
|
* const { user, accessToken } = await diviswap.auth.login({
|
|
@@ -133,22 +139,28 @@ var AuthModule = class {
|
|
|
133
139
|
const authResponse = {
|
|
134
140
|
accessToken: response.access_token || response.accessToken,
|
|
135
141
|
refreshToken: response.refresh_token || response.refreshToken,
|
|
136
|
-
user: response.user || {
|
|
142
|
+
user: response.user || {
|
|
143
|
+
id: response.user_id || response.id,
|
|
144
|
+
email: credentials.email
|
|
145
|
+
}
|
|
137
146
|
};
|
|
138
147
|
if (authResponse.accessToken) {
|
|
139
|
-
this.client.setTokens(
|
|
148
|
+
this.client.setTokens(
|
|
149
|
+
authResponse.accessToken,
|
|
150
|
+
authResponse.refreshToken
|
|
151
|
+
);
|
|
140
152
|
}
|
|
141
153
|
return authResponse;
|
|
142
154
|
}
|
|
143
155
|
/**
|
|
144
156
|
* Get current user profile
|
|
145
|
-
*
|
|
157
|
+
*
|
|
146
158
|
* @example
|
|
147
159
|
* ```typescript
|
|
148
160
|
* const user = await diviswap.auth.getProfile();
|
|
149
161
|
* console.log(user.email, user.kycStatus);
|
|
150
162
|
* ```
|
|
151
|
-
*
|
|
163
|
+
*
|
|
152
164
|
* Note: This endpoint is not yet available in the v1 API
|
|
153
165
|
*/
|
|
154
166
|
async getProfile() {
|
|
@@ -156,7 +168,7 @@ var AuthModule = class {
|
|
|
156
168
|
}
|
|
157
169
|
/**
|
|
158
170
|
* Update user profile
|
|
159
|
-
*
|
|
171
|
+
*
|
|
160
172
|
* @example
|
|
161
173
|
* ```typescript
|
|
162
174
|
* const updatedUser = await diviswap.auth.updateProfile({
|
|
@@ -164,7 +176,7 @@ var AuthModule = class {
|
|
|
164
176
|
* lastName: 'Smith'
|
|
165
177
|
* });
|
|
166
178
|
* ```
|
|
167
|
-
*
|
|
179
|
+
*
|
|
168
180
|
* Note: This endpoint is not yet available in the v1 API
|
|
169
181
|
*/
|
|
170
182
|
async updateProfile(_data) {
|
|
@@ -172,12 +184,12 @@ var AuthModule = class {
|
|
|
172
184
|
}
|
|
173
185
|
/**
|
|
174
186
|
* Request password reset
|
|
175
|
-
*
|
|
187
|
+
*
|
|
176
188
|
* @example
|
|
177
189
|
* ```typescript
|
|
178
190
|
* await diviswap.auth.requestPasswordReset('user@example.com');
|
|
179
191
|
* ```
|
|
180
|
-
*
|
|
192
|
+
*
|
|
181
193
|
* Note: This endpoint is not yet available in the v1 API
|
|
182
194
|
*/
|
|
183
195
|
async requestPasswordReset(_email) {
|
|
@@ -185,12 +197,12 @@ var AuthModule = class {
|
|
|
185
197
|
}
|
|
186
198
|
/**
|
|
187
199
|
* Set new password with reset token
|
|
188
|
-
*
|
|
200
|
+
*
|
|
189
201
|
* @example
|
|
190
202
|
* ```typescript
|
|
191
203
|
* await diviswap.auth.setPassword('reset-token', 'new-secure-password');
|
|
192
204
|
* ```
|
|
193
|
-
*
|
|
205
|
+
*
|
|
194
206
|
* Note: This endpoint is not yet available in the v1 API
|
|
195
207
|
*/
|
|
196
208
|
async setPassword(_token, _password) {
|
|
@@ -198,7 +210,7 @@ var AuthModule = class {
|
|
|
198
210
|
}
|
|
199
211
|
/**
|
|
200
212
|
* Logout current user
|
|
201
|
-
*
|
|
213
|
+
*
|
|
202
214
|
* @example
|
|
203
215
|
* ```typescript
|
|
204
216
|
* await diviswap.auth.logout();
|
|
@@ -212,8 +224,12 @@ var AuthModule = class {
|
|
|
212
224
|
* @deprecated Use diviswap.kyc.getComplianceStatus() instead
|
|
213
225
|
*/
|
|
214
226
|
async getComplianceStatus() {
|
|
215
|
-
console.warn(
|
|
216
|
-
|
|
227
|
+
console.warn(
|
|
228
|
+
"auth.getComplianceStatus() is deprecated. Use kyc.getComplianceStatus() instead."
|
|
229
|
+
);
|
|
230
|
+
throw new Error(
|
|
231
|
+
"Compliance status endpoint not available in v1 API yet"
|
|
232
|
+
);
|
|
217
233
|
}
|
|
218
234
|
/**
|
|
219
235
|
* Check if user is authenticated
|
|
@@ -223,7 +239,7 @@ var AuthModule = class {
|
|
|
223
239
|
}
|
|
224
240
|
/**
|
|
225
241
|
* Refresh access token (internal)
|
|
226
|
-
*
|
|
242
|
+
*
|
|
227
243
|
* Note: This endpoint is not yet available in the v1 API
|
|
228
244
|
*/
|
|
229
245
|
async refreshToken(_refreshToken) {
|
|
@@ -238,7 +254,7 @@ var PayeesModule = class {
|
|
|
238
254
|
}
|
|
239
255
|
/**
|
|
240
256
|
* Create a new payee (bank account)
|
|
241
|
-
*
|
|
257
|
+
*
|
|
242
258
|
* @example
|
|
243
259
|
* ```typescript
|
|
244
260
|
* // Bank account
|
|
@@ -249,7 +265,7 @@ var PayeesModule = class {
|
|
|
249
265
|
* accountType: 'checking',
|
|
250
266
|
* setAsDefault: true
|
|
251
267
|
* });
|
|
252
|
-
*
|
|
268
|
+
*
|
|
253
269
|
* // Debit card
|
|
254
270
|
* const debitCard = await diviswap.payees.create({
|
|
255
271
|
* nickname: 'My Debit Card',
|
|
@@ -269,7 +285,9 @@ var PayeesModule = class {
|
|
|
269
285
|
let response;
|
|
270
286
|
if (data.accountType === "debit_card") {
|
|
271
287
|
if (!data.debitCard) {
|
|
272
|
-
throw new Error(
|
|
288
|
+
throw new Error(
|
|
289
|
+
"Debit card information is required for debit_card account type"
|
|
290
|
+
);
|
|
273
291
|
}
|
|
274
292
|
response = await this.client.post("/api/v1/payees", {
|
|
275
293
|
name: data.nickname,
|
|
@@ -283,7 +301,9 @@ var PayeesModule = class {
|
|
|
283
301
|
});
|
|
284
302
|
} else {
|
|
285
303
|
if (!data.accountNumber || !data.routingNumber) {
|
|
286
|
-
throw new Error(
|
|
304
|
+
throw new Error(
|
|
305
|
+
"Account number and routing number are required for bank accounts"
|
|
306
|
+
);
|
|
287
307
|
}
|
|
288
308
|
response = await this.client.post("/api/v1/payees", {
|
|
289
309
|
name: data.nickname,
|
|
@@ -300,7 +320,7 @@ var PayeesModule = class {
|
|
|
300
320
|
}
|
|
301
321
|
/**
|
|
302
322
|
* List all payees
|
|
303
|
-
*
|
|
323
|
+
*
|
|
304
324
|
* @example
|
|
305
325
|
* ```typescript
|
|
306
326
|
* const payees = await diviswap.payees.list();
|
|
@@ -308,7 +328,9 @@ var PayeesModule = class {
|
|
|
308
328
|
* ```
|
|
309
329
|
*/
|
|
310
330
|
async list() {
|
|
311
|
-
const response = await this.client.get("/api/v1/users/payees", {
|
|
331
|
+
const response = await this.client.get("/api/v1/users/payees", {
|
|
332
|
+
useApiKey: false
|
|
333
|
+
});
|
|
312
334
|
return this.parsePayeesResponse(response);
|
|
313
335
|
}
|
|
314
336
|
parsePayeesResponse(response) {
|
|
@@ -341,7 +363,7 @@ var PayeesModule = class {
|
|
|
341
363
|
}
|
|
342
364
|
/**
|
|
343
365
|
* Get a specific payee
|
|
344
|
-
*
|
|
366
|
+
*
|
|
345
367
|
* @example
|
|
346
368
|
* ```typescript
|
|
347
369
|
* const payee = await diviswap.payees.get('payee-id');
|
|
@@ -357,22 +379,26 @@ var PayeesModule = class {
|
|
|
357
379
|
}
|
|
358
380
|
/**
|
|
359
381
|
* Set a payee as default
|
|
360
|
-
*
|
|
382
|
+
*
|
|
361
383
|
* @example
|
|
362
384
|
* ```typescript
|
|
363
385
|
* await diviswap.payees.setDefault('payee-id');
|
|
364
386
|
* ```
|
|
365
387
|
*/
|
|
366
388
|
async setDefault(payeeId) {
|
|
367
|
-
const response = await this.client.put(
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
389
|
+
const response = await this.client.put(
|
|
390
|
+
"/api/v1/users/payees",
|
|
391
|
+
{
|
|
392
|
+
payeeId,
|
|
393
|
+
setAsDefault: true
|
|
394
|
+
},
|
|
395
|
+
{ useApiKey: false }
|
|
396
|
+
);
|
|
371
397
|
return this.transformPayee(response);
|
|
372
398
|
}
|
|
373
399
|
/**
|
|
374
400
|
* Delete a payee
|
|
375
|
-
*
|
|
401
|
+
*
|
|
376
402
|
* @example
|
|
377
403
|
* ```typescript
|
|
378
404
|
* await diviswap.payees.delete('payee-id');
|
|
@@ -386,7 +412,7 @@ var PayeesModule = class {
|
|
|
386
412
|
}
|
|
387
413
|
/**
|
|
388
414
|
* Get verification status of a payee
|
|
389
|
-
*
|
|
415
|
+
*
|
|
390
416
|
* @example
|
|
391
417
|
* ```typescript
|
|
392
418
|
* const status = await diviswap.payees.getVerificationStatus('payee-id');
|
|
@@ -394,11 +420,13 @@ var PayeesModule = class {
|
|
|
394
420
|
* ```
|
|
395
421
|
*/
|
|
396
422
|
async getVerificationStatus(_payeeId) {
|
|
397
|
-
throw new Error(
|
|
423
|
+
throw new Error(
|
|
424
|
+
"Payee verification status endpoint not available in v1 API yet"
|
|
425
|
+
);
|
|
398
426
|
}
|
|
399
427
|
/**
|
|
400
428
|
* Verify a payee with micro-deposit amounts
|
|
401
|
-
*
|
|
429
|
+
*
|
|
402
430
|
* @example
|
|
403
431
|
* ```typescript
|
|
404
432
|
* const result = await diviswap.payees.verify('payee-id', {
|
|
@@ -408,11 +436,13 @@ var PayeesModule = class {
|
|
|
408
436
|
* ```
|
|
409
437
|
*/
|
|
410
438
|
async verify(_payeeId, _data) {
|
|
411
|
-
throw new Error(
|
|
439
|
+
throw new Error(
|
|
440
|
+
"Payee verification endpoint not available in v1 API yet"
|
|
441
|
+
);
|
|
412
442
|
}
|
|
413
443
|
/**
|
|
414
444
|
* Get the default payee
|
|
415
|
-
*
|
|
445
|
+
*
|
|
416
446
|
* @example
|
|
417
447
|
* ```typescript
|
|
418
448
|
* const defaultPayee = await diviswap.payees.getDefault();
|
|
@@ -471,19 +501,19 @@ var CHAIN_ID_TO_NAME = {
|
|
|
471
501
|
84532: "base-sepolia"
|
|
472
502
|
};
|
|
473
503
|
var CHAIN_NAME_TO_ID = {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
504
|
+
ethereum: 1,
|
|
505
|
+
eth: 1,
|
|
506
|
+
goerli: 5,
|
|
507
|
+
sepolia: 11155111,
|
|
508
|
+
polygon: 137,
|
|
509
|
+
matic: 137,
|
|
510
|
+
mumbai: 80001,
|
|
511
|
+
base: 8453,
|
|
482
512
|
"base-goerli": 84531,
|
|
483
513
|
"base-sepolia": 84532,
|
|
484
|
-
|
|
514
|
+
solana: 999999,
|
|
485
515
|
// Solana mainnet (custom ID for database compatibility)
|
|
486
|
-
|
|
516
|
+
sol: 999999
|
|
487
517
|
};
|
|
488
518
|
var STABLECOIN_ADDRESSES = {
|
|
489
519
|
ethereum: {
|
|
@@ -534,7 +564,9 @@ var TransactionsModule = class {
|
|
|
534
564
|
const chainName = normalizedChain === "eth" ? "ethereum" : normalizedChain === "matic" ? "polygon" : normalizedChain;
|
|
535
565
|
const address = this.depositAddresses[chainName];
|
|
536
566
|
if (!address || address === "0x..." || address.includes("TODO")) {
|
|
537
|
-
throw new Error(
|
|
567
|
+
throw new Error(
|
|
568
|
+
`Deposit address not configured for chain: ${chain}. Please contact support.`
|
|
569
|
+
);
|
|
538
570
|
}
|
|
539
571
|
return address;
|
|
540
572
|
}
|
|
@@ -556,7 +588,7 @@ var TransactionsModule = class {
|
|
|
556
588
|
}
|
|
557
589
|
/**
|
|
558
590
|
* Create an onramp transaction (fiat to crypto)
|
|
559
|
-
*
|
|
591
|
+
*
|
|
560
592
|
* @example
|
|
561
593
|
* ```typescript
|
|
562
594
|
* const transaction = await diviswap.transactions.onramp({
|
|
@@ -567,7 +599,7 @@ var TransactionsModule = class {
|
|
|
567
599
|
* chain: 'ethereum'
|
|
568
600
|
* });
|
|
569
601
|
* ```
|
|
570
|
-
*
|
|
602
|
+
*
|
|
571
603
|
* @throws {Error} If user is not KYC approved
|
|
572
604
|
*/
|
|
573
605
|
async onramp(_data) {
|
|
@@ -609,9 +641,7 @@ var TransactionsModule = class {
|
|
|
609
641
|
*/
|
|
610
642
|
async offramp(data) {
|
|
611
643
|
if (!data.txHash || data.txHash.trim() === "") {
|
|
612
|
-
throw new Error(
|
|
613
|
-
"txHash is required for offramp transactions."
|
|
614
|
-
);
|
|
644
|
+
throw new Error("txHash is required for offramp transactions.");
|
|
615
645
|
}
|
|
616
646
|
const payload = {
|
|
617
647
|
payee_id: data.payeeId,
|
|
@@ -660,9 +690,7 @@ var TransactionsModule = class {
|
|
|
660
690
|
*/
|
|
661
691
|
async offrampTest(data) {
|
|
662
692
|
if (!data.txHash || data.txHash.trim() === "") {
|
|
663
|
-
throw new Error(
|
|
664
|
-
"txHash is required for offramp transactions."
|
|
665
|
-
);
|
|
693
|
+
throw new Error("txHash is required for offramp transactions.");
|
|
666
694
|
}
|
|
667
695
|
const payload = {
|
|
668
696
|
payee_id: data.payeeId,
|
|
@@ -684,12 +712,12 @@ var TransactionsModule = class {
|
|
|
684
712
|
}
|
|
685
713
|
/**
|
|
686
714
|
* List transactions with optional filters
|
|
687
|
-
*
|
|
715
|
+
*
|
|
688
716
|
* @example
|
|
689
717
|
* ```typescript
|
|
690
718
|
* // Get all transactions
|
|
691
719
|
* const allTransactions = await diviswap.transactions.list();
|
|
692
|
-
*
|
|
720
|
+
*
|
|
693
721
|
* // Get only completed onramp transactions
|
|
694
722
|
* const completedOnramps = await diviswap.transactions.list({
|
|
695
723
|
* type: 'onramp',
|
|
@@ -727,7 +755,7 @@ var TransactionsModule = class {
|
|
|
727
755
|
}
|
|
728
756
|
/**
|
|
729
757
|
* Get a specific transaction by ID
|
|
730
|
-
*
|
|
758
|
+
*
|
|
731
759
|
* @example
|
|
732
760
|
* ```typescript
|
|
733
761
|
* const transaction = await diviswap.transactions.get('transaction-id');
|
|
@@ -744,7 +772,7 @@ var TransactionsModule = class {
|
|
|
744
772
|
}
|
|
745
773
|
/**
|
|
746
774
|
* Get fee estimate for a transaction
|
|
747
|
-
*
|
|
775
|
+
*
|
|
748
776
|
* @example
|
|
749
777
|
* ```typescript
|
|
750
778
|
* const estimate = await diviswap.transactions.estimateFees({
|
|
@@ -760,7 +788,7 @@ var TransactionsModule = class {
|
|
|
760
788
|
}
|
|
761
789
|
/**
|
|
762
790
|
* Get recent transactions (convenience method)
|
|
763
|
-
*
|
|
791
|
+
*
|
|
764
792
|
* @example
|
|
765
793
|
* ```typescript
|
|
766
794
|
* const recentTransactions = await diviswap.transactions.getRecent(10);
|
|
@@ -771,7 +799,7 @@ var TransactionsModule = class {
|
|
|
771
799
|
}
|
|
772
800
|
/**
|
|
773
801
|
* Get transaction statistics
|
|
774
|
-
*
|
|
802
|
+
*
|
|
775
803
|
* @example
|
|
776
804
|
* ```typescript
|
|
777
805
|
* const stats = await diviswap.transactions.getStats();
|
|
@@ -780,21 +808,24 @@ var TransactionsModule = class {
|
|
|
780
808
|
*/
|
|
781
809
|
async getStats() {
|
|
782
810
|
const transactions = await this.list();
|
|
783
|
-
const stats = transactions.reduce(
|
|
784
|
-
acc
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
811
|
+
const stats = transactions.reduce(
|
|
812
|
+
(acc, tx) => {
|
|
813
|
+
acc.totalTransactions++;
|
|
814
|
+
acc.totalVolume += tx.amount || 0;
|
|
815
|
+
if (tx.status === "pending" || tx.status === "processing") {
|
|
816
|
+
acc.pendingTransactions++;
|
|
817
|
+
} else if (tx.status === "completed") {
|
|
818
|
+
acc.completedTransactions++;
|
|
819
|
+
}
|
|
820
|
+
return acc;
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
totalTransactions: 0,
|
|
824
|
+
totalVolume: 0,
|
|
825
|
+
pendingTransactions: 0,
|
|
826
|
+
completedTransactions: 0
|
|
790
827
|
}
|
|
791
|
-
|
|
792
|
-
}, {
|
|
793
|
-
totalTransactions: 0,
|
|
794
|
-
totalVolume: 0,
|
|
795
|
-
pendingTransactions: 0,
|
|
796
|
-
completedTransactions: 0
|
|
797
|
-
});
|
|
828
|
+
);
|
|
798
829
|
return stats;
|
|
799
830
|
}
|
|
800
831
|
/**
|
|
@@ -816,11 +847,11 @@ var KycModule = class {
|
|
|
816
847
|
}
|
|
817
848
|
/**
|
|
818
849
|
* Get current compliance status including KYC and KYB
|
|
819
|
-
*
|
|
850
|
+
*
|
|
820
851
|
* @example
|
|
821
852
|
* ```typescript
|
|
822
853
|
* const status = await diviswap.kyc.getComplianceStatus();
|
|
823
|
-
*
|
|
854
|
+
*
|
|
824
855
|
* if (!status.canTransact) {
|
|
825
856
|
* if (status.nextStep === 'COMPLETE_KYC') {
|
|
826
857
|
* // Redirect to KYC flow
|
|
@@ -845,19 +876,21 @@ var KycModule = class {
|
|
|
845
876
|
kycMetadata: kycData?.metadata
|
|
846
877
|
};
|
|
847
878
|
} catch (error) {
|
|
848
|
-
throw new Error(
|
|
879
|
+
throw new Error(
|
|
880
|
+
`Failed to get compliance status: ${error.message}`
|
|
881
|
+
);
|
|
849
882
|
}
|
|
850
883
|
}
|
|
851
884
|
/**
|
|
852
885
|
* Start KYC verification session (opens Sumsub widget)
|
|
853
|
-
*
|
|
886
|
+
*
|
|
854
887
|
* @example
|
|
855
888
|
* ```typescript
|
|
856
889
|
* const session = await diviswap.kyc.startKycSession();
|
|
857
|
-
*
|
|
890
|
+
*
|
|
858
891
|
* // Redirect user to session URL
|
|
859
892
|
* window.location.href = session.sessionUrl;
|
|
860
|
-
*
|
|
893
|
+
*
|
|
861
894
|
* // Or embed in iframe
|
|
862
895
|
* const iframe = document.createElement('iframe');
|
|
863
896
|
* iframe.src = session.sessionUrl;
|
|
@@ -868,7 +901,7 @@ var KycModule = class {
|
|
|
868
901
|
}
|
|
869
902
|
/**
|
|
870
903
|
* Submit KYC documents programmatically
|
|
871
|
-
*
|
|
904
|
+
*
|
|
872
905
|
* @example
|
|
873
906
|
* ```typescript
|
|
874
907
|
* // Convert file to base64
|
|
@@ -878,10 +911,10 @@ var KycModule = class {
|
|
|
878
911
|
* reader.onload = () => resolve(reader.result as string);
|
|
879
912
|
* reader.onerror = reject;
|
|
880
913
|
* });
|
|
881
|
-
*
|
|
914
|
+
*
|
|
882
915
|
* const frontImage = await toBase64(frontFile);
|
|
883
916
|
* const backImage = await toBase64(backFile);
|
|
884
|
-
*
|
|
917
|
+
*
|
|
885
918
|
* await diviswap.kyc.submitDocuments({
|
|
886
919
|
* type: 'DRIVERS_LICENSE',
|
|
887
920
|
* frontImage,
|
|
@@ -894,13 +927,15 @@ var KycModule = class {
|
|
|
894
927
|
throw new ValidationError("Front image is required");
|
|
895
928
|
}
|
|
896
929
|
if (["DRIVERS_LICENSE", "ID_CARD"].includes(documents.type) && !documents.backImage) {
|
|
897
|
-
throw new ValidationError(
|
|
930
|
+
throw new ValidationError(
|
|
931
|
+
`Back image is required for ${documents.type}`
|
|
932
|
+
);
|
|
898
933
|
}
|
|
899
934
|
throw new Error("KYC documents endpoint not available in v1 API yet");
|
|
900
935
|
}
|
|
901
936
|
/**
|
|
902
937
|
* Submit personal information for KYC
|
|
903
|
-
*
|
|
938
|
+
*
|
|
904
939
|
* @example
|
|
905
940
|
* ```typescript
|
|
906
941
|
* await diviswap.kyc.submitPersonalInfo({
|
|
@@ -929,18 +964,25 @@ var KycModule = class {
|
|
|
929
964
|
throw new ValidationError("Complete address is required");
|
|
930
965
|
}
|
|
931
966
|
try {
|
|
932
|
-
const response = await this.client.post(
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
967
|
+
const response = await this.client.post(
|
|
968
|
+
"/api/v1/kyc/personal-info",
|
|
969
|
+
{
|
|
970
|
+
first_name: info.firstName,
|
|
971
|
+
last_name: info.lastName,
|
|
972
|
+
dob: info.dateOfBirth,
|
|
973
|
+
country: info.address.country,
|
|
974
|
+
...info.phone && { phone: info.phone },
|
|
975
|
+
...info.address.street && {
|
|
976
|
+
address: info.address.street
|
|
977
|
+
},
|
|
978
|
+
...info.address.city && { city: info.address.city },
|
|
979
|
+
...info.address.state && { state: info.address.state },
|
|
980
|
+
...info.address.postalCode && {
|
|
981
|
+
postal_code: info.address.postalCode
|
|
982
|
+
},
|
|
983
|
+
...info.ssn && { ssn: info.ssn }
|
|
984
|
+
}
|
|
985
|
+
);
|
|
944
986
|
return response;
|
|
945
987
|
} catch (error) {
|
|
946
988
|
throw new Error(`Failed to submit KYC info: ${error.message}`);
|
|
@@ -948,7 +990,7 @@ var KycModule = class {
|
|
|
948
990
|
}
|
|
949
991
|
/**
|
|
950
992
|
* Check if user can transact (convenience method)
|
|
951
|
-
*
|
|
993
|
+
*
|
|
952
994
|
* @example
|
|
953
995
|
* ```typescript
|
|
954
996
|
* const canTransact = await diviswap.kyc.canTransact();
|
|
@@ -963,7 +1005,7 @@ var KycModule = class {
|
|
|
963
1005
|
}
|
|
964
1006
|
/**
|
|
965
1007
|
* Check if KYC is approved
|
|
966
|
-
*
|
|
1008
|
+
*
|
|
967
1009
|
* @example
|
|
968
1010
|
* ```typescript
|
|
969
1011
|
* const isApproved = await diviswap.kyc.isKycApproved();
|
|
@@ -975,7 +1017,7 @@ var KycModule = class {
|
|
|
975
1017
|
}
|
|
976
1018
|
/**
|
|
977
1019
|
* Check if KYB is approved (for business accounts)
|
|
978
|
-
*
|
|
1020
|
+
*
|
|
979
1021
|
* @example
|
|
980
1022
|
* ```typescript
|
|
981
1023
|
* const isBusinessApproved = await diviswap.kyc.isKybApproved();
|
|
@@ -987,7 +1029,7 @@ var KycModule = class {
|
|
|
987
1029
|
}
|
|
988
1030
|
/**
|
|
989
1031
|
* Get rejection reasons if KYC/KYB was rejected
|
|
990
|
-
*
|
|
1032
|
+
*
|
|
991
1033
|
* @example
|
|
992
1034
|
* ```typescript
|
|
993
1035
|
* const reasons = await diviswap.kyc.getRejectionReasons();
|
|
@@ -1006,13 +1048,13 @@ var KycModule = class {
|
|
|
1006
1048
|
}
|
|
1007
1049
|
/**
|
|
1008
1050
|
* Wait for KYC approval (polling)
|
|
1009
|
-
*
|
|
1051
|
+
*
|
|
1010
1052
|
* @example
|
|
1011
1053
|
* ```typescript
|
|
1012
1054
|
* // Start KYC session
|
|
1013
1055
|
* const session = await diviswap.kyc.startKycSession();
|
|
1014
1056
|
* window.open(session.sessionUrl);
|
|
1015
|
-
*
|
|
1057
|
+
*
|
|
1016
1058
|
* // Wait for approval (polls every 5 seconds for up to 10 minutes)
|
|
1017
1059
|
* try {
|
|
1018
1060
|
* await diviswap.kyc.waitForApproval();
|
|
@@ -1032,7 +1074,9 @@ var KycModule = class {
|
|
|
1032
1074
|
return status;
|
|
1033
1075
|
}
|
|
1034
1076
|
if (status.kycStatus === "REJECTED") {
|
|
1035
|
-
throw new Error(
|
|
1077
|
+
throw new Error(
|
|
1078
|
+
`KYC rejected: ${status.kycMetadata?.rejectLabels?.join(", ") || "Unknown reason"}`
|
|
1079
|
+
);
|
|
1036
1080
|
}
|
|
1037
1081
|
attempts++;
|
|
1038
1082
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
@@ -1063,9 +1107,12 @@ var FeesModule = class {
|
|
|
1063
1107
|
*/
|
|
1064
1108
|
async setFee(data) {
|
|
1065
1109
|
if (data.userId) {
|
|
1066
|
-
await this.client.put(
|
|
1067
|
-
|
|
1068
|
-
|
|
1110
|
+
await this.client.put(
|
|
1111
|
+
`/api/v1/partner/users/${data.userId}/fee`,
|
|
1112
|
+
{
|
|
1113
|
+
percentage: data.percentage
|
|
1114
|
+
}
|
|
1115
|
+
);
|
|
1069
1116
|
return {
|
|
1070
1117
|
integratorFeePercentage: data.percentage,
|
|
1071
1118
|
baseFeePercentage: 1.5,
|
|
@@ -1117,10 +1164,13 @@ var FeesModule = class {
|
|
|
1117
1164
|
* ```
|
|
1118
1165
|
*/
|
|
1119
1166
|
async calculateFees(params) {
|
|
1120
|
-
const response = await this.client.post(
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1167
|
+
const response = await this.client.post(
|
|
1168
|
+
"/api/v1/partner/fees/calculate",
|
|
1169
|
+
{
|
|
1170
|
+
amount: params.amount,
|
|
1171
|
+
user_id: params.userId
|
|
1172
|
+
}
|
|
1173
|
+
);
|
|
1124
1174
|
return {
|
|
1125
1175
|
amount: response.amount,
|
|
1126
1176
|
baseFee: response.base_fee,
|
|
@@ -1166,7 +1216,7 @@ var AddressesModule = class {
|
|
|
1166
1216
|
}
|
|
1167
1217
|
/**
|
|
1168
1218
|
* Get all addresses for the authenticated user
|
|
1169
|
-
*
|
|
1219
|
+
*
|
|
1170
1220
|
* @example
|
|
1171
1221
|
* ```typescript
|
|
1172
1222
|
* const addresses = await diviswap.addresses.list();
|
|
@@ -1179,7 +1229,7 @@ var AddressesModule = class {
|
|
|
1179
1229
|
}
|
|
1180
1230
|
/**
|
|
1181
1231
|
* Create a new crypto address for the user
|
|
1182
|
-
*
|
|
1232
|
+
*
|
|
1183
1233
|
* @example
|
|
1184
1234
|
* ```typescript
|
|
1185
1235
|
* const address = await diviswap.addresses.create({
|
|
@@ -1200,7 +1250,7 @@ var AddressesModule = class {
|
|
|
1200
1250
|
}
|
|
1201
1251
|
/**
|
|
1202
1252
|
* Set a specific address as the default for its chain
|
|
1203
|
-
*
|
|
1253
|
+
*
|
|
1204
1254
|
* @example
|
|
1205
1255
|
* ```typescript
|
|
1206
1256
|
* await diviswap.addresses.setDefault({
|
|
@@ -1214,7 +1264,7 @@ var AddressesModule = class {
|
|
|
1214
1264
|
}
|
|
1215
1265
|
/**
|
|
1216
1266
|
* Delete a crypto address
|
|
1217
|
-
*
|
|
1267
|
+
*
|
|
1218
1268
|
* @example
|
|
1219
1269
|
* ```typescript
|
|
1220
1270
|
* await diviswap.addresses.delete({
|
|
@@ -1228,7 +1278,7 @@ var AddressesModule = class {
|
|
|
1228
1278
|
}
|
|
1229
1279
|
/**
|
|
1230
1280
|
* Get addresses for a specific chain
|
|
1231
|
-
*
|
|
1281
|
+
*
|
|
1232
1282
|
* @example
|
|
1233
1283
|
* ```typescript
|
|
1234
1284
|
* const ethAddresses = await diviswap.addresses.getByChain(1);
|
|
@@ -1242,7 +1292,7 @@ var AddressesModule = class {
|
|
|
1242
1292
|
}
|
|
1243
1293
|
/**
|
|
1244
1294
|
* Get the default address for a specific chain
|
|
1245
|
-
*
|
|
1295
|
+
*
|
|
1246
1296
|
* @example
|
|
1247
1297
|
* ```typescript
|
|
1248
1298
|
* const defaultEthAddress = await diviswap.addresses.getDefault(1);
|
|
@@ -1252,11 +1302,13 @@ var AddressesModule = class {
|
|
|
1252
1302
|
async getDefault(chainIdOrName) {
|
|
1253
1303
|
const chainId = typeof chainIdOrName === "string" ? CHAIN_IDS[chainIdOrName] : chainIdOrName;
|
|
1254
1304
|
const addresses = await this.list();
|
|
1255
|
-
return addresses.find(
|
|
1305
|
+
return addresses.find(
|
|
1306
|
+
(addr) => addr.chain_id === chainId && addr.is_default
|
|
1307
|
+
) || null;
|
|
1256
1308
|
}
|
|
1257
1309
|
/**
|
|
1258
1310
|
* Check if an address exists for the user
|
|
1259
|
-
*
|
|
1311
|
+
*
|
|
1260
1312
|
* @example
|
|
1261
1313
|
* ```typescript
|
|
1262
1314
|
* const exists = await diviswap.addresses.exists({
|
|
@@ -1274,7 +1326,7 @@ var AddressesModule = class {
|
|
|
1274
1326
|
/**
|
|
1275
1327
|
* Automatically track a wallet connection
|
|
1276
1328
|
* This is the main method for automatic address tracking
|
|
1277
|
-
*
|
|
1329
|
+
*
|
|
1278
1330
|
* @example
|
|
1279
1331
|
* ```typescript
|
|
1280
1332
|
* // When user connects wallet
|
|
@@ -1310,7 +1362,7 @@ var AddressesModule = class {
|
|
|
1310
1362
|
}
|
|
1311
1363
|
/**
|
|
1312
1364
|
* Auto-track multiple wallet connections (useful for multi-chain wallets)
|
|
1313
|
-
*
|
|
1365
|
+
*
|
|
1314
1366
|
* @example
|
|
1315
1367
|
* ```typescript
|
|
1316
1368
|
* // When user connects a multi-chain wallet
|
|
@@ -1328,7 +1380,10 @@ var AddressesModule = class {
|
|
|
1328
1380
|
const address = await this.trackWallet(connection);
|
|
1329
1381
|
results.push(address);
|
|
1330
1382
|
} catch (error) {
|
|
1331
|
-
console.error(
|
|
1383
|
+
console.error(
|
|
1384
|
+
`Failed to track wallet for chain ${connection.chainId}:`,
|
|
1385
|
+
error
|
|
1386
|
+
);
|
|
1332
1387
|
}
|
|
1333
1388
|
}
|
|
1334
1389
|
return results;
|
|
@@ -1387,10 +1442,13 @@ var WebhooksModule = class {
|
|
|
1387
1442
|
* ```
|
|
1388
1443
|
*/
|
|
1389
1444
|
async setConfigForPartner(partnerId, data) {
|
|
1390
|
-
const response = await this.client.put(
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1445
|
+
const response = await this.client.put(
|
|
1446
|
+
`/api/v1/partners/${partnerId}/webhook`,
|
|
1447
|
+
{
|
|
1448
|
+
webhook_url: data.webhook_url,
|
|
1449
|
+
webhook_secret: data.webhook_secret
|
|
1450
|
+
}
|
|
1451
|
+
);
|
|
1394
1452
|
return response;
|
|
1395
1453
|
}
|
|
1396
1454
|
/**
|
|
@@ -1404,14 +1462,18 @@ var WebhooksModule = class {
|
|
|
1404
1462
|
* ```
|
|
1405
1463
|
*/
|
|
1406
1464
|
async getConfig() {
|
|
1407
|
-
const response = await this.client.get(
|
|
1465
|
+
const response = await this.client.get(
|
|
1466
|
+
"/api/v1/partner/webhook"
|
|
1467
|
+
);
|
|
1408
1468
|
return response;
|
|
1409
1469
|
}
|
|
1410
1470
|
/**
|
|
1411
1471
|
* Get webhook config for a specific partner (user-owned)
|
|
1412
1472
|
*/
|
|
1413
1473
|
async getConfigForPartner(partnerId) {
|
|
1414
|
-
const response = await this.client.get(
|
|
1474
|
+
const response = await this.client.get(
|
|
1475
|
+
`/api/v1/partners/${partnerId}/webhook`
|
|
1476
|
+
);
|
|
1415
1477
|
return response;
|
|
1416
1478
|
}
|
|
1417
1479
|
/**
|
|
@@ -1588,7 +1650,10 @@ var TokenManager = class {
|
|
|
1588
1650
|
this.refreshPromise = refreshCallback(refreshToken);
|
|
1589
1651
|
try {
|
|
1590
1652
|
const newTokenData = await this.refreshPromise;
|
|
1591
|
-
this.setTokens(
|
|
1653
|
+
this.setTokens(
|
|
1654
|
+
newTokenData.accessToken,
|
|
1655
|
+
newTokenData.refreshToken || refreshToken
|
|
1656
|
+
);
|
|
1592
1657
|
return newTokenData.accessToken;
|
|
1593
1658
|
} finally {
|
|
1594
1659
|
this.refreshPromise = null;
|
|
@@ -1632,7 +1697,7 @@ var PartnerAuth = class {
|
|
|
1632
1697
|
].join("\n");
|
|
1633
1698
|
const signature = crypto__default.default.createHmac("sha256", this.credentials.secretKey).update(canonical).digest("base64");
|
|
1634
1699
|
const headers = {
|
|
1635
|
-
|
|
1700
|
+
Authorization: `HMAC ${this.credentials.keyId}:${signature}:${timestamp}:${nonce}`,
|
|
1636
1701
|
"X-Client-Id": this.credentials.keyId
|
|
1637
1702
|
};
|
|
1638
1703
|
if (this.credentials.customerId) {
|
|
@@ -1654,7 +1719,7 @@ var PartnerAuth = class {
|
|
|
1654
1719
|
*/
|
|
1655
1720
|
generateJWT(options = {}) {
|
|
1656
1721
|
const {
|
|
1657
|
-
audience = "api.
|
|
1722
|
+
audience = "api.diviswap.com",
|
|
1658
1723
|
expiresIn = 300,
|
|
1659
1724
|
// 5 minutes max
|
|
1660
1725
|
scopes = []
|
|
@@ -1669,13 +1734,21 @@ var PartnerAuth = class {
|
|
|
1669
1734
|
// Expiration (max 5 minutes)
|
|
1670
1735
|
iat: now,
|
|
1671
1736
|
// Issued at
|
|
1672
|
-
...this.credentials.customerId && {
|
|
1673
|
-
|
|
1737
|
+
...this.credentials.customerId && {
|
|
1738
|
+
sub: this.credentials.customerId
|
|
1739
|
+
},
|
|
1740
|
+
...this.credentials.customerEmail && {
|
|
1741
|
+
email: this.credentials.customerEmail
|
|
1742
|
+
},
|
|
1674
1743
|
...scopes.length > 0 && { scope: scopes }
|
|
1675
1744
|
};
|
|
1676
1745
|
const header = { alg: "HS256", typ: "JWT" };
|
|
1677
|
-
const encodedHeader = Buffer.from(JSON.stringify(header)).toString(
|
|
1678
|
-
|
|
1746
|
+
const encodedHeader = Buffer.from(JSON.stringify(header)).toString(
|
|
1747
|
+
"base64url"
|
|
1748
|
+
);
|
|
1749
|
+
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString(
|
|
1750
|
+
"base64url"
|
|
1751
|
+
);
|
|
1679
1752
|
const signature = crypto__default.default.createHmac("sha256", this.credentials.secretKey).update(`${encodedHeader}.${encodedPayload}`).digest("base64url");
|
|
1680
1753
|
return `${encodedHeader}.${encodedPayload}.${signature}`;
|
|
1681
1754
|
}
|
|
@@ -1714,51 +1787,63 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1714
1787
|
*/
|
|
1715
1788
|
static fromUserConfig(config, useLocalStorage = true) {
|
|
1716
1789
|
const baseUrl = config.apiUrl || this.getDefaultApiUrl(config.environment || "production");
|
|
1717
|
-
return new _UnifiedApiClient(
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1790
|
+
return new _UnifiedApiClient(
|
|
1791
|
+
{
|
|
1792
|
+
baseUrl,
|
|
1793
|
+
timeout: config.timeout || 3e4,
|
|
1794
|
+
debug: config.debug || false,
|
|
1795
|
+
mode: "user",
|
|
1796
|
+
apiKey: config.apiKey,
|
|
1797
|
+
clientId: config.clientId
|
|
1798
|
+
},
|
|
1799
|
+
useLocalStorage
|
|
1800
|
+
);
|
|
1725
1801
|
}
|
|
1726
1802
|
/**
|
|
1727
1803
|
* Create client from partner config
|
|
1728
1804
|
*/
|
|
1729
1805
|
static fromPartnerConfig(config, useLocalStorage = true) {
|
|
1730
1806
|
const baseUrl = config.apiUrl || this.getDefaultApiUrl(config.environment || "production");
|
|
1731
|
-
return new _UnifiedApiClient(
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1807
|
+
return new _UnifiedApiClient(
|
|
1808
|
+
{
|
|
1809
|
+
baseUrl,
|
|
1810
|
+
timeout: config.timeout || 3e4,
|
|
1811
|
+
debug: config.debug || false,
|
|
1812
|
+
mode: "partner",
|
|
1813
|
+
keyId: config.keyId,
|
|
1814
|
+
secretKey: config.secretKey,
|
|
1815
|
+
authMethod: config.authMethod || "hmac",
|
|
1816
|
+
customerId: config.customerId,
|
|
1817
|
+
customerEmail: config.customerEmail
|
|
1818
|
+
},
|
|
1819
|
+
useLocalStorage
|
|
1820
|
+
);
|
|
1742
1821
|
}
|
|
1743
1822
|
/**
|
|
1744
1823
|
* Create client from any config (auto-detect mode)
|
|
1745
1824
|
*/
|
|
1746
1825
|
static fromConfig(config, useLocalStorage = true) {
|
|
1747
1826
|
if ("mode" in config && config.mode === "partner" || "keyId" in config && "secretKey" in config) {
|
|
1748
|
-
return this.fromPartnerConfig(
|
|
1827
|
+
return this.fromPartnerConfig(
|
|
1828
|
+
config,
|
|
1829
|
+
useLocalStorage
|
|
1830
|
+
);
|
|
1749
1831
|
} else {
|
|
1750
|
-
return this.fromUserConfig(
|
|
1832
|
+
return this.fromUserConfig(
|
|
1833
|
+
config,
|
|
1834
|
+
useLocalStorage
|
|
1835
|
+
);
|
|
1751
1836
|
}
|
|
1752
1837
|
}
|
|
1753
1838
|
static getDefaultApiUrl(environment) {
|
|
1754
1839
|
switch (environment) {
|
|
1755
1840
|
case "production":
|
|
1756
1841
|
case "sandbox":
|
|
1757
|
-
return "https://api.
|
|
1842
|
+
return "https://api.diviswap.com";
|
|
1758
1843
|
case "development":
|
|
1759
|
-
return "https://dev-api.
|
|
1844
|
+
return "https://dev-api.diviswap.com";
|
|
1760
1845
|
default:
|
|
1761
|
-
return "https://api.
|
|
1846
|
+
return "https://api.diviswap.com";
|
|
1762
1847
|
}
|
|
1763
1848
|
}
|
|
1764
1849
|
/**
|
|
@@ -1824,7 +1909,14 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1824
1909
|
* Make authenticated API request
|
|
1825
1910
|
*/
|
|
1826
1911
|
async request(options) {
|
|
1827
|
-
const {
|
|
1912
|
+
const {
|
|
1913
|
+
method,
|
|
1914
|
+
path,
|
|
1915
|
+
body,
|
|
1916
|
+
headers = {},
|
|
1917
|
+
useApiKey = false,
|
|
1918
|
+
skipAuth = false
|
|
1919
|
+
} = options;
|
|
1828
1920
|
const url = `${this.config.baseUrl}${path}`;
|
|
1829
1921
|
const requestHeaders = {
|
|
1830
1922
|
"Content-Type": "application/json",
|
|
@@ -1840,7 +1932,10 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1840
1932
|
}
|
|
1841
1933
|
try {
|
|
1842
1934
|
const controller = new AbortController();
|
|
1843
|
-
const timeoutId = setTimeout(
|
|
1935
|
+
const timeoutId = setTimeout(
|
|
1936
|
+
() => controller.abort(),
|
|
1937
|
+
this.config.timeout
|
|
1938
|
+
);
|
|
1844
1939
|
if (this.config.debug) {
|
|
1845
1940
|
console.log(`[Diviswap SDK] ${method} ${url}`);
|
|
1846
1941
|
}
|
|
@@ -1859,7 +1954,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1859
1954
|
responseData = responseText;
|
|
1860
1955
|
}
|
|
1861
1956
|
if (this.config.debug) {
|
|
1862
|
-
console.log(
|
|
1957
|
+
console.log(
|
|
1958
|
+
`[Diviswap SDK] Response ${response.status}: ${responseText.substring(0, 500)}`
|
|
1959
|
+
);
|
|
1863
1960
|
}
|
|
1864
1961
|
if (!response.ok) {
|
|
1865
1962
|
await this.handleErrorResponse(response, responseData);
|
|
@@ -1880,7 +1977,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1880
1977
|
*/
|
|
1881
1978
|
async addPartnerAuth(method, path, body, headers) {
|
|
1882
1979
|
if (!this.partnerAuth) {
|
|
1883
|
-
throw new AuthenticationError(
|
|
1980
|
+
throw new AuthenticationError(
|
|
1981
|
+
"Partner authentication not configured"
|
|
1982
|
+
);
|
|
1884
1983
|
}
|
|
1885
1984
|
const bodyString = body ? JSON.stringify(body) : "";
|
|
1886
1985
|
const urlParts = path.split("?");
|
|
@@ -1888,7 +1987,7 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1888
1987
|
const queryString = urlParts.length > 1 ? urlParts[1] : "";
|
|
1889
1988
|
if (this.config.authMethod === "jwt") {
|
|
1890
1989
|
const jwt = this.partnerAuth.generateJWT({
|
|
1891
|
-
audience: "api.
|
|
1990
|
+
audience: "api.diviswap.com",
|
|
1892
1991
|
expiresIn: 300
|
|
1893
1992
|
});
|
|
1894
1993
|
headers["Authorization"] = `Bearer ${jwt}`;
|
|
@@ -1913,7 +2012,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1913
2012
|
headers["X-TIMESTAMP"] = Math.floor(Date.now() / 1e3).toString();
|
|
1914
2013
|
headers["X-API-Key"] = this.config.apiKey;
|
|
1915
2014
|
if (!useApiKey) {
|
|
1916
|
-
const accessToken = await this.tokenManager.getValidAccessToken(
|
|
2015
|
+
const accessToken = await this.tokenManager.getValidAccessToken(
|
|
2016
|
+
this.refreshCallback
|
|
2017
|
+
);
|
|
1917
2018
|
if (accessToken) {
|
|
1918
2019
|
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
1919
2020
|
}
|
|
@@ -1971,7 +2072,10 @@ var _Diviswap = class _Diviswap {
|
|
|
1971
2072
|
this.apiClient = UnifiedApiClient.fromConfig(config, useLocalStorage);
|
|
1972
2073
|
this.auth = new AuthModule(this.apiClient);
|
|
1973
2074
|
this.payees = new PayeesModule(this.apiClient);
|
|
1974
|
-
this.transactions = new TransactionsModule(
|
|
2075
|
+
this.transactions = new TransactionsModule(
|
|
2076
|
+
this.apiClient,
|
|
2077
|
+
config.environment || "sandbox"
|
|
2078
|
+
);
|
|
1975
2079
|
this.kyc = new KycModule(this.apiClient);
|
|
1976
2080
|
this.fees = new FeesModule(this.apiClient);
|
|
1977
2081
|
this.addresses = new AddressesModule(this.apiClient);
|
|
@@ -2003,7 +2107,9 @@ var _Diviswap = class _Diviswap {
|
|
|
2003
2107
|
*/
|
|
2004
2108
|
static getInstance() {
|
|
2005
2109
|
if (!_Diviswap.instance) {
|
|
2006
|
-
throw new ConfigurationError(
|
|
2110
|
+
throw new ConfigurationError(
|
|
2111
|
+
"Diviswap SDK not initialized. Call Diviswap.init() first."
|
|
2112
|
+
);
|
|
2007
2113
|
}
|
|
2008
2114
|
return _Diviswap.instance;
|
|
2009
2115
|
}
|
|
@@ -2018,7 +2124,9 @@ var _Diviswap = class _Diviswap {
|
|
|
2018
2124
|
* @deprecated Configuration updates require re-initialization. Call Diviswap.reset() then Diviswap.init() with new config.
|
|
2019
2125
|
*/
|
|
2020
2126
|
updateConfig(_config) {
|
|
2021
|
-
throw new ConfigurationError(
|
|
2127
|
+
throw new ConfigurationError(
|
|
2128
|
+
"Configuration updates require re-initialization. Call Diviswap.reset() then Diviswap.init() with new config."
|
|
2129
|
+
);
|
|
2022
2130
|
}
|
|
2023
2131
|
/**
|
|
2024
2132
|
* Get current configuration (excluding sensitive data)
|
|
@@ -2040,7 +2148,7 @@ var _Diviswap = class _Diviswap {
|
|
|
2040
2148
|
* const token = await diviswap.getAccessToken();
|
|
2041
2149
|
* if (token) {
|
|
2042
2150
|
* // Use token for custom API calls
|
|
2043
|
-
* fetch('https://api.
|
|
2151
|
+
* fetch('https://api.diviswap.com/custom-endpoint', {
|
|
2044
2152
|
* headers: { 'Authorization': `Bearer ${token}` }
|
|
2045
2153
|
* });
|
|
2046
2154
|
* }
|
|
@@ -2091,25 +2199,39 @@ var _Diviswap = class _Diviswap {
|
|
|
2091
2199
|
if (isPartnerMode) {
|
|
2092
2200
|
const partnerConfig = config;
|
|
2093
2201
|
if (!partnerConfig.keyId) {
|
|
2094
|
-
throw new ConfigurationError(
|
|
2202
|
+
throw new ConfigurationError(
|
|
2203
|
+
"Partner keyId is required for partner authentication"
|
|
2204
|
+
);
|
|
2095
2205
|
}
|
|
2096
2206
|
if (!partnerConfig.secretKey) {
|
|
2097
|
-
throw new ConfigurationError(
|
|
2207
|
+
throw new ConfigurationError(
|
|
2208
|
+
"Partner secretKey is required for partner authentication"
|
|
2209
|
+
);
|
|
2098
2210
|
}
|
|
2099
2211
|
if (partnerConfig.authMethod && !["hmac", "jwt"].includes(partnerConfig.authMethod)) {
|
|
2100
|
-
throw new ConfigurationError(
|
|
2212
|
+
throw new ConfigurationError(
|
|
2213
|
+
'Invalid authMethod. Must be either "hmac" or "jwt"'
|
|
2214
|
+
);
|
|
2101
2215
|
}
|
|
2102
2216
|
} else {
|
|
2103
2217
|
const userConfig = config;
|
|
2104
2218
|
if (!userConfig.apiKey) {
|
|
2105
|
-
throw new ConfigurationError(
|
|
2219
|
+
throw new ConfigurationError(
|
|
2220
|
+
"API Key is required for user authentication"
|
|
2221
|
+
);
|
|
2106
2222
|
}
|
|
2107
2223
|
if (!userConfig.clientId) {
|
|
2108
|
-
throw new ConfigurationError(
|
|
2224
|
+
throw new ConfigurationError(
|
|
2225
|
+
"Client ID is required for user authentication"
|
|
2226
|
+
);
|
|
2109
2227
|
}
|
|
2110
2228
|
}
|
|
2111
|
-
if (config.environment && !["production", "sandbox", "development"].includes(
|
|
2112
|
-
|
|
2229
|
+
if (config.environment && !["production", "sandbox", "development"].includes(
|
|
2230
|
+
config.environment
|
|
2231
|
+
)) {
|
|
2232
|
+
throw new ConfigurationError(
|
|
2233
|
+
"Invalid environment. Must be one of: production, sandbox, development"
|
|
2234
|
+
);
|
|
2113
2235
|
}
|
|
2114
2236
|
}
|
|
2115
2237
|
};
|
|
@@ -2284,7 +2406,9 @@ var _WalletTracker = class _WalletTracker {
|
|
|
2284
2406
|
* Get chain name from chain ID
|
|
2285
2407
|
*/
|
|
2286
2408
|
getChainName(chainId) {
|
|
2287
|
-
const builtInChain = Object.entries(CHAIN_IDS).find(
|
|
2409
|
+
const builtInChain = Object.entries(CHAIN_IDS).find(
|
|
2410
|
+
([_, id]) => id === chainId
|
|
2411
|
+
)?.[0];
|
|
2288
2412
|
if (builtInChain) return builtInChain;
|
|
2289
2413
|
return this.config.customChains?.[chainId];
|
|
2290
2414
|
}
|