peer-did-method-spec icon indicating copy to clipboard operation
peer-did-method-spec copied to clipboard

Recognizing and handling peer DIDs Regex seems out of date

Open devin-fisher opened this issue 3 years ago • 4 comments

The regex seems to be out of date.

^did:peer:[01](z)([1-9a-km-zA-HJ-NP-Z]{46,47})$

  1. There seems to be 3 numalgo possibilities
  2. There is no capture group for numalgo even though it is referenced.
  3. I don't really understand method 2 yet but is sure to be 46 to 47 characters long (question, not statement)

https://github.com/decentralized-identity/peer-did-method-spec/blob/202a91338f18e28612724b60f3843c6f6b123226/core.html#L279

devin-fisher avatar Apr 08 '21 21:04 devin-fisher

minimally, seems to need

^did:peer:([012])(z)([1-9a-km-zA-HJ-NP-Z]{46,47})$

devin-fisher avatar Apr 08 '21 21:04 devin-fisher

Yes, the regex is out of date. We need something like ^did:peer:([01](z)([1-9a-km-zA-HJ-NP-Z]{46,47})$|2<up to several hundred base64 chars>$). @TelegramSam : do you want to limit how long a method-2 DID can be?

dhh1128 avatar Apr 08 '21 21:04 dhh1128

Might make sense to do something like this: Generic Regex For Peer DID: ^did:peer:([\d+]).* This would derive the numalgo

Then have method specific Regex base on the numalgo

It seems that the current regex is over specific anyway. The number of characters is only true if uses the z base58. If we supported a different transform code for base64, the number of characters would be different. Do we really want to express every permutation?

devin-fisher avatar Apr 09 '21 21:04 devin-fisher

Also running into some issues with the regex when using other types of keys. E.g the fingerprint of a bls12381g1 key looks like this. Which is 69 characters long.

z3tEFVhKXU6NQAKw17iY6Uh372YwZDrMZrQHfoTXVpTtoxsDPT3naA4sgfv63o3ayoF1MU

Or the g2 variant, which is 134 characters long

UC78Kzw6c4cvZqJ8wfFeFCswrGQ6KeDTcoRGzmHD8PeEY8yeZ4QUfhHh5Kt89UXRJw6W8P2bk2ezGqk7S9gkyb9P4jEzdEfmhvkqykjVPtUfsHkEkF6zd2SuTNECxzHkNmywV1

Maybe we should just remove the character limit in the regex? Or at least make it sufficient for longer keys

TimoGlastra avatar Jan 22 '22 16:01 TimoGlastra