@arkade-os/sdk 0.3.8 → 0.3.10

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 (41) hide show
  1. package/README.md +78 -1
  2. package/dist/cjs/identity/singleKey.js +33 -1
  3. package/dist/cjs/index.js +17 -2
  4. package/dist/cjs/intent/index.js +31 -2
  5. package/dist/cjs/providers/ark.js +15 -5
  6. package/dist/cjs/providers/indexer.js +2 -2
  7. package/dist/cjs/wallet/batch.js +183 -0
  8. package/dist/cjs/wallet/index.js +15 -0
  9. package/dist/cjs/wallet/serviceWorker/request.js +0 -2
  10. package/dist/cjs/wallet/serviceWorker/wallet.js +98 -34
  11. package/dist/cjs/wallet/serviceWorker/worker.js +163 -72
  12. package/dist/cjs/wallet/utils.js +2 -2
  13. package/dist/cjs/wallet/vtxo-manager.js +5 -0
  14. package/dist/cjs/wallet/wallet.js +358 -360
  15. package/dist/esm/identity/singleKey.js +31 -0
  16. package/dist/esm/index.js +12 -7
  17. package/dist/esm/intent/index.js +31 -2
  18. package/dist/esm/providers/ark.js +15 -5
  19. package/dist/esm/providers/indexer.js +2 -2
  20. package/dist/esm/wallet/batch.js +180 -0
  21. package/dist/esm/wallet/index.js +14 -0
  22. package/dist/esm/wallet/serviceWorker/request.js +0 -2
  23. package/dist/esm/wallet/serviceWorker/wallet.js +96 -33
  24. package/dist/esm/wallet/serviceWorker/worker.js +165 -74
  25. package/dist/esm/wallet/utils.js +2 -2
  26. package/dist/esm/wallet/vtxo-manager.js +6 -1
  27. package/dist/esm/wallet/wallet.js +359 -363
  28. package/dist/types/identity/index.d.ts +5 -3
  29. package/dist/types/identity/singleKey.d.ts +20 -1
  30. package/dist/types/index.d.ts +11 -8
  31. package/dist/types/intent/index.d.ts +19 -2
  32. package/dist/types/providers/ark.d.ts +9 -8
  33. package/dist/types/providers/indexer.d.ts +2 -2
  34. package/dist/types/wallet/batch.d.ts +87 -0
  35. package/dist/types/wallet/index.d.ts +76 -16
  36. package/dist/types/wallet/serviceWorker/request.d.ts +5 -1
  37. package/dist/types/wallet/serviceWorker/wallet.d.ts +46 -15
  38. package/dist/types/wallet/serviceWorker/worker.d.ts +6 -3
  39. package/dist/types/wallet/utils.d.ts +8 -3
  40. package/dist/types/wallet/wallet.d.ts +87 -36
  41. package/package.json +1 -1
@@ -5,12 +5,16 @@ import { DefaultVtxo } from "../script/default";
5
5
  import { Network, NetworkName } from "../networks";
6
6
  import { OnchainProvider } from "../providers/onchain";
7
7
  import { SettlementEvent, ArkProvider, SignedIntent } from "../providers/ark";
8
- import { Identity } from "../identity";
9
- import { ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, GetVtxosFilter, IWallet, SendBitcoinParams, SettleParams, WalletBalance, WalletConfig } from ".";
8
+ import { SignerSession } from "../tree/signingSession";
9
+ import { Identity, ReadonlyIdentity } from "../identity";
10
+ import { ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, GetVtxosFilter, IReadonlyWallet, IWallet, ReadonlyWalletConfig, SendBitcoinParams, SettleParams, VirtualCoin, WalletBalance, WalletConfig } from ".";
11
+ import { TapLeafScript } from "../script/base";
10
12
  import { CSVMultisigTapscript } from "../script/tapscript";
13
+ import { Intent } from "../intent";
11
14
  import { IndexerProvider } from "../providers/indexer";
12
- import { WalletRepository } from "../repositories/walletRepository";
13
- import { ContractRepository } from "../repositories/contractRepository";
15
+ import { WalletRepository, WalletRepositoryImpl } from "../repositories/walletRepository";
16
+ import { ContractRepository, ContractRepositoryImpl } from "../repositories/contractRepository";
17
+ import { Batch } from "./batch";
14
18
  export type IncomingFunds = {
15
19
  type: "utxo";
16
20
  coins: Coin[];
@@ -19,6 +23,52 @@ export type IncomingFunds = {
19
23
  newVtxos: ExtendedVirtualCoin[];
20
24
  spentVtxos: ExtendedVirtualCoin[];
21
25
  };
26
+ export declare class ReadonlyWallet implements IReadonlyWallet {
27
+ readonly identity: ReadonlyIdentity;
28
+ readonly network: Network;
29
+ readonly onchainProvider: OnchainProvider;
30
+ readonly indexerProvider: IndexerProvider;
31
+ readonly arkServerPublicKey: Bytes;
32
+ readonly offchainTapscript: DefaultVtxo.Script;
33
+ readonly boardingTapscript: DefaultVtxo.Script;
34
+ readonly dustAmount: bigint;
35
+ readonly walletRepository: WalletRepository;
36
+ readonly contractRepository: ContractRepository;
37
+ protected constructor(identity: ReadonlyIdentity, network: Network, onchainProvider: OnchainProvider, indexerProvider: IndexerProvider, arkServerPublicKey: Bytes, offchainTapscript: DefaultVtxo.Script, boardingTapscript: DefaultVtxo.Script, dustAmount: bigint, walletRepository: WalletRepository, contractRepository: ContractRepository);
38
+ /**
39
+ * Protected helper to set up shared wallet configuration.
40
+ * Extracts common logic used by both ReadonlyWallet.create() and Wallet.create().
41
+ */
42
+ protected static setupWalletConfig(config: ReadonlyWalletConfig, pubkey: Uint8Array): Promise<{
43
+ arkProvider: ArkProvider;
44
+ indexerProvider: IndexerProvider;
45
+ onchainProvider: OnchainProvider;
46
+ network: Network;
47
+ networkName: NetworkName;
48
+ serverPubKey: Uint8Array<ArrayBuffer>;
49
+ offchainTapscript: DefaultVtxo.Script;
50
+ boardingTapscript: DefaultVtxo.Script;
51
+ dustAmount: bigint;
52
+ walletRepository: WalletRepositoryImpl;
53
+ contractRepository: ContractRepositoryImpl;
54
+ info: import("../providers/ark").ArkInfo;
55
+ }>;
56
+ static create(config: ReadonlyWalletConfig): Promise<ReadonlyWallet>;
57
+ get arkAddress(): ArkAddress;
58
+ getAddress(): Promise<string>;
59
+ getBoardingAddress(): Promise<string>;
60
+ getBalance(): Promise<WalletBalance>;
61
+ getVtxos(filter?: GetVtxosFilter): Promise<ExtendedVirtualCoin[]>;
62
+ protected getVirtualCoins(filter?: GetVtxosFilter): Promise<VirtualCoin[]>;
63
+ getTransactionHistory(): Promise<ArkTransaction[]>;
64
+ getBoardingTxs(): Promise<{
65
+ boardingTxs: ArkTransaction[];
66
+ commitmentsToIgnore: Set<string>;
67
+ }>;
68
+ getBoardingUtxos(): Promise<ExtendedCoin[]>;
69
+ notifyIncomingFunds(eventCallback: (coins: IncomingFunds) => void): Promise<() => void>;
70
+ fetchPendingTxs(): Promise<string[]>;
71
+ }
22
72
  /**
23
73
  * Main wallet implementation for Bitcoin transactions with Ark protocol support.
24
74
  * The wallet does not store any data locally and relies on Ark and onchain
@@ -52,52 +102,52 @@ export type IncomingFunds = {
52
102
  * });
53
103
  * ```
54
104
  */
55
- export declare class Wallet implements IWallet {
56
- readonly identity: Identity;
57
- readonly network: Network;
105
+ export declare class Wallet extends ReadonlyWallet implements IWallet {
58
106
  readonly networkName: NetworkName;
59
- readonly onchainProvider: OnchainProvider;
60
107
  readonly arkProvider: ArkProvider;
61
- readonly indexerProvider: IndexerProvider;
62
- readonly arkServerPublicKey: Bytes;
63
- readonly offchainTapscript: DefaultVtxo.Script;
64
- readonly boardingTapscript: DefaultVtxo.Script;
65
108
  readonly serverUnrollScript: CSVMultisigTapscript.Type;
66
109
  readonly forfeitOutputScript: Bytes;
67
110
  readonly forfeitPubkey: Bytes;
68
- readonly dustAmount: bigint;
69
111
  static MIN_FEE_RATE: number;
70
- readonly walletRepository: WalletRepository;
71
- readonly contractRepository: ContractRepository;
112
+ readonly identity: Identity;
72
113
  readonly renewalConfig: Required<Omit<WalletConfig["renewalConfig"], "enabled">> & {
73
114
  enabled: boolean;
74
115
  thresholdMs: number;
75
116
  };
76
- private constructor();
117
+ protected constructor(identity: Identity, network: Network, networkName: NetworkName, onchainProvider: OnchainProvider, arkProvider: ArkProvider, indexerProvider: IndexerProvider, arkServerPublicKey: Bytes, offchainTapscript: DefaultVtxo.Script, boardingTapscript: DefaultVtxo.Script, serverUnrollScript: CSVMultisigTapscript.Type, forfeitOutputScript: Bytes, forfeitPubkey: Bytes, dustAmount: bigint, walletRepository: WalletRepository, contractRepository: ContractRepository, renewalConfig?: WalletConfig["renewalConfig"]);
77
118
  static create(config: WalletConfig): Promise<Wallet>;
78
- get arkAddress(): ArkAddress;
79
- getAddress(): Promise<string>;
80
- getBoardingAddress(): Promise<string>;
81
- getBalance(): Promise<WalletBalance>;
82
- getVtxos(filter?: GetVtxosFilter): Promise<ExtendedVirtualCoin[]>;
83
- private getVirtualCoins;
84
- getTransactionHistory(): Promise<ArkTransaction[]>;
85
- getBoardingTxs(): Promise<{
86
- boardingTxs: ArkTransaction[];
87
- commitmentsToIgnore: Set<string>;
88
- }>;
89
- getBoardingUtxos(): Promise<ExtendedCoin[]>;
119
+ /**
120
+ * Convert this wallet to a readonly wallet.
121
+ *
122
+ * @returns A readonly wallet with the same configuration but readonly identity
123
+ * @example
124
+ * ```typescript
125
+ * const wallet = await Wallet.create({ identity: SingleKey.fromHex('...'), ... });
126
+ * const readonlyWallet = await wallet.toReadonly();
127
+ *
128
+ * // Can query balance and addresses
129
+ * const balance = await readonlyWallet.getBalance();
130
+ * const address = await readonlyWallet.getAddress();
131
+ *
132
+ * // But cannot send transactions (type error)
133
+ * // readonlyWallet.sendBitcoin(...); // TypeScript error
134
+ * ```
135
+ */
136
+ toReadonly(): Promise<ReadonlyWallet>;
90
137
  sendBitcoin(params: SendBitcoinParams): Promise<string>;
91
138
  settle(params?: SettleParams, eventCallback?: (event: SettlementEvent) => void): Promise<string>;
92
- notifyIncomingFunds(eventCallback: (coins: IncomingFunds) => void): Promise<() => void>;
93
- private handleBatchStartedEvent;
94
- private handleSettlementSigningEvent;
95
- private handleSettlementTreeNoncesEvent;
96
139
  private handleSettlementFinalizationEvent;
97
- safeRegisterIntent(intent: SignedIntent): Promise<string>;
98
- makeRegisterIntentSignature(coins: ExtendedCoin[], outputs: TransactionOutput[], onchainOutputsIndexes: number[], cosignerPubKeys: string[]): Promise<SignedIntent>;
99
- makeDeleteIntentSignature(coins: ExtendedCoin[]): Promise<SignedIntent>;
100
- makeGetPendingTxIntentSignature(vtxos: ExtendedVirtualCoin[]): Promise<SignedIntent>;
140
+ /**
141
+ * @implements Batch.Handler interface.
142
+ * @param intentId - The intent ID.
143
+ * @param inputs - The inputs of the intent.
144
+ * @param session - The musig2 signing session, if not provided, the signing will be skipped.
145
+ */
146
+ createBatchHandler(intentId: string, inputs: ExtendedCoin[], session?: SignerSession): Batch.Handler;
147
+ safeRegisterIntent(intent: SignedIntent<Intent.RegisterMessage>): Promise<string>;
148
+ makeRegisterIntentSignature(coins: ExtendedCoin[], outputs: TransactionOutput[], onchainOutputsIndexes: number[], cosignerPubKeys: string[]): Promise<SignedIntent<Intent.RegisterMessage>>;
149
+ makeDeleteIntentSignature(coins: ExtendedCoin[]): Promise<SignedIntent<Intent.DeleteMessage>>;
150
+ makeGetPendingTxIntentSignature(vtxos: ExtendedVirtualCoin[]): Promise<SignedIntent<Intent.GetPendingTxMessage>>;
101
151
  /**
102
152
  * Finalizes pending transactions by retrieving them from the server and finalizing each one.
103
153
  * @param vtxos - Optional list of VTXOs to use instead of retrieving them from the server
@@ -109,6 +159,7 @@ export declare class Wallet implements IWallet {
109
159
  }>;
110
160
  private prepareIntentProofInputs;
111
161
  }
162
+ export declare function getSequence(tapLeafScript: TapLeafScript): number | undefined;
112
163
  /**
113
164
  * Wait for incoming funds to the wallet
114
165
  * @param wallet - The wallet to wait for incoming funds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/sdk",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "Bitcoin wallet SDK with Taproot and Ark integration",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",