Clean api types
This commit is contained in:
parent
69087f2854
commit
cf2c26e99b
@ -1,211 +1,331 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Self
|
from typing import Optional, Self
|
||||||
|
|
||||||
|
from . import types
|
||||||
|
from .state import VeilidState
|
||||||
|
|
||||||
from .state import *
|
|
||||||
from .config import *
|
|
||||||
from .error import *
|
|
||||||
from .types import *
|
|
||||||
|
|
||||||
class RoutingContext(ABC):
|
class RoutingContext(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def with_privacy(self) -> Self:
|
async def with_privacy(self) -> Self:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def with_custom_privacy(self, stability: Stability) -> Self:
|
@abstractmethod
|
||||||
|
async def with_custom_privacy(self, stability: types.Stability) -> Self:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def with_sequencing(self, sequencing: Sequencing) -> Self:
|
@abstractmethod
|
||||||
|
async def with_sequencing(self, sequencing: types.Sequencing) -> Self:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def app_call(self, target: TypedKey | RouteId, request: bytes) -> bytes:
|
@abstractmethod
|
||||||
|
async def app_call(
|
||||||
|
self, target: types.TypedKey | types.RouteId, request: bytes
|
||||||
|
) -> bytes:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def app_message(self, target: TypedKey | RouteId, message: bytes):
|
@abstractmethod
|
||||||
|
async def app_message(self, target: types.TypedKey | types.RouteId, message: bytes):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def create_dht_record(self, kind: CryptoKind, schema: DHTSchema) -> DHTRecordDescriptor:
|
@abstractmethod
|
||||||
|
async def create_dht_record(
|
||||||
|
self, kind: types.CryptoKind, schema: types.DHTSchema
|
||||||
|
) -> types.DHTRecordDescriptor:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def open_dht_record(self, key: TypedKey, writer: Optional[KeyPair]) -> DHTRecordDescriptor:
|
@abstractmethod
|
||||||
|
async def open_dht_record(
|
||||||
|
self, key: types.TypedKey, writer: Optional[types.KeyPair]
|
||||||
|
) -> types.DHTRecordDescriptor:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def close_dht_record(self, key: TypedKey):
|
@abstractmethod
|
||||||
|
async def close_dht_record(self, key: types.TypedKey):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def delete_dht_record(self, key: TypedKey):
|
@abstractmethod
|
||||||
|
async def delete_dht_record(self, key: types.TypedKey):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def get_dht_value(self, key: TypedKey, subkey: ValueSubkey, force_refresh: bool) -> Optional[ValueData]:
|
@abstractmethod
|
||||||
|
async def get_dht_value(
|
||||||
|
self, key: types.TypedKey, subkey: types.ValueSubkey, force_refresh: bool
|
||||||
|
) -> Optional[types.ValueData]:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def set_dht_value(self, key: TypedKey, subkey: ValueSubkey, data: bytes) -> Optional[ValueData]:
|
@abstractmethod
|
||||||
|
async def set_dht_value(
|
||||||
|
self, key: types.TypedKey, subkey: types.ValueSubkey, data: bytes
|
||||||
|
) -> Optional[types.ValueData]:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def watch_dht_values(self, key: TypedKey, subkeys: list[(ValueSubkey, ValueSubkey)], expiration: Timestamp, count: int) -> Timestamp:
|
@abstractmethod
|
||||||
|
async def watch_dht_values(
|
||||||
|
self,
|
||||||
|
key: types.TypedKey,
|
||||||
|
subkeys: list[tuple[types.ValueSubkey, types.ValueSubkey]],
|
||||||
|
expiration: types.Timestamp,
|
||||||
|
count: int,
|
||||||
|
) -> types.Timestamp:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def cancel_dht_watch(self, key: TypedKey, subkeys: list[(ValueSubkey, ValueSubkey)]) -> bool:
|
@abstractmethod
|
||||||
|
async def cancel_dht_watch(
|
||||||
|
self,
|
||||||
|
key: types.TypedKey,
|
||||||
|
subkeys: list[tuple[types.ValueSubkey, types.ValueSubkey]],
|
||||||
|
) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TableDbTransaction(ABC):
|
class TableDbTransaction(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def commit(self):
|
async def commit(self):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def rollback(self):
|
async def rollback(self):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def store(self, col: int, key: bytes, value: bytes):
|
async def store(self, col: int, key: bytes, value: bytes):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def delete(self, col: int, key: bytes):
|
async def delete(self, col: int, key: bytes):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TableDb(ABC):
|
class TableDb(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def get_column_count(self) -> int:
|
async def get_column_count(self) -> int:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def get_keys(self, col: int) -> list[bytes]:
|
async def get_keys(self, col: int) -> list[bytes]:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def transact(self) -> TableDbTransaction:
|
async def transact(self) -> TableDbTransaction:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def store(self, col: int, key: bytes, value: bytes):
|
async def store(self, col: int, key: bytes, value: bytes):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def load(self, col: int, key: bytes) -> Optional[bytes]:
|
async def load(self, col: int, key: bytes) -> Optional[bytes]:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def delete(self, col: int, key: bytes) -> Optional[bytes]:
|
async def delete(self, col: int, key: bytes) -> Optional[bytes]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CryptoSystem(ABC):
|
class CryptoSystem(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def cached_dh(self, key: PublicKey, secret: SecretKey) -> SharedSecret:
|
async def cached_dh(
|
||||||
|
self, key: types.PublicKey, secret: types.SecretKey
|
||||||
|
) -> types.SharedSecret:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def compute_dh(self, key: PublicKey, secret: SecretKey) -> SharedSecret:
|
@abstractmethod
|
||||||
|
async def compute_dh(
|
||||||
|
self, key: types.PublicKey, secret: types.SecretKey
|
||||||
|
) -> types.SharedSecret:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def random_bytes(self, len: int) -> bytes:
|
async def random_bytes(self, len: int) -> bytes:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def default_salt_length(self) -> int:
|
async def default_salt_length(self) -> int:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def hash_password(self, password: bytes, salt: bytes) -> str:
|
async def hash_password(self, password: bytes, salt: bytes) -> str:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def verify_password(self, password: bytes, password_hash: str) -> bool:
|
async def verify_password(self, password: bytes, password_hash: str) -> bool:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def derive_shared_secret(self, password: bytes, salt: bytes) -> SharedSecret:
|
@abstractmethod
|
||||||
|
async def derive_shared_secret(
|
||||||
|
self, password: bytes, salt: bytes
|
||||||
|
) -> types.SharedSecret:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def random_nonce(self) -> Nonce:
|
@abstractmethod
|
||||||
|
async def random_nonce(self) -> types.Nonce:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def random_shared_secret(self) -> SharedSecret:
|
@abstractmethod
|
||||||
|
async def random_shared_secret(self) -> types.SharedSecret:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def generate_key_pair(self) -> KeyPair:
|
@abstractmethod
|
||||||
|
async def generate_key_pair(self) -> types.KeyPair:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def generate_hash(self, data: bytes) -> HashDigest:
|
@abstractmethod
|
||||||
|
async def generate_hash(self, data: bytes) -> types.HashDigest:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def validate_key_pair(self, key: PublicKey, secret: SecretKey) -> bool:
|
@abstractmethod
|
||||||
|
async def validate_key_pair(
|
||||||
|
self, key: types.PublicKey, secret: types.SecretKey
|
||||||
|
) -> bool:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def validate_hash(self, data: bytes, hash_digest: HashDigest) -> bool:
|
@abstractmethod
|
||||||
|
async def validate_hash(self, data: bytes, hash_digest: types.HashDigest) -> bool:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def distance(self, key1: CryptoKey, key2: CryptoKey) -> CryptoKeyDistance:
|
@abstractmethod
|
||||||
|
async def distance(
|
||||||
|
self, key1: types.CryptoKey, key2: types.CryptoKey
|
||||||
|
) -> types.CryptoKeyDistance:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def sign(self, key: PublicKey, secret: SecretKey, data: bytes) -> Signature:
|
@abstractmethod
|
||||||
|
async def sign(
|
||||||
|
self, key: types.PublicKey, secret: types.SecretKey, data: bytes
|
||||||
|
) -> types.Signature:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def verify(self, key: PublicKey, data: bytes, signature: Signature):
|
@abstractmethod
|
||||||
|
async def verify(
|
||||||
|
self, key: types.PublicKey, data: bytes, signature: types.Signature
|
||||||
|
):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def aead_overhead(self) -> int:
|
async def aead_overhead(self) -> int:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def decrypt_aead(self, body: bytes, nonce: Nonce, shared_secret: SharedSecret, associated_data: Optional[bytes]) -> bytes:
|
@abstractmethod
|
||||||
|
async def decrypt_aead(
|
||||||
|
self,
|
||||||
|
body: bytes,
|
||||||
|
nonce: types.Nonce,
|
||||||
|
shared_secret: types.SharedSecret,
|
||||||
|
associated_data: Optional[bytes],
|
||||||
|
) -> bytes:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def encrypt_aead(self, body: bytes, nonce: Nonce, shared_secret: SharedSecret, associated_data: Optional[bytes]) -> bytes:
|
@abstractmethod
|
||||||
|
async def encrypt_aead(
|
||||||
|
self,
|
||||||
|
body: bytes,
|
||||||
|
nonce: types.Nonce,
|
||||||
|
shared_secret: types.SharedSecret,
|
||||||
|
associated_data: Optional[bytes],
|
||||||
|
) -> bytes:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def crypt_no_auth(self, body: bytes, nonce: Nonce, shared_secret: SharedSecret) -> bytes:
|
@abstractmethod
|
||||||
|
async def crypt_no_auth(
|
||||||
|
self, body: bytes, nonce: types.Nonce, shared_secret: types.SharedSecret
|
||||||
|
) -> bytes:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VeilidAPI(ABC):
|
class VeilidAPI(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def control(self, args: list[str]) -> str:
|
async def control(self, args: list[str]) -> str:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def get_state(self) -> VeilidState:
|
async def get_state(self) -> VeilidState:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def attach(self):
|
async def attach(self):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def detach(self):
|
async def detach(self):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def new_private_route(self) -> Tuple[RouteId, bytes]:
|
@abstractmethod
|
||||||
|
async def new_private_route(self) -> tuple[types.RouteId, bytes]:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def new_custom_private_route(self, kinds: list[CryptoKind], stability: Stability, sequencing: Sequencing) -> Tuple[RouteId, bytes]:
|
@abstractmethod
|
||||||
|
async def new_custom_private_route(
|
||||||
|
self,
|
||||||
|
kinds: list[types.CryptoKind],
|
||||||
|
stability: types.Stability,
|
||||||
|
sequencing: types.Sequencing,
|
||||||
|
) -> tuple[types.RouteId, bytes]:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def import_remote_private_route(self, blob: bytes) -> RouteId:
|
@abstractmethod
|
||||||
|
async def import_remote_private_route(self, blob: bytes) -> types.RouteId:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def release_private_route(self, route_id: RouteId):
|
@abstractmethod
|
||||||
|
async def release_private_route(self, route_id: types.RouteId):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def app_call_reply(self, call_id: OperationId, message: bytes):
|
@abstractmethod
|
||||||
|
async def app_call_reply(self, call_id: types.OperationId, message: bytes):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def new_routing_context(self) -> RoutingContext:
|
async def new_routing_context(self) -> RoutingContext:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def open_table_db(self, name: str, column_count: int) -> TableDb:
|
async def open_table_db(self, name: str, column_count: int) -> TableDb:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def delete_table_db(self, name: str):
|
async def delete_table_db(self, name: str):
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def get_crypto_system(self, kind: CryptoKind) -> CryptoSystem:
|
@abstractmethod
|
||||||
|
async def get_crypto_system(self, kind: types.CryptoKind) -> CryptoSystem:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def best_crypto_system(self) -> CryptoSystem:
|
async def best_crypto_system(self) -> CryptoSystem:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def verify_signatures(self, node_ids: list[TypedKey], data: bytes, signatures: list[TypedSignature]) -> list[TypedKey]:
|
@abstractmethod
|
||||||
|
async def verify_signatures(
|
||||||
|
self,
|
||||||
|
node_ids: list[types.TypedKey],
|
||||||
|
data: bytes,
|
||||||
|
signatures: list[types.TypedSignature],
|
||||||
|
) -> list[types.TypedKey]:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def generate_signatures(self, data: bytes, key_pairs: list[TypedKeyPair]) -> list[TypedSignature]:
|
@abstractmethod
|
||||||
|
async def generate_signatures(
|
||||||
|
self, data: bytes, key_pairs: list[types.TypedKeyPair]
|
||||||
|
) -> list[types.TypedSignature]:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def generate_key_pair(self, kind: CryptoKind) -> list[TypedKeyPair]:
|
@abstractmethod
|
||||||
|
async def generate_key_pair(self, kind: types.CryptoKind) -> list[types.TypedKeyPair]:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def now(self) -> Timestamp:
|
@abstractmethod
|
||||||
|
async def now(self) -> types.Timestamp:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def debug(self, command: str) -> str:
|
async def debug(self, command: str) -> str:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
|
@abstractmethod
|
||||||
async def veilid_version_string(self) -> str:
|
async def veilid_version_string(self) -> str:
|
||||||
pass
|
pass
|
||||||
@abstractmethod
|
|
||||||
async def veilid_version(self) -> VeilidVersion:
|
@abstractmethod
|
||||||
|
async def veilid_version(self) -> types.VeilidVersion:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user