Installations
npm install @bitauth/libauth
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
^12.20.0 || ^14.13.1 || >=16.0.0
Node Version
20.12.1
NPM Version
10.5.0
Releases
Contributors
Languages
TypeScript (82.21%)
JavaScript (17.4%)
Rust (0.25%)
Dockerfile (0.14%)
Developer
Download Statistics
Total Downloads
4,471,943
Last Day
1,022
Last Week
38,305
Last Month
188,581
Last Year
2,756,375
GitHub Statistics
277 Stars
323 Commits
52 Forks
12 Watching
11 Branches
12 Contributors
Package Meta Information
Latest Version
3.0.0
Package Id
@bitauth/libauth@3.0.0
Unpacked Size
4.22 MB
Size
0.98 MB
File Count
340
NPM Version
10.5.0
Node Version
20.12.1
Publised On
10 Apr 2024
Total Downloads
Cumulative downloads
Total Downloads
4,471,943
Last day
-22.9%
1,022
Compared to previous day
Last week
-6.3%
38,305
Compared to previous week
Last month
-24.1%
188,581
Compared to previous month
Last year
141.8%
2,756,375
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
45
An ultra-lightweight JavaScript library for Bitcoin Cash, Bitcoin, and Bitauth applications.
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:
- Flexibility – Even highly-complex functionality is built-up from simpler functions. These lower-level functions can be used to experiment, tweak, and remix your own higher-level methods without maintaining a fork of the library.
- Smaller application bundles – Applications can import only the methods they need, eliminating the unused code (via dead-code elimination).
- Better auditability – Beyond having no dependencies of its own, Libauth's functional programming approach makes auditing critical code easier: smaller bundles, smaller functions, and less churn between versions (fewer cascading changes to object-oriented interfaces).
- Fully-portable – No platform-specific APIs are ever used, so the same code paths are used across all JavaScript environments (reducing the auditable "surface area" and simplifying library development).
Quick Start
To get started, install @bitauth/libauth
:
1npm install @bitauth/libauth 2# OR 3yarn add @bitauth/libauth
And import the functionality you need:
1import { secp256k1 } from '@bitauth/libauth'; 2import { msgHash, pubkey, sig } from 'somewhere'; 3 4secp256k1.verifySignatureDERLowS(sig, pubkey, msgHash) 5 ? console.log('🚀 Signature valid') 6 : 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.
- Installation
- Handling Errors
- Cryptography
- Keys
- Addresses
- Verifying Transactions
- Wallets & Transaction Creation
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
Base58 Addresses
encodeBase58Address
/decodeBase58Address
encodeBase58AddressFormat
/decodeBase58AddressFormat
lockingBytecodeToBase58Address
/base58AddressToLockingBytecode
Bech32
CashAddress
encodeCashAddress
/decodeCashAddress
lockingBytecodeToCashAddress
/cashAddressToLockingBytecode
decodeCashAddressFormatWithoutPrefix
encodeCashAddressVersionByte
/decodeCashAddressVersionByte
CashAddress-like Formats
attemptCashAddressFormatErrorCorrection
encodeCashAddressFormat
/decodeCashAddressFormat
encodeCashAddressNonStandard
/decodeCashAddressNonStandard
Crypto
hash160
(sha256
->ripemd160
)hash256
(sha256
->sha256
)hmacSha256
hmacSha512
instantiateHmacFunction
instantiatePbkdf2Function
pbkdf2HmacSha256
pbkdf2HmacSha512
ripemd160
secp256k1
sha1
sha256
sha512
Formats
Base-N Conversion
Base64
Binary Strings (e.g. 00101010
)
Hex (Hexadecimal-Encoded Strings)
Logging
Numbers
bigIntToBinUint256BEClamped
/binToBigIntUint256BE
bigIntToBinUint64LE
(bigIntToBinUint64LEClamped
)/binToBigIntUint64LE
bigIntToBinUintLE
/binToBigIntUintLE
binToBigIntUintBE
/bigIntToBinUintBE
int32SignedToUnsigned
/int32UnsignedToSigned
numberToBinInt16LE
/binToNumberInt16LE
numberToBinInt32LE
/binToNumberInt32LE
numberToBinInt32TwosCompliment
numberToBinUintLE
/binToNumberUintLE
numberToBinUint16BE
numberToBinUint16LE
(numberToBinUint16LEClamped
)/binToNumberUint16LE
numberToBinUint32BE
numberToBinUint32LE
(numberToBinUint32LEClamped
)/binToNumberUint32LE
CompactUint (A.K.A. "VarInt" or "CompactSize")
compactUintToBigInt
/bigIntToCompactUint
compactUintPrefixToSize
readCompactUint
readCompactUintMinimal
Satoshi Values
VM Numbers (A.K.A. "ScriptNum")
Miscellaneous
Time
UTF8
Keys
BIP32 Hierarchical Deterministic (HD) Keys
crackHdPrivateNodeFromHdPublicNodeAndChildPrivateNode
decodeHdKey
(decodeHdKeyUnchecked
)decodeHdPrivateKey
/encodeHdPrivateKey
decodeHdPublicKey
/encodeHdPrivateKey
deriveHdPath
deriveHdPathRelative
deriveHdPrivateNodeFromSeed
deriveHdPrivateNodeIdentifier
/deriveHdPublicNodeIdentifier
deriveHdPrivateNodeChild
/deriveHdPublicNodeChild
deriveHdPublicKey
deriveHdPublicNode
hdKeyVersionIsPrivateKey
/hdKeyVersionIsPublicKey
hdPrivateKeyToIdentifier
/hdPublicKeyToIdentifier
BIP39 Mnemonic Phrases
deriveHdPrivateNodeFromBip39Mnemonic
deriveSeedFromBip39Mnemonic
encodeBip39Mnemonic
/decodeBip39Mnemonic
generateBip39Mnemonic
Wallet Import Format (WIF)
Key Utilities
generateDeterministicEntropy
generateHdPrivateNode
generatePrivateKey
generateRandomBytes
generateRandomSeed
minimumEventsPerEntropyBits
shannonEntropyPerEvent
validateSecp256k1PrivateKey
P2P Messages
Decoding Utilities
readBytes
readCompactUintPrefixedBin
readRemainingBytes
readUint32LE
readUint64LE
readMultiple
readItemCount
Transactions
encodeTransaction
/decodeTransaction
(decodeTransactionUnsafe
)encodeTransactionOutputs
/decodeTransactionOutputs
hashTransaction
hashTransactionP2pOrder
hashTransactionUiOrder
Outputs
isArbitraryDataOutput
isSimpleMultisig
isStandardOutputBytecode
isStandardOutputBytecode2023
isStandardMultisig
isWitnessProgram
Dust Calculation
Virtual Machines
Built-In VMs
createInstructionSetBCH
createInstructionSetBCH2022
createInstructionSetBCH2023
createInstructionSetBCHCHIPs
createInstructionSetXEC
createVirtualMachine
createVirtualMachineBCH
createVirtualMachineBCH2022
createVirtualMachineBCH2023
createVirtualMachineBCHCHIPs
createVirtualMachineXEC
Debugging
assembleBytecode
assembleBytecodeBCH
assembleBytecodeBTC
disassembleBytecode
disassembleBytecodeBCH
disassembleBytecodeBTC
generateBytecodeMap
summarizeDebugTrace
stringifyDebugTraceSummary
summarizeStack
Combinators
combineOperations
mapOverOperations
pushToStack
pushToStackChecked
pushToStackVmNumber
pushToStackVmNumberChecked
useOneStackItem
useTwoStackItems
useThreeStackItems
useFourStackItems
useSixStackItems
useOneVmNumber
useTwoVmNumbers
useThreeVmNumbers
Wallet Engine
Bitcoin Cash Metadata Registries (BCMRs)
CashAssembly Language & Compiler
allErrorsAreRecoverable
cashAssemblyToBin
compileScript
containsRange
createCompiler
extractBytecodeResolutions
extractEvaluationSamples
extractEvaluationSamplesRecursive
extractUnexecutedRanges
getResolutionErrors
mergeRanges
parseScript
resolveVariableIdentifier
stringifyErrors
verifyCashAssemblyEvaluationState
walletTemplateToCompilerConfiguration
walletTemplateToCompilerBCH
Multi-Party Compilation
P2PKH Utilities
hdPrivateKeyToP2pkhLockingBytecode
hdPrivateKeyToP2pkhCashAddress
hdPublicKeyToP2pkhLockingBytecode
hdPublicKeyToP2pkhCashAddress
privateKeyToP2pkhLockingBytecode
privateKeyToP2pkhCashAddress
publicKeyToP2pkhLockingBytecode
publicKeyToP2pkhCashAddress
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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
project is fuzzed
Details
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/address/base58-address.spec.ts:22
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/address/bech32.spec.ts:16
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/address/bech32.spec.ts:17
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/address/cash-address.spec.ts:36
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/crypto/hash.spec.helper.ts:12
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/crypto/hmac.spec.ts:14
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/crypto/secp256k1.spec.ts:19
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/format/base-convert.spec.ts:18
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/format/bin-string.spec.ts:5
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/format/hex.spec.ts:12
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/format/number.spec.ts:42
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/format/time.spec.ts:16
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/format/utf8.spec.ts:12
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/format/utf8.spec.ts:13
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/key/bip39.spec.ts:42
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/key/hd-key.spec.ts:57
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/key/key-utils.spec.ts:20
- Info: TypeScriptPropertyBasedTesting integration found: src/lib/vm/instruction-sets/common/instruction-sets-utils.spec.ts:29
Reason
binaries present in source code
Details
- Warn: binary detected: src/lib/bin/ripemd160/ripemd160.wasm:1
- Warn: binary detected: src/lib/bin/secp256k1/secp256k1.wasm:1
- Warn: binary detected: src/lib/bin/sha1/sha1.wasm:1
- Warn: binary detected: src/lib/bin/sha256/sha256.wasm:1
- Warn: binary detected: src/lib/bin/sha512/sha512.wasm:1
Reason
SAST tool is not run on all commits -- score normalized to 5
Details
- Warn: 8 commits out of 15 are checked with a SAST tool
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/benchmark.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/benchmark.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/benchmark.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/benchmark.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/doc.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/doc.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/doc.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/doc.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/doc.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/doc.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/doc.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/doc.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/doc.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/doc.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/release.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/bitauth/libauth/release.yml/master?enable=pin
- Info: 0 out of 13 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 2 out of 2 containerImage dependencies pinned
Reason
1 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 3/22 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/release.yml:15
- Info: jobLevel 'issues' permission set to 'read': .github/workflows/release.yml:17
- Warn: jobLevel 'packages' permission set to 'write': .github/workflows/release.yml:18
- Warn: topLevel 'contents' permission set to 'write': .github/workflows/benchmark.yml:8
- Warn: topLevel 'deployments' permission set to 'write': .github/workflows/benchmark.yml:9
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: topLevel 'contents' permission set to 'read': .github/workflows/doc.yml:9
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
24 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: RUSTSEC-2020-0146 / GHSA-3358-4f7f-p4j4
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-8gh8-hqwg-xf34
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-x3m3-4wpv-5vgc
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-584q-6j8j-r5pm
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
Score
4
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More