Wallet
Interfaces for managing the Mystiko wallet, including creating, checking, updating, and exporting operations.
Data Structure
Wallet
data structure is as follows:
Property | Type | Description |
---|---|---|
id | String | The wallet ID. |
created_at | u64 | The creation time of the wallet. |
updated_at | u64 | The last update time of the wallet. |
encrypted_entropy | String | The encrypted entropy of the wallet. |
hashed_password | String | The hashed password of the wallet. |
account_nonce | u32 | The account nonce of the wallet. |
mnemonic_type | MnemonicType | The account mnemonic type. |
List of supported MnemonicType
:
# Represents a mnemonic phrase used in web wallets, typically consisting of 12 words.
MnemonicType.WEB;
# Represents a mnemonic phrase used in Rust-based wallets, typically consisting of 24 words.
MnemonicType.RUST;
create
Create a Mystiko Wallet.
use mystiko_protos::api::handler::v1::{CreateWalletRequest, CreateWalletResponse};
use mystiko_protos::core::handler::v1::CreateWalletOptions;
use mystiko_lib::wallet::create;
use mystiko_protos::api::v1::api_response;
let options = CreateWalletOptions::builder().password("P@ssw0rd".to_string()).build();
let request = CreateWalletRequest::builder().options(options).build();
let response = create(request);
let wallet = match response.result {
Some(api_response::Result::Data(data)) => match CreateWalletResponse::try_from(data) {
Ok(wallet) => wallet,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
The parameter list for CreateWalletOptions
:
Parameter | Required | Description |
---|---|---|
password | true | The password for the wallet. |
mnemonic | true | MnemonicOptions for the wallet. |
The parameter list for MnemonicOptions
:
Parameter | Required | Description |
---|---|---|
mnemonic_phrase | true | Mnemonic phrase for the wallet. |
mnemonic_type | true | MnemonicType for the wallet. |
check
check_current
Check current wallet.
use mystiko_protos::core::handler::v1::CheckCurrentResponse;
use mystiko_lib::wallet::check_current;
use mystiko_protos::api::v1::api_response;
let response = check_current();
let wallet = match response.result {
Some(api_response::Result::Data(data)) => match CheckCurrentResponse::try_from(data) {
Ok(wallet) => wallet,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
check_password
Check the password of the wallet.
use mystiko_protos::core::handler::v1::{CheckPasswordRequest, CheckPasswordResponse};
use mystiko_lib::wallet::check_password;
use mystiko_protos::api::v1::api_response;
let request = CheckPasswordRequest::builder().password("P@ssw0rd".to_string()).build();
let response = check_password(request);
let wallet = match response.result {
Some(api_response::Result::Data(data)) => match CheckPasswordResponse::try_from(data) {
Ok(wallet) => wallet,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
update_password
Update the password of the wallet.
use mystiko_protos::core::handler::v1::{UpdatePasswordRequest, UpdatePasswordResponse};
use mystiko_lib::wallet::update_password;
use mystiko_protos::api::v1::api_response;
let request = UpdatePasswordRequest::builder()
.old_password("P@ssw0rd".to_string())
.new_password("N3wP@ssw0rd".to_string())
.build();
let response = update_password(request);
let wallet = match response.result {
Some(api_response::Result::Data(data)) => match UpdatePasswordResponse::try_from(data) {
Ok(wallet) => wallet,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
export_mnemonic_phrase
Export the mnemonic phrase of the wallet.
use mystiko_protos::core::handler::v1::{ExportMnemonicPhraseRequest, ExportMnemonicPhraseResponse};
use mystiko_lib::wallet::export_mnemonic_phrase;
use mystiko_protos::api::v1::api_response;
let request = ExportMnemonicPhraseRequest::builder().password("P@ssw0rd".to_string()).build();
let response = export_mnemonic_phrase(request);
let phrase = match response.result {
Some(api_response::Result::Data(data)) => match ExportMnemonicPhraseResponse::try_from(data) {
Ok(phrase) => phrase,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};