@1sat/wallet-browser 0.0.1
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/createWebWallet.d.ts +73 -0
- package/dist/createWebWallet.d.ts.map +1 -0
- package/dist/createWebWallet.js +251 -0
- package/dist/createWebWallet.js.map +1 -0
- package/dist/fullSync.d.ts +58 -0
- package/dist/fullSync.d.ts.map +1 -0
- package/dist/fullSync.js +92 -0
- package/dist/fullSync.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for creating web wallets.
|
|
3
|
+
*
|
|
4
|
+
* This consolidates the common wallet setup used by both yours-wallet
|
|
5
|
+
* (browser extension) and 1sat-website (React app).
|
|
6
|
+
*/
|
|
7
|
+
import { OneSatServices } from '@1sat/client';
|
|
8
|
+
import { PrivateKey } from '@bsv/sdk';
|
|
9
|
+
import { Monitor, StorageClient, Wallet, WalletStorageManager } from '@bsv/wallet-toolbox-mobile/out/src/index.client.js';
|
|
10
|
+
import { type FullSyncResult, type FullSyncStage } from './fullSync';
|
|
11
|
+
type Chain = 'main' | 'test';
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for creating a web wallet.
|
|
14
|
+
*/
|
|
15
|
+
export interface WebWalletConfig {
|
|
16
|
+
/** Private key - can be PrivateKey instance, WIF string, or hex string */
|
|
17
|
+
privateKey: PrivateKey | string;
|
|
18
|
+
/** Network: 'main' or 'test' */
|
|
19
|
+
chain: Chain;
|
|
20
|
+
/** Fee model. Default: { model: 'sat/kb', value: 100 } */
|
|
21
|
+
feeModel?: {
|
|
22
|
+
model: 'sat/kb';
|
|
23
|
+
value: number;
|
|
24
|
+
};
|
|
25
|
+
/** Remote storage URL. If provided, attempts to connect for cloud backup. */
|
|
26
|
+
remoteStorageUrl?: string;
|
|
27
|
+
/** Unique identifier for this storage instance. Must be persisted by the consuming application and reused across sessions. Different devices should use different values to isolate sync state. */
|
|
28
|
+
storageIdentityKey: string;
|
|
29
|
+
/** Callback when a transaction is broadcasted (called after remote sync if connected) */
|
|
30
|
+
onTransactionBroadcasted?: (txid: string) => void;
|
|
31
|
+
/** Callback when a transaction is proven (called after remote sync if connected) */
|
|
32
|
+
onTransactionProven?: (txid: string, blockHeight: number) => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Result of wallet creation.
|
|
36
|
+
*/
|
|
37
|
+
export interface WebWalletResult {
|
|
38
|
+
/** Wallet instance */
|
|
39
|
+
wallet: Wallet;
|
|
40
|
+
/** 1Sat services for API access */
|
|
41
|
+
services: OneSatServices;
|
|
42
|
+
/** Monitor for transaction lifecycle (not started - call monitor.startTasks() when ready) */
|
|
43
|
+
monitor: Monitor;
|
|
44
|
+
/** Cleanup function - stops monitor, destroys wallet */
|
|
45
|
+
destroy: () => Promise<void>;
|
|
46
|
+
/** Full sync with remote backup (only available if remoteStorageUrl was provided and connected) */
|
|
47
|
+
fullSync?: (onProgress?: (stage: FullSyncStage, message: string) => void) => Promise<FullSyncResult>;
|
|
48
|
+
/** Storage manager (for debugging/diagnostics) */
|
|
49
|
+
storage: WalletStorageManager;
|
|
50
|
+
/** Remote storage client (for debugging/diagnostics, undefined if not connected) */
|
|
51
|
+
remoteStorage?: StorageClient;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a web wallet with storage, services, and monitor.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const { wallet, services, monitor, destroy } = await createWebWallet({
|
|
59
|
+
* privateKey: identityWif,
|
|
60
|
+
* chain: 'main',
|
|
61
|
+
* storageIdentityKey: 'device-unique-id',
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* // Wire up monitor callbacks
|
|
65
|
+
* monitor.onTransactionProven = async (status) => console.log('Proven:', status.txid);
|
|
66
|
+
*
|
|
67
|
+
* // Start monitor when ready
|
|
68
|
+
* monitor.startTasks();
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function createWebWallet(config: WebWalletConfig): Promise<WebWalletResult>;
|
|
72
|
+
export {};
|
|
73
|
+
//# sourceMappingURL=createWebWallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createWebWallet.d.ts","sourceRoot":"","sources":["../src/createWebWallet.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAc,UAAU,EAAwB,MAAM,UAAU,CAAA;AAEvE,OAAO,EACN,OAAO,EAEP,aAAa,EAGb,MAAM,EACN,oBAAoB,EACpB,MAAM,oDAAoD,CAAA;AAC3D,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAY,MAAM,YAAY,CAAA;AAE9E,KAAK,KAAK,GAAG,MAAM,GAAG,MAAM,CAAA;AAY5B;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,0EAA0E;IAC1E,UAAU,EAAE,UAAU,GAAG,MAAM,CAAA;IAC/B,gCAAgC;IAChC,KAAK,EAAE,KAAK,CAAA;IACZ,0DAA0D;IAC1D,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7C,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,mMAAmM;IACnM,kBAAkB,EAAE,MAAM,CAAA;IAC1B,yFAAyF;IACzF,wBAAwB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACjD,oFAAoF;IACpF,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAA;CACjE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,mCAAmC;IACnC,QAAQ,EAAE,cAAc,CAAA;IACxB,6FAA6F;IAC7F,OAAO,EAAE,OAAO,CAAA;IAChB,wDAAwD;IACxD,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,mGAAmG;IACnG,QAAQ,CAAC,EAAE,CACV,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,KACxD,OAAO,CAAC,cAAc,CAAC,CAAA;IAC5B,kDAAkD;IAClD,OAAO,EAAE,oBAAoB,CAAA;IAC7B,oFAAoF;IACpF,aAAa,CAAC,EAAE,aAAa,CAAA;CAC7B;AA+BD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,eAAe,CACpC,MAAM,EAAE,eAAe,GACrB,OAAO,CAAC,eAAe,CAAC,CAqQ1B"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for creating web wallets.
|
|
3
|
+
*
|
|
4
|
+
* This consolidates the common wallet setup used by both yours-wallet
|
|
5
|
+
* (browser extension) and 1sat-website (React app).
|
|
6
|
+
*/
|
|
7
|
+
import { OneSatServices } from '@1sat/client';
|
|
8
|
+
import { KeyDeriver, PrivateKey } from '@bsv/sdk';
|
|
9
|
+
import { Monitor, Services, StorageClient, StorageIdb, StorageProvider, Wallet, WalletStorageManager, } from '@bsv/wallet-toolbox-mobile/out/src/index.client.js';
|
|
10
|
+
import { fullSync } from './fullSync';
|
|
11
|
+
// Default database name for IndexedDB storage
|
|
12
|
+
const DEFAULT_DATABASE_NAME = 'wallet';
|
|
13
|
+
// Default timeout for remote storage connection
|
|
14
|
+
const DEFAULT_REMOTE_STORAGE_TIMEOUT = 5000;
|
|
15
|
+
// Default fee model (100 sat/kb matches yours-wallet and 1sat-indexer minimum)
|
|
16
|
+
const DEFAULT_FEE_MODEL = { model: 'sat/kb', value: 100 };
|
|
17
|
+
/**
|
|
18
|
+
* Parse a private key from various input formats.
|
|
19
|
+
* Supports PrivateKey instance, WIF string, or hex string.
|
|
20
|
+
*/
|
|
21
|
+
function parsePrivateKey(input) {
|
|
22
|
+
if (input instanceof PrivateKey) {
|
|
23
|
+
return input;
|
|
24
|
+
}
|
|
25
|
+
// Try WIF first (starts with 5, K, L for mainnet or c for testnet)
|
|
26
|
+
if (/^[5KLc][1-9A-HJ-NP-Za-km-z]{50,51}$/.test(input)) {
|
|
27
|
+
return PrivateKey.fromWif(input);
|
|
28
|
+
}
|
|
29
|
+
// Try hex (64 characters)
|
|
30
|
+
if (/^[0-9a-fA-F]{64}$/.test(input)) {
|
|
31
|
+
return new PrivateKey(input);
|
|
32
|
+
}
|
|
33
|
+
// Last resort - try WIF anyway
|
|
34
|
+
try {
|
|
35
|
+
return PrivateKey.fromWif(input);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new Error('Invalid private key format. Expected PrivateKey instance, WIF string, or 64-char hex string.');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a web wallet with storage, services, and monitor.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const { wallet, services, monitor, destroy } = await createWebWallet({
|
|
47
|
+
* privateKey: identityWif,
|
|
48
|
+
* chain: 'main',
|
|
49
|
+
* storageIdentityKey: 'device-unique-id',
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // Wire up monitor callbacks
|
|
53
|
+
* monitor.onTransactionProven = async (status) => console.log('Proven:', status.txid);
|
|
54
|
+
*
|
|
55
|
+
* // Start monitor when ready
|
|
56
|
+
* monitor.startTasks();
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export async function createWebWallet(config) {
|
|
60
|
+
const { chain } = config;
|
|
61
|
+
const feeModel = config.feeModel ?? DEFAULT_FEE_MODEL;
|
|
62
|
+
// 1. Parse private key and create KeyDeriver
|
|
63
|
+
const privateKey = parsePrivateKey(config.privateKey);
|
|
64
|
+
const identityPubKey = privateKey.toPublicKey().toString();
|
|
65
|
+
const keyDeriver = new KeyDeriver(privateKey);
|
|
66
|
+
// 2. Create fallback services and OneSatServices
|
|
67
|
+
const fallbackServices = new Services(chain);
|
|
68
|
+
const oneSatServices = new OneSatServices(chain, undefined, fallbackServices);
|
|
69
|
+
// 3. Create local storage
|
|
70
|
+
const storageOptions = StorageProvider.createStorageBaseOptions(chain);
|
|
71
|
+
storageOptions.feeModel = feeModel;
|
|
72
|
+
const localStorage = new StorageIdb(storageOptions);
|
|
73
|
+
await localStorage.migrate(DEFAULT_DATABASE_NAME, config.storageIdentityKey);
|
|
74
|
+
// 4. Create storage manager with local-only storage initially (empty backups)
|
|
75
|
+
const storage = new WalletStorageManager(identityPubKey, localStorage, []);
|
|
76
|
+
await storage.makeAvailable();
|
|
77
|
+
// 5. Create wallet (needed before StorageClient for signing)
|
|
78
|
+
const wallet = new Wallet({
|
|
79
|
+
chain,
|
|
80
|
+
keyDeriver,
|
|
81
|
+
storage,
|
|
82
|
+
services: oneSatServices,
|
|
83
|
+
});
|
|
84
|
+
// 6. Attempt remote storage connection AFTER wallet exists
|
|
85
|
+
// Push-only backup: no sync on startup, just connect for incremental backups
|
|
86
|
+
// Use fullSync() explicitly to restore from backup when needed
|
|
87
|
+
let remoteClient;
|
|
88
|
+
if (config.remoteStorageUrl) {
|
|
89
|
+
console.log(`[createWebWallet] Attempting remote storage connection to ${config.remoteStorageUrl}`);
|
|
90
|
+
try {
|
|
91
|
+
remoteClient = new StorageClient(wallet, config.remoteStorageUrl);
|
|
92
|
+
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Remote storage connection timeout')), DEFAULT_REMOTE_STORAGE_TIMEOUT));
|
|
93
|
+
await Promise.race([remoteClient.makeAvailable(), timeoutPromise]);
|
|
94
|
+
// Add remote to storage manager - it will partition as conflicting if another device is active
|
|
95
|
+
await storage.addWalletStorageProvider(remoteClient);
|
|
96
|
+
// Check if remote ended up in backup stores (active) or got partitioned (conflicting)
|
|
97
|
+
const remoteStorageKey = remoteClient.getSettings().storageIdentityKey;
|
|
98
|
+
const isActive = storage.getBackupStores().includes(remoteStorageKey);
|
|
99
|
+
if (isActive) {
|
|
100
|
+
console.log('[createWebWallet] Remote backup connected (we are active)');
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Another device is active - need fullSync then setActive
|
|
104
|
+
// fullSync builds ID mappings before setActive attempts to merge
|
|
105
|
+
console.log('[createWebWallet] Another device is active, performing full sync...');
|
|
106
|
+
await fullSync({
|
|
107
|
+
storage,
|
|
108
|
+
remoteStorage: remoteClient,
|
|
109
|
+
identityKey: identityPubKey,
|
|
110
|
+
onProgress: (stage, msg) => console.log(`[createWebWallet] fullSync ${stage}: ${msg}`),
|
|
111
|
+
});
|
|
112
|
+
// Claim active status (merge now works because mappings exist from fullSync)
|
|
113
|
+
await storage.setActive(config.storageIdentityKey, (msg) => {
|
|
114
|
+
console.log('[createWebWallet] setActive:', msg);
|
|
115
|
+
return msg;
|
|
116
|
+
});
|
|
117
|
+
console.log('[createWebWallet] Remote backup connected (now active after handoff)');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
console.log('[createWebWallet] Remote backup connection failed:', err instanceof Error ? err.message : err);
|
|
122
|
+
remoteClient = undefined;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Helper to sync to remote backup using public updateBackups API
|
|
126
|
+
const syncToBackup = async (context) => {
|
|
127
|
+
if (storage.getBackupStores().length > 0) {
|
|
128
|
+
await storage.updateBackups(undefined, (msg) => {
|
|
129
|
+
console.log(`[createWebWallet] ${context}:`, msg);
|
|
130
|
+
return msg;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
// 8. Intercept createAction/signAction to sync after immediate broadcasts
|
|
135
|
+
// With acceptDelayedBroadcast: false, broadcasts happen synchronously and
|
|
136
|
+
// bypass the monitor's onTransactionBroadcasted callback. We detect broadcasts
|
|
137
|
+
// by checking for txid in the result and sync to backup immediately.
|
|
138
|
+
if (remoteClient) {
|
|
139
|
+
const originalCreateAction = wallet.createAction.bind(wallet);
|
|
140
|
+
wallet.createAction = async (args) => {
|
|
141
|
+
const result = await originalCreateAction(args);
|
|
142
|
+
if (result.txid) {
|
|
143
|
+
console.log('[createWebWallet] Broadcast detected in createAction:', result.txid);
|
|
144
|
+
syncToBackup('Backup after createAction').catch((err) => {
|
|
145
|
+
console.warn('[createWebWallet] Failed to sync after createAction:', err);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
};
|
|
150
|
+
const originalSignAction = wallet.signAction.bind(wallet);
|
|
151
|
+
wallet.signAction = async (args) => {
|
|
152
|
+
const result = await originalSignAction(args);
|
|
153
|
+
if (result.txid) {
|
|
154
|
+
console.log('[createWebWallet] Broadcast detected in signAction:', result.txid);
|
|
155
|
+
syncToBackup('Backup after signAction').catch((err) => {
|
|
156
|
+
console.warn('[createWebWallet] Failed to sync after signAction:', err);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
// 9. Create monitor (not started - consumer calls startTasks() when ready)
|
|
163
|
+
const monitor = new Monitor({
|
|
164
|
+
chain,
|
|
165
|
+
services: oneSatServices,
|
|
166
|
+
storage,
|
|
167
|
+
chaintracks: oneSatServices.chaintracks,
|
|
168
|
+
msecsWaitPerMerkleProofServiceReq: 500,
|
|
169
|
+
taskRunWaitMsecs: 5000,
|
|
170
|
+
abandonedMsecs: 300000,
|
|
171
|
+
unprovenAttemptsLimitTest: 10,
|
|
172
|
+
unprovenAttemptsLimitMain: 144,
|
|
173
|
+
});
|
|
174
|
+
monitor.addDefaultTasks();
|
|
175
|
+
console.log('[createWebWallet] Monitor created with tasks:', monitor._tasks.map((t) => t.name));
|
|
176
|
+
// 11. Wire up monitor callbacks - sync to remote first, then call user callbacks
|
|
177
|
+
// Note: For delayed broadcasts, the monitor triggers these. For immediate broadcasts,
|
|
178
|
+
// the interception in step 8 handles the sync, but these still fire for the user callback.
|
|
179
|
+
monitor.onTransactionBroadcasted = async (result) => {
|
|
180
|
+
console.log('[createWebWallet] Monitor detected broadcast:', result.txid);
|
|
181
|
+
// Sync to remote backup first (if connected)
|
|
182
|
+
// Note: For immediate broadcasts, step 8 already synced, but this is harmless
|
|
183
|
+
if (remoteClient) {
|
|
184
|
+
try {
|
|
185
|
+
await syncToBackup('Backup after monitor broadcast');
|
|
186
|
+
console.log('[createWebWallet] Synced to backup after monitor broadcast');
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
console.warn('[createWebWallet] Failed to sync after monitor broadcast:', err);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Then call user callback (if provided)
|
|
193
|
+
if (result.txid && config.onTransactionBroadcasted) {
|
|
194
|
+
try {
|
|
195
|
+
config.onTransactionBroadcasted(result.txid);
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
console.warn('[createWebWallet] User callback error after broadcast:', err);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
monitor.onTransactionProven = async (status) => {
|
|
203
|
+
console.log('[createWebWallet] Transaction proven:', status.txid, 'block', status.blockHeight);
|
|
204
|
+
// Sync to remote backup first (if connected)
|
|
205
|
+
if (remoteClient) {
|
|
206
|
+
try {
|
|
207
|
+
await syncToBackup('Backup after confirmation');
|
|
208
|
+
console.log('[createWebWallet] Synced to backup after confirmation');
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
console.warn('[createWebWallet] Failed to sync after confirmation:', err);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// Then call user callback (if provided)
|
|
215
|
+
if (config.onTransactionProven) {
|
|
216
|
+
try {
|
|
217
|
+
config.onTransactionProven(status.txid, status.blockHeight);
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
console.warn('[createWebWallet] User callback error after proven:', err);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
// 12. Create cleanup function
|
|
225
|
+
const destroy = async () => {
|
|
226
|
+
monitor.stopTasks();
|
|
227
|
+
await monitor.destroy();
|
|
228
|
+
await wallet.destroy();
|
|
229
|
+
};
|
|
230
|
+
// 13. Create fullSync function if remote storage is connected
|
|
231
|
+
const fullSyncFn = remoteClient
|
|
232
|
+
? async (onProgress) => {
|
|
233
|
+
return fullSync({
|
|
234
|
+
storage,
|
|
235
|
+
remoteStorage: remoteClient,
|
|
236
|
+
identityKey: identityPubKey,
|
|
237
|
+
onProgress,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
: undefined;
|
|
241
|
+
return {
|
|
242
|
+
wallet,
|
|
243
|
+
services: oneSatServices,
|
|
244
|
+
monitor,
|
|
245
|
+
destroy,
|
|
246
|
+
fullSync: fullSyncFn,
|
|
247
|
+
storage,
|
|
248
|
+
remoteStorage: remoteClient,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=createWebWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createWebWallet.js","sourceRoot":"","sources":["../src/createWebWallet.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAwB,MAAM,UAAU,CAAA;AAEvE,OAAO,EACN,OAAO,EACP,QAAQ,EACR,aAAa,EACb,UAAU,EACV,eAAe,EACf,MAAM,EACN,oBAAoB,GACpB,MAAM,oDAAoD,CAAA;AAC3D,OAAO,EAA2C,QAAQ,EAAE,MAAM,YAAY,CAAA;AAK9E,8CAA8C;AAC9C,MAAM,qBAAqB,GAAG,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AAA;IACvB,CAAC,CAAA;IAED,8DAA8D;IAC9D,MAAM,UAAU,GAAG,YAAY;QAC9B,CAAC,CAAC,KAAK,EACL,UAA4D,EAClC,EAAE;YAC5B,OAAO,QAAQ,CAAC;gBACf,OAAO;gBACP,aAAa,EAAE,YAAY;gBAC3B,WAAW,EAAE,cAAc;gBAC3B,UAAU;aACV,CAAC,CAAA;QACH,CAAC;QACF,CAAC,CAAC,SAAS,CAAA;IAEZ,OAAO;QACN,MAAM;QACN,QAAQ,EAAE,cAAc;QACxB,OAAO;QACP,OAAO;QACP,QAAQ,EAAE,UAAU;QACpB,OAAO;QACP,aAAa,EAAE,YAAY;KAC3B,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Full wallet synchronization with remote backup server.
|
|
3
|
+
*
|
|
4
|
+
* Performs a complete resync: push local → reset sync state → full pull from server.
|
|
5
|
+
* This is a deliberate user action (not automatic) for recovering from sync issues.
|
|
6
|
+
*/
|
|
7
|
+
import type { WalletStorageManager } from '@bsv/wallet-toolbox-mobile/out/src/index.client.js';
|
|
8
|
+
import type { sdk as mobileToolboxSdk } from '@bsv/wallet-toolbox-mobile/out/src/index.client.js';
|
|
9
|
+
type WalletStorageProvider = mobileToolboxSdk.WalletStorageProvider;
|
|
10
|
+
export type FullSyncStage = 'pushing' | 'resetting' | 'pulling' | 'complete';
|
|
11
|
+
export interface FullSyncOptions {
|
|
12
|
+
/** Local storage manager */
|
|
13
|
+
storage: WalletStorageManager;
|
|
14
|
+
/** Remote backup storage provider (StorageClient) */
|
|
15
|
+
remoteStorage: WalletStorageProvider;
|
|
16
|
+
/** Identity key for the wallet */
|
|
17
|
+
identityKey: string;
|
|
18
|
+
/** Optional progress callback */
|
|
19
|
+
onProgress?: (stage: FullSyncStage, message: string) => void;
|
|
20
|
+
/** Max rough size per chunk in bytes (default: 1MB) */
|
|
21
|
+
maxRoughSize?: number;
|
|
22
|
+
/** Max items per chunk (default: 100) */
|
|
23
|
+
maxItems?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface FullSyncResult {
|
|
26
|
+
pushed: {
|
|
27
|
+
inserts: number;
|
|
28
|
+
updates: number;
|
|
29
|
+
};
|
|
30
|
+
pulled: {
|
|
31
|
+
inserts: number;
|
|
32
|
+
updates: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Perform a full sync with the remote backup server.
|
|
37
|
+
*
|
|
38
|
+
* Steps:
|
|
39
|
+
* 1. Push all local data to remote backup
|
|
40
|
+
* 2. Clear local syncMap / reset sync state
|
|
41
|
+
* 3. Pull ALL data from server (not incremental)
|
|
42
|
+
* 4. Rebuild complete server→client ID mappings
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const result = await fullSync({
|
|
47
|
+
* storage,
|
|
48
|
+
* remoteStorage: remoteClient,
|
|
49
|
+
* identityKey: pubKey,
|
|
50
|
+
* onProgress: (stage, msg) => console.log(`[${stage}] ${msg}`)
|
|
51
|
+
* });
|
|
52
|
+
* console.log(`Pushed: ${result.pushed.inserts}/${result.pushed.updates}`);
|
|
53
|
+
* console.log(`Pulled: ${result.pulled.inserts}/${result.pulled.updates}`);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function fullSync(options: FullSyncOptions): Promise<FullSyncResult>;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=fullSync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fullSync.d.ts","sourceRoot":"","sources":["../src/fullSync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAA;AAC9F,OAAO,KAAK,EAAE,GAAG,IAAI,gBAAgB,EAAE,MAAM,oDAAoD,CAAA;AAIjG,KAAK,qBAAqB,GAAG,gBAAgB,CAAC,qBAAqB,CAAA;AAEnE,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAA;AAE5E,MAAM,WAAW,eAAe;IAC/B,4BAA4B;IAC5B,OAAO,EAAE,oBAAoB,CAAA;IAC7B,qDAAqD;IACrD,aAAa,EAAE,qBAAqB,CAAA;IACpC,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,iCAAiC;IACjC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5D,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5C,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,QAAQ,CAC7B,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,cAAc,CAAC,CAwGzB"}
|
package/dist/fullSync.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Full wallet synchronization with remote backup server.
|
|
3
|
+
*
|
|
4
|
+
* Performs a complete resync: push local → reset sync state → full pull from server.
|
|
5
|
+
* This is a deliberate user action (not automatic) for recovering from sync issues.
|
|
6
|
+
*/
|
|
7
|
+
import { createSyncMap } from '@bsv/wallet-toolbox-mobile/out/src/storage/schema/entities/EntityBase.js';
|
|
8
|
+
import { EntitySyncState } from '@bsv/wallet-toolbox-mobile/out/src/storage/schema/entities/EntitySyncState.js';
|
|
9
|
+
/**
|
|
10
|
+
* Perform a full sync with the remote backup server.
|
|
11
|
+
*
|
|
12
|
+
* Steps:
|
|
13
|
+
* 1. Push all local data to remote backup
|
|
14
|
+
* 2. Clear local syncMap / reset sync state
|
|
15
|
+
* 3. Pull ALL data from server (not incremental)
|
|
16
|
+
* 4. Rebuild complete server→client ID mappings
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const result = await fullSync({
|
|
21
|
+
* storage,
|
|
22
|
+
* remoteStorage: remoteClient,
|
|
23
|
+
* identityKey: pubKey,
|
|
24
|
+
* onProgress: (stage, msg) => console.log(`[${stage}] ${msg}`)
|
|
25
|
+
* });
|
|
26
|
+
* console.log(`Pushed: ${result.pushed.inserts}/${result.pushed.updates}`);
|
|
27
|
+
* console.log(`Pulled: ${result.pulled.inserts}/${result.pulled.updates}`);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export async function fullSync(options) {
|
|
31
|
+
const { storage, remoteStorage, identityKey, onProgress, maxRoughSize = 1000000, // 1 MB default
|
|
32
|
+
maxItems = 100, } = options;
|
|
33
|
+
// Step 1: Push ALL local data to remote (bypassing timestamp filter)
|
|
34
|
+
onProgress?.('pushing', 'Pushing local data to remote...');
|
|
35
|
+
const localSettings = storage.getSettings();
|
|
36
|
+
const remoteSettings = await remoteStorage.makeAvailable();
|
|
37
|
+
let pushInserts = 0;
|
|
38
|
+
let pushUpdates = 0;
|
|
39
|
+
let chunkCount = 0;
|
|
40
|
+
for (;;) {
|
|
41
|
+
// Get sync state from remote for proper offsets
|
|
42
|
+
const ss = await EntitySyncState.fromStorage(remoteStorage, identityKey, localSettings);
|
|
43
|
+
const args = ss.makeRequestSyncChunkArgs(identityKey, remoteSettings.storageIdentityKey, maxRoughSize, maxItems);
|
|
44
|
+
// KEY: Override since to undefined - includes ALL data regardless of timestamp
|
|
45
|
+
args.since = undefined;
|
|
46
|
+
// Get chunk from local storage
|
|
47
|
+
const chunk = await storage.runAsSync(async (sync) => sync.getSyncChunk(args));
|
|
48
|
+
// Send chunk to remote
|
|
49
|
+
const result = await remoteStorage.processSyncChunk(args, chunk);
|
|
50
|
+
pushInserts += result.inserts;
|
|
51
|
+
pushUpdates += result.updates;
|
|
52
|
+
chunkCount++;
|
|
53
|
+
onProgress?.('pushing', `Chunk ${chunkCount}: ${result.inserts} inserts, ${result.updates} updates`);
|
|
54
|
+
if (result.done)
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
onProgress?.('pushing', `Pushed ${pushInserts} inserts, ${pushUpdates} updates`);
|
|
58
|
+
// Step 2: Reset sync state to force full pull
|
|
59
|
+
onProgress?.('resetting', 'Resetting sync state...');
|
|
60
|
+
const auth = await storage.getAuth();
|
|
61
|
+
await storage.runAsStorageProvider(async (active) => {
|
|
62
|
+
const syncStates = await active.findSyncStates({
|
|
63
|
+
partial: {
|
|
64
|
+
userId: auth.userId,
|
|
65
|
+
storageIdentityKey: remoteSettings.storageIdentityKey,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
if (syncStates.length > 0) {
|
|
69
|
+
const syncState = syncStates[0];
|
|
70
|
+
await active.updateSyncState(syncState.syncStateId, {
|
|
71
|
+
syncMap: JSON.stringify(createSyncMap()),
|
|
72
|
+
when: undefined,
|
|
73
|
+
status: 'unknown',
|
|
74
|
+
});
|
|
75
|
+
onProgress?.('resetting', 'Sync state reset complete');
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
onProgress?.('resetting', 'No existing sync state found');
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
// Step 3: Pull from remote (full pull due to reset state)
|
|
82
|
+
onProgress?.('pulling', 'Pulling all data from remote...');
|
|
83
|
+
const pullResult = await storage.syncFromReader(identityKey, remoteStorage);
|
|
84
|
+
onProgress?.('pulling', `Pulled ${pullResult.inserts} inserts, ${pullResult.updates} updates`);
|
|
85
|
+
// Step 4: Complete
|
|
86
|
+
onProgress?.('complete', 'Full sync complete');
|
|
87
|
+
return {
|
|
88
|
+
pushed: { inserts: pushInserts, updates: pushUpdates },
|
|
89
|
+
pulled: { inserts: pullResult.inserts, updates: pullResult.updates },
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=fullSync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fullSync.js","sourceRoot":"","sources":["../src/fullSync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,0EAA0E,CAAA;AACxG,OAAO,EAAE,eAAe,EAAE,MAAM,+EAA+E,CAAA;AA0B/G;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,OAAwB;IAExB,MAAM,EACL,OAAO,EACP,aAAa,EACb,WAAW,EACX,UAAU,EACV,YAAY,GAAG,OAAO,EAAE,eAAe;IACvC,QAAQ,GAAG,GAAG,GACd,GAAG,OAAO,CAAA;IAEX,qEAAqE;IACrE,UAAU,EAAE,CAAC,SAAS,EAAE,iCAAiC,CAAC,CAAA;IAE1D,MAAM,aAAa,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;IAC3C,MAAM,cAAc,GAAG,MAAM,aAAa,CAAC,aAAa,EAAE,CAAA;IAE1D,IAAI,WAAW,GAAG,CAAC,CAAA;IACnB,IAAI,WAAW,GAAG,CAAC,CAAA;IACnB,IAAI,UAAU,GAAG,CAAC,CAAA;IAElB,SAAS,CAAC;QACT,gDAAgD;QAChD,MAAM,EAAE,GAAG,MAAM,eAAe,CAAC,WAAW,CAC3C,aAAa,EACb,WAAW,EACX,aAAa,CACb,CAAA;QACD,MAAM,IAAI,GAAG,EAAE,CAAC,wBAAwB,CACvC,WAAW,EACX,cAAc,CAAC,kBAAkB,EACjC,YAAY,EACZ,QAAQ,CACR,CAAA;QAED,+EAA+E;QAC/E,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;QAEtB,+BAA+B;QAC/B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,KAAK,EAA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EAAE,2BAA2B,CAAC,CAAA;QACvD,CAAC;aAAM,CAAC;YACP,UAAU,EAAE,CAAC,WAAW,EAAE,8BAA8B,CAAC,CAAA;QAC1D,CAAC;IACF,CAAC,CAAC,CAAA;IAEF,0DAA0D;IAC1D,UAAU,EAAE,CAAC,SAAS,EAAE,iCAAiC,CAAC,CAAA;IAE1D,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,aAAa,CAAC,CAAA;IAE3E,UAAU,EAAE,CACX,SAAS,EACT,UAAU,UAAU,CAAC,OAAO,aAAa,UAAU,CAAC,OAAO,UAAU,CACrE,CAAA;IAED,mBAAmB;IACnB,UAAU,EAAE,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAA;IAE9C,OAAO;QACN,MAAM,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE;QACtD,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE;KACpE,CAAA;AACF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @1sat/wallet-browser - Browser wallet factory for 1Sat Ordinals SDK
|
|
3
|
+
*
|
|
4
|
+
* This package provides the browser-specific wallet factory using IndexedDB storage.
|
|
5
|
+
*/
|
|
6
|
+
export * from '@1sat/wallet';
|
|
7
|
+
export { createWebWallet } from './createWebWallet';
|
|
8
|
+
export type { WebWalletConfig, WebWalletResult } from './createWebWallet';
|
|
9
|
+
export { fullSync } from './fullSync';
|
|
10
|
+
export type { FullSyncOptions, FullSyncResult, FullSyncStage } from './fullSync';
|
|
11
|
+
export { Monitor, Services, StorageClient, StorageIdb, StorageProvider, Wallet, WalletStorageManager, type sdk as walletSdk, } from '@bsv/wallet-toolbox-mobile/out/src/index.client.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,cAAc,CAAA;AAG5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGzE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAGhF,OAAO,EACN,OAAO,EACP,QAAQ,EACR,aAAa,EACb,UAAU,EACV,eAAe,EACf,MAAM,EACN,oBAAoB,EACpB,KAAK,GAAG,IAAI,SAAS,GACrB,MAAM,oDAAoD,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @1sat/wallet-browser - Browser wallet factory for 1Sat Ordinals SDK
|
|
3
|
+
*
|
|
4
|
+
* This package provides the browser-specific wallet factory using IndexedDB storage.
|
|
5
|
+
*/
|
|
6
|
+
// Re-export everything from base wallet
|
|
7
|
+
export * from '@1sat/wallet';
|
|
8
|
+
// Browser-specific factory
|
|
9
|
+
export { createWebWallet } from './createWebWallet';
|
|
10
|
+
// Full sync
|
|
11
|
+
export { fullSync } from './fullSync';
|
|
12
|
+
// Re-export browser toolbox utilities
|
|
13
|
+
export { Monitor, Services, StorageClient, StorageIdb, StorageProvider, Wallet, WalletStorageManager, } from '@bsv/wallet-toolbox-mobile/out/src/index.client.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wCAAwC;AACxC,cAAc,cAAc,CAAA;AAE5B,2BAA2B;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGnD,YAAY;AACZ,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrC,sCAAsC;AACtC,OAAO,EACN,OAAO,EACP,QAAQ,EACR,aAAa,EACb,UAAU,EACV,eAAe,EACf,MAAM,EACN,oBAAoB,GAEpB,MAAM,oDAAoD,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@1sat/wallet-browser",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Browser wallet factory for 1Sat Ordinals SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist"],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"dev": "tsc --watch",
|
|
18
|
+
"clean": "rm -rf dist"
|
|
19
|
+
},
|
|
20
|
+
"keywords": ["1sat", "bsv", "ordinals", "wallet", "browser"],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@1sat/wallet": "^0.0.5"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@bsv/sdk": "^1.10.4",
|
|
27
|
+
"@bsv/wallet-toolbox-mobile": "npm:@bopen-io/wallet-toolbox-mobile@1.7.24-idb-fix.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@bsv/sdk": "^1.10.4",
|
|
31
|
+
"@bsv/wallet-toolbox-mobile": "npm:@bopen-io/wallet-toolbox-mobile@1.7.24-idb-fix.1",
|
|
32
|
+
"typescript": "^5.9.3"
|
|
33
|
+
}
|
|
34
|
+
}
|