This commit is contained in:
LesCyber 2025-03-10 16:54:56 +01:00 committed by GitHub
commit 8fc37d3da1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 48 additions and 44 deletions

View file

@ -3,8 +3,7 @@
package musig2 package musig2
import ( import (
"fmt" "errors"
"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"
) )
@ -13,52 +12,52 @@ var (
// ErrSignersNotSpecified is returned when a caller attempts to create // ErrSignersNotSpecified is returned when a caller attempts to create
// a context without specifying either the total number of signers, or // a context without specifying either the total number of signers, or
// the complete set of singers. // the complete set of singers.
ErrSignersNotSpecified = fmt.Errorf("total number of signers or all " + ErrSignersNotSpecified = errors.New("total number of signers or all " +
"signers must be known") "signers must be known")
// ErrSignerNotInKeySet is returned when a the private key for a signer // ErrSignerNotInKeySet is returned when a the private key for a signer
// isn't included in the set of signing public keys. // isn't included in the set of signing public keys.
ErrSignerNotInKeySet = fmt.Errorf("signing key is not found in key" + ErrSignerNotInKeySet = errors.New("signing key is not found in key" +
" set") " set")
// ErrAlredyHaveAllNonces is called when RegisterPubNonce is called too // ErrAlredyHaveAllNonces is called when RegisterPubNonce is called too
// many times for a given signing session. // many times for a given signing session.
ErrAlredyHaveAllNonces = fmt.Errorf("already have all nonces") ErrAlredyHaveAllNonces = errors.New("already have all nonces")
// ErrNotEnoughSigners is returned when a caller attempts to create a // ErrNotEnoughSigners is returned when a caller attempts to create a
// session from a context, but before all the required signers are // session from a context, but before all the required signers are
// known. // known.
ErrNotEnoughSigners = fmt.Errorf("not enough signers") ErrNotEnoughSigners = errors.New("not enough signers")
// ErrAlredyHaveAllNonces is returned when a caller attempts to // ErrAlredyHaveAllNonces is returned when a caller attempts to
// register a signer, once we already have the total set of known // register a signer, once we already have the total set of known
// signers. // signers.
ErrAlreadyHaveAllSigners = fmt.Errorf("all signers registered") ErrAlreadyHaveAllSigners = errors.New("all signers registered")
// ErrAlredyHaveAllSigs is called when CombineSig is called too many // ErrAlredyHaveAllSigs is called when CombineSig is called too many
// times for a given signing session. // times for a given signing session.
ErrAlredyHaveAllSigs = fmt.Errorf("already have all sigs") ErrAlredyHaveAllSigs = errors.New("already have all sigs")
// ErrSigningContextReuse is returned if a user attempts to sign using // ErrSigningContextReuse is returned if a user attempts to sign using
// the same signing context more than once. // the same signing context more than once.
ErrSigningContextReuse = fmt.Errorf("nonce already used") ErrSigningContextReuse = errors.New("nonce already used")
// ErrFinalSigInvalid is returned when the combined signature turns out // ErrFinalSigInvalid is returned when the combined signature turns out
// to be invalid. // to be invalid.
ErrFinalSigInvalid = fmt.Errorf("final signature is invalid") ErrFinalSigInvalid = errors.New("final signature is invalid")
// ErrCombinedNonceUnavailable is returned when a caller attempts to // ErrCombinedNonceUnavailable is returned when a caller attempts to
// sign a partial signature, without first having collected all the // sign a partial signature, without first having collected all the
// required combined nonces. // required combined nonces.
ErrCombinedNonceUnavailable = fmt.Errorf("missing combined nonce") ErrCombinedNonceUnavailable = errors.New("missing combined nonce")
// ErrTaprootInternalKeyUnavailable is returned when a user attempts to // ErrTaprootInternalKeyUnavailable is returned when a user attempts to
// obtain the // obtain the
ErrTaprootInternalKeyUnavailable = fmt.Errorf("taproot tweak not used") ErrTaprootInternalKeyUnavailable = errors.New("taproot tweak not used")
// ErrNotEnoughSigners is returned if a caller attempts to obtain an // ErrNotEnoughSigners is returned if a caller attempts to obtain an
// early nonce when it wasn't specified // early nonce when it wasn't specified
ErrNoEarlyNonce = fmt.Errorf("no early nonce available") ErrNoEarlyNonce = errors.New("no early nonce available")
) )
// Context is a managed signing context for musig2. It takes care of things // Context is a managed signing context for musig2. It takes care of things

View file

@ -4,7 +4,7 @@ package musig2
import ( import (
"bytes" "bytes"
"fmt" "errors"
"sort" "sort"
secp "github.com/decred/dcrd/dcrec/secp256k1/v4" secp "github.com/decred/dcrd/dcrec/secp256k1/v4"
@ -25,11 +25,11 @@ var (
// ErrTweakedKeyIsInfinity is returned if while tweaking a key, we end // ErrTweakedKeyIsInfinity is returned if while tweaking a key, we end
// up with the point at infinity. // up with the point at infinity.
ErrTweakedKeyIsInfinity = fmt.Errorf("tweaked key is infinity point") ErrTweakedKeyIsInfinity = errors.New("tweaked key is infinity point")
// ErrTweakedKeyOverflows is returned if a tweaking key is larger than // ErrTweakedKeyOverflows is returned if a tweaking key is larger than
// 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141. // 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141.
ErrTweakedKeyOverflows = fmt.Errorf("tweaked key is too large") ErrTweakedKeyOverflows = errors.New("tweaked key is too large")
) )
// sortableKeys defines a type of slice of public keys that implements the sort // sortableKeys defines a type of slice of public keys that implements the sort

View file

@ -4,7 +4,7 @@ package musig2
import ( import (
"bytes" "bytes"
"fmt" "errors"
"io" "io"
secp "github.com/decred/dcrd/dcrec/secp256k1/v4" secp "github.com/decred/dcrd/dcrec/secp256k1/v4"
@ -24,28 +24,28 @@ var (
// ErrNoncePointAtInfinity is returned if during signing, the fully // ErrNoncePointAtInfinity is returned if during signing, the fully
// combined public nonce is the point at infinity. // combined public nonce is the point at infinity.
ErrNoncePointAtInfinity = fmt.Errorf("signing nonce is the infinity " + ErrNoncePointAtInfinity = errors.New("signing nonce is the infinity " +
"point") "point")
// ErrPrivKeyZero is returned when the private key for signing is // ErrPrivKeyZero is returned when the private key for signing is
// actually zero. // actually zero.
ErrPrivKeyZero = fmt.Errorf("priv key is zero") ErrPrivKeyZero = errors.New("priv key is zero")
// ErrPartialSigInvalid is returned when a partial is found to be // ErrPartialSigInvalid is returned when a partial is found to be
// invalid. // invalid.
ErrPartialSigInvalid = fmt.Errorf("partial signature is invalid") ErrPartialSigInvalid = errors.New("partial signature is invalid")
// ErrSecretNonceZero is returned when a secret nonce is passed in a // ErrSecretNonceZero is returned when a secret nonce is passed in a
// zero. // zero.
ErrSecretNonceZero = fmt.Errorf("secret nonce is blank") ErrSecretNonceZero = errors.New("secret nonce is blank")
// ErrSecNoncePubkey is returned when the signing key does not match the // ErrSecNoncePubkey is returned when the signing key does not match the
// sec nonce pubkey // sec nonce pubkey
ErrSecNoncePubkey = fmt.Errorf("public key does not match secnonce") ErrSecNoncePubkey = errors.New("public key does not match secnonce")
// ErrPubkeyNotIncluded is returned when the signers pubkey is not included // ErrPubkeyNotIncluded is returned when the signers pubkey is not included
// in the list of pubkeys. // in the list of pubkeys.
ErrPubkeyNotIncluded = fmt.Errorf("signer's pubkey must be included" + ErrPubkeyNotIncluded = errors.New("signer's pubkey must be included" +
" in the list of pubkeys") " in the list of pubkeys")
) )
@ -397,7 +397,7 @@ func Sign(secNonce [SecNonceSize]byte, privKey *btcec.PrivateKey,
signOpts..., signOpts...,
) )
if !sigValid { if !sigValid {
return nil, fmt.Errorf("sig is invalid!") return nil, errors.New("sig is invalid!")
} }
} }

View file

@ -6,6 +6,7 @@
package schnorr package schnorr
import ( import (
"errors"
"fmt" "fmt"
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
@ -22,7 +23,7 @@ const (
// the BIP-340 32-byte format. // the BIP-340 32-byte format.
func ParsePubKey(pubKeyStr []byte) (*btcec.PublicKey, error) { func ParsePubKey(pubKeyStr []byte) (*btcec.PublicKey, error) {
if pubKeyStr == nil { if pubKeyStr == nil {
err := fmt.Errorf("nil pubkey byte string") err := errors.New("nil pubkey byte string")
return nil, err return nil, err
} }
if len(pubKeyStr) != PubKeyBytesLen { if len(pubKeyStr) != PubKeyBytesLen {

View file

@ -7,7 +7,7 @@ package builder
import ( import (
"crypto/rand" "crypto/rand"
"fmt" "errors"
"io" "io"
"math" "math"
@ -210,10 +210,10 @@ func (b *GCSBuilder) Build() (*gcs.Filter, error) {
// We'll ensure that all the parameters we need to actually build the // We'll ensure that all the parameters we need to actually build the
// filter properly are set. // filter properly are set.
if b.p == 0 { if b.p == 0 {
return nil, fmt.Errorf("p value is not set, cannot build") return nil, errors.New("p value is not set, cannot build")
} }
if b.m == 0 { if b.m == 0 {
return nil, fmt.Errorf("m value is not set, cannot build") return nil, errors.New("m value is not set, cannot build")
} }
dataSlice := make([][]byte, 0, len(b.data)) dataSlice := make([][]byte, 0, len(b.data))

View file

@ -7,7 +7,7 @@ package gcs
import ( import (
"bytes" "bytes"
"fmt" "errors"
"io" "io"
"sort" "sort"
@ -20,11 +20,11 @@ import (
var ( var (
// ErrNTooBig signifies that the filter can't handle N items. // ErrNTooBig signifies that the filter can't handle N items.
ErrNTooBig = fmt.Errorf("N is too big to fit in uint32") ErrNTooBig = errors.New("N is too big to fit in uint32")
// ErrPTooBig signifies that the filter can't handle `1/2**P` // ErrPTooBig signifies that the filter can't handle `1/2**P`
// collision probability. // collision probability.
ErrPTooBig = fmt.Errorf("P is too big to fit in uint32") ErrPTooBig = errors.New("P is too big to fit in uint32")
) )
const ( const (

View file

@ -13,6 +13,7 @@ package psbt
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"github.com/btcsuite/btcd/btcec/v2/schnorr" "github.com/btcsuite/btcd/btcec/v2/schnorr"
@ -547,7 +548,7 @@ func finalizeTaprootInput(p *Packet, inIndex int) error {
targetLeafHash := pInput.TaprootScriptSpendSig[0].LeafHash targetLeafHash := pInput.TaprootScriptSpendSig[0].LeafHash
leafScript, err := FindLeafScript(pInput, targetLeafHash) leafScript, err := FindLeafScript(pInput, targetLeafHash)
if err != nil { if err != nil {
return fmt.Errorf("control block for script spend " + return errors.New("control block for script spend " +
"signature not found") "signature not found")
} }

View file

@ -5,6 +5,7 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"net" "net"
@ -134,7 +135,7 @@ func normalizeAddress(addr string, chain *chaincfg.Params, useWallet bool) (stri
case &chaincfg.RegressionNetParams: case &chaincfg.RegressionNetParams:
if useWallet { if useWallet {
// TODO: add port once regtest is supported in btcwallet // TODO: add port once regtest is supported in btcwallet
paramErr := fmt.Errorf("cannot use -wallet with -regtest, btcwallet not yet compatible with regtest") paramErr := errors.New("cannot use -wallet with -regtest, btcwallet not yet compatible with regtest")
return "", paramErr return "", paramErr
} else { } else {
defaultPort = "18334" defaultPort = "18334"

View file

@ -104,7 +104,7 @@ func sendPostRequest(marshalledJSON []byte, cfg *config) ([]byte, error) {
} }
// Handle unsuccessful HTTP responses // Handle unsuccessful HTTP responses
if httpResponse.StatusCode < 200 || httpResponse.StatusCode >= 300 { if httpResponse.StatusCode < http.StatusOK || httpResponse.StatusCode >= http.StatusMultipleChoices {
// Generate a standard error to return if the server body is // Generate a standard error to return if the server body is
// empty. This should not happen very often, but it's better // empty. This should not happen very often, but it's better
// than showing nothing in case the target server has a poor // than showing nothing in case the target server has a poor

View file

@ -229,7 +229,7 @@ func getServiceURL(rootURL string) (url string, err error) {
return return
} }
defer r.Body.Close() defer r.Body.Close()
if r.StatusCode >= 400 { if r.StatusCode >= http.StatusBadRequest {
err = errors.New(fmt.Sprint(r.StatusCode)) err = errors.New(fmt.Sprint(r.StatusCode))
return return
} }
@ -312,7 +312,7 @@ func soapRequest(url, function, message string) (replyXML []byte, err error) {
defer r.Body.Close() defer r.Body.Close()
} }
if r.StatusCode >= 400 { if r.StatusCode >= http.StatusBadRequest {
err = errors.New("Error " + strconv.Itoa(r.StatusCode) + " for " + function) err = errors.New("Error " + strconv.Itoa(r.StatusCode) + " for " + function)
r = nil r = nil
return return

View file

@ -6,6 +6,7 @@ package wire
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io" "io"
"unicode/utf8" "unicode/utf8"
@ -81,11 +82,11 @@ const (
var LatestEncoding = WitnessEncoding var LatestEncoding = WitnessEncoding
// ErrUnknownMessage is the error returned when decoding an unknown message. // ErrUnknownMessage is the error returned when decoding an unknown message.
var ErrUnknownMessage = fmt.Errorf("received unknown message") var ErrUnknownMessage = errors.New("received unknown message")
// ErrInvalidHandshake is the error returned when a peer sends us a known // ErrInvalidHandshake is the error returned when a peer sends us a known
// message that does not belong in the version-verack handshake. // message that does not belong in the version-verack handshake.
var ErrInvalidHandshake = fmt.Errorf("invalid message during handshake") var ErrInvalidHandshake = errors.New("invalid message during handshake")
// Message is an interface that describes a bitcoin message. A type that // Message is an interface that describes a bitcoin message. A type that
// implements Message has complete control over the representation of its data // implements Message has complete control over the representation of its data

View file

@ -115,7 +115,7 @@ const (
var ( var (
// errSuperfluousWitnessRecord is returned during tx deserialization when // errSuperfluousWitnessRecord is returned during tx deserialization when
// a tx has the witness marker flag set but has no witnesses. // a tx has the witness marker flag set but has no witnesses.
errSuperfluousWitnessRecord = fmt.Errorf( errSuperfluousWitnessRecord = errors.New(
"witness flag set but tx has no witnesses", "witness flag set but tx has no witnesses",
) )
) )

View file

@ -6,6 +6,7 @@ package wire
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io" "io"
"strings" "strings"
@ -79,7 +80,7 @@ func (msg *MsgVersion) AddService(service ServiceFlag) {
func (msg *MsgVersion) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error { func (msg *MsgVersion) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) error {
buf, ok := r.(*bytes.Buffer) buf, ok := r.(*bytes.Buffer)
if !ok { if !ok {
return fmt.Errorf("MsgVersion.BtcDecode reader is not a " + return errors.New("MsgVersion.BtcDecode reader is not a " +
"*bytes.Buffer") "*bytes.Buffer")
} }

View file

@ -3,7 +3,7 @@ package wire
import ( import (
"encoding/base32" "encoding/base32"
"encoding/binary" "encoding/binary"
"fmt" "errors"
"io" "io"
"net" "net"
"strings" "strings"
@ -22,7 +22,7 @@ var (
// ErrInvalidAddressSize is an error that means an incorrect address // ErrInvalidAddressSize is an error that means an incorrect address
// size was decoded for a networkID or that the address exceeded the // size was decoded for a networkID or that the address exceeded the
// maximum size for an unknown networkID. // maximum size for an unknown networkID.
ErrInvalidAddressSize = fmt.Errorf("invalid address size") ErrInvalidAddressSize = errors.New("invalid address size")
// ErrSkippedNetworkID is returned when the cjdns, i2p, or unknown // ErrSkippedNetworkID is returned when the cjdns, i2p, or unknown
// networks are encountered during decoding. btcd does not support i2p // networks are encountered during decoding. btcd does not support i2p
@ -32,7 +32,7 @@ var (
// addresses. This error can also be returned when an OnionCat-encoded // addresses. This error can also be returned when an OnionCat-encoded
// torv2 address is received with the ipv6 networkID. This error // torv2 address is received with the ipv6 networkID. This error
// signals to the caller to continue reading. // signals to the caller to continue reading.
ErrSkippedNetworkID = fmt.Errorf("skipped networkID") ErrSkippedNetworkID = errors.New("skipped networkID")
) )
// maxNetAddressV2Payload returns the max payload size for an address used in // maxNetAddressV2Payload returns the max payload size for an address used in
@ -225,7 +225,7 @@ func writeNetAddressV2(w io.Writer, pver uint32, na *NetAddressV2) error {
address = a.addr[:] address = a.addr[:]
default: default:
// This should not occur. // This should not occur.
return fmt.Errorf("unexpected address type") return errors.New("unexpected address type")
} }
if err := writeElement(w, netID); err != nil { if err := writeElement(w, netID); err != nil {