-
-
Notifications
You must be signed in to change notification settings - Fork 768
Expand file tree
/
Copy pathevolu.py
More file actions
126 lines (107 loc) · 3.6 KB
/
evolu.py
File metadata and controls
126 lines (107 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# This file is part of the Trezor project.
#
# Copyright (C) 2012-2025 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
import click
from .. import evolu
from . import with_session
if TYPE_CHECKING:
from ..client import Session
@click.group(name="evolu")
def cli() -> None:
"""Evolu commands. Evolu is a local first storage framework. See https://github.com/evoluhq/evolu"""
@cli.command()
@click.argument("proof", type=str)
@click.option("--node_index", "-i", type=int, default=0)
@with_session
def get_node(
session: Session,
proof: str,
node_index: int,
) -> str:
"""Return the SLIP-21 node for Evolu."""
proof_bytes = bytes.fromhex(proof)
return evolu.get_node(
session,
proof=proof_bytes,
node_rotation_index=node_index,
).hex()
@cli.command()
@click.argument("proof", type=str)
@click.argument("challenge", type=str)
@click.option("--size", "-s", type=int, default=1048576) # 1 MB
@with_session
def sign_registration_request(
session: Session,
proof: str,
challenge: str,
size: int,
) -> dict[str, str]:
"""Sign a registration request for this device to be registered at the Quota Manager server."""
response = evolu.sign_registration_request(
session=session,
challenge=bytes.fromhex(challenge),
size=size,
proof=bytes.fromhex(proof),
)
return {
"certificates": ",".join([cert.hex() for cert in response.certificate_chain]),
"signature": response.signature.hex(),
}
@click.option("--credential", "-c", type=str)
@click.option("--rotation_index", "-i", type=int)
@click.option("--rotate", is_flag=True, help="Rotate the delegated identity key.")
@cli.command()
@with_session
def get_delegated_identity_key(
session: Session,
credential: Optional[str] = None,
rotation_index: Optional[int] = None,
rotate: bool = False,
) -> dict[str, str | int | None]:
"""
Request the delegated identity key of this device.
This key is used to prove the identity of the device at the Quota Manager server and to prove
to Trezor that this host has been given trust by the user to manage the Suite Sync.
"""
thp_credential = bytes.fromhex(credential) if credential else None
response = evolu.get_delegated_identity_key(
session=session,
rotation_index=rotation_index,
thp_credential=thp_credential,
rotate=rotate,
)
return {
"key": response.private_key.hex(),
"rotation_index": response.rotation_index,
}
@cli.command()
@click.option("--rotation_index", "-i", type=int)
@with_session
def index_management(
session: Session,
rotation_index: Optional[int] = None,
) -> str:
"""
Set the optional delegated identity key rotation index if unset.
Use --rotation_index to provide the value; returns the current index as a string.
"""
return str(
evolu.index_management(
session,
rotation_index=rotation_index,
).rotation_index
)