Skip to content

Commit 6f7a930

Browse files
committed
raw_to_public_key() function added.
1 parent d6a25d0 commit 6f7a930

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/moeralib/crypto/crypto.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ def raw_public_key(public_key: ec.EllipticCurvePublicKey) -> bytes:
5151
return numbers.x.to_bytes(32, 'big') + numbers.y.to_bytes(32, 'big')
5252

5353

54+
def raw_to_public_key(raw_public_key: bytes) -> ec.EllipticCurvePublicKey:
55+
"""
56+
Restore a public key from the raw format.
57+
58+
:param raw_public_key: the raw public key
59+
:return: the public key
60+
"""
61+
x = int.from_bytes(raw_public_key[:32], 'big')
62+
y = int.from_bytes(raw_public_key[32:], 'big')
63+
return ec.EllipticCurvePublicNumbers(x, y, ec.SECP256K1()).public_key()
64+
65+
5466
def raw_private_key(private_key: ec.EllipticCurvePrivateKey) -> bytes:
5567
"""
5668
Convert a private key to the raw format to pass to the client.

src/moeralib/node/cartes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ 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
32+
:param client_scope: permissions to be granted to the cartes; if not set, all permissions of the cartes' owner
3333
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
34+
:param admin_scope: additional administrative permissions (of those granted to the cartes' owner by the target
35+
node) to be granted to the cartes
36+
:param target_node_name: if set, the cartes are valid for authentication on the specified node only
3637
"""
3738
self._node = node
3839
self._client_scope = client_scope if client_scope is not None else ["all"]

0 commit comments

Comments
 (0)