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

refactor: only use ready connection for inbound #360

Conversation

TimoGlastra
Copy link
Contributor

@TimoGlastra TimoGlastra commented Jul 3, 2021

Breaking up this PR as discussed. See #396 for first sub-PR


This PR became a bit bigger than anticipated, but one change led to another and so on. However I do think this PR packs some nice improvements.

validation on incoming messages

Fixes #68

Although used a lot, we weren't putting the validation decorators to good use yet (@IsString, etc...). I've enabled them and made updates where needed to make them valid. Already found some bugs. I think once we update the AFJ backchannel for AATH we'll probably find some more interop issues with ACA-Py.

Only attach connection to inbound message context if sender and receiver match and connection is ready

Fixes #76

We were attaching the connection before it was ready and didn't do all necessary checks to make sure we're actually in the context of this connection. The connection is now only attached if the connection is ready to be used and fully matches with the incoming recipient and sender key.

### Break out indy wallet

Fixes #330

It didn't make a lot of sense to me that the indy wallet was handling indy storage and ledger stuff. I think it belongs more in the ledger and storage services. This is also more in line with where we're headed with the shared components libraries

  • Rename LedgerService to IndyLedgerService. It's very indy focussed now.
  • move storage related methods to IndyStorageService
  • move ledger related methods to IndyLedgerService

Better indy message handling

Sometimes you would get very cryptic errors such as CommonInvalidParam without a stack trace or anything that would help you get a sense of what's erroring out. I've wrapped all indy calls with a try catch and added a new IndySdkError. This will take the indy error as input, but with very nice stack tracing so you know exactly where things went wrong, without losing information from the indy error


Also fixed a bug where the mediator would terminate on unhandled promise

Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
@TimoGlastra TimoGlastra requested a review from a team as a code owner July 3, 2021 22:30
@codecov-commenter
Copy link

codecov-commenter commented Jul 3, 2021

Codecov Report

Merging #360 (075cca9) into main (52c7897) will increase coverage by 0.00%.
The diff coverage is 84.43%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #360   +/-   ##
=======================================
  Coverage   85.65%   85.66%           
=======================================
  Files         253      254    +1     
  Lines        5467     5498   +31     
  Branches      878      884    +6     
=======================================
+ Hits         4683     4710   +27     
- Misses        783      787    +4     
  Partials        1        1           
Impacted Files Coverage Δ
packages/core/src/modules/proofs/ProofsModule.ts 90.00% <ø> (ø)
.../core/src/modules/routing/handlers/BatchHandler.ts 50.00% <0.00%> (ø)
...src/modules/routing/handlers/BatchPickupHandler.ts 54.54% <0.00%> (-5.46%) ⬇️
.../core/src/modules/routing/messages/BatchMessage.ts 56.52% <55.55%> (+4.14%) ⬆️
packages/core/src/agent/Dispatcher.ts 81.39% <62.50%> (-5.10%) ⬇️
...ecorators/transport/TransportDecoratorExtension.ts 78.94% <66.66%> (-4.39%) ⬇️
packages/core/src/agent/MessageReceiver.ts 89.18% <69.23%> (-3.24%) ⬇️
...c/modules/routing/handlers/KeylistUpdateHandler.ts 92.30% <75.00%> (+0.64%) ⬆️
.../modules/connections/services/ConnectionService.ts 95.62% <82.35%> (-1.55%) ⬇️
.../modules/credentials/messages/CredentialPreview.ts 85.71% <83.33%> (+1.09%) ⬆️
... and 45 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52c7897...075cca9. Read the comment docs.

Signed-off-by: Timo Glastra <timo@animo.id>
@JamesKEbert
Copy link
Contributor

These are some good additions--and I will give some additional review once you find this is in a good state @TimoGlastra as discussed in the WG call on the 15th, which IIRC may include you splitting this out into additional PRs.

Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
Signed-off-by: Timo Glastra <timo@animo.id>
@TimoGlastra
Copy link
Contributor Author

@jakubkoci @JamesKEbert @blu3beri I've updated this PR with latest changes. Although there are still a lot of changed files, most of it is adding class-validator decorators.

Could you take a look so we can get it merged? :)

Copy link
Contributor

@berendsliedrecht berendsliedrecht left a comment

Choose a reason for hiding this comment

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

Very nice! love the addition of a lot more validators.

Just left some minor points, but nothing major.

// We check whether the sender key is the same as the key we have stored in the connection
// otherwise everyone could send messages to our key and we would just accept
// it as if it was send by the key of the connection.
// Throw error if the recipient key (ourKey) does not match the key of the connection record
if (connection && connection.theirKey != null && connection.theirKey != senderKey) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not your line, but why do we check if connection.theirKey is not null? The last check connection.theirKey != senderKey should suffice.

Also we should do !==

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't completely suffice, as in this case if connection.theirKey is null, it will not throw the error. If theirKey is null, and senderKey isn't (it will never be null due to check above) it will throw the error.

if connection.theirKey is null it means the connection does not have their key yet (we've sent an invitation, but didn't receive a request yet). This check is mostly to check if a connection that already has theirKey matches the key of the message we received

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree on the !== however

@@ -22,6 +22,7 @@ export class TimingDecorator {
@Expose({ name: 'in_time' })
@Type(() => Date)
@IsDate()
@IsOptional()
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really a comment, but is there a particular order we want to add these decorators?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. I'm not sure if there are sorters for decorators (as the order can matter I think) and doing it manually seems tedious

validateOrReject(JsonTransformer.fromJSON(obj, TransportDecorator))
const expectValid = (obj: Record<string, unknown>) => expect(validTranport(obj)).resolves.toBeUndefined()
const expectInvalid = (obj: Record<string, unknown>) => expect(validTranport(obj)).rejects.not.toBeNull()
const validTransport = (obj: Record<string, unknown>) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, but could we make obj a bit more verbose?

@@ -19,11 +19,13 @@ export class Credential {
@Expose({ name: 'cred_info' })
@Type(() => IndyCredentialInfo)
@ValidateNested()
@IsInstance(IndyCredentialInfo)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a common pattern of adding the @type decorator and the @IsInstance decorator. Is there a way to combine these decorators? Can be in a seperate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be. I'm not sure if it is easy to combine two decorators and make the work like before (as it needs the field data)

@@ -141,7 +142,7 @@ export class ProofsModule {
*/
public async requestProof(
connectionId: string,
proofRequestOptions: ProofRequestOptions,
proofRequestOptions: RequestProofOptions,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the reorder of words? Shouldn't we also rename the param then? And the line below:

config?: ProofRequestConfig to config?: RequestProofConfig or requestProofConfig?: RequestProofConfig

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is kinda messy. I'll take a look


import { AgentMessage } from '../../../agent/AgentMessage'

export enum KeylistUpdateAction {
add = 'add',
Copy link
Contributor

Choose a reason for hiding this comment

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

Camelcase?

Signed-off-by: Timo Glastra <timo@animo.id>
@TimoGlastra
Copy link
Contributor Author

If no one else is going to review, I'm going to merge this PR

@TimoGlastra TimoGlastra merged commit cb256ca into openwallet-foundation:main Oct 2, 2021
@TimoGlastra TimoGlastra deleted the refactor/only-ready-connection branch October 28, 2021 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants