Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): add Open Payments client service #595

Merged
merged 6 commits into from
Sep 15, 2022
Merged

feat(backend): add Open Payments client service #595

merged 6 commits into from
Sep 15, 2022

Conversation

wilsonianb
Copy link
Contributor

@wilsonianb wilsonianb commented Sep 8, 2022

Changes proposed in this pull request

  • add Open Payments client service
  • replace calls to Pay.setupPayment
  • return correct ilpStreamConnection type
  • Update ilp-packet to pre-release version to match types of other interledgerjs dependencies.
  • downgrade axios

Context

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Documentation added
  • Make sure that all checks pass

@github-actions github-actions bot added pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related labels Sep 8, 2022
@@ -50,6 +50,7 @@
nonceRedisKey: envString('NONCE_REDIS_KEY', 'nonceToProject'),
adminKey: envString('ADMIN_KEY', 'qwertyuiop1234567890'),
sessionLength: envInt('SESSION_LENGTH', 30), // in minutes
devAccessToken: envString('DEV_ACCESS_TOKEN', 'dev-access-token'),

Check failure

Code scanning / CodeQL

Hard-coded credentials

The hard-coded value "dev-access-token" is used as [authorization header](1).
@@ -134,6 +141,13 @@ export class IncomingPayment
return `${this.paymentPointer.url}/incoming-payments/${this.id}`
}

public get hasConnection(): boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to this would be to set connectionId to null when the incoming payment transitions to Completed/Expired

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'll change it.
My only reservation is if we don't want to lose record of the connectionId

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any admin purpose we can think of where it would be beneficial to get the ilp credentials after the payment is completed or expired?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not returning the connection with a completed/expired payment is an Open Payments OpenAPI thing.
It would technically still be possible to generate ilp credentials for the incoming payment since the connectionId use only used for the connection url:
https://github.com/interledger/rafiki/pull/595/files#diff-b9b1a593e29f9fdc18a9826d0da73d506ccca8cca9e777165b4ac86b5a0bfdd5R72

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's an OP thing. I just checked the code again and remembered that it is something completely artificial that's not even used to create the STREAM credentials. In that case, set it to null.

Comment on lines +27 to +31
const validateResponse =
deps_.openApi.createResponseValidator<IncomingPaymentJSON>({
path: '/incoming-payments/{incomingPaymentId}',
method: HttpMethod.GET
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does that have to be overwritten?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validateResponse isn't included on deps_.
Or are you asking why define a response validator that should already exist in a validator middleware?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the latter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔
Nothing is being overwritten.
Both this and the auth middleware (only for the get incoming payment route) will each create the same response validator once.
However, the auth middleware does not create response validators when running in production:
https://github.com/interledger/rafiki/blob/main/packages/openapi/src/middleware.ts#L11-L12

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I misread.

}
}

export async function getIncomingPayment(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we check whether the incoming payment is a resource on the same Rafiki instance and if so, we just use the service to get it instead of the axios call + all the validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially tried that but didn't like having two code paths, one dealing with IncomingPayments model and the other dealing with IncomingPaymentJSON, the former of which duplicated a lot of functionality in middleware and incoming payments routes.ts, including the solution for #598

Copy link
Member

@sabineschaller sabineschaller Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, we keep it simple then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks up local incoming payments / connections and keeps it simpler by calling the route methods:

@@ -134,6 +141,13 @@ export class IncomingPayment
return `${this.paymentPointer.url}/incoming-payments/${this.id}`
}

public get hasConnection(): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be cleaner.

matdehaast
matdehaast previously approved these changes Sep 13, 2022
Remove publicHost from OutgoingPaymentService.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Downgrade axios Add a dev mode access token Query incoming payments directly
3 participants