spruceid / ssi

Core library for decentralized identity.
https://spruceid.dev
Apache License 2.0
193 stars 61 forks source link

Refactor the `key` DID method & Remove associated future types. #540

Closed timothee-haudebourg closed 8 months ago

timothee-haudebourg commented 8 months ago

This PR brings the did-key library up to date with the new ssi API. During this update I notices a few issues with the previous ssi implementation that have been fixed with the refactor:

Bonus: removing ugly associated future types

While refactoring, I initially added some associated types in the new traits meant to represent the future of async functions in traits. Something like that:

trait MessageSigner {
  type Sign: Future<Output = Signature>;

  // this function is async.
  fn sign(&self, message: &[u8]) -> Self::Sign;
}

This was required because until version 1.75, rust did not support "real" async functions in traits (there was some possible workaround with the async_trait crate, but not offering enough flexibility). Now that version 1.75 is stable, I've been able to remove all the associated future types (and their often ugly implementations). The example above is reduced to:

trait MessageSigner {
  async fn sign(&self, message: &[u8]) -> Signature;
}