UNPKG

@bsv/wallet-toolbox

Version:

BRC100 conforming wallet, wallet storage and wallet signer components

1,694 lines (1,330 loc) 231 kB
# STORAGE: BSV Wallet Toolbox API Documentation The documentation is split into various pages, this page covers the persistent storage of wallet data: transactions, outputs and metadata. The [WalletStorageManager](#class-walletstoragemanager) class manages a collection of storage providers of which one is the "active" storage at any one time, and the rest are backups. It manages access to wallet data, pushing incremental updates to backups, and switching the active to what was previously a backup. The [StorageClient](#class-storageclient) implements a cloud based storage provider via JSON-RPC. The [StorageServer](#class-storageserver) class and `@bsv/wallet-infra` package can be used to host such a JSON-RPC server. The [StorageKnex](#class-storageknex) class implements `Knex` based database storage with explicit support for both MySQL and SQLite. [Return To Top](./README.md) <!--#region ts2md-api-merged-here--> ### API Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) #### Interfaces | | | | | --- | --- | --- | | [AdminStatsResult](#interface-adminstatsresult) | [ProvenTxReqHistory](#interface-proventxreqhistory) | [TableOutputBasket](#interface-tableoutputbasket) | | [CommitNewTxResults](#interface-commitnewtxresults) | [ProvenTxReqHistorySummaryApi](#interface-proventxreqhistorysummaryapi) | [TableOutputTag](#interface-tableoutputtag) | | [EntitySyncMap](#interface-entitysyncmap) | [ProvenTxReqNotify](#interface-proventxreqnotify) | [TableOutputTagMap](#interface-tableoutputtagmap) | | [GenerateChangeSdkChangeInput](#interface-generatechangesdkchangeinput) | [StorageAdminStats](#interface-storageadminstats) | [TableOutputX](#interface-tableoutputx) | | [GenerateChangeSdkChangeOutput](#interface-generatechangesdkchangeoutput) | [StorageIdbOptions](#interface-storageidboptions) | [TableProvenTx](#interface-tableproventx) | | [GenerateChangeSdkInput](#interface-generatechangesdkinput) | [StorageIdbSchema](#interface-storageidbschema) | [TableProvenTxReq](#interface-tableproventxreq) | | [GenerateChangeSdkOutput](#interface-generatechangesdkoutput) | [StorageKnexOptions](#interface-storageknexoptions) | [TableProvenTxReqDynamics](#interface-tableproventxreqdynamics) | | [GenerateChangeSdkParams](#interface-generatechangesdkparams) | [StorageProviderOptions](#interface-storageprovideroptions) | [TableSettings](#interface-tablesettings) | | [GenerateChangeSdkResult](#interface-generatechangesdkresult) | [StorageReaderOptions](#interface-storagereaderoptions) | [TableSyncState](#interface-tablesyncstate) | | [GenerateChangeSdkStorageChange](#interface-generatechangesdkstoragechange) | [StorageReaderWriterOptions](#interface-storagereaderwriteroptions) | [TableTransaction](#interface-tabletransaction) | | [GetReqsAndBeefDetail](#interface-getreqsandbeefdetail) | [SyncError](#interface-syncerror) | [TableTxLabel](#interface-tabletxlabel) | | [GetReqsAndBeefResult](#interface-getreqsandbeefresult) | [SyncMap](#interface-syncmap) | [TableTxLabelMap](#interface-tabletxlabelmap) | | [ListActionsSpecOp](#interface-listactionsspecop) | [TableCertificate](#interface-tablecertificate) | [TableUser](#interface-tableuser) | | [ListOutputsSpecOp](#interface-listoutputsspecop) | [TableCertificateField](#interface-tablecertificatefield) | [ValidateGenerateChangeSdkParamsResult](#interface-validategeneratechangesdkparamsresult) | | [PostBeefResultForTxidApi](#interface-postbeefresultfortxidapi) | [TableCertificateX](#interface-tablecertificatex) | [WalletStorageServerOptions](#interface-walletstorageserveroptions) | | [PostReqsToNetworkDetails](#interface-postreqstonetworkdetails) | [TableCommission](#interface-tablecommission) | [XValidCreateActionOutput](#interface-xvalidcreateactionoutput) | | [PostReqsToNetworkResult](#interface-postreqstonetworkresult) | [TableMonitorEvent](#interface-tablemonitorevent) | | | [ProvenTxFromTxidResult](#interface-proventxfromtxidresult) | [TableOutput](#interface-tableoutput) | | Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: AdminStatsResult ```ts export interface AdminStatsResult extends StorageAdminStats { servicesStats?: ServicesCallHistory; monitorStats?: ServicesCallHistory; } ``` See also: [ServicesCallHistory](./client.md#type-servicescallhistory), [StorageAdminStats](./storage.md#interface-storageadminstats) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: CommitNewTxResults ```ts export interface CommitNewTxResults { req: EntityProvenTxReq; log?: string; } ``` See also: [EntityProvenTxReq](./storage.md#class-entityproventxreq) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: EntitySyncMap ```ts export interface EntitySyncMap { entityName: string; idMap: Record<number, number>; maxUpdated_at?: Date; count: number; } ``` ###### Property count The cummulative count of items of this entity type received over all the `SyncChunk`s since the `since` was last updated. This is the `offset` value to use for the next SyncChunk request. ```ts count: number ``` ###### Property idMap Maps foreign ids to local ids Some entities don't have idMaps (CertificateField, TxLabelMap and OutputTagMap) ```ts idMap: Record<number, number> ``` ###### Property maxUpdated_at the maximum updated_at value seen for this entity over chunks received during this udpate cycle. ```ts maxUpdated_at?: Date ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: GenerateChangeSdkChangeInput ```ts export interface GenerateChangeSdkChangeInput { outputId: number; satoshis: number; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: GenerateChangeSdkChangeOutput ```ts export interface GenerateChangeSdkChangeOutput { satoshis: number; lockingScriptLength: number; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: GenerateChangeSdkInput ```ts export interface GenerateChangeSdkInput { satoshis: number; unlockingScriptLength: number; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: GenerateChangeSdkOutput ```ts export interface GenerateChangeSdkOutput { satoshis: number; lockingScriptLength: number; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: GenerateChangeSdkParams ```ts export interface GenerateChangeSdkParams { fixedInputs: GenerateChangeSdkInput[]; fixedOutputs: GenerateChangeSdkOutput[]; feeModel: sdk.StorageFeeModel; targetNetCount?: number; changeInitialSatoshis: number; changeFirstSatoshis: number; changeLockingScriptLength: number; changeUnlockingScriptLength: number; randomVals?: number[]; noLogging?: boolean; log?: string; } ``` See also: [GenerateChangeSdkInput](./storage.md#interface-generatechangesdkinput), [GenerateChangeSdkOutput](./storage.md#interface-generatechangesdkoutput), [StorageFeeModel](./client.md#interface-storagefeemodel) ###### Property changeFirstSatoshis Lowest amount value to assign to a change output. Drop the output if unable to satisfy. default 285 ```ts changeFirstSatoshis: number ``` ###### Property changeInitialSatoshis Satoshi amount to initialize optional new change outputs. ```ts changeInitialSatoshis: number ``` ###### Property changeLockingScriptLength Fixed change locking script length. For P2PKH template, 25 bytes ```ts changeLockingScriptLength: number ``` ###### Property changeUnlockingScriptLength Fixed change unlocking script length. For P2PKH template, 107 bytes ```ts changeUnlockingScriptLength: number ``` ###### Property targetNetCount Target for number of new change outputs added minus number of funding change outputs consumed. If undefined, only a single change output will be added if excess fees must be recaptured. ```ts targetNetCount?: number ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: GenerateChangeSdkResult ```ts export interface GenerateChangeSdkResult { allocatedChangeInputs: GenerateChangeSdkChangeInput[]; changeOutputs: GenerateChangeSdkChangeOutput[]; size: number; fee: number; satsPerKb: number; maxPossibleSatoshisAdjustment?: { fixedOutputIndex: number; satoshis: number; }; } ``` See also: [GenerateChangeSdkChangeInput](./storage.md#interface-generatechangesdkchangeinput), [GenerateChangeSdkChangeOutput](./storage.md#interface-generatechangesdkchangeoutput) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: GenerateChangeSdkStorageChange ```ts export interface GenerateChangeSdkStorageChange extends GenerateChangeSdkChangeInput { spendable: boolean; } ``` See also: [GenerateChangeSdkChangeInput](./storage.md#interface-generatechangesdkchangeinput) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: GetReqsAndBeefDetail ```ts export interface GetReqsAndBeefDetail { txid: string; req?: TableProvenTxReq; proven?: TableProvenTx; status: "readyToSend" | "alreadySent" | "error" | "unknown"; error?: string; } ``` See also: [TableProvenTx](./storage.md#interface-tableproventx), [TableProvenTxReq](./storage.md#interface-tableproventxreq) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: GetReqsAndBeefResult ```ts export interface GetReqsAndBeefResult { beef: Beef; details: GetReqsAndBeefDetail[]; } ``` See also: [GetReqsAndBeefDetail](./storage.md#interface-getreqsandbeefdetail) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: ListActionsSpecOp ```ts export interface ListActionsSpecOp { name: string; labelsToIntercept?: string[]; setStatusFilter?: () => sdk.TransactionStatus[]; postProcess?: (s: StorageProvider, auth: sdk.AuthId, vargs: sdk.ValidListActionsArgs, specOpLabels: string[], txs: Partial<TableTransaction>[]) => Promise<void>; } ``` See also: [AuthId](./client.md#interface-authid), [StorageProvider](./storage.md#class-storageprovider), [TableTransaction](./storage.md#interface-tabletransaction), [TransactionStatus](./client.md#type-transactionstatus), [ValidListActionsArgs](./client.md#interface-validlistactionsargs) ###### Property labelsToIntercept undefined to intercept no labels from vargs, empty array to intercept all labels, or an explicit array of labels to intercept. ```ts labelsToIntercept?: string[] ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: ListOutputsSpecOp ```ts export interface ListOutputsSpecOp { name: string; useBasket?: string; ignoreLimit?: boolean; includeOutputScripts?: boolean; includeSpent?: boolean; resultFromTags?: (s: StorageProvider, auth: sdk.AuthId, vargs: ValidListOutputsArgs, specOpTags: string[]) => Promise<ListOutputsResult>; resultFromOutputs?: (s: StorageProvider, auth: sdk.AuthId, vargs: ValidListOutputsArgs, specOpTags: string[], outputs: TableOutput[]) => Promise<ListOutputsResult>; filterOutputs?: (s: StorageProvider, auth: sdk.AuthId, vargs: ValidListOutputsArgs, specOpTags: string[], outputs: TableOutput[]) => Promise<TableOutput[]>; tagsToIntercept?: string[]; tagsParamsCount?: number; } ``` See also: [AuthId](./client.md#interface-authid), [StorageProvider](./storage.md#class-storageprovider), [TableOutput](./storage.md#interface-tableoutput), [ValidListOutputsArgs](./client.md#interface-validlistoutputsargs) ###### Property tagsParamsCount How many positional tags to intercept. ```ts tagsParamsCount?: number ``` ###### Property tagsToIntercept undefined to intercept no tags from vargs, empty array to intercept all tags, or an explicit array of tags to intercept. ```ts tagsToIntercept?: string[] ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: PostBeefResultForTxidApi ```ts export interface PostBeefResultForTxidApi { txid: string; status: "success" | "error"; alreadyKnown?: boolean; blockHash?: string; blockHeight?: number; merklePath?: string; } ``` ###### Property alreadyKnown if true, the transaction was already known to this service. Usually treat as a success. Potentially stop posting to additional transaction processors. ```ts alreadyKnown?: boolean ``` ###### Property status 'success' - The transaction was accepted for processing ```ts status: "success" | "error" ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: PostReqsToNetworkDetails ```ts export interface PostReqsToNetworkDetails { txid: string; req: EntityProvenTxReq; status: PostReqsToNetworkDetailsStatus; competingTxs?: string[]; } ``` See also: [EntityProvenTxReq](./storage.md#class-entityproventxreq), [PostReqsToNetworkDetailsStatus](./storage.md#type-postreqstonetworkdetailsstatus) ###### Property competingTxs Any competing double spend txids reported for this txid ```ts competingTxs?: string[] ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: PostReqsToNetworkResult ```ts export interface PostReqsToNetworkResult { status: "success" | "error"; beef: Beef; details: PostReqsToNetworkDetails[]; log: string; } ``` See also: [PostReqsToNetworkDetails](./storage.md#interface-postreqstonetworkdetails) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: ProvenTxFromTxidResult ```ts export interface ProvenTxFromTxidResult { proven?: EntityProvenTx; rawTx?: number[]; } ``` See also: [EntityProvenTx](./storage.md#class-entityproventx) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: ProvenTxReqHistory ```ts export interface ProvenTxReqHistory { notes?: sdk.ReqHistoryNote[]; } ``` See also: [ReqHistoryNote](./client.md#type-reqhistorynote) ###### Property notes Keys are Date().toISOString() Values are a description of what happened. ```ts notes?: sdk.ReqHistoryNote[] ``` See also: [ReqHistoryNote](./client.md#type-reqhistorynote) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: ProvenTxReqHistorySummaryApi ```ts export interface ProvenTxReqHistorySummaryApi { setToCompleted: boolean; setToCallback: boolean; setToUnmined: boolean; setToDoubleSpend: boolean; setToSending: boolean; setToUnconfirmed: boolean; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: ProvenTxReqNotify ```ts export interface ProvenTxReqNotify { transactionIds?: number[]; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: StorageAdminStats ```ts export interface StorageAdminStats { requestedBy: string; when: string; usersDay: number; usersWeek: number; usersMonth: number; usersTotal: number; transactionsDay: number; transactionsWeek: number; transactionsMonth: number; transactionsTotal: number; txCompletedDay: number; txCompletedWeek: number; txCompletedMonth: number; txCompletedTotal: number; txFailedDay: number; txFailedWeek: number; txFailedMonth: number; txFailedTotal: number; txUnprocessedDay: number; txUnprocessedWeek: number; txUnprocessedMonth: number; txUnprocessedTotal: number; txSendingDay: number; txSendingWeek: number; txSendingMonth: number; txSendingTotal: number; txUnprovenDay: number; txUnprovenWeek: number; txUnprovenMonth: number; txUnprovenTotal: number; txUnsignedDay: number; txUnsignedWeek: number; txUnsignedMonth: number; txUnsignedTotal: number; txNosendDay: number; txNosendWeek: number; txNosendMonth: number; txNosendTotal: number; txNonfinalDay: number; txNonfinalWeek: number; txNonfinalMonth: number; txNonfinalTotal: number; txUnfailDay: number; txUnfailWeek: number; txUnfailMonth: number; txUnfailTotal: number; satoshisDefaultDay: number; satoshisDefaultWeek: number; satoshisDefaultMonth: number; satoshisDefaultTotal: number; satoshisOtherDay: number; satoshisOtherWeek: number; satoshisOtherMonth: number; satoshisOtherTotal: number; basketsDay: number; basketsWeek: number; basketsMonth: number; basketsTotal: number; labelsDay: number; labelsWeek: number; labelsMonth: number; labelsTotal: number; tagsDay: number; tagsWeek: number; tagsMonth: number; tagsTotal: number; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: StorageIdbOptions ```ts export interface StorageIdbOptions extends StorageProviderOptions { } ``` See also: [StorageProviderOptions](./storage.md#interface-storageprovideroptions) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: StorageIdbSchema ```ts export interface StorageIdbSchema { certificates: { key: number; value: TableCertificate; indexes: { userId: number; userId_type_certifier_serialNumber: [ number, Base64String, PubKeyHex, Base64String ]; }; }; certificateFields: { key: number; value: TableCertificateField; indexes: { userId: number; certificateId: number; }; }; commissions: { key: number; value: TableCommission; indexes: { userId: number; transactionId: number; }; }; monitorEvents: { key: number; value: TableMonitorEvent; }; outputs: { key: number; value: TableOutput; indexes: { userId: number; transactionId: number; basketId: number; spentBy: string; transactionId_vout_userId: [ number, number, number ]; }; }; outputBaskets: { key: number; value: TableOutputBasket; indexes: { userId: number; name_userId: [ string, number ]; }; }; outputTags: { key: number; value: TableOutputTag; indexes: { userId: number; tag_userId: [ string, number ]; }; }; outputTagMaps: { key: number; value: TableOutputTagMap; indexes: { outputTagId: number; outputId: number; }; }; provenTxs: { key: number; value: TableProvenTx; indexes: { txid: HexString; }; }; provenTxReqs: { key: number; value: TableProvenTxReq; indexes: { provenTxId: number; txid: HexString; status: ProvenTxReqStatus; batch: string; }; }; syncStates: { key: number; value: TableSyncState; indexes: { userId: number; refNum: string; status: SyncStatus; }; }; settings: { key: number; value: TableSettings; indexes: Record<string, never>; }; transactions: { key: number; value: TableTransaction; indexes: { userId: number; provenTxId: number; reference: string; status: TransactionStatus; }; }; txLabels: { key: number; value: TableTxLabel; indexes: { userId: number; label_userId: [ string, number ]; }; }; txLabelMaps: { key: number; value: TableTxLabelMap; indexes: { transactionId: number; txLabelId: number; }; }; users: { key: number; value: TableUser; indexes: { identityKey: string; }; }; } ``` See also: [ProvenTxReqStatus](./client.md#type-proventxreqstatus), [SyncStatus](./client.md#type-syncstatus), [TableCertificate](./storage.md#interface-tablecertificate), [TableCertificateField](./storage.md#interface-tablecertificatefield), [TableCommission](./storage.md#interface-tablecommission), [TableMonitorEvent](./storage.md#interface-tablemonitorevent), [TableOutput](./storage.md#interface-tableoutput), [TableOutputBasket](./storage.md#interface-tableoutputbasket), [TableOutputTag](./storage.md#interface-tableoutputtag), [TableOutputTagMap](./storage.md#interface-tableoutputtagmap), [TableProvenTx](./storage.md#interface-tableproventx), [TableProvenTxReq](./storage.md#interface-tableproventxreq), [TableSettings](./storage.md#interface-tablesettings), [TableSyncState](./storage.md#interface-tablesyncstate), [TableTransaction](./storage.md#interface-tabletransaction), [TableTxLabel](./storage.md#interface-tabletxlabel), [TableTxLabelMap](./storage.md#interface-tabletxlabelmap), [TableUser](./storage.md#interface-tableuser), [TransactionStatus](./client.md#type-transactionstatus) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: StorageKnexOptions ```ts export interface StorageKnexOptions extends StorageProviderOptions { knex: Knex; } ``` See also: [StorageProviderOptions](./storage.md#interface-storageprovideroptions) ###### Property knex Knex database interface initialized with valid connection configuration. ```ts knex: Knex ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: StorageProviderOptions ```ts export interface StorageProviderOptions extends StorageReaderWriterOptions { chain: sdk.Chain; feeModel: sdk.StorageFeeModel; commissionSatoshis: number; commissionPubKeyHex?: PubKeyHex; } ``` See also: [Chain](./client.md#type-chain), [StorageFeeModel](./client.md#interface-storagefeemodel), [StorageReaderWriterOptions](./storage.md#interface-storagereaderwriteroptions) ###### Property commissionPubKeyHex If commissionSatoshis is greater than zero, must be a valid public key hex string. The actual locking script for each commission will use a public key derived from this key by information stored in the commissions table. ```ts commissionPubKeyHex?: PubKeyHex ``` ###### Property commissionSatoshis Transactions created by this Storage can charge a fee per transaction. A value of zero disables commission fees. ```ts commissionSatoshis: number ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: StorageReaderOptions ```ts export interface StorageReaderOptions { chain: sdk.Chain; } ``` See also: [Chain](./client.md#type-chain) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: StorageReaderWriterOptions ```ts export interface StorageReaderWriterOptions extends StorageReaderOptions { } ``` See also: [StorageReaderOptions](./storage.md#interface-storagereaderoptions) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: SyncError ```ts export interface SyncError { code: string; description: string; stack?: string; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: SyncMap ```ts export interface SyncMap { provenTx: EntitySyncMap; outputBasket: EntitySyncMap; transaction: EntitySyncMap; provenTxReq: EntitySyncMap; txLabel: EntitySyncMap; txLabelMap: EntitySyncMap; output: EntitySyncMap; outputTag: EntitySyncMap; outputTagMap: EntitySyncMap; certificate: EntitySyncMap; certificateField: EntitySyncMap; commission: EntitySyncMap; } ``` See also: [EntitySyncMap](./storage.md#interface-entitysyncmap) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableCertificate ```ts export interface TableCertificate extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; certificateId: number; userId: number; type: Base64String; serialNumber: Base64String; certifier: PubKeyHex; subject: PubKeyHex; verifier?: PubKeyHex; revocationOutpoint: OutpointString; signature: HexString; isDeleted: boolean; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableCertificateField ```ts export interface TableCertificateField extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; userId: number; certificateId: number; fieldName: string; fieldValue: string; masterKey: Base64String; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableCertificateX ```ts export interface TableCertificateX extends TableCertificate { fields?: TableCertificateField[]; } ``` See also: [TableCertificate](./storage.md#interface-tablecertificate), [TableCertificateField](./storage.md#interface-tablecertificatefield) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableCommission ```ts export interface TableCommission extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; commissionId: number; userId: number; transactionId: number; satoshis: number; keyOffset: string; isRedeemed: boolean; lockingScript: number[]; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableMonitorEvent ```ts export interface TableMonitorEvent extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; id: number; event: string; details?: string; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableOutput ```ts export interface TableOutput extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; outputId: number; userId: number; transactionId: number; basketId?: number; spendable: boolean; change: boolean; outputDescription: DescriptionString5to50Bytes; vout: number; satoshis: number; providedBy: sdk.StorageProvidedBy; purpose: string; type: string; txid?: string; senderIdentityKey?: PubKeyHex; derivationPrefix?: Base64String; derivationSuffix?: Base64String; customInstructions?: string; spentBy?: number; sequenceNumber?: number; spendingDescription?: string; scriptLength?: number; scriptOffset?: number; lockingScript?: number[]; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp), [StorageProvidedBy](./client.md#type-storageprovidedby) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableOutputBasket ```ts export interface TableOutputBasket extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; basketId: number; userId: number; name: string; numberOfDesiredUTXOs: number; minimumDesiredUTXOValue: number; isDeleted: boolean; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableOutputTag ```ts export interface TableOutputTag extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; outputTagId: number; userId: number; tag: string; isDeleted: boolean; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableOutputTagMap ```ts export interface TableOutputTagMap extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; outputTagId: number; outputId: number; isDeleted: boolean; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableOutputX ```ts export interface TableOutputX extends TableOutput { basket?: TableOutputBasket; tags?: TableOutputTag[]; } ``` See also: [TableOutput](./storage.md#interface-tableoutput), [TableOutputBasket](./storage.md#interface-tableoutputbasket), [TableOutputTag](./storage.md#interface-tableoutputtag) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableProvenTx ```ts export interface TableProvenTx extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; provenTxId: number; txid: string; height: number; index: number; merklePath: number[]; rawTx: number[]; blockHash: string; merkleRoot: string; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableProvenTxReq ```ts export interface TableProvenTxReq extends TableProvenTxReqDynamics { created_at: Date; updated_at: Date; provenTxReqId: number; provenTxId?: number; status: sdk.ProvenTxReqStatus; attempts: number; notified: boolean; txid: string; batch?: string; history: string; notify: string; rawTx: number[]; inputBEEF?: number[]; } ``` See also: [ProvenTxReqStatus](./client.md#type-proventxreqstatus), [TableProvenTxReqDynamics](./storage.md#interface-tableproventxreqdynamics) ###### Property attempts Count of how many times a service has been asked about this txid ```ts attempts: number ``` ###### Property batch If valid, a unique string identifying a batch of transactions to be sent together for processing. ```ts batch?: string ``` ###### Property history JSON string of processing history. Parses to `ProvenTxReqHistoryApi`. ```ts history: string ``` ###### Property notified Set to true when a terminal status has been set and notification has occurred. ```ts notified: boolean ``` ###### Property notify JSON string of data to drive notifications when this request completes. Parses to `ProvenTxReqNotifyApi`. ```ts notify: string ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableProvenTxReqDynamics Table properties that may change after initial record insertion. ```ts export interface TableProvenTxReqDynamics extends sdk.EntityTimeStamp { updated_at: Date; provenTxId?: number; status: sdk.ProvenTxReqStatus; attempts: number; notified: boolean; batch?: string; history: string; notify: string; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp), [ProvenTxReqStatus](./client.md#type-proventxreqstatus) ###### Property attempts Count of how many times a service has been asked about this txid ```ts attempts: number ``` ###### Property batch If valid, a unique string identifying a batch of transactions to be sent together for processing. ```ts batch?: string ``` ###### Property history JSON string of processing history. Parses to `ProvenTxReqHistoryApi`. ```ts history: string ``` ###### Property notified Set to true when a terminal status has been set and notification has occurred. ```ts notified: boolean ``` ###### Property notify JSON string of data to drive notifications when this request completes. Parses to `ProvenTxReqNotifyApi`. ```ts notify: string ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableSettings ```ts export interface TableSettings extends sdk.StorageIdentity, sdk.EntityTimeStamp { created_at: Date; updated_at: Date; storageIdentityKey: string; storageName: string; chain: sdk.Chain; dbtype: "SQLite" | "MySQL" | "IndexedDB"; maxOutputScript: number; } ``` See also: [Chain](./client.md#type-chain), [EntityTimeStamp](./client.md#interface-entitytimestamp), [StorageIdentity](./client.md#interface-storageidentity) ###### Property storageIdentityKey The identity key (public key) assigned to this storage ```ts storageIdentityKey: string ``` ###### Property storageName The human readable name assigned to this storage. ```ts storageName: string ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableSyncState ```ts export interface TableSyncState extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; syncStateId: number; userId: number; storageIdentityKey: string; storageName: string; status: sdk.SyncStatus; init: boolean; refNum: string; syncMap: string; when?: Date; satoshis?: number; errorLocal?: string; errorOther?: string; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp), [SyncStatus](./client.md#type-syncstatus) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableTransaction ```ts export interface TableTransaction extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; transactionId: number; userId: number; provenTxId?: number; status: sdk.TransactionStatus; reference: Base64String; isOutgoing: boolean; satoshis: number; description: string; version?: number; lockTime?: number; txid?: string; inputBEEF?: number[]; rawTx?: number[]; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp), [TransactionStatus](./client.md#type-transactionstatus) ###### Property isOutgoing true if transaction originated in this wallet, change returns to it. false for a transaction created externally and handed in to this wallet. ```ts isOutgoing: boolean ``` ###### Property lockTime Optional. Default is zero. When the transaction can be processed into a block: >= 500,000,000 values are interpreted as minimum required unix time stamps in seconds < 500,000,000 values are interpreted as minimum required block height ```ts lockTime?: number ``` ###### Property reference max length of 64, hex encoded ```ts reference: Base64String ``` ###### Property version If not undefined, must match value in associated rawTransaction. ```ts version?: number ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableTxLabel ```ts export interface TableTxLabel extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; txLabelId: number; userId: number; label: string; isDeleted: boolean; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableTxLabelMap ```ts export interface TableTxLabelMap extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; txLabelId: number; transactionId: number; isDeleted: boolean; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: TableUser ```ts export interface TableUser extends sdk.EntityTimeStamp { created_at: Date; updated_at: Date; userId: number; identityKey: string; activeStorage: string; } ``` See also: [EntityTimeStamp](./client.md#interface-entitytimestamp) ###### Property activeStorage The storageIdentityKey value of the active wallet storage. ```ts activeStorage: string ``` ###### Property identityKey PubKeyHex uniquely identifying user. Typically 66 hex digits. ```ts identityKey: string ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: ValidateGenerateChangeSdkParamsResult ```ts export interface ValidateGenerateChangeSdkParamsResult { hasMaxPossibleOutput?: number; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: WalletStorageServerOptions ```ts export interface WalletStorageServerOptions { port: number; wallet: Wallet; monetize: boolean; calculateRequestPrice?: (req: Request) => number | Promise<number>; adminIdentityKeys?: string[]; } ``` See also: [Wallet](./client.md#class-wallet) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Interface: XValidCreateActionOutput ```ts export interface XValidCreateActionOutput extends sdk.ValidCreateActionOutput { vout: number; providedBy: sdk.StorageProvidedBy; purpose?: string; derivationSuffix?: string; keyOffset?: string; } ``` See also: [StorageProvidedBy](./client.md#type-storageprovidedby), [ValidCreateActionOutput](./client.md#interface-validcreateactionoutput) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- #### Classes | | | | | --- | --- | --- | | [EntityBase](#class-entitybase) | [EntityProvenTxReq](#class-entityproventxreq) | [StorageIdb](#class-storageidb) | | [EntityCertificate](#class-entitycertificate) | [EntitySyncState](#class-entitysyncstate) | [StorageKnex](#class-storageknex) | | [EntityCertificateField](#class-entitycertificatefield) | [EntityTransaction](#class-entitytransaction) | [StorageProvider](#class-storageprovider) | | [EntityCommission](#class-entitycommission) | [EntityTxLabel](#class-entitytxlabel) | [StorageReader](#class-storagereader) | | [EntityOutput](#class-entityoutput) | [EntityTxLabelMap](#class-entitytxlabelmap) | [StorageReaderWriter](#class-storagereaderwriter) | | [EntityOutputBasket](#class-entityoutputbasket) | [EntityUser](#class-entityuser) | [StorageServer](#class-storageserver) | | [EntityOutputTag](#class-entityoutputtag) | [KnexMigrations](#class-knexmigrations) | [StorageSyncReader](#class-storagesyncreader) | | [EntityOutputTagMap](#class-entityoutputtagmap) | [MergeEntity](#class-mergeentity) | [WalletStorageManager](#class-walletstoragemanager) | | [EntityProvenTx](#class-entityproventx) | [StorageClient](#class-storageclient) | | Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Class: EntityBase ```ts export abstract class EntityBase<T> { api: T; constructor(api: T) abstract get id(): number; abstract get entityName(): string; abstract get entityTable(): string; abstract updateApi(): void; abstract equals(ei: T, syncMap?: SyncMap): boolean; abstract mergeNew(storage: EntityStorage, userId: number, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<void>; abstract mergeExisting(storage: EntityStorage, since: Date | undefined, ei: T, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<boolean>; toApi(): T } ``` See also: [EntityStorage](./storage.md#type-entitystorage), [SyncMap](./storage.md#interface-syncmap), [TrxToken](./client.md#interface-trxtoken) ###### Method equals Tests for equality or 'merge' / 'convergent' equality if syncMap is provided. 'convergent' equality must satisfy (A sync B) equals (B sync A) ```ts abstract equals(ei: T, syncMap?: SyncMap): boolean ``` See also: [SyncMap](./storage.md#interface-syncmap) ###### Method mergeExisting Perform a 'merge' / 'convergent' equality migration of state from external `ei` to this existing local EntityUser ```ts abstract mergeExisting(storage: EntityStorage, since: Date | undefined, ei: T, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<boolean> ``` See also: [EntityStorage](./storage.md#type-entitystorage), [SyncMap](./storage.md#interface-syncmap), [TrxToken](./client.md#interface-trxtoken) Returns true iff entity state changed and was updated to storage ###### Method mergeNew Perform a 'merge' / 'convergent' equality migration of state to this new local entity which was constructed as a copy of the external object. ```ts abstract mergeNew(storage: EntityStorage, userId: number, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<void> ``` See also: [EntityStorage](./storage.md#type-entitystorage), [SyncMap](./storage.md#interface-syncmap), [TrxToken](./client.md#interface-trxtoken) Argument Details + **userId** + local userId ###### Method toApi An entity may decode properties of the underlying Api object on construction. The `toApi` method forces an `updateApi` before returning the underlying, now updated, Api object. ```ts toApi(): T ``` Returns The underlying Api object with any entity decoded properties updated. ###### Method updateApi On construction, an entity may decode properties of the `api` object, such as JSON stringified objects. The `updateApi` method must re-encode the current state of those decoded properties into the `api` object. Used by the `toApi` method to return an updated `api` object. ```ts abstract updateApi(): void ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Class: EntityCertificate ```ts export class EntityCertificate extends EntityBase<TableCertificate> { constructor(api?: TableCertificate) override updateApi(): void get certificateId() set certificateId(v: number) get created_at() set created_at(v: Date) get updated_at() set updated_at(v: Date) get userId() set userId(v: number) get type() set type(v: string) get subject() set subject(v: string) get verifier() set verifier(v: string | undefined) get serialNumber() set serialNumber(v: string) get certifier() set certifier(v: string) get revocationOutpoint() set revocationOutpoint(v: string) get signature() set signature(v: string) get isDeleted() set isDeleted(v: boolean) override get id(): number override set id(v: number) override get entityName(): string override get entityTable(): string override equals(ei: TableCertificate, syncMap?: SyncMap): boolean static async mergeFind(storage: EntityStorage, userId: number, ei: TableCertificate, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<{ found: boolean; eo: EntityCertificate; eiId: number; }> override async mergeNew(storage: EntityStorage, userId: number, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<void> override async mergeExisting(storage: EntityStorage, since: Date | undefined, ei: TableCertificate, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<boolean> } ``` See also: [EntityBase](./storage.md#class-entitybase), [EntityStorage](./storage.md#type-entitystorage), [SyncMap](./storage.md#interface-syncmap), [TableCertificate](./storage.md#interface-tablecertificate), [TrxToken](./client.md#interface-trxtoken) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Class: EntityCertificateField ```ts export class EntityCertificateField extends EntityBase<TableCertificateField> { constructor(api?: TableCertificateField) override updateApi(): void get userId() set userId(v: number) get certificateId() set certificateId(v: number) get created_at() set created_at(v: Date) get updated_at() set updated_at(v: Date) get fieldName() set fieldName(v: string) get fieldValue() set fieldValue(v: string) get masterKey() set masterKey(v: string) override get id(): number override get entityName(): string override get entityTable(): string override equals(ei: TableCertificateField, syncMap?: SyncMap | undefined): boolean static async mergeFind(storage: EntityStorage, userId: number, ei: TableCertificateField, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<{ found: boolean; eo: EntityCertificateField; eiId: number; }> override async mergeNew(storage: EntityStorage, userId: number, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<void> override async mergeExisting(storage: EntityStorage, since: Date | undefined, ei: TableCertificateField, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<boolean> } ``` See also: [EntityBase](./storage.md#class-entitybase), [EntityStorage](./storage.md#type-entitystorage), [SyncMap](./storage.md#interface-syncmap), [TableCertificateField](./storage.md#interface-tablecertificatefield), [TrxToken](./client.md#interface-trxtoken) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ##### Class: EntityCommission ```ts export class EntityCommission extends EntityBase<TableCommission> { constructor(api?: TableCommission) override updateApi(): void get commissionId() set commissionId(v: number) get created_at() set created_at(v: Date) get updated_at() set updated_at(v: Date) get transactionId() set transactionId(v: number) get userId() set userId(v: number) get isRedeemed() set isRedeemed(v: boolean) get keyOffset() set keyOffset(v: string) get lockingScript() set lockingScript(v: number[]) get satoshis() set satoshis(v: number) override get id(): number override set id(v: number) override get entityName(): string override get entityTable(): string override equals(ei: TableCommission, syncMap?: SyncMap | undefined): boolean static async mergeFind(storage: EntityStorage, userId: number, ei: TableCommission, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<{ found: boolean; eo: EntityCommission; eiId: number; }> override async mergeNew(storage: EntityStorage, userId: number, syncMap: SyncMap, trx?: sdk.TrxToken): Promise<void> ove