@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,39 @@
|
|
|
1
|
+
import { BufferReader, BufferWriter } from "./utils";
|
|
2
|
+
/**
|
|
3
|
+
* AssetOutput references a real transaction output and specify the amount in satoshis.
|
|
4
|
+
* it must be present in an AssetGroup.
|
|
5
|
+
*
|
|
6
|
+
* @param vout - the output index in the transaction
|
|
7
|
+
* @param amount - asset amount in satoshis
|
|
8
|
+
*/
|
|
9
|
+
export declare class AssetOutput {
|
|
10
|
+
readonly vout: number;
|
|
11
|
+
readonly amount: bigint;
|
|
12
|
+
static readonly TYPE_LOCAL = 1;
|
|
13
|
+
private constructor();
|
|
14
|
+
static create(vout: number, amount: bigint | number): AssetOutput;
|
|
15
|
+
static fromString(s: string): AssetOutput;
|
|
16
|
+
static fromBytes(buf: Uint8Array): AssetOutput;
|
|
17
|
+
serialize(): Uint8Array;
|
|
18
|
+
toString(): string;
|
|
19
|
+
validate(): void;
|
|
20
|
+
static fromReader(reader: BufferReader): AssetOutput;
|
|
21
|
+
serializeTo(writer: BufferWriter): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* AssetOutputs is a list of AssetOutput references.
|
|
25
|
+
* it must be present in an AssetGroup.
|
|
26
|
+
*
|
|
27
|
+
* @param outputs - the list of asset outputs
|
|
28
|
+
*/
|
|
29
|
+
export declare class AssetOutputs {
|
|
30
|
+
readonly outputs: AssetOutput[];
|
|
31
|
+
private constructor();
|
|
32
|
+
static create(outputs: AssetOutput[]): AssetOutputs;
|
|
33
|
+
static fromString(s: string): AssetOutputs;
|
|
34
|
+
serialize(): Uint8Array;
|
|
35
|
+
toString(): string;
|
|
36
|
+
validate(): void;
|
|
37
|
+
static fromReader(reader: BufferReader): AssetOutputs;
|
|
38
|
+
serializeTo(writer: BufferWriter): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AssetRefType } from "./types";
|
|
2
|
+
import { AssetId } from "./assetId";
|
|
3
|
+
import { BufferReader, BufferWriter } from "./utils";
|
|
4
|
+
type AssetRefByID = {
|
|
5
|
+
type: AssetRefType.ByID;
|
|
6
|
+
assetId: AssetId;
|
|
7
|
+
};
|
|
8
|
+
type AssetRefByGroup = {
|
|
9
|
+
type: AssetRefType.ByGroup;
|
|
10
|
+
groupIndex: number;
|
|
11
|
+
};
|
|
12
|
+
export declare class AssetRef {
|
|
13
|
+
readonly ref: AssetRefByID | AssetRefByGroup;
|
|
14
|
+
private constructor();
|
|
15
|
+
get type(): AssetRefType;
|
|
16
|
+
static fromId(assetId: AssetId): AssetRef;
|
|
17
|
+
static fromGroupIndex(groupIndex: number): AssetRef;
|
|
18
|
+
static fromString(s: string): AssetRef;
|
|
19
|
+
static fromBytes(buf: Uint8Array): AssetRef;
|
|
20
|
+
serialize(): Uint8Array;
|
|
21
|
+
toString(): string;
|
|
22
|
+
static fromReader(reader: BufferReader): AssetRef;
|
|
23
|
+
serializeTo(writer: BufferWriter): void;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { AssetInputType, AssetRefType } from "./types";
|
|
2
|
+
export { AssetId } from "./assetId";
|
|
3
|
+
export { AssetRef } from "./assetRef";
|
|
4
|
+
export { AssetInput, AssetInputs } from "./assetInput";
|
|
5
|
+
export { AssetOutput, AssetOutputs } from "./assetOutput";
|
|
6
|
+
export { Metadata, MetadataList } from "./metadata";
|
|
7
|
+
export { AssetGroup } from "./assetGroup";
|
|
8
|
+
export { Packet, AssetPacketNotFoundError } from "./packet";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Bytes } from "@scure/btc-signer/utils.js";
|
|
2
|
+
import { BufferReader, BufferWriter } from "./utils";
|
|
3
|
+
/**
|
|
4
|
+
* Metadata represents a key-value pair.
|
|
5
|
+
* @param key - the key
|
|
6
|
+
* @param value - the value
|
|
7
|
+
*/
|
|
8
|
+
export declare class Metadata {
|
|
9
|
+
readonly key: Uint8Array;
|
|
10
|
+
readonly value: Uint8Array;
|
|
11
|
+
private constructor();
|
|
12
|
+
static create(key: Bytes, value: Bytes): Metadata;
|
|
13
|
+
static fromString(s: string): Metadata;
|
|
14
|
+
static fromBytes(buf: Uint8Array): Metadata;
|
|
15
|
+
serialize(): Uint8Array;
|
|
16
|
+
toString(): string;
|
|
17
|
+
get keyString(): string;
|
|
18
|
+
get valueString(): string;
|
|
19
|
+
validate(): void;
|
|
20
|
+
static fromReader(reader: BufferReader): Metadata;
|
|
21
|
+
serializeTo(writer: BufferWriter): void;
|
|
22
|
+
}
|
|
23
|
+
export declare class MetadataList {
|
|
24
|
+
readonly items: Metadata[];
|
|
25
|
+
static readonly ARK_LEAF_TAG = "ArkadeAssetLeaf";
|
|
26
|
+
static readonly ARK_BRANCH_TAG = "ArkadeAssetBranch";
|
|
27
|
+
static readonly ARK_LEAF_VERSION = 0;
|
|
28
|
+
constructor(items: Metadata[]);
|
|
29
|
+
static fromString(s: string): MetadataList;
|
|
30
|
+
static fromBytes(buf: Uint8Array): MetadataList;
|
|
31
|
+
static fromReader(reader: BufferReader): MetadataList;
|
|
32
|
+
serializeTo(writer: BufferWriter): void;
|
|
33
|
+
serialize(): Uint8Array;
|
|
34
|
+
[Symbol.iterator](): Iterator<Metadata>;
|
|
35
|
+
get length(): number;
|
|
36
|
+
hash(): Uint8Array;
|
|
37
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AssetGroup } from "./assetGroup";
|
|
2
|
+
import { TransactionOutput } from "@scure/btc-signer/psbt";
|
|
3
|
+
import { Transaction } from "../utils/transaction";
|
|
4
|
+
export declare class AssetPacketNotFoundError extends Error {
|
|
5
|
+
constructor(txid: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Packet represents a collection of asset groups.
|
|
9
|
+
* A packet is encoded in OP_RETURN output of an asset transaction.
|
|
10
|
+
* @param groups - the asset groups in the packet
|
|
11
|
+
*/
|
|
12
|
+
export declare class Packet {
|
|
13
|
+
readonly groups: AssetGroup[];
|
|
14
|
+
private constructor();
|
|
15
|
+
static create(groups: AssetGroup[]): Packet;
|
|
16
|
+
static fromString(s: string): Packet;
|
|
17
|
+
static fromScript(script: Uint8Array): Packet;
|
|
18
|
+
static fromTxOut(pkScript: Uint8Array): Packet;
|
|
19
|
+
static fromTx(tx: Transaction): Packet;
|
|
20
|
+
static isAssetPacket(script: Uint8Array): boolean;
|
|
21
|
+
leafTxPacket(intentTxid: Uint8Array): Packet;
|
|
22
|
+
txOut(): Required<Pick<TransactionOutput, "script" | "amount">>;
|
|
23
|
+
serialize(): Uint8Array;
|
|
24
|
+
toString(): string;
|
|
25
|
+
validate(): void;
|
|
26
|
+
private static fromReader;
|
|
27
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const TX_HASH_SIZE = 32;
|
|
2
|
+
export declare const ASSET_ID_SIZE = 34;
|
|
3
|
+
export declare const ASSET_VERSION = 1;
|
|
4
|
+
export declare enum AssetInputType {
|
|
5
|
+
Unspecified = 0,
|
|
6
|
+
Local = 1,
|
|
7
|
+
Intent = 2
|
|
8
|
+
}
|
|
9
|
+
export declare enum AssetRefType {
|
|
10
|
+
Unspecified = 0,
|
|
11
|
+
ByID = 1,
|
|
12
|
+
ByGroup = 2
|
|
13
|
+
}
|
|
14
|
+
export declare const MASK_ASSET_ID = 1;
|
|
15
|
+
export declare const MASK_CONTROL_ASSET = 2;
|
|
16
|
+
export declare const MASK_METADATA = 4;
|
|
17
|
+
export declare const ARKADE_MAGIC: Uint8Array<ArrayBuffer>;
|
|
18
|
+
export declare const MARKER_ASSET_PAYLOAD = 0;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class BufferWriter {
|
|
2
|
+
private buffer;
|
|
3
|
+
write(data: Uint8Array): void;
|
|
4
|
+
writeByte(byte: number): void;
|
|
5
|
+
writeUint16LE(value: number): void;
|
|
6
|
+
writeVarUint(value: bigint | number): void;
|
|
7
|
+
writeVarSlice(data: Uint8Array): void;
|
|
8
|
+
toBytes(): Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
export declare class BufferReader {
|
|
11
|
+
private view;
|
|
12
|
+
private offset;
|
|
13
|
+
constructor(data: Uint8Array);
|
|
14
|
+
remaining(): number;
|
|
15
|
+
readByte(): number;
|
|
16
|
+
readSlice(size: number): Uint8Array;
|
|
17
|
+
readUint16LE(): number;
|
|
18
|
+
readVarUint(): bigint;
|
|
19
|
+
readVarSlice(): Uint8Array;
|
|
20
|
+
}
|
|
21
|
+
export declare function isZeroBytes(bytes: Uint8Array): boolean;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type BTC_NETWORK } from "@scure/btc-signer/utils.js";
|
|
2
|
+
import type { Identity } from "../identity";
|
|
3
|
+
/**
|
|
4
|
+
* BIP-322 simple message signing and verification.
|
|
5
|
+
*
|
|
6
|
+
* Supports P2TR (Taproot) signing and verification, P2WPKH verification,
|
|
7
|
+
* and legacy P2PKH verification (Bitcoin Core signmessage format).
|
|
8
|
+
*
|
|
9
|
+
* Reuses the same toSpend/toSign transaction construction as Intent proofs,
|
|
10
|
+
* but with the standard BIP-322 tagged hash ("BIP0322-signed-message")
|
|
11
|
+
* instead of the Ark-specific tag.
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Sign a message (P2TR)
|
|
18
|
+
* const signature = await BIP322.sign("Hello Bitcoin!", identity);
|
|
19
|
+
*
|
|
20
|
+
* // Verify a signature (P2TR or P2WPKH)
|
|
21
|
+
* const valid = BIP322.verify("Hello Bitcoin!", signature, "bc1p...");
|
|
22
|
+
* const valid2 = BIP322.verify("Hello Bitcoin!", signature, "bc1q...");
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare namespace BIP322 {
|
|
26
|
+
/**
|
|
27
|
+
* Sign a message using the BIP-322 simple signature scheme.
|
|
28
|
+
*
|
|
29
|
+
* Constructs the standard BIP-322 toSpend and toSign transactions,
|
|
30
|
+
* signs via the Identity interface, and returns the base64-encoded
|
|
31
|
+
* witness stack.
|
|
32
|
+
*
|
|
33
|
+
* @param message - The message to sign
|
|
34
|
+
* @param identity - Identity instance (holds the private key internally)
|
|
35
|
+
* @param network - Optional Bitcoin network for P2TR address derivation
|
|
36
|
+
* @returns Base64-encoded BIP-322 simple signature (witness stack)
|
|
37
|
+
*/
|
|
38
|
+
function sign(message: string, identity: Identity, network?: BTC_NETWORK): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Verify a BIP-322 signature for a P2TR, P2WPKH, or legacy P2PKH address.
|
|
41
|
+
*
|
|
42
|
+
* For segwit addresses (P2TR, P2WPKH), reconstructs the BIP-322
|
|
43
|
+
* toSpend/toSign transactions and verifies the witness signature.
|
|
44
|
+
*
|
|
45
|
+
* For P2PKH addresses, verifies using the Bitcoin Core legacy
|
|
46
|
+
* `signmessage` format (compact recoverable ECDSA signature).
|
|
47
|
+
*
|
|
48
|
+
* @param message - The original message that was signed
|
|
49
|
+
* @param signature - Base64-encoded signature (BIP-322 witness or legacy compact)
|
|
50
|
+
* @param address - P2TR, P2WPKH, or P2PKH address of the signer
|
|
51
|
+
* @param network - Optional Bitcoin network for address decoding
|
|
52
|
+
* @returns true if the signature is valid
|
|
53
|
+
*/
|
|
54
|
+
function verify(message: string, signature: string, address: string, network?: BTC_NETWORK): boolean;
|
|
55
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Contract } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Encode a contract to the arkcontract string format.
|
|
4
|
+
*
|
|
5
|
+
* Format: arkcontract={type}&{key1}={value1}&{key2}={value2}...
|
|
6
|
+
*
|
|
7
|
+
* This format is compatible with NArk and allows contracts to be
|
|
8
|
+
* shared/imported across different Ark implementations.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const contract: Contract = {
|
|
13
|
+
* type: "vhtlc",
|
|
14
|
+
* params: { sender: "ab12...", receiver: "cd34...", ... },
|
|
15
|
+
* // ...
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* const encoded = encodeArkContract(contract);
|
|
19
|
+
* // "arkcontract=vhtlc&sender=ab12...&receiver=cd34...&..."
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function encodeArkContract(contract: Contract): string;
|
|
23
|
+
/**
|
|
24
|
+
* Parsed result from decoding an arkcontract string.
|
|
25
|
+
*
|
|
26
|
+
* This is a low-level representation. For type-safe contract creation,
|
|
27
|
+
* use `contractFromArkContract` or `contractFromArkContractWithAddress`
|
|
28
|
+
* which validate params through the handler system.
|
|
29
|
+
*/
|
|
30
|
+
export interface ParsedArkContract {
|
|
31
|
+
/** Contract type (e.g., "vhtlc", "default") */
|
|
32
|
+
type: string;
|
|
33
|
+
/** All key-value pairs from the string */
|
|
34
|
+
data: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Decode an arkcontract string into raw type and data.
|
|
38
|
+
*
|
|
39
|
+
* This is a low-level function that parses the URL-encoded format.
|
|
40
|
+
* For creating typed Contract objects, use `contractFromArkContract`
|
|
41
|
+
* or `contractFromArkContractWithAddress` instead.
|
|
42
|
+
*
|
|
43
|
+
* @param encoded - The arkcontract string
|
|
44
|
+
* @returns Parsed type and key-value data
|
|
45
|
+
* @throws If the string is not a valid arkcontract
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const parsed = decodeArkContract("arkcontract=vhtlc&sender=ab12...");
|
|
50
|
+
* // { type: "vhtlc", data: { sender: "ab12...", ... } }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function decodeArkContract(encoded: string): ParsedArkContract;
|
|
54
|
+
/**
|
|
55
|
+
* Create a Contract from an arkcontract string.
|
|
56
|
+
*
|
|
57
|
+
* This requires a handler to be registered for the contract type.
|
|
58
|
+
*
|
|
59
|
+
* @param encoded - The arkcontract string
|
|
60
|
+
* @param options - Additional options for the contract
|
|
61
|
+
* @returns A Contract object
|
|
62
|
+
* @throws If the string is invalid or no handler exists for the type
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const contract = contractFromArkContract(
|
|
67
|
+
* "arkcontract=vhtlc&sender=ab12...",
|
|
68
|
+
* {
|
|
69
|
+
* label: "Lightning Receive",
|
|
70
|
+
* }
|
|
71
|
+
* );
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function contractFromArkContract(encoded: string, options?: {
|
|
75
|
+
label?: string;
|
|
76
|
+
state?: "active" | "inactive";
|
|
77
|
+
expiresAt?: number;
|
|
78
|
+
metadata?: Record<string, unknown>;
|
|
79
|
+
}): Omit<Contract, "script" | "address"> & {
|
|
80
|
+
script?: string;
|
|
81
|
+
address?: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Create a full Contract with derived script and address.
|
|
85
|
+
*
|
|
86
|
+
* @param encoded - The arkcontract string
|
|
87
|
+
* @param serverPubKey - Server public key (for address derivation)
|
|
88
|
+
* @param addressPrefix - Address prefix (e.g., "tark" for testnet)
|
|
89
|
+
* @param options - Additional options
|
|
90
|
+
* @returns A complete Contract object
|
|
91
|
+
*/
|
|
92
|
+
export declare function contractFromArkContractWithAddress(encoded: string, serverPubKey: Uint8Array, addressPrefix: string, options?: {
|
|
93
|
+
label?: string;
|
|
94
|
+
state?: "active" | "inactive";
|
|
95
|
+
expiresAt?: number;
|
|
96
|
+
metadata?: Record<string, unknown>;
|
|
97
|
+
}): Contract;
|
|
98
|
+
/**
|
|
99
|
+
* Check if a string is an arkcontract.
|
|
100
|
+
*/
|
|
101
|
+
export declare function isArkContract(str: string): boolean;
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { IndexerProvider } from "../providers/indexer";
|
|
2
|
+
import { WalletRepository } from "../repositories/walletRepository";
|
|
3
|
+
import { Contract, ContractEventCallback, ContractState, ContractWithVtxos, GetContractsFilter, PathSelection } from "./types";
|
|
4
|
+
import { ContractWatcherConfig } from "./contractWatcher";
|
|
5
|
+
import { VirtualCoin } from "../wallet";
|
|
6
|
+
import { ContractRepository } from "../repositories";
|
|
7
|
+
/**
|
|
8
|
+
* Contract lifecycle and VTXO orchestration API.
|
|
9
|
+
*
|
|
10
|
+
* Responsibilities:
|
|
11
|
+
* - Create and persist contracts
|
|
12
|
+
* - Query stored contracts (optionally with their VTXOs)
|
|
13
|
+
* - Provide spendable path selection for a contract
|
|
14
|
+
* - Emit contract-related events (VTXO received/spent, expiry, connection reset)
|
|
15
|
+
*
|
|
16
|
+
* Notes:
|
|
17
|
+
* - Implementations typically start watching automatically during initialization
|
|
18
|
+
* (so `onContractEvent()` is just for subscribing).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const manager = await ContractManager.create({
|
|
23
|
+
* indexerProvider,
|
|
24
|
+
* contractRepository,
|
|
25
|
+
* walletRepository,
|
|
26
|
+
* getDefaultAddress,
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* const unsubscribe = manager.onContractEvent((event) => {
|
|
30
|
+
* console.log(event.type, event.timestamp);
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* const contract = await manager.createContract({
|
|
34
|
+
* label: "Lightning Receive",
|
|
35
|
+
* type: "vhtlc",
|
|
36
|
+
* params: { sender: "ab12...", receiver: "cd34..." },
|
|
37
|
+
* script: "5120...",
|
|
38
|
+
* address: "tark1...",
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Later:
|
|
42
|
+
* unsubscribe();
|
|
43
|
+
* manager.dispose();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export interface IContractManager extends Disposable {
|
|
47
|
+
/**
|
|
48
|
+
* Create and register a new contract.
|
|
49
|
+
*
|
|
50
|
+
* Implementations may validate that:
|
|
51
|
+
* - A handler exists for `params.type`
|
|
52
|
+
* - `params.script` matches the script derived from `params.params`
|
|
53
|
+
*
|
|
54
|
+
* The contract script is used as the unique identifier.
|
|
55
|
+
*/
|
|
56
|
+
createContract(params: CreateContractParams): Promise<Contract>;
|
|
57
|
+
/**
|
|
58
|
+
* List contracts with optional filters.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const vhtlcs = await manager.getContracts({ type: "vhtlc" });
|
|
63
|
+
* const active = await manager.getContracts({ state: "active" });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
getContracts(filter?: GetContractsFilter): Promise<Contract[]>;
|
|
67
|
+
/**
|
|
68
|
+
* List contracts and include their current VTXOs.
|
|
69
|
+
*
|
|
70
|
+
* If no filter is provided, returns all contracts with their VTXOs.
|
|
71
|
+
*/
|
|
72
|
+
getContractsWithVtxos(filter?: GetContractsFilter): Promise<ContractWithVtxos[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Update mutable contract fields.
|
|
75
|
+
*
|
|
76
|
+
* `script` and `createdAt` are immutable.
|
|
77
|
+
*/
|
|
78
|
+
updateContract(script: string, updates: Partial<Omit<Contract, "script" | "createdAt">>): Promise<Contract>;
|
|
79
|
+
/**
|
|
80
|
+
* Convenience helper to update only the contract state.
|
|
81
|
+
*/
|
|
82
|
+
setContractState(script: string, state: ContractState): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Delete a contract by script and stop watching it (if applicable).
|
|
85
|
+
*/
|
|
86
|
+
deleteContract(script: string): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Get all currently spendable paths for a contract.
|
|
89
|
+
*
|
|
90
|
+
* Returns an empty array if the contract or its handler cannot be found.
|
|
91
|
+
*/
|
|
92
|
+
getSpendablePaths(options: GetSpendablePathsOptions): Promise<PathSelection[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Get all possible spending paths for a contract.
|
|
95
|
+
*
|
|
96
|
+
* Returns an empty array if the contract or its handler cannot be found.
|
|
97
|
+
*/
|
|
98
|
+
getAllSpendingPaths(options: GetAllSpendingPathsOptions): Promise<PathSelection[]>;
|
|
99
|
+
/**
|
|
100
|
+
* Subscribe to contract events.
|
|
101
|
+
*
|
|
102
|
+
* @returns Unsubscribe function
|
|
103
|
+
*/
|
|
104
|
+
onContractEvent(callback: ContractEventCallback): () => void;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the underlying watcher is currently active.
|
|
107
|
+
*/
|
|
108
|
+
isWatching(): Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* Release resources (stop watching, clear listeners).
|
|
111
|
+
*/
|
|
112
|
+
dispose(): void;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Options for getting spendable paths.
|
|
116
|
+
*/
|
|
117
|
+
export type GetSpendablePathsOptions = {
|
|
118
|
+
/** The contract script */
|
|
119
|
+
contractScript: string;
|
|
120
|
+
/** The specific VTXO being evaluated */
|
|
121
|
+
vtxo: VirtualCoin;
|
|
122
|
+
/** Whether collaborative spending is available (default: true) */
|
|
123
|
+
collaborative?: boolean;
|
|
124
|
+
/** Wallet's public key (hex) to determine role */
|
|
125
|
+
walletPubKey?: string;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Options for getting all possible spending paths.
|
|
129
|
+
*/
|
|
130
|
+
export type GetAllSpendingPathsOptions = {
|
|
131
|
+
/** The contract script */
|
|
132
|
+
contractScript: string;
|
|
133
|
+
/** Whether collaborative spending is available (default: true) */
|
|
134
|
+
collaborative?: boolean;
|
|
135
|
+
/** Wallet's public key (hex) to determine role */
|
|
136
|
+
walletPubKey?: string;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Configuration for the ContractManager.
|
|
140
|
+
*/
|
|
141
|
+
export interface ContractManagerConfig {
|
|
142
|
+
/** The indexer provider */
|
|
143
|
+
indexerProvider: IndexerProvider;
|
|
144
|
+
/** The contract repository for persistence */
|
|
145
|
+
contractRepository: ContractRepository;
|
|
146
|
+
/** The wallet repository for VTXO storage (single source of truth) */
|
|
147
|
+
walletRepository: WalletRepository;
|
|
148
|
+
/** Function to get the wallet's default Ark address */
|
|
149
|
+
getDefaultAddress: () => Promise<string>;
|
|
150
|
+
/** Watcher configuration */
|
|
151
|
+
watcherConfig?: Partial<ContractWatcherConfig>;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Parameters for creating a new contract.
|
|
155
|
+
*/
|
|
156
|
+
export type CreateContractParams = Omit<Contract, "createdAt" | "state"> & {
|
|
157
|
+
/** Initial state (defaults to "active") */
|
|
158
|
+
state?: ContractState;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Central manager for contract lifecycle and operations.
|
|
162
|
+
*
|
|
163
|
+
* The ContractManager orchestrates:
|
|
164
|
+
* - Contract registration and persistence
|
|
165
|
+
* - Multi-contract watching via ContractWatcher
|
|
166
|
+
* - VTXO queries across contracts
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const manager = new ContractManager({
|
|
171
|
+
* indexerProvider: wallet.indexerProvider,
|
|
172
|
+
* contractRepository: wallet.contractRepository,
|
|
173
|
+
* getDefaultAddress: () => wallet.getAddress(),
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* // Initialize (loads persisted contracts)
|
|
177
|
+
* await manager.initialize();
|
|
178
|
+
*
|
|
179
|
+
* // Create a new VHTLC contract
|
|
180
|
+
* const contract = await manager.createContract({
|
|
181
|
+
* label: "Lightning Receive",
|
|
182
|
+
* type: "vhtlc",
|
|
183
|
+
* params: { sender: "ab12...", receiver: "cd34...", ... },
|
|
184
|
+
* script: "5120...",
|
|
185
|
+
* address: "tark1...",
|
|
186
|
+
* });
|
|
187
|
+
*
|
|
188
|
+
* // Start watching for events
|
|
189
|
+
* const stop = await manager.startWatching((event) => {
|
|
190
|
+
* console.log(`${event.type} on ${event.contractScript}`);
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* // Get balance across all contracts
|
|
194
|
+
* const balances = await manager.getAllBalances();
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
export declare class ContractManager implements IContractManager {
|
|
198
|
+
private config;
|
|
199
|
+
private watcher;
|
|
200
|
+
private initialized;
|
|
201
|
+
private eventCallbacks;
|
|
202
|
+
private stopWatcherFn?;
|
|
203
|
+
private constructor();
|
|
204
|
+
/**
|
|
205
|
+
* Static factory method for creating a new ContractManager.
|
|
206
|
+
* Initialize the manager by loading persisted contracts and starting to watch.
|
|
207
|
+
*
|
|
208
|
+
* After initialization, the manager automatically watches all active contracts
|
|
209
|
+
* and contracts with VTXOs. Use `onContractEvent()` to register event callbacks.
|
|
210
|
+
*
|
|
211
|
+
* @param config ContractManagerConfig
|
|
212
|
+
*/
|
|
213
|
+
static create(config: ContractManagerConfig): Promise<ContractManager>;
|
|
214
|
+
private initialize;
|
|
215
|
+
/**
|
|
216
|
+
* Create and register a new contract.
|
|
217
|
+
*
|
|
218
|
+
* @param params - Contract parameters
|
|
219
|
+
* @returns The created contract
|
|
220
|
+
*/
|
|
221
|
+
createContract(params: CreateContractParams): Promise<Contract>;
|
|
222
|
+
/**
|
|
223
|
+
* Get contracts with optional filters.
|
|
224
|
+
*
|
|
225
|
+
* @param filter - Optional filter criteria
|
|
226
|
+
* @returns Filtered contracts TODO: filter spent/unspent
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* // Get all VHTLC contracts
|
|
231
|
+
* const vhtlcs = await manager.getContracts({ type: 'vhtlc' });
|
|
232
|
+
*
|
|
233
|
+
* // Get all active contracts
|
|
234
|
+
* const active = await manager.getContracts({ state: 'active' });
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
getContracts(filter?: GetContractsFilter): Promise<Contract[]>;
|
|
238
|
+
getContractsWithVtxos(filter?: GetContractsFilter): Promise<ContractWithVtxos[]>;
|
|
239
|
+
private buildContractsDbFilter;
|
|
240
|
+
/**
|
|
241
|
+
* Update a contract.
|
|
242
|
+
* Nested fields like `params` and `metadata` are replaced with the provided values.
|
|
243
|
+
* If you need to preserve existing fields, merge them manually.
|
|
244
|
+
*
|
|
245
|
+
* @param script - Contract script
|
|
246
|
+
* @param updates - Fields to update
|
|
247
|
+
*/
|
|
248
|
+
updateContract(script: string, updates: Partial<Omit<Contract, "script" | "createdAt">>): Promise<Contract>;
|
|
249
|
+
/**
|
|
250
|
+
* Update a contract's params.
|
|
251
|
+
* This method preserves existing params by merging the provided values.
|
|
252
|
+
*
|
|
253
|
+
* @param script - Contract script
|
|
254
|
+
* @param updates - The new values to merge with existing params
|
|
255
|
+
*/
|
|
256
|
+
updateContractParams(script: string, updates: Contract["params"]): Promise<Contract>;
|
|
257
|
+
/**
|
|
258
|
+
* Set a contract's state.
|
|
259
|
+
*/
|
|
260
|
+
setContractState(script: string, state: ContractState): Promise<void>;
|
|
261
|
+
/**
|
|
262
|
+
* Delete a contract.
|
|
263
|
+
*
|
|
264
|
+
* @param script - Contract script
|
|
265
|
+
*/
|
|
266
|
+
deleteContract(script: string): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Get currently spendable paths for a contract.
|
|
269
|
+
*
|
|
270
|
+
* @param contractScript - The contract script
|
|
271
|
+
* @param options - Options for getting spendable paths
|
|
272
|
+
*/
|
|
273
|
+
getSpendablePaths(options: GetSpendablePathsOptions): Promise<PathSelection[]>;
|
|
274
|
+
getAllSpendingPaths(options: GetAllSpendingPathsOptions): Promise<PathSelection[]>;
|
|
275
|
+
/**
|
|
276
|
+
* Register a callback for contract events.
|
|
277
|
+
*
|
|
278
|
+
* The manager automatically watches after `initialize()`. This method
|
|
279
|
+
* allows registering callbacks to receive events.
|
|
280
|
+
*
|
|
281
|
+
* @param callback - Event callback
|
|
282
|
+
* @returns Unsubscribe function to remove this callback
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* const unsubscribe = manager.onContractEvent((event) => {
|
|
287
|
+
* console.log(`${event.type} on ${event.contractScript}`);
|
|
288
|
+
* });
|
|
289
|
+
*
|
|
290
|
+
* // Later: stop receiving events
|
|
291
|
+
* unsubscribe();
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
onContractEvent(callback: ContractEventCallback): () => void;
|
|
295
|
+
/**
|
|
296
|
+
* Check if currently watching.
|
|
297
|
+
*/
|
|
298
|
+
isWatching(): Promise<boolean>;
|
|
299
|
+
/**
|
|
300
|
+
* Emit an event to all registered callbacks.
|
|
301
|
+
*/
|
|
302
|
+
private emitEvent;
|
|
303
|
+
/**
|
|
304
|
+
* Handle events from the watcher.
|
|
305
|
+
*/
|
|
306
|
+
private handleContractEvent;
|
|
307
|
+
private getVtxosForContracts;
|
|
308
|
+
private fetchContractVxosFromIndexer;
|
|
309
|
+
private fetchContractVtxosBulk;
|
|
310
|
+
private fetchContractVtxosPaginated;
|
|
311
|
+
/**
|
|
312
|
+
* Dispose of the ContractManager and release all resources.
|
|
313
|
+
*
|
|
314
|
+
* Stops the watcher, clears callbacks, and marks
|
|
315
|
+
* the manager as uninitialized.
|
|
316
|
+
*
|
|
317
|
+
* Implements the disposable pattern for cleanup.
|
|
318
|
+
*/
|
|
319
|
+
dispose(): void;
|
|
320
|
+
/**
|
|
321
|
+
* Symbol.dispose implementation for using with `using` keyword.
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* {
|
|
325
|
+
* using manager = await wallet.getContractManager();
|
|
326
|
+
* // ... use manager
|
|
327
|
+
* } // automatically disposed
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
[Symbol.dispose](): void;
|
|
331
|
+
}
|