@1sat/wallet 0.0.3 → 0.0.4
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/OneSatWallet.d.ts +222 -0
- package/dist/OneSatWallet.d.ts.map +1 -0
- package/dist/OneSatWallet.js +754 -0
- package/dist/OneSatWallet.js.map +1 -0
- package/dist/address-sync/AddressManager.d.ts +86 -0
- package/dist/address-sync/AddressManager.d.ts.map +1 -0
- package/dist/address-sync/AddressManager.js +108 -0
- package/dist/address-sync/AddressManager.js.map +1 -0
- package/dist/address-sync/AddressSyncManager.d.ts +204 -0
- package/dist/address-sync/AddressSyncManager.d.ts.map +1 -0
- package/dist/address-sync/AddressSyncManager.js +525 -0
- package/dist/address-sync/AddressSyncManager.js.map +1 -0
- package/dist/address-sync/AddressSyncQueueIdb.d.ts +31 -0
- package/dist/address-sync/AddressSyncQueueIdb.d.ts.map +1 -0
- package/dist/address-sync/AddressSyncQueueIdb.js +356 -0
- package/dist/address-sync/AddressSyncQueueIdb.js.map +1 -0
- package/dist/address-sync/AddressSyncQueueSqlite.d.ts +55 -0
- package/dist/address-sync/AddressSyncQueueSqlite.d.ts.map +1 -0
- package/dist/address-sync/AddressSyncQueueSqlite.js +198 -0
- package/dist/address-sync/AddressSyncQueueSqlite.js.map +1 -0
- package/dist/address-sync/index.d.ts +8 -0
- package/dist/address-sync/index.d.ts.map +1 -0
- package/dist/address-sync/index.js +5 -0
- package/dist/address-sync/index.js.map +1 -0
- package/dist/backup/FileBackupProvider.d.ts +97 -0
- package/dist/backup/FileBackupProvider.d.ts.map +1 -0
- package/dist/backup/FileBackupProvider.js +185 -0
- package/dist/backup/FileBackupProvider.js.map +1 -0
- package/dist/backup/FileRestoreReader.d.ts +59 -0
- package/dist/backup/FileRestoreReader.d.ts.map +1 -0
- package/dist/backup/FileRestoreReader.js +89 -0
- package/dist/backup/FileRestoreReader.js.map +1 -0
- package/dist/backup/index.d.ts +6 -0
- package/dist/backup/index.d.ts.map +1 -0
- package/dist/backup/index.js +5 -0
- package/dist/backup/index.js.map +1 -0
- package/dist/backup/types.d.ts +32 -0
- package/dist/backup/types.d.ts.map +1 -0
- package/dist/backup/types.js +2 -0
- package/dist/backup/types.js.map +1 -0
- package/dist/browser.d.ts +6 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +6 -0
- package/dist/browser.js.map +1 -0
- package/dist/cwi/chrome.d.ts +12 -0
- package/dist/cwi/chrome.d.ts.map +1 -0
- package/dist/cwi/chrome.js +44 -0
- package/dist/cwi/chrome.js.map +1 -0
- package/dist/cwi/event.d.ts +12 -0
- package/dist/cwi/event.d.ts.map +1 -0
- package/dist/cwi/event.js +39 -0
- package/dist/cwi/event.js.map +1 -0
- package/dist/cwi/factory.d.ts +15 -0
- package/dist/cwi/factory.d.ts.map +1 -0
- package/dist/cwi/factory.js +45 -0
- package/dist/cwi/factory.js.map +1 -0
- package/dist/cwi/index.d.ts +12 -0
- package/dist/cwi/index.d.ts.map +1 -0
- package/dist/cwi/index.js +12 -0
- package/dist/cwi/index.js.map +1 -0
- package/dist/cwi/types.d.ts +40 -0
- package/dist/cwi/types.d.ts.map +1 -0
- package/dist/cwi/types.js +40 -0
- package/dist/cwi/types.js.map +1 -0
- package/dist/factory/createWebWallet.d.ts +73 -0
- package/dist/factory/createWebWallet.d.ts.map +1 -0
- package/dist/factory/createWebWallet.js +251 -0
- package/dist/factory/createWebWallet.js.map +1 -0
- package/dist/factory/fullSync.d.ts +58 -0
- package/dist/factory/fullSync.d.ts.map +1 -0
- package/dist/factory/fullSync.js +92 -0
- package/dist/factory/fullSync.js.map +1 -0
- package/dist/factory/index.d.ts +5 -0
- package/dist/factory/index.d.ts.map +1 -0
- package/dist/factory/index.js +3 -0
- package/dist/factory/index.js.map +1 -0
- package/dist/index.d.ts +18 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -21
- package/dist/index.js.map +1 -1
- package/dist/indexers/Bsv21Indexer.d.ts +36 -0
- package/dist/indexers/Bsv21Indexer.d.ts.map +1 -0
- package/dist/indexers/Bsv21Indexer.js +232 -0
- package/dist/indexers/Bsv21Indexer.js.map +1 -0
- package/dist/indexers/CosignIndexer.d.ts +14 -0
- package/dist/indexers/CosignIndexer.d.ts.map +1 -0
- package/dist/indexers/CosignIndexer.js +27 -0
- package/dist/indexers/CosignIndexer.js.map +1 -0
- package/dist/indexers/FundIndexer.d.ts +20 -0
- package/dist/indexers/FundIndexer.d.ts.map +1 -0
- package/dist/indexers/FundIndexer.js +65 -0
- package/dist/indexers/FundIndexer.js.map +1 -0
- package/dist/indexers/InscriptionIndexer.d.ts +33 -0
- package/dist/indexers/InscriptionIndexer.d.ts.map +1 -0
- package/dist/indexers/InscriptionIndexer.js +116 -0
- package/dist/indexers/InscriptionIndexer.js.map +1 -0
- package/dist/indexers/LockIndexer.d.ts +11 -0
- package/dist/indexers/LockIndexer.d.ts.map +1 -0
- package/dist/indexers/LockIndexer.js +44 -0
- package/dist/indexers/LockIndexer.js.map +1 -0
- package/dist/indexers/MapIndexer.d.ts +14 -0
- package/dist/indexers/MapIndexer.d.ts.map +1 -0
- package/dist/indexers/MapIndexer.js +65 -0
- package/dist/indexers/MapIndexer.js.map +1 -0
- package/dist/indexers/OpNSIndexer.d.ts +10 -0
- package/dist/indexers/OpNSIndexer.d.ts.map +1 -0
- package/dist/indexers/OpNSIndexer.js +39 -0
- package/dist/indexers/OpNSIndexer.js.map +1 -0
- package/dist/indexers/OrdLockIndexer.d.ts +18 -0
- package/dist/indexers/OrdLockIndexer.d.ts.map +1 -0
- package/dist/indexers/OrdLockIndexer.js +65 -0
- package/dist/indexers/OrdLockIndexer.js.map +1 -0
- package/dist/indexers/OriginIndexer.d.ts +38 -0
- package/dist/indexers/OriginIndexer.d.ts.map +1 -0
- package/dist/indexers/OriginIndexer.js +241 -0
- package/dist/indexers/OriginIndexer.js.map +1 -0
- package/dist/indexers/Outpoint.d.ts +11 -0
- package/dist/indexers/Outpoint.d.ts.map +1 -0
- package/dist/indexers/Outpoint.js +62 -0
- package/dist/indexers/Outpoint.js.map +1 -0
- package/dist/indexers/SigmaIndexer.d.ts +29 -0
- package/dist/indexers/SigmaIndexer.d.ts.map +1 -0
- package/dist/indexers/SigmaIndexer.js +134 -0
- package/dist/indexers/SigmaIndexer.js.map +1 -0
- package/dist/indexers/index.d.ts +14 -0
- package/dist/indexers/index.d.ts.map +1 -0
- package/dist/indexers/index.js +14 -0
- package/dist/indexers/index.js.map +1 -0
- package/dist/indexers/parseAddress.d.ts +10 -0
- package/dist/indexers/parseAddress.d.ts.map +1 -0
- package/dist/indexers/parseAddress.js +25 -0
- package/dist/indexers/parseAddress.js.map +1 -0
- package/dist/node.d.ts +6 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +6 -0
- package/dist/node.js.map +1 -0
- package/dist/signers/ReadOnlySigner.d.ts +16 -0
- package/dist/signers/ReadOnlySigner.d.ts.map +1 -0
- package/dist/signers/ReadOnlySigner.js +48 -0
- package/dist/signers/ReadOnlySigner.js.map +1 -0
- package/package.json +21 -8
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CWI Event Transport - For browser pages
|
|
3
|
+
* Uses CustomEvent pattern, forwarded by content script to service worker
|
|
4
|
+
*/
|
|
5
|
+
import { createCWI } from './factory';
|
|
6
|
+
// Event name for requests (listened by content script)
|
|
7
|
+
const YOURS_REQUEST = 'YoursRequest';
|
|
8
|
+
/**
|
|
9
|
+
* CustomEvent-based transport for browser page context.
|
|
10
|
+
* Content script listens for these events and forwards to service worker.
|
|
11
|
+
*/
|
|
12
|
+
const eventTransport = (action, params) => {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const messageId = `${action}-${Date.now()}-${Math.random()}`;
|
|
15
|
+
const requestEvent = new CustomEvent(YOURS_REQUEST, {
|
|
16
|
+
detail: { messageId, type: action, params },
|
|
17
|
+
});
|
|
18
|
+
function onResponse(e) {
|
|
19
|
+
const responseEvent = e;
|
|
20
|
+
const { detail } = responseEvent;
|
|
21
|
+
if (detail.success) {
|
|
22
|
+
resolve(detail.data);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
reject(new Error(detail.error || 'Unknown error'));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
self.addEventListener(messageId, onResponse, { once: true });
|
|
29
|
+
self.dispatchEvent(requestEvent);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Create a CWI for browser page context.
|
|
34
|
+
* Uses CustomEvent pattern - requires content script to forward to service worker.
|
|
35
|
+
*/
|
|
36
|
+
export const createEventCWI = () => createCWI(eventTransport);
|
|
37
|
+
// Default instance for convenience
|
|
38
|
+
export const CWI = createEventCWI();
|
|
39
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/cwi/event.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAqB,SAAS,EAAE,MAAM,WAAW,CAAA;AAGxD,uDAAuD;AACvD,MAAM,aAAa,GAAG,cAAc,CAAA;AAEpC;;;GAGG;AACH,MAAM,cAAc,GAAiB,CACpC,MAAoB,EACpB,MAAe,EACI,EAAE;IACrB,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC/C,MAAM,SAAS,GAAG,GAAG,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAA;QAC5D,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE;YACnD,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE;SAC3C,CAAC,CAAA;QAEF,SAAS,UAAU,CAAC,CAAQ;YAC3B,MAAM,aAAa,GAAG,CAIpB,CAAA;YACF,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAA;YAChC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO,CAAC,MAAM,CAAC,IAAe,CAAC,CAAA;YAChC,CAAC;iBAAM,CAAC;gBACP,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,eAAe,CAAC,CAAC,CAAA;YACnD,CAAC;QACF,CAAC;QAED,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;QAC5D,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;AACH,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAoB,EAAE,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;AAE9E,mCAAmC;AACnC,MAAM,CAAC,MAAM,GAAG,GAAG,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CWI Factory - Creates WalletInterface implementations with pluggable transport
|
|
3
|
+
*/
|
|
4
|
+
import type { WalletInterface } from '@bsv/sdk';
|
|
5
|
+
import { CWIEventName } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Transport function signature - sends a message and returns response
|
|
8
|
+
*/
|
|
9
|
+
export type CWITransport = <TResult>(action: CWIEventName, params: unknown) => Promise<TResult>;
|
|
10
|
+
/**
|
|
11
|
+
* Create a WalletInterface implementation using the provided transport.
|
|
12
|
+
* The transport handles the actual message passing (CustomEvent, chrome.runtime, etc.)
|
|
13
|
+
*/
|
|
14
|
+
export declare const createCWI: (transport: CWITransport) => WalletInterface;
|
|
15
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/cwi/factory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAClC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,OAAO,KACX,OAAO,CAAC,OAAO,CAAC,CAAA;AAErB;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,WAAW,YAAY,KAAG,eAgDlD,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CWI Factory - Creates WalletInterface implementations with pluggable transport
|
|
3
|
+
*/
|
|
4
|
+
import { CWIEventName } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Create a WalletInterface implementation using the provided transport.
|
|
7
|
+
* The transport handles the actual message passing (CustomEvent, chrome.runtime, etc.)
|
|
8
|
+
*/
|
|
9
|
+
export const createCWI = (transport) => ({
|
|
10
|
+
// Output Management
|
|
11
|
+
listOutputs: (args) => transport(CWIEventName.LIST_OUTPUTS, args),
|
|
12
|
+
relinquishOutput: (args) => transport(CWIEventName.RELINQUISH_OUTPUT, args),
|
|
13
|
+
// Action Management
|
|
14
|
+
createAction: (args) => transport(CWIEventName.CREATE_ACTION, args),
|
|
15
|
+
signAction: (args) => transport(CWIEventName.SIGN_ACTION, args),
|
|
16
|
+
abortAction: (args) => transport(CWIEventName.ABORT_ACTION, args),
|
|
17
|
+
listActions: (args) => transport(CWIEventName.LIST_ACTIONS, args),
|
|
18
|
+
internalizeAction: (args) => transport(CWIEventName.INTERNALIZE_ACTION, args),
|
|
19
|
+
// Key Operations
|
|
20
|
+
getPublicKey: (args) => transport(CWIEventName.GET_PUBLIC_KEY, args),
|
|
21
|
+
revealCounterpartyKeyLinkage: (args) => transport(CWIEventName.REVEAL_COUNTERPARTY_KEY_LINKAGE, args),
|
|
22
|
+
revealSpecificKeyLinkage: (args) => transport(CWIEventName.REVEAL_SPECIFIC_KEY_LINKAGE, args),
|
|
23
|
+
// Cryptographic Operations
|
|
24
|
+
encrypt: (args) => transport(CWIEventName.ENCRYPT, args),
|
|
25
|
+
decrypt: (args) => transport(CWIEventName.DECRYPT, args),
|
|
26
|
+
createHmac: (args) => transport(CWIEventName.CREATE_HMAC, args),
|
|
27
|
+
verifyHmac: (args) => transport(CWIEventName.VERIFY_HMAC, args),
|
|
28
|
+
createSignature: (args) => transport(CWIEventName.CREATE_SIGNATURE, args),
|
|
29
|
+
verifySignature: (args) => transport(CWIEventName.VERIFY_SIGNATURE, args),
|
|
30
|
+
// Certificate Operations
|
|
31
|
+
acquireCertificate: (args) => transport(CWIEventName.ACQUIRE_CERTIFICATE, args),
|
|
32
|
+
listCertificates: (args) => transport(CWIEventName.LIST_CERTIFICATES, args),
|
|
33
|
+
proveCertificate: (args) => transport(CWIEventName.PROVE_CERTIFICATE, args),
|
|
34
|
+
relinquishCertificate: (args) => transport(CWIEventName.RELINQUISH_CERTIFICATE, args),
|
|
35
|
+
discoverByIdentityKey: (args) => transport(CWIEventName.DISCOVER_BY_IDENTITY_KEY, args),
|
|
36
|
+
discoverByAttributes: (args) => transport(CWIEventName.DISCOVER_BY_ATTRIBUTES, args),
|
|
37
|
+
// Status & Info
|
|
38
|
+
isAuthenticated: (args) => transport(CWIEventName.IS_AUTHENTICATED, args),
|
|
39
|
+
waitForAuthentication: (args) => transport(CWIEventName.WAIT_FOR_AUTHENTICATION, args),
|
|
40
|
+
getHeight: (args) => transport(CWIEventName.GET_HEIGHT, args),
|
|
41
|
+
getHeaderForHeight: (args) => transport(CWIEventName.GET_HEADER_FOR_HEIGHT, args),
|
|
42
|
+
getNetwork: (args) => transport(CWIEventName.GET_NETWORK, args),
|
|
43
|
+
getVersion: (args) => transport(CWIEventName.GET_VERSION, args),
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/cwi/factory.ts"],"names":[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EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,gBAAgB,EAAE,IAAI,CAAC;IACzE,qBAAqB,EAAE,CAAC,IAAI,EAAE,EAAE,CAC/B,SAAS,CAAC,YAAY,CAAC,uBAAuB,EAAE,IAAI,CAAC;IACtD,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC;IAC7D,kBAAkB,EAAE,CAAC,IAAI,EAAE,EAAE,CAC5B,SAAS,CAAC,YAAY,CAAC,qBAAqB,EAAE,IAAI,CAAC;IACpD,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC;IAC/D,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC;CAC/D,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CWI (Compute With Integrity) - BRC-100 WalletInterface implementations
|
|
3
|
+
*
|
|
4
|
+
* Two implementations for different contexts:
|
|
5
|
+
* - event.ts: For browser pages (uses CustomEvent, forwarded by content script)
|
|
6
|
+
* - chrome.ts: For extension popup/options (uses chrome.runtime.sendMessage directly)
|
|
7
|
+
*/
|
|
8
|
+
export { CWIEventName, type CWIResponseDetail } from './types';
|
|
9
|
+
export { createCWI, type CWITransport } from './factory';
|
|
10
|
+
export { createEventCWI, CWI as EventCWI } from './event';
|
|
11
|
+
export { createChromeCWI, ChromeCWI } from './chrome';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cwi/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CWI (Compute With Integrity) - BRC-100 WalletInterface implementations
|
|
3
|
+
*
|
|
4
|
+
* Two implementations for different contexts:
|
|
5
|
+
* - event.ts: For browser pages (uses CustomEvent, forwarded by content script)
|
|
6
|
+
* - chrome.ts: For extension popup/options (uses chrome.runtime.sendMessage directly)
|
|
7
|
+
*/
|
|
8
|
+
export { CWIEventName } from './types';
|
|
9
|
+
export { createCWI } from './factory';
|
|
10
|
+
export { createEventCWI, CWI as EventCWI } from './event';
|
|
11
|
+
export { createChromeCWI, ChromeCWI } from './chrome';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cwi/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAA0B,MAAM,SAAS,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAqB,MAAM,WAAW,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CWI (Compute With Integrity) - Shared types for BRC-100 WalletInterface implementations
|
|
3
|
+
*/
|
|
4
|
+
export declare enum CWIEventName {
|
|
5
|
+
LIST_OUTPUTS = "cwi_listOutputs",
|
|
6
|
+
LIST_ACTIONS = "cwi_listActions",
|
|
7
|
+
GET_PUBLIC_KEY = "cwi_getPublicKey",
|
|
8
|
+
GET_HEIGHT = "cwi_getHeight",
|
|
9
|
+
GET_HEADER_FOR_HEIGHT = "cwi_getHeaderForHeight",
|
|
10
|
+
GET_NETWORK = "cwi_getNetwork",
|
|
11
|
+
GET_VERSION = "cwi_getVersion",
|
|
12
|
+
IS_AUTHENTICATED = "cwi_isAuthenticated",
|
|
13
|
+
WAIT_FOR_AUTHENTICATION = "cwi_waitForAuthentication",
|
|
14
|
+
CREATE_ACTION = "cwi_createAction",
|
|
15
|
+
SIGN_ACTION = "cwi_signAction",
|
|
16
|
+
ABORT_ACTION = "cwi_abortAction",
|
|
17
|
+
INTERNALIZE_ACTION = "cwi_internalizeAction",
|
|
18
|
+
CREATE_SIGNATURE = "cwi_createSignature",
|
|
19
|
+
VERIFY_SIGNATURE = "cwi_verifySignature",
|
|
20
|
+
ENCRYPT = "cwi_encrypt",
|
|
21
|
+
DECRYPT = "cwi_decrypt",
|
|
22
|
+
CREATE_HMAC = "cwi_createHmac",
|
|
23
|
+
VERIFY_HMAC = "cwi_verifyHmac",
|
|
24
|
+
RELINQUISH_OUTPUT = "cwi_relinquishOutput",
|
|
25
|
+
ACQUIRE_CERTIFICATE = "cwi_acquireCertificate",
|
|
26
|
+
LIST_CERTIFICATES = "cwi_listCertificates",
|
|
27
|
+
PROVE_CERTIFICATE = "cwi_proveCertificate",
|
|
28
|
+
RELINQUISH_CERTIFICATE = "cwi_relinquishCertificate",
|
|
29
|
+
DISCOVER_BY_IDENTITY_KEY = "cwi_discoverByIdentityKey",
|
|
30
|
+
DISCOVER_BY_ATTRIBUTES = "cwi_discoverByAttributes",
|
|
31
|
+
REVEAL_COUNTERPARTY_KEY_LINKAGE = "cwi_revealCounterpartyKeyLinkage",
|
|
32
|
+
REVEAL_SPECIFIC_KEY_LINKAGE = "cwi_revealSpecificKeyLinkage"
|
|
33
|
+
}
|
|
34
|
+
export interface CWIResponseDetail<T = unknown> {
|
|
35
|
+
type: CWIEventName;
|
|
36
|
+
success: boolean;
|
|
37
|
+
data?: T;
|
|
38
|
+
error?: string;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cwi/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,oBAAY,YAAY;IAEvB,YAAY,oBAAoB;IAChC,YAAY,oBAAoB;IAChC,cAAc,qBAAqB;IACnC,UAAU,kBAAkB;IAC5B,qBAAqB,2BAA2B;IAChD,WAAW,mBAAmB;IAC9B,WAAW,mBAAmB;IAC9B,gBAAgB,wBAAwB;IACxC,uBAAuB,8BAA8B;IAGrD,aAAa,qBAAqB;IAClC,WAAW,mBAAmB;IAC9B,YAAY,oBAAoB;IAChC,kBAAkB,0BAA0B;IAC5C,gBAAgB,wBAAwB;IACxC,gBAAgB,wBAAwB;IACxC,OAAO,gBAAgB;IACvB,OAAO,gBAAgB;IACvB,WAAW,mBAAmB;IAC9B,WAAW,mBAAmB;IAC9B,iBAAiB,yBAAyB;IAG1C,mBAAmB,2BAA2B;IAC9C,iBAAiB,yBAAyB;IAC1C,iBAAiB,yBAAyB;IAC1C,sBAAsB,8BAA8B;IACpD,wBAAwB,8BAA8B;IACtD,sBAAsB,6BAA6B;IAGnD,+BAA+B,qCAAqC;IACpE,2BAA2B,iCAAiC;CAC5D;AAGD,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,OAAO;IAC7C,IAAI,EAAE,YAAY,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,CAAC,CAAA;IACR,KAAK,CAAC,EAAE,MAAM,CAAA;CACd"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CWI (Compute With Integrity) - Shared types for BRC-100 WalletInterface implementations
|
|
3
|
+
*/
|
|
4
|
+
// BRC-100 Event Names - shared between all CWI implementations
|
|
5
|
+
export var CWIEventName;
|
|
6
|
+
(function (CWIEventName) {
|
|
7
|
+
// Read-only operations
|
|
8
|
+
CWIEventName["LIST_OUTPUTS"] = "cwi_listOutputs";
|
|
9
|
+
CWIEventName["LIST_ACTIONS"] = "cwi_listActions";
|
|
10
|
+
CWIEventName["GET_PUBLIC_KEY"] = "cwi_getPublicKey";
|
|
11
|
+
CWIEventName["GET_HEIGHT"] = "cwi_getHeight";
|
|
12
|
+
CWIEventName["GET_HEADER_FOR_HEIGHT"] = "cwi_getHeaderForHeight";
|
|
13
|
+
CWIEventName["GET_NETWORK"] = "cwi_getNetwork";
|
|
14
|
+
CWIEventName["GET_VERSION"] = "cwi_getVersion";
|
|
15
|
+
CWIEventName["IS_AUTHENTICATED"] = "cwi_isAuthenticated";
|
|
16
|
+
CWIEventName["WAIT_FOR_AUTHENTICATION"] = "cwi_waitForAuthentication";
|
|
17
|
+
// Signing operations (require password)
|
|
18
|
+
CWIEventName["CREATE_ACTION"] = "cwi_createAction";
|
|
19
|
+
CWIEventName["SIGN_ACTION"] = "cwi_signAction";
|
|
20
|
+
CWIEventName["ABORT_ACTION"] = "cwi_abortAction";
|
|
21
|
+
CWIEventName["INTERNALIZE_ACTION"] = "cwi_internalizeAction";
|
|
22
|
+
CWIEventName["CREATE_SIGNATURE"] = "cwi_createSignature";
|
|
23
|
+
CWIEventName["VERIFY_SIGNATURE"] = "cwi_verifySignature";
|
|
24
|
+
CWIEventName["ENCRYPT"] = "cwi_encrypt";
|
|
25
|
+
CWIEventName["DECRYPT"] = "cwi_decrypt";
|
|
26
|
+
CWIEventName["CREATE_HMAC"] = "cwi_createHmac";
|
|
27
|
+
CWIEventName["VERIFY_HMAC"] = "cwi_verifyHmac";
|
|
28
|
+
CWIEventName["RELINQUISH_OUTPUT"] = "cwi_relinquishOutput";
|
|
29
|
+
// Certificate operations
|
|
30
|
+
CWIEventName["ACQUIRE_CERTIFICATE"] = "cwi_acquireCertificate";
|
|
31
|
+
CWIEventName["LIST_CERTIFICATES"] = "cwi_listCertificates";
|
|
32
|
+
CWIEventName["PROVE_CERTIFICATE"] = "cwi_proveCertificate";
|
|
33
|
+
CWIEventName["RELINQUISH_CERTIFICATE"] = "cwi_relinquishCertificate";
|
|
34
|
+
CWIEventName["DISCOVER_BY_IDENTITY_KEY"] = "cwi_discoverByIdentityKey";
|
|
35
|
+
CWIEventName["DISCOVER_BY_ATTRIBUTES"] = "cwi_discoverByAttributes";
|
|
36
|
+
// Key linkage
|
|
37
|
+
CWIEventName["REVEAL_COUNTERPARTY_KEY_LINKAGE"] = "cwi_revealCounterpartyKeyLinkage";
|
|
38
|
+
CWIEventName["REVEAL_SPECIFIC_KEY_LINKAGE"] = "cwi_revealSpecificKeyLinkage";
|
|
39
|
+
})(CWIEventName || (CWIEventName = {}));
|
|
40
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/cwi/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,+DAA+D;AAC/D,MAAM,CAAN,IAAY,YAoCX;AApCD,WAAY,YAAY;IACvB,uBAAuB;IACvB,gDAAgC,CAAA;IAChC,gDAAgC,CAAA;IAChC,mDAAmC,CAAA;IACnC,4CAA4B,CAAA;IAC5B,gEAAgD,CAAA;IAChD,8CAA8B,CAAA;IAC9B,8CAA8B,CAAA;IAC9B,wDAAwC,CAAA;IACxC,qEAAqD,CAAA;IAErD,wCAAwC;IACxC,kDAAkC,CAAA;IAClC,8CAA8B,CAAA;IAC9B,gDAAgC,CAAA;IAChC,4DAA4C,CAAA;IAC5C,wDAAwC,CAAA;IACxC,wDAAwC,CAAA;IACxC,uCAAuB,CAAA;IACvB,uCAAuB,CAAA;IACvB,8CAA8B,CAAA;IAC9B,8CAA8B,CAAA;IAC9B,0DAA0C,CAAA;IAE1C,yBAAyB;IACzB,8DAA8C,CAAA;IAC9C,0DAA0C,CAAA;IAC1C,0DAA0C,CAAA;IAC1C,oEAAoD,CAAA;IACpD,sEAAsD,CAAA;IACtD,mEAAmD,CAAA;IAEnD,cAAc;IACd,oFAAoE,CAAA;IACpE,4EAA4D,CAAA;AAC7D,CAAC,EApCW,YAAY,KAAZ,YAAY,QAoCvB"}
|
|
@@ -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":"createW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AU,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/factory/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,QAAQ,CAAA;AAEtC,gDAAgD;AAChD,MAAM,8BAA8B,GAAG,IAAI,CAAA;AAE3C,+EAA+E;AAC/E,MAAM,iBAAiB,GAAG,EAAE,KAAK,EAAE,QAAiB,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;AA4ClE;;;GAGG;AACH,SAAS,eAAe,CAAC,KAA0B;IAClD,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAC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,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
|