clean base models

This commit is contained in:
callebtc
2023-01-14 15:01:23 +01:00
parent 482786dcc5
commit f808366eb2
2 changed files with 59 additions and 13 deletions

View File

@@ -6,6 +6,8 @@ from pydantic import BaseModel
from cashu.core.crypto import derive_keys, derive_keyset_id, derive_pubkeys from cashu.core.crypto import derive_keys, derive_keyset_id, derive_pubkeys
from cashu.core.secp import PrivateKey, PublicKey from cashu.core.secp import PrivateKey, PublicKey
# ------- PROOFS -------
class P2SHScript(BaseModel): class P2SHScript(BaseModel):
script: str script: str
@@ -40,9 +42,13 @@ class Proof(BaseModel):
class Proofs(BaseModel): class Proofs(BaseModel):
# NOTE: not used in Pydantic validation
__root__: List[Proof] __root__: List[Proof]
# ------- LIGHTNING INVOICE -------
class Invoice(BaseModel): class Invoice(BaseModel):
amount: int amount: int
pr: str pr: str
@@ -54,15 +60,10 @@ class Invoice(BaseModel):
time_paid: Union[None, str, int, float] = "" time_paid: Union[None, str, int, float] = ""
class BlindedMessage(BaseModel): # ------- API -------
amount: int
B_: str
class BlindedSignature(BaseModel): # ------- API: KEYS -------
id: Union[str, None] = None
amount: int
C_: str
class KeysResponse(BaseModel): class KeysResponse(BaseModel):
@@ -73,8 +74,13 @@ class KeysetsResponse(BaseModel):
keysets: list[str] keysets: list[str]
class BlindedMessages(BaseModel): # ------- API: MINT -------
blinded_messages: List[BlindedMessage] = []
class BlindedSignature(BaseModel):
id: Union[str, None] = None
amount: int
C_: str
class PostMintResponseLegacy(BaseModel): class PostMintResponseLegacy(BaseModel):
@@ -91,11 +97,31 @@ class GetMintResponse(BaseModel):
hash: str hash: str
# ------- API: MELT -------
class MeltRequest(BaseModel):
proofs: List[Proof]
invoice: str
class GetMeltResponse(BaseModel): class GetMeltResponse(BaseModel):
paid: Union[bool, None] paid: Union[bool, None]
preimage: Union[str, None] preimage: Union[str, None]
# ------- API: SPLIT -------
class BlindedMessage(BaseModel):
amount: int
B_: str
class BlindedMessages(BaseModel):
blinded_messages: List[BlindedMessage] = []
class SplitRequest(BaseModel): class SplitRequest(BaseModel):
proofs: List[Proof] proofs: List[Proof]
amount: int amount: int
@@ -120,6 +146,9 @@ class PostSplitResponse(BaseModel):
snd: List[BlindedSignature] snd: List[BlindedSignature]
# ------- API: CHECK -------
class CheckRequest(BaseModel): class CheckRequest(BaseModel):
proofs: List[Proof] proofs: List[Proof]
@@ -132,18 +161,24 @@ class CheckFeesResponse(BaseModel):
fee: Union[int, None] fee: Union[int, None]
class MeltRequest(BaseModel): # ------- KEYSETS -------
proofs: List[Proof]
invoice: str
class KeyBase(BaseModel): class KeyBase(BaseModel):
"""
Public key from a keyset id for a given amount.
"""
id: str id: str
amount: int amount: int
pubkey: str pubkey: str
class WalletKeyset: class WalletKeyset:
"""
Contains the keyset from the wallets's perspective.
"""
id: Union[str, None] id: Union[str, None]
public_keys: Union[Dict[int, PublicKey], None] public_keys: Union[Dict[int, PublicKey], None]
mint_url: Union[str, None] = None mint_url: Union[str, None] = None
@@ -174,6 +209,10 @@ class WalletKeyset:
class MintKeyset: class MintKeyset:
"""
Contains the keyset from the mint's perspective.
"""
id: Union[str, None] id: Union[str, None]
derivation_path: str derivation_path: str
private_keys: Dict[int, PrivateKey] private_keys: Dict[int, PrivateKey]
@@ -221,6 +260,10 @@ class MintKeyset:
class MintKeysets: class MintKeysets:
"""
Collection of keyset IDs and the corresponding keyset of the mint.
"""
keysets: Dict[str, MintKeyset] keysets: Dict[str, MintKeyset]
def __init__(self, keysets: List[MintKeyset]): def __init__(self, keysets: List[MintKeyset]):
@@ -230,6 +273,9 @@ class MintKeysets:
return [k for k, _ in self.keysets.items()] return [k for k, _ in self.keysets.items()]
# ------- TOKEN -------
class TokenMintJson(BaseModel): class TokenMintJson(BaseModel):
url: str url: str
ks: List[str] ks: List[str]

View File

@@ -61,7 +61,7 @@ A `Proof` is also called a `Token` and has the following form:
``` ```
### `Proofs` ### `Proofs`
A list of `Proof`'s. In general, this will be used for most operations instead of a single `Proof`. `Proofs` can be serialized (see Methods/Serialization [TODO: Link Serialization]) An array (list) of `Proof`'s. In general, this will be used for most operations instead of a single `Proof`. `Proofs` can be serialized (see Methods/Serialization [TODO: Link Serialization])
## 0.2 - Methods ## 0.2 - Methods