nostr polish
This commit is contained in:
parent
91d67ab4ee
commit
96b619c886
13 changed files with 996 additions and 662 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -7,7 +7,7 @@ export type Logger = { log: (v: any) => void, error: (v: any) => void }
|
||||||
export type ServerOptions = {
|
export type ServerOptions = {
|
||||||
allowCors?: true
|
allowCors?: true
|
||||||
staticFiles?: string
|
staticFiles?: string
|
||||||
allowNotImplementedMethods?: number
|
allowNotImplementedMethods?: true
|
||||||
logger?: Logger
|
logger?: Logger
|
||||||
throwErrors?: true
|
throwErrors?: true
|
||||||
GuestAuthGuard: (authorizationHeader?: string) => Promise<Types.GuestContext>
|
GuestAuthGuard: (authorizationHeader?: string) => Promise<Types.GuestContext>
|
||||||
|
|
|
||||||
115
proto/autogenerated/ts/nostr_client.ts
Normal file
115
proto/autogenerated/ts/nostr_client.ts
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
// This file was autogenerated from a .proto file, DO NOT EDIT!
|
||||||
|
import { NostrRequest } from './nostr_transport.js'
|
||||||
|
import * as Types from './types.js'
|
||||||
|
export type ResultError = { status: 'ERROR', reason: string }
|
||||||
|
|
||||||
|
export type NostrClientParams = {
|
||||||
|
pubDestination: string
|
||||||
|
retrieveNostrUserAuth: () => Promise<string | null>
|
||||||
|
checkResult?: true
|
||||||
|
}
|
||||||
|
export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>) => ({
|
||||||
|
NewAddress: async (request: Types.NewAddressRequest): Promise<ResultError | ({ status: 'OK' }& Types.NewAddressResponse)> => {
|
||||||
|
const auth = await params.retrieveNostrUserAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||||
|
const nostrRequest: NostrRequest = {}
|
||||||
|
nostrRequest.body = request
|
||||||
|
const data = await send(params.pubDestination, {rpcName:'NewAddress',authIdentifier:auth, ...nostrRequest })
|
||||||
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
|
if (data.status === 'OK') {
|
||||||
|
const result = data
|
||||||
|
if(!params.checkResult) return { status: 'OK', ...result }
|
||||||
|
const error = Types.NewAddressResponseValidate(result)
|
||||||
|
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
|
PayAddress: async (request: Types.PayAddressRequest): Promise<ResultError | ({ status: 'OK' }& Types.PayAddressResponse)> => {
|
||||||
|
const auth = await params.retrieveNostrUserAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||||
|
const nostrRequest: NostrRequest = {}
|
||||||
|
nostrRequest.body = request
|
||||||
|
const data = await send(params.pubDestination, {rpcName:'PayAddress',authIdentifier:auth, ...nostrRequest })
|
||||||
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
|
if (data.status === 'OK') {
|
||||||
|
const result = data
|
||||||
|
if(!params.checkResult) return { status: 'OK', ...result }
|
||||||
|
const error = Types.PayAddressResponseValidate(result)
|
||||||
|
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
|
NewInvoice: async (request: Types.NewInvoiceRequest): Promise<ResultError | ({ status: 'OK' }& Types.NewInvoiceResponse)> => {
|
||||||
|
const auth = await params.retrieveNostrUserAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||||
|
const nostrRequest: NostrRequest = {}
|
||||||
|
nostrRequest.body = request
|
||||||
|
const data = await send(params.pubDestination, {rpcName:'NewInvoice',authIdentifier:auth, ...nostrRequest })
|
||||||
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
|
if (data.status === 'OK') {
|
||||||
|
const result = data
|
||||||
|
if(!params.checkResult) return { status: 'OK', ...result }
|
||||||
|
const error = Types.NewInvoiceResponseValidate(result)
|
||||||
|
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
|
PayInvoice: async (request: Types.PayInvoiceRequest): Promise<ResultError | ({ status: 'OK' }& Types.PayInvoiceResponse)> => {
|
||||||
|
const auth = await params.retrieveNostrUserAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||||
|
const nostrRequest: NostrRequest = {}
|
||||||
|
nostrRequest.body = request
|
||||||
|
const data = await send(params.pubDestination, {rpcName:'PayInvoice',authIdentifier:auth, ...nostrRequest })
|
||||||
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
|
if (data.status === 'OK') {
|
||||||
|
const result = data
|
||||||
|
if(!params.checkResult) return { status: 'OK', ...result }
|
||||||
|
const error = Types.PayInvoiceResponseValidate(result)
|
||||||
|
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
|
OpenChannel: async (request: Types.OpenChannelRequest): Promise<ResultError | ({ status: 'OK' }& Types.OpenChannelResponse)> => {
|
||||||
|
const auth = await params.retrieveNostrUserAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||||
|
const nostrRequest: NostrRequest = {}
|
||||||
|
nostrRequest.body = request
|
||||||
|
const data = await send(params.pubDestination, {rpcName:'OpenChannel',authIdentifier:auth, ...nostrRequest })
|
||||||
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
|
if (data.status === 'OK') {
|
||||||
|
const result = data
|
||||||
|
if(!params.checkResult) return { status: 'OK', ...result }
|
||||||
|
const error = Types.OpenChannelResponseValidate(result)
|
||||||
|
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
|
GetLnurlWithdrawLink: async (): Promise<ResultError | ({ status: 'OK' }& Types.LnurlLinkResponse)> => {
|
||||||
|
const auth = await params.retrieveNostrUserAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||||
|
const nostrRequest: NostrRequest = {}
|
||||||
|
const data = await send(params.pubDestination, {rpcName:'GetLnurlWithdrawLink',authIdentifier:auth, ...nostrRequest })
|
||||||
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
|
if (data.status === 'OK') {
|
||||||
|
const result = data
|
||||||
|
if(!params.checkResult) return { status: 'OK', ...result }
|
||||||
|
const error = Types.LnurlLinkResponseValidate(result)
|
||||||
|
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
|
GetLNURLChannelLink: async (): Promise<ResultError | ({ status: 'OK' }& Types.LnurlLinkResponse)> => {
|
||||||
|
const auth = await params.retrieveNostrUserAuth()
|
||||||
|
if (auth === null) throw new Error('retrieveNostrUserAuth() returned null')
|
||||||
|
const nostrRequest: NostrRequest = {}
|
||||||
|
const data = await send(params.pubDestination, {rpcName:'GetLNURLChannelLink',authIdentifier:auth, ...nostrRequest })
|
||||||
|
if (data.status === 'ERROR' && typeof data.reason === 'string') return data
|
||||||
|
if (data.status === 'OK') {
|
||||||
|
const result = data
|
||||||
|
if(!params.checkResult) return { status: 'OK', ...result }
|
||||||
|
const error = Types.LnurlLinkResponseValidate(result)
|
||||||
|
if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message }
|
||||||
|
}
|
||||||
|
return { status: 'ERROR', reason: 'invalid response' }
|
||||||
|
},
|
||||||
|
})
|
||||||
112
proto/autogenerated/ts/nostr_transport.ts
Normal file
112
proto/autogenerated/ts/nostr_transport.ts
Normal file
|
|
@ -0,0 +1,112 @@
|
||||||
|
// This file was autogenerated from a .proto file, DO NOT EDIT!
|
||||||
|
|
||||||
|
import * as Types from './types.js'
|
||||||
|
export type Logger = { log: (v: any) => void, error: (v: any) => void }
|
||||||
|
type NostrResponse = (message: object) => void
|
||||||
|
export type NostrRequest = {
|
||||||
|
rpcName?: string
|
||||||
|
params?: Record<string, string>
|
||||||
|
query?: Record<string, string>
|
||||||
|
body?: any
|
||||||
|
authIdentifier?: string
|
||||||
|
requestId?: string
|
||||||
|
}
|
||||||
|
export type NostrOptions = {
|
||||||
|
logger?: Logger
|
||||||
|
throwErrors?: true
|
||||||
|
NostrUserAuthGuard: (identifier?: string) => Promise<Types.UserContext>
|
||||||
|
}
|
||||||
|
const logErrorAndReturnResponse = (error: Error, response: string, res: NostrResponse, logger: Logger) => { logger.error(error.message || error); res({ status: 'ERROR', reason: response }) }
|
||||||
|
export default (methods: Types.ServerMethods, opts: NostrOptions) => {
|
||||||
|
const logger = opts.logger || { log: console.log, error: console.error }
|
||||||
|
return async (req: NostrRequest, res: NostrResponse) => {
|
||||||
|
switch (req.rpcName) {
|
||||||
|
case 'NewAddress':
|
||||||
|
try {
|
||||||
|
if (!methods.NewAddress) throw new Error('method: NewAddress is not implemented')
|
||||||
|
const authContext = await opts.NostrUserAuthGuard(req.authIdentifier)
|
||||||
|
const request = req.body
|
||||||
|
const error = Types.NewAddressRequestValidate(request)
|
||||||
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
|
||||||
|
const query = req.query
|
||||||
|
const params = req.params
|
||||||
|
const response = await methods.NewAddress({ ...authContext, ...query, ...params }, request)
|
||||||
|
res({status: 'OK', ...response})
|
||||||
|
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||||
|
break
|
||||||
|
case 'PayAddress':
|
||||||
|
try {
|
||||||
|
if (!methods.PayAddress) throw new Error('method: PayAddress is not implemented')
|
||||||
|
const authContext = await opts.NostrUserAuthGuard(req.authIdentifier)
|
||||||
|
const request = req.body
|
||||||
|
const error = Types.PayAddressRequestValidate(request)
|
||||||
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
|
||||||
|
const query = req.query
|
||||||
|
const params = req.params
|
||||||
|
const response = await methods.PayAddress({ ...authContext, ...query, ...params }, request)
|
||||||
|
res({status: 'OK', ...response})
|
||||||
|
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||||
|
break
|
||||||
|
case 'NewInvoice':
|
||||||
|
try {
|
||||||
|
if (!methods.NewInvoice) throw new Error('method: NewInvoice is not implemented')
|
||||||
|
const authContext = await opts.NostrUserAuthGuard(req.authIdentifier)
|
||||||
|
const request = req.body
|
||||||
|
const error = Types.NewInvoiceRequestValidate(request)
|
||||||
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
|
||||||
|
const query = req.query
|
||||||
|
const params = req.params
|
||||||
|
const response = await methods.NewInvoice({ ...authContext, ...query, ...params }, request)
|
||||||
|
res({status: 'OK', ...response})
|
||||||
|
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||||
|
break
|
||||||
|
case 'PayInvoice':
|
||||||
|
try {
|
||||||
|
if (!methods.PayInvoice) throw new Error('method: PayInvoice is not implemented')
|
||||||
|
const authContext = await opts.NostrUserAuthGuard(req.authIdentifier)
|
||||||
|
const request = req.body
|
||||||
|
const error = Types.PayInvoiceRequestValidate(request)
|
||||||
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
|
||||||
|
const query = req.query
|
||||||
|
const params = req.params
|
||||||
|
const response = await methods.PayInvoice({ ...authContext, ...query, ...params }, request)
|
||||||
|
res({status: 'OK', ...response})
|
||||||
|
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||||
|
break
|
||||||
|
case 'OpenChannel':
|
||||||
|
try {
|
||||||
|
if (!methods.OpenChannel) throw new Error('method: OpenChannel is not implemented')
|
||||||
|
const authContext = await opts.NostrUserAuthGuard(req.authIdentifier)
|
||||||
|
const request = req.body
|
||||||
|
const error = Types.OpenChannelRequestValidate(request)
|
||||||
|
if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger)
|
||||||
|
const query = req.query
|
||||||
|
const params = req.params
|
||||||
|
const response = await methods.OpenChannel({ ...authContext, ...query, ...params }, request)
|
||||||
|
res({status: 'OK', ...response})
|
||||||
|
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||||
|
break
|
||||||
|
case 'GetLnurlWithdrawLink':
|
||||||
|
try {
|
||||||
|
if (!methods.GetLnurlWithdrawLink) throw new Error('method: GetLnurlWithdrawLink is not implemented')
|
||||||
|
const authContext = await opts.NostrUserAuthGuard(req.authIdentifier)
|
||||||
|
const query = req.query
|
||||||
|
const params = req.params
|
||||||
|
const response = await methods.GetLnurlWithdrawLink({ ...authContext, ...query, ...params })
|
||||||
|
res({status: 'OK', ...response})
|
||||||
|
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||||
|
break
|
||||||
|
case 'GetLNURLChannelLink':
|
||||||
|
try {
|
||||||
|
if (!methods.GetLNURLChannelLink) throw new Error('method: GetLNURLChannelLink is not implemented')
|
||||||
|
const authContext = await opts.NostrUserAuthGuard(req.authIdentifier)
|
||||||
|
const query = req.query
|
||||||
|
const params = req.params
|
||||||
|
const response = await methods.GetLNURLChannelLink({ ...authContext, ...query, ...params })
|
||||||
|
res({status: 'OK', ...response})
|
||||||
|
}catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger); if (opts.throwErrors) throw e }
|
||||||
|
break
|
||||||
|
default: logger.error('unknown rpc call name from nostr event:'+req.rpcName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -129,25 +129,61 @@ export type OptionsBaseMessage = {
|
||||||
allOptionalsAreSet?: true
|
allOptionalsAreSet?: true
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NewInvoiceRequest = {
|
export type NewAddressRequest = {
|
||||||
amountSats: number
|
addressType: AddressType
|
||||||
memo: string
|
|
||||||
}
|
}
|
||||||
export const NewInvoiceRequestOptionalFields: [] = []
|
export const NewAddressRequestOptionalFields: [] = []
|
||||||
export type NewInvoiceRequestOptions = OptionsBaseMessage & {
|
export type NewAddressRequestOptions = OptionsBaseMessage & {
|
||||||
checkOptionalsAreSet?: []
|
checkOptionalsAreSet?: []
|
||||||
amountSats_CustomCheck?: (v: number) => boolean
|
addressType_CustomCheck?: (v: AddressType) => boolean
|
||||||
memo_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
}
|
||||||
export const NewInvoiceRequestValidate = (o?: NewInvoiceRequest, opts: NewInvoiceRequestOptions = {}, path: string = 'NewInvoiceRequest::root.'): Error | null => {
|
export const NewAddressRequestValidate = (o?: NewAddressRequest, opts: NewAddressRequestOptions = {}, path: string = 'NewAddressRequest::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 (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 !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
|
||||||
|
|
||||||
if (typeof o.amountSats !== 'number') return new Error(`${path}.amountSats: is not a number`)
|
if (!enumCheckAddressType(o.addressType)) return new Error(`${path}.addressType: is not a valid AddressType`)
|
||||||
if (opts.amountSats_CustomCheck && !opts.amountSats_CustomCheck(o.amountSats)) return new Error(`${path}.amountSats: custom check failed`)
|
if (opts.addressType_CustomCheck && !opts.addressType_CustomCheck(o.addressType)) return new Error(`${path}.addressType: custom check failed`)
|
||||||
|
|
||||||
if (typeof o.memo !== 'string') return new Error(`${path}.memo: is not a string`)
|
return null
|
||||||
if (opts.memo_CustomCheck && !opts.memo_CustomCheck(o.memo)) return new Error(`${path}.memo: custom check failed`)
|
}
|
||||||
|
|
||||||
|
export type PayAddressResponse = {
|
||||||
|
txId: string
|
||||||
|
}
|
||||||
|
export const PayAddressResponseOptionalFields: [] = []
|
||||||
|
export type PayAddressResponseOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
txId_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const PayAddressResponseValidate = (o?: PayAddressResponse, opts: PayAddressResponseOptions = {}, path: string = 'PayAddressResponse::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.txId !== 'string') return new Error(`${path}.txId: is not a string`)
|
||||||
|
if (opts.txId_CustomCheck && !opts.txId_CustomCheck(o.txId)) return new Error(`${path}.txId: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PayInvoiceRequest = {
|
||||||
|
invoice: string
|
||||||
|
amount: number
|
||||||
|
}
|
||||||
|
export const PayInvoiceRequestOptionalFields: [] = []
|
||||||
|
export type PayInvoiceRequestOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
invoice_CustomCheck?: (v: string) => boolean
|
||||||
|
amount_CustomCheck?: (v: number) => boolean
|
||||||
|
}
|
||||||
|
export const PayInvoiceRequestValidate = (o?: PayInvoiceRequest, opts: PayInvoiceRequestOptions = {}, path: string = 'PayInvoiceRequest::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.invoice !== 'string') return new Error(`${path}.invoice: is not a string`)
|
||||||
|
if (opts.invoice_CustomCheck && !opts.invoice_CustomCheck(o.invoice)) return new Error(`${path}.invoice: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.amount !== 'number') return new Error(`${path}.amount: is not a number`)
|
||||||
|
if (opts.amount_CustomCheck && !opts.amount_CustomCheck(o.amount)) return new Error(`${path}.amount: custom check failed`)
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
@ -233,290 +269,6 @@ export const HandleLnurlPayResponseValidate = (o?: HandleLnurlPayResponse, opts:
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
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 NewAddressRequest = {
|
|
||||||
addressType: AddressType
|
|
||||||
}
|
|
||||||
export const NewAddressRequestOptionalFields: [] = []
|
|
||||||
export type NewAddressRequestOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
addressType_CustomCheck?: (v: AddressType) => boolean
|
|
||||||
}
|
|
||||||
export const NewAddressRequestValidate = (o?: NewAddressRequest, opts: NewAddressRequestOptions = {}, path: string = 'NewAddressRequest::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 (!enumCheckAddressType(o.addressType)) return new Error(`${path}.addressType: is not a valid AddressType`)
|
|
||||||
if (opts.addressType_CustomCheck && !opts.addressType_CustomCheck(o.addressType)) return new Error(`${path}.addressType: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type PayAddressResponse = {
|
|
||||||
txId: string
|
|
||||||
}
|
|
||||||
export const PayAddressResponseOptionalFields: [] = []
|
|
||||||
export type PayAddressResponseOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
txId_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const PayAddressResponseValidate = (o?: PayAddressResponse, opts: PayAddressResponseOptions = {}, path: string = 'PayAddressResponse::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.txId !== 'string') return new Error(`${path}.txId: is not a string`)
|
|
||||||
if (opts.txId_CustomCheck && !opts.txId_CustomCheck(o.txId)) return new Error(`${path}.txId: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type LnurlPayInfoResponse = {
|
|
||||||
tag: string
|
|
||||||
callback: string
|
|
||||||
maxSendable: number
|
|
||||||
minSendable: number
|
|
||||||
metadata: string
|
|
||||||
}
|
|
||||||
export const LnurlPayInfoResponseOptionalFields: [] = []
|
|
||||||
export type LnurlPayInfoResponseOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
tag_CustomCheck?: (v: string) => boolean
|
|
||||||
callback_CustomCheck?: (v: string) => boolean
|
|
||||||
maxSendable_CustomCheck?: (v: number) => boolean
|
|
||||||
minSendable_CustomCheck?: (v: number) => boolean
|
|
||||||
metadata_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const LnurlPayInfoResponseValidate = (o?: LnurlPayInfoResponse, opts: LnurlPayInfoResponseOptions = {}, path: string = 'LnurlPayInfoResponse::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.tag !== 'string') return new Error(`${path}.tag: is not a string`)
|
|
||||||
if (opts.tag_CustomCheck && !opts.tag_CustomCheck(o.tag)) return new Error(`${path}.tag: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.callback !== 'string') return new Error(`${path}.callback: is not a string`)
|
|
||||||
if (opts.callback_CustomCheck && !opts.callback_CustomCheck(o.callback)) return new Error(`${path}.callback: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.maxSendable !== 'number') return new Error(`${path}.maxSendable: is not a number`)
|
|
||||||
if (opts.maxSendable_CustomCheck && !opts.maxSendable_CustomCheck(o.maxSendable)) return new Error(`${path}.maxSendable: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.minSendable !== 'number') return new Error(`${path}.minSendable: is not a number`)
|
|
||||||
if (opts.minSendable_CustomCheck && !opts.minSendable_CustomCheck(o.minSendable)) return new Error(`${path}.minSendable: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.metadata !== 'string') return new Error(`${path}.metadata: is not a string`)
|
|
||||||
if (opts.metadata_CustomCheck && !opts.metadata_CustomCheck(o.metadata)) return new Error(`${path}.metadata: 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 NewAddressResponse = {
|
|
||||||
address: string
|
|
||||||
}
|
|
||||||
export const NewAddressResponseOptionalFields: [] = []
|
|
||||||
export type NewAddressResponseOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
address_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const NewAddressResponseValidate = (o?: NewAddressResponse, opts: NewAddressResponseOptions = {}, path: string = 'NewAddressResponse::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.address !== 'string') return new Error(`${path}.address: is not a string`)
|
|
||||||
if (opts.address_CustomCheck && !opts.address_CustomCheck(o.address)) return new Error(`${path}.address: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type OpenChannelRequest = {
|
|
||||||
destination: string
|
|
||||||
fundingAmount: number
|
|
||||||
pushAmount: number
|
|
||||||
closeAddress: string
|
|
||||||
}
|
|
||||||
export const OpenChannelRequestOptionalFields: [] = []
|
|
||||||
export type OpenChannelRequestOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
destination_CustomCheck?: (v: string) => boolean
|
|
||||||
fundingAmount_CustomCheck?: (v: number) => boolean
|
|
||||||
pushAmount_CustomCheck?: (v: number) => boolean
|
|
||||||
closeAddress_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const OpenChannelRequestValidate = (o?: OpenChannelRequest, opts: OpenChannelRequestOptions = {}, path: string = 'OpenChannelRequest::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.destination !== 'string') return new Error(`${path}.destination: is not a string`)
|
|
||||||
if (opts.destination_CustomCheck && !opts.destination_CustomCheck(o.destination)) return new Error(`${path}.destination: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.fundingAmount !== 'number') return new Error(`${path}.fundingAmount: is not a number`)
|
|
||||||
if (opts.fundingAmount_CustomCheck && !opts.fundingAmount_CustomCheck(o.fundingAmount)) return new Error(`${path}.fundingAmount: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.pushAmount !== 'number') return new Error(`${path}.pushAmount: is not a number`)
|
|
||||||
if (opts.pushAmount_CustomCheck && !opts.pushAmount_CustomCheck(o.pushAmount)) return new Error(`${path}.pushAmount: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.closeAddress !== 'string') return new Error(`${path}.closeAddress: is not a string`)
|
|
||||||
if (opts.closeAddress_CustomCheck && !opts.closeAddress_CustomCheck(o.closeAddress)) return new Error(`${path}.closeAddress: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AddUserRequest = {
|
|
||||||
callbackUrl: string
|
|
||||||
name: string
|
|
||||||
secret: string
|
|
||||||
}
|
|
||||||
export const AddUserRequestOptionalFields: [] = []
|
|
||||||
export type AddUserRequestOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
callbackUrl_CustomCheck?: (v: string) => boolean
|
|
||||||
name_CustomCheck?: (v: string) => boolean
|
|
||||||
secret_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const AddUserRequestValidate = (o?: AddUserRequest, opts: AddUserRequestOptions = {}, path: string = 'AddUserRequest::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.callbackUrl !== 'string') return new Error(`${path}.callbackUrl: is not a string`)
|
|
||||||
if (opts.callbackUrl_CustomCheck && !opts.callbackUrl_CustomCheck(o.callbackUrl)) return new Error(`${path}.callbackUrl: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.name !== 'string') return new Error(`${path}.name: is not a string`)
|
|
||||||
if (opts.name_CustomCheck && !opts.name_CustomCheck(o.name)) return new Error(`${path}.name: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.secret !== 'string') return new Error(`${path}.secret: is not a string`)
|
|
||||||
if (opts.secret_CustomCheck && !opts.secret_CustomCheck(o.secret)) return new Error(`${path}.secret: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type PayInvoiceRequest = {
|
|
||||||
invoice: string
|
|
||||||
amount: number
|
|
||||||
}
|
|
||||||
export const PayInvoiceRequestOptionalFields: [] = []
|
|
||||||
export type PayInvoiceRequestOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
invoice_CustomCheck?: (v: string) => boolean
|
|
||||||
amount_CustomCheck?: (v: number) => boolean
|
|
||||||
}
|
|
||||||
export const PayInvoiceRequestValidate = (o?: PayInvoiceRequest, opts: PayInvoiceRequestOptions = {}, path: string = 'PayInvoiceRequest::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.invoice !== 'string') return new Error(`${path}.invoice: is not a string`)
|
|
||||||
if (opts.invoice_CustomCheck && !opts.invoice_CustomCheck(o.invoice)) return new Error(`${path}.invoice: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.amount !== 'number') return new Error(`${path}.amount: is not a number`)
|
|
||||||
if (opts.amount_CustomCheck && !opts.amount_CustomCheck(o.amount)) return new Error(`${path}.amount: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type PayInvoiceResponse = {
|
|
||||||
preimage: string
|
|
||||||
}
|
|
||||||
export const PayInvoiceResponseOptionalFields: [] = []
|
|
||||||
export type PayInvoiceResponseOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
preimage_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const PayInvoiceResponseValidate = (o?: PayInvoiceResponse, opts: PayInvoiceResponseOptions = {}, path: string = 'PayInvoiceResponse::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.preimage !== 'string') return new Error(`${path}.preimage: is not a string`)
|
|
||||||
if (opts.preimage_CustomCheck && !opts.preimage_CustomCheck(o.preimage)) return new Error(`${path}.preimage: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type LnurlLinkResponse = {
|
|
||||||
lnurl: string
|
|
||||||
k1: string
|
|
||||||
}
|
|
||||||
export const LnurlLinkResponseOptionalFields: [] = []
|
|
||||||
export type LnurlLinkResponseOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
lnurl_CustomCheck?: (v: string) => boolean
|
|
||||||
k1_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const LnurlLinkResponseValidate = (o?: LnurlLinkResponse, opts: LnurlLinkResponseOptions = {}, path: string = 'LnurlLinkResponse::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.lnurl !== 'string') return new Error(`${path}.lnurl: is not a string`)
|
|
||||||
if (opts.lnurl_CustomCheck && !opts.lnurl_CustomCheck(o.lnurl)) return new Error(`${path}.lnurl: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.k1 !== 'string') return new Error(`${path}.k1: is not a string`)
|
|
||||||
if (opts.k1_CustomCheck && !opts.k1_CustomCheck(o.k1)) return new Error(`${path}.k1: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type NewInvoiceResponse = {
|
|
||||||
invoice: string
|
|
||||||
}
|
|
||||||
export const NewInvoiceResponseOptionalFields: [] = []
|
|
||||||
export type NewInvoiceResponseOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
invoice_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const NewInvoiceResponseValidate = (o?: NewInvoiceResponse, opts: NewInvoiceResponseOptions = {}, path: string = 'NewInvoiceResponse::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.invoice !== 'string') return new Error(`${path}.invoice: is not a string`)
|
|
||||||
if (opts.invoice_CustomCheck && !opts.invoice_CustomCheck(o.invoice)) return new Error(`${path}.invoice: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type OpenChannelResponse = {
|
|
||||||
channelId: string
|
|
||||||
}
|
|
||||||
export const OpenChannelResponseOptionalFields: [] = []
|
|
||||||
export type OpenChannelResponseOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
channelId_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const OpenChannelResponseValidate = (o?: OpenChannelResponse, opts: OpenChannelResponseOptions = {}, path: string = 'OpenChannelResponse::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.channelId !== 'string') return new Error(`${path}.channelId: is not a string`)
|
|
||||||
if (opts.channelId_CustomCheck && !opts.channelId_CustomCheck(o.channelId)) return new Error(`${path}.channelId: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AddUserResponse = {
|
export type AddUserResponse = {
|
||||||
userId: string
|
userId: string
|
||||||
authToken: string
|
authToken: string
|
||||||
|
|
@ -540,52 +292,6 @@ export const AddUserResponseValidate = (o?: AddUserResponse, opts: AddUserRespon
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AuthUserRequest = {
|
|
||||||
name: string
|
|
||||||
secret: string
|
|
||||||
}
|
|
||||||
export const AuthUserRequestOptionalFields: [] = []
|
|
||||||
export type AuthUserRequestOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
name_CustomCheck?: (v: string) => boolean
|
|
||||||
secret_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const AuthUserRequestValidate = (o?: AuthUserRequest, opts: AuthUserRequestOptions = {}, path: string = 'AuthUserRequest::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.name !== 'string') return new Error(`${path}.name: is not a string`)
|
|
||||||
if (opts.name_CustomCheck && !opts.name_CustomCheck(o.name)) return new Error(`${path}.name: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.secret !== 'string') return new Error(`${path}.secret: is not a string`)
|
|
||||||
if (opts.secret_CustomCheck && !opts.secret_CustomCheck(o.secret)) return new Error(`${path}.secret: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AuthUserResponse = {
|
|
||||||
userId: string
|
|
||||||
authToken: string
|
|
||||||
}
|
|
||||||
export const AuthUserResponseOptionalFields: [] = []
|
|
||||||
export type AuthUserResponseOptions = OptionsBaseMessage & {
|
|
||||||
checkOptionalsAreSet?: []
|
|
||||||
userId_CustomCheck?: (v: string) => boolean
|
|
||||||
authToken_CustomCheck?: (v: string) => boolean
|
|
||||||
}
|
|
||||||
export const AuthUserResponseValidate = (o?: AuthUserResponse, opts: AuthUserResponseOptions = {}, path: string = 'AuthUserResponse::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.userId !== 'string') return new Error(`${path}.userId: is not a string`)
|
|
||||||
if (opts.userId_CustomCheck && !opts.userId_CustomCheck(o.userId)) return new Error(`${path}.userId: custom check failed`)
|
|
||||||
|
|
||||||
if (typeof o.authToken !== 'string') return new Error(`${path}.authToken: is not a string`)
|
|
||||||
if (opts.authToken_CustomCheck && !opts.authToken_CustomCheck(o.authToken)) return new Error(`${path}.authToken: custom check failed`)
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EncryptionExchangeRequest = {
|
export type EncryptionExchangeRequest = {
|
||||||
publicKey: string
|
publicKey: string
|
||||||
deviceId: string
|
deviceId: string
|
||||||
|
|
@ -627,6 +333,80 @@ export const LndGetInfoRequestValidate = (o?: LndGetInfoRequest, opts: LndGetInf
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PayInvoiceResponse = {
|
||||||
|
preimage: string
|
||||||
|
}
|
||||||
|
export const PayInvoiceResponseOptionalFields: [] = []
|
||||||
|
export type PayInvoiceResponseOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
preimage_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const PayInvoiceResponseValidate = (o?: PayInvoiceResponse, opts: PayInvoiceResponseOptions = {}, path: string = 'PayInvoiceResponse::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.preimage !== 'string') return new Error(`${path}.preimage: is not a string`)
|
||||||
|
if (opts.preimage_CustomCheck && !opts.preimage_CustomCheck(o.preimage)) return new Error(`${path}.preimage: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OpenChannelRequest = {
|
||||||
|
destination: string
|
||||||
|
fundingAmount: number
|
||||||
|
pushAmount: number
|
||||||
|
closeAddress: string
|
||||||
|
}
|
||||||
|
export const OpenChannelRequestOptionalFields: [] = []
|
||||||
|
export type OpenChannelRequestOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
destination_CustomCheck?: (v: string) => boolean
|
||||||
|
fundingAmount_CustomCheck?: (v: number) => boolean
|
||||||
|
pushAmount_CustomCheck?: (v: number) => boolean
|
||||||
|
closeAddress_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const OpenChannelRequestValidate = (o?: OpenChannelRequest, opts: OpenChannelRequestOptions = {}, path: string = 'OpenChannelRequest::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.destination !== 'string') return new Error(`${path}.destination: is not a string`)
|
||||||
|
if (opts.destination_CustomCheck && !opts.destination_CustomCheck(o.destination)) return new Error(`${path}.destination: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.fundingAmount !== 'number') return new Error(`${path}.fundingAmount: is not a number`)
|
||||||
|
if (opts.fundingAmount_CustomCheck && !opts.fundingAmount_CustomCheck(o.fundingAmount)) return new Error(`${path}.fundingAmount: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.pushAmount !== 'number') return new Error(`${path}.pushAmount: is not a number`)
|
||||||
|
if (opts.pushAmount_CustomCheck && !opts.pushAmount_CustomCheck(o.pushAmount)) return new Error(`${path}.pushAmount: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.closeAddress !== 'string') return new Error(`${path}.closeAddress: is not a string`)
|
||||||
|
if (opts.closeAddress_CustomCheck && !opts.closeAddress_CustomCheck(o.closeAddress)) return new Error(`${path}.closeAddress: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AuthUserRequest = {
|
||||||
|
name: string
|
||||||
|
secret: string
|
||||||
|
}
|
||||||
|
export const AuthUserRequestOptionalFields: [] = []
|
||||||
|
export type AuthUserRequestOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
name_CustomCheck?: (v: string) => boolean
|
||||||
|
secret_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const AuthUserRequestValidate = (o?: AuthUserRequest, opts: AuthUserRequestOptions = {}, path: string = 'AuthUserRequest::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.name !== 'string') return new Error(`${path}.name: is not a string`)
|
||||||
|
if (opts.name_CustomCheck && !opts.name_CustomCheck(o.name)) return new Error(`${path}.name: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.secret !== 'string') return new Error(`${path}.secret: is not a string`)
|
||||||
|
if (opts.secret_CustomCheck && !opts.secret_CustomCheck(o.secret)) return new Error(`${path}.secret: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
export type PayAddressRequest = {
|
export type PayAddressRequest = {
|
||||||
address: string
|
address: string
|
||||||
amoutSats: number
|
amoutSats: number
|
||||||
|
|
@ -655,3 +435,223 @@ export const PayAddressRequestValidate = (o?: PayAddressRequest, opts: PayAddres
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type NewInvoiceRequest = {
|
||||||
|
amountSats: number
|
||||||
|
memo: string
|
||||||
|
}
|
||||||
|
export const NewInvoiceRequestOptionalFields: [] = []
|
||||||
|
export type NewInvoiceRequestOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
amountSats_CustomCheck?: (v: number) => boolean
|
||||||
|
memo_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const NewInvoiceRequestValidate = (o?: NewInvoiceRequest, opts: NewInvoiceRequestOptions = {}, path: string = 'NewInvoiceRequest::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.amountSats !== 'number') return new Error(`${path}.amountSats: is not a number`)
|
||||||
|
if (opts.amountSats_CustomCheck && !opts.amountSats_CustomCheck(o.amountSats)) return new Error(`${path}.amountSats: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.memo !== 'string') return new Error(`${path}.memo: is not a string`)
|
||||||
|
if (opts.memo_CustomCheck && !opts.memo_CustomCheck(o.memo)) return new Error(`${path}.memo: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NewInvoiceResponse = {
|
||||||
|
invoice: string
|
||||||
|
}
|
||||||
|
export const NewInvoiceResponseOptionalFields: [] = []
|
||||||
|
export type NewInvoiceResponseOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
invoice_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const NewInvoiceResponseValidate = (o?: NewInvoiceResponse, opts: NewInvoiceResponseOptions = {}, path: string = 'NewInvoiceResponse::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.invoice !== 'string') return new Error(`${path}.invoice: is not a string`)
|
||||||
|
if (opts.invoice_CustomCheck && !opts.invoice_CustomCheck(o.invoice)) return new Error(`${path}.invoice: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OpenChannelResponse = {
|
||||||
|
channelId: string
|
||||||
|
}
|
||||||
|
export const OpenChannelResponseOptionalFields: [] = []
|
||||||
|
export type OpenChannelResponseOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
channelId_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const OpenChannelResponseValidate = (o?: OpenChannelResponse, opts: OpenChannelResponseOptions = {}, path: string = 'OpenChannelResponse::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.channelId !== 'string') return new Error(`${path}.channelId: is not a string`)
|
||||||
|
if (opts.channelId_CustomCheck && !opts.channelId_CustomCheck(o.channelId)) return new Error(`${path}.channelId: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LnurlPayInfoResponse = {
|
||||||
|
tag: string
|
||||||
|
callback: string
|
||||||
|
maxSendable: number
|
||||||
|
minSendable: number
|
||||||
|
metadata: string
|
||||||
|
}
|
||||||
|
export const LnurlPayInfoResponseOptionalFields: [] = []
|
||||||
|
export type LnurlPayInfoResponseOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
tag_CustomCheck?: (v: string) => boolean
|
||||||
|
callback_CustomCheck?: (v: string) => boolean
|
||||||
|
maxSendable_CustomCheck?: (v: number) => boolean
|
||||||
|
minSendable_CustomCheck?: (v: number) => boolean
|
||||||
|
metadata_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const LnurlPayInfoResponseValidate = (o?: LnurlPayInfoResponse, opts: LnurlPayInfoResponseOptions = {}, path: string = 'LnurlPayInfoResponse::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.tag !== 'string') return new Error(`${path}.tag: is not a string`)
|
||||||
|
if (opts.tag_CustomCheck && !opts.tag_CustomCheck(o.tag)) return new Error(`${path}.tag: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.callback !== 'string') return new Error(`${path}.callback: is not a string`)
|
||||||
|
if (opts.callback_CustomCheck && !opts.callback_CustomCheck(o.callback)) return new Error(`${path}.callback: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.maxSendable !== 'number') return new Error(`${path}.maxSendable: is not a number`)
|
||||||
|
if (opts.maxSendable_CustomCheck && !opts.maxSendable_CustomCheck(o.maxSendable)) return new Error(`${path}.maxSendable: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.minSendable !== 'number') return new Error(`${path}.minSendable: is not a number`)
|
||||||
|
if (opts.minSendable_CustomCheck && !opts.minSendable_CustomCheck(o.minSendable)) return new Error(`${path}.minSendable: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.metadata !== 'string') return new Error(`${path}.metadata: is not a string`)
|
||||||
|
if (opts.metadata_CustomCheck && !opts.metadata_CustomCheck(o.metadata)) return new Error(`${path}.metadata: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AddUserRequest = {
|
||||||
|
callbackUrl: string
|
||||||
|
name: string
|
||||||
|
secret: string
|
||||||
|
}
|
||||||
|
export const AddUserRequestOptionalFields: [] = []
|
||||||
|
export type AddUserRequestOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
callbackUrl_CustomCheck?: (v: string) => boolean
|
||||||
|
name_CustomCheck?: (v: string) => boolean
|
||||||
|
secret_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const AddUserRequestValidate = (o?: AddUserRequest, opts: AddUserRequestOptions = {}, path: string = 'AddUserRequest::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.callbackUrl !== 'string') return new Error(`${path}.callbackUrl: is not a string`)
|
||||||
|
if (opts.callbackUrl_CustomCheck && !opts.callbackUrl_CustomCheck(o.callbackUrl)) return new Error(`${path}.callbackUrl: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.name !== 'string') return new Error(`${path}.name: is not a string`)
|
||||||
|
if (opts.name_CustomCheck && !opts.name_CustomCheck(o.name)) return new Error(`${path}.name: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.secret !== 'string') return new Error(`${path}.secret: is not a string`)
|
||||||
|
if (opts.secret_CustomCheck && !opts.secret_CustomCheck(o.secret)) return new Error(`${path}.secret: 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 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 NewAddressResponse = {
|
||||||
|
address: string
|
||||||
|
}
|
||||||
|
export const NewAddressResponseOptionalFields: [] = []
|
||||||
|
export type NewAddressResponseOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
address_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const NewAddressResponseValidate = (o?: NewAddressResponse, opts: NewAddressResponseOptions = {}, path: string = 'NewAddressResponse::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.address !== 'string') return new Error(`${path}.address: is not a string`)
|
||||||
|
if (opts.address_CustomCheck && !opts.address_CustomCheck(o.address)) return new Error(`${path}.address: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LnurlLinkResponse = {
|
||||||
|
lnurl: string
|
||||||
|
k1: string
|
||||||
|
}
|
||||||
|
export const LnurlLinkResponseOptionalFields: [] = []
|
||||||
|
export type LnurlLinkResponseOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
lnurl_CustomCheck?: (v: string) => boolean
|
||||||
|
k1_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const LnurlLinkResponseValidate = (o?: LnurlLinkResponse, opts: LnurlLinkResponseOptions = {}, path: string = 'LnurlLinkResponse::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.lnurl !== 'string') return new Error(`${path}.lnurl: is not a string`)
|
||||||
|
if (opts.lnurl_CustomCheck && !opts.lnurl_CustomCheck(o.lnurl)) return new Error(`${path}.lnurl: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.k1 !== 'string') return new Error(`${path}.k1: is not a string`)
|
||||||
|
if (opts.k1_CustomCheck && !opts.k1_CustomCheck(o.k1)) return new Error(`${path}.k1: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AuthUserResponse = {
|
||||||
|
userId: string
|
||||||
|
authToken: string
|
||||||
|
}
|
||||||
|
export const AuthUserResponseOptionalFields: [] = []
|
||||||
|
export type AuthUserResponseOptions = OptionsBaseMessage & {
|
||||||
|
checkOptionalsAreSet?: []
|
||||||
|
userId_CustomCheck?: (v: string) => boolean
|
||||||
|
authToken_CustomCheck?: (v: string) => boolean
|
||||||
|
}
|
||||||
|
export const AuthUserResponseValidate = (o?: AuthUserResponse, opts: AuthUserResponseOptions = {}, path: string = 'AuthUserResponse::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.userId !== 'string') return new Error(`${path}.userId: is not a string`)
|
||||||
|
if (opts.userId_CustomCheck && !opts.userId_CustomCheck(o.userId)) return new Error(`${path}.userId: custom check failed`)
|
||||||
|
|
||||||
|
if (typeof o.authToken !== 'string') return new Error(`${path}.authToken: is not a string`)
|
||||||
|
if (opts.authToken_CustomCheck && !opts.authToken_CustomCheck(o.authToken)) return new Error(`${path}.authToken: custom check failed`)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -43,6 +43,7 @@ extend google.protobuf.MethodOptions { // TODO: move this stuff to dep repo?
|
||||||
string http_method = 50004;
|
string http_method = 50004;
|
||||||
string http_route = 50005;
|
string http_route = 50005;
|
||||||
MethodQueryOptions query = 50006;
|
MethodQueryOptions query = 50006;
|
||||||
|
bool nostr = 50007;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,31 +94,37 @@ service LightningPub {
|
||||||
option (auth_type) = "User";
|
option (auth_type) = "User";
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
option (http_route) = "/api/user/chain/new";
|
option (http_route) = "/api/user/chain/new";
|
||||||
|
option (nostr) = true;
|
||||||
}
|
}
|
||||||
rpc PayAddress(structs.PayAddressRequest) returns (structs.PayAddressResponse){
|
rpc PayAddress(structs.PayAddressRequest) returns (structs.PayAddressResponse){
|
||||||
option (auth_type) = "User";
|
option (auth_type) = "User";
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
option (http_route) = "/api/user/chain/pay";
|
option (http_route) = "/api/user/chain/pay";
|
||||||
|
option (nostr) = true;
|
||||||
}
|
}
|
||||||
rpc NewInvoice(structs.NewInvoiceRequest) returns (structs.NewInvoiceResponse){
|
rpc NewInvoice(structs.NewInvoiceRequest) returns (structs.NewInvoiceResponse){
|
||||||
option (auth_type) = "User";
|
option (auth_type) = "User";
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
option (http_route) = "/api/user/invoice/new";
|
option (http_route) = "/api/user/invoice/new";
|
||||||
|
option (nostr) = true;
|
||||||
}
|
}
|
||||||
rpc PayInvoice(structs.PayInvoiceRequest) returns (structs.PayInvoiceResponse){
|
rpc PayInvoice(structs.PayInvoiceRequest) returns (structs.PayInvoiceResponse){
|
||||||
option (auth_type) = "User";
|
option (auth_type) = "User";
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
option (http_route) = "/api/user/invoice/pay";
|
option (http_route) = "/api/user/invoice/pay";
|
||||||
|
option (nostr) = true;
|
||||||
}
|
}
|
||||||
rpc OpenChannel(structs.OpenChannelRequest) returns (structs.OpenChannelResponse){
|
rpc OpenChannel(structs.OpenChannelRequest) returns (structs.OpenChannelResponse){
|
||||||
option (auth_type) = "User";
|
option (auth_type) = "User";
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
option (http_route) = "/api/user/open/channel";
|
option (http_route) = "/api/user/open/channel";
|
||||||
|
option (nostr) = true;
|
||||||
}
|
}
|
||||||
rpc GetLnurlWithdrawLink(structs.Empty) returns (structs.LnurlLinkResponse){
|
rpc GetLnurlWithdrawLink(structs.Empty) returns (structs.LnurlLinkResponse){
|
||||||
option (auth_type) = "User";
|
option (auth_type) = "User";
|
||||||
option (http_method) = "get";
|
option (http_method) = "get";
|
||||||
option (http_route) = "/api/user/lnurl_withdraw/link";
|
option (http_route) = "/api/user/lnurl_withdraw/link";
|
||||||
|
option (nostr) = true;
|
||||||
}
|
}
|
||||||
rpc GetLnurlWithdrawInfo(structs.Empty) returns (structs.LnurlWithdrawInfoResponse){
|
rpc GetLnurlWithdrawInfo(structs.Empty) returns (structs.LnurlWithdrawInfoResponse){
|
||||||
option (auth_type) = "Guest";
|
option (auth_type) = "Guest";
|
||||||
|
|
@ -147,5 +154,6 @@ service LightningPub {
|
||||||
option (auth_type) = "User";
|
option (auth_type) = "User";
|
||||||
option (http_method) = "post";
|
option (http_method) = "post";
|
||||||
option (http_route) = "/api/user/lnurl_channel/url";
|
option (http_route) = "/api/user/lnurl_channel/url";
|
||||||
|
option (nostr) = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dotenv/config' // TODO - test env
|
import 'dotenv/config' // TODO - test env
|
||||||
|
import crypto from 'crypto';
|
||||||
import { generatePrivateKey, getPublicKey } from 'nostr-tools';
|
import { generatePrivateKey, getPublicKey } from 'nostr-tools';
|
||||||
import NewServer from '../proto/autogenerated/ts/express_server.js'
|
import NewServer from '../proto/autogenerated/ts/express_server.js'
|
||||||
import NewClient from '../proto/autogenerated/ts/http_client.js'
|
import NewClient from '../proto/autogenerated/ts/http_client.js'
|
||||||
|
|
@ -10,6 +11,8 @@ import nostrMiddleware from './nostrMiddleware.js'
|
||||||
import { LoadNosrtSettingsFromEnv } from './services/nostr/index.js';
|
import { LoadNosrtSettingsFromEnv } from './services/nostr/index.js';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import NostrHandler from './services/nostr/index.js'
|
import NostrHandler from './services/nostr/index.js'
|
||||||
|
import NewNostrClient from '../proto/autogenerated/ts/nostr_client.js'
|
||||||
|
import { NostrRequest } from '../proto/autogenerated/ts/nostr_transport.js';
|
||||||
|
|
||||||
|
|
||||||
const settings = LoadNosrtSettingsFromEnv(true)
|
const settings = LoadNosrtSettingsFromEnv(true)
|
||||||
|
|
@ -31,14 +34,48 @@ const client = NewClient({
|
||||||
encryptCallback: async (b) => b,
|
encryptCallback: async (b) => b,
|
||||||
deviceId: "device0"
|
deviceId: "device0"
|
||||||
})
|
})
|
||||||
const clientNostr = new NostrHandler({
|
const clientCbs: Record<string, (res: any) => void> = {}
|
||||||
|
const clientNostrHandler = new NostrHandler({
|
||||||
|
allowedPubs: [],
|
||||||
|
privateKey: clientPrivateKey,
|
||||||
|
publicKey: clientPublicKey,
|
||||||
|
relays: settings.relays
|
||||||
|
}, (e) => {
|
||||||
|
const res = JSON.parse(e.content) as { requestId: string }
|
||||||
|
if (clientCbs[res.requestId]) {
|
||||||
|
const cb = clientCbs[res.requestId]
|
||||||
|
cb(res)
|
||||||
|
delete clientCbs[res.requestId]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const clientSend = (to: string, message: NostrRequest): Promise<any> => {
|
||||||
|
console.log("sending", message)
|
||||||
|
if (!message.requestId) {
|
||||||
|
message.requestId = crypto.randomBytes(20).toString('hex')
|
||||||
|
}
|
||||||
|
const reqId = message.requestId
|
||||||
|
if (clientCbs[reqId]) {
|
||||||
|
throw new Error("request was already sent")
|
||||||
|
}
|
||||||
|
clientNostrHandler.Send(to, JSON.stringify(message))
|
||||||
|
return new Promise(res => {
|
||||||
|
clientCbs[reqId] = (response: any) => {
|
||||||
|
res(response)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const clientNostr = NewNostrClient({
|
||||||
|
pubDestination: serverPublicKey,
|
||||||
|
retrieveNostrUserAuth: async () => { return clientPublicKey }
|
||||||
|
}, clientSend)
|
||||||
|
/* new NostrHandler({
|
||||||
allowedPubs: [],
|
allowedPubs: [],
|
||||||
privateKey: clientPrivateKey,
|
privateKey: clientPrivateKey,
|
||||||
publicKey: clientPublicKey,
|
publicKey: clientPublicKey,
|
||||||
relays: settings.relays
|
relays: settings.relays
|
||||||
}, (event) => {
|
}, (event) => {
|
||||||
console.log(event.content)
|
console.log(event.content)
|
||||||
})
|
})*/
|
||||||
const mainSettings = LoadMainSettingsFromEnv(true)
|
const mainSettings = LoadMainSettingsFromEnv(true)
|
||||||
const mainHandler = new Main(mainSettings) // TODO - test env file
|
const mainHandler = new Main(mainSettings) // TODO - test env file
|
||||||
const serverMethods = GetServerMethods(mainHandler)
|
const serverMethods = GetServerMethods(mainHandler)
|
||||||
|
|
@ -57,7 +94,7 @@ export const setup = async () => {
|
||||||
server.Listen(testPort)
|
server.Listen(testPort)
|
||||||
}
|
}
|
||||||
export const teardown = async () => {
|
export const teardown = async () => {
|
||||||
clientNostr.Stop()
|
clientNostrHandler.Stop()
|
||||||
serverNostr.Stop()
|
serverNostr.Stop()
|
||||||
mainHandler.lnd.Stop()
|
mainHandler.lnd.Stop()
|
||||||
server.Close()
|
server.Close()
|
||||||
|
|
@ -82,8 +119,10 @@ export default async (d: (message: string, failure?: boolean) => void) => {
|
||||||
console.log(await client.NewAddress({ addressType: Types.AddressType.WITNESS_PUBKEY_HASH }))
|
console.log(await client.NewAddress({ addressType: Types.AddressType.WITNESS_PUBKEY_HASH }))
|
||||||
d("new address ok")
|
d("new address ok")
|
||||||
await new Promise(res => setTimeout(res, 2000))
|
await new Promise(res => setTimeout(res, 2000))
|
||||||
clientNostr.Send(serverPublicKey, JSON.stringify({ requestId: "a", method: '/api/user/chain/new', body: { address_type: 'WITNESS_PUBKEY_HASH' } }))
|
//clientNostr.Send(serverPublicKey, JSON.stringify({ requestId: "a", method: '/api/user/chain/new', body: { address_type: 'WITNESS_PUBKEY_HASH' } }))
|
||||||
|
const nostrRes = await clientNostr.NewAddress({ addressType: Types.AddressType.WITNESS_PUBKEY_HASH })
|
||||||
|
console.log(nostrRes)
|
||||||
|
d("nostr ok")
|
||||||
const lnurlWithdrawLink = await client.GetLnurlWithdrawLink()
|
const lnurlWithdrawLink = await client.GetLnurlWithdrawLink()
|
||||||
if (lnurlWithdrawLink.status === 'ERROR') throw new Error(lnurlWithdrawLink.reason)
|
if (lnurlWithdrawLink.status === 'ERROR') throw new Error(lnurlWithdrawLink.reason)
|
||||||
const lnurlWithdrawInfo = await client.GetLnurlWithdrawInfo({ k1: lnurlWithdrawLink.k1 })
|
const lnurlWithdrawInfo = await client.GetLnurlWithdrawInfo({ k1: lnurlWithdrawLink.k1 })
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,38 @@ import Main from "./services/main/index.js"
|
||||||
import Nostr from "./services/nostr/index.js"
|
import Nostr from "./services/nostr/index.js"
|
||||||
import { NostrSettings } from "./services/nostr/handler.js"
|
import { NostrSettings } from "./services/nostr/handler.js"
|
||||||
import * as Types from '../proto/autogenerated/ts/types.js'
|
import * as Types from '../proto/autogenerated/ts/types.js'
|
||||||
|
import NewNostrTransport, { NostrRequest } from '../proto/autogenerated/ts/nostr_transport.js';
|
||||||
const handledRequests: string[] = [] // TODO: - big memory leak here, add TTL
|
const handledRequests: string[] = [] // TODO: - big memory leak here, add TTL
|
||||||
type EventRequest = {
|
|
||||||
requestId: string
|
export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSettings: NostrSettings) => {
|
||||||
method: string
|
const nostrTransport = NewNostrTransport(serverMethods, {
|
||||||
params: Record<string, string>
|
NostrUserAuthGuard: async pub => {
|
||||||
body: any
|
if (!pub || !nostrSettings.allowedPubs.includes(pub)) {
|
||||||
query: Record<string, string>
|
throw new Error("nostr pub invalid or not allowed")
|
||||||
|
}
|
||||||
|
let nostrUser = await mainHandler.storage.FindNostrUser(pub)
|
||||||
|
if (!nostrUser) { // TODO: add POW
|
||||||
|
nostrUser = await mainHandler.storage.AddNostrUser(pub)
|
||||||
|
}
|
||||||
|
return { user_id: nostrUser.user.user_id }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const nostr = new Nostr(nostrSettings, event => {
|
||||||
|
let j: NostrRequest
|
||||||
|
try {
|
||||||
|
j = JSON.parse(event.content)
|
||||||
|
} catch {
|
||||||
|
console.error("invalid json event received", event.content)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nostrTransport(j, res => {
|
||||||
|
nostr.Send(event.pub, JSON.stringify({ ...res, requestId: j.requestId }))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return { Stop: nostr.Stop }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSettings: NostrSettings): Nostr => {
|
export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSettings: NostrSettings): Nostr => {
|
||||||
// TODO: - move to codegen
|
// TODO: - move to codegen
|
||||||
const nostr = new Nostr(nostrSettings,
|
const nostr = new Nostr(nostrSettings,
|
||||||
|
|
@ -22,7 +44,6 @@ export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSett
|
||||||
}
|
}
|
||||||
let nostrUser = await mainHandler.storage.FindNostrUser(event.pub)
|
let nostrUser = await mainHandler.storage.FindNostrUser(event.pub)
|
||||||
if (!nostrUser) {
|
if (!nostrUser) {
|
||||||
|
|
||||||
nostrUser = await mainHandler.storage.AddNostrUser(event.pub)
|
nostrUser = await mainHandler.storage.AddNostrUser(event.pub)
|
||||||
}
|
}
|
||||||
let j: EventRequest
|
let j: EventRequest
|
||||||
|
|
@ -52,4 +73,4 @@ export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSett
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return nostr
|
return nostr
|
||||||
}
|
}*/
|
||||||
|
|
@ -21,7 +21,7 @@ export default async (d: (message: string, failure?: boolean) => void) => {
|
||||||
console.log(addr)
|
console.log(addr)
|
||||||
d("new address ok")
|
d("new address ok")
|
||||||
|
|
||||||
const invoice = await lnd.NewInvoice(1000)
|
const invoice = await lnd.NewInvoice(1000, "")
|
||||||
console.log(invoice)
|
console.log(invoice)
|
||||||
d("new invoice ok")
|
d("new invoice ok")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ process.on("message", (message: ChildProcessRequest) => {
|
||||||
break
|
break
|
||||||
case 'send':
|
case 'send':
|
||||||
sendToNostr(message.pub, message.message)
|
sendToNostr(message.pub, message.message)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
console.error("unknown nostr request", message)
|
console.error("unknown nostr request", message)
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -52,15 +52,30 @@ export default (mainHandler: Main): Types.ServerMethods => {
|
||||||
},
|
},
|
||||||
GetLnurlWithdrawInfo: async (ctx) => {
|
GetLnurlWithdrawInfo: async (ctx) => {
|
||||||
if (!ctx.k1) {
|
if (!ctx.k1) {
|
||||||
throw new Error("invalid lnurl to get info")
|
throw new Error("invalid lnurl withdraw to get info")
|
||||||
}
|
}
|
||||||
return mainHandler.GetLnurlWithdrawInfo(ctx.k1)
|
return mainHandler.GetLnurlWithdrawInfo(ctx.k1)
|
||||||
},
|
},
|
||||||
HandleLnurlWithdraw: async (ctx) => {
|
HandleLnurlWithdraw: async (ctx) => {
|
||||||
if (!ctx.k1 || !ctx.pr) {
|
if (!ctx.k1 || !ctx.pr) {
|
||||||
throw new Error("invalid lnurl to handle")
|
throw new Error("invalid lnurl withdraw to handle")
|
||||||
}
|
}
|
||||||
await mainHandler.HandleLnurlWithdraw(ctx.k1, ctx.pr)
|
return mainHandler.HandleLnurlWithdraw(ctx.k1, ctx.pr)
|
||||||
|
},
|
||||||
|
GetLnurlPayInfo: async (ctx) => {
|
||||||
|
if (!ctx.k1) {
|
||||||
|
throw new Error("invalid lnurl pay to get info")
|
||||||
|
}
|
||||||
|
return mainHandler.GetLnurlPayInfo(ctx.k1)
|
||||||
|
},
|
||||||
|
HandleLnurlPay: async (ctx) => {
|
||||||
|
if (!ctx.k1 || !ctx.amount) {
|
||||||
|
throw new Error("invalid lnurl pay to handle")
|
||||||
|
}
|
||||||
|
if (isNaN(+ctx.amount)) {
|
||||||
|
throw new Error("invalid amount in lnurl pay to handle")
|
||||||
|
}
|
||||||
|
return mainHandler.HandleLnurlPay(ctx.k1, +ctx.amount)
|
||||||
},
|
},
|
||||||
GetLNURLChannelLink: async (ctx) => {
|
GetLNURLChannelLink: async (ctx) => {
|
||||||
throw new Error("unimplemented")
|
throw new Error("unimplemented")
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ type TestModule = {
|
||||||
default: (describe: Describe) => Promise<void>
|
default: (describe: Describe) => Promise<void>
|
||||||
teardown?: () => Promise<void>
|
teardown?: () => Promise<void>
|
||||||
}
|
}
|
||||||
|
let failures = 0
|
||||||
const start = async () => {
|
const start = async () => {
|
||||||
|
|
||||||
const files = await globby("**/*.spec.js")
|
const files = await globby("**/*.spec.js")
|
||||||
|
|
@ -15,6 +16,11 @@ const start = async () => {
|
||||||
const module = await import(`./${file.slice("build/src/".length)}`) as TestModule
|
const module = await import(`./${file.slice("build/src/".length)}`) as TestModule
|
||||||
await runTestFile(file, module)
|
await runTestFile(file, module)
|
||||||
}
|
}
|
||||||
|
if (failures) {
|
||||||
|
console.error(redConsole, "there have been", `${failures}`, "failures in all tests", resetConsole)
|
||||||
|
} else {
|
||||||
|
console.log(greenConsole, "there have been 0 failures in all tests", resetConsole)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,6 +52,7 @@ const runTestFile = async (fileName: string, mod: TestModule) => {
|
||||||
const getDescribe = (fileName: string): Describe => {
|
const getDescribe = (fileName: string): Describe => {
|
||||||
return (message, failure) => {
|
return (message, failure) => {
|
||||||
if (failure) {
|
if (failure) {
|
||||||
|
failures++
|
||||||
console.error(redConsole, fileName, ":", message, resetConsole)
|
console.error(redConsole, fileName, ":", message, resetConsole)
|
||||||
} else {
|
} else {
|
||||||
console.log(greenConsole, fileName, ":", message, resetConsole)
|
console.log(greenConsole, fileName, ":", message, resetConsole)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue