From f19c26a684d6aac110cc643255e48c3478579386 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Thu, 29 Feb 2024 16:53:08 +0100 Subject: [PATCH 01/13] feat: Reorder wallet events and add a new block event --- bindings/nodejs/lib/types/wallet/event.ts | 36 +++++++++---- sdk/src/types/block/core/block.rs | 9 +++- sdk/src/wallet/events/types.rs | 54 ++++++++++++++----- sdk/src/wallet/operations/block.rs | 11 +++- .../transaction/submit_transaction.rs | 7 ++- 5 files changed, 89 insertions(+), 28 deletions(-) diff --git a/bindings/nodejs/lib/types/wallet/event.ts b/bindings/nodejs/lib/types/wallet/event.ts index 10b8884e79..aa1e0d1175 100644 --- a/bindings/nodejs/lib/types/wallet/event.ts +++ b/bindings/nodejs/lib/types/wallet/event.ts @@ -121,12 +121,14 @@ enum TransactionProgressType { GeneratingRemainderDepositAddress = 1, /** Prepared transaction. */ PreparedTransaction = 2, - /** Prepared transaction signing hash hex encoded, required for blindsigning with a Ledger Nano. */ - PreparedTransactionSigningHash = 3, /** Signing the transaction. */ - SigningTransaction = 4, + SigningTransaction = 3, + /** Prepared transaction signing hash hex encoded, required for blindsigning with a Ledger Nano. */ + PreparedTransactionSigningHash = 4, + /** Prepared block signing hash hex encoded, required for blindsigning with a Ledger Nano. */ + PrepareBlockSigningHash = 5, /** Broadcasting. */ - Broadcasting = 5, + Broadcasting = 6, } /** @@ -207,6 +209,15 @@ class PreparedTransactionProgress extends TransactionProgress { } } +/** + * A 'signing transaction' progress. + */ +class SigningTransactionProgress extends TransactionProgress { + constructor() { + super(TransactionProgressType.SigningTransaction); + } +} + /** * A 'prepared transaction hash' progress. */ @@ -223,11 +234,17 @@ class PreparedTransactionSigningHashProgress extends TransactionProgress { } /** - * A 'signing transaction' progress. + * A 'prepared block hash' progress. */ -class SigningTransactionProgress extends TransactionProgress { - constructor() { - super(TransactionProgressType.SigningTransaction); +class PreparedBlockSigningHashProgress extends TransactionProgress { + blockSigningHash: HexEncodedString; + + /** + * @param signingHash The signing hash of the block. + */ + constructor(signingHash: HexEncodedString) { + super(TransactionProgressType.PrepareBlockSigningHash); + this.blockSigningHash = signingHash; } } @@ -252,8 +269,9 @@ export { SelectingInputsProgress, GeneratingRemainderDepositAddressProgress, PreparedTransactionProgress, - PreparedTransactionSigningHashProgress, SigningTransactionProgress, + PreparedTransactionSigningHashProgress, + PreparedBlockSigningHashProgress, BroadcastingProgress, TransactionProgressType, }; diff --git a/sdk/src/types/block/core/block.rs b/sdk/src/types/block/core/block.rs index aca6943614..ee284e029a 100644 --- a/sdk/src/types/block/core/block.rs +++ b/sdk/src/types/block/core/block.rs @@ -17,7 +17,7 @@ use crate::types::block::{ block_id::{BlockHash, BlockId}, core::{BasicBlockBody, ValidationBlockBody}, output::AccountId, - payload::Payload, + payload::{signed_transaction::TransactionSigningHash, Payload}, protocol::ProtocolParameters, signature::Signature, slot::{SlotCommitmentId, SlotIndex}, @@ -25,7 +25,7 @@ use crate::types::block::{ }; /// Block without a signature. Can be finished into a [`Block`]. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Packable)] pub struct UnsignedBlock { /// The block header. pub(crate) header: BlockHeader, @@ -57,6 +57,11 @@ impl UnsignedBlock { [self.header.hash(), self.body.hash()].concat() } + /// Return the Blake2b hash of the block. + pub fn signing_hash(&self) -> TransactionSigningHash { + TransactionSigningHash::new(Blake2b256::digest(self.pack_to_vec()).into()) + } + /// Finishes an [`UnsignedBlock`] into a [`Block`]. pub fn finish_with_params<'a>( self, diff --git a/sdk/src/wallet/events/types.rs b/sdk/src/wallet/events/types.rs index 475fd5ab2e..73cbc9f9c6 100644 --- a/sdk/src/wallet/events/types.rs +++ b/sdk/src/wallet/events/types.rs @@ -200,10 +200,12 @@ pub enum TransactionProgressEvent { GeneratingRemainderDepositAddress(AddressData), /// Prepared transaction. PreparedTransaction(Box), - /// Prepared transaction signing hash hex encoded, required for blindsigning with a ledger nano - PreparedTransactionSigningHash(String), /// Signing the transaction. SigningTransaction, + /// Prepared transaction signing hash hex encoded, required for blindsigning with a ledger nano + PreparedTransactionSigningHash(String), + /// Prepared block signing hash hex encoded, required for blind signing with ledger nano + PreparedBlockSigningHash(String), /// Broadcasting. Broadcasting, } @@ -219,15 +221,22 @@ impl Serialize for TransactionProgressEvent { signing_hash: &'a str, } + #[derive(Serialize)] + #[serde(rename_all = "camelCase")] + struct PreparedBlockSigningHash_<'a> { + block_signing_hash: &'a str, + } + #[derive(Serialize)] #[serde(untagged)] enum TransactionProgressEvent_<'a> { T0, T1(&'a AddressData), T2(&'a PreparedTransactionDataDto), - T3(PreparedTransactionSigningHash_<'a>), - T4, - T5, + T3, + T4(PreparedTransactionSigningHash_<'a>), + T5(PreparedBlockSigningHash_<'a>), + T6, } #[derive(Serialize)] struct TypedTransactionProgressEvent_<'a> { @@ -249,17 +258,21 @@ impl Serialize for TransactionProgressEvent { kind: 2, event: TransactionProgressEvent_::T2(e), }, - Self::PreparedTransactionSigningHash(e) => TypedTransactionProgressEvent_ { + Self::SigningTransaction => TypedTransactionProgressEvent_ { kind: 3, - event: TransactionProgressEvent_::T3(PreparedTransactionSigningHash_ { signing_hash: e }), + event: TransactionProgressEvent_::T3, }, - Self::SigningTransaction => TypedTransactionProgressEvent_ { + Self::PreparedTransactionSigningHash(e) => TypedTransactionProgressEvent_ { kind: 4, - event: TransactionProgressEvent_::T4, + event: TransactionProgressEvent_::T4(PreparedTransactionSigningHash_ { signing_hash: e }), }, - Self::Broadcasting => TypedTransactionProgressEvent_ { + Self::PreparedBlockSigningHash(e) => TypedTransactionProgressEvent_ { kind: 5, - event: TransactionProgressEvent_::T5, + event: TransactionProgressEvent_::T5(PreparedBlockSigningHash_ { block_signing_hash: e }), + }, + Self::Broadcasting => TypedTransactionProgressEvent_ { + kind: 6, + event: TransactionProgressEvent_::T6, }, }; event.serialize(serializer) @@ -274,6 +287,12 @@ impl<'de> Deserialize<'de> for TransactionProgressEvent { signing_hash: String, } + #[derive(Deserialize)] + #[serde(rename_all = "camelCase")] + struct PreparedBlockSigningHash_ { + signing_hash: String, + } + let value = serde_json::Value::deserialize(d)?; Ok( match value @@ -289,15 +308,22 @@ impl<'de> Deserialize<'de> for TransactionProgressEvent { 2 => Self::PreparedTransaction(Box::new(PreparedTransactionDataDto::deserialize(value).map_err( |e| serde::de::Error::custom(format!("cannot deserialize PreparedTransactionDataDto: {e}")), )?)), - 3 => Self::PreparedTransactionSigningHash( + 3 => Self::SigningTransaction, + 4 => Self::PreparedTransactionSigningHash( PreparedTransactionSigningHash_::deserialize(value) .map_err(|e| { serde::de::Error::custom(format!("cannot deserialize PreparedTransactionSigningHash: {e}")) })? .signing_hash, ), - 4 => Self::SigningTransaction, - 5 => Self::Broadcasting, + 5 => Self::PreparedBlockSigningHash( + PreparedBlockSigningHash_::deserialize(value) + .map_err(|e| { + serde::de::Error::custom(format!("cannot deserialize PreparedBlockSigningHash: {e}")) + })? + .signing_hash, + ), + 6 => Self::Broadcasting, _ => return Err(serde::de::Error::custom("invalid transaction progress event type")), }, ) diff --git a/sdk/src/wallet/operations/block.rs b/sdk/src/wallet/operations/block.rs index 20273a047e..080ef31b12 100644 --- a/sdk/src/wallet/operations/block.rs +++ b/sdk/src/wallet/operations/block.rs @@ -4,7 +4,10 @@ use crate::{ client::secret::{SecretManage, SignBlock}, types::block::{output::AccountId, payload::Payload, BlockId}, - wallet::{Error, Result, Wallet}, + wallet::{ + events::{types::TransactionProgressEvent, WalletEvent}, + Error, Result, Wallet, + }, }; impl Wallet @@ -39,6 +42,12 @@ where } } + #[cfg(feature = "events")] + self.emit(WalletEvent::TransactionProgress( + TransactionProgressEvent::PreparedBlockSigningHash(unsigned_block.signing_hash().to_string()), + )) + .await; + let block = unsigned_block .sign_ed25519( &*self.get_secret_manager().read().await, diff --git a/sdk/src/wallet/operations/transaction/submit_transaction.rs b/sdk/src/wallet/operations/transaction/submit_transaction.rs index 0da286d2ee..3ef6c972c5 100644 --- a/sdk/src/wallet/operations/transaction/submit_transaction.rs +++ b/sdk/src/wallet/operations/transaction/submit_transaction.rs @@ -22,11 +22,14 @@ where ) -> crate::wallet::Result { log::debug!("[TRANSACTION] submit_signed_transaction"); + let block_id = self + .submit_basic_block(Some(Payload::from(payload)), issuer_id, true) + .await?; + #[cfg(feature = "events")] self.emit(WalletEvent::TransactionProgress(TransactionProgressEvent::Broadcasting)) .await; - self.submit_basic_block(Some(Payload::from(payload)), issuer_id, true) - .await + Ok(block_id) } } From e6cd887be297a8ba04460284599372ebb0264d27 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Fri, 1 Mar 2024 09:34:10 +0100 Subject: [PATCH 02/13] Add `BlockSigningHash` and update wallet events tests --- sdk/src/types/block/core/block.rs | 17 ++++++++---- sdk/src/wallet/operations/block.rs | 7 +++-- sdk/tests/wallet/events.rs | 43 ++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/sdk/src/types/block/core/block.rs b/sdk/src/types/block/core/block.rs index ee284e029a..557905913c 100644 --- a/sdk/src/types/block/core/block.rs +++ b/sdk/src/types/block/core/block.rs @@ -17,15 +17,22 @@ use crate::types::block::{ block_id::{BlockHash, BlockId}, core::{BasicBlockBody, ValidationBlockBody}, output::AccountId, - payload::{signed_transaction::TransactionSigningHash, Payload}, + payload::Payload, protocol::ProtocolParameters, signature::Signature, slot::{SlotCommitmentId, SlotIndex}, BlockBody, Error, }; +crate::impl_id!( + /// The signing hash of a [`Block`]. + pub BlockSigningHash { + pub const LENGTH: usize = 32; + } +); + /// Block without a signature. Can be finished into a [`Block`]. -#[derive(Clone, Debug, Eq, PartialEq, Packable)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct UnsignedBlock { /// The block header. pub(crate) header: BlockHeader, @@ -57,9 +64,9 @@ impl UnsignedBlock { [self.header.hash(), self.body.hash()].concat() } - /// Return the Blake2b hash of the block. - pub fn signing_hash(&self) -> TransactionSigningHash { - TransactionSigningHash::new(Blake2b256::digest(self.pack_to_vec()).into()) + /// Return the Blake2b hash of the block's signing input. + pub fn signing_hash(&self) -> BlockSigningHash { + BlockSigningHash::new(Blake2b256::digest(self.signing_input()).into()) } /// Finishes an [`UnsignedBlock`] into a [`Block`]. diff --git a/sdk/src/wallet/operations/block.rs b/sdk/src/wallet/operations/block.rs index 080ef31b12..4cbf5cb5bf 100644 --- a/sdk/src/wallet/operations/block.rs +++ b/sdk/src/wallet/operations/block.rs @@ -1,13 +1,12 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +#[cfg(feature = "events")] +use crate::wallet::events::types::{TransactionProgressEvent, WalletEvent}; use crate::{ client::secret::{SecretManage, SignBlock}, types::block::{output::AccountId, payload::Payload, BlockId}, - wallet::{ - events::{types::TransactionProgressEvent, WalletEvent}, - Error, Result, Wallet, - }, + wallet::{Error, Result, Wallet}, }; impl Wallet diff --git a/sdk/tests/wallet/events.rs b/sdk/tests/wallet/events.rs index 2293698ee1..778c908829 100644 --- a/sdk/tests/wallet/events.rs +++ b/sdk/tests/wallet/events.rs @@ -5,18 +5,27 @@ use iota_sdk::{ client::api::PreparedTransactionDataDto, types::block::{ address::{Address, Bech32Address, Ed25519Address}, + core::{ + basic::{MaxBurnedManaAmount, StrongParents}, + BlockHeader, + }, input::{Input, UtxoInput}, output::{ - unlock_condition::AddressUnlockCondition, BasicOutput, LeafHash, Output, OutputCommitmentProof, + unlock_condition::AddressUnlockCondition, AccountId, BasicOutput, LeafHash, Output, OutputCommitmentProof, OutputIdProof, }, - payload::signed_transaction::{Transaction, TransactionHash, TransactionId}, + payload::{ + signed_transaction::{Transaction, TransactionHash, TransactionId}, + Payload, SignedTransactionPayload, + }, protocol::iota_mainnet_protocol_parameters, rand::{ mana::rand_mana_allotment, output::{rand_basic_output, rand_output_metadata}, }, - slot::SlotIndex, + slot::{SlotCommitmentId, SlotIndex}, + unlock::Unlocks, + BlockBody, UnsignedBlock, }, wallet::{ events::types::{ @@ -115,14 +124,38 @@ fn wallet_events_serde() { mana_rewards: Default::default(), })), )); + + let block_payload = SignedTransactionPayload::new(transaction, Unlocks::new([]).unwrap()).unwrap(); + let payload = Payload::from(block_payload); + let block = UnsignedBlock::new( + BlockHeader::new( + protocol_parameters.version(), + protocol_parameters.network_id(), + 0u64, + SlotCommitmentId::new([0; 36]), + SlotIndex(0), + AccountId::new([0; 32]), + ), + BlockBody::build_basic( + StrongParents::from_vec(Vec::default()).unwrap(), + MaxBurnedManaAmount::Amount(0), + ) + .with_payload(payload) + .finish_block_body() + .unwrap(), + ); + + assert_serde_eq(WalletEvent::TransactionProgress( + TransactionProgressEvent::PreparedBlockSigningHash(block.signing_hash().to_string()), + )); } assert_serde_eq(WalletEvent::TransactionProgress( - TransactionProgressEvent::PreparedTransactionSigningHash(ED25519_ADDRESS.to_string()), + TransactionProgressEvent::SigningTransaction, )); assert_serde_eq(WalletEvent::TransactionProgress( - TransactionProgressEvent::SigningTransaction, + TransactionProgressEvent::PreparedTransactionSigningHash(ED25519_ADDRESS.to_string()), )); assert_serde_eq(WalletEvent::TransactionProgress(TransactionProgressEvent::Broadcasting)); From 073a12fbcd886365850f58f572a53dc1b68cfe27 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Fri, 1 Mar 2024 09:35:51 +0100 Subject: [PATCH 03/13] update comment --- sdk/src/types/block/core/block.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/types/block/core/block.rs b/sdk/src/types/block/core/block.rs index 557905913c..d048c1c072 100644 --- a/sdk/src/types/block/core/block.rs +++ b/sdk/src/types/block/core/block.rs @@ -25,7 +25,7 @@ use crate::types::block::{ }; crate::impl_id!( - /// The signing hash of a [`Block`]. + /// The signing hash of a [`Block`]'s signing input. pub BlockSigningHash { pub const LENGTH: usize = 32; } From 93fcccf49f7333e00cfcf465bccabe112a691d98 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Fri, 1 Mar 2024 09:49:02 +0100 Subject: [PATCH 04/13] add missing unlocks --- sdk/tests/wallet/events.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sdk/tests/wallet/events.rs b/sdk/tests/wallet/events.rs index 778c908829..f097f93af3 100644 --- a/sdk/tests/wallet/events.rs +++ b/sdk/tests/wallet/events.rs @@ -24,7 +24,7 @@ use iota_sdk::{ output::{rand_basic_output, rand_output_metadata}, }, slot::{SlotCommitmentId, SlotIndex}, - unlock::Unlocks, + unlock::{EmptyUnlock, Unlock, Unlocks}, BlockBody, UnsignedBlock, }, wallet::{ @@ -125,7 +125,11 @@ fn wallet_events_serde() { })), )); - let block_payload = SignedTransactionPayload::new(transaction, Unlocks::new([]).unwrap()).unwrap(); + let block_payload = SignedTransactionPayload::new( + transaction, + Unlocks::new([Unlock::Empty(EmptyUnlock), Unlock::Empty(EmptyUnlock)]).unwrap(), + ) + .unwrap(); let payload = Payload::from(block_payload); let block = UnsignedBlock::new( BlockHeader::new( From 26837c36fba4fdf274dbd6858f2754ad6a8dbe10 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Fri, 1 Mar 2024 10:44:13 +0100 Subject: [PATCH 05/13] I hope this works --- sdk/src/wallet/events/types.rs | 4 ++-- sdk/tests/wallet/events.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/src/wallet/events/types.rs b/sdk/src/wallet/events/types.rs index 99c255c900..19b5937b8b 100644 --- a/sdk/src/wallet/events/types.rs +++ b/sdk/src/wallet/events/types.rs @@ -288,7 +288,7 @@ impl<'de> Deserialize<'de> for TransactionProgressEvent { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] struct PreparedBlockSigningHash_ { - signing_hash: String, + block_signing_hash: String, } let value = serde_json::Value::deserialize(d)?; @@ -319,7 +319,7 @@ impl<'de> Deserialize<'de> for TransactionProgressEvent { .map_err(|e| { serde::de::Error::custom(format!("cannot deserialize PreparedBlockSigningHash: {e}")) })? - .signing_hash, + .block_signing_hash, ), 6 => Self::Broadcasting, _ => return Err(serde::de::Error::custom("invalid transaction progress event type")), diff --git a/sdk/tests/wallet/events.rs b/sdk/tests/wallet/events.rs index f097f93af3..053a83654f 100644 --- a/sdk/tests/wallet/events.rs +++ b/sdk/tests/wallet/events.rs @@ -25,7 +25,7 @@ use iota_sdk::{ }, slot::{SlotCommitmentId, SlotIndex}, unlock::{EmptyUnlock, Unlock, Unlocks}, - BlockBody, UnsignedBlock, + BlockBody, BlockId, UnsignedBlock, }, wallet::{ events::types::{ @@ -141,7 +141,7 @@ fn wallet_events_serde() { AccountId::new([0; 32]), ), BlockBody::build_basic( - StrongParents::from_vec(Vec::default()).unwrap(), + StrongParents::from_vec(vec![BlockId::new([0; 36])]).unwrap(), MaxBurnedManaAmount::Amount(0), ) .with_payload(payload) From 1b8e15e7370ec2280f7e16bb013ffb22794be3cf Mon Sep 17 00:00:00 2001 From: marc2332 Date: Fri, 1 Mar 2024 17:37:07 +0100 Subject: [PATCH 06/13] fixes and improvements --- bindings/nodejs/lib/types/wallet/event.ts | 18 ++++++++-------- sdk/src/types/block/core/block.rs | 12 ----------- sdk/src/wallet/events/types.rs | 26 +++++++++++------------ sdk/src/wallet/operations/block.rs | 2 +- sdk/tests/wallet/events.rs | 2 +- 5 files changed, 24 insertions(+), 36 deletions(-) diff --git a/bindings/nodejs/lib/types/wallet/event.ts b/bindings/nodejs/lib/types/wallet/event.ts index aa1e0d1175..2105eaac69 100644 --- a/bindings/nodejs/lib/types/wallet/event.ts +++ b/bindings/nodejs/lib/types/wallet/event.ts @@ -125,8 +125,8 @@ enum TransactionProgressType { SigningTransaction = 3, /** Prepared transaction signing hash hex encoded, required for blindsigning with a Ledger Nano. */ PreparedTransactionSigningHash = 4, - /** Prepared block signing hash hex encoded, required for blindsigning with a Ledger Nano. */ - PrepareBlockSigningHash = 5, + /** Prepared block signing input, required for blindsigning with a Ledger Nano. */ + PrepareBlockSigningInput = 5, /** Broadcasting. */ Broadcasting = 6, } @@ -234,17 +234,17 @@ class PreparedTransactionSigningHashProgress extends TransactionProgress { } /** - * A 'prepared block hash' progress. + * A 'prepared block input' progress. */ -class PreparedBlockSigningHashProgress extends TransactionProgress { - blockSigningHash: HexEncodedString; +class PreparedBlockSigningInputProgress extends TransactionProgress { + blockSigningInput: Array; /** * @param signingHash The signing hash of the block. */ - constructor(signingHash: HexEncodedString) { - super(TransactionProgressType.PrepareBlockSigningHash); - this.blockSigningHash = signingHash; + constructor(signingInput: Array) { + super(TransactionProgressType.PrepareBlockSigningInput); + this.blockSigningInput = signingInput; } } @@ -271,7 +271,7 @@ export { PreparedTransactionProgress, SigningTransactionProgress, PreparedTransactionSigningHashProgress, - PreparedBlockSigningHashProgress, + PreparedBlockSigningInputProgress, BroadcastingProgress, TransactionProgressType, }; diff --git a/sdk/src/types/block/core/block.rs b/sdk/src/types/block/core/block.rs index f1a5a92cd7..0cf0502033 100644 --- a/sdk/src/types/block/core/block.rs +++ b/sdk/src/types/block/core/block.rs @@ -24,13 +24,6 @@ use crate::types::block::{ BlockBody, }; -crate::impl_id!( - /// The signing hash of a [`Block`]'s signing input. - pub BlockSigningHash { - pub const LENGTH: usize = 32; - } -); - /// Block without a signature. Can be finished into a [`Block`]. #[derive(Clone, Debug, Eq, PartialEq)] pub struct UnsignedBlock { @@ -64,11 +57,6 @@ impl UnsignedBlock { [self.header.hash(), self.body.hash()].concat() } - /// Return the Blake2b hash of the block's signing input. - pub fn signing_hash(&self) -> BlockSigningHash { - BlockSigningHash::new(Blake2b256::digest(self.signing_input()).into()) - } - /// Finishes an [`UnsignedBlock`] into a [`Block`]. pub fn finish_with_params<'a>( self, diff --git a/sdk/src/wallet/events/types.rs b/sdk/src/wallet/events/types.rs index 19b5937b8b..87c41671bd 100644 --- a/sdk/src/wallet/events/types.rs +++ b/sdk/src/wallet/events/types.rs @@ -202,8 +202,8 @@ pub enum TransactionProgressEvent { SigningTransaction, /// Prepared transaction signing hash hex encoded, required for blindsigning with a ledger nano PreparedTransactionSigningHash(String), - /// Prepared block signing hash hex encoded, required for blind signing with ledger nano - PreparedBlockSigningHash(String), + /// Prepared block signing input, required for blind signing with ledger nano + PreparedBlockSigningInput(Vec), /// Broadcasting. Broadcasting, } @@ -221,8 +221,8 @@ impl Serialize for TransactionProgressEvent { #[derive(Serialize)] #[serde(rename_all = "camelCase")] - struct PreparedBlockSigningHash_<'a> { - block_signing_hash: &'a str, + struct PreparedBlockSigningInput_<'a> { + block_signing_input: &'a [u8], } #[derive(Serialize)] @@ -233,7 +233,7 @@ impl Serialize for TransactionProgressEvent { T2(&'a PreparedTransactionDataDto), T3, T4(PreparedTransactionSigningHash_<'a>), - T5(PreparedBlockSigningHash_<'a>), + T5(PreparedBlockSigningInput_<'a>), T6, } #[derive(Serialize)] @@ -264,9 +264,9 @@ impl Serialize for TransactionProgressEvent { kind: 4, event: TransactionProgressEvent_::T4(PreparedTransactionSigningHash_ { signing_hash: e }), }, - Self::PreparedBlockSigningHash(e) => TypedTransactionProgressEvent_ { + Self::PreparedBlockSigningInput(e) => TypedTransactionProgressEvent_ { kind: 5, - event: TransactionProgressEvent_::T5(PreparedBlockSigningHash_ { block_signing_hash: e }), + event: TransactionProgressEvent_::T5(PreparedBlockSigningInput_ { block_signing_input: e }), }, Self::Broadcasting => TypedTransactionProgressEvent_ { kind: 6, @@ -287,8 +287,8 @@ impl<'de> Deserialize<'de> for TransactionProgressEvent { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] - struct PreparedBlockSigningHash_ { - block_signing_hash: String, + struct PreparedBlockSigningInput_ { + block_signing_input: Vec, } let value = serde_json::Value::deserialize(d)?; @@ -314,12 +314,12 @@ impl<'de> Deserialize<'de> for TransactionProgressEvent { })? .signing_hash, ), - 5 => Self::PreparedBlockSigningHash( - PreparedBlockSigningHash_::deserialize(value) + 5 => Self::PreparedBlockSigningInput( + PreparedBlockSigningInput_::deserialize(value) .map_err(|e| { - serde::de::Error::custom(format!("cannot deserialize PreparedBlockSigningHash: {e}")) + serde::de::Error::custom(format!("cannot deserialize PreparedBlockSigningInput: {e}")) })? - .block_signing_hash, + .block_signing_input, ), 6 => Self::Broadcasting, _ => return Err(serde::de::Error::custom("invalid transaction progress event type")), diff --git a/sdk/src/wallet/operations/block.rs b/sdk/src/wallet/operations/block.rs index 4cbf5cb5bf..e4bf5b7d3d 100644 --- a/sdk/src/wallet/operations/block.rs +++ b/sdk/src/wallet/operations/block.rs @@ -43,7 +43,7 @@ where #[cfg(feature = "events")] self.emit(WalletEvent::TransactionProgress( - TransactionProgressEvent::PreparedBlockSigningHash(unsigned_block.signing_hash().to_string()), + TransactionProgressEvent::PreparedBlockSigningInput(unsigned_block.signing_input()), )) .await; diff --git a/sdk/tests/wallet/events.rs b/sdk/tests/wallet/events.rs index 053a83654f..e460a814b7 100644 --- a/sdk/tests/wallet/events.rs +++ b/sdk/tests/wallet/events.rs @@ -150,7 +150,7 @@ fn wallet_events_serde() { ); assert_serde_eq(WalletEvent::TransactionProgress( - TransactionProgressEvent::PreparedBlockSigningHash(block.signing_hash().to_string()), + TransactionProgressEvent::PreparedBlockSigningInput(block.signing_input()), )); } From 4228c0d8e30c5149367d069f47c5c3d2b7cea443 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Mon, 4 Mar 2024 08:41:43 +0100 Subject: [PATCH 07/13] fix typo in nodejs bindings --- bindings/nodejs/lib/types/wallet/event.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/nodejs/lib/types/wallet/event.ts b/bindings/nodejs/lib/types/wallet/event.ts index 2105eaac69..ca7e38ec2a 100644 --- a/bindings/nodejs/lib/types/wallet/event.ts +++ b/bindings/nodejs/lib/types/wallet/event.ts @@ -126,7 +126,7 @@ enum TransactionProgressType { /** Prepared transaction signing hash hex encoded, required for blindsigning with a Ledger Nano. */ PreparedTransactionSigningHash = 4, /** Prepared block signing input, required for blindsigning with a Ledger Nano. */ - PrepareBlockSigningInput = 5, + PreparedBlockSigningInput = 5, /** Broadcasting. */ Broadcasting = 6, } @@ -243,7 +243,7 @@ class PreparedBlockSigningInputProgress extends TransactionProgress { * @param signingHash The signing hash of the block. */ constructor(signingInput: Array) { - super(TransactionProgressType.PrepareBlockSigningInput); + super(TransactionProgressType.PreparedBlockSigningInput); this.blockSigningInput = signingInput; } } From b0c87cbcd41c80a6fe8cc9cf9592928794d4a923 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 5 Mar 2024 09:08:52 +0100 Subject: [PATCH 08/13] emit broadcasting event after block signing and before emitting --- sdk/src/wallet/operations/block.rs | 4 ++++ sdk/src/wallet/operations/transaction/submit_transaction.rs | 6 ------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sdk/src/wallet/operations/block.rs b/sdk/src/wallet/operations/block.rs index e4bf5b7d3d..2e2f7835fc 100644 --- a/sdk/src/wallet/operations/block.rs +++ b/sdk/src/wallet/operations/block.rs @@ -54,6 +54,10 @@ where ) .await?; + #[cfg(feature = "events")] + self.emit(WalletEvent::TransactionProgress(TransactionProgressEvent::Broadcasting)) + .await; + let block_id = self.client().post_block(&block).await?; log::debug!("submitted block {}", block_id); diff --git a/sdk/src/wallet/operations/transaction/submit_transaction.rs b/sdk/src/wallet/operations/transaction/submit_transaction.rs index 3ef6c972c5..416aaa5235 100644 --- a/sdk/src/wallet/operations/transaction/submit_transaction.rs +++ b/sdk/src/wallet/operations/transaction/submit_transaction.rs @@ -1,8 +1,6 @@ // Copyright 2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -#[cfg(feature = "events")] -use crate::wallet::events::types::{TransactionProgressEvent, WalletEvent}; use crate::{ client::secret::SecretManage, types::block::{output::AccountId, payload::Payload, BlockId}, @@ -26,10 +24,6 @@ where .submit_basic_block(Some(Payload::from(payload)), issuer_id, true) .await?; - #[cfg(feature = "events")] - self.emit(WalletEvent::TransactionProgress(TransactionProgressEvent::Broadcasting)) - .await; - Ok(block_id) } } From 6640cc4f0c899179dffcd4e224799131774340bc Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 5 Mar 2024 09:22:31 +0100 Subject: [PATCH 09/13] python events --- .../examples/exchange/4_listen_events.py | 6 ++--- bindings/python/iota_sdk/types/event.py | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bindings/python/examples/exchange/4_listen_events.py b/bindings/python/examples/exchange/4_listen_events.py index fdd180f64d..7adcc14f62 100644 --- a/bindings/python/examples/exchange/4_listen_events.py +++ b/bindings/python/examples/exchange/4_listen_events.py @@ -1,7 +1,7 @@ # Copyright 2023 IOTA Stiftung # SPDX-License-Identifier: Apache-2.0 -# This example listens to the NewOutput event. +# This example listens to the SelectingInputs event. import json import os @@ -35,8 +35,8 @@ def callback(event): received_event = True -# Only interested in new outputs here. -wallet.listen(callback, [WalletEventType.NewOutput]) +# Only interested when inputs are being selected. +wallet.listen(callback, [WalletEventType.SelectingInputs]) # Use the faucet to send testnet tokens to your address. print(f'Fill your address with the Faucet: {os.environ["FAUCET_URL"]}') diff --git a/bindings/python/iota_sdk/types/event.py b/bindings/python/iota_sdk/types/event.py index 75ed34886a..50147125bd 100644 --- a/bindings/python/iota_sdk/types/event.py +++ b/bindings/python/iota_sdk/types/event.py @@ -8,14 +8,18 @@ class WalletEventType(IntEnum): """Types of wallet events. Attributes: - LedgerAddressGeneration (0): Nano Ledger has generated an address. - NewOutput (1): A new output was created. - SpentOutput (2): An output was spent. - TransactionInclusion (3): A transaction was included into the ledger. - TransactionProgress (4): A progress update while submitting a transaction. + SelectingInputs (0): Performing input selection. + GeneratingRemainderDepositAddress (1): Generating remainder value deposit address. + PreparedTransaction (2): Prepared transaction. + SigningTransaction (3): Signing the transaction. + PreparedTransactionSigningHash (4): Prepared transaction signing hash hex encoded, required for blindsigning with a Ledger Nano. + PreparedBlockSigningInput (5): Prepared block signing input, required for blindsigning with a Ledger Nano. + Broadcasting (6): Broadcasting. """ - LedgerAddressGeneration = 0 - NewOutput = 1 - SpentOutput = 2 - TransactionInclusion = 3 - TransactionProgress = 4 + SelectingInputs = 0 + GeneratingRemainderDepositAddress = 1 + PreparedTransaction = 2 + SigningTransaction = 3 + PreparedTransactionSigningHash = 4 + PreparedBlockSigningInput = 5 + Broadcasting = 6 From 698c4b3fbb2fa92d96a470e069b8eecf94a9380c Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 5 Mar 2024 09:45:41 +0100 Subject: [PATCH 10/13] revert wallet events --- .../examples/exchange/4_listen_events.py | 6 ++--- bindings/python/iota_sdk/types/event.py | 24 ++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/bindings/python/examples/exchange/4_listen_events.py b/bindings/python/examples/exchange/4_listen_events.py index 7adcc14f62..fdd180f64d 100644 --- a/bindings/python/examples/exchange/4_listen_events.py +++ b/bindings/python/examples/exchange/4_listen_events.py @@ -1,7 +1,7 @@ # Copyright 2023 IOTA Stiftung # SPDX-License-Identifier: Apache-2.0 -# This example listens to the SelectingInputs event. +# This example listens to the NewOutput event. import json import os @@ -35,8 +35,8 @@ def callback(event): received_event = True -# Only interested when inputs are being selected. -wallet.listen(callback, [WalletEventType.SelectingInputs]) +# Only interested in new outputs here. +wallet.listen(callback, [WalletEventType.NewOutput]) # Use the faucet to send testnet tokens to your address. print(f'Fill your address with the Faucet: {os.environ["FAUCET_URL"]}') diff --git a/bindings/python/iota_sdk/types/event.py b/bindings/python/iota_sdk/types/event.py index 50147125bd..75ed34886a 100644 --- a/bindings/python/iota_sdk/types/event.py +++ b/bindings/python/iota_sdk/types/event.py @@ -8,18 +8,14 @@ class WalletEventType(IntEnum): """Types of wallet events. Attributes: - SelectingInputs (0): Performing input selection. - GeneratingRemainderDepositAddress (1): Generating remainder value deposit address. - PreparedTransaction (2): Prepared transaction. - SigningTransaction (3): Signing the transaction. - PreparedTransactionSigningHash (4): Prepared transaction signing hash hex encoded, required for blindsigning with a Ledger Nano. - PreparedBlockSigningInput (5): Prepared block signing input, required for blindsigning with a Ledger Nano. - Broadcasting (6): Broadcasting. + LedgerAddressGeneration (0): Nano Ledger has generated an address. + NewOutput (1): A new output was created. + SpentOutput (2): An output was spent. + TransactionInclusion (3): A transaction was included into the ledger. + TransactionProgress (4): A progress update while submitting a transaction. """ - SelectingInputs = 0 - GeneratingRemainderDepositAddress = 1 - PreparedTransaction = 2 - SigningTransaction = 3 - PreparedTransactionSigningHash = 4 - PreparedBlockSigningInput = 5 - Broadcasting = 6 + LedgerAddressGeneration = 0 + NewOutput = 1 + SpentOutput = 2 + TransactionInclusion = 3 + TransactionProgress = 4 From 463c96b8367018f0488edc40269f63441262a4f3 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 5 Mar 2024 12:07:54 +0100 Subject: [PATCH 11/13] improvements --- bindings/nodejs/lib/types/wallet/event.ts | 4 ++-- sdk/src/wallet/events/types.rs | 6 +++--- sdk/src/wallet/operations/block.rs | 2 +- sdk/tests/wallet/events.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bindings/nodejs/lib/types/wallet/event.ts b/bindings/nodejs/lib/types/wallet/event.ts index ca7e38ec2a..551a83a801 100644 --- a/bindings/nodejs/lib/types/wallet/event.ts +++ b/bindings/nodejs/lib/types/wallet/event.ts @@ -237,12 +237,12 @@ class PreparedTransactionSigningHashProgress extends TransactionProgress { * A 'prepared block input' progress. */ class PreparedBlockSigningInputProgress extends TransactionProgress { - blockSigningInput: Array; + blockSigningInput: string; /** * @param signingHash The signing hash of the block. */ - constructor(signingInput: Array) { + constructor(signingInput: string) { super(TransactionProgressType.PreparedBlockSigningInput); this.blockSigningInput = signingInput; } diff --git a/sdk/src/wallet/events/types.rs b/sdk/src/wallet/events/types.rs index 87c41671bd..5af775b4e4 100644 --- a/sdk/src/wallet/events/types.rs +++ b/sdk/src/wallet/events/types.rs @@ -203,7 +203,7 @@ pub enum TransactionProgressEvent { /// Prepared transaction signing hash hex encoded, required for blindsigning with a ledger nano PreparedTransactionSigningHash(String), /// Prepared block signing input, required for blind signing with ledger nano - PreparedBlockSigningInput(Vec), + PreparedBlockSigningInput(String), /// Broadcasting. Broadcasting, } @@ -222,7 +222,7 @@ impl Serialize for TransactionProgressEvent { #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct PreparedBlockSigningInput_<'a> { - block_signing_input: &'a [u8], + block_signing_input: &'a str, } #[derive(Serialize)] @@ -288,7 +288,7 @@ impl<'de> Deserialize<'de> for TransactionProgressEvent { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] struct PreparedBlockSigningInput_ { - block_signing_input: Vec, + block_signing_input: String, } let value = serde_json::Value::deserialize(d)?; diff --git a/sdk/src/wallet/operations/block.rs b/sdk/src/wallet/operations/block.rs index 2e2f7835fc..aa27466c5b 100644 --- a/sdk/src/wallet/operations/block.rs +++ b/sdk/src/wallet/operations/block.rs @@ -43,7 +43,7 @@ where #[cfg(feature = "events")] self.emit(WalletEvent::TransactionProgress( - TransactionProgressEvent::PreparedBlockSigningInput(unsigned_block.signing_input()), + TransactionProgressEvent::PreparedBlockSigningInput(prefix_hex::encode(unsigned_block.signing_input())), )) .await; diff --git a/sdk/tests/wallet/events.rs b/sdk/tests/wallet/events.rs index e460a814b7..fd029fde36 100644 --- a/sdk/tests/wallet/events.rs +++ b/sdk/tests/wallet/events.rs @@ -150,7 +150,7 @@ fn wallet_events_serde() { ); assert_serde_eq(WalletEvent::TransactionProgress( - TransactionProgressEvent::PreparedBlockSigningInput(block.signing_input()), + TransactionProgressEvent::PreparedBlockSigningInput(prefix_hex::encode(block.signing_input())), )); } From 92df5352651dd8c830ccdc242b7c9e881a6101e9 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 5 Mar 2024 12:17:42 +0100 Subject: [PATCH 12/13] use HexEncodedString in ts --- bindings/nodejs/lib/types/wallet/event.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/nodejs/lib/types/wallet/event.ts b/bindings/nodejs/lib/types/wallet/event.ts index 551a83a801..b27da01efd 100644 --- a/bindings/nodejs/lib/types/wallet/event.ts +++ b/bindings/nodejs/lib/types/wallet/event.ts @@ -237,12 +237,12 @@ class PreparedTransactionSigningHashProgress extends TransactionProgress { * A 'prepared block input' progress. */ class PreparedBlockSigningInputProgress extends TransactionProgress { - blockSigningInput: string; + blockSigningInput: HexEncodedString; /** * @param signingHash The signing hash of the block. */ - constructor(signingInput: string) { + constructor(signingInput: HexEncodedString) { super(TransactionProgressType.PreparedBlockSigningInput); this.blockSigningInput = signingInput; } From f5d6e1efd589e0792a8e836f2709500c5401726e Mon Sep 17 00:00:00 2001 From: marc2332 Date: Tue, 5 Mar 2024 12:37:29 +0100 Subject: [PATCH 13/13] clean up --- .../wallet/operations/transaction/submit_transaction.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sdk/src/wallet/operations/transaction/submit_transaction.rs b/sdk/src/wallet/operations/transaction/submit_transaction.rs index 416aaa5235..d078fba5c7 100644 --- a/sdk/src/wallet/operations/transaction/submit_transaction.rs +++ b/sdk/src/wallet/operations/transaction/submit_transaction.rs @@ -20,10 +20,7 @@ where ) -> crate::wallet::Result { log::debug!("[TRANSACTION] submit_signed_transaction"); - let block_id = self - .submit_basic_block(Some(Payload::from(payload)), issuer_id, true) - .await?; - - Ok(block_id) + self.submit_basic_block(Some(Payload::from(payload)), issuer_id, true) + .await } }