mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-21 02:54:20 +01:00
* nut-19 sign mint quote * ephemeral key for quote * `mint` adjustments + crypto/nut19.py * wip: mint side working * fix import * post-merge fixups * more fixes * make format * move nut19 to nuts directory * `key` -> `privkey` and `pubkey` * make format * mint_info method for nut-19 support * fix tests imports * fix signature missing positional argument + fix db migration format not correctly escaped + pass in NUT-19 keypair to `request_mint` `request_mint_with_callback` * make format * fix `get_invoice_status` * rename to xx * nutxx -> nut20 * mypy * remove `mint_quote_signature_required` as per spec * wip edits * clean up * fix tests * fix deprecated api tests * fix redis tests * fix cache tests * fix regtest mint external * fix mint regtest * add test without signature * test pubkeys in quotes * wip * add compat --------- Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
50 lines
2.0 KiB
Python
50 lines
2.0 KiB
Python
import base64
|
|
|
|
from loguru import logger
|
|
|
|
from ..core.crypto.keys import derive_keyset_id
|
|
from ..core.db import Database
|
|
from ..core.settings import settings
|
|
from .crud import (
|
|
get_keysets,
|
|
update_keyset,
|
|
)
|
|
from .protocols import SupportsDb, SupportsMintURL
|
|
|
|
|
|
class WalletCompat(SupportsDb, SupportsMintURL):
|
|
db: Database
|
|
|
|
async def inactivate_base64_keysets(self, force_old_keysets: bool) -> None:
|
|
# BEGIN backwards compatibility: phase out keysets with base64 ID by treating them as inactive
|
|
if settings.wallet_inactivate_base64_keysets and not force_old_keysets:
|
|
keysets_in_db = await get_keysets(mint_url=self.url, db=self.db)
|
|
for keyset in keysets_in_db:
|
|
if not keyset.active:
|
|
continue
|
|
# test if the keyset id is a hex string, if not it's base64
|
|
try:
|
|
int(keyset.id, 16)
|
|
except ValueError:
|
|
# verify that it's base64
|
|
try:
|
|
_ = base64.b64decode(keyset.id)
|
|
except ValueError:
|
|
logger.error("Unexpected: keyset id is neither hex nor base64.")
|
|
continue
|
|
|
|
# verify that we have a hex version of the same keyset by comparing public keys
|
|
hex_keyset_id = derive_keyset_id(keys=keyset.public_keys)
|
|
if hex_keyset_id not in [k.id for k in keysets_in_db]:
|
|
logger.warning(
|
|
f"Keyset {keyset.id} is base64 but we don't have a hex version. Ignoring."
|
|
)
|
|
continue
|
|
|
|
logger.warning(
|
|
f"Keyset {keyset.id} is base64 and has a hex counterpart, setting inactive."
|
|
)
|
|
keyset.active = False
|
|
await update_keyset(keyset=keyset, db=self.db)
|
|
# END backwards compatibility
|