Zenroom icon indicating copy to clipboard operation
Zenroom copied to clipboard

Multibase, multikey and multihash

Open matteo-cristino opened this issue 1 year ago • 6 comments

General multi* flow:

  • save the detected base in the codec so that it can be used during the export
  • save in ACK the raw value
  • use the CODEC when printing to print it as it was in input

Printing data in multibase format

Then I print 'data' as 'multibase' # not enough, wath base should be used?

maybe

Then I print 'data' as 'base64 multibase' # base64 can be changed with all bases

?

Printing keys in multikey format

Then I print 'ecdh' from 'keyring' as 'base64 multikey'
Then I print 'ecdh public key' as 'base64 multikey'

Printing hash in multihash format

same as above

Example

Given I have a 'multikey' named 'my key'  # -> ACK.my_key with base and alg in CODEC

When I create the ecdh key with secret 'my key'
When I create the ecdh public key

Then I print the 'my key'
Then I print the 'ecdh public key' as 'base64 multikey'

matteo-cristino avatar Jan 21 '25 17:01 matteo-cristino

Using the Then phase to encode as multistuff does not seems the best option, maybe a When statement can do it better like

When I create the multibase of 'data' with base 'base64'
When I create the multikey of [ecdh|ecdsa] secret key 'key' with base 'base64'
When I create the multikey of eddsa secret key 'key' with base 'base64'
When I create the multikey of [ecdh|ecdsa] public key 'key' with base 'base64'
When I create the multikey of eddsa public key 'key' with base 'base64'
When I create the multihash of sha2-256 'hash' with base 'base64'
When I create the multihash of sha2-384 'hash' with base 'base64'
When I create the multihash of sha3-256 'hash' with base 'base64'
When I create the multihash of sha3-384 'hash' with base 'base64'

(hash can not be autodetected from length since multihash support different type of hash like keccak and shake that can have the same length)

matteo-cristino avatar Jan 22 '25 19:01 matteo-cristino

One more round of evaluation about saving the type of hash and the multihash status in CODEC to simplify these statements:

When I create the multihash of ''

which will check if the argument is a hash, and of what kind and will tag it so into CODEC for correct rendering.

Then I print the 'multihash'
Then I print the 'multihash' as 'hex'

If the argument is tagged as multihash in CODEC, then render it as such using base64 as default encoding.

The drawback is that users need to remember what is encoded as multihash which is not evident if renamed. I think it is acceptable.

jaromil avatar Jan 28 '25 09:01 jaromil

The encoding can be moved to the then phase, you are right!

In the hash I left the type of hash since multihash is expanding also to include other hashes, so I do not think you could distinguish between sha2-256 or sha3-256 or keccak-256 or shake-256.

A full list of of multicodec can be found here

matteo-cristino avatar Jan 28 '25 10:01 matteo-cristino

We can distinguish saving in CODEC from the info given in the statement: When("create hash of '' using ''",_name,_hash) as well from a new Given statement: Given("have a '' hash '',_encoding,_hashtype) as well we can think of a When statement which arbitrarily classifies as hash any octet fitting size (size checks should be made everywhere)

jaromil avatar Jan 28 '25 10:01 jaromil

Ok seems good 👌

matteo-cristino avatar Jan 28 '25 10:01 matteo-cristino

Not yet finished but getting there.

jaromil avatar Mar 10 '25 15:03 jaromil