ts-xdbchain-sdk
Version:
A TypeScript SDK for interacting with XDBCHAIN - a Stellar-based blockchain network
370 lines • 14.5 kB
TypeScript
import { Horizon, Keypair, Asset, Account, Transaction } from 'stellar-sdk';
export interface XDBChainConfig {
network: 'mainnet' | 'futurenet';
horizonUrl?: string;
networkPassphrase?: string;
startingBalance?: string;
timeout?: number;
allowHttp?: boolean;
}
export interface XDBWallet {
publicKey: string;
secretKey: string;
network: string;
account?: Account;
}
export interface XDBBalance {
assetType: string;
assetCode: string;
assetIssuer: string | null;
balance: string;
limit: string | null;
buyingLiabilities: string;
sellingLiabilities: string;
lastModifiedLedger?: number;
isAuthorized?: boolean;
isAuthorizedToMaintainLiabilities?: boolean;
}
export interface XDBAsset {
code: string;
issuer?: string;
type: 'native' | 'credit_alphanum4' | 'credit_alphanum12';
}
export interface XDBPaymentOptions {
destination: string;
amount: string;
asset?: XDBAsset;
memo?: string;
memoType?: 'text' | 'id' | 'hash' | 'return';
source?: string;
}
export interface XDBPathPaymentOptions {
sendAsset: XDBAsset;
sendMax: string;
destination: string;
destAsset: XDBAsset;
destAmount: string;
path?: XDBAsset[];
memo?: string;
memoType?: 'text' | 'id' | 'hash' | 'return';
source?: string;
}
export interface XDBTransaction {
hash: string;
ledger: number;
createdAt: string;
fee: string;
operationCount: number;
memo?: string;
memoType?: string;
successful: boolean;
pagingToken: string;
sourceAccount: string;
sourceAccountSequence: string;
feeAccount: string;
feeCharged: string;
maxFee: string;
timeBounds?: {
minTime: string;
maxTime: string;
};
}
export interface XDBTrustlineOptions {
assetCode: string;
assetIssuer: string;
limit?: string;
source?: string;
}
export interface XDBClaimableBalance {
id: string;
assetCode: string;
assetIssuer: string | null;
amount: string;
claimants: Array<{
destination: string;
predicate: any;
}>;
sponsor?: string;
flags: number;
lastModifiedLedger: number;
lastModifiedTime: string;
}
export interface XDBStreamOptions {
cursor?: string;
limit?: number;
order?: 'asc' | 'desc';
includeFailed?: boolean;
}
export interface XDBAccountOptions {
homeDomain?: string;
inflationDest?: string;
masterWeight?: number;
lowThreshold?: number;
medThreshold?: number;
highThreshold?: number;
signer?: {
ed25519PublicKey?: string;
sha256Hash?: string;
preAuthTx?: string;
weight: number;
};
setFlags?: number;
clearFlags?: number;
source?: string;
}
export interface XDBOfferOptions {
selling: XDBAsset;
buying: XDBAsset;
amount: string;
price: string | number;
offerId?: string;
source?: string;
}
export interface XDBDataOptions {
name: string;
value: string | Buffer | null;
source?: string;
}
export interface XDBAccountMergeOptions {
destination: string;
source?: string;
}
export interface XDBBumpSequenceOptions {
bumpTo: string;
source?: string;
}
export interface XDBCreateAccountOptions {
destination: string;
startingBalance: string;
source?: string;
}
export interface XDBEffect {
id: string;
type: string;
account: string;
createdAt: string;
operationId: string;
details: any;
}
export interface XDBTrade {
id: string;
pagingToken: string;
ledgerCloseTime: string;
offerIds: {
base: string;
counter: string;
};
baseAccount: string;
baseAmount: string;
baseAssetType: string;
baseAssetCode?: string;
baseAssetIssuer?: string;
counterAccount: string;
counterAmount: string;
counterAssetType: string;
counterAssetCode?: string;
counterAssetIssuer?: string;
baseIsSeller: boolean;
price: {
n: number;
d: number;
};
}
export interface XDBOrderbook {
bids: Array<{
price: string;
amount: string;
}>;
asks: Array<{
price: string;
amount: string;
}>;
base: XDBAsset;
counter: XDBAsset;
}
export interface XDBLedger {
id: string;
pagingToken: string;
hash: string;
sequence: number;
transactionCount: number;
operationCount: number;
closedAt: string;
totalCoins: string;
feePool: string;
baseFee: number;
baseReserve: string;
maxTxSetSize: number;
protocolVersion: number;
headerXdr: string;
}
export interface XDBOffer {
id: string;
pagingToken: string;
seller: string;
selling: XDBAsset;
buying: XDBAsset;
amount: string;
price: string;
lastModifiedLedger: number;
lastModifiedTime: string;
}
export interface XDBPayment {
id: string;
pagingToken: string;
transactionSuccessful: boolean;
sourceAccount: string;
type: string;
createdAt: string;
transactionHash: string;
assetType: string;
assetCode?: string;
assetIssuer?: string;
from: string;
to: string;
amount: string;
memo?: string;
memoType?: string;
}
export declare class XDBChainError extends Error {
code?: string | undefined;
details?: any | undefined;
constructor(message: string, code?: string | undefined, details?: any | undefined);
}
export declare class XDBNetworkError extends XDBChainError {
constructor(message: string, details?: any);
}
export declare class XDBValidationError extends XDBChainError {
constructor(message: string, details?: any);
}
export declare class XDBTransactionError extends XDBChainError {
constructor(message: string, details?: any);
}
export declare class XDBAssetError extends XDBChainError {
constructor(message: string, details?: any);
}
export declare class XDBOfferError extends XDBChainError {
constructor(message: string, details?: any);
}
export declare const ACCOUNT_FLAGS: {
readonly AUTH_REQUIRED_FLAG: 1;
readonly AUTH_REVOCABLE_FLAG: 2;
readonly AUTH_IMMUTABLE_FLAG: 4;
readonly AUTH_CLAWBACK_ENABLED_FLAG: 8;
};
export declare const ASSET_TYPE: {
readonly NATIVE: "native";
readonly CREDIT_ALPHANUM4: "credit_alphanum4";
readonly CREDIT_ALPHANUM12: "credit_alphanum12";
};
export declare const OPERATION_TYPE: {
readonly CREATE_ACCOUNT: "create_account";
readonly PAYMENT: "payment";
readonly PATH_PAYMENT_STRICT_RECEIVE: "path_payment_strict_receive";
readonly PATH_PAYMENT_STRICT_SEND: "path_payment_strict_send";
readonly MANAGE_SELL_OFFER: "manage_sell_offer";
readonly MANAGE_BUY_OFFER: "manage_buy_offer";
readonly CREATE_PASSIVE_SELL_OFFER: "create_passive_sell_offer";
readonly SET_OPTIONS: "set_options";
readonly CHANGE_TRUST: "change_trust";
readonly ALLOW_TRUST: "allow_trust";
readonly ACCOUNT_MERGE: "account_merge";
readonly INFLATION: "inflation";
readonly MANAGE_DATA: "manage_data";
readonly BUMP_SEQUENCE: "bump_sequence";
readonly CREATE_CLAIMABLE_BALANCE: "create_claimable_balance";
readonly CLAIM_CLAIMABLE_BALANCE: "claim_claimable_balance";
readonly BEGIN_SPONSORING_FUTURE_RESERVES: "begin_sponsoring_future_reserves";
readonly END_SPONSORING_FUTURE_RESERVES: "end_sponsoring_future_reserves";
readonly REVOKE_SPONSORSHIP: "revoke_sponsorship";
readonly CLAWBACK: "clawback";
readonly CLAWBACK_CLAIMABLE_BALANCE: "clawback_claimable_balance";
readonly SET_TRUST_LINE_FLAGS: "set_trust_line_flags";
};
export declare class XDBChainSDK {
private server;
private networkPassphrase;
private config;
private static readonly DEFAULT_CONFIGS;
constructor(config: XDBChainConfig);
createWallet(): Promise<XDBWallet>;
loadWallet(secretKey: string): Promise<XDBWallet>;
createWalletFromSeed(seed: string | Buffer): Promise<XDBWallet>;
isValidAddress(address: string): boolean;
isValidSecretKey(secretKey: string): boolean;
generateKeypair(): Keypair;
keypairFromSecret(secretKey: string): Keypair;
keypairFromPublicKey(publicKey: string): Keypair;
loadAccount(publicKey: string): Promise<Account>;
createAccount(source: string, destination: string, startingBalance?: string): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
setAccountOptions(secretKey: string, options: XDBAccountOptions): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
mergeAccount(sourceSecret: string, destination: string): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
bumpSequence(secretKey: string, bumpTo: string): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
getBalances(publicKey: string): Promise<XDBBalance[]>;
getXDBBalance(publicKey: string): Promise<string>;
watchBalances(publicKey: string, callback: (balances: XDBBalance[]) => void): () => void;
sendPayment(senderSecret: string, options: XDBPaymentOptions): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
sendPathPaymentStrictReceive(senderSecret: string, options: XDBPathPaymentOptions): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
sendPathPaymentStrictSend(senderSecret: string, options: XDBPathPaymentOptions): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
sendBatchPayments(senderSecret: string, payments: XDBPaymentOptions[]): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
addTrustline(walletSecret: string, options: XDBTrustlineOptions): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
removeTrustline(walletSecret: string, options: Omit<XDBTrustlineOptions, 'limit'>): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
getTrustlines(publicKey: string): Promise<any[]>;
allowTrust(trustorSecret: string, trusteePublicKey: string, assetCode: string, authorize: boolean): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
createAssetObject(code: string, issuer?: string): Asset;
issueAsset(issuerSecret: string, distributorPublicKey: string, assetCode: string, amount: string): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
createSellOffer(secretKey: string, options: XDBOfferOptions): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
createBuyOffer(secretKey: string, options: XDBOfferOptions): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
createPassiveSellOffer(secretKey: string, options: XDBOfferOptions): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
cancelOffer(secretKey: string, offerId: string, selling: XDBAsset, buying: XDBAsset): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
manageData(secretKey: string, options: XDBDataOptions): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
getTransactionHistory(publicKey: string, options?: XDBStreamOptions): Promise<XDBTransaction[]>;
getTransactionsForLedger(ledgerSequence: number, options?: XDBStreamOptions): Promise<XDBTransaction[]>;
watchTransactions(publicKey: string, callback: (transaction: XDBTransaction) => void): () => void;
getOperations(publicKey: string, options?: XDBStreamOptions): Promise<any[]>;
getOperationsForLedger(ledgerSequence: number, options?: XDBStreamOptions): Promise<any[]>;
getOperationsForTransaction(transactionHash: string, options?: XDBStreamOptions): Promise<any[]>;
getPayments(publicKey: string, options?: XDBStreamOptions): Promise<XDBPayment[]>;
watchPayments(publicKey: string, callback: (payment: XDBPayment) => void): () => void;
getEffects(publicKey: string, options?: XDBStreamOptions): Promise<XDBEffect[]>;
getEffectsForOperation(operationId: string, options?: XDBStreamOptions): Promise<XDBEffect[]>;
getTrades(publicKey: string, options?: XDBStreamOptions): Promise<XDBTrade[]>;
getTradesForAssetPair(baseAsset: XDBAsset, counterAsset: XDBAsset, options?: XDBStreamOptions): Promise<XDBTrade[]>;
getOrderbook(selling: XDBAsset, buying: XDBAsset, limit?: number): Promise<XDBOrderbook>;
getOffers(publicKey: string, options?: XDBStreamOptions): Promise<XDBOffer[]>;
getLedger(sequence: number): Promise<XDBLedger>;
getLedgers(options?: XDBStreamOptions): Promise<XDBLedger[]>;
createClaimableBalance(senderSecret: string, claimantPublicKey: string, amount: string, asset?: XDBAsset): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
claimBalance(claimantSecret: string, balanceId: string): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
getClaimableBalances(publicKey: string): Promise<XDBClaimableBalance[]>;
getNetworkInfo(): Promise<any>;
getBaseFee(): Promise<number>;
getFeeStats(): Promise<any>;
fundTestnetAccount(publicKey: string): Promise<boolean>;
estimateFee(operationCount?: number): Promise<number>;
getPaymentPaths(sourcePublicKey: string, destination: XDBAsset, amount: string): Promise<any>;
getStrictReceivePaths(sourceAccount: string, destination: XDBAsset, amount: string): Promise<any>;
getStrictSendPaths(sourceAsset: XDBAsset, destinationAssets: XDBAsset[], amount: string): Promise<any>;
signTransaction(transaction: Transaction, signers: Keypair[]): Transaction;
createMultiSigTransaction(sourceAccount: Account, operations: any[], signers: Keypair[]): Promise<Transaction>;
private createAsset;
private createMemo;
getServer(): Horizon.Server;
getNetworkPassphrase(): string;
getConfig(): XDBChainConfig;
submitTransaction(transaction: Transaction): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
fromXDR(xdr: string): Transaction;
}
export declare function createXDBChainSDK(config: XDBChainConfig): XDBChainSDK;
export declare function createMainnetSDK(): XDBChainSDK;
export declare function createFuturenetSDK(): XDBChainSDK;
export declare function xdbToStroops(amount: number | string): string;
export declare function stroopsToXdb(stroops: number | string): string;
export declare function isValidAmount(amount: string): boolean;
export declare function formatAmount(amount: string, decimals?: number): string;
export declare function generateNonce(): string;
export declare function isValidMemo(memo: string, type?: string): boolean;
export declare function calculateFee(operationCount: number, baseFee: number): number;
export declare function accountExists(server: Horizon.Server, publicKey: string): Promise<boolean>;
export default XDBChainSDK;
//# sourceMappingURL=index.d.ts.map