Skip to content

Commit

Permalink
Merge pull request #274 from walt-id/251-did-document-context-should-…
Browse files Browse the repository at this point in the history
…be-optional

fix: support did documents without LD context
  • Loading branch information
severinstampler authored Mar 29, 2023
2 parents 6e81a41 + da308c7 commit d70ce93
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/id/walt/model/DecentralizedIdentifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ enum class DidMethod(val didClass: KClass<out Did>) {
@TypeFor(field = "id", adapter = DidTypeAdapter::class)
open class Did(
@SerialName("@context")
@Json(name = "@context")
@Json(name = "@context", serializeNull = false)
@ListOrSingleValue
val context: List<String>,
val context: List<String>? = null,
val id: String,
@Json(serializeNull = false) var verificationMethod: List<VerificationMethod>? = null,
@Json(serializeNull = false) @DidVerificationRelationships open var authentication: List<VerificationMethod>? = null,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/model/did/DidCheqd.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import id.walt.model.ServiceEndpoint
import id.walt.model.VerificationMethod

class DidCheqd(
context: List<String> = listOf("https://w3id.org/did-resolution/v1"),
context: List<String>? = listOf("https://w3id.org/did-resolution/v1"),
id: String, // did:cheqd:mainnet:zF7rhDBfUt9d1gJPjx7s1JXfUY7oVWkY
authentication: List<VerificationMethod>? = null,
verificationMethod: List<VerificationMethod>? = null,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/model/did/DidEbsi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import id.walt.model.ServiceEndpoint
import id.walt.model.VerificationMethod

class DidEbsi(
context: List<String>,
context: List<String>? = null,
id: String,
verificationMethod: List<VerificationMethod>? = null,
authentication: List<VerificationMethod>? = null,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/model/did/DidIota.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import id.walt.model.ServiceEndpoint
import id.walt.model.VerificationMethod

class DidIota(
context: List<String> = listOf("https://www.w3.org/ns/did/v1"),
context: List<String>? = listOf("https://www.w3.org/ns/did/v1"),
id: String,
verificationMethod: List<VerificationMethod>? = null,
authentication: List<VerificationMethod>? = null,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/model/did/DidKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import id.walt.model.ServiceEndpoint
import id.walt.model.VerificationMethod

class DidKey(
context: List<String>,
context: List<String>? = null,
id: String,
verificationMethod: List<VerificationMethod>? = null,
authentication: List<VerificationMethod>? = null,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/model/did/DidWeb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.net.URLDecoder
import java.nio.charset.StandardCharsets

class DidWeb(
context: List<String>,
context: List<String>? = null,
id: String,
verificationMethod: List<VerificationMethod>? = null,
authentication: List<VerificationMethod>? = null,
Expand Down
21 changes: 21 additions & 0 deletions src/test/kotlin/id/walt/services/did/DidServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,25 @@ class DidServiceTest : AnnotationSpec() {
DidService.importDidAndKeys(did)
}
}

@Test
fun testDidWithoutContext() {
val did = "{\n" +
" \"id\": \"did:peer:0z6Mksu6Kco9yky1pUAWnWyer17bnokrLL3bYvYFp27zv8WNv\",\n" +
" \"authentication\": [\n" +
" {\n" +
" \"id\": \"did:peer:0z6Mksu6Kco9yky1pUAWnWyer17bnokrLL3bYvYFp27zv8WNv#6Mksu6Kco9yky1pUAWnWyer17bnokrLL3bYvYFp27zv8WNv\",\n" +
" \"type\": \"Ed25519VerificationKey2020\",\n" +
" \"controller\": \"did:peer:0z6Mksu6Kco9yky1pUAWnWyer17bnokrLL3bYvYFp27zv8WNv\",\n" +
" \"publicKeyMultibase\": \"z6Mksu6Kco9yky1pUAWnWyer17bnokrLL3bYvYFp27zv8WNv\"\n" +
" }\n" +
" ]\n" +
"}"
val parsedDid = Did.decode(did)
parsedDid?.id shouldNotBe null
parsedDid!!.id shouldBe "did:peer:0z6Mksu6Kco9yky1pUAWnWyer17bnokrLL3bYvYFp27zv8WNv"
parsedDid.context shouldBe null

parsedDid.encode() shouldMatchJson did
}
}

0 comments on commit d70ce93

Please sign in to comment.