mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-08 16:33:38 +02:00
Revert "nip13: crazier and more fun and hopefully slightly more performant nonce encoding."
This reverts commit edbbd6df44
.
This commit is contained in:
@@ -1,25 +0,0 @@
|
|||||||
package nip13
|
|
||||||
|
|
||||||
const (
|
|
||||||
maxSafeAscii = 126
|
|
||||||
minSafeAscii = 35
|
|
||||||
availableSafeAscii = maxSafeAscii - minSafeAscii
|
|
||||||
)
|
|
||||||
|
|
||||||
func uintToStringCrazy(num uint64) string {
|
|
||||||
nchars := 1 + num/availableSafeAscii
|
|
||||||
chars := make([]byte, nchars)
|
|
||||||
|
|
||||||
i := 0
|
|
||||||
for {
|
|
||||||
if num < availableSafeAscii {
|
|
||||||
chars[i] = byte(num + minSafeAscii)
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
chars[i] = byte(num/availableSafeAscii + minSafeAscii)
|
|
||||||
num -= availableSafeAscii
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string(chars)
|
|
||||||
}
|
|
@@ -80,7 +80,7 @@ func Generate(event *nostr.Event, targetDifficulty int, timeout time.Duration) (
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
for {
|
for {
|
||||||
nonce++
|
nonce++
|
||||||
tag[1] = uintToStringCrazy(nonce)
|
tag[1] = strconv.FormatUint(nonce, 10)
|
||||||
if Difficulty(event.GetID()) >= targetDifficulty {
|
if Difficulty(event.GetID()) >= targetDifficulty {
|
||||||
return event, nil
|
return event, nil
|
||||||
}
|
}
|
||||||
|
@@ -100,8 +100,8 @@ func testNonceTag(t *testing.T, event *nostr.Event, commitment int) {
|
|||||||
if tag[0] != "nonce" {
|
if tag[0] != "nonce" {
|
||||||
t.Errorf("tag[0] = %q; want 'nonce'", tag[0])
|
t.Errorf("tag[0] = %q; want 'nonce'", tag[0])
|
||||||
}
|
}
|
||||||
if len(tag[1]) < 0 {
|
if n, err := strconv.ParseInt(tag[1], 10, 64); err != nil || n < 1 {
|
||||||
t.Errorf("tag[1] = %q; want a nonce character", tag[1])
|
t.Errorf("tag[1] = %q; want an int greater than 0", tag[1])
|
||||||
}
|
}
|
||||||
if n, err := strconv.Atoi(tag[2]); err != nil || n != commitment {
|
if n, err := strconv.Atoi(tag[2]); err != nil || n != commitment {
|
||||||
t.Errorf("tag[2] = %q; want %d", tag[2], commitment)
|
t.Errorf("tag[2] = %q; want %d", tag[2], commitment)
|
||||||
|
Reference in New Issue
Block a user