{"_id":"micro-base","_rev":"4597292","name":"micro-base","description":"Fast and minimal implementation of bech32, base64, base58, base32 & base16","dist-tags":{"latest":"0.10.2"},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"time":{"modified":"2026-04-10T17:09:42.000Z","created":"2021-10-13T14:05:36.212Z","0.10.2":"2021-12-24T18:12:01.016Z","0.10.1":"2021-12-23T19:25:47.886Z","0.10.0":"2021-12-11T09:50:02.294Z","0.9.0":"2021-10-15T00:31:34.281Z","0.1.0":"2021-10-13T14:05:36.212Z"},"users":{},"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-base.git"},"versions":{"0.10.2":{"name":"micro-base","version":"0.10.2","description":"Fast and minimal implementation of bech32, base64, base58, base32 & base16","main":"index.js","types":"index.d.ts","scripts":{"bench":"node test/benchmark/index.js","build":"tsc -d","lint":"prettier --print-width 100 --single-quote --check index.ts","test":"node test/index.js"},"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","homepage":"https://github.com/paulmillr/micro-base","repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-base.git"},"devDependencies":{"micro-should":"^0.2.0","prettier":"^2.3.2","typescript":"^4.3"},"keywords":["bech32","bech32m","base64","base58","base32","base16","rfc4648","rfc3548","crockford","encode","encoder","base-x","base"],"gitHead":"e5bfe1eeca6aa48fdeac8a301693828c63165847","bugs":{"url":"https://github.com/paulmillr/micro-base/issues"},"_id":"micro-base@0.10.2","_nodeVersion":"16.13.1","_npmVersion":"8.3.0","dist":{"shasum":"f6f9f0bd949ce511883e5a99f9147d80ddc32f5a","size":8190,"noattachment":false,"key":"/micro-base/-/micro-base-0.10.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-base/download/micro-base-0.10.2.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micro-base_0.10.2_1640369520867_0.29631550607003243"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-25T16:24:35.095Z","deprecated":"Switch to @scure/base for audited version of the lib & updates","publish_time":1640369521016,"_cnpm_publish_time":1640369521016},"0.10.1":{"name":"micro-base","version":"0.10.1","description":"Fast and minimal implementation of bech32, base64, base58, base32 & base16","main":"index.js","types":"index.d.ts","scripts":{"bench":"node test/benchmark/index.js","build":"tsc -d","lint":"prettier --print-width 100 --single-quote --check index.ts","test":"node test/index.js"},"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","homepage":"https://github.com/paulmillr/micro-base","repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-base.git"},"devDependencies":{"micro-should":"^0.2.0","prettier":"^2.3.2","typescript":"^4.3"},"keywords":["bech32","bech32m","base64","base58","base32","base16","rfc4648","rfc3548","crockford","encode","encoder","base-x","base"],"gitHead":"9c764a20711fadf1faade8e609310a093032510a","bugs":{"url":"https://github.com/paulmillr/micro-base/issues"},"_id":"micro-base@0.10.1","_nodeVersion":"16.13.1","_npmVersion":"8.3.0","dist":{"shasum":"0d4c0f8d6ede0666e59f51ae18f2ea3bcca5ead9","size":8170,"noattachment":false,"key":"/micro-base/-/micro-base-0.10.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-base/download/micro-base-0.10.1.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micro-base_0.10.1_1640287547720_0.5015563501026765"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-25T16:24:35.005Z","deprecated":"Switch to @scure/base for audited version of the lib & updates","publish_time":1640287547886,"_cnpm_publish_time":1640287547886},"0.10.0":{"name":"micro-base","version":"0.10.0","description":"Fast and minimal implementation of bech32, base64, base58, base32 & base16","main":"index.js","types":"index.d.ts","scripts":{"bench":"node test/benchmark/index.js","build":"tsc -d","lint":"prettier --print-width 100 --single-quote --check index.ts","test":"node test/index.js"},"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","homepage":"https://github.com/paulmillr/micro-base","repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-base.git"},"devDependencies":{"micro-should":"^0.2.0","prettier":"^2.3.2","typescript":"^4.3"},"keywords":["bech32","bech32m","base64","base58","base32","base16","rfc4648","rfc3548","crockford","encode","encoder","base-x","base"],"gitHead":"1cd04073ef187549c124d8448aceba935defcce7","bugs":{"url":"https://github.com/paulmillr/micro-base/issues"},"_id":"micro-base@0.10.0","_nodeVersion":"17.0.1","_npmVersion":"8.1.0","dist":{"shasum":"2a324c7836920b2cbca674f46d0644b7e56e4012","size":8028,"noattachment":false,"key":"/micro-base/-/micro-base-0.10.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-base/download/micro-base-0.10.0.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micro-base_0.10.0_1639216202100_0.8040923371388227"},"_hasShrinkwrap":false,"publish_time":1639216202294,"_cnpm_publish_time":1639216202294,"_cnpmcore_publish_time":"2021-12-16T11:25:18.221Z","deprecated":"Switch to @scure/base for audited version of the lib & updates"},"0.9.0":{"name":"micro-base","version":"0.9.0","description":"Fast and minimal implementation of bech32, base64, base58, base32 & base16","main":"index.js","types":"index.d.ts","scripts":{"bench":"node test/benchmark/index.js","build":"tsc -d","lint":"prettier --print-width 100 --single-quote --check index.ts","test":"node test/index.js"},"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","homepage":"https://github.com/paulmillr/micro-base","repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-base.git"},"devDependencies":{"micro-should":"^0.2.0","prettier":"^2.3.2","typescript":"^4.3"},"keywords":["bech32","bech32m","base64","base58","base32","base16","rfc4648","rfc3548","crockford","encode","encoder","base-x","base"],"gitHead":"9737997edf3215a57e6e1f1d187be9930358161b","bugs":{"url":"https://github.com/paulmillr/micro-base/issues"},"_id":"micro-base@0.9.0","_nodeVersion":"16.11.0","_npmVersion":"8.0.0","dist":{"shasum":"09cfe20285bec0ea97f41dc3d10e3fba3d0266ee","size":6179,"noattachment":false,"key":"/micro-base/-/micro-base-0.9.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-base/download/micro-base-0.9.0.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micro-base_0.9.0_1634257894105_0.2961551363681494"},"_hasShrinkwrap":false,"publish_time":1634257894281,"_cnpm_publish_time":1634257894281,"_cnpmcore_publish_time":"2021-12-16T11:25:18.466Z","deprecated":"Switch to @scure/base for audited version of the lib & updates"},"0.1.0":{"name":"micro-base","version":"0.1.0","description":"Fast and minimal implementation of bech32, base64, base58, base32 & base16","main":"index.js","types":"index.d.ts","scripts":{"bench":"node test/benchmark/index.js","build":"tsc -d","lint":"prettier --print-width 100 --single-quote --check src","test":"node test/index.js"},"author":{"name":"Paul Miller","url":"https://paulmillr.com"},"license":"MIT","homepage":"https://github.com/paulmillr/micro-base","repository":{"type":"git","url":"git+https://github.com/paulmillr/micro-base.git"},"devDependencies":{"micro-should":"^0.2.0","prettier":"^2.3.2","typescript":"^4.3"},"keywords":["bech32","bech32m","base64","base58","base32","base16","rfc4648","rfc3548","crockford","encode","encoder","base-x","base"],"gitHead":"55017569315bdc1d75da10324ccc210a53ed0b83","bugs":{"url":"https://github.com/paulmillr/micro-base/issues"},"_id":"micro-base@0.1.0","_nodeVersion":"16.11.0","_npmVersion":"8.0.0","dist":{"shasum":"33b3bdfcabe8b58a080e60d73442c6cea2b9f1f7","size":5842,"noattachment":false,"key":"/micro-base/-/micro-base-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/micro-base/download/micro-base-0.1.0.tgz"},"_npmUser":{"name":"paulmillr","email":"paul@paulmillr.com"},"directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micro-base_0.1.0_1634133936113_0.14120234980815027"},"_hasShrinkwrap":false,"publish_time":1634133936212,"_cnpm_publish_time":1634133936212,"_cnpmcore_publish_time":"2021-12-16T11:25:18.680Z","deprecated":"Switch to @scure/base for audited version of the lib & updates"}},"readme":"# micro-base\n\nFast and minimal implementation of bech32, base64, base58, base32 & base16.\n\nWritten in [functional style](#design-rationale), uses chaining, has unique tests which ensure correctness.\n\nMatches following specs:\n\n- Bech32, Bech32m: [BIP173](https://en.bitcoin.it/wiki/BIP_0173), [BIP350](https://en.bitcoin.it/wiki/BIP_0350)\n- Base16, Base32, Base32Hex, Base64, Base64Url: [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648) (aka RFC 3548)\n- [Base58](https://www.ietf.org/archive/id/draft-msporny-base58-03.txt), [Base58check](https://en.bitcoin.it/wiki/Base58Check_encoding), [Base32 Crockford](https://www.crockford.com/base32.html)\n\n## Usage\n\n> npm install micro-base\n\n```js\nconst {base16, base32, base64, base58} = require('micro-base');\n// Flavors\nconst {base58xmr, base58xrp, base32hex, base32crockford, base64url} = require('micro-base');\n\nconst data = Uint8Array.from([1, 2, 3]);\nbase64.decode(base64.encode(data));\n\n// Everything has the same API except for bech32 and base58check\nbase32.encode(data);\nbase16.encode(data);\nbase32hex.encode(data);\n\n// bech32\nconst {bech32, bech32m} = require('micro-base');\nconst words = bech32.toWords(data);\nconst be = bech32.encode('prefix', words);\nconst {prefix, words} = bech32.decode(be);\nbech32m.encode('prefix', words);\n\n// base58check is special-case\n// you need to pass sha256() function that returns Uint8Array\nconst {base58check} = require('micro-base');\nbase58check(sha256).encode(data);\n\n// Alternative API\nconst {str, bytes} = require('micro-base');\nconst encoded = str('base64', data);\nconst data = bytes('base64', encoded);\n```\n\n## Design rationale\n\nThe code may feel unnecessarily complicated; but actually it's much easier to reason about.\nAny encoding library consists of two functions:\n\n```\nencode(A) -> B\ndecode(B) -> A\n  where X = decode(encode(X))\n  # encode(decode(X)) can be !== X!\n  # because decoding can normalize input\n\ne.g.\nbase58checksum = {\n  encode(): {\n    // checksum\n    // radix conversion\n    // alphabet\n  },\n  decode(): {\n    // alphabet\n    // radix conversion\n    // checksum\n  }\n}\n```\n\nBut instead of creating two big functions for each specific case,\nwe create them from tiny composamble building blocks:\n\n```\nbase58checksum = chain(checksum(), radix(), alphabet())\n```\n\nWhich is the same as chain/pipe/sequence function in Functional Programming,\nbut significantly more useful since it enforces same order of execution of encode/decode.\nBasically you only define encode (in declarative way) and get correct decode for free.\nSo, instead of reasoning about two big functions you need only reason about primitives and encode chain.\nThe design revealed obvious bug in older version of the lib,\nwhere xmr version of base58 had errors in decode's block processing.\n\nBesides base-encodings, we can reuse the same approach with any encode/decode function\n(`bytes2number`, `bytes2u32`, etc).\nFor example, you can easily encode entropy to mnemonic (BIP-39):\n\n```ts\nexport function getCoder(wordlist: string[]) {\n  if (!Array.isArray(wordlist) || wordlist.length !== 2 ** 11 || typeof wordlist[0] !== 'string') {\n    throw new Error('Worlist: expected array of 2048 strings');\n  }\n  return mbc.chain(mbu.checksum(1, checksum), mbu.radix2(11, true), mbu.alphabet(wordlist));\n}\n```\n\n## base58 is O(n^2) and radixes\n\n`Uint8Array` is represented as big-endian number:\n\n```\n[1, 2, 3, 4, 5] -> 1*(256**4) + 2*(256**3) 3*(256**2) + 4*(256**1) + 5*(256**0)\nwhere 256 = 2**8 (8 bits per byte)\n```\n\nwhich is then converted to a number in another radix/base (16/32/58/64, etc).\n\nHowever, generic conversion between bases has [quadratic O(n^2) time complexity](https://cs.stackexchange.com/q/21799).\n\nWhich means base58 has quadratic time complexity too. Use base58 only when you have small\nconstant sized input, because variable length sized input from user can cause DoS.\n\nOn the other hand, if both bases are power of same number (like `2**8 <-> 2**64`),\nthere is linear algorithm. For now we have implementation for power-of-two bases only (radix2).\n\n## License\n\nMIT (c) Paul Miller [(https://paulmillr.com)](https://paulmillr.com), see LICENSE file.\n","_attachments":{},"homepage":"https://github.com/paulmillr/micro-base","bugs":{"url":"https://github.com/paulmillr/micro-base/issues"},"license":"MIT"}