Skip to main content

P256SigningKey

Struct P256SigningKey 

Source
pub struct P256SigningKey(/* private fields */);
Expand description

An ECDSA-P256 signing key. Private scalar is zeroed on drop.

Wire form: 64 raw bytes IEEE 1363 (r‖s), base64-encoded with padding for 88 characters — matching the verify path in crate::verify::verify_ecdsa_p256. DER-encoded signatures are NOT compatible with the ACDP registry entry for ecdsa-p256.

Implementations§

Source§

impl P256SigningKey

Source

pub fn generate() -> Self

Generate a fresh P-256 key pair using the OS RNG.

Recommended for production callers; from_bytes is for loading previously-stored key material.

Source

pub fn from_bytes(bytes: &[u8; 32]) -> Result<Self, AcdpError>

Construct from 32 raw scalar bytes (big-endian).

Returns AcdpError::SchemaViolation when the scalar is invalid (e.g. zero or ≥ curve order). The error variant matches the shape used elsewhere for key-material parse failures (AgentDid::parse_web, validate_signature_length).

Source

pub fn from_slice(bytes: &[u8]) -> Result<Self, AcdpError>

Try to construct from a slice. Returns an error if the length is wrong.

Source

pub fn sign_content_hash(&self, hash: &ContentHash) -> String

Sign the ASCII bytes of the full content_hash string per §5.8.

Uses RFC 6979 deterministic ECDSA (no rng parameter required). Returns the signature as standard base64 of the 64-byte IEEE 1363 r‖s wire form (88 chars including padding).

Source

pub fn seed_bytes(&self) -> [u8; 32]

Return the 32-byte raw private scalar (big-endian).

P-256 analogue of SigningKey::seed_bytes. Language bindings hold this [u8; 32] and reconstruct the P256SigningKey per FFI call (the key zeroizes its scalar on drop and is not Clone). The round-trip P256SigningKey::from_bytes(&k.seed_bytes()) reconstructs an identical signing key.

The scalar is private-key material — treat it as a secret and route persistence through a key vault or HSM.

Source

pub fn sign_string(&self, input: &str) -> String

Sign the UTF-8 bytes of an arbitrary string. Returns the signature as standard base64 of the 64-byte IEEE 1363 r‖s wire form (88 chars including padding).

P-256 analogue of SigningKey::sign_string — uses RFC 6979 deterministic ECDSA, so the output is reproducible. Use this for the ACDP registry’s bearer-token challenge flow when the producer’s key is ECDSA-P256; the registry verifies with crate::verify::verify_ecdsa_p256(&sec1, &sig, input).

Source

pub fn verifying_key_sec1(&self) -> Vec<u8>

SEC1-uncompressed public key (65 bytes: 0x04 || x || y).

Use this to populate a did:web verification method’s publicKeyJwk (after splitting into the x / y halves) or publicKeyMultibase representation.

Source

pub fn verifying_key_jwk(&self) -> Value

Return the public key as a P-256 JWK object suitable for embedding in a did:web verification method’s publicKeyJwk field:

{ "kty": "EC", "crv": "P-256",
  "x": "<base64url-no-pad x>",
  "y": "<base64url-no-pad y>" }

FEAT-03: lets producers wire a published key into a DID document without manually splitting the SEC1 point and base64url-encoding each half.

Source

pub fn did_verification_method( &self, method_id: &str, controller: &str, ) -> Value

Compose a complete verificationMethod entry for a did:web DID document. method_id is the full DID URL (e.g. did:web:agents.example.com:alice#key-1); controller is the containing DID (without fragment).

Output uses the JsonWebKey2020 type so consumers can resolve the algorithm via acdp_did::document::VerificationMethod::declared_algorithm (RFC-ACDP-0008 §3.9 algorithm-downgrade rejection).

Trait Implementations§

Source§

impl Debug for P256SigningKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<P256SigningKey> for AcdpSigningKey

Source§

fn from(k: P256SigningKey) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.