Skip to content

Commit 60b7b2a

Browse files
Ryan Gentrygitbook-bot
authored andcommitted
GITBOOK-335: Aperture
1 parent b122427 commit 60b7b2a

9 files changed

Lines changed: 105 additions & 42 deletions

File tree

SUMMARY.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
* [L402: Lightning HTTP 402 Protocol](the-lightning-network/l402/README.md)
3333
* [Macaroons](the-lightning-network/l402/macaroons.md)
3434
* [L402](the-lightning-network/l402/l402.md)
35-
* [Aperture](the-lightning-network/l402/aperture.md)
3635
* [📋 Protocol Specification](the-lightning-network/l402/protocol-specification.md)
3736
* [Implementations and Links](the-lightning-network/l402/implementations-and-links.md)
3837
* [Taproot Assets](the-lightning-network/taproot-assets/README.md)
@@ -95,7 +94,6 @@
9594
* [Troubleshooting](lightning-network-tools/lightning-terminal/troubleshooting.md)
9695
* [Lightning Node Connect: Under the hood](lightning-network-tools/lightning-terminal/lightning-node-connect.md)
9796
* [LNC Node Package](lightning-network-tools/lightning-terminal/lnc-npm.md)
98-
* [LNC Mailbox](lightning-network-tools/lightning-terminal/mailbox.md)
9997
* [Privacy and Security](lightning-network-tools/lightning-terminal/privacy-and-security.md)
10098
* [Privacy Policy](lightning-network-tools/lightning-terminal/privacy.md)
10199
* [Terms of Use](lightning-network-tools/lightning-terminal/tos.md)
@@ -123,6 +121,10 @@
123121
* [Get Started](lightning-network-tools/taproot-assets/get-tapd.md)
124122
* [First Steps](lightning-network-tools/taproot-assets/first-steps.md)
125123
* [Lightning Polar](lightning-network-tools/taproot-assets/polar.md)
124+
* [Aperture](lightning-network-tools/aperture/README.md)
125+
* [⚒ Get Aperture](lightning-network-tools/aperture/get-aperture.md)
126+
* [LNC Mailbox](lightning-network-tools/aperture/mailbox.md)
127+
* [Pricing](lightning-network-tools/aperture/pricing.md)
126128
* [Faraday](lightning-network-tools/faraday/README.md)
127129
* [🛠 Get Started](lightning-network-tools/faraday/get-started.md)
128130
* [The Faraday CLI](lightning-network-tools/faraday/the-faraday-cli.md)

lapps/guides/polar-lapps/run-the-app-without-lnd.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,33 @@ Open your browser to [http://localhost:3000](http://localhost:3000) if it doesn
1515

1616
If all went well with your development environment setup, you should see the initial screen below:
1717

18-
![](<../../../.gitbook/assets/preLND01 (1) (1) (1).png>)
18+
![](<../../../.gitbook/assets/preLND01 (1) (1) (1) (1).png>)
1919

2020
Click on the **Create a Post** button to go to the Create screen.
2121

22-
![](<../../../.gitbook/assets/preLND02 (1).png>)
22+
![](<../../../.gitbook/assets/preLND02 (1) (1).png>)
2323

2424
Fill in some info for the _Username_, _Title_, and _Content_ fields, then click on the **Submit** button. You will be redirected back to the screen displaying the list of posts.
2525

26-
![](../../../.gitbook/assets/preLND03.png)
26+
![](<../../../.gitbook/assets/preLND03 (1).png>)
2727

2828
Add a couple more posts, just to have some data to play with.
2929

30-
![](../../../.gitbook/assets/preLND04.png)
30+
![](<../../../.gitbook/assets/preLND04 (1).png>)
3131

3232
Click on the **Upvote** button on a post to see the votes counter increment and the posts reorder based on which has the highest votes.
3333

34-
![](../../../.gitbook/assets/preLND05.png)
34+
![](<../../../.gitbook/assets/preLND05 (1).png>)
3535

3636
The app makes use of WebSockets to update the UI in real-time when posts are created and upvoted on the backend. To see this in action, open a second browser window side-by-side with the first window. Create a new post on the left to see it automatically appear on the right. Upvote a post on the right to see it increment and reorder on the left automatically.
3737

38-
![](../../../.gitbook/assets/preLND06.png)
38+
![](<../../../.gitbook/assets/preLND06 (1).png>)
3939

4040
## Architecture
4141

4242
This application is split into two parts, the backend API server and the frontend browser-based UI.
4343

44-
![](../../../.gitbook/assets/appArchitecture.png)
44+
![](<../../../.gitbook/assets/appArchitecture (1).png>)
4545

4646
### Backend API
4747

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
description: Aperture is an implementation of L402s as a reverse HTTP proxy.
3+
---
4+
5+
# Aperture
6+
7+
Aperture is a reverse proxy that acts as a payment and authentication gateway for Lightning Network powered APIs. It can handle gRPC requests over HTTP/2 as well as REST over HTTP/1 and 2.
8+
9+
Aperture receives incoming connections, verifies the validity of the [L402](../../the-lightning-network/l402/) and either forwards the request to the appropriate end point, or obtains a [Macaroon](../../the-lightning-network/l402/macaroons.md) and sends it together with a Lightning invoice and the HTTP status code 402 Payment Required.
10+
11+
Aperture is currently used in production in Lightning [Loop](../loop/) and [Pool](../pool/).

the-lightning-network/l402/aperture.md renamed to lightning-network-tools/aperture/get-aperture.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
description: Aperture is an implementation of L402s as a reverse HTTP proxy.
33
---
44

5-
# Aperture
5+
# ⚒ Get Aperture
66

77
Aperture is a reverse proxy that acts as a payment and authentication gateway for Lightning Network powered APIs. It can handle gRPC requests over HTTP/2 as well as REST over HTTP/1 and 2.
88

9-
Aperture receives incoming connections, verifies the validity of the L402 and either forwards the request to the appropriate end point, or obtains a Macaroon and sends it together with a Lightning invoice and the HTTP status code 402 Payment Required.
9+
Aperture receives incoming connections, verifies the validity of the [L402](../../the-lightning-network/l402/) and either forwards the request to the appropriate end point, or obtains a [Macaroon](../../the-lightning-network/l402/macaroons.md) and sends it together with a Lightning invoice and the HTTP status code 402 Payment Required.
1010

11-
Aperture is currently used in production in Lightning [Loop](../../lightning-network-tools/loop/) and [Pool](../../lightning-network-tools/pool/).
11+
Aperture is currently used in production in Lightning [Loop](../loop/) and [Pool](../pool/).
1212

1313
## Install Aperture
1414

1515
Requirements: go 1.19 or later
1616

17-
`git clone` [`https://github.com/lightninglabs/aperture.git`](https://github.com/lightninglabs/aperture.git)\
17+
`git clone https://github.com/lightninglabs/aperture.git`\
1818
`cd aperture`\
1919
`make install`\
2020
`cp sample-conf.yaml aperture.yaml`

lightning-network-tools/lightning-terminal/mailbox.md renamed to lightning-network-tools/aperture/mailbox.md

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,9 @@ To traverse firewalls and Network Address Translation (NAT), LNC makes use of a
1212

1313
LNC is most useful when both the client and the Lightning node are behind a firewall or NAT, but it can also be useful when only the Lightning node is unreachable. In this case, aperture may be installed on the same machine as the client application.&#x20;
1414

15-
## Install go <a href="#docs-internal-guid-3a0b9987-7fff-a39a-eec7-f046b22bd334" id="docs-internal-guid-3a0b9987-7fff-a39a-eec7-f046b22bd334"></a>
16-
17-
To compile aperture we will need golang. You may follow [the official documentation](https://go.dev/doc/install) or look at the relevant chapter in the [LND installation guides](../lnd/run-lnd.md#docs-internal-guid-8ffda72d-7fff-a07e-3bb8-93cdf01b5103).
18-
19-
## Install aperture <a href="#docs-internal-guid-91628707-7fff-a4c8-335e-16b20cb60ce4" id="docs-internal-guid-91628707-7fff-a4c8-335e-16b20cb60ce4"></a>
20-
21-
Next we are going to install aperture.
22-
23-
`git clone https://github.com/lightninglabs/aperture.git`\
24-
`git checkout v[latest version]`\
25-
`make install`\
15+
## Requirements <a href="#docs-internal-guid-3a0b9987-7fff-a39a-eec7-f046b22bd334" id="docs-internal-guid-3a0b9987-7fff-a39a-eec7-f046b22bd334"></a>
2616

17+
To run our LNC mailbox, we are going to need Aperture. [You can learn how to install Aperture here](get-aperture.md).
2718

2819
## Configure aperture <a href="#docs-internal-guid-b757d186-7fff-3163-6ef9-f86657a3772a" id="docs-internal-guid-b757d186-7fff-3163-6ef9-f86657a3772a"></a>
2920

@@ -41,18 +32,20 @@ Next, we are going to switch to the superuser and create our configuration file.
4132

4233
Use this template and don’t forget to swap the domain name with your own. This domain name should also point to the server on which you are setting up aperture!
4334

44-
`listenaddr: "lnc.yourlightning.app:443"`\
45-
`debuglevel: "trace"`\
46-
`autocert: true`\
47-
`servername: lnc.yourlightning.app`\
48-
`authenticator:`\
49-
&#x20; `disable: true`\
50-
`hashmail:`\
51-
&#x20; `enabled: true`\
52-
&#x20; `messagerate: 1ms`\
53-
&#x20; `messageburstallowance: 99999999`\
54-
`prometheus:`\
55-
&#x20; `enabled: false`
35+
```
36+
listenaddr: "lnc.yourlightning.app:443"
37+
debuglevel: "trace"
38+
autocert: true
39+
servername: lnc.yourlightning.app
40+
authenticator:
41+
disable: true
42+
hashmail:
43+
enabled: true
44+
messagerate: 1ms
45+
messageburstallowance: 99999999
46+
prometheus:
47+
enabled: false
48+
```
5649

5750
## Run aperture <a href="#docs-internal-guid-680bd854-7fff-6acd-1c94-e2b1fb86f9ed" id="docs-internal-guid-680bd854-7fff-6acd-1c94-e2b1fb86f9ed"></a>
5851

@@ -67,7 +60,7 @@ The logs may show that aperture is now listening for connections.
6760

6861
## Connect to Terminal <a href="#docs-internal-guid-6d497483-7fff-ccdd-3290-061a74b72572" id="docs-internal-guid-6d497483-7fff-ccdd-3290-061a74b72572"></a>
6962

70-
We can now connect our LND node to Lightning Terminal using our own mailbox. You will need litd running alongside LND. Learn how to [install litd here](get-lit.md).
63+
We can now connect our LND node to Lightning Terminal using our own mailbox. You will need litd running alongside LND. Learn how to [install litd here](../lightning-terminal/get-lit.md).
7164

7265
`litcli sessions add --label="My own mailbox" --type admin --mailboxserveraddr lnc.yourlightningapp:443`
7366

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
description: Use Aperture to dynamically price resources using L402s.
3+
---
4+
5+
# Pricing
6+
7+
Aperture can be easily configured to price resources, such as files or API access. There are two pricing configurations: Fixed and dynamic pricing.
8+
9+
## User flow <a href="#docs-internal-guid-d027d658-7fff-096b-9e27-d92e4dae3fc4" id="docs-internal-guid-d027d658-7fff-096b-9e27-d92e4dae3fc4"></a>
10+
11+
In both fixed and dynamic pricing, the Aperture server acts as a proxy between the user and the content server. The user requests the resource and, without the requisite L402, is served the HTTP error response “402 Payment Required,” together with a Macaroon and a Lightning Network invoice.
12+
13+
By paying the Lightning Network invoice, the user obtains the preimage, which together with the Macaroon forms the valid L402, which the user can present to Aperture in order to obtain the desired resource.
14+
15+
[Read more: How the L402 is constructed and passed as part of the header](../../the-lightning-network/l402/protocol-specification.md#http-specification)
16+
17+
## Fixed Pricing <a href="#docs-internal-guid-865d3c77-7fff-00af-0102-b61a5964f14a" id="docs-internal-guid-865d3c77-7fff-00af-0102-b61a5964f14a"></a>
18+
19+
In fixed pricing, a resource is offered for a fixed price, expressed in satoshis. Multiple resources can be configured, each with their own price.
20+
21+
```
22+
- name: "service2"
23+
hostregexp: "service2.com:8083"
24+
pathregexp: '^/.*$'
25+
address: "123.456.789:8082"
26+
protocol: https
27+
constraints:
28+
"valid_until": "2020-01-01"
29+
price: 1
30+
```
31+
32+
For each service, a valid L402 will allow its holder to access unlimited resources on this service. To price for each resource individually, we will have to make use of dynamic pricing.
33+
34+
## Dynamic pricing
35+
36+
For dynamic pricing, you will need to configure Aperture to connect to a separate service over gRPC. This for example allows for resources to be priced in fiat currency, sell a large repository of items, each with their own pricing, or adjust prices based on demand.
37+
38+
```
39+
- name: "service3"
40+
hostregexp: "service3.com:8083"
41+
pathregexp: '^/.*$'
42+
address: "123.456.789:8082"
43+
protocol: https
44+
constraints:
45+
"valid_until": "2020-01-01"
46+
dynamicprice:
47+
enabled: true
48+
grpcaddress: 123.456.789:8083
49+
insecure: false
50+
tlscertpath: "path-to-pricer-server-tls-cert/tls.cert"
51+
```
52+
53+
{% embed url="https://www.youtube.com/watch?v=Y2ZG-qcw7Sw" %}
54+
Also watch: Aperture Dynamic Pricing Demo
55+
{% endembed %}
56+
57+
[https://github.com/ellemouton/aperture-demo](https://github.com/ellemouton/aperture-demo)

lightning-network-tools/taproot-assets/first-steps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ There are three outputs. Two outputs of 1000 satoshis each and the change output
262262

263263
Once the transaction is confirmed on the Bitcoin Blockchain the sender will attempt to make the proofs available to the recipient via an [end-to-end encrypted mailbox](../lightning-terminal/lightning-node-connect.md), similar to Lightning Node Connect (LNC).
264264

265-
By default, this mailbox is set to mailbox.terminal.lightning.today:443, but you can [run your own mailbox through aperture](../../the-lightning-network/l402/aperture.md) and configure tapd to use it by specifying the `--hashmailcourier.addr=` flag at startup.
265+
By default, this mailbox is set to mailbox.terminal.lightning.today:443, but you can [run your own mailbox through aperture](../aperture/get-aperture.md) and configure tapd to use it by specifying the `--hashmailcourier.addr=` flag at startup.
266266

267267
Once the transaction is confirmed on the Bitcoin Blockchain the sender will attempt to make the proofs available to the recipient via a [LNC-style end-to-end encrypted mailbox](../lightning-terminal/lightning-node-connect.md).
268268

the-lightning-network/l402/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ The Aperture proxy is a reverse proxy that will forward a request with a valid L
3838

3939
Aperture allows for pricing for API endpoints on the fly, including automatic tier upgrades, per-request pricing or surge pricing. In another light, this can be viewed as a global HTTP 402 reverse proxy at the load balancing level for web services and APIs.
4040

41-
{% content-ref url="aperture.md" %}
42-
[aperture.md](aperture.md)
41+
{% content-ref url="../../lightning-network-tools/aperture/get-aperture.md" %}
42+
[get-aperture.md](../../lightning-network-tools/aperture/get-aperture.md)
4343
{% endcontent-ref %}

the-lightning-network/l402/l402.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ Finally, the preimage is verified against the payment hash to ensure that all ou
8888

8989
[Learn how the L402 is obtained in Pool](https://github.com/lightninglabs/pool/blob/master/server.go#L504)
9090

91-
{% content-ref url="aperture.md" %}
92-
[aperture.md](aperture.md)
91+
{% content-ref url="../../lightning-network-tools/aperture/get-aperture.md" %}
92+
[get-aperture.md](../../lightning-network-tools/aperture/get-aperture.md)
9393
{% endcontent-ref %}

0 commit comments

Comments
 (0)