v0.1.4
Noble base58check. Typed, native, 0-dep port of bs58check module.
Repository
Current version released
4 years ago
Dependencies
denopkg.com
Versions
noble-base58check
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)
encode(payload)
decodeUnsafe(string)
encodePlain(payload)
decodePlain(string)
decodePlainUnsafe(string)
decodeRaw(buffer)
getChecksum(buffer)
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; otherwisePromise<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; otherwisePromise<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; otherwisePromise<undefined>
getChecksum(buffer)
function getChecksum(buffer: Uint8Array): Promise<Uint8Array>;
buffer: Uint8Array
- payload- Returns
Promise<Uint8Array>
: checksum (double sha256)
Inspiration
Contributing
- Clone the repository.
npm install
to install build dependencies like TypeScriptnpm run compile
to compile TypeScript codenpm run test
to run jest ontest/index.ts
License
MIT (c) Serhii Pashchenko (https://serh11p.com), see LICENSE file.