keyset not byte array

This commit is contained in:
callebtc
2022-10-09 21:58:19 +02:00
parent 6785f79da9
commit a5eefb80b0
3 changed files with 19 additions and 15 deletions

View File

@@ -101,14 +101,14 @@ class BlindedMessage(BaseModel):
class BlindedSignature(BaseModel):
id: str = ""
id: Union[str, None] = None
amount: int
C_: str
@classmethod
def from_dict(cls, d: dict):
return cls(
id=d["id"],
id=d.get("id"),
amount=d["amount"],
C_=d["C_"],
)
@@ -268,8 +268,6 @@ class MintKeyset:
def from_row(cls, row: Row):
if row is None:
return cls
# fix to convert byte to string, unclear why this is necessary
id = row[0].decode("ascii") if type(row[0]) == bytes else row[0]
return cls(
id=id,
derivation_path=row[1],

View File

@@ -30,6 +30,6 @@ def derive_pubkeys(keys: Dict[int, PrivateKey]):
def derive_keyset_id(keys: Dict[str, PublicKey]):
"""Deterministic derivation keyset_id from set of public keys."""
pubkeys_concat = "".join([p.serialize().hex() for _, p in keys.items()])
return base64.b64encode(hashlib.sha256((pubkeys_concat).encode("utf-8")).digest())[
:12
]
return base64.b64encode(
hashlib.sha256((pubkeys_concat).encode("utf-8")).digest()
).decode()[:12]

View File

@@ -108,24 +108,30 @@ class LedgerAPI:
), "Ledger not initialized correctly: mint URL not specified yet. "
# get current keyset
keyset = await self._get_keys(self.url)
logger.debug(f"Current mint keyset: {keyset.id}")
# get all active keysets
keysets = await self._get_keysets(self.url)
logger.debug(f"Mint keysets: {keysets}")
mint_keysets = []
try:
keysets_resp = await self._get_keysets(self.url)
mint_keysets = keysets_resp["keysets"]
# store active keysets
except:
pass
self.keysets = mint_keysets if len(mint_keysets) else [keyset.id]
# store current keyset
assert len(keyset.public_keys) > 0, "did not receive keys from mint."
# check if current keyset is in db
keyset_local: WalletKeyset = await get_keyset(keyset.id, db=self.db)
if keyset_local is None:
await store_keyset(keyset=keyset, db=self.db)
# store current keyset
assert len(keyset.public_keys) > 0, "did not receive keys from mint."
logger.debug(f"Mint keysets: {self.keysets}")
logger.debug(f"Current mint keyset: {keyset.id}")
self.keys = keyset.public_keys
self.keyset_id = keyset.id
# store active keysets
self.keysets = keysets["keysets"]
def request_mint(self, amount):
"""Requests a mint from the server and returns Lightning invoice."""
r = requests.get(self.url + "/mint", params={"amount": amount})