This commit is contained in:
hatim boufnichel 2022-05-15 21:24:50 +02:00
parent 8bcb3a7e85
commit de2755f8ed
173 changed files with 47169 additions and 20113 deletions

View file

@ -0,0 +1,134 @@
([]*main.Method) (len=3 cap=4) {
(*main.Method)(0xc00029e730)({
in: (main.MethodMessage) {
name: (string) (len=5) "Empty",
hasZeroFields: (bool) true
},
name: (string) (len=6) "Health",
out: (main.MethodMessage) {
name: (string) (len=5) "Empty",
hasZeroFields: (bool) true
},
opts: (*main.methodOptions)(0xc000039b60)({
authType: (*main.supportedAuth)(0xc0003a2b40)({
id: (string) (len=7) "no_auth",
name: (string) (len=6) "NoAuth",
encrypted: (bool) false,
context: (map[string]string) {
}
}),
method: (string) (len=3) "get",
route: (main.decodedRoute) {
route: (string) (len=7) "/health",
params: ([]string) <nil>
},
query: ([]string) <nil>
})
}),
(*main.Method)(0xc00029e780)({
in: (main.MethodMessage) {
name: (string) (len=25) "EncryptionExchangeRequest",
hasZeroFields: (bool) false
},
name: (string) (len=18) "EncryptionExchange",
out: (main.MethodMessage) {
name: (string) (len=5) "Empty",
hasZeroFields: (bool) true
},
opts: (*main.methodOptions)(0xc000039ce0)({
authType: (*main.supportedAuth)(0xc0003a2c00)({
id: (string) (len=7) "no_auth",
name: (string) (len=6) "NoAuth",
encrypted: (bool) false,
context: (map[string]string) {
}
}),
method: (string) (len=4) "post",
route: (main.decodedRoute) {
route: (string) (len=24) "/api/encryption/exchange",
params: ([]string) <nil>
},
query: ([]string) <nil>
})
}),
(*main.Method)(0xc00029e7d0)({
in: (main.MethodMessage) {
name: (string) (len=5) "Empty",
hasZeroFields: (bool) true
},
name: (string) (len=10) "LndGetInfo",
out: (main.MethodMessage) {
name: (string) (len=18) "LndGetInfoResponse",
hasZeroFields: (bool) false
},
opts: (*main.methodOptions)(0xc000039e60)({
authType: (*main.supportedAuth)(0xc0003a2cc0)({
id: (string) (len=7) "no_auth",
name: (string) (len=6) "NoAuth",
encrypted: (bool) false,
context: (map[string]string) {
}
}),
method: (string) (len=3) "get",
route: (main.decodedRoute) {
route: (string) (len=16) "/api/lnd/getinfo",
params: ([]string) <nil>
},
query: ([]string) <nil>
})
})
}
([]*main.Enum) <nil>
(map[string]*main.Message) (len=3) {
(string) (len=25) "EncryptionExchangeRequest": (*main.Message)(0xc000238f40)({
fullName: (string) (len=25) "EncryptionExchangeRequest",
name: (string) (len=25) "EncryptionExchangeRequest",
fields: ([]*main.Field) (len=2 cap=2) {
(*main.Field)(0xc0003a2390)({
name: (string) (len=10) "public_key",
kind: (string) (len=6) "string",
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false
}),
(*main.Field)(0xc0003a23c0)({
name: (string) (len=9) "device_id",
kind: (string) (len=6) "string",
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false
})
}
}),
(string) (len=18) "LndGetInfoResponse": (*main.Message)(0xc000238f80)({
fullName: (string) (len=18) "LndGetInfoResponse",
name: (string) (len=18) "LndGetInfoResponse",
fields: ([]*main.Field) (len=1 cap=1) {
(*main.Field)(0xc0003a23f0)({
name: (string) (len=5) "alias",
kind: (string) (len=6) "string",
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false
})
}
}),
(string) (len=5) "Empty": (*main.Message)(0xc000238f00)({
fullName: (string) (len=5) "Empty",
name: (string) (len=5) "Empty",
fields: ([]*main.Field) <nil>
})
}
parsing file: structs 3
parsing file: methods 2
-> [{no_auth NoAuth false map[]} {guest Guest false map[token:string]} {admin Admin true map[pub:string]}]

View file

@ -0,0 +1,60 @@
// This file was autogenerated from a .proto file, DO NOT EDIT!
import express, { Response } from 'express'
import * as Types from './types'
export type Logger = { log: (v: any) => void, error: (v: any) => void }
export type ServerOptions = {
allowNotImplementedMethods?: number
logger?: Logger
throwErrors?: true
NoAuthAuthGuard: (authorizationHeader?: string) => Promise<Types.NoAuthContext>
GuestAuthGuard: (authorizationHeader?: string) => Promise<Types.GuestContext>
AdminAuthGuard: (authorizationHeader?: string) => Promise<Types.AdminContext>
encryptionCallback: (ctx: Types.AuthContext, body: any) => Promise<string>
}
const logErrorAndReturnResponse = (error: Error, response: string, res: Response, logger: Logger) => { logger.error(error.message || error); res.json({ status: 'ERROR', reason: response }) }
export default (methods: Types.ServerMethods, opts: ServerOptions) => {
const logger = opts.logger || { log: console.log, error: console.error }
const app = express()
if (!opts.allowNotImplementedMethods && !methods.Health) throw new Error('method: Health is not implemented')
app.get('/health', async (req, res) => {
try {
if (!methods.Health) throw new Error('method: Health is not implemented')
const authContext = await opts.NoAuthAuthGuard(req.headers['authorization'])
const query = req.query
const params = req.params
await methods.Health({ ...authContext, ...query, ...params })
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')
app.post('/api/encryption/exchange', async (req, res) => {
try {
if (!methods.EncryptionExchange) throw new Error('method: EncryptionExchange is not implemented')
const authContext = await opts.NoAuthAuthGuard(req.headers['authorization'])
const request = req.body
const error = Types.EncryptionExchangeRequestValidate(request)
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
const query = req.query
const params = req.params
await methods.EncryptionExchange({ ...authContext, ...query, ...params }, request)
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')
app.get('/api/lnd/getinfo', async (req, res) => {
try {
if (!methods.LndGetInfo) throw new Error('method: LndGetInfo is not implemented')
const authContext = await opts.NoAuthAuthGuard(req.headers['authorization'])
const query = req.query
const params = req.params
const response = await methods.LndGetInfo({ ...authContext, ...query, ...params })
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 }
})
var server: { close: () => void } | undefined
return {
Close: () => { if (!server) { throw new Error('tried closing server before starting') } else server.close() },
Listen: (port: number) => { server = app.listen(port, () => logger.log('Example app listening on port ' + port)) }
}
}

View file

@ -0,0 +1,44 @@
// This file was autogenerated from a .proto file, DO NOT EDIT!
import axios from 'axios'
import * as Types from './types'
export type ResultError = { status: 'ERROR', reason: string }
export type ClientParams = {
baseUrl: string
retrieveNoAuthAuth: () => Promise<string | null>
retrieveGuestAuth: () => Promise<string | null>
retrieveAdminAuth: () => Promise<string | null>
}
export default (params: ClientParams) => ({
Health: async (): Promise<ResultError | { status: 'OK' }> => {
const auth = await params.retrieveNoAuthAuth()
if (auth === null) throw new Error('retrieveNoAuthAuth() returned null')
const { data } = await axios.get(params.baseUrl + '/health', { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return data
}
return { status: 'ERROR', reason: 'invalid response' }
},
EncryptionExchange: async (request: Types.EncryptionExchangeRequest): Promise<ResultError | { status: 'OK' }> => {
const auth = await params.retrieveNoAuthAuth()
if (auth === null) throw new Error('retrieveNoAuthAuth() returned null')
const { data } = await axios.post(params.baseUrl + '/api/encryption/exchange', request, { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
return data
}
return { status: 'ERROR', reason: 'invalid response' }
},
LndGetInfo: async (): Promise<ResultError | { status: 'OK', result: Types.Empty }> => {
const auth = await params.retrieveNoAuthAuth()
if (auth === null) throw new Error('retrieveNoAuthAuth() returned null')
const { data } = await axios.get(params.baseUrl + '/api/lnd/getinfo', { headers: { 'authorization': auth } })
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
if (data.status === 'OK') {
const error = Types.LndGetInfoResponseValidate(data.result)
if (error === null) { return data } else return { status: 'ERROR', reason: error.message }
}
return { status: 'ERROR', reason: 'invalid response' }
},
})

View file

@ -0,0 +1,92 @@
// This file was autogenerated from a .proto file, DO NOT EDIT!
export type NoAuthContext = {
}
export type GuestContext = {
token: string
}
export type AdminContext = {
pub: string
}
export type AuthContext = NoAuthContext | GuestContext | AdminContext
export type Health_Query = {
}
export type Health_RouteParams = {
}
export type Health_Context = Health_Query & Health_RouteParams & NoAuthContext
export type EncryptionExchange_Query = {
}
export type EncryptionExchange_RouteParams = {
}
export type EncryptionExchange_Context = EncryptionExchange_Query & EncryptionExchange_RouteParams & NoAuthContext
export type LndGetInfo_Query = {
}
export type LndGetInfo_RouteParams = {
}
export type LndGetInfo_Context = LndGetInfo_Query & LndGetInfo_RouteParams & NoAuthContext
export type ServerMethods = {
Health?: (ctx: Health_Context) => Promise<void>
EncryptionExchange?: (ctx: EncryptionExchange_Context, req: EncryptionExchangeRequest) => Promise<void>
LndGetInfo?: (ctx: LndGetInfo_Context) => Promise<LndGetInfoResponse>
}
export type OptionsBaseMessage = {
allOptionalsAreSet?: true
}
export type LndGetInfoResponse = {
alias: string
}
export const LndGetInfoResponseOptionalFields: [] = []
export type LndGetInfoResponseOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
alias_CustomCheck?: (v: string) => boolean
}
export const LndGetInfoResponseValidate = (o?: LndGetInfoResponse, opts: LndGetInfoResponseOptions = {}, path: string = 'LndGetInfoResponse::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.alias !== 'string') return new Error(`${path}.alias: is not a string`)
if (opts.alias_CustomCheck && !opts.alias_CustomCheck(o.alias)) return new Error(`${path}.alias: custom check failed`)
return null
}
export type Empty = {
}
export const EmptyOptionalFields: [] = []
export type EmptyOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
}
export const EmptyValidate = (o?: Empty, opts: EmptyOptions = {}, path: string = 'Empty::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
return null
}
export type EncryptionExchangeRequest = {
public_key: string
device_id: string
}
export const EncryptionExchangeRequestOptionalFields: [] = []
export type EncryptionExchangeRequestOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
public_key_CustomCheck?: (v: string) => boolean
device_id_CustomCheck?: (v: string) => boolean
}
export const EncryptionExchangeRequestValidate = (o?: EncryptionExchangeRequest, opts: EncryptionExchangeRequestOptions = {}, path: string = 'EncryptionExchangeRequest::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.public_key !== 'string') return new Error(`${path}.public_key: is not a string`)
if (opts.public_key_CustomCheck && !opts.public_key_CustomCheck(o.public_key)) return new Error(`${path}.public_key: custom check failed`)
if (typeof o.device_id !== 'string') return new Error(`${path}.device_id: is not a string`)
if (opts.device_id_CustomCheck && !opts.device_id_CustomCheck(o.device_id)) return new Error(`${path}.device_id: custom check failed`)
return null
}