Sunday, January 02, 2022

base58 encode/decode: JavaScript, Go, C#

Binary-to-text encoding - Wikipedia

Base58Check encoding - Bitcoin Wiki

Base58 - HandWiki

JavaScript/JS/TS/node.js

bs58 - npm based on base-x - npm

const basex = require('base-x')
// Bitcoin compatible
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
module.exports = basex(ALPHABET)

cryptocoinjs/base-x: Encode/decode any base @GitHub


base58 - npm search

base-x vs base58 vs base62 vs bs58 | npm trends


Crypto | Node.js v18.7.0 Documentation

What is Node crypto.createHash(algorithm, [options])?


GoLang

base58 package - github.com/btcsuite/btcutil/base58 - Go Packages

itchyny/base58-go: Base58 encoding/decoding package and command written in Go

base58-go/base58.go at main · itchyny/base58-go

// FlickrEncoding is the encoding scheme used for Flickr's short URLs.
"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"

// RippleEncoding is the encoding scheme used for Ripple addresses.
"rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"

// BitcoinEncoding is the encoding scheme used for Bitcoin addresses.
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"

DotNet (C#)

Base58 encoding in C# (Used for BitCoin addresses)


import crypto from 'crypto';
import bs58 from 'bs58';

const sha1 = val => crypto.createHash('sha1').update(val); // Hash
const sha256 = val => crypto.createHash('sha256').update(val); // Hash

sha1(val).digest('hex'); // 40 chars.; sha256: 64 chars    
sha1(val).digest('base64'); // 28 chars; sha256: 44 chars; not "url friendly"

const sha1base58 = val => bs58.encode(sha1(val).digest()); // 28 chars, url friendly
const sha256base58 = val => bs58.encode(sha256(val).digest()); // 44 chars, url friendly


No comments: