JSPM

noble-base58check

0.1.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q51532F
  • License MIT

Noble base58check. Typed, native, 0-dep port of bs58check module.

Package Exports

  • noble-base58check

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (noble-base58check) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

noble-base58check Node CI code style: prettier

Base58Check, a modified Base 58 binary-to-text encoding known as Base58Check is used for encoding Bitcoin addresses. More generically, Base58Check encoding is used for encoding byte arrays in Bitcoin into human-typable strings.

Port of bs58check module.

This library belongs to noble crypto

noble-crypto — high-security, easily auditable set of contained cryptographic libraries and tools.

  • No dependencies, one small file
  • Easily auditable TypeScript/JS code
  • Uses es2020 bigint. Supported in Chrome, Firefox, Safari, node 10+
  • All releases are signed and trusted
  • Check out all libraries: secp256k1, ed25519, bls12-381, ripemd160

Usage

Node:

npm install noble-base58check
import * as b58c from "noble-base58check";
import { strictEqual } from "assert";

const hash = "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i";
(async () => {
  const bytes = await b58c.decode(hash);
  const sameHash = await b58c.encode(bytes);
  strictEqual(sameHash, hash);
})();

Deno:

import * as b58c from "https://deno.land/x/base58check/mod.ts";
import { assertEquals } from "https://deno.land/x/testing/asserts.ts";

const hash = "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i";
const bytes = await b58c.decode(hash);
const sameHash = await b58c.encode(bytes);
assertEquals(sameHash, hash);

Library: https://deno.land/x/base58check

API

decode(string)
function decode(string: string): Promise<Uint8Array>;
  • string: string - string to decode with Base58Check
  • Returns Promise<Uint8Array>: decoded bytes
encode(payload)
function encode(payload: Uint8Array): Promise<string>;
  • payload: Uint8Array - payload to encode with Base58Check
  • Returns Promise<string>: encoded string
decodeUnsafe(string)
function decodeUnsafe(string: string): Promise<Uint8Array | undefined>;
  • string: string - string to decode with Base58Check
  • Returns Promise<Uint8Array | undefined>: Promise<Uint8Array> if success; otherwise Promise<undefined>
decodePlain(string)
function decodePlain(string: string): Promise<Uint8Array>;
  • string: string - string to decode with plain Base58 (without check)
  • Returns Promise<Uint8Array>: decoded bytes
encodePlain(payload)
function encodePlain(payload: Uint8Array): Promise<string>;
  • payload: Uint8Array - payload to encode with plain Base58 (without check)
  • Returns Promise<string>: encoded string
decodePlainUnsafe(string)
function decodePlainUnsafe(string: string): Promise<Uint8Array | undefined>;
  • string: string - string to decode with plain Base58 (without check)
  • Returns Promise<Uint8Array | undefined>: Promise<Uint8Array> if success; otherwise Promise<undefined>
decodeRaw(buffer)
function decodeRaw(buffer: Uint8Array): Promise<Uint8Array | undefined>;
  • buffer: Uint8Array - payload to encode with plain Base58 (without check)
  • Returns Promise<Uint8Array | undefined>: Promise<Uint8Array> payload without last 4 bytes if checksum valid; otherwise Promise<undefined>
getChecksum(buffer)
function getChecksum(buffer: Uint8Array): Promise<Uint8Array>;
  • buffer: Uint8Array - payload
  • Returns Promise<Uint8Array>: checksum (double sha256)

Inspiration

Contributing

  1. Clone the repository.
  2. npm install to install build dependencies like TypeScript
  3. npm run compile to compile TypeScript code
  4. npm run test to run jest on test/index.ts

License

MIT (c) Serhii Pashchenko (https://serh11p.com), see LICENSE file.