From 2586144a5cc1b55417febb9cc8c4f5136ad6deeb Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Thu, 18 Jan 2024 20:30:20 -0300 Subject: [PATCH] replace usage of IsValidPublicKeyHex() in subpackages. --- nip29/group.go | 4 ++-- nip29/relay/relay.go | 10 +++++----- nip46/dynamic-signer.go | 6 +++--- nip46/static-key-signer.go | 4 ++-- nip52/calendar_event.go | 2 +- nip53/nip53.go | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/nip29/group.go b/nip29/group.go index 294d151..5c398c9 100644 --- a/nip29/group.go +++ b/nip29/group.go @@ -150,7 +150,7 @@ func (group *Group) MergeInAdminsEvent(evt *nostr.Event) error { if tag[0] != "p" { continue } - if !nostr.IsValidPublicKeyHex(tag[1]) { + if !nostr.IsValid32ByteHex(tag[1]) { continue } @@ -186,7 +186,7 @@ func (group *Group) MergeInMembersEvent(evt *nostr.Event) error { if tag[0] != "p" { continue } - if !nostr.IsValidPublicKeyHex(tag[1]) { + if !nostr.IsValid32ByteHex(tag[1]) { continue } diff --git a/nip29/relay/relay.go b/nip29/relay/relay.go index 93d1f32..c4daae7 100644 --- a/nip29/relay/relay.go +++ b/nip29/relay/relay.go @@ -24,7 +24,7 @@ var moderationActionFactories = map[int]func(*nostr.Event) (Action, error){ nostr.KindSimpleGroupAddUser: func(evt *nostr.Event) (Action, error) { targets := make([]string, 0, len(evt.Tags)) for _, tag := range evt.Tags.GetAll([]string{"p", ""}) { - if !nostr.IsValidPublicKeyHex(tag[1]) { + if !nostr.IsValid32ByteHex(tag[1]) { return nil, fmt.Errorf("") } targets = append(targets, tag[1]) @@ -37,7 +37,7 @@ var moderationActionFactories = map[int]func(*nostr.Event) (Action, error){ nostr.KindSimpleGroupRemoveUser: func(evt *nostr.Event) (Action, error) { targets := make([]string, 0, len(evt.Tags)) for _, tag := range evt.Tags.GetAll([]string{"p", ""}) { - if !nostr.IsValidPublicKeyHex(tag[1]) { + if !nostr.IsValid32ByteHex(tag[1]) { return nil, fmt.Errorf("invalid public key hex") } targets = append(targets, tag[1]) @@ -81,7 +81,7 @@ var moderationActionFactories = map[int]func(*nostr.Event) (Action, error){ targets := make([]string, 0, nTags-1) for _, tag := range evt.Tags.GetAll([]string{"p", ""}) { - if !nostr.IsValidPublicKeyHex(tag[1]) { + if !nostr.IsValid32ByteHex(tag[1]) { return nil, fmt.Errorf("invalid public key hex") } targets = append(targets, tag[1]) @@ -107,7 +107,7 @@ var moderationActionFactories = map[int]func(*nostr.Event) (Action, error){ targets := make([]string, 0, nTags-1) for _, tag := range evt.Tags.GetAll([]string{"p", ""}) { - if !nostr.IsValidPublicKeyHex(tag[1]) { + if !nostr.IsValid32ByteHex(tag[1]) { return nil, fmt.Errorf("invalid public key hex") } targets = append(targets, tag[1]) @@ -127,7 +127,7 @@ var moderationActionFactories = map[int]func(*nostr.Event) (Action, error){ targets := make([]string, len(tags)) for i, tag := range tags { - if nostr.IsValidPublicKeyHex(tag[1]) { + if nostr.IsValid32ByteHex(tag[1]) { targets[i] = tag[1] } else { return nil, fmt.Errorf("invalid event id hex") diff --git a/nip46/dynamic-signer.go b/nip46/dynamic-signer.go index 1e8ffaf..a6c0e77 100644 --- a/nip46/dynamic-signer.go +++ b/nip46/dynamic-signer.go @@ -81,7 +81,7 @@ func (p *DynamicSigner) HandleRequest(event *nostr.Event) ( } targetUser := event.Tags.GetFirst([]string{"p", ""}) - if targetUser == nil || !nostr.IsValidPublicKeyHex((*targetUser)[1]) { + if targetUser == nil || !nostr.IsValid32ByteHex((*targetUser)[1]) { return req, resp, eventResponse, false, fmt.Errorf("invalid \"p\" tag") } @@ -153,7 +153,7 @@ func (p *DynamicSigner) HandleRequest(event *nostr.Event) ( break } thirdPartyPubkey := req.Params[0] - if !nostr.IsValidPublicKeyHex(thirdPartyPubkey) { + if !nostr.IsValidPublicKey(thirdPartyPubkey) { resultErr = fmt.Errorf("first argument to 'nip04_encrypt' is not a pubkey string") break } @@ -179,7 +179,7 @@ func (p *DynamicSigner) HandleRequest(event *nostr.Event) ( break } thirdPartyPubkey := req.Params[0] - if !nostr.IsValidPublicKeyHex(thirdPartyPubkey) { + if !nostr.IsValidPublicKey(thirdPartyPubkey) { resultErr = fmt.Errorf("first argument to 'nip04_decrypt' is not a pubkey string") break } diff --git a/nip46/static-key-signer.go b/nip46/static-key-signer.go index 78df95a..5771f4b 100644 --- a/nip46/static-key-signer.go +++ b/nip46/static-key-signer.go @@ -134,7 +134,7 @@ func (p *StaticKeySigner) HandleRequest(event *nostr.Event) ( break } thirdPartyPubkey := req.Params[0] - if !nostr.IsValidPublicKeyHex(thirdPartyPubkey) { + if !nostr.IsValidPublicKey(thirdPartyPubkey) { resultErr = fmt.Errorf("first argument to 'nip04_encrypt' is not a pubkey string") break } @@ -156,7 +156,7 @@ func (p *StaticKeySigner) HandleRequest(event *nostr.Event) ( break } thirdPartyPubkey := req.Params[0] - if !nostr.IsValidPublicKeyHex(thirdPartyPubkey) { + if !nostr.IsValidPublicKey(thirdPartyPubkey) { resultErr = fmt.Errorf("first argument to 'nip04_decrypt' is not a pubkey string") break } diff --git a/nip52/calendar_event.go b/nip52/calendar_event.go index 04e4433..5b4ba66 100644 --- a/nip52/calendar_event.go +++ b/nip52/calendar_event.go @@ -75,7 +75,7 @@ func ParseCalendarEvent(event nostr.Event) CalendarEvent { case "g": calev.Geohashes = append(calev.Geohashes, tag[1]) case "p": - if nostr.IsValidPublicKeyHex(tag[1]) { + if nostr.IsValid32ByteHex(tag[1]) { part := Participant{ PubKey: tag[1], } diff --git a/nip53/nip53.go b/nip53/nip53.go index ceb1b3d..8f84083 100644 --- a/nip53/nip53.go +++ b/nip53/nip53.go @@ -64,7 +64,7 @@ func ParseLiveEvent(event nostr.Event) LiveEvent { case "recording": liev.Recording = append(liev.Recording, tag[1]) case "p": - if nostr.IsValidPublicKeyHex(tag[1]) { + if nostr.IsValid32ByteHex(tag[1]) { part := Participant{ PubKey: tag[1], }