From 7fde02848e63a3d589bdae78bc7875363be78881 Mon Sep 17 00:00:00 2001 From: Marc Espin Date: Thu, 11 Jan 2024 13:44:24 +0100 Subject: [PATCH] feat(2.0, nodejs): Add changeStrongholdPassword for SecretManager (#1829) --- bindings/core/src/method/secret_manager.rs | 8 ++++++++ bindings/core/src/method_handler/secret_manager.rs | 12 ++++++++++++ bindings/nodejs/lib/secret_manager/secret-manager.ts | 10 ++++++++++ .../nodejs/lib/types/secret_manager/bridge/index.ts | 4 +++- .../types/secret_manager/bridge/secret-manager.ts | 5 +++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/bindings/core/src/method/secret_manager.rs b/bindings/core/src/method/secret_manager.rs index 3df9f6f0a1..263e600594 100644 --- a/bindings/core/src/method/secret_manager.rs +++ b/bindings/core/src/method/secret_manager.rs @@ -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)] diff --git a/bindings/core/src/method_handler/secret_manager.rs b/bindings/core/src/method_handler/secret_manager.rs index 09d1f690fb..98d826f8aa 100644 --- a/bindings/core/src/method_handler/secret_manager.rs +++ b/bindings/core/src/method_handler/secret_manager.rs @@ -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::() { + secret_manager + } else if let Some(SecretManager::Stronghold(secret_manager)) = secret_manager.downcast::() { + secret_manager + } else { + return Err(iota_sdk::client::Error::SecretManagerMismatch.into()); + }; + stronghold.change_password(password).await?; + Response::Ok + } }; Ok(response) } diff --git a/bindings/nodejs/lib/secret_manager/secret-manager.ts b/bindings/nodejs/lib/secret_manager/secret-manager.ts index ca6bcc3258..6b804e76ef 100644 --- a/bindings/nodejs/lib/secret_manager/secret-manager.ts +++ b/bindings/nodejs/lib/secret_manager/secret-manager.ts @@ -226,4 +226,14 @@ export class SecretManager { data: { password }, }); } + + /** + * Change the Stronghold password. + */ + async changeStrongholdPassword(password: string): Promise { + await this.methodHandler.callMethod({ + name: 'changeStrongholdPassword', + data: { password }, + }); + } } diff --git a/bindings/nodejs/lib/types/secret_manager/bridge/index.ts b/bindings/nodejs/lib/types/secret_manager/bridge/index.ts index 0584199625..8f8670938d 100644 --- a/bindings/nodejs/lib/types/secret_manager/bridge/index.ts +++ b/bindings/nodejs/lib/types/secret_manager/bridge/index.ts @@ -9,6 +9,7 @@ import type { __SignEd25519Method__, __SignSecp256k1EcdsaMethod__, __SetStrongholdPasswordMethod__, + __ChangeStrongholdPasswordMethod__, } from './secret-manager'; export type __SecretManagerMethods__ = @@ -21,4 +22,5 @@ export type __SecretManagerMethods__ = | __StoreMnemonicMethod__ | __SignEd25519Method__ | __SignSecp256k1EcdsaMethod__ - | __SetStrongholdPasswordMethod__; + | __SetStrongholdPasswordMethod__ + | __ChangeStrongholdPasswordMethod__; diff --git a/bindings/nodejs/lib/types/secret_manager/bridge/secret-manager.ts b/bindings/nodejs/lib/types/secret_manager/bridge/secret-manager.ts index 6daf86dffb..bcc427bd86 100644 --- a/bindings/nodejs/lib/types/secret_manager/bridge/secret-manager.ts +++ b/bindings/nodejs/lib/types/secret_manager/bridge/secret-manager.ts @@ -75,3 +75,8 @@ export interface __SetStrongholdPasswordMethod__ { name: 'setStrongholdPassword'; data: { password: string }; } + +export interface __ChangeStrongholdPasswordMethod__ { + name: 'changeStrongholdPassword'; + data: { password: string }; +}