npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@makkii/app-btc

v0.1.2

Published

Bitcoin-like application client implemented makkii-core.

Downloads

8

Readme

@makkii/app-btc

Bitcoin-like(such as Bitcoin, Litecoin, etc) application client:

  • Support Legacy address, prefix with 1
  • Support both mainnet and testnet
  • BIP39 Path m/49'/coinType'/0'/0/index For example, bitcoin's 1st account: m/49'/0'/0'/0/1
  • Support get account from WIF private key

This library uses some services:

Installation

$ npm install @makkii/app-btc

Usage

import {BtcApiClient, BtcKeystoreClient, BtcLocalSigner} from '@makkii/app-btc'

const api_client = new BtcApiClient({ network: 'BTC', insight_api: '***' });
api_client.getBalance('1ADeU4oeRSCTPn8GpZ2g6RXwDKsCuSjSbQ')
    .then(console.log)
    .catch(error=>console.log(error));

const keystore_client = new BtcKeystoreClient('BTC');
api_client.buildTransaction(
    '1ADeU4oeRSCTPn8GpZ2g6RXwDKsCuSjSbQ', // from address
    '147SwRQdpCfj5p8PnfsXV2SsVVpVcz3aPq', // to address
    0, // amount
    {
        byte_fee: 10,
    }
).then(function(unsignedTx) {
    keystore_client.signTransaction(unsignedTx, new BtcLocalSigner(), {
        private_key: '***'
    }).then(function(signedTx) {
        console.log(signedTx);
    });
});

API

Table of Contents

BtcLocalSigner

Parameters

  • network

signTransaction

Sign transaction of btc local signer

Parameters

Returns string btc signed tx

BtcKeystoreClient

Parameters

  • network ("BTC" | "BTCTEST" | "LTC" | "LTCTEST")

ledgerSupport

only btc btcTest support ledger

getCurrentNetwork

Get current network

Returns string network

checkLedgerSupport

Check ledger support

Returns boolean if support ledger

signTransaction

Sign transaction by signer

Parameters
  • tx BtcUnsignedTx
  • signer T localSigner or hardware
  • signerParam any localSigner: {private_key, compressed} hardware:{derivationIndex}
  • unsignedTx unsigned transaction build by buildTransaction

Returns Promise<string> encoded transaction

generateMnemonic

Generate mnemonic by bip39

Returns string 12 length of mnemonic

recoverKeyPairByPrivateKey

Recover key pair by private key

Parameters
  • priKey string
  • options any? compressed boolean whether to compress public key

Returns Promise<BtcKeypair>

recoverKeyPairByWIF

Recover key pair by wif

Parameters

Returns Promise<BtcKeypair>

validatePrivateKey

Validate private key

not implemented

Parameters

validateAddress

Validate address

Parameters

Returns boolean

getAccountFromMnemonic

Get account from mnemonic

Parameters

Returns Promise<BtcKeypair>

getAccountFromHardware

Get account from hardware

Parameters
  • index number derivation index
  • hardware IHardware

IBtcConfig

network

Network name

Type: ("BTC" | "BTCTEST" | "LTC" | "LTCTEST")

insight_api

bitcoin reset api: https://github.com/bitpay/insight-api/tree/v0.4.3

Type: string

broadcast

bitcoin broadcasst tx api

Type: string

explorer

bitcoin explorer url to show tx detail

Type: string

BtcUnsignedTx

BTC unsigned transaction.

  • to: Array<{ addr: string; value: number }>;
  • from: Array<{ addr: string; value: number }>;
  • value: BigNumber;
  • utxos: Array<{ hash: string; index: number; script: string; raw: string; amount: number; }>;
  • change_address: string;
  • to_address: string;
  • byte_fee: number;
  • network: string;

BtcApiClient

BTC api client that implement IsingleApiClient

Parameters

config

Config of btc api client

Type: IBtcConfig

getNetwork

Get network of btc api client

Returns string network

updateConfiguration

Update configuration of btc api client

Parameters

getBlockByNumber

Get block by number

not implemented

Parameters

getBlockNumber

Get current Block height

not implemented

getTransactionStatus

Get transaction status by tx id

Parameters

Returns Promise<BtcTxStatus> transaction status

getTransactionExplorerUrl

Get an explorer url showing transaction details

Parameters

Returns string url

getBalance

Get an account's balance

Parameters

Returns Promise<BigNumber> balance

getTransactionsByAddress

Get transactions by address

Parameters

Returns Promise<Map<string, BtcTransaction>>

sendTransaction

Send transaction

Parameters
  • unsignedTx BtcUnsignedTx unsigned transaction build by buildTransaction
  • signer T localSigner or hardware
  • signerParams any localSigner: {private_key, compressed} hardware:{derivationIndex}

Returns Promise<BtcPendingTransaction>

sameAddress

check if two address is same

Parameters

Returns boolean

sendAll

try to estimate send one address all balance

Parameters

Returns Promise<number> one address all balance after minus fee

buildTransaction

Build transaction

Parameters

Returns Promise<BtcUnsignedTx>

BtcTxStatus

BTC transaction status

  • status: boolean;
  • blockNumber?: number;
  • timestamp?: number;

BtcTransaction

BTC transaction

  • hash: string;
  • timestamp: number;
  • blockNUmber: number;
  • status: "CONFIRMED";
  • from: Array<{ addr: string; value: number; }>;
  • to: Array<{ addr: string; value: number; }>;
  • fee: number;

BtcPendingTransaction

BTC pending transaction.

  • hash: string;
  • status: "PENDING";
  • from: Array<{ addr: string; value: number; }>;
  • to: Array<{ addr: string; value: number; }>;
  • fee: number;

BtcKeypair

BTC key pair.

  • private_key: string;
  • public_key: string;
  • address: string;
  • index?: number;
  • compressed?: boolean;
  • sign?: (hash: any) => Buffer;
  • toWIF?: () => string;