lightning.ws hosts paywalled web services / APIs that are payable via the Lightning Network.
It's "eating your own dogfood" for the project ln-paywall. For more information please visit the project's GitHub repository: https://github.com/philippgille/ln-paywall.
Currently running on Testnet only.
You need to have either a direct channel or route to 034b1f48aff6d95965e2442b734b0dfb28421ef1815bf873ec5e1b736b76ed05da@node.lightning.ws:9735
Generates a QR code for the given data.
# 1. Generate invoice:
curl https://api.lightning.ws/qr
# 2. Pay the invoice that's in the response body
# 3. Send the request with the preimage as payment proof (hex encoded)
# and the data you want in the QR code as query parameter:
curl -H "x-preimage: $PAYMENT_PREIMAGE" "https://api.lightning.ws/qr?data=testtext"
# 4. The response is the QR code as PNG image
// Coming soon...
package main
import (
"fmt"
"io/ioutil"
"github.com/philippgille/ln-paywall/ln"
"github.com/philippgille/ln-paywall/pay"
)
func main() {
// Set up client
lndOptions := ln.LNDoptions{ // Default address: "localhost:10009", CertFile: "tls.cert"
MacaroonFile: "admin.macaroon", // admin.macaroon is required for making payments
}
lnClient, err := ln.NewLNDclient(lndOptions)
if err != nil {
panic(err)
}
client := pay.NewClient(nil, lnClient) // Uses http.DefaultClient if no http.Client is passed
// Send request to an ln-paywalled API
res, err := client.Get("https://api.lightning.ws/qr?data=testtext")
if err != nil {
panic(err)
}
defer res.Body.Close()
// Print response body
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println(string(resBody))
}
// 1. Generate invoice
fetch("https://api.lightning.ws/qr", {
method: 'get',
headers: new Headers({ 'Content-Type': 'text/plain' })
}).then(function (response) {
return response.text();
}).then(function (data) {
// data is the invoice
});
// 2. Pay the invoice that's in the response body
// 3. Send the request with the preimage as payment proof (hex encoded)
// and the data you want in the QR code as query parameter:
var preimage = "PAYMENT_PREIMAGE";
var data = "Hello world of QR codes!";
fetch("https://api.lightning.ws/qr?data=" + data, {
method: 'get',
headers: new Headers({
'X-Preimage': preimage
})
}).then(function (response) {
if (response.status === 200) {
// qr code image as blob
return response.blob();
} else {
// error as text
return response.text();
}
}).then(function (response) {
if (typeof response === "string") {
// handle error
} else {
var qrCodeURL = URL.createObjectURL(response);
// 4. use the qrCodeURL
// e.g. to set the src of an image html element
}
});
Translate a text with the translate API.
# 1. Generate invoice:
curl https://api.lightning.ws/translate
# 2. Pay the invoice that's in the response body
# 3. Send the request with the preimage as payment proof (hex encoded) and the
# text you want to translate in your chosen target language
curl -H "x-preimage: $PAYMENT_PREIMAGE" "https://api.lightning.ws/translate?text=Hallo%20Welt&to=en"
# 4. The response is a JSON array with the translation
// Coming soon...
package main
import (
"fmt"
"io/ioutil"
"github.com/philippgille/ln-paywall/ln"
"github.com/philippgille/ln-paywall/pay"
)
func main() {
// Set up client
lndOptions := ln.LNDoptions{ // Default address: "localhost:10009", CertFile: "tls.cert"
MacaroonFile: "admin.macaroon", // admin.macaroon is required for making payments
}
lnClient, err := ln.NewLNDclient(lndOptions)
if err != nil {
panic(err)
}
client := pay.NewClient(nil, lnClient) // Uses http.DefaultClient if no http.Client is passed
// Send request to an ln-paywalled API
res, err := client.Get("https://api.lightning.ws/translate?text=Hallo%20Welt&to=en")
if err != nil {
panic(err)
}
defer res.Body.Close()
// Print response body
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println(string(resBody))
}
// 1. Generate invoice
fetch("https://api.lightning.ws/translate", {
method: 'get',
headers: new Headers({ 'Content-Type': 'text/plain' })
}).then(function (response) {
return response.text();
}).then(function (data) {
// data is the invoice
});
// 2. Pay the invoice that's in the response body
// 3. Send the request with the preimage as payment proof (hex encoded) and the
// text you want to translate in your chosen target language
var preimage = "PAYMENT_PREIMAGE";
var text = encodeURI("Hello world of translations, please translate me now!");
var to = "de";
// 'fromTr' parameter is optional, if it's empty it will be suggested
var fromTr = "en";
var url = "https://api.lightning.ws/translate?text=" + text + "&to=" + to;
if (fromTr !== ""){
url += "&from=" + fromTr;
}
fetch(url, {
method: 'get',
headers: new Headers({ 'X-Preimage': preimage })
}).then(function (response) {
if (response.status === 200) {
return response.json();
} else {
// got error as text
return response.text();
}
}).then(function (response){
if (typeof response === "object") {
var fromLanguage = response[0].detectedLanguage.language;
var toLanguage = response[0].translations[0].to;
var tranlationText = response[0].translations[0].text;
// ...
} else {
var errorTExt = response;
// ...
}
});
/*
The response will look like this:
[
{
"detectedLanguage": {
"language": "de",
"score": 0.88
},
"translations": [
{
"text": "The API is now successfully deployed on staging",
"to": "en"
}
]
}
]
*/
Recognize text in images with the OCR API
# 1. Generate invoice:
curl https://api.lightning.ws/ocr
# 2. Pay the invoice that's in the response body
# 3. Send the request with the preimage as payment proof (hex encoded) and the
# image URL of the image you want to recognize text in
curl -H "x-preimage: $PAYMENT_PREIMAGE" "https://api.lightning.ws/ocr?imageUrl=http%3A%2F%2Fexample%2Ecom%2Fimage%2Epng"
# 4. The response is a JSON object with the bounding boxes and text of recognized text
// Coming soon...
package main
import (
"fmt"
"io/ioutil"
"github.com/philippgille/ln-paywall/ln"
"github.com/philippgille/ln-paywall/pay"
)
func main() {
// Set up client
lndOptions := ln.LNDoptions{ // Default address: "localhost:10009", CertFile: "tls.cert"
MacaroonFile: "admin.macaroon", // admin.macaroon is required for making payments
}
lnClient, err := ln.NewLNDclient(lndOptions)
if err != nil {
panic(err)
}
client := pay.NewClient(nil, lnClient) // Uses http.DefaultClient if no http.Client is passed
// Send request to an ln-paywalled API
res, err := client.Get("https://api.lightning.ws/ocr?imageUrl=http%3A%2F%2Fexample%2Ecom%2Fimage%2Epng")
if err != nil {
panic(err)
}
defer res.Body.Close()
// Print response body
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println(string(resBody))
}
// 1. Generate invoice
fetch("https://api.lightning.ws/ocr", {
method: 'get',
headers: new Headers({ 'Content-Type': 'text/plain' })
}).then(function (response) {
return response.text();
}).then(function (data) {
// data is the invoice
});
// 2. Pay the invoice that's in the response body
// 3. Send the request with the preimage as payment proof (hex encoded) and the
// image URL of the image you want to recognize text in
var preimage = "PAYMENT_PREIMAGE";
var imageUrl = encodeURI("http://example.com/image.png");
var url = "https://api.lightning.ws/ocr?imageUrl=" + imageUrl;
fetch(url, {
method: 'get',
headers: new Headers({ 'X-Preimage': preimage })
}).then(function (response) {
if (response.status === 200) {
return response.json();
} else {
// got error as text
return response.text();
}
}).then(function (response){
if (typeof response === "object") {
var recognizedText = response;
// ...
} else {
var errorTExt = response;
// ...
}
});