-
Notifications
You must be signed in to change notification settings - Fork 74
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
Fixed typo in test vectors, clarified proquint and identity, added links to specs. #85
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
246742f
Fix incorrect test bytestring in case_insensitivity.csv
sg495 faf8272
Clarified pro-quints RFC, added RFC notes to table.
sg495 dd8f0f5
Update README.md
sg495 bf71203
Update Base2.md
sg495 b2cec76
Added links to specs, created an explicit identity spec for clarifica…
sg495 3a414e6
Update README.md
sg495 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
# PRO-QUINT | ||
|
||
See: https://arxiv.org/html/0901.4016 ([/ipfs/bafybeib5jsyi5igjwhi7hzkfebpvnq2ykbwpxeaaxlkyfyxqvcecoao4qa](https://dweb.link/ipfs/bafybeib5jsyi5igjwhi7hzkfebpvnq2ykbwpxeaaxlkyfyxqvcecoao4qa)). | ||
For the original proquint specification, see: https://arxiv.org/html/0901.4016 ([/ipfs/bafybeib5jsyi5igjwhi7hzkfebpvnq2ykbwpxeaaxlkyfyxqvcecoao4qa](https://dweb.link/ipfs/bafybeib5jsyi5igjwhi7hzkfebpvnq2ykbwpxeaaxlkyfyxqvcecoao4qa)). | ||
|
||
While the multibase prefix is `p`, the "full" prefix is actually `pro-`. This way, proquints are always easily pronouncable. For example | ||
The multibase prefix for proquints is the character `p`. The base encoded data is the encoded data according to the original specification, with an additional `ro-` prefix: | ||
|
||
`127.0.0.1`, as a multibase proquint encoded number, is `pro-lusab-babad`. | ||
``` | ||
<multibase-prefix-character><additional-prefix-characters><proquint-encoded-data> | ||
``` | ||
|
||
The resulting full prefix for the actual proquint encoded data is `pro-`, making multibase-encoded proquints easily pronouncable. | ||
For example, the proquint encoding of the bytestring `[127, 0, 0, 1]` (the data for the IPv4 address `127.0.0.1`) is `lusab-babad`, so the corresponding multibase-encoded proquint bytestring is: | ||
|
||
``` | ||
pro-lusab-babad | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Identity | ||
|
||
The multibase identity prefix is the character non-printable ASCII/UTF-8 character with codepoint 0x00. Note that this is different from the multibase prefix 0 listed for base2, which is the ASCII/UTF-8 character "0" with codepoint 0x30. | ||
|
||
|
||
## Encoding | ||
|
||
A byte array `b` is encoded by converting it to the Unicode string `s` having as its UTF-8 bytes the byte array `b` prefixed with a single zero byte. | ||
|
||
Below is a minimal implementation in Python, for clarification: | ||
|
||
```py | ||
def encode_identity(b: bytes) -> str: | ||
utf8_bytes = b"\x00"+b | ||
return utf8_bytes.decode("utf-8") | ||
``` | ||
|
||
## Decoding | ||
|
||
A Unicode string `s` is decoded by obtaining its UTF-8 bytes and dropping the leading byte. The UTF-8 byte array must be non-empty and the leading byte must be zero. | ||
|
||
Below is a minimal implementation in Python, for clarification: | ||
|
||
```py | ||
def decode_identity(s: str) -> bytes: | ||
utf8_bytes = s.encode("utf-8") | ||
if not utf8_bytes or utf8_bytes[0] != 0: | ||
raise ValueError("String not identity-encoded.") | ||
return utf8_bytes[1:] | ||
``` | ||
|
||
## Examples | ||
|
||
```py | ||
>>> encode_identity(bytes([0x31, 0x63, 0x57])) | ||
'\x001cW' | ||
>>> decode_identity("\x001cW") | ||
b'1cW' | ||
>>> list(decode_identity("\x001cW")) | ||
[49, 99, 87] # [0x31, 0x63, 0x57] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work with invalid utf8, unfortunately.
Really, 0x00 (or NUL) isn't a true multibase, that's why it's so hard to describe. It exists to distinghish between text and binary in a context where 0x0 means "everything following is binary".
Really, the right way to do this would be to use a raw/utf8/ascii/etc. multicodec to specify the encoding of the "following" data. E.g.:
0x55 ...
- binary.0xXX ...
- utf8 where XX is some marker byte. Unfortunately, the BOM (0xFEFF) isn't a valid varint, so we'd probably need to pick another.All this is saying... I'd rather just drop it entirely. I don't think we're actually using it anywhere (for real, at least).
Thoughts @vmx?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to remove the identity Multibase in case there are no objections. I think in the realm of Multibase it doesn't really makes sense as it is really about string encoding things.
Though things are sadly a bit complicated. Technically the identity Multibase is used in every DAG-CBOR encoded CID. The reason is that CID is specified with the Multibased prefix being part of the actual CID: https://github.com/multiformats/cid/tree/97ff4a329f04b70c1ab7255c62af48192146b025#how-does-it-work
Though talking with other folks, hardly anyone I know thinks of CIDs that way. I (and the people I've talked to) think of CIDs without the Multibase prefix and there there is of course Multibase prefixed CIDs.
To conclude, I'd remove the the identity Multibase and update the CID spec to reflect how CIDs are thought of today.