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

Feature: Support Multibase/Multicodec #39

Open
jphastings opened this issue Sep 20, 2024 · 0 comments
Open

Feature: Support Multibase/Multicodec #39

jphastings opened this issue Sep 20, 2024 · 0 comments
Labels
feature New feature or request

Comments

@jphastings
Copy link

jphastings commented Sep 20, 2024

Describe your feature or enhancement suggestion

I'd like to be able to encode/decode Multibase and Multicodec strings. (I have included these two methods as one feature request, as I believe they are intricately linked).

Block: Multibase
Input: (text) z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK
Output: (encoding) Base58 Bitcoin (because the leading byte is z, as per the Multibase table)
Output: (bytes) ED 01 2E 6F CC E3 67 01 DC 79 14 88 E0 D0 B1 74 5C C1 E3 3A 4C 1C 9F CC 41 C6 3B D3 43 DB BE 09 70 E6

Block: Multicodec
Input: (bytes) ED 01 2E 6F CC E3 67 01 DC 79 14 88 E0 D0 B1 74 5C C1 E3 3A 4C 1C 9F CC 41 C6 3B D3 43 DB BE 09 70 E6
Output: (represents) Ed25519 public key (because the leading bytes are 0xed, as per the Multicodec spec)
Output: (bytes) 01 2E 6F CC E3 67 01 DC 79 14 88 E0 D0 B1 74 5C C1 E3 3A 4C 1C 9F CC 41 C6 3B D3 43 DB BE 09 70 E6

Block: Multibase
Input: (bytes) ED 01 2E 6F CC E3 67 01 DC 79 14 88 E0 D0 B1 74 5C C1 E3 3A 4C 1C 9F CC 41 C6 3B D3 43 DB BE 09 70 E6
Input: (encoding) Base64 URL, no padding
Output: (text) u7QEub8zjZwHceRSI4NCxdFzB4zpMHJ_MQcY700Pbvglw5g

Block: Multibase
Input: (bytes) ED 01 2E 6F CC E3 67 01 DC 79 14 88 E0 D0 B1 74 5C C1 E3 3A 4C 1C 9F CC 41 C6 3B D3 43 DB BE 09 70 E6
Input: (encoding) z-base-32
Output: (text) h7wy1h56chpuodzd3n1rqbwftqtqcda34joqj9unbaa77go65zarzb3o

Note

This demonstrates that the above z6Mkha…, u7QEub…, and h7wy1h… strings are functionally identical as an Ed25519 public key to any system that can parse Multibase + Multicodec strings.

Describe a concrete use case

Multibase and Multicodec encoding are used increasingly frequently, particularly in distributed computing, as they are self describing in their encodings (making them very future compatible). (They are used for the content addressed IDs of IPFS, the format of the did:key distributed ID method, and many other spaces — Multibase is also an active IETF draft).

I regulary interact with strings that could be Multibase + Multicodec encoded, but find myself having to manually decode them to (a) determine if they're valid/really are Multibase, (b) to extract the "lookup byte" and manually check what the string represents, and/or (c) to re-encode them with a different base. It would be immensely useful if cipher editor allowed me to break apart and rebuild a multicodec with a few clicks!

Implementation

There is an official Multiformat JS library that covers all the encoding/decoding needed: multiformats/js-multiformats

@jphastings jphastings added the feature New feature or request label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant