Saturday, May 01, 2021

short UUID: 36 => 20 chars, or 22 chars with base58 encoding

http://codehardblog.azurewebsites.net/encoding-uuid-based-keys-to-save-memory/

Jeff Atwood's C# implementation of Ascii85 

Ascii85 - Wikipedia

ascii85 - npm

huandu/node-ascii85: Ascii85 (Base85) encoding/decoding module for node.js.

base85 - npm

nE0sIghT/ascii85.js: ASCII85 a.k.a. Base85 implementation in JavaScript


uuid - npm

short-uuid - npm

oculus42/short-uuid: Translate standard UUIDs into shorter formats and back.


'086d7702-9976-4abe-bde7-966333cbb13d'

'bxH8@ORBzte1kon$$@AK'



Ask HN: Who invented Base58 Encoding - Flickr or Bitcoin? | Hacker News


A commonly held view is that Satoshi Nakamoto invented Base58 encoding for Bitcoin: https://en.wikipedia.org/wiki/Base58

However, a Flickr discussion about Base58 encoded URLs exists from April 2009: https://www.flickr.com/groups/api/discuss/72157616713786392/

Did Flickr deploy their Base58 encoded URLs before the Bitcoin white paper was published on Oct 31, 2008?


recode uuid to shorter URL safe string, length: 36 => 22, i.e.
'1496c7cb-b4e4-4c84-954f-3da570e2e281' => '3xsFQ446662SRziHg4g3uZ'

import short from 'short-uuid';
const translator = short(); // defaults to flickrBase58 encoding (like bitcoin)
const shortId = translator.fromUUID(id);


import { v4 as uuidV4 } from 'uuid';
import bs58 from 'bs58';
const uuidBytes = () => uuidV4({}, Buffer.alloc(16)); // generates random uuid as byte array
const uuidHex = () => uuidBytes().toString('hex') // 32 chars; also 'base64', 24 chars
const uuidBase58 = () => bs58.encode(uuidBytes()); // 22 chars









No comments: