mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 23:53:41 +02:00
watchtower: add wtclient.ClientSession constructor
This commit is contained in:
@@ -435,27 +435,19 @@ func getTowerAndSessionCandidates(db DB, keyRing ECDHKeyRing,
|
||||
}
|
||||
|
||||
for _, s := range sessions {
|
||||
towerKeyDesc, err := keyRing.DeriveKey(
|
||||
keychain.KeyLocator{
|
||||
Family: keychain.KeyFamilyTowerSession,
|
||||
Index: s.KeyIndex,
|
||||
},
|
||||
if !sessionFilter(s) {
|
||||
continue
|
||||
}
|
||||
|
||||
cs, err := NewClientSessionFromDBSession(
|
||||
s, tower, keyRing,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sessionKeyECDH := keychain.NewPubKeyECDH(
|
||||
towerKeyDesc, keyRing,
|
||||
)
|
||||
|
||||
// Add the session to the set of candidate sessions.
|
||||
candidateSessions[s.ID] = &ClientSession{
|
||||
ID: s.ID,
|
||||
ClientSessionBody: s.ClientSessionBody,
|
||||
Tower: tower,
|
||||
SessionKeyECDH: sessionKeyECDH,
|
||||
}
|
||||
candidateSessions[s.ID] = cs
|
||||
|
||||
perActiveTower(tower)
|
||||
}
|
||||
|
@@ -198,3 +198,30 @@ type ClientSession struct {
|
||||
// key used to connect to the watchtower.
|
||||
SessionKeyECDH keychain.SingleKeyECDH
|
||||
}
|
||||
|
||||
// NewClientSessionFromDBSession converts a wtdb.ClientSession to a
|
||||
// ClientSession.
|
||||
func NewClientSessionFromDBSession(s *wtdb.ClientSession, tower *Tower,
|
||||
keyRing ECDHKeyRing) (*ClientSession, error) {
|
||||
|
||||
towerKeyDesc, err := keyRing.DeriveKey(
|
||||
keychain.KeyLocator{
|
||||
Family: keychain.KeyFamilyTowerSession,
|
||||
Index: s.KeyIndex,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sessionKeyECDH := keychain.NewPubKeyECDH(
|
||||
towerKeyDesc, keyRing,
|
||||
)
|
||||
|
||||
return &ClientSession{
|
||||
ID: s.ID,
|
||||
ClientSessionBody: s.ClientSessionBody,
|
||||
Tower: tower,
|
||||
SessionKeyECDH: sessionKeyECDH,
|
||||
}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user