How to encode r_hash to check payment invoice using LND REST API - base64

I am trying to use LND to create an invoice and then check it. This is quite easy using the command line, but I'm stuck on the encoding of the r_hash in the HTTP API. Docs can be found here.
If I create an invoice using:
curl -X POST 'https://localhost:8080/v1/invoices' -k -H 'Grpc-metadata-macaroon: my-macaroon'
I get something along the lines of
{
"r_hash":"ud8NgqDTgCUri3sqb8D85YaRsnCtnQzY56iLwGWUXA4=",
"payment_request":"lnbc1ps5xjcxpp5h80smq4q6wqz22ut0v4xls8uukrfrvns4kwsek884z9uqev5ts8qdqqcqzpgxqyz5vqsp5c0sxrfllt0hste83mevptfyvgcf9csg05rg8326vvhl9a0mfm73s9qyyssqgcehn536edaxhjpycu4hedl9klkqtkknnng653fdfqxxwpcdncus7gkmtxy9wpeezw9tupwh4nunpt9f0yg233233xgs0c2qpnlqe4sq7jlqxp",
"add_index":"61",
"payment_addr":"w+Bhp/9b7wXk8d5YFaSMRhJcQQ+g0HirTGX+Xr9p36M="
}
The r_hash here is different from what the cli gives me when I look up the invoice: b9df0d82a0d380252b8b7b2a6fc0fce58691b270ad9d0cd8e7a88bc065945c0e.
My problem is I don't know how to convert between the two. I've tried hex and base64. The docs say the r_hash must be encoded as base64.

Got it. The API was returning the hash base64 encoded, and I was able to get the API to accept it hex encoded. This required decoding and re-encoding:
import codecs, base64
codecs.encode(base64.b64decode(h.encode('utf-8')), 'hex')

Related

Unable to interpret decoded Base64 value

I am getting a Base64 value when I implement the monitor function from the react-native-ble-plx library.
Base64 value : E06YXDQdOj+RrhQ9aJk3Pd4nL78V3A67/CqlO4BcED4AAAAAAAAAAA==
When I decode this value on any online platform I get the following value: N˜\4:?‘®=h™7=Þ'/¿Ü»ü*¥;€>
Not sure what this exactly means. Any guidance would be of great help.
I am using Xsens DOT sensor to capture orientation dataSample data

How to convert png base64 to a jpg base64 nodejs

So, I am currently using an API using curl that expects a base64 string as a body. This base64 has to be in the JPG format, though. The images that I am uploading are online so the most ideal solution would look something like this:
var url = "www.someimg.nl/pic.png";
var base64png = Base64.Encode(url);
var base64jpg = Base64.Convert(base64png, "JPG");
//Do my curl here
All the solutions that I see usually save the file while they are converting it. I do not want to do this as I do not want a local copy of every image handled by my program. Is there any way to do what I am describing?

Convert Binary content of PDF file To JSON format using node.js

we want Json format from binary content of pdf file using node.js.
Actually we are getting binary content of pdf from 3 party api response , using this response we will save in our database ,so give me working code for convert binary pdf format to json format
in simple words
Please let us know , "any working code so i have just pass binary data got json data" .
The JSON format natively doesn't support binary data.
Use Base64 or base85
I think the best you can do space-wise is base85 which represents four bytes as five characters. However, this is only a 7% improvement over base64, it's more expensive to compute, and implementations are less common than for base64 so it's probably not a win.

Convert p12 APNS certificate to base64 string

I want to send the .p12 file of APNS certificate to One Signal API, but I need first to convert the .p12 file to base64 string. How do I do that?
The API documentation is below:
https://documentation.onesignal.com/reference#create-an-app
If you're on a Mac you can use the base64 utility that comes with Mac.
base64 -i certificate.p12 -o outputfile
This depends on the programming language you are using.
For example, here's how to do it in Ruby:
base64_encoded_p12 = Base64.encode64(File.read('/path/to/your/file.p12'))
new Buffer(fs.readFileSync(__dirname + "/ios_push_certificate.p12")).toString('base64')
That is the correct script after all.
You can use this on Linux
base64 file.p12
To write the base64 output to any file, you can use this
base64 file.p12 > output.base64
Note: This works for any files not only .p12

Issue with Cloudinary in reading and uploading image from binary or base64 string

I am trying to upload and image to cloudinary by passing binary data of an image or base64 string. when i try to pass a base64 string as a data uri I am getting a error with the response of status code 502. but it works fine with small base64 strings.
This works fine
res = cloudinary.uploader.upload("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==")
whereas when I pass some lengthy string it fails with 502 status code.
Might be because the uri cannot handle large value. Is there any other right way for passing lengthy strings?
or how can i pass a binary data as a input to the cloudinary?
I'm Itay from Cloudinary.
In order to understand this issue better we'll need to take a deeper look at your account. We'll need some more information like your cloud name, timestamp of the fault uploads and more.
If you prefer this to be handled more privately, you're more than welcomed to open a support ticket (http://support.cloudinary.com/tickets/new) and we'll be happy to assist.

Resources