@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.
- package/dist/wallet/factory.js +27 -40
- package/package.json +1 -1
package/dist/wallet/factory.js
CHANGED
|
@@ -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
|
|
95
|
+
// Add remote to storage manager - it will partition as conflicting if another device is active
|
|
96
96
|
await storage.addWalletStorageProvider(remoteClient);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
console.log("[createWebWallet]
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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]
|
|
122
|
+
console.log("[createWebWallet] Remote backup connection failed:", err instanceof Error ? err.message : err);
|
|
136
123
|
remoteClient = undefined;
|
|
137
124
|
}
|
|
138
125
|
}
|