Skip to content

Keys

Info

This reference provides a detailed implementation of the keyring types included in the SDK. All of these keyrings are based on the JWK (JSON Web Key) standard defined in RFC 7517. For more information about the keyring specification, please refer to the keyring spec.

SignKeyRing dataclass

__iter__()

Yield alg and jwk headers specified in RFC 7517-7516 standard.

Returns:

Type Description
Setting

The iterable header settings to associate

Source code in nucleus/sdk/expose/key.py
70
71
72
73
74
75
76
def __iter__(self) -> Setting:
    """Yield `alg` and `jwk` headers specified in RFC 7517-7516 standard.

    :return: The iterable header settings to associate
    """
    yield 'alg', self.alg.value
    yield 'jwk', self._jwk.export_public(True)

as_dict()

Exports the key in the standard JSON format.

Returns:

Type Description
Raw

A portable representation of the key in JWK format.

Source code in nucleus/sdk/expose/key.py
109
110
111
112
113
114
def as_dict(self) -> Raw:
    """Exports the key in the standard JSON format.

    :return: A portable representation of the key in JWK format.
    """
    return self._jwk.export(True, True)  # type: ignore

fingerprint()

Return the base64 decoded thumbprint as specified by RFC 7638.

Returns:

Type Description
str

The decoded sha256 thumbprint.

Source code in nucleus/sdk/expose/key.py
131
132
133
134
135
136
137
138
def fingerprint(self) -> str:
    """Return the base64 decoded thumbprint as specified by RFC 7638.

    :return: The decoded sha256 thumbprint.
    """
    b64_thumbprint = self._jwk.thumbprint()
    decoded_thumbprint = base64url_decode(b64_thumbprint)
    return decoded_thumbprint.hex()

from_dict(jwk) classmethod

Creates a Keyring object from a JWK (JSON Web Key) dictionary.

Parameters:

Name Type Description Default
jwk Raw

The JWK dictionary to import

required

Returns:

Type Description
SignKeyRing

SignKeyRing object

Source code in nucleus/sdk/expose/key.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@classmethod
def from_dict(cls, jwk: Raw) -> SignKeyRing:
    """Creates a Keyring object from a JWK (JSON Web Key) dictionary.

    :param jwk: The JWK dictionary to import
    :return: SignKeyRing object
    """

    allowed_fields = set([f.name for f in dataclasses.fields(cls)])
    fields = {k: v for k, v in jwk.items() if k in allowed_fields}

    key = cls(**{**fields, **{'_lazy_mode': True}})
    key.import_key(jwk)
    return key

import_key(jwk)

Restore the internal key associated with a JWK (JSON Web Key).

Parameters:

Name Type Description Default
jwk Raw

The JWK to restore.

required

Returns:

Type Description
SignKeyRing

SignKeyRing object

Source code in nucleus/sdk/expose/key.py
 98
 99
100
101
102
103
104
105
106
107
def import_key(self, jwk: Raw) -> SignKeyRing:
    """Restore the internal key associated with a JWK (JSON Web Key).

    :param jwk: The JWK to restore.
    :return: SignKeyRing object

    """
    json_string = str(JSON(jwk))
    self._jwk = JWK.from_json(json_string)
    return self

jwk()

Return the internal JWK (JSON Web Key) instance

Returns:

Type Description
JWK

The JWK (JSON Web Key) instance

Source code in nucleus/sdk/expose/key.py
91
92
93
94
95
96
def jwk(self) -> JWK:
    """Return the internal JWK (JSON Web Key) instance

    :return: The JWK (JSON Web Key) instance
    """
    return self._jwk