From 556659a345f856239f8704d2cd92b442a480ab96 Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Sat, 12 Oct 2024 18:20:26 -0700 Subject: [PATCH] pyre and lint --- nwc-frontend/src/types/AppInfo.ts | 12 +++--- .../api_handlers/client_app_lookup_handler.py | 2 +- nwc_backend/configs/local_dev.py | 3 +- nwc_backend/configs/local_docker.py | 3 +- nwc_backend/configs/testing.py | 2 +- .../client_app_identity_lookup_test.py | 40 +++++++++---------- .../nostr/client_app_identity_lookup.py | 6 ++- 7 files changed, 35 insertions(+), 33 deletions(-) diff --git a/nwc-frontend/src/types/AppInfo.ts b/nwc-frontend/src/types/AppInfo.ts index 9cc97c2..d7273f5 100644 --- a/nwc-frontend/src/types/AppInfo.ts +++ b/nwc-frontend/src/types/AppInfo.ts @@ -4,11 +4,9 @@ export interface AppInfo { nip05Verified: boolean; domain: string; avatar: string; - nip68Verification?: - | { - status: string; - authorityName: string; - authorityPubKey: string; - } - | null; + nip68Verification?: { + status: string; + authorityName: string; + authorityPubKey: string; + } | null; } diff --git a/nwc_backend/api_handlers/client_app_lookup_handler.py b/nwc_backend/api_handlers/client_app_lookup_handler.py index 76ba335..2007373 100644 --- a/nwc_backend/api_handlers/client_app_lookup_handler.py +++ b/nwc_backend/api_handlers/client_app_lookup_handler.py @@ -15,7 +15,7 @@ async def get_client_app() -> Response: client_app_info = await look_up_client_app_identity(client_id) if not client_app_info: return Response("Client app not found", status=404) - + nip68_verification_json = None if client_app_info.app_authority_verification: nip68_verification_json = { diff --git a/nwc_backend/configs/local_dev.py b/nwc_backend/configs/local_dev.py index e69be4a..e3d095c 100644 --- a/nwc_backend/configs/local_dev.py +++ b/nwc_backend/configs/local_dev.py @@ -2,6 +2,7 @@ import os import secrets +from typing import List # DATABASE_URI: str = "postgresql+asyncpg://:@127.0.0.1:5432/nwc" DATABASE_URI: str = "sqlite+aiosqlite:///" + os.path.join( @@ -37,6 +38,6 @@ ] # NIP-68 client app authorities which can verify app identity events. -CLIENT_APP_AUTHORITIES = [ +CLIENT_APP_AUTHORITIES: List[str] = [ # "nprofile1qqstse98yvaykl3k2yez3732tmsc9vaq8c3uhex0s4qp4dl8fczmp9spp4mhxue69uhkummn9ekx7mq26saje" # Lightspark at nos.lol ] diff --git a/nwc_backend/configs/local_docker.py b/nwc_backend/configs/local_docker.py index b2e69c5..0d2b072 100644 --- a/nwc_backend/configs/local_docker.py +++ b/nwc_backend/configs/local_docker.py @@ -2,6 +2,7 @@ import os import secrets +from typing import List DATABASE_URI: str = "sqlite+aiosqlite:///" + os.path.join( os.getcwd(), "instance", "nwc.sqlite" @@ -36,6 +37,6 @@ ] # NIP-68 client app authorities which can verify app identity events. -CLIENT_APP_AUTHORITIES = [ +CLIENT_APP_AUTHORITIES: List[str] = [ # "nprofile1qqstse98yvaykl3k2yez3732tmsc9vaq8c3uhex0s4qp4dl8fczmp9spp4mhxue69uhkummn9ekx7mq26saje" # Lightspark at nos.lol ] diff --git a/nwc_backend/configs/testing.py b/nwc_backend/configs/testing.py index 51e8f51..ed7a058 100644 --- a/nwc_backend/configs/testing.py +++ b/nwc_backend/configs/testing.py @@ -32,5 +32,5 @@ ] CLIENT_APP_AUTHORITIES = [ - "nprofile1qqstg4syz8qyk9xeyp5j7haaw9nz67a6wzt80tmu5vn5g4ckpxlagvqpp4mhxue69uhkummn9ekx7mqnegwyj" # Fake authority at nos.lol + "nprofile1qqstg4syz8qyk9xeyp5j7haaw9nz67a6wzt80tmu5vn5g4ckpxlagvqpp4mhxue69uhkummn9ekx7mqnegwyj" # Fake authority at nos.lol ] diff --git a/nwc_backend/nostr/__tests__/client_app_identity_lookup_test.py b/nwc_backend/nostr/__tests__/client_app_identity_lookup_test.py index 72d7355..c1957ca 100644 --- a/nwc_backend/nostr/__tests__/client_app_identity_lookup_test.py +++ b/nwc_backend/nostr/__tests__/client_app_identity_lookup_test.py @@ -72,6 +72,7 @@ async def on_get_events(filters: List[Filter], source: EventSource): assert identity is not None assert identity.name == "Blue Drink" + assert identity.nip05 is not None assert identity.nip05.verification_status == Nip05VerificationStatus.VERIFIED assert identity.image_url == "https://bluedrink.com/image.png" @@ -110,6 +111,7 @@ async def on_get_events(filters: List[Filter], source: EventSource): assert identity is not None assert identity.name == "Green Drink" + assert identity.nip05 is not None assert identity.nip05.verification_status == Nip05VerificationStatus.VERIFIED assert identity.image_url == "https://greendrink.com/image.png" assert identity.allowed_redirect_urls == ["https://greendrink.com/callback"] @@ -137,9 +139,10 @@ async def test_only_kind13195_with_label( ).to_event(Keys.parse(CLIENT_PRIVKEY)) async def on_get_events(filters: List[Filter], source: EventSource): - if Kind(13195) in filters[0].as_record().kinds: + filter_kinds = filters[0].as_record().kinds or [] + if Kind(13195) in filter_kinds: return [id_event] - if Kind.from_enum(KindEnum.LABEL()) in filters[0].as_record().kinds: + if Kind.from_enum(KindEnum.LABEL()) in filter_kinds: # pyre-ignore[6] return [ EventBuilder.label("nip68.client_app", ["verified", "nip68.client_app"]) .add_tags([Tag.event(id_event.id())]) @@ -161,18 +164,15 @@ async def on_get_events(filters: List[Filter], source: EventSource): assert identity is not None assert identity.name == "Green Drink" + assert identity.nip05 is not None assert identity.nip05.verification_status == Nip05VerificationStatus.VERIFIED assert identity.image_url == "https://greendrink.com/image.png" assert identity.allowed_redirect_urls == ["https://greendrink.com/callback"] - assert identity.app_authority_verification is not None - assert identity.app_authority_verification.authority_name == "Important Authority" - assert ( - identity.app_authority_verification.authority_pubkey - == Keys.parse(AUTHORITY_PRIVKEY).public_key().to_hex() - ) - assert ( - identity.app_authority_verification.status == Nip68VerificationStatus.VERIFIED - ) + nip68 = identity.app_authority_verification + assert nip68 is not None + assert nip68.authority_name == "Important Authority" + assert nip68.authority_pubkey == Keys.parse(AUTHORITY_PRIVKEY).public_key().to_hex() + assert nip68.status == Nip68VerificationStatus.VERIFIED @patch.object(Nip05, "verify", new_callable=AsyncMock) @@ -196,9 +196,10 @@ async def test_kind13195_with_revoked_label( ).to_event(Keys.parse(CLIENT_PRIVKEY)) async def on_get_events(filters: List[Filter], source: EventSource): - if Kind(13195) in filters[0].as_record().kinds: + filter_kinds = filters[0].as_record().kinds or [] + if Kind(13195) in filter_kinds: return [id_event] - if Kind.from_enum(KindEnum.LABEL()) in filters[0].as_record().kinds: + if Kind.from_enum(KindEnum.LABEL()) in filter_kinds: # pyre-ignore[6] return [ EventBuilder.label("nip68.client_app", ["revoked", "nip68.client_app"]) .add_tags([Tag.event(id_event.id())]) @@ -220,13 +221,12 @@ async def on_get_events(filters: List[Filter], source: EventSource): assert identity is not None assert identity.name == "Yellow Drink" + assert identity.nip05 is not None assert identity.nip05.verification_status == Nip05VerificationStatus.VERIFIED assert identity.image_url == "https://yellowdrink.com/image.png" assert identity.allowed_redirect_urls == ["https://yellowdrink.com/callback"] - assert identity.app_authority_verification is not None - assert identity.app_authority_verification.authority_name == "Important Authority" - assert ( - identity.app_authority_verification.authority_pubkey - == Keys.parse(AUTHORITY_PRIVKEY).public_key().to_hex() - ) - assert identity.app_authority_verification.status == Nip68VerificationStatus.REVOKED + nip68 = identity.app_authority_verification + assert nip68 is not None + assert nip68.authority_name == "Important Authority" + assert nip68.authority_pubkey == Keys.parse(AUTHORITY_PRIVKEY).public_key().to_hex() + assert nip68.status == Nip68VerificationStatus.REVOKED diff --git a/nwc_backend/nostr/client_app_identity_lookup.py b/nwc_backend/nostr/client_app_identity_lookup.py index 4056c9b..b28f590 100644 --- a/nwc_backend/nostr/client_app_identity_lookup.py +++ b/nwc_backend/nostr/client_app_identity_lookup.py @@ -288,7 +288,7 @@ async def _check_app_authorities( if event.kind().as_enum() == KindEnum.LABEL() ] - metadata_events_by_pubkey = { + metadata_events_by_pubkey: dict[str, Event] = { event.author().to_hex(): event for event in verification_and_metadata_events if event.kind().as_enum() == KindEnum.METADATA() @@ -308,6 +308,7 @@ def authority_name_for_pubkey(pubkey: str) -> str: # If any verifications were revoked, prioritize that status above all others. for event in verification_events: status = event.get_tag_content( + # pyre-ignore[6] TagKind.SINGLE_LETTER(SingleLetterTag.lowercase(Alphabet.L)) ) if status and status.lower() == "revoked": @@ -315,12 +316,13 @@ def authority_name_for_pubkey(pubkey: str) -> str: status=Nip68VerificationStatus.REVOKED, authority_pubkey=event.author().to_hex(), authority_name=authority_name_for_pubkey(event.author().to_hex()), - revoked_at=event.created_at(), + revoked_at=event.created_at().as_secs(), ) # If any verifications were confirmed, return the first one. for event in verification_events: status = event.get_tag_content( + # pyre-ignore[6] TagKind.SINGLE_LETTER(SingleLetterTag.lowercase(Alphabet.L)) ) if status and status.lower() == "verified":