4.0.0 • Published 2 years ago

base-x v4.0.0

Weekly downloads
338,301
License
MIT
Repository
github
Last release
2 years ago

base-x

NPM Package Build Status

js-standard-style

Fast base encoding / decoding of any given alphabet using bitcoin style leading zero compression.

WARNING: This module is NOT RFC3548 compliant, it cannot be used for base16 (hex), base32, or base64 encoding in a standards compliant manner.

Example

Base58

var BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
var bs58 = require('base-x')(BASE58)

var decoded = bs58.decode('5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr')

console.log(decoded)
// => Uint8Array(33) [
//   128, 237, 219, 220,  17, 104, 241, 218,
//   234, 219, 211, 228,  76,  30,  63, 143,
//    90,  40,  76,  32,  41, 247, 138, 210,
//   106, 249, 133, 131, 164, 153, 222,  91,
//    25
// ]

console.log(bs58.encode(decoded))
// => 5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr

Alphabets

See below for a list of commonly recognized alphabets, and their respective base.

BaseAlphabet
201
801234567
110123456789a
160123456789abcdef
320123456789ABCDEFGHJKMNPQRSTVWXYZ
32ybndrfg8ejkmcpqxot1uwisza345h769 (z-base-32)
360123456789abcdefghijklmnopqrstuvwxyz
58123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
620123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
64ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
67ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~

How it works

It encodes octet arrays by doing long divisions on all significant digits in the array, creating a representation of that number in the new base. Then for every leading zero in the input (not significant as a number) it will encode as a single leader character. This is the first in the alphabet and will decode as 8 bits. The other characters depend upon the base. For example, a base58 alphabet packs roughly 5.858 bits per character.

This means the encoded string 000f (using a base16, 0-f alphabet) will actually decode to 4 bytes unlike a canonical hex encoding which uniformly packs 4 bits into each character.

While unusual, this does mean that no padding is required and it works for bases like 43.

LICENSE MIT

A direct derivation of the base58 implementation from bitcoin/bitcoin, generalized for variable length alphabets.

@dxos/client@fintom/utilcrypto-codec@kadr/staticsecux-connect@bitexchange-ltd/bitexchange-server-7.5.0-beta.3dgiot_amis@pioul/multicoin-address-validatorgeoportal-server1ledgerjs-hw-app-ergoontology-dapi-test@liteflow/apivischainviscoin@everything-registry/sub-chunk-1216keidgourmet-buildergix-gix-polar-sharedgix-polar-sharedgnome-wallet-address-validatorgraphql-tower-global-idgraphql-tower-uniguegraphql-tower-uniquegroestlcoin-address-validationksw-address-codeclacchain-identitylacchain-trustlaccpass-chain-of-trustjw58kafirchain-tetriskadrelacpass-chain-of-trustlacpass-identitylamassu-configslf-ui-kitledger-ergo-jsledgerd-address-codeclumo-utilslemo-utilsleylines-serverlunes-address-validatorluragraphql-shortcakehardhat-teaplughardhat-teaxyzhdaddressgeneratorhd-addresshexo-enhancerhexo-enhancer-for-diaryhive-multisig-sdkhqsl-tshrdc-address-codechwa-ripple-address-codecinutilp-kit-cliid22iso-basejcc_jingtum_base_libjingtum-base-lib-guomijingtum-base-libjson-cipher-urlip-address-from-santziurenihilicryptorimg.bi-servermanyfacedcoinmeeseeks-climixbee-ts-sdkmnidmesg-jsmksuidmolestiaeidnatusadnbv-ur-codecnest-tinyurlneka-wallet-address-validatormulticoin-address-validator-rnmulticoin-address-validatormulticoin-address-validator-tsmulticoin-address-validator-xnextjs-apollonkn-sdknkn-walletnano-uuidnara-address-codecmustard3neotracker-shared-webng-rt-digitalasset-sdk-samplenetworking-by-santzmulti-apinidavellirnode-identifiernisiaspernatur@reef-defi/util-crypto@retrip/js@santz/dashboard@santz112/dashboard@samwen/base62-shax@samwen/base62-util@samwen/cloud-utils
4.0.0

2 years ago

3.0.9

3 years ago

3.0.8

4 years ago

3.0.7

5 years ago

3.0.6

5 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

7 years ago

3.0.2

7 years ago

2.0.6

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago