Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js-multibase is deprecated, says to use js-multiformats, but no docs on how to use it? #262

Open
treeder opened this issue Jul 20, 2023 · 3 comments

Comments

@treeder
Copy link

treeder commented Jul 20, 2023

I just want to decode, but it's not clear how to do it:

const decodedBytes = multibase.decode(bytes)

???

@vmx
Copy link
Member

vmx commented Jul 25, 2023

I've added an example to #47 (comment).

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'))

@treeder
Copy link
Author

treeder commented Jul 25, 2023

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...

@vmx
Copy link
Member

vmx commented Jul 25, 2023

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: #121 (comment) and implemented e.g. at MatrixAI/js-id@17cf2eb.

The idea is that usually an application won't encounter all possible encodings, but you know which ones to expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants