@0xio/sdk 2.1.3
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/CHANGELOG.md +238 -0
- package/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/index.d.ts +698 -0
- package/dist/index.esm.js +1705 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +1745 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +1751 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +80 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,698 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0xio Wallet SDK - Type Definitions
|
|
3
|
+
* Comprehensive type system for 0xio wallet integration with Octra Network
|
|
4
|
+
*/
|
|
5
|
+
interface WalletAddress {
|
|
6
|
+
readonly address: string;
|
|
7
|
+
readonly publicKey?: string;
|
|
8
|
+
}
|
|
9
|
+
interface Balance {
|
|
10
|
+
readonly public: number;
|
|
11
|
+
readonly private?: number;
|
|
12
|
+
readonly total: number;
|
|
13
|
+
readonly currency: 'OCT';
|
|
14
|
+
}
|
|
15
|
+
interface NetworkInfo {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly rpcUrl: string;
|
|
19
|
+
readonly explorerUrl?: string;
|
|
20
|
+
readonly color: string;
|
|
21
|
+
readonly isTestnet: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface TransactionData {
|
|
24
|
+
readonly to: string;
|
|
25
|
+
readonly amount: number;
|
|
26
|
+
readonly message?: string;
|
|
27
|
+
readonly feeLevel?: 1 | 3;
|
|
28
|
+
readonly isPrivate?: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface SignedTransaction {
|
|
31
|
+
readonly from: string;
|
|
32
|
+
readonly to_: string;
|
|
33
|
+
readonly amount: string;
|
|
34
|
+
readonly nonce: string;
|
|
35
|
+
readonly ou: string;
|
|
36
|
+
readonly timestamp: string;
|
|
37
|
+
readonly message?: string;
|
|
38
|
+
readonly signature: string;
|
|
39
|
+
readonly public_key: string;
|
|
40
|
+
}
|
|
41
|
+
interface TransactionResult {
|
|
42
|
+
readonly txHash: string;
|
|
43
|
+
readonly success: boolean;
|
|
44
|
+
readonly message?: string;
|
|
45
|
+
readonly explorerUrl?: string;
|
|
46
|
+
}
|
|
47
|
+
interface TransactionHistory {
|
|
48
|
+
readonly transactions: Transaction[];
|
|
49
|
+
readonly totalCount: number;
|
|
50
|
+
readonly page: number;
|
|
51
|
+
readonly hasMore: boolean;
|
|
52
|
+
}
|
|
53
|
+
interface Transaction {
|
|
54
|
+
readonly hash: string;
|
|
55
|
+
readonly from: string;
|
|
56
|
+
readonly to: string;
|
|
57
|
+
readonly amount: number;
|
|
58
|
+
readonly fee: number;
|
|
59
|
+
readonly timestamp: number;
|
|
60
|
+
readonly status: 'pending' | 'confirmed' | 'failed';
|
|
61
|
+
readonly message?: string;
|
|
62
|
+
readonly blockHeight?: number;
|
|
63
|
+
}
|
|
64
|
+
interface ConnectionInfo {
|
|
65
|
+
isConnected: boolean;
|
|
66
|
+
address?: string;
|
|
67
|
+
balance?: Balance;
|
|
68
|
+
networkInfo?: NetworkInfo;
|
|
69
|
+
connectedAt?: number;
|
|
70
|
+
}
|
|
71
|
+
interface ConnectOptions {
|
|
72
|
+
readonly requestPermissions?: Permission[];
|
|
73
|
+
readonly networkId?: string;
|
|
74
|
+
}
|
|
75
|
+
type Permission = 'read_balance' | 'send_transactions' | 'view_private_balance' | 'private_transfers';
|
|
76
|
+
type WalletEventType = 'connect' | 'disconnect' | 'accountChanged' | 'balanceChanged' | 'networkChanged' | 'transactionConfirmed' | 'error' | 'extensionLocked' | 'extensionUnlocked';
|
|
77
|
+
interface WalletEvent<T = any> {
|
|
78
|
+
readonly type: WalletEventType;
|
|
79
|
+
readonly data: T;
|
|
80
|
+
readonly timestamp: number;
|
|
81
|
+
}
|
|
82
|
+
interface ConnectEvent {
|
|
83
|
+
readonly address: string;
|
|
84
|
+
readonly balance: Balance;
|
|
85
|
+
readonly networkInfo: NetworkInfo;
|
|
86
|
+
readonly permissions: Permission[];
|
|
87
|
+
}
|
|
88
|
+
interface DisconnectEvent {
|
|
89
|
+
readonly reason: 'user_action' | 'extension_unavailable' | 'network_error' | 'extension_locked';
|
|
90
|
+
}
|
|
91
|
+
interface AccountChangedEvent {
|
|
92
|
+
readonly previousAddress?: string;
|
|
93
|
+
readonly newAddress: string;
|
|
94
|
+
readonly balance: Balance;
|
|
95
|
+
}
|
|
96
|
+
interface BalanceChangedEvent {
|
|
97
|
+
readonly address: string;
|
|
98
|
+
readonly previousBalance: Balance | undefined;
|
|
99
|
+
readonly newBalance: Balance;
|
|
100
|
+
}
|
|
101
|
+
interface NetworkChangedEvent {
|
|
102
|
+
readonly previousNetwork?: NetworkInfo;
|
|
103
|
+
readonly newNetwork: NetworkInfo;
|
|
104
|
+
}
|
|
105
|
+
interface TransactionConfirmedEvent {
|
|
106
|
+
readonly transaction: Transaction;
|
|
107
|
+
}
|
|
108
|
+
interface ErrorEvent {
|
|
109
|
+
readonly code: ErrorCode;
|
|
110
|
+
readonly message: string;
|
|
111
|
+
readonly details?: any;
|
|
112
|
+
}
|
|
113
|
+
declare enum ErrorCode {
|
|
114
|
+
EXTENSION_NOT_FOUND = "EXTENSION_NOT_FOUND",
|
|
115
|
+
CONNECTION_REFUSED = "CONNECTION_REFUSED",
|
|
116
|
+
USER_REJECTED = "USER_REJECTED",
|
|
117
|
+
INSUFFICIENT_BALANCE = "INSUFFICIENT_BALANCE",
|
|
118
|
+
INVALID_ADDRESS = "INVALID_ADDRESS",
|
|
119
|
+
INVALID_AMOUNT = "INVALID_AMOUNT",
|
|
120
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
121
|
+
TRANSACTION_FAILED = "TRANSACTION_FAILED",
|
|
122
|
+
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
123
|
+
WALLET_LOCKED = "WALLET_LOCKED",
|
|
124
|
+
RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED",
|
|
125
|
+
UNKNOWN_ERROR = "UNKNOWN_ERROR"
|
|
126
|
+
}
|
|
127
|
+
declare class ZeroXIOWalletError extends Error {
|
|
128
|
+
readonly code: ErrorCode;
|
|
129
|
+
readonly details?: any | undefined;
|
|
130
|
+
constructor(code: ErrorCode, message: string, details?: any | undefined);
|
|
131
|
+
}
|
|
132
|
+
interface PrivateBalanceInfo {
|
|
133
|
+
readonly hasPrivateBalance: boolean;
|
|
134
|
+
readonly encryptedAmount?: string;
|
|
135
|
+
readonly canDecrypt: boolean;
|
|
136
|
+
}
|
|
137
|
+
interface PrivateTransferData {
|
|
138
|
+
readonly to: string;
|
|
139
|
+
readonly amount: number;
|
|
140
|
+
readonly message?: string;
|
|
141
|
+
}
|
|
142
|
+
interface PendingPrivateTransfer {
|
|
143
|
+
readonly id: string;
|
|
144
|
+
readonly from: string;
|
|
145
|
+
readonly encryptedAmount: string;
|
|
146
|
+
readonly message?: string;
|
|
147
|
+
readonly timestamp: number;
|
|
148
|
+
readonly canClaim: boolean;
|
|
149
|
+
}
|
|
150
|
+
interface SDKConfig {
|
|
151
|
+
readonly appName: string;
|
|
152
|
+
readonly appDescription?: string;
|
|
153
|
+
readonly appVersion?: string;
|
|
154
|
+
readonly appUrl?: string;
|
|
155
|
+
readonly appIcon?: string;
|
|
156
|
+
readonly requiredPermissions?: Permission[];
|
|
157
|
+
readonly networkId?: string;
|
|
158
|
+
readonly debug?: boolean;
|
|
159
|
+
}
|
|
160
|
+
interface ExtensionRequest {
|
|
161
|
+
readonly id: string;
|
|
162
|
+
readonly method: string;
|
|
163
|
+
readonly params: any;
|
|
164
|
+
readonly timestamp: number;
|
|
165
|
+
}
|
|
166
|
+
interface ExtensionResponse<T = any> {
|
|
167
|
+
readonly id: string;
|
|
168
|
+
readonly success: boolean;
|
|
169
|
+
readonly data?: T;
|
|
170
|
+
readonly error?: {
|
|
171
|
+
code: ErrorCode;
|
|
172
|
+
message: string;
|
|
173
|
+
details?: any;
|
|
174
|
+
};
|
|
175
|
+
readonly timestamp: number;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 0xio Wallet SDK - Event System
|
|
180
|
+
* Type-safe event emitter for wallet events
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
type EventListener<T = any> = (event: WalletEvent<T>) => void;
|
|
184
|
+
declare class EventEmitter {
|
|
185
|
+
private listeners;
|
|
186
|
+
private debug;
|
|
187
|
+
constructor(debug?: boolean);
|
|
188
|
+
/**
|
|
189
|
+
* Add event listener
|
|
190
|
+
*/
|
|
191
|
+
on<T = any>(eventType: WalletEventType, listener: EventListener<T>): void;
|
|
192
|
+
/**
|
|
193
|
+
* Remove event listener
|
|
194
|
+
*/
|
|
195
|
+
off<T = any>(eventType: WalletEventType, listener: EventListener<T>): void;
|
|
196
|
+
/**
|
|
197
|
+
* Add one-time event listener
|
|
198
|
+
*/
|
|
199
|
+
once<T = any>(eventType: WalletEventType, listener: EventListener<T>): void;
|
|
200
|
+
/**
|
|
201
|
+
* Emit event to all listeners
|
|
202
|
+
*/
|
|
203
|
+
emit<T = any>(eventType: WalletEventType, data: T): void;
|
|
204
|
+
/**
|
|
205
|
+
* Remove all listeners for a specific event type
|
|
206
|
+
*/
|
|
207
|
+
removeAllListeners(eventType?: WalletEventType): void;
|
|
208
|
+
/**
|
|
209
|
+
* Get number of listeners for an event type
|
|
210
|
+
*/
|
|
211
|
+
listenerCount(eventType: WalletEventType): number;
|
|
212
|
+
/**
|
|
213
|
+
* Get all event types that have listeners
|
|
214
|
+
*/
|
|
215
|
+
eventTypes(): WalletEventType[];
|
|
216
|
+
/**
|
|
217
|
+
* Check if there are any listeners for an event type
|
|
218
|
+
*/
|
|
219
|
+
hasListeners(eventType: WalletEventType): boolean;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 0xio Wallet SDK - Main Wallet Class
|
|
224
|
+
* Primary interface for DApp developers to interact with 0xio Wallet
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
declare class ZeroXIOWallet extends EventEmitter {
|
|
228
|
+
private communicator;
|
|
229
|
+
private config;
|
|
230
|
+
private connectionInfo;
|
|
231
|
+
private isInitialized;
|
|
232
|
+
private logger;
|
|
233
|
+
constructor(config: SDKConfig);
|
|
234
|
+
/**
|
|
235
|
+
* Initialize the SDK
|
|
236
|
+
* Must be called before using any other methods
|
|
237
|
+
*/
|
|
238
|
+
initialize(): Promise<boolean>;
|
|
239
|
+
/**
|
|
240
|
+
* Check if SDK is initialized
|
|
241
|
+
*/
|
|
242
|
+
isReady(): boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Connect to wallet
|
|
245
|
+
*/
|
|
246
|
+
connect(options?: ConnectOptions): Promise<ConnectEvent>;
|
|
247
|
+
/**
|
|
248
|
+
* Disconnect from wallet
|
|
249
|
+
*/
|
|
250
|
+
disconnect(): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Check if connected to wallet
|
|
253
|
+
*/
|
|
254
|
+
isConnected(): boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Get current connection info
|
|
257
|
+
*/
|
|
258
|
+
getConnectionInfo(): ConnectionInfo;
|
|
259
|
+
/**
|
|
260
|
+
* Check connection status with extension
|
|
261
|
+
*/
|
|
262
|
+
getConnectionStatus(): Promise<ConnectionInfo>;
|
|
263
|
+
/**
|
|
264
|
+
* Get current wallet address
|
|
265
|
+
*/
|
|
266
|
+
getAddress(): string | null;
|
|
267
|
+
/**
|
|
268
|
+
* Get current balance
|
|
269
|
+
*/
|
|
270
|
+
getBalance(forceRefresh?: boolean): Promise<Balance>;
|
|
271
|
+
/**
|
|
272
|
+
* Get network information
|
|
273
|
+
*/
|
|
274
|
+
getNetworkInfo(): Promise<NetworkInfo>;
|
|
275
|
+
/**
|
|
276
|
+
* Send transaction
|
|
277
|
+
*/
|
|
278
|
+
sendTransaction(txData: TransactionData): Promise<TransactionResult>;
|
|
279
|
+
/**
|
|
280
|
+
* Get transaction history
|
|
281
|
+
*/
|
|
282
|
+
getTransactionHistory(page?: number, limit?: number): Promise<TransactionHistory>;
|
|
283
|
+
/**
|
|
284
|
+
* Get private balance information
|
|
285
|
+
*/
|
|
286
|
+
getPrivateBalanceInfo(): Promise<PrivateBalanceInfo>;
|
|
287
|
+
/**
|
|
288
|
+
* Encrypt public balance to private
|
|
289
|
+
*/
|
|
290
|
+
encryptBalance(amount: number): Promise<boolean>;
|
|
291
|
+
/**
|
|
292
|
+
* Decrypt private balance to public
|
|
293
|
+
*/
|
|
294
|
+
decryptBalance(amount: number): Promise<boolean>;
|
|
295
|
+
/**
|
|
296
|
+
* Send private transfer
|
|
297
|
+
*/
|
|
298
|
+
sendPrivateTransfer(transferData: PrivateTransferData): Promise<TransactionResult>;
|
|
299
|
+
/**
|
|
300
|
+
* Get pending private transfers
|
|
301
|
+
*/
|
|
302
|
+
getPendingPrivateTransfers(): Promise<PendingPrivateTransfer[]>;
|
|
303
|
+
/**
|
|
304
|
+
* Claim private transfer
|
|
305
|
+
*/
|
|
306
|
+
claimPrivateTransfer(transferId: string): Promise<TransactionResult>;
|
|
307
|
+
private ensureInitialized;
|
|
308
|
+
private ensureConnected;
|
|
309
|
+
private setupExtensionEventListeners;
|
|
310
|
+
/**
|
|
311
|
+
* Handle account changed event from extension
|
|
312
|
+
*/
|
|
313
|
+
private handleAccountChanged;
|
|
314
|
+
/**
|
|
315
|
+
* Handle network changed event from extension
|
|
316
|
+
*/
|
|
317
|
+
private handleNetworkChanged;
|
|
318
|
+
/**
|
|
319
|
+
* Handle balance changed event from extension
|
|
320
|
+
*/
|
|
321
|
+
private handleBalanceChanged;
|
|
322
|
+
/**
|
|
323
|
+
* Handle extension locked event
|
|
324
|
+
*/
|
|
325
|
+
private handleExtensionLocked;
|
|
326
|
+
/**
|
|
327
|
+
* Handle extension unlocked event
|
|
328
|
+
*/
|
|
329
|
+
private handleExtensionUnlocked;
|
|
330
|
+
/**
|
|
331
|
+
* Handle transaction confirmed event
|
|
332
|
+
*/
|
|
333
|
+
private handleTransactionConfirmed;
|
|
334
|
+
/**
|
|
335
|
+
* Clean up SDK resources
|
|
336
|
+
*/
|
|
337
|
+
cleanup(): void;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* 0xio Wallet SDK - Extension Communication Module
|
|
342
|
+
*
|
|
343
|
+
* @fileoverview Manages secure communication between the SDK and browser extension.
|
|
344
|
+
* Implements message passing, request/response handling, rate limiting, and origin validation
|
|
345
|
+
* to ensure secure wallet interactions.
|
|
346
|
+
*
|
|
347
|
+
* @module communication
|
|
348
|
+
* @version 1.2.0
|
|
349
|
+
* @license MIT
|
|
350
|
+
*/
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* ExtensionCommunicator - Manages communication with the 0xio Wallet browser extension
|
|
354
|
+
*
|
|
355
|
+
* @class
|
|
356
|
+
* @extends EventEmitter
|
|
357
|
+
*
|
|
358
|
+
* @description
|
|
359
|
+
* Handles all communication between the SDK and wallet extension including:
|
|
360
|
+
* - Request/response message passing with origin validation
|
|
361
|
+
* - Rate limiting to prevent DoS attacks
|
|
362
|
+
* - Automatic retry logic with exponential backoff
|
|
363
|
+
* - Extension detection and availability monitoring
|
|
364
|
+
* - Cryptographically secure request ID generation
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```typescript
|
|
368
|
+
* const communicator = new ExtensionCommunicator(true); // debug mode
|
|
369
|
+
* await communicator.initialize();
|
|
370
|
+
*
|
|
371
|
+
* const response = await communicator.sendRequest('get_balance', {});
|
|
372
|
+
* console.log(response);
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
declare class ExtensionCommunicator extends EventEmitter {
|
|
376
|
+
/** Legacy request counter (deprecated, kept for fallback) */
|
|
377
|
+
private requestId;
|
|
378
|
+
/** Map of pending requests awaiting responses */
|
|
379
|
+
private pendingRequests;
|
|
380
|
+
/** Initialization state flag */
|
|
381
|
+
private isInitialized;
|
|
382
|
+
/** Logger instance for debugging */
|
|
383
|
+
private logger;
|
|
384
|
+
/** Interval handle for periodic extension detection */
|
|
385
|
+
private extensionDetectionInterval;
|
|
386
|
+
/** Current extension availability state */
|
|
387
|
+
private isExtensionAvailableState;
|
|
388
|
+
/** Maximum number of concurrent pending requests */
|
|
389
|
+
private readonly MAX_CONCURRENT_REQUESTS;
|
|
390
|
+
/** Time window for rate limiting (milliseconds) */
|
|
391
|
+
private readonly RATE_LIMIT_WINDOW;
|
|
392
|
+
/** Maximum requests allowed per time window */
|
|
393
|
+
private readonly MAX_REQUESTS_PER_WINDOW;
|
|
394
|
+
/** Timestamps of recent requests for rate limiting */
|
|
395
|
+
private requestTimestamps;
|
|
396
|
+
/**
|
|
397
|
+
* Creates a new ExtensionCommunicator instance
|
|
398
|
+
*
|
|
399
|
+
* @param {boolean} debug - Enable debug logging
|
|
400
|
+
*/
|
|
401
|
+
constructor(debug?: boolean);
|
|
402
|
+
/**
|
|
403
|
+
* Initialize communication with the wallet extension
|
|
404
|
+
*
|
|
405
|
+
* @description
|
|
406
|
+
* Performs initial setup and verification:
|
|
407
|
+
* 1. Waits for extension to become available
|
|
408
|
+
* 2. Sends ping to verify communication
|
|
409
|
+
* 3. Establishes message handlers
|
|
410
|
+
*
|
|
411
|
+
* Must be called before any other methods.
|
|
412
|
+
*
|
|
413
|
+
* @returns {Promise<boolean>} True if initialization succeeded, false otherwise
|
|
414
|
+
* @throws {ZeroXIOWalletError} If extension is not available after timeout
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* const success = await communicator.initialize();
|
|
419
|
+
* if (!success) {
|
|
420
|
+
* console.error('Failed to initialize wallet connection');
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
initialize(): Promise<boolean>;
|
|
425
|
+
/**
|
|
426
|
+
* Check if extension is available
|
|
427
|
+
*/
|
|
428
|
+
isExtensionAvailable(): boolean;
|
|
429
|
+
/**
|
|
430
|
+
* Send request to extension
|
|
431
|
+
*/
|
|
432
|
+
sendRequest<T = any>(method: string, params?: any, timeout?: number): Promise<T>;
|
|
433
|
+
/**
|
|
434
|
+
* Send request to extension with automatic retry logic
|
|
435
|
+
*/
|
|
436
|
+
sendRequestWithRetry<T = any>(method: string, params?: any, maxRetries?: number, timeout?: number): Promise<T>;
|
|
437
|
+
/**
|
|
438
|
+
* Setup message listener for responses from extension
|
|
439
|
+
*/
|
|
440
|
+
private setupMessageListener;
|
|
441
|
+
/**
|
|
442
|
+
* Handle extension event
|
|
443
|
+
*/
|
|
444
|
+
private handleExtensionEvent;
|
|
445
|
+
/**
|
|
446
|
+
* Handle response from extension
|
|
447
|
+
*/
|
|
448
|
+
private handleExtensionResponse;
|
|
449
|
+
/**
|
|
450
|
+
* Post message to extension via content script
|
|
451
|
+
*/
|
|
452
|
+
private postMessageToExtension;
|
|
453
|
+
/**
|
|
454
|
+
* Check if we're in a context that can communicate with extension
|
|
455
|
+
*/
|
|
456
|
+
private hasExtensionContext;
|
|
457
|
+
/**
|
|
458
|
+
* Check and enforce rate limits to prevent denial-of-service attacks
|
|
459
|
+
*
|
|
460
|
+
* @private
|
|
461
|
+
* @throws {ZeroXIOWalletError} RATE_LIMIT_EXCEEDED if limits are exceeded
|
|
462
|
+
*
|
|
463
|
+
* @description
|
|
464
|
+
* Implements two-tier rate limiting:
|
|
465
|
+
* 1. Concurrent requests: Maximum 50 pending requests at once
|
|
466
|
+
* 2. Request frequency: Maximum 20 requests per second
|
|
467
|
+
*
|
|
468
|
+
* Rate limiting protects both the SDK and extension from:
|
|
469
|
+
* - Accidental infinite loops in dApp code
|
|
470
|
+
* - Malicious DoS attacks
|
|
471
|
+
* - Resource exhaustion
|
|
472
|
+
*
|
|
473
|
+
* @security Critical security function - enforces resource limits
|
|
474
|
+
*/
|
|
475
|
+
private checkRateLimit;
|
|
476
|
+
/**
|
|
477
|
+
* Generate cryptographically secure unique request ID
|
|
478
|
+
*
|
|
479
|
+
* @private
|
|
480
|
+
* @returns {string} A unique, unpredictable request identifier
|
|
481
|
+
*
|
|
482
|
+
* @description
|
|
483
|
+
* Uses Web Crypto API for secure random ID generation:
|
|
484
|
+
* 1. Primary: crypto.randomUUID() - UUID v4 format
|
|
485
|
+
* 2. Fallback: crypto.getRandomValues() - 128-bit random hex
|
|
486
|
+
* 3. Last resort: timestamp + counter (logs warning)
|
|
487
|
+
*
|
|
488
|
+
* Security importance:
|
|
489
|
+
* - Prevents request ID prediction attacks
|
|
490
|
+
* - Mitigates replay attacks
|
|
491
|
+
* - Makes session hijacking more difficult
|
|
492
|
+
*
|
|
493
|
+
* @security Critical - IDs must be cryptographically unpredictable
|
|
494
|
+
*/
|
|
495
|
+
private generateRequestId;
|
|
496
|
+
/**
|
|
497
|
+
* Start continuous extension detection
|
|
498
|
+
*/
|
|
499
|
+
private startExtensionDetection;
|
|
500
|
+
/**
|
|
501
|
+
* Check if extension is currently available
|
|
502
|
+
*/
|
|
503
|
+
private checkExtensionAvailability;
|
|
504
|
+
/**
|
|
505
|
+
* Detect extension signals/indicators
|
|
506
|
+
*/
|
|
507
|
+
private detectExtensionSignals;
|
|
508
|
+
/**
|
|
509
|
+
* Wait for extension to become available
|
|
510
|
+
*/
|
|
511
|
+
private waitForExtensionAvailability;
|
|
512
|
+
/**
|
|
513
|
+
* Get browser diagnostics for error reporting
|
|
514
|
+
*/
|
|
515
|
+
private getBrowserDiagnostics;
|
|
516
|
+
/**
|
|
517
|
+
* Get extension state diagnostics
|
|
518
|
+
*/
|
|
519
|
+
private getExtensionDiagnostics;
|
|
520
|
+
/**
|
|
521
|
+
* Cleanup pending requests
|
|
522
|
+
*/
|
|
523
|
+
cleanup(): void;
|
|
524
|
+
/**
|
|
525
|
+
* Get debug information
|
|
526
|
+
*/
|
|
527
|
+
getDebugInfo(): {
|
|
528
|
+
initialized: boolean;
|
|
529
|
+
available: boolean;
|
|
530
|
+
pendingRequests: number;
|
|
531
|
+
hasExtensionContext: boolean;
|
|
532
|
+
extensionDiagnostics: any;
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Network configuration for 0xio SDK
|
|
538
|
+
*/
|
|
539
|
+
|
|
540
|
+
declare const NETWORKS: Record<string, NetworkInfo>;
|
|
541
|
+
declare const DEFAULT_NETWORK_ID = "mainnet";
|
|
542
|
+
/**
|
|
543
|
+
* Get network configuration by ID
|
|
544
|
+
*/
|
|
545
|
+
declare function getNetworkConfig(networkId?: string): NetworkInfo;
|
|
546
|
+
/**
|
|
547
|
+
* Get all available networks
|
|
548
|
+
*/
|
|
549
|
+
declare function getAllNetworks(): NetworkInfo[];
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Default balance structure
|
|
553
|
+
*/
|
|
554
|
+
declare function createDefaultBalance(total?: number): Balance;
|
|
555
|
+
/**
|
|
556
|
+
* SDK Configuration constants
|
|
557
|
+
*/
|
|
558
|
+
declare const SDK_CONFIG: {
|
|
559
|
+
readonly version: "2.1.2";
|
|
560
|
+
readonly defaultNetworkId: "mainnet";
|
|
561
|
+
readonly communicationTimeout: 30000;
|
|
562
|
+
readonly retryAttempts: 3;
|
|
563
|
+
readonly retryDelay: 1000;
|
|
564
|
+
};
|
|
565
|
+
/**
|
|
566
|
+
* Get default network configuration
|
|
567
|
+
*/
|
|
568
|
+
declare function getDefaultNetwork(): NetworkInfo;
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* 0xio Wallet SDK - Utilities
|
|
572
|
+
* Helper functions for validation, formatting, and common operations
|
|
573
|
+
*/
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Validate wallet address for Octra blockchain
|
|
577
|
+
*/
|
|
578
|
+
declare function isValidAddress(address: string): boolean;
|
|
579
|
+
/**
|
|
580
|
+
* Validate transaction amount
|
|
581
|
+
*/
|
|
582
|
+
declare function isValidAmount(amount: number): boolean;
|
|
583
|
+
/**
|
|
584
|
+
* Validate network ID
|
|
585
|
+
*/
|
|
586
|
+
declare function isValidNetworkId(networkId: string): boolean;
|
|
587
|
+
/**
|
|
588
|
+
* Validate transaction message
|
|
589
|
+
*/
|
|
590
|
+
declare function isValidMessage(message: string): boolean;
|
|
591
|
+
/**
|
|
592
|
+
* Validate fee level
|
|
593
|
+
*/
|
|
594
|
+
declare function isValidFeeLevel(feeLevel: number): boolean;
|
|
595
|
+
/**
|
|
596
|
+
* Format OCT amount for display
|
|
597
|
+
*/
|
|
598
|
+
declare function formatOCT(amount: number, decimals?: number): string;
|
|
599
|
+
/**
|
|
600
|
+
* Format address for display (truncated)
|
|
601
|
+
*/
|
|
602
|
+
declare function formatAddress(address: string, prefixLength?: number, suffixLength?: number): string;
|
|
603
|
+
/**
|
|
604
|
+
* Format timestamp for display
|
|
605
|
+
*/
|
|
606
|
+
declare function formatTimestamp(timestamp: number): string;
|
|
607
|
+
/**
|
|
608
|
+
* Format transaction hash for display
|
|
609
|
+
*/
|
|
610
|
+
declare function formatTxHash(hash: string, length?: number): string;
|
|
611
|
+
/**
|
|
612
|
+
* Convert OCT to micro OCT (for network transmission)
|
|
613
|
+
*/
|
|
614
|
+
declare function toMicroOCT(amount: number): string;
|
|
615
|
+
/**
|
|
616
|
+
* Convert micro OCT to OCT (for display)
|
|
617
|
+
*/
|
|
618
|
+
declare function fromMicroOCT(microAmount: string | number): number;
|
|
619
|
+
/**
|
|
620
|
+
* Create standardized error messages
|
|
621
|
+
*/
|
|
622
|
+
declare function createErrorMessage(code: ErrorCode, context?: string): string;
|
|
623
|
+
/**
|
|
624
|
+
* Check if error is a specific type
|
|
625
|
+
*/
|
|
626
|
+
declare function isErrorType(error: any, code: ErrorCode): boolean;
|
|
627
|
+
/**
|
|
628
|
+
* Create a promise that resolves after a delay
|
|
629
|
+
*/
|
|
630
|
+
declare function delay(ms: number): Promise<void>;
|
|
631
|
+
/**
|
|
632
|
+
* Retry an async operation with exponential backoff
|
|
633
|
+
*/
|
|
634
|
+
declare function retry<T>(operation: () => Promise<T>, maxRetries?: number, baseDelay?: number): Promise<T>;
|
|
635
|
+
/**
|
|
636
|
+
* Timeout wrapper for promises
|
|
637
|
+
*/
|
|
638
|
+
declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, timeoutMessage?: string): Promise<T>;
|
|
639
|
+
/**
|
|
640
|
+
* Check if running in browser environment
|
|
641
|
+
*/
|
|
642
|
+
declare function isBrowser(): boolean;
|
|
643
|
+
/**
|
|
644
|
+
* Check if browser supports required features
|
|
645
|
+
*/
|
|
646
|
+
declare function checkBrowserSupport(): {
|
|
647
|
+
supported: boolean;
|
|
648
|
+
missingFeatures: string[];
|
|
649
|
+
};
|
|
650
|
+
/**
|
|
651
|
+
* Generate mock data for development/testing
|
|
652
|
+
*/
|
|
653
|
+
declare function generateMockData(): {
|
|
654
|
+
address: string;
|
|
655
|
+
balance: {
|
|
656
|
+
public: number;
|
|
657
|
+
private: number;
|
|
658
|
+
total: number;
|
|
659
|
+
currency: "OCT";
|
|
660
|
+
};
|
|
661
|
+
networkInfo: {
|
|
662
|
+
id: string;
|
|
663
|
+
name: string;
|
|
664
|
+
rpcUrl: string;
|
|
665
|
+
color: string;
|
|
666
|
+
isTestnet: boolean;
|
|
667
|
+
};
|
|
668
|
+
};
|
|
669
|
+
/**
|
|
670
|
+
* Create development logger
|
|
671
|
+
*/
|
|
672
|
+
declare function createLogger(prefix: string, debug: boolean): {
|
|
673
|
+
log: (...args: any[]) => void;
|
|
674
|
+
warn: (...args: any[]) => void;
|
|
675
|
+
error: (...args: any[]) => void;
|
|
676
|
+
debug: (...args: any[]) => void;
|
|
677
|
+
table: (data: any) => void;
|
|
678
|
+
group: (label: string) => void;
|
|
679
|
+
groupEnd: () => void;
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
declare const SDK_VERSION = "2.1.1";
|
|
683
|
+
declare const SUPPORTED_EXTENSION_VERSIONS: string[];
|
|
684
|
+
declare function createZeroXIOWallet(config: {
|
|
685
|
+
appName: string;
|
|
686
|
+
appDescription?: string;
|
|
687
|
+
debug?: boolean;
|
|
688
|
+
autoConnect?: boolean;
|
|
689
|
+
}): Promise<ZeroXIOWallet>;
|
|
690
|
+
declare const createOctraWallet: typeof createZeroXIOWallet;
|
|
691
|
+
declare function checkSDKCompatibility(): {
|
|
692
|
+
compatible: boolean;
|
|
693
|
+
issues: string[];
|
|
694
|
+
recommendations: string[];
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
export { DEFAULT_NETWORK_ID, ErrorCode, EventEmitter, ExtensionCommunicator, NETWORKS, SDK_CONFIG, SDK_VERSION, SUPPORTED_EXTENSION_VERSIONS, ZeroXIOWallet, ZeroXIOWalletError, checkBrowserSupport, checkSDKCompatibility, createDefaultBalance, createErrorMessage, createLogger, createOctraWallet, createZeroXIOWallet, delay, formatAddress, formatOCT, formatTimestamp, formatTxHash, formatOCT as formatZeroXIO, fromMicroOCT, fromMicroOCT as fromMicroZeroXIO, generateMockData, getAllNetworks, getDefaultNetwork, getNetworkConfig, isBrowser, isErrorType, isValidAddress, isValidAmount, isValidFeeLevel, isValidMessage, isValidNetworkId, retry, toMicroOCT, toMicroOCT as toMicroZeroXIO, withTimeout };
|
|
698
|
+
export type { AccountChangedEvent, Balance, BalanceChangedEvent, ConnectEvent, ConnectOptions, ConnectionInfo, DisconnectEvent, ErrorEvent, ExtensionRequest, ExtensionResponse, NetworkChangedEvent, NetworkInfo, PendingPrivateTransfer, Permission, PrivateBalanceInfo, PrivateTransferData, SDKConfig, SignedTransaction, Transaction, TransactionConfirmedEvent, TransactionData, TransactionHistory, TransactionResult, WalletAddress, WalletEvent, WalletEventType };
|