@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,19 @@
|
|
|
1
|
+
import { StorageAdapter } from "../../storage";
|
|
2
|
+
import { WalletRepository } from "../walletRepository";
|
|
3
|
+
export declare const MIGRATION_KEY: (repoType: "wallet" | "contract") => string;
|
|
4
|
+
export type MigrationStatus = "pending" | "in-progress" | "done" | "not-needed";
|
|
5
|
+
export declare function getMigrationStatus(repoType: "wallet" | "contract", storageAdapter: StorageAdapter): Promise<MigrationStatus>;
|
|
6
|
+
export declare function requiresMigration(repoType: "wallet" | "contract", storageAdapter: StorageAdapter): Promise<boolean>;
|
|
7
|
+
export declare function rollbackMigration(repoType: "wallet" | "contract", storageAdapter: StorageAdapter): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Migrate wallet data from the legacy storage adapter to the new one.
|
|
10
|
+
* It accepts both onchain and offchain addresses, make sure to pass both.
|
|
11
|
+
*
|
|
12
|
+
* @param storageAdapter
|
|
13
|
+
* @param fresh
|
|
14
|
+
* @param addresses
|
|
15
|
+
*/
|
|
16
|
+
export declare function migrateWalletRepository(storageAdapter: StorageAdapter, fresh: WalletRepository, addresses: {
|
|
17
|
+
onchain: string[];
|
|
18
|
+
offchain: string[];
|
|
19
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { WalletRepository, WalletState } from "../walletRepository";
|
|
2
|
+
import { StorageAdapter } from "../../storage";
|
|
3
|
+
import { ArkTransaction, ExtendedCoin, ExtendedVirtualCoin } from "../../wallet";
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated This is only to be used in migration from storage V1
|
|
6
|
+
*/
|
|
7
|
+
export declare class WalletRepositoryImpl implements WalletRepository {
|
|
8
|
+
readonly version: 1;
|
|
9
|
+
private storage;
|
|
10
|
+
constructor(storage: StorageAdapter);
|
|
11
|
+
getVtxos(address: string): Promise<ExtendedVirtualCoin[]>;
|
|
12
|
+
saveVtxos(address: string, vtxos: ExtendedVirtualCoin[]): Promise<void>;
|
|
13
|
+
clearVtxos(address: string): Promise<void>;
|
|
14
|
+
deleteVtxos(address: string): Promise<void>;
|
|
15
|
+
getUtxos(address: string): Promise<ExtendedCoin[]>;
|
|
16
|
+
saveUtxos(address: string, utxos: ExtendedCoin[]): Promise<void>;
|
|
17
|
+
clearUtxos(address: string): Promise<void>;
|
|
18
|
+
deleteUtxos(address: string): Promise<void>;
|
|
19
|
+
getTransactionHistory(address: string): Promise<ArkTransaction[]>;
|
|
20
|
+
saveTransactions(address: string, txs: ArkTransaction[]): Promise<void>;
|
|
21
|
+
clearTransactions(address: string): Promise<void>;
|
|
22
|
+
deleteTransactions(address: string): Promise<void>;
|
|
23
|
+
getWalletState(): Promise<WalletState | null>;
|
|
24
|
+
saveWalletState(state: WalletState): Promise<void>;
|
|
25
|
+
clear(): Promise<void>;
|
|
26
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
27
|
+
}
|
|
@@ -1,38 +1,27 @@
|
|
|
1
|
-
import { StorageAdapter } from "../storage";
|
|
2
1
|
import { ArkTransaction, ExtendedCoin, ExtendedVirtualCoin } from "../wallet";
|
|
3
2
|
export interface WalletState {
|
|
4
3
|
lastSyncTime?: number;
|
|
5
4
|
settings?: Record<string, any>;
|
|
6
5
|
}
|
|
7
|
-
export
|
|
6
|
+
export type CommitmentTxRecord = {
|
|
7
|
+
txid: string;
|
|
8
|
+
createdAt: number;
|
|
9
|
+
};
|
|
10
|
+
export interface WalletRepository extends AsyncDisposable {
|
|
11
|
+
readonly version: 1;
|
|
12
|
+
/**
|
|
13
|
+
* Clear all data from storage.
|
|
14
|
+
*/
|
|
15
|
+
clear(): Promise<void>;
|
|
8
16
|
getVtxos(address: string): Promise<ExtendedVirtualCoin[]>;
|
|
9
17
|
saveVtxos(address: string, vtxos: ExtendedVirtualCoin[]): Promise<void>;
|
|
10
|
-
|
|
11
|
-
clearVtxos(address: string): Promise<void>;
|
|
18
|
+
deleteVtxos(address: string): Promise<void>;
|
|
12
19
|
getUtxos(address: string): Promise<ExtendedCoin[]>;
|
|
13
20
|
saveUtxos(address: string, utxos: ExtendedCoin[]): Promise<void>;
|
|
14
|
-
|
|
15
|
-
clearUtxos(address: string): Promise<void>;
|
|
21
|
+
deleteUtxos(address: string): Promise<void>;
|
|
16
22
|
getTransactionHistory(address: string): Promise<ArkTransaction[]>;
|
|
17
23
|
saveTransactions(address: string, txs: ArkTransaction[]): Promise<void>;
|
|
18
|
-
|
|
19
|
-
getWalletState(): Promise<WalletState | null>;
|
|
20
|
-
saveWalletState(state: WalletState): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
export declare class WalletRepositoryImpl implements WalletRepository {
|
|
23
|
-
private storage;
|
|
24
|
-
constructor(storage: StorageAdapter);
|
|
25
|
-
getVtxos(address: string): Promise<ExtendedVirtualCoin[]>;
|
|
26
|
-
saveVtxos(address: string, vtxos: ExtendedVirtualCoin[]): Promise<void>;
|
|
27
|
-
removeVtxo(address: string, vtxoId: string): Promise<void>;
|
|
28
|
-
clearVtxos(address: string): Promise<void>;
|
|
29
|
-
getUtxos(address: string): Promise<ExtendedCoin[]>;
|
|
30
|
-
saveUtxos(address: string, utxos: ExtendedCoin[]): Promise<void>;
|
|
31
|
-
removeUtxo(address: string, utxoId: string): Promise<void>;
|
|
32
|
-
clearUtxos(address: string): Promise<void>;
|
|
33
|
-
getTransactionHistory(address: string): Promise<ArkTransaction[]>;
|
|
34
|
-
saveTransactions(address: string, txs: ArkTransaction[]): Promise<void>;
|
|
35
|
-
clearTransactions(address: string): Promise<void>;
|
|
24
|
+
deleteTransactions(address: string): Promise<void>;
|
|
36
25
|
getWalletState(): Promise<WalletState | null>;
|
|
37
26
|
saveWalletState(state: WalletState): Promise<void>;
|
|
38
27
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Bytes } from "@scure/btc-signer/utils";
|
|
2
|
+
import { DefaultVtxo } from "./default";
|
|
3
|
+
import { TapLeafScript, VtxoScript } from "./base";
|
|
4
|
+
/**
|
|
5
|
+
* DelegateVtxo extends DefaultVtxo with an extra delegator path
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace DelegateVtxo {
|
|
8
|
+
/**
|
|
9
|
+
* Options extends DefaultVtxo.Options and adds a delegatePubKey
|
|
10
|
+
*/
|
|
11
|
+
interface Options extends DefaultVtxo.Options {
|
|
12
|
+
delegatePubKey: Bytes;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* DelegateVtxo.Script extends DefaultVtxo.Script and adds a delegate path.
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const vtxoScript = new DelegateVtxo.Script({
|
|
19
|
+
* pubKey: new Uint8Array(32),
|
|
20
|
+
* serverPubKey: new Uint8Array(32),
|
|
21
|
+
* delegatePubKey: new Uint8Array(32),
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* console.log("script pub key:", vtxoScript.pkScript)
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
class Script extends VtxoScript {
|
|
28
|
+
readonly options: Options;
|
|
29
|
+
readonly defaultVtxo: DefaultVtxo.Script;
|
|
30
|
+
readonly delegateScript: string;
|
|
31
|
+
constructor(options: Options);
|
|
32
|
+
forfeit(): TapLeafScript;
|
|
33
|
+
exit(): TapLeafScript;
|
|
34
|
+
delegate(): TapLeafScript;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { StorageAdapter } from "./index";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use repositories instead
|
|
4
|
+
* Note: This requires @react-native-async-storage/async-storage to be installed
|
|
5
|
+
*/
|
|
2
6
|
export declare class AsyncStorageAdapter implements StorageAdapter {
|
|
3
7
|
private AsyncStorage;
|
|
4
8
|
constructor();
|
|
@@ -41,3 +41,9 @@ export declare function verifyTapscriptSignatures(tx: Transaction, inputIndex: n
|
|
|
41
41
|
* @param originalTx original transaction
|
|
42
42
|
*/
|
|
43
43
|
export declare function combineTapscriptSigs(signedTx: Transaction, originalTx: Transaction): Transaction;
|
|
44
|
+
/**
|
|
45
|
+
* Validates if a given string is a valid Ark address by attempting to decode it.
|
|
46
|
+
* @param address The Ark address to validate.
|
|
47
|
+
* @returns True if the address is valid, false otherwise.
|
|
48
|
+
*/
|
|
49
|
+
export declare function isValidArkAddress(address: string): boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Network } from "../networks";
|
|
1
2
|
export type VSize = {
|
|
2
3
|
value: bigint;
|
|
3
4
|
fee(feeRate: bigint): bigint;
|
|
@@ -7,7 +8,7 @@ export declare class TxWeightEstimator {
|
|
|
7
8
|
static readonly INPUT_SIZE: number;
|
|
8
9
|
static readonly BASE_CONTROL_BLOCK_SIZE: number;
|
|
9
10
|
static readonly OUTPUT_SIZE: number;
|
|
10
|
-
static readonly
|
|
11
|
+
static readonly P2WPKH_OUTPUT_SIZE: number;
|
|
11
12
|
static readonly BASE_TX_SIZE: number;
|
|
12
13
|
static readonly WITNESS_HEADER_SIZE = 2;
|
|
13
14
|
static readonly WITNESS_SCALE_FACTOR = 4;
|
|
@@ -24,7 +25,16 @@ export declare class TxWeightEstimator {
|
|
|
24
25
|
addKeySpendInput(isDefault?: boolean): TxWeightEstimator;
|
|
25
26
|
addP2PKHInput(): TxWeightEstimator;
|
|
26
27
|
addTapscriptInput(leafWitnessSize: number, leafScriptSize: number, leafControlBlockSize: number): TxWeightEstimator;
|
|
27
|
-
|
|
28
|
+
addP2WPKHOutput(): TxWeightEstimator;
|
|
28
29
|
addP2TROutput(): TxWeightEstimator;
|
|
30
|
+
/**
|
|
31
|
+
* Adds an output given a raw script.
|
|
32
|
+
* Cost = 8 bytes (amount) + varint(scriptLen) + scriptLen
|
|
33
|
+
*/
|
|
34
|
+
addOutputScript(script: Uint8Array): TxWeightEstimator;
|
|
35
|
+
/**
|
|
36
|
+
* Adds an output by decoding the address to get the exact script size.
|
|
37
|
+
*/
|
|
38
|
+
addOutputAddress(address: string, network: Network): TxWeightEstimator;
|
|
29
39
|
vsize(): VSize;
|
|
30
40
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { AssetDetails, BurnParams, IAssetManager, IReadonlyAssetManager, IssuanceParams, IssuanceResult, ReissuanceParams } from ".";
|
|
2
|
+
import { IndexerProvider } from "../providers/indexer";
|
|
3
|
+
import { Wallet } from "./wallet";
|
|
4
|
+
export declare class ReadonlyAssetManager implements IReadonlyAssetManager {
|
|
5
|
+
readonly indexer: IndexerProvider;
|
|
6
|
+
constructor(indexer: IndexerProvider);
|
|
7
|
+
getAssetDetails(assetId: string): Promise<AssetDetails>;
|
|
8
|
+
}
|
|
9
|
+
export declare class AssetManager extends ReadonlyAssetManager implements IAssetManager {
|
|
10
|
+
readonly wallet: Wallet;
|
|
11
|
+
constructor(wallet: Wallet);
|
|
12
|
+
/**
|
|
13
|
+
* Issue a new asset.
|
|
14
|
+
* @param params - Parameters for asset issuance
|
|
15
|
+
* @param params.amount - Amount of asset units to issue
|
|
16
|
+
* @param params.controlAsset - Optional control asset (for reissuable assets)
|
|
17
|
+
* @param params.metadata - Optional metadata to attach to the asset
|
|
18
|
+
* @returns Promise resolving to the ark transaction ID and asset ID
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Issue a simple non-reissuable asset
|
|
23
|
+
* const result = await wallet.issueAsset({ amount: 1000 });
|
|
24
|
+
* console.log('Asset ID:', result.assetId);
|
|
25
|
+
*
|
|
26
|
+
* // Issue a reissuable asset with a new control asset
|
|
27
|
+
* const result = await wallet.issueAsset({
|
|
28
|
+
* amount: 1000,
|
|
29
|
+
* controlAsset: 1 // creates new control asset with amount 1
|
|
30
|
+
* });
|
|
31
|
+
* console.log('Control Asset ID:', result.controlAssetId);
|
|
32
|
+
* console.log('Asset ID:', result.assetId);
|
|
33
|
+
*
|
|
34
|
+
* // Issue a reissuable asset with an existing control asset
|
|
35
|
+
* const result = await wallet.issueAsset({
|
|
36
|
+
* amount: 1000,
|
|
37
|
+
* controlAsset: 'controlAssetId'
|
|
38
|
+
* });
|
|
39
|
+
* console.log('Control Asset ID:', result.controlAssetId);
|
|
40
|
+
* console.log('Asset ID:', result.assetId);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
issue(params: IssuanceParams): Promise<IssuanceResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Reissue more units of an existing asset.
|
|
46
|
+
* Requires ownership of the control asset.
|
|
47
|
+
*
|
|
48
|
+
* @param params - Parameters for asset reissuance
|
|
49
|
+
* @param params.assetId - The asset ID to reissue (control asset ID is resolved via getAssetDetails)
|
|
50
|
+
* @param params.amount - Amount of additional units to issue
|
|
51
|
+
* @returns Promise resolving to the ark transaction ID
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const txid = await wallet.assetManager.reissue({
|
|
56
|
+
* assetId: 'def456...',
|
|
57
|
+
* amount: 500
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
reissue(params: ReissuanceParams): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Burn assets.
|
|
64
|
+
* @param params - Parameters for burning
|
|
65
|
+
* @param params.assetId - The asset ID to burn
|
|
66
|
+
* @param params.amount - Amount of units to burn
|
|
67
|
+
* @returns Promise resolving to the ark transaction ID
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const txid = await wallet.assetManager.burn({
|
|
72
|
+
* assetId: 'abc123...',
|
|
73
|
+
* amount: 100
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
burn(params: BurnParams): Promise<string>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Packet } from "../asset";
|
|
2
|
+
import { Asset, Recipient, VirtualCoin } from "./index";
|
|
3
|
+
/**
|
|
4
|
+
* Creates an asset packet from asset inputs and receivers.
|
|
5
|
+
* Groups inputs and outputs by asset ID and creates the Packet object
|
|
6
|
+
* @param assetInputs - map input index -> assets
|
|
7
|
+
* @param receivers - array of recipients with their asset allocations
|
|
8
|
+
* @param changeReceiver - (optional) change receiver containing remaining assets
|
|
9
|
+
* @returns packet containing all asset groups
|
|
10
|
+
*/
|
|
11
|
+
export declare function createAssetPacket(assetInputs: Map<number, Asset[]>, receivers: Recipient[], changeReceiver?: Recipient): Packet;
|
|
12
|
+
/**
|
|
13
|
+
* Selects coins that contain a specific asset.
|
|
14
|
+
* Returns coins sorted by amount (smallest first for better coin selection).
|
|
15
|
+
*/
|
|
16
|
+
export declare function selectCoinsWithAsset(coins: VirtualCoin[], assetId: string, requiredAmount: bigint): {
|
|
17
|
+
selected: VirtualCoin[];
|
|
18
|
+
totalAssetAmount: bigint;
|
|
19
|
+
};
|
|
20
|
+
export declare function computeAssetChange(inputAssets: Map<string, bigint>, outputAssets: Map<string, bigint>): Map<string, bigint>;
|
|
21
|
+
export declare function selectedCoinsToAssetInputs(selectedCoins: VirtualCoin[]): Map<number, Asset[]>;
|
|
@@ -7,7 +7,7 @@ import { TxTree } from "../tree/txTree";
|
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
9
|
* // use wallet handler or create a custom one
|
|
10
|
-
* const handler = wallet.createBatchHandler(intentId, inputs, musig2session);
|
|
10
|
+
* const handler = wallet.createBatchHandler(intentId, inputs, expectedRecipients, musig2session);
|
|
11
11
|
*
|
|
12
12
|
* const abortController = new AbortController();
|
|
13
13
|
* // Get event stream from Ark provider
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ArkProvider, ExtendedVirtualCoin, Identity, Outpoint } from "..";
|
|
2
|
+
import { DelegatorProvider } from "../providers/delegator";
|
|
3
|
+
export interface DelegatorManager {
|
|
4
|
+
delegate(vtxos: ExtendedVirtualCoin[], destination: string, delegateAt?: Date): Promise<{
|
|
5
|
+
delegated: Outpoint[];
|
|
6
|
+
failed: {
|
|
7
|
+
outpoints: Outpoint[];
|
|
8
|
+
error: unknown;
|
|
9
|
+
}[];
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export declare class DelegatorManagerImpl implements DelegatorManager {
|
|
13
|
+
readonly delegatorProvider: DelegatorProvider;
|
|
14
|
+
readonly arkInfoProvider: Pick<ArkProvider, "getInfo">;
|
|
15
|
+
readonly identity: Identity;
|
|
16
|
+
constructor(delegatorProvider: DelegatorProvider, arkInfoProvider: Pick<ArkProvider, "getInfo">, identity: Identity);
|
|
17
|
+
delegate(vtxos: ExtendedVirtualCoin[], destination: string, delegateAt?: Date): Promise<{
|
|
18
|
+
delegated: Outpoint[];
|
|
19
|
+
failed: {
|
|
20
|
+
outpoints: Outpoint[];
|
|
21
|
+
error: unknown;
|
|
22
|
+
}[];
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { WalletRepository } from "../../repositories/walletRepository";
|
|
2
|
+
import type { ContractRepository } from "../../repositories/contractRepository";
|
|
3
|
+
import type { AsyncStorageTaskQueue } from "../../worker/expo/asyncStorageTaskQueue";
|
|
4
|
+
import type { TaskProcessor } from "../../worker/expo/taskRunner";
|
|
5
|
+
/**
|
|
6
|
+
* Wallet parameters persisted by {@link ExpoWallet.setup} and read
|
|
7
|
+
* by the background handler to reconstruct providers and `extendVtxo`
|
|
8
|
+
* without a network call.
|
|
9
|
+
*/
|
|
10
|
+
export interface PersistedBackgroundConfig {
|
|
11
|
+
arkServerUrl: string;
|
|
12
|
+
pubkeyHex: string;
|
|
13
|
+
serverPubKeyHex: string;
|
|
14
|
+
exitTimelockValue: string;
|
|
15
|
+
exitTimelockType: "blocks" | "seconds";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options for {@link defineExpoBackgroundTask}.
|
|
19
|
+
*/
|
|
20
|
+
export interface DefineBackgroundTaskOptions {
|
|
21
|
+
/** AsyncStorage-backed queue (must match the one passed to ExpoWallet.setup). */
|
|
22
|
+
taskQueue: AsyncStorageTaskQueue;
|
|
23
|
+
/** Wallet repository (fresh instance is fine — connects to the same DB). */
|
|
24
|
+
walletRepository: WalletRepository;
|
|
25
|
+
/** Contract repository (fresh instance is fine — connects to the same DB). */
|
|
26
|
+
contractRepository: ContractRepository;
|
|
27
|
+
/** Processors to run. Defaults to `[contractPollProcessor]`. */
|
|
28
|
+
processors?: TaskProcessor[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Define the Expo background task handler.
|
|
32
|
+
*
|
|
33
|
+
* **Must be called at module/global scope** (before React mounts).
|
|
34
|
+
* Internally calls `TaskManager.defineTask()`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* // At the top of your app entry file
|
|
39
|
+
* import { defineExpoBackgroundTask } from "@arkade-os/sdk/wallet/expo";
|
|
40
|
+
* import { AsyncStorageTaskQueue } from "@arkade-os/sdk/worker/expo";
|
|
41
|
+
* import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
42
|
+
*
|
|
43
|
+
* const taskQueue = new AsyncStorageTaskQueue(AsyncStorage);
|
|
44
|
+
* defineExpoBackgroundTask("ark-background-poll", {
|
|
45
|
+
* taskQueue,
|
|
46
|
+
* walletRepository: new IndexedDBWalletRepository(),
|
|
47
|
+
* contractRepository: new IndexedDBContractRepository(),
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function defineExpoBackgroundTask(taskName: string, options: DefineBackgroundTaskOptions): void;
|
|
52
|
+
/**
|
|
53
|
+
* Activate the OS-level background task scheduler.
|
|
54
|
+
*
|
|
55
|
+
* Call this after {@link defineExpoBackgroundTask} (typically inside
|
|
56
|
+
* {@link ExpoWallet.setup} or in a React component after wallet init).
|
|
57
|
+
*
|
|
58
|
+
* @param minimumInterval - Minimum interval in minutes (default 15).
|
|
59
|
+
*/
|
|
60
|
+
export declare function registerExpoBackgroundTask(taskName: string, options?: {
|
|
61
|
+
minimumInterval?: number;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Unregister the background task from the OS scheduler.
|
|
65
|
+
*/
|
|
66
|
+
export declare function unregisterExpoBackgroundTask(taskName: string): Promise<void>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ExpoWallet } from "./wallet";
|
|
2
|
+
export type { ExpoWalletConfig, ExpoBackgroundConfig } from "./wallet";
|
|
3
|
+
export { defineExpoBackgroundTask, registerExpoBackgroundTask, unregisterExpoBackgroundTask, } from "./background";
|
|
4
|
+
export type { DefineBackgroundTaskOptions, PersistedBackgroundConfig, } from "./background";
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Wallet } from "../wallet";
|
|
2
|
+
import type { IWallet, IAssetManager, WalletBalance, WalletConfig, SendBitcoinParams, SettleParams, GetVtxosFilter, ArkTransaction, ExtendedCoin, ExtendedVirtualCoin, Recipient } from "..";
|
|
3
|
+
import type { SettlementEvent } from "../../providers/ark";
|
|
4
|
+
import type { Identity } from "../../identity";
|
|
5
|
+
import type { IContractManager } from "../../contracts/contractManager";
|
|
6
|
+
import type { TaskQueue } from "../../worker/expo/taskQueue";
|
|
7
|
+
import type { TaskProcessor } from "../../worker/expo/taskRunner";
|
|
8
|
+
/**
|
|
9
|
+
* Background processing configuration for {@link ExpoWallet}.
|
|
10
|
+
*/
|
|
11
|
+
export interface ExpoBackgroundConfig {
|
|
12
|
+
/** Identifier registered with expo-background-task. */
|
|
13
|
+
taskName: string;
|
|
14
|
+
/** Persistence layer for foreground ↔ background handoff. */
|
|
15
|
+
taskQueue: TaskQueue;
|
|
16
|
+
/** Processors to run on each tick. Defaults to `[contractPollProcessor]`. */
|
|
17
|
+
processors?: TaskProcessor[];
|
|
18
|
+
/** If set, automatically polls at this interval (ms) while the app is in the foreground. */
|
|
19
|
+
foregroundIntervalMs?: number;
|
|
20
|
+
/** If set, registers the background task with the OS at this interval (minutes, min 15). */
|
|
21
|
+
minimumBackgroundInterval?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for {@link ExpoWallet.setup}.
|
|
25
|
+
*/
|
|
26
|
+
export interface ExpoWalletConfig extends WalletConfig {
|
|
27
|
+
background: ExpoBackgroundConfig;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Expo/React Native wallet with built-in background task processing.
|
|
31
|
+
*
|
|
32
|
+
* Wraps a standard {@link Wallet} and adds a lightweight task queue
|
|
33
|
+
* for keeping contract/VTXO state fresh while the app is active and
|
|
34
|
+
* across Expo BackgroundTask wakes.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { ExpoWallet } from "@arkade-os/sdk/wallet/expo";
|
|
39
|
+
* import { AsyncStorageTaskQueue } from "@arkade-os/sdk/worker/expo";
|
|
40
|
+
*
|
|
41
|
+
* const wallet = await ExpoWallet.setup({
|
|
42
|
+
* identity: SingleKey.fromHex(privateKey),
|
|
43
|
+
* arkServerUrl,
|
|
44
|
+
* esploraUrl,
|
|
45
|
+
* storage: { walletRepository, contractRepository },
|
|
46
|
+
* background: {
|
|
47
|
+
* taskName: "ark-background-poll",
|
|
48
|
+
* taskQueue: new AsyncStorageTaskQueue(AsyncStorage),
|
|
49
|
+
* foregroundIntervalMs: 20_000,
|
|
50
|
+
* minimumBackgroundInterval: 15,
|
|
51
|
+
* },
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* const balance = await wallet.getBalance();
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare class ExpoWallet implements IWallet {
|
|
58
|
+
private readonly wallet;
|
|
59
|
+
private readonly taskQueue;
|
|
60
|
+
private readonly processors;
|
|
61
|
+
private readonly deps;
|
|
62
|
+
readonly identity: Identity;
|
|
63
|
+
readonly arkProvider: Wallet["arkProvider"];
|
|
64
|
+
readonly indexerProvider: Wallet["indexerProvider"];
|
|
65
|
+
private foregroundIntervalId?;
|
|
66
|
+
private readonly taskName;
|
|
67
|
+
private constructor();
|
|
68
|
+
/**
|
|
69
|
+
* Create an ExpoWallet with background task support.
|
|
70
|
+
*
|
|
71
|
+
* 1. Creates the inner {@link Wallet} via `Wallet.create()`.
|
|
72
|
+
* 2. Wires up processors (defaults to {@link contractPollProcessor}).
|
|
73
|
+
* 3. Persists background config for the background handler (if the queue supports it).
|
|
74
|
+
* 4. Seeds the task queue with a `contract-poll` task.
|
|
75
|
+
* 5. Registers the background task with the OS scheduler (if `minimumBackgroundInterval` is set).
|
|
76
|
+
* 6. Starts foreground polling if `foregroundIntervalMs` is set.
|
|
77
|
+
*/
|
|
78
|
+
static setup(config: ExpoWalletConfig): Promise<ExpoWallet>;
|
|
79
|
+
private startForegroundPolling;
|
|
80
|
+
private runForegroundPoll;
|
|
81
|
+
private seedContractPollTask;
|
|
82
|
+
/**
|
|
83
|
+
* Stop foreground polling and unregister the background task.
|
|
84
|
+
*/
|
|
85
|
+
dispose(): Promise<void>;
|
|
86
|
+
getAddress(): Promise<string>;
|
|
87
|
+
getBoardingAddress(): Promise<string>;
|
|
88
|
+
getBalance(): Promise<WalletBalance>;
|
|
89
|
+
getVtxos(filter?: GetVtxosFilter): Promise<ExtendedVirtualCoin[]>;
|
|
90
|
+
getBoardingUtxos(): Promise<ExtendedCoin[]>;
|
|
91
|
+
getTransactionHistory(): Promise<ArkTransaction[]>;
|
|
92
|
+
getContractManager(): Promise<IContractManager>;
|
|
93
|
+
sendBitcoin(params: SendBitcoinParams): Promise<string>;
|
|
94
|
+
settle(params?: SettleParams, eventCallback?: (event: SettlementEvent) => void): Promise<string>;
|
|
95
|
+
send(...recipients: Recipient[]): Promise<string>;
|
|
96
|
+
get assetManager(): IAssetManager;
|
|
97
|
+
}
|