Skip to content

Commit

Permalink
Merge branch 'develop' into feat/camelCase-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Jul 18, 2023
2 parents 3079f05 + 4d3f2fe commit ad34947
Show file tree
Hide file tree
Showing 22 changed files with 204 additions and 68 deletions.
45 changes: 35 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bindings/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ backtrace = { version = "0.3.68", default-features = false, features = [ "std" ]
derivative = { version = "2.2.0", default-features = false }
fern-logger = { version = "0.5.0", default-features = false }
futures = { version = "0.3.28", default-features = false }
iota-crypto = { version = "0.22.2", default-features = false, features = [ "slip10" ] }
iota-crypto = { version = "0.23.0", default-features = false, features = [ "slip10", "bip44" ] }
log = { version = "0.4.19", default-features = false }
packable = { version = "0.8.1", default-features = false }
prefix-hex = { version = "0.7.0", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ derive_more = { version = "0.99.17", default-features = false, features = [ "fro
getset = { version = "0.1.2", default-features = false }
hashbrown = { version = "0.14.0", default-features = false, features = [ "ahash", "inline-more" ] }
hex = { version = "0.4.3", default-features = false }
iota-crypto = { version = "0.22.2", default-features = false, features = [ "blake2b", "ed25519", "secp256k1", "ternary_encoding" ] }
iota-crypto = { version = "0.23.0", default-features = false, features = [ "blake2b", "ed25519", "secp256k1", "ternary_encoding" ] }
iterator-sorted = { version = "0.1.0", default-features = false }
itertools = { version = "0.11.0", default-features = false, features = [ "use_alloc" ] }
packable = { version = "0.8.1", default-features = false, features = [ "primitive-types" ] }
Expand All @@ -43,7 +43,7 @@ futures = { version = "0.3.28", default-features = false, features = [ "thread-p
heck = { version = "0.4.1", default-features = false, optional = true }
instant = { version = "0.1.12", default-features = false, optional = true }
iota-ledger-nano = { version = "1.0.0-alpha.4", default-features = false, optional = true }
iota_stronghold = { version = "2.0.0-rc.1", default-features = false, optional = true }
iota_stronghold = { version = "2.0.0-rc.2", default-features = false, optional = true }
log = { version = "0.4.19", default-features = false, optional = true }
num_cpus = { version = "1.16.0", default-features = false, optional = true }
once_cell = { version = "1.18.0", default-features = false, optional = true }
Expand Down
3 changes: 1 addition & 2 deletions sdk/examples/how_tos/sign_and_verify_ed25519/sign_ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ async fn main() -> Result<()> {
.store_mnemonic(Mnemonic::from(std::env::var("MNEMONIC").unwrap()))
.await?;

let bip44_chain = Bip44::new()
.with_coin_type(SHIMMER_COIN_TYPE)
let bip44_chain = Bip44::new(SHIMMER_COIN_TYPE)
.with_account(ACCOUNT_INDEX)
.with_change(INTERNAL_ADDRESS as _)
.with_address_index(ADDRESS_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ impl<'a> ClientBlockBuilder<'a> {
output: output_with_meta.output,
output_metadata: output_with_meta.metadata,
chain: Some(
Bip44::new()
.with_coin_type(self.coin_type)
Bip44::new(self.coin_type)
.with_account(account_index)
.with_change(internal as _)
.with_address_index(address_index),
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/client/api/block_builder/input_selection/manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ impl<'a> ClientBlockBuilder<'a> {
output: output_with_meta.output,
output_metadata: output_with_meta.metadata,
chain: address_index_internal.map(|(address_index, internal)| {
Bip44::new()
.with_coin_type(self.coin_type)
Bip44::new(self.coin_type)
.with_account(self.account_index)
.with_change(internal as _)
.with_address_index(address_index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ impl<'a> ClientBlockBuilder<'a> {
output: output_with_meta.output().to_owned(),
output_metadata: output_with_meta.metadata().to_owned(),
chain: Some(
Bip44::new()
.with_coin_type(self.coin_type)
Bip44::new(self.coin_type)
.with_account(self.account_index)
.with_change(internal as _)
.with_address_index(address_index),
Expand Down Expand Up @@ -130,8 +129,7 @@ impl<'a> ClientBlockBuilder<'a> {
output: output_with_meta.output().to_owned(),
output_metadata: output_with_meta.metadata().to_owned(),
chain: address_index_internal.map(|(address_index, internal)| {
Bip44::new()
.with_coin_type(self.coin_type)
Bip44::new(self.coin_type)
.with_account(self.account_index)
.with_change(internal as _)
.with_address_index(address_index)
Expand Down Expand Up @@ -185,8 +183,7 @@ impl<'a> ClientBlockBuilder<'a> {
output: output_with_meta.output,
output_metadata: output_with_meta.metadata,
chain: address_index_internal.map(|(address_index, internal)| {
Bip44::new()
.with_coin_type(self.coin_type)
Bip44::new(self.coin_type)
.with_account(self.account_index)
.with_change(internal as _)
.with_address_index(address_index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ impl<'a> ClientBlockBuilder<'a> {
output: output_with_meta.output,
output_metadata: output_with_meta.metadata,
chain: address_index_internal.map(|(address_index, internal)| {
Bip44::new()
.with_coin_type(self.coin_type)
Bip44::new(self.coin_type)
.with_account(self.account_index)
.with_change(internal as _)
.with_address_index(address_index)
Expand Down
6 changes: 2 additions & 4 deletions sdk/src/client/secret/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ impl SecretManage for MnemonicSecretManager {

Ok(address_indexes
.map(|address_index| {
let chain = Bip44::new()
.with_coin_type(coin_type)
let chain = Bip44::new(coin_type)
.with_account(account_index)
.with_change(internal as _)
.with_address_index(address_index);
Expand Down Expand Up @@ -81,8 +80,7 @@ impl SecretManage for MnemonicSecretManager {

Ok(address_indexes
.map(|address_index| {
let chain = Bip44::new()
.with_coin_type(coin_type)
let chain = Bip44::new(coin_type)
.with_account(account_index)
.with_change(internal as _)
.with_address_index(address_index);
Expand Down
6 changes: 2 additions & 4 deletions sdk/src/client/stronghold/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ impl SecretManage for StrongholdAdapter {
let internal = options.into().map(|o| o.internal).unwrap_or_default();

for address_index in address_indexes {
let chain = Bip44::new()
.with_coin_type(coin_type)
let chain = Bip44::new(coin_type)
.with_account(account_index)
.with_change(internal as _)
.with_address_index(address_index);
Expand Down Expand Up @@ -139,8 +138,7 @@ impl SecretManage for StrongholdAdapter {
let internal = options.into().map(|o| o.internal).unwrap_or_default();

for address_index in address_indexes {
let chain = Bip44::new()
.with_coin_type(coin_type)
let chain = Bip44::new(coin_type)
.with_account(account_index)
.with_change(internal as _)
.with_address_index(address_index);
Expand Down
7 changes: 3 additions & 4 deletions sdk/src/utils/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,16 @@ pub mod bip44 {
use serde::{Deserialize, Serialize};

#[derive(Default, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase", remote = "Bip44")]
#[serde(default = "default_bip44", rename_all = "camelCase", remote = "Bip44")]
pub struct Bip44Def {
#[serde(default = "default_coin_type")]
coin_type: u32,
account: u32,
change: u32,
address_index: u32,
}

const fn default_coin_type() -> u32 {
crate::client::constants::IOTA_COIN_TYPE
fn default_bip44() -> Bip44 {
Bip44::new(crate::client::constants::IOTA_COIN_TYPE)
}

pub mod option_bip44 {
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/wallet/account/operations/syncing/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ where
.map_or(false, |tx| !tx.incoming);

// BIP 44 (HD wallets) and 4218 is the registered index for IOTA https://github.com/satoshilabs/slips/blob/master/slip-0044.md
let chain = Bip44::new()
.with_coin_type(account_details.coin_type)
let chain = Bip44::new(account_details.coin_type)
.with_account(account_details.index)
.with_change(associated_address.internal as _)
.with_address_index(associated_address.key_index);
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/wallet/account/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ impl OutputData {
.find(|a| a.address.inner == unlock_address)
{
Some(
Bip44::new()
.with_coin_type(account.coin_type)
Bip44::new(account.coin_type)
.with_account(account.index)
.with_change(address.internal as _)
.with_address_index(address.key_index),
Expand Down
56 changes: 55 additions & 1 deletion sdk/tests/client/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use iota_sdk::{
use serde::{Deserialize, Serialize};

#[tokio::test]
async fn addresses() {
async fn ed25519_addresses() {
let secret_manager = crate::client::node_api::setup_secret_manager();

let opts = GetAddressesOptions::default()
Expand All @@ -40,6 +40,24 @@ async fn addresses() {
);
}

#[tokio::test]
async fn evm_addresses() {
let secret_manager = crate::client::node_api::setup_secret_manager();

let opts = GetAddressesOptions::default()
.with_bech32_hrp(IOTA_TESTNET_BECH32_HRP)
.with_coin_type(IOTA_COIN_TYPE)
.with_range(0..1);
let public = secret_manager.generate_evm_addresses(opts.clone()).await.unwrap();
let internal = secret_manager.generate_evm_addresses(opts.internal()).await.unwrap();

// Address generated with bip32 path: [44, 4218, 0, 0, 0].
// This address was generated with a MnemonicSecretManager and verified with an outside source.
// Seed: 0x256a818b2aac458941f7274985a410e57fb750f3a3a67969ece5bd9ae7eef5b2.
assert_eq!(public[0], "0xb23e784f0464a30d536c961e414925eab6b3107d");
assert_eq!(internal[0], "0x98d8833ec4b82587d66207eb9c578fd0134c51b6");
}

#[tokio::test]
async fn public_key_to_address() {
let client = Client::builder().finish().await.unwrap();
Expand Down Expand Up @@ -236,6 +254,7 @@ async fn search_address() -> Result<()> {

let secret_manager = SecretManager::try_from_mnemonic(generate_mnemonic()?)?;

// Public
let addresses = secret_manager
.generate_ed25519_addresses(
GetAddressesOptions::from_client(&client)
Expand All @@ -259,5 +278,40 @@ async fn search_address() -> Result<()> {

assert_eq!(res, (9, false));

// Internal
let addresses = secret_manager
.generate_ed25519_addresses(
GetAddressesOptions::from_client(&client)
.await?
.internal()
.with_coin_type(IOTA_COIN_TYPE)
.with_account_index(0)
.with_range(9..10)
.with_bech32_hrp(IOTA_BECH32_HRP),
)
.await?;

let res = iota_sdk::client::api::search_address(
&secret_manager,
IOTA_BECH32_HRP,
IOTA_COIN_TYPE,
0,
0..10,
&addresses[0],
)
.await?;

assert_eq!(res, (9, true));

// not in range
let res =
iota_sdk::client::api::search_address(&secret_manager, IOTA_BECH32_HRP, IOTA_COIN_TYPE, 0, 0..9, &addresses[0])
.await;

match res {
Err(iota_sdk::client::Error::InputAddressNotFound { .. }) => {}
_ => panic!("should not have found search address range & public"),
}

Ok(())
}
2 changes: 1 addition & 1 deletion sdk/tests/client/input_signing_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use iota_sdk::{
fn input_signing_data_conversion() {
let protocol_parameters = protocol_parameters();

let bip44_chain = Bip44::new().with_coin_type(SHIMMER_COIN_TYPE);
let bip44_chain = Bip44::new(SHIMMER_COIN_TYPE);

let output = BasicOutput::build_with_amount(1_000_000)
.add_unlock_condition(AddressUnlockCondition::new(
Expand Down
5 changes: 3 additions & 2 deletions sdk/tests/client/node_api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async fn test_get_utxo_changes_by_id() {
let node_info = client.get_info().await.unwrap();

let r = client
.get_utxo_changes_by_id(&node_info.node_info.status.latest_milestone.milestone_id.unwrap())
.get_utxo_changes_by_id(&node_info.node_info.status.confirmed_milestone.milestone_id.unwrap())
.await
.unwrap();

Expand All @@ -266,9 +266,10 @@ async fn test_get_utxo_changes_by_index() {
let node_info = client.get_info().await.unwrap();

let r = client
.get_utxo_changes_by_index(node_info.node_info.status.latest_milestone.index)
.get_utxo_changes_by_index(node_info.node_info.status.confirmed_milestone.index)
.await
.unwrap();
assert_eq!(r.index, node_info.node_info.status.confirmed_milestone.index);

println!("{r:#?}");
}
Expand Down
Loading

0 comments on commit ad34947

Please sign in to comment.