@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/LICENSE +1 -1
- package/README.md +73 -82
- package/bin/create-diviswap-app.js +5 -5
- package/dist/cli/index.js +442 -185
- package/dist/cli/templates/nextjs-app/api-route.ts.hbs +8 -52
- package/dist/cli/templates/nextjs-app/types.ts.hbs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +333 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +333 -215
- 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-Cohx6L51.d.mts} +12 -24
- package/dist/{wallet-DZymADRo.d.ts → wallet-Cohx6L51.d.ts} +12 -24
- package/package.json +98 -97
- package/src/cli/templates/index.ts +86 -54
- package/src/cli/templates/nextjs-app/api-route.ts.hbs +8 -52
- package/src/cli/templates/nextjs-app/types.ts.hbs +1 -1
- 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) {
|
|
@@ -236,12 +252,28 @@ var PayeesModule = class {
|
|
|
236
252
|
constructor(client) {
|
|
237
253
|
this.client = client;
|
|
238
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Validate ABA routing number checksum
|
|
257
|
+
*/
|
|
258
|
+
validateRoutingNumber(routing) {
|
|
259
|
+
if (routing.length !== 9 || !/^\d{9}$/.test(routing)) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
const d = routing.split("").map(Number);
|
|
263
|
+
const checksum = 3 * (d[0] + d[3] + d[6]) + 7 * (d[1] + d[4] + d[7]) + 1 * (d[2] + d[5] + d[8]);
|
|
264
|
+
return checksum % 10 === 0;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Validate account number format
|
|
268
|
+
*/
|
|
269
|
+
validateAccountNumber(account) {
|
|
270
|
+
return /^\d{4,17}$/.test(account);
|
|
271
|
+
}
|
|
239
272
|
/**
|
|
240
273
|
* Create a new payee (bank account)
|
|
241
|
-
*
|
|
274
|
+
*
|
|
242
275
|
* @example
|
|
243
276
|
* ```typescript
|
|
244
|
-
* // Bank account
|
|
245
277
|
* const bankAccount = await diviswap.payees.create({
|
|
246
278
|
* nickname: 'My Checking',
|
|
247
279
|
* accountNumber: '123456789',
|
|
@@ -249,50 +281,32 @@ var PayeesModule = class {
|
|
|
249
281
|
* accountType: 'checking',
|
|
250
282
|
* setAsDefault: true
|
|
251
283
|
* });
|
|
252
|
-
*
|
|
253
|
-
* // Debit card
|
|
254
|
-
* const debitCard = await diviswap.payees.create({
|
|
255
|
-
* nickname: 'My Debit Card',
|
|
256
|
-
* accountType: 'debit_card',
|
|
257
|
-
* debitCard: {
|
|
258
|
-
* number: '4111111111111111',
|
|
259
|
-
* expirationMonth: '12',
|
|
260
|
-
* expirationYear: '2025',
|
|
261
|
-
* cvv: '123'
|
|
262
|
-
* },
|
|
263
|
-
* setAsDefault: false
|
|
264
|
-
* });
|
|
265
284
|
* ```
|
|
266
285
|
*/
|
|
267
286
|
async create(data) {
|
|
268
287
|
try {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
});
|
|
284
|
-
} else {
|
|
285
|
-
if (!data.accountNumber || !data.routingNumber) {
|
|
286
|
-
throw new Error("Account number and routing number are required for bank accounts");
|
|
287
|
-
}
|
|
288
|
-
response = await this.client.post("/api/v1/payees", {
|
|
289
|
-
name: data.nickname,
|
|
290
|
-
account_number: data.accountNumber,
|
|
291
|
-
routing_number: data.routingNumber,
|
|
292
|
-
type: (data.accountType || "checking").toUpperCase(),
|
|
293
|
-
set_as_default: data.setAsDefault || false
|
|
294
|
-
});
|
|
288
|
+
if (!data.accountNumber || !data.routingNumber) {
|
|
289
|
+
throw new Error(
|
|
290
|
+
"Account number and routing number are required for bank accounts"
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
if (!this.validateRoutingNumber(data.routingNumber)) {
|
|
294
|
+
throw new Error(
|
|
295
|
+
"Invalid routing number. Please provide a valid 9-digit ABA routing number."
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
if (!this.validateAccountNumber(data.accountNumber)) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
"Invalid account number. Must be 4-17 digits with no letters or special characters."
|
|
301
|
+
);
|
|
295
302
|
}
|
|
303
|
+
const response = await this.client.post("/api/v1/payees", {
|
|
304
|
+
name: data.nickname,
|
|
305
|
+
account_number: data.accountNumber,
|
|
306
|
+
routing_number: data.routingNumber,
|
|
307
|
+
type: (data.accountType || "checking").toUpperCase(),
|
|
308
|
+
set_as_default: data.setAsDefault || false
|
|
309
|
+
});
|
|
296
310
|
return this.transformPayee(response);
|
|
297
311
|
} catch (error) {
|
|
298
312
|
throw new Error(`Failed to create payee: ${error.message}`);
|
|
@@ -300,7 +314,7 @@ var PayeesModule = class {
|
|
|
300
314
|
}
|
|
301
315
|
/**
|
|
302
316
|
* List all payees
|
|
303
|
-
*
|
|
317
|
+
*
|
|
304
318
|
* @example
|
|
305
319
|
* ```typescript
|
|
306
320
|
* const payees = await diviswap.payees.list();
|
|
@@ -308,7 +322,9 @@ var PayeesModule = class {
|
|
|
308
322
|
* ```
|
|
309
323
|
*/
|
|
310
324
|
async list() {
|
|
311
|
-
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
|
+
});
|
|
312
328
|
return this.parsePayeesResponse(response);
|
|
313
329
|
}
|
|
314
330
|
parsePayeesResponse(response) {
|
|
@@ -341,7 +357,7 @@ var PayeesModule = class {
|
|
|
341
357
|
}
|
|
342
358
|
/**
|
|
343
359
|
* Get a specific payee
|
|
344
|
-
*
|
|
360
|
+
*
|
|
345
361
|
* @example
|
|
346
362
|
* ```typescript
|
|
347
363
|
* const payee = await diviswap.payees.get('payee-id');
|
|
@@ -357,22 +373,26 @@ var PayeesModule = class {
|
|
|
357
373
|
}
|
|
358
374
|
/**
|
|
359
375
|
* Set a payee as default
|
|
360
|
-
*
|
|
376
|
+
*
|
|
361
377
|
* @example
|
|
362
378
|
* ```typescript
|
|
363
379
|
* await diviswap.payees.setDefault('payee-id');
|
|
364
380
|
* ```
|
|
365
381
|
*/
|
|
366
382
|
async setDefault(payeeId) {
|
|
367
|
-
const response = await this.client.put(
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
383
|
+
const response = await this.client.put(
|
|
384
|
+
"/api/v1/users/payees",
|
|
385
|
+
{
|
|
386
|
+
payeeId,
|
|
387
|
+
setAsDefault: true
|
|
388
|
+
},
|
|
389
|
+
{ useApiKey: false }
|
|
390
|
+
);
|
|
371
391
|
return this.transformPayee(response);
|
|
372
392
|
}
|
|
373
393
|
/**
|
|
374
394
|
* Delete a payee
|
|
375
|
-
*
|
|
395
|
+
*
|
|
376
396
|
* @example
|
|
377
397
|
* ```typescript
|
|
378
398
|
* await diviswap.payees.delete('payee-id');
|
|
@@ -386,7 +406,7 @@ var PayeesModule = class {
|
|
|
386
406
|
}
|
|
387
407
|
/**
|
|
388
408
|
* Get verification status of a payee
|
|
389
|
-
*
|
|
409
|
+
*
|
|
390
410
|
* @example
|
|
391
411
|
* ```typescript
|
|
392
412
|
* const status = await diviswap.payees.getVerificationStatus('payee-id');
|
|
@@ -394,11 +414,13 @@ var PayeesModule = class {
|
|
|
394
414
|
* ```
|
|
395
415
|
*/
|
|
396
416
|
async getVerificationStatus(_payeeId) {
|
|
397
|
-
throw new Error(
|
|
417
|
+
throw new Error(
|
|
418
|
+
"Payee verification status endpoint not available in v1 API yet"
|
|
419
|
+
);
|
|
398
420
|
}
|
|
399
421
|
/**
|
|
400
422
|
* Verify a payee with micro-deposit amounts
|
|
401
|
-
*
|
|
423
|
+
*
|
|
402
424
|
* @example
|
|
403
425
|
* ```typescript
|
|
404
426
|
* const result = await diviswap.payees.verify('payee-id', {
|
|
@@ -408,11 +430,13 @@ var PayeesModule = class {
|
|
|
408
430
|
* ```
|
|
409
431
|
*/
|
|
410
432
|
async verify(_payeeId, _data) {
|
|
411
|
-
throw new Error(
|
|
433
|
+
throw new Error(
|
|
434
|
+
"Payee verification endpoint not available in v1 API yet"
|
|
435
|
+
);
|
|
412
436
|
}
|
|
413
437
|
/**
|
|
414
438
|
* Get the default payee
|
|
415
|
-
*
|
|
439
|
+
*
|
|
416
440
|
* @example
|
|
417
441
|
* ```typescript
|
|
418
442
|
* const defaultPayee = await diviswap.payees.getDefault();
|
|
@@ -471,19 +495,19 @@ var CHAIN_ID_TO_NAME = {
|
|
|
471
495
|
84532: "base-sepolia"
|
|
472
496
|
};
|
|
473
497
|
var CHAIN_NAME_TO_ID = {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
498
|
+
ethereum: 1,
|
|
499
|
+
eth: 1,
|
|
500
|
+
goerli: 5,
|
|
501
|
+
sepolia: 11155111,
|
|
502
|
+
polygon: 137,
|
|
503
|
+
matic: 137,
|
|
504
|
+
mumbai: 80001,
|
|
505
|
+
base: 8453,
|
|
482
506
|
"base-goerli": 84531,
|
|
483
507
|
"base-sepolia": 84532,
|
|
484
|
-
|
|
508
|
+
solana: 999999,
|
|
485
509
|
// Solana mainnet (custom ID for database compatibility)
|
|
486
|
-
|
|
510
|
+
sol: 999999
|
|
487
511
|
};
|
|
488
512
|
var STABLECOIN_ADDRESSES = {
|
|
489
513
|
ethereum: {
|
|
@@ -534,7 +558,9 @@ var TransactionsModule = class {
|
|
|
534
558
|
const chainName = normalizedChain === "eth" ? "ethereum" : normalizedChain === "matic" ? "polygon" : normalizedChain;
|
|
535
559
|
const address = this.depositAddresses[chainName];
|
|
536
560
|
if (!address || address === "0x..." || address.includes("TODO")) {
|
|
537
|
-
throw new Error(
|
|
561
|
+
throw new Error(
|
|
562
|
+
`Deposit address not configured for chain: ${chain}. Please contact support.`
|
|
563
|
+
);
|
|
538
564
|
}
|
|
539
565
|
return address;
|
|
540
566
|
}
|
|
@@ -556,7 +582,7 @@ var TransactionsModule = class {
|
|
|
556
582
|
}
|
|
557
583
|
/**
|
|
558
584
|
* Create an onramp transaction (fiat to crypto)
|
|
559
|
-
*
|
|
585
|
+
*
|
|
560
586
|
* @example
|
|
561
587
|
* ```typescript
|
|
562
588
|
* const transaction = await diviswap.transactions.onramp({
|
|
@@ -567,7 +593,7 @@ var TransactionsModule = class {
|
|
|
567
593
|
* chain: 'ethereum'
|
|
568
594
|
* });
|
|
569
595
|
* ```
|
|
570
|
-
*
|
|
596
|
+
*
|
|
571
597
|
* @throws {Error} If user is not KYC approved
|
|
572
598
|
*/
|
|
573
599
|
async onramp(_data) {
|
|
@@ -609,9 +635,7 @@ var TransactionsModule = class {
|
|
|
609
635
|
*/
|
|
610
636
|
async offramp(data) {
|
|
611
637
|
if (!data.txHash || data.txHash.trim() === "") {
|
|
612
|
-
throw new Error(
|
|
613
|
-
"txHash is required for offramp transactions."
|
|
614
|
-
);
|
|
638
|
+
throw new Error("txHash is required for offramp transactions.");
|
|
615
639
|
}
|
|
616
640
|
const payload = {
|
|
617
641
|
payee_id: data.payeeId,
|
|
@@ -660,9 +684,7 @@ var TransactionsModule = class {
|
|
|
660
684
|
*/
|
|
661
685
|
async offrampTest(data) {
|
|
662
686
|
if (!data.txHash || data.txHash.trim() === "") {
|
|
663
|
-
throw new Error(
|
|
664
|
-
"txHash is required for offramp transactions."
|
|
665
|
-
);
|
|
687
|
+
throw new Error("txHash is required for offramp transactions.");
|
|
666
688
|
}
|
|
667
689
|
const payload = {
|
|
668
690
|
payee_id: data.payeeId,
|
|
@@ -684,12 +706,12 @@ var TransactionsModule = class {
|
|
|
684
706
|
}
|
|
685
707
|
/**
|
|
686
708
|
* List transactions with optional filters
|
|
687
|
-
*
|
|
709
|
+
*
|
|
688
710
|
* @example
|
|
689
711
|
* ```typescript
|
|
690
712
|
* // Get all transactions
|
|
691
713
|
* const allTransactions = await diviswap.transactions.list();
|
|
692
|
-
*
|
|
714
|
+
*
|
|
693
715
|
* // Get only completed onramp transactions
|
|
694
716
|
* const completedOnramps = await diviswap.transactions.list({
|
|
695
717
|
* type: 'onramp',
|
|
@@ -727,7 +749,7 @@ var TransactionsModule = class {
|
|
|
727
749
|
}
|
|
728
750
|
/**
|
|
729
751
|
* Get a specific transaction by ID
|
|
730
|
-
*
|
|
752
|
+
*
|
|
731
753
|
* @example
|
|
732
754
|
* ```typescript
|
|
733
755
|
* const transaction = await diviswap.transactions.get('transaction-id');
|
|
@@ -744,7 +766,7 @@ var TransactionsModule = class {
|
|
|
744
766
|
}
|
|
745
767
|
/**
|
|
746
768
|
* Get fee estimate for a transaction
|
|
747
|
-
*
|
|
769
|
+
*
|
|
748
770
|
* @example
|
|
749
771
|
* ```typescript
|
|
750
772
|
* const estimate = await diviswap.transactions.estimateFees({
|
|
@@ -760,7 +782,7 @@ var TransactionsModule = class {
|
|
|
760
782
|
}
|
|
761
783
|
/**
|
|
762
784
|
* Get recent transactions (convenience method)
|
|
763
|
-
*
|
|
785
|
+
*
|
|
764
786
|
* @example
|
|
765
787
|
* ```typescript
|
|
766
788
|
* const recentTransactions = await diviswap.transactions.getRecent(10);
|
|
@@ -771,7 +793,7 @@ var TransactionsModule = class {
|
|
|
771
793
|
}
|
|
772
794
|
/**
|
|
773
795
|
* Get transaction statistics
|
|
774
|
-
*
|
|
796
|
+
*
|
|
775
797
|
* @example
|
|
776
798
|
* ```typescript
|
|
777
799
|
* const stats = await diviswap.transactions.getStats();
|
|
@@ -780,21 +802,24 @@ var TransactionsModule = class {
|
|
|
780
802
|
*/
|
|
781
803
|
async getStats() {
|
|
782
804
|
const transactions = await this.list();
|
|
783
|
-
const stats = transactions.reduce(
|
|
784
|
-
acc
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
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
|
|
790
821
|
}
|
|
791
|
-
|
|
792
|
-
}, {
|
|
793
|
-
totalTransactions: 0,
|
|
794
|
-
totalVolume: 0,
|
|
795
|
-
pendingTransactions: 0,
|
|
796
|
-
completedTransactions: 0
|
|
797
|
-
});
|
|
822
|
+
);
|
|
798
823
|
return stats;
|
|
799
824
|
}
|
|
800
825
|
/**
|
|
@@ -816,11 +841,11 @@ var KycModule = class {
|
|
|
816
841
|
}
|
|
817
842
|
/**
|
|
818
843
|
* Get current compliance status including KYC and KYB
|
|
819
|
-
*
|
|
844
|
+
*
|
|
820
845
|
* @example
|
|
821
846
|
* ```typescript
|
|
822
847
|
* const status = await diviswap.kyc.getComplianceStatus();
|
|
823
|
-
*
|
|
848
|
+
*
|
|
824
849
|
* if (!status.canTransact) {
|
|
825
850
|
* if (status.nextStep === 'COMPLETE_KYC') {
|
|
826
851
|
* // Redirect to KYC flow
|
|
@@ -845,19 +870,21 @@ var KycModule = class {
|
|
|
845
870
|
kycMetadata: kycData?.metadata
|
|
846
871
|
};
|
|
847
872
|
} catch (error) {
|
|
848
|
-
throw new Error(
|
|
873
|
+
throw new Error(
|
|
874
|
+
`Failed to get compliance status: ${error.message}`
|
|
875
|
+
);
|
|
849
876
|
}
|
|
850
877
|
}
|
|
851
878
|
/**
|
|
852
879
|
* Start KYC verification session (opens Sumsub widget)
|
|
853
|
-
*
|
|
880
|
+
*
|
|
854
881
|
* @example
|
|
855
882
|
* ```typescript
|
|
856
883
|
* const session = await diviswap.kyc.startKycSession();
|
|
857
|
-
*
|
|
884
|
+
*
|
|
858
885
|
* // Redirect user to session URL
|
|
859
886
|
* window.location.href = session.sessionUrl;
|
|
860
|
-
*
|
|
887
|
+
*
|
|
861
888
|
* // Or embed in iframe
|
|
862
889
|
* const iframe = document.createElement('iframe');
|
|
863
890
|
* iframe.src = session.sessionUrl;
|
|
@@ -868,7 +895,7 @@ var KycModule = class {
|
|
|
868
895
|
}
|
|
869
896
|
/**
|
|
870
897
|
* Submit KYC documents programmatically
|
|
871
|
-
*
|
|
898
|
+
*
|
|
872
899
|
* @example
|
|
873
900
|
* ```typescript
|
|
874
901
|
* // Convert file to base64
|
|
@@ -878,10 +905,10 @@ var KycModule = class {
|
|
|
878
905
|
* reader.onload = () => resolve(reader.result as string);
|
|
879
906
|
* reader.onerror = reject;
|
|
880
907
|
* });
|
|
881
|
-
*
|
|
908
|
+
*
|
|
882
909
|
* const frontImage = await toBase64(frontFile);
|
|
883
910
|
* const backImage = await toBase64(backFile);
|
|
884
|
-
*
|
|
911
|
+
*
|
|
885
912
|
* await diviswap.kyc.submitDocuments({
|
|
886
913
|
* type: 'DRIVERS_LICENSE',
|
|
887
914
|
* frontImage,
|
|
@@ -894,13 +921,15 @@ var KycModule = class {
|
|
|
894
921
|
throw new ValidationError("Front image is required");
|
|
895
922
|
}
|
|
896
923
|
if (["DRIVERS_LICENSE", "ID_CARD"].includes(documents.type) && !documents.backImage) {
|
|
897
|
-
throw new ValidationError(
|
|
924
|
+
throw new ValidationError(
|
|
925
|
+
`Back image is required for ${documents.type}`
|
|
926
|
+
);
|
|
898
927
|
}
|
|
899
928
|
throw new Error("KYC documents endpoint not available in v1 API yet");
|
|
900
929
|
}
|
|
901
930
|
/**
|
|
902
931
|
* Submit personal information for KYC
|
|
903
|
-
*
|
|
932
|
+
*
|
|
904
933
|
* @example
|
|
905
934
|
* ```typescript
|
|
906
935
|
* await diviswap.kyc.submitPersonalInfo({
|
|
@@ -929,18 +958,25 @@ var KycModule = class {
|
|
|
929
958
|
throw new ValidationError("Complete address is required");
|
|
930
959
|
}
|
|
931
960
|
try {
|
|
932
|
-
const response = await this.client.post(
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
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
|
+
);
|
|
944
980
|
return response;
|
|
945
981
|
} catch (error) {
|
|
946
982
|
throw new Error(`Failed to submit KYC info: ${error.message}`);
|
|
@@ -948,7 +984,7 @@ var KycModule = class {
|
|
|
948
984
|
}
|
|
949
985
|
/**
|
|
950
986
|
* Check if user can transact (convenience method)
|
|
951
|
-
*
|
|
987
|
+
*
|
|
952
988
|
* @example
|
|
953
989
|
* ```typescript
|
|
954
990
|
* const canTransact = await diviswap.kyc.canTransact();
|
|
@@ -963,7 +999,7 @@ var KycModule = class {
|
|
|
963
999
|
}
|
|
964
1000
|
/**
|
|
965
1001
|
* Check if KYC is approved
|
|
966
|
-
*
|
|
1002
|
+
*
|
|
967
1003
|
* @example
|
|
968
1004
|
* ```typescript
|
|
969
1005
|
* const isApproved = await diviswap.kyc.isKycApproved();
|
|
@@ -975,7 +1011,7 @@ var KycModule = class {
|
|
|
975
1011
|
}
|
|
976
1012
|
/**
|
|
977
1013
|
* Check if KYB is approved (for business accounts)
|
|
978
|
-
*
|
|
1014
|
+
*
|
|
979
1015
|
* @example
|
|
980
1016
|
* ```typescript
|
|
981
1017
|
* const isBusinessApproved = await diviswap.kyc.isKybApproved();
|
|
@@ -987,7 +1023,7 @@ var KycModule = class {
|
|
|
987
1023
|
}
|
|
988
1024
|
/**
|
|
989
1025
|
* Get rejection reasons if KYC/KYB was rejected
|
|
990
|
-
*
|
|
1026
|
+
*
|
|
991
1027
|
* @example
|
|
992
1028
|
* ```typescript
|
|
993
1029
|
* const reasons = await diviswap.kyc.getRejectionReasons();
|
|
@@ -1006,13 +1042,13 @@ var KycModule = class {
|
|
|
1006
1042
|
}
|
|
1007
1043
|
/**
|
|
1008
1044
|
* Wait for KYC approval (polling)
|
|
1009
|
-
*
|
|
1045
|
+
*
|
|
1010
1046
|
* @example
|
|
1011
1047
|
* ```typescript
|
|
1012
1048
|
* // Start KYC session
|
|
1013
1049
|
* const session = await diviswap.kyc.startKycSession();
|
|
1014
1050
|
* window.open(session.sessionUrl);
|
|
1015
|
-
*
|
|
1051
|
+
*
|
|
1016
1052
|
* // Wait for approval (polls every 5 seconds for up to 10 minutes)
|
|
1017
1053
|
* try {
|
|
1018
1054
|
* await diviswap.kyc.waitForApproval();
|
|
@@ -1032,7 +1068,9 @@ var KycModule = class {
|
|
|
1032
1068
|
return status;
|
|
1033
1069
|
}
|
|
1034
1070
|
if (status.kycStatus === "REJECTED") {
|
|
1035
|
-
throw new Error(
|
|
1071
|
+
throw new Error(
|
|
1072
|
+
`KYC rejected: ${status.kycMetadata?.rejectLabels?.join(", ") || "Unknown reason"}`
|
|
1073
|
+
);
|
|
1036
1074
|
}
|
|
1037
1075
|
attempts++;
|
|
1038
1076
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
@@ -1063,9 +1101,12 @@ var FeesModule = class {
|
|
|
1063
1101
|
*/
|
|
1064
1102
|
async setFee(data) {
|
|
1065
1103
|
if (data.userId) {
|
|
1066
|
-
await this.client.put(
|
|
1067
|
-
|
|
1068
|
-
|
|
1104
|
+
await this.client.put(
|
|
1105
|
+
`/api/v1/partner/users/${data.userId}/fee`,
|
|
1106
|
+
{
|
|
1107
|
+
percentage: data.percentage
|
|
1108
|
+
}
|
|
1109
|
+
);
|
|
1069
1110
|
return {
|
|
1070
1111
|
integratorFeePercentage: data.percentage,
|
|
1071
1112
|
baseFeePercentage: 1.5,
|
|
@@ -1117,10 +1158,13 @@ var FeesModule = class {
|
|
|
1117
1158
|
* ```
|
|
1118
1159
|
*/
|
|
1119
1160
|
async calculateFees(params) {
|
|
1120
|
-
const response = await this.client.post(
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
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
|
+
);
|
|
1124
1168
|
return {
|
|
1125
1169
|
amount: response.amount,
|
|
1126
1170
|
baseFee: response.base_fee,
|
|
@@ -1166,7 +1210,7 @@ var AddressesModule = class {
|
|
|
1166
1210
|
}
|
|
1167
1211
|
/**
|
|
1168
1212
|
* Get all addresses for the authenticated user
|
|
1169
|
-
*
|
|
1213
|
+
*
|
|
1170
1214
|
* @example
|
|
1171
1215
|
* ```typescript
|
|
1172
1216
|
* const addresses = await diviswap.addresses.list();
|
|
@@ -1179,7 +1223,7 @@ var AddressesModule = class {
|
|
|
1179
1223
|
}
|
|
1180
1224
|
/**
|
|
1181
1225
|
* Create a new crypto address for the user
|
|
1182
|
-
*
|
|
1226
|
+
*
|
|
1183
1227
|
* @example
|
|
1184
1228
|
* ```typescript
|
|
1185
1229
|
* const address = await diviswap.addresses.create({
|
|
@@ -1200,7 +1244,7 @@ var AddressesModule = class {
|
|
|
1200
1244
|
}
|
|
1201
1245
|
/**
|
|
1202
1246
|
* Set a specific address as the default for its chain
|
|
1203
|
-
*
|
|
1247
|
+
*
|
|
1204
1248
|
* @example
|
|
1205
1249
|
* ```typescript
|
|
1206
1250
|
* await diviswap.addresses.setDefault({
|
|
@@ -1214,7 +1258,7 @@ var AddressesModule = class {
|
|
|
1214
1258
|
}
|
|
1215
1259
|
/**
|
|
1216
1260
|
* Delete a crypto address
|
|
1217
|
-
*
|
|
1261
|
+
*
|
|
1218
1262
|
* @example
|
|
1219
1263
|
* ```typescript
|
|
1220
1264
|
* await diviswap.addresses.delete({
|
|
@@ -1228,7 +1272,7 @@ var AddressesModule = class {
|
|
|
1228
1272
|
}
|
|
1229
1273
|
/**
|
|
1230
1274
|
* Get addresses for a specific chain
|
|
1231
|
-
*
|
|
1275
|
+
*
|
|
1232
1276
|
* @example
|
|
1233
1277
|
* ```typescript
|
|
1234
1278
|
* const ethAddresses = await diviswap.addresses.getByChain(1);
|
|
@@ -1242,7 +1286,7 @@ var AddressesModule = class {
|
|
|
1242
1286
|
}
|
|
1243
1287
|
/**
|
|
1244
1288
|
* Get the default address for a specific chain
|
|
1245
|
-
*
|
|
1289
|
+
*
|
|
1246
1290
|
* @example
|
|
1247
1291
|
* ```typescript
|
|
1248
1292
|
* const defaultEthAddress = await diviswap.addresses.getDefault(1);
|
|
@@ -1252,11 +1296,13 @@ var AddressesModule = class {
|
|
|
1252
1296
|
async getDefault(chainIdOrName) {
|
|
1253
1297
|
const chainId = typeof chainIdOrName === "string" ? CHAIN_IDS[chainIdOrName] : chainIdOrName;
|
|
1254
1298
|
const addresses = await this.list();
|
|
1255
|
-
return addresses.find(
|
|
1299
|
+
return addresses.find(
|
|
1300
|
+
(addr) => addr.chain_id === chainId && addr.is_default
|
|
1301
|
+
) || null;
|
|
1256
1302
|
}
|
|
1257
1303
|
/**
|
|
1258
1304
|
* Check if an address exists for the user
|
|
1259
|
-
*
|
|
1305
|
+
*
|
|
1260
1306
|
* @example
|
|
1261
1307
|
* ```typescript
|
|
1262
1308
|
* const exists = await diviswap.addresses.exists({
|
|
@@ -1274,7 +1320,7 @@ var AddressesModule = class {
|
|
|
1274
1320
|
/**
|
|
1275
1321
|
* Automatically track a wallet connection
|
|
1276
1322
|
* This is the main method for automatic address tracking
|
|
1277
|
-
*
|
|
1323
|
+
*
|
|
1278
1324
|
* @example
|
|
1279
1325
|
* ```typescript
|
|
1280
1326
|
* // When user connects wallet
|
|
@@ -1310,7 +1356,7 @@ var AddressesModule = class {
|
|
|
1310
1356
|
}
|
|
1311
1357
|
/**
|
|
1312
1358
|
* Auto-track multiple wallet connections (useful for multi-chain wallets)
|
|
1313
|
-
*
|
|
1359
|
+
*
|
|
1314
1360
|
* @example
|
|
1315
1361
|
* ```typescript
|
|
1316
1362
|
* // When user connects a multi-chain wallet
|
|
@@ -1328,7 +1374,10 @@ var AddressesModule = class {
|
|
|
1328
1374
|
const address = await this.trackWallet(connection);
|
|
1329
1375
|
results.push(address);
|
|
1330
1376
|
} catch (error) {
|
|
1331
|
-
console.error(
|
|
1377
|
+
console.error(
|
|
1378
|
+
`Failed to track wallet for chain ${connection.chainId}:`,
|
|
1379
|
+
error
|
|
1380
|
+
);
|
|
1332
1381
|
}
|
|
1333
1382
|
}
|
|
1334
1383
|
return results;
|
|
@@ -1387,10 +1436,13 @@ var WebhooksModule = class {
|
|
|
1387
1436
|
* ```
|
|
1388
1437
|
*/
|
|
1389
1438
|
async setConfigForPartner(partnerId, data) {
|
|
1390
|
-
const response = await this.client.put(
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
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
|
+
);
|
|
1394
1446
|
return response;
|
|
1395
1447
|
}
|
|
1396
1448
|
/**
|
|
@@ -1404,14 +1456,18 @@ var WebhooksModule = class {
|
|
|
1404
1456
|
* ```
|
|
1405
1457
|
*/
|
|
1406
1458
|
async getConfig() {
|
|
1407
|
-
const response = await this.client.get(
|
|
1459
|
+
const response = await this.client.get(
|
|
1460
|
+
"/api/v1/partner/webhook"
|
|
1461
|
+
);
|
|
1408
1462
|
return response;
|
|
1409
1463
|
}
|
|
1410
1464
|
/**
|
|
1411
1465
|
* Get webhook config for a specific partner (user-owned)
|
|
1412
1466
|
*/
|
|
1413
1467
|
async getConfigForPartner(partnerId) {
|
|
1414
|
-
const response = await this.client.get(
|
|
1468
|
+
const response = await this.client.get(
|
|
1469
|
+
`/api/v1/partners/${partnerId}/webhook`
|
|
1470
|
+
);
|
|
1415
1471
|
return response;
|
|
1416
1472
|
}
|
|
1417
1473
|
/**
|
|
@@ -1588,7 +1644,10 @@ var TokenManager = class {
|
|
|
1588
1644
|
this.refreshPromise = refreshCallback(refreshToken);
|
|
1589
1645
|
try {
|
|
1590
1646
|
const newTokenData = await this.refreshPromise;
|
|
1591
|
-
this.setTokens(
|
|
1647
|
+
this.setTokens(
|
|
1648
|
+
newTokenData.accessToken,
|
|
1649
|
+
newTokenData.refreshToken || refreshToken
|
|
1650
|
+
);
|
|
1592
1651
|
return newTokenData.accessToken;
|
|
1593
1652
|
} finally {
|
|
1594
1653
|
this.refreshPromise = null;
|
|
@@ -1632,7 +1691,7 @@ var PartnerAuth = class {
|
|
|
1632
1691
|
].join("\n");
|
|
1633
1692
|
const signature = crypto__default.default.createHmac("sha256", this.credentials.secretKey).update(canonical).digest("base64");
|
|
1634
1693
|
const headers = {
|
|
1635
|
-
|
|
1694
|
+
Authorization: `HMAC ${this.credentials.keyId}:${signature}:${timestamp}:${nonce}`,
|
|
1636
1695
|
"X-Client-Id": this.credentials.keyId
|
|
1637
1696
|
};
|
|
1638
1697
|
if (this.credentials.customerId) {
|
|
@@ -1654,7 +1713,7 @@ var PartnerAuth = class {
|
|
|
1654
1713
|
*/
|
|
1655
1714
|
generateJWT(options = {}) {
|
|
1656
1715
|
const {
|
|
1657
|
-
audience = "api.
|
|
1716
|
+
audience = "api.diviswap.com",
|
|
1658
1717
|
expiresIn = 300,
|
|
1659
1718
|
// 5 minutes max
|
|
1660
1719
|
scopes = []
|
|
@@ -1669,13 +1728,21 @@ var PartnerAuth = class {
|
|
|
1669
1728
|
// Expiration (max 5 minutes)
|
|
1670
1729
|
iat: now,
|
|
1671
1730
|
// Issued at
|
|
1672
|
-
...this.credentials.customerId && {
|
|
1673
|
-
|
|
1731
|
+
...this.credentials.customerId && {
|
|
1732
|
+
sub: this.credentials.customerId
|
|
1733
|
+
},
|
|
1734
|
+
...this.credentials.customerEmail && {
|
|
1735
|
+
email: this.credentials.customerEmail
|
|
1736
|
+
},
|
|
1674
1737
|
...scopes.length > 0 && { scope: scopes }
|
|
1675
1738
|
};
|
|
1676
1739
|
const header = { alg: "HS256", typ: "JWT" };
|
|
1677
|
-
const encodedHeader = Buffer.from(JSON.stringify(header)).toString(
|
|
1678
|
-
|
|
1740
|
+
const encodedHeader = Buffer.from(JSON.stringify(header)).toString(
|
|
1741
|
+
"base64url"
|
|
1742
|
+
);
|
|
1743
|
+
const encodedPayload = Buffer.from(JSON.stringify(payload)).toString(
|
|
1744
|
+
"base64url"
|
|
1745
|
+
);
|
|
1679
1746
|
const signature = crypto__default.default.createHmac("sha256", this.credentials.secretKey).update(`${encodedHeader}.${encodedPayload}`).digest("base64url");
|
|
1680
1747
|
return `${encodedHeader}.${encodedPayload}.${signature}`;
|
|
1681
1748
|
}
|
|
@@ -1714,51 +1781,63 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1714
1781
|
*/
|
|
1715
1782
|
static fromUserConfig(config, useLocalStorage = true) {
|
|
1716
1783
|
const baseUrl = config.apiUrl || this.getDefaultApiUrl(config.environment || "production");
|
|
1717
|
-
return new _UnifiedApiClient(
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
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
|
+
);
|
|
1725
1795
|
}
|
|
1726
1796
|
/**
|
|
1727
1797
|
* Create client from partner config
|
|
1728
1798
|
*/
|
|
1729
1799
|
static fromPartnerConfig(config, useLocalStorage = true) {
|
|
1730
1800
|
const baseUrl = config.apiUrl || this.getDefaultApiUrl(config.environment || "production");
|
|
1731
|
-
return new _UnifiedApiClient(
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
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
|
+
);
|
|
1742
1815
|
}
|
|
1743
1816
|
/**
|
|
1744
1817
|
* Create client from any config (auto-detect mode)
|
|
1745
1818
|
*/
|
|
1746
1819
|
static fromConfig(config, useLocalStorage = true) {
|
|
1747
1820
|
if ("mode" in config && config.mode === "partner" || "keyId" in config && "secretKey" in config) {
|
|
1748
|
-
return this.fromPartnerConfig(
|
|
1821
|
+
return this.fromPartnerConfig(
|
|
1822
|
+
config,
|
|
1823
|
+
useLocalStorage
|
|
1824
|
+
);
|
|
1749
1825
|
} else {
|
|
1750
|
-
return this.fromUserConfig(
|
|
1826
|
+
return this.fromUserConfig(
|
|
1827
|
+
config,
|
|
1828
|
+
useLocalStorage
|
|
1829
|
+
);
|
|
1751
1830
|
}
|
|
1752
1831
|
}
|
|
1753
1832
|
static getDefaultApiUrl(environment) {
|
|
1754
1833
|
switch (environment) {
|
|
1755
1834
|
case "production":
|
|
1756
1835
|
case "sandbox":
|
|
1757
|
-
return "https://api.
|
|
1836
|
+
return "https://api.diviswap.com";
|
|
1758
1837
|
case "development":
|
|
1759
|
-
return "https://dev-api.
|
|
1838
|
+
return "https://dev-api.diviswap.com";
|
|
1760
1839
|
default:
|
|
1761
|
-
return "https://api.
|
|
1840
|
+
return "https://api.diviswap.com";
|
|
1762
1841
|
}
|
|
1763
1842
|
}
|
|
1764
1843
|
/**
|
|
@@ -1824,7 +1903,14 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1824
1903
|
* Make authenticated API request
|
|
1825
1904
|
*/
|
|
1826
1905
|
async request(options) {
|
|
1827
|
-
const {
|
|
1906
|
+
const {
|
|
1907
|
+
method,
|
|
1908
|
+
path,
|
|
1909
|
+
body,
|
|
1910
|
+
headers = {},
|
|
1911
|
+
useApiKey = false,
|
|
1912
|
+
skipAuth = false
|
|
1913
|
+
} = options;
|
|
1828
1914
|
const url = `${this.config.baseUrl}${path}`;
|
|
1829
1915
|
const requestHeaders = {
|
|
1830
1916
|
"Content-Type": "application/json",
|
|
@@ -1840,7 +1926,10 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1840
1926
|
}
|
|
1841
1927
|
try {
|
|
1842
1928
|
const controller = new AbortController();
|
|
1843
|
-
const timeoutId = setTimeout(
|
|
1929
|
+
const timeoutId = setTimeout(
|
|
1930
|
+
() => controller.abort(),
|
|
1931
|
+
this.config.timeout
|
|
1932
|
+
);
|
|
1844
1933
|
if (this.config.debug) {
|
|
1845
1934
|
console.log(`[Diviswap SDK] ${method} ${url}`);
|
|
1846
1935
|
}
|
|
@@ -1859,7 +1948,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1859
1948
|
responseData = responseText;
|
|
1860
1949
|
}
|
|
1861
1950
|
if (this.config.debug) {
|
|
1862
|
-
console.log(
|
|
1951
|
+
console.log(
|
|
1952
|
+
`[Diviswap SDK] Response ${response.status}: ${responseText.substring(0, 500)}`
|
|
1953
|
+
);
|
|
1863
1954
|
}
|
|
1864
1955
|
if (!response.ok) {
|
|
1865
1956
|
await this.handleErrorResponse(response, responseData);
|
|
@@ -1880,7 +1971,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1880
1971
|
*/
|
|
1881
1972
|
async addPartnerAuth(method, path, body, headers) {
|
|
1882
1973
|
if (!this.partnerAuth) {
|
|
1883
|
-
throw new AuthenticationError(
|
|
1974
|
+
throw new AuthenticationError(
|
|
1975
|
+
"Partner authentication not configured"
|
|
1976
|
+
);
|
|
1884
1977
|
}
|
|
1885
1978
|
const bodyString = body ? JSON.stringify(body) : "";
|
|
1886
1979
|
const urlParts = path.split("?");
|
|
@@ -1888,7 +1981,7 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1888
1981
|
const queryString = urlParts.length > 1 ? urlParts[1] : "";
|
|
1889
1982
|
if (this.config.authMethod === "jwt") {
|
|
1890
1983
|
const jwt = this.partnerAuth.generateJWT({
|
|
1891
|
-
audience: "api.
|
|
1984
|
+
audience: "api.diviswap.com",
|
|
1892
1985
|
expiresIn: 300
|
|
1893
1986
|
});
|
|
1894
1987
|
headers["Authorization"] = `Bearer ${jwt}`;
|
|
@@ -1913,7 +2006,9 @@ var UnifiedApiClient = class _UnifiedApiClient {
|
|
|
1913
2006
|
headers["X-TIMESTAMP"] = Math.floor(Date.now() / 1e3).toString();
|
|
1914
2007
|
headers["X-API-Key"] = this.config.apiKey;
|
|
1915
2008
|
if (!useApiKey) {
|
|
1916
|
-
const accessToken = await this.tokenManager.getValidAccessToken(
|
|
2009
|
+
const accessToken = await this.tokenManager.getValidAccessToken(
|
|
2010
|
+
this.refreshCallback
|
|
2011
|
+
);
|
|
1917
2012
|
if (accessToken) {
|
|
1918
2013
|
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
1919
2014
|
}
|
|
@@ -1971,7 +2066,10 @@ var _Diviswap = class _Diviswap {
|
|
|
1971
2066
|
this.apiClient = UnifiedApiClient.fromConfig(config, useLocalStorage);
|
|
1972
2067
|
this.auth = new AuthModule(this.apiClient);
|
|
1973
2068
|
this.payees = new PayeesModule(this.apiClient);
|
|
1974
|
-
this.transactions = new TransactionsModule(
|
|
2069
|
+
this.transactions = new TransactionsModule(
|
|
2070
|
+
this.apiClient,
|
|
2071
|
+
config.environment || "sandbox"
|
|
2072
|
+
);
|
|
1975
2073
|
this.kyc = new KycModule(this.apiClient);
|
|
1976
2074
|
this.fees = new FeesModule(this.apiClient);
|
|
1977
2075
|
this.addresses = new AddressesModule(this.apiClient);
|
|
@@ -2003,7 +2101,9 @@ var _Diviswap = class _Diviswap {
|
|
|
2003
2101
|
*/
|
|
2004
2102
|
static getInstance() {
|
|
2005
2103
|
if (!_Diviswap.instance) {
|
|
2006
|
-
throw new ConfigurationError(
|
|
2104
|
+
throw new ConfigurationError(
|
|
2105
|
+
"Diviswap SDK not initialized. Call Diviswap.init() first."
|
|
2106
|
+
);
|
|
2007
2107
|
}
|
|
2008
2108
|
return _Diviswap.instance;
|
|
2009
2109
|
}
|
|
@@ -2018,7 +2118,9 @@ var _Diviswap = class _Diviswap {
|
|
|
2018
2118
|
* @deprecated Configuration updates require re-initialization. Call Diviswap.reset() then Diviswap.init() with new config.
|
|
2019
2119
|
*/
|
|
2020
2120
|
updateConfig(_config) {
|
|
2021
|
-
throw new ConfigurationError(
|
|
2121
|
+
throw new ConfigurationError(
|
|
2122
|
+
"Configuration updates require re-initialization. Call Diviswap.reset() then Diviswap.init() with new config."
|
|
2123
|
+
);
|
|
2022
2124
|
}
|
|
2023
2125
|
/**
|
|
2024
2126
|
* Get current configuration (excluding sensitive data)
|
|
@@ -2040,7 +2142,7 @@ var _Diviswap = class _Diviswap {
|
|
|
2040
2142
|
* const token = await diviswap.getAccessToken();
|
|
2041
2143
|
* if (token) {
|
|
2042
2144
|
* // Use token for custom API calls
|
|
2043
|
-
* fetch('https://api.
|
|
2145
|
+
* fetch('https://api.diviswap.com/custom-endpoint', {
|
|
2044
2146
|
* headers: { 'Authorization': `Bearer ${token}` }
|
|
2045
2147
|
* });
|
|
2046
2148
|
* }
|
|
@@ -2091,25 +2193,39 @@ var _Diviswap = class _Diviswap {
|
|
|
2091
2193
|
if (isPartnerMode) {
|
|
2092
2194
|
const partnerConfig = config;
|
|
2093
2195
|
if (!partnerConfig.keyId) {
|
|
2094
|
-
throw new ConfigurationError(
|
|
2196
|
+
throw new ConfigurationError(
|
|
2197
|
+
"Partner keyId is required for partner authentication"
|
|
2198
|
+
);
|
|
2095
2199
|
}
|
|
2096
2200
|
if (!partnerConfig.secretKey) {
|
|
2097
|
-
throw new ConfigurationError(
|
|
2201
|
+
throw new ConfigurationError(
|
|
2202
|
+
"Partner secretKey is required for partner authentication"
|
|
2203
|
+
);
|
|
2098
2204
|
}
|
|
2099
2205
|
if (partnerConfig.authMethod && !["hmac", "jwt"].includes(partnerConfig.authMethod)) {
|
|
2100
|
-
throw new ConfigurationError(
|
|
2206
|
+
throw new ConfigurationError(
|
|
2207
|
+
'Invalid authMethod. Must be either "hmac" or "jwt"'
|
|
2208
|
+
);
|
|
2101
2209
|
}
|
|
2102
2210
|
} else {
|
|
2103
2211
|
const userConfig = config;
|
|
2104
2212
|
if (!userConfig.apiKey) {
|
|
2105
|
-
throw new ConfigurationError(
|
|
2213
|
+
throw new ConfigurationError(
|
|
2214
|
+
"API Key is required for user authentication"
|
|
2215
|
+
);
|
|
2106
2216
|
}
|
|
2107
2217
|
if (!userConfig.clientId) {
|
|
2108
|
-
throw new ConfigurationError(
|
|
2218
|
+
throw new ConfigurationError(
|
|
2219
|
+
"Client ID is required for user authentication"
|
|
2220
|
+
);
|
|
2109
2221
|
}
|
|
2110
2222
|
}
|
|
2111
|
-
if (config.environment && !["production", "sandbox", "development"].includes(
|
|
2112
|
-
|
|
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
|
+
);
|
|
2113
2229
|
}
|
|
2114
2230
|
}
|
|
2115
2231
|
};
|
|
@@ -2284,7 +2400,9 @@ var _WalletTracker = class _WalletTracker {
|
|
|
2284
2400
|
* Get chain name from chain ID
|
|
2285
2401
|
*/
|
|
2286
2402
|
getChainName(chainId) {
|
|
2287
|
-
const builtInChain = Object.entries(CHAIN_IDS).find(
|
|
2403
|
+
const builtInChain = Object.entries(CHAIN_IDS).find(
|
|
2404
|
+
([_, id]) => id === chainId
|
|
2405
|
+
)?.[0];
|
|
2288
2406
|
if (builtInChain) return builtInChain;
|
|
2289
2407
|
return this.config.customChains?.[chainId];
|
|
2290
2408
|
}
|