bitauth / libauth

An ultra-lightweight, zero-dependency TypeScript library for Bitcoin Cash, Bitcoin, and Bitauth applications.
https://libauth.org
MIT License
274 stars 53 forks source link
authentication bch bitcoin bitcoin-cash bsv btc ecash javascript ripemd160 secp256k1 sha256 sha512 typescript webassembly xec

Libauth logo

An ultra-lightweight JavaScript library for Bitcoin Cash, Bitcoin, and Bitauth applications.

Docs: Getting Started →

API Reference

NPM version Codecov CI Follow Libauth on Twitter Join Chat on Telegram npm downloads GitHub stars

Libauth

An ultra-lightweight JavaScript library for Bitcoin Cash, Bitcoin, and Bitauth applications.

Libauth has no dependencies and works in all JavaScript environments, including Node.js, Deno, and browsers.

Purpose

Libauth is designed to be flexible, lightweight, and easily auditable. Rather than providing a single, overarching, object-oriented API, all functionality is composed from simple functions. This has several benefits:

Quick Start

To get started, install @bitauth/libauth:

npm install @bitauth/libauth
# OR
yarn add @bitauth/libauth

And import the functionality you need:

import { secp256k1 } from '@bitauth/libauth';
import { msgHash, pubkey, sig } from 'somewhere';

secp256k1.verifySignatureDERLowS(sig, pubkey, msgHash)
  ? console.log('🚀 Signature valid')
  : console.log('❌ Signature invalid');

See Installation for more guidance on getting set up.

Guides

These guides introduce some of the high-level concepts and functionality provided by Libauth.

More Examples

In addition to the usage examples in these guides, note that Libauth includes comprehensive tests that can help demonstrate usage of all functionality.

For example, utilities related to hexadecimal-encoded strings are defined in hex.ts; for thorough usage examples, see the co-located hex.spec.ts. You can also use GitHub search to see how a particular utility is used throughout the library, e.g. splitEvery.

API Overview

Below is a partial selection of functionality provided by Libauth. If you're looking for something else, be sure to search the API Reference.

High-level utilities are composed from lower-level utilities which are also exported, so it's often possible to remix behavior in your own codebase with relatively little duplication or maintenance burden. See the Defined in ... link on each utility's API reference page to review and copy the implementation.

Table of Contents - [Address Formats](#address-formats) - [Base58 Addresses](#base58-addresses) - [Bech32](#bech32) - [CashAddress](#cashaddress) - [CashAddress-like Formats](#cashaddress-like-formats) - [Crypto](#crypto) - [Formats](#formats) - [Base-N Conversion](#base-n-conversion) - [Base64](#base64) - [Binary Strings (e.g. `00101010`)](#binary-strings-eg-00101010) - [Hex (Hexadecimal-Encoded Strings)](#hex-hexadecimal-encoded-strings) - [Logging](#logging) - [Numbers](#numbers) - [CompactUint (A.K.A. "VarInt" or "CompactSize")](#compactuint-aka-varint-or-compactsize) - [Satoshi Values](#satoshi-values) - [VM Numbers (A.K.A. "ScriptNum")](#vm-numbers-aka-scriptnum) - [Miscellaneous](#miscellaneous) - [Time](#time) - [UTF8](#utf8) - [Keys](#keys) - [BIP32 Hierarchical Deterministic (HD) Keys](#bip32-hierarchical-deterministic-hd-keys) - [BIP39 Mnemonic Phrases](#bip39-mnemonic-phrases) - [Wallet Import Format (WIF)](#wallet-import-format-wif) - [Key Utilities](#key-utilities) - [P2P Messages](#p2p-messages) - [Decoding Utilities](#decoding-utilities) - [Transactions](#transactions) - [Outputs](#outputs) - [Dust Calculation](#dust-calculation) - [Virtual Machines](#virtual-machines) - [Built-In VMs](#built-in-vms) - [Debugging](#debugging) - [Combinators](#combinators) - [Wallet Engine](#wallet-engine) - [Bitcoin Cash Metadata Registries (BCMRs)](#bitcoin-cash-metadata-registries-bcmrs) - [CashAssembly Language \& Compiler](#cashassembly-language--compiler) - [Multi-Party Compilation](#multi-party-compilation) - [Wallet Templates](#wallet-templates)

Address Formats

Base58 Addresses

Bech32

CashAddress

CashAddress-like Formats

Crypto

Formats

Base-N Conversion

Base64

Binary Strings (e.g. 00101010)

Hex (Hexadecimal-Encoded Strings)

Logging

Numbers

CompactUint (A.K.A. "VarInt" or "CompactSize")
Satoshi Values
VM Numbers (A.K.A. "ScriptNum")

Miscellaneous

Time

UTF8

Keys

BIP32 Hierarchical Deterministic (HD) Keys

BIP39 Mnemonic Phrases

Wallet Import Format (WIF)

Key Utilities

P2P Messages

Decoding Utilities

Transactions

Outputs

Dust Calculation

Virtual Machines

Built-In VMs

Debugging

Combinators

Wallet Engine

Bitcoin Cash Metadata Registries (BCMRs)

CashAssembly Language & Compiler

Multi-Party Compilation

P2PKH Utilities

Wallet Templates

VMB Tests

Libauth's test suite includes a set of cross-implementation Virtual Machine Bytecode (VMB) test vectors for each supported VM. See Libauth VMB Tests for details.

CashAssembly

CashAssembly is the assembly language used by Libauth's Wallet Templates. To learn more about CashAssembly, read the Bitauth IDE Guide.

Contributing

Pull Requests welcome! Please see CONTRIBUTING.md for details.