delphi.market/test/lnauth.go

36 lines
682 B
Go
Raw Normal View History

package test
import (
"crypto/ecdsa"
"crypto/rand"
"encoding/hex"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
)
2023-11-03 22:38:23 +00:00
func GenerateKeyPair() (*secp256k1.PrivateKey, *secp256k1.PublicKey, error) {
var (
sk *secp256k1.PrivateKey
2023-11-03 22:38:23 +00:00
err error
)
if sk, err = secp256k1.GeneratePrivateKey(); err != nil {
return nil, nil, err
}
return sk, sk.PubKey(), nil
}
func Sign(sk *secp256k1.PrivateKey, k1_ string) (string, error) {
var (
k1 []byte
sig []byte
err error
)
if k1, err = hex.DecodeString(k1_); err != nil {
2023-11-03 22:38:23 +00:00
return "", err
}
if sig, err = ecdsa.SignASN1(rand.Reader, sk.ToECDSA(), k1); err != nil {
2023-11-03 22:38:23 +00:00
return "", err
}
2023-11-03 22:38:23 +00:00
return hex.EncodeToString(sig), nil
}