@arkade-os/sdk 0.3.13 → 0.4.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +586 -54
- 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/bip322/index.js +270 -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/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 +72 -14
- package/dist/cjs/intent/index.js +47 -11
- 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/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 +19 -0
- package/dist/cjs/repositories/indexedDB/manager.js +97 -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/realm/contractRepository.js +120 -0
- package/dist/cjs/repositories/realm/index.js +9 -0
- package/dist/cjs/repositories/realm/schemas.js +108 -0
- package/dist/cjs/repositories/realm/types.js +7 -0
- package/dist/cjs/repositories/realm/walletRepository.js +273 -0
- package/dist/cjs/repositories/serialization.js +49 -0
- package/dist/cjs/repositories/sqlite/contractRepository.js +139 -0
- package/dist/cjs/repositories/sqlite/index.js +7 -0
- package/dist/cjs/repositories/sqlite/types.js +2 -0
- package/dist/cjs/repositories/sqlite/walletRepository.js +328 -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/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/serviceWorker/wallet-message-handler.js +568 -0
- package/dist/cjs/wallet/serviceWorker/wallet.js +383 -102
- package/dist/cjs/wallet/utils.js +58 -0
- package/dist/cjs/wallet/validation.js +151 -0
- package/dist/cjs/wallet/vtxo-manager.js +8 -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/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/bip322/index.js +267 -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/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 +28 -15
- package/dist/esm/intent/index.js +44 -9
- 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/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 +4 -0
- package/dist/esm/repositories/indexedDB/manager.js +92 -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/realm/contractRepository.js +116 -0
- package/dist/esm/repositories/realm/index.js +3 -0
- package/dist/esm/repositories/realm/schemas.js +105 -0
- package/dist/esm/repositories/realm/types.js +6 -0
- package/dist/esm/repositories/realm/walletRepository.js +269 -0
- package/dist/esm/repositories/serialization.js +40 -0
- package/dist/esm/repositories/sqlite/contractRepository.js +135 -0
- package/dist/esm/repositories/sqlite/index.js +2 -0
- package/dist/esm/repositories/sqlite/types.js +1 -0
- package/dist/esm/repositories/sqlite/walletRepository.js +324 -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/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/serviceWorker/wallet-message-handler.js +564 -0
- package/dist/esm/wallet/serviceWorker/wallet.js +382 -101
- package/dist/esm/wallet/utils.js +54 -0
- package/dist/esm/wallet/validation.js +139 -0
- package/dist/esm/wallet/vtxo-manager.js +8 -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/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/bip322/index.d.ts +55 -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/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 +22 -12
- package/dist/types/intent/index.d.ts +15 -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 +4 -0
- package/dist/types/repositories/indexedDB/manager.d.ts +22 -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/realm/contractRepository.d.ts +24 -0
- package/dist/types/repositories/realm/index.d.ts +4 -0
- package/dist/types/repositories/realm/schemas.d.ts +208 -0
- package/dist/types/repositories/realm/types.d.ts +16 -0
- package/dist/types/repositories/realm/walletRepository.d.ts +31 -0
- package/dist/types/repositories/serialization.d.ts +40 -0
- package/dist/types/repositories/sqlite/contractRepository.d.ts +33 -0
- package/dist/types/repositories/sqlite/index.d.ts +3 -0
- package/dist/types/repositories/sqlite/types.d.ts +18 -0
- package/dist/types/repositories/sqlite/walletRepository.d.ts +40 -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/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/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 +12 -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 +69 -11
- 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,76 @@
|
|
|
1
|
+
const registrations = new Map();
|
|
2
|
+
function ensureServiceWorkerSupport() {
|
|
3
|
+
if (!("serviceWorker" in navigator)) {
|
|
4
|
+
throw new Error("Service workers are not supported in this browser");
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function registerOnce(path) {
|
|
8
|
+
if (!registrations.has(path)) {
|
|
9
|
+
const registrationPromise = navigator.serviceWorker
|
|
10
|
+
.register(path)
|
|
11
|
+
.then(async (registration) => {
|
|
12
|
+
try {
|
|
13
|
+
await registration.update();
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.warn("Service worker update failed; continuing with registration", error);
|
|
17
|
+
}
|
|
18
|
+
return registration;
|
|
19
|
+
})
|
|
20
|
+
.catch((error) => {
|
|
21
|
+
// delete failed registration to allow retrials
|
|
22
|
+
registrations.delete(path);
|
|
23
|
+
throw error;
|
|
24
|
+
});
|
|
25
|
+
registrations.set(path, registrationPromise);
|
|
26
|
+
}
|
|
27
|
+
return registrations.get(path);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Registers a service worker for the given path only once and caches the
|
|
31
|
+
* registration promise for subsequent calls.
|
|
32
|
+
*
|
|
33
|
+
* @param path - Service worker script path to register.
|
|
34
|
+
* @throws if service workers are not supported or registration fails.
|
|
35
|
+
*/
|
|
36
|
+
export async function setupServiceWorkerOnce(path) {
|
|
37
|
+
ensureServiceWorkerSupport();
|
|
38
|
+
return registerOnce(path);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns an active service worker instance, optionally ensuring a specific
|
|
42
|
+
* script path is registered before resolving.
|
|
43
|
+
*
|
|
44
|
+
* @param path - Optional service worker script path to register and prefer.
|
|
45
|
+
* @throws if service workers are not supported or no active worker is available.
|
|
46
|
+
*/
|
|
47
|
+
export async function getActiveServiceWorker(path) {
|
|
48
|
+
ensureServiceWorkerSupport();
|
|
49
|
+
// Avoid mixing registrations when a specific script path is provided.
|
|
50
|
+
const registration = path
|
|
51
|
+
? await registerOnce(path)
|
|
52
|
+
: await navigator.serviceWorker.ready;
|
|
53
|
+
let serviceWorker = registration.active ||
|
|
54
|
+
registration.waiting ||
|
|
55
|
+
registration.installing ||
|
|
56
|
+
navigator.serviceWorker.controller;
|
|
57
|
+
if (!serviceWorker && path) {
|
|
58
|
+
const readyRegistration = await navigator.serviceWorker.ready;
|
|
59
|
+
serviceWorker =
|
|
60
|
+
readyRegistration.active ||
|
|
61
|
+
readyRegistration.waiting ||
|
|
62
|
+
readyRegistration.installing ||
|
|
63
|
+
navigator.serviceWorker.controller;
|
|
64
|
+
}
|
|
65
|
+
if (!serviceWorker) {
|
|
66
|
+
throw new Error("Service worker not ready yet");
|
|
67
|
+
}
|
|
68
|
+
return serviceWorker;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clears the cached registration promises.
|
|
72
|
+
* Intended for tests to reset state between runs.
|
|
73
|
+
*/
|
|
74
|
+
export const __resetServiceWorkerManager = () => {
|
|
75
|
+
registrations.clear();
|
|
76
|
+
};
|
|
@@ -2,9 +2,10 @@ export const DEFAULT_DB_NAME = "arkade-service-worker";
|
|
|
2
2
|
/**
|
|
3
3
|
* setupServiceWorker sets up the service worker.
|
|
4
4
|
* @param path - the path to the service worker script
|
|
5
|
+
* @throws if service workers are not supported or activation fails
|
|
5
6
|
* @example
|
|
6
7
|
* ```typescript
|
|
7
|
-
* const
|
|
8
|
+
* const worker = await setupServiceWorker("/service-worker.js");
|
|
8
9
|
* ```
|
|
9
10
|
*/
|
|
10
11
|
export async function setupServiceWorker(path) {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncStorage-backed TaskQueue for Expo/React Native.
|
|
3
|
+
*
|
|
4
|
+
* Persists inbox, outbox, and an optional config blob to AsyncStorage
|
|
5
|
+
* so that data survives process restarts and can be shared between
|
|
6
|
+
* foreground and background execution contexts.
|
|
7
|
+
*/
|
|
8
|
+
export class AsyncStorageTaskQueue {
|
|
9
|
+
constructor(storage, prefix = "ark:task-queue") {
|
|
10
|
+
this.storage = storage;
|
|
11
|
+
this.inboxKey = `${prefix}:inbox`;
|
|
12
|
+
this.outboxKey = `${prefix}:outbox`;
|
|
13
|
+
this.configKey = `${prefix}:config`;
|
|
14
|
+
}
|
|
15
|
+
// ── Inbox ────────────────────────────────────────────────────────
|
|
16
|
+
async addTask(task) {
|
|
17
|
+
const tasks = await this.readList(this.inboxKey);
|
|
18
|
+
tasks.push(task);
|
|
19
|
+
await this.writeList(this.inboxKey, tasks);
|
|
20
|
+
}
|
|
21
|
+
async removeTask(id) {
|
|
22
|
+
const tasks = await this.readList(this.inboxKey);
|
|
23
|
+
await this.writeList(this.inboxKey, tasks.filter((t) => t.id !== id));
|
|
24
|
+
}
|
|
25
|
+
async getTasks(type) {
|
|
26
|
+
const tasks = await this.readList(this.inboxKey);
|
|
27
|
+
if (type) {
|
|
28
|
+
return tasks.filter((t) => t.type === type);
|
|
29
|
+
}
|
|
30
|
+
return tasks;
|
|
31
|
+
}
|
|
32
|
+
async clearTasks() {
|
|
33
|
+
await this.storage.removeItem(this.inboxKey);
|
|
34
|
+
}
|
|
35
|
+
// ── Outbox ───────────────────────────────────────────────────────
|
|
36
|
+
async pushResult(result) {
|
|
37
|
+
const results = await this.readList(this.outboxKey);
|
|
38
|
+
results.push(result);
|
|
39
|
+
await this.writeList(this.outboxKey, results);
|
|
40
|
+
}
|
|
41
|
+
async getResults() {
|
|
42
|
+
return this.readList(this.outboxKey);
|
|
43
|
+
}
|
|
44
|
+
async acknowledgeResults(ids) {
|
|
45
|
+
const idSet = new Set(ids);
|
|
46
|
+
const results = await this.readList(this.outboxKey);
|
|
47
|
+
await this.writeList(this.outboxKey, results.filter((r) => !idSet.has(r.id)));
|
|
48
|
+
}
|
|
49
|
+
// ── Config persistence (for background handler rehydration) ──────
|
|
50
|
+
/**
|
|
51
|
+
* Persist a config blob alongside the queue data.
|
|
52
|
+
* Used by {@link ExpoWallet.setup} to store the wallet parameters
|
|
53
|
+
* that the background handler needs to reconstruct providers.
|
|
54
|
+
*/
|
|
55
|
+
async persistConfig(config) {
|
|
56
|
+
await this.storage.setItem(this.configKey, JSON.stringify(config));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Load the persisted config blob.
|
|
60
|
+
* Used by the background handler to rehydrate wallet dependencies.
|
|
61
|
+
*/
|
|
62
|
+
async loadConfig() {
|
|
63
|
+
const raw = await this.storage.getItem(this.configKey);
|
|
64
|
+
return raw ? JSON.parse(raw) : null;
|
|
65
|
+
}
|
|
66
|
+
// ── Helpers ──────────────────────────────────────────────────────
|
|
67
|
+
async readList(key) {
|
|
68
|
+
const raw = await this.storage.getItem(key);
|
|
69
|
+
return raw ? JSON.parse(raw) : [];
|
|
70
|
+
}
|
|
71
|
+
async writeList(key, list) {
|
|
72
|
+
await this.storage.setItem(key, JSON.stringify(list));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const CONTRACT_POLL_TASK_TYPE = "contract-poll";
|
|
2
|
+
/**
|
|
3
|
+
* Polls the indexer for the latest VTXO state of every contract and
|
|
4
|
+
* persists the results to the wallet repository.
|
|
5
|
+
*
|
|
6
|
+
* Replicates the polling subset of {@link ContractManager.initialize}:
|
|
7
|
+
* 1. Load all contracts from the contract repository.
|
|
8
|
+
* 2. Mark expired active contracts as inactive.
|
|
9
|
+
* 3. Paginated fetch of spendable VTXOs from the indexer.
|
|
10
|
+
* 4. Extend each VTXO with tapscript data.
|
|
11
|
+
* 5. Save to the wallet repository.
|
|
12
|
+
*/
|
|
13
|
+
export const contractPollProcessor = {
|
|
14
|
+
taskType: CONTRACT_POLL_TASK_TYPE,
|
|
15
|
+
async execute(item, deps) {
|
|
16
|
+
const { contractRepository, walletRepository, indexerProvider, extendVtxo, } = deps;
|
|
17
|
+
const contracts = await contractRepository.getContracts();
|
|
18
|
+
const now = Date.now();
|
|
19
|
+
let contractsProcessed = 0;
|
|
20
|
+
let vtxosSaved = 0;
|
|
21
|
+
for (const contract of contracts) {
|
|
22
|
+
// Mark expired active contracts as inactive
|
|
23
|
+
if (contract.state === "active" &&
|
|
24
|
+
contract.expiresAt &&
|
|
25
|
+
contract.expiresAt <= now) {
|
|
26
|
+
contract.state = "inactive";
|
|
27
|
+
await contractRepository.saveContract(contract);
|
|
28
|
+
}
|
|
29
|
+
// Paginated fetch of spendable VTXOs
|
|
30
|
+
const pageSize = 100;
|
|
31
|
+
let pageIndex = 0;
|
|
32
|
+
let hasMore = true;
|
|
33
|
+
const allVtxos = [];
|
|
34
|
+
while (hasMore) {
|
|
35
|
+
const { vtxos, page } = await indexerProvider.getVtxos({
|
|
36
|
+
scripts: [contract.script],
|
|
37
|
+
spendableOnly: true,
|
|
38
|
+
pageIndex,
|
|
39
|
+
pageSize,
|
|
40
|
+
});
|
|
41
|
+
for (const vtxo of vtxos) {
|
|
42
|
+
allVtxos.push(extendVtxo(vtxo, contract));
|
|
43
|
+
}
|
|
44
|
+
hasMore = page ? vtxos.length === pageSize : false;
|
|
45
|
+
pageIndex++;
|
|
46
|
+
}
|
|
47
|
+
await walletRepository.saveVtxos(contract.address, allVtxos);
|
|
48
|
+
vtxosSaved += allVtxos.length;
|
|
49
|
+
contractsProcessed++;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
taskItemId: item.id,
|
|
53
|
+
type: CONTRACT_POLL_TASK_TYPE,
|
|
54
|
+
status: "success",
|
|
55
|
+
data: { contractsProcessed, vtxosSaved },
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { contractPollProcessor, CONTRACT_POLL_TASK_TYPE, } from './contractPollProcessor.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory TaskQueue for testing and lightweight use.
|
|
3
|
+
* State is lost when the process exits.
|
|
4
|
+
*/
|
|
5
|
+
export class InMemoryTaskQueue {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.inbox = new Map();
|
|
8
|
+
this.outbox = new Map();
|
|
9
|
+
}
|
|
10
|
+
async addTask(task) {
|
|
11
|
+
this.inbox.set(task.id, task);
|
|
12
|
+
}
|
|
13
|
+
async removeTask(id) {
|
|
14
|
+
this.inbox.delete(id);
|
|
15
|
+
}
|
|
16
|
+
async getTasks(type) {
|
|
17
|
+
const tasks = Array.from(this.inbox.values());
|
|
18
|
+
if (type) {
|
|
19
|
+
return tasks.filter((t) => t.type === type);
|
|
20
|
+
}
|
|
21
|
+
return tasks;
|
|
22
|
+
}
|
|
23
|
+
async clearTasks() {
|
|
24
|
+
this.inbox.clear();
|
|
25
|
+
}
|
|
26
|
+
async pushResult(result) {
|
|
27
|
+
this.outbox.set(result.id, result);
|
|
28
|
+
}
|
|
29
|
+
async getResults() {
|
|
30
|
+
return Array.from(this.outbox.values());
|
|
31
|
+
}
|
|
32
|
+
async acknowledgeResults(ids) {
|
|
33
|
+
for (const id of ids) {
|
|
34
|
+
this.outbox.delete(id);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getRandomId } from '../../wallet/utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Run all pending tasks from the queue through matching processors.
|
|
4
|
+
*
|
|
5
|
+
* For each task in the inbox:
|
|
6
|
+
* 1. Find the processor whose `taskType` matches `task.type`.
|
|
7
|
+
* 2. Execute it, producing a {@link TaskResult}.
|
|
8
|
+
* 3. Push the result to the outbox and remove the task from the inbox.
|
|
9
|
+
*
|
|
10
|
+
* Tasks with no matching processor produce a `"noop"` result.
|
|
11
|
+
* Processor errors produce a `"failed"` result with the error message.
|
|
12
|
+
*/
|
|
13
|
+
export async function runTasks(queue, processors, deps) {
|
|
14
|
+
const tasks = await queue.getTasks();
|
|
15
|
+
const processorMap = new Map(processors.map((p) => [p.taskType, p]));
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const task of tasks) {
|
|
18
|
+
const processor = processorMap.get(task.type);
|
|
19
|
+
let partial;
|
|
20
|
+
if (!processor) {
|
|
21
|
+
partial = {
|
|
22
|
+
taskItemId: task.id,
|
|
23
|
+
type: task.type,
|
|
24
|
+
status: "noop",
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
try {
|
|
29
|
+
partial = await processor.execute(task, deps);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
partial = {
|
|
33
|
+
taskItemId: task.id,
|
|
34
|
+
type: task.type,
|
|
35
|
+
status: "failed",
|
|
36
|
+
data: {
|
|
37
|
+
error: error instanceof Error
|
|
38
|
+
? error.message
|
|
39
|
+
: String(error),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const result = {
|
|
45
|
+
...partial,
|
|
46
|
+
id: getRandomId(),
|
|
47
|
+
executedAt: Date.now(),
|
|
48
|
+
};
|
|
49
|
+
await queue.pushResult(result);
|
|
50
|
+
await queue.removeTask(task.id);
|
|
51
|
+
results.push(result);
|
|
52
|
+
}
|
|
53
|
+
return results;
|
|
54
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/// <reference lib="webworker" />
|
|
2
|
+
import { getActiveServiceWorker, setupServiceWorkerOnce, } from './browser/service-worker-manager.js';
|
|
3
|
+
import { RestArkProvider } from '../providers/ark.js';
|
|
4
|
+
import { ReadonlySingleKey, SingleKey } from '../identity/index.js';
|
|
5
|
+
import { ReadonlyWallet, Wallet } from '../wallet/wallet.js';
|
|
6
|
+
import { hex } from "@scure/base";
|
|
7
|
+
export class MessageBus {
|
|
8
|
+
constructor(walletRepository, contractRepository, { messageHandlers, tickIntervalMs = 10000, debug = false, buildServices, }) {
|
|
9
|
+
this.walletRepository = walletRepository;
|
|
10
|
+
this.contractRepository = contractRepository;
|
|
11
|
+
this.running = false;
|
|
12
|
+
this.tickTimeout = null;
|
|
13
|
+
this.tickInProgress = false;
|
|
14
|
+
this.debug = false;
|
|
15
|
+
this.initialized = false;
|
|
16
|
+
this.handlers = new Map(messageHandlers.map((u) => [u.messageTag, u]));
|
|
17
|
+
this.tickIntervalMs = tickIntervalMs;
|
|
18
|
+
this.debug = debug;
|
|
19
|
+
this.buildServicesFn = buildServices ?? this.buildServices.bind(this);
|
|
20
|
+
}
|
|
21
|
+
async start() {
|
|
22
|
+
if (this.running)
|
|
23
|
+
return;
|
|
24
|
+
this.running = true;
|
|
25
|
+
if (this.debug)
|
|
26
|
+
console.log("MessageBus starting");
|
|
27
|
+
// Hook message routing
|
|
28
|
+
self.addEventListener("message", this.onMessage.bind(this));
|
|
29
|
+
// activate service worker immediately
|
|
30
|
+
self.addEventListener("install", () => {
|
|
31
|
+
self.skipWaiting();
|
|
32
|
+
});
|
|
33
|
+
// take control of clients immediately
|
|
34
|
+
self.addEventListener("activate", () => {
|
|
35
|
+
self.clients.claim();
|
|
36
|
+
if (this.initialized) {
|
|
37
|
+
this.runTick();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async stop() {
|
|
42
|
+
if (this.debug)
|
|
43
|
+
console.log("MessageBus stopping");
|
|
44
|
+
this.running = false;
|
|
45
|
+
this.tickInProgress = false;
|
|
46
|
+
this.initialized = false;
|
|
47
|
+
if (this.tickTimeout !== null) {
|
|
48
|
+
self.clearTimeout(this.tickTimeout);
|
|
49
|
+
this.tickTimeout = null;
|
|
50
|
+
}
|
|
51
|
+
self.removeEventListener("message", this.onMessage.bind(this));
|
|
52
|
+
await Promise.all(Array.from(this.handlers.values()).map((updater) => updater.stop()));
|
|
53
|
+
}
|
|
54
|
+
scheduleNextTick() {
|
|
55
|
+
if (!this.running)
|
|
56
|
+
return;
|
|
57
|
+
if (this.tickTimeout !== null)
|
|
58
|
+
return;
|
|
59
|
+
if (this.tickInProgress)
|
|
60
|
+
return;
|
|
61
|
+
this.tickTimeout = self.setTimeout(() => this.runTick(), this.tickIntervalMs);
|
|
62
|
+
}
|
|
63
|
+
async runTick() {
|
|
64
|
+
if (!this.running)
|
|
65
|
+
return;
|
|
66
|
+
if (this.tickInProgress)
|
|
67
|
+
return;
|
|
68
|
+
this.tickInProgress = true;
|
|
69
|
+
if (this.tickTimeout !== null) {
|
|
70
|
+
self.clearTimeout(this.tickTimeout);
|
|
71
|
+
this.tickTimeout = null;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const now = Date.now();
|
|
75
|
+
for (const updater of this.handlers.values()) {
|
|
76
|
+
try {
|
|
77
|
+
const response = await updater.tick(now);
|
|
78
|
+
if (this.debug)
|
|
79
|
+
console.log(`[${updater.messageTag}] outgoing tick response:`, response);
|
|
80
|
+
if (response && response.length > 0) {
|
|
81
|
+
self.clients
|
|
82
|
+
.matchAll({
|
|
83
|
+
includeUncontrolled: true,
|
|
84
|
+
type: "window",
|
|
85
|
+
})
|
|
86
|
+
.then((clients) => {
|
|
87
|
+
for (const message of response) {
|
|
88
|
+
clients.forEach((client) => {
|
|
89
|
+
client.postMessage(message);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
if (this.debug)
|
|
97
|
+
console.error(`[${updater.messageTag}] tick failed`, err);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
this.tickInProgress = false;
|
|
103
|
+
this.scheduleNextTick();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async waitForInit(config) {
|
|
107
|
+
if (this.initialized)
|
|
108
|
+
return;
|
|
109
|
+
const services = await this.buildServicesFn(config);
|
|
110
|
+
// Start all handlers
|
|
111
|
+
for (const updater of this.handlers.values()) {
|
|
112
|
+
if (this.debug)
|
|
113
|
+
console.log(`Starting updater: ${updater.messageTag}`);
|
|
114
|
+
await updater.start(services, {
|
|
115
|
+
walletRepository: this.walletRepository,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// Kick off scheduler
|
|
119
|
+
this.scheduleNextTick();
|
|
120
|
+
this.initialized = true;
|
|
121
|
+
}
|
|
122
|
+
async buildServices(config) {
|
|
123
|
+
const arkProvider = new RestArkProvider(config.arkServer.url);
|
|
124
|
+
const storage = {
|
|
125
|
+
walletRepository: this.walletRepository,
|
|
126
|
+
contractRepository: this.contractRepository,
|
|
127
|
+
};
|
|
128
|
+
if ("privateKey" in config.wallet) {
|
|
129
|
+
const identity = SingleKey.fromHex(config.wallet.privateKey);
|
|
130
|
+
const wallet = await Wallet.create({
|
|
131
|
+
identity,
|
|
132
|
+
arkServerUrl: config.arkServer.url,
|
|
133
|
+
arkServerPublicKey: config.arkServer.publicKey,
|
|
134
|
+
storage,
|
|
135
|
+
});
|
|
136
|
+
return { wallet, arkProvider, readonlyWallet: wallet };
|
|
137
|
+
}
|
|
138
|
+
else if ("publicKey" in config.wallet) {
|
|
139
|
+
const identity = ReadonlySingleKey.fromPublicKey(hex.decode(config.wallet.publicKey));
|
|
140
|
+
const readonlyWallet = await ReadonlyWallet.create({
|
|
141
|
+
identity,
|
|
142
|
+
arkServerUrl: config.arkServer.url,
|
|
143
|
+
arkServerPublicKey: config.arkServer.publicKey,
|
|
144
|
+
storage,
|
|
145
|
+
});
|
|
146
|
+
return { readonlyWallet, arkProvider };
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw new Error("Missing privateKey or publicKey in configuration object");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async onMessage(event) {
|
|
153
|
+
const { id, tag, broadcast } = event.data;
|
|
154
|
+
if (tag === "INITIALIZE_MESSAGE_BUS") {
|
|
155
|
+
if (this.debug) {
|
|
156
|
+
console.log("Init Command received");
|
|
157
|
+
}
|
|
158
|
+
await this.waitForInit(event.data.config);
|
|
159
|
+
event.source?.postMessage({ id, tag });
|
|
160
|
+
if (this.debug) {
|
|
161
|
+
console.log("MessageBus initialized");
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (!this.initialized) {
|
|
166
|
+
if (this.debug)
|
|
167
|
+
console.warn("Event received before initialization, dropping", event.data);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (!id || !tag) {
|
|
171
|
+
if (this.debug)
|
|
172
|
+
console.error("Invalid message received, missing required fields:", event.data);
|
|
173
|
+
event.source?.postMessage({
|
|
174
|
+
id,
|
|
175
|
+
tag: tag ?? "unknown",
|
|
176
|
+
error: new TypeError("Invalid message received, missing required fields"),
|
|
177
|
+
});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (broadcast) {
|
|
181
|
+
const updaters = Array.from(this.handlers.values());
|
|
182
|
+
const results = await Promise.allSettled(updaters.map((updater) => updater.handleMessage(event.data)));
|
|
183
|
+
results.forEach((result, index) => {
|
|
184
|
+
const updater = updaters[index];
|
|
185
|
+
if (result.status === "fulfilled") {
|
|
186
|
+
const response = result.value;
|
|
187
|
+
if (response) {
|
|
188
|
+
event.source?.postMessage(response);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
if (this.debug)
|
|
193
|
+
console.error(`[${updater.messageTag}] handleMessage failed`, result.reason);
|
|
194
|
+
const error = result.reason instanceof Error
|
|
195
|
+
? result.reason
|
|
196
|
+
: new Error(String(result.reason));
|
|
197
|
+
event.source?.postMessage({
|
|
198
|
+
id,
|
|
199
|
+
tag: updater.messageTag,
|
|
200
|
+
error,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const updater = this.handlers.get(tag);
|
|
207
|
+
if (!updater) {
|
|
208
|
+
if (this.debug)
|
|
209
|
+
console.warn(`[${tag}] unknown message tag, ignoring message`);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
const response = await updater.handleMessage(event.data);
|
|
214
|
+
if (this.debug)
|
|
215
|
+
console.log(`[${tag}] outgoing response:`, response);
|
|
216
|
+
if (response) {
|
|
217
|
+
event.source?.postMessage(response);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
if (this.debug)
|
|
222
|
+
console.error(`[${tag}] handleMessage failed`, err);
|
|
223
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
224
|
+
event.source?.postMessage({ id, tag, error });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Returns the registered SW for the path.
|
|
229
|
+
* It uses the functions in `service-worker-manager.ts` module.
|
|
230
|
+
* @param path
|
|
231
|
+
* @return the Service Worker
|
|
232
|
+
* @throws if not running in a browser environment
|
|
233
|
+
*/
|
|
234
|
+
static async getServiceWorker(path) {
|
|
235
|
+
return getActiveServiceWorker(path);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Set up and register the Service Worker, ensuring it's done once at most.
|
|
239
|
+
* It uses the functions in `service-worker-manager.ts` module.
|
|
240
|
+
* @param path
|
|
241
|
+
* @return the Service Worker
|
|
242
|
+
* @throws if not running in a browser environment
|
|
243
|
+
*/
|
|
244
|
+
static async setup(path) {
|
|
245
|
+
await setupServiceWorkerOnce(path);
|
|
246
|
+
return getActiveServiceWorker(path);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AssetId } from "./assetId";
|
|
2
|
+
import { AssetRef } from "./assetRef";
|
|
3
|
+
import { AssetInput } from "./assetInput";
|
|
4
|
+
import { AssetOutput } from "./assetOutput";
|
|
5
|
+
import { Metadata } from "./metadata";
|
|
6
|
+
import { BufferReader, BufferWriter } from "./utils";
|
|
7
|
+
/**
|
|
8
|
+
* An asset group contains inputs/outputs and all data related to a given asset id.
|
|
9
|
+
*/
|
|
10
|
+
export declare class AssetGroup {
|
|
11
|
+
readonly assetId: AssetId | null;
|
|
12
|
+
readonly controlAsset: AssetRef | null;
|
|
13
|
+
readonly inputs: AssetInput[];
|
|
14
|
+
readonly outputs: AssetOutput[];
|
|
15
|
+
private readonly metadataList;
|
|
16
|
+
constructor(assetId: AssetId | null, controlAsset: AssetRef | null, inputs: AssetInput[], outputs: AssetOutput[], metadata: Metadata[]);
|
|
17
|
+
static create(assetId: AssetId | null, controlAsset: AssetRef | null, inputs: AssetInput[], outputs: AssetOutput[], metadata: Metadata[]): AssetGroup;
|
|
18
|
+
static fromString(s: string): AssetGroup;
|
|
19
|
+
static fromBytes(buf: Uint8Array): AssetGroup;
|
|
20
|
+
isIssuance(): boolean;
|
|
21
|
+
isReissuance(): boolean;
|
|
22
|
+
serialize(): Uint8Array;
|
|
23
|
+
validate(): void;
|
|
24
|
+
toBatchLeafAssetGroup(intentTxid: Uint8Array): AssetGroup;
|
|
25
|
+
toString(): string;
|
|
26
|
+
static fromReader(reader: BufferReader): AssetGroup;
|
|
27
|
+
serializeTo(writer: BufferWriter): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BufferReader, BufferWriter } from "./utils";
|
|
2
|
+
/**
|
|
3
|
+
* AssetId represents the id of an asset.
|
|
4
|
+
* @param txid - the genesis transaction id (decoded from hex)
|
|
5
|
+
* @param groupIndex - the asset group index in the genesis transaction
|
|
6
|
+
*/
|
|
7
|
+
export declare class AssetId {
|
|
8
|
+
readonly txid: Uint8Array;
|
|
9
|
+
readonly groupIndex: number;
|
|
10
|
+
private constructor();
|
|
11
|
+
static create(txid: string, groupIndex: number): AssetId;
|
|
12
|
+
static fromString(s: string): AssetId;
|
|
13
|
+
static fromBytes(buf: Uint8Array): AssetId;
|
|
14
|
+
serialize(): Uint8Array;
|
|
15
|
+
toString(): string;
|
|
16
|
+
validate(): void;
|
|
17
|
+
static fromReader(reader: BufferReader): AssetId;
|
|
18
|
+
serializeTo(writer: BufferWriter): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AssetInputType } from "./types";
|
|
2
|
+
import { BufferReader, BufferWriter } from "./utils";
|
|
3
|
+
type AssetInputLocal = {
|
|
4
|
+
type: AssetInputType.Local;
|
|
5
|
+
vin: number;
|
|
6
|
+
amount: bigint;
|
|
7
|
+
};
|
|
8
|
+
type AssetInputIntent = Pick<AssetInputLocal, "vin" | "amount"> & {
|
|
9
|
+
type: AssetInputType.Intent;
|
|
10
|
+
txid: Uint8Array;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* AssetInput represents an input of an asset group.
|
|
14
|
+
* a local input references a real transaction input and specify the amount in satoshis.
|
|
15
|
+
* an intent input references an external intent transaction. It is created by the server to handle batch leaf transaction.
|
|
16
|
+
*/
|
|
17
|
+
export declare class AssetInput {
|
|
18
|
+
readonly input: AssetInputLocal | AssetInputIntent;
|
|
19
|
+
private constructor();
|
|
20
|
+
get vin(): number;
|
|
21
|
+
get amount(): bigint;
|
|
22
|
+
static create(vin: number, amount: bigint | number): AssetInput;
|
|
23
|
+
static createIntent(txid: string, vin: number, amount: bigint | number): AssetInput;
|
|
24
|
+
static fromString(s: string): AssetInput;
|
|
25
|
+
static fromBytes(buf: Uint8Array): AssetInput;
|
|
26
|
+
serialize(): Uint8Array;
|
|
27
|
+
toString(): string;
|
|
28
|
+
validate(): void;
|
|
29
|
+
static fromReader(reader: BufferReader): AssetInput;
|
|
30
|
+
serializeTo(writer: BufferWriter): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* AssetInputs represents a list of asset inputs.
|
|
34
|
+
*/
|
|
35
|
+
export declare class AssetInputs {
|
|
36
|
+
readonly inputs: AssetInput[];
|
|
37
|
+
private constructor();
|
|
38
|
+
static create(inputs: AssetInput[]): AssetInputs;
|
|
39
|
+
static fromString(s: string): AssetInputs;
|
|
40
|
+
serialize(): Uint8Array;
|
|
41
|
+
toString(): string;
|
|
42
|
+
validate(): void;
|
|
43
|
+
static fromReader(reader: BufferReader): AssetInputs;
|
|
44
|
+
serializeTo(writer: BufferWriter): void;
|
|
45
|
+
}
|
|
46
|
+
export {};
|