Skip to content

Commit

Permalink
feat: ✨ bake macaroons
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed Jun 7, 2020
1 parent 7bdbaaf commit 8c9607d
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pages/tools.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { GridWrapper } from 'src/components/gridWrapper/GridWrapper';
import { withApollo } from 'config/client';
import { Bakery } from 'src/views/tools/bakery/Bakery';
import { BackupsView } from '../src/views/tools/backups/Backups';
import { MessagesView } from '../src/views/tools/messages/Messages';
import { WalletVersion } from '../src/views/tools/WalletVersion';
Expand All @@ -9,6 +10,7 @@ const ToolsView = () => (
<>
<BackupsView />
<MessagesView />
<Bakery />
<WalletVersion />
</>
);
Expand Down
4 changes: 3 additions & 1 deletion server/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { healthTypes } from './health/types';
import { githubResolvers } from './github/resolvers';
import { routeTypes } from './route/types';
import { generalResolvers } from './resolvers';
import { macaroonResolvers } from './macaroon/resolvers';

const typeDefs = [
generalTypes,
Expand Down Expand Up @@ -78,7 +79,8 @@ const resolvers = merge(
walletResolvers,
transactionResolvers,
healthResolvers,
githubResolvers
githubResolvers,
macaroonResolvers
);

export default makeExecutableSchema({ typeDefs, resolvers });
59 changes: 59 additions & 0 deletions server/schema/macaroon/resolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ContextType } from 'server/types/apiTypes';
import { requestLimiter } from 'server/helpers/rateLimiter';
import { getLnd } from 'server/helpers/helpers';
import { to } from 'server/helpers/async';
import { grantAccess } from 'ln-service';
import { AuthType } from 'src/context/AccountContext';
import { logger } from 'server/helpers/logger';

export type PermissionsType = {
is_ok_to_adjust_peers: boolean;
is_ok_to_create_chain_addresses: boolean;
is_ok_to_create_invoices: boolean;
is_ok_to_create_macaroons: boolean;
is_ok_to_derive_keys: boolean;
is_ok_to_get_chain_transactions: boolean;
is_ok_to_get_invoices: boolean;
is_ok_to_get_wallet_info: boolean;
is_ok_to_get_payments: boolean;
is_ok_to_get_peers: boolean;
is_ok_to_pay: boolean;
is_ok_to_send_to_chain_addresses: boolean;
is_ok_to_sign_bytes: boolean;
is_ok_to_sign_messages: boolean;
is_ok_to_stop_daemon: boolean;
is_ok_to_verify_bytes_signatures: boolean;
is_ok_to_verify_messages: boolean;
};

type ParamsType = {
auth: AuthType;
permissions: PermissionsType;
};

export const macaroonResolvers = {
Mutation: {
createMacaroon: async (
_: undefined,
params: ParamsType,
context: ContextType
) => {
await requestLimiter(context.ip, 'createMacaroon');

const { auth, permissions } = params;

const lnd = getLnd(auth, context);

const { macaroon, permissions: permissionList } = await to(
grantAccess({ lnd, ...permissions })
);

logger.debug(
'Macaroon created with the following permissions: %o',
permissionList.join(', ')
);

return macaroon;
},
},
};
21 changes: 21 additions & 0 deletions server/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ export const generalTypes = gql`
cert: String
}
input permissionsType {
is_ok_to_adjust_peers: Boolean
is_ok_to_create_chain_addresses: Boolean
is_ok_to_create_invoices: Boolean
is_ok_to_create_macaroons: Boolean
is_ok_to_derive_keys: Boolean
is_ok_to_get_chain_transactions: Boolean
is_ok_to_get_invoices: Boolean
is_ok_to_get_wallet_info: Boolean
is_ok_to_get_payments: Boolean
is_ok_to_get_peers: Boolean
is_ok_to_pay: Boolean
is_ok_to_send_to_chain_addresses: Boolean
is_ok_to_sign_bytes: Boolean
is_ok_to_sign_messages: Boolean
is_ok_to_stop_daemon: Boolean
is_ok_to_verify_bytes_signatures: Boolean
is_ok_to_verify_messages: Boolean
}
scalar Date
scalar Time
scalar DateTime
Expand Down Expand Up @@ -134,5 +154,6 @@ export const mutationTypes = gql`
maxFee: Int
): Int
logout(type: String!): Boolean
createMacaroon(auth: authType!, permissions: permissionsType!): String
}
`;
2 changes: 1 addition & 1 deletion src/components/generic/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from './Styled';
import { StatusDot, DetailLine } from './CardGeneric';

const shorten = (text: string): string => {
export const shorten = (text: string): string => {
const amount = 6;
const beginning = text.slice(0, amount);
const end = text.slice(text.length - amount);
Expand Down
64 changes: 64 additions & 0 deletions src/graphql/mutations/__generated__/createMacaroon.generated.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/graphql/mutations/createMacaroon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import gql from 'graphql-tag';

export const CREATE_MACAROON = gql`
mutation CreateMacaroon($auth: authType!, $permissions: permissionsType!) {
createMacaroon(auth: $auth, permissions: $permissions)
}
`;
26 changes: 26 additions & 0 deletions src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ export type AuthType = {
cert?: Maybe<Scalars['String']>;
};

export type PermissionsType = {
is_ok_to_adjust_peers?: Maybe<Scalars['Boolean']>;
is_ok_to_create_chain_addresses?: Maybe<Scalars['Boolean']>;
is_ok_to_create_invoices?: Maybe<Scalars['Boolean']>;
is_ok_to_create_macaroons?: Maybe<Scalars['Boolean']>;
is_ok_to_derive_keys?: Maybe<Scalars['Boolean']>;
is_ok_to_get_chain_transactions?: Maybe<Scalars['Boolean']>;
is_ok_to_get_invoices?: Maybe<Scalars['Boolean']>;
is_ok_to_get_wallet_info?: Maybe<Scalars['Boolean']>;
is_ok_to_get_payments?: Maybe<Scalars['Boolean']>;
is_ok_to_get_peers?: Maybe<Scalars['Boolean']>;
is_ok_to_pay?: Maybe<Scalars['Boolean']>;
is_ok_to_send_to_chain_addresses?: Maybe<Scalars['Boolean']>;
is_ok_to_sign_bytes?: Maybe<Scalars['Boolean']>;
is_ok_to_sign_messages?: Maybe<Scalars['Boolean']>;
is_ok_to_stop_daemon?: Maybe<Scalars['Boolean']>;
is_ok_to_verify_bytes_signatures?: Maybe<Scalars['Boolean']>;
is_ok_to_verify_messages?: Maybe<Scalars['Boolean']>;
};

export type Query = {
__typename?: 'Query';
getVolumeHealth?: Maybe<ChannelsHealth>;
Expand Down Expand Up @@ -262,6 +282,7 @@ export type Mutation = {
removePeer?: Maybe<Scalars['Boolean']>;
sendMessage?: Maybe<Scalars['Int']>;
logout?: Maybe<Scalars['Boolean']>;
createMacaroon?: Maybe<Scalars['String']>;
};

export type MutationCloseChannelArgs = {
Expand Down Expand Up @@ -349,6 +370,11 @@ export type MutationLogoutArgs = {
type: Scalars['String'];
};

export type MutationCreateMacaroonArgs = {
auth: AuthType;
permissions: PermissionsType;
};

export type NodeType = {
__typename?: 'nodeType';
alias: Scalars['String'];
Expand Down
Loading

0 comments on commit 8c9607d

Please sign in to comment.