@bsv/wallet-toolbox-client 2.4.21 → 2.5.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.
@@ -2094,6 +2094,7 @@ interface FindProvenTxReqsArgs extends FindSincePagedArgs {
2094
2094
  }
2095
2095
  interface FindProvenTxsArgs extends FindSincePagedArgs {
2096
2096
  partial: Partial<TableProvenTx>;
2097
+ txids?: string[];
2097
2098
  }
2098
2099
  interface FindStaleMerkleRootsArgs {
2099
2100
  height: number;
@@ -2604,7 +2605,8 @@ declare class ScriptTemplateBRC29 implements ScriptTemplate {
2604
2605
  getKeyID(): string;
2605
2606
  getKeyDeriver(privKey: PrivateKey | HexString): KeyDeriverApi;
2606
2607
  lock(lockerPrivKey: string, unlockerPubKey: string): LockingScript;
2607
- unlock(unlockerPrivKey: string, lockerPubKey: string, sourceSatoshis?: number, lockingScript?: Script): ScriptTemplateUnlock;
2608
+ unlock(unlockerPrivKey: PrivateKey | HexString, lockerPubKey: PublicKey | string, sourceSatoshis?: number, lockingScript?: Script): ScriptTemplateUnlock;
2609
+ unlockWithDerivedPrivateKey(derivedPrivateKey: PrivateKey, sourceSatoshis?: number, lockingScript?: Script): ScriptTemplateUnlock;
2608
2610
  /**
2609
2611
  * P2PKH unlock estimateLength is a constant
2610
2612
  */
@@ -3167,8 +3169,9 @@ declare class EntityProvenTx extends EntityBase<TableProvenTx> {
3167
3169
  /**
3168
3170
  * @returns desirialized `MerklePath` object, value is cached.
3169
3171
  */
3170
- getMerklePath(): MerklePath;
3172
+ getMerklePath(validateRoots?: boolean): MerklePath;
3171
3173
  _mp?: MerklePath;
3174
+ _mpUnchecked?: MerklePath;
3172
3175
  get provenTxId(): number;
3173
3176
  set provenTxId(v: number);
3174
3177
  get created_at(): Date;
@@ -3874,6 +3877,9 @@ declare abstract class StorageReaderWriter extends StorageReader {
3874
3877
  }
3875
3878
  interface StorageReaderWriterOptions extends StorageReaderOptions {}
3876
3879
  //#endregion
3880
+ //#region ../src/storage/methods/availableManagedChange.d.ts
3881
+ type ManagedChangeInputCandidate = Pick<TableOutput, 'outputId' | 'transactionId' | 'satoshis' | 'txid' | 'vout'>;
3882
+ //#endregion
3877
3883
  //#region ../src/storage/StorageProvider.d.ts
3878
3884
  declare abstract class StorageProvider extends StorageReaderWriter implements WalletStorageProvider {
3879
3885
  isDirty: boolean;
@@ -3898,7 +3904,32 @@ declare abstract class StorageProvider extends StorageReaderWriter implements Wa
3898
3904
  }>;
3899
3905
  abstract purgeData(params: PurgeParams, trx?: TrxToken): Promise<PurgeResults>;
3900
3906
  abstract allocateChangeInput(userId: number, basketId: number, targetSatoshis: number, exactSatoshis: number | undefined, excludeSending: boolean, transactionId: number): Promise<TableOutput | undefined>;
3907
+ /** Mark a planned set of change inputs spent within the caller's transaction. */
3908
+ markChangeInputsSpent(outputIds: number[], transactionId: number, trx: TrxToken): Promise<number>;
3909
+ /**
3910
+ * Insert outputs that do not need their generated ids returned to the
3911
+ * caller. Engines with a multi-row insert override this common-path helper;
3912
+ * the fallback preserves existing storage implementations unchanged.
3913
+ */
3914
+ insertOutputs(outputs: TableOutput[], trx?: TrxToken): Promise<void>;
3915
+ /** Return unreserved wallet-managed outputs eligible for automatic funding. */
3916
+ findAvailableManagedChangeInputs(userId: number, basketId: number, excludeSending: boolean, trx?: TrxToken): Promise<TableOutput[]>;
3917
+ /** Read only the fields needed by the in-memory funding planner. */
3918
+ findAvailableManagedChangeInputCandidates(userId: number, basketId: number, excludeSending: boolean, trx?: TrxToken): Promise<ManagedChangeInputCandidate[]>;
3919
+ /** Read the current status of a set of source transactions without loading raw transaction bytes. */
3920
+ findTransactionStatusesByIds(userId: number, transactionIds: number[], trx?: TrxToken): Promise<Map<number, TransactionStatus>>;
3921
+ /**
3922
+ * Lock and return the selected funding rows whose source transaction and
3923
+ * action-batch reservation state still permit allocation.
3924
+ */
3925
+ findFundingOutputsForUpdate(userId: number, outputIds: number[], statuses: TransactionStatus[], trx: TrxToken): Promise<Record<number, TableOutput>>;
3901
3926
  abstract getProvenOrRawTx(txid: string, trx?: TrxToken): Promise<ProvenOrRawTx>;
3927
+ /**
3928
+ * Resolve several transaction proofs in one storage operation when the
3929
+ * backend supports it. The default preserves compatibility for custom
3930
+ * providers; SQL and IndexedDB providers override this hot path.
3931
+ */
3932
+ getProvenOrRawTxs(txids: string[], trx?: TrxToken): Promise<Map<string, ProvenOrRawTx>>;
3902
3933
  abstract getRawTxOfKnownValidTransaction(txid?: string, offset?: number, length?: number, trx?: TrxToken): Promise<number[] | undefined>;
3903
3934
  abstract getLabelsForTransactionId(transactionId?: number, trx?: TrxToken): Promise<TableTxLabel[]>;
3904
3935
  abstract getTagsForOutputId(outputId: number, trx?: TrxToken): Promise<TableOutputTag[]>;
@@ -3922,6 +3953,8 @@ declare abstract class StorageProvider extends StorageReaderWriter implements Wa
3922
3953
  deleteActionBatchBlobRecords(_actionBatchId: number, _trx?: TrxToken): Promise<void>;
3923
3954
  getCapabilities(): Promise<StorageCapabilities>;
3924
3955
  protected supportsActionBatchPersistence(): boolean;
3956
+ /** Custom providers may require physical expiry cleanup before reservations are queried. */
3957
+ protected requiresActionBatchCleanupBeforeCreateAction(): boolean;
3925
3958
  beginActionBatch(auth: AuthId, args: BeginActionBatchArgs): Promise<BeginActionBatchResult>;
3926
3959
  extendActionBatch(auth: AuthId, args: ExtendActionBatchArgs): Promise<ExtendActionBatchResult>;
3927
3960
  renewActionBatch(auth: AuthId, batchId: string): Promise<RenewActionBatchResult>;
@@ -3940,7 +3973,7 @@ declare abstract class StorageProvider extends StorageReaderWriter implements Wa
3940
3973
  findOutputsByOutpointsForUpdate(userId: number, outpoints: Array<{
3941
3974
  txid: string;
3942
3975
  vout: number;
3943
- }>, trx: TrxToken): Promise<Record<string, TableOutput>>;
3976
+ }>, trx: TrxToken, _noScript?: boolean): Promise<Record<string, TableOutput>>;
3944
3977
  findOrInsertOutputBasketsBulk(userId: number, names: string[], trx?: TrxToken): Promise<Record<string, TableOutputBasket>>;
3945
3978
  findOrInsertOutputTagsBulk(userId: number, tags: string[], trx?: TrxToken): Promise<Record<string, TableOutputTag>>;
3946
3979
  findOrInsertTxLabelsBulk(userId: number, labels: string[], trx?: TrxToken): Promise<Record<string, TableTxLabel>>;
@@ -4032,6 +4065,7 @@ declare abstract class StorageProvider extends StorageReaderWriter implements Wa
4032
4065
  private handleProvenTxBranch;
4033
4066
  getValidBeefForTxid(...[txid, mergeToBeef, trustSelf, knownTxids, trx, requiredLevels, chainTracker, skipInvalidProofs]: [txid: string, mergeToBeef?: Beef, trustSelf?: TrustSelf, knownTxids?: string[], trx?: TrxToken, requiredLevels?: number, chainTracker?: ChainTracker, skipInvalidProofs?: boolean]): Promise<Beef | undefined>;
4034
4067
  getBeefForTransaction(txid: string, options: StorageGetBeefOptions): Promise<Beef>;
4068
+ getBeefForTransactions(txids: string[], options: StorageGetBeefOptions): Promise<Beef>;
4035
4069
  findMonitorEventById(id: number, trx?: TrxToken): Promise<TableMonitorEvent | undefined>;
4036
4070
  relinquishCertificate(auth: AuthId, args: RelinquishCertificateArgs): Promise<number>;
4037
4071
  relinquishOutput(auth: AuthId, args: RelinquishOutputArgs): Promise<number>;
@@ -4465,6 +4499,8 @@ interface StorageIdbSchema {
4465
4499
  value: TableOutput;
4466
4500
  indexes: {
4467
4501
  userId: number;
4502
+ userId_basketId: [number, number];
4503
+ txid_vout_userId: [string, number, number];
4468
4504
  transactionId: number;
4469
4505
  basketId: number;
4470
4506
  spentBy: string;
@@ -4572,6 +4608,7 @@ declare class StorageIdb extends StorageProvider implements WalletStorageProvide
4572
4608
  db?: IDBPDatabase<StorageIdbSchema>;
4573
4609
  constructor(options: StorageIdbOptions);
4574
4610
  protected supportsActionBatchPersistence(): boolean;
4611
+ protected requiresActionBatchCleanupBeforeCreateAction(): boolean;
4575
4612
  /**
4576
4613
  * This method must be called at least once before any other method accesses the database,
4577
4614
  * and each time the schema may have updated.
@@ -4639,6 +4676,7 @@ declare class StorageIdb extends StorageProvider implements WalletStorageProvide
4639
4676
  */
4640
4677
  allocateChangeInput(userId: number, basketId: number, targetSatoshis: number, exactSatoshis: number | undefined, excludeSending: boolean, transactionId: number): Promise<TableOutput | undefined>;
4641
4678
  getProvenOrRawTx(txid: string, trx?: TrxToken): Promise<ProvenOrRawTx>;
4679
+ getProvenOrRawTxs(txids: string[], trx?: TrxToken): Promise<Map<string, ProvenOrRawTx>>;
4642
4680
  getRawTxOfKnownValidTransaction(txid?: string, offset?: number, length?: number, trx?: TrxToken): Promise<number[] | undefined>;
4643
4681
  private getRawTxForSlice;
4644
4682
  private getRawTxFull;
@@ -4647,6 +4685,16 @@ declare class StorageIdb extends StorageProvider implements WalletStorageProvide
4647
4685
  listActions(auth: AuthId, vargs: Validation.ValidListActionsArgs): Promise<ListActionsResult>;
4648
4686
  listOutputs(auth: AuthId, vargs: Validation.ValidListOutputsArgs): Promise<ListOutputsResult>;
4649
4687
  countChangeInputs(userId: number, basketId: number, excludeSending: boolean): Promise<number>;
4688
+ findTransactionStatusesByIds(userId: number, transactionIds: number[], trx?: TrxToken): Promise<Map<number, TransactionStatus>>;
4689
+ private findOutputsByOutpointsInternal;
4690
+ findOutputsByOutpoints(userId: number, outpoints: Array<{
4691
+ txid: string;
4692
+ vout: number;
4693
+ }>, trx?: TrxToken): Promise<Record<string, TableOutput>>;
4694
+ findOutputsByOutpointsForUpdate(userId: number, outpoints: Array<{
4695
+ txid: string;
4696
+ vout: number;
4697
+ }>, trx: TrxToken, noScript?: boolean): Promise<Record<string, TableOutput>>;
4650
4698
  findCertificatesAuth(auth: AuthId, args: FindCertificatesArgs): Promise<TableCertificateX[]>;
4651
4699
  findOutputBasketsAuth(auth: AuthId, args: FindOutputBasketsArgs): Promise<TableOutputBasket[]>;
4652
4700
  findOutputsAuth(auth: AuthId, args: FindOutputsArgs): Promise<TableOutput[]>;
@@ -4739,6 +4787,7 @@ declare class StorageIdb extends StorageProvider implements WalletStorageProvide
4739
4787
  filterOutputBaskets(args: FindOutputBasketsArgs, filtered: (v: TableOutputBasket) => void): Promise<void>;
4740
4788
  findOutputBaskets(args: FindOutputBasketsArgs): Promise<TableOutputBasket[]>;
4741
4789
  private openOutputsCursor;
4790
+ private eligibleOutputTransactionIds;
4742
4791
  filterOutputs(args: FindOutputsArgs, filtered: (v: TableOutput) => void, tagIds?: number[], isQueryModeAll?: boolean): Promise<void>;
4743
4792
  private outputMatchesTags;
4744
4793
  findOutputs(args: FindOutputsArgs, tagIds?: number[], isQueryModeAll?: boolean): Promise<TableOutput[]>;
@@ -8246,9 +8295,9 @@ interface WalletArgs {
8246
8295
  */
8247
8296
  makeLogger?: MakeWalletLogger;
8248
8297
  /**
8249
- * Internal Wallet Toolbox optimization policy. `auto` negotiates the optional
8250
- * action-batch storage capability; `legacy` always uses per-action storage.
8251
- * This does not change the BRC-100 wallet interface.
8298
+ * Internal Wallet Toolbox optimization policy. `auto` (the default)
8299
+ * negotiates the optional action-batch storage capability; `legacy` always
8300
+ * uses per-action storage. This does not change the BRC-100 wallet interface.
8252
8301
  */
8253
8302
  actionBatchMode?: ActionBatchMode;
8254
8303
  /**
@@ -8839,7 +8888,7 @@ interface UMPTokenInteractor {
8839
8888
  *
8840
8889
  * @param hash The hash of the presentation key.
8841
8890
  * @returns The UMP token if found; otherwise, undefined.
8842
- * @throws Implementations should throw when absence cannot be established authoritatively.
8891
+ * @throws Implementations should throw when no verified token or clean empty response is available.
8843
8892
  */
8844
8893
  findByPresentationKeyHash: (hash: number[]) => Promise<UMPToken | undefined>;
8845
8894
  /**
@@ -8848,7 +8897,7 @@ interface UMPTokenInteractor {
8848
8897
  *
8849
8898
  * @param hash The hash of the recovery key.
8850
8899
  * @returns The UMP token if found; otherwise, undefined.
8851
- * @throws Implementations should throw when absence cannot be established authoritatively.
8900
+ * @throws Implementations should throw when no verified token or clean empty response is available.
8852
8901
  */
8853
8902
  findByRecoveryKeyHash: (hash: number[]) => Promise<UMPToken | undefined>;
8854
8903
  /**
@@ -8876,7 +8925,7 @@ interface UMPTokenLookupDiagnostics {
8876
8925
  }
8877
8926
  type UMPTokenLookupFailureReason = 'lookup-unavailable' | 'lookup-incomplete' | 'token-malformed' | 'token-ambiguous';
8878
8927
  /**
8879
- * Raised when UMP absence cannot be established authoritatively.
8928
+ * Raised when a UMP lookup yields neither a verified token nor a clean empty response.
8880
8929
  *
8881
8930
  * Callers must offer retry/recovery rather than treating this error as a new
8882
8931
  * account. Diagnostics contain counts only and never hashes, keys, or tokens.
@@ -8936,9 +8985,37 @@ declare class OverlayUMPTokenInteractor implements UMPTokenInteractor {
8936
8985
  */
8937
8986
  findByRecoveryKeyHash(hash: number[]): Promise<UMPToken | undefined>;
8938
8987
  private findToken;
8988
+ /**
8989
+ * Picks the newest rendition among distinct verified tokens, when possible.
8990
+ *
8991
+ * The on-chain UMP protocol expresses token updates by consumption: the
8992
+ * transaction creating a new rendition spends the previous rendition's
8993
+ * outpoint (there is no rendition counter field in the current format).
8994
+ * A candidate is therefore superseded when any other candidate's ancestry
8995
+ * (available from its BEEF) spends the candidate's outpoint.
8996
+ *
8997
+ * @returns The single unsuperseded candidate, or undefined when supersession
8998
+ * cannot be established for every stale candidate (e.g. forked tokens).
8999
+ */
9000
+ private resolveNewestToken;
9001
+ /**
9002
+ * Whether `tx` spends an input whose source output (available in the BEEF)
9003
+ * decodes as a UMP token sharing the candidate's presentation or recovery
9004
+ * hash — on-chain proof that the candidate is an update of a same-identity
9005
+ * predecessor rather than an independently minted token.
9006
+ */
9007
+ private consumesSameIdentityToken;
9008
+ /**
9009
+ * Accumulates every outpoint spent by `tx` and by the ancestor transactions
9010
+ * embedded in its BEEF, so supersession is detected even when intermediate
9011
+ * renditions are absent from the lookup answer. Iterative so arbitrarily
9012
+ * long update chains cannot exhaust the call stack.
9013
+ */
9014
+ private collectSpentOutpoints;
8939
9015
  private emptyLookupDiagnostics;
8940
9016
  private toLookupDiagnostics;
8941
9017
  private lookupDiagnosticAttributes;
9018
+ private captureLookupCompleted;
8942
9019
  private captureLookupFailure;
8943
9020
  /**
8944
9021
  * Creates or updates (replaces) a UMP token on-chain. If `oldTokenToConsume` is provided,