-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stronghold Storage Implementation #1157
Conversation
JwkStorage
0d3feef
to
a5258e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
We have to expose a constant key type for users to use and please annotate types in the storage implementations.
Co-authored-by: Philipp Gackstatter <philipp.gackstatter@iota.org>
# Conflicts: # bindings/wasm/docs/api-reference.md # bindings/wasm/src/credential/jwt_credential_validation/jwt_credential_validator.rs # bindings/wasm/src/credential/jwt_credential_validation/mod.rs # bindings/wasm/src/credential/jwt_credential_validation/options.rs # bindings/wasm/src/credential/mod.rs # bindings/wasm/src/did/jws_verification_options.rs # bindings/wasm/src/did/wasm_core_document.rs # bindings/wasm/src/error.rs # bindings/wasm/src/iota/iota_document.rs # bindings/wasm/src/jose/jws_header.rs # bindings/wasm/src/jose/mod.rs # bindings/wasm/src/storage/jwk_storage.rs # bindings/wasm/src/storage/signature_options.rs # bindings/wasm/src/verification/custom_verification.rs # bindings/wasm/tests/jwk_storage.ts # bindings/wasm/tests/storage.ts # identity_core/src/error.rs # identity_credential/src/credential/credential.rs # identity_credential/src/credential/jwt_serialization.rs # identity_credential/src/credential/mod.rs # identity_credential/src/validator/vc_jwt_validation/credential_jwt_validator.rs # identity_credential/src/validator/vc_jwt_validation/mod.rs # identity_document/src/document/core_document.rs # identity_document/src/error.rs # identity_document/src/verifiable/jws_verification_options.rs # identity_iota/Cargo.toml # identity_iota_core/src/document/iota_document.rs # identity_iota_core/src/error.rs # identity_jose/examples/jws_encoding_decoding.rs # identity_jose/src/jws/custom_verification/jws_verifier.rs # identity_jose/src/jws/decoder.rs # identity_jose/src/jws/encoding/mod.rs # identity_jose/src/jws/encoding/utils.rs # identity_jose/src/tests/rfc7515.rs # identity_jose/src/tests/rfc8037.rs # identity_jose/src/tests/roundtrip.rs # identity_storage/Cargo.toml # identity_storage/src/key_id_storage/method_digest.rs # identity_storage/src/key_storage/memstore.rs # identity_storage/src/lib.rs # identity_storage/src/storage/error.rs # identity_storage/src/storage/mod.rs # identity_storage/src/storage/signature_options.rs # identity_storage/src/storage/tests/api.rs # identity_storage/src/storage/tests/credential_validation.rs # identity_storage/src/storage/tests/mod.rs # identity_verification/Cargo.toml # identity_verification/src/verification_method/method.rs # libjose/src/jwk/key_params.rs # libjose/tests/jwe.rs # libjose/tests/jws.rs
examples/0_basic/8_stronghold.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Stronghold should be its own example. We already use stronghold for the client in every example and we should encourage using it in identity too by showing stronghold for identity usage in every example. That's how we always did it in the past and I think that was good.
identity_storage/Cargo.toml
Outdated
@@ -21,12 +21,15 @@ identity_document = { version = "=0.7.0-alpha.6", path = "../identity_document", | |||
identity_iota_core = { version = "=0.7.0-alpha.6", path = "../identity_iota_core", default-features = false, optional = true } | |||
identity_verification = { version = "=0.7.0-alpha.6", path = "../identity_verification", default_features = false } | |||
iota-crypto = { version = "0.23", default-features = false, features = ["blake2b", "ed25519", "random"], optional = true } | |||
iota-sdk = { version = "1.0", default-features = false, features = ["tls", "client", "stronghold"], optional = true } | |||
iota_stronghold = { version = "2.0", optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please follow our codebase convention and use default-features = false
and activate what we need.
pub(crate) static IDENTITY_CLIENT_PATH: &[u8] = b"iota_identity_client"; | ||
|
||
/// The Ed25519 key type. | ||
#[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is correctly exported, the lint should not be necessary, right? Why is this here again?
let keytype: ProceduresKeyType = match key_type.to_string().to_lowercase().as_str() { | ||
"ed25519" => Ok(ProceduresKeyType::Ed25519), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the StrongholdKeyType
enum to make this case easy to handle. Not sure why we need to lowercase convert anything here and cause another allocation.
let keytype: ProceduresKeyType = match key_type.to_string().to_lowercase().as_str() { | |
"ed25519" => Ok(ProceduresKeyType::Ed25519), | |
let keytype: ProceduresKeyType = match key_type { | |
StrongholdKeyType::Ed25519 => Ok(ProceduresKeyType::Ed25519), |
.write_secret(location, zeroize::Zeroizing::from(secret_key.to_bytes().to_vec())) | ||
.map_err(|err| { | ||
KeyStorageError::new(KeyStorageErrorKind::Unspecified) | ||
.with_custom_message("stronghold client error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.with_custom_message("stronghold client error") | |
.with_custom_message("stronghold write secret failed") |
} | ||
|
||
/// Shared reference to the inner [`SecretManager`]. | ||
pub fn inner(&self) -> Arc<SecretManager> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn inner(&self) -> Arc<SecretManager> { | |
pub fn as_secret_manager(&self) -> Arc<SecretManager> { |
Follow rust convention with as_
and be more specific about what this fn does.
Actually, does this need to return Arc<SecretManager>
? Wouldn't &SecretManager
be sufficient?
} | ||
|
||
///Acquire lock of the inner [`Stronghold`]. | ||
pub async fn get_stronghold(&self) -> MutexGuard<'_, Stronghold> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub async fn get_stronghold(&self) -> MutexGuard<'_, Stronghold> { | |
pub(crate) async fn get_stronghold(&self) -> MutexGuard<'_, Stronghold> { |
This can be pub(crate)
if I'm not mistaken.
self.0.clone() | ||
} | ||
|
||
///Acquire lock of the inner [`Stronghold`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
///Acquire lock of the inner [`Stronghold`]. | |
/// Acquire lock of the inner [`Stronghold`]. |
use tokio::sync::MutexGuard; | ||
|
||
/// Wrapper around `SecretManager` that implements the storage interfaces. | ||
#[derive(Clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we derive Debug
as well?
use std::sync::Arc; | ||
use tokio::sync::MutexGuard; | ||
|
||
/// Wrapper around `SecretManager` that implements the storage interfaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Wrapper around `SecretManager` that implements the storage interfaces. | |
/// Wrapper around a `StrongholdSecretManager` that implements the [`KeyIdStorage`](todo:link) and [`JwkStorage`](todo:link) interfaces. |
Yes, technically it wraps a SecretManager
, but conceptually it's a StrongholdSecretManager
and that is what matters to the user.
Maybe we can change the examples in a separate PR. |
Description of change
Stronghold storage implementation.
Still to do:
KeyIdStorage
Links to any relevant issues
Be sure to reference any related issues by adding
fixes issue #
.Type of change