@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 LiberEx
3
+ Copyright (c) 2024 Diviswap
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
- apiKey: 'your-api-key',
25
- clientId: 'your-client-id',
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
- // Start KYC verification
39
- const session = await diviswap.kyc.startKycSession();
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 onramp transaction (buy crypto)
54
- const transaction = await diviswap.transactions.onramp({
55
- amount: 100,
56
- currency: 'USD',
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
- toAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f6E123'
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
- // Get user profile
93
- const user = await diviswap.auth.getProfile();
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
- // Verify with micro-deposits
149
- await diviswap.payees.verify(payee.id, {
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: 'onramp'
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
- // Calculate fees for transparency
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
- apiKey: 'your-api-key', // Required
342
- clientId: 'your-client-id', // Required
343
- environment: 'production', // Optional: 'production' | 'sandbox' | 'development'
344
- apiUrl: 'https://custom.api', // Optional: Override default API URL
345
- debug: false, // Optional: Enable debug logging
346
- timeout: 30000, // Optional: Request timeout in ms
347
- defaultFee: 0.5 // Optional: Your default fee % (default: 0.5)
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.io`
354
- - **Sandbox**: `https://sandbox.api.diviswap.io`
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
- - API keys and Client IDs are required for all requests
360
- - Requests are signed with HMAC-SHA256
361
- - Tokens are automatically refreshed when expired
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 Onramp Flow
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 buyBitcoin() {
363
+ async function sellCrypto() {
374
364
  // Initialize SDK
375
365
  const diviswap = Diviswap.init({
376
- apiKey: process.env.DIVISWAP_API_KEY,
377
- clientId: process.env.DIVISWAP_CLIENT_ID,
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
- // Check fee estimate
410
- const estimate = await diviswap.transactions.estimateFees({
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
- console.log(`You'll pay $${estimate.fee} in fees`);
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
- // Create transaction
419
- const tx = await diviswap.transactions.onramp({
420
- amount: 100,
421
- currency: 'USD',
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
- toAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f6E123'
411
+ chain: 'ethereum',
412
+ txHash: '0x...' // Transaction hash from step 1
424
413
  });
425
414
 
426
- console.log(`Transaction ${tx.id} created!`);
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
- buyBitcoin();
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
- apiKey: process.env.DIVISWAP_API_KEY,
444
- clientId: process.env.DIVISWAP_CLIENT_ID,
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.io
505
- - Documentation: https://docs.diviswap.io
506
- - Issues: https://github.com/diviswap/sdk/issues
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
- // If no args or first arg is not a flag, assume create-app
15
- args.unshift('create-app');
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
- stdio: 'inherit',
20
- env: process.env
19
+ stdio: 'inherit',
20
+ env: process.env,
21
21
  });
22
22
 
23
23
  child.on('exit', (code) => {
24
- process.exit(code || 0);
24
+ process.exit(code || 0);
25
25
  });