forked from cashubtc/nutshell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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 |