Skip to content

Commit

Permalink
Merge branch 'develop' into feat/ed25519-signature
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Jul 14, 2023
2 parents 8657b27 + 8cc7982 commit f08cee2
Show file tree
Hide file tree
Showing 127 changed files with 157 additions and 637 deletions.
2 changes: 1 addition & 1 deletion .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"packages": {
"wallet-nodejs-binding": {
"path": "./sdk/src/wallet/bindings/nodejs",
"path": "./bindings/nodejs-old",
"manager": "javascript",
"getPublishedVersion": "npm view ${ pkgFile.pkg.name } version",
"prepublish": [
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/bindings-wallet-covector-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
$NodeVersion = (node --version) -replace '^.'
$NodeFallbackVersion = "16.19.0"
& .\scripts\download-node-lib-win-arm64.ps1 $NodeVersion $NodeFallbackVersion
working-directory: sdk/src/wallet/bindings/nodejs
working-directory: bindings/nodejs-old

- name: Install LLVM and Clang (Windows) # required for bindgen to work, see https://github.com/rust-lang/rust-bindgen/issues/1797
uses: KyleMayes/install-llvm-action@32c4866ebb71e0949e8833eb49beeebed48532bd
Expand Down Expand Up @@ -167,17 +167,17 @@ jobs:
- name: Install dependencies
run: npm install typescript && npm ci
working-directory: sdk/src/wallet/bindings/nodejs
working-directory: bindings/nodejs-old

- name: Build Node.js prebuild (x64)
run: npm run prebuild-x64
working-directory: sdk/src/wallet/bindings/nodejs
working-directory: bindings/nodejs-old

# Temporarily disabled because it does not work like this https://github.com/iotaledger/iota-sdk/issues/97
# - name: Build Node.js prebuild (arm64)
# run: npm run prebuild-arm64
# working-directory: sdk/src/wallet/bindings/nodejs
# working-directory: bindings/nodejs-old

- name: Upload prebuild to GitHub release
run: npx prebuild --upload-all ${{ secrets.GITHUB_TOKEN }} --tag-prefix wallet-nodejs-binding-v
working-directory: sdk/src/wallet/bindings/nodejs
working-directory: bindings/nodejs-old
12 changes: 6 additions & 6 deletions .github/workflows/bindings-wallet-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- "!**/tests/**" # Exclude all tests
- "!cli/**" # Exclude CLI
- "!**/bindings/**" # Exclude all bindings
- "sdk/src/wallet/bindings/nodejs/**"
- "bindings/nodejs-old/**"
- ".github/workflows/bindings-wallet-nodejs.yml"
- ".patches/*"
pull_request:
Expand All @@ -26,7 +26,7 @@ on:
- "!**/tests/**" # Exclude all tests
- "!cli/**" # Exclude CLI
- "!**/bindings/**" # Exclude all bindings
- "sdk/src/wallet/bindings/nodejs/**"
- "bindings/nodejs-old/**"
- ".github/workflows/bindings-wallet-nodejs.yml"
- ".patches/*"
schedule:
Expand Down Expand Up @@ -67,14 +67,14 @@ jobs:
- name: Set up Rust
uses: ./.github/actions/setup-rust
with:
cache-root: sdk/src/wallet/bindings/nodejs
cache-root: bindings/nodejs-old

- name: Set Up Node.js ${{ matrix.node }} and Yarn Cache
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: npm
cache-dependency-path: sdk/src/wallet/bindings/nodejs/package-lock.json
cache-dependency-path: bindings/nodejs-old/package-lock.json

# This step is required for bindgen to work on Windows.
- name: Set Up Clang/LLVM (Windows)
Expand All @@ -99,8 +99,8 @@ jobs:
- name: Build nodejs binding
run: npm ci --build-from-source
working-directory: sdk/src/wallet/bindings/nodejs
working-directory: bindings/nodejs-old

- name: Run npm test
run: npm test
working-directory: sdk/src/wallet/bindings/nodejs
working-directory: bindings/nodejs-old
3 changes: 1 addition & 2 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ resolver = "2"
members = [
"bindings/core",
"bindings/nodejs",
"bindings/nodejs-old",
"bindings/python",
"bindings/wasm",
"cli",
"sdk",
"sdk/src/wallet/bindings/nodejs"
]

[profile.dev]
Expand Down
4 changes: 2 additions & 2 deletions bindings/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ license = "Apache-2.0"
publish = false

[dependencies]
iota-sdk = { path = "../../sdk", default-features = false, features = [ "wallet", "tls", "message_interface" ] }
iota-sdk = { path = "../../sdk", default-features = false, features = [ "wallet", "tls" ] }

backtrace = { version = "0.3.67", default-features = false }
backtrace = { version = "0.3.67", 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 }
Expand Down
1 change: 1 addition & 0 deletions bindings/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! Core library for iota-sdk bindings

mod error;
pub mod message_interface_old;
mod method;
mod method_handler;
mod panic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

use crypto::keys::bip44::Bip44;
use serde::{Deserialize, Serialize};

#[cfg(feature = "participation")]
use crate::wallet::account::types::participation::ParticipationEventRegistrationOptions;
use iota_sdk::wallet::account::types::participation::ParticipationEventRegistrationOptions;
#[cfg(feature = "participation")]
use crate::{
use iota_sdk::{
client::node_manager::node::Node,
types::api::plugins::participation::types::{ParticipationEventId, ParticipationEventType},
};
use crate::{
use iota_sdk::{
client::{
api::{GetAddressesOptions, PreparedTransactionDataDto, SignedTransactionDataDto},
secret::GenerateAddressOptions,
Expand All @@ -30,24 +28,14 @@ use crate::{
utils::serde::bip44::Bip44Def,
wallet::{
account::{
operations::{
output_claiming::OutputsToClaim,
syncing::SyncOptions,
transaction::{
high_level::{
create_alias::CreateAliasParams,
minting::{create_native_token::CreateNativeTokenParams, mint_nfts::MintNftParams},
},
prepare_output::OutputParams,
TransactionOptionsDto,
},
},
FilterOptions,
CreateAliasParams, CreateNativeTokenParams, FilterOptions, MintNftParams, OutputParams, OutputsToClaim,
SyncOptions, TransactionOptionsDto,
},
SendNativeTokensParams, SendNftParams, SendParams,
},
U256,
};
use serde::{Deserialize, Serialize};

/// Each public account method.
#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ use std::fmt::{Debug, Formatter, Result};
#[cfg(feature = "stronghold")]
use std::path::PathBuf;

use serde::{Deserialize, Serialize};

use super::account_method::AccountMethod;
#[cfg(feature = "events")]
use crate::wallet::events::types::{WalletEvent, WalletEventType};
use crate::{
use iota_sdk::wallet::events::types::{WalletEvent, WalletEventType};
use iota_sdk::{
client::{node_manager::node::NodeAuth, secret::GenerateAddressOptions},
types::block::address::{Bech32Address, Hrp},
wallet::{
account::{operations::syncing::SyncOptions, types::AccountIdentifier},
account::{types::AccountIdentifier, SyncOptions},
ClientOptions,
},
Url,
};
use serde::{Deserialize, Serialize};

use super::account_method::AccountMethod;

/// The messages that can be sent to the actor.
#[derive(Clone, Serialize, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ use std::{
use backtrace::Backtrace;
use crypto::keys::bip39::Mnemonic;
use futures::{Future, FutureExt};

#[cfg(feature = "events")]
use crate::wallet::events::types::{Event, WalletEventType};
use crate::{
use iota_sdk::wallet::events::types::{Event, WalletEventType};
use iota_sdk::{
client::{
api::{PreparedTransactionData, PreparedTransactionDataDto, SignedTransactionData, SignedTransactionDataDto},
constants::SHIMMER_TESTNET_BECH32_HRP,
Expand All @@ -34,19 +33,15 @@ use crate::{
},
wallet::{
account::{
operations::transaction::{
high_level::minting::create_native_token::CreateNativeTokenTransactionDto, TransactionOptions,
},
types::{AccountIdentifier, TransactionDto},
OutputDataDto,
},
message_interface::{
account_method::AccountMethod, dtos::AccountDetailsDto, message::Message, response::Response,
AccountDetailsDto, CreateNativeTokenTransactionDto, OutputDataDto, TransactionOptions,
},
Result, Wallet,
},
};

use crate::message_interface_old::{account_method::AccountMethod, message::Message, response::Response};

fn panic_to_response_message(panic: Box<dyn Any>) -> Response {
let msg = panic.downcast_ref::<String>().map_or_else(
|| {
Expand Down Expand Up @@ -571,8 +566,7 @@ impl WalletMessageHandler {
}
AccountMethod::GenerateEvmAddresses { options } => {
let addresses = account
.wallet
.secret_manager
.get_secret_manager()
.read()
.await
.generate_evm_addresses(options)
Expand All @@ -581,7 +575,7 @@ impl WalletMessageHandler {
}
AccountMethod::VerifyEd25519Signature { signature, message } => {
let signature = Ed25519Signature::try_from(signature)?;
let message: Vec<u8> = prefix_hex::decode(message).map_err(crate::client::Error::from)?;
let message: Vec<u8> = prefix_hex::decode(message).map_err(iota_sdk::client::Error::from)?;
Ok(Response::Bool(signature.verify(&message)))
}
AccountMethod::VerifySecp256k1EcdsaSignature {
Expand All @@ -594,14 +588,13 @@ impl WalletMessageHandler {
let public_key = secp256k1_ecdsa::PublicKey::try_from_bytes(&public_key)?;
let signature = prefix_hex::decode(signature).map_err(|_| Error::InvalidField("signature"))?;
let signature = secp256k1_ecdsa::Signature::try_from_bytes(&signature)?;
let message: Vec<u8> = prefix_hex::decode(message).map_err(crate::client::Error::from)?;
let message: Vec<u8> = prefix_hex::decode(message).map_err(iota_sdk::client::Error::from)?;
Ok(Response::Bool(public_key.verify_keccak256(&signature, &message)))
}
AccountMethod::SignSecp256k1Ecdsa { message, chain } => {
let msg: Vec<u8> = prefix_hex::decode(message).map_err(crate::client::Error::from)?;
let msg: Vec<u8> = prefix_hex::decode(message).map_err(iota_sdk::client::Error::from)?;
let (public_key, signature) = account
.wallet
.secret_manager
.get_secret_manager()
.read()
.await
.sign_secp256k1_ecdsa(&msg, chain)
Expand Down Expand Up @@ -850,7 +843,7 @@ impl WalletMessageHandler {
outputs
.into_iter()
.map(|o| Ok(Output::try_from_dto(o, token_supply)?))
.collect::<crate::wallet::Result<Vec<_>>>()?,
.collect::<iota_sdk::wallet::Result<Vec<_>>>()?,
options.map(TransactionOptions::try_from_dto).transpose()?,
)
.await?;
Expand Down Expand Up @@ -925,7 +918,8 @@ impl WalletMessageHandler {
convert_async_panics(|| async {
let transaction = account
.increase_voting_power(
u64::from_str(&amount).map_err(|_| crate::client::Error::InvalidAmount(amount.clone()))?,
u64::from_str(&amount)
.map_err(|_| iota_sdk::client::Error::InvalidAmount(amount.clone()))?,
)
.await?;
Ok(Response::SentTransaction(TransactionDto::from(&transaction)))
Expand All @@ -937,7 +931,8 @@ impl WalletMessageHandler {
convert_async_panics(|| async {
let transaction = account
.decrease_voting_power(
u64::from_str(&amount).map_err(|_| crate::client::Error::InvalidAmount(amount.clone()))?,
u64::from_str(&amount)
.map_err(|_| iota_sdk::client::Error::InvalidAmount(amount.clone()))?,
)
.await?;
Ok(Response::SentTransaction(TransactionDto::from(&transaction)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
// SPDX-License-Identifier: Apache-2.0

mod account_method;
pub mod dtos;
mod message;
mod message_handler;
mod response;

use fern_logger::{logger_init, LoggerConfig, LoggerOutputConfigBuilder};
use iota_sdk::{
client::secret::{SecretManager, SecretManagerDto},
wallet::{ClientOptions, Wallet},
};
use serde::{Deserialize, Serialize, Serializer};

pub use self::{
account_method::AccountMethod, message::Message, message_handler::WalletMessageHandler, response::Response,
};
use crate::{
client::secret::{SecretManager, SecretManagerDto},
wallet::{ClientOptions, Wallet},
};

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -59,7 +58,7 @@ pub fn init_logger(config: String) -> Result<(), fern_logger::Error> {
logger_init(config)
}

pub async fn create_message_handler(options: Option<ManagerOptions>) -> crate::wallet::Result<WalletMessageHandler> {
pub async fn create_message_handler(options: Option<ManagerOptions>) -> iota_sdk::wallet::Result<WalletMessageHandler> {
log::debug!(
"create_message_handler with options: {}",
serde_json::to_string(&options)?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@

use std::fmt::{Debug, Formatter, Result};

use serde::Serialize;
#[cfg(feature = "participation")]
use {
crate::types::api::plugins::participation::types::{ParticipationEventId, ParticipationEventStatus},
crate::wallet::account::operations::participation::{AccountParticipationOverview, ParticipationEventWithNodes},
std::collections::HashMap,
};

#[cfg(feature = "ledger_nano")]
use crate::client::secret::LedgerNanoStatus;
use crate::{
use iota_sdk::client::secret::LedgerNanoStatus;
use iota_sdk::{
client::{
api::{PreparedTransactionDataDto, SignedTransactionDataDto},
NodeInfoWrapper,
Expand All @@ -25,14 +17,19 @@ use crate::{
},
wallet::{
account::{
operations::transaction::high_level::minting::create_native_token::CreateNativeTokenTransactionDto,
types::{address::AccountAddress, AddressWithUnspentOutputs, Balance, TransactionDto},
OutputDataDto,
types::{AccountAddress, AddressWithUnspentOutputs, Balance, TransactionDto},
AccountDetailsDto, CreateNativeTokenTransactionDto, OutputDataDto,
},
message_interface::dtos::AccountDetailsDto,
Error,
},
};
use serde::Serialize;
#[cfg(feature = "participation")]
use {
iota_sdk::types::api::plugins::participation::types::{ParticipationEventId, ParticipationEventStatus},
iota_sdk::wallet::account::{AccountParticipationOverview, ParticipationEventWithNodes},
std::collections::HashMap,
};

/// The response message.
#[derive(Serialize)]
Expand Down
Loading

0 comments on commit f08cee2

Please sign in to comment.