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

@thorchain/asgardex-bitcoin

v0.5.0

Published

Custom Bitcoin client and utilities used by ASGARDEX clients

Downloads

64

Readme

@thorchain/asgardex-bitcoin

Implements the following:

interface BitcoinClient {
  generatePhrase(): string
  setPhrase(phrase?: string): void
  validatePhrase(phrase: string): boolean
  purgeClient(): void
  setNetwork(net: Network): void
  getNetwork(net: Network): Bitcoin.networks.Network
  setBaseUrl(endpoint: string): void
  getAddress(): string
  validateAddress(address: string): boolean
  scanUTXOs(): Promise<void>
  getBalance(): number
  getBalanceForAddress(address?: string): Promise<number>
  getTransactions(address: string): Promise<Txs>
  calcFees(memo?: string): Promise<object>
  vaultTx(addressVault: string, valueOut: number, memo: string, feeRate: number): Promise<string>
  normalTx(addressTo: string, valueOut: number, feeRate: number): Promise<string>
}

Modules

Installation

yarn add @thorchain/asgardex-bitcoin

Following dependencies will be installed into your project:

  • bitcoinjs-lib
  • bip39
  • wif
  • moment
  • axios

Testing

Uses a dotenv file to hold a USER_PHRASE and a VAULT_PHRASE

Usage

Initialize client and use class methods:

import { Client, Network } from '../src/client'

const btcClient = new Client(Network.TEST)

const newPhrase = btcClient.generatePhrase()

.generatePhrase()

Generate a 12 word BIP-39 seed phrase.

Return: string

.setPhrase(phrase)

Loads a 12 word BIP-39 seed phrase to use as a BTC send/receive address.

phrase: 12 word BIP-39 seed phrase as string

Return: void

.validatePhrase(phrase)

Validates if provided phrase is BIP-39.

phrase: 12 word BIP-39 seed phrase as string

Return: boolean

.purgeClient()

Clears UTXOs and seed phrase from client class properties.

Return: void

.setNetwork(net)

Set testnet or mainnet network using the Network interface.

net: Network.TEST or Network.MAIN

Return: void

.setBaseUrl(endpoint)

Set an electrs REST API endpoint to use for chain data.

endpoint: endpoint as string

Return: void

.getAddress()

Gets a P2WPKH address using the seed phrase set in .setPhrase() or initialization. If no phrase is set will error.

Return: string

.validateAddress(address)

Validates if provided address is p2wpkh and same network as the client.

address: string

Return: boolean

.scanUTXOs()

Async

Scans the UTXOs on the set seed phrase in .setPhrase() and stores them in class properties.

Return: void

.getBalance()

Get the balance of UTXOs from .scanUTXOs()

Return: number in sats

.getBalanceForAddress(address)

Async

Get the balance of UTXOs for an external address

address: string

Return: number in sats

.getTransactions(address)

Async

Get transactions for an address

address: string

Return: Array of objects

.calcFees(memo)

Async

Calculates the fee rate and the fee total estimate for fast, regular, and slow transactions. Add a memo for a vault TX

memo: string optional

Return: object of objects

.vaultTx(addressVault, valueOut, memo, feeRate)

Async

Generates a valid Vault TX hex to be broadcast

addressVault: string

valueOut: number in sats

memo: string

feeRate: number

.normalTx(addressTo, valueOut, feeRate)

Async

Generates a valid Vault TX hex to be broadcast

addressTo: string

valueOut: number in sats

feeRate: number