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
Feat: support for multiformat represenation in IPLD schema #241
Comments
@warpfork would love to see what you think about it |
@Gozala can you talk more about the use-cases you have in mind for this? I'm a little weary about this because of the history with When I came to actually implementing something that used it, it turned out that it was just easier and cleaner to do it in the application layer and treat that field as It's possible that in doing that I'm missing out on some benefits of properly representing them fully in the Node interface and maybe we'll come back to it, but maybe it gets to be an ADL at that future date which would still invalidate the need for So it'd be good to avoid adding bespoke representations unless we have solid (and ideally multiple) use-cases for them. Also the term "multiformat" doesn't necessarily imply a byte representation, there are various string forms of multiformat things too (multibase, multiaddr). |
Primary use case that came up is discussed here ucan-wg/ucan-ipld#4 and also motivated me to open multiformats/multicodec#289 Secondary motivation (although it might outweigh primary one in value) is an ability to define schema for various multiformats in a schema syntax, which I find to be much better than markdown descriptions like one used in multihash repo
This is an interesting context and relevant one because goal here is also to represent signatures. That said I wonder if the problem there was more around IPLD schema stuff than it is with the concept itself. On our side IPLD schema does not really serves any other purpose than a protocol definition that implementation can claim compatibility with. At the end of the day I imagine us passing bytes as is. That said I don't think passing decoded struct would prove to be less useful. In fact (at least in JS) we use a hybrid approach for this kind of thing where we can represent things as views over some bytes e.g. in this case it would be something like: class Signature extends Uint8Array {
get alogorithm() {
const [code, _] = varint.decode(this)
Object.defineProperties(this, {
alogorithm: { value: code }
})
return code
}
get size() {
const { buffer, byteOffset, byteLength, algorithm } = this
const offset = varint.encodingLength(algorithm) + byteOffset
const [size] = varint.decode(new Uint8Array(buffer, offset, byteLength))
Object.defineProperties(this, {
size { value: size }
})
return size
}
get bytes() {
const { buffer, byteOffset, byteLength, algorithm, size } = this
const offset = varint.encodingLength(algorithm) + varint.encodingLength(size) + byteOffset
const bytes = new Uint8Array(buffer, offset, byteLength)
Object.defineProperties(this, {
size { value: bytes }
})
return bytes
}
}
I think more broader problem I'm getting at is:
Which implies following:
Having a first class support for multiformats would help address 1 to 3 above. It could be that no 4 is not always desired but that I would expect you could improve on the tooling side which does actual decode e.g. generate those view structs as shown in the example, which would allow you to use them as ordinary Uint8Array or as a struct. |
@Gozala : are you planning to take on this work? |
I'm not sure what taking this on would entail, but I'm happy to help where I can. I believe there is quite a bit of a toolchain built around IPLD schemas. I'm happy to tackle spec work and some work around js tools, however I don't think I'm qualified to tackle go tools as I'm not familiar with those tools or have much experience with a language. In other words if someone can help scope it down necessary work, I can speak to what I'll be able to help with. |
yeah, ok, I think this seems reasonable and could potentially be leverage for other things I think the main areas of work to get new features into IPLD schemas, in rough order of importance:
|
Today there is no good way describe multiformats like https://github.com/multiformats/multihash the best we can do is basically something along the following lines:
It would be a lot nicer if we could actually define the structure for
sig
field there instead of some comment e.g.This in practice could be something between the lines of tuple and byteprefix representations where:
Bytes
orInteger
representation.Integers
's are encoded as varints.Bytes
are just appended.Not only this would help us have better schemas when multiformats are involved, but also provide a better language for describing multiformats than a markdown files with some prose.
The text was updated successfully, but these errors were encountered: