nut-09 mint info (#155)

* nut-09 mint info

* bump to 0.11.1

* make format
This commit is contained in:
calle
2023-04-01 00:47:27 +02:00
committed by GitHub
parent 2ded9c8b5c
commit 47f886487c
9 changed files with 76 additions and 13 deletions

View File

@@ -2,7 +2,7 @@ DEBUG=FALSE
CASHU_DIR=~/.cashu CASHU_DIR=~/.cashu
# WALLET # --------- WALLET ---------
# MINT_URL=https://localhost:3338 # MINT_URL=https://localhost:3338
MINT_HOST=127.0.0.1 MINT_HOST=127.0.0.1
@@ -17,7 +17,20 @@ TOR=TRUE
#SOCKS_HOST=localhost #SOCKS_HOST=localhost
#SOCKS_PORT=9050 #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="<hex_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 MINT_PRIVATE_KEY=supersecretprivatekey
@@ -36,8 +49,3 @@ LIGHTNING_RESERVE_FEE_MIN=4000
MINT_LNBITS_ENDPOINT=https://legend.lnbits.com MINT_LNBITS_ENDPOINT=https://legend.lnbits.com
MINT_LNBITS_KEY=yourkeyasdasdasd 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"

View File

@@ -115,7 +115,7 @@ cashu info
Returns: Returns:
```bash ```bash
Version: 0.11.0 Version: 0.11.1
Debug: False Debug: False
Cashu dir: /home/user/.cashu Cashu dir: /home/user/.cashu
Wallet: wallet Wallet: wallet

View File

@@ -102,6 +102,19 @@ class Invoice(BaseModel):
# ------- API ------- # ------- 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 ------- # ------- API: KEYS -------

View File

@@ -22,7 +22,7 @@ def derive_keys(master_key: str, derivation_path: str = ""):
return { return {
2 2
** i: PrivateKey( ** 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() .hexdigest()
.encode("utf-8")[:32], .encode("utf-8")[:32],
raw=True, 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]): def derive_pubkeys(keys: Dict[int, PrivateKey]):
return { return {
amt: keys[amt].pubkey for amt in [2**i for i in range(settings.max_order)] amt: keys[amt].pubkey for amt in [2**i for i in range(settings.max_order)]

View File

@@ -8,7 +8,7 @@ from pydantic import BaseSettings, Extra, Field, validator
env = Env() env = Env()
VERSION = "0.11.0" VERSION = "0.11.1"
def find_env_file(): def find_env_file():
@@ -58,6 +58,15 @@ class MintSettings(CashuSettings):
mint_lnbits_key: str = Field(default=None) 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): class WalletSettings(CashuSettings):
lightning: bool = Field(default=True) lightning: bool = Field(default=True)
tor: 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) version: str = Field(default=VERSION)
# def __init__(self, env_file=None): # def __init__(self, env_file=None):

View File

@@ -14,6 +14,7 @@ from cashu.core.base import (
MintKeysets, MintKeysets,
Proof, Proof,
) )
from cashu.core.crypto import derive_pubkey
from cashu.core.db import Database from cashu.core.db import Database
from cashu.core.helpers import fee_reserve, sum_proofs from cashu.core.helpers import fee_reserve, sum_proofs
from cashu.core.script import verify_script from cashu.core.script import verify_script
@@ -40,6 +41,7 @@ class Ledger:
self.db = db self.db = db
self.crud = crud self.crud = crud
self.lightning = lightning self.lightning = lightning
self.pubkey = derive_pubkey(self.master_key)
async def load_used_proofs(self): async def load_used_proofs(self):
"""Load all used proofs from database.""" """Load all used proofs from database."""

View File

@@ -10,6 +10,7 @@ from cashu.core.base import (
CheckFeesResponse, CheckFeesResponse,
CheckSpendableRequest, CheckSpendableRequest,
CheckSpendableResponse, CheckSpendableResponse,
GetInfoResponse,
GetMeltResponse, GetMeltResponse,
GetMintResponse, GetMintResponse,
KeysetsResponse, KeysetsResponse,
@@ -21,11 +22,32 @@ from cashu.core.base import (
PostSplitResponse, PostSplitResponse,
) )
from cashu.core.errors import CashuError from cashu.core.errors import CashuError
from cashu.core.settings import settings
from cashu.mint.startup import ledger from cashu.mint.startup import ledger
router: APIRouter = APIRouter() 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( @router.get(
"/keys", "/keys",
name="Mint public keys", name="Mint public keys",

View File

@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "cashu" name = "cashu"
version = "0.11.0" version = "0.11.1"
description = "Ecash wallet and mint." description = "Ecash wallet and mint."
authors = ["calle <callebtc@protonmail.com>"] authors = ["calle <callebtc@protonmail.com>"]
license = "MIT" license = "MIT"

View File

@@ -13,7 +13,7 @@ entry_points = {"console_scripts": ["cashu = cashu.wallet.cli.cli:cli"]}
setuptools.setup( setuptools.setup(
name="cashu", name="cashu",
version="0.11.0", version="0.11.1",
description="Ecash wallet and mint for Bitcoin Lightning", description="Ecash wallet and mint for Bitcoin Lightning",
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",