@arkade-os/sdk 0.4.23 → 0.4.24

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 (40) hide show
  1. package/README.md +21 -1
  2. package/dist/cjs/contracts/contractManager.js +29 -4
  3. package/dist/cjs/contracts/contractWatcher.js +9 -3
  4. package/dist/cjs/contracts/handlers/default.js +3 -2
  5. package/dist/cjs/contracts/handlers/delegate.js +3 -2
  6. package/dist/cjs/contracts/handlers/helpers.js +2 -58
  7. package/dist/cjs/contracts/handlers/vhtlc.js +7 -6
  8. package/dist/cjs/contracts/vtxoOwnership.js +60 -0
  9. package/dist/cjs/index.js +3 -3
  10. package/dist/cjs/script/base.js +12 -47
  11. package/dist/cjs/script/tapscript.js +97 -73
  12. package/dist/cjs/utils/timelock.js +59 -0
  13. package/dist/cjs/utils/unknownFields.js +2 -39
  14. package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +59 -9
  15. package/dist/cjs/wallet/unroll.js +79 -67
  16. package/dist/cjs/wallet/wallet.js +78 -8
  17. package/dist/cjs/worker/expo/processors/contractPollProcessor.js +7 -2
  18. package/dist/esm/contracts/contractManager.js +29 -4
  19. package/dist/esm/contracts/contractWatcher.js +9 -3
  20. package/dist/esm/contracts/handlers/default.js +2 -1
  21. package/dist/esm/contracts/handlers/delegate.js +2 -1
  22. package/dist/esm/contracts/handlers/helpers.js +1 -22
  23. package/dist/esm/contracts/handlers/vhtlc.js +2 -1
  24. package/dist/esm/contracts/vtxoOwnership.js +53 -0
  25. package/dist/esm/index.js +1 -1
  26. package/dist/esm/script/base.js +12 -14
  27. package/dist/esm/script/tapscript.js +97 -40
  28. package/dist/esm/utils/timelock.js +22 -0
  29. package/dist/esm/utils/unknownFields.js +2 -6
  30. package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +59 -9
  31. package/dist/esm/wallet/unroll.js +78 -67
  32. package/dist/esm/wallet/wallet.js +76 -6
  33. package/dist/esm/worker/expo/processors/contractPollProcessor.js +7 -2
  34. package/dist/types/contracts/handlers/helpers.d.ts +0 -9
  35. package/dist/types/contracts/vtxoOwnership.d.ts +25 -0
  36. package/dist/types/index.d.ts +1 -1
  37. package/dist/types/script/tapscript.d.ts +4 -0
  38. package/dist/types/utils/timelock.d.ts +9 -0
  39. package/dist/types/wallet/unroll.d.ts +10 -0
  40. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { warnAndFilterVtxosForScript } from '../../../contracts/vtxoOwnership.js';
1
2
  export const CONTRACT_POLL_TASK_TYPE = "contract-poll";
2
3
  /**
3
4
  * Polls the indexer for the latest VTXO state of every contract and
@@ -40,8 +41,12 @@ export const contractPollProcessor = {
40
41
  hasMore = page ? vtxos.length === pageSize : false;
41
42
  pageIndex++;
42
43
  }
43
- await walletRepository.saveVtxos(contract.address, allVtxos);
44
- vtxosSaved += allVtxos.length;
44
+ // Skip wrong-script rows (legacy duplicates or indexer drift)
45
+ // before persisting; the loop must keep going for the remaining
46
+ // contracts even when one row is rejected.
47
+ const filtered = warnAndFilterVtxosForScript(allVtxos, contract.script, "contractPollProcessor");
48
+ await walletRepository.saveVtxos(contract.address, filtered);
49
+ vtxosSaved += filtered.length;
45
50
  contractsProcessed++;
46
51
  }
47
52
  return {
@@ -1,13 +1,4 @@
1
- import { RelativeTimelock } from "../../script/tapscript";
2
1
  import { Contract, PathContext } from "../types";
3
- /**
4
- * Convert RelativeTimelock to BIP68 sequence number.
5
- */
6
- export declare function timelockToSequence(timelock: RelativeTimelock): number;
7
- /**
8
- * Convert BIP68 sequence number back to RelativeTimelock.
9
- */
10
- export declare function sequenceToTimelock(sequence: number): RelativeTimelock;
11
2
  /**
12
3
  * Resolve wallet's role from explicit role or by matching descriptor/pubkey.
13
4
  */
@@ -0,0 +1,25 @@
1
+ import type { VirtualCoin } from "../wallet";
2
+ /**
3
+ * Tier 1 helpers that enforce VTXO ownership at call sites that already know
4
+ * the intended contract script. Address-keyed repositories may still hand back
5
+ * legacy duplicate rows under the wrong bucket; these helpers gate reads and
6
+ * writes so a wrong-script row never wins.
7
+ *
8
+ * `script` is the authoritative ownership key. Equality is strict: a missing
9
+ * or empty `vtxo.script` never matches.
10
+ */
11
+ export declare function vtxoOutpoint(vtxo: Pick<VirtualCoin, "txid" | "vout">): string;
12
+ export declare function isVtxoForScript(vtxo: Pick<VirtualCoin, "script">, script: string): boolean;
13
+ export declare function filterVtxosForScript<T extends Pick<VirtualCoin, "script">>(vtxos: T[], script: string): T[];
14
+ /**
15
+ * Background/indexer sync flavour: drop wrong-script rows and log enough
16
+ * context to identify each rejection. Returns only matching rows so the
17
+ * caller can keep going.
18
+ */
19
+ export declare function warnAndFilterVtxosForScript<T extends Pick<VirtualCoin, "txid" | "vout" | "script">>(vtxos: T[], script: string, context: string): T[];
20
+ /**
21
+ * User-initiated transaction/signing flavour: throw before persisting or
22
+ * signing inconsistent ownership state. Silently skipping here would hide a
23
+ * serious bug in the wallet's spend path.
24
+ */
25
+ export declare function validateVtxosForScript(vtxos: Array<Pick<VirtualCoin, "txid" | "vout" | "script">>, script: string, context: string): void;
@@ -51,7 +51,7 @@ export * as asset from "./extension/asset";
51
51
  import { ContractManager, ContractWatcher, contractHandlers, DefaultContractHandler, DelegateContractHandler, VHTLCContractHandler, encodeArkContract, decodeArkContract, contractFromArkContract, contractFromArkContractWithAddress, isArkContract } from "./contracts";
52
52
  import type { Contract, ContractVtxo, ContractState, ContractEvent, ContractEventCallback, ContractBalance, ContractWithVtxos, ContractHandler, PathSelection, PathContext, ContractManagerConfig, CreateContractParams, ContractWatcherConfig, ParsedArkContract, DefaultContractParams, DelegateContractParams, VHTLCContractParams } from "./contracts";
53
53
  import { IContractManager } from "./contracts/contractManager";
54
- import { timelockToSequence, sequenceToTimelock } from "./contracts/handlers/helpers";
54
+ import { timelockToSequence, sequenceToTimelock } from "./utils/timelock";
55
55
  import { closeDatabase, openDatabase } from "./repositories/indexedDB/manager";
56
56
  import { WalletMessageHandler, WalletNotInitializedError, ReadonlyWalletError, DelegatorNotConfiguredError } from "./wallet/serviceWorker/wallet-message-handler";
57
57
  import { MESSAGE_BUS_NOT_INITIALIZED, MessageBusNotInitializedError, ServiceWorkerTimeoutError } from "./worker/errors";
@@ -90,6 +90,7 @@ export declare namespace CSVMultisigTapscript {
90
90
  function decode(script: Uint8Array): Type;
91
91
  /** Return true when the tapscript is a CSV multisig tapscript. */
92
92
  function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
93
+ function isScriptValid(script: Uint8Array): true | Error;
93
94
  }
94
95
  /**
95
96
  * Combines a condition script with an exit closure. The resulting script requires
@@ -114,6 +115,7 @@ export declare namespace ConditionCSVMultisigTapscript {
114
115
  function decode(script: Uint8Array): Type;
115
116
  /** Return true when the tapscript is a condition + CSV multisig tapscript. */
116
117
  function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
118
+ function isScriptValid(script: Uint8Array): true | Error;
117
119
  }
118
120
  /**
119
121
  * Combines a condition script with a forfeit closure. The resulting script requires
@@ -138,6 +140,7 @@ export declare namespace ConditionMultisigTapscript {
138
140
  function decode(script: Uint8Array): Type;
139
141
  /** Return true when the tapscript is a condition + multisig tapscript. */
140
142
  function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
143
+ function isScriptValid(script: Uint8Array): true | Error;
141
144
  }
142
145
  /**
143
146
  * Implements an absolute timelock (CLTV) script combined with a forfeit closure.
@@ -162,4 +165,5 @@ export declare namespace CLTVMultisigTapscript {
162
165
  function decode(script: Uint8Array): Type;
163
166
  /** Return true when the tapscript is a CLTV multisig tapscript. */
164
167
  function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
168
+ function isScriptValid(script: Uint8Array): true | Error;
165
169
  }
@@ -0,0 +1,9 @@
1
+ import type { RelativeTimelock } from "../script/tapscript";
2
+ /**
3
+ * Convert RelativeTimelock to BIP68 sequence number.
4
+ */
5
+ export declare function timelockToSequence(timelock: RelativeTimelock): number;
6
+ /**
7
+ * Convert BIP68 sequence number back to RelativeTimelock.
8
+ */
9
+ export declare function sequenceToTimelock(sequence: number): RelativeTimelock;
@@ -15,6 +15,7 @@ export declare namespace Unroll {
15
15
  */
16
16
  type UnrollStep = {
17
17
  tx: Transaction;
18
+ pkg: [parent: string, child: string];
18
19
  };
19
20
  /**
20
21
  * Wait step where the transaction has to be confirmed onchain
@@ -102,3 +103,12 @@ export declare namespace Unroll {
102
103
  */
103
104
  function completeUnroll(wallet: Wallet, vtxoTxids: string[], outputAddress: string): Promise<string>;
104
105
  }
106
+ /**
107
+ * Prepares the transaction that spends the CSV path to complete unrolling a VTXO.
108
+ * @param wallet the wallet owning the VTXO(s)
109
+ * @param vtxoTxIds the txids of the VTXO(s) to complete unroll
110
+ * @param outputAddress the address to send the unrolled funds to
111
+ * @throws if the VTXO(s) are not fully unrolled, if the txids are not found, if the tx is not confirmed, if no exit path is found or not available
112
+ * @returns the transaction spending the unrolled funds
113
+ */
114
+ export declare function prepareUnrollTransaction(wallet: Wallet, vtxoTxIds: string[], outputAddress: string): Promise<Transaction>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/sdk",
3
- "version": "0.4.23",
3
+ "version": "0.4.24",
4
4
  "description": "TypeScript SDK for building Bitcoin wallets using the Arkade protocol",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",