feat: add typed constructors for AuthSingleSig#2722
Open
giwaov wants to merge 1 commit into0xMiden:nextfrom
Open
feat: add typed constructors for AuthSingleSig#2722giwaov wants to merge 1 commit into0xMiden:nextfrom
giwaov wants to merge 1 commit into0xMiden:nextfrom
Conversation
Add scheme-specific constructors that accept typed public keys instead of a generic PublicKeyCommitment, preventing mismatches between key type and authentication scheme: - falcon512_poseidon2(pub_key): creates component from a Falcon512 key - ecdsa_k256_keccak(pub_key): creates component from an ECDSA K256 key - from_public_key(pub_key): creates component from a PublicKey enum Also add From<ecdsa_k256_keccak::PublicKey> for PublicKeyCommitment for parity with the existing Falcon512 conversion. Closes 0xMiden#2537
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add scheme-specific constructors to
AuthSingleSigthat accept typed public keys directly, preventing mismatches between the key type and authentication scheme.Rationale
The existing
AuthSingleSig::new(pub_key_commitment, auth_scheme)constructor takes a genericPublicKeyCommitmentand a separateAuthScheme, which allows callers to accidentally pair an ECDSA key commitment withAuthScheme::Falcon512Poseidon2(or vice versa). Typed constructors eliminate this class of bug by deriving the scheme from the key type.Changes
crates/miden-standards/src/account/auth/singlesig.rs:falcon512_poseidon2(pub_key): accepts afalcon512_poseidon2::PublicKeyand creates the component with the correct schemeecdsa_k256_keccak(pub_key): accepts anecdsa_k256_keccak::PublicKeyand creates the component with the correct schemefrom_public_key(pub_key): accepts aPublicKeyenum and extracts both the scheme and commitmentcrates/miden-protocol/src/account/auth.rs:From<ecdsa_k256_keccak::PublicKey> for PublicKeyCommitmentfor parity with the existing Falcon512 conversion (required by the new constructors)The existing
new()constructor is preserved for backward compatibility.Test plan
cargo check -p miden-standardsandcargo check -p miden-protocolboth passnew()constructor is unchangednew()with type-safe inputsCloses #2537