Skip to content

Commit d6a25d0

Browse files
committed
Documentation.
1 parent f0e3564 commit d6a25d0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/moeralib/crypto/crypto.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def raw_private_key(private_key: ec.EllipticCurvePrivateKey) -> bytes:
6262

6363

6464
def raw_to_private_key(raw_private_key: bytes) -> ec.EllipticCurvePrivateKey:
65+
"""
66+
Restore a private key from the raw format.
67+
68+
:param raw_private_key: the raw private key
69+
:return: the private key
70+
"""
6571
return ec.derive_private_key(int.from_bytes(raw_private_key, 'big'), ec.SECP256K1())
6672

6773

src/moeralib/node/cartes.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def __init__(self, node: MoeraNode, client_scope: List[Scope] | None = None, adm
2929
target_node_name: str | None = None):
3030
"""
3131
:param node: node to get cartes from
32+
:param client_scope: permissions to be granted to the carte; if not set, all permissions of the carte's owner
33+
are granted
34+
:param admin_scope: additional administrative permissions (of those granted to the carte's owner by the target
35+
node) to be granted to the carte
3236
"""
3337
self._node = node
3438
self._client_scope = client_scope if client_scope is not None else ["all"]
@@ -71,8 +75,22 @@ def to_scope_mask(scope: List[Scope]) -> int:
7175

7276

7377
def generate_carte(owner_name: str | None, signing_key: ec.EllipticCurvePrivateKey, beginning: Timestamp | None,
74-
address: str | None = None, ttl: int = 600, node_name: str | None = None,
78+
ttl: int = 600, address: str | None = None, node_name: str | None = None,
7579
client_scope: List[Scope] | int = SCOPE_VALUES["all"], admin_scope: List[Scope] | int = 0) -> str:
80+
"""
81+
Generate a carte with the given parameters and sign it with the provided private signing key.
82+
83+
:param owner_name: name of the node authenticating with the carte
84+
:param signing_key: the private signing key to sign the carte
85+
:param beginning: timestamp of the beginning of the carte's life
86+
:param ttl: length of the carte's life, in seconds
87+
:param address: if set, the carte is valid for authentication from the given IP address only
88+
:param node_name: if set, the carte is valid for authentication on the specified node only
89+
:param client_scope: list of permissions granted to the carte
90+
:param admin_scope: list of additional administrative permissions (of those granted to the carte's owner by
91+
the target node) granted to the carte
92+
:return: the carte
93+
"""
7694
if isinstance(client_scope, list):
7795
client_scope = to_scope_mask(client_scope)
7896
if isinstance(admin_scope, list):

0 commit comments

Comments
 (0)