//go:build wasm //:build wasm package schnorr import ( "crypto/secp256k1" "crypto/sha256" ) func PubKeyFromSecKey(seckey []byte) ([]byte, bool) { var sk [32]byte copy(sk[:], seckey) pk, ok := secp256k1.PubKeyFromSecKey(sk) if !ok { return nil, false } return pk[:], true } func SignSchnorr(seckey, msg, auxRand []byte) ([]byte, bool) { var sk, m, aux [32]byte copy(sk[:], seckey) copy(m[:], msg) copy(aux[:], auxRand) sig, ok := secp256k1.SignSchnorr(sk, m, aux) if !ok { return nil, false } return sig[:], true } func VerifySchnorr(pubkey, msg, sig []byte) (ok bool) { var pk, m [32]byte var s [64]byte copy(pk[:], pubkey) copy(m[:], msg) copy(s[:], sig) return secp256k1.VerifySchnorr(pk, m, s) } func ECDH(seckey, pubkey []byte) ([]byte, bool) { var sk, pk [32]byte copy(sk[:], seckey) copy(pk[:], pubkey) shared, ok := secp256k1.ECDH(sk, pk) if !ok { return nil, false } return shared[:], true } func SHA256Sum(data []byte) (buf []byte) { h := sha256.Sum(data) return h[:] } func ScalarAddModN(a, b []byte) ([]byte, bool) { var fa, fb [32]byte copy(fa[:], a) copy(fb[:], b) r, ok := secp256k1.ScalarAddModN(fa, fb) if !ok { return nil, false } return r[:], true } func CompressedPubKey(seckey []byte) ([]byte, bool) { var sk [32]byte copy(sk[:], seckey) cpk, ok := secp256k1.CompressedPubKey(sk) if !ok { return nil, false } return cpk[:], true }