@arkade-os/sdk 0.3.1 → 0.3.3

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.
@@ -31,6 +31,7 @@ const deserializeTapLeaf = (t) => {
31
31
  };
32
32
  const deserializeVtxo = (o) => ({
33
33
  ...o,
34
+ createdAt: new Date(o.createdAt),
34
35
  tapTree: fromHex(o.tapTree),
35
36
  forfeitTapLeafScript: deserializeTapLeaf(o.forfeitTapLeafScript),
36
37
  intentTapLeafScript: deserializeTapLeaf(o.intentTapLeafScript),
@@ -69,6 +69,33 @@ class Worker {
69
69
  const address = await this.wallet.getBoardingAddress();
70
70
  return await this.walletRepository.getUtxos(address);
71
71
  }
72
+ async getTransactionHistory() {
73
+ if (!this.wallet)
74
+ return [];
75
+ let txs = [];
76
+ try {
77
+ const { boardingTxs, commitmentsToIgnore: roundsToIgnore } = await this.wallet.getBoardingTxs();
78
+ const { spendable, spent } = await this.getAllVtxos();
79
+ // convert VTXOs to offchain transactions
80
+ console.log("getTransactionHistory - vtxosToTxs:", spendable);
81
+ const offchainTxs = (0, transactionHistory_1.vtxosToTxs)(spendable, spent, roundsToIgnore);
82
+ txs = [...boardingTxs, ...offchainTxs];
83
+ // sort transactions by creation time in descending order (newest first)
84
+ txs.sort(
85
+ // place createdAt = 0 (unconfirmed txs) first, then descending
86
+ (a, b) => {
87
+ if (a.createdAt === 0)
88
+ return -1;
89
+ if (b.createdAt === 0)
90
+ return 1;
91
+ return b.createdAt - a.createdAt;
92
+ });
93
+ }
94
+ catch (error) {
95
+ console.error("Error getting transaction history:", error);
96
+ }
97
+ return txs;
98
+ }
72
99
  async start(withServiceWorkerUpdate = true) {
73
100
  self.addEventListener("message", async (event) => {
74
101
  await this.handleMessage(event);
@@ -115,8 +142,12 @@ class Worker {
115
142
  // Get wallet address and save vtxos using unified repository
116
143
  const address = await this.wallet.getAddress();
117
144
  await this.walletRepository.saveVtxos(address, vtxos);
145
+ // Fetch boarding utxos and save using unified repository
146
+ const boardingAddress = await this.wallet.getBoardingAddress();
147
+ const coins = await this.wallet.onchainProvider.getCoins(boardingAddress);
148
+ await this.walletRepository.saveUtxos(boardingAddress, coins.map((utxo) => (0, utils_1.extendCoin)(this.wallet, utxo)));
118
149
  // Get transaction history to cache boarding txs
119
- const txs = await this.wallet.getTransactionHistory();
150
+ const txs = await this.getTransactionHistory();
120
151
  if (txs)
121
152
  await this.walletRepository.saveTransactions(address, txs);
122
153
  // unsubscribe previous subscription if any
@@ -434,21 +465,7 @@ class Worker {
434
465
  return;
435
466
  }
436
467
  try {
437
- const { boardingTxs, commitmentsToIgnore: roundsToIgnore } = await this.wallet.getBoardingTxs();
438
- const { spendable, spent } = await this.getAllVtxos();
439
- // convert VTXOs to offchain transactions
440
- const offchainTxs = (0, transactionHistory_1.vtxosToTxs)(spendable, spent, roundsToIgnore);
441
- const txs = [...boardingTxs, ...offchainTxs];
442
- // sort transactions by creation time in descending order (newest first)
443
- txs.sort(
444
- // place createdAt = 0 (unconfirmed txs) first, then descending
445
- (a, b) => {
446
- if (a.createdAt === 0)
447
- return -1;
448
- if (b.createdAt === 0)
449
- return 1;
450
- return b.createdAt - a.createdAt;
451
- });
468
+ const txs = await this.getTransactionHistory();
452
469
  event.source?.postMessage(response_1.Response.transactionHistory(message.id, txs));
453
470
  }
454
471
  catch (error) {
@@ -28,6 +28,7 @@ const deserializeTapLeaf = (t) => {
28
28
  };
29
29
  const deserializeVtxo = (o) => ({
30
30
  ...o,
31
+ createdAt: new Date(o.createdAt),
31
32
  tapTree: fromHex(o.tapTree),
32
33
  forfeitTapLeafScript: deserializeTapLeaf(o.forfeitTapLeafScript),
33
34
  intentTapLeafScript: deserializeTapLeaf(o.intentTapLeafScript),
@@ -66,6 +66,33 @@ export class Worker {
66
66
  const address = await this.wallet.getBoardingAddress();
67
67
  return await this.walletRepository.getUtxos(address);
68
68
  }
69
+ async getTransactionHistory() {
70
+ if (!this.wallet)
71
+ return [];
72
+ let txs = [];
73
+ try {
74
+ const { boardingTxs, commitmentsToIgnore: roundsToIgnore } = await this.wallet.getBoardingTxs();
75
+ const { spendable, spent } = await this.getAllVtxos();
76
+ // convert VTXOs to offchain transactions
77
+ console.log("getTransactionHistory - vtxosToTxs:", spendable);
78
+ const offchainTxs = vtxosToTxs(spendable, spent, roundsToIgnore);
79
+ txs = [...boardingTxs, ...offchainTxs];
80
+ // sort transactions by creation time in descending order (newest first)
81
+ txs.sort(
82
+ // place createdAt = 0 (unconfirmed txs) first, then descending
83
+ (a, b) => {
84
+ if (a.createdAt === 0)
85
+ return -1;
86
+ if (b.createdAt === 0)
87
+ return 1;
88
+ return b.createdAt - a.createdAt;
89
+ });
90
+ }
91
+ catch (error) {
92
+ console.error("Error getting transaction history:", error);
93
+ }
94
+ return txs;
95
+ }
69
96
  async start(withServiceWorkerUpdate = true) {
70
97
  self.addEventListener("message", async (event) => {
71
98
  await this.handleMessage(event);
@@ -112,8 +139,12 @@ export class Worker {
112
139
  // Get wallet address and save vtxos using unified repository
113
140
  const address = await this.wallet.getAddress();
114
141
  await this.walletRepository.saveVtxos(address, vtxos);
142
+ // Fetch boarding utxos and save using unified repository
143
+ const boardingAddress = await this.wallet.getBoardingAddress();
144
+ const coins = await this.wallet.onchainProvider.getCoins(boardingAddress);
145
+ await this.walletRepository.saveUtxos(boardingAddress, coins.map((utxo) => extendCoin(this.wallet, utxo)));
115
146
  // Get transaction history to cache boarding txs
116
- const txs = await this.wallet.getTransactionHistory();
147
+ const txs = await this.getTransactionHistory();
117
148
  if (txs)
118
149
  await this.walletRepository.saveTransactions(address, txs);
119
150
  // unsubscribe previous subscription if any
@@ -431,21 +462,7 @@ export class Worker {
431
462
  return;
432
463
  }
433
464
  try {
434
- const { boardingTxs, commitmentsToIgnore: roundsToIgnore } = await this.wallet.getBoardingTxs();
435
- const { spendable, spent } = await this.getAllVtxos();
436
- // convert VTXOs to offchain transactions
437
- const offchainTxs = vtxosToTxs(spendable, spent, roundsToIgnore);
438
- const txs = [...boardingTxs, ...offchainTxs];
439
- // sort transactions by creation time in descending order (newest first)
440
- txs.sort(
441
- // place createdAt = 0 (unconfirmed txs) first, then descending
442
- (a, b) => {
443
- if (a.createdAt === 0)
444
- return -1;
445
- if (b.createdAt === 0)
446
- return 1;
447
- return b.createdAt - a.createdAt;
448
- });
465
+ const txs = await this.getTransactionHistory();
449
466
  event.source?.postMessage(Response.transactionHistory(message.id, txs));
450
467
  }
451
468
  catch (error) {
@@ -29,6 +29,7 @@ export declare class Worker {
29
29
  * Get all boarding utxos from wallet repository
30
30
  */
31
31
  private getAllBoardingUtxos;
32
+ private getTransactionHistory;
32
33
  start(withServiceWorkerUpdate?: boolean): Promise<void>;
33
34
  clear(): Promise<void>;
34
35
  reload(): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Bitcoin wallet SDK with Taproot and Ark integration",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",