Installation
April 10, 2024 ยท View on GitHub
Welcome! Libauth is designed to be low-level and lightweight: all functionality is exported as simple functions, so your bundler can eliminate the code you don't use.
Libauth is a pure ESM package, so Node.js v12 or higher is required (or Deno), and using ESM is recommended.
Node.js Usage
To get started, install @bitauth/libauth in your environment:
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');
Web Usage
For web projects, a bundler with dead-code elimination (A.K.A. "tree shaking") is strongly recommended โ Libauth is designed to minimize application code size, and dead-code elimination will improve load performance in nearly all applications.
Consider Vite (recommended), Parcel, Rollup, Webpack, or a bundler designed for your web framework.
Deno Usage
For Deno usage, Libauth can be imported with the npm: protocol:
import { hexToBin } from 'npm:@bitauth/libauth';
console.log(hexToBin('beef'));
Using Typescript Types
Libauth should work with modern TypeScript projects without any configuration.
If you're having trouble, note that Libauth uses BigInt, WebAssembly, and es2017 features for some functionality. To type-check this library in you application (without skipLibCheck), your tsconfig.json will need a minimum target of es2020 or lib must include es2017 and esnext.bigint. If your application is not already importing types for WebAssembly, you may also need to add dom to lib.