UNPKG

wallet-storage

Version:

BRC100 conforming wallet, wallet storage and wallet signer components

497 lines (359 loc) 18.5 kB
# API Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) ## Interfaces | | | --- | | [ArcMinerGetTxData](#interface-arcminergettxdata) | | [ArcMinerPostBeefDataApi](#interface-arcminerpostbeefdataapi) | | [ArcMinerPostTxsData](#interface-arcminerposttxsdata) | | [ArcServiceConfig](#interface-arcserviceconfig) | | [ExchangeRatesIoApi](#interface-exchangeratesioapi) | Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Interface: ArcMinerGetTxData ```ts export interface ArcMinerGetTxData { status: number; title: string; blockHash: string; blockHeight: number; competingTxs: null | string[]; extraInfo: string; merklePath: string; timestamp: string; txid: string; txStatus: string; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Interface: ArcMinerPostBeefDataApi ```ts export interface ArcMinerPostBeefDataApi { status: number; title: string; blockHash?: string; blockHeight?: number; competingTxs?: null; extraInfo: string; merklePath?: string; timestamp?: string; txid?: string; txStatus?: string; type?: string; detail?: string; instance?: string; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Interface: ArcMinerPostTxsData ```ts export interface ArcMinerPostTxsData { status: number; title: string; blockHash: string; blockHeight: number; competingTxs: null | string[]; extraInfo: string; merklePath: string; timestamp: string; txid: string; txStatus: string; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Interface: ArcServiceConfig ```ts export interface ArcServiceConfig { name: string; url: string; arcConfig: ArcConfig; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Interface: ExchangeRatesIoApi ```ts export interface ExchangeRatesIoApi { success: boolean; timestamp: number; base: "EUR" | "USD"; date: string; rates: Record<string, number>; } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ## Classes | | | --- | | [ServiceCollection](#class-servicecollection) | | [Services](#class-services) | Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Class: ServiceCollection ```ts export class ServiceCollection<T> { services: { name: string; service: T; }[]; _index: number; constructor(services?: { name: string; service: T; }[]) add(s: { name: string; service: T; }): ServiceCollection<T> remove(name: string): void get name() get service() get allServices() get count() get index() reset() next(): number clone(): ServiceCollection<T> } ``` Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Class: Services ```ts export class Services implements sdk.WalletServices { static createDefaultOptions(chain: sdk.Chain): sdk.WalletServicesOptions options: sdk.WalletServicesOptions; getMerklePathServices: ServiceCollection<sdk.GetMerklePathService>; getRawTxServices: ServiceCollection<sdk.GetRawTxService>; postTxsServices: ServiceCollection<sdk.PostTxsService>; postBeefServices: ServiceCollection<sdk.PostBeefService>; getUtxoStatusServices: ServiceCollection<sdk.GetUtxoStatusService>; updateFiatExchangeRateServices: ServiceCollection<sdk.UpdateFiatExchangeRateService>; chain: sdk.Chain; constructor(optionsOrChain: sdk.Chain | sdk.WalletServicesOptions) async getChainTracker(): Promise<ChainTracker> async getBsvExchangeRate(): Promise<number> async getFiatExchangeRate(currency: "USD" | "GBP" | "EUR", base?: "USD" | "GBP" | "EUR"): Promise<number> get getProofsCount() get getRawTxsCount() get postTxsServicesCount() get postBeefServicesCount() get getUtxoStatsCount() async getUtxoStatus(output: string, outputFormat?: sdk.GetUtxoStatusOutputFormat, useNext?: boolean): Promise<sdk.GetUtxoStatusResult> async postTxs(beef: Beef, txids: string[]): Promise<sdk.PostTxsResult[]> async postBeef(beef: Beef, txids: string[]): Promise<sdk.PostBeefResult[]> async getRawTx(txid: string, useNext?: boolean): Promise<sdk.GetRawTxResult> async invokeChaintracksWithRetry<R>(method: () => Promise<R>): Promise<R> async getHeaderForHeight(height: number): Promise<number[]> async getHeight(): Promise<number> async hashToHeader(hash: string): Promise<sdk.BlockHeader> async getMerklePath(txid: string, useNext?: boolean): Promise<sdk.GetMerklePathResult> targetCurrencies = ["USD", "GBP", "EUR"]; async updateFiatExchangeRates(rates?: sdk.FiatExchangeRates, updateMsecs?: number): Promise<sdk.FiatExchangeRates> async nLockTimeIsFinal(tx: string | number[] | BsvTransaction | number): Promise<boolean> } ``` See also: [BlockHeader](#interface-blockheader), [Chain](#type-chain), [FiatExchangeRates](#interface-fiatexchangerates), [GetMerklePathResult](#interface-getmerklepathresult), [GetMerklePathService](#type-getmerklepathservice), [GetRawTxResult](#interface-getrawtxresult), [GetRawTxService](#type-getrawtxservice), [GetUtxoStatusOutputFormat](#type-getutxostatusoutputformat), [GetUtxoStatusResult](#interface-getutxostatusresult), [GetUtxoStatusService](#type-getutxostatusservice), [PostBeefResult](#interface-postbeefresult), [PostBeefService](#type-postbeefservice), [PostTxsResult](#interface-posttxsresult), [PostTxsService](#type-posttxsservice), [ServiceCollection](#class-servicecollection), [UpdateFiatExchangeRateService](#type-updatefiatexchangerateservice), [WalletServices](#interface-walletservices), [WalletServicesOptions](#interface-walletservicesoptions) <details> <summary>Class Services Details</summary> #### Method postTxs The beef must contain at least each rawTx for each txid. Some services may require input transactions as well. These will be fetched if missing, greatly extending the service response time. ```ts async postTxs(beef: Beef, txids: string[]): Promise<sdk.PostTxsResult[]> ``` See also: [PostTxsResult](#interface-posttxsresult) </details> Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ## Functions | | | | --- | --- | | [createDefaultWalletServicesOptions](#function-createdefaultwalletservicesoptions) | [makePostBeefToTaalARC](#function-makepostbeeftotaalarc) | | [getExchangeRatesIo](#function-getexchangeratesio) | [makePostTxsToTaalARC](#function-makeposttxstotaalarc) | | [getMerklePathFromTaalARC](#function-getmerklepathfromtaalarc) | [postBeefToArcMiner](#function-postbeeftoarcminer) | | [getMerklePathFromWhatsOnChainTsc](#function-getmerklepathfromwhatsonchaintsc) | [postBeefToTaalArcMiner](#function-postbeeftotaalarcminer) | | [getRawTxFromWhatsOnChain](#function-getrawtxfromwhatsonchain) | [postTxsToTaalArcMiner](#function-posttxstotaalarcminer) | | [getTaalArcServiceConfig](#function-gettaalarcserviceconfig) | [toBinaryBaseBlockHeader](#function-tobinarybaseblockheader) | | [getUtxoStatusFromWhatsOnChain](#function-getutxostatusfromwhatsonchain) | [updateBsvExchangeRate](#function-updatebsvexchangerate) | | [makeErrorResult](#function-makeerrorresult) | [updateChaintracksFiatExchangeRates](#function-updatechaintracksfiatexchangerates) | | [makeGetMerklePathFromTaalARC](#function-makegetmerklepathfromtaalarc) | [updateExchangeratesapi](#function-updateexchangeratesapi) | | [makePostBeefResult](#function-makepostbeefresult) | [validateScriptHash](#function-validatescripthash) | Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: createDefaultWalletServicesOptions ```ts export function createDefaultWalletServicesOptions(chain: sdk.Chain): sdk.WalletServicesOptions ``` See also: [Chain](#type-chain), [WalletServicesOptions](#interface-walletservicesoptions) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: getExchangeRatesIo ```ts export async function getExchangeRatesIo(key: string): Promise<ExchangeRatesIoApi> ``` See also: [ExchangeRatesIoApi](#interface-exchangeratesioapi) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: getMerklePathFromTaalARC ```ts export async function getMerklePathFromTaalARC(txid: string, config: ArcServiceConfig, services: sdk.WalletServices): Promise<sdk.GetMerklePathResult> ``` See also: [ArcServiceConfig](#interface-arcserviceconfig), [GetMerklePathResult](#interface-getmerklepathresult), [WalletServices](#interface-walletservices) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: getMerklePathFromWhatsOnChainTsc WhatOnChain.com has their own "hash/pos/R/L" proof format and a more TSC compliant proof format. The "/proof/tsc" endpoint is much closer to the TSC specification. It provides "index" directly and each node is just the provided hash value. The "targetType" is unspecified and thus defaults to block header hash, requiring a Chaintracks lookup to get the merkleRoot... Duplicate hash values are provided in full instead of being replaced by "*". ```ts export async function getMerklePathFromWhatsOnChainTsc(txid: string, chain: sdk.Chain, services: sdk.WalletServices): Promise<sdk.GetMerklePathResult> ``` See also: [Chain](#type-chain), [GetMerklePathResult](#interface-getmerklepathresult), [WalletServices](#interface-walletservices) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: getRawTxFromWhatsOnChain ```ts export async function getRawTxFromWhatsOnChain(txid: string, chain: sdk.Chain): Promise<sdk.GetRawTxResult> ``` See also: [Chain](#type-chain), [GetRawTxResult](#interface-getrawtxresult) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: getTaalArcServiceConfig ```ts export function getTaalArcServiceConfig(chain: sdk.Chain, apiKey: string): ArcServiceConfig ``` See also: [ArcServiceConfig](#interface-arcserviceconfig), [Chain](#type-chain) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: getUtxoStatusFromWhatsOnChain ```ts export async function getUtxoStatusFromWhatsOnChain(output: string, chain: sdk.Chain, outputFormat?: sdk.GetUtxoStatusOutputFormat): Promise<sdk.GetUtxoStatusResult> ``` See also: [Chain](#type-chain), [GetUtxoStatusOutputFormat](#type-getutxostatusoutputformat), [GetUtxoStatusResult](#interface-getutxostatusresult) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: makeErrorResult ```ts export function makeErrorResult(error: sdk.WalletError, miner: ArcServiceConfig, beef: number[], txids: string[], dd?: ArcMinerPostBeefDataApi): sdk.PostBeefResult ``` See also: [ArcMinerPostBeefDataApi](#interface-arcminerpostbeefdataapi), [ArcServiceConfig](#interface-arcserviceconfig), [PostBeefResult](#interface-postbeefresult), [WalletError](#class-walleterror) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: makeGetMerklePathFromTaalARC ```ts export function makeGetMerklePathFromTaalARC(config: ArcServiceConfig): sdk.GetMerklePathService ``` See also: [ArcServiceConfig](#interface-arcserviceconfig), [GetMerklePathService](#type-getmerklepathservice) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: makePostBeefResult ```ts export function makePostBeefResult(dd: ArcMinerPostBeefDataApi, miner: ArcServiceConfig, beef: number[], txids: string[]): sdk.PostBeefResult ``` See also: [ArcMinerPostBeefDataApi](#interface-arcminerpostbeefdataapi), [ArcServiceConfig](#interface-arcserviceconfig), [PostBeefResult](#interface-postbeefresult) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: makePostBeefToTaalARC ```ts export function makePostBeefToTaalARC(config: ArcServiceConfig): sdk.PostBeefService ``` See also: [ArcServiceConfig](#interface-arcserviceconfig), [PostBeefService](#type-postbeefservice) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: makePostTxsToTaalARC ```ts export function makePostTxsToTaalARC(config: ArcServiceConfig): sdk.PostTxsService ``` See also: [ArcServiceConfig](#interface-arcserviceconfig), [PostTxsService](#type-posttxsservice) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: postBeefToArcMiner ```ts export async function postBeefToArcMiner(beef: Beef | number[], txids: string[], config: ArcServiceConfig): Promise<sdk.PostBeefResult> ``` See also: [ArcServiceConfig](#interface-arcserviceconfig), [PostBeefResult](#interface-postbeefresult) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: postBeefToTaalArcMiner ```ts export async function postBeefToTaalArcMiner(beef: Beef, txids: string[], config: ArcServiceConfig, services: sdk.WalletServices): Promise<sdk.PostBeefResult> ``` See also: [ArcServiceConfig](#interface-arcserviceconfig), [PostBeefResult](#interface-postbeefresult), [WalletServices](#interface-walletservices) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: postTxsToTaalArcMiner ```ts export async function postTxsToTaalArcMiner(beef: Beef, txids: string[], config: ArcServiceConfig, services: sdk.WalletServices): Promise<sdk.PostTxsResult> ``` See also: [ArcServiceConfig](#interface-arcserviceconfig), [PostTxsResult](#interface-posttxsresult), [WalletServices](#interface-walletservices) <details> <summary>Function postTxsToTaalArcMiner Details</summary> Argument Details + **txs** + All transactions must have source transactions. Will just source locking scripts and satoshis do?? toHexEF() is used. </details> Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: toBinaryBaseBlockHeader Serializes a block header as an 80 byte array. The exact serialized format is defined in the Bitcoin White Paper such that computing a double sha256 hash of the array computes the block hash for the header. ```ts export function toBinaryBaseBlockHeader(header: sdk.BaseBlockHeader): number[] { const writer = new Utils.Writer(); writer.writeUInt32BE(header.version); writer.writeReverse(asArray(header.previousHash)); writer.writeReverse(asArray(header.merkleRoot)); writer.writeUInt32BE(header.time); writer.writeUInt32BE(header.bits); writer.writeUInt32BE(header.nonce); const r = writer.toArray(); return r; } ``` See also: [BaseBlockHeader](#interface-baseblockheader), [asArray](#function-asarray) <details> <summary>Function toBinaryBaseBlockHeader Details</summary> Returns 80 byte array </details> Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: updateBsvExchangeRate ```ts export async function updateBsvExchangeRate(rate?: sdk.BsvExchangeRate, updateMsecs?: number): Promise<sdk.BsvExchangeRate> ``` See also: [BsvExchangeRate](#interface-bsvexchangerate) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: updateChaintracksFiatExchangeRates ```ts export async function updateChaintracksFiatExchangeRates(targetCurrencies: string[], options: sdk.WalletServicesOptions): Promise<sdk.FiatExchangeRates> ``` See also: [FiatExchangeRates](#interface-fiatexchangerates), [WalletServicesOptions](#interface-walletservicesoptions) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: updateExchangeratesapi ```ts export async function updateExchangeratesapi(targetCurrencies: string[], options: sdk.WalletServicesOptions): Promise<sdk.FiatExchangeRates> ``` See also: [FiatExchangeRates](#interface-fiatexchangerates), [WalletServicesOptions](#interface-walletservicesoptions) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ### Function: validateScriptHash ```ts export function validateScriptHash(output: string, outputFormat?: sdk.GetUtxoStatusOutputFormat): string ``` See also: [GetUtxoStatusOutputFormat](#type-getutxostatusoutputformat) Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables) --- ## Types ## Variables