AddAutopilotSession
AddAutopilotSession creates a new LNC session and attempts to register it with the Autopilot server.
Source: lit-autopilot.proto
gRPC
rpc AddAutopilotSession (AddAutopilotSessionRequest) returns (AddAutopilotSessionResponse);
REST
HTTP Method | Path |
---|---|
POST | /v1/autopilot/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-autopilot.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.Autopilot(GRPC_HOST, creds);
let request = {
label: <string>,
expiry_timestamp_seconds: <uint64>,
mailbox_server_addr: <string>,
dev_server: <bool>,
features: <FeaturesEntry>,
session_rules: <RulesMap>,
no_privacy_mapper: <bool>,
linked_group_id: <bytes>,
privacy_flags: <uint64>,
privacy_flags_set: <bool>,
};
client.addAutopilotSession(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "session": <Session>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the lit-autopilot.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import lit-autopilot_pb2 as litrpc, lit-autopilot_pb2_grpc as lit-autopilotstub
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-autopilotstub.AutopilotStub(channel)
request = litrpc.AddAutopilotSessionRequest(
label=<string>,
expiry_timestamp_seconds=<uint64>,
mailbox_server_addr=<string>,
dev_server=<bool>,
features=<FeaturesEntry>,
session_rules=<RulesMap>,
no_privacy_mapper=<bool>,
linked_group_id=<bytes>,
privacy_flags=<uint64>,
privacy_flags_set=<bool>,
)
response = stub.AddAutopilotSession(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>
expiry_timestamp_seconds: <string>, // <uint64>
mailbox_server_addr: <string>, // <string>
dev_server: <boolean>, // <bool>
features: <object>, // <FeaturesEntry>
session_rules: <object>, // <RulesMap>
no_privacy_mapper: <boolean>, // <bool>
linked_group_id: <string>, // <bytes> (base64 encoded)
privacy_flags: <string>, // <uint64>
privacy_flags_set: <boolean>, // <bool>
};
let options = {
url: `https://${REST_HOST}/v1/autopilot/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/autopilot/sessions'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
data = {
'label': <string>,
'expiry_timestamp_seconds': <uint64>,
'mailbox_server_addr': <string>,
'dev_server': <bool>,
'features': <FeaturesEntry>,
'session_rules': <RulesMap>,
'no_privacy_mapper': <bool>,
'linked_group_id': base64.b64encode(<bytes>),
'privacy_flags': <uint64>,
'privacy_flags_set': <bool>,
}
r = requests.post(url, headers=headers, data=json.dumps(data), verify=TLS_PATH)
print(r.json())
# {
# "session": <Session>,
# }
$ litcli autopilot add --help
NAME:
litcli autopilot add - Initialize an Autopilot session.
USAGE:
litcli autopilot add [command options] [arguments...]
DESCRIPTION:
Initialize an Autopilot session.
If one of the 'feature-' flags is set for any 'feature', then that flag
must be provided for each 'feature'.
The rules and configuration options available for each feature can be
seen in the 'autopilot features' output. For a rule, all fields must be
set since the unset ones are interpreteded as zero values. Rule values
must adhere to the limits found in 'autopilot features'. If a rule is
not set, default values are used.
An example call for AutoFees reads:
#!/bin/bash
./litcli autopilot add --label=customRules \
--feature=AutoFees \
--feature-rules='{
"rules": {
"channel-policy-bounds": {
"chan_policy_bounds": {
"min_base_msat": "0",
"max_base_msat": "10000",
"min_rate_ppm": 10,
"max_rate_ppm": 5000,
"min_cltv_delta": 60,
"max_cltv_delta": 120,
"min_htlc_msat": "1",
"max_htlc_msat": "100000000000"
}
},
"peer-restriction": {
"peer_restrict": {
"peer_ids": [
"abcabc",
"defdef"
]
}
}
}
}' \
--feature-config='{}'
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.
--feature value
--group_id value The hex encoded group ID of the session group to link this one to.
--feature-config value JSON-serialized configuration with the expected format: {"version":0,"option1":"parameter1","option2":"parameter2",...}. An empty configuration is allowed with {} to use the default configuration.
--feature-rules value JSON-serialized rule map (see main description for a format example).An empty rule map is allowed with {} to use the default rules.
--privacy-flags value String representation of privacy flags to set for the session. Each individual flag will remove privacy from certain aspects of messages transmitted to autopilot. The strongest privacy is on by default and an empty string means full privacy. Some features may not be able to run correctly with full privacy, see the autopilot features call for a list of default required privacy flags. Those minimally required privacy flags are set automatically if nothing is specified here. Combining several features will require the union of all individual feature's privacy flags, which is why it is recommended to register each feature separately for best privacy. Linking to a previous session must preserve privacy flags of the previous session. Example: "ClearPubkeys|ClearAmounts"
Messages
litrpc.AddAutopilotSessionRequest
Source: lit-autopilot.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
label | string | string | body |
expiry_timestamp_seconds | uint64 | string | body |
mailbox_server_addr | string | string | body |
dev_server | bool | boolean | body |
features | FeaturesEntry[] | object | body |
session_rules | RulesMap | object | body |
no_privacy_mapper | bool | boolean | body |
linked_group_id | bytes | string | body |
privacy_flags | uint64 | string | body |
privacy_flags_set | bool | boolean | body |
litrpc.AddAutopilotSessionResponse
Source: lit-autopilot.proto
Field | gRPC Type | REST Type |
---|---|---|
session | Session | object |
Nested Messages
litrpc.AddAutopilotSessionRequest.FeaturesEntry
Field | gRPC Type | REST Type |
---|---|---|
key | string | unknown |
value | FeatureConfig | unknown |
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.FeatureConfig
Field | gRPC Type | REST Type |
---|---|---|
rules | RulesMap | object |
config | bytes | string |
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 |