Skip to content

lib+api: add litd proto files and Lit API class #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as LndApi } from './lnd';
export { default as LoopApi } from './loop';
export { default as PoolApi } from './pool';
export { default as FaradayApi } from './faraday';
export { default as LitApi } from './lit';
19 changes: 19 additions & 0 deletions lib/api/lit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Autopilot, Firewall, Sessions } from '../types/proto/litrpc';
import { serviceNames as sn } from '../types/proto/schema';

/**
* An API wrapper to communicate with the LiT node via GRPC
*/
class LitApi {
autopilot: Autopilot;
firewall: Firewall;
sessions: Sessions;

constructor(createRpc: Function, lnc: any) {
this.autopilot = createRpc(sn.litrpc.Autopilot, lnc);
this.firewall = createRpc(sn.litrpc.Firewall, lnc);
this.sessions = createRpc(sn.litrpc.Sessions, lnc);
}
}

export default LitApi;
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './types/proto';
export { camelKeysToSnake, isObject, snakeKeysToCamel } from './util/objects';
export { LndApi, LoopApi, PoolApi, FaradayApi } from './api';
export { LndApi, LoopApi, PoolApi, FaradayApi, LitApi } from './api';
export { subscriptionMethods } from './types/proto/schema';
3 changes: 2 additions & 1 deletion lib/types/proto/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as frdrpc from './frdrpc';
import * as litrpc from './litrpc';
import * as autopilotrpc from './autopilotrpc';
import * as chainrpc from './chainrpc';
import * as invoicesrpc from './invoicesrpc';
Expand All @@ -10,4 +11,4 @@ import * as watchtowerrpc from './watchtowerrpc';
import * as wtclientrpc from './wtclientrpc';
import * as looprpc from './looprpc';
import * as poolrpc from './poolrpc';
export { frdrpc, autopilotrpc, chainrpc, invoicesrpc, lnrpc, routerrpc, signrpc, walletrpc, watchtowerrpc, wtclientrpc, looprpc, poolrpc };
export { frdrpc, litrpc, autopilotrpc, chainrpc, invoicesrpc, lnrpc, routerrpc, signrpc, walletrpc, watchtowerrpc, wtclientrpc, looprpc, poolrpc };
165 changes: 165 additions & 0 deletions lib/types/proto/lit/firewall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* eslint-disable */
export enum ActionState {
/** STATE_UNKNOWN - No state was assigned to the action. This should never be the case. */
STATE_UNKNOWN = 'STATE_UNKNOWN',
/**
* STATE_PENDING - Pending means that the request resulting in the action being created
* came through but that no response came back from the appropriate backend.
* This means that the Action is either still being processed or that it
* did not successfully complete.
*/
STATE_PENDING = 'STATE_PENDING',
/** STATE_DONE - Done means that the action successfully completed. */
STATE_DONE = 'STATE_DONE',
/** STATE_ERROR - Error means that the Action did not successfully complete. */
STATE_ERROR = 'STATE_ERROR',
UNRECOGNIZED = 'UNRECOGNIZED'
}

export interface PrivacyMapConversionRequest {
/**
* If set to true, then the input string will be taken as the real value and
* the response will the the pseudo value it if exists. Otherwise, the input
* string will be assumed to be the pseudo value.
*/
realToPseudo: boolean;
/** The session ID under which to search for the real-pseudo pair. */
sessionId: Uint8Array | string;
/** The input to be converted into the real or pseudo value. */
input: string;
}

export interface PrivacyMapConversionResponse {
/** The resulting real or pseudo output. */
output: string;
}

export interface ListActionsRequest {
/**
* The feature name which the filter the actions by. If left empty, all feature
* actions will be returned.
*/
featureName: string;
/**
* The actor name to filter on. If left empty, all actor actions will be
* returned.
*/
actorName: string;
/**
* The method name to filter on. If left empty, actions for any method will be
* returned.
*/
methodName: string;
/**
* The action state to filter on. If set to zero, actions for any state will
* be returned.
*/
state: ActionState;
/**
* The index of an action that will be used as the start of a query to
* determine which actions should be returned in the response.
*/
indexOffset: string;
/** The max number of actions to return in the response to this query. */
maxNumActions: string;
/**
* If set, the actions returned will result from seeking backwards from the
* specified index offset. This can be used to paginate backwards.
*/
reversed: boolean;
/**
* Set to true if the total number of all actions that match the given filters
* should be counted and returned in the request. Note that setting this will
* significantly decrease the performance of the query if there are many
* actions in the db.
*/
countTotal: boolean;
/**
* The session ID to filter on. If left empty, actions for any session will
* be returned.
*/
sessionId: Uint8Array | string;
/**
* If specified, then only actions created after the given timestamp will be
* considered.
*/
startTimestamp: string;
/**
* If specified, then only actions created before the given timestamp will be
* considered.
*/
endTimestamp: string;
}

export interface ListActionsResponse {
/** A list of actions performed by the autopilot server. */
actions: Action[];
/**
* The index of the last item in the set of returned actions. This can be used
* to seek further, pagination style.
*/
lastIndexOffset: string;
/**
* The total number of actions that matched the filter in the request. It is
* only set if count_total was set in the request.
*/
totalCount: string;
}

export interface Action {
/** The name of the actor that initiated the action. */
actorName: string;
/** The name of the feature that triggered the action. */
featureName: string;
/** A human readable reason that the action was performed. */
trigger: string;
/**
* A human readable string describing the intended outcome successfully
* performing the action.
*/
intent: string;
/** Structured info added by the action performer. */
structuredJsonData: string;
/** The URI of the method called. */
rpcMethod: string;
/** The parameters of the method call in compact json form. */
rpcParamsJson: string;
/** The unix timestamp in seconds at which the action was attempted. */
timestamp: string;
/** The action state. See ActionState for the meaning of each state. */
state: ActionState;
/**
* If the state is Error, then this string will show the human readable reason
* for why the action errored out.
*/
errorReason: string;
/** The ID of the session under which the action was performed. */
sessionId: Uint8Array | string;
}

export interface Firewall {
listActions(request?: DeepPartial<ListActionsRequest>): Promise<ListActionsResponse>;
privacyMapConversion(
request?: DeepPartial<PrivacyMapConversionRequest>
): Promise<PrivacyMapConversionResponse>;
}

type Builtin =
| Date
| Function
| Uint8Array
| string
| number
| boolean
| undefined;

type DeepPartial<T> = T extends Builtin
? T
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

158 changes: 158 additions & 0 deletions lib/types/proto/lit/lit-autopilot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/* eslint-disable */
import type {
RulesMap,
Session,
RuleValue,
MacaroonPermission
} from './lit-sessions';

export interface AddAutopilotSessionRequest {
/** A human readable label to assign to the session. */
label: string;
/** The unix timestamp at which this session should be revoked. */
expiryTimestampSeconds: string;
/** The address of the mailbox server to connect to for this session. */
mailboxServerAddr: string;
/** Set to true if tls should be skipped for when connecting to the mailbox. */
devServer: boolean;
/**
* The features that the session should subscribe to. Each feature maps to
* a FeatureConfig that should be applied to that feature.
*/
features: { [key: string]: FeatureConfig };
/**
* Rules that apply to the entire session. By default, no rules will apply
* to the entire session.
*/
sessionRules: RulesMap | undefined;
/** Set to true of the session should not make use of the privacy mapper. */
noPrivacyMapper: boolean;
}

export interface AddAutopilotSessionRequest_FeaturesEntry {
key: string;
value: FeatureConfig | undefined;
}

export interface FeatureConfig {
/**
* The RulesMap acts as an override map. In other words, by default the rules
* values recommended by the Auto Pilot server will be used but the RulesMap
* can be used to override the defaults.
*/
rules: RulesMap | undefined;
/** Serialised configuration for the feature. */
config: Uint8Array | string;
}

export interface ListAutopilotSessionsRequest {}

export interface ListAutopilotSessionsResponse {
/** A list of the Autopilot sessions. */
sessions: Session[];
}

export interface AddAutopilotSessionResponse {
/** Details of the session that was just created. */
session: Session | undefined;
}

export interface ListAutopilotFeaturesRequest {}

export interface ListAutopilotFeaturesResponse {
/** A map of feature names to Feature objects describing the feature. */
features: { [key: string]: Feature };
}

export interface ListAutopilotFeaturesResponse_FeaturesEntry {
key: string;
value: Feature | undefined;
}

export interface RevokeAutopilotSessionRequest {
localPublicKey: Uint8Array | string;
}

export interface RevokeAutopilotSessionResponse {}

export interface Feature {
/** Name is the name of the Autopilot feature. */
name: string;
/** A human readable description of what the feature offers. */
description: string;
/**
* A map of rules that make sense for this feature. Each rule is accompanied
* with appropriate default values for the feature along with minimum and
* maximum values for the rules.
*/
rules: { [key: string]: RuleValues };
/** A list of URI permissions required by the feature. */
permissionsList: Permissions[];
/**
* A boolean indicating if the user would need to upgrade their Litd version in
* order to subscribe to the Autopilot feature. This will be true if the
* feature rules set contains a rule that Litd is unaware of.
*/
requiresUpgrade: boolean;
}

export interface Feature_RulesEntry {
key: string;
value: RuleValues | undefined;
}

export interface RuleValues {
/** Whether or not the users version of Litd is aware of this rule. */
known: boolean;
/**
* The default values for the rule that the Autopilot server recommends for
* the associated feature.
*/
defaults: RuleValue | undefined;
/** The minimum sane value for this rule for the associated feature. */
minValue: RuleValue | undefined;
/** The maximum sane value for this rule for the associated feature. */
maxValue: RuleValue | undefined;
}

export interface Permissions {
/** The URI in question. */
method: string;
/** A list of the permissions required for this method. */
operations: MacaroonPermission[];
}

export interface Autopilot {
listAutopilotFeatures(
request?: DeepPartial<ListAutopilotFeaturesRequest>
): Promise<ListAutopilotFeaturesResponse>;
addAutopilotSession(
request?: DeepPartial<AddAutopilotSessionRequest>
): Promise<AddAutopilotSessionResponse>;
listAutopilotSessions(
request?: DeepPartial<ListAutopilotSessionsRequest>
): Promise<ListAutopilotSessionsResponse>;
revokeAutopilotSession(
request?: DeepPartial<RevokeAutopilotSessionRequest>
): Promise<RevokeAutopilotSessionResponse>;
}

type Builtin =
| Date
| Function
| Uint8Array
| string
| number
| boolean
| undefined;

type DeepPartial<T> = T extends Builtin
? T
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

Loading