iotaledger/identity.rs

[Request] Support full DID Syntax in CoreDID

Closed this issue · 8 comments

Description

When implementing a custom resolver for the did:web method, one is required to pass a CoreDID to the resolve() function. According to the spec of did:web, one needs to percent-encode the method-specific identifier to prevent the port from being interpreted as another method delimiter, for example: did:web:localhost%3A12345.
However, when calling CoreDID::parse("did:web:localhost%3A12345"), I am getting an InvalidMethodId error.
I do not see any conflict in supporting this as percent-encoding is part of the official DID Syntax.

Motivation

Allow implementation of resolver for did:web.

Requirements

  1. Allow parsing a percent-encoded did:web to a valid CoreDID.

Open questions (optional)

n/a

Are you planning to do it yourself in a pull request?

No

Tasks

Hi @daniel-mader, unfortunately the error comes from the crate did-url. I'm not sure we can quickly fix it. I will take a closer look.

The did-url crate looks unmaintained to me. Is forking it and fixing it yourself an option?

@daniel-mader I forked and fixed did-url. You can use cargo's [path.crates-io] to get it. In your Cargo.toml file (where you have a dependency to identity_iota) add this:

[patch.crates-io]
did_url = { git = "https://github.com/iotaledger/did_url.git" }

We should be able to get ownership of that crate eventually, but for now this should get you going.

Thank you @UMR1352! I replaced the dependency as you described and I now got this in my Cargo.lock:

[[package]]
name = "did_url"
version = "0.1.0"
source = "git+https://github.com/iotaledger/did_url.git#985e6179644db6c238228175c30883ef8b957840"
dependencies = [
 "form_urlencoded",
 "serde",
]

This looks correct to me, I also ran cargo clean and cargo update to make sure I got the right dependency.

However, I still get the InvalidMethodId when running identity_iota::did::CoreDID::parse("did:web:localhost%3A12345"). The only thing I can think of right now that could cause this is that CoreDID::parse() is not using did_url::DID::parse() as we think it does. Can you verify the fix by running CoreDID::parse() from within identity.rs?

@daniel-mader you are right, identity_did performs a second validation of method_id in CoreDID::parse and that fails. Lemme look into this and reach back to you.

@daniel-mader I fixed it, but unfortunately we can't merge it into main as long as we are linking to did_url through a git repo. I suggest you get the fix by linking identity_iota through the bug/did-url-par-encoding branch, like this:

identity_iota = { git = "https://github.com/iotaledger/identity.rs/tree/bug/did-url-par-encoding.git" }

Keep #1303 monitored, either we get ownership of did_url or we publish our fork to crates and we merge the PR.

Thanks for the quick fix! I can verify it works for my use case! 🥳

I set the dependency like so:

identity_iota = { git = "https://github.com/iotaledger/identity.rs.git", branch = "bug/did-url-par-encoding" }

(Your suggestion somehow didn't work for me, I got a unexpected http status code: 404; for unknown reasons.)

I also assume that I do not need the [patch.crates-io] anymore, since it's included in your fix, correct?

(Your suggestion somehow didn't work for me, I got a unexpected http status code: 404; for unknown reasons.)

My bad, I wrote the snipped without actually trying it. Glad you could make it work anyway.

I also assume that I do not need the [patch.crates-io] anymore, since it's included in your fix, correct?

Exactly, in that branch the library uses did_url through our fork so you don't have to patch it yourself.