diff --git a/.env.example b/.env.example index d3c0a54..d696d37 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,7 @@ DEBUG=FALSE CASHU_DIR=~/.cashu -# WALLET +# --------- WALLET --------- # MINT_URL=https://localhost:3338 MINT_HOST=127.0.0.1 @@ -17,7 +17,20 @@ TOR=TRUE #SOCKS_HOST=localhost #SOCKS_PORT=9050 -# MINT +# NOSTR +# nostr private key to which to receive tokens to +NOSTR_PRIVATE_KEY=nostr_privatekey_here_hex_or_bech32 +# nostr relays (comma separated list) +NOSTR_RELAYS="wss://nostr-pub.wellorder.net" + +# --------- MINT --------- + +MINT_INFO_NAME="My Cashu mint" +MINT_INFO_PUBKEY="" +MINT_INFO_DESCRIPTION="The short mint description" +MINT_INFO_DESCRIPTION_LONG="A long mint description that can be a long piece of text." +MINT_INFO_CONTACT=["Email: contact@me.com", "Twitter: @me", "Nostr: npub..."] +# MINT_INFO_MOTD="Message to users" MINT_PRIVATE_KEY=supersecretprivatekey @@ -36,8 +49,3 @@ LIGHTNING_RESERVE_FEE_MIN=4000 MINT_LNBITS_ENDPOINT=https://legend.lnbits.com MINT_LNBITS_KEY=yourkeyasdasdasd -# NOSTR -# nostr private key to which to receive tokens to -NOSTR_PRIVATE_KEY=nostr_privatekey_here_hex_or_bech32 -# nostr relays (comma separated list) -NOSTR_RELAYS="wss://nostr-pub.wellorder.net" diff --git a/README.md b/README.md index d77a321..9c6ea01 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ cashu info Returns: ```bash -Version: 0.11.0 +Version: 0.11.1 Debug: False Cashu dir: /home/user/.cashu Wallet: wallet diff --git a/cashu/core/base.py b/cashu/core/base.py index 49ed79f..f488412 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -102,6 +102,19 @@ class Invoice(BaseModel): # ------- API ------- +# ------- API: INFO ------- + + +class GetInfoResponse(BaseModel): + name: Optional[str] = None + pubkey: Optional[str] = None + version: Optional[str] = None + description: Optional[str] = None + description_long: Optional[str] = None + contact: Optional[List[str]] = None + nuts: Optional[List[str]] = None + motd: Optional[str] = None + # ------- API: KEYS ------- diff --git a/cashu/core/crypto.py b/cashu/core/crypto.py index e19f58a..dd0b8bb 100644 --- a/cashu/core/crypto.py +++ b/cashu/core/crypto.py @@ -22,7 +22,7 @@ def derive_keys(master_key: str, derivation_path: str = ""): return { 2 ** i: PrivateKey( - hashlib.sha256((str(master_key) + derivation_path + str(i)).encode("utf-8")) + hashlib.sha256((master_key + derivation_path + str(i)).encode("utf-8")) .hexdigest() .encode("utf-8")[:32], raw=True, @@ -31,6 +31,13 @@ def derive_keys(master_key: str, derivation_path: str = ""): } +def derive_pubkey(master_key: str): + return PrivateKey( + hashlib.sha256((master_key).encode("utf-8")).hexdigest().encode("utf-8")[:32], + raw=True, + ).pubkey + + def derive_pubkeys(keys: Dict[int, PrivateKey]): return { amt: keys[amt].pubkey for amt in [2**i for i in range(settings.max_order)] diff --git a/cashu/core/settings.py b/cashu/core/settings.py index 03304c5..bc4628b 100644 --- a/cashu/core/settings.py +++ b/cashu/core/settings.py @@ -8,7 +8,7 @@ from pydantic import BaseSettings, Extra, Field, validator env = Env() -VERSION = "0.11.0" +VERSION = "0.11.1" def find_env_file(): @@ -58,6 +58,15 @@ class MintSettings(CashuSettings): mint_lnbits_key: str = Field(default=None) +class MintInformation(CashuSettings): + mint_info_name: str = Field(default="Cashu mint") + mint_info_description: str = Field(default=None) + mint_info_description_long: str = Field(default=None) + mint_info_contact: List[str] = Field(default=[]) + mint_info_nuts: List[str] = Field(default=["NUT-07", "NUT-08"]) + mint_info_motd: str = Field(default=None) + + class WalletSettings(CashuSettings): lightning: bool = Field(default=True) tor: bool = Field(default=True) @@ -79,7 +88,9 @@ class WalletSettings(CashuSettings): ) -class Settings(EnvSettings, MintSettings, WalletSettings, CashuSettings): +class Settings( + EnvSettings, MintSettings, MintInformation, WalletSettings, CashuSettings +): version: str = Field(default=VERSION) # def __init__(self, env_file=None): diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 190f8f5..4b66a6b 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -14,6 +14,7 @@ from cashu.core.base import ( MintKeysets, Proof, ) +from cashu.core.crypto import derive_pubkey from cashu.core.db import Database from cashu.core.helpers import fee_reserve, sum_proofs from cashu.core.script import verify_script @@ -40,6 +41,7 @@ class Ledger: self.db = db self.crud = crud self.lightning = lightning + self.pubkey = derive_pubkey(self.master_key) async def load_used_proofs(self): """Load all used proofs from database.""" diff --git a/cashu/mint/router.py b/cashu/mint/router.py index 2cf29d6..73c4305 100644 --- a/cashu/mint/router.py +++ b/cashu/mint/router.py @@ -10,6 +10,7 @@ from cashu.core.base import ( CheckFeesResponse, CheckSpendableRequest, CheckSpendableResponse, + GetInfoResponse, GetMeltResponse, GetMintResponse, KeysetsResponse, @@ -21,11 +22,32 @@ from cashu.core.base import ( PostSplitResponse, ) from cashu.core.errors import CashuError +from cashu.core.settings import settings from cashu.mint.startup import ledger router: APIRouter = APIRouter() +@router.get( + "/info", + name="Mint information", + summary="Mint information, operator contact information, and other info.", + response_model=GetInfoResponse, + response_model_exclude_none=True, +) +async def info(): + return GetInfoResponse( + name=settings.mint_info_name, + pubkey=ledger.pubkey.serialize().hex() if ledger.pubkey else None, + version=f"Nutshell/{settings.version}", + description=settings.mint_info_description, + description_long=settings.mint_info_description_long, + contact=settings.mint_info_contact, + nuts=settings.mint_info_nuts, + motd=settings.mint_info_motd, + ) + + @router.get( "/keys", name="Mint public keys", diff --git a/pyproject.toml b/pyproject.toml index b7eed49..439fdb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cashu" -version = "0.11.0" +version = "0.11.1" description = "Ecash wallet and mint." authors = ["calle "] license = "MIT" diff --git a/setup.py b/setup.py index e35fb62..b4ee7e6 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ entry_points = {"console_scripts": ["cashu = cashu.wallet.cli.cli:cli"]} setuptools.setup( name="cashu", - version="0.11.0", + version="0.11.1", description="Ecash wallet and mint for Bitcoin Lightning", long_description=long_description, long_description_content_type="text/markdown",