@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/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -17,12 +17,14 @@ pnpm add @diviswap/sdk
|
|
|
17
17
|
### Basic Usage
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
|
-
import Diviswap from '@diviswap/sdk';
|
|
20
|
+
import { Diviswap } from '@diviswap/sdk';
|
|
21
21
|
|
|
22
22
|
// Initialize the SDK
|
|
23
23
|
const diviswap = Diviswap.init({
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
mode: 'partner',
|
|
25
|
+
keyId: process.env.DIVISWAP_PARTNER_KEY_ID,
|
|
26
|
+
secretKey: process.env.DIVISWAP_PARTNER_SECRET_KEY,
|
|
27
|
+
authMethod: 'hmac',
|
|
26
28
|
environment: 'sandbox' // or 'production'
|
|
27
29
|
});
|
|
28
30
|
|
|
@@ -35,10 +37,8 @@ const { user } = await diviswap.auth.register({
|
|
|
35
37
|
// Check KYC status
|
|
36
38
|
const compliance = await diviswap.kyc.getComplianceStatus();
|
|
37
39
|
if (!compliance.canTransact) {
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
// Redirect user to complete KYC
|
|
41
|
-
window.location.href = session.sessionUrl;
|
|
40
|
+
// KYC verification required - redirect to your KYC flow
|
|
41
|
+
console.log('KYC required:', compliance.nextStep);
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -50,12 +50,15 @@ const payee = await diviswap.payees.create({
|
|
|
50
50
|
accountType: 'checking'
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
// Create an
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
// Create an offramp transaction (sell crypto for fiat)
|
|
54
|
+
// First send crypto, then record the transaction
|
|
55
|
+
const transaction = await diviswap.transactions.offramp({
|
|
56
|
+
amount: 0.5,
|
|
57
|
+
currency: 'ETH',
|
|
58
|
+
fromAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f6E123',
|
|
57
59
|
payeeId: payee.id,
|
|
58
|
-
|
|
60
|
+
chain: 'ethereum',
|
|
61
|
+
txHash: '0x...' // Your crypto transaction hash
|
|
59
62
|
});
|
|
60
63
|
```
|
|
61
64
|
|
|
@@ -89,8 +92,8 @@ await diviswap.auth.login({
|
|
|
89
92
|
password: 'password'
|
|
90
93
|
});
|
|
91
94
|
|
|
92
|
-
//
|
|
93
|
-
const
|
|
95
|
+
// Check if authenticated
|
|
96
|
+
const isLoggedIn = diviswap.auth.isAuthenticated();
|
|
94
97
|
|
|
95
98
|
// Logout
|
|
96
99
|
await diviswap.auth.logout();
|
|
@@ -105,10 +108,6 @@ if (!status.canTransact) {
|
|
|
105
108
|
console.log('KYC required:', status.nextStep);
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
// Start KYC verification
|
|
109
|
-
const session = await diviswap.kyc.startKycSession();
|
|
110
|
-
// Redirect to: session.sessionUrl
|
|
111
|
-
|
|
112
111
|
// Check if KYC approved
|
|
113
112
|
const isApproved = await diviswap.kyc.isKycApproved();
|
|
114
113
|
|
|
@@ -145,35 +144,27 @@ const payees = await diviswap.payees.list();
|
|
|
145
144
|
// Set default payee
|
|
146
145
|
await diviswap.payees.setDefault(payee.id);
|
|
147
146
|
|
|
148
|
-
//
|
|
149
|
-
await diviswap.payees.
|
|
150
|
-
amount1: 0.32,
|
|
151
|
-
amount2: 0.45
|
|
152
|
-
});
|
|
147
|
+
// Delete a payee
|
|
148
|
+
await diviswap.payees.delete(payee.id);
|
|
153
149
|
```
|
|
154
150
|
|
|
155
151
|
### Transactions
|
|
152
|
+
**IMPORTANT: If no transaction hash is supplied, the offramp will fail.**
|
|
156
153
|
|
|
157
154
|
```typescript
|
|
158
|
-
// Onramp (buy crypto with fiat)
|
|
159
|
-
const onramp = await diviswap.transactions.onramp({
|
|
160
|
-
amount: 100,
|
|
161
|
-
currency: 'USD',
|
|
162
|
-
payeeId: 'payee-id',
|
|
163
|
-
toAddress: '0x...'
|
|
164
|
-
});
|
|
165
|
-
|
|
166
155
|
// Offramp (sell crypto for fiat)
|
|
156
|
+
// IMPORTANT: Send crypto first, then call offramp with the tx hash
|
|
167
157
|
const offramp = await diviswap.transactions.offramp({
|
|
168
158
|
amount: 0.5,
|
|
169
159
|
currency: 'ETH',
|
|
170
160
|
fromAddress: '0x...',
|
|
171
|
-
payeeId: 'payee-id'
|
|
161
|
+
payeeId: 'payee-id',
|
|
162
|
+
chain: 'ethereum',
|
|
163
|
+
txHash: '0x...' // Required: hash from your crypto transaction.
|
|
172
164
|
});
|
|
173
165
|
|
|
174
166
|
// List transactions
|
|
175
167
|
const transactions = await diviswap.transactions.list({
|
|
176
|
-
type: 'onramp',
|
|
177
168
|
status: 'completed'
|
|
178
169
|
});
|
|
179
170
|
|
|
@@ -181,8 +172,11 @@ const transactions = await diviswap.transactions.list({
|
|
|
181
172
|
const estimate = await diviswap.transactions.estimateFees({
|
|
182
173
|
amount: 100,
|
|
183
174
|
currency: 'USD',
|
|
184
|
-
type: '
|
|
175
|
+
type: 'offramp'
|
|
185
176
|
});
|
|
177
|
+
|
|
178
|
+
// Get recent transactions
|
|
179
|
+
const recent = await diviswap.transactions.getRecent(10);
|
|
186
180
|
```
|
|
187
181
|
|
|
188
182
|
### Address Management
|
|
@@ -306,18 +300,15 @@ CHAIN_IDS.arbitrumSepolia // 421614
|
|
|
306
300
|
// Set your custom fee (default is 0.5%)
|
|
307
301
|
await diviswap.fees.setFee({ percentage: 0.75 });
|
|
308
302
|
|
|
309
|
-
//
|
|
303
|
+
// Get current fee settings
|
|
304
|
+
const fees = await diviswap.fees.getFees();
|
|
305
|
+
console.log(`Total fee: ${fees.totalFeePercentage}%`);
|
|
306
|
+
|
|
307
|
+
// Calculate fees for a specific amount
|
|
310
308
|
const calc = await diviswap.fees.calculateFees({ amount: 100 });
|
|
311
309
|
console.log(`Diviswap fee: $${calc.baseFee} (1.5%)`);
|
|
312
310
|
console.log(`Your earnings: $${calc.integratorFee} (0.75%)`);
|
|
313
311
|
console.log(`Total fee: $${calc.totalFee}`);
|
|
314
|
-
|
|
315
|
-
// Track your earnings
|
|
316
|
-
const earnings = await diviswap.fees.getEarnings({
|
|
317
|
-
startDate: '2024-01-01',
|
|
318
|
-
endDate: '2024-01-31'
|
|
319
|
-
});
|
|
320
|
-
console.log(`Monthly revenue: $${earnings.totalEarned}`);
|
|
321
312
|
```
|
|
322
313
|
|
|
323
314
|
## Monetization
|
|
@@ -328,7 +319,6 @@ Earn revenue from every transaction with customizable integrator fees:
|
|
|
328
319
|
- **Fully customizable** - Set any fee percentage
|
|
329
320
|
- **Per-user pricing** - Different fees for different user tiers
|
|
330
321
|
- **Transparent** - Users see exact fee breakdowns
|
|
331
|
-
- **Real-time tracking** - Monitor your earnings
|
|
332
322
|
|
|
333
323
|
See the [Integrator Fees Guide](docs/guides/integrator-fees.md) for details.
|
|
334
324
|
|
|
@@ -338,43 +328,45 @@ See the [Integrator Fees Guide](docs/guides/integrator-fees.md) for details.
|
|
|
338
328
|
|
|
339
329
|
```typescript
|
|
340
330
|
Diviswap.init({
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
331
|
+
mode: 'partner', // Required: 'partner' for partner authentication
|
|
332
|
+
keyId: 'pk_...', // Required: Your Partner Key ID
|
|
333
|
+
secretKey: 'sk_...', // Required: Your Partner Secret Key
|
|
334
|
+
authMethod: 'hmac', // Optional: 'hmac' (default) or 'jwt'
|
|
335
|
+
environment: 'production', // Optional: 'production' | 'sandbox' | 'development'
|
|
336
|
+
debug: false, // Optional: Enable debug logging
|
|
337
|
+
timeout: 30000 // Optional: Request timeout in ms
|
|
348
338
|
});
|
|
349
339
|
```
|
|
350
340
|
|
|
351
341
|
### Environments
|
|
352
342
|
|
|
353
|
-
- **Production**: `https://api.diviswap.
|
|
354
|
-
- **Sandbox**: `https://
|
|
343
|
+
- **Production**: `https://api.diviswap.com`
|
|
344
|
+
- **Sandbox**: `https://api.diviswap.com` (uses sandbox partner credentials)
|
|
355
345
|
- **Development**: `http://localhost:5000`
|
|
356
346
|
|
|
357
347
|
## Security
|
|
358
348
|
|
|
359
|
-
-
|
|
360
|
-
-
|
|
361
|
-
-
|
|
349
|
+
- Partner authentication with HMAC-SHA256 request signing (recommended) or JWT
|
|
350
|
+
- Partner credentials (keyId/secretKey) are required for all requests
|
|
351
|
+
- User sessions managed via JWT tokens after login
|
|
362
352
|
- Sensitive data is never logged in debug mode
|
|
363
353
|
- KYC verification required before transactions
|
|
364
354
|
- All user data encrypted and stored securely
|
|
365
355
|
|
|
366
356
|
## Examples
|
|
367
357
|
|
|
368
|
-
### Complete
|
|
358
|
+
### Complete Offramp Flow
|
|
369
359
|
|
|
370
360
|
```typescript
|
|
371
|
-
import Diviswap from '@diviswap/sdk';
|
|
361
|
+
import { Diviswap } from '@diviswap/sdk';
|
|
372
362
|
|
|
373
|
-
async function
|
|
363
|
+
async function sellCrypto() {
|
|
374
364
|
// Initialize SDK
|
|
375
365
|
const diviswap = Diviswap.init({
|
|
376
|
-
|
|
377
|
-
|
|
366
|
+
mode: 'partner',
|
|
367
|
+
keyId: process.env.DIVISWAP_PARTNER_KEY_ID,
|
|
368
|
+
secretKey: process.env.DIVISWAP_PARTNER_SECRET_KEY,
|
|
369
|
+
authMethod: 'hmac',
|
|
378
370
|
environment: 'sandbox'
|
|
379
371
|
});
|
|
380
372
|
|
|
@@ -388,9 +380,7 @@ async function buyBitcoin() {
|
|
|
388
380
|
// Check KYC status
|
|
389
381
|
const compliance = await diviswap.kyc.getComplianceStatus();
|
|
390
382
|
if (!compliance.canTransact) {
|
|
391
|
-
console.log('KYC verification required');
|
|
392
|
-
const session = await diviswap.kyc.startKycSession();
|
|
393
|
-
console.log('Complete KYC at:', session.sessionUrl);
|
|
383
|
+
console.log('KYC verification required:', compliance.nextStep);
|
|
394
384
|
return;
|
|
395
385
|
}
|
|
396
386
|
|
|
@@ -406,31 +396,30 @@ async function buyBitcoin() {
|
|
|
406
396
|
});
|
|
407
397
|
}
|
|
408
398
|
|
|
409
|
-
//
|
|
410
|
-
const
|
|
411
|
-
amount: 100,
|
|
412
|
-
currency: 'USD',
|
|
413
|
-
type: 'onramp'
|
|
414
|
-
});
|
|
399
|
+
// Get deposit address for the chain
|
|
400
|
+
const depositAddress = diviswap.transactions.getDepositAddressForChain('ethereum');
|
|
415
401
|
|
|
416
|
-
|
|
402
|
+
// 1. First, send crypto to the deposit address (using your wallet library)
|
|
403
|
+
// const txHash = await sendTransaction({ to: depositAddress, value: amount });
|
|
417
404
|
|
|
418
|
-
//
|
|
419
|
-
const tx = await diviswap.transactions.
|
|
420
|
-
amount:
|
|
421
|
-
currency: '
|
|
405
|
+
// 2. Then record the offramp transaction with the tx hash
|
|
406
|
+
const tx = await diviswap.transactions.offramp({
|
|
407
|
+
amount: 0.5,
|
|
408
|
+
currency: 'ETH',
|
|
409
|
+
fromAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f6E123',
|
|
422
410
|
payeeId: payee.id,
|
|
423
|
-
|
|
411
|
+
chain: 'ethereum',
|
|
412
|
+
txHash: '0x...' // Transaction hash from step 1
|
|
424
413
|
});
|
|
425
414
|
|
|
426
|
-
console.log(`
|
|
415
|
+
console.log(`Offramp ${tx.id} created!`);
|
|
427
416
|
|
|
428
417
|
} catch (error) {
|
|
429
418
|
console.error('Error:', error);
|
|
430
419
|
}
|
|
431
420
|
}
|
|
432
421
|
|
|
433
|
-
|
|
422
|
+
sellCrypto();
|
|
434
423
|
```
|
|
435
424
|
|
|
436
425
|
### Complete Wallet Integration Flow
|
|
@@ -440,8 +429,10 @@ import { Diviswap, connectWallet, useWalletAddresses } from '@diviswap/sdk';
|
|
|
440
429
|
|
|
441
430
|
async function integrateWallet() {
|
|
442
431
|
const diviswap = Diviswap.init({
|
|
443
|
-
|
|
444
|
-
|
|
432
|
+
mode: 'partner',
|
|
433
|
+
keyId: process.env.DIVISWAP_PARTNER_KEY_ID,
|
|
434
|
+
secretKey: process.env.DIVISWAP_PARTNER_SECRET_KEY,
|
|
435
|
+
authMethod: 'hmac',
|
|
445
436
|
environment: 'sandbox'
|
|
446
437
|
});
|
|
447
438
|
|
|
@@ -501,9 +492,9 @@ try {
|
|
|
501
492
|
|
|
502
493
|
## Support
|
|
503
494
|
|
|
504
|
-
- Email: support@diviswap.
|
|
505
|
-
- Documentation: https://docs.diviswap.
|
|
506
|
-
- Issues: https://github.com/diviswap
|
|
495
|
+
- Email: support@diviswap.com
|
|
496
|
+
- Documentation: https://docs.diviswap.com
|
|
497
|
+
- Issues: https://github.com/liberex-sv/diviswap-sdk/issues
|
|
507
498
|
|
|
508
499
|
## License
|
|
509
500
|
|
|
@@ -11,15 +11,15 @@ const cliPath = join(__dirname, '..', 'dist', 'cli', 'index.js');
|
|
|
11
11
|
// Forward all arguments to the main CLI, defaulting to create-app if no command specified
|
|
12
12
|
const args = process.argv.slice(2);
|
|
13
13
|
if (args.length === 0 || !args[0].startsWith('-')) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// If no args or first arg is not a flag, assume create-app
|
|
15
|
+
args.unshift('create-app');
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const child = spawn('node', [cliPath, ...args], {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
stdio: 'inherit',
|
|
20
|
+
env: process.env,
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
child.on('exit', (code) => {
|
|
24
|
-
|
|
24
|
+
process.exit(code || 0);
|
|
25
25
|
});
|