Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from walt-id/feat-js-support
Browse files Browse the repository at this point in the history
close open branch before moving and archiving project
  • Loading branch information
severinstampler authored Dec 8, 2023
2 parents 49fefe6 + f969777 commit daed73f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ kotlin {
}
}
js(IR) {
browser {
/*browser {
commonWebpackConfig {
cssSupport {
enabled.set(true)
}
}
}
}*/
nodejs {
generateTypeScriptDefinitions()
}
Expand Down Expand Up @@ -85,7 +85,6 @@ kotlin {
}
}
val jsTest by getting {

}
val nativeMain by getting
val nativeTest by getting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal object DataElementSerializer: KSerializer<AnyDataElement> {
TDATE, TIME -> deserializeDateTime(decoder, tag)
FULL_DATE_STR, FULL_DATE_INT -> deserializeFullDate(decoder, tag)
COSE_SIGN1 -> ListElement(decoder.decodeSerializableValue(ListSerializer(DataElementSerializer)))
else -> throw SerializationException("The given tagged value type is currently not supported")
else -> throw SerializationException("The given tagged value type $tag is currently not supported")
}
}
7 -> when(curHead) {
Expand Down
18 changes: 9 additions & 9 deletions src/jsTest/kotlin/id/walt/mdoc/JSTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.encodeToHexString
import kotlin.test.Test

/*class JSTest {
class JSTest {

@OptIn(DelicateCoroutinesApi::class, ExperimentalJsExport::class)
//@Test
/*fun test1() = GlobalScope.promise {
fun test1() = GlobalScope.promise {
val key: dynamic = object {}
key["d"] = Hex.decode("6c1382765aec5358f117733d281c1c7bdc39884d04a45a1e6c67c858bc206c19")
val cryptoProvider = SimpleAsyncCOSECryptoProvider(listOf(
COSECryptoProviderKeyInfo("ISSUER_KEY_ID", "ES256", key)
))
testSigningMdl(cryptoProvider)
}*/
}

//@OptIn(ExperimentalSerializationApi::class)
/*suspend fun testSigningMdl(cryptoProvider: SimpleAsyncCOSECryptoProvider) {
@OptIn(ExperimentalSerializationApi::class)
suspend fun testSigningMdl(cryptoProvider: SimpleAsyncCOSECryptoProvider) {
// ISO-IEC_18013-5:2021
// Personal identification — ISO-compliant driving licence
// Part 5: Mobile driving licence (mDL) application
println("test signing mdl")
// create device key info structure of device public key, for holder binding
val deviceKeyInfo = DeviceKeyInfo(MapElement(mapOf(MapKey("k") to StringElement("1234"))))
println("device key info: ${deviceKeyInfo}")
// build mdoc of type mDL and sign using issuer key with holder binding to device key
val mdoc = MDocBuilder("org.iso.18013.5.1.mDL")
.addItemToSign("org.iso.18013.5.1", "family_name", "Doe".toDE())
Expand All @@ -56,5 +56,5 @@ import kotlin.test.Test
)
println("SIGNED MDOC (mDL):")
println(Cbor.encodeToHexString(mdoc))
}*/
}*/
}
}
45 changes: 45 additions & 0 deletions src/jvmTest/kotlin/id/walt/mdoc/JVMMdocTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,39 @@ import kotlinx.datetime.plus
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.decodeFromHexString
import kotlinx.serialization.encodeToHexString
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo
import org.bouncycastle.asn1.sec.ECPrivateKey
import org.bouncycastle.asn1.sec.SECNamedCurves
import org.bouncycastle.asn1.x500.X500Name
import org.bouncycastle.asn1.x509.BasicConstraints
import org.bouncycastle.asn1.x509.Extension
import org.bouncycastle.asn1.x509.KeyUsage
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo
import org.bouncycastle.asn1.x9.X9ECParameters
import org.bouncycastle.cert.X509v3CertificateBuilder
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter
import org.bouncycastle.crypto.params.ECDomainParameters
import org.bouncycastle.crypto.params.ECPrivateKeyParameters
import org.bouncycastle.crypto.params.ECPublicKeyParameters
import org.bouncycastle.jcajce.provider.asymmetric.ec.IESCipher.ECIESwithSHA256
import org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi.ECDSA
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.jce.spec.ECKeySpec
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder
import java.io.ByteArrayInputStream
import java.math.BigInteger
import java.security.KeyFactory
import java.security.KeyPair
import java.security.KeyPairGenerator
import java.security.SecureRandom
import java.security.Security
import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate
import java.security.spec.ECParameterSpec
import java.security.spec.ECPrivateKeySpec
import java.security.spec.EllipticCurve
import java.security.spec.PKCS8EncodedKeySpec
import java.security.spec.X509EncodedKeySpec
import java.util.*

class JVMMdocTest: AnnotationSpec() {
Expand Down Expand Up @@ -465,4 +481,33 @@ class JVMMdocTest: AnnotationSpec() {
val coseSign1 = Cbor.decodeFromByteArray(COSESign1Serializer, Hex.decode(jsCoseResult))
coseSign1.algorithm shouldBe AlgorithmID.ECDSA_256
}

/*@Test
fun testReproduceJSTestResult() {
val key = Hex.decode("6c1382765aec5358f117733d281c1c7bdc39884d04a45a1e6c67c858bc206c19")
val curve = SECNamedCurves.getByName("secp256k1") as X9ECParameters
val domain = ECDomainParameters(curve.curve, curve.g, curve.n, curve.h)
val d = BigInteger(key)
val q = domain.g.multiply(d)
val pubParams = ECPublicKeyParameters(q, domain)
val pub = pubParams.q.getEncoded(false)
val priv = ECPrivateKey(d)
val kf = KeyFactory.getInstance("EC")
val cryptoProvider = SimpleCOSECryptoProvider(listOf(
COSECryptoProviderKeyInfo("ISSUER_KEY_ID", AlgorithmID.ECDSA_256,
pub,
)
))
val deviceKeyInfo = DeviceKeyInfo(MapElement(mapOf(MapKey("k") to StringElement("1234"))))
val mdoc = MDocBuilder("org.iso.18013.5.1.mDL")
.addItemToSign("org.iso.18013.5.1", "family_name", "Doe".toDE())
.addItemToSign("org.iso.18013.5.1", "given_name", "John".toDE())
.addItemToSign("org.iso.18013.5.1", "birth_date", FullDateElement(LocalDate(1990, 1, 15)))
.sign(
ValidityInfo(Clock.System.now(), Clock.System.now(), Clock.System.now().plus(365*24, DateTimeUnit.HOUR)),
deviceKeyInfo, cryptoProvider, "ISSUER_KEY_ID"
)
println("SIGNED MDOC (mDL):")
println(Cbor.encodeToHexString(mdoc))
}*/
}

0 comments on commit daed73f

Please sign in to comment.