Skip to content

Commit 2fb968b

Browse files
authored
Merge pull request #13 from lightninglabs/autopilot
lib+api: add litd proto files and Lit API class
2 parents 1417a94 + 71a00d6 commit 2fb968b

File tree

16 files changed

+1242
-6
lines changed

16 files changed

+1242
-6
lines changed

lib/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { default as LndApi } from './lnd';
22
export { default as LoopApi } from './loop';
33
export { default as PoolApi } from './pool';
44
export { default as FaradayApi } from './faraday';
5+
export { default as LitApi } from './lit';

lib/api/lit.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Autopilot, Firewall, Sessions } from '../types/proto/litrpc';
2+
import { serviceNames as sn } from '../types/proto/schema';
3+
4+
/**
5+
* An API wrapper to communicate with the LiT node via GRPC
6+
*/
7+
class LitApi {
8+
autopilot: Autopilot;
9+
firewall: Firewall;
10+
sessions: Sessions;
11+
12+
constructor(createRpc: Function, lnc: any) {
13+
this.autopilot = createRpc(sn.litrpc.Autopilot, lnc);
14+
this.firewall = createRpc(sn.litrpc.Firewall, lnc);
15+
this.sessions = createRpc(sn.litrpc.Sessions, lnc);
16+
}
17+
}
18+
19+
export default LitApi;

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './types/proto';
22
export { camelKeysToSnake, isObject, snakeKeysToCamel } from './util/objects';
3-
export { LndApi, LoopApi, PoolApi, FaradayApi } from './api';
3+
export { LndApi, LoopApi, PoolApi, FaradayApi, LitApi } from './api';
44
export { subscriptionMethods } from './types/proto/schema';

lib/types/proto/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as frdrpc from './frdrpc';
2+
import * as litrpc from './litrpc';
23
import * as autopilotrpc from './autopilotrpc';
34
import * as chainrpc from './chainrpc';
45
import * as invoicesrpc from './invoicesrpc';
@@ -10,4 +11,4 @@ import * as watchtowerrpc from './watchtowerrpc';
1011
import * as wtclientrpc from './wtclientrpc';
1112
import * as looprpc from './looprpc';
1213
import * as poolrpc from './poolrpc';
13-
export { frdrpc, autopilotrpc, chainrpc, invoicesrpc, lnrpc, routerrpc, signrpc, walletrpc, watchtowerrpc, wtclientrpc, looprpc, poolrpc };
14+
export { frdrpc, litrpc, autopilotrpc, chainrpc, invoicesrpc, lnrpc, routerrpc, signrpc, walletrpc, watchtowerrpc, wtclientrpc, looprpc, poolrpc };

lib/types/proto/lit/firewall.ts

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/* eslint-disable */
2+
export enum ActionState {
3+
/** STATE_UNKNOWN - No state was assigned to the action. This should never be the case. */
4+
STATE_UNKNOWN = 'STATE_UNKNOWN',
5+
/**
6+
* STATE_PENDING - Pending means that the request resulting in the action being created
7+
* came through but that no response came back from the appropriate backend.
8+
* This means that the Action is either still being processed or that it
9+
* did not successfully complete.
10+
*/
11+
STATE_PENDING = 'STATE_PENDING',
12+
/** STATE_DONE - Done means that the action successfully completed. */
13+
STATE_DONE = 'STATE_DONE',
14+
/** STATE_ERROR - Error means that the Action did not successfully complete. */
15+
STATE_ERROR = 'STATE_ERROR',
16+
UNRECOGNIZED = 'UNRECOGNIZED'
17+
}
18+
19+
export interface PrivacyMapConversionRequest {
20+
/**
21+
* If set to true, then the input string will be taken as the real value and
22+
* the response will the the pseudo value it if exists. Otherwise, the input
23+
* string will be assumed to be the pseudo value.
24+
*/
25+
realToPseudo: boolean;
26+
/** The session ID under which to search for the real-pseudo pair. */
27+
sessionId: Uint8Array | string;
28+
/** The input to be converted into the real or pseudo value. */
29+
input: string;
30+
}
31+
32+
export interface PrivacyMapConversionResponse {
33+
/** The resulting real or pseudo output. */
34+
output: string;
35+
}
36+
37+
export interface ListActionsRequest {
38+
/**
39+
* The feature name which the filter the actions by. If left empty, all feature
40+
* actions will be returned.
41+
*/
42+
featureName: string;
43+
/**
44+
* The actor name to filter on. If left empty, all actor actions will be
45+
* returned.
46+
*/
47+
actorName: string;
48+
/**
49+
* The method name to filter on. If left empty, actions for any method will be
50+
* returned.
51+
*/
52+
methodName: string;
53+
/**
54+
* The action state to filter on. If set to zero, actions for any state will
55+
* be returned.
56+
*/
57+
state: ActionState;
58+
/**
59+
* The index of an action that will be used as the start of a query to
60+
* determine which actions should be returned in the response.
61+
*/
62+
indexOffset: string;
63+
/** The max number of actions to return in the response to this query. */
64+
maxNumActions: string;
65+
/**
66+
* If set, the actions returned will result from seeking backwards from the
67+
* specified index offset. This can be used to paginate backwards.
68+
*/
69+
reversed: boolean;
70+
/**
71+
* Set to true if the total number of all actions that match the given filters
72+
* should be counted and returned in the request. Note that setting this will
73+
* significantly decrease the performance of the query if there are many
74+
* actions in the db.
75+
*/
76+
countTotal: boolean;
77+
/**
78+
* The session ID to filter on. If left empty, actions for any session will
79+
* be returned.
80+
*/
81+
sessionId: Uint8Array | string;
82+
/**
83+
* If specified, then only actions created after the given timestamp will be
84+
* considered.
85+
*/
86+
startTimestamp: string;
87+
/**
88+
* If specified, then only actions created before the given timestamp will be
89+
* considered.
90+
*/
91+
endTimestamp: string;
92+
}
93+
94+
export interface ListActionsResponse {
95+
/** A list of actions performed by the autopilot server. */
96+
actions: Action[];
97+
/**
98+
* The index of the last item in the set of returned actions. This can be used
99+
* to seek further, pagination style.
100+
*/
101+
lastIndexOffset: string;
102+
/**
103+
* The total number of actions that matched the filter in the request. It is
104+
* only set if count_total was set in the request.
105+
*/
106+
totalCount: string;
107+
}
108+
109+
export interface Action {
110+
/** The name of the actor that initiated the action. */
111+
actorName: string;
112+
/** The name of the feature that triggered the action. */
113+
featureName: string;
114+
/** A human readable reason that the action was performed. */
115+
trigger: string;
116+
/**
117+
* A human readable string describing the intended outcome successfully
118+
* performing the action.
119+
*/
120+
intent: string;
121+
/** Structured info added by the action performer. */
122+
structuredJsonData: string;
123+
/** The URI of the method called. */
124+
rpcMethod: string;
125+
/** The parameters of the method call in compact json form. */
126+
rpcParamsJson: string;
127+
/** The unix timestamp in seconds at which the action was attempted. */
128+
timestamp: string;
129+
/** The action state. See ActionState for the meaning of each state. */
130+
state: ActionState;
131+
/**
132+
* If the state is Error, then this string will show the human readable reason
133+
* for why the action errored out.
134+
*/
135+
errorReason: string;
136+
/** The ID of the session under which the action was performed. */
137+
sessionId: Uint8Array | string;
138+
}
139+
140+
export interface Firewall {
141+
listActions(request?: DeepPartial<ListActionsRequest>): Promise<ListActionsResponse>;
142+
privacyMapConversion(
143+
request?: DeepPartial<PrivacyMapConversionRequest>
144+
): Promise<PrivacyMapConversionResponse>;
145+
}
146+
147+
type Builtin =
148+
| Date
149+
| Function
150+
| Uint8Array
151+
| string
152+
| number
153+
| boolean
154+
| undefined;
155+
156+
type DeepPartial<T> = T extends Builtin
157+
? T
158+
: T extends Array<infer U>
159+
? Array<DeepPartial<U>>
160+
: T extends ReadonlyArray<infer U>
161+
? ReadonlyArray<DeepPartial<U>>
162+
: T extends {}
163+
? { [K in keyof T]?: DeepPartial<T[K]> }
164+
: Partial<T>;
165+
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/* eslint-disable */
2+
import type {
3+
RulesMap,
4+
Session,
5+
RuleValue,
6+
MacaroonPermission
7+
} from './lit-sessions';
8+
9+
export interface AddAutopilotSessionRequest {
10+
/** A human readable label to assign to the session. */
11+
label: string;
12+
/** The unix timestamp at which this session should be revoked. */
13+
expiryTimestampSeconds: string;
14+
/** The address of the mailbox server to connect to for this session. */
15+
mailboxServerAddr: string;
16+
/** Set to true if tls should be skipped for when connecting to the mailbox. */
17+
devServer: boolean;
18+
/**
19+
* The features that the session should subscribe to. Each feature maps to
20+
* a FeatureConfig that should be applied to that feature.
21+
*/
22+
features: { [key: string]: FeatureConfig };
23+
/**
24+
* Rules that apply to the entire session. By default, no rules will apply
25+
* to the entire session.
26+
*/
27+
sessionRules: RulesMap | undefined;
28+
/** Set to true of the session should not make use of the privacy mapper. */
29+
noPrivacyMapper: boolean;
30+
}
31+
32+
export interface AddAutopilotSessionRequest_FeaturesEntry {
33+
key: string;
34+
value: FeatureConfig | undefined;
35+
}
36+
37+
export interface FeatureConfig {
38+
/**
39+
* The RulesMap acts as an override map. In other words, by default the rules
40+
* values recommended by the Auto Pilot server will be used but the RulesMap
41+
* can be used to override the defaults.
42+
*/
43+
rules: RulesMap | undefined;
44+
/** Serialised configuration for the feature. */
45+
config: Uint8Array | string;
46+
}
47+
48+
export interface ListAutopilotSessionsRequest {}
49+
50+
export interface ListAutopilotSessionsResponse {
51+
/** A list of the Autopilot sessions. */
52+
sessions: Session[];
53+
}
54+
55+
export interface AddAutopilotSessionResponse {
56+
/** Details of the session that was just created. */
57+
session: Session | undefined;
58+
}
59+
60+
export interface ListAutopilotFeaturesRequest {}
61+
62+
export interface ListAutopilotFeaturesResponse {
63+
/** A map of feature names to Feature objects describing the feature. */
64+
features: { [key: string]: Feature };
65+
}
66+
67+
export interface ListAutopilotFeaturesResponse_FeaturesEntry {
68+
key: string;
69+
value: Feature | undefined;
70+
}
71+
72+
export interface RevokeAutopilotSessionRequest {
73+
localPublicKey: Uint8Array | string;
74+
}
75+
76+
export interface RevokeAutopilotSessionResponse {}
77+
78+
export interface Feature {
79+
/** Name is the name of the Autopilot feature. */
80+
name: string;
81+
/** A human readable description of what the feature offers. */
82+
description: string;
83+
/**
84+
* A map of rules that make sense for this feature. Each rule is accompanied
85+
* with appropriate default values for the feature along with minimum and
86+
* maximum values for the rules.
87+
*/
88+
rules: { [key: string]: RuleValues };
89+
/** A list of URI permissions required by the feature. */
90+
permissionsList: Permissions[];
91+
/**
92+
* A boolean indicating if the user would need to upgrade their Litd version in
93+
* order to subscribe to the Autopilot feature. This will be true if the
94+
* feature rules set contains a rule that Litd is unaware of.
95+
*/
96+
requiresUpgrade: boolean;
97+
}
98+
99+
export interface Feature_RulesEntry {
100+
key: string;
101+
value: RuleValues | undefined;
102+
}
103+
104+
export interface RuleValues {
105+
/** Whether or not the users version of Litd is aware of this rule. */
106+
known: boolean;
107+
/**
108+
* The default values for the rule that the Autopilot server recommends for
109+
* the associated feature.
110+
*/
111+
defaults: RuleValue | undefined;
112+
/** The minimum sane value for this rule for the associated feature. */
113+
minValue: RuleValue | undefined;
114+
/** The maximum sane value for this rule for the associated feature. */
115+
maxValue: RuleValue | undefined;
116+
}
117+
118+
export interface Permissions {
119+
/** The URI in question. */
120+
method: string;
121+
/** A list of the permissions required for this method. */
122+
operations: MacaroonPermission[];
123+
}
124+
125+
export interface Autopilot {
126+
listAutopilotFeatures(
127+
request?: DeepPartial<ListAutopilotFeaturesRequest>
128+
): Promise<ListAutopilotFeaturesResponse>;
129+
addAutopilotSession(
130+
request?: DeepPartial<AddAutopilotSessionRequest>
131+
): Promise<AddAutopilotSessionResponse>;
132+
listAutopilotSessions(
133+
request?: DeepPartial<ListAutopilotSessionsRequest>
134+
): Promise<ListAutopilotSessionsResponse>;
135+
revokeAutopilotSession(
136+
request?: DeepPartial<RevokeAutopilotSessionRequest>
137+
): Promise<RevokeAutopilotSessionResponse>;
138+
}
139+
140+
type Builtin =
141+
| Date
142+
| Function
143+
| Uint8Array
144+
| string
145+
| number
146+
| boolean
147+
| undefined;
148+
149+
type DeepPartial<T> = T extends Builtin
150+
? T
151+
: T extends Array<infer U>
152+
? Array<DeepPartial<U>>
153+
: T extends ReadonlyArray<infer U>
154+
? ReadonlyArray<DeepPartial<U>>
155+
: T extends {}
156+
? { [K in keyof T]?: DeepPartial<T[K]> }
157+
: Partial<T>;
158+

0 commit comments

Comments
 (0)