@1sat/wallet-toolbox 0.0.36 → 0.0.38
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.d.ts +4 -0
- package/dist/wallet/factory.js +43 -13
- package/package.json +3 -3
package/dist/wallet/factory.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ export interface WebWalletConfig {
|
|
|
28
28
|
};
|
|
29
29
|
/** Remote storage URL. If provided, attempts to connect for cloud backup. */
|
|
30
30
|
remoteStorageUrl?: string;
|
|
31
|
+
/** Callback when a transaction is broadcasted (called after remote sync if connected) */
|
|
32
|
+
onTransactionBroadcasted?: (txid: string) => void;
|
|
33
|
+
/** Callback when a transaction is proven (called after remote sync if connected) */
|
|
34
|
+
onTransactionProven?: (txid: string, blockHeight: number) => void;
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
37
|
* Result of wallet creation.
|
package/dist/wallet/factory.js
CHANGED
|
@@ -162,31 +162,61 @@ export async function createWebWallet(config) {
|
|
|
162
162
|
unprovenAttemptsLimitMain: 144,
|
|
163
163
|
});
|
|
164
164
|
monitor.addDefaultTasks();
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
// Helper to sync to remote backup using updateBackups (same as initialization)
|
|
166
|
+
const syncToBackup = async (context) => {
|
|
167
|
+
const storageAny = storage;
|
|
168
|
+
if (storageAny._backups?.length && storageAny.updateBackups) {
|
|
169
|
+
await storageAny.updateBackups(undefined, (msg) => {
|
|
170
|
+
console.log(`[Monitor] ${context}:`, msg);
|
|
171
|
+
return msg;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
// 9. Wire up monitor callbacks - sync to remote first, then call user callbacks
|
|
176
|
+
monitor.onTransactionBroadcasted = async (result) => {
|
|
177
|
+
console.log("[Monitor] Transaction broadcasted:", result.txid);
|
|
178
|
+
// Sync to remote backup first (if connected)
|
|
179
|
+
if (remoteClient) {
|
|
169
180
|
try {
|
|
170
|
-
|
|
171
|
-
await storage.syncToWriter(auth, remoteClient);
|
|
181
|
+
await syncToBackup("Backup after broadcast");
|
|
172
182
|
console.log("[Monitor] Synced to backup after broadcast");
|
|
173
183
|
}
|
|
174
184
|
catch (err) {
|
|
175
185
|
console.warn("[Monitor] Failed to sync after broadcast:", err);
|
|
176
186
|
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
187
|
+
}
|
|
188
|
+
// Then call user callback (if provided)
|
|
189
|
+
if (result.txid && config.onTransactionBroadcasted) {
|
|
190
|
+
try {
|
|
191
|
+
config.onTransactionBroadcasted(result.txid);
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
console.warn("[Monitor] User callback error after broadcast:", err);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
monitor.onTransactionProven = async (status) => {
|
|
199
|
+
console.log("[Monitor] Transaction proven:", status.txid, "block", status.blockHeight);
|
|
200
|
+
// Sync to remote backup first (if connected)
|
|
201
|
+
if (remoteClient) {
|
|
180
202
|
try {
|
|
181
|
-
|
|
182
|
-
await storage.syncToWriter(auth, remoteClient);
|
|
203
|
+
await syncToBackup("Backup after confirmation");
|
|
183
204
|
console.log("[Monitor] Synced to backup after confirmation");
|
|
184
205
|
}
|
|
185
206
|
catch (err) {
|
|
186
207
|
console.warn("[Monitor] Failed to sync after confirmation:", err);
|
|
187
208
|
}
|
|
188
|
-
}
|
|
189
|
-
|
|
209
|
+
}
|
|
210
|
+
// Then call user callback (if provided)
|
|
211
|
+
if (config.onTransactionProven) {
|
|
212
|
+
try {
|
|
213
|
+
config.onTransactionProven(status.txid, status.blockHeight);
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
console.warn("[Monitor] User callback error after proven:", err);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
190
220
|
// 10. Create cleanup function
|
|
191
221
|
const destroy = async () => {
|
|
192
222
|
monitor.stopTasks();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1sat/wallet-toolbox",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"description": "BSV wallet library extending @bsv/wallet-toolbox with 1Sat Ordinals protocol support",
|
|
5
5
|
"author": "1Sat Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"fflate": "^0.8.2"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@bsv/wallet-toolbox-mobile": "npm:@bopen-io/wallet-toolbox-mobile@^1.7.20-idb-fix.
|
|
47
|
+
"@bsv/wallet-toolbox-mobile": "npm:@bopen-io/wallet-toolbox-mobile@^1.7.20-idb-fix.19"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"@bsv/wallet-toolbox-mobile": {
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@biomejs/biome": "^1.9.4",
|
|
56
56
|
"@bsv/wallet-toolbox": "npm:@bopen-io/wallet-toolbox@^1.7.20-idb-fix.17",
|
|
57
|
-
"@bsv/wallet-toolbox-mobile": "npm:@bopen-io/wallet-toolbox-mobile@^1.7.20-idb-fix.
|
|
57
|
+
"@bsv/wallet-toolbox-mobile": "npm:@bopen-io/wallet-toolbox-mobile@^1.7.20-idb-fix.19",
|
|
58
58
|
"@types/bun": "^1.3.4",
|
|
59
59
|
"@types/chrome": "^0.1.32",
|
|
60
60
|
"typescript": "^5.9.3"
|