commit c645a4049f14708d5f71761b52c2649229bacac3
Author: lash <dev@holbrook.no>
Date: Tue, 23 Sep 2025 23:38:44 +0100
Initial commit
Diffstat:
11 files changed, 223 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,3 @@
+__pycache__
+*.egg-info
+build
diff --git a/adesse/__init__.py b/adesse/__init__.py
@@ -0,0 +1,2 @@
+from .base import Serializer
+from .entity import Entity
diff --git a/adesse/base.py b/adesse/base.py
@@ -0,0 +1,26 @@
+from rdflib import Graph
+from rdflib.namespace import NamespaceManager
+from rdflib.namespace import FOAF, XSD, PROV, DC, DCTERMS
+
+from .ns import DF, COUNTRY, PSS
+
+
+class Serializer:
+
+ def __init__(self):
+ self.g = Graph()
+ self.ns = NamespaceManager(self.g)
+ self.ns.bind('dc', DC)
+ self.ns.bind('prov', PROV)
+ self.ns.bind('xsd', XSD)
+ self.ns.bind('df', DF)
+ self.ns.bind('pss', PSS)
+ self.ns.bind('iso3316', COUNTRY)
+
+
+ def add(self, o):
+ self.g.add(o)
+
+
+ def __str__(self):
+ return self.g.serialize(format='xml')
diff --git a/adesse/bundle.py b/adesse/bundle.py
@@ -0,0 +1,8 @@
+from .base import Base
+
+
+class Bundle:
+
+ def __init__(self, crt):
+ self.cert = crt
+ self.witness = []
diff --git a/adesse/cert.py b/adesse/cert.py
@@ -0,0 +1,24 @@
+from .uri import to_uuid_uri
+from .base import DF
+from .entity import Entity
+
+
+class Cert(Entity):
+
+ def __init__(self, subj, obj, agent, uu=None):
+ super().__init__(uu=uu)
+ self.subject = subj
+ self.object = obj
+ self.agent = agent
+
+
+ def apply(self, g):
+ uu = to_uuid_uri(self.uu)
+ o = self.subject.to_ref()
+ g.add((uu, DF.subject, o))
+ o = self.object.to_ref()
+ g.add((uu, DF.object, o))
+ o = self.agent.to_ref()
+ g.add((uu, DF.agent, o))
+
+ self.subject.apply(g)
diff --git a/adesse/entity.py b/adesse/entity.py
@@ -0,0 +1,19 @@
+import uuid
+import datetime
+
+from .uri import to_uuid_uri
+
+
+class Entity:
+
+ def __init__(self, uu=None):
+ if not uu:
+ uu = uuid.uuid4()
+ elif not isinstance(uu, uuid.UUID):
+ raise ValueError("not uuid")
+ self.uu = uu
+ self.dt = datetime.datetime.now()
+
+
+ def to_ref(self):
+ return to_uuid_uri(self.uu)
diff --git a/adesse/ns.py b/adesse/ns.py
@@ -0,0 +1,27 @@
+from rdflib.namespace import Namespace, DefinedNamespace
+from rdflib.term import URIRef
+
+COUNTRY = Namespace('http://www.iso.org/obp/ui/#iso:code:3166:')
+
+class DF(DefinedNamespace):
+ subject: URIRef
+ object: URIRef
+ agent: URIRef
+
+ _NS = Namespace('http://defalsify.org/rdf/0.1/core/')
+
+
+class PSS(DefinedNamespace):
+
+ Topic: URIRef
+ Nationality: URIRef
+ ResidenceCountry: URIRef
+
+ _NS = Namespace('http://standards.internetofproduction.org/pub/r7g0n9fo/release/4')
+
+
+class WOT(DefinedNamespace):
+
+ PubKey: URIRef
+
+ _NS = Namespace('http://xmlns.com/wot/0.1/#')
diff --git a/adesse/person.py b/adesse/person.py
@@ -0,0 +1,32 @@
+from rdflib import Literal
+from rdflib.namespace import FOAF, DCTERMS, XSD
+
+from .entity import Entity
+from .ns import PSS
+from .uri import to_uuid_uri, to_country_uri
+
+
+class Person(Entity):
+
+ def __init__(self, firstname, lastname, nationality, residence_country=None, common_name=None, uu=None):
+ super().__init__(uu=uu)
+ self.firstname = firstname
+ self.lastname = lastname
+ self.nationality = nationality
+ if residence_country:
+ self.residence_country = residence_country
+ else:
+ self.residence_country = nationality
+ if common_name:
+ self.common_name = common_name
+ else:
+ self.common_name = self.firstname + ' ' + self.lastname
+
+ def apply(self, g):
+ uu = to_uuid_uri(self.uu)
+ g.add((uu, FOAF.givenName, Literal(self.firstname)))
+ g.add((uu, FOAF.familyName, Literal(self.lastname)))
+ g.add((uu, FOAF.name, Literal(self.common_name)))
+ g.add((uu, PSS.Nationality, to_country_uri(self.nationality)))
+ g.add((uu, PSS.ResidenceCountry, to_country_uri(self.residence_country)))
+ g.add((uu, DCTERMS.created, Literal(self.dt.isoformat(), datatype=XSD.DateTime)))
diff --git a/adesse/uri.py b/adesse/uri.py
@@ -0,0 +1,31 @@
+from uuid import UUID
+
+from iso3166 import countries
+from rdflib import Literal
+from rdflib.namespace import Namespace
+from rdflib.namespace import URIPattern
+from rdflib.namespace import URIRef
+from rdflib.namespace import XSD
+
+from .ns import COUNTRY
+
+uu = URIPattern("URN:uuid:%s")
+
+def to_uuid_uri(u):
+ if not u:
+ raise ValueError("undefined uuid")
+ if not isinstance(u, UUID):
+ raise ValueError("not uuid: %s", u)
+ return uu%(str(u))
+
+
+def to_country_uri(s):
+ v = None
+ try:
+ v = countries.get(s)
+ except KeyError:
+ pass
+ if v == None:
+ raise ValueError('invalid country: ' + s)
+ #return URIRef(v.alpha2, datatype=XSD.Datetime)
+ return COUNTRY[v.alpha2]
diff --git a/pyproject.toml b/pyproject.toml
@@ -0,0 +1,26 @@
+[build-system]
+requires = ["setuptools>=61.0"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "adesse"
+version = "0.0.1"
+description = "Signed "
+requires-python = ">=3.8"
+dependencies = [
+ "lxml~=6.0.1",
+ "rdflib~=7.2.1",
+ "iso3166~=2.1.1",
+]
+
+[project.scripts]
+ungana = "adesse.runnable.cmd:main"
+
+[tool.setuptools.packages.find]
+where = ["."]
+include = ["adresse*"]
+
+[tool.setuptools.package-data]
+ungana = [
+ "adesse/data/*"
+]
diff --git a/test/test_serialize.py b/test/test_serialize.py
@@ -0,0 +1,25 @@
+import unittest
+
+from adesse import Serializer, Entity
+from adesse.person import Person
+from adesse.cert import Cert
+
+
+class TestSerialize(unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+
+ def test_serialize(self):
+ z = Serializer()
+ subj = Person("Melvin", "Ferd", "SV", common_name="Melvin B. Ferd")
+ obj = Entity()
+ agent = Entity()
+ c = Cert(subj, obj, agent)
+ c.apply(z)
+ print(str(z))
+
+
+if __name__ == '__main__':
+ unittest.main()