AddSession
AddSession adds and starts a new LNC session.
Source: lit-sessions.proto
gRPC
rpc AddSession (AddSessionRequest) returns (AddSessionResponse);
REST
HTTP Method | Path |
---|---|
POST | /v1/sessions |
Code Samples
- gRPC
- REST
- Shell
- Javascript
- Python
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const GRPC_HOST = 'localhost:8443'
const MACAROON_PATH = 'LIT_DIR/regtest/lit.macaroon'
const TLS_PATH = 'LIT_DIR/tls.cert'
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('lit-sessions.proto', loaderOptions);
const litrpc = grpc.loadPackageDefinition(packageDefinition).litrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new litrpc.Sessions(GRPC_HOST, creds);
let request = {
label: <string>,
session_type: <SessionType>,
expiry_timestamp_seconds: <uint64>,
mailbox_server_addr: <string>,
dev_server: <bool>,
macaroon_custom_permissions: <MacaroonPermission>,
account_id: <string>,
};
client.addSession(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "session": <Session>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the lit-sessions.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import lit-sessions_pb2 as litrpc, lit-sessions_pb2_grpc as lit-sessionsstub
GRPC_HOST = 'localhost:8443'
MACAROON_PATH = 'LIT_DIR/regtest/lit.macaroon'
TLS_PATH = 'LIT_DIR/tls.cert'
# create macaroon credentials
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
def metadata_callback(context, callback):
callback([('macaroon', macaroon)], None)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# create SSL credentials
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
# combine macaroon and SSL credentials
combined_creds = grpc.composite_channel_credentials(ssl_creds, auth_creds)
# make the request
channel = grpc.secure_channel(GRPC_HOST, combined_creds)
stub = lit-sessionsstub.SessionsStub(channel)
request = litrpc.AddSessionRequest(
label=<string>,
session_type=<SessionType>,
expiry_timestamp_seconds=<uint64>,
mailbox_server_addr=<string>,
dev_server=<bool>,
macaroon_custom_permissions=<MacaroonPermission>,
account_id=<string>,
)
response = stub.AddSession(request)
print(response)
# {
# "session": <Session>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8443'
const MACAROON_PATH = 'LIT_DIR/regtest/lit.macaroon'
let requestBody = {
label: <string>, // <string>
session_type: <string>, // <SessionType>
expiry_timestamp_seconds: <string>, // <uint64>
mailbox_server_addr: <string>, // <string>
dev_server: <boolean>, // <bool>
macaroon_custom_permissions: <array>, // <MacaroonPermission>
account_id: <string>, // <string>
};
let options = {
url: `https://${REST_HOST}/v1/sessions`,
// Work-around for self-signed certificates.
rejectUnauthorized: false,
json: true,
headers: {
'Grpc-Metadata-macaroon': fs.readFileSync(MACAROON_PATH).toString('hex'),
},
form: JSON.stringify(requestBody),
}
request.post(options, function(error, response, body) {
console.log(body);
});
// Console output:
// {
// "session": <object>, // <Session>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8443'
MACAROON_PATH = 'LIT_DIR/regtest/lit.macaroon'
TLS_PATH = 'LIT_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/sessions'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
data = {
'label': <string>,
'session_type': <SessionType>,
'expiry_timestamp_seconds': <uint64>,
'mailbox_server_addr': <string>,
'dev_server': <bool>,
'macaroon_custom_permissions': <MacaroonPermission>,
'account_id': <string>,
}
r = requests.post(url, headers=headers, data=json.dumps(data), verify=TLS_PATH)
print(r.json())
# {
# "session": <Session>,
# }
$ litcli sessions add --help
NAME:
litcli sessions add - Create a new Lightning Node Connect session.
USAGE:
litcli sessions add [command options] [arguments...]
DESCRIPTION:
Add a new active session.
OPTIONS:
--label value The session label.
--expiry value The number of seconds that the session should remain active. (default: 7776000)
--mailboxserveraddr value The host:port of the mailbox server to be used. (default: "mailbox.terminal.lightning.today:443")
--devserver Set to true to skip verification of the server's tls cert.
--type value The session type to be created which will determine the permissions a user has when connecting with the session; options include readonly|admin|account|custom. (default: "readonly")
--uri lnrpc The URI that should be included in the macaroon of a custom session. Note that this flag will only be used if the 'type' flag is set to 'custom'. This flag can be specified multiple times if multiple URIs should be included. Note that a regex can also be specified which will then result in all URIs matching the regex to be included. For example, '/lnrpc\..*' will result in all lnrpc permissions being included.
--account_id value The account id that should be used for the account session. Note that this flag will only be used if the 'type' flag is set to 'account'.
Messages
litrpc.AddSessionRequest
Source: lit-sessions.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
label | string | string | body |
session_type | SessionType | string | body |
expiry_timestamp_seconds | uint64 | string | body |
mailbox_server_addr | string | string | body |
dev_server | bool | boolean | body |
macaroon_custom_permissions | MacaroonPermission[] | array | body |
account_id | string | string | body |
litrpc.AddSessionResponse
Source: lit-sessions.proto
Field | gRPC Type | REST Type |
---|---|---|
session | Session | object |
Nested Messages
litrpc.ChannelConstraint
Field | gRPC Type | REST Type |
---|---|---|
min_capacity_sat | uint64 | string |
max_capacity_sat | uint64 | string |
max_push_sat | uint64 | string |
private_allowed | bool | boolean |
public_allowed | bool | boolean |
litrpc.ChannelPolicyBounds
Field | gRPC Type | REST Type |
---|---|---|
min_base_msat | uint64 | string |
max_base_msat | uint64 | string |
min_rate_ppm | uint32 | integer |
max_rate_ppm | uint32 | integer |
min_cltv_delta | uint32 | integer |
max_cltv_delta | uint32 | integer |
min_htlc_msat | uint64 | string |
max_htlc_msat | uint64 | string |
litrpc.ChannelRestrict
Field | gRPC Type | REST Type |
---|---|---|
channel_ids | uint64[] | array |
litrpc.HistoryLimit
Field | gRPC Type | REST Type |
---|---|---|
start_time | uint64 | string |
duration | uint64 | string |
litrpc.MacaroonPermission
Field | gRPC Type | REST Type |
---|---|---|
entity | string | string |
action | string | string |
litrpc.MacaroonRecipe
Field | gRPC Type | REST Type |
---|---|---|
permissions | MacaroonPermission[] | array |
caveats | string[] | array |
litrpc.OffChainBudget
Field | gRPC Type | REST Type |
---|---|---|
max_amt_msat | uint64 | string |
max_fees_msat | uint64 | string |
litrpc.OnChainBudget
Field | gRPC Type | REST Type |
---|---|---|
absolute_amt_sats | uint64 | string |
max_sat_per_v_byte | uint64 | string |
litrpc.PeerRestrict
Field | gRPC Type | REST Type |
---|---|---|
peer_ids | string[] | array |
litrpc.Rate
Field | gRPC Type | REST Type |
---|---|---|
iterations | uint32 | integer |
num_hours | uint32 | integer |
litrpc.RateLimit
Field | gRPC Type | REST Type |
---|---|---|
read_limit | Rate | object |
write_limit | Rate | object |
litrpc.RulesMap
Field | gRPC Type | REST Type |
---|---|---|
rules | RulesEntry[] | object |
litrpc.RulesMap.RulesEntry
Field | gRPC Type | REST Type |
---|---|---|
key | string | unknown |
value | RuleValue | unknown |
litrpc.RuleValue
Field | gRPC Type | REST Type |
---|---|---|
rate_limit | RateLimit | object |
chan_policy_bounds | ChannelPolicyBounds | object |
history_limit | HistoryLimit | object |
off_chain_budget | OffChainBudget | object |
on_chain_budget | OnChainBudget | object |
send_to_self | SendToSelf | object |
channel_restrict | ChannelRestrict | object |
peer_restrict | PeerRestrict | object |
channel_constraint | ChannelConstraint | object |
litrpc.SendToSelf
note
This response has no parameters.
litrpc.Session
Field | gRPC Type | REST Type |
---|---|---|
id | bytes | string |
label | string | string |
session_state | SessionState | string |
session_type | SessionType | string |
expiry_timestamp_seconds | uint64 | string |
mailbox_server_addr | string | string |
dev_server | bool | boolean |
pairing_secret | bytes | string |
pairing_secret_mnemonic | string | string |
local_public_key | bytes | string |
remote_public_key | bytes | string |
created_at | uint64 | string |
macaroon_recipe | MacaroonRecipe | object |
account_id | string | string |
autopilot_feature_info | AutopilotFeatureInfoEntry[] | object |
revoked_at | uint64 | string |
group_id | bytes | string |
feature_configs | FeatureConfigsEntry[] | object |
privacy_flags | uint64 | string |
litrpc.Session.AutopilotFeatureInfoEntry
Field | gRPC Type | REST Type |
---|---|---|
key | string | unknown |
value | RulesMap | unknown |
litrpc.Session.FeatureConfigsEntry
Field | gRPC Type | REST Type |
---|---|---|
key | string | unknown |
value | string | unknown |
Enums
litrpc.SessionState
Name | Number |
---|---|
STATE_CREATED | 0 |
STATE_IN_USE | 1 |
STATE_REVOKED | 2 |
STATE_EXPIRED | 3 |
litrpc.SessionType
Name | Number |
---|---|
TYPE_MACAROON_READONLY | 0 |
TYPE_MACAROON_ADMIN | 1 |
TYPE_MACAROON_CUSTOM | 2 |
TYPE_UI_PASSWORD | 3 |
TYPE_AUTOPILOT | 4 |
TYPE_MACAROON_ACCOUNT | 5 |