w3pk 0.10.2 → 0.10.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.
@@ -36,13 +36,13 @@ await w3pk.getAddress()
36
36
 
37
37
  ### Don't Import Internal Classes
38
38
 
39
- Internal implementation classes like `WalletSigner`, `SessionManager`, `IndexedDBWalletStorage`, etc. are **not part of the public API** and may change without notice:
39
+ Internal implementation classes like `WalletSigner`, `SessionManager`, `LocalStorageWalletStorage`, etc. are **not part of the public API** and may change without notice:
40
40
 
41
41
  ```typescript
42
42
  // ❌ Don't do this - internal APIs
43
43
  import { WalletSigner } from 'w3pk/wallet/signing'
44
44
  import { SessionManager } from 'w3pk/core/session'
45
- import { IndexedDBWalletStorage } from 'w3pk/wallet/storage'
45
+ import { LocalStorageWalletStorage } from 'w3pk/wallet/storage'
46
46
 
47
47
  // ✅ Do this instead - public SDK API
48
48
  import { createWeb3Passkey } from 'w3pk'
@@ -90,9 +90,9 @@ const auth2 = await w3pk.signAuthorization({
90
90
  ```typescript
91
91
  // ❌ Don't use internal WalletSigner class directly
92
92
  import { WalletSigner } from 'w3pk/wallet/signing'
93
- import { IndexedDBWalletStorage } from 'w3pk/wallet/storage'
93
+ import { LocalStorageWalletStorage } from 'w3pk/wallet/storage'
94
94
 
95
- const storage = new IndexedDBWalletStorage()
95
+ const storage = new LocalStorageWalletStorage()
96
96
  const signer = new WalletSigner(storage)
97
97
 
98
98
  // This bypasses session management and requires manual credential handling
@@ -120,6 +120,7 @@ await signer.signAuthorization(
120
120
 
121
121
  **Backup & Recovery:**
122
122
  - `createBackupFile()` - Create encrypted backup
123
+ - `confirmRecoveryPhraseBackup()` - Record that the user wrote down the recovery phrase
123
124
  - `restoreFromBackupFile()` - Restore from backup
124
125
  - `setupSocialRecovery()` - Split backup among guardians
125
126
  - `recoverFromGuardians()` - Recover from guardian shares
@@ -696,6 +697,8 @@ const result = await w3pk.signMessage(message, {
696
697
  })
697
698
  ```
698
699
 
700
+ SIWE works in STANDARD, STRICT and YOLO modes; PRIMARY mode throws. Get the address with the same mode and tag you sign with. In production, have the server issue the nonce and tie it to the address, as EIP-4361 recommends; see [examples/siwe-login.ts](../examples/siwe-login.ts).
701
+
699
702
  **Use for:**
700
703
  - Web3 authentication flows
701
704
  - App login
@@ -1220,23 +1223,37 @@ async function promptBackupOptions() {
1220
1223
 
1221
1224
  ### Allow Users Multiple Backup Options
1222
1225
 
1223
- **Critical:** Users should set up at least one backup method immediately after registration.
1226
+ **Critical:** Users should set up at least one backup method immediately after registration. Browser storage can be wiped (eviction, Safari's 7-day cap, clearing site data), and a wallet without a backup is then lost for good.
1224
1227
 
1225
1228
  ```typescript
1226
- // ✅ Provide multiple backup options
1227
- async function setupBackups() {
1228
- const status = await w3pk.getBackupStatus()
1229
+ // ✅ Ask for a backup right after registration
1230
+ const { hasBackup } = await w3pk.register({ username })
1229
1231
 
1230
- console.log('Security Score:', status.securityScore.score)
1231
- console.log('Has passkey sync:', status.securityScore.hasPasskeyBackup)
1232
- console.log('Has encrypted backup:', status.securityScore.hasEncryptedBackup)
1233
- console.log('Has social recovery:', status.securityScore.hasSocialRecovery)
1232
+ if (!hasBackup) {
1233
+ // "Back up now": a backup file, or the recovery phrase written down
1234
+ const choice = await showBackupNowPrompt()
1234
1235
 
1235
- // Warn if security score is low
1236
- if (status.securityScore.score < 60) {
1237
- showBackupWarning()
1236
+ if (choice === 'file') {
1237
+ const { blob, filename } = await w3pk.createBackupFile('password', password)
1238
+ downloadFile(blob, filename)
1239
+ } else if (choice === 'phrase') {
1240
+ await showRecoveryPhrase()
1241
+ await w3pk.confirmRecoveryPhraseBackup()
1238
1242
  }
1239
1243
  }
1244
+
1245
+ // ✅ Keep warning while no backup exists
1246
+ async function checkBackup() {
1247
+ const status = await w3pk.getBackupStatus()
1248
+
1249
+ if (!status.hasBackup) {
1250
+ showBackupWarning() // the score is capped at 20 ('vulnerable')
1251
+ }
1252
+
1253
+ console.log('Security Score:', status.securityScore.total)
1254
+ console.log('Backup methods:', status.methods) // 'file' | 'qr' | 'phrase'
1255
+ console.log('Last backup:', status.lastBackupAt)
1256
+ }
1240
1257
  ```
1241
1258
 
1242
1259
  ### Three-Layer Backup Strategy
@@ -1252,7 +1269,7 @@ Encourage users to enable multiple backup methods:
1252
1269
  // - Microsoft Account (Windows/Edge)
1253
1270
 
1254
1271
  const status = await w3pk.getBackupStatus()
1255
- if (status.securityScore.hasPasskeyBackup) {
1272
+ if (status.passkeySync.enabled) {
1256
1273
  console.log('✅ Passkey synced to cloud')
1257
1274
  }
1258
1275
  ```
@@ -1316,11 +1333,10 @@ async function setupSocialRecovery() {
1316
1333
  // Check backup status regularly
1317
1334
  async function checkBackupReminder() {
1318
1335
  const status = await w3pk.getBackupStatus()
1319
- const daysSinceRegistration = calculateDaysSince(status.createdAt)
1336
+ const daysSinceRegistration = calculateDaysSince(registeredAt) // tracked by your app
1320
1337
 
1321
1338
  // Remind users who haven't set up backup
1322
- if (!status.securityScore.hasEncryptedBackup &&
1323
- !status.securityScore.hasSocialRecovery) {
1339
+ if (!status.hasBackup) {
1324
1340
 
1325
1341
  if (daysSinceRegistration === 1) {
1326
1342
  showBackupReminder('urgent')
@@ -1413,7 +1429,7 @@ const strictWallet = await w3pk.deriveWallet('STRICT')
1413
1429
 
1414
1430
  **Persistent Session Security:**
1415
1431
  - STANDARD / YOLO: persistent sessions allowed. STRICT: ❌ NEVER allowed.
1416
- - Time-limited expiration; origin-isolated via IndexedDB.
1432
+ - Time-limited expiration; origin-isolated via localStorage.
1417
1433
  - ⚠️ The at-rest key is derived from **public** credential metadata in the same browser profile, not an authenticator secret — a persistent session is **decryptable by anyone who can read this origin's storage**, for the whole duration it's enabled. "Remember Me" is a UX-for-security trade-off that widens the exposure window; it does not add a new trust dependency beyond the origin-code integrity you already rely on. Keep the duration short for higher-value wallets and don't enable on shared devices.
1418
1434
  - Decide this deliberately against your threat model: **[SECURITY.md → At-Rest Encryption](./SECURITY.md#at-rest-encryption-what-it-protects-and-what-it-doesnt)**.
1419
1435