Skip to content

Commit

Permalink
Add a ToSchnorr function to convert ECDSAPrivateKey to SchnorrKeyPair
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai committed Apr 29, 2021
1 parent efb5e76 commit 1e10cbd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ecdsa_privkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
}

0 comments on commit 1e10cbd

Please sign in to comment.