mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
... and out of the `sessions` directory. This is to avoid import cycles when we start explicitly linking accounts to sessions.
30 lines
743 B
Go
30 lines
743 B
Go
package macaroons
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
|
"google.golang.org/protobuf/proto"
|
|
"gopkg.in/macaroon-bakery.v2/bakery"
|
|
"gopkg.in/macaroon.v2"
|
|
)
|
|
|
|
// RootKeyIDFromMacaroon extracts the root key ID of the passed macaroon.
|
|
func RootKeyIDFromMacaroon(mac *macaroon.Macaroon) (uint64, error) {
|
|
rawID := mac.Id()
|
|
if rawID[0] != byte(bakery.LatestVersion) {
|
|
return 0, fmt.Errorf("mac id is not on the latest version")
|
|
}
|
|
|
|
decodedID := &lnrpc.MacaroonId{}
|
|
idProto := rawID[1:]
|
|
err := proto.Unmarshal(idProto, decodedID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
// The storage ID is a string representation of a 64-bit unsigned
|
|
// number.
|
|
return strconv.ParseUint(string(decodedID.StorageId), 10, 64)
|
|
}
|