Skip to content

Serializers

Info

This reference defines the necessary types required to handle SEP-001 serialization. It provides the implementation details for handling serialization based on the specification's guidelines for each strategy. Please see more about serializers spec.

Compact(standard)

JWS Compact serializer implementation.

Initialize a new instance with the standard implementation.

Parameters:

Name Type Description Default
standard Standard

Standard object

required
Source code in nucleus/sdk/expose/marshall.py
 97
 98
 99
100
101
102
103
104
105
106
def __init__(self, standard: Standard):
    """Initialize a new instance with the standard implementation.

    :param standard: Standard object
    """

    raw_payload = standard.payload()
    self._header = standard.header()
    self._claims = list(map(bytes, map(JSON, raw_payload.values())))
    self._payload = self._payload_cid_values(raw_payload)

__bytes__()

Return compact serialization as bytes.

Returns:

Type Description
bytes
Source code in nucleus/sdk/expose/marshall.py
175
176
177
178
179
180
def __bytes__(self) -> bytes:
    """Return compact serialization as bytes.

    :return:
    """
    return bytes(self._payload)

__iter__()

Yield typ headers specified in SEP-001 standard.

Returns:

Type Description
Setting

The iterable media type settings

Source code in nucleus/sdk/expose/marshall.py
161
162
163
164
165
166
def __iter__(self) -> Setting:
    """Yield `typ` headers specified in SEP-001 standard.

    :return: The iterable media type settings
    """
    return iter(self._header.items())

__str__()

Return compact serialization as string.

Returns:

Type Description
str
Source code in nucleus/sdk/expose/marshall.py
168
169
170
171
172
173
def __str__(self) -> str:
    """Return compact serialization as string.

    :return:
    """
    return self._s11n

save_to(store)

Publishes Compact serialization into the local store.

Parameters:

Name Type Description Default
store Store

The Store function

required

Returns:

Type Description
Object
Source code in nucleus/sdk/expose/marshall.py
147
148
149
150
151
152
153
154
155
156
157
158
159
def save_to(self, store: Store) -> Object:
    """Publishes Compact serialization into the local store.

    :param store: The Store function
    :return:
    """

    # 1. store claims in blocks
    for claim in self._claims:
        store(claim)

    # 2. store serialization and return
    return store(self._s11n)

update(jwt)

Acts as an observer, waiting for events triggered by any cryptographic operation. Encodes JWS/JWE to compact serialization when a cryptographic operation notifies.

Parameters:

Name Type Description Default
jwt JWT

The JWT implementation passed by the cryptographic operation.

required

Returns:

Type Description
Compact

The compact serialization string.

Source code in nucleus/sdk/expose/marshall.py
136
137
138
139
140
141
142
143
144
145
def update(self, jwt: JWT) -> Compact:
    """Acts as an observer, waiting for events triggered by any cryptographic operation.
    Encodes JWS/JWE to compact serialization when a cryptographic operation notifies.

    :param jwt: The JWT implementation passed by the cryptographic operation.
    :return: The compact serialization string.
    """
    # set new state for serialization attribute
    self._s11n = jwt.serialize(True)
    return self

DagJose(standard)

Dag-JOSE serializer implementation.

Initialize a new instance with the standard implementation.

Parameters:

Name Type Description Default
standard Standard

Standard object

required
Source code in nucleus/sdk/expose/marshall.py
34
35
36
37
38
39
40
41
def __init__(self, standard: Standard):
    """Initialize a new instance with the standard implementation.

    :param standard: Standard object
    """
    self._header = standard.header()
    self._cbor = dag_cbor.encode(standard.payload())
    self._cid = _cid_from_bytes(self._cbor, 'dag-cbor')

__bytes__()

Return DAG-JOSE serialization as bytes.

Returns:

Type Description
bytes
Source code in nucleus/sdk/expose/marshall.py
57
58
59
60
61
62
def __bytes__(self) -> bytes:
    """Return DAG-JOSE serialization as bytes.

    :return:
    """
    return bytes(self._cid)

__iter__()

Yield typ headers specified in SEP-001 standard.

Returns:

Type Description
Setting

The iterable media type settings

Source code in nucleus/sdk/expose/marshall.py
43
44
45
46
47
48
def __iter__(self) -> Setting:
    """Yield `typ` headers specified in SEP-001 standard.

    :return: The iterable media type settings
    """
    return iter(self._header.items())

__str__()

Return DAG-JOSE serialization as string.

Returns:

Type Description
str
Source code in nucleus/sdk/expose/marshall.py
50
51
52
53
54
55
def __str__(self) -> str:
    """Return DAG-JOSE serialization as string.

    :return:
    """
    return str(self._s11n)

save_to(store)

Publishes DAG-JOSE into the local store.

Parameters:

Name Type Description Default
store Store

The Store function

required

Returns:

Type Description
Object
Source code in nucleus/sdk/expose/marshall.py
76
77
78
79
80
81
82
83
84
85
86
def save_to(self, store: Store) -> Object:
    """Publishes DAG-JOSE into the local store.

    :param store: The Store function
    :return:
    """

    # 1. store cbor in blocks
    # 2. store serialization and return
    store(self._cbor)
    return store(self._s11n)

update(jwt)

Acts as an observer, waiting for events triggered by any cryptographic operation. Encodes JWS/JWE to DAG-JOSE serialization when a cryptographic operation notifies.

Parameters:

Name Type Description Default
jwt JWT

The JWT implementation passed by the cryptographic operation.

required

Returns:

Type Description
DagJose

The DAG-JOSE serialization format.

Source code in nucleus/sdk/expose/marshall.py
64
65
66
67
68
69
70
71
72
73
74
def update(self, jwt: JWT) -> DagJose:
    """Acts as an observer, waiting for events triggered by any cryptographic operation.
    Encodes JWS/JWE to DAG-JOSE serialization when a cryptographic operation notifies.

    :param jwt: The JWT implementation passed by the cryptographic operation.
    :return: The DAG-JOSE serialization format.
    """
    general_json = json_decode(jwt.serialize(False))
    # set new state for serialization attribute
    self._s11n = JSON({'link': self._cid, **general_json})
    return self