@ -90,7 +90,15 @@ export class CommonService {
if ( req . session . selectedNode && req . session . selectedNode . ln _implementation ) {
switch ( req . session . selectedNode . ln _implementation . toUpperCase ( ) ) {
case 'CLN' :
req . session . selectedNode . options . headers = { rune : Buffer . from ( fs . readFileSync ( req . session . selectedNode . macaroon _path ) ) . toString ( ) . replace ( '\n' , '' ) } ;
try {
if ( ! req . session . selectedNode . macaroon _value ) {
req . session . selectedNode . macaroon _value = this . getMacaroonValue ( req . session . selectedNode . macaroon _path ) ;
}
req . session . selectedNode . options . headers = { rune : req . session . selectedNode . macaroon _value } ;
}
catch ( err ) {
throw new Error ( err ) ;
}
break ;
case 'ECL' :
req . session . selectedNode . options . headers = { authorization : 'Basic ' + Buffer . from ( ':' + req . session . selectedNode . ln _api _password ) . toString ( 'base64' ) } ;
@ -116,6 +124,17 @@ export class CommonService {
return { status : 502 , message : err } ;
}
} ;
this . getMacaroonValue = ( macaroon _path ) => {
const data = fs . readFileSync ( macaroon _path , 'utf8' ) ;
const pattern = /LIGHTNING_RUNE="(?<runeValue>[^"]+)"/ ;
const match = data . match ( pattern ) ;
if ( match . groups . runeValue ) {
return match . groups . runeValue ;
}
else {
throw new Error ( 'Rune not found in the file.' ) ;
}
} ;
this . setOptions = ( req ) => {
if ( this . nodes [ 0 ] . options && this . nodes [ 0 ] . options . headers ) {
return ;
@ -132,7 +151,15 @@ export class CommonService {
if ( node . ln _implementation ) {
switch ( node . ln _implementation . toUpperCase ( ) ) {
case 'CLN' :
node . options . headers = { rune : Buffer . from ( fs . readFileSync ( node . macaroon _path ) ) . toString ( ) . replace ( '\n' , '' ) } ;
try {
if ( ! node . macaroon _value ) {
node . macaroon _value = this . getMacaroonValue ( node . macaroon _path ) ;
}
node . options . headers = { rune : node . macaroon _value } ;
}
catch ( err ) {
throw new Error ( err ) ;
}
break ;
case 'ECL' :
node . options . headers = { authorization : 'Basic ' + Buffer . from ( ':' + node . ln _api _password ) . toString ( 'base64' ) } ;