mirror of
https://github.com/guggero/chantools.git
synced 2026-08-13 12:33:34 +02:00
lnd/signer: add ECDH method
It can now be used as keychain.ECDHRing.
This commit is contained in:
parent
4a31d4c208
commit
22cff1a33b
1 changed files with 23 additions and 0 deletions
|
|
@ -308,3 +308,26 @@ func ECDH(privKey *btcec.PrivateKey, pub *btcec.PublicKey) ([32]byte, error) {
|
|||
sPubKey := btcec.NewPublicKey(&s.X, &s.Y)
|
||||
return sha256.Sum256(sPubKey.SerializeCompressed()), nil
|
||||
}
|
||||
|
||||
// ECDH performs a scalar multiplication (ECDH-like operation) between
|
||||
// the target key descriptor and remote public key. The output
|
||||
// returned will be the sha256 of the resulting shared point serialized
|
||||
// in compressed format. If k is our private key, and P is the public
|
||||
// key, we perform the following operation:
|
||||
//
|
||||
// sx := k*P
|
||||
// s := sha256(sx.SerializeCompressed())
|
||||
//
|
||||
// NOTE: This is part of the keychain.ECDHRing interface.
|
||||
func (s *Signer) ECDH(keyDesc keychain.KeyDescriptor, pubKey *btcec.PublicKey) (
|
||||
[32]byte, error) {
|
||||
|
||||
// First, derive the private key.
|
||||
privKey, err := s.FetchPrivateKey(&keyDesc)
|
||||
if err != nil {
|
||||
return [32]byte{}, fmt.Errorf("failed to derive the private "+
|
||||
"key: %w", err)
|
||||
}
|
||||
|
||||
return ECDH(privKey, pubKey)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue