Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor block signature #995

Merged
merged 130 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
0672c10
Add parents to block
Jul 25, 2023
93559d5
Add burned mana to rust block (#926)
Jul 25, 2023
4495658
merge imports
Jul 25, 2023
5cbc0d3
Split block into basic and validation types
Jul 25, 2023
865fea4
Merge branch '2.0' into feat/parents
thibault-martinez Jul 26, 2023
57a1f63
udep
Jul 26, 2023
d5edb2d
Comment out more tests that will change
Jul 26, 2023
24e295d
oop
Jul 26, 2023
1efdbff
Merge branch 'feat/parents' into feat/split-block
Jul 26, 2023
85145ae
Merge branch '2.0' into feat/split-block
Jul 26, 2023
53f0d3f
no_std
Jul 26, 2023
2a6c41b
Merge branch '2.0' into feat/split-block
Jul 26, 2023
4039714
impl more of BlockWrapper
Jul 26, 2023
2eea8e1
fix client block builder
Jul 26, 2023
8f56690
Merge branch '2.0' into feat/block-wrapper
Jul 26, 2023
e1c9e88
Merge branch '2.0' into feat/split-block
Jul 26, 2023
9bd73a6
Update sdk/src/types/block/protocol.rs
Jul 27, 2023
a040723
Merge branch '2.0' into feat/split-block
Jul 27, 2023
aca7962
PR suggestion
Jul 27, 2023
6535f66
Merge branch 'feat/split-block' into feat/block-wrapper
Jul 27, 2023
de3bb52
no_std
Jul 27, 2023
d1edd92
Merge branch '2.0' into feat/split-block
Jul 27, 2023
5b8905b
Merge branch 'feat/split-block' into feat/block-wrapper
Jul 27, 2023
4598158
Update sdk/src/types/block/validation.rs
Jul 27, 2023
cbad02b
invalid block kind
Jul 27, 2023
fea5428
Merge branch '2.0' into feat/split-block
Jul 28, 2023
0b36227
Merge branch 'feat/split-block' into feat/block-wrapper
Jul 28, 2023
039828c
Refactor types so that `Block` is the highest level enum
Jul 28, 2023
3f6317d
small improvements
Jul 28, 2023
b886793
Merge branch '2.0' into feat/split-block
Jul 28, 2023
2ec174d
Pr suggestions
Jul 28, 2023
55d0365
Merge branch 'feat/split-block' into feat/block-wrapper
Jul 28, 2023
3c096df
Allow warnings and stub in missing values
Jul 31, 2023
1b6d04c
clippy
Jul 31, 2023
b6143e3
properly pack kind and disable clippy CI for now
Jul 31, 2023
5e4c5ba
Implement new block ID
Jul 31, 2023
6f09c41
Merge branch '2.0' into feat/split-block
Jul 31, 2023
3fcc6c1
Merge branch 'feat/split-block' into feat/block-id
Jul 31, 2023
6a1cd28
Rework BlockId into struct
Jul 31, 2023
88ea920
Merge branch '2.0' into feat/split-block
Aug 1, 2023
4dddef8
Merge branch 'feat/split-block' into feat/block-id
Aug 1, 2023
d3f5785
serde with string
Aug 1, 2023
64d70e0
align dto to spec
Aug 1, 2023
b3f98fc
PR suggestions
Aug 1, 2023
5dbdeea
PR suggs
Aug 2, 2023
731425b
Merge branch '2.0' into feat/split-block
Aug 3, 2023
0ada1bb
Merge branch '2.0' into feat/split-block
Aug 3, 2023
859c682
Merge branch 'feat/split-block' into feat/block-id
Aug 3, 2023
6a0f90a
remove pub(crate) protocol params fields
Aug 3, 2023
96213ae
cleanup
Aug 3, 2023
c20bafb
Merge branch '2.0' into feat/split-block
Aug 4, 2023
cd04af6
Merge branch 'feat/split-block' into feat/block-id
Aug 4, 2023
2449a84
Merge branch '2.0' into feat/block-id
Aug 4, 2023
361c659
comments
Aug 4, 2023
be166eb
fix tests
Aug 4, 2023
a36374f
Use Signature for serialized layouts
Aug 7, 2023
b00a99e
more signature fixes
Aug 7, 2023
0b93f85
Refactor block signature
Aug 7, 2023
837ec0e
Merge branch '2.0' into feat/block-id
Aug 7, 2023
ccc8d39
Merge branch 'feat/block-id' into feat/block-signing
Aug 7, 2023
cabe442
Merge branch '2.0' into feat/block-id
Aug 8, 2023
581570e
Fix block id computation, fix return type, reexport BlockHash, clippy…
Thoralf-M Aug 8, 2023
e530218
no_std
Aug 8, 2023
e28243e
Merge branch '2.0' into feat/block-id
Aug 8, 2023
0b3ea14
fix block ID slot index on big endian systems and clippy
Aug 9, 2023
de59085
fix with_slot_index too
Aug 9, 2023
53f57e6
Merge branch 'feat/block-id' into feat/block-signing
Aug 9, 2023
ece2c52
PR suggestion
Aug 9, 2023
3a08211
oof
Aug 10, 2023
d461c5e
add memory layout test
Aug 10, 2023
3d6a977
Merge branch '2.0' into feat/block-id
Aug 10, 2023
092a860
Merge branch 'feat/block-id' into feat/block-signing
Aug 10, 2023
14f039a
Merge branch '2.0' into feat/block-signing
Aug 14, 2023
04cecee
no_std
Aug 14, 2023
be5c004
Merge branch 2.0
Aug 14, 2023
06ec0f0
Merge branch '2.0' into feat/block-signing
Aug 14, 2023
f4bbe75
Merge branch '2.0' into feat/block-signing
Aug 14, 2023
4029dd5
Add ext trait to help block builder signing
Aug 14, 2023
19002f7
Update sdk/src/types/block/core.rs
Thoralf-M Aug 15, 2023
065479a
Merge branch '2.0' into feat/block-signing
Aug 15, 2023
e3fe4d1
Merge branch '2.0' into feat/block-signing
Thoralf-M Aug 16, 2023
d8cd896
Merge branch '2.0' into feat/block-signing
Aug 18, 2023
3f58a5b
Merge branch '2.0' into feat/block-signing
Aug 18, 2023
44f3e10
Merge branch '2.0' into feat/block-signing
Aug 23, 2023
db2f832
Merge branch '2.0' into feat/block-signing
Aug 23, 2023
efd9d3a
Merge branch '2.0' into feat/block-signing
Aug 28, 2023
4510bbe
Fix merge breakage and clippy
Aug 28, 2023
87709ef
Merge branch '2.0' into feat/block-signing
Aug 28, 2023
507725f
Merge branch '2.0' into feat/block-signing
Aug 29, 2023
0220711
Merge branch '2.0' into feat/block-signing
Aug 29, 2023
7962587
Merge branch '2.0' into feat/block-signing
Aug 31, 2023
11f8e50
Merge branch '2.0' into feat/block-signing
Sep 1, 2023
791a188
Merge branch '2.0' into feat/block-signing
Sep 5, 2023
eba0664
Merge branch '2.0' into feat/block-signing
Sep 6, 2023
272daa5
Merge branch '2.0' into feat/block-signing
Sep 6, 2023
ec20b03
Merge branch '2.0' into feat/block-signing
Sep 7, 2023
c10c152
Merge branch '2.0' into feat/block-signing
Sep 7, 2023
c43ad1a
Merge branch '2.0' into feat/block-signing
Sep 8, 2023
ce78b60
Merge branch '2.0' into feat/block-signing
Sep 8, 2023
a2a017e
Merge branch '2.0' into feat/block-signing
Sep 11, 2023
0b92fff
Merge branch '2.0' into feat/block-signing
Sep 11, 2023
72c4b10
Merge branch '2.0' into feat/block-signing
Sep 12, 2023
fa7c996
Merge branch '2.0' into feat/block-signing
Sep 12, 2023
8379fbc
Merge branch '2.0' into feat/block-signing
Sep 13, 2023
02e55dd
Merge branch '2.0' into feat/block-signing
Sep 14, 2023
6c1ab39
Merge branch '2.0' into feat/block-signing
Sep 14, 2023
0ba8d2f
fix nostd
Sep 14, 2023
387cf08
fix tests
Sep 14, 2023
ded48b6
Merge branch '2.0' into feat/block-signing
Sep 15, 2023
fef1fa4
Merge branch '2.0' into feat/block-signing
Sep 15, 2023
9497152
Merge branch '2.0' into feat/block-signing
Sep 18, 2023
e4edaf7
Merge branch '2.0' into feat/block-signing
Sep 19, 2023
4a6b443
Merge branch '2.0' into feat/block-signing
Sep 19, 2023
7a86ade
Merge branch '2.0' into feat/block-signing
Sep 20, 2023
5d6027c
Merge branch '2.0' into feat/block-signing
Sep 27, 2023
fb520e0
Merge branch '2.0' into feat/block-signing
Sep 27, 2023
d2c2887
Merge branch '2.0' into feat/block-signing
Sep 29, 2023
8a530e4
Merge branch '2.0' into feat/block-signing
Oct 2, 2023
7bd62b5
Merge branch '2.0' into feat/block-signing
Oct 3, 2023
ab366b7
remove generics
Oct 3, 2023
5303608
Merge branch '2.0' into feat/block-signing
Oct 4, 2023
e24855c
Nits
thibault-martinez Oct 4, 2023
4dbbd3f
simplify name
Oct 4, 2023
b5d14e2
rename trait
Oct 4, 2023
555450a
use header more
Oct 4, 2023
981a673
move it move it
Oct 4, 2023
5d692af
PR suggestions
Oct 4, 2023
405aab4
no_std
Oct 4, 2023
3be5cfd
Merge branch '2.0' into feat/block-signing
thibault-martinez Oct 5, 2023
64c4550
Nit
thibault-martinez Oct 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[cfg(feature = "mqtt")]
use iota_sdk::client::mqtt::{MqttPayload, Topic};
use iota_sdk::{
client::{request_funds_from_faucet, Client},
client::{request_funds_from_faucet, secret::SecretManager, Client},
types::{
api::core::response::OutputWithMetadataResponse,
block::{
Expand Down Expand Up @@ -173,15 +173,16 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::GetProtocolParameters => Response::ProtocolParameters(client.get_protocol_parameters().await?),
ClientMethod::PostBlockPayload { payload } => {
let block = client
.finish_basic_block_builder(
.build_basic_block::<SecretManager>(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
Some(Payload::try_from_dto_with_params(
payload,
&client.get_protocol_parameters().await?,
)?),
todo!("secret manager"),
todo!("chain"),
)
.await?;

Expand Down
10 changes: 7 additions & 3 deletions sdk/examples/client/block/00_block_no_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
//! cargo run --release --example block_no_payload
//! ```

use iota_sdk::client::{Client, Result};
use crypto::keys::bip44::Bip44;
use iota_sdk::client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -20,14 +21,17 @@ async fn main() -> Result<()> {
// Create a node client.
let client = Client::builder().with_node(&node_url)?.finish().await?;

let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?;

// Create and send the block.
let block = client
.finish_basic_block_builder(
.build_basic_block(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
None,
&secret_manager,
Bip44::new(IOTA_COIN_TYPE),
)
.await?;

Expand Down
10 changes: 7 additions & 3 deletions sdk/examples/client/block/01_block_confirmation_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
//! cargo run --release --example block_confirmation_time
//! ```

use crypto::keys::bip44::Bip44;
use iota_sdk::{
client::{Client, Result},
client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result},
types::api::core::response::BlockState,
};

Expand All @@ -23,14 +24,17 @@ async fn main() -> Result<()> {
// Create a node client.
let client = Client::builder().with_node(&node_url)?.finish().await?;

let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?;

// Create and send a block.
let block = client
.finish_basic_block_builder(
.build_basic_block(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
None,
&secret_manager,
Bip44::new(IOTA_COIN_TYPE),
)
.await?;
let block_id = client.block_id(&block).await?;
Expand Down
10 changes: 7 additions & 3 deletions sdk/examples/client/block/02_block_custom_parents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
//! cargo run --release --example block_custom_parents
//! ```

use iota_sdk::client::{Client, Result};
use crypto::keys::bip44::Bip44;
use iota_sdk::client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -20,18 +21,21 @@ async fn main() -> Result<()> {
// Create a node client.
let client = Client::builder().with_node(&node_url)?.finish().await?;

let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?;

// Use issuance as custom parents.
let issuance = client.get_issuance().await?;
println!("Issuance:\n{issuance:#?}");

// Create and send the block with custom parents.
let block = client
.finish_basic_block_builder(
.build_basic_block(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
Some(issuance.strong_parents()?),
None,
&secret_manager,
Bip44::new(IOTA_COIN_TYPE),
)
.await?;

Expand Down
10 changes: 7 additions & 3 deletions sdk/examples/client/block/03_block_custom_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
//! cargo run --release --example block_custom_payload
//! ```

use crypto::keys::bip44::Bip44;
use iota_sdk::{
client::{Client, Result},
client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result},
types::block::payload::{Payload, TaggedDataPayload},
};

Expand All @@ -23,17 +24,20 @@ async fn main() -> Result<()> {
// Create a node client.
let client = Client::builder().with_node(&node_url)?.finish().await?;

let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?;

// Create a custom payload.
let tagged_data_payload = TaggedDataPayload::new(*b"Your tag", *b"Your data")?;

// Create and send the block with the custom payload.
let block = client
.finish_basic_block_builder(
.build_basic_block(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
Some(Payload::from(tagged_data_payload)),
&secret_manager,
Bip44::new(IOTA_COIN_TYPE),
)
.await?;

Expand Down
10 changes: 7 additions & 3 deletions sdk/examples/client/block/04_block_tagged_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
//! cargo run --release --example block_tagged_data [TAG] [DATA]
//! ```

use crypto::keys::bip44::Bip44;
use iota_sdk::{
client::{Client, Result},
client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result},
types::block::payload::{Payload, TaggedDataPayload},
};

Expand All @@ -23,11 +24,12 @@ async fn main() -> Result<()> {
// Create a node client.
let client = Client::builder().with_node(&node_url)?.finish().await?;

let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?;

// Create and send the block with tag and data.
let block = client
.finish_basic_block_builder(
.build_basic_block(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
Some(Payload::TaggedData(Box::new(
Expand All @@ -43,6 +45,8 @@ async fn main() -> Result<()> {
)
.unwrap(),
))),
&secret_manager,
Bip44::new(IOTA_COIN_TYPE),
)
.await?;

Expand Down
10 changes: 7 additions & 3 deletions sdk/examples/client/node_api_core/04_post_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
//! cargo run --release --example node_api_core_post_block [NODE URL]
//! ```

use iota_sdk::client::{Client, Result};
use crypto::keys::bip44::Bip44;
use iota_sdk::client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -23,14 +24,17 @@ async fn main() -> Result<()> {
// Create a node client.
let client = Client::builder().with_node(&node_url)?.finish().await?;

let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?;

// Create the block.
let block = client
.finish_basic_block_builder(
.build_basic_block(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
None,
&secret_manager,
Bip44::new(IOTA_COIN_TYPE),
)
.await?;
// Post the block.
Expand Down
10 changes: 7 additions & 3 deletions sdk/examples/client/node_api_core/05_post_block_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
//! cargo run --release --example node_api_core_post_block_raw [NODE URL]
//! ```

use iota_sdk::client::{Client, Result};
use crypto::keys::bip44::Bip44;
use iota_sdk::client::{constants::IOTA_COIN_TYPE, secret::SecretManager, Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -23,14 +24,17 @@ async fn main() -> Result<()> {
// Create a node client.
let client = Client::builder().with_node(&node_url)?.finish().await?;

let secret_manager = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?;

// Create the block.
let block = client
.finish_basic_block_builder(
.build_basic_block(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
None,
&secret_manager,
Bip44::new(IOTA_COIN_TYPE),
)
.await?;
// Post the block as raw bytes.
Expand Down
48 changes: 29 additions & 19 deletions sdk/src/client/api/block_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@
pub mod input_selection;
pub mod transaction;

use crypto::keys::bip44::Bip44;

pub use self::transaction::verify_semantic;
use crate::{
client::{ClientInner, Result},
client::{
secret::{SecretManage, SignBlock},
ClientInner, Result,
},
types::block::{
core::{basic, Block, BlockWrapper},
core::{basic, BlockHeader, BlockWrapper},
payload::Payload,
signature::Ed25519Signature,
IssuerId,
Block, IssuerId,
},
};

impl ClientInner {
pub async fn finish_basic_block_builder(
pub async fn build_basic_block<S: SecretManage>(
&self,
issuer_id: IssuerId,
signature: Ed25519Signature,
issuing_time: Option<u64>,
strong_parents: Option<basic::StrongParents>,
payload: Option<Payload>,
) -> Result<BlockWrapper> {
secret_manager: &S,
chain: Bip44,
) -> Result<BlockWrapper>
where
crate::client::Error: From<S::Error>,
{
let issuance = self.get_issuance().await?;
let strong_parents = strong_parents.unwrap_or(issuance.strong_parents()?);

Expand All @@ -40,22 +48,24 @@ impl ClientInner {
issuing_time
});

let protocol_parameters = self.get_protocol_parameters().await?;
let protocol_params = self.get_protocol_parameters().await?;

Ok(BlockWrapper::new(
protocol_parameters.version(),
protocol_parameters.network_id(),
issuing_time,
issuance.commitment.id(),
issuance.latest_finalized_slot,
issuer_id,
// TODO correct value for max_burned_mana
Block::build_basic(strong_parents, 0)
Ok(BlockWrapper::build(
BlockHeader::new(
protocol_params.version(),
protocol_params.network_id(),
issuing_time,
issuance.commitment.id(),
issuance.latest_finalized_slot,
issuer_id,
),
Block::build_basic(strong_parents, 0) // TODO: burned mana calculation
.with_weak_parents(issuance.weak_parents()?)
.with_shallow_like_parents(issuance.shallow_like_parents()?)
.with_payload(payload)
.finish_block()?,
signature,
))
)
.sign_ed25519(secret_manager, chain)
.await?)
}
}
28 changes: 28 additions & 0 deletions sdk/src/client/secret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ use crate::{
},
types::block::{
address::{Address, Ed25519Address},
core::BlockWrapperBuilder,
output::Output,
payload::{transaction::TransactionEssence, TransactionPayload},
signature::{Ed25519Signature, Signature},
unlock::{AccountUnlock, NftUnlock, ReferenceUnlock, SignatureUnlock, Unlock, Unlocks},
BlockWrapper,
},
};

Expand Down Expand Up @@ -602,3 +604,29 @@ where

Ok(tx_payload)
}

#[async_trait]
pub trait SignBlock {
async fn sign_ed25519<S: SecretManage>(
self,
secret_manager: &S,
chain: Bip44,
) -> crate::client::Result<BlockWrapper>
where
crate::client::Error: From<S::Error>;
}

#[async_trait]
impl SignBlock for BlockWrapperBuilder {
async fn sign_ed25519<S: SecretManage>(
self,
secret_manager: &S,
chain: Bip44,
) -> crate::client::Result<BlockWrapper>
where
crate::client::Error: From<S::Error>,
{
let msg = self.signing_input();
Ok(self.finish(secret_manager.sign_ed25519(&msg, chain).await?)?)
}
}
12 changes: 12 additions & 0 deletions sdk/src/types/block/core/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ impl BasicBlockBuilder {
}
}

impl From<BasicBlock> for BasicBlockBuilder {
fn from(value: BasicBlock) -> Self {
Self {
strong_parents: value.strong_parents,
weak_parents: value.weak_parents,
shallow_like_parents: value.shallow_like_parents,
payload: value.payload,
max_burned_mana: value.max_burned_mana,
}
}
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct BasicBlock {
/// Blocks that are strongly directly approved.
Expand Down
Loading
Loading