Skip to content

Commit

Permalink
Fix logic on retaining protected term definitions if redefined equiva…
Browse files Browse the repository at this point in the history
…lently.
  • Loading branch information
gkellogg committed Jun 15, 2024
1 parent fcd3aed commit 3e95e23
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 2 deletions.
62 changes: 62 additions & 0 deletions example-files/vc1373-2.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"@context": [
{
"@protected": true,
"@vocab": "https://www.w3.org/ns/credentials/issuer-dependent#",
"id": "@id",
"type": "@type",
"VerifiablePresentation": {
"@id": "https://www.w3.org/2018/credentials#VerifiablePresentation",
"@context": {
"@protected": true,
"id": "@id",
"type": "@type",
"holder": {
"@id": "https://www.w3.org/2018/credentials#holder",
"@type": "@id"
},
"proof": {
"@id": "https://w3id.org/security#proof",
"@type": "@id",
"@container": "@graph"
},
"verifiableCredential": {
"@id": "https://www.w3.org/2018/credentials#verifiableCredential",
"@type": "@id",
"@container": "@graph",
"@context": null
},
"termsOfUse": {
"@id": "https://www.w3.org/2018/credentials#termsOfUse",
"@type": "@id"
}
}
},
"issuer": {
"@id": "https://www.w3.org/2018/credentials#issuer",
"@type": "@id",
"@context": {
"@protected": true,

"id": "@id",
"type": "@type",

"description": {
"@id": "https://schema.org/description",
"@context": {
"value": "@value", "lang": "@language", "dir": "@direction"
}
},
"name": {
"@id": "https://schema.org/name",
"@context": {
"value": "@value", "lang": "@language", "dir": "@direction"
}
}
}
}
}
],
"type": "VerifiablePresentation",
"verifiableCredential": ["http://university.example/credentials/1872"]
}
126 changes: 126 additions & 0 deletions example-files/vc1373.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"@context": [
{
"@protected": true,
"@vocab": "https://www.w3.org/ns/credentials/issuer-dependent#",
"id": "@id",
"type": "@type",
"VerifiablePresentation": {
"@id": "https://www.w3.org/2018/credentials#VerifiablePresentation",
"@context": {
"@protected": true,
"id": "@id",
"type": "@type",
"holder": {
"@id": "https://www.w3.org/2018/credentials#holder",
"@type": "@id"
},
"proof": {
"@id": "https://w3id.org/security#proof",
"@type": "@id",
"@container": "@graph"
},
"verifiableCredential": {
"@id": "https://www.w3.org/2018/credentials#verifiableCredential",
"@type": "@id",
"@container": "@graph",
"@context": null
},
"termsOfUse": {
"@id": "https://www.w3.org/2018/credentials#termsOfUse",
"@type": "@id"
}
}
},
"issuer": {
"@id": "https://www.w3.org/2018/credentials#issuer",
"@type": "@id",
"@context": {
"@protected": true,

"id": "@id",
"type": "@type",

"description": {
"@id": "https://schema.org/description",
"@context": {
"value": "@value", "lang": "@language", "dir": "@direction"
}
},
"name": {
"@id": "https://schema.org/name",
"@context": {
"value": "@value", "lang": "@language", "dir": "@direction"
}
}
}
}
}
],
"type": "VerifiablePresentation",
"verifiableCredential": [
{
"@context": [
{
"@protected": true,
"@vocab": "https://www.w3.org/ns/credentials/issuer-dependent#",
"id": "@id",
"type": "@type",
"VerifiablePresentation": {
"@id": "https://www.w3.org/2018/credentials#VerifiablePresentation",
"@context": {
"@protected": true,
"id": "@id",
"type": "@type",
"holder": {
"@id": "https://www.w3.org/2018/credentials#holder",
"@type": "@id"
},
"proof": {
"@id": "https://w3id.org/security#proof",
"@type": "@id",
"@container": "@graph"
},
"verifiableCredential": {
"@id": "https://www.w3.org/2018/credentials#verifiableCredential",
"@type": "@id",
"@container": "@graph",
"@context": null
},
"termsOfUse": {
"@id": "https://www.w3.org/2018/credentials#termsOfUse",
"@type": "@id"
}
}
},
"issuer": {
"@id": "https://www.w3.org/2018/credentials#issuer",
"@type": "@id",
"@context": {
"@protected": true,

"id": "@id",
"type": "@type",

"description": {
"@id": "https://schema.org/description",
"@context": {
"value": "@value", "lang": "@language", "dir": "@direction"
}
},
"name": {
"@id": "https://schema.org/name",
"@context": {
"value": "@value", "lang": "@language", "dir": "@direction"
}
}
}
}
}
],
"id": "http://university.example/credentials/1872",
"type": "VerifiableCredential",
"issuer": "https://university.example/issuers/565049"
}
]
}
1 change: 1 addition & 0 deletions json-ld.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'multi_json', '~> 1.15'
gem.add_runtime_dependency "rack", '>= 2.2', '< 4'
gem.add_runtime_dependency 'rdf', '~> 3.3'
gem.add_runtime_dependency 'rexml', '~> 3.2'
gem.add_development_dependency 'getoptlong', '~> 0.2'
gem.add_development_dependency 'jsonlint', '~> 0.4' unless is_java
gem.add_development_dependency 'oj', '~> 3.15' unless is_java
Expand Down
6 changes: 4 additions & 2 deletions lib/json/ld/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,11 @@ def create_term_definition(local_context, term, defined,
end
end

if previous_definition&.protected? && definition != previous_definition && !override_protected
if !override_protected && previous_definition&.protected?
if definition != previous_definition
raise JSON::LD::JsonLdError::ProtectedTermRedefinition, "Attempt to redefine protected term #{term}"
end
definition = previous_definition
raise JSON::LD::JsonLdError::ProtectedTermRedefinition, "Attempt to redefine protected term #{term}"
end

term_definitions[term] = definition
Expand Down

0 comments on commit 3e95e23

Please sign in to comment.