js-multiformats
js-multiformats copied to clipboard
js-multibase is deprecated, says to use js-multiformats, but no docs on how to use it?
I just want to decode, but it's not clear how to do it:
const decodedBytes = multibase.decode(bytes)
???
I've added an example to https://github.com/multiformats/js-multiformats/issues/47#issuecomment-1649873600.
import { bases } from 'multiformats/basics'
// Single known multibase.
console.log(bases.base32.decode('bozwxq'))
// Combine multiple multibases.
const base32or64 = bases.base32.decoder.or(bases.base64url.decoder)
console.log(base32or64.decode('bozwxq'))
console.log(base32or64.decode('udm14'))
Thanks @vmx . Does that mean we have to know what bases are used in advance? Seems like it kind of defeats the whole point of this...
Seems like it kind of defeats the whole point of this...
It's always been some sort of fixed list (also in multibase). The difference is that you now decide which ones you care about. The answer may be "all of them". If that's the case you can also create a lookup table as mentioned in that comment: https://github.com/multiformats/js-multiformats/issues/121#issuecomment-937495215 and implemented e.g. at https://github.com/MatrixAI/js-id/commit/17cf2eb0137a46cd47cfbd70e14b731619086d39.
The idea is that usually an application won't encounter all possible encodings, but you know which ones to expect.