@t402/wdk 2.0.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { Address } from 'viem';
2
- import { ClientEvmSigner, BridgeSigner, Usdt0Bridge } from '@t402/evm';
2
+ import { ClientEvmSigner, Usdt0Bridge, BridgeSigner } from '@t402/evm';
3
3
  export { BridgeQuote, BridgeSigner, LAYERZERO_ENDPOINT_IDS, USDT0_OFT_ADDRESSES, Usdt0Bridge, getBridgeableChains, supportsBridging } from '@t402/evm';
4
4
 
5
5
  /**
@@ -660,8 +660,7 @@ declare function createWDKSigner(wdk: WDKInstance, chain: string, accountIndex?:
660
660
  */
661
661
  declare class MockWDKSigner implements ClientEvmSigner {
662
662
  readonly address: Address;
663
- private _privateKey;
664
- constructor(address: Address, privateKey: `0x${string}`);
663
+ constructor(address: Address, _privateKey: `0x${string}`);
665
664
  signTypedData(_message: {
666
665
  domain: Record<string, unknown>;
667
666
  types: Record<string, unknown>;
@@ -706,8 +705,6 @@ declare class MockWDKSigner implements ClientEvmSigner {
706
705
  */
707
706
  declare class T402WDK {
708
707
  private _wdk;
709
- private _config;
710
- private _options;
711
708
  private _normalizedChains;
712
709
  private _seedPhrase;
713
710
  private _signerCache;
@@ -863,7 +860,7 @@ declare class T402WDK {
863
860
  * @param preferredToken - Preferred token ("USDT0" | "USDC")
864
861
  * @throws {BalanceError} If balance aggregation fails
865
862
  */
866
- findBestChainForPayment(amount: bigint, preferredToken?: "USDT0" | "USDC"): Promise<{
863
+ findBestChainForPayment(amount: bigint, preferredToken?: 'USDT0' | 'USDC'): Promise<{
867
864
  chain: string;
868
865
  token: string;
869
866
  balance: bigint;
@@ -943,7 +940,7 @@ declare class T402WDK {
943
940
  /**
944
941
  * Default chain configurations
945
942
  */
946
- declare const DEFAULT_CHAINS: Record<string, Omit<NormalizedChainConfig, "provider">>;
943
+ declare const DEFAULT_CHAINS: Record<string, Omit<NormalizedChainConfig, 'provider'>>;
947
944
  /**
948
945
  * Default RPC endpoints (public endpoints, may have rate limits)
949
946
  */
@@ -1099,9 +1096,9 @@ declare class SignerError extends WDKError {
1099
1096
  * Error thrown for signing operations
1100
1097
  */
1101
1098
  declare class SigningError extends WDKError {
1102
- readonly operation: "signTypedData" | "signMessage";
1099
+ readonly operation: 'signTypedData' | 'signMessage';
1103
1100
  constructor(code: WDKErrorCode, message: string, options: {
1104
- operation: "signTypedData" | "signMessage";
1101
+ operation: 'signTypedData' | 'signMessage';
1105
1102
  cause?: Error;
1106
1103
  context?: Record<string, unknown>;
1107
1104
  });
@@ -1232,7 +1229,7 @@ declare class WdkBridge {
1232
1229
  /**
1233
1230
  * Get or create a bridge instance for a chain
1234
1231
  */
1235
- private getBridge;
1232
+ getBridge(chain: string, signer: WDKSigner): Usdt0Bridge;
1236
1233
  /**
1237
1234
  * Check if a chain supports USDT0 bridging
1238
1235
  */
@@ -1282,4 +1279,380 @@ declare class WdkBridge {
1282
1279
  */
1283
1280
  declare function createDirectBridge(signer: BridgeSigner, chain: string): Usdt0Bridge;
1284
1281
 
1285
- export { type AggregatedBalance, BalanceCache, type BalanceCacheConfig, type BalanceCacheStats, BalanceError, BridgeError, type BridgeParams, type BridgeQuoteResult, type BridgeResult, CHAIN_TOKENS, type CacheConfig, type CacheStats, type ChainBalance, ChainError, DEFAULT_BALANCE_CACHE_CONFIG, DEFAULT_CACHE_CONFIG, DEFAULT_CHAINS, DEFAULT_RETRY_CONFIG, DEFAULT_RPC_ENDPOINTS, type EvmChainConfig, MockWDKSigner, type NormalizedChainConfig, RPCError, type RetryConfig, SignerError, SigningError, type T402BalanceCacheConfig, T402WDK, type T402WDKConfig, type T402WDKOptions, type T402WDKSigner, TTLCache, type TokenBalance, type TokenInfo, TransactionError, type TypedDataDomain, type TypedDataTypes, USDC_ADDRESSES, USDT0_ADDRESSES, USDT_LEGACY_ADDRESSES, type WDKAccount, type WDKConstructor, WDKError, WDKErrorCode, WDKInitializationError, type WDKInstance, WDKSigner, WdkBridge, createDirectBridge, createWDKSigner, getChainFromNetwork, getChainId, getNetworkFromChain, getPreferredToken, getUsdt0Chains, hasErrorCode, isWDKError, normalizeChainConfig, withRetry, withTimeout, wrapError };
1282
+ /**
1283
+ * Hardware wallet type definitions for T402 WDK
1284
+ */
1285
+
1286
+ /**
1287
+ * Supported hardware wallet types
1288
+ */
1289
+ type HardwareWalletType = 'ledger' | 'trezor';
1290
+ /**
1291
+ * Hardware wallet device status
1292
+ */
1293
+ type DeviceStatus = 'disconnected' | 'connecting' | 'connected' | 'locked' | 'unlocked' | 'app_closed' | 'ready';
1294
+ /**
1295
+ * Hardware wallet connection options
1296
+ */
1297
+ interface HardwareWalletConnectionOptions {
1298
+ /** Transport type for Ledger (default: "webusb") */
1299
+ transport?: 'webusb' | 'webhid' | 'bluetooth';
1300
+ /** Account index for HD derivation (default: 0) */
1301
+ accountIndex?: number;
1302
+ /** Custom derivation path (default: m/44'/60'/0'/0/{accountIndex}) */
1303
+ derivationPath?: string;
1304
+ /** Timeout for connection in milliseconds (default: 30000) */
1305
+ timeout?: number;
1306
+ }
1307
+ /**
1308
+ * Hardware wallet device info
1309
+ */
1310
+ interface HardwareWalletDeviceInfo {
1311
+ /** Wallet type */
1312
+ type: HardwareWalletType;
1313
+ /** Device model (e.g., "Nano S", "Nano X", "Model T") */
1314
+ model?: string;
1315
+ /** Firmware version */
1316
+ firmwareVersion?: string;
1317
+ /** Whether the device is locked */
1318
+ isLocked: boolean;
1319
+ /** Current device status */
1320
+ status: DeviceStatus;
1321
+ }
1322
+ /**
1323
+ * Hardware wallet signer interface
1324
+ */
1325
+ interface HardwareWalletSigner {
1326
+ /** Get wallet address */
1327
+ readonly address: Address;
1328
+ /** Wallet type */
1329
+ readonly walletType: HardwareWalletType;
1330
+ /** Device info */
1331
+ readonly deviceInfo: HardwareWalletDeviceInfo;
1332
+ /** Whether the signer is connected */
1333
+ readonly isConnected: boolean;
1334
+ /**
1335
+ * Connect to the hardware wallet
1336
+ */
1337
+ connect(): Promise<void>;
1338
+ /**
1339
+ * Disconnect from the hardware wallet
1340
+ */
1341
+ disconnect(): Promise<void>;
1342
+ /**
1343
+ * Sign EIP-712 typed data
1344
+ */
1345
+ signTypedData(params: {
1346
+ domain: Record<string, unknown>;
1347
+ types: Record<string, unknown>;
1348
+ primaryType: string;
1349
+ message: Record<string, unknown>;
1350
+ }): Promise<`0x${string}`>;
1351
+ /**
1352
+ * Sign a personal message
1353
+ */
1354
+ signMessage(message: string | Uint8Array): Promise<`0x${string}`>;
1355
+ /**
1356
+ * Get all available addresses (for account selection)
1357
+ * @param count Number of addresses to retrieve
1358
+ * @param startIndex Starting index
1359
+ */
1360
+ getAddresses?(count: number, startIndex?: number): Promise<Address[]>;
1361
+ }
1362
+ /**
1363
+ * Ledger-specific options
1364
+ */
1365
+ interface LedgerOptions extends HardwareWalletConnectionOptions {
1366
+ /** Whether to scramble key for privacy (default: true) */
1367
+ scrambleKey?: boolean;
1368
+ /** App name on the Ledger (default: "Ethereum") */
1369
+ appName?: string;
1370
+ }
1371
+ /**
1372
+ * Trezor-specific options
1373
+ */
1374
+ interface TrezorOptions extends HardwareWalletConnectionOptions {
1375
+ /** Manifest for Trezor Connect (required) */
1376
+ manifest: {
1377
+ email: string;
1378
+ appUrl: string;
1379
+ };
1380
+ /** Whether to use popup for interactions (default: true) */
1381
+ popup?: boolean;
1382
+ /** Debug mode */
1383
+ debug?: boolean;
1384
+ }
1385
+ /**
1386
+ * Error codes for hardware wallet operations
1387
+ */
1388
+ declare enum HardwareWalletErrorCode {
1389
+ DEVICE_NOT_FOUND = "DEVICE_NOT_FOUND",
1390
+ CONNECTION_FAILED = "CONNECTION_FAILED",
1391
+ DEVICE_LOCKED = "DEVICE_LOCKED",
1392
+ APP_NOT_OPEN = "APP_NOT_OPEN",
1393
+ TRANSPORT_ERROR = "TRANSPORT_ERROR",
1394
+ USER_REJECTED = "USER_REJECTED",
1395
+ SIGNING_FAILED = "SIGNING_FAILED",
1396
+ INVALID_DATA = "INVALID_DATA",
1397
+ NOT_SUPPORTED = "NOT_SUPPORTED",
1398
+ TIMEOUT = "TIMEOUT",
1399
+ UNKNOWN_ERROR = "UNKNOWN_ERROR"
1400
+ }
1401
+ /**
1402
+ * Hardware wallet error
1403
+ */
1404
+ declare class HardwareWalletError extends Error {
1405
+ readonly code: HardwareWalletErrorCode;
1406
+ readonly walletType: HardwareWalletType;
1407
+ readonly cause?: Error;
1408
+ constructor(code: HardwareWalletErrorCode, message: string, walletType: HardwareWalletType, cause?: Error);
1409
+ }
1410
+
1411
+ /**
1412
+ * Ledger Hardware Wallet Signer for T402 WDK
1413
+ *
1414
+ * Provides T402-compatible signing using Ledger hardware wallets.
1415
+ * Supports Nano S, Nano S Plus, Nano X, and Stax devices.
1416
+ *
1417
+ * @example
1418
+ * ```typescript
1419
+ * import { LedgerSigner } from '@t402/wdk';
1420
+ *
1421
+ * const ledger = new LedgerSigner({ accountIndex: 0 });
1422
+ * await ledger.connect();
1423
+ *
1424
+ * // Get address
1425
+ * console.log('Address:', ledger.address);
1426
+ *
1427
+ * // Sign typed data for T402 payment
1428
+ * const signature = await ledger.signTypedData(typedData);
1429
+ * ```
1430
+ */
1431
+
1432
+ /**
1433
+ * Ledger hardware wallet signer
1434
+ */
1435
+ declare class LedgerSigner implements HardwareWalletSigner {
1436
+ readonly walletType: "ledger";
1437
+ private _address;
1438
+ private _transport;
1439
+ private _eth;
1440
+ private _options;
1441
+ private _status;
1442
+ private _deviceInfo;
1443
+ constructor(options?: LedgerOptions);
1444
+ /**
1445
+ * Get the wallet address
1446
+ */
1447
+ get address(): Address;
1448
+ /**
1449
+ * Get device info
1450
+ */
1451
+ get deviceInfo(): HardwareWalletDeviceInfo;
1452
+ /**
1453
+ * Check if connected
1454
+ */
1455
+ get isConnected(): boolean;
1456
+ /**
1457
+ * Get the derivation path
1458
+ */
1459
+ get derivationPath(): string;
1460
+ /**
1461
+ * Connect to the Ledger device
1462
+ */
1463
+ connect(): Promise<void>;
1464
+ /**
1465
+ * Disconnect from the Ledger device
1466
+ */
1467
+ disconnect(): Promise<void>;
1468
+ /**
1469
+ * Sign EIP-712 typed data
1470
+ *
1471
+ * Note: Requires Ethereum app version 1.6.0+ for EIP-712 support
1472
+ */
1473
+ signTypedData(params: {
1474
+ domain: Record<string, unknown>;
1475
+ types: Record<string, unknown>;
1476
+ primaryType: string;
1477
+ message: Record<string, unknown>;
1478
+ }): Promise<`0x${string}`>;
1479
+ /**
1480
+ * Sign a personal message
1481
+ */
1482
+ signMessage(message: string | Uint8Array): Promise<`0x${string}`>;
1483
+ /**
1484
+ * Get multiple addresses for account selection
1485
+ */
1486
+ getAddresses(count?: number, startIndex?: number): Promise<Address[]>;
1487
+ /**
1488
+ * Get the appropriate transport module based on options
1489
+ */
1490
+ private _getTransportModule;
1491
+ /**
1492
+ * Wrap errors in HardwareWalletError
1493
+ */
1494
+ private _wrapError;
1495
+ }
1496
+ /**
1497
+ * Create a Ledger signer and connect
1498
+ */
1499
+ declare function createLedgerSigner(options?: LedgerOptions): Promise<LedgerSigner>;
1500
+
1501
+ /**
1502
+ * Trezor Hardware Wallet Signer for T402 WDK
1503
+ *
1504
+ * Provides T402-compatible signing using Trezor hardware wallets.
1505
+ * Supports Trezor One, Model T, and Safe 3 devices.
1506
+ *
1507
+ * @example
1508
+ * ```typescript
1509
+ * import { TrezorSigner } from '@t402/wdk';
1510
+ *
1511
+ * const trezor = new TrezorSigner({
1512
+ * manifest: {
1513
+ * email: 'developer@example.com',
1514
+ * appUrl: 'https://example.com'
1515
+ * }
1516
+ * });
1517
+ * await trezor.connect();
1518
+ *
1519
+ * // Get address
1520
+ * console.log('Address:', trezor.address);
1521
+ *
1522
+ * // Sign typed data for T402 payment
1523
+ * const signature = await trezor.signTypedData(typedData);
1524
+ * ```
1525
+ */
1526
+
1527
+ /**
1528
+ * Trezor hardware wallet signer
1529
+ */
1530
+ declare class TrezorSigner implements HardwareWalletSigner {
1531
+ readonly walletType: "trezor";
1532
+ private _address;
1533
+ private _options;
1534
+ private _status;
1535
+ private _deviceInfo;
1536
+ private _initialized;
1537
+ constructor(options: TrezorOptions);
1538
+ /**
1539
+ * Get the wallet address
1540
+ */
1541
+ get address(): Address;
1542
+ /**
1543
+ * Get device info
1544
+ */
1545
+ get deviceInfo(): HardwareWalletDeviceInfo;
1546
+ /**
1547
+ * Check if connected
1548
+ */
1549
+ get isConnected(): boolean;
1550
+ /**
1551
+ * Get the derivation path
1552
+ */
1553
+ get derivationPath(): string;
1554
+ /**
1555
+ * Initialize Trezor Connect
1556
+ */
1557
+ private _initTrezorConnect;
1558
+ /**
1559
+ * Connect to the Trezor device
1560
+ */
1561
+ connect(): Promise<void>;
1562
+ /**
1563
+ * Disconnect from the Trezor device
1564
+ */
1565
+ disconnect(): Promise<void>;
1566
+ /**
1567
+ * Sign EIP-712 typed data
1568
+ */
1569
+ signTypedData(params: {
1570
+ domain: Record<string, unknown>;
1571
+ types: Record<string, unknown>;
1572
+ primaryType: string;
1573
+ message: Record<string, unknown>;
1574
+ }): Promise<`0x${string}`>;
1575
+ /**
1576
+ * Sign a personal message
1577
+ */
1578
+ signMessage(message: string | Uint8Array): Promise<`0x${string}`>;
1579
+ /**
1580
+ * Get multiple addresses for account selection
1581
+ */
1582
+ getAddresses(count?: number, startIndex?: number): Promise<Address[]>;
1583
+ /**
1584
+ * Convert EIP-712 types to Trezor format
1585
+ */
1586
+ private _convertTypesToTrezorFormat;
1587
+ /**
1588
+ * Wrap errors in HardwareWalletError
1589
+ */
1590
+ private _wrapError;
1591
+ }
1592
+ /**
1593
+ * Create a Trezor signer and connect
1594
+ */
1595
+ declare function createTrezorSigner(options: TrezorOptions): Promise<TrezorSigner>;
1596
+
1597
+ /**
1598
+ * Hardware Wallet Support for T402 WDK
1599
+ *
1600
+ * This module provides hardware wallet integration for T402 payments,
1601
+ * supporting Ledger and Trezor devices.
1602
+ *
1603
+ * @example Ledger
1604
+ * ```typescript
1605
+ * import { LedgerSigner, createLedgerSigner } from '@t402/wdk';
1606
+ *
1607
+ * // Create and connect
1608
+ * const ledger = await createLedgerSigner({ accountIndex: 0 });
1609
+ * console.log('Address:', ledger.address);
1610
+ *
1611
+ * // Sign T402 payment
1612
+ * const signature = await ledger.signTypedData(paymentData);
1613
+ *
1614
+ * // Disconnect when done
1615
+ * await ledger.disconnect();
1616
+ * ```
1617
+ *
1618
+ * @example Trezor
1619
+ * ```typescript
1620
+ * import { TrezorSigner, createTrezorSigner } from '@t402/wdk';
1621
+ *
1622
+ * // Create and connect (manifest required)
1623
+ * const trezor = await createTrezorSigner({
1624
+ * manifest: {
1625
+ * email: 'developer@example.com',
1626
+ * appUrl: 'https://example.com'
1627
+ * }
1628
+ * });
1629
+ * console.log('Address:', trezor.address);
1630
+ *
1631
+ * // Sign T402 payment
1632
+ * const signature = await trezor.signTypedData(paymentData);
1633
+ *
1634
+ * // Disconnect when done
1635
+ * await trezor.disconnect();
1636
+ * ```
1637
+ */
1638
+
1639
+ /**
1640
+ * Detect available hardware wallets
1641
+ *
1642
+ * Note: This function checks for WebUSB/WebHID support and
1643
+ * doesn't actually probe for devices.
1644
+ */
1645
+ declare function detectHardwareWalletSupport(): {
1646
+ ledger: {
1647
+ webusb: boolean;
1648
+ webhid: boolean;
1649
+ bluetooth: boolean;
1650
+ };
1651
+ trezor: boolean;
1652
+ };
1653
+ /**
1654
+ * Check if hardware wallet signing is supported in the current environment
1655
+ */
1656
+ declare function isHardwareWalletSupported(): boolean;
1657
+
1658
+ export { type AggregatedBalance, BalanceCache, type BalanceCacheConfig, type BalanceCacheStats, BalanceError, BridgeError, type BridgeParams, type BridgeQuoteResult, type BridgeResult, CHAIN_TOKENS, type CacheConfig, type CacheStats, type ChainBalance, ChainError, DEFAULT_BALANCE_CACHE_CONFIG, DEFAULT_CACHE_CONFIG, DEFAULT_CHAINS, DEFAULT_RETRY_CONFIG, DEFAULT_RPC_ENDPOINTS, type DeviceStatus, type EvmChainConfig, type HardwareWalletConnectionOptions, type HardwareWalletDeviceInfo, HardwareWalletError, HardwareWalletErrorCode, type HardwareWalletSigner, type HardwareWalletType, type LedgerOptions, LedgerSigner, MockWDKSigner, type NormalizedChainConfig, RPCError, type RetryConfig, SignerError, SigningError, type T402BalanceCacheConfig, T402WDK, type T402WDKConfig, type T402WDKOptions, type T402WDKSigner, TTLCache, type TokenBalance, type TokenInfo, TransactionError, type TrezorOptions, TrezorSigner, type TypedDataDomain, type TypedDataTypes, USDC_ADDRESSES, USDT0_ADDRESSES, USDT_LEGACY_ADDRESSES, type WDKAccount, type WDKConstructor, WDKError, WDKErrorCode, WDKInitializationError, type WDKInstance, WDKSigner, WdkBridge, createDirectBridge, createLedgerSigner, createTrezorSigner, createWDKSigner, detectHardwareWalletSupport, getChainFromNetwork, getChainId, getNetworkFromChain, getPreferredToken, getUsdt0Chains, hasErrorCode, isHardwareWalletSupported, isWDKError, normalizeChainConfig, withRetry, withTimeout, wrapError };