diff --git a/api/lnd/index.js b/api/lnd/index.js index abc39e8248..1f5bb1dca9 100644 --- a/api/lnd/index.js +++ b/api/lnd/index.js @@ -1,6 +1,6 @@ import { cachedFetcher } from '@/lib/fetch' import { toPositiveNumber } from '@/lib/validate' -import { authenticatedLndGrpc } from '@/lib/lnd' +import { authenticatedLndGrpc } from 'proxed-lnd-service' import { getIdentity, getHeight, getWalletInfo, getNode } from 'ln-service' const lnd = global.lnd || authenticatedLndGrpc({ diff --git a/lib/lnd.js b/lib/lnd.js deleted file mode 100644 index b9d379541e..0000000000 --- a/lib/lnd.js +++ /dev/null @@ -1,52 +0,0 @@ -// fork of https://github.com/alexbosworth/lightning/blob/master/lnd_grpc/authenticated_lnd_grpc.js -// that allows to enable or disable proxy - -import { join } from 'path' -import apiForProto from 'lightning/lnd_grpc/api_for_proto' -import { defaultSocket, grpcSslCipherSuites, packageTypes, protoFiles, protosDir, serviceTypes } from 'lightning/grpc/index' -import grpcCredentials from 'lightning/lnd_grpc/grpc_credentials' -import { createRequire } from 'module' - -const { GRPC_SSL_CIPHER_SUITES } = process.env -const { keys } = Object - -export function authenticatedLndGrpc ({ cert, macaroon, path, socket }, withProxy) { - const req = createRequire(import.meta.url) - - const lightningModulePath = req.resolve('lightning') - const pathForProto = proto => join(lightningModulePath, protosDir, proto) - - const { credentials } = grpcCredentials({ cert, macaroon }) - const lndSocket = socket || defaultSocket - - if (!!cert && GRPC_SSL_CIPHER_SUITES !== grpcSslCipherSuites) { - process.env.GRPC_SSL_CIPHER_SUITES = grpcSslCipherSuites - } - - const params = { - 'grpc.max_receive_message_length': -1, - 'grpc.max_send_message_length': -1, - 'grpc.enable_http_proxy': withProxy ? 1 : 0 - } - - // Assemble different services from their proto files - return { - lnd: keys(serviceTypes).reduce((services, type) => { - const service = serviceTypes[type] - - const file = protoFiles[service] - - services[type] = apiForProto({ - credentials, - params, - service, - path: path ? join(path, file) : pathForProto(file), - socket: lndSocket, - type: packageTypes[service] - }) - - return services - }, - {}) - } -} diff --git a/package-lock.json b/package-lock.json index 3326e9a10e..edba1a1c74 100644 --- a/package-lock.json +++ b/package-lock.json @@ -65,6 +65,7 @@ "pg-boss": "^9.0.3", "piexifjs": "^1.0.6", "prisma": "^5.20.0", + "proxed-lnd-service": "github:stackernews/proxed-lnd-service#10.22.1", "qrcode.react": "^4.0.1", "react": "^18.3.1", "react-avatar-editor": "^13.0.2", @@ -16842,6 +16843,17 @@ "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" }, + "node_modules/proxed-lnd-service": { + "version": "10.22.1", + "resolved": "git+ssh://git@github.com/stackernews/proxed-lnd-service.git#5453e5a83f2b2d87b64c28169a0c8a0bbacaa98c", + "license": "MIT", + "dependencies": { + "ln-service": "^57.22.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", diff --git a/package.json b/package.json index d4fa4d1115..155c3fde3c 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "pg-boss": "^9.0.3", "piexifjs": "^1.0.6", "prisma": "^5.20.0", + "proxed-lnd-service": "github:stackernews/proxed-lnd-service#10.22.1", "qrcode.react": "^4.0.1", "react": "^18.3.1", "react-avatar-editor": "^13.0.2", diff --git a/wallets/lnd/server.js b/wallets/lnd/server.js index 8e260984fe..5f70a858ce 100644 --- a/wallets/lnd/server.js +++ b/wallets/lnd/server.js @@ -1,5 +1,5 @@ import { datePivot } from '@/lib/time' -import { authenticatedLndGrpc } from '@/lib/lnd' +import { authenticatedLndGrpc } from 'proxed-lnd-service' import { createInvoice as lndCreateInvoice } from 'ln-service' import { TOR_REGEXP } from '@/lib/url' diff --git a/worker/index.js b/worker/index.js index 3b12e962f1..34fb4f0956 100644 --- a/worker/index.js +++ b/worker/index.js @@ -16,7 +16,7 @@ import { timestampItem } from './ots.js' import { computeStreaks, checkStreak } from './streak.js' import { nip57 } from './nostr.js' import fetch from 'cross-fetch' -import { authenticatedLndGrpc } from '@/lib/lnd' +import { authenticatedLndGrpc } from 'proxed-lnd-service' import { views, rankViews } from './views.js' import { imgproxy } from './imgproxy.js' import { deleteItem } from './ephemeralItems.js'