-
Notifications
You must be signed in to change notification settings - Fork 5
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/ATL-4076
- Loading branch information
Showing
18 changed files
with
122 additions
and
311 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
33 changes: 11 additions & 22 deletions
33
atala-prism-sdk/src/commonMain/kotlin/io/iohk/atala/prism/walletsdk/castor/did/DIDParser.kt
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 |
---|---|---|
@@ -1,34 +1,23 @@ | ||
package io.iohk.atala.prism.walletsdk.castor.did | ||
|
||
import io.iohk.atala.prism.walletsdk.castor.antlrgrammar.DIDAbnfLexer | ||
import io.iohk.atala.prism.walletsdk.castor.antlrgrammar.DIDAbnfParser | ||
import io.iohk.atala.prism.walletsdk.domain.models.CastorError | ||
import io.iohk.atala.prism.walletsdk.domain.models.DID | ||
import org.antlr.v4.kotlinruntime.CharStreams | ||
import org.antlr.v4.kotlinruntime.CommonTokenStream | ||
import org.antlr.v4.kotlinruntime.tree.ParseTree | ||
import org.antlr.v4.kotlinruntime.tree.ParseTreeWalker | ||
import kotlin.jvm.Throws | ||
|
||
object DIDParser { | ||
|
||
@Throws(CastorError.InvalidDIDString::class) | ||
fun parse(didString: String): DID { | ||
val inputStream = CharStreams.fromString(didString) | ||
val lexer = DIDAbnfLexer(inputStream) | ||
val tokenStream = CommonTokenStream(lexer) | ||
val parser = DIDAbnfParser(tokenStream) | ||
|
||
parser.errorHandler = ErrorStrategy() | ||
|
||
val context = parser.did() | ||
val listener = DIDParserListener() | ||
ParseTreeWalker().walk(listener, context as ParseTree) | ||
|
||
val scheme = listener.scheme ?: throw CastorError.InvalidDIDString("Invalid DID string, missing scheme") | ||
val methodName = listener.methodName ?: throw CastorError.InvalidDIDString("Invalid DID string, missing method name") | ||
val methodId = listener.methodId ?: throw CastorError.InvalidDIDString("Invalid DID string, missing method ID") | ||
|
||
return DID(scheme, methodName, methodId) | ||
val regex = | ||
"""^did:(?<method>[a-z0-9]+):(?<idstring>[a-z0-9.\-_%]+:*[a-z0-9.\-_%]+[^#?:]+)$""".toRegex(RegexOption.IGNORE_CASE) | ||
val matchResult = regex.find(didString) | ||
matchResult?.let { | ||
val scheme = "did" | ||
val methodName = it.groups["method"]?.value | ||
?: throw CastorError.InvalidDIDString("Invalid DID string, missing method name") | ||
val methodId = it.groups["idstring"]?.value | ||
?: throw CastorError.InvalidDIDString("Invalid DID string, missing method ID") | ||
return DID(scheme, methodName, methodId) | ||
} ?: throw CastorError.InvalidDIDString("DID string does not match the expected structure.") | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
...m-sdk/src/commonMain/kotlin/io/iohk/atala/prism/walletsdk/castor/did/DIDParserListener.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.