mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-04 15:50:16 +02:00
get rid of all the deprecated things.
This commit is contained in:
parent
7ede46661c
commit
9057b1a7e1
10
helpers.go
10
helpers.go
@ -103,3 +103,13 @@ func subIdToSerial(subId string) int64 {
|
|||||||
serialId, _ := strconv.ParseInt(subId[0:n], 10, 64)
|
serialId, _ := strconv.ParseInt(subId[0:n], 10, 64)
|
||||||
return serialId
|
return serialId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isLowerHex(thing string) bool {
|
||||||
|
for _, charNumber := range thing {
|
||||||
|
if (charNumber >= 48 && charNumber <= 57) || (charNumber >= 97 && charNumber <= 102) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
10
keys.go
10
keys.go
@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcec/v2/schnorr"
|
"github.com/btcsuite/btcd/btcec/v2/schnorr"
|
||||||
@ -39,16 +38,11 @@ func GetPublicKey(sk string) (string, error) {
|
|||||||
return hex.EncodeToString(schnorr.SerializePubKey(pk)), nil
|
return hex.EncodeToString(schnorr.SerializePubKey(pk)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use IsValid32ByteHex instead -- functionality unchanged.
|
func IsValidPublicKey(pk string) bool {
|
||||||
func IsValidPublicKeyHex(pk string) bool {
|
if !isLowerHex(pk) {
|
||||||
if strings.ToLower(pk) != pk {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
dec, _ := hex.DecodeString(pk)
|
|
||||||
return len(dec) == 32
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsValidPublicKey(pk string) bool {
|
|
||||||
v, _ := hex.DecodeString(pk)
|
v, _ := hex.DecodeString(pk)
|
||||||
_, err := schnorr.ParsePubKey(v)
|
_, err := schnorr.ParsePubKey(v)
|
||||||
return err == nil
|
return err == nil
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
package nip13
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/nbd-wtf/go-nostr"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Deprecated: use DoWork() instead.
|
|
||||||
func Generate(event *nostr.Event, targetDifficulty int, timeout time.Duration) (*nostr.Event, error) {
|
|
||||||
if event.PubKey == "" {
|
|
||||||
return nil, ErrMissingPubKey
|
|
||||||
}
|
|
||||||
|
|
||||||
tag := nostr.Tag{"nonce", "", strconv.Itoa(targetDifficulty)}
|
|
||||||
event.Tags = append(event.Tags, tag)
|
|
||||||
var nonce uint64
|
|
||||||
start := time.Now()
|
|
||||||
for {
|
|
||||||
nonce++
|
|
||||||
tag[1] = strconv.FormatUint(nonce, 10)
|
|
||||||
if Difficulty(event.GetID()) >= targetDifficulty {
|
|
||||||
return event, nil
|
|
||||||
}
|
|
||||||
// benchmarks show one iteration is approx 3000ns on i7-8565U @ 1.8GHz.
|
|
||||||
// so, check every 30ms; arbitrary
|
|
||||||
if nonce%10000 == 0 && time.Since(start) > timeout {
|
|
||||||
return nil, ErrGenerateTimeout
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
2
utils.go
2
utils.go
@ -19,7 +19,7 @@ func IsValidRelayURL(u string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsValid32ByteHex(thing string) bool {
|
func IsValid32ByteHex(thing string) bool {
|
||||||
if strings.ToLower(thing) != thing {
|
if !isLowerHex(thing) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if len(thing) != 64 {
|
if len(thing) != 64 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user