@1sat/wallet-toolbox 0.0.63 → 0.0.65

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.
@@ -73,7 +73,7 @@ export async function createWebWallet(config) {
73
73
  const localStorage = new StorageIdb(storageOptions);
74
74
  await localStorage.migrate(DEFAULT_DATABASE_NAME, config.storageIdentityKey);
75
75
  // 4. Create storage manager with local-only storage initially (empty backups)
76
- const storage = new WalletStorageManager(identityPubKey, localStorage, []);
76
+ let storage = new WalletStorageManager(identityPubKey, localStorage, []);
77
77
  await storage.makeAvailable();
78
78
  // 5. Create the underlying Wallet FIRST (needed for StorageClient signing)
79
79
  const underlyingWallet = new Wallet({
@@ -95,6 +95,10 @@ export async function createWebWallet(config) {
95
95
  // Add remote storage to the existing storage manager using public API
96
96
  await storage.addWalletStorageProvider(remoteClient);
97
97
  console.log("[createWebWallet] Remote storage connected successfully");
98
+ // Pull changes from remote to sync with other devices
99
+ console.log("[createWebWallet] Syncing from remote...");
100
+ const syncResult = await storage.syncFromReader(identityPubKey, remoteClient);
101
+ console.log(`[createWebWallet] Synced from remote: ${syncResult.inserts} inserts, ${syncResult.updates} updates`);
98
102
  }
99
103
  catch (err) {
100
104
  console.log("[createWebWallet] Remote storage connection failed:", err instanceof Error ? err.message : err);
@@ -114,8 +118,8 @@ export async function createWebWallet(config) {
114
118
  })),
115
119
  });
116
120
  // 7. Handle conflicting actives or sync to backups
117
- const conflictingStores = storage.getConflictingStores();
118
- const backupStores = storage.getBackupStores();
121
+ let conflictingStores = storage.getConflictingStores();
122
+ let backupStores = storage.getBackupStores();
119
123
  if (conflictingStores.length > 0) {
120
124
  const localKey = storage.getActiveStore();
121
125
  console.log("[createWebWallet] Resolving conflicting actives...");
@@ -128,6 +132,19 @@ export async function createWebWallet(config) {
128
132
  }
129
133
  catch (err) {
130
134
  console.log("[createWebWallet] Conflict resolution failed:", err instanceof Error ? err.message : err);
135
+ // FALLBACK: If conflict resolution fails, operate in local-only mode
136
+ // This allows the wallet to function even when remote sync is broken
137
+ console.log("[createWebWallet] Falling back to local-only mode (remote disabled)");
138
+ // Recreate storage manager with only local storage to clear conflicts
139
+ storage = new WalletStorageManager(identityPubKey, localStorage, []);
140
+ await storage.makeAvailable();
141
+ // Update the wallet's storage reference
142
+ underlyingWallet.storage = storage;
143
+ remoteClient = undefined;
144
+ // Refresh conflict state
145
+ conflictingStores = storage.getConflictingStores();
146
+ backupStores = storage.getBackupStores();
147
+ console.log("[createWebWallet] Local-only mode active, isActiveEnabled:", storage.isActiveEnabled);
131
148
  }
132
149
  }
133
150
  else if (backupStores.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/wallet-toolbox",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "description": "BSV wallet library extending @bsv/wallet-toolbox with 1Sat Ordinals protocol support",
5
5
  "author": "1Sat Team",
6
6
  "license": "MIT",