@1sat/wallet-toolbox 0.0.69 → 0.0.70
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 +5 -40
- package/package.json +1 -1
package/dist/wallet/factory.js
CHANGED
|
@@ -83,56 +83,21 @@ 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
|
|
95
|
+
// Add remote as backup destination (push-only, no pull)
|
|
96
96
|
await storage.addWalletStorageProvider(remoteClient);
|
|
97
|
-
console.log("[createWebWallet] Remote
|
|
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
|
+
console.log("[createWebWallet] Remote backup connected");
|
|
133
98
|
}
|
|
134
99
|
catch (err) {
|
|
135
|
-
console.log("[createWebWallet]
|
|
100
|
+
console.log("[createWebWallet] Remote backup connection failed:", err instanceof Error ? err.message : err);
|
|
136
101
|
remoteClient = undefined;
|
|
137
102
|
}
|
|
138
103
|
}
|