-
Notifications
You must be signed in to change notification settings - Fork 217
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
[ADP-322] Add metadata encryption to HTTP API. #4555
[ADP-322] Add metadata encryption to HTTP API. #4555
Conversation
fa84e60
to
1842e52
Compare
0cb0d8b
to
78798e7
Compare
fb38fbf
to
c2d8bb9
Compare
eda0d55
to
1c48366
Compare
|
||
data ApiEncryptMetadata = ApiEncryptMetadata | ||
{ passphrase :: ApiT (Passphrase "lenient") | ||
, enc :: Maybe EncryptMetadataMethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what reason do we allow this field to be Nothing
?
If it is set to Nothing
, then what do we expect the behaviour to be?
if txt == "basic" then | ||
pure AES256CBC | ||
else | ||
fail "'basic' is expected." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: derive this instance automatically.
See: #4588
Cipher algorithm uses 8-byte salt, PKCS#7 padding as specified in | ||
https://datatracker.ietf.org/doc/html/rfc5652#section-6.3 is applied. | ||
Only metadata value under `msg` field is encrypted. If `msg` field is missing error | ||
will be emitted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a user who is new to this feature, I'm finding this description
section a little hard to follow!
For example, it refers to a field called msg
. However, this object only has two fields: enc
and passphrase
.
From reading through the tests (Api.TypesSpec
), I can see that msg
is supposed to be the key in a TxMetaMap
.
Is there any way that we can give a more complete description of how to use this feature? (Ideally, so that the user doesn't have to go hunting through CIP 83.)
fbfb5a7
to
556012e
Compare
556012e
to
29d71c2
Compare
dc28dc5
to
70a1c46
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for creating this PR and for your patience with waiting for reviews.
Given this PR adds just the encryption functionality, with decryption planned for a later PR, I think this PR is okay to merge for now.
However, I do have some proposals that I think should be addressed in subsequent PRs:
-
Currently, the "business logic" for metadata encryption is located within the
Cardano.Wallet.Api.Http.Shelley.Server
module. I would propose to extract this logic out into a pure function that (a). doesn't rely on HTTP API types and (b). lives in a more appropriate location, preferably outside of theServer
module, so that theServer
module only needs to handle concerns that directly relate to the HTTP API. Perhaps this new location could be something likeCardano.Write.Tx.Metadata.Encryption
? -
I would propose to replace all instances of the magic value
674
with references to thecip20MetadataKey
constant (already used bytoMetadataEncrypted
), and similarly, to re-locate this constant to the proposedCardano.Write.Tx.Metadata.Encryption
module. -
When we have a pure function that performs decryption, I would propose to:
- add a new test module
Cardano.Write.Tx.Metadata.EncryptionSpec
. - add a QuickCheck property test for the encryption-decryption round-trip property:
decrypt . encrypt == id
. - add a selection of golden example-based unit tests (i.e., tests that are very quick to run that don't require us to fire up the integration test suite).
- add a new test module
-
I still find the description of
x-encryptMetadata
in the swagger file a little hard to follow. Perhaps it would be possible to find someone who is completely new to this feature, and work with them to revise this description in a way that is easier for new users to understand? (See earlier review comment: https://github.com/cardano-foundation/cardano-wallet/pull/4555/files#r1599427620)
Again, many thanks again for creating this PR!
Jonathan
The key returned by `findMsgValue` was always equal to the value of the `cip20MetadataKey` constant. Other functions that need to refer to this constant can do so directly.
The `bimap` function is already widely used within this codebase, and is exported from `base`, whereas `mapBoth` requires the use of an additional library.
Of `encryptMessage`.
0bb3ed6
to
a83c7e1
Compare
…ail in a few bullet 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 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 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 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. --> - [x] Adding noninvasive api changes to `constructTransaction` - [x] Applying changes to Api.Server - [x] Extend `ErrConstructTx` - [x] Implementing `toMetadataEncryption` according to https://github.com/cardano-foundation/CIPs/tree/master/CIP-0083 - [x] Prepare goldens in line to openSSL and CIP83 examples - [x] Show error emitting works - [x] Add salting to key gen and encryption - [x] Add integration test showing error - [x] Add integration test showing encryption ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number adp-322 <!-- 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: a2cac93
constructTransaction
ErrConstructTx
toMetadataEncryption
according to https://github.com/cardano-foundation/CIPs/tree/master/CIP-0083Comments
Issue Number
adp-322