Skip to content

Commit

Permalink
feat(2.0, nodejs): Add changeStrongholdPassword for SecretManager (#1829
Browse files Browse the repository at this point in the history
)
  • Loading branch information
marc2332 authored Jan 11, 2024
1 parent 381c972 commit 7fde028
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bindings/core/src/method/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ pub enum SecretManagerMethod {
#[derivative(Debug(format_with = "OmittedDebug::omitted_fmt"))]
password: String,
},
/// Change the stronghold password.
/// Expected response: [`Ok`](crate::Response::Ok)
#[cfg(feature = "stronghold")]
#[cfg_attr(docsrs, doc(cfg(feature = "stronghold")))]
ChangeStrongholdPassword {
#[derivative(Debug(format_with = "OmittedDebug::omitted_fmt"))]
password: String,
},
}

#[cfg(test)]
Expand Down
12 changes: 12 additions & 0 deletions bindings/core/src/method_handler/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ where
stronghold.set_password(password).await?;
Response::Ok
}
#[cfg(feature = "stronghold")]
SecretManagerMethod::ChangeStrongholdPassword { password } => {
let stronghold = if let Some(secret_manager) = secret_manager.downcast::<StrongholdSecretManager>() {
secret_manager
} else if let Some(SecretManager::Stronghold(secret_manager)) = secret_manager.downcast::<SecretManager>() {
secret_manager
} else {
return Err(iota_sdk::client::Error::SecretManagerMismatch.into());
};
stronghold.change_password(password).await?;
Response::Ok
}
};
Ok(response)
}
10 changes: 10 additions & 0 deletions bindings/nodejs/lib/secret_manager/secret-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,14 @@ export class SecretManager {
data: { password },
});
}

/**
* Change the Stronghold password.
*/
async changeStrongholdPassword(password: string): Promise<void> {
await this.methodHandler.callMethod({
name: 'changeStrongholdPassword',
data: { password },
});
}
}
4 changes: 3 additions & 1 deletion bindings/nodejs/lib/types/secret_manager/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
__SignEd25519Method__,
__SignSecp256k1EcdsaMethod__,
__SetStrongholdPasswordMethod__,
__ChangeStrongholdPasswordMethod__,
} from './secret-manager';

export type __SecretManagerMethods__ =
Expand All @@ -21,4 +22,5 @@ export type __SecretManagerMethods__ =
| __StoreMnemonicMethod__
| __SignEd25519Method__
| __SignSecp256k1EcdsaMethod__
| __SetStrongholdPasswordMethod__;
| __SetStrongholdPasswordMethod__
| __ChangeStrongholdPasswordMethod__;
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ export interface __SetStrongholdPasswordMethod__ {
name: 'setStrongholdPassword';
data: { password: string };
}

export interface __ChangeStrongholdPasswordMethod__ {
name: 'changeStrongholdPassword';
data: { password: string };
}

0 comments on commit 7fde028

Please sign in to comment.