Skip to content

Commit

Permalink
Merge branch 'main' into feature/ATL-4076
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianIOHK authored Nov 27, 2023
2 parents 558f5a7 + 854fc70 commit ecb34be
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 311 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ on:
required: false
description: Authorization key
default: 1gnp5fzLTwNBvLBXLk9THLgxe9SLoh+7
pull_request:
branches:
- main
push:
branches:
- main
Expand Down
37 changes: 4 additions & 33 deletions atala-prism-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ koverReport {
packages(
"io.iohk.atala.prism.protos",
"io.iohk.atala.prism.walletsdk.domain",
"io.iohk.atala.prism.walletsdk.castor.antlrgrammar",
"ioiohkatalaprismwalletsdkpluto.data"
)
}
Expand All @@ -56,15 +55,7 @@ kotlin {
}

sourceSets {
val commonAntlr by creating {
kotlin.srcDir("build/generated-src/commonAntlr/kotlin")
dependencies {
api(kotlin("stdlib-common"))
api("com.github.piacenti:antlr-kotlin-runtime:0.0.14")
}
}
val commonMain by getting {
this.dependsOn(commonAntlr)
kotlin.srcDir("${project(":protosLib").buildDir}/generated/source/proto/main/kotlin")
resources.srcDir("${project(":protosLib").projectDir}/src/main")
dependencies {
Expand Down Expand Up @@ -232,26 +223,6 @@ tasks.withType<DokkaTask>().configureEach {
}
}

val antlrGenerationTask by tasks.register<com.strumenta.antlrkotlin.gradleplugin.AntlrKotlinTask>("generateKotlinCommonGrammarSource") {
// the classpath used to run antlr code generation
antlrClasspath = configurations.detachedConfiguration(
project.dependencies.create("com.github.piacenti:antlr-kotlin-runtime:0.0.14")
)
maxHeapSize = "64m"
packageName = "io.iohk.atala.prism.walletsdk.castor.antlrgrammar"
arguments = listOf("-long-messages", "-Dlanguage=JavaScript")
source = project.objects
.sourceDirectorySet("antlr", "antlr")
.srcDir("src/commonAntlr/antlr").apply {
include("*.g4")
}
// outputDirectory is required, put it into the build directory
// if you do not want to add the generated sources to version control
outputDirectory = File("build/generated-src/commonAntlr/kotlin")
// use this setting if you want to add the generated sources to version control
// outputDirectory = File("src/commonAntlr/kotlin")
}

val buildProtoLibsGen by tasks.creating {
group = "build"
this.dependsOn(":protosLib:generateProto")
Expand All @@ -265,17 +236,17 @@ afterEvaluate {
this.enabled = false
}
tasks.getByName("runKtlintCheckOverCommonMainSourceSet") {
dependsOn(buildProtoLibsGen, antlrGenerationTask)
dependsOn(buildProtoLibsGen)
}
tasks.getByName("build") {
dependsOn(buildProtoLibsGen, antlrGenerationTask)
dependsOn(buildProtoLibsGen)
}

tasks.withType<KotlinCompile> {
dependsOn(buildProtoLibsGen, antlrGenerationTask)
dependsOn(buildProtoLibsGen)
}

tasks.withType<ProcessResources> {
dependsOn(buildProtoLibsGen, antlrGenerationTask)
dependsOn(buildProtoLibsGen)
}
}
34 changes: 0 additions & 34 deletions atala-prism-sdk/src/commonAntlr/antlr/DIDAbnf.g4

This file was deleted.

62 changes: 0 additions & 62 deletions atala-prism-sdk/src/commonAntlr/antlr/DIDUrlAbnf.g4

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ class ApolloImpl : Apollo {

val hdKey = HDKey(seedByteArray, 0, 0)
val derivedHdKey = hdKey.derive(derivationPath)
return Secp256k1PrivateKey(derivedHdKey.getKMMSecp256k1PrivateKey().raw)
val private = Secp256k1PrivateKey(derivedHdKey.getKMMSecp256k1PrivateKey().raw)
private.keySpecification[SeedKey().property] = seed
private.keySpecification[DerivationPathKey().property] = derivationPath
private.keySpecification[IndexKey().property] = "0"
return private
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
package io.iohk.atala.prism.walletsdk.apollo.utils

import io.iohk.atala.prism.apollo.base64.base64UrlEncoded
import io.iohk.atala.prism.apollo.derivation.DerivationPath
import io.iohk.atala.prism.apollo.derivation.HDKey
import io.iohk.atala.prism.apollo.utils.KMMECSecp256k1PrivateKey
import io.iohk.atala.prism.walletsdk.apollo.helpers.BytesOps
import io.iohk.atala.prism.walletsdk.domain.models.Curve
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.CurveKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.CurvePointXKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.CurvePointYKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.DerivableKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.ExportableKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.JWK
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.KeyTypes
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.PEMKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.PEMKeyType
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.PrivateKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.PublicKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.SeedKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.SignableKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.StorableKey

class Secp256k1PrivateKey(nativeValue: ByteArray) : PrivateKey(), SignableKey, StorableKey, ExportableKey {
class Secp256k1PrivateKey(nativeValue: ByteArray) :
PrivateKey(),
SignableKey,
StorableKey,
ExportableKey,
DerivableKey {
override val type: KeyTypes = KeyTypes.EC
override val keySpecification: MutableMap<String, String> = mutableMapOf()
override val size: Int
Expand All @@ -42,6 +52,7 @@ class Secp256k1PrivateKey(nativeValue: ByteArray) : PrivateKey(), SignableKey, S
keyData = raw
).pemEncoded()
}

override fun getJwk(): JWK {
return JWK(
kty = "OKP",
Expand All @@ -50,7 +61,6 @@ class Secp256k1PrivateKey(nativeValue: ByteArray) : PrivateKey(), SignableKey, S
y = getProperty(CurvePointYKey().property).base64UrlEncoded
)
}

override fun jwkWithKid(kid: String): JWK {
return JWK(
kty = "OKP",
Expand All @@ -65,4 +75,14 @@ class Secp256k1PrivateKey(nativeValue: ByteArray) : PrivateKey(), SignableKey, S
get() = raw
override val restorationIdentifier: String
get() = "secp256k1+priv"

override fun derive(derivationPath: DerivationPath): PrivateKey {
val seed = getProperty(SeedKey().property)

val seedByteArray = BytesOps.hexToBytes(seed)

val hdKey = HDKey(seedByteArray, 0, 0)
val derivedHdKey = hdKey.derive(derivationPath.toString())
return Secp256k1PrivateKey(derivedHdKey.getKMMSecp256k1PrivateKey().raw)
}
}
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.")
}
}

This file was deleted.

Loading

0 comments on commit ecb34be

Please sign in to comment.