diff --git a/cashu/core/nuts/nutxx.py b/cashu/core/nuts/nut20.py similarity index 84% rename from cashu/core/nuts/nutxx.py rename to cashu/core/nuts/nut20.py index 399ea56d..153a156c 100644 --- a/cashu/core/nuts/nutxx.py +++ b/cashu/core/nuts/nut20.py @@ -7,12 +7,10 @@ def construct_message(quote_id: str, outputs: List[BlindedMessage]) -> bytes: serialized_outputs = b"".join([o.B_.encode("utf-8") for o in outputs]) - msgbytes = sha256( - quote_id.encode("utf-8") - + serialized_outputs - ).digest() + msgbytes = sha256(quote_id.encode("utf-8") + serialized_outputs).digest() return msgbytes + def sign_mint_quote( quote_id: str, outputs: List[BlindedMessage], @@ -23,6 +21,7 @@ def sign_mint_quote( sig = privkey.schnorr_sign(msgbytes, None, raw=True) return sig.hex() + def verify_mint_quote( quote_id: str, outputs: List[BlindedMessage], @@ -32,4 +31,4 @@ def verify_mint_quote( pubkey = PublicKey(bytes.fromhex(public_key), raw=True) msgbytes = construct_message(quote_id, outputs) sig = bytes.fromhex(signature) - return pubkey.schnorr_verify(msgbytes, sig, None, raw=True) \ No newline at end of file + return pubkey.schnorr_verify(msgbytes, sig, None, raw=True) diff --git a/cashu/mint/verification.py b/cashu/mint/verification.py index ed53f408..0a986189 100644 --- a/cashu/mint/verification.py +++ b/cashu/mint/verification.py @@ -21,7 +21,7 @@ TransactionError, TransactionUnitError, ) -from ..core.nuts import nutxx +from ..core.nuts import nut20 from ..core.settings import settings from ..lightning.base import LightningBackend from ..mint.crud import LedgerCrud @@ -281,11 +281,14 @@ def _verify_and_get_unit_method( return unit, method def _verify_mint_quote_witness( - self, quote: MintQuote, outputs: List[BlindedMessage], witness: Optional[str], + self, + quote: MintQuote, + outputs: List[BlindedMessage], + witness: Optional[str], ) -> bool: """Verify signature on quote id and outputs""" if not quote.pubkey: return True if not witness: return False - return nutxx.verify_mint_quote(quote.quote, outputs, quote.pubkey, witness) \ No newline at end of file + return nut20.verify_mint_quote(quote.quote, outputs, quote.pubkey, witness) diff --git a/cashu/wallet/api/router.py b/cashu/wallet/api/router.py index d37eae42..b0e6f440 100644 --- a/cashu/wallet/api/router.py +++ b/cashu/wallet/api/router.py @@ -189,7 +189,7 @@ async def swap( if incoming_wallet.url == outgoing_wallet.url: raise Exception("mints for swap have to be different") - # get keypair to lock the quote with (NUTXX) + # get keypair to lock the quote with (NUT-20) keypair = await incoming_wallet.get_quote_ephemeral_keypair() # request invoice from incoming mint mint_quote = await incoming_wallet.request_mint(amount, keypair=keypair) @@ -209,7 +209,9 @@ async def swap( ) # mint token in incoming mint - await incoming_wallet.mint(amount, quote_id=mint_quote.quote, quote_privkey=mint_quote.privkey) + await incoming_wallet.mint( + amount, quote_id=mint_quote.quote, quote_privkey=mint_quote.privkey + ) await incoming_wallet.load_proofs(reload=True) mint_balances = await incoming_wallet.balance_per_minturl() return SwapResponse( diff --git a/cashu/wallet/mint_info.py b/cashu/wallet/mint_info.py index 34657572..0064981a 100644 --- a/cashu/wallet/mint_info.py +++ b/cashu/wallet/mint_info.py @@ -57,7 +57,7 @@ def supports_websocket_mint_quote(self, method: Method, unit: Unit) -> bool: def supports_mint_quote_signature(self) -> bool: if not self.nuts: return False - nutxx = self.nuts.get(MINT_QUOTE_SIGNATURE_NUT, None) - if nutxx: - return nutxx["supported"] + nut20 = self.nuts.get(MINT_QUOTE_SIGNATURE_NUT, None) + if nut20: + return nut20["supported"] return False diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index abbb7d99..79c4cdc3 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -36,7 +36,7 @@ PostCheckStateResponse, PostMeltQuoteResponse, ) -from ..core.nuts import nutxx +from ..core.nuts import nut20 from ..core.p2pk import Secret from ..core.settings import settings from ..core.split import amount_split @@ -387,7 +387,11 @@ async def _check_used_secrets(self, secrets): logger.trace("Secret check complete.") async def request_mint_with_callback( - self, amount: int, callback: Callable, memo: Optional[str] = None, keypair: Optional[Tuple[str, str]] = None + self, + amount: int, + callback: Callable, + memo: Optional[str] = None, + keypair: Optional[Tuple[str, str]] = None, ) -> Tuple[MintQuote, SubscriptionManager]: """Request a quote invoice for minting tokens. @@ -417,7 +421,8 @@ async def request_mint_with_callback( return quote, subscriptions - async def request_mint(self, + async def request_mint( + self, amount: int, memo: Optional[str] = None, keypair: Optional[Tuple[str, str]] = None, @@ -444,8 +449,7 @@ async def request_mint(self, # TODO: generate secret with BIP39 (seed and specific derivation + counter) async def get_quote_ephemeral_keypair(self) -> Optional[Tuple[str, str]]: - """Creates a keypair for a quote IF the mint supports NUT-19 - """ + """Creates a keypair for a quote IF the mint supports NUT-19""" if not self.mint_info: await self.load_mint_info() if self.mint_info.supports_mint_quote_signature(): @@ -549,7 +553,7 @@ async def mint( witness: Optional[str] = None if quote_privkey: - witness = nutxx.sign_mint_quote(quote_id, outputs, quote_privkey) + witness = nut20.sign_mint_quote(quote_id, outputs, quote_privkey) # will raise exception if mint is unsuccessful promises = await super().mint(outputs, quote_id, witness)