7
7
8
8
"github.com/btcsuite/btcd/btcec"
9
9
"github.com/lightninglabs/lightning-node-connect/mailbox"
10
+ "gopkg.in/macaroon-bakery.v2/bakery"
10
11
"gopkg.in/macaroon.v2"
11
12
)
12
13
@@ -30,6 +31,13 @@ const (
30
31
StateExpired State = 3
31
32
)
32
33
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
+
33
41
// Session is a struct representing a long-term Terminal Connect session.
34
42
type Session struct {
35
43
Label string
@@ -39,7 +47,7 @@ type Session struct {
39
47
ServerAddr string
40
48
DevServer bool
41
49
MacaroonRootKey uint64
42
- Macaroon * macaroon. Macaroon
50
+ MacaroonRecipe * MacaroonRecipe
43
51
PairingSecret [mailbox .NumPasswordBytes ]byte
44
52
LocalPrivateKey * btcec.PrivateKey
45
53
LocalPublicKey * btcec.PublicKey
@@ -48,7 +56,8 @@ type Session struct {
48
56
49
57
// NewSession creates a new session with the given user-defined parameters.
50
58
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 ) {
52
61
53
62
_ , pairingSecret , err := mailbox .NewPassword ()
54
63
if err != nil {
@@ -62,7 +71,7 @@ func NewSession(label string, typ Type, expiry time.Time, serverAddr string,
62
71
pubKey := privateKey .PubKey ()
63
72
macRootKey := binary .BigEndian .Uint64 (pubKey .SerializeCompressed ()[0 :8 ])
64
73
65
- return & Session {
74
+ sess := & Session {
66
75
Label : label ,
67
76
State : StateCreated ,
68
77
Type : typ ,
@@ -74,7 +83,16 @@ func NewSession(label string, typ Type, expiry time.Time, serverAddr string,
74
83
LocalPrivateKey : privateKey ,
75
84
LocalPublicKey : pubKey ,
76
85
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
78
96
}
79
97
80
98
// Store is the interface a persistent storage must implement for storing and
0 commit comments