mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-21 14:04:03 +01:00
chore: changes to auth
This commit is contained in:
parent
a3155e236a
commit
d045d5be6c
3 changed files with 49 additions and 31 deletions
7
.prettierrc
Normal file
7
.prettierrc
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"printWidth": 100,
|
||||
"trailingComma": "all",
|
||||
"tabWidth": 4,
|
||||
"semi": true,
|
||||
"singleQuote": true
|
||||
}
|
|
@ -52,7 +52,7 @@
|
|||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "pretty-quick --staged"
|
||||
"pre-commit": "pretty-quick"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,47 +2,58 @@ import base64url from "base64url";
|
|||
import { authenticatedLndGrpc } from "ln-service";
|
||||
|
||||
export const getIp = (req: any) => {
|
||||
if (!req || !req.headers) {
|
||||
return "";
|
||||
}
|
||||
const forwarded = req.headers["x-forwarded-for"];
|
||||
const before = forwarded
|
||||
? forwarded.split(/, /)[0]
|
||||
: req.connection.remoteAddress;
|
||||
const ip = process.env.NODE_ENV === "development" ? "1.2.3.4" : before;
|
||||
return ip;
|
||||
if (!req || !req.headers) {
|
||||
return "";
|
||||
}
|
||||
const forwarded = req.headers["x-forwarded-for"];
|
||||
const before = forwarded
|
||||
? forwarded.split(/, /)[0]
|
||||
: req.connection.remoteAddress;
|
||||
const ip = process.env.NODE_ENV === "development" ? "1.2.3.4" : before;
|
||||
return ip;
|
||||
};
|
||||
|
||||
export const getBase64CertfromDerFormat = (url: string) => {
|
||||
if (!url) return null;
|
||||
if (!url) return null;
|
||||
|
||||
const base64 = base64url.toBase64(url);
|
||||
const base64 = base64url.toBase64(url);
|
||||
|
||||
const prefix = "-----BEGIN CERTIFICATE-----\n";
|
||||
const postfix = "-----END CERTIFICATE-----";
|
||||
const pem = base64.match(/.{0,64}/g) || [];
|
||||
const pemString = pem.join("\n");
|
||||
const pemComplete = prefix + pemString + postfix;
|
||||
const pemText = base64url.encode(pemComplete);
|
||||
const prefix = "-----BEGIN CERTIFICATE-----\n";
|
||||
const postfix = "-----END CERTIFICATE-----";
|
||||
const pem = base64.match(/.{0,64}/g) || [];
|
||||
const pemString = pem.join("\n");
|
||||
const pemComplete = prefix + pemString + postfix;
|
||||
const pemText = base64url.encode(pemComplete);
|
||||
|
||||
return pemText;
|
||||
return pemText;
|
||||
};
|
||||
|
||||
export const getAuthLnd = (auth: string) => {
|
||||
const url = new URL(auth);
|
||||
const url = new URL(auth);
|
||||
|
||||
const encodedCert = url.searchParams.get("cert") || "";
|
||||
const encodedMacaroon = url.searchParams.get("macaroon") || "";
|
||||
const socket = url.host;
|
||||
// console.log(url);
|
||||
const encodedCert = url.searchParams.get("cert") || "";
|
||||
const encodedMacaroon = url.searchParams.get("macaroon") || "";
|
||||
const socket = url.host;
|
||||
|
||||
const cert = getBase64CertfromDerFormat(encodedCert);
|
||||
const macaroon = base64url.toBase64(encodedMacaroon);
|
||||
const cert = getBase64CertfromDerFormat(encodedCert);
|
||||
// const macaroon = base64url.toBase64(encodedMacaroon);
|
||||
|
||||
const { lnd } = authenticatedLndGrpc({
|
||||
cert,
|
||||
macaroon,
|
||||
socket
|
||||
});
|
||||
// const cert = base64url.toBase64(encodedCert);
|
||||
const macaroon = base64url.toBase64(encodedMacaroon);
|
||||
|
||||
return lnd;
|
||||
// console.log(encodedCert);
|
||||
|
||||
const params =
|
||||
encodedCert !== ""
|
||||
? {
|
||||
cert,
|
||||
macaroon,
|
||||
socket
|
||||
}
|
||||
: { macaroon, socket };
|
||||
|
||||
const { lnd } = authenticatedLndGrpc(params);
|
||||
|
||||
return lnd;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue