Skip to content

Commit

Permalink
Merge pull request #324 from axone-protocol/feat/vc-proof-of-particip…
Browse files Browse the repository at this point in the history
…ation

Feat/vc proof of participation
  • Loading branch information
ccamel authored Jan 31, 2025
2 parents 06f9a68 + d4992c8 commit 612ef77
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 17 deletions.
78 changes: 78 additions & 0 deletions docs/schemas/credential-proof-of-participation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
sidebar_position: 9
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

# Proof of participation credential

> **Name**: `credential-proof-of-participation`
>
> **Namespace**: [https://w3id.org/axone/ontology/v4/schema/credential/proof-of-participation/](https://w3id.org/axone/ontology/v4/schema/credential/proof-of-participation/)
## Namespaces

Here are the namespaces used in this schema:

- `rdf`: [http://www.w3.org/1999/02/22-rdf-syntax-ns#](http://www.w3.org/1999/02/22-rdf-syntax-ns#)
- `rdfs`: [http://www.w3.org/2000/01/rdf-schema#](http://www.w3.org/2000/01/rdf-schema#)
- `skos`: [http://www.w3.org/2004/02/skos/core#](http://www.w3.org/2004/02/skos/core#)
- `dcterms`: [http://purl.org/dc/terms/](http://purl.org/dc/terms/)
- `schema`: [http://schema.org/](http://schema.org/)
- `credential-proof-of-participation`: [https://w3id.org/axone/ontology/v4/schema/credential/proof-of-participation/](https://w3id.org/axone/ontology/v4/schema/credential/proof-of-participation/)

## Verifiable Credential

> **IRI**: [credential-proof-of-participation:ProofOfParticipationCredential](https://w3id.org/axone/ontology/v4/schema/credential/proof-of-participation/ProofOfParticipationCredential)
### Description

A Verifiable Credential attesting that a participant has taken part in a specific event.

The event is linked using `:participatedIn`, which references an instance of [schema:Event](https://schema.org/Event) (e.g.,
`schema:Hackathon` or `schema:DeliveryEvent` for token airdrops).

### Examples

```json title="katai-proof-of-participation.jsonld"
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/axone/ontology/v4/schema/credential/proof-of-participation/",
"https://schema.org"
],
"type": [
"VerifiableCredential",
"ProofOfParticipationCredential"
],
"id": "https://credentials.axone.xyz/proof-of-participation/katai/42",
"credentialSubject": {
"id": "urn:addr:axone1y6wwdp0gmgnj6hf0jt0r67axhw0fp5dsq37ccv",
"participatedIn": {
"id": "https://play.katai.axone.xyz/sprints/c5295c01-8381-4747-b7be-c7b12dc3b918",
"name": "KatAI | Community-Driven Kat Art, AI & Rewards",
"startDate": "2025-01-08T17:00:00.000Z",
"endDate": "2025-01-29T16:59:59.000Z"
}
},
"issuanceDate": "2025-01-11T19:14:24.344904+01:00",
"issuer": {
"id": "did:key:zQ3shs7auhJSmVJpiUbQWco6bxxEhSqWnVEPvaBHBRvBKw6Q3",
"name": "Axone"
}
}

```

### Properties

#### Participated in
>
> **IRI**: [credential-proof-of-participation:participatedIn](https://w3id.org/axone/ontology/v4/schema/credential/proof-of-participation/participatedIn)
>
> **Domain**: [credential-proof-of-participation:ProofOfParticipationCredential](https://w3id.org/axone/ontology/v4/schema/credential/proof-of-participation/ProofOfParticipationCredential)
>
> **Range**: [schema:Event](http://schema.org/Event)
Links the Proof of Participation Credential to the event the participant took part in.

The event can be any instance of [schema:Event](https://schema.org/Event).
2 changes: 1 addition & 1 deletion docs/schemas/credential-zone-description.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 9
sidebar_position: 10
---
[//]: # (This file is auto-generated. Please do not modify it yourself.)

Expand Down
30 changes: 14 additions & 16 deletions script/cli/nquads.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

import click
from pyld import jsonld
from rdflib import Namespace

SCHEMA = Namespace("http://schema.org/")
AXONE = Namespace("https://w3id.org/axone/ontology/")
DEFAULT_CONTEXT_MAPPING = {
"https://schema.org": "https://schema.org/docs/jsonldcontext.jsonld"
}


def convert_nquads(input_file: Union[str, os.PathLike], output_file: TextIO,
context_folder: Optional[Union[str, os.PathLike]] = None, algorithm: str = "URGNA2012") -> None:
"""Converts a JSON-LD schema to N-Quads format."""
context_mapping = create_context_mapping(context_folder)
context_mapping = create_context_mapping(context_folder, DEFAULT_CONTEXT_MAPPING)

click.echo(f"🔬 Loading graph from {input_file}")
normalized = jsonld.normalize(
Expand All @@ -30,9 +30,9 @@ def convert_nquads(input_file: Union[str, os.PathLike], output_file: TextIO,
output_file.write(normalized)


def create_context_mapping(context_folder: Optional[Union[str, os.PathLike]]) -> Dict[str, str]:
def create_context_mapping(context_folder: Optional[Union[str, os.PathLike]], default_context_mapping: Dict[str, str] = {}) -> Dict[str, str]:
"""Creates a JSON-LD context mapping from files in the specified folder."""
context = {}
context_mapping = default_context_mapping.copy()

if context_folder:
context_folder = str(context_folder)
Expand All @@ -42,21 +42,19 @@ def create_context_mapping(context_folder: Optional[Union[str, os.PathLike]]) ->
if file.endswith('.jsonld'):
file_path = os.path.join(root, file)
document = jsonld.load_document(f"file://{Path(file_path).resolve()}",
options={'documentLoader': create_custom_document_loader()})
options={'documentLoader': create_custom_document_loader(default_context_mapping)})
uri = extract_context_uri(document)
if uri:
click.echo(f"📌 Mapping: {uri}{file}")
context[uri] = file_path
context_mapping[uri] = f"file://{file_path}"

return context
return context_mapping


def create_custom_document_loader(context_mapping: Optional[Dict[str, str]] = None) -> Callable[[str, Dict[str, str]], Dict[str, Union[str, None]]]:
def create_custom_document_loader(context_mapping: Dict[str, str] = {}) -> Callable[[str, Dict[str, str]], Dict[str, Union[str, None]]]:
"""Creates a custom document loader for JSON-LD which supports local file Axone URIs."""
if context_mapping is None:
context_mapping = {}

def loader(url: str, options: Dict[str, str] = {}) -> Dict[str, Union[str, None]]:
click.echo(f"🛜 Resolving: {url}")
if url.startswith("file://"):
path = url[7:]
with open(path, 'r') as f:
Expand All @@ -67,8 +65,7 @@ def loader(url: str, options: Dict[str, str] = {}) -> Dict[str, Union[str, None]
'contextUrl': None
}
elif url in context_mapping:
local_path = context_mapping[url]
return loader(f"file://{local_path}")
return loader(context_mapping[url])
else:
return jsonld.requests_document_loader()(url, options=options)

Expand All @@ -85,7 +82,8 @@ def extract_context_uri(document: Dict) -> Optional[str]:
elif isinstance(context, list):
return context[0] if context else None
elif isinstance(context, dict):
first_id = next((v.get('@id') for v in context.values() if isinstance(v, dict) and '@id' in v), None)
first_id = next((v.get('@id') for v in context.values()
if isinstance(v, dict) and '@id' in v), None)
if first_id:
match = re.match(r'(.*/).*', first_id)
return match.group(1) if match else None
Expand Down
26 changes: 26 additions & 0 deletions src/example/participation/katai-proof-of-participation.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/axone/ontology/v$major/schema/credential/proof-of-participation/",
"https://schema.org"
],
"type": [
"VerifiableCredential",
"ProofOfParticipationCredential"
],
"id": "https://credentials.axone.xyz/proof-of-participation/katai/42",
"credentialSubject": {
"id": "urn:addr:axone1y6wwdp0gmgnj6hf0jt0r67axhw0fp5dsq37ccv",
"participatedIn": {
"id": "https://play.katai.axone.xyz/sprints/c5295c01-8381-4747-b7be-c7b12dc3b918",
"name": "KatAI | Community-Driven Kat Art, AI & Rewards",
"startDate": "2025-01-08T17:00:00.000Z",
"endDate": "2025-01-29T16:59:59.000Z"
}
},
"issuanceDate": "2025-01-11T19:14:24.344904+01:00",
"issuer": {
"id": "did:key:zQ3shs7auhJSmVJpiUbQWco6bxxEhSqWnVEPvaBHBRvBKw6Q3",
"name": "Axone"
}
}
25 changes: 25 additions & 0 deletions src/schema/participation/credential-proof-of-participation.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix : <https://w3id.org/axone/ontology/v$major/schema/credential/proof-of-participation/> .
@prefix schema: <http://schema.org/> .

:ProofOfParticipationCredential a rdfs:Class ;
rdfs:label "Proof of Participation Credential"@en ;
rdfs:comment """
A Verifiable Credential attesting that a participant has taken part in a specific event.
The event is linked using `:participatedIn`, which references an instance of [schema:Event](https://schema.org/Event) (e.g.,
`schema:Hackathon` or `schema:DeliveryEvent` for token airdrops).
"""@en .

:participatedIn a rdf:Property ;
rdfs:label "participated in"@en ;
rdfs:comment """
Links the Proof of Participation Credential to the event the participant took part in.
The event can be any instance of [schema:Event](https://schema.org/Event).
"""@en ;
schema:domainIncludes :ProofOfParticipationCredential ;
schema:rangeIncludes schema:Event .


0 comments on commit 612ef77

Please sign in to comment.