Skip to content

Commit 72faf76

Browse files
committed
session: store macaroon recipe instead of macaroon
In this commit, the `macaroon` field of `Session` is removed and instead a `MacaroonRecipe` is added.
1 parent 5cf26cb commit 72faf76

File tree

4 files changed

+611
-60
lines changed

4 files changed

+611
-60
lines changed

session/interface.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/btcsuite/btcd/btcec"
99
"github.com/lightninglabs/lightning-node-connect/mailbox"
10+
"gopkg.in/macaroon-bakery.v2/bakery"
1011
"gopkg.in/macaroon.v2"
1112
)
1213

@@ -30,6 +31,13 @@ const (
3031
StateExpired State = 3
3132
)
3233

34+
// MacaroonRecipe defines the permissions and caveats that should be used
35+
// to bake a macaroon.
36+
type MacaroonRecipe struct {
37+
Permissions []bakery.Op
38+
Caveats []macaroon.Caveat
39+
}
40+
3341
// Session is a struct representing a long-term Terminal Connect session.
3442
type Session struct {
3543
Label string
@@ -39,7 +47,7 @@ type Session struct {
3947
ServerAddr string
4048
DevServer bool
4149
MacaroonRootKey uint64
42-
Macaroon *macaroon.Macaroon
50+
MacaroonRecipe *MacaroonRecipe
4351
PairingSecret [mailbox.NumPasswordBytes]byte
4452
LocalPrivateKey *btcec.PrivateKey
4553
LocalPublicKey *btcec.PublicKey
@@ -48,7 +56,8 @@ type Session struct {
4856

4957
// NewSession creates a new session with the given user-defined parameters.
5058
func NewSession(label string, typ Type, expiry time.Time, serverAddr string,
51-
devServer bool) (*Session, error) {
59+
devServer bool, perms []bakery.Op, caveats []macaroon.Caveat) (*Session,
60+
error) {
5261

5362
_, pairingSecret, err := mailbox.NewPassword()
5463
if err != nil {
@@ -62,7 +71,7 @@ func NewSession(label string, typ Type, expiry time.Time, serverAddr string,
6271
pubKey := privateKey.PubKey()
6372
macRootKey := binary.BigEndian.Uint64(pubKey.SerializeCompressed()[0:8])
6473

65-
return &Session{
74+
sess := &Session{
6675
Label: label,
6776
State: StateCreated,
6877
Type: typ,
@@ -74,7 +83,16 @@ func NewSession(label string, typ Type, expiry time.Time, serverAddr string,
7483
LocalPrivateKey: privateKey,
7584
LocalPublicKey: pubKey,
7685
RemotePublicKey: nil,
77-
}, nil
86+
}
87+
88+
if perms != nil || caveats != nil {
89+
sess.MacaroonRecipe = &MacaroonRecipe{
90+
Permissions: perms,
91+
Caveats: caveats,
92+
}
93+
}
94+
95+
return sess, nil
7896
}
7997

8098
// Store is the interface a persistent storage must implement for storing and

0 commit comments

Comments
 (0)