Skip to content

feat: add typed constructors for AuthSingleSig#2722

Open
giwaov wants to merge 1 commit into0xMiden:nextfrom
giwaov:feat/auth-singlesig-constructors
Open

feat: add typed constructors for AuthSingleSig#2722
giwaov wants to merge 1 commit into0xMiden:nextfrom
giwaov:feat/auth-singlesig-constructors

Conversation

@giwaov
Copy link
Copy Markdown

@giwaov giwaov commented Apr 4, 2026

Summary

Add scheme-specific constructors to AuthSingleSig that 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 generic PublicKeyCommitment and a separate AuthScheme, which allows callers to accidentally pair an ECDSA key commitment with AuthScheme::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 a falcon512_poseidon2::PublicKey and creates the component with the correct scheme
  • ecdsa_k256_keccak(pub_key): accepts an ecdsa_k256_keccak::PublicKey and creates the component with the correct scheme
  • from_public_key(pub_key): accepts a PublicKey enum and extracts both the scheme and commitment

crates/miden-protocol/src/account/auth.rs:

  • Add From<ecdsa_k256_keccak::PublicKey> for PublicKeyCommitment for 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-standards and cargo check -p miden-protocol both pass
  • Existing tests continue to pass since the original new() constructor is unchanged
  • The new constructors are thin wrappers over new() with type-safe inputs

Closes #2537

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
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.

Create explicit constructors for AuthSingleSig

1 participant