0.2.26 • Published 14 days ago

btms-core v0.2.26

Weekly downloads
-
License
Open BSV License
Repository
github
Last release
14 days ago

btms-core

Tools for creating and managing UTXO-based tokens

Installation

npm i btms-core

Example Usage

// todo

Documentation

Links: API, Interfaces, Classes

Interfaces

Asset
IncomingPayment
OverlaySearchResult
OwnershipProof
SubmitResult
TokenForRecipient

Links: API, Interfaces, Classes


Interface: Asset

export interface Asset {
    assetId: string;
    balance: number;
    name?: string;
    iconURL?: string;
    metadata?: string;
    incoming?: boolean;
    incomingAmount?: number;
    new?: boolean;
}

Links: API, Interfaces, Classes


Interface: TokenForRecipient

export interface TokenForRecipient {
    txid: string;
    vout: number;
    amount: number;
    envelope: CreateActionResult;
    keyID: string;
    outputScript: string;
}

Links: API, Interfaces, Classes


Interface: SubmitResult

export interface SubmitResult {
    status: "auccess";
    topics: Record<string, number[]>;
}

Links: API, Interfaces, Classes


Interface: OverlaySearchResult

export interface OverlaySearchResult {
    inputs: string | null;
    mapiResponses: string | null;
    outputScript: string;
    proof: string | null;
    rawTx: string;
    satoshis: number;
    txid: string;
    vout: number;
}

Links: API, Interfaces, Classes


Interface: IncomingPayment

export interface IncomingPayment {
    txid: string;
    vout: number;
    outputScript: string;
    amount: number;
    token: TokenForRecipient;
    sender: string;
    messageId: string;
    keyID: string;
    envelope: CreateActionResult;
}

Links: API, Interfaces, Classes


Interface: OwnershipProof

export interface OwnershipProof {
    prover: string;
    verifier: string;
    assetId: string;
    amount: number;
    tokens: {
        output: GetTransactionOutputResult;
        linkage: SpecificKeyLinkageResult;
    }[];
}

Links: API, Interfaces, Classes


Classes

Class: BTMS

The BTMS class provides an interface for managing and transacting assets using the Babbage SDK.

export 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;
    constructor(confederacyHost = "https://confederacy.babbage.systems", peerServHost = "https://peerserv.babbage.systems", tokensMessageBox = "tokens-box", protocolID = "tokens", basket = "tokens", tokensTopic = "tokens", satoshis = 1000, privateKey?: string, marketplaceMessageBox = "marketplace", marketplaceTopic = "marketplace") 
    async listAssets(): Promise<Asset[]> 
    async issue(amount: number, name: string): Promise<SubmitResult> 
    async send(assetId: string, recipient: string, sendAmount: number, disablePeerServ = false, onPaymentSent = (payment: TokenForRecipient) => { }): Promise<SubmitResult> 
    async listIncomingPayments(assetId: string): Promise<IncomingPayment[]> 
    async acceptIncomingPayment(assetId: string, payment: IncomingPayment): Promise<boolean> 
    async refundIncomingTransaction(assetId: string, payment: IncomingPayment): Promise<SubmitResult> 
    async getTokens(assetId: string, includeEnvelope = true): Promise<GetTransactionOutputResult[]> 
    async getBalance(assetId: string, myTokens?: GetTransactionOutputResult[]): Promise<number> 
    async getTransactions(assetId: string, limit: number, offset: number): Promise<{
        transactions: {
            date: string;
            amount: number;
            txid: string;
            counterparty: string;
        }[];
    }> 
    async proveOwnership(assetId: string, amount: number, verifier: string): Promise<OwnershipProof> 
    async verifyOwnership(proof: OwnershipProof, useAnyoneKey = false): Promise<boolean> 
    validateAssetId(assetId: string): boolean 
    async listAssetForSale(assetId: string, amount: number, desiredAssets: Record<string, number>, description?: string): Promise<SubmitResult> 
    async findAllAssetsForSale(findMine = false): Promise<MarketplaceEntry[]> 
    async makeOffer(entry: MarketplaceEntry, assetId: string, amount: number): Promise<void> 
    async listOutgoingOffers(): Promise<MarketplaceOffer[]> 
    async cancelOutgoingOffer(offer: MarketplaceOffer): Promise<void> 
    async listIncomingOffers(forEntry?: MarketplaceEntry): Promise<MarketplaceOffer[]> 
    async acceptOffer(offer: MarketplaceOffer): Promise<void> 
    async acknowledgeNewlyAcquiredMarketplaceAssets(): Promise<void> 
    async rejectOffer(offer: MarketplaceOffer): Promise<void> 
    async acknowledgeRejection(offer: MarketplaceOffer): Promise<void> 
}
Constructor

BTMS constructor.

constructor(confederacyHost = "https://confederacy.babbage.systems", peerServHost = "https://peerserv.babbage.systems", tokensMessageBox = "tokens-box", protocolID = "tokens", basket = "tokens", tokensTopic = "tokens", satoshis = 1000, privateKey?: string, marketplaceMessageBox = "marketplace", marketplaceTopic = "marketplace") 

Argument Details

  • confederacyHost
    • The confederacy host URL.
  • peerServHost
    • The peer service host URL.
  • tokensMessageBox
    • The message box ID.
  • protocolID
    • The protocol ID.
  • basket
    • The asset basket ID.
  • tokensTopic
    • The topic associated with the asset.
  • satoshis
    • The number of satoshis involved in transactions.
Method findAllAssetsForSale

Returns an array of all marketplace entries

async findAllAssetsForSale(findMine = false): Promise<MarketplaceEntry[]> 

Returns

An array of all marketplace entries

Method getBalance

Get the balance of a given asset.

async getBalance(assetId: string, myTokens?: GetTransactionOutputResult[]): Promise<number> 

Returns

Returns a promise that resolves to the balance.

Argument Details

  • assetId
    • The ID of the asset.
  • myTokens
    • (Optional) An array of token objects owned by the caller.
Method getTokens

Get all tokens for a given asset.

async getTokens(assetId: string, includeEnvelope = true): Promise<GetTransactionOutputResult[]> 

Returns

Returns a promise that resolves to an array of token objects.

Argument Details

  • assetId
    • The ID of the asset.
  • includeEnvelope
    • Include the envelope in the result.
Method listAssetForSale

Lists an asset on the marketplace for sale

async listAssetForSale(assetId: string, amount: number, desiredAssets: Record<string, number>, description?: string): Promise<SubmitResult> 

Returns

Overlay network submission results

Argument Details

  • assetId
    • The ID of the asset to list
  • amount
    • The amount you want to sell
  • desiredAssets
    • Assets you would desire to have in return so people can make you an offer
  • description
    • Marketplace listing description
Method listIncomingPayments

List incoming payments for a given asset.

async listIncomingPayments(assetId: string): Promise<IncomingPayment[]> 

Returns

Returns a promise that resolves to an array of payment objects.

Argument Details

  • assetId
    • The ID of the asset.
Method send

Send tokens to a recipient.

async send(assetId: string, recipient: string, sendAmount: number, disablePeerServ = false, onPaymentSent = (payment: TokenForRecipient) => { }): Promise<SubmitResult> 

Returns

Returns a promise that resolves to a transaction action object.

Argument Details

  • assetId
    • The ID of the asset to be sent.
  • recipient
    • The recipient's public key.
  • sendAmount
    • The amount of the asset to be sent.

Throws

Throws an error if the sender does not have enough tokens.

Method validateAssetId

Checks that an asset ID is in the correct format

validateAssetId(assetId: string): boolean 

Returns

a boolean indicating asset ID validity

Argument Details

  • assetId
    • Asset ID to validate

Links: API, Interfaces, Classes


License

The license for the code in this repository is the Open BSV License.

0.2.26

14 days ago

0.2.25

14 days ago

0.2.24

14 days ago

0.2.23

14 days ago

0.2.22

20 days ago

0.2.21

21 days ago

0.2.20

1 month ago

0.2.19

1 month ago

0.2.18

1 month ago

0.2.17

1 month ago

0.2.16

1 month ago

0.2.15

1 month ago

0.2.14

1 month ago

0.2.13

1 month ago

0.2.12

1 month ago

0.2.11

2 months ago

0.2.10

2 months ago

0.2.9

2 months ago

0.2.7

2 months ago

0.2.8

2 months ago

0.2.6

2 months ago

0.2.5

2 months ago

0.2.4

2 months ago

0.2.1

2 months ago

0.2.0

2 months ago

0.2.3

2 months ago

0.2.2

2 months ago

0.1.38

2 months ago

0.1.37

2 months ago

0.1.34

3 months ago

0.1.35

3 months ago

0.1.36

3 months ago

0.1.33

3 months ago

0.1.32

3 months ago

0.1.31

3 months ago

0.1.30

3 months ago

0.1.29

3 months ago

0.1.27

3 months ago

0.1.28

3 months ago

0.1.25

3 months ago

0.1.26

3 months ago

0.1.24

3 months ago

0.1.23

3 months ago

0.1.21

4 months ago

0.1.22

4 months ago

0.1.20

4 months ago

0.1.19

4 months ago

0.1.18

4 months ago

0.1.17

4 months ago

0.1.16

4 months ago

0.1.15

5 months ago

0.1.14

5 months ago

0.1.8

9 months ago

0.1.7

9 months ago

0.1.6

9 months ago

0.1.5

9 months ago

0.1.4

9 months ago

0.1.3

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.0

9 months ago