Skip to content
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

fix: generate dids from indy seed secret bytes #1224

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions aries/aries_vcx_wallet/src/wallet/askar/askar_did_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ use super::{
use crate::{
errors::error::{VcxWalletError, VcxWalletResult},
wallet::{
base_wallet::{did_data::DidData, did_wallet::DidWallet, record_category::RecordCategory},
base_wallet::{
base58_string::Base58String, did_data::DidData, did_wallet::DidWallet,
record_category::RecordCategory,
},
structs_io::UnpackMessageOutput,
utils::bytes_to_string,
},
};

Expand All @@ -32,22 +36,23 @@ impl DidWallet for AskarWallet {
.len())
}

// Creates an Indy DID from a 'seed', which is the non-expanded ed25519 secret key.
async fn create_and_store_my_did(
&self,
seed: Option<&str>,
_did_method_name: Option<&str>,
) -> VcxWalletResult<DidData> {
let mut tx = self.transaction().await?;
let (did, local_key) = self
.insert_key(
&mut tx,
KeyAlg::Ed25519,
seed_from_opt(seed).as_bytes(),
RngMethod::RandomDet,
)
.await?;
let mut tx = self.session().await?;

let base58_seed = Base58String::from_bytes(&seed_from_opt(seed).as_bytes());
let secret_bytes = &base58_seed.decode()?[0..32];
let local_key = LocalKey::from_secret_bytes(KeyAlg::Ed25519, &secret_bytes)?;
let verkey = local_key_to_public_key(&local_key)?;

let base58_did = Base58String::from_bytes(&local_key.to_public_bytes()?[0..16]);
let did = bytes_to_string(base58_did.as_bytes())?;

self.insert_key(&mut tx, &did, &local_key).await?;
self.insert_did(
&mut tx,
&did,
Expand Down Expand Up @@ -78,14 +83,12 @@ impl DidWallet for AskarWallet {
async fn replace_did_key_start(&self, did: &str, seed: Option<&str>) -> VcxWalletResult<Key> {
let mut tx = self.transaction().await?;
if self.find_current_did(&mut tx, did).await?.is_some() {
let (_, local_key) = self
.insert_key(
&mut tx,
KeyAlg::Ed25519,
seed_from_opt(seed).as_bytes(),
RngMethod::RandomDet,
)
.await?;
let local_key = LocalKey::from_seed(
KeyAlg::Ed25519,
seed_from_opt(seed).as_bytes(),
RngMethod::RandomDet.into(),
)?;
self.insert_key(&mut tx, &did, &local_key).await?;

let verkey = local_key_to_public_key(&local_key)?;
self.insert_did(
Expand Down
18 changes: 6 additions & 12 deletions aries/aries_vcx_wallet/src/wallet/askar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use aries_askar::{
use async_trait::async_trait;
use public_key::Key;

use self::{
askar_utils::local_key_to_bs58_public_key, askar_wallet_config::AskarWalletConfig,
rng_method::RngMethod,
};
use self::askar_wallet_config::AskarWalletConfig;
use super::{
base_wallet::{
did_value::DidValue, key_value::KeyValue, record_category::RecordCategory, BaseWallet,
Expand Down Expand Up @@ -142,16 +139,13 @@ impl AskarWallet {
async fn insert_key(
&self,
session: &mut Session,
alg: KeyAlg,
seed: &[u8],
rng_method: RngMethod,
) -> VcxWalletResult<(String, LocalKey)> {
let key = LocalKey::from_seed(alg, seed, rng_method.into())?;
let key_name = local_key_to_bs58_public_key(&key)?.into_inner();
key_name: &str,
local_key: &LocalKey,
) -> VcxWalletResult<()> {
session
.insert_key(&key_name, &key, None, None, None)
.insert_key(&key_name, &local_key, None, None, None)
.await?;
Ok((key_name, key))
Ok(())
}

async fn find_did(
Expand Down
2 changes: 1 addition & 1 deletion aries/misc/test_utils/src/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub async fn dev_build_featured_wallet(key_seed: &str) -> (String, impl BaseWall
{
use crate::{constants::INSTITUTION_DID, mock_wallet::MockWallet};

return (INSTITUTION_DID.to_owned(), MockWallet);
(INSTITUTION_DID.to_owned(), MockWallet)
}
}

Expand Down
Loading