From 201c095a7235f496fd70719225224838a4bee3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Talha=20=C3=96zdemir?= Date: Wed, 20 Sep 2023 16:14:39 +0300 Subject: [PATCH 1/3] feat(backend): remove connections route (#1940) - remove connections route from open payments spec - remove connections route and any associated service functions from backend --- openapi/resource-server.yaml | 36 ------------------- packages/backend/src/app.ts | 19 +--------- packages/backend/src/index.ts | 8 ----- .../src/open_payments/connection/routes.ts | 35 ------------------ 4 files changed, 1 insertion(+), 97 deletions(-) delete mode 100644 packages/backend/src/open_payments/connection/routes.ts diff --git a/openapi/resource-server.yaml b/openapi/resource-server.yaml index 6a0589b1d5..4b2718afc0 100644 --- a/openapi/resource-server.yaml +++ b/openapi/resource-server.yaml @@ -103,42 +103,6 @@ paths: operationId: get-wallet-addres-keys description: Retrieve the public keys of the Wallet Address. security: [] - '/connections/{id}': - servers: - - url: 'https://openpayments.guide' - get: - summary: Get ILP STREAM credentials for a connection - tags: - - stream-connection - responses: - '200': - description: Connection Found - content: - application/json: - schema: - $ref: '#/components/schemas/ilp-stream-connection' - examples: - Get connection: - value: - id: 'https://openpayments.guide/connections/016da9d5-c9a4-4c80-a354-86b915a04ff8' - ilpAddress: g.ilp.iwuyge987y.98y0f34tsrt8y - sharedSecret: 1c7eaXa4rd2fFOBl1iydvCT1tV5TbM3RW1WLCafu_JA - assetCode: USD - assetScale: 2 - '404': - description: Connection Not Found - operationId: get-ilp-stream-connection - description: |- - *NB* Use server url specific to this path. - - Fetch new connection credentials for an ILP STREAM connection. - - A connection is an ephemeral resource that is created to accommodate new incoming payments. - - A new set of credential will be generated each time this API is called. - security: [] - parameters: - - $ref: '#/components/parameters/id' /incoming-payments: post: summary: Create an Incoming Payment diff --git a/packages/backend/src/app.ts b/packages/backend/src/app.ts index 7c395d8022..806b868bb2 100644 --- a/packages/backend/src/app.ts +++ b/packages/backend/src/app.ts @@ -35,8 +35,7 @@ import { } from './open_payments/auth/middleware' import { RatesService } from './rates/service' import { - spspMiddleware, - SPSPConnectionContext + spspMiddleware } from './payment-method/ilp/spsp/middleware' import { SPSPRoutes } from './payment-method/ilp/spsp/routes' import { @@ -360,24 +359,8 @@ export class App { 'outgoingPaymentRoutes' ) const quoteRoutes = await this.container.use('quoteRoutes') - const connectionRoutes = await this.container.use('connectionRoutes') const { resourceServerSpec } = await this.container.use('openApi') - // GET /connections/{id} - router.get( - WALLET_ADDRESS_PATH + '/connections/:id', - connectionMiddleware, - spspMiddleware, - createValidatorMiddleware>( - resourceServerSpec, - { - path: '/connections/{id}', - method: HttpMethod.GET - } - ), - connectionRoutes.get - ) - // POST /incoming-payments // Create incoming payment router.post>( diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index 395e4a464c..7e71eb1b51 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -38,7 +38,6 @@ import { createConnectorService } from './payment-method/ilp/connector' import { createOpenAPI } from '@interledger/openapi' import { createAuthenticatedClient as createOpenPaymentsClient } from '@interledger/open-payments' import { createConnectionService } from './open_payments/connection/service' -import { createConnectionRoutes } from './open_payments/connection/routes' import { createWalletAddressKeyService } from './open_payments/wallet_address/key/service' import { createReceiverService } from './open_payments/receiver/service' import { createRemoteIncomingPaymentService } from './open_payments/payment/incoming_remote/service' @@ -292,13 +291,6 @@ export function initIocContainer( streamServer: await deps.use('streamServer') }) }) - container.singleton('connectionRoutes', async (deps) => { - return createConnectionRoutes({ - logger: await deps.use('logger'), - incomingPaymentService: await deps.use('incomingPaymentService'), - connectionService: await deps.use('connectionService') - }) - }) container.singleton('receiverService', async (deps) => { const config = await deps.use('config') return await createReceiverService({ diff --git a/packages/backend/src/open_payments/connection/routes.ts b/packages/backend/src/open_payments/connection/routes.ts deleted file mode 100644 index 2f4570e07c..0000000000 --- a/packages/backend/src/open_payments/connection/routes.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Logger } from 'pino' -import { IncomingPaymentService } from '../payment/incoming/service' -import { ConnectionContext } from './middleware' -import { ConnectionService } from './service' - -interface ServiceDependencies { - logger: Logger - incomingPaymentService: IncomingPaymentService - connectionService: ConnectionService -} - -export interface ConnectionRoutes { - get(ctx: ConnectionContext): Promise -} - -export function createConnectionRoutes( - deps_: ServiceDependencies -): ConnectionRoutes { - const logger = deps_.logger.child({ - service: 'ConnectionRoutes' - }) - const deps = { ...deps_, logger } - return { - get: (ctx: ConnectionContext) => getConnection(deps, ctx) - } -} - -async function getConnection( - deps: ServiceDependencies, - ctx: ConnectionContext -): Promise { - const connection = deps.connectionService.get(ctx.incomingPayment) - if (!connection) return ctx.throw(404) - ctx.body = connection.toOpenPaymentsType() -} From f2e8d736d0de08515d8432d63447d50a87a3d2a0 Mon Sep 17 00:00:00 2001 From: Nathan Lie Date: Wed, 18 Oct 2023 07:20:12 -0700 Subject: [PATCH 2/3] chore: formatting --- packages/backend/src/app.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/backend/src/app.ts b/packages/backend/src/app.ts index 806b868bb2..f0e032825b 100644 --- a/packages/backend/src/app.ts +++ b/packages/backend/src/app.ts @@ -23,7 +23,6 @@ import { HttpTokenService } from './payment-method/ilp/peer-http-token/service' import { AssetService, AssetOptions } from './asset/service' import { AccountingService } from './accounting/service' import { PeerService } from './payment-method/ilp/peer/service' -import { connectionMiddleware } from './open_payments/connection/middleware' import { createWalletAddressMiddleware } from './open_payments/wallet_address/middleware' import { WalletAddress } from './open_payments/wallet_address/model' import { WalletAddressService } from './open_payments/wallet_address/service' @@ -34,9 +33,7 @@ import { RequestAction } from './open_payments/auth/middleware' import { RatesService } from './rates/service' -import { - spspMiddleware -} from './payment-method/ilp/spsp/middleware' +import { spspMiddleware } from './payment-method/ilp/spsp/middleware' import { SPSPRoutes } from './payment-method/ilp/spsp/routes' import { IncomingPaymentRoutes, From af4f469f99878dc7083d1750696de269c816896b Mon Sep 17 00:00:00 2001 From: Nathan Lie Date: Wed, 18 Oct 2023 08:12:55 -0700 Subject: [PATCH 3/3] feat: revert local openapi, remove connection routes test --- openapi/resource-server.yaml | 36 ++++++ .../open_payments/connection/routes.test.ts | 121 ------------------ 2 files changed, 36 insertions(+), 121 deletions(-) delete mode 100644 packages/backend/src/open_payments/connection/routes.test.ts diff --git a/openapi/resource-server.yaml b/openapi/resource-server.yaml index 4b2718afc0..6a0589b1d5 100644 --- a/openapi/resource-server.yaml +++ b/openapi/resource-server.yaml @@ -103,6 +103,42 @@ paths: operationId: get-wallet-addres-keys description: Retrieve the public keys of the Wallet Address. security: [] + '/connections/{id}': + servers: + - url: 'https://openpayments.guide' + get: + summary: Get ILP STREAM credentials for a connection + tags: + - stream-connection + responses: + '200': + description: Connection Found + content: + application/json: + schema: + $ref: '#/components/schemas/ilp-stream-connection' + examples: + Get connection: + value: + id: 'https://openpayments.guide/connections/016da9d5-c9a4-4c80-a354-86b915a04ff8' + ilpAddress: g.ilp.iwuyge987y.98y0f34tsrt8y + sharedSecret: 1c7eaXa4rd2fFOBl1iydvCT1tV5TbM3RW1WLCafu_JA + assetCode: USD + assetScale: 2 + '404': + description: Connection Not Found + operationId: get-ilp-stream-connection + description: |- + *NB* Use server url specific to this path. + + Fetch new connection credentials for an ILP STREAM connection. + + A connection is an ephemeral resource that is created to accommodate new incoming payments. + + A new set of credential will be generated each time this API is called. + security: [] + parameters: + - $ref: '#/components/parameters/id' /incoming-payments: post: summary: Create an Incoming Payment diff --git a/packages/backend/src/open_payments/connection/routes.test.ts b/packages/backend/src/open_payments/connection/routes.test.ts deleted file mode 100644 index 297f76cdfc..0000000000 --- a/packages/backend/src/open_payments/connection/routes.test.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { IocContract } from '@adonisjs/fold' -import { Knex } from 'knex' -import jestOpenAPI from 'jest-openapi' - -import { AppServices } from '../../app' -import { Config, IAppConfig } from '../../config/app' -import { createTestApp, TestContainer } from '../../tests/app' -import { truncateTables } from '../../tests/tableManager' -import { initIocContainer } from '../../' -import { ConnectionContext } from './middleware' -import { ConnectionRoutes } from './routes' -import { createAsset } from '../../tests/asset' -import { createContext } from '../../tests/context' -import { WalletAddress } from '../wallet_address/model' -import { - IncomingPayment, - IncomingPaymentState -} from '../payment/incoming/model' -import { createIncomingPayment } from '../../tests/incomingPayment' -import { createWalletAddress } from '../../tests/walletAddress' -import base64url from 'base64url' - -describe('Connection Routes', (): void => { - let deps: IocContract - let appContainer: TestContainer - let knex: Knex - let config: IAppConfig - let connectionRoutes: ConnectionRoutes - - beforeAll(async (): Promise => { - config = Config - config.authServerGrantUrl = 'https://auth.wallet.example/authorize' - deps = await initIocContainer(config) - appContainer = await createTestApp(deps) - knex = appContainer.knex - const { resourceServerSpec } = await deps.use('openApi') - jestOpenAPI(resourceServerSpec) - }) - - let walletAddress: WalletAddress - let incomingPayment: IncomingPayment - beforeEach(async (): Promise => { - connectionRoutes = await deps.use('connectionRoutes') - config = await deps.use('config') - - const asset = await createAsset(deps) - walletAddress = await createWalletAddress(deps, { assetId: asset.id }) - incomingPayment = await createIncomingPayment(deps, { - walletAddressId: walletAddress.id, - expiresAt: new Date(Date.now() + 30_000), - incomingAmount: { - value: BigInt('123'), - assetScale: asset.scale, - assetCode: asset.code - }, - metadata: { - description: 'hello world', - externalRef: '#123' - } - }) - }) - - afterEach(async (): Promise => { - await truncateTables(knex) - }) - - afterAll(async (): Promise => { - await appContainer.shutdown() - }) - - describe('get', (): void => { - test.each` - state - ${IncomingPaymentState.Completed} - ${IncomingPaymentState.Expired} - `( - `returns 404 for $state incoming payment`, - async ({ state }): Promise => { - await incomingPayment.$query(knex).patch({ - state, - expiresAt: - state === IncomingPaymentState.Expired ? new Date() : undefined - }) - const ctx = createContext({ - headers: { Accept: 'application/json' }, - url: `/connections/${incomingPayment.connectionId}` - }) - ctx.incomingPayment = incomingPayment - await expect(connectionRoutes.get(ctx)).rejects.toHaveProperty( - 'status', - 404 - ) - } - ) - - test('returns 200 with connection', async (): Promise => { - const ctx = createContext({ - headers: { Accept: 'application/json' }, - url: `/connections/${incomingPayment.connectionId}` - }) - ctx.incomingPayment = incomingPayment - await expect(connectionRoutes.get(ctx)).resolves.toBeUndefined() - expect(ctx.response).toSatisfyApiSpec() - - const sharedSecret = (ctx.response.body as Record)[ - 'sharedSecret' - ] - - expect(ctx.body).toEqual({ - id: `${config.openPaymentsUrl}/connections/${incomingPayment.connectionId}`, - ilpAddress: expect.stringMatching(/^test\.rafiki\.[a-zA-Z0-9_-]{95}$/), - sharedSecret, - assetCode: incomingPayment.asset.code, - assetScale: incomingPayment.asset.scale - }) - const sharedSecretBuffer = Buffer.from(sharedSecret as string, 'base64') - expect(sharedSecretBuffer).toHaveLength(32) - expect(sharedSecret).toEqual(base64url(sharedSecretBuffer)) - }) - }) -})