Skip to main content

Wallet

Interfaces for managing the Mystiko wallet, including creating, checking, updating, and exporting operations.

Data Structure

Wallet data structure is as follows:

PropertyTypeDescription
idString
The wallet ID.
created_atu64
The creation time of the wallet.
updated_atu64
The last update time of the wallet.
encrypted_entropyString
The encrypted entropy of the wallet.
hashed_passwordString
The hashed password of the wallet.
account_nonceu32
The account nonce of the wallet.
mnemonic_typeMnemonicType
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:

ParameterRequiredDescription
passwordtrue
The password for the wallet.
mnemonictrue
MnemonicOptions for the wallet.

The parameter list for MnemonicOptions:

ParameterRequiredDescription
mnemonic_phrasetrue
Mnemonic phrase for the wallet.
mnemonic_typetrue
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"));
}
};