ucanto icon indicating copy to clipboard operation
ucanto copied to clipboard

API for serializing / deserializing delegations

Open Gozala opened this issue 3 years ago • 2 comments

As per https://github.com/web3-storage/ucanto/pull/173#issuecomment-1347442859 there seems to be a desire for an API that can serialize / de-serialize delegations

Gozala avatar Dec 12 '22 23:12 Gozala

@alanshaw this has came up in the past with @hugomrdias and my answer was, we can't have fromJSON because:

  1. It's unclear what JSON representation of DAG would look like or how would it deduplicate.
  2. I also worry that one could craft JSON that is invalid delegation and could deceive system into thinking it's valid unless verified.

All in all fromJSON sounds error prone that I don't believe it's worth it.

What we do have instead is

https://github.com/web3-storage/ucanto/blob/e97bd8e15d5e42a3e9be2ce949acdd18de543dc1/packages/core/src/delegation.js#L215-L225

Which is used by transport to serialize delegation into a CAR which can represent DAGs

https://github.com/web3-storage/ucanto/blob/e97bd8e15d5e42a3e9be2ce949acdd18de543dc1/packages/transport/src/car.js#L25-L30

Only reason there was never toCAR / fromCAR is because I wrote sync car encoder but have not got around to writing sync decoder. However sounds like @hugomrdias got around to doing it, so perhaps he'd be game to integrate it here and add those methods ?

I know CAR isn't a string, but but we have base codec to deal with that.

If we really want a JSON version than I think we need to define CAR like structure in DAG JSON in which case it would become plausible.

Gozala avatar Dec 12 '22 23:12 Gozala

yes its this file https://github.com/web3-storage/w3protocol/blob/6abe8c2dcc72a888ce998c6f5d126f6ba3f81c4c/packages/access-client/src/encoding.js

I used base64url for the string encoding. We should move those to ucanto directly.

Is this enough for your needs @alanshaw ?

if it is we should add this task to the current phase

hugomrdias avatar Jan 12 '23 12:01 hugomrdias