Skip to content

feat: Add Generic Principal Decoding#58

Open
Goddhi wants to merge 5 commits intostoracha:mainfrom
Goddhi:decode-signer/verifier
Open

feat: Add Generic Principal Decoding#58
Goddhi wants to merge 5 commits intostoracha:mainfrom
Goddhi:decode-signer/verifier

Conversation

@Goddhi
Copy link

@Goddhi Goddhi commented Aug 6, 2025

generic decoding functions for principals (signers and verifiers) that can automatically detect and decode the correct implementation based on multiformat codec prefixes.
issue

@Goddhi Goddhi requested review from alanshaw and volmedo as code owners August 6, 2025 04:05
@volmedo
Copy link
Member

volmedo commented Aug 18, 2025

hey @Goddhi, thanks for the PR and sorry it's taking a while for us to review. I'll review and provide feedback shortly. In the meantime, take a look at the issue in the test run 🙏🏻

@Goddhi
Copy link
Author

Goddhi commented Aug 19, 2025

@volmedo thanks for taking a look! I’ve fixed the issue that caused the CI failure. 🙏

@alanshaw
Copy link
Member

alanshaw commented Sep 9, 2025

@Peeja did you need this feature - would you care to review?

@Peeja
Copy link
Member

Peeja commented Oct 24, 2025

@Goddhi Can you point me to what this was for? I think I'm missing context, I'm not sure why this was needed.

@Goddhi
Copy link
Author

Goddhi commented Oct 24, 2025

@Peeja Thie PR addresses the issue described in this issue 46
The problem is the principal.Signer and principal.Verifier can be encoded polymorphically using Encode(), which returns multiformat bytes containing the algorithm identifier. However, there's no way to decode those bytes back to the correct implementation automatically. Users must know in advance whether they're decoding an Ed25519 or RSA principal.
from the PR i made i introduced DecodeSigner(encoded []byte) this automatically decodes to the correct signer implementation based on the multiformat code and
DecodeVerifier(encoded []byte) automatically decodes to the correct verifier implementation.

@Peeja
Copy link
Member

Peeja commented Oct 24, 2025

@Goddhi Ah! Of course, sorry, I'm not sure why I missed the issue link before.

Copy link
Member

@Peeja Peeja left a comment

Choose a reason for hiding this comment

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

This looks great! Let's just move it around a bit. Let's move decode.Signer() to "github.com/storacha/go-ucanto/principal/ed25519/signer".Decode(), and decode.Verifier() to "github.com/storacha/go-ucanto/principal/ed25519/verifier".Decode().

As for decode.Principal(), I'm not sure we really need that one. I think if you don't know which you have, something weird is going on, and if you really need to, it's not hard to do this handling and switching yourself. Let's drop that one.

@Goddhi
Copy link
Author

Goddhi commented Oct 24, 2025

Thanks for the clarification, @Peeja That makes sense, keeping the decode logic with the specific implementations is cleaner.
i just made a new commit based on your suggestion, I removed the decode.Principal() entirely.

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.

4 participants