UNPKG

@bsv/spv-wallet-js-client

Version:

TypeScript library for connecting to a SPV Wallet server

1,202 lines (1,188 loc) 37.4 kB
import { HD, PrivateKey, TransactionInput } from '@bsv/sdk'; import EventEmitter from 'events'; interface Client { server_url: string; } interface ExclusiveStartKeyPage<T> { content: T; page: ExclusiveStartKeyPageInfo; } interface ExclusiveStartKeyPageInfo { orderByField?: string; sortDirection?: string; totalElements: number; size: number; lastEvaluatedKey: string; } /** * MerkleRoot interface * * Holds the content of the sync merkleroot response */ interface MerkleRoot { merkleRoot: string; blockHeight: number; } /** * Repository interface * * Holds methods needed to get lastEvaluatedKey from the client's database and to save them */ interface MerkleRootsRepository { getLastMerkleRoot(): Promise<string | undefined>; saveMerkleRoots(syncedMerkleRoots: MerkleRoot[]): Promise<void>; } /** * Xpub interface * * @example * { "_id": "7406ab7d9e781685d6d0ceb319b84b332ff1b773ff0bbce1671d843d50c9532a", "created_at": new Date(1645796112916), "metadata": [ { "k": "user_agent", "v": "SPVWalletUserAPI v1.0.0" }, ], "current_balance": 99848517, "next_internal_num": 100, "next_external_num": 229 } */ interface XPub { /** * metadata object */ metadata?: Metadata; /** * xpub id */ id: string; /** * Current balance in sats of the xpub */ currentBalance: number; /** * Next internal (change address) number to use for a new destination * * NOTE: Do not use this to create new destinations, always let SPV Wallet create the destination */ nextInternalNum: number; /** * Next external number to use for a new destination * * NOTE: Do not use this to create new destinations, always let SPV Wallet create the destination */ nextExternalNum: number; /** * Date when this object was created */ createdAt?: Date; /** * Date when this object was last updated */ updatedAt?: Date; /** * If this object has been deleted, this date will be set */ deletedAt?: Date; } /** * Page interface * * Holds information about the pagination state */ interface Page { number: number; size: number; totalPages: number; totalElements: number; sortDirection: string; orderByField: string; } /** * Paged response interface * * Holds the content and page information */ interface PageModel<T> { content: Array<T>; page: Page; } /** * Database key value conditions to filter on the metadata object * * @example * const metadata = { * spvWalletVersion: "v0.1.3", * someKey: "some value" * } */ interface Metadata { /** * Key value element */ [key: string]: any; } /** * Xpub interface * * @example * { "_id": "7406ab7d9e781685d6d0ceb319b84b332ff1b773ff0bbce1671d843d50c9532a", "createdAt": new Date(1645796112916), "metadata": [ { "k": "user_agent", "v": "SPVWalletUserAPI v1.0.0" }, ], "currentBalance": 99848517, "nextInternalNum": 100, "nextExternalNum": 229 } */ interface User { metadata?: Metadata; id: string; currentBalance: number; nextInternalNum: number; nextExternalNum: number; createdAt?: Date; updatedAt?: Date; deletedAt?: Date; } /** * Admin stats interface */ interface AdminStats { /** * Total balance of all outputs in sats in the database */ balance: number; /** * Number of destinations in the database */ destinations: number; /** * Number of transactions in the database */ transactions: number; /** * Number of paymail addresses in the database */ paymailAddresses: number; /** * Number of utxos in the database */ utxos: number; /** * Number of xpubs registered in the database */ xpubs: number; /** * A key value object of dates and number of transactions on that date (YYYYMMDD) */ transactionsPerDay: { [key: string]: any; }; /** * Number of utxos per output type */ utxosPerType: { [key: string]: any; }; } /** * Access key interface for non-admin (User) endpoints. */ interface AccessKey { id: string; xpubId: string; key?: string; metadata?: Metadata; createdAt: Date; updatedAt?: Date; deletedAt?: Date; revokedAt?: Date; } /** * NewContact interface for adding a new contact by admin. * creatorPaymail is the paymail of the user who will be owner of the contact and it's required for admin createContact action. */ interface NewContact { creatorPaymail: string; fullName: string; metadata?: Metadata; } /** * Contact interface for non-admin (User) endpoints. */ interface Contact { id: string; fullName: string; paymail: string; pubKey: string; status: string; createdAt: Date; updatedAt?: Date; deletedAt?: Date; metadata?: Metadata; } /** * Destination interface for non-admin (User) endpoints. */ interface Destination { id: string; xpubId: string; lockingScript: string; type: string; chain: number; num: number; paymailExternalDerivationNum?: number; address: string; draftId: string; metadata: Metadata; createdAt: Date; updatedAt?: Date; deletedAt?: Date; } /** * Transaction interface for non-admin (User) endpoints. */ interface Tx { id: string; hex: string; blockHash: string; blockHeight: number; fee: number; numberOfInputs: number; numberOfOutputs: number; outputValue: number; totalValue: number; metadata?: Metadata; direction: string; createdAt: Date; updatedAt?: Date; deletedAt?: Date; } /** * Transaction interface for Admin endpoints. */ interface AdminTx extends Tx { draftId: string; xpubsInIds: string[]; xpubOutIds: string[]; outputs: Record<string, number>; status: string; outputValue: number; } /** * Utxo interface. */ interface Utxo { id: string; xpubId: string; satoshis: number; scriptPubKey: string; type: string; draftId?: string; reservedAt?: Date; spendingTxId?: string; transaction?: Tx; createdAt: Date; updatedAt?: Date; deletedAt?: Date; metadata?: Metadata; } /** * Paymail address interface for Admin endpoints */ interface PaymailAddress { id: string; xpubId: string; alias: string; domain: string; address: string; publicName: string; avatar: string; metadata: Metadata; createdAt: Date; updatedAt?: Date; deletedAt?: Date; } /** * OP_RETURN data for transactions. */ interface OpReturn { hex?: string; hexParts?: string[]; map?: MapProtocol; stringParts?: string[]; } /** * MAP protocol definition. */ interface MapProtocol { app?: string; type?: string; keys?: { [key: string]: any; }; } /** * Fee unit to use when calculating the fee for the transaction (satoshis per byte). */ interface FeeUnit { satoshis: number; bytes: number; } /** * Configuration for syncing transaction on-chain. */ interface SyncConfig { broadcast: boolean; broadcastInstant: boolean; syncOnChain: boolean; paymailP2p: boolean; } /** * A record pointing to a UTXO by transaction ID and output index. */ interface UtxoPointer { transactionId: string; outputIndex: number; } /** * Transaction used as an input in a draft transaction. */ interface TxInput { createdAt?: Date; updatedAt?: Date; metadata?: Metadata; deletedAt?: Date; id?: string; transactionId: string; xpubId?: string; outputIndex: number; satoshis: number; scriptPubKey: string; type: string; draftId?: string; reservedAt?: Date; spendingTxId?: string; destination?: Destination; } /** * Transaction output record in a draft transaction. */ interface TxOutput { paymailP4?: PaymailP4; satoshis?: number; script?: string; scripts?: ScriptOutput[]; to?: string; opReturn?: OpReturn; } /** * Script output of a transaction. */ interface ScriptOutput { address?: string; satoshis?: number; script: string; scriptType?: string; } /** * Paymail p2p record for communicating with other p2p providers. */ interface PaymailP4 { alias: string; domain: string; fromPaymail?: string; note?: string; pubKey?: string; receiveEndpoint?: string; referenceId?: string; resolutionType: string; } /** * Configuration for a new transaction. */ interface TxConfig { changeDestinations?: Destination[]; changeDestinationsStrategy?: ChangeStrategy; changeMinimumSatoshis?: number; changeNumberOfDestinations?: number; changeSatoshis?: number; expiresIn?: number; fee?: number; feeUnit?: FeeUnit; fromUtxos?: UtxoPointer[]; includeUtxos?: UtxoPointer[]; inputs?: TxInput[]; miner?: string; outputs: TxOutput[]; sendAllTo?: string; sync?: SyncConfig; } /** * Configuration for a draft transaction. */ interface DraftTransactionConfig { changeDestinations?: Destination[]; changeDestinationsStrategy?: ChangeStrategy; changeMinimumSatoshis?: number; changeNumberOfDestinations?: number; changeSatoshis?: number; expiresIn?: number; fee?: number; feeUnit?: FeeUnit; fromUtxos?: UtxoPointer[]; miner?: string; outputs: TxOutput[]; sendAllTo?: string; sync?: SyncConfig; } /** * Status of a draft transaction. */ type DraftStatus = 'draft' | 'canceled' | 'expired' | 'complete'; /** * Draft transaction interface. */ interface DraftTx { id: string; hex: string; metadata?: Metadata; xpubId: string; expiresAt: Date; configuration: TxConfig; status: DraftStatus; finalTxId?: string; createdAt: Date; updatedAt?: Date; deletedAt?: Date; } /** * Strategy to use for the change of a transaction. */ type ChangeStrategy = 'default' | 'random' | 'nominations'; /** * Key basic information. */ interface Key { xPriv(): string; xPub: PubKey; } /** * Extends Key interface with mnemonic information. */ interface KeyWithMnemonic extends Key { mnemonic: string; } /** * Public key information. */ interface PubKey { toString(): string; } interface AdminKey { adminKey: string; } /** * Webhook interface for admin endpoints. */ interface Webhook { url: string; banned: boolean; } type AdminClientOptions = AdminKey; interface XpubWithoutSigning { xPriv?: never; xPub: string; accessKey?: never; } interface XprivWithSigning { xPriv?: string; xPub?: never; accessKey?: never; } interface AccessKeyWithSigning { xPriv?: never; xPub?: never; accessKey: string; } type ClientOptions = XpubWithoutSigning | XprivWithSigning | AccessKeyWithSigning; /** * Query page params to limit and order database list results. */ interface QueryPageParams { page?: number; size?: number; sort?: string; sortBy?: string; } /** * SharedConfig defines the configuration shared by different parts of the application. */ interface SharedConfig { paymailDomains: string[]; experimentalFeatures: { [key: string]: boolean; }; } type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE'; interface StringEvent { value: string; } interface UserEvent { xpubId: string; } interface TransactionEvent extends UserEvent { transactionId: string; status: string; xpubOutputValue: Record<string, number>; } type Events = { StringEvent: StringEvent; UserEvent: UserEvent; TransactionEvent: TransactionEvent; }; declare const deriveChildKeyFromHex: (hdKey: HD, hexHash: string) => HD; declare const deriveHDChildKeyFromHex: (hdKey: HD, hexHash: string) => HD; declare const generateKeys: () => KeyWithMnemonic; declare const getKeysFromMnemonic: (mnemonicStr: string) => KeyWithMnemonic; declare const getKeysFromString: (privateKey: string) => Key; interface AuthPayload { AuthHash?: string; AuthNonce?: string; AuthTime?: number; BodyContents?: string; Signature?: string; xPub?: string; accessKey?: string; } declare const AuthHeader = "x-auth-xpub"; declare const AuthAccessKey = "x-auth-key"; declare const AuthSignature = "x-auth-signature"; declare const AuthHeaderHash = "x-auth-hash"; declare const AuthHeaderNonce = "x-auth-nonce"; declare const AuthHeaderTime = "x-auth-time"; declare const setSignature: (headers: { [key: string]: string; }, signingKey: HD | PrivateKey, bodyString: string) => { [key: string]: string; }; declare const createSignature: (signingKey: HD | PrivateKey, bodyString: string) => AuthPayload; declare const getSigningMessage: (xPub: string, auth: AuthPayload) => string; interface Logger { debug(msg: string, ...args: any[]): void; info(msg: string, ...args: any[]): void; warn(msg: string, ...args: any[]): void; error(msg: string, ...args: any[]): void; } interface ConsoleLoggerLevel { level: 'debug' | 'info' | 'warn' | 'error' | 'disabled'; } type LoggerConfig = Logger | ConsoleLoggerLevel; declare class SpvWalletError extends Error { constructor(message: string); } declare class ErrorInvalidClientOptions extends SpvWalletError { constructor(logger: Logger, options: ClientOptions); } declare class ErrorInvalidAdminClientOptions extends SpvWalletError { constructor(logger: Logger, options: AdminClientOptions); } declare class ErrorNoXPrivToSignTransaction extends SpvWalletError { constructor(); } declare class ErrorClientInitNoXpriv extends SpvWalletError { constructor(); } declare class ErrorTxIdsDontMatchToDraft extends SpvWalletError { input: TxInput; draftInput: TransactionInput; constructor(logger: Logger, input: TxInput, index: number, draftInput: TransactionInput); } declare class ErrorNoAdminKey extends SpvWalletError { constructor(); } declare class ErrorResponse extends SpvWalletError { response: Response; content: string; constructor(logger: Logger, response: Response, content: string); } declare class ErrorWrongHex extends SpvWalletError { value: string; constructor(wrongHex: string); } declare class ErrorNoXPrivToGenerateTOTP extends SpvWalletError { constructor(); } declare class ErrorNoXPrivToValidateTOTP extends SpvWalletError { constructor(); } declare class ErrorWrongTOTP extends SpvWalletError { constructor(); } declare class ErrorSyncMerkleRootsTimeout extends SpvWalletError { constructor(); } declare class ErrorStaleLastEvaluatedKey extends SpvWalletError { constructor(); } interface RawEvent { type: string; content: any; } interface WebhookOptions { tokenHeader?: string; tokenValue?: string; } interface WebhookHttpHandler { getHeader(name: string): string; handleResponse(status: number, body?: any): void; getBody(): RawEvent[]; } type EventHandler<T> = (event: T) => Promise<void>; declare class EventsMap { private logger; private registered; constructor(logger: Logger); store<T extends keyof Events>(eventName: string, handler: EventHandler<Events[T]>): void; load(eventName: string): EventEmitter | undefined; } interface TimeRange { from?: string; to?: string; } interface ModelFilter { includeDeleted?: boolean; createdRange?: TimeRange; updatedRange?: TimeRange; } interface AccessKeyFilter extends ModelFilter { revokedRange?: TimeRange; } interface AdminAccessKeyFilter extends AccessKeyFilter { xpubId?: string; } type ContactStatus = 'unconfirmed' | 'awaiting' | 'confirmed' | 'rejected'; interface ContactFilter extends ModelFilter { id?: string; fullName?: string; paymail?: string; pubKey?: string; status?: ContactStatus; } interface AdminPaymailFilter extends ModelFilter { id?: string; xpubId?: string; alias?: string; domain?: string; publicName?: string; } interface PaymailFilter extends ModelFilter { id?: string; alias?: string; domain?: string; publicName?: string; } type TransactionStatus = 'UNKNOWN' | 'QUEUED' | 'RECEIVED' | 'STORED' | 'ANNOUNCED_TO_NETWORK' | 'REQUESTED_BY_NETWORK' | 'SENT_TO_NETWORK' | 'ACCEPTED_BY_NETWORK' | 'SEEN_ON_NETWORK' | 'MINED' | 'SEEN_IN_ORPHAN_MEMPOOL' | 'CONFIRMED' | 'REJECTED'; interface TransactionFilter extends ModelFilter { id?: string; hex?: string; blockHash?: string; blockHeight?: number; fee?: number; numberOfInputs?: number; numberOfOutputs?: number; draftId?: string; totalValue?: number; status?: TransactionStatus | string; } type UtxoType = 'pubkey' | 'pubkeyhash' | 'nulldata' | 'multisig' | 'nonstandard' | 'scripthash' | 'metanet' | 'token_stas' | 'token_sensible'; interface UtxoFilter extends ModelFilter { transactionId?: string; outputIndex?: number; id?: string; satoshis?: number; scriptPubKey?: string; type?: UtxoType; draftId?: string; reservedRange?: TimeRange; spendingTxId?: string; } interface AdminUtxoFilter extends UtxoFilter { xpubId?: string; } interface XpubFilter extends ModelFilter { id?: string; currentBalance?: number; } interface AdminContactFilter extends ContactFilter { xpubId?: string; } declare class HttpClient { private logger; private adminKey?; private signingKey?; private xPubString?; private baseUrl; constructor(logger: Logger, url: string, key?: string | HD | PrivateKey, adminKey?: string); adminRequest(path: string, method?: HttpMethod, payload?: any): Promise<any>; request(path: string, method?: HttpMethod, payload?: any): Promise<any>; hasAdminKey(): boolean; private makeRequest; private prepareUrl; } /** * SPVWalletAdminAPI class for handling administrative operations * * @class SPVWalletAdminAPI */ declare class SPVWalletAdminAPI { logger: Logger; http: HttpClient; /** * Creates a new instance of SPVWalletAdminAPI * * @param {string} serverUrl - The base URL of the SPV Wallet server * @param {AdminClientOptions} options - Configuration options including adminKey * @param {LoggerConfig} loggerConfig - Logger configuration (optional) */ constructor(serverUrl: string, options: AdminClientOptions, loggerConfig?: LoggerConfig); private ensureSuffix; private makeRequester; /** * Check if the admin key is valid * * @returns {Promise<boolean>} True if admin key is valid */ status(): Promise<boolean>; /** * Get server statistics * * @returns {Promise<AdminStats>} Server statistics */ stats(): Promise<AdminStats>; /** * Get a list of all access keys in the system * * @param {AdminAccessKeyFilter} conditions - Filter conditions for access keys * @param {Metadata} metadata - Metadata filter * @param {QueryPageParams} params - Pagination parameters * @returns {Promise<PageModel<AccessKey>>} List of access keys */ accessKeys(conditions: AdminAccessKeyFilter, metadata: Metadata, params: QueryPageParams): Promise<PageModel<AccessKey>>; /** * Get a list of all contacts in the system * * @param {AdminContactFilter} conditions - Filter conditions for contacts * @param {Metadata} metadata - Metadata filter * @param {QueryPageParams} params - Pagination parameters * @returns {Promise<PageModel<Contact>>} List of contacts */ contacts(conditions: AdminContactFilter, metadata: Metadata, params: QueryPageParams): Promise<PageModel<Contact>>; /** * Update contact information * * @param {string} id - Contact ID * @param {string} fullName - New full name for the contact * @param {Metadata} metadata - Updated metadata * @returns {Promise<Contact>} Updated contact information */ contactUpdate(id: string, fullName: string, metadata: Metadata): Promise<Contact>; /** * Delete a contact * * @param {string} id - ID of the contact to delete * @returns {Promise<void>} */ deleteContact(id: string): Promise<void>; /** * Accept a contact invitation * * @param {string} id - ID of the invitation to accept * @returns {Promise<Contact>} The accepted contact */ acceptInvitation(id: string): Promise<Contact>; /** * Reject a contact invitation * * @param {string} id - ID of the invitation to reject * @returns {Promise<void>} */ rejectInvitation(id: string): Promise<void>; /** * Get a transaction by ID * * @param {string} id - Transaction ID * @returns {Promise<AdminTx>} Transaction details */ transaction(id: string): Promise<AdminTx>; /** * Get a list of all transactions * * @param {TransactionFilter} conditions - Filter conditions for transactions * @param {Metadata} metadata - Metadata filter * @param {QueryPageParams} params - Pagination parameters * @returns {Promise<PageModel<AdminTx>>} List of transactions */ transactions(conditions: TransactionFilter, metadata: Metadata, params: QueryPageParams): Promise<PageModel<AdminTx>>; /** * Get a list of all UTXOs * * @param {AdminUtxoFilter} conditions - Filter conditions for UTXOs * @param {Metadata} metadata - Metadata filter * @param {QueryPageParams} params - Pagination parameters * @returns {Promise<PageModel<Utxo>>} List of UTXOs */ utxos(conditions: AdminUtxoFilter, metadata: Metadata, params: QueryPageParams): Promise<PageModel<Utxo>>; /** * Get a list of all xPubs * * @param {XpubFilter} conditions - Filter conditions for xPubs * @param {Metadata} metadata - Metadata filter * @param {QueryPageParams} params - Pagination parameters * @returns {Promise<PageModel<XPub>>} List of xPubs */ xPubs(conditions: XpubFilter, metadata: Metadata, params: QueryPageParams): Promise<PageModel<XPub>>; /** * Register a new xPub * * @param {string} rawXPub - Raw xPub key to register * @param {Metadata} metadata - Metadata for the xPub * @returns {Promise<XPub>} Registered xPub information */ createXPub(rawXPub: string, metadata: Metadata): Promise<XPub>; /** * Get a paymail by address * * @param {string} id - Paymail ID or address * @returns {Promise<PaymailAddress>} Paymail information */ paymail(id: string): Promise<PaymailAddress>; /** * Get a list of all paymails * * @param {AdminPaymailFilter} conditions - Filter conditions for paymails * @param {Metadata} metadata - Metadata filter * @param {QueryPageParams} params - Pagination parameters * @returns {Promise<PageModel<PaymailAddress>>} List of paymail addresses */ paymails(conditions: AdminPaymailFilter, metadata: Metadata, params: QueryPageParams): Promise<PageModel<PaymailAddress>>; /** * Create a new paymail * * @param {string} rawXPub - Raw xpub to register the paymail to * @param {string} address - Paymail address (e.g., alias@domain.com) * @param {string} publicName - Public name for the paymail * @param {string} avatar - Avatar URL * @param {Metadata} metadata - Additional metadata * @returns {Promise<PaymailAddress>} Created paymail address */ createPaymail(rawXPub: string, address: string, publicName: string, avatar: string, metadata: Metadata): Promise<PaymailAddress>; /** * Delete a paymail * @param {string} id - Paymail Id of user to be deleted */ deletePaymail(id: string): Promise<void>; /** * Get webhook subscriptions * * @returns {Promise<Webhook[]>} List of webhook subscriptions */ webhooks(): Promise<Webhook[]>; /** * Subscribe to webhook * * @param {string} url - Webhook URL * @param {string} tokenHeader - Header name for the authentication token * @param {string} tokenValue - Value of the authentication token * @returns {Promise<void>} */ subscribeWebhook(url: string, tokenHeader: string, tokenValue: string): Promise<void>; /** * Unsubscribe from webhook * * @param {string} url - URL of the webhook to unsubscribe * @returns {Promise<void>} */ unsubscribeWebhook(url: string): Promise<void>; /** * Create new contact * * @param {string} contactPaymail - Paymail address for the new contact * @param {NewContact} newContact - Contact information * @returns {Promise<Contact>} Created contact */ createContact(contactPaymail: string, newContact: NewContact): Promise<Contact>; /** * Confirm contacts * * @param {string} paymailA - First contact's paymail * @param {string} paymailB - Second contact's paymail * @returns {Promise<void>} */ confirmContacts(paymailA: string, paymailB: string): Promise<void>; /** * Get shared configuration * * @returns {Promise<SharedConfig>} Shared configuration settings */ sharedConfig(): Promise<SharedConfig>; } declare class WebhookManager { url: string; options: WebhookOptions; subscriber: SPVWalletAdminAPI; handlers: EventsMap; constructor(subscriber: SPVWalletAdminAPI, url: string, options?: WebhookOptions); subscribe(): Promise<void>; unsubscribe(): Promise<void>; handleIncomingEvents(httpHandler: WebhookHttpHandler): Promise<void>; registerHandler<T extends keyof Events>(eventName: T, handlerFunction: EventHandler<Events[T]>): void; } /** * SPVWalletUserAPI class for handling user-specific operations * * @class SPVWalletUserAPI */ declare class SPVWalletUserAPI { private logger; private http; private xPriv?; /** * Creates a new instance of SPVWalletUserAPI * * @param {string} serverUrl - The base URL of the SPV Wallet server * @param {ClientOptions} options - Configuration options including xPub, xPriv, or accessKey * @param {LoggerConfig} loggerConfig - Logger configuration (optional) */ constructor(serverUrl: string, options: ClientOptions, loggerConfig?: LoggerConfig); private ensureSuffix; private makeRequester; /** * Get a list of all contacts for the current user * * @param {ContactFilter} conditions - Key value object to use to filter the documents * @param {Metadata} metadata - Key value object to use to filter the documents by the metadata * @param {QueryPageParams} queryParams - Database query parameters for page, page size and sorting * @returns {Promise<PageModel<Contact>>} List of contacts matching the criteria */ contacts(conditions: ContactFilter, metadata: Metadata, queryParams: QueryPageParams): Promise<PageModel<Contact>>; /** * Get a single contact by paymail address * * @param {string} paymail - Paymail address of the contact * @returns {Promise<Contact>} Contact information */ contactWithPaymail(paymail: string): Promise<Contact>; /** * Update or insert a contact * * @param {string} paymail - Contact's paymail address * @param {string} fullName - Full name of the contact * @param {string} requesterPaymail - Paymail of the requester * @param {Metadata} metadata - Additional metadata for the contact * @returns {Promise<Contact>} Updated or created contact */ upsertContact(paymail: string, fullName: string, requesterPaymail: string, metadata: Metadata): Promise<Contact>; /** * Remove a contact by paymail address * * @param {string} paymail - Paymail address of the contact to remove * @returns {Promise<void>} */ removeContact(paymail: string): Promise<void>; /** * Confirm a contact by validating their TOTP passcode * * @param {Contact} contact - Contact to confirm * @param {string} passcode - TOTP passcode to validate * @param {string} requesterPaymail - Paymail of the person requesting confirmation * @param {number} [period=DEFAULT_TOTP_PERIOD] - TOTP period in seconds * @param {number} [digits=DEFAULT_TOTP_DIGITS] - Number of digits in TOTP * @returns {Promise<boolean>} True if confirmation successful * @throws {ErrorWrongTOTP} If TOTP validation fails */ confirmContact(contact: Contact, passcode: string, requesterPaymail: string, period?: number, digits?: number): Promise<boolean>; /** * Remove confirmation status from a contact * * @param {string} paymail - Paymail address of the contact to unconfirm * @returns {Promise<void>} */ unconfirmContact(paymail: string): Promise<void>; /** * Accept a contact invitation * * @param {string} paymail - Paymail address of the contact who sent the invitation * @returns {Promise<void>} */ acceptInvitation(paymail: string): Promise<void>; /** * Reject a contact invitation * * @param {string} paymail - Paymail address of the contact whose invitation to reject * @returns {Promise<void>} */ rejectInvitation(paymail: string): Promise<void>; /** * Get shared configuration settings * * @returns {Promise<SharedConfig>} Shared configuration object */ sharedConfig(): Promise<SharedConfig>; /** * Draft a new transaction * * @param {DraftTransactionConfig} config - Configuration for the draft transaction * @param {Metadata} metadata - Additional metadata for the transaction * @returns {Promise<DraftTx>} The draft transaction */ draftTransaction(config: DraftTransactionConfig, metadata: Metadata): Promise<DraftTx>; /** * Record a transaction in the system * * @param {string} hex - Transaction hex * @param {string} referenceId - Reference ID (usually draft transaction ID) * @param {Metadata} metadata - Additional metadata for the transaction * @returns {Promise<Tx>} The recorded transaction */ recordTransaction(hex: string, referenceId: string, metadata: Metadata): Promise<Tx>; /** * Update transaction metadata * * @param {string} txId - Transaction ID * @param {Metadata} metadata - New metadata to update * @returns {Promise<Tx>} Updated transaction */ updateTransactionMetadata(txId: string, metadata: Metadata): Promise<Tx>; /** * Get a list of transactions * * @param {TransactionFilter} conditions - Filter conditions * @param {Metadata} metadata - Metadata filter * @param {QueryPageParams} queryParams - Pagination parameters * @returns {Promise<PageModel<Tx>>} List of transactions */ transactions(conditions: TransactionFilter, metadata: Metadata, queryParams: QueryPageParams): Promise<PageModel<Tx>>; /** * Get transaction by ID * * @param {string} id - Transaction ID * @returns {Promise<Tx>} Transaction details */ transaction(id: string): Promise<Tx>; /** * Finalize a draft transaction by signing it * * @param {DraftTx} draft - Draft transaction to finalize * @returns {Promise<string>} Signed transaction hex * @throws {ErrorNoXPrivToSignTransaction} If xPriv is not available * @throws {ErrorTxIdsDontMatchToDraft} If transaction IDs don't match */ finalizeTransaction(draft: DraftTx): Promise<string>; /** * Send to recipients (combines draft, sign, and record) * * @param {DraftTransactionConfig} config - Transaction configuration * @param {Metadata} metadata - Transaction metadata * @returns {Promise<Tx>} The final transaction */ sendToRecipients(config: DraftTransactionConfig, metadata: Metadata): Promise<Tx>; /** * Get current user's xPub information * * @returns {Promise<User>} User information */ xPub(): Promise<User>; /** * Update xPub metadata * * @param {Metadata} metadata - New metadata to update * @returns {Promise<User>} Updated user information */ updateXPubMetadata(metadata: Metadata): Promise<User>; /** * Generate a new access key * * @param {Metadata} metadata - Metadata for the new access key * @returns {Promise<AccessKey>} Generated access key */ generateAccessKey(metadata: Metadata): Promise<AccessKey>; /** * Get a list of access keys * * @param {AccessKeyFilter} conditions - Filter conditions for access keys * @param {QueryPageParams} queryParams - Pagination parameters * @returns {Promise<PageModel<AccessKey>>} List of access keys */ accessKeys(conditions: AccessKeyFilter, queryParams: QueryPageParams): Promise<PageModel<AccessKey>>; /** * Get a specific access key by ID * * @param {string} id - Access key ID * @returns {Promise<AccessKey>} Access key details */ accessKey(id: string): Promise<AccessKey>; /** * Revoke an access key * * @param {string} id - ID of the access key to revoke * @returns {Promise<void>} */ revokeAccessKey(id: string): Promise<void>; /** * Get a list of UTXOs * * @param {UtxoFilter} conditions - Filter conditions for UTXOs * @param {Metadata} metadata - Metadata filter * @param {QueryPageParams} queryParams - Pagination parameters * @returns {Promise<PageModel<Utxo>>} List of UTXOs */ utxos(conditions: UtxoFilter, metadata: Metadata, queryParams: QueryPageParams): Promise<PageModel<Utxo>>; /** * Get merkle roots * * @param {string} [lastEvaluatedKey] - Last evaluated key for pagination * @returns {Promise<ExclusiveStartKeyPage<MerkleRoot[]>>} Page of merkle roots */ merkleRoots(lastEvaluatedKey?: string): Promise<ExclusiveStartKeyPage<MerkleRoot[]>>; /** * Sync merkle roots from the client db to the last known block * * @param {MerkleRootsRepository} repo - Repository interface for merkle root operations * @param {number} [timeoutMs] - Optional timeout in milliseconds * @throws {ErrorSyncMerkleRootsTimeout} When the sync operation times out * @throws {ErrorStaleLastEvaluatedKey} When the last evaluated key becomes stale * @returns {Promise<void>} */ syncMerkleRoots(repo: MerkleRootsRepository, timeoutMs?: number): Promise<void>; /** * Generate TOTP for a contact * * @param {Contact} contact - Contact to generate TOTP for * @param {number} [period=DEFAULT_TOTP_PERIOD] - TOTP period * @param {number} [digits=DEFAULT_TOTP_DIGITS] - Number of TOTP digits * @returns {string} Generated TOTP * @throws {ErrorNoXPrivToGenerateTOTP} If xPriv is not available */ generateTotpForContact(contact: Contact, period?: number, digits?: number): string; validateTotpForContact(contact: Contact, passcode: string, requesterPaymail: string, period?: number, digits?: number): boolean; /** * Get a list of paymail addresses * * @param {PaymailFilter} conditions - Filter conditions for paymail addresses * @param {Metadata} metadata - Metadata filter * @param {QueryPageParams} queryParams - Pagination parameters * @returns {Promise<PageModel<PaymailAddress>>} List of paymail addresses */ paymails(conditions: PaymailFilter, metadata: Metadata, queryParams: QueryPageParams): Promise<PageModel<PaymailAddress>>; } export { type AccessKey, type AccessKeyWithSigning, type AdminClientOptions, type AdminKey, type AdminStats, type AdminTx, AuthAccessKey, AuthHeader, AuthHeaderHash, AuthHeaderNonce, AuthHeaderTime, type AuthPayload, AuthSignature, type ChangeStrategy, type Client, type ClientOptions, type Contact, type Destination, type DraftStatus, type DraftTransactionConfig, type DraftTx, ErrorClientInitNoXpriv, ErrorInvalidAdminClientOptions, ErrorInvalidClientOptions, ErrorNoAdminKey, ErrorNoXPrivToGenerateTOTP, ErrorNoXPrivToSignTransaction, ErrorNoXPrivToValidateTOTP, ErrorResponse, ErrorStaleLastEvaluatedKey, ErrorSyncMerkleRootsTimeout, ErrorTxIdsDontMatchToDraft, ErrorWrongHex, ErrorWrongTOTP, type EventHandler, type Events, EventsMap, type ExclusiveStartKeyPage, type ExclusiveStartKeyPageInfo, type FeeUnit, type HttpMethod, type Key, type KeyWithMnemonic, type MapProtocol, type MerkleRoot, type MerkleRootsRepository, type Metadata, type NewContact, type OpReturn, type Page, type PageModel, type PaymailAddress, type PaymailP4, type PubKey, type QueryPageParams, type RawEvent, SPVWalletAdminAPI, SPVWalletUserAPI, type ScriptOutput, type SharedConfig, SpvWalletError, type StringEvent, type SyncConfig, type TransactionEvent, type Tx, type TxConfig, type TxInput, type TxOutput, type User, type UserEvent, type Utxo, type UtxoPointer, type Webhook, type WebhookHttpHandler, WebhookManager, type WebhookOptions, type XPub, type XprivWithSigning, type XpubWithoutSigning, createSignature, deriveChildKeyFromHex, deriveHDChildKeyFromHex, generateKeys, getKeysFromMnemonic, getKeysFromString, getSigningMessage, setSignature };