w3pk 0.9.1 → 0.9.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
@@ -11,6 +11,8 @@ Passwordless Web3 authentication SDK with encrypted wallets and privacy features
11
11
  ## Install
12
12
  ```bash
13
13
  npm install w3pk ethers
14
+ # or
15
+ npm install w3pk viem
14
16
  ```
15
17
 
16
18
  ## Quick Start
@@ -34,9 +36,6 @@ const tx = await w3pk.sendTransaction({ to: '0x...', value: 1n * 10n**18n, chain
34
36
  // EIP-1193 provider (ethers, viem, wagmi, RainbowKit)
35
37
  const eip1193 = w3pk.getEIP1193Provider({ chainId: 1 })
36
38
 
37
- // Derive wallets (STANDARD/STRICT/YOLO modes)
38
- const wallet = await w3pk.deriveWallet('STANDARD', 'GAMING')
39
-
40
39
  // Get RPC endpoints
41
40
  const endpoints = await w3pk.getEndpoints(1)
42
41
  ```
@@ -85,17 +84,28 @@ await w3pk.logout()
85
84
 
86
85
  ### Wallet Derivation
87
86
 
87
+ w3pk supports multiple security modes for deriving wallets with different privacy and security trade-offs:
88
+
88
89
  ```typescript
89
- // STANDARD mode - address only (no private key)
90
+ // PRIMARY mode - WebAuthn P-256 passkey (EIP-7951)
91
+ // Uses hardware-backed passkey directly, no seed phrase involved
92
+ const primaryWallet = await w3pk.deriveWallet('PRIMARY')
93
+ // Returns: { address, publicKey, origin, mode: 'PRIMARY', tag: 'MAIN' }
94
+
95
+ // STANDARD mode - Default balanced security (recommended)
96
+ // Returns address only, private key stays in SDK for signing
90
97
  const mainWallet = await w3pk.deriveWallet('STANDARD')
91
- // Returns: { address, index, origin, tag: 'MAIN' }
98
+ // Returns: { address, index, origin, mode: 'STANDARD', tag: 'MAIN' }
92
99
 
93
- // YOLO mode - includes private key for app-specific use
100
+ // YOLO mode - Private key exposed to app
101
+ // Use only when app needs direct key access (advanced use cases)
94
102
  const gamingWallet = await w3pk.deriveWallet('YOLO', 'GAMING')
95
- // Returns: { address, privateKey, index, origin, tag: 'GAMING' }
103
+ // Returns: { address, privateKey, index, origin, mode: 'YOLO', tag: 'GAMING' }
96
104
 
97
- // STRICT mode - address only, no persistent sessions allowed
105
+ // STRICT mode - Maximum security, re-auth required every time
106
+ // Requires biometric/PIN for each call - impractical for most apps
98
107
  const strictWallet = await w3pk.deriveWallet('STRICT', 'SECURE')
108
+ // Returns: { address, privateKey, index, origin, mode: 'STRICT', tag: 'SECURE' }
99
109
 
100
110
  // Different tags generate different addresses
101
111
  console.log(mainWallet.address !== gamingWallet.address) // true
@@ -345,8 +355,13 @@ console.log('Security Score:', status.securityScore.total) // 0-100
345
355
  // Create encrypted backup file
346
356
  const { blob, filename } = await w3pk.createBackupFile('password', password)
347
357
 
348
- // Setup social recovery (M-of-N guardians)
349
- await w3pk.setupSocialRecovery(
358
+ // Setup social recovery (M-of-N guardians) - guardians store backup file fragments
359
+ import { SocialRecoveryManager } from 'w3pk'
360
+ const backupFileJson = await blob.text()
361
+ const socialRecovery = new SocialRecoveryManager()
362
+ const guardians = await socialRecovery.setupSocialRecovery(
363
+ backupFileJson,
364
+ w3pk.user.ethereumAddress,
350
365
  [
351
366
  { name: 'Alice', email: 'alice@example.com' },
352
367
  { name: 'Bob', phone: '+1234567890' },
@@ -356,10 +371,11 @@ await w3pk.setupSocialRecovery(
356
371
  )
357
372
 
358
373
  // Generate guardian invite
359
- const invite = await w3pk.generateGuardianInvite(guardianShare)
374
+ const invite = await socialRecovery.generateGuardianInvite(guardians[0])
360
375
 
361
- // Recover from guardian shares
362
- const { mnemonic } = await w3pk.recoverFromGuardians([share1, share2])
376
+ // Recover from guardian shares - reconstructs encrypted backup file
377
+ const { backupFileJson } = await socialRecovery.recoverFromGuardians([share1, share2])
378
+ await w3pk.registerWithBackupFile(backupFileJson, password, 'username')
363
379
 
364
380
  // Restore from backup file
365
381
  await w3pk.restoreFromBackupFile(encryptedData, password)
@@ -421,6 +437,8 @@ console.log(result.report)
421
437
  await inspectNow() // Logs report directly to console
422
438
  ```
423
439
 
440
+ **Note:** Inspection API calls are sponsored by the [W3HC (Web3 Hackers Collective)](https://w3hc.org).
441
+
424
442
  **Node.js (analyze local files):**
425
443
  ```typescript
426
444
  import { inspect, gatherCode } from 'w3pk/inspect/node'
@@ -464,6 +482,7 @@ Host applications should verify their installed W3PK build against this registry
464
482
  - [Security Inspection](./docs/INSPECTION.md)
465
483
  - [EIP-7951](./docs/EIP-7951.md)
466
484
  - [Security Architecture](./docs/SECURITY.md)
485
+ - [Post-Quantum Cryptography](./docs/POST_QUANTUM.md) - Quantum-safe migration roadmap
467
486
  - [Recovery & Backup System](./docs/RECOVERY.md)
468
487
  - [Portability Guide](./docs/PORTABILITY.md)
469
488
  - [ZK Proofs](./docs/ZK.md)
package/dist/index.d.mts CHANGED
@@ -1753,6 +1753,93 @@ interface RecoveryProgress {
1753
1753
  canRecover: boolean;
1754
1754
  }
1755
1755
 
1756
+ /**
1757
+ * Social Recovery Manager
1758
+ * Manages guardian-based wallet recovery using Shamir Secret Sharing
1759
+ */
1760
+
1761
+ declare class SocialRecoveryManager {
1762
+ private storageKey;
1763
+ /**
1764
+ * Get storage (localStorage or in-memory fallback)
1765
+ */
1766
+ private getItem;
1767
+ /**
1768
+ * Set storage (localStorage or in-memory fallback)
1769
+ */
1770
+ private setItem;
1771
+ /**
1772
+ * Set up social recovery
1773
+ * Splits encrypted backup file into M-of-N shares and distributes to guardians
1774
+ *
1775
+ * @param backupFileJson - The complete backup file JSON string (password-encrypted)
1776
+ * @param ethereumAddress - The Ethereum address for verification
1777
+ * @param guardians - Array of guardian information
1778
+ * @param threshold - Minimum number of guardians needed for recovery
1779
+ */
1780
+ setupSocialRecovery(backupFileJson: string, ethereumAddress: string, guardians: {
1781
+ name: string;
1782
+ email?: string;
1783
+ phone?: string;
1784
+ }[], threshold: number): Promise<Guardian[]>;
1785
+ /**
1786
+ * Get current social recovery configuration
1787
+ */
1788
+ getSocialRecoveryConfig(): SocialRecoveryConfig | null;
1789
+ /**
1790
+ * Generate guardian invitation
1791
+ * Creates QR code and educational materials for guardian
1792
+ */
1793
+ generateGuardianInvite(guardian: Guardian): Promise<GuardianInvite>;
1794
+ /**
1795
+ * Generate QR code from share data
1796
+ * Uses 'qrcode' library if available, falls back to canvas text
1797
+ */
1798
+ private generateQRCode;
1799
+ /**
1800
+ * Create fallback QR representation
1801
+ */
1802
+ private createPlaceholderQR;
1803
+ /**
1804
+ * Wrap text for display
1805
+ */
1806
+ private wrapText;
1807
+ /**
1808
+ * Get guardian explainer text
1809
+ */
1810
+ private getGuardianExplainer;
1811
+ /**
1812
+ * Recover backup file from guardian shares
1813
+ * Returns the reconstructed backup file JSON that can be used with restoreFromBackupFile()
1814
+ */
1815
+ recoverFromGuardians(shareData: string[]): Promise<{
1816
+ backupFileJson: string;
1817
+ ethereumAddress: string;
1818
+ }>;
1819
+ /**
1820
+ * Get recovery progress
1821
+ */
1822
+ getRecoveryProgress(collectedShares: string[]): RecoveryProgress;
1823
+ /**
1824
+ * Mark guardian as verified
1825
+ * Note: This updates guardian status but does NOT automatically refresh security score.
1826
+ * The security score will be updated on the next call to BackupManager.getBackupStatus()
1827
+ */
1828
+ markGuardianVerified(guardianId: string): void;
1829
+ /**
1830
+ * Revoke a guardian
1831
+ */
1832
+ revokeGuardian(guardianId: string): void;
1833
+ /**
1834
+ * Add new guardian (requires re-sharing with new backup file)
1835
+ */
1836
+ addGuardian(backupFileJson: string, newGuardian: {
1837
+ name: string;
1838
+ email?: string;
1839
+ phone?: string;
1840
+ }): Promise<Guardian>;
1841
+ }
1842
+
1756
1843
  /**
1757
1844
  * Cross-Device Sync Type Definitions
1758
1845
  */
@@ -1982,4 +2069,4 @@ declare function inspectNow(options?: BrowserInspectOptions): Promise<void>;
1982
2069
 
1983
2070
  declare function createWeb3Passkey(config?: Web3PasskeyConfig): Web3Passkey;
1984
2071
 
1985
- export { ApiError, AuthenticationError, type BackupStatus, type BrowserInspectOptions, type BrowserInspectResult, CryptoError, DEFAULT_MODE, DEFAULT_TAG, type DeviceInfo, type EIP1193Provider, type EIP7702Authorization, type EncryptedBackupInfo, type Guardian, type GuardianInvite, type PasskeySelectionResult, type QRBackupOptions, type RecoveryProgress, type RecoveryScenario, type RecoveryShare, RecoverySimulator, RegistrationError, type SecurityScore, type SignAuthorizationParams, type SimulationResult, type SiweMessage, type SocialRecoveryConfig, type StealthAddressConfig, StealthAddressModule, type StealthAddressResult, type StealthKeys, StorageError, type SyncCapabilities, type SyncStatus, type SyncVault, type UserInfo, WalletError, type WalletInfo, Web3Passkey, type Web3PasskeyConfig, Web3PasskeyError, arrayBufferToBase64Url, assertEthereumAddress, assertMnemonic, assertUsername, authenticateWithPasskey, base64ToArrayBuffer, base64UrlDecode, base64UrlToArrayBuffer, canControlStealthAddress, checkStealthAddress, clearCache, computeStealthPrivateKey, createSiweMessage, createWalletFromMnemonic, createWeb3Passkey, createWeb3Passkey as default, deriveAddressFromP256PublicKey, deriveIndexFromOriginModeAndTag, deriveStealthKeys, deriveWalletFromMnemonic, detectWalletProvider, encodeEIP7702AuthorizationMessage, extractRS, generateBIP39Wallet, generateSiweNonce, generateStealthAddress, getAllChains, getAllTopics, getChainById, getCurrentBuildHash, getCurrentOrigin, getDefaultProvider, getEndpoints, getExplainer, getOriginSpecificAddress, getPackageVersion, getW3pkBuildHash, hashEIP7702AuthorizationMessage, inspect, inspectNow, isStrongPassword, normalizeOrigin, parseSiweMessage, promptPasskeySelection, requestExternalWalletAuthorization, safeAtob, safeBtoa, searchExplainers, supportsEIP7702Authorization, validateEthereumAddress, validateMnemonic, validateSiweMessage, validateUsername, verifyBuildHash, verifyEIP7702Authorization, verifySiweSignature };
2072
+ export { ApiError, AuthenticationError, type BackupStatus, type BrowserInspectOptions, type BrowserInspectResult, CryptoError, DEFAULT_MODE, DEFAULT_TAG, type DeviceInfo, type EIP1193Provider, type EIP7702Authorization, type EncryptedBackupInfo, type Guardian, type GuardianInvite, type PasskeySelectionResult, type QRBackupOptions, type RecoveryProgress, type RecoveryScenario, type RecoveryShare, RecoverySimulator, RegistrationError, type SecurityScore, type SignAuthorizationParams, type SimulationResult, type SiweMessage, type SocialRecoveryConfig, SocialRecoveryManager, type StealthAddressConfig, StealthAddressModule, type StealthAddressResult, type StealthKeys, StorageError, type SyncCapabilities, type SyncStatus, type SyncVault, type UserInfo, WalletError, type WalletInfo, Web3Passkey, type Web3PasskeyConfig, Web3PasskeyError, arrayBufferToBase64Url, assertEthereumAddress, assertMnemonic, assertUsername, authenticateWithPasskey, base64ToArrayBuffer, base64UrlDecode, base64UrlToArrayBuffer, canControlStealthAddress, checkStealthAddress, clearCache, computeStealthPrivateKey, createSiweMessage, createWalletFromMnemonic, createWeb3Passkey, createWeb3Passkey as default, deriveAddressFromP256PublicKey, deriveIndexFromOriginModeAndTag, deriveStealthKeys, deriveWalletFromMnemonic, detectWalletProvider, encodeEIP7702AuthorizationMessage, extractRS, generateBIP39Wallet, generateSiweNonce, generateStealthAddress, getAllChains, getAllTopics, getChainById, getCurrentBuildHash, getCurrentOrigin, getDefaultProvider, getEndpoints, getExplainer, getOriginSpecificAddress, getPackageVersion, getW3pkBuildHash, hashEIP7702AuthorizationMessage, inspect, inspectNow, isStrongPassword, normalizeOrigin, parseSiweMessage, promptPasskeySelection, requestExternalWalletAuthorization, safeAtob, safeBtoa, searchExplainers, supportsEIP7702Authorization, validateEthereumAddress, validateMnemonic, validateSiweMessage, validateUsername, verifyBuildHash, verifyEIP7702Authorization, verifySiweSignature };
package/dist/index.d.ts CHANGED
@@ -1753,6 +1753,93 @@ interface RecoveryProgress {
1753
1753
  canRecover: boolean;
1754
1754
  }
1755
1755
 
1756
+ /**
1757
+ * Social Recovery Manager
1758
+ * Manages guardian-based wallet recovery using Shamir Secret Sharing
1759
+ */
1760
+
1761
+ declare class SocialRecoveryManager {
1762
+ private storageKey;
1763
+ /**
1764
+ * Get storage (localStorage or in-memory fallback)
1765
+ */
1766
+ private getItem;
1767
+ /**
1768
+ * Set storage (localStorage or in-memory fallback)
1769
+ */
1770
+ private setItem;
1771
+ /**
1772
+ * Set up social recovery
1773
+ * Splits encrypted backup file into M-of-N shares and distributes to guardians
1774
+ *
1775
+ * @param backupFileJson - The complete backup file JSON string (password-encrypted)
1776
+ * @param ethereumAddress - The Ethereum address for verification
1777
+ * @param guardians - Array of guardian information
1778
+ * @param threshold - Minimum number of guardians needed for recovery
1779
+ */
1780
+ setupSocialRecovery(backupFileJson: string, ethereumAddress: string, guardians: {
1781
+ name: string;
1782
+ email?: string;
1783
+ phone?: string;
1784
+ }[], threshold: number): Promise<Guardian[]>;
1785
+ /**
1786
+ * Get current social recovery configuration
1787
+ */
1788
+ getSocialRecoveryConfig(): SocialRecoveryConfig | null;
1789
+ /**
1790
+ * Generate guardian invitation
1791
+ * Creates QR code and educational materials for guardian
1792
+ */
1793
+ generateGuardianInvite(guardian: Guardian): Promise<GuardianInvite>;
1794
+ /**
1795
+ * Generate QR code from share data
1796
+ * Uses 'qrcode' library if available, falls back to canvas text
1797
+ */
1798
+ private generateQRCode;
1799
+ /**
1800
+ * Create fallback QR representation
1801
+ */
1802
+ private createPlaceholderQR;
1803
+ /**
1804
+ * Wrap text for display
1805
+ */
1806
+ private wrapText;
1807
+ /**
1808
+ * Get guardian explainer text
1809
+ */
1810
+ private getGuardianExplainer;
1811
+ /**
1812
+ * Recover backup file from guardian shares
1813
+ * Returns the reconstructed backup file JSON that can be used with restoreFromBackupFile()
1814
+ */
1815
+ recoverFromGuardians(shareData: string[]): Promise<{
1816
+ backupFileJson: string;
1817
+ ethereumAddress: string;
1818
+ }>;
1819
+ /**
1820
+ * Get recovery progress
1821
+ */
1822
+ getRecoveryProgress(collectedShares: string[]): RecoveryProgress;
1823
+ /**
1824
+ * Mark guardian as verified
1825
+ * Note: This updates guardian status but does NOT automatically refresh security score.
1826
+ * The security score will be updated on the next call to BackupManager.getBackupStatus()
1827
+ */
1828
+ markGuardianVerified(guardianId: string): void;
1829
+ /**
1830
+ * Revoke a guardian
1831
+ */
1832
+ revokeGuardian(guardianId: string): void;
1833
+ /**
1834
+ * Add new guardian (requires re-sharing with new backup file)
1835
+ */
1836
+ addGuardian(backupFileJson: string, newGuardian: {
1837
+ name: string;
1838
+ email?: string;
1839
+ phone?: string;
1840
+ }): Promise<Guardian>;
1841
+ }
1842
+
1756
1843
  /**
1757
1844
  * Cross-Device Sync Type Definitions
1758
1845
  */
@@ -1982,4 +2069,4 @@ declare function inspectNow(options?: BrowserInspectOptions): Promise<void>;
1982
2069
 
1983
2070
  declare function createWeb3Passkey(config?: Web3PasskeyConfig): Web3Passkey;
1984
2071
 
1985
- export { ApiError, AuthenticationError, type BackupStatus, type BrowserInspectOptions, type BrowserInspectResult, CryptoError, DEFAULT_MODE, DEFAULT_TAG, type DeviceInfo, type EIP1193Provider, type EIP7702Authorization, type EncryptedBackupInfo, type Guardian, type GuardianInvite, type PasskeySelectionResult, type QRBackupOptions, type RecoveryProgress, type RecoveryScenario, type RecoveryShare, RecoverySimulator, RegistrationError, type SecurityScore, type SignAuthorizationParams, type SimulationResult, type SiweMessage, type SocialRecoveryConfig, type StealthAddressConfig, StealthAddressModule, type StealthAddressResult, type StealthKeys, StorageError, type SyncCapabilities, type SyncStatus, type SyncVault, type UserInfo, WalletError, type WalletInfo, Web3Passkey, type Web3PasskeyConfig, Web3PasskeyError, arrayBufferToBase64Url, assertEthereumAddress, assertMnemonic, assertUsername, authenticateWithPasskey, base64ToArrayBuffer, base64UrlDecode, base64UrlToArrayBuffer, canControlStealthAddress, checkStealthAddress, clearCache, computeStealthPrivateKey, createSiweMessage, createWalletFromMnemonic, createWeb3Passkey, createWeb3Passkey as default, deriveAddressFromP256PublicKey, deriveIndexFromOriginModeAndTag, deriveStealthKeys, deriveWalletFromMnemonic, detectWalletProvider, encodeEIP7702AuthorizationMessage, extractRS, generateBIP39Wallet, generateSiweNonce, generateStealthAddress, getAllChains, getAllTopics, getChainById, getCurrentBuildHash, getCurrentOrigin, getDefaultProvider, getEndpoints, getExplainer, getOriginSpecificAddress, getPackageVersion, getW3pkBuildHash, hashEIP7702AuthorizationMessage, inspect, inspectNow, isStrongPassword, normalizeOrigin, parseSiweMessage, promptPasskeySelection, requestExternalWalletAuthorization, safeAtob, safeBtoa, searchExplainers, supportsEIP7702Authorization, validateEthereumAddress, validateMnemonic, validateSiweMessage, validateUsername, verifyBuildHash, verifyEIP7702Authorization, verifySiweSignature };
2072
+ export { ApiError, AuthenticationError, type BackupStatus, type BrowserInspectOptions, type BrowserInspectResult, CryptoError, DEFAULT_MODE, DEFAULT_TAG, type DeviceInfo, type EIP1193Provider, type EIP7702Authorization, type EncryptedBackupInfo, type Guardian, type GuardianInvite, type PasskeySelectionResult, type QRBackupOptions, type RecoveryProgress, type RecoveryScenario, type RecoveryShare, RecoverySimulator, RegistrationError, type SecurityScore, type SignAuthorizationParams, type SimulationResult, type SiweMessage, type SocialRecoveryConfig, SocialRecoveryManager, type StealthAddressConfig, StealthAddressModule, type StealthAddressResult, type StealthKeys, StorageError, type SyncCapabilities, type SyncStatus, type SyncVault, type UserInfo, WalletError, type WalletInfo, Web3Passkey, type Web3PasskeyConfig, Web3PasskeyError, arrayBufferToBase64Url, assertEthereumAddress, assertMnemonic, assertUsername, authenticateWithPasskey, base64ToArrayBuffer, base64UrlDecode, base64UrlToArrayBuffer, canControlStealthAddress, checkStealthAddress, clearCache, computeStealthPrivateKey, createSiweMessage, createWalletFromMnemonic, createWeb3Passkey, createWeb3Passkey as default, deriveAddressFromP256PublicKey, deriveIndexFromOriginModeAndTag, deriveStealthKeys, deriveWalletFromMnemonic, detectWalletProvider, encodeEIP7702AuthorizationMessage, extractRS, generateBIP39Wallet, generateSiweNonce, generateStealthAddress, getAllChains, getAllTopics, getChainById, getCurrentBuildHash, getCurrentOrigin, getDefaultProvider, getEndpoints, getExplainer, getOriginSpecificAddress, getPackageVersion, getW3pkBuildHash, hashEIP7702AuthorizationMessage, inspect, inspectNow, isStrongPassword, normalizeOrigin, parseSiweMessage, promptPasskeySelection, requestExternalWalletAuthorization, safeAtob, safeBtoa, searchExplainers, supportsEIP7702Authorization, validateEthereumAddress, validateMnemonic, validateSiweMessage, validateUsername, verifyBuildHash, verifyEIP7702Authorization, verifySiweSignature };