-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/prismagent-with-castor-new-protobuf
- Loading branch information
Showing
18 changed files
with
287 additions
and
681 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
mercury/mercury-library/resolver/src/main/scala/io/iohk/atala/resolvers/DidValidator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.iohk.atala.resolvers | ||
|
||
import io.iohk.atala.mercury.model.DidId | ||
|
||
object DidValidator extends DidValidator | ||
trait DidValidator { | ||
val regexAny = "^did:(.*):(.*)$".r | ||
|
||
/** Ex: did:prism:66940961cc0f6a884ff5876992991b994ca518aa34b3bacfd15f2b51a7b042cf | ||
*/ | ||
val regexPRISM = "^did:prism:(.*)$".r | ||
|
||
/** Ex: | ||
* did:peer:2.Ez6LSeSTchYyPTBk131pKECXWP7t1CYG2RMgRE2KWoiWi962w.Vz6MkmLJC9YyMerhFD831jrbVAo8rHXiBvDV6UKnt8xzQY7MJ.SeyJ0IjoiZG0iLCJzIjoiaHR0cDovL2xvY2FsaG9zdEw5OTk5IiwiciI6W10sImEiOlsiZGlkY29tbS92MiJdfQ | ||
*/ | ||
val regexPeer = | ||
"^did:peer:(([01](z)([1-9a-km-zA-HJ-NP-Z]{46,47}))|(2((\\.[AEVID](z)([1-9a-km-zA-HJ-NP-Z]{46,47}))+(\\.(S)[0-9a-zA-Z=]*)?)))$".r | ||
|
||
def isDidPRISM(did: String) = did match { | ||
case regexPRISM(id) => true | ||
case _ => false | ||
} | ||
def isDidPeer(did: String) = did match { | ||
case regexPeer(id, _*) => true | ||
case _ => false | ||
} | ||
|
||
def validDID(did: DidId): Boolean = validDID(did.value) | ||
def validDID(did: String): Boolean = did match { | ||
case regexAny(method, id) => true | ||
case _ => false | ||
} | ||
|
||
def supportedDid(did: DidId): Boolean = supportedDid(did.value) | ||
def supportedDid(did: String): Boolean = did match | ||
case regexPRISM(id) => true | ||
case regexPeer(id, _*) => true | ||
case regexAny("example", "alice") => true // for debug | ||
case regexAny("example", "mediator") => true // for debug | ||
case regexAny("example", "bob") => true // for debug | ||
case regexAny(method, id) => false | ||
case _ => false // NOT a DID | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...ry/mercury-library/resolver/src/test/scala/io/iohk/atala/resolvers/DidValidatorSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.iohk.atala.resolvers | ||
|
||
import munit.* | ||
|
||
/** resolver/testOnly io.iohk.atala.resolvers.DidValidatorSpec | ||
*/ | ||
class DidValidatorSpec extends ZSuite { | ||
val exPRISM = "did:prism:66940961cc0f6a884ff5876992991b994ca518aa34b3bacfd15f2b51a7b042cf" | ||
val exPeer = | ||
"did:peer:2.Ez6LSeSTchYyPTBk131pKECXWP7t1CYG2RMgRE2KWoiWi962w.Vz6MkmLJC9YyMerhFD831jrbVAo8rHXiBvDV6UKnt8xzQY7MJ.SeyJ0IjoiZG0iLCJzIjoiaHR0cDovL2xvY2FsaG9zdEw5OTk5IiwiciI6W10sImEiOlsiZGlkY29tbS92MiJdfQ" | ||
|
||
test("validDID") { | ||
assertEquals(DidValidator.validDID(exPRISM), true) | ||
assertEquals(DidValidator.validDID(exPeer), true) | ||
assertEquals(DidValidator.validDID("did:test:ola"), true) | ||
} | ||
|
||
test("supportedDid") { | ||
assertEquals(DidValidator.supportedDid(exPRISM), true) | ||
assertEquals(DidValidator.supportedDid(exPeer), true) | ||
assertEquals(DidValidator.supportedDid("did:test:ola"), false) | ||
} | ||
|
||
test("isDidPRISM and isDidPeer") { | ||
assertEquals(DidValidator.isDidPRISM(exPRISM), true) | ||
assertEquals(DidValidator.isDidPeer(exPRISM), false) | ||
|
||
assertEquals(DidValidator.isDidPRISM(exPeer), false) | ||
assertEquals(DidValidator.isDidPeer(exPeer), true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.