@arkade-os/sdk 0.3.12 → 0.4.0-next.0
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/README.md +483 -54
- package/dist/cjs/adapters/expo-db.js +35 -0
- package/dist/cjs/asset/assetGroup.js +141 -0
- package/dist/cjs/asset/assetId.js +88 -0
- package/dist/cjs/asset/assetInput.js +204 -0
- package/dist/cjs/asset/assetOutput.js +159 -0
- package/dist/cjs/asset/assetRef.js +82 -0
- package/dist/cjs/asset/index.js +24 -0
- package/dist/cjs/asset/metadata.js +172 -0
- package/dist/cjs/asset/packet.js +164 -0
- package/dist/cjs/asset/types.js +25 -0
- package/dist/cjs/asset/utils.js +105 -0
- package/dist/cjs/contracts/arkcontract.js +148 -0
- package/dist/cjs/contracts/contractManager.js +436 -0
- package/dist/cjs/contracts/contractWatcher.js +567 -0
- package/dist/cjs/contracts/handlers/default.js +85 -0
- package/dist/cjs/contracts/handlers/delegate.js +89 -0
- package/dist/cjs/contracts/handlers/helpers.js +105 -0
- package/dist/cjs/contracts/handlers/index.js +19 -0
- package/dist/cjs/contracts/handlers/registry.js +89 -0
- package/dist/cjs/contracts/handlers/vhtlc.js +193 -0
- package/dist/cjs/contracts/index.js +41 -0
- package/dist/cjs/contracts/types.js +2 -0
- package/dist/cjs/db/manager.js +97 -0
- package/dist/cjs/forfeit.js +12 -8
- package/dist/cjs/identity/index.js +1 -0
- package/dist/cjs/identity/seedIdentity.js +255 -0
- package/dist/cjs/index.js +70 -14
- package/dist/cjs/intent/index.js +28 -2
- package/dist/cjs/providers/ark.js +7 -0
- package/dist/cjs/providers/delegator.js +66 -0
- package/dist/cjs/providers/expoIndexer.js +5 -0
- package/dist/cjs/providers/indexer.js +68 -1
- package/dist/cjs/providers/onchain.js +2 -2
- package/dist/cjs/providers/utils.js +1 -0
- package/dist/cjs/repositories/contractRepository.js +0 -103
- package/dist/cjs/repositories/inMemory/contractRepository.js +55 -0
- package/dist/cjs/repositories/inMemory/walletRepository.js +80 -0
- package/dist/cjs/repositories/index.js +16 -0
- package/dist/cjs/repositories/indexedDB/contractRepository.js +187 -0
- package/dist/cjs/repositories/indexedDB/db.js +57 -0
- package/dist/cjs/repositories/indexedDB/schema.js +159 -0
- package/dist/cjs/repositories/indexedDB/walletRepository.js +338 -0
- package/dist/cjs/repositories/indexedDB/websqlAdapter.js +144 -0
- package/dist/cjs/repositories/migrations/contractRepositoryImpl.js +127 -0
- package/dist/cjs/repositories/migrations/fromStorageAdapter.js +66 -0
- package/dist/cjs/repositories/migrations/walletRepositoryImpl.js +180 -0
- package/dist/cjs/repositories/walletRepository.js +0 -169
- package/dist/cjs/script/base.js +54 -0
- package/dist/cjs/script/delegate.js +49 -0
- package/dist/cjs/storage/asyncStorage.js +4 -1
- package/dist/cjs/storage/fileSystem.js +3 -0
- package/dist/cjs/storage/inMemory.js +3 -0
- package/dist/cjs/storage/indexedDB.js +5 -1
- package/dist/cjs/storage/localStorage.js +3 -0
- package/dist/cjs/utils/arkTransaction.js +16 -0
- package/dist/cjs/utils/transactionHistory.js +50 -0
- package/dist/cjs/utils/txSizeEstimator.js +39 -14
- package/dist/cjs/wallet/asset-manager.js +338 -0
- package/dist/cjs/wallet/asset.js +117 -0
- package/dist/cjs/wallet/batch.js +1 -1
- package/dist/cjs/wallet/delegator.js +235 -0
- package/dist/cjs/wallet/expo/background.js +133 -0
- package/dist/cjs/wallet/expo/index.js +9 -0
- package/dist/cjs/wallet/expo/wallet.js +231 -0
- package/dist/cjs/wallet/onchain.js +57 -12
- package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +568 -0
- package/dist/cjs/wallet/serviceWorker/wallet.js +383 -102
- package/dist/cjs/wallet/unroll.js +7 -2
- package/dist/cjs/wallet/utils.js +60 -0
- package/dist/cjs/wallet/validation.js +151 -0
- package/dist/cjs/wallet/vtxo-manager.js +1 -1
- package/dist/cjs/wallet/wallet.js +702 -260
- package/dist/cjs/worker/browser/service-worker-manager.js +82 -0
- package/dist/cjs/{wallet/serviceWorker → worker/browser}/utils.js +2 -1
- package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +78 -0
- package/dist/cjs/worker/expo/index.js +12 -0
- package/dist/cjs/worker/expo/processors/contractPollProcessor.js +61 -0
- package/dist/cjs/worker/expo/processors/index.js +6 -0
- package/dist/cjs/worker/expo/taskQueue.js +41 -0
- package/dist/cjs/worker/expo/taskRunner.js +57 -0
- package/dist/cjs/worker/messageBus.js +252 -0
- package/dist/esm/adapters/expo-db.js +27 -0
- package/dist/esm/asset/assetGroup.js +137 -0
- package/dist/esm/asset/assetId.js +84 -0
- package/dist/esm/asset/assetInput.js +199 -0
- package/dist/esm/asset/assetOutput.js +154 -0
- package/dist/esm/asset/assetRef.js +78 -0
- package/dist/esm/asset/index.js +8 -0
- package/dist/esm/asset/metadata.js +167 -0
- package/dist/esm/asset/packet.js +159 -0
- package/dist/esm/asset/types.js +22 -0
- package/dist/esm/asset/utils.js +99 -0
- package/dist/esm/contracts/arkcontract.js +141 -0
- package/dist/esm/contracts/contractManager.js +432 -0
- package/dist/esm/contracts/contractWatcher.js +563 -0
- package/dist/esm/contracts/handlers/default.js +82 -0
- package/dist/esm/contracts/handlers/delegate.js +86 -0
- package/dist/esm/contracts/handlers/helpers.js +66 -0
- package/dist/esm/contracts/handlers/index.js +12 -0
- package/dist/esm/contracts/handlers/registry.js +86 -0
- package/dist/esm/contracts/handlers/vhtlc.js +190 -0
- package/dist/esm/contracts/index.js +13 -0
- package/dist/esm/contracts/types.js +1 -0
- package/dist/esm/db/manager.js +92 -0
- package/dist/esm/forfeit.js +11 -8
- package/dist/esm/identity/index.js +1 -0
- package/dist/esm/identity/seedIdentity.js +249 -0
- package/dist/esm/index.js +25 -15
- package/dist/esm/intent/index.js +28 -2
- package/dist/esm/providers/ark.js +7 -0
- package/dist/esm/providers/delegator.js +62 -0
- package/dist/esm/providers/expoIndexer.js +5 -0
- package/dist/esm/providers/indexer.js +68 -1
- package/dist/esm/providers/onchain.js +2 -2
- package/dist/esm/providers/utils.js +1 -0
- package/dist/esm/repositories/contractRepository.js +1 -101
- package/dist/esm/repositories/inMemory/contractRepository.js +51 -0
- package/dist/esm/repositories/inMemory/walletRepository.js +76 -0
- package/dist/esm/repositories/index.js +8 -0
- package/dist/esm/repositories/indexedDB/contractRepository.js +183 -0
- package/dist/esm/repositories/indexedDB/db.js +42 -0
- package/dist/esm/repositories/indexedDB/schema.js +155 -0
- package/dist/esm/repositories/indexedDB/walletRepository.js +334 -0
- package/dist/esm/repositories/indexedDB/websqlAdapter.js +138 -0
- package/dist/esm/repositories/migrations/contractRepositoryImpl.js +121 -0
- package/dist/esm/repositories/migrations/fromStorageAdapter.js +58 -0
- package/dist/esm/repositories/migrations/walletRepositoryImpl.js +176 -0
- package/dist/esm/repositories/walletRepository.js +1 -167
- package/dist/esm/script/base.js +21 -1
- package/dist/esm/script/delegate.js +46 -0
- package/dist/esm/storage/asyncStorage.js +4 -1
- package/dist/esm/storage/fileSystem.js +3 -0
- package/dist/esm/storage/inMemory.js +3 -0
- package/dist/esm/storage/indexedDB.js +5 -1
- package/dist/esm/storage/localStorage.js +3 -0
- package/dist/esm/utils/arkTransaction.js +15 -0
- package/dist/esm/utils/transactionHistory.js +50 -0
- package/dist/esm/utils/txSizeEstimator.js +39 -14
- package/dist/esm/wallet/asset-manager.js +333 -0
- package/dist/esm/wallet/asset.js +111 -0
- package/dist/esm/wallet/batch.js +1 -1
- package/dist/esm/wallet/delegator.js +231 -0
- package/dist/esm/wallet/expo/background.js +128 -0
- package/dist/esm/wallet/expo/index.js +2 -0
- package/dist/esm/wallet/expo/wallet.js +194 -0
- package/dist/esm/wallet/onchain.js +57 -12
- package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +564 -0
- package/dist/esm/wallet/serviceWorker/wallet.js +382 -101
- package/dist/esm/wallet/unroll.js +7 -2
- package/dist/esm/wallet/utils.js +55 -0
- package/dist/esm/wallet/validation.js +139 -0
- package/dist/esm/wallet/vtxo-manager.js +1 -1
- package/dist/esm/wallet/wallet.js +704 -229
- package/dist/esm/worker/browser/service-worker-manager.js +76 -0
- package/dist/esm/{wallet/serviceWorker → worker/browser}/utils.js +2 -1
- package/dist/esm/worker/expo/asyncStorageTaskQueue.js +74 -0
- package/dist/esm/worker/expo/index.js +4 -0
- package/dist/esm/worker/expo/processors/contractPollProcessor.js +58 -0
- package/dist/esm/worker/expo/processors/index.js +1 -0
- package/dist/esm/worker/expo/taskQueue.js +37 -0
- package/dist/esm/worker/expo/taskRunner.js +54 -0
- package/dist/esm/worker/messageBus.js +248 -0
- package/dist/types/adapters/expo-db.d.ts +7 -0
- package/dist/types/asset/assetGroup.d.ts +28 -0
- package/dist/types/asset/assetId.d.ts +19 -0
- package/dist/types/asset/assetInput.d.ts +46 -0
- package/dist/types/asset/assetOutput.d.ts +39 -0
- package/dist/types/asset/assetRef.d.ts +25 -0
- package/dist/types/asset/index.d.ts +8 -0
- package/dist/types/asset/metadata.d.ts +37 -0
- package/dist/types/asset/packet.d.ts +27 -0
- package/dist/types/asset/types.d.ts +18 -0
- package/dist/types/asset/utils.d.ts +21 -0
- package/dist/types/contracts/arkcontract.d.ts +101 -0
- package/dist/types/contracts/contractManager.d.ts +331 -0
- package/dist/types/contracts/contractWatcher.d.ts +192 -0
- package/dist/types/contracts/handlers/default.d.ts +19 -0
- package/dist/types/contracts/handlers/delegate.d.ts +21 -0
- package/dist/types/contracts/handlers/helpers.d.ts +18 -0
- package/dist/types/contracts/handlers/index.d.ts +7 -0
- package/dist/types/contracts/handlers/registry.d.ts +65 -0
- package/dist/types/contracts/handlers/vhtlc.d.ts +32 -0
- package/dist/types/contracts/index.d.ts +14 -0
- package/dist/types/contracts/types.d.ts +222 -0
- package/dist/types/db/manager.d.ts +22 -0
- package/dist/types/forfeit.d.ts +2 -1
- package/dist/types/identity/index.d.ts +1 -0
- package/dist/types/identity/seedIdentity.d.ts +128 -0
- package/dist/types/index.d.ts +21 -12
- package/dist/types/intent/index.d.ts +2 -1
- package/dist/types/providers/ark.d.ts +11 -2
- package/dist/types/providers/delegator.d.ts +29 -0
- package/dist/types/providers/indexer.d.ts +11 -1
- package/dist/types/repositories/contractRepository.d.ts +30 -19
- package/dist/types/repositories/inMemory/contractRepository.d.ts +17 -0
- package/dist/types/repositories/inMemory/walletRepository.d.ts +26 -0
- package/dist/types/repositories/index.d.ts +7 -0
- package/dist/types/repositories/indexedDB/contractRepository.d.ts +21 -0
- package/dist/types/repositories/indexedDB/db.d.ts +56 -0
- package/dist/types/repositories/indexedDB/schema.d.ts +8 -0
- package/dist/types/repositories/indexedDB/walletRepository.d.ts +25 -0
- package/dist/types/repositories/indexedDB/websqlAdapter.d.ts +49 -0
- package/dist/types/repositories/migrations/contractRepositoryImpl.d.ts +24 -0
- package/dist/types/repositories/migrations/fromStorageAdapter.d.ts +19 -0
- package/dist/types/repositories/migrations/walletRepositoryImpl.d.ts +27 -0
- package/dist/types/repositories/walletRepository.d.ts +13 -24
- package/dist/types/script/base.d.ts +1 -0
- package/dist/types/script/delegate.d.ts +36 -0
- package/dist/types/storage/asyncStorage.d.ts +4 -0
- package/dist/types/storage/fileSystem.d.ts +3 -0
- package/dist/types/storage/inMemory.d.ts +3 -0
- package/dist/types/storage/index.d.ts +3 -0
- package/dist/types/storage/indexedDB.d.ts +3 -0
- package/dist/types/storage/localStorage.d.ts +3 -0
- package/dist/types/utils/arkTransaction.d.ts +6 -0
- package/dist/types/utils/txSizeEstimator.d.ts +12 -2
- package/dist/types/wallet/asset-manager.d.ts +78 -0
- package/dist/types/wallet/asset.d.ts +21 -0
- package/dist/types/wallet/batch.d.ts +1 -1
- package/dist/types/wallet/delegator.d.ts +24 -0
- package/dist/types/wallet/expo/background.d.ts +66 -0
- package/dist/types/wallet/expo/index.d.ts +4 -0
- package/dist/types/wallet/expo/wallet.d.ts +97 -0
- package/dist/types/wallet/index.d.ts +75 -2
- package/dist/types/wallet/onchain.d.ts +22 -1
- package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +366 -0
- package/dist/types/wallet/serviceWorker/wallet.d.ts +20 -11
- package/dist/types/wallet/utils.d.ts +13 -1
- package/dist/types/wallet/validation.d.ts +24 -0
- package/dist/types/wallet/wallet.d.ts +111 -17
- package/dist/types/worker/browser/service-worker-manager.d.ts +21 -0
- package/dist/types/{wallet/serviceWorker → worker/browser}/utils.d.ts +2 -1
- package/dist/types/worker/expo/asyncStorageTaskQueue.d.ts +46 -0
- package/dist/types/worker/expo/index.d.ts +7 -0
- package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +14 -0
- package/dist/types/worker/expo/processors/index.d.ts +1 -0
- package/dist/types/worker/expo/taskQueue.d.ts +50 -0
- package/dist/types/worker/expo/taskRunner.d.ts +42 -0
- package/dist/types/worker/messageBus.d.ts +109 -0
- package/package.json +71 -17
- package/dist/cjs/wallet/serviceWorker/request.js +0 -78
- package/dist/cjs/wallet/serviceWorker/response.js +0 -222
- package/dist/cjs/wallet/serviceWorker/worker.js +0 -655
- package/dist/esm/wallet/serviceWorker/request.js +0 -75
- package/dist/esm/wallet/serviceWorker/response.js +0 -219
- package/dist/esm/wallet/serviceWorker/worker.js +0 -651
- package/dist/types/wallet/serviceWorker/request.d.ts +0 -74
- package/dist/types/wallet/serviceWorker/response.d.ts +0 -123
- package/dist/types/wallet/serviceWorker/worker.d.ts +0 -53
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContractRepositoryImpl = exports.getCollectionStorageKey = exports.getContractStorageKey = void 0;
|
|
4
|
+
const getContractStorageKey = (id, key) => `contract:${id}:${key}`;
|
|
5
|
+
exports.getContractStorageKey = getContractStorageKey;
|
|
6
|
+
const getCollectionStorageKey = (type) => `collection:${type}`;
|
|
7
|
+
exports.getCollectionStorageKey = getCollectionStorageKey;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated This is only to be used in migration from storage V1
|
|
10
|
+
*/
|
|
11
|
+
class ContractRepositoryImpl {
|
|
12
|
+
constructor(storage) {
|
|
13
|
+
this.version = 1;
|
|
14
|
+
this.storage = storage;
|
|
15
|
+
}
|
|
16
|
+
async getContractData(contractId, key) {
|
|
17
|
+
const stored = await this.storage.getItem((0, exports.getContractStorageKey)(contractId, key));
|
|
18
|
+
if (!stored)
|
|
19
|
+
return null;
|
|
20
|
+
try {
|
|
21
|
+
const data = JSON.parse(stored);
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error(`Failed to parse contract data for ${contractId}:${key}:`, error);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async setContractData(contractId, key, data) {
|
|
30
|
+
try {
|
|
31
|
+
await this.storage.setItem((0, exports.getContractStorageKey)(contractId, key), JSON.stringify(data));
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error(`Failed to persist contract data for ${contractId}:${key}:`, error);
|
|
35
|
+
throw error; // Rethrow to notify caller of failure
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async deleteContractData(contractId, key) {
|
|
39
|
+
try {
|
|
40
|
+
await this.storage.removeItem((0, exports.getContractStorageKey)(contractId, key));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error(`Failed to remove contract data for ${contractId}:${key}:`, error);
|
|
44
|
+
throw error; // Rethrow to notify caller of failure
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async getContractCollection(contractType) {
|
|
48
|
+
const stored = await this.storage.getItem((0, exports.getCollectionStorageKey)(contractType));
|
|
49
|
+
if (!stored)
|
|
50
|
+
return [];
|
|
51
|
+
try {
|
|
52
|
+
const collection = JSON.parse(stored);
|
|
53
|
+
return collection;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error(`Failed to parse contract collection ${contractType}:`, error);
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async saveToContractCollection(contractType, item, idField) {
|
|
61
|
+
const collection = await this.getContractCollection(contractType);
|
|
62
|
+
// Validate that the item has the required id field
|
|
63
|
+
const itemId = item[idField];
|
|
64
|
+
if (itemId === undefined || itemId === null) {
|
|
65
|
+
throw new Error(`Item is missing required field '${String(idField)}'`);
|
|
66
|
+
}
|
|
67
|
+
// Find existing item index without mutating the original collection
|
|
68
|
+
const existingIndex = collection.findIndex((i) => i[idField] === itemId);
|
|
69
|
+
// Build new collection without mutating the cached one
|
|
70
|
+
let newCollection;
|
|
71
|
+
if (existingIndex !== -1) {
|
|
72
|
+
// Replace existing item
|
|
73
|
+
newCollection = [
|
|
74
|
+
...collection.slice(0, existingIndex),
|
|
75
|
+
item,
|
|
76
|
+
...collection.slice(existingIndex + 1),
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Add new item
|
|
81
|
+
newCollection = [...collection, item];
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
await this.storage.setItem((0, exports.getCollectionStorageKey)(contractType), JSON.stringify(newCollection));
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.error(`Failed to persist contract collection ${contractType}:`, error);
|
|
88
|
+
throw error; // Rethrow to notify caller of failure
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async removeFromContractCollection(contractType, id, idField) {
|
|
92
|
+
// Validate input parameters
|
|
93
|
+
if (id === undefined || id === null) {
|
|
94
|
+
throw new Error(`Invalid id provided for removal: ${String(id)}`);
|
|
95
|
+
}
|
|
96
|
+
const collection = await this.getContractCollection(contractType);
|
|
97
|
+
// Build new collection without the specified item
|
|
98
|
+
const filtered = collection.filter((item) => item[idField] !== id);
|
|
99
|
+
try {
|
|
100
|
+
await this.storage.setItem((0, exports.getCollectionStorageKey)(contractType), JSON.stringify(filtered));
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error(`Failed to persist contract collection removal for ${contractType}:`, error);
|
|
104
|
+
throw error; // Rethrow to notify caller of failure
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// The following methods are implemented for compatibility with the new ContractRepository interface
|
|
108
|
+
// but aren't used.
|
|
109
|
+
async getContracts(_) {
|
|
110
|
+
throw new TypeError("Method not implemented, this is a legacy class and should only be used for migrating data.");
|
|
111
|
+
}
|
|
112
|
+
async saveContract(_) {
|
|
113
|
+
throw new TypeError("Method not implemented, this is a legacy class and should only be used for migrating data.");
|
|
114
|
+
}
|
|
115
|
+
async deleteContract(_) {
|
|
116
|
+
throw new TypeError("Method not implemented, this is a legacy class and should only be used for migrating data.");
|
|
117
|
+
}
|
|
118
|
+
// used only for tests
|
|
119
|
+
async clear() {
|
|
120
|
+
await this.storage.clear();
|
|
121
|
+
}
|
|
122
|
+
async [Symbol.asyncDispose]() {
|
|
123
|
+
// deprecated StorageAdapter doesn't have a `close()` method
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.ContractRepositoryImpl = ContractRepositoryImpl;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MIGRATION_KEY = void 0;
|
|
4
|
+
exports.getMigrationStatus = getMigrationStatus;
|
|
5
|
+
exports.requiresMigration = requiresMigration;
|
|
6
|
+
exports.rollbackMigration = rollbackMigration;
|
|
7
|
+
exports.migrateWalletRepository = migrateWalletRepository;
|
|
8
|
+
const walletRepositoryImpl_1 = require("./walletRepositoryImpl");
|
|
9
|
+
const MIGRATION_KEY = (repoType) => `migration-from-storage-adapter-${repoType}`;
|
|
10
|
+
exports.MIGRATION_KEY = MIGRATION_KEY;
|
|
11
|
+
async function getMigrationStatus(repoType, storageAdapter) {
|
|
12
|
+
try {
|
|
13
|
+
const migration = await storageAdapter.getItem((0, exports.MIGRATION_KEY)(repoType));
|
|
14
|
+
if (migration === "done")
|
|
15
|
+
return "done";
|
|
16
|
+
if (migration === "in-progress")
|
|
17
|
+
return "in-progress";
|
|
18
|
+
return "pending";
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
if (e instanceof DOMException && e.name === "NotFoundError")
|
|
22
|
+
return "not-needed";
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function requiresMigration(repoType, storageAdapter) {
|
|
27
|
+
const status = await getMigrationStatus(repoType, storageAdapter);
|
|
28
|
+
return status === "pending" || status === "in-progress";
|
|
29
|
+
}
|
|
30
|
+
async function rollbackMigration(repoType, storageAdapter) {
|
|
31
|
+
await storageAdapter.removeItem((0, exports.MIGRATION_KEY)(repoType));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Migrate wallet data from the legacy storage adapter to the new one.
|
|
35
|
+
* It accepts both onchain and offchain addresses, make sure to pass both.
|
|
36
|
+
*
|
|
37
|
+
* @param storageAdapter
|
|
38
|
+
* @param fresh
|
|
39
|
+
* @param addresses
|
|
40
|
+
*/
|
|
41
|
+
async function migrateWalletRepository(storageAdapter, fresh, addresses) {
|
|
42
|
+
const migrate = await requiresMigration("wallet", storageAdapter);
|
|
43
|
+
if (!migrate)
|
|
44
|
+
return;
|
|
45
|
+
await storageAdapter.setItem((0, exports.MIGRATION_KEY)("wallet"), "in-progress");
|
|
46
|
+
const old = new walletRepositoryImpl_1.WalletRepositoryImpl(storageAdapter);
|
|
47
|
+
const walletData = await old.getWalletState();
|
|
48
|
+
const onchainAddrData = await Promise.all(addresses.onchain.map(async (address) => {
|
|
49
|
+
const utxos = await old.getUtxos(address);
|
|
50
|
+
return { address, utxos };
|
|
51
|
+
}));
|
|
52
|
+
const offchainAddrData = await Promise.all(addresses.offchain.map(async (address) => {
|
|
53
|
+
const vtxos = await old.getVtxos(address);
|
|
54
|
+
const txs = await old.getTransactionHistory(address);
|
|
55
|
+
return { address, vtxos, txs };
|
|
56
|
+
}));
|
|
57
|
+
await Promise.all([
|
|
58
|
+
walletData && fresh.saveWalletState(walletData),
|
|
59
|
+
...offchainAddrData.map((addressData) => Promise.all([
|
|
60
|
+
fresh.saveVtxos(addressData.address, addressData.vtxos),
|
|
61
|
+
fresh.saveTransactions(addressData.address, addressData.txs),
|
|
62
|
+
])),
|
|
63
|
+
...onchainAddrData.map((addressData) => fresh.saveUtxos(addressData.address, addressData.utxos)),
|
|
64
|
+
]);
|
|
65
|
+
await storageAdapter.setItem((0, exports.MIGRATION_KEY)("wallet"), "done");
|
|
66
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WalletRepositoryImpl = void 0;
|
|
4
|
+
const base_1 = require("@scure/base");
|
|
5
|
+
const btc_signer_1 = require("@scure/btc-signer");
|
|
6
|
+
const getVtxosStorageKey = (address) => `vtxos:${address}`;
|
|
7
|
+
const getUtxosStorageKey = (address) => `utxos:${address}`;
|
|
8
|
+
const getTransactionsStorageKey = (address) => `tx:${address}`;
|
|
9
|
+
const walletStateStorageKey = "wallet:state";
|
|
10
|
+
// Utility functions for (de)serializing complex structures
|
|
11
|
+
const serializeVtxo = (v) => ({
|
|
12
|
+
...v,
|
|
13
|
+
tapTree: base_1.hex.encode(v.tapTree),
|
|
14
|
+
forfeitTapLeafScript: serializeTapLeaf(v.forfeitTapLeafScript),
|
|
15
|
+
intentTapLeafScript: serializeTapLeaf(v.intentTapLeafScript),
|
|
16
|
+
extraWitness: v.extraWitness?.map(base_1.hex.encode),
|
|
17
|
+
});
|
|
18
|
+
const serializeUtxo = (u) => ({
|
|
19
|
+
...u,
|
|
20
|
+
tapTree: base_1.hex.encode(u.tapTree),
|
|
21
|
+
forfeitTapLeafScript: serializeTapLeaf(u.forfeitTapLeafScript),
|
|
22
|
+
intentTapLeafScript: serializeTapLeaf(u.intentTapLeafScript),
|
|
23
|
+
extraWitness: u.extraWitness?.map(base_1.hex.encode),
|
|
24
|
+
});
|
|
25
|
+
const deserializeVtxo = (o) => ({
|
|
26
|
+
...o,
|
|
27
|
+
createdAt: new Date(o.createdAt),
|
|
28
|
+
tapTree: base_1.hex.decode(o.tapTree),
|
|
29
|
+
forfeitTapLeafScript: deserializeTapLeaf(o.forfeitTapLeafScript),
|
|
30
|
+
intentTapLeafScript: deserializeTapLeaf(o.intentTapLeafScript),
|
|
31
|
+
extraWitness: o.extraWitness?.map(base_1.hex.decode),
|
|
32
|
+
});
|
|
33
|
+
const deserializeUtxo = (o) => ({
|
|
34
|
+
...o,
|
|
35
|
+
tapTree: base_1.hex.decode(o.tapTree),
|
|
36
|
+
forfeitTapLeafScript: deserializeTapLeaf(o.forfeitTapLeafScript),
|
|
37
|
+
intentTapLeafScript: deserializeTapLeaf(o.intentTapLeafScript),
|
|
38
|
+
extraWitness: o.extraWitness?.map(base_1.hex.decode),
|
|
39
|
+
});
|
|
40
|
+
const serializeTapLeaf = ([cb, s]) => ({
|
|
41
|
+
cb: base_1.hex.encode(btc_signer_1.TaprootControlBlock.encode(cb)),
|
|
42
|
+
s: base_1.hex.encode(s),
|
|
43
|
+
});
|
|
44
|
+
const deserializeTapLeaf = (t) => {
|
|
45
|
+
const cb = btc_signer_1.TaprootControlBlock.decode(base_1.hex.decode(t.cb));
|
|
46
|
+
const s = base_1.hex.decode(t.s);
|
|
47
|
+
return [cb, s];
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated This is only to be used in migration from storage V1
|
|
51
|
+
*/
|
|
52
|
+
class WalletRepositoryImpl {
|
|
53
|
+
constructor(storage) {
|
|
54
|
+
this.version = 1;
|
|
55
|
+
this.storage = storage;
|
|
56
|
+
}
|
|
57
|
+
async getVtxos(address) {
|
|
58
|
+
const stored = await this.storage.getItem(getVtxosStorageKey(address));
|
|
59
|
+
if (!stored)
|
|
60
|
+
return [];
|
|
61
|
+
try {
|
|
62
|
+
const parsed = JSON.parse(stored);
|
|
63
|
+
return parsed.map(deserializeVtxo);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error(`Failed to parse VTXOs for address ${address}:`, error);
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async saveVtxos(address, vtxos) {
|
|
71
|
+
const storedVtxos = await this.getVtxos(address);
|
|
72
|
+
for (const vtxo of vtxos) {
|
|
73
|
+
const existing = storedVtxos.findIndex((v) => v.txid === vtxo.txid && v.vout === vtxo.vout);
|
|
74
|
+
if (existing !== -1) {
|
|
75
|
+
storedVtxos[existing] = vtxo;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
storedVtxos.push(vtxo);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
await this.storage.setItem(getVtxosStorageKey(address), JSON.stringify(storedVtxos.map(serializeVtxo)));
|
|
82
|
+
}
|
|
83
|
+
async clearVtxos(address) {
|
|
84
|
+
return this.deleteVtxos(address);
|
|
85
|
+
}
|
|
86
|
+
async deleteVtxos(address) {
|
|
87
|
+
await this.storage.removeItem(getVtxosStorageKey(address));
|
|
88
|
+
}
|
|
89
|
+
async getUtxos(address) {
|
|
90
|
+
const stored = await this.storage.getItem(getUtxosStorageKey(address));
|
|
91
|
+
if (!stored)
|
|
92
|
+
return [];
|
|
93
|
+
try {
|
|
94
|
+
const parsed = JSON.parse(stored);
|
|
95
|
+
return parsed.map(deserializeUtxo);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error(`Failed to parse UTXOs for address ${address}:`, error);
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async saveUtxos(address, utxos) {
|
|
103
|
+
const storedUtxos = await this.getUtxos(address);
|
|
104
|
+
utxos.forEach((utxo) => {
|
|
105
|
+
const existing = storedUtxos.findIndex((u) => u.txid === utxo.txid && u.vout === utxo.vout);
|
|
106
|
+
if (existing !== -1) {
|
|
107
|
+
storedUtxos[existing] = utxo;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
storedUtxos.push(utxo);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
await this.storage.setItem(getUtxosStorageKey(address), JSON.stringify(storedUtxos.map(serializeUtxo)));
|
|
114
|
+
}
|
|
115
|
+
async clearUtxos(address) {
|
|
116
|
+
return this.deleteVtxos(address);
|
|
117
|
+
}
|
|
118
|
+
async deleteUtxos(address) {
|
|
119
|
+
await this.storage.removeItem(getUtxosStorageKey(address));
|
|
120
|
+
}
|
|
121
|
+
async getTransactionHistory(address) {
|
|
122
|
+
const storageKey = getTransactionsStorageKey(address);
|
|
123
|
+
const stored = await this.storage.getItem(storageKey);
|
|
124
|
+
if (!stored)
|
|
125
|
+
return [];
|
|
126
|
+
try {
|
|
127
|
+
return JSON.parse(stored);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.error(`Failed to parse transactions for address ${address}:`, error);
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async saveTransactions(address, txs) {
|
|
135
|
+
const storedTransactions = await this.getTransactionHistory(address);
|
|
136
|
+
for (const tx of txs) {
|
|
137
|
+
const existing = storedTransactions.findIndex((t) => t.key.boardingTxid === tx.key.boardingTxid &&
|
|
138
|
+
t.key.commitmentTxid === tx.key.commitmentTxid &&
|
|
139
|
+
t.key.arkTxid === tx.key.arkTxid);
|
|
140
|
+
if (existing !== -1) {
|
|
141
|
+
storedTransactions[existing] = tx;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
storedTransactions.push(tx);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
await this.storage.setItem(getTransactionsStorageKey(address), JSON.stringify(storedTransactions));
|
|
148
|
+
}
|
|
149
|
+
async clearTransactions(address) {
|
|
150
|
+
return this.deleteTransactions(address);
|
|
151
|
+
}
|
|
152
|
+
async deleteTransactions(address) {
|
|
153
|
+
await this.storage.removeItem(getTransactionsStorageKey(address));
|
|
154
|
+
}
|
|
155
|
+
async getWalletState() {
|
|
156
|
+
const stored = await this.storage.getItem(walletStateStorageKey);
|
|
157
|
+
if (!stored)
|
|
158
|
+
return null;
|
|
159
|
+
try {
|
|
160
|
+
const state = JSON.parse(stored);
|
|
161
|
+
return state;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error("Failed to parse wallet state:", error);
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async saveWalletState(state) {
|
|
169
|
+
await this.storage.setItem(walletStateStorageKey, JSON.stringify(state));
|
|
170
|
+
}
|
|
171
|
+
// New method added in V2, not implemented for legacy
|
|
172
|
+
async clear() {
|
|
173
|
+
throw new Error("Method not implemented.");
|
|
174
|
+
}
|
|
175
|
+
async [Symbol.asyncDispose]() {
|
|
176
|
+
// deprecated StorageAdapter doesn't have a `close()` method
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.WalletRepositoryImpl = WalletRepositoryImpl;
|
|
@@ -1,171 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WalletRepositoryImpl = void 0;
|
|
4
|
-
const base_1 = require("@scure/base");
|
|
5
|
-
const btc_signer_1 = require("@scure/btc-signer");
|
|
6
|
-
const getVtxosStorageKey = (address) => `vtxos:${address}`;
|
|
7
|
-
const getUtxosStorageKey = (address) => `utxos:${address}`;
|
|
8
|
-
const getTransactionsStorageKey = (address) => `tx:${address}`;
|
|
9
|
-
const walletStateStorageKey = "wallet:state";
|
|
10
|
-
// Utility functions for (de)serializing complex structures
|
|
11
|
-
const toHex = (b) => (b ? base_1.hex.encode(b) : undefined);
|
|
12
|
-
const fromHex = (h) => h ? base_1.hex.decode(h) : undefined;
|
|
13
|
-
const serializeTapLeaf = ([cb, s]) => ({
|
|
14
|
-
cb: base_1.hex.encode(btc_signer_1.TaprootControlBlock.encode(cb)),
|
|
15
|
-
s: base_1.hex.encode(s),
|
|
16
|
-
});
|
|
17
|
-
const serializeVtxo = (v) => ({
|
|
18
|
-
...v,
|
|
19
|
-
tapTree: toHex(v.tapTree),
|
|
20
|
-
forfeitTapLeafScript: serializeTapLeaf(v.forfeitTapLeafScript),
|
|
21
|
-
intentTapLeafScript: serializeTapLeaf(v.intentTapLeafScript),
|
|
22
|
-
extraWitness: v.extraWitness?.map(toHex),
|
|
23
|
-
});
|
|
24
|
-
const serializeUtxo = (u) => ({
|
|
25
|
-
...u,
|
|
26
|
-
tapTree: toHex(u.tapTree),
|
|
27
|
-
forfeitTapLeafScript: serializeTapLeaf(u.forfeitTapLeafScript),
|
|
28
|
-
intentTapLeafScript: serializeTapLeaf(u.intentTapLeafScript),
|
|
29
|
-
extraWitness: u.extraWitness?.map(toHex),
|
|
30
|
-
});
|
|
31
|
-
const deserializeTapLeaf = (t) => {
|
|
32
|
-
const cb = btc_signer_1.TaprootControlBlock.decode(fromHex(t.cb));
|
|
33
|
-
const s = fromHex(t.s);
|
|
34
|
-
return [cb, s];
|
|
35
|
-
};
|
|
36
|
-
const deserializeVtxo = (o) => ({
|
|
37
|
-
...o,
|
|
38
|
-
createdAt: new Date(o.createdAt),
|
|
39
|
-
tapTree: fromHex(o.tapTree),
|
|
40
|
-
forfeitTapLeafScript: deserializeTapLeaf(o.forfeitTapLeafScript),
|
|
41
|
-
intentTapLeafScript: deserializeTapLeaf(o.intentTapLeafScript),
|
|
42
|
-
extraWitness: o.extraWitness?.map(fromHex),
|
|
43
|
-
});
|
|
44
|
-
const deserializeUtxo = (o) => ({
|
|
45
|
-
...o,
|
|
46
|
-
tapTree: fromHex(o.tapTree),
|
|
47
|
-
forfeitTapLeafScript: deserializeTapLeaf(o.forfeitTapLeafScript),
|
|
48
|
-
intentTapLeafScript: deserializeTapLeaf(o.intentTapLeafScript),
|
|
49
|
-
extraWitness: o.extraWitness?.map(fromHex),
|
|
50
|
-
});
|
|
51
|
-
class WalletRepositoryImpl {
|
|
52
|
-
constructor(storage) {
|
|
53
|
-
this.storage = storage;
|
|
54
|
-
}
|
|
55
|
-
async getVtxos(address) {
|
|
56
|
-
const stored = await this.storage.getItem(getVtxosStorageKey(address));
|
|
57
|
-
if (!stored)
|
|
58
|
-
return [];
|
|
59
|
-
try {
|
|
60
|
-
const parsed = JSON.parse(stored);
|
|
61
|
-
return parsed.map(deserializeVtxo);
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
console.error(`Failed to parse VTXOs for address ${address}:`, error);
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async saveVtxos(address, vtxos) {
|
|
69
|
-
const storedVtxos = await this.getVtxos(address);
|
|
70
|
-
for (const vtxo of vtxos) {
|
|
71
|
-
const existing = storedVtxos.findIndex((v) => v.txid === vtxo.txid && v.vout === vtxo.vout);
|
|
72
|
-
if (existing !== -1) {
|
|
73
|
-
storedVtxos[existing] = vtxo;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
storedVtxos.push(vtxo);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
await this.storage.setItem(getVtxosStorageKey(address), JSON.stringify(storedVtxos.map(serializeVtxo)));
|
|
80
|
-
}
|
|
81
|
-
async removeVtxo(address, vtxoId) {
|
|
82
|
-
const vtxos = await this.getVtxos(address);
|
|
83
|
-
const [txid, vout] = vtxoId.split(":");
|
|
84
|
-
const filtered = vtxos.filter((v) => !(v.txid === txid && v.vout === parseInt(vout, 10)));
|
|
85
|
-
await this.storage.setItem(getVtxosStorageKey(address), JSON.stringify(filtered.map(serializeVtxo)));
|
|
86
|
-
}
|
|
87
|
-
async clearVtxos(address) {
|
|
88
|
-
await this.storage.removeItem(getVtxosStorageKey(address));
|
|
89
|
-
}
|
|
90
|
-
async getUtxos(address) {
|
|
91
|
-
const stored = await this.storage.getItem(getUtxosStorageKey(address));
|
|
92
|
-
if (!stored)
|
|
93
|
-
return [];
|
|
94
|
-
try {
|
|
95
|
-
const parsed = JSON.parse(stored);
|
|
96
|
-
return parsed.map(deserializeUtxo);
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
console.error(`Failed to parse UTXOs for address ${address}:`, error);
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async saveUtxos(address, utxos) {
|
|
104
|
-
const storedUtxos = await this.getUtxos(address);
|
|
105
|
-
utxos.forEach((utxo) => {
|
|
106
|
-
const existing = storedUtxos.findIndex((u) => u.txid === utxo.txid && u.vout === utxo.vout);
|
|
107
|
-
if (existing !== -1) {
|
|
108
|
-
storedUtxos[existing] = utxo;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
storedUtxos.push(utxo);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
await this.storage.setItem(getUtxosStorageKey(address), JSON.stringify(storedUtxos.map(serializeUtxo)));
|
|
115
|
-
}
|
|
116
|
-
async removeUtxo(address, utxoId) {
|
|
117
|
-
const utxos = await this.getUtxos(address);
|
|
118
|
-
const [txid, vout] = utxoId.split(":");
|
|
119
|
-
const filtered = utxos.filter((v) => !(v.txid === txid && v.vout === parseInt(vout, 10)));
|
|
120
|
-
await this.storage.setItem(getUtxosStorageKey(address), JSON.stringify(filtered.map(serializeUtxo)));
|
|
121
|
-
}
|
|
122
|
-
async clearUtxos(address) {
|
|
123
|
-
await this.storage.removeItem(getUtxosStorageKey(address));
|
|
124
|
-
}
|
|
125
|
-
async getTransactionHistory(address) {
|
|
126
|
-
const storageKey = getTransactionsStorageKey(address);
|
|
127
|
-
const stored = await this.storage.getItem(storageKey);
|
|
128
|
-
if (!stored)
|
|
129
|
-
return [];
|
|
130
|
-
try {
|
|
131
|
-
return JSON.parse(stored);
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
console.error(`Failed to parse transactions for address ${address}:`, error);
|
|
135
|
-
return [];
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
async saveTransactions(address, txs) {
|
|
139
|
-
const storedTransactions = await this.getTransactionHistory(address);
|
|
140
|
-
for (const tx of txs) {
|
|
141
|
-
const existing = storedTransactions.findIndex((t) => t.key === tx.key);
|
|
142
|
-
if (existing !== -1) {
|
|
143
|
-
storedTransactions[existing] = tx;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
storedTransactions.push(tx);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
await this.storage.setItem(getTransactionsStorageKey(address), JSON.stringify(storedTransactions));
|
|
150
|
-
}
|
|
151
|
-
async clearTransactions(address) {
|
|
152
|
-
await this.storage.removeItem(getTransactionsStorageKey(address));
|
|
153
|
-
}
|
|
154
|
-
async getWalletState() {
|
|
155
|
-
const stored = await this.storage.getItem(walletStateStorageKey);
|
|
156
|
-
if (!stored)
|
|
157
|
-
return null;
|
|
158
|
-
try {
|
|
159
|
-
const state = JSON.parse(stored);
|
|
160
|
-
return state;
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
console.error("Failed to parse wallet state:", error);
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
async saveWalletState(state) {
|
|
168
|
-
await this.storage.setItem(walletStateStorageKey, JSON.stringify(state));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
exports.WalletRepositoryImpl = WalletRepositoryImpl;
|
package/dist/cjs/script/base.js
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.VtxoScript = exports.TapTreeCoder = void 0;
|
|
4
37
|
exports.scriptFromTapLeafScript = scriptFromTapLeafScript;
|
|
38
|
+
exports.getSequence = getSequence;
|
|
5
39
|
const btc_signer_1 = require("@scure/btc-signer");
|
|
40
|
+
const bip68 = __importStar(require("bip68"));
|
|
6
41
|
const payment_js_1 = require("@scure/btc-signer/payment.js");
|
|
7
42
|
const psbt_js_1 = require("@scure/btc-signer/psbt.js");
|
|
8
43
|
const base_1 = require("@scure/base");
|
|
@@ -95,3 +130,22 @@ class VtxoScript {
|
|
|
95
130
|
}
|
|
96
131
|
}
|
|
97
132
|
exports.VtxoScript = VtxoScript;
|
|
133
|
+
function getSequence(tapLeafScript) {
|
|
134
|
+
let sequence = undefined;
|
|
135
|
+
try {
|
|
136
|
+
const scriptWithLeafVersion = tapLeafScript[1];
|
|
137
|
+
const script = scriptWithLeafVersion.subarray(0, scriptWithLeafVersion.length - 1);
|
|
138
|
+
try {
|
|
139
|
+
const params = tapscript_1.CSVMultisigTapscript.decode(script).params;
|
|
140
|
+
sequence = bip68.encode(params.timelock.type === "blocks"
|
|
141
|
+
? { blocks: Number(params.timelock.value) }
|
|
142
|
+
: { seconds: Number(params.timelock.value) });
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
const params = tapscript_1.CLTVMultisigTapscript.decode(script).params;
|
|
146
|
+
sequence = Number(params.absoluteTimelock);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch { }
|
|
150
|
+
return sequence;
|
|
151
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DelegateVtxo = void 0;
|
|
4
|
+
const default_1 = require("./default");
|
|
5
|
+
const tapscript_1 = require("./tapscript");
|
|
6
|
+
const base_1 = require("./base");
|
|
7
|
+
const base_2 = require("@scure/base");
|
|
8
|
+
/**
|
|
9
|
+
* DelegateVtxo extends DefaultVtxo with an extra delegator path
|
|
10
|
+
*/
|
|
11
|
+
var DelegateVtxo;
|
|
12
|
+
(function (DelegateVtxo) {
|
|
13
|
+
/**
|
|
14
|
+
* DelegateVtxo.Script extends DefaultVtxo.Script and adds a delegate path.
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const vtxoScript = new DelegateVtxo.Script({
|
|
18
|
+
* pubKey: new Uint8Array(32),
|
|
19
|
+
* serverPubKey: new Uint8Array(32),
|
|
20
|
+
* delegatePubKey: new Uint8Array(32),
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* console.log("script pub key:", vtxoScript.pkScript)
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
class Script extends base_1.VtxoScript {
|
|
27
|
+
constructor(options) {
|
|
28
|
+
const defaultVtxo = new default_1.DefaultVtxo.Script(options);
|
|
29
|
+
const { delegatePubKey, pubKey, serverPubKey } = options;
|
|
30
|
+
const delegateScript = tapscript_1.MultisigTapscript.encode({
|
|
31
|
+
pubkeys: [pubKey, delegatePubKey, serverPubKey],
|
|
32
|
+
}).script;
|
|
33
|
+
super([...defaultVtxo.scripts, delegateScript]);
|
|
34
|
+
this.options = options;
|
|
35
|
+
this.defaultVtxo = defaultVtxo;
|
|
36
|
+
this.delegateScript = base_2.hex.encode(delegateScript);
|
|
37
|
+
}
|
|
38
|
+
forfeit() {
|
|
39
|
+
return this.findLeaf(this.defaultVtxo.forfeitScript);
|
|
40
|
+
}
|
|
41
|
+
exit() {
|
|
42
|
+
return this.findLeaf(this.defaultVtxo.exitScript);
|
|
43
|
+
}
|
|
44
|
+
delegate() {
|
|
45
|
+
return this.findLeaf(this.delegateScript);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
DelegateVtxo.Script = Script;
|
|
49
|
+
})(DelegateVtxo || (exports.DelegateVtxo = DelegateVtxo = {}));
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AsyncStorageAdapter = void 0;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use repositories instead
|
|
6
|
+
* Note: This requires @react-native-async-storage/async-storage to be installed
|
|
7
|
+
*/
|
|
5
8
|
class AsyncStorageAdapter {
|
|
6
9
|
constructor() {
|
|
7
10
|
try {
|
|
@@ -36,6 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.FileSystemStorageAdapter = void 0;
|
|
37
37
|
const fs = __importStar(require("fs/promises"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use repositories instead
|
|
41
|
+
*/
|
|
39
42
|
class FileSystemStorageAdapter {
|
|
40
43
|
constructor(dirPath) {
|
|
41
44
|
// Normalize and resolve the storage base path once
|