@1sat/wallet-toolbox 0.0.69 → 0.0.71

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.
@@ -83,56 +83,43 @@ export async function createWebWallet(config) {
83
83
  services: oneSatServices,
84
84
  });
85
85
  // 6. Attempt remote storage connection AFTER wallet exists
86
+ // Push-only backup: no sync on startup, just connect for incremental backups
87
+ // Use fullSync() explicitly to restore from backup when needed
86
88
  let remoteClient;
87
89
  if (config.remoteStorageUrl) {
88
90
  console.log(`[createWebWallet] Attempting remote storage connection to ${config.remoteStorageUrl}`);
89
91
  try {
90
- // Create StorageClient with the REAL wallet (not a temp wallet)
91
- // StorageClient captures the wallet at construction for signing requests
92
92
  remoteClient = new StorageClient(underlyingWallet, config.remoteStorageUrl);
93
93
  const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error("Remote storage connection timeout")), DEFAULT_REMOTE_STORAGE_TIMEOUT));
94
94
  await Promise.race([remoteClient.makeAvailable(), timeoutPromise]);
95
- // Add remote storage to the existing storage manager using public API
95
+ // Add remote to storage manager - it will partition as conflicting if another device is active
96
96
  await storage.addWalletStorageProvider(remoteClient);
97
- console.log("[createWebWallet] Remote storage connected successfully");
98
- // Bidirectional sync: pull first, then push
99
- // Pull builds idMap via natural key matching (reference for transactions)
100
- // Push sends local changes to remote
101
- console.log("[createWebWallet] Pulling from remote...");
102
- const pullResult = await storage.syncFromReader(identityPubKey, remoteClient);
103
- console.log(`[createWebWallet] Pulled: ${pullResult.inserts} inserts, ${pullResult.updates} updates`);
104
- console.log("[createWebWallet] Pushing to remote...");
105
- await storage.updateBackups(undefined, (msg) => {
106
- console.log("[createWebWallet] Push:", msg);
107
- return msg;
108
- });
109
- console.log("[createWebWallet] Push complete");
110
- }
111
- catch (err) {
112
- console.log("[createWebWallet] Remote storage connection failed:", err instanceof Error ? err.message : err);
113
- remoteClient = undefined;
114
- }
115
- }
116
- // Log storage state for debugging
117
- console.log("[createWebWallet] Storage state:", {
118
- activeKey: storage.getActiveStore(),
119
- backups: storage.getBackupStores().length,
120
- conflictingActives: storage.getConflictingStores().length,
121
- isActiveEnabled: storage.isActiveEnabled,
122
- });
123
- // Handle conflicting actives - must resolve before wallet can function
124
- if (storage.getConflictingStores().length > 0) {
125
- const localKey = storage.getActiveStore();
126
- console.log("[createWebWallet] Resolving conflicting actives...");
127
- try {
128
- await storage.setActive(localKey, (msg) => {
129
- console.log("[createWebWallet] Conflict resolution:", msg);
130
- return msg;
131
- });
132
- console.log("[createWebWallet] Conflict resolution complete");
97
+ // Check if remote ended up in backup stores (active) or got partitioned (conflicting)
98
+ const remoteStorageKey = remoteClient.getSettings().storageIdentityKey;
99
+ const isActive = storage.getBackupStores().includes(remoteStorageKey);
100
+ if (isActive) {
101
+ console.log("[createWebWallet] Remote backup connected (we are active)");
102
+ }
103
+ else {
104
+ // Another device is active - need fullSync then setActive
105
+ // fullSync builds ID mappings before setActive attempts to merge
106
+ console.log("[createWebWallet] Another device is active, performing full sync...");
107
+ await fullSync({
108
+ storage,
109
+ remoteStorage: remoteClient,
110
+ identityKey: identityPubKey,
111
+ onProgress: (stage, msg) => console.log(`[createWebWallet] fullSync ${stage}: ${msg}`),
112
+ });
113
+ // Claim active status (merge now works because mappings exist from fullSync)
114
+ await storage.setActive(config.storageIdentityKey, (msg) => {
115
+ console.log("[createWebWallet] setActive:", msg);
116
+ return msg;
117
+ });
118
+ console.log("[createWebWallet] Remote backup connected (now active after handoff)");
119
+ }
133
120
  }
134
121
  catch (err) {
135
- console.log("[createWebWallet] Conflict resolution failed, falling back to local-only:", err instanceof Error ? err.message : err);
122
+ console.log("[createWebWallet] Remote backup connection failed:", err instanceof Error ? err.message : err);
136
123
  remoteClient = undefined;
137
124
  }
138
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/wallet-toolbox",
3
- "version": "0.0.69",
3
+ "version": "0.0.71",
4
4
  "description": "BSV wallet library extending @bsv/wallet-toolbox with 1Sat Ordinals protocol support",
5
5
  "author": "1Sat Team",
6
6
  "license": "MIT",