Skip to content

Commit

Permalink
pyre and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jklein24 committed Oct 13, 2024
1 parent f982e9f commit 556659a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 33 deletions.
12 changes: 5 additions & 7 deletions nwc-frontend/src/types/AppInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion nwc_backend/api_handlers/client_app_lookup_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion nwc_backend/configs/local_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
]
3 changes: 2 additions & 1 deletion nwc_backend/configs/local_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
]
2 changes: 1 addition & 1 deletion nwc_backend/configs/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
]

CLIENT_APP_AUTHORITIES = [
"nprofile1qqstg4syz8qyk9xeyp5j7haaw9nz67a6wzt80tmu5vn5g4ckpxlagvqpp4mhxue69uhkummn9ekx7mqnegwyj" # Fake authority at nos.lol
"nprofile1qqstg4syz8qyk9xeyp5j7haaw9nz67a6wzt80tmu5vn5g4ckpxlagvqpp4mhxue69uhkummn9ekx7mqnegwyj" # Fake authority at nos.lol
]
40 changes: 20 additions & 20 deletions nwc_backend/nostr/__tests__/client_app_identity_lookup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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())])
Expand All @@ -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)
Expand All @@ -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())])
Expand All @@ -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
6 changes: 4 additions & 2 deletions nwc_backend/nostr/client_app_identity_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -308,19 +308,21 @@ 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":
return Nip68Verification(
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":
Expand Down

0 comments on commit 556659a

Please sign in to comment.