@diviswap/sdk 1.7.6
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 +21 -0
- package/README.md +510 -0
- package/bin/create-diviswap-app.js +25 -0
- package/bin/diviswap-sdk.js +4 -0
- package/dist/cli/index.js +1888 -0
- package/dist/cli/templates/nextjs-app/actions.ts.hbs +259 -0
- package/dist/cli/templates/nextjs-app/api-hooks.ts.hbs +439 -0
- package/dist/cli/templates/nextjs-app/api-route.ts.hbs +502 -0
- package/dist/cli/templates/nextjs-app/auth-context.tsx.hbs +59 -0
- package/dist/cli/templates/nextjs-app/client.ts.hbs +116 -0
- package/dist/cli/templates/nextjs-app/dashboard-hooks.ts.hbs +180 -0
- package/dist/cli/templates/nextjs-app/example-page.tsx.hbs +276 -0
- package/dist/cli/templates/nextjs-app/hooks.ts.hbs +252 -0
- package/dist/cli/templates/nextjs-app/kyc-hooks.ts.hbs +87 -0
- package/dist/cli/templates/nextjs-app/kyc-wizard.css.hbs +433 -0
- package/dist/cli/templates/nextjs-app/kyc-wizard.tsx.hbs +711 -0
- package/dist/cli/templates/nextjs-app/layout-wrapper.tsx.hbs +13 -0
- package/dist/cli/templates/nextjs-app/layout.tsx.hbs +13 -0
- package/dist/cli/templates/nextjs-app/middleware.ts.hbs +49 -0
- package/dist/cli/templates/nextjs-app/provider-wrapper.tsx.hbs +8 -0
- package/dist/cli/templates/nextjs-app/provider.tsx.hbs +408 -0
- package/dist/cli/templates/nextjs-app/setup-provider.tsx.hbs +25 -0
- package/dist/cli/templates/nextjs-app/types.ts.hbs +159 -0
- package/dist/cli/templates/react/api-client-wrapper.ts.hbs +89 -0
- package/dist/cli/templates/react/example.tsx.hbs +69 -0
- package/dist/cli/templates/react/tanstack-hooks.ts.hbs +185 -0
- package/dist/cli/templates/webhooks/nextjs.hbs +98 -0
- package/dist/index.d.mts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +2339 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2313 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react/index.d.mts +192 -0
- package/dist/react/index.d.ts +192 -0
- package/dist/react/index.js +1083 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +1064 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/wallet-BEGvzNtB.d.mts +1614 -0
- package/dist/wallet-BEGvzNtB.d.ts +1614 -0
- package/package.json +102 -0
- package/src/cli/templates/index.ts +65 -0
- package/src/cli/templates/nextjs-app/actions.ts.hbs +259 -0
- package/src/cli/templates/nextjs-app/api-hooks.ts.hbs +439 -0
- package/src/cli/templates/nextjs-app/api-route.ts.hbs +502 -0
- package/src/cli/templates/nextjs-app/auth-context.tsx.hbs +59 -0
- package/src/cli/templates/nextjs-app/client.ts.hbs +116 -0
- package/src/cli/templates/nextjs-app/dashboard-hooks.ts.hbs +180 -0
- package/src/cli/templates/nextjs-app/example-page.tsx.hbs +276 -0
- package/src/cli/templates/nextjs-app/hooks.ts.hbs +252 -0
- package/src/cli/templates/nextjs-app/kyc-hooks.ts.hbs +87 -0
- package/src/cli/templates/nextjs-app/kyc-wizard.css.hbs +433 -0
- package/src/cli/templates/nextjs-app/kyc-wizard.tsx.hbs +711 -0
- package/src/cli/templates/nextjs-app/layout-wrapper.tsx.hbs +13 -0
- package/src/cli/templates/nextjs-app/layout.tsx.hbs +13 -0
- package/src/cli/templates/nextjs-app/middleware.ts.hbs +49 -0
- package/src/cli/templates/nextjs-app/provider-wrapper.tsx.hbs +8 -0
- package/src/cli/templates/nextjs-app/provider.tsx.hbs +408 -0
- package/src/cli/templates/nextjs-app/setup-provider.tsx.hbs +25 -0
- package/src/cli/templates/nextjs-app/types.ts.hbs +159 -0
- package/src/cli/templates/react/api-client-wrapper.ts.hbs +89 -0
- package/src/cli/templates/react/example.tsx.hbs +69 -0
- package/src/cli/templates/react/tanstack-hooks.ts.hbs +185 -0
- package/src/cli/templates/shared/client.ts +78 -0
- package/src/cli/templates/webhooks/nextjs.hbs +98 -0
|
@@ -0,0 +1,1614 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for Diviswap SDK
|
|
3
|
+
*/
|
|
4
|
+
type Environment = 'production' | 'sandbox' | 'development';
|
|
5
|
+
type AuthMode = 'user' | 'partner';
|
|
6
|
+
interface BaseDiviswapConfig {
|
|
7
|
+
/** Environment to use (defaults to 'production') */
|
|
8
|
+
environment?: Environment;
|
|
9
|
+
/** Custom API URL (optional) */
|
|
10
|
+
apiUrl?: string;
|
|
11
|
+
/** Enable debug logging (defaults to false) */
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
/** Request timeout in milliseconds (defaults to 30000) */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
/** Default integrator fee percentage (defaults to 0.5%) */
|
|
16
|
+
defaultFee?: number;
|
|
17
|
+
/** Token storage strategy: 'localStorage' (default), 'memory' (for iframes), or 'custom' */
|
|
18
|
+
tokenStorage?: 'localStorage' | 'memory' | 'custom';
|
|
19
|
+
/** Custom token storage implementation (required when tokenStorage is 'custom') */
|
|
20
|
+
customTokenStorage?: {
|
|
21
|
+
get: () => {
|
|
22
|
+
accessToken: string | null;
|
|
23
|
+
refreshToken: string | null;
|
|
24
|
+
};
|
|
25
|
+
set: (accessToken: string, refreshToken?: string) => void;
|
|
26
|
+
clear: () => void;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
interface UserDiviswapConfig extends BaseDiviswapConfig {
|
|
30
|
+
/** Your Diviswap API Key */
|
|
31
|
+
apiKey: string;
|
|
32
|
+
/** Your Diviswap Client ID */
|
|
33
|
+
clientId: string;
|
|
34
|
+
/** Authentication mode (automatically set to 'user') */
|
|
35
|
+
mode?: 'user';
|
|
36
|
+
}
|
|
37
|
+
interface PartnerDiviswapConfig extends BaseDiviswapConfig {
|
|
38
|
+
/** Authentication mode (optional - auto-detected from keyId/secretKey) */
|
|
39
|
+
mode?: 'partner';
|
|
40
|
+
/** Partner key ID (pk_...) */
|
|
41
|
+
keyId: string;
|
|
42
|
+
/** Partner secret key (sk_...) */
|
|
43
|
+
secretKey: string;
|
|
44
|
+
/** Authentication method: 'hmac' (default) or 'jwt' */
|
|
45
|
+
authMethod?: 'hmac' | 'jwt';
|
|
46
|
+
/** Customer ID in your system (for shadow user linking) */
|
|
47
|
+
customerId?: string;
|
|
48
|
+
/** Customer email (for shadow user linking) */
|
|
49
|
+
customerEmail?: string;
|
|
50
|
+
}
|
|
51
|
+
type DiviswapConfig = UserDiviswapConfig | PartnerDiviswapConfig;
|
|
52
|
+
/** @deprecated Use DiviswapConfig instead */
|
|
53
|
+
type LiberExConfig = DiviswapConfig;
|
|
54
|
+
/** @deprecated Use UserDiviswapConfig instead */
|
|
55
|
+
type UserLiberExConfig = UserDiviswapConfig;
|
|
56
|
+
/** @deprecated Use PartnerDiviswapConfig instead */
|
|
57
|
+
type PartnerLiberExConfig = PartnerDiviswapConfig;
|
|
58
|
+
interface LegacyDiviswapConfig {
|
|
59
|
+
apiKey: string;
|
|
60
|
+
clientId: string;
|
|
61
|
+
environment?: Environment;
|
|
62
|
+
apiUrl?: string;
|
|
63
|
+
debug?: boolean;
|
|
64
|
+
timeout?: number;
|
|
65
|
+
defaultFee?: number;
|
|
66
|
+
tokenStorage?: 'localStorage' | 'memory' | 'custom';
|
|
67
|
+
customTokenStorage?: {
|
|
68
|
+
get: () => {
|
|
69
|
+
accessToken: string | null;
|
|
70
|
+
refreshToken: string | null;
|
|
71
|
+
};
|
|
72
|
+
set: (accessToken: string, refreshToken?: string) => void;
|
|
73
|
+
clear: () => void;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
interface AuthCredentials {
|
|
77
|
+
email: string;
|
|
78
|
+
password: string;
|
|
79
|
+
}
|
|
80
|
+
interface User {
|
|
81
|
+
id: string;
|
|
82
|
+
email: string;
|
|
83
|
+
firstName?: string;
|
|
84
|
+
lastName?: string;
|
|
85
|
+
phone?: string;
|
|
86
|
+
kycStatus?: KycStatus;
|
|
87
|
+
kybStatus?: KybStatus;
|
|
88
|
+
createdAt: string;
|
|
89
|
+
updatedAt: string;
|
|
90
|
+
}
|
|
91
|
+
interface IndividualData {
|
|
92
|
+
residential_country_code: string;
|
|
93
|
+
residential_address_line_one: string;
|
|
94
|
+
residential_address_line_two?: string;
|
|
95
|
+
residential_city: string;
|
|
96
|
+
residential_state: string;
|
|
97
|
+
residential_postal_code: string;
|
|
98
|
+
id_country_code: string;
|
|
99
|
+
dob: string;
|
|
100
|
+
id_number: string;
|
|
101
|
+
}
|
|
102
|
+
interface RegisterRequest extends AuthCredentials {
|
|
103
|
+
firstName?: string;
|
|
104
|
+
lastName?: string;
|
|
105
|
+
phone?: string;
|
|
106
|
+
referralCode?: string;
|
|
107
|
+
individual?: IndividualData;
|
|
108
|
+
}
|
|
109
|
+
interface AuthResponse {
|
|
110
|
+
accessToken: string;
|
|
111
|
+
refreshToken?: string;
|
|
112
|
+
user: User;
|
|
113
|
+
}
|
|
114
|
+
interface Payee {
|
|
115
|
+
id: string;
|
|
116
|
+
nickname: string;
|
|
117
|
+
accountNumber: string;
|
|
118
|
+
routingNumber: string;
|
|
119
|
+
accountType: 'checking' | 'savings';
|
|
120
|
+
isDefault: boolean;
|
|
121
|
+
verified: boolean;
|
|
122
|
+
createdAt: string;
|
|
123
|
+
updatedAt: string;
|
|
124
|
+
}
|
|
125
|
+
interface CreatePayeeRequest {
|
|
126
|
+
nickname: string;
|
|
127
|
+
accountNumber?: string;
|
|
128
|
+
routingNumber?: string;
|
|
129
|
+
accountType: 'checking' | 'savings' | 'debit_card';
|
|
130
|
+
setAsDefault?: boolean;
|
|
131
|
+
debitCard?: {
|
|
132
|
+
number: string;
|
|
133
|
+
expirationMonth: string;
|
|
134
|
+
expirationYear: string;
|
|
135
|
+
cvv: string;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
interface Transaction {
|
|
139
|
+
id: string;
|
|
140
|
+
type?: 'onramp' | 'offramp';
|
|
141
|
+
status?: 'pending' | 'processing' | 'completed' | 'failed';
|
|
142
|
+
amount?: number;
|
|
143
|
+
currency?: string;
|
|
144
|
+
fromAddress?: string;
|
|
145
|
+
toAddress?: string;
|
|
146
|
+
payeeId?: string;
|
|
147
|
+
fee?: number;
|
|
148
|
+
createdAt?: string;
|
|
149
|
+
updatedAt?: string;
|
|
150
|
+
to_address?: string;
|
|
151
|
+
chain_id?: number;
|
|
152
|
+
message?: string;
|
|
153
|
+
test_mode?: boolean;
|
|
154
|
+
feature_flag_enabled?: boolean;
|
|
155
|
+
}
|
|
156
|
+
interface OnrampRequest {
|
|
157
|
+
amount: number;
|
|
158
|
+
currency: string;
|
|
159
|
+
payeeId: string;
|
|
160
|
+
toAddress: string;
|
|
161
|
+
chain?: string;
|
|
162
|
+
}
|
|
163
|
+
interface OfframpRequest {
|
|
164
|
+
amount: number;
|
|
165
|
+
currency: string;
|
|
166
|
+
fromAddress: string;
|
|
167
|
+
payeeId: string;
|
|
168
|
+
chain?: string;
|
|
169
|
+
memo?: string;
|
|
170
|
+
toAddress?: string;
|
|
171
|
+
txHash?: string;
|
|
172
|
+
}
|
|
173
|
+
interface ApiResponse<T = any> {
|
|
174
|
+
success: boolean;
|
|
175
|
+
data?: T;
|
|
176
|
+
error?: string;
|
|
177
|
+
message?: string;
|
|
178
|
+
}
|
|
179
|
+
type KycStatus = 'NOT_STARTED' | 'PENDING' | 'PENDING_VERIFICATION' | 'APPROVED' | 'REJECTED';
|
|
180
|
+
type KybStatus = 'NOT_STARTED' | 'PENDING' | 'PENDING_VERIFICATION' | 'APPROVED' | 'REJECTED';
|
|
181
|
+
interface KycMetadata {
|
|
182
|
+
applicantId?: string;
|
|
183
|
+
levelName?: string;
|
|
184
|
+
rejectLabels?: string[];
|
|
185
|
+
createdAt?: string;
|
|
186
|
+
reviewResult?: {
|
|
187
|
+
reviewAnswer?: string;
|
|
188
|
+
rejectLabels?: string[];
|
|
189
|
+
moderationComment?: string;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
interface KybMetadata {
|
|
193
|
+
applicantId?: string;
|
|
194
|
+
levelName?: string;
|
|
195
|
+
createdAt?: string;
|
|
196
|
+
}
|
|
197
|
+
interface OrganizationInfo {
|
|
198
|
+
id: string;
|
|
199
|
+
name: string;
|
|
200
|
+
businessName?: string;
|
|
201
|
+
businessType?: string;
|
|
202
|
+
ein?: string;
|
|
203
|
+
createdAt?: string;
|
|
204
|
+
needsVerification?: boolean;
|
|
205
|
+
}
|
|
206
|
+
interface ComplianceStatus {
|
|
207
|
+
kycStatus: KycStatus;
|
|
208
|
+
kycMetadata?: KycMetadata;
|
|
209
|
+
kybStatus: KybStatus;
|
|
210
|
+
kybMetadata?: KybMetadata;
|
|
211
|
+
organizationInfo?: OrganizationInfo;
|
|
212
|
+
canTransact: boolean;
|
|
213
|
+
requiresAction: boolean;
|
|
214
|
+
nextStep?: 'COMPLETE_KYC' | 'COMPLETE_KYB' | 'WAIT_FOR_APPROVAL' | null;
|
|
215
|
+
verificationLevel?: string;
|
|
216
|
+
kycUri?: string;
|
|
217
|
+
}
|
|
218
|
+
interface KycSessionResponse {
|
|
219
|
+
sessionUrl: string;
|
|
220
|
+
applicantId: string;
|
|
221
|
+
expiresAt: string;
|
|
222
|
+
}
|
|
223
|
+
interface KycDocumentRequest {
|
|
224
|
+
type: 'PASSPORT' | 'DRIVERS_LICENSE' | 'ID_CARD' | 'RESIDENCE_PERMIT';
|
|
225
|
+
frontImage: string;
|
|
226
|
+
backImage?: string;
|
|
227
|
+
}
|
|
228
|
+
interface KycPersonalInfo {
|
|
229
|
+
firstName: string;
|
|
230
|
+
lastName: string;
|
|
231
|
+
dateOfBirth: string;
|
|
232
|
+
ssn?: string;
|
|
233
|
+
phone?: string;
|
|
234
|
+
address: {
|
|
235
|
+
street: string;
|
|
236
|
+
city: string;
|
|
237
|
+
state: string;
|
|
238
|
+
postalCode: string;
|
|
239
|
+
country: string;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* JWT Token management with auto-refresh
|
|
245
|
+
*/
|
|
246
|
+
interface TokenData {
|
|
247
|
+
accessToken: string;
|
|
248
|
+
refreshToken?: string;
|
|
249
|
+
expiresAt?: number;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Token Manager handles JWT token lifecycle
|
|
253
|
+
*/
|
|
254
|
+
declare class TokenManager {
|
|
255
|
+
private storage;
|
|
256
|
+
private refreshPromise;
|
|
257
|
+
constructor(useLocalStorage?: boolean);
|
|
258
|
+
/**
|
|
259
|
+
* Parse JWT token to extract expiration
|
|
260
|
+
*/
|
|
261
|
+
private parseToken;
|
|
262
|
+
/**
|
|
263
|
+
* Store tokens
|
|
264
|
+
*/
|
|
265
|
+
setTokens(accessToken: string, refreshToken?: string): void;
|
|
266
|
+
/**
|
|
267
|
+
* Get current access token
|
|
268
|
+
*/
|
|
269
|
+
getAccessToken(): string | null;
|
|
270
|
+
/**
|
|
271
|
+
* Get refresh token
|
|
272
|
+
*/
|
|
273
|
+
getRefreshToken(): string | null;
|
|
274
|
+
/**
|
|
275
|
+
* Check if token is expired or about to expire (5 min buffer)
|
|
276
|
+
*/
|
|
277
|
+
isTokenExpired(): boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Clear all tokens
|
|
280
|
+
*/
|
|
281
|
+
clearTokens(): void;
|
|
282
|
+
/**
|
|
283
|
+
* Refresh access token
|
|
284
|
+
*/
|
|
285
|
+
refreshAccessToken(refreshCallback: (refreshToken: string) => Promise<TokenData>): Promise<string>;
|
|
286
|
+
/**
|
|
287
|
+
* Get valid access token (refresh if needed)
|
|
288
|
+
*/
|
|
289
|
+
getValidAccessToken(refreshCallback?: (refreshToken: string) => Promise<TokenData>): Promise<string | null>;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Unified API Client supporting both user and partner authentication
|
|
294
|
+
*/
|
|
295
|
+
|
|
296
|
+
interface UnifiedApiClientConfig {
|
|
297
|
+
baseUrl: string;
|
|
298
|
+
timeout: number;
|
|
299
|
+
debug: boolean;
|
|
300
|
+
mode: AuthMode;
|
|
301
|
+
apiKey?: string;
|
|
302
|
+
clientId?: string;
|
|
303
|
+
keyId?: string;
|
|
304
|
+
secretKey?: string;
|
|
305
|
+
authMethod?: 'hmac' | 'jwt';
|
|
306
|
+
customerId?: string;
|
|
307
|
+
customerEmail?: string;
|
|
308
|
+
}
|
|
309
|
+
interface RequestOptions {
|
|
310
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
311
|
+
path: string;
|
|
312
|
+
body?: any;
|
|
313
|
+
headers?: Record<string, string>;
|
|
314
|
+
useApiKey?: boolean;
|
|
315
|
+
skipAuth?: boolean;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Unified API client supporting both user and partner authentication modes
|
|
319
|
+
*/
|
|
320
|
+
declare class UnifiedApiClient {
|
|
321
|
+
private config;
|
|
322
|
+
tokenManager: TokenManager;
|
|
323
|
+
private partnerAuth?;
|
|
324
|
+
private refreshCallback?;
|
|
325
|
+
constructor(config: UnifiedApiClientConfig, useLocalStorage?: boolean);
|
|
326
|
+
/**
|
|
327
|
+
* Create client from legacy user config (backward compatibility)
|
|
328
|
+
*/
|
|
329
|
+
static fromUserConfig(config: UserDiviswapConfig, useLocalStorage?: boolean): UnifiedApiClient;
|
|
330
|
+
/**
|
|
331
|
+
* Create client from partner config
|
|
332
|
+
*/
|
|
333
|
+
static fromPartnerConfig(config: PartnerDiviswapConfig, useLocalStorage?: boolean): UnifiedApiClient;
|
|
334
|
+
/**
|
|
335
|
+
* Create client from any config (auto-detect mode)
|
|
336
|
+
*/
|
|
337
|
+
static fromConfig(config: DiviswapConfig, useLocalStorage?: boolean): UnifiedApiClient;
|
|
338
|
+
private static getDefaultApiUrl;
|
|
339
|
+
/**
|
|
340
|
+
* Update customer context for partner auth
|
|
341
|
+
*/
|
|
342
|
+
setCustomer(customerId: string, customerEmail?: string): void;
|
|
343
|
+
/**
|
|
344
|
+
* Clear customer context
|
|
345
|
+
*/
|
|
346
|
+
clearCustomer(): void;
|
|
347
|
+
/**
|
|
348
|
+
* Get authentication mode
|
|
349
|
+
*/
|
|
350
|
+
getAuthMode(): 'user' | 'partner';
|
|
351
|
+
/**
|
|
352
|
+
* Get current customer ID (partner mode only)
|
|
353
|
+
*/
|
|
354
|
+
getCustomerId(): string | undefined;
|
|
355
|
+
/**
|
|
356
|
+
* Set refresh callback for automatic token refresh (user mode only)
|
|
357
|
+
*/
|
|
358
|
+
setRefreshCallback(callback: (refreshToken: string) => Promise<TokenData>): void;
|
|
359
|
+
/**
|
|
360
|
+
* Set access token directly (user mode only)
|
|
361
|
+
*/
|
|
362
|
+
setTokens(accessToken: string, refreshToken?: string): void;
|
|
363
|
+
/**
|
|
364
|
+
* Get current access token (user mode only)
|
|
365
|
+
*/
|
|
366
|
+
getAccessToken(): Promise<string | null>;
|
|
367
|
+
/**
|
|
368
|
+
* Clear stored tokens (user mode only)
|
|
369
|
+
*/
|
|
370
|
+
clearTokens(): void;
|
|
371
|
+
/**
|
|
372
|
+
* Make authenticated API request
|
|
373
|
+
*/
|
|
374
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
375
|
+
/**
|
|
376
|
+
* Add partner authentication headers
|
|
377
|
+
*/
|
|
378
|
+
private addPartnerAuth;
|
|
379
|
+
/**
|
|
380
|
+
* Add user authentication headers (legacy)
|
|
381
|
+
*/
|
|
382
|
+
private addUserAuth;
|
|
383
|
+
private handleErrorResponse;
|
|
384
|
+
get<T>(path: string, options?: Omit<RequestOptions, 'method' | 'path'>): Promise<T>;
|
|
385
|
+
post<T>(path: string, body?: any, options?: Omit<RequestOptions, 'method' | 'path' | 'body'>): Promise<T>;
|
|
386
|
+
put<T>(path: string, body?: any, options?: Omit<RequestOptions, 'method' | 'path' | 'body'>): Promise<T>;
|
|
387
|
+
delete<T>(path: string, options?: Omit<RequestOptions, 'method' | 'path'>): Promise<T>;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Authentication module for Diviswap SDK
|
|
392
|
+
*/
|
|
393
|
+
|
|
394
|
+
declare class AuthModule {
|
|
395
|
+
private client;
|
|
396
|
+
constructor(client: UnifiedApiClient);
|
|
397
|
+
/**
|
|
398
|
+
* Register a new user
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```typescript
|
|
402
|
+
* const { user, accessToken } = await diviswap.auth.register({
|
|
403
|
+
* email: 'user@example.com',
|
|
404
|
+
* password: 'secure-password',
|
|
405
|
+
* firstName: 'John',
|
|
406
|
+
* lastName: 'Doe'
|
|
407
|
+
* });
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
register(data: RegisterRequest): Promise<AuthResponse>;
|
|
411
|
+
/**
|
|
412
|
+
* Login an existing user
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* const { user, accessToken } = await diviswap.auth.login({
|
|
417
|
+
* email: 'user@example.com',
|
|
418
|
+
* password: 'secure-password'
|
|
419
|
+
* });
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
login(credentials: AuthCredentials): Promise<AuthResponse>;
|
|
423
|
+
/**
|
|
424
|
+
* Get current user profile
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* const user = await diviswap.auth.getProfile();
|
|
429
|
+
* console.log(user.email, user.kycStatus);
|
|
430
|
+
* ```
|
|
431
|
+
*
|
|
432
|
+
* Note: This endpoint is not yet available in the v1 API
|
|
433
|
+
*/
|
|
434
|
+
getProfile(): Promise<User>;
|
|
435
|
+
/**
|
|
436
|
+
* Update user profile
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```typescript
|
|
440
|
+
* const updatedUser = await diviswap.auth.updateProfile({
|
|
441
|
+
* firstName: 'Jane',
|
|
442
|
+
* lastName: 'Smith'
|
|
443
|
+
* });
|
|
444
|
+
* ```
|
|
445
|
+
*
|
|
446
|
+
* Note: This endpoint is not yet available in the v1 API
|
|
447
|
+
*/
|
|
448
|
+
updateProfile(_data: Partial<User>): Promise<User>;
|
|
449
|
+
/**
|
|
450
|
+
* Request password reset
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```typescript
|
|
454
|
+
* await diviswap.auth.requestPasswordReset('user@example.com');
|
|
455
|
+
* ```
|
|
456
|
+
*
|
|
457
|
+
* Note: This endpoint is not yet available in the v1 API
|
|
458
|
+
*/
|
|
459
|
+
requestPasswordReset(_email: string): Promise<ApiResponse>;
|
|
460
|
+
/**
|
|
461
|
+
* Set new password with reset token
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* ```typescript
|
|
465
|
+
* await diviswap.auth.setPassword('reset-token', 'new-secure-password');
|
|
466
|
+
* ```
|
|
467
|
+
*
|
|
468
|
+
* Note: This endpoint is not yet available in the v1 API
|
|
469
|
+
*/
|
|
470
|
+
setPassword(_token: string, _password: string): Promise<ApiResponse>;
|
|
471
|
+
/**
|
|
472
|
+
* Logout current user
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```typescript
|
|
476
|
+
* await diviswap.auth.logout();
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
logout(): Promise<void>;
|
|
480
|
+
/**
|
|
481
|
+
* Get compliance status
|
|
482
|
+
* @deprecated Use diviswap.kyc.getComplianceStatus() instead
|
|
483
|
+
*/
|
|
484
|
+
getComplianceStatus(): Promise<any>;
|
|
485
|
+
/**
|
|
486
|
+
* Check if user is authenticated
|
|
487
|
+
*/
|
|
488
|
+
isAuthenticated(): boolean;
|
|
489
|
+
/**
|
|
490
|
+
* Refresh access token (internal)
|
|
491
|
+
*
|
|
492
|
+
* Note: This endpoint is not yet available in the v1 API
|
|
493
|
+
*/
|
|
494
|
+
private refreshToken;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Payees module for managing bank accounts
|
|
499
|
+
*/
|
|
500
|
+
|
|
501
|
+
interface VerifyPayeeRequest {
|
|
502
|
+
amount1: number;
|
|
503
|
+
amount2: number;
|
|
504
|
+
}
|
|
505
|
+
declare class PayeesModule {
|
|
506
|
+
private client;
|
|
507
|
+
constructor(client: UnifiedApiClient);
|
|
508
|
+
/**
|
|
509
|
+
* Create a new payee (bank account)
|
|
510
|
+
*
|
|
511
|
+
* @example
|
|
512
|
+
* ```typescript
|
|
513
|
+
* // Bank account
|
|
514
|
+
* const bankAccount = await diviswap.payees.create({
|
|
515
|
+
* nickname: 'My Checking',
|
|
516
|
+
* accountNumber: '123456789',
|
|
517
|
+
* routingNumber: '021000021',
|
|
518
|
+
* accountType: 'checking',
|
|
519
|
+
* setAsDefault: true
|
|
520
|
+
* });
|
|
521
|
+
*
|
|
522
|
+
* // Debit card
|
|
523
|
+
* const debitCard = await diviswap.payees.create({
|
|
524
|
+
* nickname: 'My Debit Card',
|
|
525
|
+
* accountType: 'debit_card',
|
|
526
|
+
* debitCard: {
|
|
527
|
+
* number: '4111111111111111',
|
|
528
|
+
* expirationMonth: '12',
|
|
529
|
+
* expirationYear: '2025',
|
|
530
|
+
* cvv: '123'
|
|
531
|
+
* },
|
|
532
|
+
* setAsDefault: false
|
|
533
|
+
* });
|
|
534
|
+
* ```
|
|
535
|
+
*/
|
|
536
|
+
create(data: CreatePayeeRequest): Promise<Payee>;
|
|
537
|
+
/**
|
|
538
|
+
* List all payees
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* ```typescript
|
|
542
|
+
* const payees = await diviswap.payees.list();
|
|
543
|
+
* const defaultPayee = payees.find(p => p.isDefault);
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
list(): Promise<Payee[]>;
|
|
547
|
+
private parsePayeesResponse;
|
|
548
|
+
/**
|
|
549
|
+
* Get a specific payee
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```typescript
|
|
553
|
+
* const payee = await diviswap.payees.get('payee-id');
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
get(payeeId: string): Promise<Payee>;
|
|
557
|
+
/**
|
|
558
|
+
* Set a payee as default
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* ```typescript
|
|
562
|
+
* await diviswap.payees.setDefault('payee-id');
|
|
563
|
+
* ```
|
|
564
|
+
*/
|
|
565
|
+
setDefault(payeeId: string): Promise<Payee>;
|
|
566
|
+
/**
|
|
567
|
+
* Delete a payee
|
|
568
|
+
*
|
|
569
|
+
* @example
|
|
570
|
+
* ```typescript
|
|
571
|
+
* await diviswap.payees.delete('payee-id');
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
delete(payeeId: string): Promise<ApiResponse>;
|
|
575
|
+
/**
|
|
576
|
+
* Get verification status of a payee
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* ```typescript
|
|
580
|
+
* const status = await diviswap.payees.getVerificationStatus('payee-id');
|
|
581
|
+
* console.log(status.verified, status.microDepositsStatus);
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
584
|
+
getVerificationStatus(_payeeId: string): Promise<any>;
|
|
585
|
+
/**
|
|
586
|
+
* Verify a payee with micro-deposit amounts
|
|
587
|
+
*
|
|
588
|
+
* @example
|
|
589
|
+
* ```typescript
|
|
590
|
+
* const result = await diviswap.payees.verify('payee-id', {
|
|
591
|
+
* amount1: 0.32,
|
|
592
|
+
* amount2: 0.45
|
|
593
|
+
* });
|
|
594
|
+
* ```
|
|
595
|
+
*/
|
|
596
|
+
verify(_payeeId: string, _data: VerifyPayeeRequest): Promise<ApiResponse>;
|
|
597
|
+
/**
|
|
598
|
+
* Get the default payee
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* ```typescript
|
|
602
|
+
* const defaultPayee = await diviswap.payees.getDefault();
|
|
603
|
+
* if (!defaultPayee) {
|
|
604
|
+
* console.log('No default payee set');
|
|
605
|
+
* }
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
getDefault(): Promise<Payee | null>;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Transactions module for crypto on/off ramps
|
|
613
|
+
*/
|
|
614
|
+
|
|
615
|
+
interface TransactionFilters {
|
|
616
|
+
type?: 'onramp' | 'offramp';
|
|
617
|
+
status?: 'pending' | 'processing' | 'completed' | 'failed';
|
|
618
|
+
startDate?: string;
|
|
619
|
+
endDate?: string;
|
|
620
|
+
limit?: number;
|
|
621
|
+
offset?: number;
|
|
622
|
+
}
|
|
623
|
+
interface FeeEstimate {
|
|
624
|
+
amount: number;
|
|
625
|
+
currency: string;
|
|
626
|
+
fee: number;
|
|
627
|
+
total: number;
|
|
628
|
+
}
|
|
629
|
+
declare class TransactionsModule {
|
|
630
|
+
private client;
|
|
631
|
+
private depositAddresses;
|
|
632
|
+
constructor(client: UnifiedApiClient, environment?: 'production' | 'sandbox' | 'development');
|
|
633
|
+
/**
|
|
634
|
+
* Map chain name to chain ID
|
|
635
|
+
* @private
|
|
636
|
+
*/
|
|
637
|
+
private getChainId;
|
|
638
|
+
/**
|
|
639
|
+
* Get deposit address for a given chain
|
|
640
|
+
* @private
|
|
641
|
+
*/
|
|
642
|
+
private getDepositAddress;
|
|
643
|
+
/**
|
|
644
|
+
* Get all configured deposit addresses
|
|
645
|
+
* @returns Object mapping chain names to deposit addresses
|
|
646
|
+
*/
|
|
647
|
+
getDepositAddresses(): Record<string, string>;
|
|
648
|
+
/**
|
|
649
|
+
* Get deposit address for a specific chain
|
|
650
|
+
* @param chain - Chain name (e.g., 'ethereum', 'base', 'polygon')
|
|
651
|
+
* @returns The deposit address for the specified chain
|
|
652
|
+
* @throws Error if chain is not supported
|
|
653
|
+
*/
|
|
654
|
+
getDepositAddressForChain(chain: string): string;
|
|
655
|
+
/**
|
|
656
|
+
* Create an onramp transaction (fiat to crypto)
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* ```typescript
|
|
660
|
+
* const transaction = await diviswap.transactions.onramp({
|
|
661
|
+
* amount: 100,
|
|
662
|
+
* currency: 'USD',
|
|
663
|
+
* payeeId: 'payee-id',
|
|
664
|
+
* toAddress: '0xa3da8ffC1D131F917f9D0Ac078D82914e75d9651',
|
|
665
|
+
* chain: 'ethereum'
|
|
666
|
+
* });
|
|
667
|
+
* ```
|
|
668
|
+
*
|
|
669
|
+
* @throws {Error} If user is not KYC approved
|
|
670
|
+
*/
|
|
671
|
+
onramp(_data: OnrampRequest): Promise<Transaction>;
|
|
672
|
+
/**
|
|
673
|
+
* Create an offramp transaction (crypto to fiat)
|
|
674
|
+
*
|
|
675
|
+
* ⚠️ IMPORTANT: Follow the production pattern:
|
|
676
|
+
* 1. Send crypto transaction on blockchain FIRST
|
|
677
|
+
* 2. Get the transaction hash
|
|
678
|
+
* 3. Call this method with the hash
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* ```typescript
|
|
682
|
+
* import { extractTransactionHash } from '@diviswap/sdk';
|
|
683
|
+
*
|
|
684
|
+
* // 1. Send crypto transaction first and get tx hash
|
|
685
|
+
* const txResult = await sendTransactionAsync({
|
|
686
|
+
* to: depositAddress,
|
|
687
|
+
* value: parseEther('0.5')
|
|
688
|
+
* });
|
|
689
|
+
*
|
|
690
|
+
* // 2. Extract hash (handles different wallet return types)
|
|
691
|
+
* const txHash = extractTransactionHash(txResult);
|
|
692
|
+
*
|
|
693
|
+
* // 3. Record the transaction
|
|
694
|
+
* const transaction = await diviswap.transactions.offramp({
|
|
695
|
+
* amount: 0.5,
|
|
696
|
+
* currency: 'ETH',
|
|
697
|
+
* fromAddress: '0xa3da8ffC1D131F917f9D0Ac078D82914e75d9651',
|
|
698
|
+
* payeeId: 'payee-id',
|
|
699
|
+
* chain: 'ethereum',
|
|
700
|
+
* txHash: txHash
|
|
701
|
+
* });
|
|
702
|
+
* ```
|
|
703
|
+
*
|
|
704
|
+
* @throws {Error} If user is not KYC approved
|
|
705
|
+
*/
|
|
706
|
+
offramp(data: OfframpRequest & {
|
|
707
|
+
txHash: string;
|
|
708
|
+
}): Promise<Transaction>;
|
|
709
|
+
/**
|
|
710
|
+
* Create a test offramp transaction using the same production flow.
|
|
711
|
+
* Requires a transaction hash - send crypto first, then call this method.
|
|
712
|
+
*
|
|
713
|
+
* ⚠️ IMPORTANT: Follow the production pattern:
|
|
714
|
+
* 1. Send crypto transaction on blockchain FIRST
|
|
715
|
+
* 2. Get the transaction hash
|
|
716
|
+
* 3. Call this method with the hash
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* ```typescript
|
|
720
|
+
* // 1. Send crypto transaction first and get tx hash
|
|
721
|
+
* const txHash = await sendCryptoTransaction({...});
|
|
722
|
+
*
|
|
723
|
+
* // 2. Record the transaction using production endpoint
|
|
724
|
+
* const transaction = await diviswap.transactions.offrampTest({
|
|
725
|
+
* amount: 0.1,
|
|
726
|
+
* currency: 'USDC',
|
|
727
|
+
* fromAddress: '0x...',
|
|
728
|
+
* toAddress: '0x...',
|
|
729
|
+
* payeeId: 'payee-id',
|
|
730
|
+
* chain: 'base',
|
|
731
|
+
* txHash: txHash
|
|
732
|
+
* });
|
|
733
|
+
* ```
|
|
734
|
+
*/
|
|
735
|
+
offrampTest(data: OfframpRequest & {
|
|
736
|
+
txHash: string;
|
|
737
|
+
}): Promise<Transaction>;
|
|
738
|
+
/**
|
|
739
|
+
* List transactions with optional filters
|
|
740
|
+
*
|
|
741
|
+
* @example
|
|
742
|
+
* ```typescript
|
|
743
|
+
* // Get all transactions
|
|
744
|
+
* const allTransactions = await diviswap.transactions.list();
|
|
745
|
+
*
|
|
746
|
+
* // Get only completed onramp transactions
|
|
747
|
+
* const completedOnramps = await diviswap.transactions.list({
|
|
748
|
+
* type: 'onramp',
|
|
749
|
+
* status: 'completed'
|
|
750
|
+
* });
|
|
751
|
+
* ```
|
|
752
|
+
*/
|
|
753
|
+
list(filters?: TransactionFilters): Promise<Transaction[]>;
|
|
754
|
+
/**
|
|
755
|
+
* Get a specific transaction by ID
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
758
|
+
* ```typescript
|
|
759
|
+
* const transaction = await diviswap.transactions.get('transaction-id');
|
|
760
|
+
* console.log(transaction.status, transaction.amount);
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
763
|
+
get(transactionId: string): Promise<Transaction>;
|
|
764
|
+
/**
|
|
765
|
+
* Get fee estimate for a transaction
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```typescript
|
|
769
|
+
* const estimate = await diviswap.transactions.estimateFees({
|
|
770
|
+
* amount: 100,
|
|
771
|
+
* currency: 'USD',
|
|
772
|
+
* type: 'onramp'
|
|
773
|
+
* });
|
|
774
|
+
* console.log(`Fee: $${estimate.fee}, Total: $${estimate.total}`);
|
|
775
|
+
* ```
|
|
776
|
+
*/
|
|
777
|
+
estimateFees(params: {
|
|
778
|
+
amount: number;
|
|
779
|
+
currency: string;
|
|
780
|
+
type: 'onramp' | 'offramp';
|
|
781
|
+
}): Promise<FeeEstimate>;
|
|
782
|
+
/**
|
|
783
|
+
* Get recent transactions (convenience method)
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* ```typescript
|
|
787
|
+
* const recentTransactions = await diviswap.transactions.getRecent(10);
|
|
788
|
+
* ```
|
|
789
|
+
*/
|
|
790
|
+
getRecent(limit?: number): Promise<Transaction[]>;
|
|
791
|
+
/**
|
|
792
|
+
* Get transaction statistics
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```typescript
|
|
796
|
+
* const stats = await diviswap.transactions.getStats();
|
|
797
|
+
* console.log(`Total volume: $${stats.totalVolume}`);
|
|
798
|
+
* ```
|
|
799
|
+
*/
|
|
800
|
+
getStats(): Promise<{
|
|
801
|
+
totalTransactions: number;
|
|
802
|
+
totalVolume: number;
|
|
803
|
+
pendingTransactions: number;
|
|
804
|
+
completedTransactions: number;
|
|
805
|
+
}>;
|
|
806
|
+
/**
|
|
807
|
+
* Get stablecoin addresses for a specific chain
|
|
808
|
+
* @param chain - Chain name (e.g., 'ethereum', 'base', 'polygon')
|
|
809
|
+
* @returns Object mapping stablecoin symbols to contract addresses
|
|
810
|
+
*/
|
|
811
|
+
getStablecoinAddresses(chain: string): Record<string, string>;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* KYC/KYB module for identity verification
|
|
816
|
+
*/
|
|
817
|
+
|
|
818
|
+
declare class KycModule {
|
|
819
|
+
private readonly client;
|
|
820
|
+
constructor(client: UnifiedApiClient);
|
|
821
|
+
/**
|
|
822
|
+
* Get current compliance status including KYC and KYB
|
|
823
|
+
*
|
|
824
|
+
* @example
|
|
825
|
+
* ```typescript
|
|
826
|
+
* const status = await diviswap.kyc.getComplianceStatus();
|
|
827
|
+
*
|
|
828
|
+
* if (!status.canTransact) {
|
|
829
|
+
* if (status.nextStep === 'COMPLETE_KYC') {
|
|
830
|
+
* // Redirect to KYC flow
|
|
831
|
+
* }
|
|
832
|
+
* }
|
|
833
|
+
* ```
|
|
834
|
+
*/
|
|
835
|
+
getComplianceStatus(): Promise<ComplianceStatus>;
|
|
836
|
+
/**
|
|
837
|
+
* Start KYC verification session (opens Sumsub widget)
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```typescript
|
|
841
|
+
* const session = await diviswap.kyc.startKycSession();
|
|
842
|
+
*
|
|
843
|
+
* // Redirect user to session URL
|
|
844
|
+
* window.location.href = session.sessionUrl;
|
|
845
|
+
*
|
|
846
|
+
* // Or embed in iframe
|
|
847
|
+
* const iframe = document.createElement('iframe');
|
|
848
|
+
* iframe.src = session.sessionUrl;
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
startKycSession(): Promise<KycSessionResponse>;
|
|
852
|
+
/**
|
|
853
|
+
* Submit KYC documents programmatically
|
|
854
|
+
*
|
|
855
|
+
* @example
|
|
856
|
+
* ```typescript
|
|
857
|
+
* // Convert file to base64
|
|
858
|
+
* const toBase64 = (file: File) => new Promise<string>((resolve, reject) => {
|
|
859
|
+
* const reader = new FileReader();
|
|
860
|
+
* reader.readAsDataURL(file);
|
|
861
|
+
* reader.onload = () => resolve(reader.result as string);
|
|
862
|
+
* reader.onerror = reject;
|
|
863
|
+
* });
|
|
864
|
+
*
|
|
865
|
+
* const frontImage = await toBase64(frontFile);
|
|
866
|
+
* const backImage = await toBase64(backFile);
|
|
867
|
+
*
|
|
868
|
+
* await diviswap.kyc.submitDocuments({
|
|
869
|
+
* type: 'DRIVERS_LICENSE',
|
|
870
|
+
* frontImage,
|
|
871
|
+
* backImage
|
|
872
|
+
* });
|
|
873
|
+
* ```
|
|
874
|
+
*/
|
|
875
|
+
submitDocuments(documents: KycDocumentRequest): Promise<ApiResponse>;
|
|
876
|
+
/**
|
|
877
|
+
* Submit personal information for KYC
|
|
878
|
+
*
|
|
879
|
+
* @example
|
|
880
|
+
* ```typescript
|
|
881
|
+
* await diviswap.kyc.submitPersonalInfo({
|
|
882
|
+
* firstName: 'John',
|
|
883
|
+
* lastName: 'Doe',
|
|
884
|
+
* dateOfBirth: '1990-01-01',
|
|
885
|
+
* ssn: '123-45-6789',
|
|
886
|
+
* address: {
|
|
887
|
+
* street: '123 Main St',
|
|
888
|
+
* city: 'New York',
|
|
889
|
+
* state: 'NY',
|
|
890
|
+
* postalCode: '10001',
|
|
891
|
+
* country: 'US'
|
|
892
|
+
* }
|
|
893
|
+
* });
|
|
894
|
+
* ```
|
|
895
|
+
*/
|
|
896
|
+
submitPersonalInfo(info: KycPersonalInfo): Promise<ApiResponse>;
|
|
897
|
+
/**
|
|
898
|
+
* Check if user can transact (convenience method)
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```typescript
|
|
902
|
+
* const canTransact = await diviswap.kyc.canTransact();
|
|
903
|
+
* if (!canTransact) {
|
|
904
|
+
* // Show KYC prompt
|
|
905
|
+
* }
|
|
906
|
+
* ```
|
|
907
|
+
*/
|
|
908
|
+
canTransact(): Promise<boolean>;
|
|
909
|
+
/**
|
|
910
|
+
* Check if KYC is approved
|
|
911
|
+
*
|
|
912
|
+
* @example
|
|
913
|
+
* ```typescript
|
|
914
|
+
* const isApproved = await diviswap.kyc.isKycApproved();
|
|
915
|
+
* ```
|
|
916
|
+
*/
|
|
917
|
+
isKycApproved(): Promise<boolean>;
|
|
918
|
+
/**
|
|
919
|
+
* Check if KYB is approved (for business accounts)
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* ```typescript
|
|
923
|
+
* const isBusinessApproved = await diviswap.kyc.isKybApproved();
|
|
924
|
+
* ```
|
|
925
|
+
*/
|
|
926
|
+
isKybApproved(): Promise<boolean>;
|
|
927
|
+
/**
|
|
928
|
+
* Get rejection reasons if KYC/KYB was rejected
|
|
929
|
+
*
|
|
930
|
+
* @example
|
|
931
|
+
* ```typescript
|
|
932
|
+
* const reasons = await diviswap.kyc.getRejectionReasons();
|
|
933
|
+
* if (reasons.length > 0) {
|
|
934
|
+
* console.log('Rejected because:', reasons.join(', '));
|
|
935
|
+
* }
|
|
936
|
+
* ```
|
|
937
|
+
*/
|
|
938
|
+
getRejectionReasons(): Promise<string[]>;
|
|
939
|
+
/**
|
|
940
|
+
* Wait for KYC approval (polling)
|
|
941
|
+
*
|
|
942
|
+
* @example
|
|
943
|
+
* ```typescript
|
|
944
|
+
* // Start KYC session
|
|
945
|
+
* const session = await diviswap.kyc.startKycSession();
|
|
946
|
+
* window.open(session.sessionUrl);
|
|
947
|
+
*
|
|
948
|
+
* // Wait for approval (polls every 5 seconds for up to 10 minutes)
|
|
949
|
+
* try {
|
|
950
|
+
* await diviswap.kyc.waitForApproval();
|
|
951
|
+
* console.log('KYC approved!');
|
|
952
|
+
* } catch (error) {
|
|
953
|
+
* console.log('KYC not approved:', error.message);
|
|
954
|
+
* }
|
|
955
|
+
* ```
|
|
956
|
+
*/
|
|
957
|
+
waitForApproval(options?: {
|
|
958
|
+
pollInterval?: number;
|
|
959
|
+
maxAttempts?: number;
|
|
960
|
+
}): Promise<ComplianceStatus>;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Fees module for managing integrator fees
|
|
965
|
+
*
|
|
966
|
+
* This module allows integrators to:
|
|
967
|
+
* - Set a custom fee percentage on top of Diviswap's base 1.5% fee
|
|
968
|
+
* - Configure fees globally or per-user
|
|
969
|
+
* - Retrieve current fee settings
|
|
970
|
+
* - Calculate total fees for transactions
|
|
971
|
+
*/
|
|
972
|
+
|
|
973
|
+
interface FeeSettings {
|
|
974
|
+
integratorFeePercentage: number;
|
|
975
|
+
baseFeePercentage: number;
|
|
976
|
+
totalFeePercentage: number;
|
|
977
|
+
userId?: string;
|
|
978
|
+
}
|
|
979
|
+
interface SetFeeRequest {
|
|
980
|
+
percentage: number;
|
|
981
|
+
userId?: number;
|
|
982
|
+
}
|
|
983
|
+
interface FeeCalculation {
|
|
984
|
+
amount: number;
|
|
985
|
+
baseFee: number;
|
|
986
|
+
integratorFee: number;
|
|
987
|
+
totalFee: number;
|
|
988
|
+
netAmount: number;
|
|
989
|
+
}
|
|
990
|
+
declare class FeesModule {
|
|
991
|
+
private client;
|
|
992
|
+
constructor(client: UnifiedApiClient);
|
|
993
|
+
/**
|
|
994
|
+
* Set integrator fee percentage
|
|
995
|
+
*
|
|
996
|
+
* @example
|
|
997
|
+
* ```typescript
|
|
998
|
+
* // Set global integrator fee to 0.75% (applies to all your users)
|
|
999
|
+
* await diviswap.fees.setFee({ percentage: 0.75 });
|
|
1000
|
+
*
|
|
1001
|
+
* // Set fee for specific user (overrides global)
|
|
1002
|
+
* await diviswap.fees.setFee({
|
|
1003
|
+
* percentage: 1.0,
|
|
1004
|
+
* userId: 123
|
|
1005
|
+
* });
|
|
1006
|
+
* ```
|
|
1007
|
+
*/
|
|
1008
|
+
setFee(data: SetFeeRequest): Promise<FeeSettings>;
|
|
1009
|
+
/**
|
|
1010
|
+
* Get current fee settings
|
|
1011
|
+
*
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```typescript
|
|
1014
|
+
* // Get global fee settings (your default)
|
|
1015
|
+
* const fees = await diviswap.fees.getFees();
|
|
1016
|
+
* console.log(`Total fee: ${fees.totalFeePercentage}%`);
|
|
1017
|
+
* ```
|
|
1018
|
+
*/
|
|
1019
|
+
getFees(): Promise<FeeSettings>;
|
|
1020
|
+
/**
|
|
1021
|
+
* Calculate fees for a transaction amount
|
|
1022
|
+
*
|
|
1023
|
+
* @example
|
|
1024
|
+
* ```typescript
|
|
1025
|
+
* const calc = await diviswap.fees.calculateFees({
|
|
1026
|
+
* amount: 100,
|
|
1027
|
+
* userId: 123 // Optional: checks for user-specific override
|
|
1028
|
+
* });
|
|
1029
|
+
*
|
|
1030
|
+
* console.log(`Base fee: $${calc.baseFee}`);
|
|
1031
|
+
* console.log(`Your fee: $${calc.integratorFee}`);
|
|
1032
|
+
* console.log(`Total fee: $${calc.totalFee}`);
|
|
1033
|
+
* console.log(`User receives: $${calc.netAmount}`);
|
|
1034
|
+
* ```
|
|
1035
|
+
*/
|
|
1036
|
+
calculateFees(params: {
|
|
1037
|
+
amount: number;
|
|
1038
|
+
userId?: number;
|
|
1039
|
+
}): Promise<FeeCalculation>;
|
|
1040
|
+
/**
|
|
1041
|
+
* Remove custom fee for a user (reverts to partner default)
|
|
1042
|
+
*
|
|
1043
|
+
* @example
|
|
1044
|
+
* ```typescript
|
|
1045
|
+
* // Remove VIP user's custom fee, they'll use your default fee again
|
|
1046
|
+
* await diviswap.fees.removeFee(123);
|
|
1047
|
+
* ```
|
|
1048
|
+
*/
|
|
1049
|
+
removeFee(userId: number): Promise<void>;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* Address-related type definitions
|
|
1054
|
+
*/
|
|
1055
|
+
interface Address {
|
|
1056
|
+
id: number;
|
|
1057
|
+
uuid: string;
|
|
1058
|
+
uuid_history: string[];
|
|
1059
|
+
chain_id: number;
|
|
1060
|
+
address: string;
|
|
1061
|
+
is_default: boolean;
|
|
1062
|
+
user_id?: number;
|
|
1063
|
+
organization_id?: number;
|
|
1064
|
+
created_at: string;
|
|
1065
|
+
updated_at: string;
|
|
1066
|
+
}
|
|
1067
|
+
interface CreateAddressRequest {
|
|
1068
|
+
chain_id: number;
|
|
1069
|
+
address: string;
|
|
1070
|
+
is_default?: boolean;
|
|
1071
|
+
}
|
|
1072
|
+
interface SetDefaultAddressRequest {
|
|
1073
|
+
chain_id: number;
|
|
1074
|
+
address: string;
|
|
1075
|
+
}
|
|
1076
|
+
interface DeleteAddressRequest {
|
|
1077
|
+
chain_id: number;
|
|
1078
|
+
address: string;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Chain ID mappings
|
|
1082
|
+
*/
|
|
1083
|
+
declare const CHAIN_IDS: {
|
|
1084
|
+
readonly ethereum: 1;
|
|
1085
|
+
readonly optimism: 10;
|
|
1086
|
+
readonly base: 8453;
|
|
1087
|
+
readonly polygon: 137;
|
|
1088
|
+
readonly arbitrum: 42161;
|
|
1089
|
+
readonly sepolia: 11155111;
|
|
1090
|
+
readonly optimism_sepolia: 11155420;
|
|
1091
|
+
readonly base_sepolia: 84532;
|
|
1092
|
+
readonly polygon_mumbai: 80001;
|
|
1093
|
+
readonly arbitrum_sepolia: 421614;
|
|
1094
|
+
};
|
|
1095
|
+
type ChainName = keyof typeof CHAIN_IDS;
|
|
1096
|
+
/**
|
|
1097
|
+
* Wallet connection info for automatic tracking
|
|
1098
|
+
*/
|
|
1099
|
+
interface WalletConnection {
|
|
1100
|
+
address: string;
|
|
1101
|
+
chainId: number;
|
|
1102
|
+
chainName?: string;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* Addresses module for managing crypto addresses
|
|
1107
|
+
*/
|
|
1108
|
+
|
|
1109
|
+
declare class AddressesModule {
|
|
1110
|
+
private client;
|
|
1111
|
+
constructor(client: UnifiedApiClient);
|
|
1112
|
+
/**
|
|
1113
|
+
* Get all addresses for the authenticated user
|
|
1114
|
+
*
|
|
1115
|
+
* @example
|
|
1116
|
+
* ```typescript
|
|
1117
|
+
* const addresses = await diviswap.addresses.list();
|
|
1118
|
+
* console.log('User addresses:', addresses);
|
|
1119
|
+
* ```
|
|
1120
|
+
*/
|
|
1121
|
+
list(): Promise<Address[]>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Create a new crypto address for the user
|
|
1124
|
+
*
|
|
1125
|
+
* @example
|
|
1126
|
+
* ```typescript
|
|
1127
|
+
* const address = await diviswap.addresses.create({
|
|
1128
|
+
* chain_id: 1, // Ethereum mainnet
|
|
1129
|
+
* address: '0x742d35Cc6647C9532c9fc77C68076aFb1e5AAc05',
|
|
1130
|
+
* is_default: true
|
|
1131
|
+
* });
|
|
1132
|
+
* ```
|
|
1133
|
+
*/
|
|
1134
|
+
create(data: CreateAddressRequest): Promise<Address>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Set a specific address as the default for its chain
|
|
1137
|
+
*
|
|
1138
|
+
* @example
|
|
1139
|
+
* ```typescript
|
|
1140
|
+
* await diviswap.addresses.setDefault({
|
|
1141
|
+
* chain_id: 1,
|
|
1142
|
+
* address: '0x742d35Cc6647C9532c9fc77C68076aFb1e5AAc05'
|
|
1143
|
+
* });
|
|
1144
|
+
* ```
|
|
1145
|
+
*/
|
|
1146
|
+
setDefault(data: SetDefaultAddressRequest): Promise<void>;
|
|
1147
|
+
/**
|
|
1148
|
+
* Delete a crypto address
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```typescript
|
|
1152
|
+
* await diviswap.addresses.delete({
|
|
1153
|
+
* chain_id: 1,
|
|
1154
|
+
* address: '0x742d35Cc6647C9532c9fc77C68076aFb1e5AAc05'
|
|
1155
|
+
* });
|
|
1156
|
+
* ```
|
|
1157
|
+
*/
|
|
1158
|
+
delete(data: DeleteAddressRequest): Promise<void>;
|
|
1159
|
+
/**
|
|
1160
|
+
* Get addresses for a specific chain
|
|
1161
|
+
*
|
|
1162
|
+
* @example
|
|
1163
|
+
* ```typescript
|
|
1164
|
+
* const ethAddresses = await diviswap.addresses.getByChain(1);
|
|
1165
|
+
* const baseAddresses = await diviswap.addresses.getByChain('base');
|
|
1166
|
+
* ```
|
|
1167
|
+
*/
|
|
1168
|
+
getByChain(chainIdOrName: number | ChainName): Promise<Address[]>;
|
|
1169
|
+
/**
|
|
1170
|
+
* Get the default address for a specific chain
|
|
1171
|
+
*
|
|
1172
|
+
* @example
|
|
1173
|
+
* ```typescript
|
|
1174
|
+
* const defaultEthAddress = await diviswap.addresses.getDefault(1);
|
|
1175
|
+
* const defaultBaseAddress = await diviswap.addresses.getDefault('base');
|
|
1176
|
+
* ```
|
|
1177
|
+
*/
|
|
1178
|
+
getDefault(chainIdOrName: number | ChainName): Promise<Address | null>;
|
|
1179
|
+
/**
|
|
1180
|
+
* Check if an address exists for the user
|
|
1181
|
+
*
|
|
1182
|
+
* @example
|
|
1183
|
+
* ```typescript
|
|
1184
|
+
* const exists = await diviswap.addresses.exists({
|
|
1185
|
+
* chain_id: 1,
|
|
1186
|
+
* address: '0x742d35Cc6647C9532c9fc77C68076aFb1e5AAc05'
|
|
1187
|
+
* });
|
|
1188
|
+
* ```
|
|
1189
|
+
*/
|
|
1190
|
+
exists(data: {
|
|
1191
|
+
chain_id: number;
|
|
1192
|
+
address: string;
|
|
1193
|
+
}): Promise<boolean>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Automatically track a wallet connection
|
|
1196
|
+
* This is the main method for automatic address tracking
|
|
1197
|
+
*
|
|
1198
|
+
* @example
|
|
1199
|
+
* ```typescript
|
|
1200
|
+
* // When user connects wallet
|
|
1201
|
+
* const connection = await diviswap.addresses.trackWallet({
|
|
1202
|
+
* address: account,
|
|
1203
|
+
* chainId: chainId,
|
|
1204
|
+
* chainName: 'ethereum' // optional
|
|
1205
|
+
* });
|
|
1206
|
+
* ```
|
|
1207
|
+
*/
|
|
1208
|
+
trackWallet(connection: WalletConnection): Promise<Address>;
|
|
1209
|
+
/**
|
|
1210
|
+
* Auto-track multiple wallet connections (useful for multi-chain wallets)
|
|
1211
|
+
*
|
|
1212
|
+
* @example
|
|
1213
|
+
* ```typescript
|
|
1214
|
+
* // When user connects a multi-chain wallet
|
|
1215
|
+
* const addresses = await diviswap.addresses.trackMultipleWallets([
|
|
1216
|
+
* { address: account, chainId: 1 }, // Ethereum
|
|
1217
|
+
* { address: account, chainId: 8453 }, // Base
|
|
1218
|
+
* { address: account, chainId: 10 } // Optimism
|
|
1219
|
+
* ]);
|
|
1220
|
+
* ```
|
|
1221
|
+
*/
|
|
1222
|
+
trackMultipleWallets(connections: WalletConnection[]): Promise<Address[]>;
|
|
1223
|
+
/**
|
|
1224
|
+
* Helper to get chain name from chain ID
|
|
1225
|
+
*/
|
|
1226
|
+
getChainName(chainId: number): string | undefined;
|
|
1227
|
+
/**
|
|
1228
|
+
* Helper to get chain ID from chain name
|
|
1229
|
+
*/
|
|
1230
|
+
getChainId(chainName: ChainName): number;
|
|
1231
|
+
/**
|
|
1232
|
+
* Get all supported chains
|
|
1233
|
+
*/
|
|
1234
|
+
getSupportedChains(): Record<string, number>;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* Webhooks module for managing partner webhook configurations
|
|
1239
|
+
*/
|
|
1240
|
+
|
|
1241
|
+
interface WebhookConfig {
|
|
1242
|
+
webhook_url: string | null;
|
|
1243
|
+
has_webhook_secret: boolean;
|
|
1244
|
+
enabled: boolean;
|
|
1245
|
+
}
|
|
1246
|
+
interface WebhookEvent {
|
|
1247
|
+
id: number;
|
|
1248
|
+
partner_id: number;
|
|
1249
|
+
user_id: number | null;
|
|
1250
|
+
event_type: string;
|
|
1251
|
+
payload: any;
|
|
1252
|
+
status: 'pending' | 'delivered' | 'failed';
|
|
1253
|
+
response_code: number | null;
|
|
1254
|
+
attempts: number;
|
|
1255
|
+
max_attempts: number;
|
|
1256
|
+
created_at: string;
|
|
1257
|
+
delivered_at: string | null;
|
|
1258
|
+
next_retry_at: string | null;
|
|
1259
|
+
}
|
|
1260
|
+
interface SetWebhookRequest {
|
|
1261
|
+
webhook_url: string;
|
|
1262
|
+
webhook_secret?: string;
|
|
1263
|
+
}
|
|
1264
|
+
declare class WebhooksModule {
|
|
1265
|
+
private client;
|
|
1266
|
+
constructor(client: UnifiedApiClient);
|
|
1267
|
+
/**
|
|
1268
|
+
* Set webhook URL and secret for your partner account
|
|
1269
|
+
*
|
|
1270
|
+
* @example
|
|
1271
|
+
* ```typescript
|
|
1272
|
+
* await diviswap.webhooks.setConfig({
|
|
1273
|
+
* webhook_url: 'https://myapp.com/api/webhooks/diviswap',
|
|
1274
|
+
* webhook_secret: 'whsec_...' // Optional, auto-generated if not provided
|
|
1275
|
+
* });
|
|
1276
|
+
* ```
|
|
1277
|
+
*/
|
|
1278
|
+
setConfig(data: SetWebhookRequest): Promise<{
|
|
1279
|
+
success: boolean;
|
|
1280
|
+
webhook_url: string;
|
|
1281
|
+
webhook_secret: string;
|
|
1282
|
+
}>;
|
|
1283
|
+
/**
|
|
1284
|
+
* Set webhook for a specific partner (user-owned partner)
|
|
1285
|
+
*
|
|
1286
|
+
* @example
|
|
1287
|
+
* ```typescript
|
|
1288
|
+
* await diviswap.webhooks.setConfigForPartner(4, {
|
|
1289
|
+
* webhook_url: 'https://myapp.com/webhooks'
|
|
1290
|
+
* });
|
|
1291
|
+
* ```
|
|
1292
|
+
*/
|
|
1293
|
+
setConfigForPartner(partnerId: number, data: SetWebhookRequest): Promise<{
|
|
1294
|
+
success: boolean;
|
|
1295
|
+
webhook_url: string;
|
|
1296
|
+
webhook_secret: string;
|
|
1297
|
+
}>;
|
|
1298
|
+
/**
|
|
1299
|
+
* Get current webhook configuration
|
|
1300
|
+
*
|
|
1301
|
+
* @example
|
|
1302
|
+
* ```typescript
|
|
1303
|
+
* const config = await diviswap.webhooks.getConfig();
|
|
1304
|
+
* console.log(`Webhook enabled: ${config.enabled}`);
|
|
1305
|
+
* console.log(`URL: ${config.webhook_url}`);
|
|
1306
|
+
* ```
|
|
1307
|
+
*/
|
|
1308
|
+
getConfig(): Promise<WebhookConfig>;
|
|
1309
|
+
/**
|
|
1310
|
+
* Get webhook config for a specific partner (user-owned)
|
|
1311
|
+
*/
|
|
1312
|
+
getConfigForPartner(partnerId: number): Promise<WebhookConfig>;
|
|
1313
|
+
/**
|
|
1314
|
+
* List webhook delivery events
|
|
1315
|
+
*
|
|
1316
|
+
* @example
|
|
1317
|
+
* ```typescript
|
|
1318
|
+
* const events = await diviswap.webhooks.listEvents({
|
|
1319
|
+
* limit: 100,
|
|
1320
|
+
* status: 'failed'
|
|
1321
|
+
* });
|
|
1322
|
+
*
|
|
1323
|
+
* events.forEach(event => {
|
|
1324
|
+
* console.log(`${event.event_type}: ${event.status}`);
|
|
1325
|
+
* });
|
|
1326
|
+
* ```
|
|
1327
|
+
*/
|
|
1328
|
+
listEvents(options?: {
|
|
1329
|
+
partnerId?: number;
|
|
1330
|
+
limit?: number;
|
|
1331
|
+
status?: 'pending' | 'delivered' | 'failed';
|
|
1332
|
+
}): Promise<{
|
|
1333
|
+
success: boolean;
|
|
1334
|
+
events: WebhookEvent[];
|
|
1335
|
+
}>;
|
|
1336
|
+
/**
|
|
1337
|
+
* Send a test webhook to verify your endpoint is working
|
|
1338
|
+
*
|
|
1339
|
+
* @example
|
|
1340
|
+
* ```typescript
|
|
1341
|
+
* const result = await diviswap.webhooks.test();
|
|
1342
|
+
* if (result.success) {
|
|
1343
|
+
* console.log('Webhook endpoint is working!');
|
|
1344
|
+
* }
|
|
1345
|
+
* ```
|
|
1346
|
+
*/
|
|
1347
|
+
test(partnerId?: number): Promise<any>;
|
|
1348
|
+
/**
|
|
1349
|
+
* Verify a webhook signature (static helper for your webhook endpoint)
|
|
1350
|
+
*
|
|
1351
|
+
* @example
|
|
1352
|
+
* ```typescript
|
|
1353
|
+
* import crypto from 'crypto';
|
|
1354
|
+
*
|
|
1355
|
+
* const isValid = WebhooksModule.verifySignature(
|
|
1356
|
+
* rawBody,
|
|
1357
|
+
* request.headers['x-signature'],
|
|
1358
|
+
* process.env.WEBHOOK_SECRET
|
|
1359
|
+
* );
|
|
1360
|
+
* ```
|
|
1361
|
+
*/
|
|
1362
|
+
static verifySignature(payload: string, signature: string, secret: string): boolean;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
/**
|
|
1366
|
+
* Main Diviswap SDK Client
|
|
1367
|
+
*/
|
|
1368
|
+
|
|
1369
|
+
/**
|
|
1370
|
+
* Diviswap SDK Client
|
|
1371
|
+
*
|
|
1372
|
+
* @example
|
|
1373
|
+
* User Authentication (existing):
|
|
1374
|
+
* ```typescript
|
|
1375
|
+
* const diviswap = Diviswap.init({
|
|
1376
|
+
* apiKey: 'your-api-key',
|
|
1377
|
+
* clientId: 'your-client-id',
|
|
1378
|
+
* environment: 'sandbox'
|
|
1379
|
+
* });
|
|
1380
|
+
* ```
|
|
1381
|
+
*
|
|
1382
|
+
* Partner Authentication (new):
|
|
1383
|
+
* ```typescript
|
|
1384
|
+
* const diviswap = Diviswap.init({
|
|
1385
|
+
* mode: 'partner',
|
|
1386
|
+
* keyId: 'pk_...',
|
|
1387
|
+
* secretKey: 'sk_...',
|
|
1388
|
+
* authMethod: 'hmac', // or 'jwt'
|
|
1389
|
+
* environment: 'sandbox'
|
|
1390
|
+
* });
|
|
1391
|
+
* ```
|
|
1392
|
+
*/
|
|
1393
|
+
declare class Diviswap {
|
|
1394
|
+
private config;
|
|
1395
|
+
private static instance;
|
|
1396
|
+
private apiClient;
|
|
1397
|
+
auth: AuthModule;
|
|
1398
|
+
payees: PayeesModule;
|
|
1399
|
+
transactions: TransactionsModule;
|
|
1400
|
+
kyc: KycModule;
|
|
1401
|
+
fees: FeesModule;
|
|
1402
|
+
addresses: AddressesModule;
|
|
1403
|
+
webhooks: WebhooksModule;
|
|
1404
|
+
private constructor();
|
|
1405
|
+
/**
|
|
1406
|
+
* Initialize the Diviswap SDK
|
|
1407
|
+
*
|
|
1408
|
+
* @param config - SDK configuration
|
|
1409
|
+
* @returns Diviswap SDK instance
|
|
1410
|
+
*
|
|
1411
|
+
* @example
|
|
1412
|
+
* ```typescript
|
|
1413
|
+
* const diviswap = Diviswap.init({
|
|
1414
|
+
* apiKey: 'your-api-key',
|
|
1415
|
+
* clientId: 'your-client-id'
|
|
1416
|
+
* });
|
|
1417
|
+
* ```
|
|
1418
|
+
*/
|
|
1419
|
+
static init(config: DiviswapConfig): Diviswap;
|
|
1420
|
+
/**
|
|
1421
|
+
* Get the current SDK instance
|
|
1422
|
+
* @throws {ConfigurationError} If SDK hasn't been initialized
|
|
1423
|
+
*/
|
|
1424
|
+
static getInstance(): Diviswap;
|
|
1425
|
+
/**
|
|
1426
|
+
* Reset the SDK instance (useful for testing)
|
|
1427
|
+
*/
|
|
1428
|
+
static reset(): void;
|
|
1429
|
+
/**
|
|
1430
|
+
* Update SDK configuration
|
|
1431
|
+
* @deprecated Configuration updates require re-initialization. Call Diviswap.reset() then Diviswap.init() with new config.
|
|
1432
|
+
*/
|
|
1433
|
+
updateConfig(_config: Partial<DiviswapConfig>): void;
|
|
1434
|
+
/**
|
|
1435
|
+
* Get current configuration (excluding sensitive data)
|
|
1436
|
+
*/
|
|
1437
|
+
getConfig(): Partial<DiviswapConfig>;
|
|
1438
|
+
/**
|
|
1439
|
+
* Get current access token (for developers who need it for custom API calls)
|
|
1440
|
+
* Only available in user authentication mode.
|
|
1441
|
+
*
|
|
1442
|
+
* @example
|
|
1443
|
+
* ```typescript
|
|
1444
|
+
* const token = await diviswap.getAccessToken();
|
|
1445
|
+
* if (token) {
|
|
1446
|
+
* // Use token for custom API calls
|
|
1447
|
+
* fetch('https://api.diviswap.io/custom-endpoint', {
|
|
1448
|
+
* headers: { 'Authorization': `Bearer ${token}` }
|
|
1449
|
+
* });
|
|
1450
|
+
* }
|
|
1451
|
+
* ```
|
|
1452
|
+
*/
|
|
1453
|
+
getAccessToken(): Promise<string | null>;
|
|
1454
|
+
/**
|
|
1455
|
+
* Set access token (for server-side usage where tokens are stored externally)
|
|
1456
|
+
* Only available in user authentication mode.
|
|
1457
|
+
*
|
|
1458
|
+
* @example
|
|
1459
|
+
* ```typescript
|
|
1460
|
+
* // In a Next.js API route where token is stored in cookies
|
|
1461
|
+
* const token = cookies().get('diviswap_session')?.value;
|
|
1462
|
+
* if (token) {
|
|
1463
|
+
* diviswap.setAccessToken(token);
|
|
1464
|
+
* }
|
|
1465
|
+
* ```
|
|
1466
|
+
*/
|
|
1467
|
+
setAccessToken(accessToken: string, refreshToken?: string): void;
|
|
1468
|
+
/**
|
|
1469
|
+
* Set customer context for partner authentication mode
|
|
1470
|
+
*
|
|
1471
|
+
* @example
|
|
1472
|
+
* ```typescript
|
|
1473
|
+
* // For partner auth mode - link requests to a specific customer
|
|
1474
|
+
* diviswap.setCustomer('user-123', 'user@example.com');
|
|
1475
|
+
*
|
|
1476
|
+
* // Now all API calls will be made on behalf of this customer
|
|
1477
|
+
* const payees = await diviswap.payees.getAll();
|
|
1478
|
+
* ```
|
|
1479
|
+
*/
|
|
1480
|
+
setCustomer(customerId: string, customerEmail?: string): void;
|
|
1481
|
+
/**
|
|
1482
|
+
* Clear customer context for partner authentication mode
|
|
1483
|
+
*/
|
|
1484
|
+
clearCustomer(): void;
|
|
1485
|
+
private validateConfig;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
/**
|
|
1489
|
+
* Wallet integration helpers for automatic address tracking
|
|
1490
|
+
*/
|
|
1491
|
+
|
|
1492
|
+
/**
|
|
1493
|
+
* Ethereum-like wallet interface (compatible with MetaMask, WalletConnect, etc.)
|
|
1494
|
+
*/
|
|
1495
|
+
interface EthereumWallet {
|
|
1496
|
+
request: (args: {
|
|
1497
|
+
method: string;
|
|
1498
|
+
params?: any[];
|
|
1499
|
+
}) => Promise<any>;
|
|
1500
|
+
on?: (event: string, handler: (...args: any[]) => void) => void;
|
|
1501
|
+
removeListener?: (event: string, handler: (...args: any[]) => void) => void;
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Automatic wallet tracking configuration
|
|
1505
|
+
*/
|
|
1506
|
+
interface WalletTrackingConfig {
|
|
1507
|
+
/** Automatically track when accounts change */
|
|
1508
|
+
trackAccountChanges?: boolean;
|
|
1509
|
+
/** Automatically track when chain changes */
|
|
1510
|
+
trackChainChanges?: boolean;
|
|
1511
|
+
/** Set newly connected addresses as default for their chain */
|
|
1512
|
+
setAsDefault?: boolean;
|
|
1513
|
+
/** Custom chain mappings for unsupported chains */
|
|
1514
|
+
customChains?: Record<number, string>;
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Wallet tracking manager for automatic address management
|
|
1518
|
+
*/
|
|
1519
|
+
declare class WalletTracker {
|
|
1520
|
+
private static instance;
|
|
1521
|
+
private wallet;
|
|
1522
|
+
private diviswap;
|
|
1523
|
+
private config;
|
|
1524
|
+
private listeners;
|
|
1525
|
+
private constructor();
|
|
1526
|
+
/**
|
|
1527
|
+
* Get or create the wallet tracker instance
|
|
1528
|
+
*/
|
|
1529
|
+
static getInstance(config?: WalletTrackingConfig): WalletTracker;
|
|
1530
|
+
/**
|
|
1531
|
+
* Initialize wallet tracking with Diviswap SDK instance
|
|
1532
|
+
*/
|
|
1533
|
+
init(diviswap: Diviswap, wallet?: EthereumWallet): void;
|
|
1534
|
+
/**
|
|
1535
|
+
* Connect and track a wallet
|
|
1536
|
+
*/
|
|
1537
|
+
connect(): Promise<WalletConnection[]>;
|
|
1538
|
+
/**
|
|
1539
|
+
* Track current wallet state without requesting connection
|
|
1540
|
+
*/
|
|
1541
|
+
trackCurrent(): Promise<WalletConnection[]>;
|
|
1542
|
+
/**
|
|
1543
|
+
* Setup listener for account changes
|
|
1544
|
+
*/
|
|
1545
|
+
private setupAccountChangeListener;
|
|
1546
|
+
/**
|
|
1547
|
+
* Setup listener for chain changes
|
|
1548
|
+
*/
|
|
1549
|
+
private setupChainChangeListener;
|
|
1550
|
+
/**
|
|
1551
|
+
* Get chain name from chain ID
|
|
1552
|
+
*/
|
|
1553
|
+
private getChainName;
|
|
1554
|
+
/**
|
|
1555
|
+
* Cleanup listeners
|
|
1556
|
+
*/
|
|
1557
|
+
cleanup(): void;
|
|
1558
|
+
/**
|
|
1559
|
+
* Update configuration
|
|
1560
|
+
*/
|
|
1561
|
+
updateConfig(config: Partial<WalletTrackingConfig>): void;
|
|
1562
|
+
}
|
|
1563
|
+
/**
|
|
1564
|
+
* Convenience functions for easy integration
|
|
1565
|
+
*/
|
|
1566
|
+
/**
|
|
1567
|
+
* Connect wallet and automatically track addresses
|
|
1568
|
+
*
|
|
1569
|
+
* @example
|
|
1570
|
+
* ```typescript
|
|
1571
|
+
* import { Diviswap, connectWallet } from '@diviswap/sdk';
|
|
1572
|
+
*
|
|
1573
|
+
* const diviswap = Diviswap.init(config);
|
|
1574
|
+
*
|
|
1575
|
+
* // Connect and track wallet automatically
|
|
1576
|
+
* const connections = await connectWallet(diviswap);
|
|
1577
|
+
* console.log('Tracked addresses:', connections);
|
|
1578
|
+
* ```
|
|
1579
|
+
*/
|
|
1580
|
+
declare function connectWallet(diviswap: Diviswap, wallet?: EthereumWallet, config?: WalletTrackingConfig): Promise<WalletConnection[]>;
|
|
1581
|
+
/**
|
|
1582
|
+
* Track current wallet state without requesting connection
|
|
1583
|
+
*
|
|
1584
|
+
* @example
|
|
1585
|
+
* ```typescript
|
|
1586
|
+
* import { Diviswap, trackCurrentWallet } from '@diviswap/sdk';
|
|
1587
|
+
*
|
|
1588
|
+
* const diviswap = Diviswap.init(config);
|
|
1589
|
+
*
|
|
1590
|
+
* // Track currently connected accounts
|
|
1591
|
+
* const connections = await trackCurrentWallet(diviswap);
|
|
1592
|
+
* ```
|
|
1593
|
+
*/
|
|
1594
|
+
declare function trackCurrentWallet(diviswap: Diviswap, wallet?: EthereumWallet, config?: WalletTrackingConfig): Promise<WalletConnection[]>;
|
|
1595
|
+
/**
|
|
1596
|
+
* Setup automatic wallet tracking (listens for account/chain changes)
|
|
1597
|
+
*
|
|
1598
|
+
* @example
|
|
1599
|
+
* ```typescript
|
|
1600
|
+
* import { Diviswap, setupWalletTracking } from '@diviswap/sdk';
|
|
1601
|
+
*
|
|
1602
|
+
* const diviswap = Diviswap.init(config);
|
|
1603
|
+
*
|
|
1604
|
+
* // Setup automatic tracking
|
|
1605
|
+
* setupWalletTracking(diviswap, {
|
|
1606
|
+
* trackAccountChanges: true,
|
|
1607
|
+
* trackChainChanges: true,
|
|
1608
|
+
* setAsDefault: true
|
|
1609
|
+
* });
|
|
1610
|
+
* ```
|
|
1611
|
+
*/
|
|
1612
|
+
declare function setupWalletTracking(diviswap: Diviswap, wallet?: EthereumWallet, config?: WalletTrackingConfig): WalletTracker;
|
|
1613
|
+
|
|
1614
|
+
export { type AuthCredentials as A, type OrganizationInfo as B, type ComplianceStatus as C, Diviswap as D, type Environment as E, type KycDocumentRequest as F, type KycPersonalInfo as G, type IndividualData as I, type KycStatus as K, type LiberExConfig as L, type OnrampRequest as O, type Payee as P, type RegisterRequest as R, type SetDefaultAddressRequest as S, type Transaction as T, type User as U, type WalletConnection as W, type DiviswapConfig as a, type KybStatus as b, type KycSessionResponse as c, type Address as d, type CreateAddressRequest as e, type DeleteAddressRequest as f, type ChainName as g, CHAIN_IDS as h, WalletTracker as i, connectWallet as j, type EthereumWallet as k, type WalletTrackingConfig as l, type AuthMode as m, type UserDiviswapConfig as n, type PartnerDiviswapConfig as o, type UserLiberExConfig as p, type PartnerLiberExConfig as q, type LegacyDiviswapConfig as r, setupWalletTracking as s, trackCurrentWallet as t, type AuthResponse as u, type CreatePayeeRequest as v, type OfframpRequest as w, type ApiResponse as x, type KycMetadata as y, type KybMetadata as z };
|