Skip to content

(Re)move keys and credential decoding layer - #1332

Open
palas wants to merge 8 commits into
masterfrom
move-keys
Open

(Re)move keys and credential decoding layer#1332
palas wants to merge 8 commits into
masterfrom
move-keys

Conversation

@palas

@palas palas commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

DO NOT MERGE: work in progress and contains SRPs

Context

In IntersectMBO/cardano-keys#4, we move cardano key machinery to a separate repo with fewer dependencies than cardano-api, so that they can be used by testing projects in the consensus repos, among others, without having to depend in the full stack that cardano-api requires.

This PR simply removes things that were moved, and links existing code so that it uses them from cardano-keys.

Initially, this PR has an SRP to ensure that it works before we release cardano-keys. After cardano-keys is released we will remove that SRP and depend directly through CHaP.

How to trust this PR

The thing to check would be that it all keeps working, and that everything was moved as it was, and nothing was deleted here that was not added in IntersectMBO/cardano-keys#4, other than the refactorings and modifications that were necessary. CI passing would be a pretty good sign that both this PR and IntersectMBO/cardano-keys#4 are correct.

Additionally IntersectMBO/cardano-cli#1444 builds on this PR to ensure cardano-cli will build and tests pass.

You can use this report to check what was moved, copied, deleted, or written from scratch in cardano-keys.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff
  • Changelog fragment added in .changes/

The key layer now lives in its own package. The source-repository-package
is temporary, until cardano-keys has its first CHaP release, so the repo is
listed in master-check-exceptions.list. random is no longer imported directly
by the library.
Module names and export lists are unchanged. What each module still holds
locally is what cardano-keys does not provide: the Error instances, the
parsec parsers, the era-coupled and file-based text-envelope functions, and
the operational certificate issuing half.

The golden error files are keyed by the defining module of the error type, so
the two directories for the types that moved are renamed. Their contents are
unchanged.
Every HasTextEnvelope instance defines textEnvelopeTypes now. Call sites that
want the single type to write keep using textEnvelopeType, which is a free
function over the head of that list.
Cardano.Keys.Serialise.Orphans carries these, and a second definition in the
same dependency graph is a duplicate-instance error.
@palas palas self-assigned this Sep 8, 2026
Copilot AI lite review requested due to automatic review settings September 8, 2026 13:37
@palas palas changed the title Move keys Move keys and credential decoding layer Sep 8, 2026
@palas palas changed the title Move keys and credential decoding layer (Re)move keys and credential decoding layer Sep 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

It introduces a large breaking refactor with a new cross-repo dependency and broad API/serialisation surface impact that warrants final human verification beyond automated checks.

Pull request overview

Moves key-related machinery (key types, hashes, and multiple serialisation layers) out of cardano-api into the new cardano-keys package, while keeping cardano-api’s module names and re-exports stable for downstream compatibility. This PR also adapts the public API to the new HasTextEnvelope shape and pins cardano-keys via a temporary source-repository-package until it is available through CHaP.

Changes:

  • Replaces substantial in-repo implementations (key types + CBOR/Bech32/raw-bytes/text-envelope serialisation) with re-exports from cardano-keys, preserving compatibility surfaces.
  • Updates HasTextEnvelope instances to the new textEnvelopeTypes :: AsType a -> NonEmpty TextEnvelopeType method and re-exports textEnvelopeType as a convenience function.
  • Adds a temporary source-repository-package pin for cardano-keys, updates the cabal dependency graph, and adjusts golden error outputs to match the moved/rendered error formatting.
File summaries
File Description
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.TextEnvelope.TextEnvelopeError/TextEnvelopeUnknownType.txt Adds golden output for unknown text-envelope type rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.TextEnvelope.TextEnvelopeError/TextEnvelopeUnknownKeyWitness.txt Adds golden output for unknown key witness error rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.TextEnvelope.TextEnvelopeError/TextEnvelopeTypeError.txt Adds golden output for text-envelope type mismatch rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.TextEnvelope.TextEnvelopeError/TextEnvelopeDecodeError.txt Adds golden output for CBOR decode error rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.TextEnvelope.TextEnvelopeError/TextEnvelopeAesonDecodeError.txt Adds golden output for Aeson decode error rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.Bech32.Bech32DecodeError/Bech32WrongPrefix.txt Adds golden output for Bech32 wrong-prefix rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.Bech32.Bech32DecodeError/Bech32UnexpectedPrefix.txt Adds golden output for Bech32 unexpected-prefix rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.Bech32.Bech32DecodeError/Bech32UnexpectedHeader.txt Adds golden output for CIP-129 header mismatch rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.Bech32.Bech32DecodeError/Bech32InvalidUtf8.txt Adds golden output for invalid UTF-8 Bech32 input rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.Bech32.Bech32DecodeError/Bech32DeserialiseFromBytesError.txt Adds golden output for data-part deserialisation failure rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.Bech32.Bech32DecodeError/Bech32DecodingError.txt Adds golden output for underlying Bech32 decoding error rendering.
cardano-api/test/cardano-api-golden/files/errors/Cardano.Keys.Serialise.Bech32.Bech32DecodeError/Bech32DataPartToBytesError.txt Adds golden output for Bech32 data-part extraction failure rendering.
cardano-api/src/Cardano/Api/Tx/Internal/Sign.hs Updates HasTextEnvelope instances to implement textEnvelopeTypes.
cardano-api/src/Cardano/Api/Serialise/TextEnvelope/Internal.hs Re-exports text-envelope codec/decoders from cardano-keys; keeps Error instance locally via renderTextEnvelopeError.
cardano-api/src/Cardano/Api/Serialise/TextEnvelope.hs Re-exports textEnvelopeType at the public wrapper module level.
cardano-api/src/Cardano/Api/Serialise/SerialiseUsing.hs Switches to a compatibility re-export of Cardano.Keys.Serialise.Using.
cardano-api/src/Cardano/Api/Serialise/Raw.hs Re-exports raw-bytes serialisation from cardano-keys; retains parsing helper and local Error instances using render… functions.
cardano-api/src/Cardano/Api/Serialise/Cbor.hs Re-exports CBOR serialisation interfaces from cardano-keys.
cardano-api/src/Cardano/Api/Serialise/Bech32.hs Re-exports Bech32 serialisation from cardano-keys; keeps local Error instance via renderBech32DecodeError.
cardano-api/src/Cardano/Api/Query/Internal/Type/QueryInMode.hs Updates HasTextEnvelope usage to textEnvelopeTypes and imports NonEmpty.
cardano-api/src/Cardano/Api/ProtocolParameters.hs Updates HasTextEnvelope instance to textEnvelopeTypes.
cardano-api/src/Cardano/Api/Plutus/Internal/Script.hs Updates script-related HasTextEnvelope instances to textEnvelopeTypes.
cardano-api/src/Cardano/Api/Key/Internal/Praos.hs Replaces in-repo Praos key implementation with re-export from Cardano.Keys.Praos.
cardano-api/src/Cardano/Api/Key/Internal/Leios.hs Replaces in-repo Leios key implementation with re-export from Cardano.Keys.Leios.
cardano-api/src/Cardano/Api/Key/Internal/Class.hs Replaces in-repo key class definitions with re-export from Cardano.Keys.Class.
cardano-api/src/Cardano/Api/Key/Internal.hs Replaces large Shelley key implementation with re-export from Cardano.Keys.Shelley, keeping parsing helper.
cardano-api/src/Cardano/Api/Internal/Orphans/Serialisation.hs Removes orphan CBOR instances that now live elsewhere after the extraction.
cardano-api/src/Cardano/Api/Internal/Orphans/Misc.hs Drops Data-deriving orphans tied to moved/removed serialisation error types.
cardano-api/src/Cardano/Api/HasTypeProxy.hs Re-exports HasTypeProxy infrastructure from cardano-keys.
cardano-api/src/Cardano/Api/Hash.hs Re-exports hash types/utilities from cardano-keys.
cardano-api/src/Cardano/Api/Governance/Internal/Poll.hs Updates HasTextEnvelope instance to textEnvelopeTypes.
cardano-api/src/Cardano/Api/Governance/Internal/Action/VotingProcedure.hs Updates governance action HasTextEnvelope instances to textEnvelopeTypes.
cardano-api/src/Cardano/Api/Governance/Internal/Action/ProposalProcedure.hs Updates proposal HasTextEnvelope instance to textEnvelopeTypes.
cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Certificate/Type.hs Updates experimental certificate HasTextEnvelope instance to textEnvelopeTypes.
cardano-api/src/Cardano/Api/Experimental/Plutus/Internal/Script.hs Updates experimental plutus script HasTextEnvelope instance to textEnvelopeTypes.
cardano-api/src/Cardano/Api/Certificate/Internal/OperationalCertificate.hs Re-exports operational certificate types/accessors from cardano-keys; retains issuing function in cardano-api.
cardano-api/src/Cardano/Api/Byron/Internal/Key.hs Replaces in-repo Byron key implementation with re-export from Cardano.Keys.Byron.
cardano-api/cardano-api.cabal Adds cardano-keys dependency and removes now-unused random dependency.
cabal.project Temporarily pins cardano-keys via source-repository-package until CHaP release.
.github/master-check-exceptions.list Adds cardano-keys repo URL to master-check exception list.
.changes/depend-on-cardano-keys.yml Adds changelog fragment correctly marking the change as breaking and documenting key API deltas.
Review details
  • Files reviewed: 29/41 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

With the cardano-keys dependency added, the GHC 9.14 plan greedily
selects crypton 1.1.4, which cardano-crypto-class rejects, so the
x86_64 evaluation fails. Both packages already require crypton < 1.1;
stating it as a constraint keeps the solver on that version.
cardano-keys capped cardano-crypto at ^>=1.1, rejecting the 1.3.0 the
GHC 9.14 plan needs, so the x86_64 evaluation was unsolvable. The
re-pinned commit drops the cap; verified with a real GHC 9.14.1 solve.
Comment thread cabal.project
-- cardano-crypto-class (in cardano-api and in the cardano-keys dependency)
-- requires crypton < 1.1; without this the GHC 9.14 solver greedily picks
-- crypton 1.1.4 and then cannot resolve cardano-crypto-class.
, crypton < 1.1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this should be behind GHC version check

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.

3 participants