btms-core
Version:
Tools for creating and managing UTXO-based tokens
196 lines • 7.55 kB
TypeScript
import { CreateActionResult, GetTransactionOutputResult, SpecificKeyLinkageResult, EnvelopeApi } from '@babbage/sdk-ts';
import { Authrite } from 'authrite-js';
import Tokenator from '@babbage/tokenator';
export interface Asset {
assetId: string;
balance: number;
name?: string;
iconURL?: string;
metadata?: string;
incoming?: boolean;
incomingAmount?: number;
new?: boolean;
}
export interface TokenForRecipient {
txid: string;
vout: number;
amount: number;
envelope: CreateActionResult;
keyID: string;
outputScript: string;
}
export interface SubmitResult {
status: 'auccess';
topics: Record<string, number[]>;
}
export interface OverlaySearchResult {
inputs: string | null;
mapiResponses: string | null;
outputScript: string;
proof: string | null;
rawTx: string;
satoshis: number;
txid: string;
vout: number;
}
export interface IncomingPayment {
txid: string;
vout: number;
outputScript: string;
amount: number;
token: TokenForRecipient;
sender: string;
messageId: string;
keyID: string;
envelope: CreateActionResult;
}
export interface OwnershipProof {
prover: string;
verifier: string;
assetId: string;
amount: number;
tokens: {
output: GetTransactionOutputResult;
linkage: SpecificKeyLinkageResult;
}[];
}
interface MarketplaceEntry {
assetId: string;
amount: number;
seller: string;
description: string;
desiredAssets: Record<string, number>;
ownershipProof: OwnershipProof;
metadata: string;
}
interface MarketplaceOffer {
buyerOffersAssetId: string;
buyerOffersAmount: number;
buyerProof: OwnershipProof;
buyerPartialTX: string;
buyerFundingEnvelope: CreateActionResult | EnvelopeApi;
sellerEntry: MarketplaceEntry;
fundingKeyID: string;
messageId?: string;
rejected?: boolean;
isAsDesiredBySeller?: boolean;
desiredSellerKeyID?: string;
desiredSellerChangeKeyID?: string;
desiredBuyerKeyID?: string;
desiredBuyerChangeKeyID?: string;
}
/**
* The BTMS class provides an interface for managing and transacting assets using the Babbage SDK.
* @class
*/
export declare class BTMS {
confederacyHost: string;
peerServHost: string;
tokenator: Tokenator;
tokensMessageBox: string;
marketplaceMessageBox: string;
protocolID: string;
basket: string;
tokenTopic: string;
satoshis: number;
authrite: Authrite;
privateKey: string | undefined;
marketplaceTopic: string;
/**
* BTMS constructor.
* @constructor
* @param {string} confederacyHost - The confederacy host URL.
* @param {string} peerServHost - The peer service host URL.
* @param {string} tokensMessageBox - The message box ID.
* @param {string} protocolID - The protocol ID.
* @param {string} basket - The asset basket ID.
* @param {string} tokensTopic - The topic associated with the asset.
* @param {number} satoshis - The number of satoshis involved in transactions.
*/
constructor(confederacyHost?: string, peerServHost?: string, tokensMessageBox?: string, protocolID?: string, basket?: string, tokensTopic?: string, satoshis?: number, privateKey?: string, marketplaceMessageBox?: string, marketplaceTopic?: string);
listAssets(): Promise<Asset[]>;
issue(amount: number, name: string): Promise<SubmitResult>;
/**
* Send tokens to a recipient.
* @async
* @param {string} assetId - The ID of the asset to be sent.
* @param {string} recipient - The recipient's public key.
* @param {number} sendAmount - The amount of the asset to be sent.
* @returns {Promise<any>} Returns a promise that resolves to a transaction action object.
* @throws {Error} Throws an error if the sender does not have enough tokens.
*/
send(assetId: string, recipient: string, sendAmount: number, disablePeerServ?: boolean, onPaymentSent?: (payment: TokenForRecipient) => void): Promise<SubmitResult>;
/**
* List incoming payments for a given asset.
* @async
* @param {string} assetId - The ID of the asset.
* @returns {Promise<any[]>} Returns a promise that resolves to an array of payment objects.
*/
listIncomingPayments(assetId: string): Promise<IncomingPayment[]>;
acceptIncomingPayment(assetId: string, payment: IncomingPayment): Promise<boolean>;
refundIncomingTransaction(assetId: string, payment: IncomingPayment): Promise<SubmitResult>;
/**
* Get all tokens for a given asset.
* @async
* @param {string} assetId - The ID of the asset.
* @param {boolean} includeEnvelope - Include the envelope in the result.
* @returns {Promise<any[]>} Returns a promise that resolves to an array of token objects.
*/
getTokens(assetId: string, includeEnvelope?: boolean): Promise<GetTransactionOutputResult[]>;
/**
* Get the balance of a given asset.
* @async
* @param {string} assetId - The ID of the asset.
* @param {any[]} myTokens - (Optional) An array of token objects owned by the caller.
* @returns {Promise<number>} Returns a promise that resolves to the balance.
*/
getBalance(assetId: string, myTokens?: GetTransactionOutputResult[]): Promise<number>;
getTransactions(assetId: string, limit: number, offset: number): Promise<{
transactions: {
date: string;
amount: number;
txid: string;
counterparty: string;
}[];
}>;
proveOwnership(assetId: string, amount: number, verifier: string): Promise<OwnershipProof>;
verifyOwnership(proof: OwnershipProof, useAnyoneKey?: boolean): Promise<boolean>;
/**
* Checks that an asset ID is in the correct format
* @param assetId Asset ID to validate
* @returns a boolean indicating asset ID validity
*/
validateAssetId(assetId: string): boolean;
/**
* Lists an asset on the marketplace for sale
* @param assetId The ID of the asset to list
* @param amount The amount you want to sell
* @param desiredAssets Assets you would desire to have in return so people can make you an offer
* @param description Marketplace listing description
* @returns Overlay network submission results
*/
listAssetForSale(assetId: string, amount: number, desiredAssets: Record<string, number>, description?: string): Promise<SubmitResult>;
/**
* Returns an array of all marketplace entries
* @returns An array of all marketplace entries
*/
findAllAssetsForSale(findMine?: boolean): Promise<MarketplaceEntry[]>;
makeOffer(entry: MarketplaceEntry, assetId: string, amount: number): Promise<void>;
listOutgoingOffers(): Promise<MarketplaceOffer[]>;
cancelOutgoingOffer(offer: MarketplaceOffer): Promise<void>;
listIncomingOffers(forEntry?: MarketplaceEntry): Promise<MarketplaceOffer[]>;
acceptOffer(offer: MarketplaceOffer): Promise<void>;
acknowledgeNewlyAcquiredMarketplaceAssets(): Promise<void>;
rejectOffer(offer: MarketplaceOffer): Promise<void>;
acknowledgeRejection(offer: MarketplaceOffer): Promise<void>;
private verifyLinkageForProver;
private findFromTokenOverlay;
private findFromMarketplaceOverlay;
private submitToTokenOverlay;
private submitToMarketplaceOverlay;
private getCounterpartyFromInstructions;
private getKeyIDFromInstructions;
private getRandomKeyID;
}
export {};
//# sourceMappingURL=index.d.ts.map