New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@thorwallet/xchain-bitcoin

Package Overview
Dependencies
Maintainers
3
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thorwallet/xchain-bitcoin - npm Package Compare versions

Comparing version 0.0.1-alpha.979 to 0.1.0-lazy.0

lib/get-balance.d.ts

0

lib/blockstream-api.d.ts

@@ -0,0 +0,0 @@ import { BroadcastTxParams } from './types/common';

90

lib/client.d.ts

@@ -1,2 +0,11 @@

import { Address, Balance, Fee, FeeRate, Network, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, UTXOClient, XChainClientParams } from '@thorwallet/xchain-client';
import { TxHistoryParams, TxsPage, Address, XChainClient, Tx, TxParams, TxHash, Network, Fees, XChainClientParams } from '@thorwallet/xchain-client';
import { FeesWithRates, FeeRate, FeeRates, Signature } from './types/client-types';
/**
* BitcoinClient Interface
*/
interface BitcoinClient {
getFeesWithRates(memo?: string): Promise<FeesWithRates>;
getFeesWithMemo(memo: string): Promise<Fees>;
getFeeRates(): Promise<FeeRates>;
}
export declare type BitcoinClientParams = XChainClientParams & {

@@ -9,6 +18,9 @@ sochainUrl?: string;

*/
declare class Client extends UTXOClient {
declare class Client implements BitcoinClient, XChainClient {
private net;
private phrase;
private sochainUrl;
private blockstreamUrl;
addrCache: Record<string, Record<number, string>>;
private rootDerivationPaths;
private addrCache;
/**

@@ -20,3 +32,3 @@ * Constructor

*/
constructor({ network, sochainUrl, blockstreamUrl, rootDerivationPaths, phrase, }: BitcoinClientParams);
constructor({ network, sochainUrl, blockstreamUrl, rootDerivationPaths, }: BitcoinClientParams);
/**

@@ -28,3 +40,3 @@ * Set/Update the sochain url.

*/
setSochainUrl(url: string): void;
setSochainUrl: (url: string) => void;
/**

@@ -36,3 +48,3 @@ * Set/Update the blockstream url.

*/
setBlockstreamUrl(url: string): void;
setBlockstreamUrl: (url: string) => void;
/**

@@ -82,3 +94,3 @@ * Set/update a new phrase.

*/
getExplorerUrl(): string;
getExplorerUrl: () => string;
/**

@@ -90,3 +102,3 @@ * Get the explorer url for the given address.

*/
getExplorerAddressUrl(address: string): string;
getExplorerAddressUrl: (address: Address) => string;
/**

@@ -98,3 +110,3 @@ * Get the explorer url for the given transaction id.

*/
getExplorerTxUrl(txID: string): string;
getExplorerTxUrl: (txID: string) => string;
/**

@@ -130,11 +142,4 @@ * Get the current address.

*/
validateAddress(address: string): boolean;
validateAddress: (address: string) => boolean;
/**
* Get the BTC balance of a given address.
*
* @param {Address} the BTC address
* @returns {Balance[]} The BTC balance of the address.
*/
getBalance(address: Address): Promise<Balance[]>;
/**
* Get transaction history of a given address with pagination options.

@@ -146,7 +151,48 @@ * By default it will return the transaction history of the current wallet.

*/
getTransactions(params?: TxHistoryParams): Promise<TxsPage>;
getTransactionData(txId: string): Promise<Tx>;
protected getSuggestedFeeRate(): Promise<FeeRate>;
protected calcFee(feeRate: FeeRate, memo?: string): Promise<Fee>;
getTransactions: (params?: TxHistoryParams | undefined) => Promise<TxsPage>;
/**
* Get the transaction details of a given transaction id.
*
* @param {string} txId The transaction id.
* @returns {Tx} The transaction details of the given transaction id.
*/
getTransactionData: (txId: string) => Promise<Tx>;
/**
* Get the rates and fees.
*
* @param {string} memo The memo to be used for fee calculation (optional)
* @returns {FeesWithRates} The fees and rates
*/
getFeesWithRates: (memo?: string | undefined) => Promise<FeesWithRates>;
/**
* Get the current fees.
*
* @returns {Fees} The fees without memo
*/
getFees: () => Promise<Fees>;
/**
* Get the fees for transactions with memo.
* If you want to get `Fees` and `FeeRates` at once, use `getFeesAndRates` method
*
* @param {string} memo
* @returns {Fees} The fees with memo
*/
getFeesWithMemo: (memo: string) => Promise<Fees>;
/**
* Get the fee rates for transactions without a memo.
* If you want to get `Fees` and `FeeRates` at once, use `getFeesAndRates` method
*
* @returns {FeeRates} The fee rate
*/
getFeeRates: () => Promise<FeeRates>;
/**
* Sign an arbitrary string message.
*
*
* @returns {Signature} The current address.
*
* @throws {"Phrase must be provided"} Thrown if phrase has not been set before.
*/
signMessage: (msg: string) => Promise<Signature>;
/**
* Transfer BTC.

@@ -161,2 +207,2 @@ *

}
export { Client };
export { Client, Network };

@@ -7,2 +7,1 @@ /**

export declare const MIN_TX_FEE = 1000;
export declare const BTC_DECIMAL = 8;

@@ -0,0 +0,0 @@ import { Address } from '@thorwallet/xchain-client/lib';

export * from './types';
export * from './client';
export * from './const';
export { broadcastTx, getDefaultFees, getDefaultFeesWithRates, getPrefix, scanUTXOs, buildTx, validateAddress, calcFee, } from './utils';
export { broadcastTx, getDefaultFees, getDefaultFeesWithRates, getPrefix, BTC_DECIMAL, scanUTXOs, buildTx, validateAddress, calcFee, } from './utils';
export { createTxInfo } from './ledger';

@@ -0,0 +0,0 @@ import { LedgerTxInfo, LedgerTxInfoParams } from './types/ledger';

@@ -0,3 +1,3 @@

import { BtcAddressUTXOs, BtcAddressDTO, Transaction, AddressParams, TxHashParams, TxConfirmedStatus } from './types/sochain-api-types';
import { BaseAmount } from '@thorwallet/xchain-util';
import { AddressParams, BtcAddressDTO, BtcAddressUTXO, Transaction, TxConfirmedStatus, TxHashParams } from './types/sochain-api-types';
/**

@@ -44,5 +44,5 @@ * Get address information.

* @param {string} address
* @returns {BtcAddressUTXO[]}
* @returns {BtcAddressUTXOs}
*/
export declare const getUnspentTxs: ({ sochainUrl, network, address, startingFromTxId, }: AddressParams) => Promise<BtcAddressUTXO[]>;
export declare const getUnspentTxs: ({ sochainUrl, network, address, startingFromTxId, }: AddressParams) => Promise<BtcAddressUTXOs>;
/**

@@ -54,3 +54,3 @@ * Get Tx Confirmation status

* @param {string} sochainUrl The sochain node url.
* @param {Network} network
* @param {string} network mainnet | testnet
* @param {string} hash tx id

@@ -66,7 +66,7 @@ * @returns {TxConfirmedStatus}

* @param {string} sochainUrl The sochain node url.
* @param {Network} network
* @param {string} network
* @param {string} address
* @returns {BtcAddressUTXO[]}
* @returns {BtcAddressUTXOs}
*/
export declare const getConfirmedUnspentTxs: ({ sochainUrl, network, address, }: AddressParams) => Promise<BtcAddressUTXO[]>;
export declare const getConfirmedUnspentTxs: ({ sochainUrl, network, address, }: AddressParams) => Promise<BtcAddressUTXOs>;
/**

@@ -73,0 +73,0 @@ * Get Bitcoin suggested transaction fee.

@@ -1,6 +0,12 @@

import { Address, FeeRate, Network } from '@thorwallet/xchain-client';
import { Address, FeeOptionKey, Fees, Network } from '@thorwallet/xchain-client';
export declare type FeeRate = number;
export declare type FeeRates = Record<FeeOptionKey, FeeRate>;
export declare type FeesWithRates = {
rates: FeeRates;
fees: Fees;
};
export declare type NormalTxParams = {
addressTo: Address;
addressTo: string;
amount: number;
feeRate: FeeRate;
feeRate: number;
};

@@ -16,1 +22,5 @@ export declare type VaultTxParams = NormalTxParams & {

};
export declare type Signature = {
signature: string;
pubKey: string;
};
/// <reference types="node" />
import { Network } from '@thorwallet/xchain-client';
import { Network } from '../client';
export declare type Witness = {

@@ -14,2 +14,3 @@ value: number;

};
export declare type UTXOs = UTXO[];
export declare type BroadcastTxParams = {

@@ -20,2 +21,5 @@ network: Network;

};
export declare type DerivePath = Record<Network, string>;
export declare type DerivePath = {
mainnet: string;
testnet: string;
};
export * from './client-types';
export * from './common';
export * from './ledger';

@@ -1,9 +0,9 @@

import { Address, FeeRate, Network, TxParams } from '@thorwallet/xchain-client';
import { OnlyRequired } from '@thorwallet/xchain-util';
import { UTXO } from './common';
import { Address, Network, TxParams } from '@thorwallet/xchain-client';
import { FeeRate } from './client-types';
import { UTXOs } from './common';
export declare type LedgerTxInfo = {
utxos: UTXO[];
utxos: UTXOs;
newTxHex: string;
};
export declare type LedgerTxInfoParams = OnlyRequired<TxParams> & {
export declare type LedgerTxInfoParams = Pick<TxParams, 'amount' | 'recipient'> & {
feeRate: FeeRate;

@@ -10,0 +10,0 @@ sender: Address;

@@ -76,2 +76,3 @@ import { Network, TxHash } from '@thorwallet/xchain-client';

};
export declare type BtcAddressUTXOs = BtcAddressUTXO[];
export declare type BtcBroadcastTransfer = {

@@ -78,0 +79,0 @@ network: string;

/// <reference types="node" />
import { Address, Balance, FeeRate, Fees, FeesWithRates, Network, TxHash, TxParams } from '@thorwallet/xchain-client';
import * as Bitcoin from 'bitcoinjs-lib';
import { Address, Balance, Fees, Network, TxHash, TxParams } from '@thorwallet/xchain-client';
import { BaseAmount } from '@thorwallet/xchain-util';
import * as Bitcoin from 'bitcoinjs-lib';
import { BroadcastTxParams, UTXO } from './types/common';
import { AddressParams, ScanUTXOParam } from './types/sochain-api-types';
import { FeeRate, FeesWithRates } from './types/client-types';
import { BroadcastTxParams, UTXOs } from './types/common';
export declare const BTC_DECIMAL = 8;
/**

@@ -17,3 +19,3 @@ * Compile memo.

*
* @param {UTXO[]} inputs The UTXOs.
* @param {UTXOs} inputs The UTXOs.
* @param {FeeRate} feeRate The fee rate.

@@ -23,11 +25,18 @@ * @param {Buffer} data The compiled memo (Optional).

*/
export declare const getFee: (inputs: UTXO[], feeRate: FeeRate, data?: Buffer | null) => number;
export declare const getFee: (inputs: UTXOs, feeRate: FeeRate, data?: Buffer | null) => number;
/**
* Get the average value of an array.
*
* @param {number[]} array
* @param {Array<number>} array
* @returns {number} The average value.
*/
export declare const arrayAverage: (array: number[]) => number;
export declare const arrayAverage: (array: Array<number>) => number;
/**
* Check if give network is a testnet.
*
* @param {Network} network
* @returns {boolean} `true` or `false`
*/
export declare const isTestnet: (network: Network) => boolean;
/**
* Get Bitcoin network to be used with bitcoinjs.

@@ -45,3 +54,3 @@ *

* @param {Address} address
* @returns {Balance[]} The balances of the given address.
* @returns {Array<Balance>} The balances of the given address.
*/

@@ -63,5 +72,5 @@ export declare const getBalance: (params: AddressParams) => Promise<Balance[]>;

* @param {Address} address
* @returns {UTXO[]} The UTXOs of the given address.
* @returns {Array<UTXO>} The UTXOs of the given address.
*/
export declare const scanUTXOs: ({ sochainUrl, network, address, confirmedOnly, }: ScanUTXOParam) => Promise<UTXO[]>;
export declare const scanUTXOs: ({ sochainUrl, network, address, confirmedOnly, }: ScanUTXOParam) => Promise<UTXOs>;
/**

@@ -81,3 +90,3 @@ * Build transcation.

psbt: Bitcoin.Psbt;
utxos: UTXO[];
utxos: UTXOs;
}>;

@@ -118,2 +127,2 @@ /**

**/
export declare const getPrefix: (network: Network) => "bc1" | "tb1";
export declare const getPrefix: (network: Network) => "tb1" | "bc1";
{
"name": "@thorwallet/xchain-bitcoin",
"version": "0.0.1-alpha.979+0c7e5d5",
"version": "0.1.0-lazy.0",
"description": "Custom Bitcoin client and utilities used by XChainJS clients",

@@ -28,3 +28,3 @@ "keywords": [

"clean": "rimraf lib/**",
"build": "yarn clean && tsc",
"build": "yarn clean && rollup -c",
"test": "jest",

@@ -36,9 +36,9 @@ "lint": "eslint \"{src,__tests__}/**/*.ts\" --fix --max-warnings 0",

"devDependencies": {
"@thorwallet/xchain-client": "0.0.1-alpha.979+0c7e5d5",
"@thorwallet/xchain-crypto": "0.0.1-alpha.979+0c7e5d5",
"@thorwallet/xchain-util": "0.0.1-alpha.979+0c7e5d5",
"@thorwallet/xchain-client": "0.1.0-lazy.0",
"@thorwallet/xchain-crypto": "0.1.0-lazy.0",
"@thorwallet/xchain-util": "0.1.0-lazy.0",
"@types/bitcoinjs-lib": "^5.0.0",
"@types/wif": "^2.0.2",
"axios": "^0.21.1",
"axios-mock-adapter": "^1.20.0",
"@types/wif": "^2.0.1",
"axios": "^0.21.0",
"axios-mock-adapter": "^1.19.0",
"bitcoinjs-lib": "^5.2.0",

@@ -52,3 +52,3 @@ "coinselect": "^3.1.12",

"@thorwallet/xchain-util": "0.0.1-alpha.869+49db531",
"axios": "^0.21.1",
"axios": "^0.21.0",
"bitcoinjs-lib": "^5.2.0",

@@ -61,3 +61,3 @@ "coinselect": "^3.1.12",

},
"gitHead": "0c7e5d56b9441bcdeda08208a290d9dd46446cd0"
"gitHead": "225d9a291955c53caa553410986334369fda6d22"
}

@@ -45,3 +45,3 @@ # `@xchainjs/xchain-client`

// Create a new client interface
const btcClient = new Client({ network: Network.Mainnet, nodeUrl: 'https://sochain.com/api/v2' })
const btcClient = new Client({ network: 'mainnet', nodeUrl: 'https://sochain.com/api/v2' })

@@ -48,0 +48,0 @@ // Set phrase

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc