Skip to content

Commit

Permalink
getProxyRootPubkey with CLN support
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Apr 26, 2023
1 parent 4fb8167 commit c874ab1
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 34 deletions.
7 changes: 4 additions & 3 deletions dist/src/grpc/lightning.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/grpc/lightning.js.map

Large diffs are not rendered by default.

50 changes: 36 additions & 14 deletions dist/src/utils/proxy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/utils/proxy.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/grpc/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function loadCredentials(macName?: string): grpc.ChannelCredentials {
}
}

const loadMtlsCredentials = () => {
export const loadMtlsCredentials = () => {
const glCert = fs.readFileSync(config.cln_ca_cert)
const glPriv = fs.readFileSync(config.cln_device_key)
const glChain = fs.readFileSync(config.cln_device_cert)
Expand Down
52 changes: 40 additions & 12 deletions src/utils/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Op } from 'sequelize'
const config = loadConfig()
const LND_IP = config.lnd_ip || 'localhost'
const PROXY_LND_IP = config.proxy_lnd_ip || 'localhost'
const IS_CLN = config.lightning_provider === 'CLN'

const check_proxy_balance = false

Expand Down Expand Up @@ -210,19 +211,46 @@ export function getProxyRootPubkey(): Promise<string> {
resolve(proxyRootPubkey)
return
}
// normal client, to get pubkey of LND
const credentials = Lightning.loadCredentials()
const lnrpcDescriptor = loadProto('lightning')
const lnrpc = lnrpcDescriptor.lnrpc
const lc = new lnrpc.Lightning(LND_IP + ':' + config.lnd_port, credentials)
lc.getInfo({}, function (err, response) {
if (err == null && response) {
proxyRootPubkey = response.identity_pubkey
resolve(proxyRootPubkey)
} else {
reject('CANT GET ROOT KEY')

if (IS_CLN) {
const credentials = Lightning.loadMtlsCredentials()
const descriptor = loadProto('cln/node')
const cln = descriptor.cln
const options = {
'grpc.ssl_target_name_override': 'cln',
}
})
const clnClient = new cln.Node(
LND_IP + ':' + config.lnd_port,
credentials,
options
)
clnClient.getinfo({}, function (err, response) {
if (response && err == null) {
const pubkey = Buffer.from(response.id).toString('hex')
proxyRootPubkey = pubkey
resolve(proxyRootPubkey)
} else {
reject(err)
}
})
} else {
// normal client, to get pubkey of LND or CLN
const credentials = Lightning.loadCredentials()
const lnrpcDescriptor = loadProto('lightning')
const lnrpc = lnrpcDescriptor.lnrpc
const lc = new lnrpc.Lightning(
LND_IP + ':' + config.lnd_port,
credentials
)
lc.getInfo({}, function (err, response) {
if (err == null && response) {
proxyRootPubkey = response.identity_pubkey
resolve(proxyRootPubkey)
} else {
reject('CANT GET ROOT KEY')
}
})
}
})
}

Expand Down
11 changes: 10 additions & 1 deletion testing/cln/alice.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"tribes_host": "localhost:13000",
"tribes_mqtt_port": "1883",
"tribes_insecure": true,
"public_url": "127.0.0.1:3001"
"public_url": "127.0.0.1:3001",
"proxy_initial_sats": 1000,
"proxy_new_nodes": 0,
"proxy_lnd_ip": "127.0.0.1",
"proxy_admin_token": "d86hnf8irgbcv093jdns",
"proxy_admin_url": "http://localhost:5555",
"dont_ping_hub": true,
"proxy_lnd_port": "11111",
"proxy_tls_location": "/Users/evanfeenstra/code/sphinx/sphinx-proxy/cert/tls.cert",
"proxy_macaroons_dir": "/Users/evanfeenstra/code/sphinx/sphinx-proxy/macaroons"
}
}
6 changes: 5 additions & 1 deletion testing/cln/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
**alice**
**alice proxy CLN**

in sphinx-swarm run `cargo run --bin cln`

in sphinx-rs/vls-mqtt use local .env and `cargo run`

in sphinx-proxy run `./cln/creds.sh`

`./sphinx-proxy --mode cln`

node ./dist/app.js --config="/Users/evanfeenstra/code/sphinx/sphinx-relay/testing/cln/alice.json" --db="/Users/evanfeenstra/code/sphinx/sphinx-relay/testing/cln/alice-db.json"

0 comments on commit c874ab1

Please sign in to comment.