Fast & minimal implementation of bech32, base64, base32, base16 & base58

Overview

micro-base

Fast and minimal implementation of bech32, base64, base58, base32 & base16.

Matches following specs:

Usage

npm install micro-base

const {base16, base32, base64, base58} = require('micro-base');
// Flavors
const {base58xmr, base58xrp, base32hex, base32crockford, base64url} = require('micro-base');

const data = Uint8Array.from([1, 2, 3]);
base64.decode(base64.encode(data));

// Everything has the same API except for bech32 and base58check
base32.encode(data);
base16.encode(data);
base32hex.encode(data);

// bech32
const {bech32, bech32m} = require('micro-base');
const words = bech32.toWords(data);
const be = bech32.encode('prefix', words);
const {prefix, words} = bech32.decode(be);
bech32m.encode('prefix', words);

// base58check is special-case
// you need to pass sha256() function that returns Uint8Array
const {base58check} = require('micro-base');
base58check(sha256).encode(data);

// Alternative API
const {str, bytes} = require('micro-base');
const encoded = str('base64', data);
const data = bytes('base64', encoded);

License

MIT (c) Paul Miller (https://paulmillr.com), see LICENSE file.

You might also like...

A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh

A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh

three-bvh-csg An experimental, in progress, flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh. More than 100 time

Jan 5, 2023

A quotaless, partially limitless, and fast Node.js Multiplayer Piano server implementation that efficiently makes use of the protocol and uWebSockets.js

speedymppserver A quotaless, partially limitless, and fast Node.js Multiplayer Piano server implementation that efficiently makes use of the protocol

Oct 14, 2022

Quickly create an interactive HTML mock-up by auto sourcing lorem ipsum/images generators, with minimal html markup, and no server side code

RoughDraft.js v0.1.5 Quickly mockup / prototype HTML pages with auto-generated content, without additional JavaScript or server side code. section

Dec 21, 2022

A minimal norui portfolio example built with NextJS and powered by Notion ๐Ÿš€.

A minimal norui portfolio example built with NextJS and powered by Notion ๐Ÿš€.

Minimal Norui A minimal norui portfolio example built with NextJS and powered by Notion ๐Ÿš€ . Links Demo Site Documentation Minimal Norui Notion Databa

Nov 13, 2022

Minimal Phaser3 + Create React App template

Minimal Phaser3 + Create React App template

Phaser 3 + Create React App template This project was bootstrapped with Create React App. What's included? - Check the preview Phaser 3 - overlaid can

Dec 26, 2022

Minimal template engine with compiled output for JavaScript.

@fnando/seagull Minimal template engine with compiled output for JavaScript. Installation This package is available as a NPM package. To install it, u

Mar 1, 2022

Minimal Typescript / NextJS dApp template bootstrapped with wagmi Ethereum react hooks library.

Welcome to the NextJS wagmi starter template ๐Ÿ‘‹ Looking to get up and running with a Typescript / NextJS dApp as quickly as possible? You're in the ri

Jan 4, 2023

Absolutely minimal view layer for building web interfaces.

Superfine Superfine is a minimal view layer for building web interfaces. Think Hyperapp without the frameworkโ€”no state machines, effects, or subscript

Dec 29, 2022

Verbosely Documented, Minimal Starknet Contract Examples.

cairo-by-example โ€ข Verbosely Documented, Minimal Starknet Contract Examples. Cairo By Example deployed to https://cairo-by-example.xyz Developing Clon

Dec 6, 2022
Comments
  • Publish to deno.land/x

    Publish to deno.land/x

    I would be great if this could be published to deno.land/x. For my specific usages of @scure/base in the libs I do publish, we currently point to esm.sh/@scure/[email protected] so it certainly would help my little corner of the world.

    Normally I would make a PR to add mod.ts with a simple export * from './index.ts' however since there are webhook setup in the repo as well, it is best left as an issue since the single file PR doesn't add that much value to the overall process.

    opened by jacogr 2
  • Add deno mod.ts with deno execution test

    Add deno mod.ts with deno execution test

    This PR adds -

    1. The root mod.ts as per https://github.com/paulmillr/scure-base/issues/8
    2. A Deno test test/deno.ts that consumes mod.ts (some basic tests repeated)
    3. A new target for deno:test in package.json to execute 2 above

    It does not repeat all the tests that are there, but rather just ensures that the actual imports from mod.ts works and it functional.

    opened by jacogr 0
  • Add TS types field to exports map

    Add TS types field to exports map

    This PR add the "types" field to the export map for TS usage. This should also fix the skypack build - in the same vein as similar PRs in noble-{ed25519, hashes, secp256k1}

    Sorry about the flood of small PRs to the relevant repos, I just looked into all the packages that I do use in my travels.

    opened by jacogr 0
  • Optional Padding

    Optional Padding

    RFC4648 states:

    In some circumstances, the use of padding ("=") in base-encoded data is not required or used.

    An example of a specification that prohibits padding characters is RFC8555:

    ... the base64url alphabet and MUST NOT include base64 padding characters ("=").

    Therefore, it would be nice if the encoding/decoding functions provided an option to omit padding characters.

    opened by cinolt 0
Releases(1.1.1)
Owner
Paul Miller
Paul Miller
base64 decoder and encoder for nextjs ๐ŸŽ‰

next-base64 next-base64 is a library for client-side and server-side base64 encoding and decoding Installation # Using npm npm install --save next-bas

Yony Calsin 5 Sep 11, 2022
Makes Base64 en & -decoding simpler as it is.

jQuery.base64.js (feel free to write a bit about it) You can check for btoa and atob support and refer to jQuery.base64 if (!window.btoa) window.btoa

Yannick Albert 120 Sep 23, 2022
Gatsby-starter-minimal-blog - Typography driven, feature-rich blogging theme with minimal aesthetics.

Gatsby-starter-minimal-blog - Typography driven, feature-rich blogging theme with minimal aesthetics. Includes tags/categories support and extensive features for code blocks such as live preview, line numbers, and line highlighting.

Priya Chakraborty 0 Jan 29, 2022
Audited & minimal implementation of BIP39 mnemonic phrases

scure-bip39 Secure, audited & minimal implementation of BIP39 mnemonic phrases. Developed for js-ethereum-cryptography. Check out scure-bip32 if you n

Paul Miller 47 Dec 25, 2022
Minimal web3 implementation: call eth contracts directly from JS

micro-web3 Minimal web3 implementation: call eth contracts directly from JS Connect to any web3 server: host your own with execution layer client, or

Paul Miller 46 Dec 29, 2022
Minimal implementation of SLIP-0010 hierarchical deterministic (HD) wallets

micro-ed25519-hdkey Secure, minimal implementation of SLIP-0010 hierarchical deterministic (HD) wallets. Uses audited @noble/ed25519 under the hood. B

Paul Miller 11 Dec 25, 2022
Fast and minimal JS server-side writer and client-side manager.

unihead Fast and minimal JS <head> server-side writer and client-side manager. Nearly every SSR framework out there relies on server-side components t

Jonas Galvez 24 Sep 4, 2022
A minimal routing library designed to sit on top of Bun's fast HTTP server.

siopao A minimal routing library designed to sit on top of Bun's fast HTTP server. Based on Radix Tree. Sio=Hot Pao=Bun Installation bun add siopao Us

Robert Soriano 69 Nov 8, 2022
A fast simplex noise implementation in Javascript.

simplex-noise.js API Documentation simplex-noise.js is a simplex noise implementation in Javascript/TypeScript. It works in the browser and nodejs. Us

Jonas Wagner 1.2k Jan 2, 2023
A RESP 'Redis Serialization Protocol' library implementation to generate a server, uses a similar approach to express to define you serer, making it easy and fast.

RESPRESS A RESP 'Redis Serialization Protocol' library implementation to generate a server, uses a similar approach to express to define you serer, ma

Yousef Wadi 9 Aug 29, 2022