Closed bennyhodl closed 2 years ago
How are you running/building the REST query?
I ran the following command on a local LND node:
curl --insecure -XPOST -H "Grpc-Metadata-macaroon: $(xxd -ps -u -c 1000 $HOME/docker/mounts/regtest/alice/admin.macaroon)" \
-H "Content-type: application/json" -d '{"permissions": [ {"entity": "offchain","action": "read"}]}' \
'https://localhost:8091/v1/macaroon'
and it returned:
{"macaroon":"020103...."}
Building it on the frontend with axios.
async generateBscMacaroon(url: string, nodeId: string): Promise<boolean> {
// Set the permissions that we want to give this macaroon access to
const body = { permissions: [{"entity": "offchain", "action": "read"}] };
// Call the node to generate the macaroon
const response = await this.httpService.post(url, body, {
url: "/v1/macaroon",
httpsAgent: agent,
headers: {
"Grpc-Metadata-macaroon": macaroon
}
});
}
How are you running/building the REST query?
I ran the following command on a local LND node:
curl --insecure -XPOST -H "Grpc-Metadata-macaroon: $(xxd -ps -u -c 1000 $HOME/docker/mounts/regtest/alice/admin.macaroon)" \ -H "Content-type: application/json" -d '{"permissions": [ {"entity": "offchain","action": "read"}]}' \ 'https://localhost:8091/v1/macaroon'
and it returned:
{"macaroon":"020103...."}
I just tried successfully running:
axios({
method: 'POST',
url: "https://localhost:8091/v1/macaroon",
headers: {
'Grpc-Metadata-macaroon': macaroon,
'Content-Type': 'application/json'
},
data: {"permissions": [{"entity": "offchain", "action": "read"}]},
withCredentials: false,
httpsAgent: new https.Agent({
rejectUnauthorized: false
})
}).then(function (response: any) {
console.log(response.data);
}).catch(function (error: any) {
console.log(error);
});
// returns
// {
// macaroon: '0201036...'
// }
NOTE: Using body
did not work for me, instead I was using data
.
I also just tried axios for the first time, so I'm unsure of all intermediate steps you are doing to query lnd. It looks like it is unrelated to the body of the query, but somewhere in the agent/axios config.
I'm closing this Issue and converting it into a discussion, as the problem does not seem to stem from lnd code issues. Let me know if you got anywhere,
Background
I am trying to bake a macaroon with custom permissions and cannot find the right type to include in the body.
Your environment
lnd
v15
Steps to reproduce
Tell us how to reproduce this issue. Please provide stacktraces and links to code in question.
Expected behaviour
Return a macaroon on the REST interface.
Actual behaviour
Returns:
{"code":2,"message":"encoding/hex: invalid byte: U+0067 'g'","details":[]}