w3pk 0.7.1 → 0.7.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/README.md CHANGED
@@ -19,8 +19,8 @@ import { createWeb3Passkey } from 'w3pk'
19
19
  const w3pk = createWeb3Passkey()
20
20
 
21
21
  // Register (auto-generates wallet and stores it securely)
22
- const { mnemonic } = await w3pk.register({ username: 'alice' })
23
- console.log('⚠️ Save this recovery phrase:', mnemonic)
22
+ const { address, username } = await w3pk.register({ username: 'alice' })
23
+ console.log(' Registered:', username, 'with address:', address)
24
24
 
25
25
  // Login (for subsequent sessions)
26
26
  await w3pk.login()
@@ -46,6 +46,7 @@ const rpcUrl = endpoints[0]
46
46
  - 🌱 HD wallet generation (BIP39/BIP44)
47
47
  - 🔢 Multi-address derivation
48
48
  - 🥷 ERC-5564 stealth addresses (privacy-preserving transactions with view tags)
49
+ - 🧮 ZK primitives (zero-knowledge proof generation and verification)
49
50
  - 🔗 Chainlist support (2390+ networks, auto-filtered RPC endpoints)
50
51
  - ⚡ EIP-7702 network detection (329+ supported networks)
51
52
  - 🛡️ Three-layer backup & recovery system
@@ -53,23 +54,14 @@ const rpcUrl = endpoints[0]
53
54
  - Encrypted backups (ZIP/QR with password protection)
54
55
  - Social recovery (Shamir Secret Sharing)
55
56
 
56
- **Optional: Zero-Knowledge Proofs**
57
-
58
- Requires additional dependencies (~70MB):
59
- ```bash
60
- npm install snarkjs circomlibjs
61
- ```
62
-
63
- See [ZK Integration Guide](./docs/ZK_INTEGRATION_GUIDE.md) to get started.
64
-
65
57
  ## API
66
58
 
67
59
  ### Authentication Flow
68
60
 
69
61
  ```typescript
70
- // Register (auto-stores wallet)
71
- const { mnemonic } = await w3pk.register({ username: 'alice' })
72
- // Returns: { mnemonic } - SAVE THIS!
62
+ // Register (generates and stores wallet securely)
63
+ const { address, username } = await w3pk.register({ username: 'alice' })
64
+ // Returns: { address, username }
73
65
 
74
66
  // Subsequent sessions: just login
75
67
  await w3pk.login()
@@ -82,12 +74,15 @@ w3pk.isAuthenticated
82
74
  w3pk.user
83
75
  ```
84
76
 
85
- **Advanced: Pre-generate wallet (optional)**
77
+ **Important: Backup your wallet!**
86
78
  ```typescript
87
- // If you want to see the wallet before registering:
88
- const { mnemonic } = await w3pk.generateWallet()
89
- const { mnemonic } = await w3pk.register({ username: 'alice' })
90
- // register() will use the pre-generated wallet
79
+ // After registration, users can create a backup
80
+ const mnemonic = await w3pk.exportMnemonic({ requireAuth: true })
81
+ console.log('⚠️ Save this recovery phrase:', mnemonic)
82
+
83
+ // Or create encrypted backups:
84
+ const zipBackup = await w3pk.createZipBackup('strong-password')
85
+ const qrBackup = await w3pk.createQRBackup('optional-password')
91
86
  ```
92
87
 
93
88
  ### Wallet Operations
@@ -225,12 +220,21 @@ const myPayments = await w3pk.stealth?.scanAnnouncements(announcements)
225
220
  ### Backup & Recovery
226
221
 
227
222
  ```typescript
223
+ import { isStrongPassword } from 'w3pk'
224
+
225
+ // Validate password strength before creating backups
226
+ const password = 'MyS3cur3!Password@2042'
227
+ if (!isStrongPassword(password)) {
228
+ throw new Error('Password does not meet security requirements')
229
+ }
230
+ // Requirements: 12+ chars, uppercase, lowercase, number, special char, not common
231
+
228
232
  // Get backup status
229
233
  const status = await w3pk.getBackupStatus()
230
234
  console.log('Security Score:', status.securityScore.score) // 0-100
231
235
 
232
236
  // Create encrypted ZIP backup
233
- const blob = await w3pk.createZipBackup('MyS3cur3!Password@2042')
237
+ const blob = await w3pk.createZipBackup(password)
234
238
  // Save blob to file system
235
239
 
236
240
  // Create QR backup
package/dist/index.d.mts CHANGED
@@ -320,9 +320,10 @@ declare class Web3Passkey {
320
320
  private zkModule?;
321
321
  constructor(config?: Web3PasskeyConfig);
322
322
  /**
323
- * Lazy-load ZK module to avoid bundling large dependencies
323
+ * Lazy-load ZK module only when accessed
324
+ * This prevents bundlers from including circomlibjs unless ZK features are used
324
325
  */
325
- private initializeZKModule;
326
+ private loadZKModule;
326
327
  /**
327
328
  * Get mnemonic from active session or trigger authentication
328
329
  * This is used internally by methods that need the mnemonic
@@ -334,12 +335,13 @@ declare class Web3Passkey {
334
335
  * Register a new user with WebAuthn
335
336
  * Automatically generates a wallet if none exists
336
337
  * Creates a passkey and associates it with the Ethereum address (account #0)
337
- * Returns the mnemonic phrase - IMPORTANT: User must save this!
338
+ * Returns the derived address #0 and username
338
339
  */
339
340
  register(options: {
340
341
  username: string;
341
342
  }): Promise<{
342
- mnemonic: string;
343
+ address: string;
344
+ username: string;
343
345
  }>;
344
346
  /**
345
347
  * Login with WebAuthn (usernameless)
@@ -550,10 +552,6 @@ declare class Web3Passkey {
550
552
  * @param hours - Session duration in hours
551
553
  */
552
554
  setSessionDuration(hours: number): void;
553
- /**
554
- * SDK version
555
- */
556
- get version(): string;
557
555
  }
558
556
 
559
557
  /**
@@ -1104,6 +1102,30 @@ declare function getAllTopics(): string[];
1104
1102
  */
1105
1103
  declare function searchExplainers(query: string): EducationalModule[];
1106
1104
 
1105
+ /**
1106
+ * Input validation utilities
1107
+ */
1108
+ declare function validateEthereumAddress(address: string): boolean;
1109
+ declare function validateUsername(username: string): boolean;
1110
+ declare function validateMnemonic(mnemonic: string): boolean;
1111
+ declare function assertEthereumAddress(address: string): void;
1112
+ declare function assertUsername(username: string): void;
1113
+ declare function assertMnemonic(mnemonic: string): void;
1114
+ /**
1115
+ * Validates password strength based on security best practices
1116
+ * @param password - The password to validate
1117
+ * @returns true if password meets strength requirements, false otherwise
1118
+ *
1119
+ * Requirements:
1120
+ * - At least 12 characters long
1121
+ * - Contains at least one uppercase letter
1122
+ * - Contains at least one lowercase letter
1123
+ * - Contains at least one number
1124
+ * - Contains at least one special character
1125
+ * - Not a common password
1126
+ */
1127
+ declare function isStrongPassword(password: string): boolean;
1128
+
1107
1129
  /**
1108
1130
  * Web3 Passkey SDK
1109
1131
  * Passwordless authentication with encrypted wallets
@@ -1111,4 +1133,4 @@ declare function searchExplainers(query: string): EducationalModule[];
1111
1133
 
1112
1134
  declare function createWeb3Passkey(config?: Web3PasskeyConfig): Web3Passkey;
1113
1135
 
1114
- export { ApiError, AuthenticationError, BackupManager, type BackupStatus, BackupStorage, CryptoError, type DeviceInfo, DeviceManager, type EncryptedBackupInfo, type Guardian, type GuardianInvite, PlatformDetector, type QRBackupOptions, type RecoveryProgress, type RecoveryScenario, type RecoveryShare, RecoverySimulator, RegistrationError, type SecurityScore, type SimulationResult, type SocialRecoveryConfig, SocialRecoveryManager, type StealthAddressConfig, StealthAddressModule, type StealthAddressResult, type StealthKeys, StorageError, type SyncCapabilities, type SyncStatus, type SyncVault, type UserInfo, VaultSync, WalletError, type WalletInfo, Web3Passkey, type Web3PasskeyConfig, Web3PasskeyError, type ZipBackupOptions, canControlStealthAddress, checkStealthAddress, computeStealthPrivateKey, createWalletFromMnemonic, createWeb3Passkey, createWeb3Passkey as default, deriveStealthKeys, deriveWalletFromMnemonic, generateBIP39Wallet, generateStealthAddress, getAllTopics, getExplainer, searchExplainers };
1136
+ export { ApiError, AuthenticationError, BackupManager, type BackupStatus, BackupStorage, CryptoError, type DeviceInfo, DeviceManager, type EncryptedBackupInfo, type Guardian, type GuardianInvite, PlatformDetector, type QRBackupOptions, type RecoveryProgress, type RecoveryScenario, type RecoveryShare, RecoverySimulator, RegistrationError, type SecurityScore, type SimulationResult, type SocialRecoveryConfig, SocialRecoveryManager, type StealthAddressConfig, StealthAddressModule, type StealthAddressResult, type StealthKeys, StorageError, type SyncCapabilities, type SyncStatus, type SyncVault, type UserInfo, VaultSync, WalletError, type WalletInfo, Web3Passkey, type Web3PasskeyConfig, Web3PasskeyError, type ZipBackupOptions, assertEthereumAddress, assertMnemonic, assertUsername, canControlStealthAddress, checkStealthAddress, computeStealthPrivateKey, createWalletFromMnemonic, createWeb3Passkey, createWeb3Passkey as default, deriveStealthKeys, deriveWalletFromMnemonic, generateBIP39Wallet, generateStealthAddress, getAllTopics, getExplainer, isStrongPassword, searchExplainers, validateEthereumAddress, validateMnemonic, validateUsername };
package/dist/index.d.ts CHANGED
@@ -320,9 +320,10 @@ declare class Web3Passkey {
320
320
  private zkModule?;
321
321
  constructor(config?: Web3PasskeyConfig);
322
322
  /**
323
- * Lazy-load ZK module to avoid bundling large dependencies
323
+ * Lazy-load ZK module only when accessed
324
+ * This prevents bundlers from including circomlibjs unless ZK features are used
324
325
  */
325
- private initializeZKModule;
326
+ private loadZKModule;
326
327
  /**
327
328
  * Get mnemonic from active session or trigger authentication
328
329
  * This is used internally by methods that need the mnemonic
@@ -334,12 +335,13 @@ declare class Web3Passkey {
334
335
  * Register a new user with WebAuthn
335
336
  * Automatically generates a wallet if none exists
336
337
  * Creates a passkey and associates it with the Ethereum address (account #0)
337
- * Returns the mnemonic phrase - IMPORTANT: User must save this!
338
+ * Returns the derived address #0 and username
338
339
  */
339
340
  register(options: {
340
341
  username: string;
341
342
  }): Promise<{
342
- mnemonic: string;
343
+ address: string;
344
+ username: string;
343
345
  }>;
344
346
  /**
345
347
  * Login with WebAuthn (usernameless)
@@ -550,10 +552,6 @@ declare class Web3Passkey {
550
552
  * @param hours - Session duration in hours
551
553
  */
552
554
  setSessionDuration(hours: number): void;
553
- /**
554
- * SDK version
555
- */
556
- get version(): string;
557
555
  }
558
556
 
559
557
  /**
@@ -1104,6 +1102,30 @@ declare function getAllTopics(): string[];
1104
1102
  */
1105
1103
  declare function searchExplainers(query: string): EducationalModule[];
1106
1104
 
1105
+ /**
1106
+ * Input validation utilities
1107
+ */
1108
+ declare function validateEthereumAddress(address: string): boolean;
1109
+ declare function validateUsername(username: string): boolean;
1110
+ declare function validateMnemonic(mnemonic: string): boolean;
1111
+ declare function assertEthereumAddress(address: string): void;
1112
+ declare function assertUsername(username: string): void;
1113
+ declare function assertMnemonic(mnemonic: string): void;
1114
+ /**
1115
+ * Validates password strength based on security best practices
1116
+ * @param password - The password to validate
1117
+ * @returns true if password meets strength requirements, false otherwise
1118
+ *
1119
+ * Requirements:
1120
+ * - At least 12 characters long
1121
+ * - Contains at least one uppercase letter
1122
+ * - Contains at least one lowercase letter
1123
+ * - Contains at least one number
1124
+ * - Contains at least one special character
1125
+ * - Not a common password
1126
+ */
1127
+ declare function isStrongPassword(password: string): boolean;
1128
+
1107
1129
  /**
1108
1130
  * Web3 Passkey SDK
1109
1131
  * Passwordless authentication with encrypted wallets
@@ -1111,4 +1133,4 @@ declare function searchExplainers(query: string): EducationalModule[];
1111
1133
 
1112
1134
  declare function createWeb3Passkey(config?: Web3PasskeyConfig): Web3Passkey;
1113
1135
 
1114
- export { ApiError, AuthenticationError, BackupManager, type BackupStatus, BackupStorage, CryptoError, type DeviceInfo, DeviceManager, type EncryptedBackupInfo, type Guardian, type GuardianInvite, PlatformDetector, type QRBackupOptions, type RecoveryProgress, type RecoveryScenario, type RecoveryShare, RecoverySimulator, RegistrationError, type SecurityScore, type SimulationResult, type SocialRecoveryConfig, SocialRecoveryManager, type StealthAddressConfig, StealthAddressModule, type StealthAddressResult, type StealthKeys, StorageError, type SyncCapabilities, type SyncStatus, type SyncVault, type UserInfo, VaultSync, WalletError, type WalletInfo, Web3Passkey, type Web3PasskeyConfig, Web3PasskeyError, type ZipBackupOptions, canControlStealthAddress, checkStealthAddress, computeStealthPrivateKey, createWalletFromMnemonic, createWeb3Passkey, createWeb3Passkey as default, deriveStealthKeys, deriveWalletFromMnemonic, generateBIP39Wallet, generateStealthAddress, getAllTopics, getExplainer, searchExplainers };
1136
+ export { ApiError, AuthenticationError, BackupManager, type BackupStatus, BackupStorage, CryptoError, type DeviceInfo, DeviceManager, type EncryptedBackupInfo, type Guardian, type GuardianInvite, PlatformDetector, type QRBackupOptions, type RecoveryProgress, type RecoveryScenario, type RecoveryShare, RecoverySimulator, RegistrationError, type SecurityScore, type SimulationResult, type SocialRecoveryConfig, SocialRecoveryManager, type StealthAddressConfig, StealthAddressModule, type StealthAddressResult, type StealthKeys, StorageError, type SyncCapabilities, type SyncStatus, type SyncVault, type UserInfo, VaultSync, WalletError, type WalletInfo, Web3Passkey, type Web3PasskeyConfig, Web3PasskeyError, type ZipBackupOptions, assertEthereumAddress, assertMnemonic, assertUsername, canControlStealthAddress, checkStealthAddress, computeStealthPrivateKey, createWalletFromMnemonic, createWeb3Passkey, createWeb3Passkey as default, deriveStealthKeys, deriveWalletFromMnemonic, generateBIP39Wallet, generateStealthAddress, getAllTopics, getExplainer, isStrongPassword, searchExplainers, validateEthereumAddress, validateMnemonic, validateUsername };