mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 13:22:56 +01:00
use base64x everywhere instead of encoding/base64.
This commit is contained in:
parent
8140857879
commit
cb74908f5d
2
go.mod
2
go.mod
@ -9,6 +9,7 @@ require (
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4
|
||||
github.com/btcsuite/btcd/btcutil v1.1.5
|
||||
github.com/bytedance/sonic v1.12.10
|
||||
github.com/cloudwego/base64x v0.1.5
|
||||
github.com/coder/websocket v1.8.12
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
|
||||
github.com/dgraph-io/badger/v4 v4.5.0
|
||||
@ -51,7 +52,6 @@ require (
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.3 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect
|
||||
github.com/dgraph-io/ristretto/v2 v2.1.0 // indirect
|
||||
|
@ -5,12 +5,12 @@ import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/cloudwego/base64x"
|
||||
)
|
||||
|
||||
// ComputeSharedSecret returns a shared secret key used to encrypt messages.
|
||||
@ -70,7 +70,7 @@ func Encrypt(message string, key []byte) (string, error) {
|
||||
ciphertext := make([]byte, len(paddedMsgBytes))
|
||||
mode.CryptBlocks(ciphertext, paddedMsgBytes)
|
||||
|
||||
return base64.StdEncoding.EncodeToString(ciphertext) + "?iv=" + base64.StdEncoding.EncodeToString(iv), nil
|
||||
return base64x.StdEncoding.EncodeToString(ciphertext) + "?iv=" + base64x.StdEncoding.EncodeToString(iv), nil
|
||||
}
|
||||
|
||||
// Decrypt decrypts a content string using the shared secret key.
|
||||
@ -81,12 +81,12 @@ func Decrypt(content string, key []byte) (string, error) {
|
||||
return "", fmt.Errorf("error parsing encrypted message: no initialization vector")
|
||||
}
|
||||
|
||||
ciphertext, err := base64.StdEncoding.DecodeString(parts[0])
|
||||
ciphertext, err := base64x.StdEncoding.DecodeString(parts[0])
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error decoding ciphertext from base64: %w", err)
|
||||
}
|
||||
|
||||
iv, err := base64.StdEncoding.DecodeString(parts[1])
|
||||
iv, err := base64x.StdEncoding.DecodeString(parts[1])
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error decoding iv from base64: %w", err)
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"crypto/hmac"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
@ -13,6 +12,7 @@ import (
|
||||
"math"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/cloudwego/base64x"
|
||||
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"golang.org/x/crypto/chacha20"
|
||||
"golang.org/x/crypto/hkdf"
|
||||
@ -90,7 +90,7 @@ func Encrypt(plaintext string, conversationKey [32]byte, applyOptions ...func(op
|
||||
copy(concat[1+32:], ciphertext)
|
||||
copy(concat[1+32+len(ciphertext):], mac)
|
||||
|
||||
return base64.StdEncoding.EncodeToString(concat), nil
|
||||
return base64x.StdEncoding.EncodeToString(concat), nil
|
||||
}
|
||||
|
||||
func Decrypt(b64ciphertextWrapped string, conversationKey [32]byte) (string, error) {
|
||||
@ -102,7 +102,7 @@ func Decrypt(b64ciphertextWrapped string, conversationKey [32]byte) (string, err
|
||||
return "", fmt.Errorf("unknown version")
|
||||
}
|
||||
|
||||
decoded, err := base64.StdEncoding.DecodeString(b64ciphertextWrapped)
|
||||
decoded, err := base64x.StdEncoding.DecodeString(b64ciphertextWrapped)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("invalid base64")
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"hash"
|
||||
@ -13,6 +12,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/cloudwego/base64x"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
@ -131,7 +131,7 @@ func generateAuthHeader(sk, host string, fileHash hash.Hash) (string, error) {
|
||||
return "", fmt.Errorf("json.Marshal: %w", err)
|
||||
}
|
||||
|
||||
payload := base64.StdEncoding.EncodeToString(b)
|
||||
payload := base64x.StdEncoding.EncodeToString(b)
|
||||
|
||||
return fmt.Sprintf("Nostr %s", payload), nil
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ package blossom
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
|
||||
"github.com/cloudwego/base64x"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
@ -85,5 +85,5 @@ func (c *Client) authorizationHeader(
|
||||
}
|
||||
|
||||
jevt, _ := json.Marshal(evt)
|
||||
return "Nostr " + base64.StdEncoding.EncodeToString(jevt)
|
||||
return "Nostr " + base64x.StdEncoding.EncodeToString(jevt)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user