From 1e10cbd50f9eb3175cfd106f59e6006012ea20ed Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Thu, 29 Apr 2021 17:32:12 +0300 Subject: [PATCH] Add a ToSchnorr function to convert ECDSAPrivateKey to SchnorrKeyPair --- ecdsa_privkey.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ecdsa_privkey.go b/ecdsa_privkey.go index 88de9b5..d1be53e 100644 --- a/ecdsa_privkey.go +++ b/ecdsa_privkey.go @@ -123,7 +123,7 @@ func (key *ECDSAPrivateKey) Negate() error { return nil } -// Add a tweak to the public key by doing `key + tweak % Group Order`. this adds it in place. +// Add a tweak to the private key by doing `key + tweak % Group Order`. this adds it in place. // This is meant for creating BIP-32(HD) wallets func (key *ECDSAPrivateKey) Add(tweak [32]byte) error { if !key.init { @@ -137,3 +137,13 @@ func (key *ECDSAPrivateKey) Add(tweak [32]byte) error { } return nil } + +// ToSchnorr converts an ECDSA private key to a schnorr keypair +// Note: You shouldn't sign using the same key in both ECDSA and Schnorr signatures. +// this function is for convenience when using BIP-32 +func (key *ECDSAPrivateKey) ToSchnorr() (*SchnorrKeyPair, error) { + if !key.init { + return nil, errors.WithStack(errNonInitializedKey) + } + return DeserializeSchnorrPrivateKey((*SerializedPrivateKey)(&key.privateKey)) +}