@1sat/wallet-toolbox 0.0.64 → 0.0.66

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.
@@ -5,7 +5,11 @@
5
5
  */
6
6
  import { Inscription } from "@bopen-io/templates";
7
7
  import { P2PKH, Script, Utils } from "@bsv/sdk";
8
- import { FUNDING_BASKET } from "../constants";
8
+ /**
9
+ * Magic constant that tells the wallet to send all available funds minus fees.
10
+ * When an output has this satoshis value, it's adjusted to the maximum fundable amount.
11
+ */
12
+ const maxPossibleSatoshis = 2099999999999999;
9
13
  // ============================================================================
10
14
  // Internal helpers
11
15
  // ============================================================================
@@ -153,32 +157,14 @@ export const sendAllBsv = {
153
157
  if (isPaymail(destination)) {
154
158
  return { error: "paymail-not-yet-implemented" };
155
159
  }
156
- const listResult = await ctx.wallet.listOutputs({
157
- basket: FUNDING_BASKET,
158
- include: "locking scripts",
159
- limit: 10000,
160
- });
161
- if (!listResult.outputs || listResult.outputs.length === 0) {
162
- return { error: "no-funds" };
163
- }
164
- const totalSats = listResult.outputs.reduce((sum, o) => sum + o.satoshis, 0);
165
- const estimatedFee = Math.ceil((listResult.outputs.length * 150 + 44) * 1);
166
- const sendAmount = totalSats - estimatedFee;
167
- if (sendAmount <= 0) {
168
- return { error: "insufficient-funds-for-fee" };
169
- }
170
- const inputs = listResult.outputs.map((o) => ({
171
- outpoint: o.outpoint,
172
- inputDescription: "Sweep funds",
173
- }));
174
160
  const result = await ctx.wallet.createAction({
175
161
  description: "Send all BSV",
176
- inputs,
177
162
  outputs: [
178
163
  {
179
164
  lockingScript: new P2PKH().lock(destination).toHex(),
180
- satoshis: sendAmount,
165
+ satoshis: maxPossibleSatoshis,
181
166
  outputDescription: "Sweep all funds",
167
+ tags: [],
182
168
  },
183
169
  ],
184
170
  options: { signAndProcess: true, acceptDelayedBroadcast: false },
@@ -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({
@@ -118,8 +118,8 @@ export async function createWebWallet(config) {
118
118
  })),
119
119
  });
120
120
  // 7. Handle conflicting actives or sync to backups
121
- const conflictingStores = storage.getConflictingStores();
122
- const backupStores = storage.getBackupStores();
121
+ let conflictingStores = storage.getConflictingStores();
122
+ let backupStores = storage.getBackupStores();
123
123
  if (conflictingStores.length > 0) {
124
124
  const localKey = storage.getActiveStore();
125
125
  console.log("[createWebWallet] Resolving conflicting actives...");
@@ -132,6 +132,19 @@ export async function createWebWallet(config) {
132
132
  }
133
133
  catch (err) {
134
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);
135
148
  }
136
149
  }
137
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.64",
3
+ "version": "0.0.66",
4
4
  "description": "BSV wallet library extending @bsv/wallet-toolbox with 1Sat Ordinals protocol support",
5
5
  "author": "1Sat Team",
6
6
  "license": "MIT",