@1sat/wallet-browser 0.0.18 → 0.0.20
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 +8 -54
- package/dist/createWebWallet.d.ts.map +1 -1
- package/dist/createWebWallet.js +40 -251
- package/dist/createWebWallet.js.map +1 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -10
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/fullSync.d.ts +0 -58
- package/dist/fullSync.d.ts.map +0 -1
- package/dist/fullSync.js +0 -92
- package/dist/fullSync.js.map +0 -1
|
@@ -1,76 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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';
|
|
1
|
+
import type { OneSatServices } from '@1sat/client';
|
|
2
|
+
import type { PrivateKey } from '@bsv/sdk';
|
|
9
3
|
import { Monitor, StorageClient, Wallet, WalletStorageManager } from '@bsv/wallet-toolbox/out/src/index.client.js';
|
|
10
|
-
import { type FullSyncResult, type FullSyncStage } from './fullSync';
|
|
11
4
|
import type { MonitorEvent } from './types';
|
|
12
|
-
type Chain = 'main' | 'test';
|
|
13
|
-
/**
|
|
14
|
-
* Configuration for creating a web wallet.
|
|
15
|
-
*/
|
|
16
5
|
export interface WebWalletConfig {
|
|
17
|
-
/** Private key - can be PrivateKey instance, WIF string, or hex string */
|
|
18
6
|
privateKey: PrivateKey | string;
|
|
19
|
-
|
|
20
|
-
chain: Chain;
|
|
21
|
-
/** Fee model. Default: { model: 'sat/kb', value: 100 } */
|
|
7
|
+
chain: 'main' | 'test';
|
|
22
8
|
feeModel?: {
|
|
23
9
|
model: 'sat/kb';
|
|
24
10
|
value: number;
|
|
25
11
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/** 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. */
|
|
12
|
+
activeRemote?: string;
|
|
13
|
+
backups?: string[];
|
|
29
14
|
storageIdentityKey: string;
|
|
30
|
-
|
|
15
|
+
connectionTimeout?: number;
|
|
31
16
|
onTransactionBroadcasted?: (txid: string) => void;
|
|
32
|
-
/** Callback when a transaction is proven (called after remote sync if connected) */
|
|
33
17
|
onTransactionProven?: (txid: string, blockHeight: number) => void;
|
|
34
|
-
/** Typed monitor event callback for structured lifecycle events */
|
|
35
18
|
onMonitorEvent?: (event: MonitorEvent) => void;
|
|
36
19
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Result of wallet creation.
|
|
39
|
-
*/
|
|
40
20
|
export interface WebWalletResult {
|
|
41
|
-
/** Wallet instance */
|
|
42
21
|
wallet: Wallet;
|
|
43
|
-
/** 1Sat services for API access */
|
|
44
22
|
services: OneSatServices;
|
|
45
|
-
|
|
46
|
-
monitor: Monitor;
|
|
47
|
-
/** Cleanup function - stops monitor, destroys wallet */
|
|
23
|
+
monitor?: Monitor;
|
|
48
24
|
destroy: () => Promise<void>;
|
|
49
|
-
/** Full sync with remote backup (only available if remoteStorageUrl was provided and connected) */
|
|
50
|
-
fullSync?: (onProgress?: (stage: FullSyncStage, message: string) => void) => Promise<FullSyncResult>;
|
|
51
|
-
/** Storage manager (for debugging/diagnostics) */
|
|
52
25
|
storage: WalletStorageManager;
|
|
53
|
-
/** Remote storage client (for debugging/diagnostics, undefined if not connected) */
|
|
54
26
|
remoteStorage?: StorageClient;
|
|
27
|
+
migrateRemote: (url: string) => Promise<void>;
|
|
55
28
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Create a web wallet with storage, services, and monitor.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const { wallet, services, monitor, destroy } = await createWebWallet({
|
|
62
|
-
* privateKey: identityWif,
|
|
63
|
-
* chain: 'main',
|
|
64
|
-
* storageIdentityKey: 'device-unique-id',
|
|
65
|
-
* });
|
|
66
|
-
*
|
|
67
|
-
* // Wire up monitor callbacks
|
|
68
|
-
* monitor.onTransactionProven = async (status) => console.log('Proven:', status.txid);
|
|
69
|
-
*
|
|
70
|
-
* // Start monitor when ready
|
|
71
|
-
* monitor.startTasks();
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
29
|
export declare function createWebWallet(config: WebWalletConfig): Promise<WebWalletResult>;
|
|
75
|
-
export {};
|
|
76
30
|
//# sourceMappingURL=createWebWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createWebWallet.d.ts","sourceRoot":"","sources":["../src/createWebWallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createWebWallet.d.ts","sourceRoot":"","sources":["../src/createWebWallet.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EACN,OAAO,EAEP,aAAa,EAGb,MAAM,EACN,oBAAoB,EACpB,MAAM,6CAA6C,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAI3C,MAAM,WAAW,eAAe;IAC/B,UAAU,EAAE,UAAU,GAAG,MAAM,CAAA;IAC/B,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,wBAAwB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IACjD,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAA;IACjE,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;CAC9C;AAED,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,cAAc,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,OAAO,EAAE,oBAAoB,CAAA;IAC7B,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7C;AAED,wBAAsB,eAAe,CACpC,MAAM,EAAE,eAAe,GACrB,OAAO,CAAC,eAAe,CAAC,CA6D1B"}
|
package/dist/createWebWallet.js
CHANGED
|
@@ -1,272 +1,61 @@
|
|
|
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';
|
|
1
|
+
import { createWalletCore, DEFAULT_FEE_MODEL, } from '@1sat/wallet';
|
|
9
2
|
import { Monitor, Services, StorageClient, StorageIdb, StorageProvider, Wallet, WalletStorageManager, } from '@bsv/wallet-toolbox/out/src/index.client.js';
|
|
10
|
-
import { fullSync } from './fullSync';
|
|
11
|
-
// Default database name for IndexedDB storage
|
|
12
3
|
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
4
|
export async function createWebWallet(config) {
|
|
60
|
-
const { chain, onMonitorEvent } = config;
|
|
61
5
|
const feeModel = config.feeModel ?? DEFAULT_FEE_MODEL;
|
|
62
|
-
const
|
|
63
|
-
try {
|
|
64
|
-
onMonitorEvent?.(event);
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
// Never let event handler errors crash wallet operations
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
// 1. Parse private key and create KeyDeriver
|
|
71
|
-
const privateKey = parsePrivateKey(config.privateKey);
|
|
72
|
-
const identityPubKey = privateKey.toPublicKey().toString();
|
|
73
|
-
const keyDeriver = new KeyDeriver(privateKey);
|
|
74
|
-
// 2. Create fallback services and OneSatServices
|
|
75
|
-
const fallbackServices = new Services(chain);
|
|
76
|
-
const oneSatServices = new OneSatServices(chain, undefined, fallbackServices);
|
|
77
|
-
// 3. Create local storage
|
|
78
|
-
const storageOptions = StorageProvider.createStorageBaseOptions(chain);
|
|
6
|
+
const storageOptions = StorageProvider.createStorageBaseOptions(config.chain);
|
|
79
7
|
storageOptions.feeModel = feeModel;
|
|
80
8
|
const localStorage = new StorageIdb(storageOptions);
|
|
81
9
|
await localStorage.migrate(DEFAULT_DATABASE_NAME, config.storageIdentityKey);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
storage,
|
|
90
|
-
services: oneSatServices,
|
|
10
|
+
const core = await createWalletCore(config, localStorage, {
|
|
11
|
+
Services,
|
|
12
|
+
StorageClient,
|
|
13
|
+
StorageProvider,
|
|
14
|
+
Wallet,
|
|
15
|
+
WalletStorageManager,
|
|
16
|
+
Monitor,
|
|
91
17
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// Check if remote ended up in backup stores (active) or got partitioned (conflicting)
|
|
105
|
-
const remoteStorageKey = remoteClient.getSettings().storageIdentityKey;
|
|
106
|
-
const isActive = storage.getBackupStores().includes(remoteStorageKey);
|
|
107
|
-
if (isActive) {
|
|
108
|
-
console.log('[createWebWallet] Remote backup connected (we are active)');
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
// Another device is active - need fullSync then setActive
|
|
112
|
-
// fullSync builds ID mappings before setActive attempts to merge
|
|
113
|
-
console.log('[createWebWallet] Another device is active, performing full sync...');
|
|
114
|
-
await fullSync({
|
|
115
|
-
storage,
|
|
116
|
-
remoteStorage: remoteClient,
|
|
117
|
-
identityKey: identityPubKey,
|
|
118
|
-
onProgress: (stage, msg) => {
|
|
119
|
-
console.log(`[createWebWallet] fullSync ${stage}: ${msg}`);
|
|
120
|
-
emit({ type: 'sync:progress', stage, message: msg });
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
// Claim active status (merge now works because mappings exist from fullSync)
|
|
124
|
-
await storage.setActive(config.storageIdentityKey, (msg) => {
|
|
125
|
-
console.log('[createWebWallet] setActive:', msg);
|
|
126
|
-
return msg;
|
|
127
|
-
});
|
|
128
|
-
console.log('[createWebWallet] Remote backup connected (now active after handoff)');
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
133
|
-
console.log('[createWebWallet] Remote backup connection failed:', msg);
|
|
134
|
-
emit({ type: 'error', source: 'remote-storage', message: msg });
|
|
135
|
-
remoteClient = undefined;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// Helper to sync to remote backup using public updateBackups API
|
|
139
|
-
const syncToBackup = async (context) => {
|
|
140
|
-
if (storage.getBackupStores().length > 0) {
|
|
141
|
-
await storage.updateBackups(undefined, (msg) => {
|
|
142
|
-
console.log(`[createWebWallet] ${context}:`, msg);
|
|
143
|
-
emit({ type: 'sync:backup', message: `${context}: ${msg}` });
|
|
144
|
-
return msg;
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
// 8. Intercept createAction/signAction to sync after immediate broadcasts
|
|
149
|
-
// With acceptDelayedBroadcast: false, broadcasts happen synchronously and
|
|
150
|
-
// bypass the monitor's onTransactionBroadcasted callback. We detect broadcasts
|
|
151
|
-
// by checking for txid in the result and sync to backup immediately.
|
|
152
|
-
if (remoteClient) {
|
|
153
|
-
const originalCreateAction = wallet.createAction.bind(wallet);
|
|
154
|
-
wallet.createAction = async (args) => {
|
|
155
|
-
const result = await originalCreateAction(args);
|
|
156
|
-
if (result.txid) {
|
|
157
|
-
console.log('[createWebWallet] Broadcast detected in createAction:', result.txid);
|
|
158
|
-
syncToBackup('Backup after createAction').catch((err) => {
|
|
159
|
-
console.warn('[createWebWallet] Failed to sync after createAction:', err);
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
return result;
|
|
163
|
-
};
|
|
164
|
-
const originalSignAction = wallet.signAction.bind(wallet);
|
|
165
|
-
wallet.signAction = async (args) => {
|
|
166
|
-
const result = await originalSignAction(args);
|
|
167
|
-
if (result.txid) {
|
|
168
|
-
console.log('[createWebWallet] Broadcast detected in signAction:', result.txid);
|
|
169
|
-
syncToBackup('Backup after signAction').catch((err) => {
|
|
170
|
-
console.warn('[createWebWallet] Failed to sync after signAction:', err);
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
return result;
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
// 9. Create monitor (not started - consumer calls startTasks() when ready)
|
|
177
|
-
const monitor = new Monitor({
|
|
178
|
-
chain,
|
|
179
|
-
services: oneSatServices,
|
|
180
|
-
storage,
|
|
181
|
-
chaintracks: oneSatServices.chaintracks,
|
|
182
|
-
msecsWaitPerMerkleProofServiceReq: 500,
|
|
183
|
-
taskRunWaitMsecs: 5000,
|
|
184
|
-
abandonedMsecs: 300000,
|
|
185
|
-
unprovenAttemptsLimitTest: 10,
|
|
186
|
-
unprovenAttemptsLimitMain: 144,
|
|
187
|
-
});
|
|
188
|
-
monitor.addDefaultTasks();
|
|
189
|
-
console.log('[createWebWallet] Monitor created with tasks:', monitor._tasks.map((t) => t.name));
|
|
190
|
-
// 11. Wire up monitor callbacks - sync to remote first, then call user callbacks
|
|
191
|
-
// Note: For delayed broadcasts, the monitor triggers these. For immediate broadcasts,
|
|
192
|
-
// the interception in step 8 handles the sync, but these still fire for the user callback.
|
|
193
|
-
monitor.onTransactionBroadcasted = async (result) => {
|
|
194
|
-
console.log('[createWebWallet] Monitor detected broadcast:', result.txid);
|
|
195
|
-
emit({ type: 'broadcast', txid: result.txid, status: 'success' });
|
|
196
|
-
// Sync to remote backup first (if connected)
|
|
197
|
-
// Note: For immediate broadcasts, step 8 already synced, but this is harmless
|
|
198
|
-
if (remoteClient) {
|
|
199
|
-
try {
|
|
200
|
-
await syncToBackup('Backup after monitor broadcast');
|
|
201
|
-
console.log('[createWebWallet] Synced to backup after monitor broadcast');
|
|
202
|
-
}
|
|
203
|
-
catch (err) {
|
|
204
|
-
console.warn('[createWebWallet] Failed to sync after monitor broadcast:', err);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
// Then call user callback (if provided)
|
|
208
|
-
if (result.txid && config.onTransactionBroadcasted) {
|
|
209
|
-
try {
|
|
210
|
-
config.onTransactionBroadcasted(result.txid);
|
|
211
|
-
}
|
|
212
|
-
catch (err) {
|
|
213
|
-
console.warn('[createWebWallet] User callback error after broadcast:', err);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
monitor.onTransactionProven = async (status) => {
|
|
218
|
-
console.log('[createWebWallet] Transaction proven:', status.txid, 'block', status.blockHeight);
|
|
219
|
-
emit({
|
|
220
|
-
type: 'proven',
|
|
221
|
-
txid: status.txid,
|
|
222
|
-
blockHeight: status.blockHeight,
|
|
223
|
-
blockHash: status.blockHash ?? '',
|
|
18
|
+
let monitor;
|
|
19
|
+
if (!config.activeRemote) {
|
|
20
|
+
monitor = new Monitor({
|
|
21
|
+
chain: config.chain,
|
|
22
|
+
services: core.services,
|
|
23
|
+
storage: core.storage,
|
|
24
|
+
chaintracks: core.services.chaintracks,
|
|
25
|
+
msecsWaitPerMerkleProofServiceReq: 500,
|
|
26
|
+
taskRunWaitMsecs: 5000,
|
|
27
|
+
abandonedMsecs: 300000,
|
|
28
|
+
unprovenAttemptsLimitTest: 10,
|
|
29
|
+
unprovenAttemptsLimitMain: 144,
|
|
224
30
|
});
|
|
225
|
-
|
|
226
|
-
if (
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
catch (err) {
|
|
232
|
-
console.warn('[createWebWallet] Failed to sync after confirmation:', err);
|
|
233
|
-
}
|
|
31
|
+
monitor.addDefaultTasks();
|
|
32
|
+
if (config.onTransactionBroadcasted) {
|
|
33
|
+
monitor.onTransactionBroadcasted = async (result) => {
|
|
34
|
+
if (result.txid)
|
|
35
|
+
config.onTransactionBroadcasted(result.txid);
|
|
36
|
+
};
|
|
234
37
|
}
|
|
235
|
-
// Then call user callback (if provided)
|
|
236
38
|
if (config.onTransactionProven) {
|
|
237
|
-
|
|
39
|
+
monitor.onTransactionProven = async (status) => {
|
|
238
40
|
config.onTransactionProven(status.txid, status.blockHeight);
|
|
239
|
-
}
|
|
240
|
-
catch (err) {
|
|
241
|
-
console.warn('[createWebWallet] User callback error after proven:', err);
|
|
242
|
-
}
|
|
41
|
+
};
|
|
243
42
|
}
|
|
244
|
-
}
|
|
245
|
-
// 12. Create cleanup function
|
|
43
|
+
}
|
|
246
44
|
const destroy = async () => {
|
|
247
|
-
monitor
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
};
|
|
251
|
-
// 13. Create fullSync function if remote storage is connected
|
|
252
|
-
const fullSyncFn = remoteClient
|
|
253
|
-
? async (onProgress) => {
|
|
254
|
-
return fullSync({
|
|
255
|
-
storage,
|
|
256
|
-
remoteStorage: remoteClient,
|
|
257
|
-
identityKey: identityPubKey,
|
|
258
|
-
onProgress,
|
|
259
|
-
});
|
|
45
|
+
if (monitor) {
|
|
46
|
+
monitor.stopTasks();
|
|
47
|
+
await monitor.destroy();
|
|
260
48
|
}
|
|
261
|
-
|
|
49
|
+
await core.destroy();
|
|
50
|
+
};
|
|
262
51
|
return {
|
|
263
|
-
wallet,
|
|
264
|
-
services:
|
|
52
|
+
wallet: core.wallet,
|
|
53
|
+
services: core.services,
|
|
265
54
|
monitor,
|
|
266
55
|
destroy,
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
56
|
+
storage: core.storage,
|
|
57
|
+
remoteStorage: core.remoteClients[0],
|
|
58
|
+
migrateRemote: core.migrateRemote,
|
|
270
59
|
};
|
|
271
60
|
}
|
|
272
61
|
//# sourceMappingURL=createWebWallet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createWebWallet.js","sourceRoot":"","sources":["../src/createWebWallet.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"createWebWallet.js","sourceRoot":"","sources":["../src/createWebWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,cAAc,CAAA;AAGrB,OAAO,EACN,OAAO,EACP,QAAQ,EACR,aAAa,EACb,UAAU,EACV,eAAe,EACf,MAAM,EACN,oBAAoB,GACpB,MAAM,6CAA6C,CAAA;AAGpD,MAAM,qBAAqB,GAAG,QAAQ,CAAA;AAyBtC,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,MAAuB;IAEvB,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,iBAAiB,CAAA;IAErD,MAAM,cAAc,GAAG,eAAe,CAAC,wBAAwB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC7E,cAAc,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAClC,MAAM,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AAG,KAAK,IAAmB,EAAE;QACzC,IAAI,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,SAAS,EAAE,CAAA;YACnB,MAAM,OAAO,CAAC,OAAO,EAAE,CAAA;QACxB,CAAC;QACD,MAAM,IAAI,CAAC,OAAO,EAAE,CAAA;IACrB,CAAC,CAAA;IAED,OAAO;QACN,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO;QACP,OAAO;QACP,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;QACpC,aAAa,EAAE,IAAI,CAAC,aAAa;KACjC,CAAA;AACF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
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
1
|
export * from '@1sat/wallet';
|
|
7
2
|
export { createWebWallet } from './createWebWallet';
|
|
8
3
|
export type { WebWalletConfig, WebWalletResult } from './createWebWallet';
|
|
9
|
-
export { fullSync } from './fullSync';
|
|
10
|
-
export type { FullSyncOptions, FullSyncResult, FullSyncStage } from './fullSync';
|
|
11
4
|
export type { MonitorEvent } from './types';
|
|
12
5
|
export { Monitor, Services, StorageClient, StorageIdb, StorageProvider, Wallet, WalletStorageManager, type sdk as walletSdk, } from '@bsv/wallet-toolbox/out/src/index.client.js';
|
|
13
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEzE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,OAAO,EACN,OAAO,EACP,QAAQ,EACR,aAAa,EACb,UAAU,EACV,eAAe,EACf,MAAM,EACN,oBAAoB,EACpB,KAAK,GAAG,IAAI,SAAS,GACrB,MAAM,6CAA6C,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
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
1
|
export * from '@1sat/wallet';
|
|
8
|
-
// Browser-specific factory
|
|
9
2
|
export { createWebWallet } from './createWebWallet';
|
|
10
|
-
// Full sync
|
|
11
|
-
export { fullSync } from './fullSync';
|
|
12
|
-
// Re-export browser toolbox utilities
|
|
13
3
|
export { Monitor, Services, StorageClient, StorageIdb, StorageProvider, Wallet, WalletStorageManager, } from '@bsv/wallet-toolbox/out/src/index.client.js';
|
|
14
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAKnD,OAAO,EACN,OAAO,EACP,QAAQ,EACR,aAAa,EACb,UAAU,EACV,eAAe,EACf,MAAM,EACN,oBAAoB,GAEpB,MAAM,6CAA6C,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { FullSyncStage } from './fullSync';
|
|
2
1
|
/** Typed event union emitted by the monitor and wallet lifecycle hooks. */
|
|
3
2
|
export type MonitorEvent = {
|
|
4
3
|
type: 'broadcast';
|
|
@@ -11,7 +10,7 @@ export type MonitorEvent = {
|
|
|
11
10
|
blockHash: string;
|
|
12
11
|
} | {
|
|
13
12
|
type: 'sync:progress';
|
|
14
|
-
stage:
|
|
13
|
+
stage: string;
|
|
15
14
|
message: string;
|
|
16
15
|
} | {
|
|
17
16
|
type: 'sync:backup';
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GACrB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACnD;IACA,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAChB,GACD;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACtD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1sat/wallet-browser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "Browser wallet factory for 1Sat Ordinals SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"keywords": ["1sat", "bsv", "ordinals", "wallet", "browser"],
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@1sat/wallet": "0.0.
|
|
23
|
+
"@1sat/wallet": "0.0.32"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@1sat/client": "0.0.
|
|
27
|
-
"@bsv/sdk": "^2.0.
|
|
28
|
-
"@bsv/wallet-toolbox": "^2.
|
|
26
|
+
"@1sat/client": "0.0.17",
|
|
27
|
+
"@bsv/sdk": "^2.0.6",
|
|
28
|
+
"@bsv/wallet-toolbox": "^2.1.8"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@bsv/sdk": "^2.0.
|
|
32
|
-
"@bsv/wallet-toolbox": "^2.
|
|
31
|
+
"@bsv/sdk": "^2.0.6",
|
|
32
|
+
"@bsv/wallet-toolbox": "^2.1.8",
|
|
33
33
|
"typescript": "^5.9.3"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/dist/fullSync.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
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/out/src/index.client.js';
|
|
8
|
-
import type { sdk as mobileToolboxSdk } from '@bsv/wallet-toolbox/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
|
package/dist/fullSync.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fullSync.d.ts","sourceRoot":"","sources":["../src/fullSync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAA;AACvF,OAAO,KAAK,EAAE,GAAG,IAAI,gBAAgB,EAAE,MAAM,6CAA6C,CAAA;AAI1F,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
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
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/out/src/storage/schema/entities/EntityBase.js';
|
|
8
|
-
import { EntitySyncState } from '@bsv/wallet-toolbox/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
|
package/dist/fullSync.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fullSync.js","sourceRoot":"","sources":["../src/fullSync.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,mEAAmE,CAAA;AACjG,OAAO,EAAE,eAAe,EAAE,MAAM,wEAAwE,CAAA;AA0BxG;;;;;;;;;;;;;;;;;;;;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,G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