@arkade-os/sdk 0.2.3 → 0.3.0-alpha.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.
Files changed (121) hide show
  1. package/README.md +114 -43
  2. package/dist/cjs/adapters/asyncStorage.js +5 -0
  3. package/dist/cjs/adapters/fileSystem.js +5 -0
  4. package/dist/cjs/adapters/indexedDB.js +5 -0
  5. package/dist/cjs/adapters/localStorage.js +5 -0
  6. package/dist/cjs/arknote/index.js +4 -4
  7. package/dist/cjs/bip322/index.js +11 -9
  8. package/dist/cjs/forfeit.js +2 -2
  9. package/dist/cjs/identity/index.js +15 -0
  10. package/dist/cjs/identity/singleKey.js +24 -5
  11. package/dist/cjs/index.js +7 -5
  12. package/dist/cjs/musig2/keys.js +7 -7
  13. package/dist/cjs/musig2/nonces.js +1 -1
  14. package/dist/cjs/musig2/sign.js +6 -6
  15. package/dist/cjs/networks.js +6 -6
  16. package/dist/cjs/repositories/contractRepository.js +130 -0
  17. package/dist/cjs/repositories/index.js +18 -0
  18. package/dist/cjs/repositories/walletRepository.js +136 -0
  19. package/dist/cjs/script/address.js +3 -3
  20. package/dist/cjs/script/base.js +7 -7
  21. package/dist/cjs/script/tapscript.js +21 -21
  22. package/dist/cjs/script/vhtlc.js +2 -2
  23. package/dist/cjs/storage/asyncStorage.js +47 -0
  24. package/dist/cjs/storage/fileSystem.js +138 -0
  25. package/dist/cjs/storage/inMemory.js +21 -0
  26. package/dist/cjs/storage/indexedDB.js +97 -0
  27. package/dist/cjs/storage/localStorage.js +48 -0
  28. package/dist/cjs/tree/signingSession.js +12 -11
  29. package/dist/cjs/tree/txTree.js +6 -6
  30. package/dist/cjs/tree/validation.js +5 -5
  31. package/dist/cjs/utils/arkTransaction.js +5 -5
  32. package/dist/cjs/utils/unknownFields.js +5 -5
  33. package/dist/cjs/wallet/onchain.js +16 -10
  34. package/dist/cjs/wallet/serviceWorker/request.js +4 -14
  35. package/dist/cjs/wallet/serviceWorker/response.js +0 -13
  36. package/dist/cjs/wallet/serviceWorker/wallet.js +124 -130
  37. package/dist/cjs/wallet/serviceWorker/worker.js +84 -53
  38. package/dist/cjs/wallet/unroll.js +6 -6
  39. package/dist/cjs/wallet/wallet.js +37 -20
  40. package/dist/esm/adapters/asyncStorage.js +1 -0
  41. package/dist/esm/adapters/fileSystem.js +1 -0
  42. package/dist/esm/adapters/indexedDB.js +1 -0
  43. package/dist/esm/adapters/localStorage.js +1 -0
  44. package/dist/esm/arknote/index.js +2 -2
  45. package/dist/esm/bip322/index.js +4 -2
  46. package/dist/esm/forfeit.js +1 -1
  47. package/dist/esm/identity/index.js +1 -1
  48. package/dist/esm/identity/singleKey.js +22 -3
  49. package/dist/esm/index.js +5 -4
  50. package/dist/esm/musig2/keys.js +7 -7
  51. package/dist/esm/musig2/nonces.js +1 -1
  52. package/dist/esm/musig2/sign.js +5 -5
  53. package/dist/esm/networks.js +1 -1
  54. package/dist/esm/repositories/contractRepository.js +126 -0
  55. package/dist/esm/repositories/index.js +2 -0
  56. package/dist/esm/repositories/walletRepository.js +132 -0
  57. package/dist/esm/script/address.js +1 -1
  58. package/dist/esm/script/base.js +3 -3
  59. package/dist/esm/script/tapscript.js +2 -2
  60. package/dist/esm/script/vhtlc.js +1 -1
  61. package/dist/esm/storage/asyncStorage.js +43 -0
  62. package/dist/esm/storage/fileSystem.js +101 -0
  63. package/dist/esm/storage/inMemory.js +17 -0
  64. package/dist/esm/storage/indexedDB.js +93 -0
  65. package/dist/esm/storage/localStorage.js +44 -0
  66. package/dist/esm/tree/signingSession.js +4 -3
  67. package/dist/esm/tree/txTree.js +2 -2
  68. package/dist/esm/tree/validation.js +2 -2
  69. package/dist/esm/utils/arkTransaction.js +2 -2
  70. package/dist/esm/utils/unknownFields.js +1 -1
  71. package/dist/esm/wallet/onchain.js +14 -8
  72. package/dist/esm/wallet/serviceWorker/request.js +4 -14
  73. package/dist/esm/wallet/serviceWorker/response.js +0 -13
  74. package/dist/esm/wallet/serviceWorker/wallet.js +125 -131
  75. package/dist/esm/wallet/serviceWorker/worker.js +85 -54
  76. package/dist/esm/wallet/unroll.js +2 -2
  77. package/dist/esm/wallet/wallet.js +25 -8
  78. package/dist/types/adapters/asyncStorage.d.ts +2 -0
  79. package/dist/types/adapters/fileSystem.d.ts +2 -0
  80. package/dist/types/adapters/indexedDB.d.ts +2 -0
  81. package/dist/types/adapters/localStorage.d.ts +2 -0
  82. package/dist/types/arknote/index.d.ts +1 -1
  83. package/dist/types/bip322/index.d.ts +2 -2
  84. package/dist/types/forfeit.d.ts +1 -1
  85. package/dist/types/identity/index.d.ts +4 -2
  86. package/dist/types/identity/singleKey.d.ts +13 -2
  87. package/dist/types/index.d.ts +5 -5
  88. package/dist/types/repositories/contractRepository.d.ts +20 -0
  89. package/dist/types/repositories/index.d.ts +2 -0
  90. package/dist/types/repositories/walletRepository.d.ts +38 -0
  91. package/dist/types/script/address.d.ts +1 -1
  92. package/dist/types/script/base.d.ts +1 -1
  93. package/dist/types/script/default.d.ts +1 -1
  94. package/dist/types/script/tapscript.d.ts +1 -1
  95. package/dist/types/script/vhtlc.d.ts +1 -1
  96. package/dist/types/storage/asyncStorage.d.ts +9 -0
  97. package/dist/types/storage/fileSystem.d.ts +11 -0
  98. package/dist/types/storage/inMemory.d.ts +8 -0
  99. package/dist/types/storage/index.d.ts +6 -0
  100. package/dist/types/storage/indexedDB.d.ts +12 -0
  101. package/dist/types/storage/localStorage.d.ts +8 -0
  102. package/dist/types/tree/txTree.d.ts +1 -1
  103. package/dist/types/tree/validation.d.ts +1 -1
  104. package/dist/types/utils/anchor.d.ts +1 -1
  105. package/dist/types/utils/arkTransaction.d.ts +3 -3
  106. package/dist/types/utils/unknownFields.d.ts +1 -1
  107. package/dist/types/wallet/index.d.ts +4 -1
  108. package/dist/types/wallet/onchain.d.ts +5 -4
  109. package/dist/types/wallet/serviceWorker/request.d.ts +1 -7
  110. package/dist/types/wallet/serviceWorker/response.d.ts +1 -8
  111. package/dist/types/wallet/serviceWorker/wallet.d.ts +67 -21
  112. package/dist/types/wallet/serviceWorker/worker.d.ts +16 -4
  113. package/dist/types/wallet/unroll.d.ts +1 -1
  114. package/dist/types/wallet/wallet.d.ts +5 -1
  115. package/package.json +39 -15
  116. package/dist/cjs/wallet/serviceWorker/db/vtxo/idb.js +0 -185
  117. package/dist/esm/wallet/serviceWorker/db/vtxo/idb.js +0 -181
  118. package/dist/types/wallet/serviceWorker/db/vtxo/idb.d.ts +0 -20
  119. package/dist/types/wallet/serviceWorker/db/vtxo/index.d.ts +0 -14
  120. /package/dist/cjs/{wallet/serviceWorker/db/vtxo → storage}/index.js +0 -0
  121. /package/dist/esm/{wallet/serviceWorker/db/vtxo → storage}/index.js +0 -0
@@ -1,5 +1,5 @@
1
1
  import { TapLeafScript, VtxoScript } from "../script/base";
2
- import { Bytes } from "@scure/btc-signer/utils";
2
+ import { Bytes } from "@scure/btc-signer/utils.js";
3
3
  import { ExtendedCoin, Status } from "../wallet";
4
4
  /**
5
5
  * ArkNotes are special virtual coins in the Ark protocol that can be created
@@ -1,5 +1,5 @@
1
- import { Transaction } from "@scure/btc-signer";
2
- import { TransactionInput, TransactionOutput } from "@scure/btc-signer/psbt";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
+ import { TransactionInput, TransactionOutput } from "@scure/btc-signer/psbt.js";
3
3
  /**
4
4
  * BIP-322 signature implementation for Bitcoin message signing.
5
5
  *
@@ -1,3 +1,3 @@
1
- import { Transaction } from "@scure/btc-signer";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
2
  import { TransactionInputUpdate } from "@scure/btc-signer/psbt";
3
3
  export declare function buildForfeitTx(inputs: TransactionInputUpdate[], forfeitPkScript: Uint8Array, txLocktime?: number): Transaction;
@@ -1,7 +1,9 @@
1
- import { Transaction } from "@scure/btc-signer";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
2
  import { SignerSession } from "../tree/signingSession";
3
3
  export interface Identity {
4
4
  sign(tx: Transaction, inputIndexes?: number[]): Promise<Transaction>;
5
- xOnlyPublicKey(): Uint8Array;
5
+ xOnlyPublicKey(): Promise<Uint8Array>;
6
6
  signerSession(): SignerSession;
7
+ signMessage(message: string): Promise<Uint8Array>;
7
8
  }
9
+ export * from "./singleKey";
@@ -1,4 +1,4 @@
1
- import { Transaction } from "@scure/btc-signer";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
2
  import { Identity } from ".";
3
3
  import { SignerSession } from "../tree/signingSession";
4
4
  /**
@@ -12,6 +12,9 @@ import { SignerSession } from "../tree/signingSession";
12
12
  * // Create from raw bytes
13
13
  * const key = SingleKey.fromPrivateKey(privateKeyBytes);
14
14
  *
15
+ * // Create random key
16
+ * const randomKey = SingleKey.fromRandomBytes();
17
+ *
15
18
  * // Sign a transaction
16
19
  * const signedTx = await key.sign(transaction);
17
20
  * ```
@@ -21,7 +24,15 @@ export declare class SingleKey implements Identity {
21
24
  private constructor();
22
25
  static fromPrivateKey(privateKey: Uint8Array): SingleKey;
23
26
  static fromHex(privateKeyHex: string): SingleKey;
27
+ static fromRandomBytes(): SingleKey;
28
+ /**
29
+ * Export the private key as a hex string.
30
+ *
31
+ * @returns The private key as a hex string
32
+ */
33
+ toHex(): string;
24
34
  sign(tx: Transaction, inputIndexes?: number[]): Promise<Transaction>;
25
- xOnlyPublicKey(): Uint8Array;
35
+ xOnlyPublicKey(): Promise<Uint8Array>;
26
36
  signerSession(): SignerSession;
37
+ signMessage(message: string): Promise<Uint8Array>;
27
38
  }
@@ -1,4 +1,4 @@
1
- import { Transaction } from "@scure/btc-signer";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
2
  import { SingleKey } from "./identity/singleKey";
3
3
  import { Identity } from "./identity";
4
4
  import { ArkAddress } from "./script/address";
@@ -23,13 +23,13 @@ import { buildOffchainTx, ArkTxInput, OffchainTx } from "./utils/arkTransaction"
23
23
  import { VtxoTaprootTree, ConditionWitness, getArkPsbtFields, setArkPsbtField, ArkPsbtFieldCoder, ArkPsbtFieldKey, ArkPsbtFieldKeyType, CosignerPublicKey, VtxoTreeExpiry } from "./utils/unknownFields";
24
24
  import { BIP322 } from "./bip322";
25
25
  import { ArkNote } from "./arknote";
26
- import { IndexedDBVtxoRepository } from "./wallet/serviceWorker/db/vtxo/idb";
27
- import { VtxoRepository } from "./wallet/serviceWorker/db/vtxo";
28
26
  import { networks, Network, NetworkName } from "./networks";
29
27
  import { RestIndexerProvider, IndexerProvider, IndexerTxType, ChainTxType, PageResponse, Batch, ChainTx, CommitmentTx, TxHistoryRecord, VtxoChain, Tx, Vtxo, PaginationOptions, SubscriptionResponse } from "./providers/indexer";
30
28
  import { Nonces } from "./musig2/nonces";
31
29
  import { PartialSig } from "./musig2/sign";
32
30
  import { AnchorBumper, P2A } from "./utils/anchor";
33
31
  import { Unroll } from "./wallet/unroll";
34
- export { Wallet, SingleKey, OnchainWallet, Ramps, ESPLORA_URL, EsploraProvider, RestArkProvider, RestIndexerProvider, ArkAddress, DefaultVtxo, VtxoScript, VHTLC, TxType, IndexerTxType, ChainTxType, SettlementEventType, setupServiceWorker, Worker, ServiceWorkerWallet, Request, Response, decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, ArkPsbtFieldKey, ArkPsbtFieldKeyType, setArkPsbtField, getArkPsbtFields, CosignerPublicKey, VtxoTreeExpiry, VtxoTaprootTree, ConditionWitness, buildOffchainTx, waitForIncomingFunds, ArkNote, networks, IndexedDBVtxoRepository, BIP322, TxTree, P2A, Unroll, Transaction, };
35
- export type { Identity, IWallet, WalletConfig, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, VtxoRepository, ArkTxInput, OffchainTx, TapLeaves, IncomingFunds, IndexerProvider, PageResponse, Batch, ChainTx, CommitmentTx, TxHistoryRecord, Vtxo, VtxoChain, Tx, OnchainProvider, ArkProvider, SettlementEvent, ArkInfo, Intent, Output, TxNotification, ExplorerTransaction, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesAggregatedEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, MarketHour, PaginationOptions, SubscriptionResponse, Network, NetworkName, ArkTapscript, RelativeTimelock, EncodedVtxoScript, TapLeafScript, SignerSession, TreeNonces, TreePartialSigs, GetVtxosFilter, Nonces, PartialSig, ArkPsbtFieldCoder, TxTreeNode, AnchorBumper, };
32
+ import { WalletRepositoryImpl } from "./repositories/walletRepository";
33
+ import { ContractRepositoryImpl } from "./repositories/contractRepository";
34
+ export { Wallet, SingleKey, OnchainWallet, Ramps, ESPLORA_URL, EsploraProvider, RestArkProvider, RestIndexerProvider, ArkAddress, DefaultVtxo, VtxoScript, VHTLC, TxType, IndexerTxType, ChainTxType, SettlementEventType, setupServiceWorker, Worker, ServiceWorkerWallet, Request, Response, decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, ArkPsbtFieldKey, ArkPsbtFieldKeyType, setArkPsbtField, getArkPsbtFields, CosignerPublicKey, VtxoTreeExpiry, VtxoTaprootTree, ConditionWitness, buildOffchainTx, waitForIncomingFunds, ArkNote, networks, WalletRepositoryImpl, ContractRepositoryImpl, BIP322, TxTree, P2A, Unroll, Transaction, };
35
+ export type { Identity, IWallet, WalletConfig, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, ArkTxInput, OffchainTx, TapLeaves, IncomingFunds, IndexerProvider, PageResponse, Batch, ChainTx, CommitmentTx, TxHistoryRecord, Vtxo, VtxoChain, Tx, OnchainProvider, ArkProvider, SettlementEvent, ArkInfo, Intent, Output, TxNotification, ExplorerTransaction, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesAggregatedEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, MarketHour, PaginationOptions, SubscriptionResponse, Network, NetworkName, ArkTapscript, RelativeTimelock, EncodedVtxoScript, TapLeafScript, SignerSession, TreeNonces, TreePartialSigs, GetVtxosFilter, Nonces, PartialSig, ArkPsbtFieldCoder, TxTreeNode, AnchorBumper, };
@@ -0,0 +1,20 @@
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
+ getContractCollection<T>(contractType: string): Promise<ReadonlyArray<T>>;
7
+ saveToContractCollection<T, K extends keyof T>(contractType: string, item: T, idField: K): Promise<void>;
8
+ removeFromContractCollection<T, K extends keyof T>(contractType: string, id: T[K], idField: K): Promise<void>;
9
+ }
10
+ export declare class ContractRepositoryImpl implements ContractRepository {
11
+ private storage;
12
+ private cache;
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
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./walletRepository";
2
+ export * from "./contractRepository";
@@ -0,0 +1,38 @@
1
+ import { StorageAdapter } from "../storage";
2
+ import { ExtendedVirtualCoin } from "../wallet";
3
+ export interface WalletState {
4
+ lastSyncTime?: number;
5
+ settings?: Record<string, any>;
6
+ }
7
+ export interface Transaction {
8
+ id: string;
9
+ timestamp: number;
10
+ amount: number;
11
+ type: "send" | "receive";
12
+ status: "pending" | "confirmed" | "failed";
13
+ }
14
+ export interface WalletRepository {
15
+ getVtxos(address: string): Promise<ExtendedVirtualCoin[]>;
16
+ saveVtxo(address: string, vtxo: ExtendedVirtualCoin): Promise<void>;
17
+ saveVtxos(address: string, vtxos: ExtendedVirtualCoin[]): Promise<void>;
18
+ removeVtxo(address: string, vtxoId: string): Promise<void>;
19
+ clearVtxos(address: string): Promise<void>;
20
+ getTransactionHistory(address: string): Promise<Transaction[]>;
21
+ saveTransaction(address: string, tx: Transaction): Promise<void>;
22
+ getWalletState(): Promise<WalletState | null>;
23
+ saveWalletState(state: WalletState): Promise<void>;
24
+ }
25
+ export declare class WalletRepositoryImpl implements WalletRepository {
26
+ private storage;
27
+ private cache;
28
+ constructor(storage: StorageAdapter);
29
+ getVtxos(address: string): Promise<ExtendedVirtualCoin[]>;
30
+ saveVtxo(address: string, vtxo: ExtendedVirtualCoin): Promise<void>;
31
+ saveVtxos(address: string, vtxos: ExtendedVirtualCoin[]): Promise<void>;
32
+ removeVtxo(address: string, vtxoId: string): Promise<void>;
33
+ clearVtxos(address: string): Promise<void>;
34
+ getTransactionHistory(address: string): Promise<Transaction[]>;
35
+ saveTransaction(address: string, tx: Transaction): Promise<void>;
36
+ getWalletState(): Promise<WalletState | null>;
37
+ saveWalletState(state: WalletState): Promise<void>;
38
+ }
@@ -1,4 +1,4 @@
1
- import { Bytes } from "@scure/btc-signer/utils";
1
+ import { Bytes } from "@scure/btc-signer/utils.js";
2
2
  /**
3
3
  * ArkAddress allows to create and decode bech32m encoded ark address.
4
4
  * An ark address is composed of:
@@ -1,4 +1,4 @@
1
- import { BTC_NETWORK, Bytes } from "@scure/btc-signer/utils";
1
+ import { BTC_NETWORK, Bytes } from "@scure/btc-signer/utils.js";
2
2
  import { ArkAddress } from "./address";
3
3
  import { ConditionCSVMultisigTapscript, CSVMultisigTapscript } from "./tapscript";
4
4
  export type TapLeafScript = [
@@ -1,4 +1,4 @@
1
- import { Bytes } from "@scure/btc-signer/utils";
1
+ import { Bytes } from "@scure/btc-signer/utils.js";
2
2
  import { TapLeafScript, VtxoScript } from "./base";
3
3
  import { RelativeTimelock } from "./tapscript";
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { Bytes } from "@scure/btc-signer/utils";
1
+ import { Bytes } from "@scure/btc-signer/utils.js";
2
2
  /**
3
3
  * RelativeTimelock lets to create timelocked with CHECKSEQUENCEVERIFY script.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { Bytes } from "@scure/btc-signer/utils";
1
+ import { Bytes } from "@scure/btc-signer/utils.js";
2
2
  import { RelativeTimelock } from "./tapscript";
3
3
  import { TapLeafScript, VtxoScript } from "./base";
4
4
  /**
@@ -0,0 +1,9 @@
1
+ import type { StorageAdapter } from "./index";
2
+ export declare class AsyncStorageAdapter implements StorageAdapter {
3
+ private AsyncStorage;
4
+ constructor();
5
+ getItem(key: string): Promise<string | null>;
6
+ setItem(key: string, value: string): Promise<void>;
7
+ removeItem(key: string): Promise<void>;
8
+ clear(): Promise<void>;
9
+ }
@@ -0,0 +1,11 @@
1
+ import type { StorageAdapter } from "./index";
2
+ export declare class FileSystemStorageAdapter implements StorageAdapter {
3
+ private readonly basePath;
4
+ constructor(dirPath: string);
5
+ private validateAndGetFilePath;
6
+ private ensureDirectory;
7
+ getItem(key: string): Promise<string | null>;
8
+ setItem(key: string, value: string): Promise<void>;
9
+ removeItem(key: string): Promise<void>;
10
+ clear(): Promise<void>;
11
+ }
@@ -0,0 +1,8 @@
1
+ import type { StorageAdapter } from "./index";
2
+ export declare class InMemoryStorageAdapter implements StorageAdapter {
3
+ private store;
4
+ getItem(key: string): Promise<string | null>;
5
+ setItem(key: string, value: string): Promise<void>;
6
+ removeItem(key: string): Promise<void>;
7
+ clear(): Promise<void>;
8
+ }
@@ -0,0 +1,6 @@
1
+ export interface StorageAdapter {
2
+ getItem(key: string): Promise<string | null>;
3
+ setItem(key: string, value: string): Promise<void>;
4
+ removeItem(key: string): Promise<void>;
5
+ clear(): Promise<void>;
6
+ }
@@ -0,0 +1,12 @@
1
+ import type { StorageAdapter } from "./index";
2
+ export declare class IndexedDBStorageAdapter implements StorageAdapter {
3
+ private dbName;
4
+ private version;
5
+ private db;
6
+ constructor(dbName: string, version?: number);
7
+ private getDB;
8
+ getItem(key: string): Promise<string | null>;
9
+ setItem(key: string, value: string): Promise<void>;
10
+ removeItem(key: string): Promise<void>;
11
+ clear(): Promise<void>;
12
+ }
@@ -0,0 +1,8 @@
1
+ import type { StorageAdapter } from "./index";
2
+ export declare class LocalStorageAdapter implements StorageAdapter {
3
+ private getSafeLocalStorage;
4
+ getItem(key: string): Promise<string | null>;
5
+ setItem(key: string, value: string): Promise<void>;
6
+ removeItem(key: string): Promise<void>;
7
+ clear(): Promise<void>;
8
+ }
@@ -1,4 +1,4 @@
1
- import { Transaction } from "@scure/btc-signer";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
2
  /**
3
3
  * TxTreeNode is a node of the tree.
4
4
  * It contains the transaction id, the transaction and the children.
@@ -1,4 +1,4 @@
1
- import { Transaction } from "@scure/btc-signer";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
2
  import { TxTree } from "./txTree";
3
3
  export declare const ErrInvalidSettlementTx: (tx: string) => Error;
4
4
  export declare const ErrInvalidSettlementTxOutputs: Error;
@@ -1,4 +1,4 @@
1
- import { Transaction } from "@scure/btc-signer";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
2
  import { TransactionInputUpdate } from "@scure/btc-signer/psbt";
3
3
  export declare const ANCHOR_VALUE = 0n;
4
4
  export declare const ANCHOR_PKSCRIPT: Uint8Array<ArrayBuffer>;
@@ -1,9 +1,9 @@
1
- import { Transaction } from "@scure/btc-signer";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
2
  import { VirtualCoin } from "../wallet";
3
3
  import { EncodedVtxoScript, TapLeafScript } from "../script/base";
4
4
  import { CSVMultisigTapscript } from "../script/tapscript";
5
- import { TransactionOutput } from "@scure/btc-signer/psbt";
6
- import { Bytes } from "@scure/btc-signer/utils";
5
+ import { TransactionOutput } from "@scure/btc-signer/psbt.js";
6
+ import { Bytes } from "@scure/btc-signer/utils.js";
7
7
  export type ArkTxInput = {
8
8
  tapLeafScript: TapLeafScript;
9
9
  checkpointTapLeafScript?: Bytes;
@@ -1,4 +1,4 @@
1
- import { Transaction } from "@scure/btc-signer";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
2
  import { TransactionInputUpdate } from "@scure/btc-signer/psbt";
3
3
  /**
4
4
  * ArkPsbtFieldKey is the key values for ark psbt fields.
@@ -2,7 +2,8 @@ import { Output, SettlementEvent } from "../providers/ark";
2
2
  import { Identity } from "../identity";
3
3
  import { RelativeTimelock } from "../script/tapscript";
4
4
  import { EncodedVtxoScript, TapLeafScript } from "../script/base";
5
- import { Bytes } from "@scure/btc-signer/utils";
5
+ import { Bytes } from "@scure/btc-signer/utils.js";
6
+ import { StorageAdapter } from "../storage";
6
7
  /**
7
8
  * Configuration options for wallet initialization.
8
9
  *
@@ -18,6 +19,7 @@ export interface WalletConfig {
18
19
  arkServerPublicKey?: string;
19
20
  boardingTimelock?: RelativeTimelock;
20
21
  exitTimelock?: RelativeTimelock;
22
+ storage?: StorageAdapter;
21
23
  }
22
24
  export interface WalletBalance {
23
25
  boarding: {
@@ -113,6 +115,7 @@ export type GetVtxosFilter = {
113
115
  * operations, and transaction management including sending, settling, and unrolling.
114
116
  */
115
117
  export interface IWallet {
118
+ identity: Identity;
116
119
  getAddress(): Promise<string>;
117
120
  getBoardingAddress(): Promise<string>;
118
121
  getBalance(): Promise<WalletBalance>;
@@ -1,9 +1,9 @@
1
- import { P2TR } from "@scure/btc-signer/payment";
1
+ import { P2TR } from "@scure/btc-signer/payment.js";
2
2
  import { Coin, SendBitcoinParams } from ".";
3
3
  import { Identity } from "../identity";
4
4
  import { Network, NetworkName } from "../networks";
5
5
  import { OnchainProvider } from "../providers/onchain";
6
- import { Transaction } from "@scure/btc-signer";
6
+ import { Transaction } from "@scure/btc-signer/transaction.js";
7
7
  import { AnchorBumper } from "../utils/anchor";
8
8
  /**
9
9
  * Onchain Bitcoin wallet implementation for traditional Bitcoin transactions.
@@ -14,7 +14,7 @@ import { AnchorBumper } from "../utils/anchor";
14
14
  *
15
15
  * @example
16
16
  * ```typescript
17
- * const wallet = new OnchainWallet(identity, 'mainnet');
17
+ * const wallet = await OnchainWallet.create(identity, 'mainnet');
18
18
  * const balance = await wallet.getBalance();
19
19
  * const txid = await wallet.send({
20
20
  * address: 'bc1...',
@@ -29,7 +29,8 @@ export declare class OnchainWallet implements AnchorBumper {
29
29
  readonly onchainP2TR: P2TR;
30
30
  readonly provider: OnchainProvider;
31
31
  readonly network: Network;
32
- constructor(identity: Identity, network: NetworkName, provider?: OnchainProvider);
32
+ private constructor();
33
+ static create(identity: Identity, networkName: NetworkName, provider?: OnchainProvider): Promise<OnchainWallet>;
33
34
  get address(): string;
34
35
  getCoins(): Promise<Coin[]>;
35
36
  getBalance(): Promise<number>;
@@ -3,7 +3,7 @@ import { SettleParams, SendBitcoinParams, GetVtxosFilter } from "..";
3
3
  * Request is the namespace that contains the request types for the service worker.
4
4
  */
5
5
  export declare namespace Request {
6
- type Type = "INIT_WALLET" | "SETTLE" | "GET_ADDRESS" | "GET_BOARDING_ADDRESS" | "GET_BALANCE" | "GET_VTXOS" | "GET_VIRTUAL_COINS" | "GET_BOARDING_UTXOS" | "SEND_BITCOIN" | "GET_TRANSACTION_HISTORY" | "GET_STATUS" | "CLEAR" | "SIGN";
6
+ type Type = "INIT_WALLET" | "SETTLE" | "GET_ADDRESS" | "GET_BOARDING_ADDRESS" | "GET_BALANCE" | "GET_VTXOS" | "GET_VIRTUAL_COINS" | "GET_BOARDING_UTXOS" | "SEND_BITCOIN" | "GET_TRANSACTION_HISTORY" | "GET_STATUS" | "CLEAR";
7
7
  interface Base {
8
8
  type: Type;
9
9
  id: string;
@@ -62,10 +62,4 @@ export declare namespace Request {
62
62
  interface Clear extends Base {
63
63
  type: "CLEAR";
64
64
  }
65
- interface Sign extends Base {
66
- type: "SIGN";
67
- tx: string;
68
- inputIndexes?: number[];
69
- }
70
- function isSign(message: Base): message is Sign;
71
65
  }
@@ -4,7 +4,7 @@ import { SettlementEvent } from "../../providers/ark";
4
4
  * Response is the namespace that contains the response types for the service worker.
5
5
  */
6
6
  export declare namespace Response {
7
- type Type = "WALLET_INITIALIZED" | "SETTLE_EVENT" | "SETTLE_SUCCESS" | "ADDRESS" | "BOARDING_ADDRESS" | "BALANCE" | "VTXOS" | "VIRTUAL_COINS" | "BOARDING_UTXOS" | "SEND_BITCOIN_SUCCESS" | "TRANSACTION_HISTORY" | "WALLET_STATUS" | "ERROR" | "CLEAR_RESPONSE" | "SIGN_SUCCESS";
7
+ type Type = "WALLET_INITIALIZED" | "SETTLE_EVENT" | "SETTLE_SUCCESS" | "ADDRESS" | "BOARDING_ADDRESS" | "BALANCE" | "VTXOS" | "VIRTUAL_COINS" | "BOARDING_UTXOS" | "SEND_BITCOIN_SUCCESS" | "TRANSACTION_HISTORY" | "WALLET_STATUS" | "ERROR" | "CLEAR_RESPONSE";
8
8
  interface Base {
9
9
  type: Type;
10
10
  success: boolean;
@@ -101,11 +101,4 @@ export declare namespace Response {
101
101
  }
102
102
  function isClearResponse(response: Base): response is ClearResponse;
103
103
  function clearResponse(id: string, success: boolean): ClearResponse;
104
- interface SignSuccess extends Base {
105
- type: "SIGN_SUCCESS";
106
- success: true;
107
- tx: string;
108
- }
109
- function signSuccess(id: string, tx: string): SignSuccess;
110
- function isSignSuccess(response: Base): response is SignSuccess;
111
104
  }
@@ -1,9 +1,13 @@
1
- import { IWallet, WalletBalance, SendBitcoinParams, SettleParams, ArkTransaction, WalletConfig, ExtendedCoin, ExtendedVirtualCoin, GetVtxosFilter } from "..";
1
+ import { IWallet, WalletBalance, SendBitcoinParams, SettleParams, ArkTransaction, ExtendedCoin, ExtendedVirtualCoin, GetVtxosFilter } from "..";
2
2
  import { Response } from "./response";
3
3
  import { SettlementEvent } from "../../providers/ark";
4
4
  import { Identity } from "../../identity";
5
- import { SignerSession } from "../../tree/signingSession";
6
- import { Transaction } from "@scure/btc-signer";
5
+ import { StorageAdapter } from "../../storage";
6
+ import { WalletRepository } from "../../repositories/walletRepository";
7
+ import { ContractRepository } from "../../repositories/contractRepository";
8
+ export type PrivateKeyIdentity = Identity & {
9
+ toHex(): string;
10
+ };
7
11
  /**
8
12
  * Service Worker-based wallet implementation for browser environments.
9
13
  *
@@ -14,12 +18,21 @@ import { Transaction } from "@scure/btc-signer";
14
18
  *
15
19
  * @example
16
20
  * ```typescript
17
- * // Create and initialize the service worker wallet
21
+ * // SIMPLE: Recommended approach
22
+ * const identity = SingleKey.fromHex('your_private_key_hex');
23
+ * const wallet = await ServiceWorkerWallet.setup({
24
+ * serviceWorkerPath: '/service-worker.js',
25
+ * arkServerUrl: 'https://mutinynet.arkade.sh',
26
+ * identity
27
+ * });
28
+ *
29
+ * // ADVANCED: Manual setup with service worker control
18
30
  * const serviceWorker = await setupServiceWorker("/service-worker.js");
19
- * const wallet = new ServiceWorkerWallet(serviceWorker);
20
- * await wallet.init({
21
- * privateKey: 'your_private_key_hex',
22
- * arkServerUrl: 'https://ark.example.com'
31
+ * const identity = SingleKey.fromHex('your_private_key_hex');
32
+ * const wallet = await ServiceWorkerWallet.create({
33
+ * serviceWorker,
34
+ * identity,
35
+ * arkServerUrl: 'https://mutinynet.arkade.sh'
23
36
  * });
24
37
  *
25
38
  * // Use like any other wallet
@@ -27,25 +40,58 @@ import { Transaction } from "@scure/btc-signer";
27
40
  * const balance = await wallet.getBalance();
28
41
  * ```
29
42
  */
30
- export declare class ServiceWorkerWallet implements IWallet, Identity {
43
+ interface ServiceWorkerWalletOptions {
44
+ arkServerPublicKey?: string;
45
+ arkServerUrl: string;
46
+ esploraUrl?: string;
47
+ identity: PrivateKeyIdentity;
48
+ storage?: StorageAdapter;
49
+ }
50
+ export type ServiceWorkerWalletCreateOptions = ServiceWorkerWalletOptions & {
51
+ serviceWorker: ServiceWorker;
52
+ };
53
+ export type ServiceWorkerWalletSetupOptions = ServiceWorkerWalletOptions & {
54
+ serviceWorkerPath: string;
55
+ };
56
+ export declare class ServiceWorkerWallet implements IWallet {
31
57
  readonly serviceWorker: ServiceWorker;
32
- private cachedXOnlyPublicKey;
33
- constructor(serviceWorker: ServiceWorker);
34
- getStatus(): Promise<Response.WalletStatus["status"]>;
35
- init(config: Omit<WalletConfig, "identity"> & {
36
- privateKey: string;
37
- }, failIfInitialized?: boolean): Promise<void>;
38
- clear(): Promise<void>;
58
+ readonly walletRepository: WalletRepository;
59
+ readonly contractRepository: ContractRepository;
60
+ readonly identity: Identity;
61
+ private constructor();
62
+ static create(options: ServiceWorkerWalletCreateOptions): Promise<ServiceWorkerWallet>;
63
+ /**
64
+ * Simplified setup method that handles service worker registration,
65
+ * identity creation, and wallet initialization automatically.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * // One-liner setup - handles everything automatically!
70
+ * const wallet = await ServiceWorkerWallet.setup({
71
+ * serviceWorkerPath: '/service-worker.js',
72
+ * arkServerUrl: 'https://mutinynet.arkade.sh'
73
+ * });
74
+ *
75
+ * // With custom identity
76
+ * const identity = SingleKey.fromHex('your_private_key_hex');
77
+ * const wallet = await ServiceWorkerWallet.setup({
78
+ * serviceWorkerPath: '/service-worker.js',
79
+ * arkServerUrl: 'https://mutinynet.arkade.sh',
80
+ * identity
81
+ * });
82
+ * ```
83
+ */
84
+ static setup(options: ServiceWorkerWalletSetupOptions): Promise<ServiceWorkerWallet>;
39
85
  private sendMessage;
86
+ clear(): Promise<void>;
40
87
  getAddress(): Promise<string>;
41
88
  getBoardingAddress(): Promise<string>;
42
89
  getBalance(): Promise<WalletBalance>;
43
- getVtxos(filter?: GetVtxosFilter): Promise<ExtendedVirtualCoin[]>;
44
90
  getBoardingUtxos(): Promise<ExtendedCoin[]>;
91
+ getStatus(): Promise<Response.WalletStatus["status"]>;
92
+ getTransactionHistory(): Promise<ArkTransaction[]>;
93
+ getVtxos(filter?: GetVtxosFilter): Promise<ExtendedVirtualCoin[]>;
45
94
  sendBitcoin(params: SendBitcoinParams): Promise<string>;
46
95
  settle(params?: SettleParams, callback?: (event: SettlementEvent) => void): Promise<string>;
47
- getTransactionHistory(): Promise<ArkTransaction[]>;
48
- xOnlyPublicKey(): Uint8Array;
49
- signerSession(): SignerSession;
50
- sign(tx: Transaction, inputIndexes?: number[]): Promise<Transaction>;
51
96
  }
97
+ export {};
@@ -1,16 +1,28 @@
1
- import { VtxoRepository } from "./db/vtxo";
2
1
  /**
3
2
  * Worker is a class letting to interact with ServiceWorkerWallet from the client
4
3
  * it aims to be run in a service worker context
5
4
  */
6
5
  export declare class Worker {
7
- private readonly vtxoRepository;
8
6
  private readonly messageCallback;
9
7
  private wallet;
10
8
  private arkProvider;
11
9
  private indexerProvider;
12
10
  private vtxoSubscription;
13
- constructor(vtxoRepository?: VtxoRepository, messageCallback?: (message: ExtendableMessageEvent) => void);
11
+ private walletRepository;
12
+ private storage;
13
+ constructor(messageCallback?: (message: ExtendableMessageEvent) => void);
14
+ /**
15
+ * Get spendable vtxos for the current wallet address
16
+ */
17
+ private getSpendableVtxos;
18
+ /**
19
+ * Get swept vtxos for the current wallet address
20
+ */
21
+ private getSweptVtxos;
22
+ /**
23
+ * Get all vtxos categorized by type
24
+ */
25
+ private getAllVtxos;
14
26
  start(withServiceWorkerUpdate?: boolean): Promise<void>;
15
27
  clear(): Promise<void>;
16
28
  reload(): Promise<void>;
@@ -27,6 +39,6 @@ export declare class Worker {
27
39
  private handleGetBoardingUtxos;
28
40
  private handleGetTransactionHistory;
29
41
  private handleGetStatus;
30
- private handleSign;
31
42
  private handleMessage;
43
+ private sendMessageToAllClients;
32
44
  }
@@ -1,4 +1,4 @@
1
- import { Transaction } from "@scure/btc-signer";
1
+ import { Transaction } from "@scure/btc-signer/transaction.js";
2
2
  import { ChainTx, IndexerProvider } from "../providers/indexer";
3
3
  import { AnchorBumper } from "../utils/anchor";
4
4
  import { OnchainProvider } from "../providers/onchain";
@@ -5,9 +5,11 @@ import { OnchainProvider } from "../providers/onchain";
5
5
  import { SettlementEvent, ArkProvider } from "../providers/ark";
6
6
  import { Identity } from "../identity";
7
7
  import { ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, GetVtxosFilter, IWallet, SendBitcoinParams, SettleParams, VirtualCoin, WalletBalance, WalletConfig } from ".";
8
- import { Bytes } from "@scure/btc-signer/utils";
8
+ import { Bytes } from "@scure/btc-signer/utils.js";
9
9
  import { CSVMultisigTapscript } from "../script/tapscript";
10
10
  import { IndexerProvider } from "../providers/indexer";
11
+ import { WalletRepository } from "../repositories/walletRepository";
12
+ import { ContractRepository } from "../repositories/contractRepository";
11
13
  export type IncomingFunds = {
12
14
  type: "utxo";
13
15
  coins: Coin[];
@@ -54,6 +56,8 @@ export declare class Wallet implements IWallet {
54
56
  readonly forfeitOutputScript: Bytes;
55
57
  readonly dustAmount: bigint;
56
58
  static MIN_FEE_RATE: number;
59
+ readonly walletRepository: WalletRepository;
60
+ readonly contractRepository: ContractRepository;
57
61
  private constructor();
58
62
  static create(config: WalletConfig): Promise<Wallet>;
59
63
  get arkAddress(): ArkAddress;