lightning 4.7.1 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/README.md +4 -0
  3. package/grpc/handle_remove_listener.js +25 -0
  4. package/grpc/index.js +2 -0
  5. package/grpc/protos/lightning.proto +237 -5
  6. package/index.js +2 -0
  7. package/lnd_methods/index.js +2 -0
  8. package/lnd_methods/info/constants.json +1 -0
  9. package/lnd_methods/macaroon/grant_access.d.ts +2 -0
  10. package/lnd_methods/macaroon/grant_access.js +24 -1
  11. package/lnd_methods/macaroon/index.d.ts +1 -0
  12. package/lnd_methods/macaroon/index.js +8 -1
  13. package/lnd_methods/macaroon/methods.json +500 -0
  14. package/lnd_methods/macaroon/subscribe_to_rpc_requests.js +113 -0
  15. package/lnd_methods/macaroon/uris_for_method.js +49 -0
  16. package/lnd_methods/macaroon/verify_access.d.ts +28 -0
  17. package/lnd_methods/offchain/delete_payment.js +2 -2
  18. package/lnd_methods/offchain/get_channels.d.ts +2 -0
  19. package/lnd_methods/offchain/get_channels.js +1 -0
  20. package/lnd_methods/offchain/get_pending_channels.js +1 -0
  21. package/lnd_methods/offchain/subscribe_to_channels.d.ts +2 -0
  22. package/lnd_methods/offchain/subscribe_to_channels.js +6 -4
  23. package/lnd_methods/offchain/update_routing_fees.d.ts +25 -1
  24. package/lnd_methods/offchain/update_routing_fees.js +31 -3
  25. package/lnd_methods/onchain/open_channel.js +1 -1
  26. package/lnd_methods/onchain/propose_channel.js +1 -1
  27. package/lnd_responses/constants.json +26 -0
  28. package/lnd_responses/index.js +6 -0
  29. package/lnd_responses/rpc_channel_as_channel.js +2 -4
  30. package/lnd_responses/rpc_channel_as_old_rpc_channel.js +28 -0
  31. package/lnd_responses/rpc_failed_policy_as_fail.js +55 -0
  32. package/lnd_responses/rpc_request_update_as_event.js +121 -0
  33. package/package.json +6 -6
  34. package/test/grpc/test_handle_remove_listener.js +34 -0
  35. package/test/lnd_methods/macaroon/test_grant_access.js +16 -0
  36. package/test/lnd_methods/macaroon/test_uris_for_method.js +34 -0
  37. package/test/lnd_methods/offchain/test_get_channels.js +1 -0
  38. package/test/lnd_methods/offchain/test_subscribe_to_channels.js +9 -0
  39. package/test/lnd_methods/offchain/test_update_routing_fees.js +22 -1
  40. package/test/lnd_responses/test_rpc_channel_as_channel.js +1 -5
  41. package/test/lnd_responses/test_rpc_channel_as_old_rpc_channel.js +64 -0
  42. package/test/lnd_responses/test_rpc_failed_policy_as_fail.js +67 -0
  43. package/test/lnd_responses/test_rpc_fees_as_channel_fees.js +1 -1
  44. package/test/lnd_responses/test_rpc_request_update_as_event.js +130 -0
  45. package/test/protos/protos.json +6 -2
  46. package/test/typescript/update_routing_fees.test-d.ts +13 -5
  47. package/test/typescript/verify_access.test-d.ts +23 -0
package/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Versions
2
2
 
3
- ## 4.7.1
3
+ ## 4.10.0
4
+
5
+ - `getChannels`: Add `past_states` to reflect the number of updates
6
+ - `subscribeToChannels`: Add `past_states` to reflect to number of updates
7
+
8
+ ## 4.9.0
9
+
10
+ - `grantAccess`: Add support for specifying `methods` for permissions
11
+
12
+ ## 4.8.0
13
+
14
+ - `updateRoutingFees`: Add `failures` to indicate failed policy updates
15
+ - `verifyAccess`: Add method to confirm a macaroon has given permissions
16
+
17
+ ## 4.7.2
4
18
 
5
19
  - `getPayment`: Add `created_at` to indicate the creation date of the payment
6
20
  - `getPayment`: Add `request` to indicate serialized payment request
package/README.md CHANGED
@@ -89,6 +89,8 @@ Methods exported by this library support typescript, but ln-service includes add
89
89
  Remove failed payments from the database.
90
90
  - [deleteForwardingReputations](https://github.com/alexbosworth/ln-service#deleteforwardingreputations)
91
91
  Clear pathfinding reputations of routing nodes and channels.
92
+ - [deletePayment](https://github.com/alexbosworth/ln-service#deletepayment): Remove a
93
+ past payment record.
92
94
  - [deletePayments](https://github.com/alexbosworth/ln-service#deletepayments): Remove all
93
95
  past payment records.
94
96
  - [diffieHellmanComputeSecret](https://github.com/alexbosworth/ln-service#diffiehellmancomputesecret):
@@ -295,6 +297,8 @@ Methods exported by this library support typescript, but ln-service includes add
295
297
  Edit the configuration for routing calculations
296
298
  - [updateRoutingFees](https://github.com/alexbosworth/ln-service#updateroutingfees): Set the
297
299
  forwarding fees or other routing policies for a channel or all channels.
300
+ - [verifyAccess](https://github.com/alexbosworth/ln-service#verifyaccess): Confirm a macaroon
301
+ has permission to access a given resource.
298
302
  - [verifyBackup](https://github.com/alexbosworth/ln-service#verifybackup): Check if a channel fund
299
303
  recovery backup file is valid.
300
304
  - [verifyBackups](https://github.com/alexbosworth/ln-service#verifybackups): Check if multiple
@@ -0,0 +1,25 @@
1
+ const sumOf = arr => arr.reduce((sum, n) => sum + n, Number());
2
+
3
+ /** Get a function that emits an error from a gRPC subscription proxy
4
+
5
+ {
6
+ emitter: <EventEmitter Subscription Proxy Object>
7
+ events: [<Event Name String>]
8
+ subscription: <gRPC Subscription Object>
9
+ }
10
+ */
11
+ module.exports = ({emitter, events, subscription}) => {
12
+ // Cancel the subscription when all listeners are removed
13
+ emitter.on('removeListener', () => {
14
+ const counts = events.map(n => emitter.listenerCount(n));
15
+
16
+ // Exit early when there are still active listeners
17
+ if (!!sumOf(counts)) {
18
+ return;
19
+ }
20
+
21
+ subscription.cancel();
22
+
23
+ return;
24
+ });
25
+ };
package/grpc/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const {defaultSocket} = require('./grpc_services');
2
2
  const emitSubscriptionError = require('./emit_subscription_error');
3
3
  const {grpcSslCipherSuites} = require('./grpc_services');
4
+ const handleRemoveListener = require('./handle_remove_listener');
4
5
  const {maxReceiveMessageLength} = require('./grpc_services');
5
6
  const {packageTypes} = require('./grpc_services');
6
7
  const {protoFiles} = require('./grpc_services');
@@ -13,6 +14,7 @@ module.exports = {
13
14
  defaultSocket,
14
15
  emitSubscriptionError,
15
16
  grpcSslCipherSuites,
17
+ handleRemoveListener,
16
18
  maxReceiveMessageLength,
17
19
  packageTypes,
18
20
  protoFiles,
@@ -540,6 +540,23 @@ service Lightning {
540
540
  */
541
541
  rpc CheckMacaroonPermissions (CheckMacPermRequest)
542
542
  returns (CheckMacPermResponse);
543
+
544
+ /*
545
+ RegisterRPCMiddleware adds a new gRPC middleware to the interceptor chain. A
546
+ gRPC middleware is software component external to lnd that aims to add
547
+ additional business logic to lnd by observing/intercepting/validating
548
+ incoming gRPC client requests and (if needed) replacing/overwriting outgoing
549
+ messages before they're sent to the client. When registering the middleware
550
+ must identify itself and indicate what custom macaroon caveats it wants to
551
+ be responsible for. Only requests that contain a macaroon with that specific
552
+ custom caveat are then sent to the middleware for inspection. The other
553
+ option is to register for the read-only mode in which all requests/responses
554
+ are forwarded for interception to the middleware but the middleware is not
555
+ allowed to modify any responses. As a security measure, _no_ middleware can
556
+ modify responses for requests made with _unencumbered_ macaroons!
557
+ */
558
+ rpc RegisterRPCMiddleware (stream RPCMiddlewareResponse)
559
+ returns (stream RPCMiddlewareRequest);
543
560
  }
544
561
 
545
562
  message Utxo {
@@ -1140,6 +1157,11 @@ message HTLC {
1140
1157
  }
1141
1158
 
1142
1159
  enum CommitmentType {
1160
+ /*
1161
+ Returned when the commitment type isn't known or unavailable.
1162
+ */
1163
+ UNKNOWN_COMMITMENT_TYPE = 999;
1164
+
1143
1165
  /*
1144
1166
  A channel using the legacy commitment format having tweaked to_remote
1145
1167
  keys.
@@ -1160,11 +1182,6 @@ enum CommitmentType {
1160
1182
  been broadcast.
1161
1183
  */
1162
1184
  ANCHORS = 2;
1163
-
1164
- /*
1165
- Returned when the commitment type isn't known or unavailable.
1166
- */
1167
- UNKNOWN_COMMITMENT_TYPE = 999;
1168
1185
  }
1169
1186
 
1170
1187
  message ChannelConstraints {
@@ -2219,6 +2236,9 @@ message PendingChannelsResponse {
2219
2236
 
2220
2237
  // The commitment type used by this channel.
2221
2238
  CommitmentType commitment_type = 9;
2239
+
2240
+ // Total number of forwarding packages created in this channel.
2241
+ int64 num_forwarding_packages = 10;
2222
2242
  }
2223
2243
 
2224
2244
  message PendingOpenChannel {
@@ -3635,7 +3655,28 @@ message PolicyUpdateRequest {
3635
3655
  // If true, min_htlc_msat is applied.
3636
3656
  bool min_htlc_msat_specified = 8;
3637
3657
  }
3658
+ enum UpdateFailure {
3659
+ UPDATE_FAILURE_UNKNOWN = 0;
3660
+ UPDATE_FAILURE_PENDING = 1;
3661
+ UPDATE_FAILURE_NOT_FOUND = 2;
3662
+ UPDATE_FAILURE_INTERNAL_ERR = 3;
3663
+ UPDATE_FAILURE_INVALID_PARAMETER = 4;
3664
+ }
3665
+
3666
+ message FailedUpdate {
3667
+ // The outpoint in format txid:n
3668
+ OutPoint outpoint = 1;
3669
+
3670
+ // Reason for the policy update failure.
3671
+ UpdateFailure reason = 2;
3672
+
3673
+ // A string representation of the policy update error.
3674
+ string update_error = 3;
3675
+ }
3676
+
3638
3677
  message PolicyUpdateResponse {
3678
+ // List of failed policy updates.
3679
+ repeated FailedUpdate failed_updates = 1;
3639
3680
  }
3640
3681
 
3641
3682
  message ForwardingHistoryRequest {
@@ -3803,6 +3844,12 @@ message BakeMacaroonRequest {
3803
3844
 
3804
3845
  // The root key ID used to create the macaroon, must be a positive integer.
3805
3846
  uint64 root_key_id = 2;
3847
+
3848
+ /*
3849
+ Informs the RPC on whether to allow external permissions that LND is not
3850
+ aware of.
3851
+ */
3852
+ bool allow_external_permissions = 3;
3806
3853
  }
3807
3854
  message BakeMacaroonResponse {
3808
3855
  // The hex encoded macaroon, serialized in binary format.
@@ -4024,3 +4071,188 @@ message CheckMacPermRequest {
4024
4071
  message CheckMacPermResponse {
4025
4072
  bool valid = 1;
4026
4073
  }
4074
+
4075
+ message RPCMiddlewareRequest {
4076
+ /*
4077
+ The unique ID of the intercepted request. Useful for mapping request to
4078
+ response when implementing full duplex message interception.
4079
+ */
4080
+ uint64 request_id = 1;
4081
+
4082
+ /*
4083
+ The raw bytes of the complete macaroon as sent by the gRPC client in the
4084
+ original request. This might be empty for a request that doesn't require
4085
+ macaroons such as the wallet unlocker RPCs.
4086
+ */
4087
+ bytes raw_macaroon = 2;
4088
+
4089
+ /*
4090
+ The parsed condition of the macaroon's custom caveat for convenient access.
4091
+ This field only contains the value of the custom caveat that the handling
4092
+ middleware has registered itself for. The condition _must_ be validated for
4093
+ messages of intercept_type stream_auth and request!
4094
+ */
4095
+ string custom_caveat_condition = 3;
4096
+
4097
+ /*
4098
+ There are three types of messages that will be sent to the middleware for
4099
+ inspection and approval: Stream authentication, request and response
4100
+ interception. The first two can only be accepted (=forward to main RPC
4101
+ server) or denied (=return error to client). Intercepted responses can also
4102
+ be replaced/overwritten.
4103
+ */
4104
+ oneof intercept_type {
4105
+ /*
4106
+ Intercept stream authentication: each new streaming RPC call that is
4107
+ initiated against lnd and contains the middleware's custom macaroon
4108
+ caveat can be approved or denied based upon the macaroon in the stream
4109
+ header. This message will only be sent for streaming RPCs, unary RPCs
4110
+ must handle the macaroon authentication in the request interception to
4111
+ avoid an additional message round trip between lnd and the middleware.
4112
+ */
4113
+ StreamAuth stream_auth = 4;
4114
+
4115
+ /*
4116
+ Intercept incoming gRPC client request message: all incoming messages,
4117
+ both on streaming and unary RPCs, are forwarded to the middleware for
4118
+ inspection. For unary RPC messages the middleware is also expected to
4119
+ validate the custom macaroon caveat of the request.
4120
+ */
4121
+ RPCMessage request = 5;
4122
+
4123
+ /*
4124
+ Intercept outgoing gRPC response message: all outgoing messages, both on
4125
+ streaming and unary RPCs, are forwarded to the middleware for inspection
4126
+ and amendment. The response in this message is the original response as
4127
+ it was generated by the main RPC server. It can either be accepted
4128
+ (=forwarded to the client), replaced/overwritten with a new message of
4129
+ the same type, or replaced by an error message.
4130
+ */
4131
+ RPCMessage response = 6;
4132
+ }
4133
+ }
4134
+
4135
+ message StreamAuth {
4136
+ /*
4137
+ The full URI (in the format /<rpcpackage>.<ServiceName>/MethodName, for
4138
+ example /lnrpc.Lightning/GetInfo) of the streaming RPC method that was just
4139
+ established.
4140
+ */
4141
+ string method_full_uri = 1;
4142
+ }
4143
+
4144
+ message RPCMessage {
4145
+ /*
4146
+ The full URI (in the format /<rpcpackage>.<ServiceName>/MethodName, for
4147
+ example /lnrpc.Lightning/GetInfo) of the RPC method the message was sent
4148
+ to/from.
4149
+ */
4150
+ string method_full_uri = 1;
4151
+
4152
+ /*
4153
+ Indicates whether the message was sent over a streaming RPC method or not.
4154
+ */
4155
+ bool stream_rpc = 2;
4156
+
4157
+ /*
4158
+ The full canonical gRPC name of the message type (in the format
4159
+ <rpcpackage>.TypeName, for example lnrpc.GetInfoRequest).
4160
+ */
4161
+ string type_name = 3;
4162
+
4163
+ /*
4164
+ The full content of the gRPC message, serialized in the binary protobuf
4165
+ format.
4166
+ */
4167
+ bytes serialized = 4;
4168
+ }
4169
+
4170
+ message RPCMiddlewareResponse {
4171
+ /*
4172
+ The unique ID of the intercepted request that this response refers to. Must
4173
+ always be set when giving feedback to an intercept but is ignored for the
4174
+ initial registration message.
4175
+ */
4176
+ uint64 request_id = 1;
4177
+
4178
+ /*
4179
+ The middleware can only send two types of messages to lnd: The initial
4180
+ registration message that identifies the middleware and after that only
4181
+ feedback messages to requests sent to the middleware.
4182
+ */
4183
+ oneof middleware_message {
4184
+ /*
4185
+ The registration message identifies the middleware that's being
4186
+ registered in lnd. The registration message must be sent immediately
4187
+ after initiating the RegisterRpcMiddleware stream, otherwise lnd will
4188
+ time out the attempt and terminate the request. NOTE: The middleware
4189
+ will only receive interception messages for requests that contain a
4190
+ macaroon with the custom caveat that the middleware declares it is
4191
+ responsible for handling in the registration message! As a security
4192
+ measure, _no_ middleware can intercept requests made with _unencumbered_
4193
+ macaroons!
4194
+ */
4195
+ MiddlewareRegistration register = 2;
4196
+
4197
+ /*
4198
+ The middleware received an interception request and gives feedback to
4199
+ it. The request_id indicates what message the feedback refers to.
4200
+ */
4201
+ InterceptFeedback feedback = 3;
4202
+ }
4203
+ }
4204
+
4205
+ message MiddlewareRegistration {
4206
+ /*
4207
+ The name of the middleware to register. The name should be as informative
4208
+ as possible and is logged on registration.
4209
+ */
4210
+ string middleware_name = 1;
4211
+
4212
+ /*
4213
+ The name of the custom macaroon caveat that this middleware is responsible
4214
+ for. Only requests/responses that contain a macaroon with the registered
4215
+ custom caveat are forwarded for interception to the middleware. The
4216
+ exception being the read-only mode: All requests/responses are forwarded to
4217
+ a middleware that requests read-only access but such a middleware won't be
4218
+ allowed to _alter_ responses. As a security measure, _no_ middleware can
4219
+ change responses to requests made with _unencumbered_ macaroons!
4220
+ NOTE: Cannot be used at the same time as read_only_mode.
4221
+ */
4222
+ string custom_macaroon_caveat_name = 2;
4223
+
4224
+ /*
4225
+ Instead of defining a custom macaroon caveat name a middleware can register
4226
+ itself for read-only access only. In that mode all requests/responses are
4227
+ forwarded to the middleware but the middleware isn't allowed to alter any of
4228
+ the responses.
4229
+ NOTE: Cannot be used at the same time as custom_macaroon_caveat_name.
4230
+ */
4231
+ bool read_only_mode = 3;
4232
+ }
4233
+
4234
+ message InterceptFeedback {
4235
+ /*
4236
+ The error to return to the user. If this is non-empty, the incoming gRPC
4237
+ stream/request is aborted and the error is returned to the gRPC client. If
4238
+ this value is empty, it means the middleware accepts the stream/request/
4239
+ response and the processing of it can continue.
4240
+ */
4241
+ string error = 1;
4242
+
4243
+ /*
4244
+ A boolean indicating that the gRPC response should be replaced/overwritten.
4245
+ As its name suggests, this can only be used as a feedback to an intercepted
4246
+ response RPC message and is ignored for feedback on any other message. This
4247
+ boolean is needed because in protobuf an empty message is serialized as a
4248
+ 0-length or nil byte slice and we wouldn't be able to distinguish between
4249
+ an empty replacement message and the "don't replace anything" case.
4250
+ */
4251
+ bool replace_response = 2;
4252
+
4253
+ /*
4254
+ If the replace_response field is set to true, this field must contain the
4255
+ binary serialized gRPC response message in the protobuf format.
4256
+ */
4257
+ bytes replacement_serialized = 3;
4258
+ }
package/index.js CHANGED
@@ -123,6 +123,7 @@ const {updateConnectedWatchtower} = require('./lnd_methods');
123
123
  const {updateChainTransaction} = require('./lnd_methods');
124
124
  const {updatePathfindingSettings} = require('./lnd_methods');
125
125
  const {updateRoutingFees} = require('./lnd_methods');
126
+ const {verifyAccess} = require('./lnd_methods');
126
127
  const {verifyBackup} = require('./lnd_methods');
127
128
  const {verifyBackups} = require('./lnd_methods');
128
129
  const {verifyBytesSignature} = require('./lnd_methods');
@@ -254,6 +255,7 @@ module.exports = {
254
255
  updateChainTransaction,
255
256
  updatePathfindingSettings,
256
257
  updateRoutingFees,
258
+ verifyAccess,
257
259
  verifyBackup,
258
260
  verifyBackups,
259
261
  verifyBytesSignature,
@@ -111,6 +111,7 @@ const {subscribeToPayViaRequest} = require('./offchain');
111
111
  const {subscribeToPayViaRoutes} = require('./offchain');
112
112
  const {subscribeToPeers} = require('./peers');
113
113
  const {subscribeToProbeForRoute} = require('./offchain');
114
+ const {subscribeToRpcRequests} = require('./macaroon');
114
115
  const {subscribeToTransactions} = require('./onchain');
115
116
  const {subscribeToWalletStatus} = require('./unauthenticated');
116
117
  const {unlockUtxo} = require('./onchain');
@@ -239,6 +240,7 @@ module.exports = {
239
240
  subscribeToPayViaRoutes,
240
241
  subscribeToPeers,
241
242
  subscribeToProbeForRoute,
243
+ subscribeToRpcRequests,
242
244
  subscribeToTransactions,
243
245
  subscribeToWalletStatus,
244
246
  unlockUtxo,
@@ -25,6 +25,7 @@
25
25
  "596fd90ef310cd7abbf2251edaae9ba4d5f8a689": "0.13.1-beta",
26
26
  "725ff104808f49f0a5247bfdb4b6b5da7f488d38": "0.13.0-beta",
27
27
  "7f34774529fa0964d47fc418d4d2965435cbfdc0": "0.11.1-beta",
28
+ "86d3dec7b939b21bb10f2cd1ff56970c392a1c69": "0.13.2-beta",
28
29
  "86114c575c2dff9dff1e1bb4df961c64aea9fc1c": "0.10.4-beta",
29
30
  "d176d2d65fc06e6631c4dc9478592be8545a21de": "0.12.0-beta",
30
31
  "d233f61383f2f950aa06f5b09da5b0e78e784fae": "0.12.1-beta",
@@ -44,6 +44,8 @@ export type GrantAccessArgs = AuthenticatedLightningArgs<{
44
44
  is_ok_to_verify_bytes_signatures?: boolean;
45
45
  /** Can Verify Messages From Node Keys */
46
46
  is_ok_to_verify_messages?: boolean;
47
+ /** Method Name */
48
+ methods?: string[];
47
49
  /** Entity:Action */
48
50
  permissions?: string[];
49
51
  }>;
@@ -3,8 +3,10 @@ const {returnResult} = require('asyncjs-util');
3
3
 
4
4
  const {isLnd} = require('./../../lnd_requests');
5
5
  const permissions = require('./permissions');
6
+ const urisForMethod = require('./uris_for_method');
6
7
 
7
8
  const accessDenied = 'permission denied';
9
+ const flatten = arr => [].concat(...arr);
8
10
  const hexAsBase64 = hex => Buffer.from(hex, 'hex').toString('base64');
9
11
  const isHex = n => !!n && !(n.length % 2) && /^[0-9A-F]*$/i.test(n);
10
12
  const {keys} = Object;
@@ -12,6 +14,8 @@ const method = 'bakeMacaroon';
12
14
  const notSupported = 'unknown service lnrpc.Lightning';
13
15
  const permissionSeparator = ':';
14
16
  const type = 'default';
17
+ const uniq = arr => Array.from(new Set(arr));
18
+ const uriAsPermission = uri => `uri:${uri}`;
15
19
 
16
20
  /** Give access to the node by making a macaroon access credential
17
21
 
@@ -24,6 +28,8 @@ const type = 'default';
24
28
 
25
29
  Note: `id` is not supported in LND versions 0.11.0 and below
26
30
 
31
+ `methods` is not supported in LND versions 0.11.0 and below
32
+
27
33
  {
28
34
  [id]: <Macaroon Id Positive Numeric String>
29
35
  [is_ok_to_adjust_peers]: <Can Add or Remove Peers Bool>
@@ -46,6 +52,7 @@ const type = 'default';
46
52
  [is_ok_to_verify_bytes_signatures]: <Can Verify Signatures of Bytes Bool>
47
53
  [is_ok_to_verify_messages]: <Can Verify Messages From Node Keys Bool>
48
54
  lnd: <Authenticated LND API Object>
55
+ [methods]: [<Method Name String>]
49
56
  [permissions]: [<Entity:Action String>]
50
57
  }
51
58
 
@@ -71,9 +78,25 @@ module.exports = (args, cbk) => {
71
78
  return cbk();
72
79
  },
73
80
 
81
+ // Derive URI permissions
82
+ uris: ['validate', ({}, cbk) => {
83
+ try {
84
+ const uris = (args.methods || []).map(method => {
85
+ return urisForMethod({method}).uris;
86
+ });
87
+
88
+ const permissions = uniq(flatten(uris)).map(uriAsPermission);
89
+
90
+ return cbk(null, permissions);
91
+ } catch (err) {
92
+ return cbk([400, err.message]);
93
+ }
94
+ }],
95
+
74
96
  // Permissions to grant
75
- permissions: ['validate', ({}, cbk) => {
97
+ permissions: ['uris', ({uris}, cbk) => {
76
98
  const access = []
99
+ .concat(uris)
77
100
  .concat(keys(permissions).filter(n => !!args[permissions[n]]))
78
101
  .concat(args.permissions || []);
79
102
 
@@ -1,3 +1,4 @@
1
1
  export * from './get_access_ids';
2
2
  export * from './grant_access';
3
3
  export * from './revoke_access';
4
+ export * from './verify_access';
@@ -1,6 +1,13 @@
1
1
  const getAccessIds = require('./get_access_ids');
2
2
  const grantAccess = require('./grant_access');
3
3
  const revokeAccess = require('./revoke_access');
4
+ const subscribeToRpcRequests = require('./subscribe_to_rpc_requests');
4
5
  const verifyAccess = require('./verify_access');
5
6
 
6
- module.exports = {getAccessIds, grantAccess, revokeAccess, verifyAccess};
7
+ module.exports = {
8
+ getAccessIds,
9
+ grantAccess,
10
+ revokeAccess,
11
+ subscribeToRpcRequests,
12
+ verifyAccess,
13
+ };