refactor: complete coreerr.E() conversion across all packages
Convert all remaining fmt.Errorf and errors.New in production code to coreerr.E(). Covers crypto/ (keygen, signature, clsag, keyimage, pow), consensus/block, and chain/ring. Only sentinel error definitions in errors.go and varint.go retain errors.New (correct usage). Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
772cd1b0fd
commit
97c5510184
5 changed files with 23 additions and 17 deletions
|
|
@ -8,8 +8,9 @@ package crypto
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
|
||||
coreerr "forge.lthn.ai/core/go-log"
|
||||
)
|
||||
|
||||
// PointMul8 multiplies a curve point by the cofactor 8.
|
||||
|
|
@ -20,7 +21,7 @@ func PointMul8(pk [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&result[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return result, errors.New("crypto: point_mul8 failed")
|
||||
return result, coreerr.E("PointMul8", "point_mul8 failed", nil)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
@ -34,7 +35,7 @@ func PointDiv8(pk [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&result[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return result, errors.New("crypto: point_div8 failed")
|
||||
return result, coreerr.E("PointDiv8", "point_div8 failed", nil)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
@ -48,7 +49,7 @@ func PointSub(a, b [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&result[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return result, errors.New("crypto: point_sub failed")
|
||||
return result, coreerr.E("PointSub", "point_sub failed", nil)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
@ -81,7 +82,7 @@ func GenerateCLSAGGG(hash [32]byte, ring []byte, ringSize int,
|
|||
(*C.uint8_t)(unsafe.Pointer(&sig[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return nil, errors.New("crypto: generate_CLSAG_GG failed")
|
||||
return nil, coreerr.E("GenerateCLSAGGG", "generate_CLSAG_GG failed", nil)
|
||||
}
|
||||
return sig, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ package crypto
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
coreerr "forge.lthn.ai/core/go-log"
|
||||
)
|
||||
|
||||
// GenerateKeys creates a new random key pair.
|
||||
|
|
@ -20,7 +21,7 @@ func GenerateKeys() (pub [32]byte, sec [32]byte, err error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&sec[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
err = fmt.Errorf("crypto: generate_keys failed (rc=%d)", rc)
|
||||
err = coreerr.E("GenerateKeys", fmt.Sprintf("generate_keys failed (rc=%d)", rc), nil)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -33,7 +34,7 @@ func SecretToPublic(sec [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&pub[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return pub, fmt.Errorf("crypto: secret_to_public failed (rc=%d)", rc)
|
||||
return pub, coreerr.E("SecretToPublic", fmt.Sprintf("secret_to_public failed (rc=%d)", rc), nil)
|
||||
}
|
||||
return pub, nil
|
||||
}
|
||||
|
|
@ -52,7 +53,7 @@ func GenerateKeyDerivation(pub [32]byte, sec [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&d[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return d, errors.New("crypto: generate_key_derivation failed")
|
||||
return d, coreerr.E("GenerateKeyDerivation", "generate_key_derivation failed", nil)
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
|
@ -67,7 +68,7 @@ func DerivePublicKey(derivation [32]byte, index uint64, base [32]byte) ([32]byte
|
|||
(*C.uint8_t)(unsafe.Pointer(&derived[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return derived, errors.New("crypto: derive_public_key failed")
|
||||
return derived, coreerr.E("DerivePublicKey", "derive_public_key failed", nil)
|
||||
}
|
||||
return derived, nil
|
||||
}
|
||||
|
|
@ -82,7 +83,7 @@ func DeriveSecretKey(derivation [32]byte, index uint64, base [32]byte) ([32]byte
|
|||
(*C.uint8_t)(unsafe.Pointer(&derived[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return derived, errors.New("crypto: derive_secret_key failed")
|
||||
return derived, coreerr.E("DeriveSecretKey", "derive_secret_key failed", nil)
|
||||
}
|
||||
return derived, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@ package crypto
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
|
||||
coreerr "forge.lthn.ai/core/go-log"
|
||||
)
|
||||
|
||||
// GenerateKeyImage computes the key image for a public/secret key pair.
|
||||
|
|
@ -22,7 +23,7 @@ func GenerateKeyImage(pub [32]byte, sec [32]byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&ki[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return ki, errors.New("crypto: generate_key_image failed")
|
||||
return ki, coreerr.E("GenerateKeyImage", "generate_key_image failed", nil)
|
||||
}
|
||||
return ki, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import "C"
|
|||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
coreerr "forge.lthn.ai/core/go-log"
|
||||
)
|
||||
|
||||
// RandomXHash computes the RandomX PoW hash. The key is the cache
|
||||
|
|
@ -23,7 +25,7 @@ func RandomXHash(key, input []byte) ([32]byte, error) {
|
|||
(*C.uint8_t)(unsafe.Pointer(&output[0])),
|
||||
)
|
||||
if ret != 0 {
|
||||
return output, fmt.Errorf("crypto: RandomX hash failed with code %d", ret)
|
||||
return output, coreerr.E("RandomXHash", fmt.Sprintf("RandomX hash failed with code %d", ret), nil)
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@ package crypto
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
|
||||
coreerr "forge.lthn.ai/core/go-log"
|
||||
)
|
||||
|
||||
// GenerateSignature creates a standard (non-ring) signature.
|
||||
|
|
@ -22,7 +23,7 @@ func GenerateSignature(hash [32]byte, pub [32]byte, sec [32]byte) ([64]byte, err
|
|||
(*C.uint8_t)(unsafe.Pointer(&sig[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return sig, errors.New("crypto: generate_signature failed")
|
||||
return sig, coreerr.E("GenerateSignature", "generate_signature failed", nil)
|
||||
}
|
||||
return sig, nil
|
||||
}
|
||||
|
|
@ -60,7 +61,7 @@ func GenerateRingSignature(hash [32]byte, image [32]byte, pubs [][32]byte,
|
|||
(*C.uint8_t)(unsafe.Pointer(&flatSigs[0])),
|
||||
)
|
||||
if rc != 0 {
|
||||
return nil, errors.New("crypto: generate_ring_signature failed")
|
||||
return nil, coreerr.E("GenerateRingSignature", "generate_ring_signature failed", nil)
|
||||
}
|
||||
|
||||
sigs := make([][64]byte, n)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue