Files
nostr/crypto/p8k/utils_other.go
mleku 511bba3a12 Add cross-platform support for crypto/p8k package
- Split all p8k files into *_linux.go and *_other.go variants
- Linux files use purego to load libsecp256k1.so dynamically
- Other platforms (darwin, windows, android, js/wasm) use stub that
  forces fallback to pure Go p256k1.mleku.dev implementation
- Add !android to Linux build tags since Android matches linux but
  purego requires CGO on Android
- Extract shared constants to constants.go (no build tags)
- Enables cross-compilation for macOS, Windows, and Android without
  requiring libsecp256k1 or CGO

Build tags:
- Linux: //go:build linux && !android && !purego
- Other: //go:build !linux || android || purego

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 11:14:46 +00:00

79 lines
3.5 KiB
Go

//go:build !linux || android || purego
package secp
import (
"fmt"
"runtime"
)
// GeneratePrivateKey always returns an error on non-Linux platforms
func GeneratePrivateKey() (privKey []byte, err error) {
return nil, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// PublicKeyFromPrivate always returns an error on non-Linux platforms
func PublicKeyFromPrivate(privKey []byte, compressed bool) (pubKey []byte, err error) {
return nil, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// SignMessage always returns an error on non-Linux platforms
func SignMessage(msgHash []byte, privKey []byte) (sig []byte, err error) {
return nil, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// VerifyMessage always returns an error on non-Linux platforms
func VerifyMessage(msgHash []byte, compactSig []byte, serializedPubKey []byte) (valid bool, err error) {
return false, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// SignMessageDER always returns an error on non-Linux platforms
func SignMessageDER(msgHash []byte, privKey []byte) (derSig []byte, err error) {
return nil, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// VerifyMessageDER always returns an error on non-Linux platforms
func VerifyMessageDER(msgHash []byte, derSig []byte, serializedPubKey []byte) (valid bool, err error) {
return false, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// SchnorrSign always returns an error on non-Linux platforms
func SchnorrSign(msgHash []byte, privKey []byte, auxRand []byte) (sig []byte, err error) {
return nil, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// SchnorrVerifyWithPubKey always returns an error on non-Linux platforms
func SchnorrVerifyWithPubKey(msgHash []byte, sig []byte, xonlyPubKey []byte) (valid bool, err error) {
return false, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// XOnlyPubKeyFromPrivate always returns an error on non-Linux platforms
func XOnlyPubKeyFromPrivate(privKey []byte) (xonly []byte, pkParity int32, err error) {
return nil, 0, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// ComputeECDH always returns an error on non-Linux platforms
func ComputeECDH(serializedPubKey []byte, privKey []byte) (secret []byte, err error) {
return nil, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// SignRecoverableCompact always returns an error on non-Linux platforms
func SignRecoverableCompact(msgHash []byte, privKey []byte) (sig []byte, recID int32, err error) {
return nil, 0, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// RecoverPubKey always returns an error on non-Linux platforms
func RecoverPubKey(msgHash []byte, compactSig []byte, recID int32, compressed bool) (pubKey []byte, err error) {
return nil, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// ValidatePrivateKey always returns an error on non-Linux platforms
func ValidatePrivateKey(privKey []byte) (valid bool, err error) {
return false, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}
// IsPublicKeyValid always returns an error on non-Linux platforms
func IsPublicKeyValid(serializedPubKey []byte) (valid bool, err error) {
return false, fmt.Errorf("not supported on %s - use pure Go implementation", runtime.GOOS)
}