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
Add several varint prefix codes + lenghts for Holochain IDs #111
Add several varint prefix codes + lenghts for Holochain IDs #111
Conversation
Just a quick query to see if there is anything we can do to help this move ahead... Do you have any recommendations? Thanks! |
It would be great if you could pick number that is > |
Thanks @vmx; I've changed the multicodec prefix from 0x1E to 0x86, which will also work for us. |
fyi - here is a test suite exercising this multihash format, including reed-solomon ecc: https://github.com/holochain/n3h/blob/master/packages/hc-dpki/lib/util.test.js An example agent address:
|
Hi, @Stebalien, @vmx; Thanks for considering this addition; we really appreciate your time and effort on this project. Any more recommendations for us, to make this easier for you to merge? |
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.
LGTM. Given that this is now in the two-byte range, I don't see any reason to debate this.
@neonphog Is this really a multihash format? |
Note: Prefixes are usually encoded using 128 bit varints. That way one prefix won't be a prefix of another prefix. 0x86 is going to encode to FYI, you can get base64 encoded prefix of "holo" if you use 0x0d0243. This will encode to a 3 byte varint: |
You may also want to consider using multibase to allow alternative encodings. However, that may cause some issues with vanity prefixes. |
I see what you are saying. You are correct, this is not a hash. It is an identifier comprised of two 256 bit (32 byte) public keys, and 48 bits (6 bytes) of reed-solomon parity data. But these IDs will be used to address agent entries in a content addressable store that also includes data entries that will be keyed using sha256 hashes. It will be useful for us to easily identify the "hash" type. |
Thanks for the suggestion! Discussing this now 👍 |
@Stebalien We are having trouble confirming that 0x0d0243 converts into a varint as Also; does this mean that we would actually reserve |
Thanks for checking that! I was encoding it as a signed varint, not an unsigned varint. The code should have been 0x1a0486 which encodes to Code: package main
import (
"encoding/base64"
"encoding/binary"
"fmt"
)
func CodeToBase64(code uint64) string {
buf := make([]byte, binary.MaxVarintLen64)
len := binary.PutUvarint(buf, code)
buf = buf[:len]
return base64.StdEncoding.EncodeToString(buf)
}
func Base64ToCode(s string) (uint64, error) {
buf, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return 0, err
}
code, n := binary.Uvarint(buf)
if n == 0 {
return 0, fmt.Errorf("code too large")
} else if n != len(buf) {
return 0, fmt.Errorf("invalid varint")
}
return code, nil
}
func main() {
fmt.Println(CodeToBase64(0x1a0486))
fmt.Println(Base64ToCode("holo"))
fmt.Println(base64.StdEncoding.DecodeString("holo"))
}
Yes. Well, 0x1a0486. |
Sorry, don't merge yet -- still not correct! |
@pjkundert As you are playing around with getting a nice prefix, I'd just like to mention that IPFS is moving towards base32 encoding things (ipfs/kubo#4143), you might want to take that into account. |
Yes, base-32 is nice; also, because we can add Reed-Solomon error detection/correction using 5-bit symbols directly to end of the base-32 hash (instead of to the original payload), providing greater error/erasure detection and correction power per R-S symbol (because erroneous input symbols are not blurred across multiple Reed-Solomon symbols). Base64 URL encoding would also allow this, with 6-bit R-S symbols -- but the inclusion of Our Holochain keys are already very large (102 Base58 symbols), and further expansion with a less powerful encoding would make them just too large. |
Sheesh! No joy. Do not merge. This approach won't work for us, either. Base58 propagates errors into all subsequent octets output during a decode -- error correction built into the underlying payload is worthless... |
At long last... We've validated the round-tripping of these Varint prefixes with our encoding, and everything is good to merge! Thanks so much for your patience... @vmx We did end up settling on Base-32 with 63-symbol encoded values, so that we could use our values as DNS labels. |
I'll leave this open for a few days in case someone else wants to chime in. Please bug me if I don't merge it within a week. |
Thanks! |
Holochain is an open source framework for building fully distributed, peer-to-peer applications. See https://holo.host for more background.
We will be launching in the next few months, and would like our Holochain node Addresses to have the 0x86 prefix, if possible. That, along with our 70-byte long core keys+parity data will result in a multicodec prefix of 0x8646. When base-64 encoded, this yields Addresses with prefix "hkZ...", which is useful for our users to help them quickly identify potential Holochain Addresses.
Thanks for your consideration!