@arkade-os/sdk 0.3.13 → 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.
Files changed (240) hide show
  1. package/README.md +483 -54
  2. package/dist/cjs/adapters/expo-db.js +35 -0
  3. package/dist/cjs/asset/assetGroup.js +141 -0
  4. package/dist/cjs/asset/assetId.js +88 -0
  5. package/dist/cjs/asset/assetInput.js +204 -0
  6. package/dist/cjs/asset/assetOutput.js +159 -0
  7. package/dist/cjs/asset/assetRef.js +82 -0
  8. package/dist/cjs/asset/index.js +24 -0
  9. package/dist/cjs/asset/metadata.js +172 -0
  10. package/dist/cjs/asset/packet.js +164 -0
  11. package/dist/cjs/asset/types.js +25 -0
  12. package/dist/cjs/asset/utils.js +105 -0
  13. package/dist/cjs/contracts/arkcontract.js +148 -0
  14. package/dist/cjs/contracts/contractManager.js +436 -0
  15. package/dist/cjs/contracts/contractWatcher.js +567 -0
  16. package/dist/cjs/contracts/handlers/default.js +85 -0
  17. package/dist/cjs/contracts/handlers/delegate.js +89 -0
  18. package/dist/cjs/contracts/handlers/helpers.js +105 -0
  19. package/dist/cjs/contracts/handlers/index.js +19 -0
  20. package/dist/cjs/contracts/handlers/registry.js +89 -0
  21. package/dist/cjs/contracts/handlers/vhtlc.js +193 -0
  22. package/dist/cjs/contracts/index.js +41 -0
  23. package/dist/cjs/contracts/types.js +2 -0
  24. package/dist/cjs/db/manager.js +97 -0
  25. package/dist/cjs/forfeit.js +12 -8
  26. package/dist/cjs/identity/index.js +1 -0
  27. package/dist/cjs/identity/seedIdentity.js +255 -0
  28. package/dist/cjs/index.js +70 -14
  29. package/dist/cjs/intent/index.js +28 -2
  30. package/dist/cjs/providers/ark.js +7 -0
  31. package/dist/cjs/providers/delegator.js +66 -0
  32. package/dist/cjs/providers/expoIndexer.js +5 -0
  33. package/dist/cjs/providers/indexer.js +68 -1
  34. package/dist/cjs/providers/utils.js +1 -0
  35. package/dist/cjs/repositories/contractRepository.js +0 -103
  36. package/dist/cjs/repositories/inMemory/contractRepository.js +55 -0
  37. package/dist/cjs/repositories/inMemory/walletRepository.js +80 -0
  38. package/dist/cjs/repositories/index.js +16 -0
  39. package/dist/cjs/repositories/indexedDB/contractRepository.js +187 -0
  40. package/dist/cjs/repositories/indexedDB/db.js +57 -0
  41. package/dist/cjs/repositories/indexedDB/schema.js +159 -0
  42. package/dist/cjs/repositories/indexedDB/walletRepository.js +338 -0
  43. package/dist/cjs/repositories/indexedDB/websqlAdapter.js +144 -0
  44. package/dist/cjs/repositories/migrations/contractRepositoryImpl.js +127 -0
  45. package/dist/cjs/repositories/migrations/fromStorageAdapter.js +66 -0
  46. package/dist/cjs/repositories/migrations/walletRepositoryImpl.js +180 -0
  47. package/dist/cjs/repositories/walletRepository.js +0 -169
  48. package/dist/cjs/script/base.js +54 -0
  49. package/dist/cjs/script/delegate.js +49 -0
  50. package/dist/cjs/storage/asyncStorage.js +4 -1
  51. package/dist/cjs/storage/fileSystem.js +3 -0
  52. package/dist/cjs/storage/inMemory.js +3 -0
  53. package/dist/cjs/storage/indexedDB.js +5 -1
  54. package/dist/cjs/storage/localStorage.js +3 -0
  55. package/dist/cjs/utils/arkTransaction.js +16 -0
  56. package/dist/cjs/utils/transactionHistory.js +50 -0
  57. package/dist/cjs/wallet/asset-manager.js +338 -0
  58. package/dist/cjs/wallet/asset.js +117 -0
  59. package/dist/cjs/wallet/batch.js +1 -1
  60. package/dist/cjs/wallet/delegator.js +235 -0
  61. package/dist/cjs/wallet/expo/background.js +133 -0
  62. package/dist/cjs/wallet/expo/index.js +9 -0
  63. package/dist/cjs/wallet/expo/wallet.js +231 -0
  64. package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +568 -0
  65. package/dist/cjs/wallet/serviceWorker/wallet.js +383 -102
  66. package/dist/cjs/wallet/utils.js +58 -0
  67. package/dist/cjs/wallet/validation.js +151 -0
  68. package/dist/cjs/wallet/vtxo-manager.js +1 -1
  69. package/dist/cjs/wallet/wallet.js +702 -260
  70. package/dist/cjs/worker/browser/service-worker-manager.js +82 -0
  71. package/dist/cjs/{wallet/serviceWorker → worker/browser}/utils.js +2 -1
  72. package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +78 -0
  73. package/dist/cjs/worker/expo/index.js +12 -0
  74. package/dist/cjs/worker/expo/processors/contractPollProcessor.js +61 -0
  75. package/dist/cjs/worker/expo/processors/index.js +6 -0
  76. package/dist/cjs/worker/expo/taskQueue.js +41 -0
  77. package/dist/cjs/worker/expo/taskRunner.js +57 -0
  78. package/dist/cjs/worker/messageBus.js +252 -0
  79. package/dist/esm/adapters/expo-db.js +27 -0
  80. package/dist/esm/asset/assetGroup.js +137 -0
  81. package/dist/esm/asset/assetId.js +84 -0
  82. package/dist/esm/asset/assetInput.js +199 -0
  83. package/dist/esm/asset/assetOutput.js +154 -0
  84. package/dist/esm/asset/assetRef.js +78 -0
  85. package/dist/esm/asset/index.js +8 -0
  86. package/dist/esm/asset/metadata.js +167 -0
  87. package/dist/esm/asset/packet.js +159 -0
  88. package/dist/esm/asset/types.js +22 -0
  89. package/dist/esm/asset/utils.js +99 -0
  90. package/dist/esm/contracts/arkcontract.js +141 -0
  91. package/dist/esm/contracts/contractManager.js +432 -0
  92. package/dist/esm/contracts/contractWatcher.js +563 -0
  93. package/dist/esm/contracts/handlers/default.js +82 -0
  94. package/dist/esm/contracts/handlers/delegate.js +86 -0
  95. package/dist/esm/contracts/handlers/helpers.js +66 -0
  96. package/dist/esm/contracts/handlers/index.js +12 -0
  97. package/dist/esm/contracts/handlers/registry.js +86 -0
  98. package/dist/esm/contracts/handlers/vhtlc.js +190 -0
  99. package/dist/esm/contracts/index.js +13 -0
  100. package/dist/esm/contracts/types.js +1 -0
  101. package/dist/esm/db/manager.js +92 -0
  102. package/dist/esm/forfeit.js +11 -8
  103. package/dist/esm/identity/index.js +1 -0
  104. package/dist/esm/identity/seedIdentity.js +249 -0
  105. package/dist/esm/index.js +25 -15
  106. package/dist/esm/intent/index.js +28 -2
  107. package/dist/esm/providers/ark.js +7 -0
  108. package/dist/esm/providers/delegator.js +62 -0
  109. package/dist/esm/providers/expoIndexer.js +5 -0
  110. package/dist/esm/providers/indexer.js +68 -1
  111. package/dist/esm/providers/utils.js +1 -0
  112. package/dist/esm/repositories/contractRepository.js +1 -101
  113. package/dist/esm/repositories/inMemory/contractRepository.js +51 -0
  114. package/dist/esm/repositories/inMemory/walletRepository.js +76 -0
  115. package/dist/esm/repositories/index.js +8 -0
  116. package/dist/esm/repositories/indexedDB/contractRepository.js +183 -0
  117. package/dist/esm/repositories/indexedDB/db.js +42 -0
  118. package/dist/esm/repositories/indexedDB/schema.js +155 -0
  119. package/dist/esm/repositories/indexedDB/walletRepository.js +334 -0
  120. package/dist/esm/repositories/indexedDB/websqlAdapter.js +138 -0
  121. package/dist/esm/repositories/migrations/contractRepositoryImpl.js +121 -0
  122. package/dist/esm/repositories/migrations/fromStorageAdapter.js +58 -0
  123. package/dist/esm/repositories/migrations/walletRepositoryImpl.js +176 -0
  124. package/dist/esm/repositories/walletRepository.js +1 -167
  125. package/dist/esm/script/base.js +21 -1
  126. package/dist/esm/script/delegate.js +46 -0
  127. package/dist/esm/storage/asyncStorage.js +4 -1
  128. package/dist/esm/storage/fileSystem.js +3 -0
  129. package/dist/esm/storage/inMemory.js +3 -0
  130. package/dist/esm/storage/indexedDB.js +5 -1
  131. package/dist/esm/storage/localStorage.js +3 -0
  132. package/dist/esm/utils/arkTransaction.js +15 -0
  133. package/dist/esm/utils/transactionHistory.js +50 -0
  134. package/dist/esm/wallet/asset-manager.js +333 -0
  135. package/dist/esm/wallet/asset.js +111 -0
  136. package/dist/esm/wallet/batch.js +1 -1
  137. package/dist/esm/wallet/delegator.js +231 -0
  138. package/dist/esm/wallet/expo/background.js +128 -0
  139. package/dist/esm/wallet/expo/index.js +2 -0
  140. package/dist/esm/wallet/expo/wallet.js +194 -0
  141. package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +564 -0
  142. package/dist/esm/wallet/serviceWorker/wallet.js +382 -101
  143. package/dist/esm/wallet/utils.js +54 -0
  144. package/dist/esm/wallet/validation.js +139 -0
  145. package/dist/esm/wallet/vtxo-manager.js +1 -1
  146. package/dist/esm/wallet/wallet.js +704 -229
  147. package/dist/esm/worker/browser/service-worker-manager.js +76 -0
  148. package/dist/esm/{wallet/serviceWorker → worker/browser}/utils.js +2 -1
  149. package/dist/esm/worker/expo/asyncStorageTaskQueue.js +74 -0
  150. package/dist/esm/worker/expo/index.js +4 -0
  151. package/dist/esm/worker/expo/processors/contractPollProcessor.js +58 -0
  152. package/dist/esm/worker/expo/processors/index.js +1 -0
  153. package/dist/esm/worker/expo/taskQueue.js +37 -0
  154. package/dist/esm/worker/expo/taskRunner.js +54 -0
  155. package/dist/esm/worker/messageBus.js +248 -0
  156. package/dist/types/adapters/expo-db.d.ts +7 -0
  157. package/dist/types/asset/assetGroup.d.ts +28 -0
  158. package/dist/types/asset/assetId.d.ts +19 -0
  159. package/dist/types/asset/assetInput.d.ts +46 -0
  160. package/dist/types/asset/assetOutput.d.ts +39 -0
  161. package/dist/types/asset/assetRef.d.ts +25 -0
  162. package/dist/types/asset/index.d.ts +8 -0
  163. package/dist/types/asset/metadata.d.ts +37 -0
  164. package/dist/types/asset/packet.d.ts +27 -0
  165. package/dist/types/asset/types.d.ts +18 -0
  166. package/dist/types/asset/utils.d.ts +21 -0
  167. package/dist/types/contracts/arkcontract.d.ts +101 -0
  168. package/dist/types/contracts/contractManager.d.ts +331 -0
  169. package/dist/types/contracts/contractWatcher.d.ts +192 -0
  170. package/dist/types/contracts/handlers/default.d.ts +19 -0
  171. package/dist/types/contracts/handlers/delegate.d.ts +21 -0
  172. package/dist/types/contracts/handlers/helpers.d.ts +18 -0
  173. package/dist/types/contracts/handlers/index.d.ts +7 -0
  174. package/dist/types/contracts/handlers/registry.d.ts +65 -0
  175. package/dist/types/contracts/handlers/vhtlc.d.ts +32 -0
  176. package/dist/types/contracts/index.d.ts +14 -0
  177. package/dist/types/contracts/types.d.ts +222 -0
  178. package/dist/types/db/manager.d.ts +22 -0
  179. package/dist/types/forfeit.d.ts +2 -1
  180. package/dist/types/identity/index.d.ts +1 -0
  181. package/dist/types/identity/seedIdentity.d.ts +128 -0
  182. package/dist/types/index.d.ts +21 -12
  183. package/dist/types/intent/index.d.ts +2 -1
  184. package/dist/types/providers/ark.d.ts +11 -2
  185. package/dist/types/providers/delegator.d.ts +29 -0
  186. package/dist/types/providers/indexer.d.ts +11 -1
  187. package/dist/types/repositories/contractRepository.d.ts +30 -19
  188. package/dist/types/repositories/inMemory/contractRepository.d.ts +17 -0
  189. package/dist/types/repositories/inMemory/walletRepository.d.ts +26 -0
  190. package/dist/types/repositories/index.d.ts +7 -0
  191. package/dist/types/repositories/indexedDB/contractRepository.d.ts +21 -0
  192. package/dist/types/repositories/indexedDB/db.d.ts +56 -0
  193. package/dist/types/repositories/indexedDB/schema.d.ts +8 -0
  194. package/dist/types/repositories/indexedDB/walletRepository.d.ts +25 -0
  195. package/dist/types/repositories/indexedDB/websqlAdapter.d.ts +49 -0
  196. package/dist/types/repositories/migrations/contractRepositoryImpl.d.ts +24 -0
  197. package/dist/types/repositories/migrations/fromStorageAdapter.d.ts +19 -0
  198. package/dist/types/repositories/migrations/walletRepositoryImpl.d.ts +27 -0
  199. package/dist/types/repositories/walletRepository.d.ts +13 -24
  200. package/dist/types/script/base.d.ts +1 -0
  201. package/dist/types/script/delegate.d.ts +36 -0
  202. package/dist/types/storage/asyncStorage.d.ts +4 -0
  203. package/dist/types/storage/fileSystem.d.ts +3 -0
  204. package/dist/types/storage/inMemory.d.ts +3 -0
  205. package/dist/types/storage/index.d.ts +3 -0
  206. package/dist/types/storage/indexedDB.d.ts +3 -0
  207. package/dist/types/storage/localStorage.d.ts +3 -0
  208. package/dist/types/utils/arkTransaction.d.ts +6 -0
  209. package/dist/types/wallet/asset-manager.d.ts +78 -0
  210. package/dist/types/wallet/asset.d.ts +21 -0
  211. package/dist/types/wallet/batch.d.ts +1 -1
  212. package/dist/types/wallet/delegator.d.ts +24 -0
  213. package/dist/types/wallet/expo/background.d.ts +66 -0
  214. package/dist/types/wallet/expo/index.d.ts +4 -0
  215. package/dist/types/wallet/expo/wallet.d.ts +97 -0
  216. package/dist/types/wallet/index.d.ts +75 -2
  217. package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +366 -0
  218. package/dist/types/wallet/serviceWorker/wallet.d.ts +20 -11
  219. package/dist/types/wallet/utils.d.ts +12 -1
  220. package/dist/types/wallet/validation.d.ts +24 -0
  221. package/dist/types/wallet/wallet.d.ts +111 -17
  222. package/dist/types/worker/browser/service-worker-manager.d.ts +21 -0
  223. package/dist/types/{wallet/serviceWorker → worker/browser}/utils.d.ts +2 -1
  224. package/dist/types/worker/expo/asyncStorageTaskQueue.d.ts +46 -0
  225. package/dist/types/worker/expo/index.d.ts +7 -0
  226. package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +14 -0
  227. package/dist/types/worker/expo/processors/index.d.ts +1 -0
  228. package/dist/types/worker/expo/taskQueue.d.ts +50 -0
  229. package/dist/types/worker/expo/taskRunner.d.ts +42 -0
  230. package/dist/types/worker/messageBus.d.ts +109 -0
  231. package/package.json +65 -11
  232. package/dist/cjs/wallet/serviceWorker/request.js +0 -78
  233. package/dist/cjs/wallet/serviceWorker/response.js +0 -222
  234. package/dist/cjs/wallet/serviceWorker/worker.js +0 -655
  235. package/dist/esm/wallet/serviceWorker/request.js +0 -75
  236. package/dist/esm/wallet/serviceWorker/response.js +0 -219
  237. package/dist/esm/wallet/serviceWorker/worker.js +0 -651
  238. package/dist/types/wallet/serviceWorker/request.d.ts +0 -74
  239. package/dist/types/wallet/serviceWorker/response.d.ts +0 -123
  240. package/dist/types/wallet/serviceWorker/worker.d.ts +0 -53
@@ -0,0 +1,128 @@
1
+ import { Identity, ReadonlyIdentity } from ".";
2
+ import { Transaction } from "../utils/transaction";
3
+ import { SignerSession } from "../tree/signingSession";
4
+ /** Use default BIP86 derivation with network selection. */
5
+ export interface NetworkOptions {
6
+ /** Mainnet (coin type 0) or testnet (coin type 1). */
7
+ isMainnet: boolean;
8
+ }
9
+ /** Use a custom output descriptor for derivation. */
10
+ export interface DescriptorOptions {
11
+ /** Custom output descriptor that determines the derivation path. */
12
+ descriptor: string;
13
+ }
14
+ /** Either default BIP86 derivation (with optional network) or a custom descriptor. */
15
+ export type SeedIdentityOptions = NetworkOptions | DescriptorOptions;
16
+ export type MnemonicOptions = SeedIdentityOptions & {
17
+ /** Optional BIP39 passphrase for additional seed entropy. */
18
+ passphrase?: string;
19
+ };
20
+ /**
21
+ * Seed-based identity derived from a raw seed and an output descriptor.
22
+ *
23
+ * This is the recommended identity type for most applications. It uses
24
+ * standard BIP86 (Taproot) derivation by default and stores an output
25
+ * descriptor for interoperability with other wallets. The descriptor
26
+ * format is HD-ready, allowing future support for multiple addresses
27
+ * and change derivation.
28
+ *
29
+ * Prefer this (or {@link MnemonicIdentity}) over `SingleKey` for new
30
+ * integrations — `SingleKey` exists for backward compatibility with
31
+ * raw nsec-style keys.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const seed = mnemonicToSeedSync(mnemonic);
36
+ *
37
+ * // Testnet (BIP86 path m/86'/1'/0'/0/0)
38
+ * const identity = SeedIdentity.fromSeed(seed, { isMainnet: false });
39
+ *
40
+ * // Mainnet (BIP86 path m/86'/0'/0'/0/0)
41
+ * const identity = SeedIdentity.fromSeed(seed, { isMainnet: true });
42
+ *
43
+ * // Custom descriptor
44
+ * const identity = SeedIdentity.fromSeed(seed, { descriptor });
45
+ * ```
46
+ */
47
+ export declare class SeedIdentity implements Identity {
48
+ protected readonly seed: Uint8Array;
49
+ private readonly derivedKey;
50
+ readonly descriptor: string;
51
+ constructor(seed: Uint8Array, descriptor: string);
52
+ /**
53
+ * Creates a SeedIdentity from a raw 64-byte seed.
54
+ *
55
+ * Pass `{ isMainnet }` for default BIP86 derivation, or
56
+ * `{ descriptor }` for a custom derivation path.
57
+ *
58
+ * @param seed - 64-byte seed (typically from mnemonicToSeedSync)
59
+ * @param opts - Network selection or custom descriptor.
60
+ */
61
+ static fromSeed(seed: Uint8Array, opts: SeedIdentityOptions): SeedIdentity;
62
+ xOnlyPublicKey(): Promise<Uint8Array>;
63
+ compressedPublicKey(): Promise<Uint8Array>;
64
+ sign(tx: Transaction, inputIndexes?: number[]): Promise<Transaction>;
65
+ signMessage(message: Uint8Array, signatureType?: "schnorr" | "ecdsa"): Promise<Uint8Array>;
66
+ signerSession(): SignerSession;
67
+ /**
68
+ * Converts to a watch-only identity that cannot sign.
69
+ */
70
+ toReadonly(): Promise<ReadonlyDescriptorIdentity>;
71
+ }
72
+ /**
73
+ * Mnemonic-based identity derived from a BIP39 phrase.
74
+ *
75
+ * This is the most user-friendly identity type — recommended for wallet
76
+ * applications where users manage their own backup phrase. Extends
77
+ * {@link SeedIdentity} with mnemonic validation and optional passphrase
78
+ * support.
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const identity = MnemonicIdentity.fromMnemonic(
83
+ * 'abandon abandon abandon ...',
84
+ * { isMainnet: true, passphrase: 'secret' }
85
+ * );
86
+ * ```
87
+ */
88
+ export declare class MnemonicIdentity extends SeedIdentity {
89
+ private constructor();
90
+ /**
91
+ * Creates a MnemonicIdentity from a BIP39 mnemonic phrase.
92
+ *
93
+ * Pass `{ isMainnet }` for default BIP86 derivation, or
94
+ * `{ descriptor }` for a custom derivation path.
95
+ *
96
+ * @param phrase - BIP39 mnemonic phrase (12 or 24 words)
97
+ * @param opts - Network selection or custom descriptor, plus optional passphrase
98
+ */
99
+ static fromMnemonic(phrase: string, opts: MnemonicOptions): MnemonicIdentity;
100
+ }
101
+ /**
102
+ * Watch-only identity from an output descriptor.
103
+ *
104
+ * Can derive public keys but cannot sign transactions. Use this for
105
+ * watch-only wallets or when sharing identity information without
106
+ * exposing private keys.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const descriptor = "tr([fingerprint/86'/0'/0']xpub.../0/0)";
111
+ * const readonly = ReadonlyDescriptorIdentity.fromDescriptor(descriptor);
112
+ * const pubKey = await readonly.xOnlyPublicKey();
113
+ * ```
114
+ */
115
+ export declare class ReadonlyDescriptorIdentity implements ReadonlyIdentity {
116
+ readonly descriptor: string;
117
+ private readonly xOnlyPubKey;
118
+ private readonly compressedPubKey;
119
+ private constructor();
120
+ /**
121
+ * Creates a ReadonlyDescriptorIdentity from an output descriptor.
122
+ *
123
+ * @param descriptor - Taproot descriptor: tr([fingerprint/path']xpub.../child/path)
124
+ */
125
+ static fromDescriptor(descriptor: string): ReadonlyDescriptorIdentity;
126
+ xOnlyPublicKey(): Promise<Uint8Array>;
127
+ compressedPublicKey(): Promise<Uint8Array>;
128
+ }
@@ -1,27 +1,29 @@
1
1
  import { Transaction } from "./utils/transaction";
2
2
  import { SingleKey, ReadonlySingleKey } from "./identity/singleKey";
3
+ import { SeedIdentity, MnemonicIdentity, ReadonlyDescriptorIdentity } from "./identity/seedIdentity";
4
+ import type { SeedIdentityOptions, MnemonicOptions, NetworkOptions, DescriptorOptions } from "./identity/seedIdentity";
3
5
  import { Identity, ReadonlyIdentity } from "./identity";
4
6
  import { ArkAddress } from "./script/address";
5
7
  import { VHTLC } from "./script/vhtlc";
6
8
  import { DefaultVtxo } from "./script/default";
7
- import { VtxoScript, EncodedVtxoScript, TapLeafScript, TapTreeCoder } from "./script/base";
8
- import { TxType, IWallet, IReadonlyWallet, BaseWalletConfig, WalletConfig, ReadonlyWalletConfig, ProviderClass, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, GetVtxosFilter, TapLeaves, isSpendable, isSubdust, isRecoverable, isExpired } from "./wallet";
9
+ import { DelegateVtxo } from "./script/delegate";
10
+ import { MessageHandler, RequestEnvelope, ResponseEnvelope, MessageBus } from "./worker/messageBus";
11
+ import { VtxoScript, EncodedVtxoScript, TapLeafScript, TapTreeCoder, getSequence } from "./script/base";
12
+ import { TxType, IWallet, IReadonlyWallet, BaseWalletConfig, WalletConfig, ReadonlyWalletConfig, ProviderClass, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, GetVtxosFilter, TapLeaves, StorageConfig, isSpendable, isSubdust, isRecoverable, isExpired, Asset, Recipient, IssuanceParams, IssuanceResult, ReissuanceParams, BurnParams, AssetDetails, AssetMetadata, KnownMetadata } from "./wallet";
9
13
  import { Batch } from "./wallet/batch";
10
- import { Wallet, ReadonlyWallet, waitForIncomingFunds, IncomingFunds, getSequence } from "./wallet/wallet";
14
+ import { Wallet, ReadonlyWallet, waitForIncomingFunds, IncomingFunds } from "./wallet/wallet";
11
15
  import { TxTree, TxTreeNode } from "./tree/txTree";
12
16
  import { SignerSession, TreeNonces, TreePartialSigs } from "./tree/signingSession";
13
17
  import { Ramps } from "./wallet/ramps";
14
18
  import { isVtxoExpiringSoon, VtxoManager } from "./wallet/vtxo-manager";
15
19
  import { ServiceWorkerWallet, ServiceWorkerReadonlyWallet } from "./wallet/serviceWorker/wallet";
16
20
  import { OnchainWallet } from "./wallet/onchain";
17
- import { setupServiceWorker } from "./wallet/serviceWorker/utils";
18
- import { Worker } from "./wallet/serviceWorker/worker";
19
- import { Request } from "./wallet/serviceWorker/request";
20
- import { Response } from "./wallet/serviceWorker/response";
21
+ import { setupServiceWorker } from "./worker/browser/utils";
21
22
  import { ESPLORA_URL, EsploraProvider, OnchainProvider, ExplorerTransaction } from "./providers/onchain";
22
23
  import { RestArkProvider, ArkProvider, SettlementEvent, SettlementEventType, ArkInfo, SignedIntent, Output, TxNotification, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, ScheduledSession, FeeInfo } from "./providers/ark";
24
+ import { DelegatorProvider, DelegateInfo, DelegateOptions, RestDelegatorProvider } from "./providers/delegator";
23
25
  import { CLTVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CSVMultisigTapscript, decodeTapscript, MultisigTapscript, TapscriptType, ArkTapscript, RelativeTimelock } from "./script/tapscript";
24
- import { hasBoardingTxExpired, buildOffchainTx, verifyTapscriptSignatures, ArkTxInput, OffchainTx, combineTapscriptSigs } from "./utils/arkTransaction";
26
+ import { hasBoardingTxExpired, buildOffchainTx, verifyTapscriptSignatures, ArkTxInput, OffchainTx, combineTapscriptSigs, isValidArkAddress } from "./utils/arkTransaction";
25
27
  import { VtxoTaprootTree, ConditionWitness, getArkPsbtFields, setArkPsbtField, ArkPsbtFieldCoder, ArkPsbtFieldKey, ArkPsbtFieldKeyType, CosignerPublicKey, VtxoTreeExpiry } from "./utils/unknownFields";
26
28
  import { Intent } from "./intent";
27
29
  import { ArkNote } from "./arknote";
@@ -31,11 +33,18 @@ import { Nonces } from "./musig2/nonces";
31
33
  import { PartialSig } from "./musig2/sign";
32
34
  import { AnchorBumper, P2A } from "./utils/anchor";
33
35
  import { Unroll } from "./wallet/unroll";
34
- import { WalletRepositoryImpl } from "./repositories/walletRepository";
35
- import { ContractRepositoryImpl } from "./repositories/contractRepository";
36
36
  import { ArkError, maybeArkError } from "./providers/errors";
37
37
  import { validateVtxoTxGraph, validateConnectorsTxGraph } from "./tree/validation";
38
38
  import { buildForfeitTx } from "./forfeit";
39
+ import { IndexedDBWalletRepository, IndexedDBContractRepository, InMemoryWalletRepository, InMemoryContractRepository, MIGRATION_KEY, migrateWalletRepository, requiresMigration, getMigrationStatus, rollbackMigration, WalletRepositoryImpl, ContractRepositoryImpl, WalletRepository, ContractRepository } from "./repositories";
40
+ import type { MigrationStatus } from "./repositories";
41
+ import { DelegatorManagerImpl, DelegatorManager } from "./wallet/delegator";
39
42
  export * from "./arkfee";
40
- export { Wallet, ReadonlyWallet, SingleKey, ReadonlySingleKey, OnchainWallet, Ramps, VtxoManager, ESPLORA_URL, EsploraProvider, RestArkProvider, RestIndexerProvider, ArkAddress, DefaultVtxo, VtxoScript, VHTLC, TxType, IndexerTxType, ChainTxType, SettlementEventType, setupServiceWorker, Worker, ServiceWorkerWallet, ServiceWorkerReadonlyWallet, Request, Response, decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, TapTreeCoder, ArkPsbtFieldKey, ArkPsbtFieldKeyType, setArkPsbtField, getArkPsbtFields, CosignerPublicKey, VtxoTreeExpiry, VtxoTaprootTree, ConditionWitness, buildOffchainTx, verifyTapscriptSignatures, waitForIncomingFunds, hasBoardingTxExpired, combineTapscriptSigs, isVtxoExpiringSoon, ArkNote, networks, WalletRepositoryImpl, ContractRepositoryImpl, Intent, TxTree, P2A, Unroll, Transaction, ArkError, maybeArkError, Batch, validateVtxoTxGraph, validateConnectorsTxGraph, buildForfeitTx, isRecoverable, isSpendable, isSubdust, isExpired, getSequence, };
41
- export type { Identity, ReadonlyIdentity, IWallet, IReadonlyWallet, BaseWalletConfig, WalletConfig, ReadonlyWalletConfig, ProviderClass, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, ArkTxInput, OffchainTx, TapLeaves, IncomingFunds, IndexerProvider, PageResponse, BatchInfo, ChainTx, CommitmentTx, TxHistoryRecord, Vtxo, VtxoChain, Tx, OnchainProvider, ArkProvider, SettlementEvent, FeeInfo, ArkInfo, SignedIntent, Output, TxNotification, ExplorerTransaction, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, ScheduledSession, PaginationOptions, SubscriptionResponse, SubscriptionHeartbeat, SubscriptionEvent, Network, NetworkName, ArkTapscript, RelativeTimelock, EncodedVtxoScript, TapLeafScript, SignerSession, TreeNonces, TreePartialSigs, GetVtxosFilter, Nonces, PartialSig, ArkPsbtFieldCoder, TxTreeNode, AnchorBumper, };
43
+ export * as asset from "./asset";
44
+ import { ContractManager, ContractWatcher, contractHandlers, DefaultContractHandler, DelegateContractHandler, VHTLCContractHandler, encodeArkContract, decodeArkContract, contractFromArkContract, contractFromArkContractWithAddress, isArkContract } from "./contracts";
45
+ import type { Contract, ContractVtxo, ContractState, ContractEvent, ContractEventCallback, ContractBalance, ContractWithVtxos, ContractHandler, PathSelection, PathContext, ContractManagerConfig, CreateContractParams, ContractWatcherConfig, ParsedArkContract, DefaultContractParams, DelegateContractParams, VHTLCContractParams } from "./contracts";
46
+ import { IContractManager } from "./contracts/contractManager";
47
+ import { closeDatabase, openDatabase } from "./db/manager";
48
+ import { WalletMessageHandler } from "./wallet/serviceWorker/wallet-message-handler";
49
+ export { Wallet, ReadonlyWallet, SingleKey, ReadonlySingleKey, SeedIdentity, MnemonicIdentity, ReadonlyDescriptorIdentity, OnchainWallet, Ramps, VtxoManager, DelegatorManagerImpl, RestDelegatorProvider, ESPLORA_URL, EsploraProvider, RestArkProvider, RestIndexerProvider, ArkAddress, DefaultVtxo, DelegateVtxo, VtxoScript, VHTLC, TxType, IndexerTxType, ChainTxType, SettlementEventType, setupServiceWorker, MessageBus, WalletMessageHandler, ServiceWorkerWallet, ServiceWorkerReadonlyWallet, decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, TapTreeCoder, ArkPsbtFieldKey, ArkPsbtFieldKeyType, setArkPsbtField, getArkPsbtFields, CosignerPublicKey, VtxoTreeExpiry, VtxoTaprootTree, ConditionWitness, buildOffchainTx, verifyTapscriptSignatures, waitForIncomingFunds, hasBoardingTxExpired, combineTapscriptSigs, isVtxoExpiringSoon, isValidArkAddress, ArkNote, networks, closeDatabase, openDatabase, IndexedDBWalletRepository, IndexedDBContractRepository, InMemoryWalletRepository, InMemoryContractRepository, MIGRATION_KEY, migrateWalletRepository, requiresMigration, getMigrationStatus, rollbackMigration, WalletRepositoryImpl, ContractRepositoryImpl, Intent, TxTree, P2A, Unroll, Transaction, ArkError, maybeArkError, Batch, validateVtxoTxGraph, validateConnectorsTxGraph, buildForfeitTx, isRecoverable, isSpendable, isSubdust, isExpired, getSequence, ContractManager, ContractWatcher, contractHandlers, DefaultContractHandler, DelegateContractHandler, VHTLCContractHandler, encodeArkContract, decodeArkContract, contractFromArkContract, contractFromArkContractWithAddress, isArkContract, };
50
+ export type { Identity, ReadonlyIdentity, IWallet, IReadonlyWallet, BaseWalletConfig, WalletConfig, ReadonlyWalletConfig, ProviderClass, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, ArkTxInput, OffchainTx, TapLeaves, IncomingFunds, SeedIdentityOptions, MnemonicOptions, NetworkOptions, DescriptorOptions, IndexerProvider, PageResponse, BatchInfo, ChainTx, CommitmentTx, TxHistoryRecord, Vtxo, VtxoChain, Tx, OnchainProvider, ArkProvider, SettlementEvent, FeeInfo, ArkInfo, SignedIntent, Output, TxNotification, ExplorerTransaction, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, ScheduledSession, PaginationOptions, SubscriptionResponse, SubscriptionHeartbeat, SubscriptionEvent, Network, NetworkName, ArkTapscript, RelativeTimelock, EncodedVtxoScript, TapLeafScript, SignerSession, TreeNonces, TreePartialSigs, GetVtxosFilter, Asset, Recipient, IssuanceParams, IssuanceResult, ReissuanceParams, BurnParams, AssetDetails, AssetMetadata, KnownMetadata, Nonces, PartialSig, ArkPsbtFieldCoder, TxTreeNode, AnchorBumper, StorageConfig, Contract, ContractVtxo, ContractState, ContractEvent, ContractEventCallback, ContractBalance, ContractWithVtxos, ContractHandler, IContractManager, PathSelection, PathContext, ContractManagerConfig, CreateContractParams, ContractWatcherConfig, ParsedArkContract, DefaultContractParams, DelegateContractParams, VHTLCContractParams, MessageHandler, RequestEnvelope, ResponseEnvelope, DelegatorManager, DelegatorProvider, DelegateInfo, DelegateOptions, WalletRepository, ContractRepository, MigrationStatus, };
@@ -1,5 +1,6 @@
1
1
  import { TransactionInput, TransactionOutput } from "@scure/btc-signer/psbt.js";
2
2
  import { Transaction } from "../utils/transaction";
3
+ import { ExtendedCoin } from "../wallet";
3
4
  /**
4
5
  * Intent proof implementation for Bitcoin message signing.
5
6
  *
@@ -37,7 +38,7 @@ export declare namespace Intent {
37
38
  * @param outputs - Optional array of transaction outputs
38
39
  * @returns An unsigned Intent proof transaction
39
40
  */
40
- function create(message: string | Message, inputs: TransactionInput[], outputs?: TransactionOutput[]): Proof;
41
+ function create(message: string | Message, ins: (TransactionInput | ExtendedCoin)[], outputs?: TransactionOutput[]): Proof;
41
42
  function fee(proof: Proof): number;
42
43
  type RegisterMessage = {
43
44
  type: "register";
@@ -15,7 +15,8 @@ export declare enum SettlementEventType {
15
15
  TreeSigningStarted = "tree_signing_started",
16
16
  TreeNonces = "tree_nonces",
17
17
  TreeTx = "tree_tx",
18
- TreeSignature = "tree_signature"
18
+ TreeSignature = "tree_signature",
19
+ StreamStarted = "stream_started"
19
20
  }
20
21
  export type BatchFinalizationEvent = {
21
22
  type: SettlementEventType.BatchFinalization;
@@ -66,7 +67,11 @@ export type TreeSignatureEvent = {
66
67
  txid: string;
67
68
  signature: string;
68
69
  };
69
- export type SettlementEvent = BatchFinalizationEvent | BatchFinalizedEvent | BatchFailedEvent | TreeSigningStartedEvent | TreeNoncesEvent | BatchStartedEvent | TreeTxEvent | TreeSignatureEvent;
70
+ export type StreamStartedEvent = {
71
+ type: SettlementEventType.StreamStarted;
72
+ id: string;
73
+ };
74
+ export type SettlementEvent = BatchFinalizationEvent | BatchFinalizedEvent | BatchFailedEvent | TreeSigningStartedEvent | TreeNoncesEvent | BatchStartedEvent | TreeTxEvent | TreeSignatureEvent | StreamStartedEvent;
70
75
  export interface ScheduledSession {
71
76
  duration: bigint;
72
77
  fees: FeeInfo;
@@ -229,6 +234,9 @@ declare namespace ProtoTypes {
229
234
  txid: string;
230
235
  signature: string;
231
236
  }
237
+ interface StreamStartedEvent {
238
+ id: string;
239
+ }
232
240
  interface Heartbeat {
233
241
  }
234
242
  export interface VtxoData {
@@ -259,6 +267,7 @@ declare namespace ProtoTypes {
259
267
  treeNonces?: TreeNoncesEvent;
260
268
  treeTx?: TreeTxEvent;
261
269
  treeSignature?: TreeSignatureEvent;
270
+ streamStarted?: StreamStartedEvent;
262
271
  heartbeat?: Heartbeat;
263
272
  }
264
273
  export interface GetTransactionsStreamResponse {
@@ -0,0 +1,29 @@
1
+ import { Intent } from "../intent";
2
+ import { SignedIntent } from "./ark";
3
+ export interface DelegateInfo {
4
+ pubkey: string;
5
+ fee: string;
6
+ delegatorAddress: string;
7
+ }
8
+ export interface DelegateOptions {
9
+ rejectReplace?: boolean;
10
+ }
11
+ export interface DelegatorProvider {
12
+ delegate(intent: SignedIntent<Intent.RegisterMessage>, forfeitTxs: string[], options?: DelegateOptions): Promise<void>;
13
+ getDelegateInfo(): Promise<DelegateInfo>;
14
+ }
15
+ /**
16
+ * REST-based Delegator provider implementation.
17
+ * @example
18
+ * ```typescript
19
+ * const provider = new RestDelegatorProvider('https://delegator.example.com');
20
+ * const info = await provider.getDelegateInfo();
21
+ * await provider.delegate(intent, forfeitTxs);
22
+ * ```
23
+ */
24
+ export declare class RestDelegatorProvider implements DelegatorProvider {
25
+ url: string;
26
+ constructor(url: string);
27
+ delegate(intent: SignedIntent<Intent.RegisterMessage>, forfeitTxs: string[], options?: DelegateOptions): Promise<void>;
28
+ getDelegateInfo(): Promise<DelegateInfo>;
29
+ }
@@ -1,4 +1,4 @@
1
- import { Outpoint, VirtualCoin } from "../wallet";
1
+ import { AssetDetails, Outpoint, VirtualCoin } from "../wallet";
2
2
  export type PaginationOptions = {
3
3
  pageIndex?: number;
4
4
  pageSize?: number;
@@ -16,8 +16,11 @@ export declare enum ChainTxType {
16
16
  CHECKPOINT = "INDEXER_CHAINED_TX_TYPE_CHECKPOINT"
17
17
  }
18
18
  export interface PageResponse {
19
+ /** Current page index **/
19
20
  current: number;
21
+ /** Next page index **/
20
22
  next: number;
23
+ /** Total pages given the page-size used in the query **/
21
24
  total: number;
22
25
  }
23
26
  export interface BatchInfo {
@@ -56,6 +59,10 @@ export interface TxHistoryRecord {
56
59
  isSettled: boolean;
57
60
  settledBy: string;
58
61
  }
62
+ export interface VtxoAsset {
63
+ assetId: string;
64
+ amount: string;
65
+ }
59
66
  export interface Vtxo {
60
67
  outpoint: Outpoint;
61
68
  createdAt: string;
@@ -70,6 +77,7 @@ export interface Vtxo {
70
77
  commitmentTxids: string[];
71
78
  settledBy?: string;
72
79
  arkTxid?: string;
80
+ assets?: VtxoAsset[];
73
81
  }
74
82
  export interface VtxoChain {
75
83
  chain: ChainTx[];
@@ -130,6 +138,7 @@ export interface IndexerProvider {
130
138
  vtxos: VirtualCoin[];
131
139
  page?: PageResponse;
132
140
  }>;
141
+ getAssetDetails(assetId: string): Promise<AssetDetails>;
133
142
  subscribeForScripts(scripts: string[], subscriptionId?: string): Promise<string>;
134
143
  unsubscribeForScripts(subscriptionId: string, scripts?: string[]): Promise<void>;
135
144
  }
@@ -181,6 +190,7 @@ export declare class RestIndexerProvider implements IndexerProvider {
181
190
  vtxos: VirtualCoin[];
182
191
  page?: PageResponse;
183
192
  }>;
193
+ getAssetDetails(assetId: string): Promise<AssetDetails>;
184
194
  subscribeForScripts(scripts: string[], subscriptionId?: string): Promise<string>;
185
195
  unsubscribeForScripts(subscriptionId: string, scripts?: string[]): Promise<void>;
186
196
  }
@@ -1,21 +1,32 @@
1
- import { StorageAdapter } from "../storage";
2
- export interface ContractRepository {
3
- getContractData<T>(contractId: string, key: string): Promise<T | null>;
4
- setContractData<T>(contractId: string, key: string, data: T): Promise<void>;
5
- deleteContractData(contractId: string, key: string): Promise<void>;
6
- clearContractData(): Promise<void>;
7
- getContractCollection<T>(contractType: string): Promise<ReadonlyArray<T>>;
8
- saveToContractCollection<T, K extends keyof T>(contractType: string, item: T, idField: K): Promise<void>;
9
- removeFromContractCollection<T, K extends keyof T>(contractType: string, id: T[K], idField: K): Promise<void>;
1
+ import { Contract, ContractState } from "../contracts/types";
2
+ /**
3
+ * Filter options for querying contracts.
4
+ */
5
+ export interface ContractFilter {
6
+ /** Filter by script(s) */
7
+ script?: string | string[];
8
+ /** Filter by state(s) */
9
+ state?: ContractState | ContractState[];
10
+ /** Filter by contract type(s) */
11
+ type?: string | string[];
10
12
  }
11
- export declare class ContractRepositoryImpl implements ContractRepository {
12
- private storage;
13
- constructor(storage: StorageAdapter);
14
- getContractData<T>(contractId: string, key: string): Promise<T | null>;
15
- setContractData<T>(contractId: string, key: string, data: T): Promise<void>;
16
- deleteContractData(contractId: string, key: string): Promise<void>;
17
- getContractCollection<T>(contractType: string): Promise<ReadonlyArray<T>>;
18
- saveToContractCollection<T, K extends keyof T>(contractType: string, item: T, idField: K): Promise<void>;
19
- removeFromContractCollection<T, K extends keyof T>(contractType: string, id: T[K], idField: K): Promise<void>;
20
- clearContractData(): Promise<void>;
13
+ export interface ContractRepository extends AsyncDisposable {
14
+ readonly version: 1;
15
+ /**
16
+ * Clear all data from storage.
17
+ */
18
+ clear(): Promise<void>;
19
+ /**
20
+ * Get contracts with optional filter.
21
+ * Returns all contracts if no filter provided.
22
+ */
23
+ getContracts(filter?: ContractFilter): Promise<Contract[]>;
24
+ /**
25
+ * Save or update a contract.
26
+ */
27
+ saveContract(contract: Contract): Promise<void>;
28
+ /**
29
+ * Delete a contract by script.
30
+ */
31
+ deleteContract(script: string): Promise<void>;
21
32
  }
@@ -0,0 +1,17 @@
1
+ import { ContractFilter, ContractRepository } from "../contractRepository";
2
+ import { Contract } from "../../contracts";
3
+ /**
4
+ * In-memory implementation of ContractRepository.
5
+ * Data is ephemeral and scoped to the instance.
6
+ */
7
+ export declare class InMemoryContractRepository implements ContractRepository {
8
+ readonly version: 1;
9
+ private readonly contractData;
10
+ private readonly collections;
11
+ private readonly contractsByScript;
12
+ clear(): Promise<void>;
13
+ getContracts(filter?: ContractFilter): Promise<Contract[]>;
14
+ saveContract(contract: Contract): Promise<void>;
15
+ deleteContract(script: string): Promise<void>;
16
+ [Symbol.asyncDispose](): Promise<void>;
17
+ }
@@ -0,0 +1,26 @@
1
+ import { ArkTransaction, ExtendedCoin, ExtendedVirtualCoin } from "../../wallet";
2
+ import { WalletRepository, WalletState } from "../walletRepository";
3
+ /**
4
+ * In-memory implementation of WalletRepository.
5
+ * Data is ephemeral and scoped to the instance.
6
+ */
7
+ export declare class InMemoryWalletRepository implements WalletRepository {
8
+ readonly version: 1;
9
+ private readonly vtxosByAddress;
10
+ private readonly utxosByAddress;
11
+ private readonly txsByAddress;
12
+ private walletState;
13
+ getVtxos(address: string): Promise<ExtendedVirtualCoin[]>;
14
+ saveVtxos(address: string, vtxos: ExtendedVirtualCoin[]): Promise<void>;
15
+ deleteVtxos(address: string): Promise<void>;
16
+ getUtxos(address: string): Promise<ExtendedCoin[]>;
17
+ saveUtxos(address: string, utxos: ExtendedCoin[]): Promise<void>;
18
+ deleteUtxos(address: string): Promise<void>;
19
+ getTransactionHistory(address: string): Promise<ArkTransaction[]>;
20
+ saveTransactions(address: string, txs: ArkTransaction[]): Promise<void>;
21
+ deleteTransactions(address: string): Promise<void>;
22
+ getWalletState(): Promise<WalletState | null>;
23
+ saveWalletState(state: WalletState): Promise<void>;
24
+ clear(): Promise<void>;
25
+ [Symbol.asyncDispose](): Promise<void>;
26
+ }
@@ -1,2 +1,9 @@
1
1
  export * from "./walletRepository";
2
2
  export * from "./contractRepository";
3
+ export * from "./inMemory/walletRepository";
4
+ export * from "./inMemory/contractRepository";
5
+ export * from "./indexedDB/contractRepository";
6
+ export * from "./indexedDB/walletRepository";
7
+ export { MIGRATION_KEY, migrateWalletRepository, requiresMigration, getMigrationStatus, rollbackMigration, type MigrationStatus, } from "./migrations/fromStorageAdapter";
8
+ export { WalletRepositoryImpl } from "./migrations/walletRepositoryImpl";
9
+ export { ContractRepositoryImpl } from "./migrations/contractRepositoryImpl";
@@ -0,0 +1,21 @@
1
+ import { Contract } from "../../contracts";
2
+ import { ContractFilter, ContractRepository } from "../contractRepository";
3
+ /**
4
+ * IndexedDB-based implementation of ContractRepository.
5
+ *
6
+ * Data is stored as JSON strings in key/value stores.
7
+ */
8
+ export declare class IndexedDBContractRepository implements ContractRepository {
9
+ private readonly dbName;
10
+ readonly version: 1;
11
+ private db;
12
+ constructor(dbName?: string);
13
+ clear(): Promise<void>;
14
+ getContracts(filter?: ContractFilter): Promise<Contract[]>;
15
+ saveContract(contract: Contract): Promise<void>;
16
+ deleteContract(script: string): Promise<void>;
17
+ private getContractsByIndexValues;
18
+ private applyContractFilter;
19
+ private getDB;
20
+ [Symbol.asyncDispose](): Promise<void>;
21
+ }
@@ -0,0 +1,56 @@
1
+ import { TapLeafScript } from "../../script/base";
2
+ import { ExtendedCoin, ExtendedVirtualCoin } from "../../wallet";
3
+ import { DB_VERSION, STORE_CONTRACTS, LEGACY_STORE_CONTRACT_COLLECTIONS, STORE_TRANSACTIONS, STORE_UTXOS, STORE_VTXOS, STORE_WALLET_STATE } from "./schema";
4
+ export { STORE_VTXOS, STORE_UTXOS, STORE_TRANSACTIONS, STORE_WALLET_STATE, STORE_CONTRACTS, LEGACY_STORE_CONTRACT_COLLECTIONS, DB_VERSION, };
5
+ export type SerializedVtxo = ReturnType<typeof serializeVtxo>;
6
+ export type SerializedUtxo = ReturnType<typeof serializeUtxo>;
7
+ export declare const serializeTapLeaf: ([cb, s]: TapLeafScript) => {
8
+ cb: string;
9
+ s: string;
10
+ };
11
+ export declare const serializeVtxo: (v: ExtendedVirtualCoin) => {
12
+ tapTree: string;
13
+ forfeitTapLeafScript: {
14
+ cb: string;
15
+ s: string;
16
+ };
17
+ intentTapLeafScript: {
18
+ cb: string;
19
+ s: string;
20
+ };
21
+ extraWitness: string[] | undefined;
22
+ virtualStatus: import("../../wallet").VirtualStatus;
23
+ spentBy?: string;
24
+ settledBy?: string;
25
+ arkTxId?: string;
26
+ createdAt: Date;
27
+ isUnrolled: boolean;
28
+ isSpent?: boolean;
29
+ assets?: import("../../wallet").Asset[];
30
+ value: number;
31
+ status: import("../../wallet").Status;
32
+ txid: string;
33
+ vout: number;
34
+ };
35
+ export declare const serializeUtxo: (u: ExtendedCoin) => {
36
+ tapTree: string;
37
+ forfeitTapLeafScript: {
38
+ cb: string;
39
+ s: string;
40
+ };
41
+ intentTapLeafScript: {
42
+ cb: string;
43
+ s: string;
44
+ };
45
+ extraWitness: string[] | undefined;
46
+ value: number;
47
+ status: import("../../wallet").Status;
48
+ txid: string;
49
+ vout: number;
50
+ };
51
+ export declare const deserializeTapLeaf: (t: {
52
+ cb: string;
53
+ s: string;
54
+ }) => TapLeafScript;
55
+ export declare const deserializeVtxo: (o: SerializedVtxo) => ExtendedVirtualCoin;
56
+ export declare const deserializeUtxo: (o: SerializedUtxo) => ExtendedCoin;
@@ -0,0 +1,8 @@
1
+ export declare const STORE_VTXOS = "vtxos";
2
+ export declare const STORE_UTXOS = "utxos";
3
+ export declare const STORE_TRANSACTIONS = "transactions";
4
+ export declare const STORE_WALLET_STATE = "walletState";
5
+ export declare const STORE_CONTRACTS = "contracts";
6
+ export declare const LEGACY_STORE_CONTRACT_COLLECTIONS = "contractsCollections";
7
+ export declare const DB_VERSION = 2;
8
+ export declare function initDatabase(db: IDBDatabase): void;
@@ -0,0 +1,25 @@
1
+ import { ExtendedCoin, ExtendedVirtualCoin, ArkTransaction } from "../../wallet";
2
+ import { WalletRepository, WalletState } from "../walletRepository";
3
+ /**
4
+ * IndexedDB-based implementation of WalletRepository.
5
+ */
6
+ export declare class IndexedDBWalletRepository implements WalletRepository {
7
+ private readonly dbName;
8
+ readonly version: 1;
9
+ private db;
10
+ constructor(dbName?: string);
11
+ clear(): Promise<void>;
12
+ [Symbol.asyncDispose](): Promise<void>;
13
+ getVtxos(address: string): Promise<ExtendedVirtualCoin[]>;
14
+ saveVtxos(address: string, vtxos: ExtendedVirtualCoin[]): Promise<void>;
15
+ deleteVtxos(address: string): Promise<void>;
16
+ getUtxos(address: string): Promise<ExtendedCoin[]>;
17
+ saveUtxos(address: string, utxos: ExtendedCoin[]): Promise<void>;
18
+ deleteUtxos(address: string): Promise<void>;
19
+ getTransactionHistory(address: string): Promise<ArkTransaction[]>;
20
+ saveTransactions(address: string, txs: ArkTransaction[]): Promise<void>;
21
+ deleteTransactions(address: string): Promise<void>;
22
+ getWalletState(): Promise<WalletState | null>;
23
+ saveWalletState(state: WalletState): Promise<void>;
24
+ private getDB;
25
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * WebSQL adapter over expo-sqlite.
3
+ *
4
+ * Bridges the WebSQL API surface that indexeddbshim expects to the
5
+ * synchronous expo-sqlite driver. Only the subset actually called by
6
+ * the shim is implemented:
7
+ *
8
+ * openDatabase(name, version, displayName, estimatedSize) → WebSQLDatabase
9
+ * db.transaction(cb, errCb?, successCb?)
10
+ * tx.executeSql(sql, args?, successCb?, errorCb?)
11
+ * resultSet = { insertId, rowsAffected, rows: { length, item(i) } }
12
+ */
13
+ import { type SQLiteDatabase } from "expo-sqlite";
14
+ export interface SQLResultSetRowList {
15
+ length: number;
16
+ item(index: number): any;
17
+ }
18
+ export interface SQLResultSet {
19
+ insertId: number;
20
+ rowsAffected: number;
21
+ rows: SQLResultSetRowList;
22
+ }
23
+ export interface SQLError {
24
+ code: number;
25
+ message: string;
26
+ }
27
+ type ExecuteSqlSuccessCb = (tx: WebSQLTransaction, resultSet: SQLResultSet) => void;
28
+ type ExecuteSqlErrorCb = (tx: WebSQLTransaction, error: SQLError) => boolean | void;
29
+ interface QueuedStatement {
30
+ sql: string;
31
+ args: any[];
32
+ successCb?: ExecuteSqlSuccessCb;
33
+ errorCb?: ExecuteSqlErrorCb;
34
+ }
35
+ export declare class WebSQLTransaction {
36
+ /** @internal */
37
+ _queue: QueuedStatement[];
38
+ executeSql(sql: string, args?: any[], successCb?: ExecuteSqlSuccessCb, errorCb?: ExecuteSqlErrorCb): void;
39
+ }
40
+ export declare class WebSQLDatabase {
41
+ /** @internal */
42
+ _db: SQLiteDatabase;
43
+ version: string;
44
+ constructor(db: SQLiteDatabase, version: string);
45
+ transaction(callback: (tx: WebSQLTransaction) => void, errorCb?: (error: SQLError) => void, successCb?: () => void): void;
46
+ readTransaction(callback: (tx: WebSQLTransaction) => void, errorCb?: (error: SQLError) => void, successCb?: () => void): void;
47
+ }
48
+ export declare function openDatabase(name: string, version: string, _displayName: string, _estimatedSize: number, _creationCallback?: (db: WebSQLDatabase) => void): WebSQLDatabase;
49
+ export {};
@@ -0,0 +1,24 @@
1
+ import { StorageAdapter } from "../../storage";
2
+ import { ContractFilter, ContractRepository } from "../contractRepository";
3
+ import { Contract } from "../../contracts/types";
4
+ export declare const getContractStorageKey: (id: string, key: string) => string;
5
+ export declare const getCollectionStorageKey: (type: string) => string;
6
+ /**
7
+ * @deprecated This is only to be used in migration from storage V1
8
+ */
9
+ export declare class ContractRepositoryImpl implements ContractRepository {
10
+ readonly version: 1;
11
+ private storage;
12
+ constructor(storage: StorageAdapter);
13
+ getContractData<T>(contractId: string, key: string): Promise<T | null>;
14
+ setContractData<T>(contractId: string, key: string, data: T): Promise<void>;
15
+ deleteContractData(contractId: string, key: string): Promise<void>;
16
+ getContractCollection<T>(contractType: string): Promise<ReadonlyArray<T>>;
17
+ saveToContractCollection<T, K extends keyof T>(contractType: string, item: T, idField: K): Promise<void>;
18
+ removeFromContractCollection<T, K extends keyof T>(contractType: string, id: T[K], idField: K): Promise<void>;
19
+ getContracts(_?: ContractFilter): Promise<Contract[]>;
20
+ saveContract(_: Contract): Promise<void>;
21
+ deleteContract(_: string): Promise<void>;
22
+ clear(): Promise<void>;
23
+ [Symbol.asyncDispose](): Promise<void>;
24
+ }