initial nosrt integration
This commit is contained in:
parent
947cf34ff4
commit
50ba34e050
44 changed files with 40869 additions and 7913 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import express, { Response, json, urlencoded } from 'express'
|
||||
import cors from 'cors'
|
||||
import * as Types from './types'
|
||||
import * as Types from './types.js'
|
||||
export type Logger = { log: (v: any) => void, error: (v: any) => void }
|
||||
export type ServerOptions = {
|
||||
allowCors?: true
|
||||
|
|
@ -21,7 +21,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const logger = opts.logger || { log: console.log, error: console.error }
|
||||
const app = express()
|
||||
if (opts.allowCors) {
|
||||
app.use(cors())
|
||||
app.use(cors())
|
||||
}
|
||||
app.use(json())
|
||||
app.use(urlencoded({ extended: true }))
|
||||
|
|
@ -33,7 +33,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
await methods.Health({ ...authContext, ...query, ...params })
|
||||
res.json({status: 'OK'})
|
||||
res.json({ status: 'OK' })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.EncryptionExchange) throw new Error('method: EncryptionExchange is not implemented')
|
||||
|
|
@ -47,7 +47,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
await methods.EncryptionExchange({ ...authContext, ...query, ...params }, request)
|
||||
res.json({status: 'OK'})
|
||||
res.json({ status: 'OK' })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.LndGetInfo) throw new Error('method: LndGetInfo is not implemented')
|
||||
|
|
@ -63,7 +63,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.LndGetInfo({ ...authContext, ...query, ...params }, request)
|
||||
res.json({status: 'OK', result: await opts.encryptCallback(encryptionDeviceId, response)})
|
||||
res.json({ status: 'OK', result: await opts.encryptCallback(encryptionDeviceId, response) })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.AddUser) throw new Error('method: AddUser is not implemented')
|
||||
|
|
@ -77,7 +77,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.AddUser({ ...authContext, ...query, ...params }, request)
|
||||
res.json({status: 'OK', result: response})
|
||||
res.json({ status: 'OK', result: response })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.AuthUser) throw new Error('method: AuthUser is not implemented')
|
||||
|
|
@ -91,7 +91,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.AuthUser({ ...authContext, ...query, ...params }, request)
|
||||
res.json({status: 'OK', result: response})
|
||||
res.json({ status: 'OK', result: response })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.NewAddress) throw new Error('method: NewAddress is not implemented')
|
||||
|
|
@ -105,7 +105,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.NewAddress({ ...authContext, ...query, ...params }, request)
|
||||
res.json({status: 'OK', result: response})
|
||||
res.json({ status: 'OK', result: response })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.PayAddress) throw new Error('method: PayAddress is not implemented')
|
||||
|
|
@ -119,7 +119,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.PayAddress({ ...authContext, ...query, ...params }, request)
|
||||
res.json({status: 'OK', result: response})
|
||||
res.json({ status: 'OK', result: response })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.NewInvoice) throw new Error('method: NewInvoice is not implemented')
|
||||
|
|
@ -133,7 +133,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.NewInvoice({ ...authContext, ...query, ...params }, request)
|
||||
res.json({status: 'OK', result: response})
|
||||
res.json({ status: 'OK', result: response })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.PayInvoice) throw new Error('method: PayInvoice is not implemented')
|
||||
|
|
@ -147,7 +147,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.PayInvoice({ ...authContext, ...query, ...params }, request)
|
||||
res.json({status: 'OK', result: response})
|
||||
res.json({ status: 'OK', result: response })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.OpenChannel) throw new Error('method: OpenChannel is not implemented')
|
||||
|
|
@ -161,7 +161,7 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.OpenChannel({ ...authContext, ...query, ...params }, request)
|
||||
res.json({status: 'OK', result: response})
|
||||
res.json({ status: 'OK', result: response })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (!opts.allowNotImplementedMethods && !methods.GetOpenChannelLNURL) throw new Error('method: GetOpenChannelLNURL is not implemented')
|
||||
|
|
@ -172,11 +172,11 @@ export default (methods: Types.ServerMethods, opts: ServerOptions) => {
|
|||
const query = req.query
|
||||
const params = req.params
|
||||
const response = await methods.GetOpenChannelLNURL({ ...authContext, ...query, ...params })
|
||||
res.json({status: 'OK', result: response})
|
||||
res.json({ status: 'OK', result: response })
|
||||
} catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||
})
|
||||
if (opts.staticFiles) {
|
||||
app.use(express.static(opts.staticFiles))
|
||||
app.use(express.static(opts.staticFiles))
|
||||
}
|
||||
var server: { close: () => void } | undefined
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// This file was autogenerated from a .proto file, DO NOT EDIT!
|
||||
import axios from 'axios'
|
||||
import * as Types from './types'
|
||||
import * as Types from './types.js'
|
||||
export type ResultError = { status: 'ERROR', reason: string }
|
||||
|
||||
export type ClientParams = {
|
||||
|
|
@ -19,7 +19,7 @@ export default (params: ClientParams) => ({
|
|||
let finalRoute = '/api/health'
|
||||
const { data } = await axios.get(params.baseUrl + finalRoute, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
return data
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
|
|
@ -30,7 +30,7 @@ export default (params: ClientParams) => ({
|
|||
let finalRoute = '/api/encryption/exchange'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
return data
|
||||
}
|
||||
return { status: 'ERROR', reason: 'invalid response' }
|
||||
|
|
@ -39,9 +39,9 @@ export default (params: ClientParams) => ({
|
|||
const auth = await params.retrieveAdminAuth()
|
||||
if (auth === null) throw new Error('retrieveAdminAuth() returned null')
|
||||
let finalRoute = '/api/lnd/getinfo'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, await params.encryptCallback(request), { headers: { 'authorization': auth, 'x-e2ee-device-id-x': params.deviceId } })
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, await params.encryptCallback(request), { headers: { 'authorization': auth, 'x-e2ee-device-id-x': params.deviceId } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
const result = await params.decryptCallback(data.result)
|
||||
const error = Types.LndGetInfoResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', result: result } } else return { status: 'ERROR', reason: error.message }
|
||||
|
|
@ -54,7 +54,7 @@ export default (params: ClientParams) => ({
|
|||
let finalRoute = '/api/user/add'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
const result = data.result
|
||||
const error = Types.AddUserResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', result: result } } else return { status: 'ERROR', reason: error.message }
|
||||
|
|
@ -67,7 +67,7 @@ export default (params: ClientParams) => ({
|
|||
let finalRoute = '/api/user/auth'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
const result = data.result
|
||||
const error = Types.AuthUserResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', result: result } } else return { status: 'ERROR', reason: error.message }
|
||||
|
|
@ -80,7 +80,7 @@ export default (params: ClientParams) => ({
|
|||
let finalRoute = '/api/user/chain/new'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
const result = data.result
|
||||
const error = Types.NewAddressResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', result: result } } else return { status: 'ERROR', reason: error.message }
|
||||
|
|
@ -93,7 +93,7 @@ export default (params: ClientParams) => ({
|
|||
let finalRoute = '/api/user/chain/pay'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
const result = data.result
|
||||
const error = Types.PayAddressResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', result: result } } else return { status: 'ERROR', reason: error.message }
|
||||
|
|
@ -106,7 +106,7 @@ export default (params: ClientParams) => ({
|
|||
let finalRoute = '/api/user/invoice/new'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
const result = data.result
|
||||
const error = Types.NewInvoiceResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', result: result } } else return { status: 'ERROR', reason: error.message }
|
||||
|
|
@ -119,7 +119,7 @@ export default (params: ClientParams) => ({
|
|||
let finalRoute = '/api/user/invoice/pay'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
const result = data.result
|
||||
const error = Types.PayInvoiceResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', result: result } } else return { status: 'ERROR', reason: error.message }
|
||||
|
|
@ -132,7 +132,7 @@ export default (params: ClientParams) => ({
|
|||
let finalRoute = '/api/user/open/channel'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, request, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
const result = data.result
|
||||
const error = Types.OpenChannelResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', result: result } } else return { status: 'ERROR', reason: error.message }
|
||||
|
|
@ -145,7 +145,7 @@ export default (params: ClientParams) => ({
|
|||
let finalRoute = '/api/user/lnurl_channel'
|
||||
const { data } = await axios.post(params.baseUrl + finalRoute, {}, { headers: { 'authorization': auth } })
|
||||
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||
if (data.status === 'OK') {
|
||||
if (data.status === 'OK') {
|
||||
const result = data.result
|
||||
const error = Types.GetOpenChannelLNURLResponseValidate(result)
|
||||
if (error === null) { return { status: 'OK', result: result } } else return { status: 'ERROR', reason: error.message }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue