From 2ec08535683dc97721ee4cb71b7fbd783b93ebe5 Mon Sep 17 00:00:00 2001 From: boufni95 Date: Fri, 8 Nov 2024 19:51:48 +0000 Subject: [PATCH 1/2] open/close chans --- src/Api/pub/autogenerated/ts/http_client.ts | 339 +++++----- src/Api/pub/autogenerated/ts/nostr_client.ts | 331 ++++----- .../pub/autogenerated/ts/nostr_transport.ts | 376 ++++++----- src/Api/pub/autogenerated/ts/types.ts | 629 ++++++++++++------ src/Pages/Channels/index.tsx | 50 +- 5 files changed, 1031 insertions(+), 694 deletions(-) diff --git a/src/Api/pub/autogenerated/ts/http_client.ts b/src/Api/pub/autogenerated/ts/http_client.ts index 56f06543..a6bc5ab0 100644 --- a/src/Api/pub/autogenerated/ts/http_client.ts +++ b/src/Api/pub/autogenerated/ts/http_client.ts @@ -17,99 +17,110 @@ export type ClientParams = { checkResult?: true } export default (params: ClientParams) => ({ - AddApp: async (request: Types.AddAppRequest): Promise => { + AddApp: async (request: Types.AddAppRequest): Promise => { const auth = await params.retrieveAdminAuth() if (auth === null) throw new Error('retrieveAdminAuth() returned null') let finalRoute = '/api/admin/app/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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.AuthAppValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - AddAppInvoice: async (request: Types.AddAppInvoiceRequest): Promise => { + AddAppInvoice: async (request: Types.AddAppInvoiceRequest): Promise => { const auth = await params.retrieveAppAuth() if (auth === null) throw new Error('retrieveAppAuth() returned null') let finalRoute = '/api/app/add/invoice' 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 - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - AddAppUser: async (request: Types.AddAppUserRequest): Promise => { + AddAppUser: async (request: Types.AddAppUserRequest): Promise => { const auth = await params.retrieveAppAuth() if (auth === null) throw new Error('retrieveAppAuth() returned null') let finalRoute = '/api/app/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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.AppUserValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - AddAppUserInvoice: async (request: Types.AddAppUserInvoiceRequest): Promise => { + AddAppUserInvoice: async (request: Types.AddAppUserInvoiceRequest): Promise => { const auth = await params.retrieveAppAuth() if (auth === null) throw new Error('retrieveAppAuth() returned null') let finalRoute = '/api/app/user/add/invoice' 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 - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - AddProduct: async (request: Types.AddProductRequest): Promise => { + AddPeer: async (request: Types.AddPeerRequest): Promise => { + const auth = await params.retrieveAdminAuth() + if (auth === null) throw new Error('retrieveAdminAuth() returned null') + let finalRoute = '/api/admin/peer' + 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') { + return data + } + return { status: 'ERROR', reason: 'invalid response' } + }, + AddProduct: async (request: Types.AddProductRequest): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/product/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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.ProductValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - AuthApp: async (request: Types.AuthAppRequest): Promise => { + AuthApp: async (request: Types.AuthAppRequest): Promise => { const auth = await params.retrieveAdminAuth() if (auth === null) throw new Error('retrieveAdminAuth() returned null') let finalRoute = '/api/admin/app/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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.AuthAppValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - AuthorizeDebit: async (request: Types.DebitAuthorizationRequest): Promise => { + AuthorizeDebit: async (request: Types.DebitAuthorizationRequest): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/debit/authorize' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.DebitAuthorizationValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } @@ -121,59 +132,73 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/user/debit/ban' 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' } }, - BanUser: async (request: Types.BanUserRequest): Promise => { + BanUser: async (request: Types.BanUserRequest): Promise => { const auth = await params.retrieveAdminAuth() if (auth === null) throw new Error('retrieveAdminAuth() returned null') let finalRoute = '/api/admin/user/ban' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.BanUserResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - BatchUser: async (requests:Types.UserMethodInputs[]): Promise => { + BatchUser: async (requests: Types.UserMethodInputs[]): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/batch' - const { data } = await axios.post(params.baseUrl + finalRoute, {requests}, { headers: { 'authorization': auth } }) + const { data } = await axios.post(params.baseUrl + finalRoute, { requests }, { headers: { 'authorization': auth } }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { return { status: 'OK', ...data } - } + } return { status: 'ERROR', reason: 'invalid response' } }, - CreateOneTimeInviteLink: async (request: Types.CreateOneTimeInviteLinkRequest): Promise => { + CloseChannel: async (request: Types.CloseChannelRequest): Promise => { + const auth = await params.retrieveAdminAuth() + if (auth === null) throw new Error('retrieveAdminAuth() returned null') + let finalRoute = '/api/admin/channel/close' + 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') { + const result = data + if (!params.checkResult) return { status: 'OK', ...result } + const error = Types.CloseChannelResponseValidate(result) + if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } + } + return { status: 'ERROR', reason: 'invalid response' } + }, + CreateOneTimeInviteLink: async (request: Types.CreateOneTimeInviteLinkRequest): Promise => { const auth = await params.retrieveAdminAuth() if (auth === null) throw new Error('retrieveAdminAuth() returned null') let finalRoute = '/api/admin/app/invite/create' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.CreateOneTimeInviteLinkResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - DecodeInvoice: async (request: Types.DecodeInvoiceRequest): Promise => { + DecodeInvoice: async (request: Types.DecodeInvoiceRequest): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/invoice/decode' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.DecodeInvoiceResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } @@ -185,7 +210,7 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/user/debit/edit' 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' } @@ -196,7 +221,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' } @@ -207,127 +232,127 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/guest/npub/enroll/admin' 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' } }, - GetApp: async (): Promise => { + GetApp: async (): Promise => { const auth = await params.retrieveAppAuth() if (auth === null) throw new Error('retrieveAppAuth() returned null') let finalRoute = '/api/app/get' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.ApplicationValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetAppUser: async (request: Types.GetAppUserRequest): Promise => { + GetAppUser: async (request: Types.GetAppUserRequest): Promise => { const auth = await params.retrieveAppAuth() if (auth === null) throw new Error('retrieveAppAuth() returned null') let finalRoute = '/api/app/user/get' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.AppUserValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetAppUserLNURLInfo: async (request: Types.GetAppUserLNURLInfoRequest): Promise => { + GetAppUserLNURLInfo: async (request: Types.GetAppUserLNURLInfoRequest): Promise => { const auth = await params.retrieveAppAuth() if (auth === null) throw new Error('retrieveAppAuth() returned null') let finalRoute = '/api/app/user/lnurl/pay/info' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LnurlPayInfoResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetAppsMetrics: async (request: Types.AppsMetricsRequest): Promise => { + GetAppsMetrics: async (request: Types.AppsMetricsRequest): Promise => { const auth = await params.retrieveMetricsAuth() if (auth === null) throw new Error('retrieveMetricsAuth() returned null') let finalRoute = '/api/reports/apps' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.AppsMetricsValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetDebitAuthorizations: async (): Promise => { + GetDebitAuthorizations: async (): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/debit/get' 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') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.DebitAuthorizationsValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetHttpCreds: async (cb: (v:ResultError | ({ status: 'OK' }& Types.HttpCreds)) => void): Promise => { throw new Error('http streams are not supported')}, - GetInviteLinkState: async (request: Types.GetInviteTokenStateRequest): Promise => { + GetHttpCreds: async (cb: (v: ResultError | ({ status: 'OK' } & Types.HttpCreds)) => void): Promise => { throw new Error('http streams are not supported') }, + GetInviteLinkState: async (request: Types.GetInviteTokenStateRequest): Promise => { const auth = await params.retrieveAdminAuth() if (auth === null) throw new Error('retrieveAdminAuth() returned null') let finalRoute = '/api/admin/app/invite/get' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.GetInviteTokenStateResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetLNURLChannelLink: async (): Promise => { + GetLNURLChannelLink: async (): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/lnurl_channel/url' 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 - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - GetLiveDebitRequests: async (cb: (v:ResultError | ({ status: 'OK' }& Types.LiveDebitRequest)) => void): Promise => { throw new Error('http streams are not supported')}, - GetLiveUserOperations: async (cb: (v:ResultError | ({ status: 'OK' }& Types.LiveUserOperation)) => void): Promise => { throw new Error('http streams are not supported')}, - GetLndMetrics: async (request: Types.LndMetricsRequest): Promise => { + GetLiveDebitRequests: async (cb: (v: ResultError | ({ status: 'OK' } & Types.LiveDebitRequest)) => void): Promise => { throw new Error('http streams are not supported') }, + GetLiveUserOperations: async (cb: (v: ResultError | ({ status: 'OK' } & Types.LiveUserOperation)) => void): Promise => { throw new Error('http streams are not supported') }, + GetLndMetrics: async (request: Types.LndMetricsRequest): Promise => { const auth = await params.retrieveMetricsAuth() if (auth === null) throw new Error('retrieveMetricsAuth() returned null') let finalRoute = '/api/reports/lnd' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LndMetricsValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetLnurlPayInfo: async (query: Types.GetLnurlPayInfo_Query): Promise => { + GetLnurlPayInfo: async (query: Types.GetLnurlPayInfo_Query): Promise => { const auth = await params.retrieveGuestAuth() if (auth === null) throw new Error('retrieveGuestAuth() returned null') let finalRoute = '/api/guest/lnurl_pay/info' @@ -335,29 +360,29 @@ export default (params: ClientParams) => ({ finalRoute = finalRoute + (q === '' ? '' : '?' + q) 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') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LnurlPayInfoResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetLnurlPayLink: async (): Promise => { + GetLnurlPayLink: async (): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/lnurl_pay/link' 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') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - GetLnurlWithdrawInfo: async (query: Types.GetLnurlWithdrawInfo_Query): Promise => { + GetLnurlWithdrawInfo: async (query: Types.GetLnurlWithdrawInfo_Query): Promise => { const auth = await params.retrieveGuestAuth() if (auth === null) throw new Error('retrieveGuestAuth() returned null') let finalRoute = '/api/guest/lnurl_withdraw/info' @@ -365,115 +390,129 @@ export default (params: ClientParams) => ({ finalRoute = finalRoute + (q === '' ? '' : '?' + q) 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') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LnurlWithdrawInfoResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetLnurlWithdrawLink: async (): Promise => { + GetLnurlWithdrawLink: async (): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/lnurl_withdraw/link' 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') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - GetMigrationUpdate: async (cb: (v:ResultError | ({ status: 'OK' }& Types.MigrationUpdate)) => void): Promise => { throw new Error('http streams are not supported')}, - GetPaymentState: async (request: Types.GetPaymentStateRequest): Promise => { + GetMigrationUpdate: async (cb: (v: ResultError | ({ status: 'OK' } & Types.MigrationUpdate)) => void): Promise => { throw new Error('http streams are not supported') }, + GetNPubLinkingState: async (request: Types.GetNPubLinking): Promise => { + const auth = await params.retrieveAppAuth() + if (auth === null) throw new Error('retrieveAppAuth() returned null') + let finalRoute = '/api/app/user/npub/state' + 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') { + const result = data + if (!params.checkResult) return { status: 'OK', ...result } + const error = Types.NPubLinkingValidate(result) + if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } + } + return { status: 'ERROR', reason: 'invalid response' } + }, + GetPaymentState: async (request: Types.GetPaymentStateRequest): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/payment/state' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.PaymentStateValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetSeed: async (): Promise => { + GetSeed: async (): Promise => { const auth = await params.retrieveAdminAuth() if (auth === null) throw new Error('retrieveAdminAuth() returned null') let finalRoute = '/api/admin/seed' 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') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LndSeedValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetUsageMetrics: async (): Promise => { + GetUsageMetrics: async (): Promise => { const auth = await params.retrieveMetricsAuth() if (auth === null) throw new Error('retrieveMetricsAuth() returned null') let finalRoute = '/api/reports/usage' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.UsageMetricsValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetUserInfo: async (): Promise => { + GetUserInfo: async (): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/info' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.UserInfoValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetUserOperations: async (request: Types.GetUserOperationsRequest): Promise => { + GetUserOperations: async (request: Types.GetUserOperationsRequest): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/operations' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.GetUserOperationsResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - HandleLnurlAddress: async (routeParams: Types.HandleLnurlAddress_RouteParams): Promise => { + HandleLnurlAddress: async (routeParams: Types.HandleLnurlAddress_RouteParams): Promise => { const auth = await params.retrieveGuestAuth() if (auth === null) throw new Error('retrieveGuestAuth() returned null') let finalRoute = '/.well-known/lnurlp/:address_name' finalRoute = finalRoute.replace(':address_name', routeParams['address_name']) 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') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LnurlPayInfoResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - HandleLnurlPay: async (query: Types.HandleLnurlPay_Query): Promise => { + HandleLnurlPay: async (query: Types.HandleLnurlPay_Query): Promise => { const auth = await params.retrieveGuestAuth() if (auth === null) throw new Error('retrieveGuestAuth() returned null') let finalRoute = '/api/guest/lnurl_pay/handle' @@ -481,9 +520,9 @@ export default (params: ClientParams) => ({ finalRoute = finalRoute + (q === '' ? '' : '?' + q) 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') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.HandleLnurlPayResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } @@ -497,7 +536,7 @@ export default (params: ClientParams) => ({ finalRoute = finalRoute + (q === '' ? '' : '?' + q) 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' } @@ -508,7 +547,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' } @@ -519,68 +558,68 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/guest/npub/link' 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' } }, - ListChannels: async (): Promise => { + ListChannels: async (): Promise => { const auth = await params.retrieveAdminAuth() if (auth === null) throw new Error('retrieveAdminAuth() returned null') let finalRoute = '/api/admin/channels' 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') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LndChannelsValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - LndGetInfo: async (request: Types.LndGetInfoRequest): Promise => { + LndGetInfo: async (request: Types.LndGetInfoRequest): Promise => { const auth = await params.retrieveAdminAuth() if (auth === null) throw new Error('retrieveAdminAuth() returned null') let finalRoute = '/api/admin/lnd/getinfo' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LndGetInfoResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - NewAddress: async (request: Types.NewAddressRequest): Promise => { + NewAddress: async (request: Types.NewAddressRequest): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') 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 - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - NewInvoice: async (request: Types.NewInvoiceRequest): Promise => { + NewInvoice: async (request: Types.NewInvoiceRequest): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') 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 - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - NewProductInvoice: async (query: Types.NewProductInvoice_Query): Promise => { + NewProductInvoice: async (query: Types.NewProductInvoice_Query): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/product/get/invoice' @@ -588,79 +627,79 @@ export default (params: ClientParams) => ({ finalRoute = finalRoute + (q === '' ? '' : '?' + q) 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') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - OpenChannel: async (request: Types.OpenChannelRequest): Promise => { - const auth = await params.retrieveUserAuth() - if (auth === null) throw new Error('retrieveUserAuth() returned null') - let finalRoute = '/api/user/open/channel' + OpenChannel: async (request: Types.OpenChannelRequest): Promise => { + const auth = await params.retrieveAdminAuth() + if (auth === null) throw new Error('retrieveAdminAuth() returned null') + let finalRoute = '/api/admin/channel/open' 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 - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - PayAddress: async (request: Types.PayAddressRequest): Promise => { + PayAddress: async (request: Types.PayAddressRequest): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') 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 - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - PayAppUserInvoice: async (request: Types.PayAppUserInvoiceRequest): Promise => { + PayAppUserInvoice: async (request: Types.PayAppUserInvoiceRequest): Promise => { const auth = await params.retrieveAppAuth() if (auth === null) throw new Error('retrieveAppAuth() returned null') let finalRoute = '/api/app/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 - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - PayInvoice: async (request: Types.PayInvoiceRequest): Promise => { + PayInvoice: async (request: Types.PayInvoiceRequest): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') 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 - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - RequestNPubLinkingToken: async (request: Types.RequestNPubLinkingTokenRequest): Promise => { + RequestNPubLinkingToken: async (request: Types.RequestNPubLinkingTokenRequest): Promise => { const auth = await params.retrieveAppAuth() if (auth === null) throw new Error('retrieveAppAuth() returned null') let finalRoute = '/api/app/user/npub/token' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.RequestNPubLinkingTokenResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } @@ -672,20 +711,20 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/user/debit/reset' 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' } }, - ResetNPubLinkingToken: async (request: Types.RequestNPubLinkingTokenRequest): Promise => { + ResetNPubLinkingToken: async (request: Types.RequestNPubLinkingTokenRequest): Promise => { const auth = await params.retrieveAppAuth() if (auth === null) throw new Error('retrieveAppAuth() returned null') let finalRoute = '/api/app/user/npub/token/reset' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.RequestNPubLinkingTokenResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } @@ -697,7 +736,7 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/user/debit/finish' 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' } @@ -708,7 +747,7 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/app/internal/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') { return data } return { status: 'ERROR', reason: 'invalid response' } @@ -719,7 +758,7 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/app/user/internal/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') { return data } return { status: 'ERROR', reason: 'invalid response' } @@ -730,7 +769,7 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/app/mock/blance/set' 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' } @@ -741,7 +780,7 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/app/mock/user/blance/set' 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' } @@ -752,20 +791,20 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/lnd/mock/invoice/paid' 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' } }, - UpdateCallbackUrl: async (request: Types.CallbackUrl): Promise => { + UpdateCallbackUrl: async (request: Types.CallbackUrl): Promise => { const auth = await params.retrieveUserAuth() if (auth === null) throw new Error('retrieveUserAuth() returned null') let finalRoute = '/api/user/cb/update' 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 - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.CallbackUrlValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } @@ -777,7 +816,7 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/guest/invite' 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' } @@ -788,7 +827,7 @@ export default (params: ClientParams) => ({ let finalRoute = '/api/user/health' 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') { return data } return { status: 'ERROR', reason: 'invalid response' } diff --git a/src/Api/pub/autogenerated/ts/nostr_client.ts b/src/Api/pub/autogenerated/ts/nostr_client.ts index 10a7141f..e6864d3a 100644 --- a/src/Api/pub/autogenerated/ts/nostr_client.ts +++ b/src/Api/pub/autogenerated/ts/nostr_client.ts @@ -11,62 +11,74 @@ export type NostrClientParams = { retrieveNostrUserAuth: () => Promise checkResult?: true } -export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({ - AddApp: async (request: Types.AddAppRequest): Promise => { +export default (params: NostrClientParams, send: (to: string, message: NostrRequest) => Promise, subscribe: (to: string, message: NostrRequest, cb: (res: any) => void) => void) => ({ + AddApp: async (request: Types.AddAppRequest): Promise => { const auth = await params.retrieveNostrAdminAuth() if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'AddApp',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'AddApp', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.AuthAppValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - AddProduct: async (request: Types.AddProductRequest): Promise => { + AddPeer: async (request: Types.AddPeerRequest): Promise => { + const auth = await params.retrieveNostrAdminAuth() + if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') + const nostrRequest: NostrRequest = {} + nostrRequest.body = request + const data = await send(params.pubDestination, { rpcName: 'AddPeer', authIdentifier: auth, ...nostrRequest }) + if (data.status === 'ERROR' && typeof data.reason === 'string') return data + if (data.status === 'OK') { + return data + } + return { status: 'ERROR', reason: 'invalid response' } + }, + AddProduct: async (request: Types.AddProductRequest): Promise => { 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:'AddProduct',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'AddProduct', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.ProductValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - AuthApp: async (request: Types.AuthAppRequest): Promise => { + AuthApp: async (request: Types.AuthAppRequest): Promise => { const auth = await params.retrieveNostrAdminAuth() if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'AuthApp',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'AuthApp', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.AuthAppValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - AuthorizeDebit: async (request: Types.DebitAuthorizationRequest): Promise => { + AuthorizeDebit: async (request: Types.DebitAuthorizationRequest): Promise => { 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:'AuthorizeDebit',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'AuthorizeDebit', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.DebitAuthorizationValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } @@ -77,64 +89,79 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'BanDebit',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'BanDebit', authIdentifier: auth, ...nostrRequest }) 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' } }, - BanUser: async (request: Types.BanUserRequest): Promise => { + BanUser: async (request: Types.BanUserRequest): Promise => { const auth = await params.retrieveNostrAdminAuth() if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'BanUser',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'BanUser', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.BanUserResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - BatchUser: async (requests:Types.UserMethodInputs[]): Promise => { + BatchUser: async (requests: Types.UserMethodInputs[]): Promise => { const auth = await params.retrieveNostrUserAuth() if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') - const nostrRequest: NostrRequest = {body:{requests}} - const data = await send(params.pubDestination, {rpcName:'BatchUser',authIdentifier:auth, ...nostrRequest }) + const nostrRequest: NostrRequest = { body: { requests } } + const data = await send(params.pubDestination, { rpcName: 'BatchUser', authIdentifier: auth, ...nostrRequest }) 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' } + }, + CloseChannel: async (request: Types.CloseChannelRequest): Promise => { + const auth = await params.retrieveNostrAdminAuth() + if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') + const nostrRequest: NostrRequest = {} + nostrRequest.body = request + const data = await send(params.pubDestination, { rpcName: 'CloseChannel', 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.CloseChannelResponseValidate(result) + if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } + } return { status: 'ERROR', reason: 'invalid response' } }, - CreateOneTimeInviteLink: async (request: Types.CreateOneTimeInviteLinkRequest): Promise => { + CreateOneTimeInviteLink: async (request: Types.CreateOneTimeInviteLinkRequest): Promise => { const auth = await params.retrieveNostrAdminAuth() if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'CreateOneTimeInviteLink',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'CreateOneTimeInviteLink', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.CreateOneTimeInviteLinkResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - DecodeInvoice: async (request: Types.DecodeInvoiceRequest): Promise => { + DecodeInvoice: async (request: Types.DecodeInvoiceRequest): Promise => { 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:'DecodeInvoice',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'DecodeInvoice', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.DecodeInvoiceResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } @@ -145,9 +172,9 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'EditDebit',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'EditDebit', authIdentifier: auth, ...nostrRequest }) 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' } @@ -157,241 +184,241 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'EnrollAdminToken',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'EnrollAdminToken', authIdentifier: auth, ...nostrRequest }) 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' } }, - GetAppsMetrics: async (request: Types.AppsMetricsRequest): Promise => { + GetAppsMetrics: async (request: Types.AppsMetricsRequest): Promise => { const auth = await params.retrieveNostrMetricsAuth() if (auth === null) throw new Error('retrieveNostrMetricsAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'GetAppsMetrics',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'GetAppsMetrics', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.AppsMetricsValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetDebitAuthorizations: async (): Promise => { + GetDebitAuthorizations: async (): Promise => { const auth = await params.retrieveNostrUserAuth() if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} - const data = await send(params.pubDestination, {rpcName:'GetDebitAuthorizations',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'GetDebitAuthorizations', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.DebitAuthorizationsValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetHttpCreds: async (cb: (res:ResultError | ({ status: 'OK' }& Types.HttpCreds)) => void): Promise => { + GetHttpCreds: async (cb: (res: ResultError | ({ status: 'OK' } & Types.HttpCreds)) => void): Promise => { const auth = await params.retrieveNostrUserAuth() if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} - subscribe(params.pubDestination, {rpcName:'GetHttpCreds',authIdentifier:auth, ...nostrRequest }, (data) => { + subscribe(params.pubDestination, { rpcName: 'GetHttpCreds', authIdentifier: auth, ...nostrRequest }, (data) => { if (data.status === 'ERROR' && typeof data.reason === 'string') return cb(data) - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return cb({ status: 'OK', ...result }) + if (!params.checkResult) return cb({ status: 'OK', ...result }) const error = Types.HttpCredsValidate(result) if (error === null) { return cb({ status: 'OK', ...result }) } else return cb({ status: 'ERROR', reason: error.message }) } return cb({ status: 'ERROR', reason: 'invalid response' }) }) }, - GetInviteLinkState: async (request: Types.GetInviteTokenStateRequest): Promise => { + GetInviteLinkState: async (request: Types.GetInviteTokenStateRequest): Promise => { const auth = await params.retrieveNostrAdminAuth() if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'GetInviteLinkState',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'GetInviteLinkState', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.GetInviteTokenStateResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetLNURLChannelLink: async (): Promise => { + GetLNURLChannelLink: async (): Promise => { 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 }) + 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') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - GetLiveDebitRequests: async (cb: (res:ResultError | ({ status: 'OK' }& Types.LiveDebitRequest)) => void): Promise => { + GetLiveDebitRequests: async (cb: (res: ResultError | ({ status: 'OK' } & Types.LiveDebitRequest)) => void): Promise => { const auth = await params.retrieveNostrUserAuth() if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} - subscribe(params.pubDestination, {rpcName:'GetLiveDebitRequests',authIdentifier:auth, ...nostrRequest }, (data) => { + subscribe(params.pubDestination, { rpcName: 'GetLiveDebitRequests', authIdentifier: auth, ...nostrRequest }, (data) => { if (data.status === 'ERROR' && typeof data.reason === 'string') return cb(data) - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return cb({ status: 'OK', ...result }) + if (!params.checkResult) return cb({ status: 'OK', ...result }) const error = Types.LiveDebitRequestValidate(result) if (error === null) { return cb({ status: 'OK', ...result }) } else return cb({ status: 'ERROR', reason: error.message }) } return cb({ status: 'ERROR', reason: 'invalid response' }) }) }, - GetLiveUserOperations: async (cb: (res:ResultError | ({ status: 'OK' }& Types.LiveUserOperation)) => void): Promise => { + GetLiveUserOperations: async (cb: (res: ResultError | ({ status: 'OK' } & Types.LiveUserOperation)) => void): Promise => { const auth = await params.retrieveNostrUserAuth() if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} - subscribe(params.pubDestination, {rpcName:'GetLiveUserOperations',authIdentifier:auth, ...nostrRequest }, (data) => { + subscribe(params.pubDestination, { rpcName: 'GetLiveUserOperations', authIdentifier: auth, ...nostrRequest }, (data) => { if (data.status === 'ERROR' && typeof data.reason === 'string') return cb(data) - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return cb({ status: 'OK', ...result }) + if (!params.checkResult) return cb({ status: 'OK', ...result }) const error = Types.LiveUserOperationValidate(result) if (error === null) { return cb({ status: 'OK', ...result }) } else return cb({ status: 'ERROR', reason: error.message }) } return cb({ status: 'ERROR', reason: 'invalid response' }) }) }, - GetLndMetrics: async (request: Types.LndMetricsRequest): Promise => { + GetLndMetrics: async (request: Types.LndMetricsRequest): Promise => { const auth = await params.retrieveNostrMetricsAuth() if (auth === null) throw new Error('retrieveNostrMetricsAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'GetLndMetrics',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'GetLndMetrics', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LndMetricsValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetLnurlPayLink: async (): Promise => { + GetLnurlPayLink: async (): Promise => { const auth = await params.retrieveNostrUserAuth() if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} - const data = await send(params.pubDestination, {rpcName:'GetLnurlPayLink',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'GetLnurlPayLink', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - GetLnurlWithdrawLink: async (): Promise => { + GetLnurlWithdrawLink: async (): Promise => { 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 }) + 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') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - GetMigrationUpdate: async (cb: (res:ResultError | ({ status: 'OK' }& Types.MigrationUpdate)) => void): Promise => { + GetMigrationUpdate: async (cb: (res: ResultError | ({ status: 'OK' } & Types.MigrationUpdate)) => void): Promise => { const auth = await params.retrieveNostrUserAuth() if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} - subscribe(params.pubDestination, {rpcName:'GetMigrationUpdate',authIdentifier:auth, ...nostrRequest }, (data) => { + subscribe(params.pubDestination, { rpcName: 'GetMigrationUpdate', authIdentifier: auth, ...nostrRequest }, (data) => { if (data.status === 'ERROR' && typeof data.reason === 'string') return cb(data) - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return cb({ status: 'OK', ...result }) + if (!params.checkResult) return cb({ status: 'OK', ...result }) const error = Types.MigrationUpdateValidate(result) if (error === null) { return cb({ status: 'OK', ...result }) } else return cb({ status: 'ERROR', reason: error.message }) } return cb({ status: 'ERROR', reason: 'invalid response' }) }) }, - GetPaymentState: async (request: Types.GetPaymentStateRequest): Promise => { + GetPaymentState: async (request: Types.GetPaymentStateRequest): Promise => { 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:'GetPaymentState',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'GetPaymentState', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.PaymentStateValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetSeed: async (): Promise => { + GetSeed: async (): Promise => { const auth = await params.retrieveNostrAdminAuth() if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') const nostrRequest: NostrRequest = {} - const data = await send(params.pubDestination, {rpcName:'GetSeed',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'GetSeed', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LndSeedValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetUsageMetrics: async (): Promise => { + GetUsageMetrics: async (): Promise => { const auth = await params.retrieveNostrMetricsAuth() if (auth === null) throw new Error('retrieveNostrMetricsAuth() returned null') const nostrRequest: NostrRequest = {} - const data = await send(params.pubDestination, {rpcName:'GetUsageMetrics',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'GetUsageMetrics', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.UsageMetricsValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetUserInfo: async (): Promise => { + GetUserInfo: async (): Promise => { const auth = await params.retrieveNostrUserAuth() if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} - const data = await send(params.pubDestination, {rpcName:'GetUserInfo',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'GetUserInfo', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.UserInfoValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - GetUserOperations: async (request: Types.GetUserOperationsRequest): Promise => { + GetUserOperations: async (request: Types.GetUserOperationsRequest): Promise => { 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:'GetUserOperations',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'GetUserOperations', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.GetUserOperationsResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } @@ -402,127 +429,127 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ if (auth === null) throw new Error('retrieveNostrGuestWithPubAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'LinkNPubThroughToken',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'LinkNPubThroughToken', authIdentifier: auth, ...nostrRequest }) 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' } }, - ListChannels: async (): Promise => { + ListChannels: async (): Promise => { const auth = await params.retrieveNostrAdminAuth() if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') const nostrRequest: NostrRequest = {} - const data = await send(params.pubDestination, {rpcName:'ListChannels',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'ListChannels', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LndChannelsValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - LndGetInfo: async (request: Types.LndGetInfoRequest): Promise => { + LndGetInfo: async (request: Types.LndGetInfoRequest): Promise => { const auth = await params.retrieveNostrAdminAuth() if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'LndGetInfo',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'LndGetInfo', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.LndGetInfoResponseValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } return { status: 'ERROR', reason: 'invalid response' } }, - NewAddress: async (request: Types.NewAddressRequest): Promise => { + NewAddress: async (request: Types.NewAddressRequest): Promise => { 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 }) + 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') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - NewInvoice: async (request: Types.NewInvoiceRequest): Promise => { + NewInvoice: async (request: Types.NewInvoiceRequest): Promise => { 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 }) + 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') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - NewProductInvoice: async (query: Types.NewProductInvoice_Query): Promise => { + NewProductInvoice: async (query: Types.NewProductInvoice_Query): Promise => { const auth = await params.retrieveNostrUserAuth() if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.query = query - const data = await send(params.pubDestination, {rpcName:'NewProductInvoice',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'NewProductInvoice', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - OpenChannel: async (request: Types.OpenChannelRequest): Promise => { - const auth = await params.retrieveNostrUserAuth() - if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') + OpenChannel: async (request: Types.OpenChannelRequest): Promise => { + const auth = await params.retrieveNostrAdminAuth() + if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'OpenChannel',authIdentifier:auth, ...nostrRequest }) + 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') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - PayAddress: async (request: Types.PayAddressRequest): Promise => { + PayAddress: async (request: Types.PayAddressRequest): Promise => { 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 }) + 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') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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' } }, - PayInvoice: async (request: Types.PayInvoiceRequest): Promise => { + PayInvoice: async (request: Types.PayInvoiceRequest): Promise => { 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 }) + 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') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + 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 } } @@ -533,9 +560,9 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'ResetDebit',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'ResetDebit', authIdentifier: auth, ...nostrRequest }) 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' } @@ -545,23 +572,23 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'RespondToDebit',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'RespondToDebit', authIdentifier: auth, ...nostrRequest }) 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' } }, - UpdateCallbackUrl: async (request: Types.CallbackUrl): Promise => { + UpdateCallbackUrl: async (request: Types.CallbackUrl): Promise => { 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:'UpdateCallbackUrl',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'UpdateCallbackUrl', authIdentifier: auth, ...nostrRequest }) if (data.status === 'ERROR' && typeof data.reason === 'string') return data - if (data.status === 'OK') { + if (data.status === 'OK') { const result = data - if(!params.checkResult) return { status: 'OK', ...result } + if (!params.checkResult) return { status: 'OK', ...result } const error = Types.CallbackUrlValidate(result) if (error === null) { return { status: 'OK', ...result } } else return { status: 'ERROR', reason: error.message } } @@ -572,9 +599,9 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ if (auth === null) throw new Error('retrieveNostrGuestWithPubAuth() returned null') const nostrRequest: NostrRequest = {} nostrRequest.body = request - const data = await send(params.pubDestination, {rpcName:'UseInviteLink',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'UseInviteLink', authIdentifier: auth, ...nostrRequest }) 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' } @@ -583,9 +610,9 @@ export default (params: NostrClientParams, send: (to:string, message: NostrRequ const auth = await params.retrieveNostrUserAuth() if (auth === null) throw new Error('retrieveNostrUserAuth() returned null') const nostrRequest: NostrRequest = {} - const data = await send(params.pubDestination, {rpcName:'UserHealth',authIdentifier:auth, ...nostrRequest }) + const data = await send(params.pubDestination, { rpcName: 'UserHealth', authIdentifier: auth, ...nostrRequest }) 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' } diff --git a/src/Api/pub/autogenerated/ts/nostr_transport.ts b/src/Api/pub/autogenerated/ts/nostr_transport.ts index 4b38912a..e2586994 100644 --- a/src/Api/pub/autogenerated/ts/nostr_transport.ts +++ b/src/Api/pub/autogenerated/ts/nostr_transport.ts @@ -16,12 +16,12 @@ export type NostrOptions = { logger?: Logger throwErrors?: true metricsCallback: (metrics: Types.RequestMetric[]) => void - NostrAdminAuthGuard: (appId?:string, identifier?: string) => Promise - NostrGuestWithPubAuthGuard: (appId?:string, identifier?: string) => Promise - NostrMetricsAuthGuard: (appId?:string, identifier?: string) => Promise - NostrUserAuthGuard: (appId?:string, identifier?: string) => Promise + NostrAdminAuthGuard: (appId?: string, identifier?: string) => Promise + NostrGuestWithPubAuthGuard: (appId?: string, identifier?: string) => Promise + NostrMetricsAuthGuard: (appId?: string, identifier?: string) => Promise + NostrUserAuthGuard: (appId?: string, identifier?: string) => Promise } -const logErrorAndReturnResponse = (error: Error, response: string, res: NostrResponse, logger: Logger, metric: Types.RequestMetric, metricsCallback: (metrics: Types.RequestMetric[]) => void) => { +const logErrorAndReturnResponse = (error: Error, response: string, res: NostrResponse, logger: Logger, metric: Types.RequestMetric, metricsCallback: (metrics: Types.RequestMetric[]) => void) => { logger.error(error.message || error); metricsCallback([{ ...metric, error: response }]); res({ status: 'ERROR', reason: response }) } export default (methods: Types.ServerMethods, opts: NostrOptions) => { @@ -42,11 +42,27 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.AddAppRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.AddApp({rpcName:'AddApp', ctx:authContext , req: request}) + const response = await methods.AddApp({ rpcName: 'AddApp', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + break + case 'AddPeer': + try { + if (!methods.AddPeer) throw new Error('method: AddPeer is not implemented') + const authContext = await opts.NostrAdminAuthGuard(req.appId, req.authIdentifier) + stats.guard = process.hrtime.bigint() + authCtx = authContext + const request = req.body + const error = Types.AddPeerRequestValidate(request) + stats.validate = process.hrtime.bigint() + if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) + await methods.AddPeer({ rpcName: 'AddPeer', ctx: authContext, req: request }) + stats.handle = process.hrtime.bigint() + res({ status: 'OK' }) + opts.metricsCallback([{ ...info, ...stats, ...authContext }]) + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'AddProduct': try { @@ -58,11 +74,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.AddProductRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.AddProduct({rpcName:'AddProduct', ctx:authContext , req: request}) + const response = await methods.AddProduct({ rpcName: 'AddProduct', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'AuthApp': try { @@ -74,11 +90,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.AuthAppRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.AuthApp({rpcName:'AuthApp', ctx:authContext , req: request}) + const response = await methods.AuthApp({ rpcName: 'AuthApp', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'AuthorizeDebit': try { @@ -90,11 +106,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DebitAuthorizationRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.AuthorizeDebit({rpcName:'AuthorizeDebit', ctx:authContext , req: request}) + const response = await methods.AuthorizeDebit({ rpcName: 'AuthorizeDebit', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'BanDebit': try { @@ -106,11 +122,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DebitOperationValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - await methods.BanDebit({rpcName:'BanDebit', ctx:authContext , req: request}) + await methods.BanDebit({ rpcName: 'BanDebit', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK'}) + res({ status: 'OK' }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'BanUser': try { @@ -122,17 +138,17 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.BanUserRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.BanUser({rpcName:'BanUser', ctx:authContext , req: request}) + const response = await methods.BanUser({ rpcName: 'BanUser', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'BatchUser': try { info.batch = true const requests = req.body.requests as Types.UserMethodInputs[] - if (!Array.isArray(requests))throw new Error('invalid body, is not an array') + if (!Array.isArray(requests)) throw new Error('invalid body, is not an array') info.batchSize = requests.length if (requests.length > 10) throw new Error('too many requests in the batch') const ctx = await opts.NostrUserAuthGuard(req.appId, req.authIdentifier) @@ -146,7 +162,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const opInfo: Types.RequestInfo = { rpcName: operation.rpcName, batch: true, nostr: true, batchSize: 0 } const opStats: Types.RequestStats = { startMs, start: startTime, parse: stats.parse, guard: stats.guard, validate: 0n, handle: 0n } try { - switch(operation.rpcName) { + switch (operation.rpcName) { case 'AddProduct': if (!methods.AddProduct) { throw new Error('method not defined: AddProduct') @@ -154,7 +170,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.AddProductRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - const res = await methods.AddProduct({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.AddProduct({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -166,7 +182,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DebitAuthorizationRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - const res = await methods.AuthorizeDebit({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.AuthorizeDebit({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -178,7 +194,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DebitOperationValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - await methods.BanDebit({...operation, ctx}); responses.push({ status: 'OK' }) + await methods.BanDebit({ ...operation, ctx }); responses.push({ status: 'OK' }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -190,7 +206,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DecodeInvoiceRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - const res = await methods.DecodeInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.DecodeInvoice({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -202,7 +218,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DebitAuthorizationRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - await methods.EditDebit({...operation, ctx}); responses.push({ status: 'OK' }) + await methods.EditDebit({ ...operation, ctx }); responses.push({ status: 'OK' }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -214,7 +230,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.EnrollAdminTokenRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - await methods.EnrollAdminToken({...operation, ctx}); responses.push({ status: 'OK' }) + await methods.EnrollAdminToken({ ...operation, ctx }); responses.push({ status: 'OK' }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -224,7 +240,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { throw new Error('method not defined: GetDebitAuthorizations') } else { opStats.validate = opStats.guard - const res = await methods.GetDebitAuthorizations({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.GetDebitAuthorizations({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -234,7 +250,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { throw new Error('method not defined: GetLNURLChannelLink') } else { opStats.validate = opStats.guard - const res = await methods.GetLNURLChannelLink({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.GetLNURLChannelLink({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -244,7 +260,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { throw new Error('method not defined: GetLnurlPayLink') } else { opStats.validate = opStats.guard - const res = await methods.GetLnurlPayLink({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.GetLnurlPayLink({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -254,7 +270,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { throw new Error('method not defined: GetLnurlWithdrawLink') } else { opStats.validate = opStats.guard - const res = await methods.GetLnurlWithdrawLink({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.GetLnurlWithdrawLink({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -266,7 +282,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.GetPaymentStateRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - const res = await methods.GetPaymentState({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.GetPaymentState({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -276,7 +292,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { throw new Error('method not defined: GetUserInfo') } else { opStats.validate = opStats.guard - const res = await methods.GetUserInfo({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.GetUserInfo({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -288,7 +304,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.GetUserOperationsRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - const res = await methods.GetUserOperations({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.GetUserOperations({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -300,7 +316,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.NewAddressRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - const res = await methods.NewAddress({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.NewAddress({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -312,7 +328,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.NewInvoiceRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - const res = await methods.NewInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.NewInvoice({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -322,19 +338,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { throw new Error('method not defined: NewProductInvoice') } else { opStats.validate = opStats.guard - const res = await methods.NewProductInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res }) - opStats.handle = process.hrtime.bigint() - callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) - } - break - case 'OpenChannel': - if (!methods.OpenChannel) { - throw new Error('method not defined: OpenChannel') - } else { - const error = Types.OpenChannelRequestValidate(operation.req) - opStats.validate = process.hrtime.bigint() - if (error !== null) throw error - const res = await methods.OpenChannel({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.NewProductInvoice({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -346,7 +350,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.PayAddressRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - const res = await methods.PayAddress({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.PayAddress({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -358,7 +362,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.PayInvoiceRequestValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - const res = await methods.PayInvoice({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.PayInvoice({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -370,7 +374,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DebitOperationValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - await methods.ResetDebit({...operation, ctx}); responses.push({ status: 'OK' }) + await methods.ResetDebit({ ...operation, ctx }); responses.push({ status: 'OK' }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -382,7 +386,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DebitResponseValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - await methods.RespondToDebit({...operation, ctx}); responses.push({ status: 'OK' }) + await methods.RespondToDebit({ ...operation, ctx }); responses.push({ status: 'OK' }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -394,7 +398,7 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.CallbackUrlValidate(operation.req) opStats.validate = process.hrtime.bigint() if (error !== null) throw error - const res = await methods.UpdateCallbackUrl({...operation, ctx}); responses.push({ status: 'OK', ...res }) + const res = await methods.UpdateCallbackUrl({ ...operation, ctx }); responses.push({ status: 'OK', ...res }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } @@ -404,20 +408,36 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { throw new Error('method not defined: UserHealth') } else { opStats.validate = opStats.guard - await methods.UserHealth({...operation, ctx}); responses.push({ status: 'OK' }) + await methods.UserHealth({ ...operation, ctx }); responses.push({ status: 'OK' }) opStats.handle = process.hrtime.bigint() callsMetrics.push({ ...opInfo, ...opStats, ...ctx }) } break default: - throw new Error('unkown rpcName') + throw new Error('unkown rpcName') } - } catch(ex) {const e = ex as any; logger.error(e.message || e); callsMetrics.push({ ...opInfo, ...opStats, ...ctx, error: e.message }); responses.push({ status: 'ERROR', reason: e.message || e })} + } catch (ex) { const e = ex as any; logger.error(e.message || e); callsMetrics.push({ ...opInfo, ...opStats, ...ctx, error: e.message }); responses.push({ status: 'ERROR', reason: e.message || e }) } } stats.handle = process.hrtime.bigint() res({ status: 'OK', responses }) opts.metricsCallback([{ ...info, ...stats, ...ctx }, ...callsMetrics]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + break + case 'CloseChannel': + try { + if (!methods.CloseChannel) throw new Error('method: CloseChannel is not implemented') + const authContext = await opts.NostrAdminAuthGuard(req.appId, req.authIdentifier) + stats.guard = process.hrtime.bigint() + authCtx = authContext + const request = req.body + const error = Types.CloseChannelRequestValidate(request) + stats.validate = process.hrtime.bigint() + if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) + const response = await methods.CloseChannel({ rpcName: 'CloseChannel', ctx: authContext, req: request }) + stats.handle = process.hrtime.bigint() + res({ status: 'OK', ...response }) + opts.metricsCallback([{ ...info, ...stats, ...authContext }]) + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'CreateOneTimeInviteLink': try { @@ -429,11 +449,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.CreateOneTimeInviteLinkRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.CreateOneTimeInviteLink({rpcName:'CreateOneTimeInviteLink', ctx:authContext , req: request}) + const response = await methods.CreateOneTimeInviteLink({ rpcName: 'CreateOneTimeInviteLink', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'DecodeInvoice': try { @@ -445,11 +465,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DecodeInvoiceRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.DecodeInvoice({rpcName:'DecodeInvoice', ctx:authContext , req: request}) + const response = await methods.DecodeInvoice({ rpcName: 'DecodeInvoice', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'EditDebit': try { @@ -461,11 +481,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DebitAuthorizationRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - await methods.EditDebit({rpcName:'EditDebit', ctx:authContext , req: request}) + await methods.EditDebit({ rpcName: 'EditDebit', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK'}) + res({ status: 'OK' }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'EnrollAdminToken': try { @@ -477,11 +497,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.EnrollAdminTokenRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - await methods.EnrollAdminToken({rpcName:'EnrollAdminToken', ctx:authContext , req: request}) + await methods.EnrollAdminToken({ rpcName: 'EnrollAdminToken', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK'}) + res({ status: 'OK' }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetAppsMetrics': try { @@ -493,11 +513,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.AppsMetricsRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.GetAppsMetrics({rpcName:'GetAppsMetrics', ctx:authContext , req: request}) + const response = await methods.GetAppsMetrics({ rpcName: 'GetAppsMetrics', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetDebitAuthorizations': try { @@ -506,11 +526,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - const response = await methods.GetDebitAuthorizations({rpcName:'GetDebitAuthorizations', ctx:authContext }) + const response = await methods.GetDebitAuthorizations({ rpcName: 'GetDebitAuthorizations', ctx: authContext }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetHttpCreds': try { @@ -519,11 +539,13 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - methods.GetHttpCreds({rpcName:'GetHttpCreds', ctx:authContext ,cb: (response, err) => { - stats.handle = process.hrtime.bigint() - if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)} else { res({status: 'OK', ...response});opts.metricsCallback([{ ...info, ...stats, ...authContext }])} - }}) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + methods.GetHttpCreds({ + rpcName: 'GetHttpCreds', ctx: authContext, cb: (response, err) => { + stats.handle = process.hrtime.bigint() + if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback) } else { res({ status: 'OK', ...response }); opts.metricsCallback([{ ...info, ...stats, ...authContext }]) } + } + }) + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetInviteLinkState': try { @@ -535,11 +557,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.GetInviteTokenStateRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.GetInviteLinkState({rpcName:'GetInviteLinkState', ctx:authContext , req: request}) + const response = await methods.GetInviteLinkState({ rpcName: 'GetInviteLinkState', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetLNURLChannelLink': try { @@ -548,11 +570,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - const response = await methods.GetLNURLChannelLink({rpcName:'GetLNURLChannelLink', ctx:authContext }) + const response = await methods.GetLNURLChannelLink({ rpcName: 'GetLNURLChannelLink', ctx: authContext }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetLiveDebitRequests': try { @@ -561,11 +583,13 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - methods.GetLiveDebitRequests({rpcName:'GetLiveDebitRequests', ctx:authContext ,cb: (response, err) => { - stats.handle = process.hrtime.bigint() - if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)} else { res({status: 'OK', ...response});opts.metricsCallback([{ ...info, ...stats, ...authContext }])} - }}) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + methods.GetLiveDebitRequests({ + rpcName: 'GetLiveDebitRequests', ctx: authContext, cb: (response, err) => { + stats.handle = process.hrtime.bigint() + if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback) } else { res({ status: 'OK', ...response }); opts.metricsCallback([{ ...info, ...stats, ...authContext }]) } + } + }) + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetLiveUserOperations': try { @@ -574,11 +598,13 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - methods.GetLiveUserOperations({rpcName:'GetLiveUserOperations', ctx:authContext ,cb: (response, err) => { - stats.handle = process.hrtime.bigint() - if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)} else { res({status: 'OK', ...response});opts.metricsCallback([{ ...info, ...stats, ...authContext }])} - }}) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + methods.GetLiveUserOperations({ + rpcName: 'GetLiveUserOperations', ctx: authContext, cb: (response, err) => { + stats.handle = process.hrtime.bigint() + if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback) } else { res({ status: 'OK', ...response }); opts.metricsCallback([{ ...info, ...stats, ...authContext }]) } + } + }) + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetLndMetrics': try { @@ -590,11 +616,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.LndMetricsRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.GetLndMetrics({rpcName:'GetLndMetrics', ctx:authContext , req: request}) + const response = await methods.GetLndMetrics({ rpcName: 'GetLndMetrics', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetLnurlPayLink': try { @@ -603,11 +629,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - const response = await methods.GetLnurlPayLink({rpcName:'GetLnurlPayLink', ctx:authContext }) + const response = await methods.GetLnurlPayLink({ rpcName: 'GetLnurlPayLink', ctx: authContext }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetLnurlWithdrawLink': try { @@ -616,11 +642,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - const response = await methods.GetLnurlWithdrawLink({rpcName:'GetLnurlWithdrawLink', ctx:authContext }) + const response = await methods.GetLnurlWithdrawLink({ rpcName: 'GetLnurlWithdrawLink', ctx: authContext }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetMigrationUpdate': try { @@ -629,11 +655,13 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - methods.GetMigrationUpdate({rpcName:'GetMigrationUpdate', ctx:authContext ,cb: (response, err) => { - stats.handle = process.hrtime.bigint() - if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback)} else { res({status: 'OK', ...response});opts.metricsCallback([{ ...info, ...stats, ...authContext }])} - }}) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + methods.GetMigrationUpdate({ + rpcName: 'GetMigrationUpdate', ctx: authContext, cb: (response, err) => { + stats.handle = process.hrtime.bigint() + if (err) { logErrorAndReturnResponse(err, err.message, res, logger, { ...info, ...stats, ...authContext }, opts.metricsCallback) } else { res({ status: 'OK', ...response }); opts.metricsCallback([{ ...info, ...stats, ...authContext }]) } + } + }) + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetPaymentState': try { @@ -645,11 +673,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.GetPaymentStateRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.GetPaymentState({rpcName:'GetPaymentState', ctx:authContext , req: request}) + const response = await methods.GetPaymentState({ rpcName: 'GetPaymentState', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetSeed': try { @@ -658,11 +686,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - const response = await methods.GetSeed({rpcName:'GetSeed', ctx:authContext }) + const response = await methods.GetSeed({ rpcName: 'GetSeed', ctx: authContext }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetUsageMetrics': try { @@ -671,11 +699,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - const response = await methods.GetUsageMetrics({rpcName:'GetUsageMetrics', ctx:authContext }) + const response = await methods.GetUsageMetrics({ rpcName: 'GetUsageMetrics', ctx: authContext }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetUserInfo': try { @@ -684,11 +712,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - const response = await methods.GetUserInfo({rpcName:'GetUserInfo', ctx:authContext }) + const response = await methods.GetUserInfo({ rpcName: 'GetUserInfo', ctx: authContext }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'GetUserOperations': try { @@ -700,11 +728,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.GetUserOperationsRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.GetUserOperations({rpcName:'GetUserOperations', ctx:authContext , req: request}) + const response = await methods.GetUserOperations({ rpcName: 'GetUserOperations', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'LinkNPubThroughToken': try { @@ -716,11 +744,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.LinkNPubThroughTokenRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - await methods.LinkNPubThroughToken({rpcName:'LinkNPubThroughToken', ctx:authContext , req: request}) + await methods.LinkNPubThroughToken({ rpcName: 'LinkNPubThroughToken', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK'}) + res({ status: 'OK' }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'ListChannels': try { @@ -729,11 +757,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - const response = await methods.ListChannels({rpcName:'ListChannels', ctx:authContext }) + const response = await methods.ListChannels({ rpcName: 'ListChannels', ctx: authContext }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'LndGetInfo': try { @@ -745,11 +773,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.LndGetInfoRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.LndGetInfo({rpcName:'LndGetInfo', ctx:authContext , req: request}) + const response = await methods.LndGetInfo({ rpcName: 'LndGetInfo', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'NewAddress': try { @@ -761,11 +789,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.NewAddressRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.NewAddress({rpcName:'NewAddress', ctx:authContext , req: request}) + const response = await methods.NewAddress({ rpcName: 'NewAddress', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'NewInvoice': try { @@ -777,11 +805,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.NewInvoiceRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.NewInvoice({rpcName:'NewInvoice', ctx:authContext , req: request}) + const response = await methods.NewInvoice({ rpcName: 'NewInvoice', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'NewProductInvoice': try { @@ -790,27 +818,27 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - const response = await methods.NewProductInvoice({rpcName:'NewProductInvoice', ctx:authContext ,query: req.query||{}}) + const response = await methods.NewProductInvoice({ rpcName: 'NewProductInvoice', ctx: authContext, query: req.query || {} }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); 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.appId, req.authIdentifier) + const authContext = await opts.NostrAdminAuthGuard(req.appId, req.authIdentifier) stats.guard = process.hrtime.bigint() authCtx = authContext const request = req.body const error = Types.OpenChannelRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.OpenChannel({rpcName:'OpenChannel', ctx:authContext , req: request}) + const response = await methods.OpenChannel({ rpcName: 'OpenChannel', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'PayAddress': try { @@ -822,11 +850,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.PayAddressRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.PayAddress({rpcName:'PayAddress', ctx:authContext , req: request}) + const response = await methods.PayAddress({ rpcName: 'PayAddress', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'PayInvoice': try { @@ -838,11 +866,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.PayInvoiceRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.PayInvoice({rpcName:'PayInvoice', ctx:authContext , req: request}) + const response = await methods.PayInvoice({ rpcName: 'PayInvoice', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'ResetDebit': try { @@ -854,11 +882,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DebitOperationValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - await methods.ResetDebit({rpcName:'ResetDebit', ctx:authContext , req: request}) + await methods.ResetDebit({ rpcName: 'ResetDebit', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK'}) + res({ status: 'OK' }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'RespondToDebit': try { @@ -870,11 +898,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.DebitResponseValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - await methods.RespondToDebit({rpcName:'RespondToDebit', ctx:authContext , req: request}) + await methods.RespondToDebit({ rpcName: 'RespondToDebit', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK'}) + res({ status: 'OK' }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'UpdateCallbackUrl': try { @@ -886,11 +914,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.CallbackUrlValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - const response = await methods.UpdateCallbackUrl({rpcName:'UpdateCallbackUrl', ctx:authContext , req: request}) + const response = await methods.UpdateCallbackUrl({ rpcName: 'UpdateCallbackUrl', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK', ...response}) + res({ status: 'OK', ...response }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'UseInviteLink': try { @@ -902,11 +930,11 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { const error = Types.UseInviteLinkRequestValidate(request) stats.validate = process.hrtime.bigint() if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) - await methods.UseInviteLink({rpcName:'UseInviteLink', ctx:authContext , req: request}) + await methods.UseInviteLink({ rpcName: 'UseInviteLink', ctx: authContext, req: request }) stats.handle = process.hrtime.bigint() - res({status: 'OK'}) + res({ status: 'OK' }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break case 'UserHealth': try { @@ -915,13 +943,13 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { stats.guard = process.hrtime.bigint() authCtx = authContext stats.validate = stats.guard - await methods.UserHealth({rpcName:'UserHealth', ctx:authContext }) + await methods.UserHealth({ rpcName: 'UserHealth', ctx: authContext }) stats.handle = process.hrtime.bigint() - res({status: 'OK'}) + res({ status: 'OK' }) opts.metricsCallback([{ ...info, ...stats, ...authContext }]) - }catch(ex){ const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break - default: logger.error('unknown rpc call name from nostr event:'+req.rpcName) + default: logger.error('unknown rpc call name from nostr event:' + req.rpcName) } } } diff --git a/src/Api/pub/autogenerated/ts/types.ts b/src/Api/pub/autogenerated/ts/types.ts index b3de5706..b5bb55d9 100644 --- a/src/Api/pub/autogenerated/ts/types.ts +++ b/src/Api/pub/autogenerated/ts/types.ts @@ -2,18 +2,18 @@ export type ResultError = { status: 'ERROR', reason: string } export type RequestInfo = { rpcName: string, batch: boolean, nostr: boolean, batchSize: number } -export type RequestStats = { startMs:number, start:bigint, parse: bigint, guard: bigint, validate: bigint, handle: bigint } +export type RequestStats = { startMs: number, start: bigint, parse: bigint, guard: bigint, validate: bigint, handle: bigint } export type RequestMetric = AuthContext & RequestInfo & RequestStats & { error?: string } export type AdminContext = { admin_id: string } -export type AdminMethodInputs = AddApp_Input | AuthApp_Input | BanUser_Input | CreateOneTimeInviteLink_Input | GetInviteLinkState_Input | GetSeed_Input | ListChannels_Input | LndGetInfo_Input -export type AdminMethodOutputs = AddApp_Output | AuthApp_Output | BanUser_Output | CreateOneTimeInviteLink_Output | GetInviteLinkState_Output | GetSeed_Output | ListChannels_Output | LndGetInfo_Output +export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetInviteLinkState_Input | GetSeed_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input +export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetInviteLinkState_Output | GetSeed_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output export type AppContext = { app_id: string } -export type AppMethodInputs = AddAppInvoice_Input | AddAppUser_Input | AddAppUserInvoice_Input | GetApp_Input | GetAppUser_Input | GetAppUserLNURLInfo_Input | PayAppUserInvoice_Input | RequestNPubLinkingToken_Input | ResetNPubLinkingToken_Input | SendAppUserToAppPayment_Input | SendAppUserToAppUserPayment_Input | SetMockAppBalance_Input | SetMockAppUserBalance_Input -export type AppMethodOutputs = AddAppInvoice_Output | AddAppUser_Output | AddAppUserInvoice_Output | GetApp_Output | GetAppUser_Output | GetAppUserLNURLInfo_Output | PayAppUserInvoice_Output | RequestNPubLinkingToken_Output | ResetNPubLinkingToken_Output | SendAppUserToAppPayment_Output | SendAppUserToAppUserPayment_Output | SetMockAppBalance_Output | SetMockAppUserBalance_Output +export type AppMethodInputs = AddAppInvoice_Input | AddAppUser_Input | AddAppUserInvoice_Input | GetApp_Input | GetAppUser_Input | GetAppUserLNURLInfo_Input | GetNPubLinkingState_Input | PayAppUserInvoice_Input | RequestNPubLinkingToken_Input | ResetNPubLinkingToken_Input | SendAppUserToAppPayment_Input | SendAppUserToAppUserPayment_Input | SetMockAppBalance_Input | SetMockAppUserBalance_Input +export type AppMethodOutputs = AddAppInvoice_Output | AddAppUser_Output | AddAppUserInvoice_Output | GetApp_Output | GetAppUser_Output | GetAppUserLNURLInfo_Output | GetNPubLinkingState_Output | PayAppUserInvoice_Output | RequestNPubLinkingToken_Output | ResetNPubLinkingToken_Output | SendAppUserToAppPayment_Output | SendAppUserToAppUserPayment_Output | SetMockAppBalance_Output | SetMockAppUserBalance_Output export type GuestContext = { } export type GuestMethodInputs = EncryptionExchange_Input | GetLnurlPayInfo_Input | GetLnurlWithdrawInfo_Input | HandleLnurlAddress_Input | HandleLnurlPay_Input | HandleLnurlWithdraw_Input | Health_Input | SetMockInvoiceAsPaid_Input @@ -34,128 +34,137 @@ export type UserContext = { app_user_id: string user_id: string } -export type UserMethodInputs = AddProduct_Input | AuthorizeDebit_Input | BanDebit_Input | DecodeInvoice_Input | EditDebit_Input | EnrollAdminToken_Input | GetDebitAuthorizations_Input | GetLNURLChannelLink_Input | GetLnurlPayLink_Input | GetLnurlWithdrawLink_Input | GetPaymentState_Input | GetUserInfo_Input | GetUserOperations_Input | NewAddress_Input | NewInvoice_Input | NewProductInvoice_Input | OpenChannel_Input | PayAddress_Input | PayInvoice_Input | ResetDebit_Input | RespondToDebit_Input | UpdateCallbackUrl_Input | UserHealth_Input -export type UserMethodOutputs = AddProduct_Output | AuthorizeDebit_Output | BanDebit_Output | DecodeInvoice_Output | EditDebit_Output | EnrollAdminToken_Output | GetDebitAuthorizations_Output | GetLNURLChannelLink_Output | GetLnurlPayLink_Output | GetLnurlWithdrawLink_Output | GetPaymentState_Output | GetUserInfo_Output | GetUserOperations_Output | NewAddress_Output | NewInvoice_Output | NewProductInvoice_Output | OpenChannel_Output | PayAddress_Output | PayInvoice_Output | ResetDebit_Output | RespondToDebit_Output | UpdateCallbackUrl_Output | UserHealth_Output +export type UserMethodInputs = AddProduct_Input | AuthorizeDebit_Input | BanDebit_Input | DecodeInvoice_Input | EditDebit_Input | EnrollAdminToken_Input | GetDebitAuthorizations_Input | GetLNURLChannelLink_Input | GetLnurlPayLink_Input | GetLnurlWithdrawLink_Input | GetPaymentState_Input | GetUserInfo_Input | GetUserOperations_Input | NewAddress_Input | NewInvoice_Input | NewProductInvoice_Input | PayAddress_Input | PayInvoice_Input | ResetDebit_Input | RespondToDebit_Input | UpdateCallbackUrl_Input | UserHealth_Input +export type UserMethodOutputs = AddProduct_Output | AuthorizeDebit_Output | BanDebit_Output | DecodeInvoice_Output | EditDebit_Output | EnrollAdminToken_Output | GetDebitAuthorizations_Output | GetLNURLChannelLink_Output | GetLnurlPayLink_Output | GetLnurlWithdrawLink_Output | GetPaymentState_Output | GetUserInfo_Output | GetUserOperations_Output | NewAddress_Output | NewInvoice_Output | NewProductInvoice_Output | PayAddress_Output | PayInvoice_Output | ResetDebit_Output | RespondToDebit_Output | UpdateCallbackUrl_Output | UserHealth_Output export type AuthContext = AdminContext | AppContext | GuestContext | GuestWithPubContext | MetricsContext | UserContext -export type AddApp_Input = {rpcName:'AddApp', req: AddAppRequest} +export type AddApp_Input = { rpcName: 'AddApp', req: AddAppRequest } export type AddApp_Output = ResultError | ({ status: 'OK' } & AuthApp) -export type AddAppInvoice_Input = {rpcName:'AddAppInvoice', req: AddAppInvoiceRequest} +export type AddAppInvoice_Input = { rpcName: 'AddAppInvoice', req: AddAppInvoiceRequest } export type AddAppInvoice_Output = ResultError | ({ status: 'OK' } & NewInvoiceResponse) -export type AddAppUser_Input = {rpcName:'AddAppUser', req: AddAppUserRequest} +export type AddAppUser_Input = { rpcName: 'AddAppUser', req: AddAppUserRequest } export type AddAppUser_Output = ResultError | ({ status: 'OK' } & AppUser) -export type AddAppUserInvoice_Input = {rpcName:'AddAppUserInvoice', req: AddAppUserInvoiceRequest} +export type AddAppUserInvoice_Input = { rpcName: 'AddAppUserInvoice', req: AddAppUserInvoiceRequest } export type AddAppUserInvoice_Output = ResultError | ({ status: 'OK' } & NewInvoiceResponse) -export type AddProduct_Input = {rpcName:'AddProduct', req: AddProductRequest} +export type AddPeer_Input = { rpcName: 'AddPeer', req: AddPeerRequest } +export type AddPeer_Output = ResultError | { status: 'OK' } + +export type AddProduct_Input = { rpcName: 'AddProduct', req: AddProductRequest } export type AddProduct_Output = ResultError | ({ status: 'OK' } & Product) -export type AuthApp_Input = {rpcName:'AuthApp', req: AuthAppRequest} +export type AuthApp_Input = { rpcName: 'AuthApp', req: AuthAppRequest } export type AuthApp_Output = ResultError | ({ status: 'OK' } & AuthApp) -export type AuthorizeDebit_Input = {rpcName:'AuthorizeDebit', req: DebitAuthorizationRequest} +export type AuthorizeDebit_Input = { rpcName: 'AuthorizeDebit', req: DebitAuthorizationRequest } export type AuthorizeDebit_Output = ResultError | ({ status: 'OK' } & DebitAuthorization) -export type BanDebit_Input = {rpcName:'BanDebit', req: DebitOperation} +export type BanDebit_Input = { rpcName: 'BanDebit', req: DebitOperation } export type BanDebit_Output = ResultError | { status: 'OK' } -export type BanUser_Input = {rpcName:'BanUser', req: BanUserRequest} +export type BanUser_Input = { rpcName: 'BanUser', req: BanUserRequest } export type BanUser_Output = ResultError | ({ status: 'OK' } & BanUserResponse) export type BatchUser_Input = UserMethodInputs export type BatchUser_Output = UserMethodOutputs -export type CreateOneTimeInviteLink_Input = {rpcName:'CreateOneTimeInviteLink', req: CreateOneTimeInviteLinkRequest} +export type CloseChannel_Input = { rpcName: 'CloseChannel', req: CloseChannelRequest } +export type CloseChannel_Output = ResultError | ({ status: 'OK' } & CloseChannelResponse) + +export type CreateOneTimeInviteLink_Input = { rpcName: 'CreateOneTimeInviteLink', req: CreateOneTimeInviteLinkRequest } export type CreateOneTimeInviteLink_Output = ResultError | ({ status: 'OK' } & CreateOneTimeInviteLinkResponse) -export type DecodeInvoice_Input = {rpcName:'DecodeInvoice', req: DecodeInvoiceRequest} +export type DecodeInvoice_Input = { rpcName: 'DecodeInvoice', req: DecodeInvoiceRequest } export type DecodeInvoice_Output = ResultError | ({ status: 'OK' } & DecodeInvoiceResponse) -export type EditDebit_Input = {rpcName:'EditDebit', req: DebitAuthorizationRequest} +export type EditDebit_Input = { rpcName: 'EditDebit', req: DebitAuthorizationRequest } export type EditDebit_Output = ResultError | { status: 'OK' } -export type EncryptionExchange_Input = {rpcName:'EncryptionExchange', req: EncryptionExchangeRequest} +export type EncryptionExchange_Input = { rpcName: 'EncryptionExchange', req: EncryptionExchangeRequest } export type EncryptionExchange_Output = ResultError | { status: 'OK' } -export type EnrollAdminToken_Input = {rpcName:'EnrollAdminToken', req: EnrollAdminTokenRequest} +export type EnrollAdminToken_Input = { rpcName: 'EnrollAdminToken', req: EnrollAdminTokenRequest } export type EnrollAdminToken_Output = ResultError | { status: 'OK' } -export type GetApp_Input = {rpcName:'GetApp'} +export type GetApp_Input = { rpcName: 'GetApp' } export type GetApp_Output = ResultError | ({ status: 'OK' } & Application) -export type GetAppUser_Input = {rpcName:'GetAppUser', req: GetAppUserRequest} +export type GetAppUser_Input = { rpcName: 'GetAppUser', req: GetAppUserRequest } export type GetAppUser_Output = ResultError | ({ status: 'OK' } & AppUser) -export type GetAppUserLNURLInfo_Input = {rpcName:'GetAppUserLNURLInfo', req: GetAppUserLNURLInfoRequest} +export type GetAppUserLNURLInfo_Input = { rpcName: 'GetAppUserLNURLInfo', req: GetAppUserLNURLInfoRequest } export type GetAppUserLNURLInfo_Output = ResultError | ({ status: 'OK' } & LnurlPayInfoResponse) -export type GetAppsMetrics_Input = {rpcName:'GetAppsMetrics', req: AppsMetricsRequest} +export type GetAppsMetrics_Input = { rpcName: 'GetAppsMetrics', req: AppsMetricsRequest } export type GetAppsMetrics_Output = ResultError | ({ status: 'OK' } & AppsMetrics) -export type GetDebitAuthorizations_Input = {rpcName:'GetDebitAuthorizations'} +export type GetDebitAuthorizations_Input = { rpcName: 'GetDebitAuthorizations' } export type GetDebitAuthorizations_Output = ResultError | ({ status: 'OK' } & DebitAuthorizations) -export type GetHttpCreds_Input = {rpcName:'GetHttpCreds', cb:(res: HttpCreds, err:Error|null)=> void} +export type GetHttpCreds_Input = { rpcName: 'GetHttpCreds', cb: (res: HttpCreds, err: Error | null) => void } export type GetHttpCreds_Output = ResultError | { status: 'OK' } -export type GetInviteLinkState_Input = {rpcName:'GetInviteLinkState', req: GetInviteTokenStateRequest} +export type GetInviteLinkState_Input = { rpcName: 'GetInviteLinkState', req: GetInviteTokenStateRequest } export type GetInviteLinkState_Output = ResultError | ({ status: 'OK' } & GetInviteTokenStateResponse) -export type GetLNURLChannelLink_Input = {rpcName:'GetLNURLChannelLink'} +export type GetLNURLChannelLink_Input = { rpcName: 'GetLNURLChannelLink' } export type GetLNURLChannelLink_Output = ResultError | ({ status: 'OK' } & LnurlLinkResponse) -export type GetLiveDebitRequests_Input = {rpcName:'GetLiveDebitRequests', cb:(res: LiveDebitRequest, err:Error|null)=> void} +export type GetLiveDebitRequests_Input = { rpcName: 'GetLiveDebitRequests', cb: (res: LiveDebitRequest, err: Error | null) => void } export type GetLiveDebitRequests_Output = ResultError | { status: 'OK' } -export type GetLiveUserOperations_Input = {rpcName:'GetLiveUserOperations', cb:(res: LiveUserOperation, err:Error|null)=> void} +export type GetLiveUserOperations_Input = { rpcName: 'GetLiveUserOperations', cb: (res: LiveUserOperation, err: Error | null) => void } export type GetLiveUserOperations_Output = ResultError | { status: 'OK' } -export type GetLndMetrics_Input = {rpcName:'GetLndMetrics', req: LndMetricsRequest} +export type GetLndMetrics_Input = { rpcName: 'GetLndMetrics', req: LndMetricsRequest } export type GetLndMetrics_Output = ResultError | ({ status: 'OK' } & LndMetrics) export type GetLnurlPayInfo_Query = { k1?: string } -export type GetLnurlPayInfo_Input = {rpcName:'GetLnurlPayInfo', query: GetLnurlPayInfo_Query} +export type GetLnurlPayInfo_Input = { rpcName: 'GetLnurlPayInfo', query: GetLnurlPayInfo_Query } export type GetLnurlPayInfo_Output = ResultError | ({ status: 'OK' } & LnurlPayInfoResponse) -export type GetLnurlPayLink_Input = {rpcName:'GetLnurlPayLink'} +export type GetLnurlPayLink_Input = { rpcName: 'GetLnurlPayLink' } export type GetLnurlPayLink_Output = ResultError | ({ status: 'OK' } & LnurlLinkResponse) export type GetLnurlWithdrawInfo_Query = { k1?: string } -export type GetLnurlWithdrawInfo_Input = {rpcName:'GetLnurlWithdrawInfo', query: GetLnurlWithdrawInfo_Query} +export type GetLnurlWithdrawInfo_Input = { rpcName: 'GetLnurlWithdrawInfo', query: GetLnurlWithdrawInfo_Query } export type GetLnurlWithdrawInfo_Output = ResultError | ({ status: 'OK' } & LnurlWithdrawInfoResponse) -export type GetLnurlWithdrawLink_Input = {rpcName:'GetLnurlWithdrawLink'} +export type GetLnurlWithdrawLink_Input = { rpcName: 'GetLnurlWithdrawLink' } export type GetLnurlWithdrawLink_Output = ResultError | ({ status: 'OK' } & LnurlLinkResponse) -export type GetMigrationUpdate_Input = {rpcName:'GetMigrationUpdate', cb:(res: MigrationUpdate, err:Error|null)=> void} +export type GetMigrationUpdate_Input = { rpcName: 'GetMigrationUpdate', cb: (res: MigrationUpdate, err: Error | null) => void } export type GetMigrationUpdate_Output = ResultError | { status: 'OK' } -export type GetPaymentState_Input = {rpcName:'GetPaymentState', req: GetPaymentStateRequest} +export type GetNPubLinkingState_Input = { rpcName: 'GetNPubLinkingState', req: GetNPubLinking } +export type GetNPubLinkingState_Output = ResultError | ({ status: 'OK' } & NPubLinking) + +export type GetPaymentState_Input = { rpcName: 'GetPaymentState', req: GetPaymentStateRequest } export type GetPaymentState_Output = ResultError | ({ status: 'OK' } & PaymentState) -export type GetSeed_Input = {rpcName:'GetSeed'} +export type GetSeed_Input = { rpcName: 'GetSeed' } export type GetSeed_Output = ResultError | ({ status: 'OK' } & LndSeed) -export type GetUsageMetrics_Input = {rpcName:'GetUsageMetrics'} +export type GetUsageMetrics_Input = { rpcName: 'GetUsageMetrics' } export type GetUsageMetrics_Output = ResultError | ({ status: 'OK' } & UsageMetrics) -export type GetUserInfo_Input = {rpcName:'GetUserInfo'} +export type GetUserInfo_Input = { rpcName: 'GetUserInfo' } export type GetUserInfo_Output = ResultError | ({ status: 'OK' } & UserInfo) -export type GetUserOperations_Input = {rpcName:'GetUserOperations', req: GetUserOperationsRequest} +export type GetUserOperations_Input = { rpcName: 'GetUserOperations', req: GetUserOperationsRequest } export type GetUserOperations_Output = ResultError | ({ status: 'OK' } & GetUserOperationsResponse) export type HandleLnurlAddress_RouteParams = { address_name: string } -export type HandleLnurlAddress_Input = {rpcName:'HandleLnurlAddress', params: HandleLnurlAddress_RouteParams} +export type HandleLnurlAddress_Input = { rpcName: 'HandleLnurlAddress', params: HandleLnurlAddress_RouteParams } export type HandleLnurlAddress_Output = ResultError | ({ status: 'OK' } & LnurlPayInfoResponse) export type HandleLnurlPay_Query = { @@ -164,150 +173,153 @@ export type HandleLnurlPay_Query = { lnurl?: string nostr?: string } -export type HandleLnurlPay_Input = {rpcName:'HandleLnurlPay', query: HandleLnurlPay_Query} +export type HandleLnurlPay_Input = { rpcName: 'HandleLnurlPay', query: HandleLnurlPay_Query } export type HandleLnurlPay_Output = ResultError | ({ status: 'OK' } & HandleLnurlPayResponse) export type HandleLnurlWithdraw_Query = { k1?: string pr?: string } -export type HandleLnurlWithdraw_Input = {rpcName:'HandleLnurlWithdraw', query: HandleLnurlWithdraw_Query} +export type HandleLnurlWithdraw_Input = { rpcName: 'HandleLnurlWithdraw', query: HandleLnurlWithdraw_Query } export type HandleLnurlWithdraw_Output = ResultError | { status: 'OK' } -export type Health_Input = {rpcName:'Health'} +export type Health_Input = { rpcName: 'Health' } export type Health_Output = ResultError | { status: 'OK' } -export type LinkNPubThroughToken_Input = {rpcName:'LinkNPubThroughToken', req: LinkNPubThroughTokenRequest} +export type LinkNPubThroughToken_Input = { rpcName: 'LinkNPubThroughToken', req: LinkNPubThroughTokenRequest } export type LinkNPubThroughToken_Output = ResultError | { status: 'OK' } -export type ListChannels_Input = {rpcName:'ListChannels'} +export type ListChannels_Input = { rpcName: 'ListChannels' } export type ListChannels_Output = ResultError | ({ status: 'OK' } & LndChannels) -export type LndGetInfo_Input = {rpcName:'LndGetInfo', req: LndGetInfoRequest} +export type LndGetInfo_Input = { rpcName: 'LndGetInfo', req: LndGetInfoRequest } export type LndGetInfo_Output = ResultError | ({ status: 'OK' } & LndGetInfoResponse) -export type NewAddress_Input = {rpcName:'NewAddress', req: NewAddressRequest} +export type NewAddress_Input = { rpcName: 'NewAddress', req: NewAddressRequest } export type NewAddress_Output = ResultError | ({ status: 'OK' } & NewAddressResponse) -export type NewInvoice_Input = {rpcName:'NewInvoice', req: NewInvoiceRequest} +export type NewInvoice_Input = { rpcName: 'NewInvoice', req: NewInvoiceRequest } export type NewInvoice_Output = ResultError | ({ status: 'OK' } & NewInvoiceResponse) export type NewProductInvoice_Query = { id?: string } -export type NewProductInvoice_Input = {rpcName:'NewProductInvoice', query: NewProductInvoice_Query} +export type NewProductInvoice_Input = { rpcName: 'NewProductInvoice', query: NewProductInvoice_Query } export type NewProductInvoice_Output = ResultError | ({ status: 'OK' } & NewInvoiceResponse) -export type OpenChannel_Input = {rpcName:'OpenChannel', req: OpenChannelRequest} +export type OpenChannel_Input = { rpcName: 'OpenChannel', req: OpenChannelRequest } export type OpenChannel_Output = ResultError | ({ status: 'OK' } & OpenChannelResponse) -export type PayAddress_Input = {rpcName:'PayAddress', req: PayAddressRequest} +export type PayAddress_Input = { rpcName: 'PayAddress', req: PayAddressRequest } export type PayAddress_Output = ResultError | ({ status: 'OK' } & PayAddressResponse) -export type PayAppUserInvoice_Input = {rpcName:'PayAppUserInvoice', req: PayAppUserInvoiceRequest} +export type PayAppUserInvoice_Input = { rpcName: 'PayAppUserInvoice', req: PayAppUserInvoiceRequest } export type PayAppUserInvoice_Output = ResultError | ({ status: 'OK' } & PayInvoiceResponse) -export type PayInvoice_Input = {rpcName:'PayInvoice', req: PayInvoiceRequest} +export type PayInvoice_Input = { rpcName: 'PayInvoice', req: PayInvoiceRequest } export type PayInvoice_Output = ResultError | ({ status: 'OK' } & PayInvoiceResponse) -export type RequestNPubLinkingToken_Input = {rpcName:'RequestNPubLinkingToken', req: RequestNPubLinkingTokenRequest} +export type RequestNPubLinkingToken_Input = { rpcName: 'RequestNPubLinkingToken', req: RequestNPubLinkingTokenRequest } export type RequestNPubLinkingToken_Output = ResultError | ({ status: 'OK' } & RequestNPubLinkingTokenResponse) -export type ResetDebit_Input = {rpcName:'ResetDebit', req: DebitOperation} +export type ResetDebit_Input = { rpcName: 'ResetDebit', req: DebitOperation } export type ResetDebit_Output = ResultError | { status: 'OK' } -export type ResetNPubLinkingToken_Input = {rpcName:'ResetNPubLinkingToken', req: RequestNPubLinkingTokenRequest} +export type ResetNPubLinkingToken_Input = { rpcName: 'ResetNPubLinkingToken', req: RequestNPubLinkingTokenRequest } export type ResetNPubLinkingToken_Output = ResultError | ({ status: 'OK' } & RequestNPubLinkingTokenResponse) -export type RespondToDebit_Input = {rpcName:'RespondToDebit', req: DebitResponse} +export type RespondToDebit_Input = { rpcName: 'RespondToDebit', req: DebitResponse } export type RespondToDebit_Output = ResultError | { status: 'OK' } -export type SendAppUserToAppPayment_Input = {rpcName:'SendAppUserToAppPayment', req: SendAppUserToAppPaymentRequest} +export type SendAppUserToAppPayment_Input = { rpcName: 'SendAppUserToAppPayment', req: SendAppUserToAppPaymentRequest } export type SendAppUserToAppPayment_Output = ResultError | { status: 'OK' } -export type SendAppUserToAppUserPayment_Input = {rpcName:'SendAppUserToAppUserPayment', req: SendAppUserToAppUserPaymentRequest} +export type SendAppUserToAppUserPayment_Input = { rpcName: 'SendAppUserToAppUserPayment', req: SendAppUserToAppUserPaymentRequest } export type SendAppUserToAppUserPayment_Output = ResultError | { status: 'OK' } -export type SetMockAppBalance_Input = {rpcName:'SetMockAppBalance', req: SetMockAppBalanceRequest} +export type SetMockAppBalance_Input = { rpcName: 'SetMockAppBalance', req: SetMockAppBalanceRequest } export type SetMockAppBalance_Output = ResultError | { status: 'OK' } -export type SetMockAppUserBalance_Input = {rpcName:'SetMockAppUserBalance', req: SetMockAppUserBalanceRequest} +export type SetMockAppUserBalance_Input = { rpcName: 'SetMockAppUserBalance', req: SetMockAppUserBalanceRequest } export type SetMockAppUserBalance_Output = ResultError | { status: 'OK' } -export type SetMockInvoiceAsPaid_Input = {rpcName:'SetMockInvoiceAsPaid', req: SetMockInvoiceAsPaidRequest} +export type SetMockInvoiceAsPaid_Input = { rpcName: 'SetMockInvoiceAsPaid', req: SetMockInvoiceAsPaidRequest } export type SetMockInvoiceAsPaid_Output = ResultError | { status: 'OK' } -export type UpdateCallbackUrl_Input = {rpcName:'UpdateCallbackUrl', req: CallbackUrl} +export type UpdateCallbackUrl_Input = { rpcName: 'UpdateCallbackUrl', req: CallbackUrl } export type UpdateCallbackUrl_Output = ResultError | ({ status: 'OK' } & CallbackUrl) -export type UseInviteLink_Input = {rpcName:'UseInviteLink', req: UseInviteLinkRequest} +export type UseInviteLink_Input = { rpcName: 'UseInviteLink', req: UseInviteLinkRequest } export type UseInviteLink_Output = ResultError | { status: 'OK' } -export type UserHealth_Input = {rpcName:'UserHealth'} +export type UserHealth_Input = { rpcName: 'UserHealth' } export type UserHealth_Output = ResultError | { status: 'OK' } export type ServerMethods = { - AddApp?: (req: AddApp_Input & {ctx: AdminContext }) => Promise - AddAppInvoice?: (req: AddAppInvoice_Input & {ctx: AppContext }) => Promise - AddAppUser?: (req: AddAppUser_Input & {ctx: AppContext }) => Promise - AddAppUserInvoice?: (req: AddAppUserInvoice_Input & {ctx: AppContext }) => Promise - AddProduct?: (req: AddProduct_Input & {ctx: UserContext }) => Promise - AuthApp?: (req: AuthApp_Input & {ctx: AdminContext }) => Promise - AuthorizeDebit?: (req: AuthorizeDebit_Input & {ctx: UserContext }) => Promise - BanDebit?: (req: BanDebit_Input & {ctx: UserContext }) => Promise - BanUser?: (req: BanUser_Input & {ctx: AdminContext }) => Promise - CreateOneTimeInviteLink?: (req: CreateOneTimeInviteLink_Input & {ctx: AdminContext }) => Promise - DecodeInvoice?: (req: DecodeInvoice_Input & {ctx: UserContext }) => Promise - EditDebit?: (req: EditDebit_Input & {ctx: UserContext }) => Promise - EncryptionExchange?: (req: EncryptionExchange_Input & {ctx: GuestContext }) => Promise - EnrollAdminToken?: (req: EnrollAdminToken_Input & {ctx: UserContext }) => Promise - GetApp?: (req: GetApp_Input & {ctx: AppContext }) => Promise - GetAppUser?: (req: GetAppUser_Input & {ctx: AppContext }) => Promise - GetAppUserLNURLInfo?: (req: GetAppUserLNURLInfo_Input & {ctx: AppContext }) => Promise - GetAppsMetrics?: (req: GetAppsMetrics_Input & {ctx: MetricsContext }) => Promise - GetDebitAuthorizations?: (req: GetDebitAuthorizations_Input & {ctx: UserContext }) => Promise - GetHttpCreds?: (req: GetHttpCreds_Input & {ctx: UserContext }) => Promise - GetInviteLinkState?: (req: GetInviteLinkState_Input & {ctx: AdminContext }) => Promise - GetLNURLChannelLink?: (req: GetLNURLChannelLink_Input & {ctx: UserContext }) => Promise - GetLiveDebitRequests?: (req: GetLiveDebitRequests_Input & {ctx: UserContext }) => Promise - GetLiveUserOperations?: (req: GetLiveUserOperations_Input & {ctx: UserContext }) => Promise - GetLndMetrics?: (req: GetLndMetrics_Input & {ctx: MetricsContext }) => Promise - GetLnurlPayInfo?: (req: GetLnurlPayInfo_Input & {ctx: GuestContext }) => Promise - GetLnurlPayLink?: (req: GetLnurlPayLink_Input & {ctx: UserContext }) => Promise - GetLnurlWithdrawInfo?: (req: GetLnurlWithdrawInfo_Input & {ctx: GuestContext }) => Promise - GetLnurlWithdrawLink?: (req: GetLnurlWithdrawLink_Input & {ctx: UserContext }) => Promise - GetMigrationUpdate?: (req: GetMigrationUpdate_Input & {ctx: UserContext }) => Promise - GetPaymentState?: (req: GetPaymentState_Input & {ctx: UserContext }) => Promise - GetSeed?: (req: GetSeed_Input & {ctx: AdminContext }) => Promise - GetUsageMetrics?: (req: GetUsageMetrics_Input & {ctx: MetricsContext }) => Promise - GetUserInfo?: (req: GetUserInfo_Input & {ctx: UserContext }) => Promise - GetUserOperations?: (req: GetUserOperations_Input & {ctx: UserContext }) => Promise - HandleLnurlAddress?: (req: HandleLnurlAddress_Input & {ctx: GuestContext }) => Promise - HandleLnurlPay?: (req: HandleLnurlPay_Input & {ctx: GuestContext }) => Promise - HandleLnurlWithdraw?: (req: HandleLnurlWithdraw_Input & {ctx: GuestContext }) => Promise - Health?: (req: Health_Input & {ctx: GuestContext }) => Promise - LinkNPubThroughToken?: (req: LinkNPubThroughToken_Input & {ctx: GuestWithPubContext }) => Promise - ListChannels?: (req: ListChannels_Input & {ctx: AdminContext }) => Promise - LndGetInfo?: (req: LndGetInfo_Input & {ctx: AdminContext }) => Promise - NewAddress?: (req: NewAddress_Input & {ctx: UserContext }) => Promise - NewInvoice?: (req: NewInvoice_Input & {ctx: UserContext }) => Promise - NewProductInvoice?: (req: NewProductInvoice_Input & {ctx: UserContext }) => Promise - OpenChannel?: (req: OpenChannel_Input & {ctx: UserContext }) => Promise - PayAddress?: (req: PayAddress_Input & {ctx: UserContext }) => Promise - PayAppUserInvoice?: (req: PayAppUserInvoice_Input & {ctx: AppContext }) => Promise - PayInvoice?: (req: PayInvoice_Input & {ctx: UserContext }) => Promise - RequestNPubLinkingToken?: (req: RequestNPubLinkingToken_Input & {ctx: AppContext }) => Promise - ResetDebit?: (req: ResetDebit_Input & {ctx: UserContext }) => Promise - ResetNPubLinkingToken?: (req: ResetNPubLinkingToken_Input & {ctx: AppContext }) => Promise - RespondToDebit?: (req: RespondToDebit_Input & {ctx: UserContext }) => Promise - SendAppUserToAppPayment?: (req: SendAppUserToAppPayment_Input & {ctx: AppContext }) => Promise - SendAppUserToAppUserPayment?: (req: SendAppUserToAppUserPayment_Input & {ctx: AppContext }) => Promise - SetMockAppBalance?: (req: SetMockAppBalance_Input & {ctx: AppContext }) => Promise - SetMockAppUserBalance?: (req: SetMockAppUserBalance_Input & {ctx: AppContext }) => Promise - SetMockInvoiceAsPaid?: (req: SetMockInvoiceAsPaid_Input & {ctx: GuestContext }) => Promise - UpdateCallbackUrl?: (req: UpdateCallbackUrl_Input & {ctx: UserContext }) => Promise - UseInviteLink?: (req: UseInviteLink_Input & {ctx: GuestWithPubContext }) => Promise - UserHealth?: (req: UserHealth_Input & {ctx: UserContext }) => Promise + AddApp?: (req: AddApp_Input & { ctx: AdminContext }) => Promise + AddAppInvoice?: (req: AddAppInvoice_Input & { ctx: AppContext }) => Promise + AddAppUser?: (req: AddAppUser_Input & { ctx: AppContext }) => Promise + AddAppUserInvoice?: (req: AddAppUserInvoice_Input & { ctx: AppContext }) => Promise + AddPeer?: (req: AddPeer_Input & { ctx: AdminContext }) => Promise + AddProduct?: (req: AddProduct_Input & { ctx: UserContext }) => Promise + AuthApp?: (req: AuthApp_Input & { ctx: AdminContext }) => Promise + AuthorizeDebit?: (req: AuthorizeDebit_Input & { ctx: UserContext }) => Promise + BanDebit?: (req: BanDebit_Input & { ctx: UserContext }) => Promise + BanUser?: (req: BanUser_Input & { ctx: AdminContext }) => Promise + CloseChannel?: (req: CloseChannel_Input & { ctx: AdminContext }) => Promise + CreateOneTimeInviteLink?: (req: CreateOneTimeInviteLink_Input & { ctx: AdminContext }) => Promise + DecodeInvoice?: (req: DecodeInvoice_Input & { ctx: UserContext }) => Promise + EditDebit?: (req: EditDebit_Input & { ctx: UserContext }) => Promise + EncryptionExchange?: (req: EncryptionExchange_Input & { ctx: GuestContext }) => Promise + EnrollAdminToken?: (req: EnrollAdminToken_Input & { ctx: UserContext }) => Promise + GetApp?: (req: GetApp_Input & { ctx: AppContext }) => Promise + GetAppUser?: (req: GetAppUser_Input & { ctx: AppContext }) => Promise + GetAppUserLNURLInfo?: (req: GetAppUserLNURLInfo_Input & { ctx: AppContext }) => Promise + GetAppsMetrics?: (req: GetAppsMetrics_Input & { ctx: MetricsContext }) => Promise + GetDebitAuthorizations?: (req: GetDebitAuthorizations_Input & { ctx: UserContext }) => Promise + GetHttpCreds?: (req: GetHttpCreds_Input & { ctx: UserContext }) => Promise + GetInviteLinkState?: (req: GetInviteLinkState_Input & { ctx: AdminContext }) => Promise + GetLNURLChannelLink?: (req: GetLNURLChannelLink_Input & { ctx: UserContext }) => Promise + GetLiveDebitRequests?: (req: GetLiveDebitRequests_Input & { ctx: UserContext }) => Promise + GetLiveUserOperations?: (req: GetLiveUserOperations_Input & { ctx: UserContext }) => Promise + GetLndMetrics?: (req: GetLndMetrics_Input & { ctx: MetricsContext }) => Promise + GetLnurlPayInfo?: (req: GetLnurlPayInfo_Input & { ctx: GuestContext }) => Promise + GetLnurlPayLink?: (req: GetLnurlPayLink_Input & { ctx: UserContext }) => Promise + GetLnurlWithdrawInfo?: (req: GetLnurlWithdrawInfo_Input & { ctx: GuestContext }) => Promise + GetLnurlWithdrawLink?: (req: GetLnurlWithdrawLink_Input & { ctx: UserContext }) => Promise + GetMigrationUpdate?: (req: GetMigrationUpdate_Input & { ctx: UserContext }) => Promise + GetNPubLinkingState?: (req: GetNPubLinkingState_Input & { ctx: AppContext }) => Promise + GetPaymentState?: (req: GetPaymentState_Input & { ctx: UserContext }) => Promise + GetSeed?: (req: GetSeed_Input & { ctx: AdminContext }) => Promise + GetUsageMetrics?: (req: GetUsageMetrics_Input & { ctx: MetricsContext }) => Promise + GetUserInfo?: (req: GetUserInfo_Input & { ctx: UserContext }) => Promise + GetUserOperations?: (req: GetUserOperations_Input & { ctx: UserContext }) => Promise + HandleLnurlAddress?: (req: HandleLnurlAddress_Input & { ctx: GuestContext }) => Promise + HandleLnurlPay?: (req: HandleLnurlPay_Input & { ctx: GuestContext }) => Promise + HandleLnurlWithdraw?: (req: HandleLnurlWithdraw_Input & { ctx: GuestContext }) => Promise + Health?: (req: Health_Input & { ctx: GuestContext }) => Promise + LinkNPubThroughToken?: (req: LinkNPubThroughToken_Input & { ctx: GuestWithPubContext }) => Promise + ListChannels?: (req: ListChannels_Input & { ctx: AdminContext }) => Promise + LndGetInfo?: (req: LndGetInfo_Input & { ctx: AdminContext }) => Promise + NewAddress?: (req: NewAddress_Input & { ctx: UserContext }) => Promise + NewInvoice?: (req: NewInvoice_Input & { ctx: UserContext }) => Promise + NewProductInvoice?: (req: NewProductInvoice_Input & { ctx: UserContext }) => Promise + OpenChannel?: (req: OpenChannel_Input & { ctx: AdminContext }) => Promise + PayAddress?: (req: PayAddress_Input & { ctx: UserContext }) => Promise + PayAppUserInvoice?: (req: PayAppUserInvoice_Input & { ctx: AppContext }) => Promise + PayInvoice?: (req: PayInvoice_Input & { ctx: UserContext }) => Promise + RequestNPubLinkingToken?: (req: RequestNPubLinkingToken_Input & { ctx: AppContext }) => Promise + ResetDebit?: (req: ResetDebit_Input & { ctx: UserContext }) => Promise + ResetNPubLinkingToken?: (req: ResetNPubLinkingToken_Input & { ctx: AppContext }) => Promise + RespondToDebit?: (req: RespondToDebit_Input & { ctx: UserContext }) => Promise + SendAppUserToAppPayment?: (req: SendAppUserToAppPayment_Input & { ctx: AppContext }) => Promise + SendAppUserToAppUserPayment?: (req: SendAppUserToAppUserPayment_Input & { ctx: AppContext }) => Promise + SetMockAppBalance?: (req: SetMockAppBalance_Input & { ctx: AppContext }) => Promise + SetMockAppUserBalance?: (req: SetMockAppUserBalance_Input & { ctx: AppContext }) => Promise + SetMockInvoiceAsPaid?: (req: SetMockInvoiceAsPaid_Input & { ctx: GuestContext }) => Promise + UpdateCallbackUrl?: (req: UpdateCallbackUrl_Input & { ctx: UserContext }) => Promise + UseInviteLink?: (req: UseInviteLink_Input & { ctx: GuestWithPubContext }) => Promise + UserHealth?: (req: UserHealth_Input & { ctx: UserContext }) => Promise } export enum AddressType { @@ -366,7 +378,7 @@ export const AddAppInvoiceRequestValidate = (o?: AddAppInvoiceRequest, opts: Add const invoice_reqErr = NewInvoiceRequestValidate(o.invoice_req, opts.invoice_req_Options, `${path}.invoice_req`) if (invoice_reqErr !== null) return invoice_reqErr - + if (typeof o.payer_identifier !== 'string') return new Error(`${path}.payer_identifier: is not a string`) if (opts.payer_identifier_CustomCheck && !opts.payer_identifier_CustomCheck(o.payer_identifier)) return new Error(`${path}.payer_identifier: custom check failed`) @@ -420,7 +432,7 @@ export const AddAppUserInvoiceRequestValidate = (o?: AddAppUserInvoiceRequest, o const invoice_reqErr = NewInvoiceRequestValidate(o.invoice_req, opts.invoice_req_Options, `${path}.invoice_req`) if (invoice_reqErr !== null) return invoice_reqErr - + if (typeof o.payer_identifier !== 'string') return new Error(`${path}.payer_identifier: is not a string`) if (opts.payer_identifier_CustomCheck && !opts.payer_identifier_CustomCheck(o.payer_identifier)) return new Error(`${path}.payer_identifier: custom check failed`) @@ -459,6 +471,34 @@ export const AddAppUserRequestValidate = (o?: AddAppUserRequest, opts: AddAppUse return null } +export type AddPeerRequest = { + host: string + port: number + pubkey: string +} +export const AddPeerRequestOptionalFields: [] = [] +export type AddPeerRequestOptions = OptionsBaseMessage & { + checkOptionalsAreSet?: [] + host_CustomCheck?: (v: string) => boolean + port_CustomCheck?: (v: number) => boolean + pubkey_CustomCheck?: (v: string) => boolean +} +export const AddPeerRequestValidate = (o?: AddPeerRequest, opts: AddPeerRequestOptions = {}, path: string = 'AddPeerRequest::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.host !== 'string') return new Error(`${path}.host: is not a string`) + if (opts.host_CustomCheck && !opts.host_CustomCheck(o.host)) return new Error(`${path}.host: custom check failed`) + + if (typeof o.port !== 'number') return new Error(`${path}.port: is not a number`) + if (opts.port_CustomCheck && !opts.port_CustomCheck(o.port)) return new Error(`${path}.port: custom check failed`) + + if (typeof o.pubkey !== 'string') return new Error(`${path}.pubkey: is not a string`) + if (opts.pubkey_CustomCheck && !opts.pubkey_CustomCheck(o.pubkey)) return new Error(`${path}.pubkey: custom check failed`) + + return null +} + export type AddProductRequest = { name: string price_sats: number @@ -513,7 +553,7 @@ export const AppMetricsValidate = (o?: AppMetrics, opts: AppMetricsOptions = {}, const appErr = ApplicationValidate(o.app, opts.app_Options, `${path}.app`) if (appErr !== null) return appErr - + if (typeof o.available !== 'number') return new Error(`${path}.available: is not a number`) if (opts.available_CustomCheck && !opts.available_CustomCheck(o.available)) return new Error(`${path}.available: custom check failed`) @@ -542,7 +582,7 @@ export const AppMetricsValidate = (o?: AppMetrics, opts: AppMetricsOptions = {}, const usersErr = UsersInfoValidate(o.users, opts.users_Options, `${path}.users`) if (usersErr !== null) return usersErr - + return null } @@ -568,7 +608,7 @@ export const AppUserValidate = (o?: AppUser, opts: AppUserOptions = {}, path: st const infoErr = UserInfoValidate(o.info, opts.info_Options, `${path}.info`) if (infoErr !== null) return infoErr - + if (typeof o.max_withdrawable !== 'number') return new Error(`${path}.max_withdrawable: is not a number`) if (opts.max_withdrawable_CustomCheck && !opts.max_withdrawable_CustomCheck(o.max_withdrawable)) return new Error(`${path}.max_withdrawable: custom check failed`) @@ -677,7 +717,7 @@ export const AuthAppValidate = (o?: AuthApp, opts: AuthAppOptions = {}, path: st const appErr = ApplicationValidate(o.app, opts.app_Options, `${path}.app`) if (appErr !== null) return appErr - + if (typeof o.auth_token !== 'string') return new Error(`${path}.auth_token: is not a string`) if (opts.auth_token_CustomCheck && !opts.auth_token_CustomCheck(o.auth_token)) return new Error(`${path}.auth_token: custom check failed`) @@ -806,6 +846,57 @@ export const CallbackUrlValidate = (o?: CallbackUrl, opts: CallbackUrlOptions = return null } +export type CloseChannelRequest = { + force: boolean + funding_txid: string + output_index: number + sat_per_v_byte: number +} +export const CloseChannelRequestOptionalFields: [] = [] +export type CloseChannelRequestOptions = OptionsBaseMessage & { + checkOptionalsAreSet?: [] + force_CustomCheck?: (v: boolean) => boolean + funding_txid_CustomCheck?: (v: string) => boolean + output_index_CustomCheck?: (v: number) => boolean + sat_per_v_byte_CustomCheck?: (v: number) => boolean +} +export const CloseChannelRequestValidate = (o?: CloseChannelRequest, opts: CloseChannelRequestOptions = {}, path: string = 'CloseChannelRequest::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.force !== 'boolean') return new Error(`${path}.force: is not a boolean`) + if (opts.force_CustomCheck && !opts.force_CustomCheck(o.force)) return new Error(`${path}.force: custom check failed`) + + if (typeof o.funding_txid !== 'string') return new Error(`${path}.funding_txid: is not a string`) + if (opts.funding_txid_CustomCheck && !opts.funding_txid_CustomCheck(o.funding_txid)) return new Error(`${path}.funding_txid: custom check failed`) + + if (typeof o.output_index !== 'number') return new Error(`${path}.output_index: is not a number`) + if (opts.output_index_CustomCheck && !opts.output_index_CustomCheck(o.output_index)) return new Error(`${path}.output_index: custom check failed`) + + if (typeof o.sat_per_v_byte !== 'number') return new Error(`${path}.sat_per_v_byte: is not a number`) + if (opts.sat_per_v_byte_CustomCheck && !opts.sat_per_v_byte_CustomCheck(o.sat_per_v_byte)) return new Error(`${path}.sat_per_v_byte: custom check failed`) + + return null +} + +export type CloseChannelResponse = { + closing_txid: string +} +export const CloseChannelResponseOptionalFields: [] = [] +export type CloseChannelResponseOptions = OptionsBaseMessage & { + checkOptionalsAreSet?: [] + closing_txid_CustomCheck?: (v: string) => boolean +} +export const CloseChannelResponseValidate = (o?: CloseChannelResponse, opts: CloseChannelResponseOptions = {}, path: string = 'CloseChannelResponse::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.closing_txid !== 'string') return new Error(`${path}.closing_txid: is not a string`) + if (opts.closing_txid_CustomCheck && !opts.closing_txid_CustomCheck(o.closing_txid)) return new Error(`${path}.closing_txid: custom check failed`) + + return null +} + export type ClosedChannel = { capacity: number channel_id: string @@ -1044,7 +1135,7 @@ export const DebitResponseValidate = (o?: DebitResponse, opts: DebitResponseOpti const responseErr = DebitResponse_responseValidate(o.response, opts.response_Options, `${path}.response`) if (responseErr !== null) return responseErr - + return null } @@ -1063,7 +1154,7 @@ export const DebitRuleValidate = (o?: DebitRule, opts: DebitRuleOptions = {}, pa const ruleErr = DebitRule_ruleValidate(o.rule, opts.rule_Options, `${path}.rule`) if (ruleErr !== null) return ruleErr - + return null } @@ -1227,6 +1318,24 @@ export const GetAppUserRequestValidate = (o?: GetAppUserRequest, opts: GetAppUse return null } +export type GetChannelPolicyRequest = { + channel_id: string +} +export const GetChannelPolicyRequestOptionalFields: [] = [] +export type GetChannelPolicyRequestOptions = OptionsBaseMessage & { + checkOptionalsAreSet?: [] + channel_id_CustomCheck?: (v: string) => boolean +} +export const GetChannelPolicyRequestValidate = (o?: GetChannelPolicyRequest, opts: GetChannelPolicyRequestOptions = {}, path: string = 'GetChannelPolicyRequest::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.channel_id !== 'string') return new Error(`${path}.channel_id: is not a string`) + if (opts.channel_id_CustomCheck && !opts.channel_id_CustomCheck(o.channel_id)) return new Error(`${path}.channel_id: custom check failed`) + + return null +} + export type GetInviteTokenStateRequest = { invite_token: string } @@ -1263,6 +1372,24 @@ export const GetInviteTokenStateResponseValidate = (o?: GetInviteTokenStateRespo return null } +export type GetNPubLinking = { + user_identifier: string +} +export const GetNPubLinkingOptionalFields: [] = [] +export type GetNPubLinkingOptions = OptionsBaseMessage & { + checkOptionalsAreSet?: [] + user_identifier_CustomCheck?: (v: string) => boolean +} +export const GetNPubLinkingValidate = (o?: GetNPubLinking, opts: GetNPubLinkingOptions = {}, path: string = 'GetNPubLinking::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.user_identifier !== 'string') return new Error(`${path}.user_identifier: is not a string`) + if (opts.user_identifier_CustomCheck && !opts.user_identifier_CustomCheck(o.user_identifier)) return new Error(`${path}.user_identifier: custom check failed`) + + return null +} + export type GetPaymentStateRequest = { invoice: string } @@ -1371,27 +1498,27 @@ export const GetUserOperationsResponseValidate = (o?: GetUserOperationsResponse, const latestIncomingInvoiceOperationsErr = UserOperationsValidate(o.latestIncomingInvoiceOperations, opts.latestIncomingInvoiceOperations_Options, `${path}.latestIncomingInvoiceOperations`) if (latestIncomingInvoiceOperationsErr !== null) return latestIncomingInvoiceOperationsErr - + const latestIncomingTxOperationsErr = UserOperationsValidate(o.latestIncomingTxOperations, opts.latestIncomingTxOperations_Options, `${path}.latestIncomingTxOperations`) if (latestIncomingTxOperationsErr !== null) return latestIncomingTxOperationsErr - + const latestIncomingUserToUserPayemntsErr = UserOperationsValidate(o.latestIncomingUserToUserPayemnts, opts.latestIncomingUserToUserPayemnts_Options, `${path}.latestIncomingUserToUserPayemnts`) if (latestIncomingUserToUserPayemntsErr !== null) return latestIncomingUserToUserPayemntsErr - + const latestOutgoingInvoiceOperationsErr = UserOperationsValidate(o.latestOutgoingInvoiceOperations, opts.latestOutgoingInvoiceOperations_Options, `${path}.latestOutgoingInvoiceOperations`) if (latestOutgoingInvoiceOperationsErr !== null) return latestOutgoingInvoiceOperationsErr - + const latestOutgoingTxOperationsErr = UserOperationsValidate(o.latestOutgoingTxOperations, opts.latestOutgoingTxOperations_Options, `${path}.latestOutgoingTxOperations`) if (latestOutgoingTxOperationsErr !== null) return latestOutgoingTxOperationsErr - + const latestOutgoingUserToUserPayemntsErr = UserOperationsValidate(o.latestOutgoingUserToUserPayemnts, opts.latestOutgoingUserToUserPayemnts_Options, `${path}.latestOutgoingUserToUserPayemnts`) if (latestOutgoingUserToUserPayemntsErr !== null) return latestOutgoingUserToUserPayemntsErr - + return null } @@ -1506,7 +1633,7 @@ export const LiveDebitRequestValidate = (o?: LiveDebitRequest, opts: LiveDebitRe const debitErr = LiveDebitRequest_debitValidate(o.debit, opts.debit_Options, `${path}.debit`) if (debitErr !== null) return debitErr - + if (typeof o.npub !== 'string') return new Error(`${path}.npub: is not a string`) if (opts.npub_CustomCheck && !opts.npub_CustomCheck(o.npub)) return new Error(`${path}.npub: custom check failed`) @@ -1531,7 +1658,7 @@ export const LiveUserOperationValidate = (o?: LiveUserOperation, opts: LiveUserO const operationErr = UserOperationValidate(o.operation, opts.operation_Options, `${path}.operation`) if (operationErr !== null) return operationErr - + return null } @@ -1899,13 +2026,32 @@ export const MigrationUpdateValidate = (o?: MigrationUpdate, opts: MigrationUpda const closureErr = ClosureMigrationValidate(o.closure, opts.closure_Options, `${path}.closure`) if (closureErr !== null) return closureErr } - + if (typeof o.relays === 'object' || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('relays')) { const relaysErr = RelaysMigrationValidate(o.relays, opts.relays_Options, `${path}.relays`) if (relaysErr !== null) return relaysErr } - + + + return null +} + +export type NPubLinking = { + state: NPubLinking_state +} +export const NPubLinkingOptionalFields: [] = [] +export type NPubLinkingOptions = OptionsBaseMessage & { + checkOptionalsAreSet?: [] + state_Options?: NPubLinking_stateOptions +} +export const NPubLinkingValidate = (o?: NPubLinking, opts: NPubLinkingOptions = {}, path: string = 'NPubLinking::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') + + const stateErr = NPubLinking_stateValidate(o.state, opts.state_Options, `${path}.state`) + if (stateErr !== null) return stateErr + return null } @@ -1949,12 +2095,15 @@ export const NewAddressResponseValidate = (o?: NewAddressResponse, opts: NewAddr export type NewInvoiceRequest = { amountSats: number memo: string + zap?: string } -export const NewInvoiceRequestOptionalFields: [] = [] +export type NewInvoiceRequestOptionalField = 'zap' +export const NewInvoiceRequestOptionalFields: NewInvoiceRequestOptionalField[] = ['zap'] export type NewInvoiceRequestOptions = OptionsBaseMessage & { - checkOptionalsAreSet?: [] + checkOptionalsAreSet?: NewInvoiceRequestOptionalField[] amountSats_CustomCheck?: (v: number) => boolean memo_CustomCheck?: (v: string) => boolean + zap_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') @@ -1966,6 +2115,9 @@ export const NewInvoiceRequestValidate = (o?: NewInvoiceRequest, opts: NewInvoic 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`) + if ((o.zap || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('zap')) && typeof o.zap !== 'string') return new Error(`${path}.zap: is not a string`) + if (opts.zap_CustomCheck && !opts.zap_CustomCheck(o.zap)) return new Error(`${path}.zap: custom check failed`) + return null } @@ -2036,52 +2188,58 @@ export const OpenChannelValidate = (o?: OpenChannel, opts: OpenChannelOptions = } export type OpenChannelRequest = { - closeAddress: string - destination: string - fundingAmount: number - pushAmount: number -} -export const OpenChannelRequestOptionalFields: [] = [] + close_address?: string + local_funding_amount: number + node_pubkey: string + push_sat?: number + sat_per_v_byte: number +} +export type OpenChannelRequestOptionalField = 'close_address' | 'push_sat' +export const OpenChannelRequestOptionalFields: OpenChannelRequestOptionalField[] = ['close_address', 'push_sat'] export type OpenChannelRequestOptions = OptionsBaseMessage & { - checkOptionalsAreSet?: [] - closeAddress_CustomCheck?: (v: string) => boolean - destination_CustomCheck?: (v: string) => boolean - fundingAmount_CustomCheck?: (v: number) => boolean - pushAmount_CustomCheck?: (v: number) => boolean + checkOptionalsAreSet?: OpenChannelRequestOptionalField[] + close_address_CustomCheck?: (v?: string) => boolean + local_funding_amount_CustomCheck?: (v: number) => boolean + node_pubkey_CustomCheck?: (v: string) => boolean + push_sat_CustomCheck?: (v?: number) => boolean + sat_per_v_byte_CustomCheck?: (v: number) => 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.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`) + if ((o.close_address || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('close_address')) && typeof o.close_address !== 'string') return new Error(`${path}.close_address: is not a string`) + if (opts.close_address_CustomCheck && !opts.close_address_CustomCheck(o.close_address)) return new Error(`${path}.close_address: custom check failed`) - 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.local_funding_amount !== 'number') return new Error(`${path}.local_funding_amount: is not a number`) + if (opts.local_funding_amount_CustomCheck && !opts.local_funding_amount_CustomCheck(o.local_funding_amount)) return new Error(`${path}.local_funding_amount: 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.node_pubkey !== 'string') return new Error(`${path}.node_pubkey: is not a string`) + if (opts.node_pubkey_CustomCheck && !opts.node_pubkey_CustomCheck(o.node_pubkey)) return new Error(`${path}.node_pubkey: 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 ((o.push_sat || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('push_sat')) && typeof o.push_sat !== 'number') return new Error(`${path}.push_sat: is not a number`) + if (opts.push_sat_CustomCheck && !opts.push_sat_CustomCheck(o.push_sat)) return new Error(`${path}.push_sat: custom check failed`) + + if (typeof o.sat_per_v_byte !== 'number') return new Error(`${path}.sat_per_v_byte: is not a number`) + if (opts.sat_per_v_byte_CustomCheck && !opts.sat_per_v_byte_CustomCheck(o.sat_per_v_byte)) return new Error(`${path}.sat_per_v_byte: custom check failed`) return null } export type OpenChannelResponse = { - channelId: string + channel_id: string } export const OpenChannelResponseOptionalFields: [] = [] export type OpenChannelResponseOptions = OptionsBaseMessage & { checkOptionalsAreSet?: [] - channelId_CustomCheck?: (v: string) => boolean + channel_id_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`) + if (typeof o.channel_id !== 'string') return new Error(`${path}.channel_id: is not a string`) + if (opts.channel_id_CustomCheck && !opts.channel_id_CustomCheck(o.channel_id)) return new Error(`${path}.channel_id: custom check failed`) return null } @@ -2878,31 +3036,31 @@ export const enumCheckDebitResponse_response_type = (e?: DebitResponse_response_ for (const v in DebitResponse_response_type) if (e === v) return true return false } -export type DebitResponse_response = - {type:DebitResponse_response_type.DENIED, denied:Empty}| - {type:DebitResponse_response_type.INVOICE, invoice:string} +export type DebitResponse_response = + { type: DebitResponse_response_type.DENIED, denied: Empty } | + { type: DebitResponse_response_type.INVOICE, invoice: string } export type DebitResponse_responseOptions = { denied_Options?: EmptyOptions invoice_CustomCheck?: (v: string) => boolean } -export const DebitResponse_responseValidate = (o?: DebitResponse_response, opts:DebitResponse_responseOptions = {}, path: string = 'DebitResponse_response::root.'): Error | null => { +export const DebitResponse_responseValidate = (o?: DebitResponse_response, opts: DebitResponse_responseOptions = {}, path: string = 'DebitResponse_response::root.'): Error | null => { if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null') const stringType: string = o.type switch (o.type) { case DebitResponse_response_type.DENIED: - const deniedErr = EmptyValidate(o.denied, opts.denied_Options, `${path}.denied`) - if (deniedErr !== null) return deniedErr - + const deniedErr = EmptyValidate(o.denied, opts.denied_Options, `${path}.denied`) + if (deniedErr !== null) return deniedErr + - break + break case DebitResponse_response_type.INVOICE: - 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.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`) - break + break default: - return new Error(path + ': unknown type '+ stringType) + return new Error(path + ': unknown type ' + stringType) } return null } @@ -2914,68 +3072,121 @@ export const enumCheckDebitRule_rule_type = (e?: DebitRule_rule_type): boolean = for (const v in DebitRule_rule_type) if (e === v) return true return false } -export type DebitRule_rule = - {type:DebitRule_rule_type.EXPIRATION_RULE, expiration_rule:DebitExpirationRule}| - {type:DebitRule_rule_type.FREQUENCY_RULE, frequency_rule:FrequencyRule} +export type DebitRule_rule = + { type: DebitRule_rule_type.EXPIRATION_RULE, expiration_rule: DebitExpirationRule } | + { type: DebitRule_rule_type.FREQUENCY_RULE, frequency_rule: FrequencyRule } export type DebitRule_ruleOptions = { expiration_rule_Options?: DebitExpirationRuleOptions frequency_rule_Options?: FrequencyRuleOptions } -export const DebitRule_ruleValidate = (o?: DebitRule_rule, opts:DebitRule_ruleOptions = {}, path: string = 'DebitRule_rule::root.'): Error | null => { +export const DebitRule_ruleValidate = (o?: DebitRule_rule, opts: DebitRule_ruleOptions = {}, path: string = 'DebitRule_rule::root.'): Error | null => { if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null') const stringType: string = o.type switch (o.type) { case DebitRule_rule_type.EXPIRATION_RULE: - const expiration_ruleErr = DebitExpirationRuleValidate(o.expiration_rule, opts.expiration_rule_Options, `${path}.expiration_rule`) - if (expiration_ruleErr !== null) return expiration_ruleErr - + const expiration_ruleErr = DebitExpirationRuleValidate(o.expiration_rule, opts.expiration_rule_Options, `${path}.expiration_rule`) + if (expiration_ruleErr !== null) return expiration_ruleErr - break + + break case DebitRule_rule_type.FREQUENCY_RULE: - const frequency_ruleErr = FrequencyRuleValidate(o.frequency_rule, opts.frequency_rule_Options, `${path}.frequency_rule`) - if (frequency_ruleErr !== null) return frequency_ruleErr - + const frequency_ruleErr = FrequencyRuleValidate(o.frequency_rule, opts.frequency_rule_Options, `${path}.frequency_rule`) + if (frequency_ruleErr !== null) return frequency_ruleErr + - break + break default: - return new Error(path + ': unknown type '+ stringType) + return new Error(path + ': unknown type ' + stringType) } return null } export enum LiveDebitRequest_debit_type { FREQUENCY = 'frequency', + FULL_ACCESS = 'full_access', INVOICE = 'invoice', } export const enumCheckLiveDebitRequest_debit_type = (e?: LiveDebitRequest_debit_type): boolean => { for (const v in LiveDebitRequest_debit_type) if (e === v) return true return false } -export type LiveDebitRequest_debit = - {type:LiveDebitRequest_debit_type.FREQUENCY, frequency:FrequencyRule}| - {type:LiveDebitRequest_debit_type.INVOICE, invoice:string} +export type LiveDebitRequest_debit = + { type: LiveDebitRequest_debit_type.FREQUENCY, frequency: FrequencyRule } | + { type: LiveDebitRequest_debit_type.FULL_ACCESS, full_access: Empty } | + { type: LiveDebitRequest_debit_type.INVOICE, invoice: string } export type LiveDebitRequest_debitOptions = { frequency_Options?: FrequencyRuleOptions + full_access_Options?: EmptyOptions invoice_CustomCheck?: (v: string) => boolean } -export const LiveDebitRequest_debitValidate = (o?: LiveDebitRequest_debit, opts:LiveDebitRequest_debitOptions = {}, path: string = 'LiveDebitRequest_debit::root.'): Error | null => { +export const LiveDebitRequest_debitValidate = (o?: LiveDebitRequest_debit, opts: LiveDebitRequest_debitOptions = {}, path: string = 'LiveDebitRequest_debit::root.'): Error | null => { if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null') const stringType: string = o.type switch (o.type) { case LiveDebitRequest_debit_type.FREQUENCY: - const frequencyErr = FrequencyRuleValidate(o.frequency, opts.frequency_Options, `${path}.frequency`) - if (frequencyErr !== null) return frequencyErr - + const frequencyErr = FrequencyRuleValidate(o.frequency, opts.frequency_Options, `${path}.frequency`) + if (frequencyErr !== null) return frequencyErr - break + + break + case LiveDebitRequest_debit_type.FULL_ACCESS: + const full_accessErr = EmptyValidate(o.full_access, opts.full_access_Options, `${path}.full_access`) + if (full_accessErr !== null) return full_accessErr + + + break case LiveDebitRequest_debit_type.INVOICE: - 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.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`) + + break + default: + return new Error(path + ': unknown type ' + stringType) + } + return null +} +export enum NPubLinking_state_type { + LINKED_NPUB = 'linked_npub', + LINKING_TOKEN = 'linking_token', + UNLINKED = 'unlinked', +} +export const enumCheckNPubLinking_state_type = (e?: NPubLinking_state_type): boolean => { + for (const v in NPubLinking_state_type) if (e === v) return true + return false +} +export type NPubLinking_state = + { type: NPubLinking_state_type.LINKED_NPUB, linked_npub: string } | + { type: NPubLinking_state_type.LINKING_TOKEN, linking_token: string } | + { type: NPubLinking_state_type.UNLINKED, unlinked: Empty } + +export type NPubLinking_stateOptions = { + linked_npub_CustomCheck?: (v: string) => boolean + linking_token_CustomCheck?: (v: string) => boolean + unlinked_Options?: EmptyOptions +} +export const NPubLinking_stateValidate = (o?: NPubLinking_state, opts: NPubLinking_stateOptions = {}, path: string = 'NPubLinking_state::root.'): Error | null => { + if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null') + const stringType: string = o.type + switch (o.type) { + case NPubLinking_state_type.LINKED_NPUB: + if (typeof o.linked_npub !== 'string') return new Error(`${path}.linked_npub: is not a string`) + if (opts.linked_npub_CustomCheck && !opts.linked_npub_CustomCheck(o.linked_npub)) return new Error(`${path}.linked_npub: custom check failed`) + + break + case NPubLinking_state_type.LINKING_TOKEN: + if (typeof o.linking_token !== 'string') return new Error(`${path}.linking_token: is not a string`) + if (opts.linking_token_CustomCheck && !opts.linking_token_CustomCheck(o.linking_token)) return new Error(`${path}.linking_token: custom check failed`) + + break + case NPubLinking_state_type.UNLINKED: + const unlinkedErr = EmptyValidate(o.unlinked, opts.unlinked_Options, `${path}.unlinked`) + if (unlinkedErr !== null) return unlinkedErr + - break + break default: - return new Error(path + ': unknown type '+ stringType) + return new Error(path + ': unknown type ' + stringType) } return null } diff --git a/src/Pages/Channels/index.tsx b/src/Pages/Channels/index.tsx index 1632274a..5adb9b32 100644 --- a/src/Pages/Channels/index.tsx +++ b/src/Pages/Channels/index.tsx @@ -3,6 +3,7 @@ import * as Icons from "../../Assets/SvgIconLibrary"; import { useSelector } from "../../State/store"; import { getNostrClient } from "../../Api"; import { NostrKeyPair } from "../../Api/nostrHandler"; +import PromptForActionModal, { ActionType } from "../../Components/Modals/PromptForActionModal"; interface OfflineChannel { id: number; avatar: string; @@ -24,6 +25,10 @@ export const Channels = () => { const [maxBalance, setMaxBalance] = useState(0); const [activeChannels, setActiveChannels] = useState([]); const [offlineChannels, setOfflineChannels] = useState([]); + const [selectedChannel, setSelectedChannel] = useState<{ id: number, name: string } | null>(null); + const [openModal, setOpenModal] = useState<'addPeer' | 'openChannel' | 'closeChannel' | ''>(''); + const [peerUri, setPeerUri] = useState(''); + const spendSources = useSelector(state => state.spendSource) const selectedSource = useMemo(() => { return spendSources.order.find(p => !!spendSources.sources[p].adminToken) @@ -98,7 +103,7 @@ export const Channels = () => {
{offlineChannels.map((channel: OfflineChannel, index: number) => ( -
+
{ setSelectedChannel({ id: channel.id, name: channel.name }); setOpenModal('closeChannel') }}>
{
- {`${ - channel.timeStamp - ? channel.timeStamp > 1000 - ? "💀 Last seen 10 days ago" - : "🔍 Last seen 2 hours ago" - : "🔗 Pending Force Close" - }`} + {`${channel.timeStamp + ? channel.timeStamp > 1000 + ? "💀 Last seen 10 days ago" + : "🔍 Last seen 2 hours ago" + : "🔗 Pending Force Close" + }`}
@@ -159,7 +163,7 @@ export const Channels = () => {
{activeChannels.map((channel: ActiveChannel, index: number) => ( -
+
{ setSelectedChannel({ id: channel.id, name: channel.name }); setOpenModal('closeChannel') }}>
{
+
+ + + +
Connected to
{spendSources.sources[selectedSource || ""].pasteField}
+ {openModal === 'addPeer' && { setOpenModal('') }} + action={() => { setOpenModal('') }} + jsx={<>} + />} + {openModal === 'openChannel' && { setOpenModal('') }} + action={() => { setOpenModal('') }} + jsx={<> + + } + />} + {openModal === 'closeChannel' && selectedChannel && { setOpenModal('') }} + action={() => { setOpenModal('') }} + jsx={<>

closing channel: {selectedChannel.id}

} + />}
); }; From 705e31eb2ca9df5cc159163f196b36e0b87c911a Mon Sep 17 00:00:00 2001 From: boufni95 Date: Mon, 18 Nov 2024 18:01:26 +0000 Subject: [PATCH 2/2] wired all ops --- src/Api/nostrHandler.ts | 4 +- src/Api/pub/autogenerated/ts/http_client.ts | 13 +- src/Api/pub/autogenerated/ts/nostr_client.ts | 16 +- .../pub/autogenerated/ts/nostr_transport.ts | 18 ++- src/Api/pub/autogenerated/ts/types.ts | 143 ++++++++++++++--- src/Pages/Channels/EditChannel.tsx | 150 ++++++++++++++++++ src/Pages/Channels/OpenChannel.tsx | 100 ++++++++++++ src/Pages/Channels/index.tsx | 71 +++------ 8 files changed, 442 insertions(+), 73 deletions(-) create mode 100644 src/Pages/Channels/EditChannel.tsx create mode 100644 src/Pages/Channels/OpenChannel.tsx diff --git a/src/Api/nostrHandler.ts b/src/Api/nostrHandler.ts index 78797c0f..711858c7 100644 --- a/src/Api/nostrHandler.ts +++ b/src/Api/nostrHandler.ts @@ -118,11 +118,11 @@ export default class RelayCluster { } SendNip69 = async (relays: string[], pubKey: string, data: nip69.NofferData, keys: NostrKeyPair): Promise => { - return nip69.SendNofferRequest(this.pool, Buffer.from(keys.privateKey, 'hex'), relays, pubKey, data) + return nip69.SendNofferRequest(this.pool, new Uint8Array(Buffer.from(keys.privateKey, 'hex')), relays, pubKey, data) } sendRaw = async (relays: string[], event: UnsignedEvent, privateKey: string) => { - const signed = finalizeEvent(event, Buffer.from(privateKey, 'hex')) + const signed = finalizeEvent(event, new Uint8Array(Buffer.from(privateKey, 'hex'))) this.pool.publish(relays, signed).forEach(p => { p.then(() => logger.info("sent ok")) p.catch(() => logger.error("failed to send")) diff --git a/src/Api/pub/autogenerated/ts/http_client.ts b/src/Api/pub/autogenerated/ts/http_client.ts index a6bc5ab0..198d5f10 100644 --- a/src/Api/pub/autogenerated/ts/http_client.ts +++ b/src/Api/pub/autogenerated/ts/http_client.ts @@ -1,6 +1,6 @@ // This file was autogenerated from a .proto file, DO NOT EDIT! import axios from 'axios' -import * as Types from './types.js' +import * as Types from './types' export type ResultError = { status: 'ERROR', reason: string } export type ClientParams = { @@ -810,6 +810,17 @@ export default (params: ClientParams) => ({ } return { status: 'ERROR', reason: 'invalid response' } }, + UpdateChannelPolicy: async (request: Types.UpdateChannelPolicyRequest): Promise => { + const auth = await params.retrieveAdminAuth() + if (auth === null) throw new Error('retrieveAdminAuth() returned null') + let finalRoute = '/api/admin/channel/policy/update' + 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') { + return data + } + return { status: 'ERROR', reason: 'invalid response' } + }, UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise => { const auth = await params.retrieveGuestWithPubAuth() if (auth === null) throw new Error('retrieveGuestWithPubAuth() returned null') diff --git a/src/Api/pub/autogenerated/ts/nostr_client.ts b/src/Api/pub/autogenerated/ts/nostr_client.ts index e6864d3a..0c7a7c82 100644 --- a/src/Api/pub/autogenerated/ts/nostr_client.ts +++ b/src/Api/pub/autogenerated/ts/nostr_client.ts @@ -1,6 +1,6 @@ // This file was autogenerated from a .proto file, DO NOT EDIT! -import { NostrRequest } from './nostr_transport.js' -import * as Types from './types.js' +import { NostrRequest } from './nostr_transport' +import * as Types from './types' export type ResultError = { status: 'ERROR', reason: string } export type NostrClientParams = { @@ -594,6 +594,18 @@ export default (params: NostrClientParams, send: (to: string, message: NostrRequ } return { status: 'ERROR', reason: 'invalid response' } }, + UpdateChannelPolicy: async (request: Types.UpdateChannelPolicyRequest): Promise => { + const auth = await params.retrieveNostrAdminAuth() + if (auth === null) throw new Error('retrieveNostrAdminAuth() returned null') + const nostrRequest: NostrRequest = {} + nostrRequest.body = request + const data = await send(params.pubDestination, { rpcName: 'UpdateChannelPolicy', authIdentifier: auth, ...nostrRequest }) + if (data.status === 'ERROR' && typeof data.reason === 'string') return data + if (data.status === 'OK') { + return data + } + return { status: 'ERROR', reason: 'invalid response' } + }, UseInviteLink: async (request: Types.UseInviteLinkRequest): Promise => { const auth = await params.retrieveNostrGuestWithPubAuth() if (auth === null) throw new Error('retrieveNostrGuestWithPubAuth() returned null') diff --git a/src/Api/pub/autogenerated/ts/nostr_transport.ts b/src/Api/pub/autogenerated/ts/nostr_transport.ts index e2586994..d14f1c7d 100644 --- a/src/Api/pub/autogenerated/ts/nostr_transport.ts +++ b/src/Api/pub/autogenerated/ts/nostr_transport.ts @@ -1,6 +1,6 @@ // This file was autogenerated from a .proto file, DO NOT EDIT! -import * as Types from './types.js' +import * as Types from './types' export type Logger = { log: (v: any) => void, error: (v: any) => void } type NostrResponse = (message: object) => void export type NostrRequest = { @@ -920,6 +920,22 @@ export default (methods: Types.ServerMethods, opts: NostrOptions) => { opts.metricsCallback([{ ...info, ...stats, ...authContext }]) } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } break + case 'UpdateChannelPolicy': + try { + if (!methods.UpdateChannelPolicy) throw new Error('method: UpdateChannelPolicy is not implemented') + const authContext = await opts.NostrAdminAuthGuard(req.appId, req.authIdentifier) + stats.guard = process.hrtime.bigint() + authCtx = authContext + const request = req.body + const error = Types.UpdateChannelPolicyRequestValidate(request) + stats.validate = process.hrtime.bigint() + if (error !== null) return logErrorAndReturnResponse(error, 'invalid request body', res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback) + await methods.UpdateChannelPolicy({ rpcName: 'UpdateChannelPolicy', ctx: authContext, req: request }) + stats.handle = process.hrtime.bigint() + res({ status: 'OK' }) + opts.metricsCallback([{ ...info, ...stats, ...authContext }]) + } catch (ex) { const e = ex as any; logErrorAndReturnResponse(e, e.message || e, res, logger, { ...info, ...stats, ...authCtx }, opts.metricsCallback); if (opts.throwErrors) throw e } + break case 'UseInviteLink': try { if (!methods.UseInviteLink) throw new Error('method: UseInviteLink is not implemented') diff --git a/src/Api/pub/autogenerated/ts/types.ts b/src/Api/pub/autogenerated/ts/types.ts index b5bb55d9..d8e46a08 100644 --- a/src/Api/pub/autogenerated/ts/types.ts +++ b/src/Api/pub/autogenerated/ts/types.ts @@ -7,8 +7,8 @@ export type RequestMetric = AuthContext & RequestInfo & RequestStats & { error?: export type AdminContext = { admin_id: string } -export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetInviteLinkState_Input | GetSeed_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input -export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetInviteLinkState_Output | GetSeed_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output +export type AdminMethodInputs = AddApp_Input | AddPeer_Input | AuthApp_Input | BanUser_Input | CloseChannel_Input | CreateOneTimeInviteLink_Input | GetInviteLinkState_Input | GetSeed_Input | ListChannels_Input | LndGetInfo_Input | OpenChannel_Input | UpdateChannelPolicy_Input +export type AdminMethodOutputs = AddApp_Output | AddPeer_Output | AuthApp_Output | BanUser_Output | CloseChannel_Output | CreateOneTimeInviteLink_Output | GetInviteLinkState_Output | GetSeed_Output | ListChannels_Output | LndGetInfo_Output | OpenChannel_Output | UpdateChannelPolicy_Output export type AppContext = { app_id: string } @@ -249,6 +249,9 @@ export type SetMockInvoiceAsPaid_Output = ResultError | { status: 'OK' } export type UpdateCallbackUrl_Input = { rpcName: 'UpdateCallbackUrl', req: CallbackUrl } export type UpdateCallbackUrl_Output = ResultError | ({ status: 'OK' } & CallbackUrl) +export type UpdateChannelPolicy_Input = { rpcName: 'UpdateChannelPolicy', req: UpdateChannelPolicyRequest } +export type UpdateChannelPolicy_Output = ResultError | { status: 'OK' } + export type UseInviteLink_Input = { rpcName: 'UseInviteLink', req: UseInviteLinkRequest } export type UseInviteLink_Output = ResultError | { status: 'OK' } @@ -318,6 +321,7 @@ export type ServerMethods = { SetMockAppUserBalance?: (req: SetMockAppUserBalance_Input & { ctx: AppContext }) => Promise SetMockInvoiceAsPaid?: (req: SetMockInvoiceAsPaid_Input & { ctx: GuestContext }) => Promise UpdateCallbackUrl?: (req: UpdateCallbackUrl_Input & { ctx: UserContext }) => Promise + UpdateChannelPolicy?: (req: UpdateChannelPolicy_Input & { ctx: AdminContext }) => Promise UseInviteLink?: (req: UseInviteLink_Input & { ctx: GuestWithPubContext }) => Promise UserHealth?: (req: UserHealth_Input & { ctx: UserContext }) => Promise } @@ -846,6 +850,44 @@ export const CallbackUrlValidate = (o?: CallbackUrl, opts: CallbackUrlOptions = return null } +export type ChannelPolicy = { + base_fee_msat: number + fee_rate_ppm: number + max_htlc_msat: number + min_htlc_msat: number + timelock_delta: number +} +export const ChannelPolicyOptionalFields: [] = [] +export type ChannelPolicyOptions = OptionsBaseMessage & { + checkOptionalsAreSet?: [] + base_fee_msat_CustomCheck?: (v: number) => boolean + fee_rate_ppm_CustomCheck?: (v: number) => boolean + max_htlc_msat_CustomCheck?: (v: number) => boolean + min_htlc_msat_CustomCheck?: (v: number) => boolean + timelock_delta_CustomCheck?: (v: number) => boolean +} +export const ChannelPolicyValidate = (o?: ChannelPolicy, opts: ChannelPolicyOptions = {}, path: string = 'ChannelPolicy::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.base_fee_msat !== 'number') return new Error(`${path}.base_fee_msat: is not a number`) + if (opts.base_fee_msat_CustomCheck && !opts.base_fee_msat_CustomCheck(o.base_fee_msat)) return new Error(`${path}.base_fee_msat: custom check failed`) + + if (typeof o.fee_rate_ppm !== 'number') return new Error(`${path}.fee_rate_ppm: is not a number`) + if (opts.fee_rate_ppm_CustomCheck && !opts.fee_rate_ppm_CustomCheck(o.fee_rate_ppm)) return new Error(`${path}.fee_rate_ppm: custom check failed`) + + if (typeof o.max_htlc_msat !== 'number') return new Error(`${path}.max_htlc_msat: is not a number`) + if (opts.max_htlc_msat_CustomCheck && !opts.max_htlc_msat_CustomCheck(o.max_htlc_msat)) return new Error(`${path}.max_htlc_msat: custom check failed`) + + if (typeof o.min_htlc_msat !== 'number') return new Error(`${path}.min_htlc_msat: is not a number`) + if (opts.min_htlc_msat_CustomCheck && !opts.min_htlc_msat_CustomCheck(o.min_htlc_msat)) return new Error(`${path}.min_htlc_msat: custom check failed`) + + if (typeof o.timelock_delta !== 'number') return new Error(`${path}.timelock_delta: is not a number`) + if (opts.timelock_delta_CustomCheck && !opts.timelock_delta_CustomCheck(o.timelock_delta)) return new Error(`${path}.timelock_delta: custom check failed`) + + return null +} + export type CloseChannelRequest = { force: boolean funding_txid: string @@ -1318,24 +1360,6 @@ export const GetAppUserRequestValidate = (o?: GetAppUserRequest, opts: GetAppUse return null } -export type GetChannelPolicyRequest = { - channel_id: string -} -export const GetChannelPolicyRequestOptionalFields: [] = [] -export type GetChannelPolicyRequestOptions = OptionsBaseMessage & { - checkOptionalsAreSet?: [] - channel_id_CustomCheck?: (v: string) => boolean -} -export const GetChannelPolicyRequestValidate = (o?: GetChannelPolicyRequest, opts: GetChannelPolicyRequestOptions = {}, path: string = 'GetChannelPolicyRequest::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.channel_id !== 'string') return new Error(`${path}.channel_id: is not a string`) - if (opts.channel_id_CustomCheck && !opts.channel_id_CustomCheck(o.channel_id)) return new Error(`${path}.channel_id: custom check failed`) - - return null -} - export type GetInviteTokenStateRequest = { invite_token: string } @@ -2143,20 +2167,25 @@ export type OpenChannel = { active: boolean capacity: number channel_id: string + channel_point: string label: string lifetime: number local_balance: number + policy?: ChannelPolicy remote_balance: number } -export const OpenChannelOptionalFields: [] = [] +export type OpenChannelOptionalField = 'policy' +export const OpenChannelOptionalFields: OpenChannelOptionalField[] = ['policy'] export type OpenChannelOptions = OptionsBaseMessage & { - checkOptionalsAreSet?: [] + checkOptionalsAreSet?: OpenChannelOptionalField[] active_CustomCheck?: (v: boolean) => boolean capacity_CustomCheck?: (v: number) => boolean channel_id_CustomCheck?: (v: string) => boolean + channel_point_CustomCheck?: (v: string) => boolean label_CustomCheck?: (v: string) => boolean lifetime_CustomCheck?: (v: number) => boolean local_balance_CustomCheck?: (v: number) => boolean + policy_Options?: ChannelPolicyOptions remote_balance_CustomCheck?: (v: number) => boolean } export const OpenChannelValidate = (o?: OpenChannel, opts: OpenChannelOptions = {}, path: string = 'OpenChannel::root.'): Error | null => { @@ -2172,6 +2201,9 @@ export const OpenChannelValidate = (o?: OpenChannel, opts: OpenChannelOptions = if (typeof o.channel_id !== 'string') return new Error(`${path}.channel_id: is not a string`) if (opts.channel_id_CustomCheck && !opts.channel_id_CustomCheck(o.channel_id)) return new Error(`${path}.channel_id: custom check failed`) + if (typeof o.channel_point !== 'string') return new Error(`${path}.channel_point: is not a string`) + if (opts.channel_point_CustomCheck && !opts.channel_point_CustomCheck(o.channel_point)) return new Error(`${path}.channel_point: custom check failed`) + if (typeof o.label !== 'string') return new Error(`${path}.label: is not a string`) if (opts.label_CustomCheck && !opts.label_CustomCheck(o.label)) return new Error(`${path}.label: custom check failed`) @@ -2181,6 +2213,12 @@ export const OpenChannelValidate = (o?: OpenChannel, opts: OpenChannelOptions = if (typeof o.local_balance !== 'number') return new Error(`${path}.local_balance: is not a number`) if (opts.local_balance_CustomCheck && !opts.local_balance_CustomCheck(o.local_balance)) return new Error(`${path}.local_balance: custom check failed`) + if (typeof o.policy === 'object' || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('policy')) { + const policyErr = ChannelPolicyValidate(o.policy, opts.policy_Options, `${path}.policy`) + if (policyErr !== null) return policyErr + } + + if (typeof o.remote_balance !== 'number') return new Error(`${path}.remote_balance: is not a number`) if (opts.remote_balance_CustomCheck && !opts.remote_balance_CustomCheck(o.remote_balance)) return new Error(`${path}.remote_balance: custom check failed`) @@ -2717,6 +2755,31 @@ export const SetMockInvoiceAsPaidRequestValidate = (o?: SetMockInvoiceAsPaidRequ return null } +export type UpdateChannelPolicyRequest = { + policy: ChannelPolicy + update: UpdateChannelPolicyRequest_update +} +export const UpdateChannelPolicyRequestOptionalFields: [] = [] +export type UpdateChannelPolicyRequestOptions = OptionsBaseMessage & { + checkOptionalsAreSet?: [] + policy_Options?: ChannelPolicyOptions + update_Options?: UpdateChannelPolicyRequest_updateOptions +} +export const UpdateChannelPolicyRequestValidate = (o?: UpdateChannelPolicyRequest, opts: UpdateChannelPolicyRequestOptions = {}, path: string = 'UpdateChannelPolicyRequest::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') + + const policyErr = ChannelPolicyValidate(o.policy, opts.policy_Options, `${path}.policy`) + if (policyErr !== null) return policyErr + + + const updateErr = UpdateChannelPolicyRequest_updateValidate(o.update, opts.update_Options, `${path}.update`) + if (updateErr !== null) return updateErr + + + return null +} + export type UsageMetric = { auth_in_nano: number batch: boolean @@ -3184,6 +3247,42 @@ export const NPubLinking_stateValidate = (o?: NPubLinking_state, opts: NPubLinki if (unlinkedErr !== null) return unlinkedErr + break + default: + return new Error(path + ': unknown type ' + stringType) + } + return null +} +export enum UpdateChannelPolicyRequest_update_type { + ALL = 'all', + CHANNEL_POINT = 'channel_point', +} +export const enumCheckUpdateChannelPolicyRequest_update_type = (e?: UpdateChannelPolicyRequest_update_type): boolean => { + for (const v in UpdateChannelPolicyRequest_update_type) if (e === v) return true + return false +} +export type UpdateChannelPolicyRequest_update = + { type: UpdateChannelPolicyRequest_update_type.ALL, all: Empty } | + { type: UpdateChannelPolicyRequest_update_type.CHANNEL_POINT, channel_point: string } + +export type UpdateChannelPolicyRequest_updateOptions = { + all_Options?: EmptyOptions + channel_point_CustomCheck?: (v: string) => boolean +} +export const UpdateChannelPolicyRequest_updateValidate = (o?: UpdateChannelPolicyRequest_update, opts: UpdateChannelPolicyRequest_updateOptions = {}, path: string = 'UpdateChannelPolicyRequest_update::root.'): Error | null => { + if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null') + const stringType: string = o.type + switch (o.type) { + case UpdateChannelPolicyRequest_update_type.ALL: + const allErr = EmptyValidate(o.all, opts.all_Options, `${path}.all`) + if (allErr !== null) return allErr + + + break + case UpdateChannelPolicyRequest_update_type.CHANNEL_POINT: + if (typeof o.channel_point !== 'string') return new Error(`${path}.channel_point: is not a string`) + if (opts.channel_point_CustomCheck && !opts.channel_point_CustomCheck(o.channel_point)) return new Error(`${path}.channel_point: custom check failed`) + break default: return new Error(path + ': unknown type ' + stringType) diff --git a/src/Pages/Channels/EditChannel.tsx b/src/Pages/Channels/EditChannel.tsx new file mode 100644 index 00000000..e1794cb9 --- /dev/null +++ b/src/Pages/Channels/EditChannel.tsx @@ -0,0 +1,150 @@ +import React, { useEffect, useMemo, useState } from "react"; +import * as Icons from "../../Assets/SvgIconLibrary"; +import { useSelector } from "../../State/store"; +import { getNostrClient } from "../../Api"; +import { NostrKeyPair } from "../../Api/nostrHandler"; +import PromptForActionModal, { ActionType } from "../../Components/Modals/PromptForActionModal"; +import { SpendFrom } from "../../globalTypes"; +import * as Types from '../../Api/pub/autogenerated/ts/types' +import { toast } from "react-toastify"; +import Checkbox from "../../Components/Checkbox"; +export type SelectedChannel = { id: number, name: string } +export const EditChannel = ({ adminSource, selectedChannel, deselect }: { adminSource: SpendFrom, selectedChannel: Types.OpenChannel | null, deselect: () => void }) => { + const [openModal, setOpenModal] = useState<'showPolicy' | 'updatePolocy' | 'closeChannel'>('showPolicy'); + const [baseFeeMsat, setBaseFeeMsat] = useState(); + const [feeRatePpm, setFeeRatePpm] = useState(0); + const [maxHtlcMsat, setMaxHtlcMsat] = useState(0); + const [minHtlcMsat, setMinHtlcMsat] = useState(0); + const [timeLockDelta, setTimeLockDelta] = useState(0); + const [satsPerVByte, setSatsPerVByte] = useState(0); + const [force, setForce] = useState(false); + useEffect(() => { + if (selectedChannel && selectedChannel.policy) { + setBaseFeeMsat(selectedChannel.policy.base_fee_msat) + setFeeRatePpm(selectedChannel.policy.fee_rate_ppm) + setMaxHtlcMsat(selectedChannel.policy.max_htlc_msat) + setMinHtlcMsat(selectedChannel.policy.min_htlc_msat) + setTimeLockDelta(selectedChannel.policy.timelock_delta) + } + }, [selectedChannel]) + const updatePolicy = async () => { + if (!selectedChannel) { + toast.error('No channel selected') + return + } + if (!baseFeeMsat || !feeRatePpm || !maxHtlcMsat || !minHtlcMsat || !timeLockDelta) { + toast.error('Please enter all fields') + return + } + const client = await getNostrClient(adminSource.pasteField, adminSource.keys) + const res = await client.UpdateChannelPolicy({ + policy: { base_fee_msat: baseFeeMsat, fee_rate_ppm: feeRatePpm, max_htlc_msat: maxHtlcMsat, min_htlc_msat: minHtlcMsat, timelock_delta: timeLockDelta }, + update: { type: Types.UpdateChannelPolicyRequest_update_type.CHANNEL_POINT, channel_point: selectedChannel.channel_point } + }) + if (res.status === 'ERROR') { + toast.error(res.reason) + return + } + toast.success('Policy updated successfully') + } + const closeChannel = async () => { + if (!selectedChannel) { + toast.error('No channel selected') + return + } + if (satsPerVByte <= 0) { + toast.error('Please enter a valid sats per vbyte') + return + } + const client = await getNostrClient(adminSource.pasteField, adminSource.keys) + const [txid, output] = selectedChannel.channel_point.split(':') + const res = await client.CloseChannel({ + funding_txid: txid, + output_index: +output, + force: force, + sat_per_v_byte: satsPerVByte + }) + if (res.status === 'ERROR') { + toast.error(res.reason) + return + } + toast.success('Channel closed successfully') + } + if (!selectedChannel) { + return null + } + + if (openModal === 'showPolicy') { + return { deselect() }} + action={() => { deselect() }} + jsx={<> + {selectedChannel.policy &&
+

Base fee Msat: {selectedChannel.policy.base_fee_msat}

+

Fee rate Ppm: {selectedChannel.policy.fee_rate_ppm}

+

Max HTLC Msat: {selectedChannel.policy.max_htlc_msat}

+

Min HTLC Msat: {selectedChannel.policy.min_htlc_msat}

+

Time Lock Delta: {selectedChannel.policy.timelock_delta}

+ + +
} + {!selectedChannel.policy &&
No Policy found for channel
} + } + /> + } + if (openModal === 'updatePolocy') { + return { setOpenModal('showPolicy') }} + action={() => { updatePolicy(); setOpenModal('showPolicy') }} + jsx={<> + {selectedChannel.policy &&
+
+ + { setBaseFeeMsat(+e.target.value) }}> +
+
+ + { setFeeRatePpm(+e.target.value) }}> +
+
+ + { setMaxHtlcMsat(+e.target.value) }}> +
+
+ + { setMinHtlcMsat(+e.target.value) }}> +
+
+ + { setTimeLockDelta(+e.target.value) }}> +
+
} + } + /> + } + if (openModal === 'closeChannel') { + return { setOpenModal('showPolicy') }} + action={() => { closeChannel(); setOpenModal('showPolicy') }} + jsx={<> +

Are you sure you want to close the channel?

+
+ + { setSatsPerVByte(+e.target.value) }}> +
+
+ + { setForce(e.target.checked) }} id="forceClose" /> +
+ } + /> + } + + return null +}; \ No newline at end of file diff --git a/src/Pages/Channels/OpenChannel.tsx b/src/Pages/Channels/OpenChannel.tsx new file mode 100644 index 00000000..959d6de3 --- /dev/null +++ b/src/Pages/Channels/OpenChannel.tsx @@ -0,0 +1,100 @@ +import React, { useEffect, useMemo, useState } from "react"; +import * as Icons from "../../Assets/SvgIconLibrary"; +import { useSelector } from "../../State/store"; +import { getNostrClient } from "../../Api"; +import { NostrKeyPair } from "../../Api/nostrHandler"; +import PromptForActionModal, { ActionType } from "../../Components/Modals/PromptForActionModal"; +import { SpendFrom } from "../../globalTypes"; +import { toast } from "react-toastify"; + +export const OpenChannel = ({ adminSource }: { adminSource: SpendFrom }) => { + const [openModal, setOpenModal] = useState<'addPeer' | 'openChannel' | ''>(''); + const [peerUri, setPeerUri] = useState(''); + const [peerPubkey, setPeerPubkey] = useState(''); + const [channelAmount, setChannelAmount] = useState(0); + const [satsPerVByte, setSatsPerVByte] = useState(0); + const addPeer = async () => { + if (!peerUri) { + toast.error('Please enter a valid peer uri') + return + } + const [pubkey, addr] = peerUri.split('@') + if (!pubkey || !addr) { + toast.error('Please enter a valid peer uri') + return + } + const [host, port] = addr.split(':') + if (!host || !port || isNaN(+port)) { + toast.error('Please enter a valid peer uri') + return + } + const client = await getNostrClient(adminSource.pasteField, adminSource.keys) + const res = await client.AddPeer({ pubkey, host, port: +port }) + if (res.status === 'ERROR') { + toast.error(res.reason) + return + } + toast.success('Peer added successfully') + } + + const openChannel = async () => { + if (!peerPubkey) { + toast.error('Please enter a valid peer pubkey') + return + } + if (channelAmount <= 0) { + toast.error('Please enter a valid channel amount') + return + } + if (satsPerVByte <= 0) { + toast.error('Please enter a valid sats per vbyte') + return + } + const client = await getNostrClient(adminSource.pasteField, adminSource.keys) + const res = await client.OpenChannel({ node_pubkey: peerPubkey, local_funding_amount: channelAmount, sat_per_v_byte: satsPerVByte }) + if (res.status === 'ERROR') { + toast.error(res.reason) + return + } + toast.success('Channel opened successfully') + } + + return ( +
+
+ + + +
+ {openModal === 'addPeer' && { setOpenModal('') }} + action={() => { addPeer(); setOpenModal('') }} + jsx={<> + + { setPeerUri(e.target.value) }}>} + />} + {openModal === 'openChannel' && { setOpenModal('') }} + action={() => { openChannel(); setOpenModal('') }} + jsx={<> +
+ + { setPeerPubkey(e.target.value) }}> +
+
+ + { setChannelAmount(+e.target.value) }}> +
+
+ + { setSatsPerVByte(+e.target.value) }}> +
+ } + />} +
+ ); +}; \ No newline at end of file diff --git a/src/Pages/Channels/index.tsx b/src/Pages/Channels/index.tsx index 5adb9b32..a6bc83c3 100644 --- a/src/Pages/Channels/index.tsx +++ b/src/Pages/Channels/index.tsx @@ -4,6 +4,9 @@ import { useSelector } from "../../State/store"; import { getNostrClient } from "../../Api"; import { NostrKeyPair } from "../../Api/nostrHandler"; import PromptForActionModal, { ActionType } from "../../Components/Modals/PromptForActionModal"; +import { OpenChannel } from "./OpenChannel"; +import { EditChannel, SelectedChannel } from "./EditChannel"; +import * as Types from '../../Api/pub/autogenerated/ts/types' interface OfflineChannel { id: number; avatar: string; @@ -11,6 +14,7 @@ interface OfflineChannel { subNode: string; timeStamp?: number; satAmount: number; + channel: Types.OpenChannel } interface ActiveChannel { @@ -19,20 +23,32 @@ interface ActiveChannel { name: string; localSatAmount: number; RemoteSatAmount: number; + channel: Types.OpenChannel } + + export const Channels = () => { const [maxBalance, setMaxBalance] = useState(0); const [activeChannels, setActiveChannels] = useState([]); const [offlineChannels, setOfflineChannels] = useState([]); - const [selectedChannel, setSelectedChannel] = useState<{ id: number, name: string } | null>(null); - const [openModal, setOpenModal] = useState<'addPeer' | 'openChannel' | 'closeChannel' | ''>(''); - const [peerUri, setPeerUri] = useState(''); + const [selectedChannel, setSelectedChannel] = useState(null); + const spendSources = useSelector(state => state.spendSource) const selectedSource = useMemo(() => { return spendSources.order.find(p => !!spendSources.sources[p].adminToken) }, [spendSources]) + useEffect(() => { + if (!selectedSource) { + throw new Error("admin source not found") + } + const source = spendSources.sources[selectedSource] + if (!source || !source.adminToken) { + throw new Error("admin source not found") + } + fetchChannels(source.pasteField, source.keys) + }, [selectedSource]) const fetchChannels = async (nprofile: string, keys: NostrKeyPair) => { const client = await getNostrClient(nprofile, keys) const res = await client.ListChannels() @@ -50,9 +66,9 @@ export const Channels = () => { max = c.remote_balance } if (c.active) { - active.push({ avatar: "", id: i, name: c.label, localSatAmount: c.local_balance, RemoteSatAmount: c.remote_balance }) + active.push({ avatar: "", id: i, name: c.label, localSatAmount: c.local_balance, RemoteSatAmount: c.remote_balance, channel: c }) } else { - offline.push({ avatar: "", id: i, name: c.label, satAmount: c.capacity, timeStamp: c.lifetime, subNode: "Initiate force-close" }) + offline.push({ avatar: "", id: i, name: c.label, satAmount: c.capacity, timeStamp: c.lifetime, subNode: "Initiate force-close", channel: c }) } }) setMaxBalance(max) @@ -61,16 +77,7 @@ export const Channels = () => { } - useEffect(() => { - if (!selectedSource) { - throw new Error("admin source not found") - } - const source = spendSources.sources[selectedSource] - if (!source || !source.adminToken) { - throw new Error("admin source not found") - } - fetchChannels(source.pasteField, source.keys) - }, [selectedSource]) + const totalSatAmount: number = offlineChannels.reduce( (acc, obj) => acc + obj.satAmount, 0 @@ -103,7 +110,7 @@ export const Channels = () => {
{offlineChannels.map((channel: OfflineChannel, index: number) => ( -
{ setSelectedChannel({ id: channel.id, name: channel.name }); setOpenModal('closeChannel') }}> +
{ setSelectedChannel(channel.channel); }}>
{
{activeChannels.map((channel: ActiveChannel, index: number) => ( -
{ setSelectedChannel({ id: channel.id, name: channel.name }); setOpenModal('closeChannel') }}> +
{ setSelectedChannel(channel.channel); }}>
{
-
- - - -
+ + setSelectedChannel(null)} />
Connected to
{spendSources.sources[selectedSource || ""].pasteField}
- {openModal === 'addPeer' && { setOpenModal('') }} - action={() => { setOpenModal('') }} - jsx={<>} - />} - {openModal === 'openChannel' && { setOpenModal('') }} - action={() => { setOpenModal('') }} - jsx={<> - - } - />} - {openModal === 'closeChannel' && selectedChannel && { setOpenModal('') }} - action={() => { setOpenModal('') }} - jsx={<>

closing channel: {selectedChannel.id}

} - />}
); };