-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/main' into fix-readme
- Loading branch information
Showing
14 changed files
with
637 additions
and
47 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
72 changes: 72 additions & 0 deletions
72
...d-libraries/waltid-did/src/commonMain/kotlin/id/walt/did/dids/document/DidEbsiDocument.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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package id.walt.did.dids.document | ||
|
||
import kotlinx.serialization.* | ||
import kotlinx.serialization.json.* | ||
import kotlin.js.ExperimentalJsExport | ||
import kotlin.js.JsExport | ||
import kotlin.js.JsName | ||
|
||
@JsExport | ||
@OptIn(ExperimentalSerializationApi::class, ExperimentalJsExport::class) | ||
@Serializable | ||
data class DidEbsiDocument( | ||
@EncodeDefault @SerialName("@context") val context: List<String> = DEFAULT_CONTEXT, | ||
val id: String, // did:ebsi: | ||
val controller: List<String>?, | ||
val verificationMethod: List<VerificationMethod>?, | ||
val authentication: List<String>?, | ||
val assertionMethod: List<String>?, | ||
val capabilityInvocation: List<String>?, | ||
val capabilityDelegation: List<String>?, | ||
val keyAgreement: List<String>?, | ||
) { | ||
companion object { | ||
private val DEFAULT_CONTEXT = | ||
listOf("https://www.w3.org/ns/did/v1", "https://w3id.org/security/suites/jws-2020/v1") | ||
private val json = Json { | ||
explicitNulls = false | ||
} | ||
} | ||
|
||
@Serializable | ||
data class VerificationMethod( | ||
val id: String, // did:ebsi: | ||
val type: String, // JsonWebKey2020 | ||
val controller: String, // did:ebsi: | ||
val publicKeyJwk: JsonObject // jwk | ||
) | ||
|
||
fun toMap() = json.encodeToJsonElement(this).jsonObject.toMap() | ||
|
||
@JsName("secondaryConstructor") | ||
constructor(didDoc: DidDocument) : this( | ||
context = DEFAULT_CONTEXT, | ||
id = didDoc["id"]!!.jsonPrimitive.content, | ||
controller = didDoc["controller"]?.jsonArray?.map { | ||
it.jsonPrimitive.content | ||
}, | ||
verificationMethod = didDoc["verificationMethod"]?.jsonArray?.map { | ||
val verificationMethod = it.jsonObject | ||
val id = verificationMethod["id"]!!.jsonPrimitive.content | ||
val type = verificationMethod["type"]!!.jsonPrimitive.content | ||
val controller = verificationMethod["controller"]!!.jsonPrimitive.content | ||
val publicKeyJwk = verificationMethod["publicKeyJwk"]!!.jsonObject | ||
VerificationMethod(id, type, controller, publicKeyJwk) | ||
}, | ||
authentication = didDoc["authentication"]?.jsonArray?.map { | ||
it.jsonPrimitive.content | ||
}, | ||
assertionMethod = didDoc["assertionMethod"]?.jsonArray?.map { | ||
it.jsonPrimitive.content | ||
}, | ||
capabilityInvocation = didDoc["capabilityInvocation"]?.jsonArray?.map { | ||
it.jsonPrimitive.content | ||
}, | ||
capabilityDelegation = didDoc["capabilityDelegation"]?.jsonArray?.map { | ||
it.jsonPrimitive.content | ||
}, | ||
keyAgreement = didDoc["keyAgreement"]?.jsonArray?.map { | ||
it.jsonPrimitive.content | ||
}, | ||
) | ||
} |
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
24 changes: 24 additions & 0 deletions
24
waltid-libraries/waltid-did/src/jvmTest/kotlin/LocalDidJwkConsistencyTest.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import id.walt.crypto.keys.KeyType | ||
import id.walt.crypto.keys.jwk.JWKKey | ||
import id.walt.did.dids.registrar.dids.DidJwkCreateOptions | ||
import id.walt.did.dids.registrar.local.jwk.DidJwkRegistrar | ||
import id.walt.did.dids.resolver.local.DidJwkResolver | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class LocalDidJwkConsistencyTest { | ||
|
||
private val localResolver = DidJwkResolver() | ||
private val localRegistrar = DidJwkRegistrar() | ||
|
||
@Test | ||
fun testDidJwkCreateAndResolveConsistency() = runTest{ | ||
val keyList: List<JWKKey> = KeyType.entries.map { JWKKey.generate(it) } | ||
for (key in keyList) { | ||
val didResult = localRegistrar.registerByKey(key, DidJwkCreateOptions(keyType = key.keyType)) | ||
val resolvedKey = localResolver.resolveToKey(didResult.did).getOrThrow() | ||
assertEquals(key.getThumbprint(),resolvedKey.getThumbprint()) | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
waltid-libraries/waltid-did/src/jvmTest/kotlin/LocalDidKeyConsistencyTest.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import id.walt.crypto.keys.KeyType | ||
import id.walt.crypto.keys.jwk.JWKKey | ||
import id.walt.did.dids.registrar.dids.DidKeyCreateOptions | ||
import id.walt.did.dids.registrar.local.key.DidKeyRegistrar | ||
import id.walt.did.dids.resolver.local.DidKeyResolver | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class LocalDidKeyConsistencyTest { | ||
|
||
private val localResolver = DidKeyResolver() | ||
private val localRegistrar = DidKeyRegistrar() | ||
|
||
@Test | ||
fun testDidKeyCreateAndResolveConsistency() = runTest{ | ||
val keyList: List<JWKKey> = KeyType.entries.map { JWKKey.generate(it) } | ||
for (key in keyList) { | ||
val didResult = localRegistrar.registerByKey(key, DidKeyCreateOptions(keyType = key.keyType)) | ||
val resolvedKey = localResolver.resolveToKey(didResult.did).getOrThrow() | ||
assertEquals(key.getThumbprint(),resolvedKey.getThumbprint()) | ||
} | ||
} | ||
|
||
@Test | ||
fun testDidKeyCreateAndResolveJwkJcsPubConsistency() = runTest { | ||
val keyList: List<JWKKey> = KeyType.entries.map { JWKKey.generate(it) } | ||
for (key in keyList) { | ||
val didResult = localRegistrar.registerByKey(key, DidKeyCreateOptions(keyType = key.keyType, useJwkJcsPub = true)) | ||
localResolver.resolveToKey(didResult.did) | ||
val resolvedKey = localResolver.resolveToKey(didResult.did).getOrThrow() | ||
assertEquals(key.getThumbprint(),resolvedKey.getThumbprint()) | ||
} | ||
} | ||
} |
Oops, something went wrong.