Skip to content

bovine.activitystreams.controller

bovine.activitystreams.controller

Controller dataclass

Experimental class to represent a controller document see FEP-521a.

See also the recent W3C Draft: Controller Documents

>>> multikey = Multikey(
... id="https://server.example/users/alice#ed25519-key",
... controller="https://server.example/users/alice",
... multibase="z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2")
>>> Controller(assertion_method=[multikey]).build()
{'@context': ['https://www.w3.org/ns/did/v1',
    'https://w3id.org/security/multikey/v1'],
    'assertionMethod':
        [{'id': 'https://server.example/users/alice#ed25519-key',
        'type': 'Multikey',
        'controller': 'https://server.example/users/alice',
        'publicKeyMultibase': 'z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2'}]}

Parameters:

Name Type Description Default
assertion_method List[Multikey]

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

<dynamic>
authentication List[Multikey]

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

<dynamic>
Source code in bovine/bovine/activitystreams/controller.py
@dataclass
class Controller:
    """Experimental class to represent a controller document
    see [FEP-521a](https://codeberg.org/fediverse/fep/src/branch/main/fep/521a/fep-521a.md).

    See also the recent W3C Draft: [Controller Documents](https://www.w3.org/TR/controller-document/)

    ```pycon
    >>> multikey = Multikey(
    ... id="https://server.example/users/alice#ed25519-key",
    ... controller="https://server.example/users/alice",
    ... multibase="z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2")
    >>> Controller(assertion_method=[multikey]).build()
    {'@context': ['https://www.w3.org/ns/did/v1',
        'https://w3id.org/security/multikey/v1'],
        'assertionMethod':
            [{'id': 'https://server.example/users/alice#ed25519-key',
            'type': 'Multikey',
            'controller': 'https://server.example/users/alice',
            'publicKeyMultibase': 'z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2'}]}

    ```
    """

    assertion_method: List[Multikey] = field(default_factory=list)
    authentication: List[Multikey] = field(default_factory=list)

    def build(self):
        """Creates the controller document. Currently only assertion_method is supported"""
        if len(self.assertion_method) == 0:
            return {}

        return {
            "@context": [
                "https://www.w3.org/ns/did/v1",
                "https://w3id.org/security/multikey/v1",
            ],
            "assertionMethod": [
                key.build(include_context=False) for key in self.assertion_method
            ],
        }

build

build()

Creates the controller document. Currently only assertion_method is supported

Source code in bovine/bovine/activitystreams/controller.py
def build(self):
    """Creates the controller document. Currently only assertion_method is supported"""
    if len(self.assertion_method) == 0:
        return {}

    return {
        "@context": [
            "https://www.w3.org/ns/did/v1",
            "https://w3id.org/security/multikey/v1",
        ],
        "assertionMethod": [
            key.build(include_context=False) for key in self.assertion_method
        ],
    }

Multikey dataclass

Represents a Multikey

Parameters:

Name Type Description Default
id str
required
controller str
required
multibase str
required
type str
'Multikey'
Source code in bovine/bovine/activitystreams/controller.py
@dataclass
class Multikey:
    """Represents a Multikey"""

    id: str
    controller: str
    multibase: str
    type: str = "Multikey"

    def build(self, include_context=True):
        result = {
            "id": self.id,
            "type": self.type,
            "controller": self.controller,
            "publicKeyMultibase": self.multibase,
        }
        if include_context:
            result["@context"] = "https://w3id.org/security/multikey/v1"
        return result

    @staticmethod
    def from_multibase_and_controller(controller, multibase):
        return Multikey(
            id=f"{controller}#{multibase}", controller=controller, multibase=multibase
        )