pub struct KeySigner<'a> { /* private fields */ }Expand description
A Signer over one key of a KeyStore.
The signer looks the key up once, when it is created, and keeps the public Jwk so that a
caller building a DID document or a JWS header never round-trips to the store for it
(KeySigner::public_jwk). Signing goes to the store on every call.
Signer::kid is the key id, unless KeySigner::with_kid set another value, such as the
DID URL of the verification method the key backs.
§Examples
use identity_kit::jose::{CompactJws, DefaultVerifier, JwsAlgorithm, JwsHeader, KeyType, encode_compact};
use identity_kit::keys::{InMemoryKeyStore, KeySigner, KeySpec, KeyStore};
let store = InMemoryKeyStore::new();
let key = store.generate(KeySpec::new(KeyType::Ed25519, JwsAlgorithm::EdDSA)).await?;
let signer = KeySigner::new(&store, key, JwsAlgorithm::EdDSA).await?;
let header = JwsHeader::new(JwsAlgorithm::EdDSA).with_kid(signer.key_id().as_str());
let token = encode_compact(&header, b"{}", &signer).await?;
let jws = CompactJws::decode(&token)?;
jws.verify(&DefaultVerifier, signer.public_jwk())?;Implementations§
Source§impl<'a> KeySigner<'a>
impl<'a> KeySigner<'a>
Sourcepub async fn new(
store: &'a dyn KeyStore,
key: KeyId,
alg: JwsAlgorithm,
) -> Result<Self, KeyStoreError>
pub async fn new( store: &'a dyn KeyStore, key: KeyId, alg: JwsAlgorithm, ) -> Result<Self, KeyStoreError>
A signer over key of store, signing with alg.
§Errors
KeyStoreError::UnsupportedAlgorithm when the store does not advertise alg,
KeyStoreError::NotFound when the key does not exist,
KeyStoreError::AlgorithmMismatch when the key’s public JWK names another algorithm,
and whatever else the store reports.
Sourcepub fn with_kid(self, kid: impl Into<String>) -> Self
pub fn with_kid(self, kid: impl Into<String>) -> Self
This signer with Signer::kid set to kid instead of the key id.
Sourcepub fn public_jwk(&self) -> &Jwk
pub fn public_jwk(&self) -> &Jwk
The public key, as the store reported it when the signer was created.