Skip to content

Commit

Permalink
feat(2.0 nodejs): Add setStrongholdPassword for SecretManager (#1807
Browse files Browse the repository at this point in the history
)

* feat(nodejs): Silently stop background syncing when Wallet is dropped

* feat(2.0): Optimized background sync

* fix

* switch to tokio notify

* chore: Remove comment

* final touches

* feat(2.0, nodejs): Add setStrongholdPassword for SecretManager

* revert example

* fmt

* Update bindings/core/src/method_handler/secret_manager.rs

Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com>

* Update secret-manager.ts

* Update bindings/nodejs/lib/types/secret_manager/bridge/secret-manager.ts

Co-authored-by: Thibault Martinez <thibault.martinez.30@gmail.com>

* fmt

---------

Co-authored-by: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com>
Co-authored-by: Thibault Martinez <thibault.martinez.30@gmail.com>
  • Loading branch information
3 people authored Jan 10, 2024
1 parent 4374ef0 commit 381c972
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 @@ -79,6 +79,14 @@ pub enum SecretManagerMethod {
#[derivative(Debug(format_with = "OmittedDebug::omitted_fmt"))]
mnemonic: String,
},
/// Set the stronghold password.
/// Expected response: [`Ok`](crate::Response::Ok)
#[cfg(feature = "stronghold")]
#[cfg_attr(docsrs, doc(cfg(feature = "stronghold")))]
SetStrongholdPassword {
#[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 @@ -135,6 +135,18 @@ where
return Err(iota_sdk::client::Error::SecretManagerMismatch.into());
}
}
#[cfg(feature = "stronghold")]
SecretManagerMethod::SetStrongholdPassword { 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.set_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 @@ -216,4 +216,14 @@ export class SecretManager {

return JSON.parse(response).payload;
}

/**
* Set the Stronghold password.
*/
async setStrongholdPassword(password: string): Promise<void> {
await this.methodHandler.callMethod({
name: 'setStrongholdPassword',
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 @@ -8,6 +8,7 @@ import type {
__SignatureUnlockMethod__,
__SignEd25519Method__,
__SignSecp256k1EcdsaMethod__,
__SetStrongholdPasswordMethod__,
} from './secret-manager';

export type __SecretManagerMethods__ =
Expand All @@ -19,4 +20,5 @@ export type __SecretManagerMethods__ =
| __SignatureUnlockMethod__
| __StoreMnemonicMethod__
| __SignEd25519Method__
| __SignSecp256k1EcdsaMethod__;
| __SignSecp256k1EcdsaMethod__
| __SetStrongholdPasswordMethod__;
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ export interface __SignSecp256k1EcdsaMethod__ {
export interface __GetLedgerNanoStatusMethod__ {
name: 'getLedgerNanoStatus';
}

export interface __SetStrongholdPasswordMethod__ {
name: 'setStrongholdPassword';
data: { password: string };
}

0 comments on commit 381c972

Please sign in to comment.