Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
making the lnd config right
Browse files Browse the repository at this point in the history
  • Loading branch information
ildella committed Jul 26, 2023
1 parent c0a0eca commit 411eda7
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
2 changes: 1 addition & 1 deletion errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const parseAxiosError = error => {
message || dataError.message || 'no message provided in the response, check the server logs'
const {method, url} = basic
const humanReadableMessage =
`${status} <-- ${method} ${url} || ${finalMessage}`
`${status} ${method} ${url} :: ${finalMessage}`
// console.log({humanReadableMessage})
return {
status,
Expand Down
1 change: 1 addition & 0 deletions lnd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
lndClients: require('./lnd-clients'),
lndStreams: require('./lnd-streams'),
lndPolarConfig: require('./lnd-polar-config'),
lndEnvConfig: require('./lnd-env-config'),
}
15 changes: 15 additions & 0 deletions lnd/lnd-env-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {curry} = require('../fusto')

module.exports = curry((future, {
host = '127.0.0.1',
port = 8080,
// username,
macaroonType = 'readonly',

Check warning on line 7 in lnd/lnd-env-config.js

View workflow job for this annotation

GitHub Actions / test (18.x)

'macaroonType' is assigned a value but never used

Check warning on line 7 in lnd/lnd-env-config.js

View workflow job for this annotation

GitHub Actions / test (20.x)

'macaroonType' is assigned a value but never used
}) => {
// const macaroonPath = `${basePath}/${username}/data/chain/bitcoin/regtest/admin.macaroon`
const baseUrl = `${host}:${port}`
// const macaroon = process.env[`LND_${macaroonType.toUpperCase()}_MACAROON`]
const macaroon = process.env.LND_INVOICE_MACAROON
const cert = process.env.LND_TLS_CERT
return {macaroon, cert, baseUrl}
})
4 changes: 3 additions & 1 deletion lnd/lnd-polar-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ module.exports = curry((polarNetwork, {
host = '127.0.0.1',
port = 8080,
username,
macaroonType = 'readonly',
}) => {
const basePath = polarBasePath(polarNetwork)
const macaroonPath = `${basePath}/${username}/data/chain/bitcoin/regtest/admin.macaroon`
// const macaroonPath = `${basePath}/${username}/data/chain/bitcoin/regtest/admin.macaroon`
const macaroonPath = `${basePath}/${username}/data/chain/bitcoin/regtest/${macaroonType}.macaroon`
const tlsPath = `${basePath}/${username}/tls.cert`
const baseUrl = `${host}:${port}`
const macaroon = readFileSync(macaroonPath).toString('hex')

Check warning on line 20 in lnd/lnd-polar-config.js

View workflow job for this annotation

GitHub Actions / test (18.x)

Found readFileSync from package "fs" with non literal argument at index 0

Check warning on line 20 in lnd/lnd-polar-config.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Found readFileSync from package "fs" with non literal argument at index 0
Expand Down
20 changes: 20 additions & 0 deletions tests/lnd/lnd-env-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// const assert = require('assert')
// const {test} = require('node:test')

const {lndEnvConfig} = require('../../lnd')

test('calling network by id', () => {
const network = lndEnvConfig()
expect(network).toBeDefined()
// const alice = network({username: 'alice'})
})

test('load config', () => {
process.env.LND_INVOICE_MACAROON = 'a fake macaroon'
process.env.LND_TLS_CERT = 'a fake cert'
const network = lndEnvConfig(1)
const alice = network({username: 'alice', macaroonType: 'invoice'})
expect(alice).toHaveProperty('baseUrl', '127.0.0.1:8080')
expect(alice).toHaveProperty('cert', 'a fake cert')
expect(alice).toHaveProperty('macaroon', 'a fake macaroon')
})
36 changes: 34 additions & 2 deletions tests/lnd/lnd-polar-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@

const lndPolarConfig = require('../../lnd/lnd-polar-config')

const isHexString = string => {
const hexPattern = /^[0-9a-fA-F]+$/
return hexPattern.test(string)
}

const isValidUTF8 = str => {
try {
Buffer.from(str, 'utf8')
return true
} catch (error) {
return false
}
}

test('calling network by id', () => {
const network = lndPolarConfig(2)
const network = lndPolarConfig(3)
expect(network).toBeDefined()
// const alice = network({username: 'alice'})
})

test('load config', () => {
Expand All @@ -16,3 +29,22 @@ test('load config', () => {
expect(alice).toHaveProperty('cert')
expect(alice).toHaveProperty('baseUrl')
})

test('check content', () => {
const network = lndPolarConfig(3)
const {cert, macaroon} = network({username: 'alice'})

expect(isHexString(macaroon)).toBe(true)
expect(isHexString(cert)).toBe(false)

const certUtf8 = Buffer.from(cert).toString('utf8')
// console.log(certUtf8)
expect(isValidUTF8(certUtf8)).toBe(true)
expect(certUtf8.length).toBe(806)
expect(certUtf8.startsWith('-----BEGIN CERTIFICATE-----')).toBe(true)
expect(certUtf8.endsWith('-----END CERTIFICATE-----\n')).toBe(true)
expect(certUtf8.includes('MIICJzCCAc2gAwIBA')).toBe(true)
// expect(cert).toHaveProperty('data')
// expect(cert).toHaveProperty('type')
// expect(cert).toMatchObject({type: 'Buffer'})
})

0 comments on commit 411eda7

Please sign in to comment.