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

Decrypt encrypted metadata #4667

Merged
merged 26 commits into from
Aug 6, 2024

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented Jul 8, 2024

Idea is to enable decryption of already encrypted metadata in decodeTransaction. The user specifies passphrase in which metadata was encrypted and the metadata located as in CIP83 is decrypted. The change is added in non-intrusive way. Due to lack of JSON instances exposure in cardano-api the needed functions were added (they are about to be erased when cardano-api exposes metadataValueFromJsonNoSchema in next node versions).

The heart of solution is fromMetadataEncrypted. Api spec was updated. Integration tests expanded to show the case.

Comments

Issue Number

adp-3348

@paweljakubas paweljakubas self-assigned this Jul 8, 2024
@paweljakubas paweljakubas marked this pull request as ready for review July 9, 2024 09:22
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-3348/decrypt-encrypted-metadata branch from c95d74c to 5435a5b Compare July 10, 2024 04:47
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a comment

Choose a reason for hiding this comment

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

Thank you! First round of comments. 🤓

specifications/api/metadata-encrypt.md Show resolved Hide resolved
specifications/api/metadata-encrypt.md Show resolved Hide resolved
specifications/api/metadata-encrypt.md Outdated Show resolved Hide resolved
specifications/api/metadata-encrypt.md Show resolved Hide resolved
specifications/api/metadata-encrypt.md Outdated Show resolved Hide resolved
specifications/api/metadata-encrypt.md Outdated Show resolved Hide resolved
lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs Outdated Show resolved Hide resolved
lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs Outdated Show resolved Hide resolved
lib/wallet/src/Cardano/Wallet.hs Outdated Show resolved Hide resolved
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-3348/decrypt-encrypted-metadata branch from 5435a5b to fe20c90 Compare July 17, 2024 15:22
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-3348/decrypt-encrypted-metadata branch 2 times, most recently from 0fee12a to 642f5e2 Compare July 19, 2024 17:32
lib/api/src/Cardano/Wallet/Api/Types/SchemaMetadata.hs Outdated Show resolved Hide resolved
lib/api/src/Cardano/Wallet/Api/Types/SchemaMetadata.hs Outdated Show resolved Hide resolved
-- [TxMetaText base64_1, TxMetaText base64_2, ..., TxMetaText base64_n]
-- (d) add `enc` field with encryption method value 'basic'
toMetadataEncrypted
:: ByteString
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
:: ByteString
:: Passphrase "lenient"

This type documents the purpose of the parameter more clearly.

lib/api/src/Cardano/Wallet/Api/Types/SchemaMetadata.hs Outdated Show resolved Hide resolved
lib/api/src/Cardano/Wallet/Api/Types/SchemaMetadata.hs Outdated Show resolved Hide resolved
-- (d) update structure
-- (e) decode metadata
fromMetadataEncrypted
:: ByteString
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
:: ByteString
:: Passphrase "lenient"

lib/api/src/Cardano/Wallet/Api/Types/SchemaMetadata.hs Outdated Show resolved Hide resolved
lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs Outdated Show resolved Hide resolved
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a comment

Choose a reason for hiding this comment

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

Second round of review. I insist on the separation of concerns. 🤓

After addressing the separation of concerns, I would also like to see property tests for

toMetadataEncrypted pwd . fromMetadataEncrypted pwd = id
fromMetadataEncrypted pwd . toMetadataEncrypted pwd = id

These two properties are vital to the whole feature and we need to cover them with extensive property tests in a way that integration tests cannot achieve.

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-3348/decrypt-encrypted-metadata branch 2 times, most recently from 153408d to d9f8a2d Compare July 30, 2024 14:59
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-3348/decrypt-encrypted-metadata branch from 481cf05 to 099416a Compare July 31, 2024 07:58
@paweljakubas paweljakubas mentioned this pull request Jul 31, 2024
4 tasks
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a comment

Choose a reason for hiding this comment

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

Much better, thank you! 😊 The new module is much more, well, modular, and also captures the possible error conditions nicely.

But I still have a couple of comments that I would like to see fixed before merging:

  • isRight encrypted in the tests — having this here decreases my confidence in the tests unless we also use cover, fortunately, I don't think that it's necessary here.
  • error in fromMetadaEncrypted — unfortunately, I think that this case can be hit when the metadata is sufficiently malformed. We need to turn this into a Left instead.

See detailed comments.

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-3348/decrypt-encrypted-metadata branch 2 times, most recently from 55868d2 to df60f0c Compare August 5, 2024 17:04
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-3348/decrypt-encrypted-metadata branch from df60f0c to 81231cc Compare August 6, 2024 08:10
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a comment

Choose a reason for hiding this comment

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

Thank you! 😊 Good to merge now — but could you squash the commits a little bit?

relocation to primitive 2

relocation to primitive 3

relocation to primitive 4

relocation to primitive 5
adjust unit tests

another property
hlint

rebase cleanup
improve on unit tests - part 2

improve on unit tests - part 3 and add better error handling
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-3348/decrypt-encrypted-metadata branch from 81231cc to 3027af8 Compare August 6, 2024 11:44
@paweljakubas paweljakubas enabled auto-merge August 6, 2024 11:45
@paweljakubas paweljakubas added this pull request to the merge queue Aug 6, 2024
Merged via the queue into master with commit b887956 Aug 6, 2024
23 checks passed
@paweljakubas paweljakubas deleted the paweljakubas/adp-3348/decrypt-encrypted-metadata branch August 6, 2024 14:58
WilliamKingNoel-Bot pushed a commit that referenced this pull request Aug 6, 2024
…points the work accomplished in this PR. Before you submit, don't forget to: CODE-OF-CONDUCT.md CONTRIBUTING.md LICENSE MAINTAINERS.md README.md cabal.project configs docker-compose.yml docs flake.lock flake.nix floskell.json fourmolu.yaml hie-direnv.yaml justfile lib nix prototypes reports run scripts specifications test touch.me.CI weeder.dhall Make sure the GitHub PR fields are correct: ✓ Set a good Title for your PR. ✓ Assign yourself to the PR. ✓ Assign one or more reviewer(s). ✓ Link to a Jira issue, and/or other GitHub issues or PRs. ✓ In the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages. CODE-OF-CONDUCT.md CONTRIBUTING.md LICENSE MAINTAINERS.md README.md cabal.project configs docker-compose.yml docs flake.lock flake.nix floskell.json fourmolu.yaml hie-direnv.yaml justfile lib nix prototypes reports run scripts specifications test touch.me.CI weeder.dhall Don't waste reviewers' time: ✓ If it's a draft, select the Create Draft PR option. ✓ Self-review your changes to make sure nothing unexpected slipped through. CODE-OF-CONDUCT.md CONTRIBUTING.md LICENSE MAINTAINERS.md README.md cabal.project configs docker-compose.yml docs flake.lock flake.nix floskell.json fourmolu.yaml hie-direnv.yaml justfile lib nix prototypes reports run scripts specifications test touch.me.CI weeder.dhall Try to make your intent clear: ✓ Write a good Description that explains what this PR is meant to do. ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding Jira ticket. ✓ Highlight what Testing you have done. ✓ Acknowledge any changes required to the Documentation. --> Idea is to enable decryption of already encrypted metadata in decodeTransaction. The user specifies passphrase in which metadata was encrypted and the metadata located as in CIP83 is decrypted. The change is added in non-intrusive way. Due to lack of JSON instances exposure in cardano-api the needed functions were added (they are about to be erased when cardano-api exposes `metadataValueFromJsonNoSchema` in next node versions). The heart of solution is `fromMetadataEncrypted`. Api spec was updated. Integration tests expanded to show the case. ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number adp-3348 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Source commit: b887956
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants