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

Add atomic module to bee-transaction #238

Merged
merged 76 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
24cb600
Initial draft
Jul 30, 2020
0bfe5b9
Add syntactical validation
Aug 4, 2020
a5ba0c7
Add lexicographical order validation
Aug 4, 2020
ced06f9
Add signed transaction builder
Aug 5, 2020
d271e18
Derive default trait instead of new
Aug 6, 2020
7338363
Update type of WotsAddress
Aug 7, 2020
b35ea0e
Add bincode serialization for Input
Aug 10, 2020
281f8b9
Add serialization for Output
Aug 10, 2020
48c6584
Fix input field name
Aug 10, 2020
50448a2
Add signing process when building tx payload
Aug 11, 2020
3a5bfa5
Add wots support
Aug 11, 2020
9119f50
Update changes from bee-signing
Aug 19, 2020
834edf8
Add sematic verification for ed25 signature
Aug 19, 2020
5b642a2
Simplifiy Signature Unlock
Aug 19, 2020
121611c
Update error type using thiserror
Aug 19, 2020
908e4ba
Box payload enum varients
Aug 19, 2020
d1bbc27
Derive Clone for all objects
Sep 8, 2020
1a34cd8
Fix index type in legacy bundle
Sep 8, 2020
5586029
Update index to BIP32Path
Sep 9, 2020
f1cd601
Add prelude module
Sep 12, 2020
94644dd
Update changes from BIP32Path
Sep 15, 2020
1bf21f0
Update changes from slip10 v0.4
Sep 15, 2020
9888dfa
Add Serialize trait to UnsignedTransaction
Sep 16, 2020
c00678e
fix(deps) use bee `dev` branch
lucasfernog Sep 10, 2020
96dc0a4
Derive Debug, Serialize traits to all payloads
Sep 17, 2020
10aaa54
Add Serde support to entire message
Sep 17, 2020
2eac007
Add Bech32 support
Sep 22, 2020
8ee9647
Nits
thibault-martinez Sep 23, 2020
ac95484
Avoid name repetition
thibault-martinez Sep 23, 2020
8f3dd38
Impl From instead of from_ methods
thibault-martinez Sep 23, 2020
df6c7c0
Add From impls and fix tests
thibault-martinez Sep 23, 2020
7fe5c39
Use Seed enum from bee-signing-ext instead
Sep 24, 2020
4a0a3c1
Update output amount to NonZeroU64
Sep 28, 2020
ada32e5
Add MessageBuilder
Sep 28, 2020
72a7ef1
Add MessageBuilder to prelude
Sep 28, 2020
77d5793
Update input path to BIP32Path
Sep 28, 2020
fbcc4bb
Update Seed paramters as reference instead
Sep 28, 2020
b829376
Update tx payload builder signature
Sep 28, 2020
6efaf66
Provide message getters and fix typo
Sep 29, 2020
13f5c5c
Add no_std support
Sep 30, 2020
c045e57
HASH_LENGTH
thibault-martinez Oct 1, 2020
b2fbb55
TAG_LENGTH
thibault-martinez Oct 1, 2020
3c24edc
trunk/branch -> parent1/parent2
thibault-martinez Oct 1, 2020
6435b5c
Temporarily remove no_std
thibault-martinez Oct 1, 2020
7fa09ee
Remove Indexation pub field
thibault-martinez Oct 1, 2020
6d66e36
Remove Reference pub field
thibault-martinez Oct 1, 2020
13c9181
Remove UnsignedData pub field
thibault-martinez Oct 1, 2020
1210b08
Fix compilation
thibault-martinez Oct 1, 2020
78679e1
Remove confusing Input new function
thibault-martinez Oct 1, 2020
3de8b02
Remove confusing Output new function
thibault-martinez Oct 1, 2020
e00eee9
Nonce returns a copy
thibault-martinez Oct 2, 2020
a75cd8d
Remove convenient methods
thibault-martinez Oct 2, 2020
000bc30
Remove Hash inner pub
thibault-martinez Oct 2, 2020
2812f95
Address module
thibault-martinez Oct 2, 2020
f068012
Remove SerDe
thibault-martinez Oct 2, 2020
9607992
Update some vec types to box
Oct 5, 2020
999b942
Update bound check method
Oct 5, 2020
e4b4164
Warnings
thibault-martinez Oct 5, 2020
a4a8ac3
Constant ranges for input/output bounds
thibault-martinez Oct 5, 2020
d61a66d
Remove Ord/PartialOrd derivation
thibault-martinez Oct 5, 2020
18d78d7
Remove unnecessary traits derivation
thibault-martinez Oct 5, 2020
3d2a938
Remove Milestone pub fields
thibault-martinez Oct 6, 2020
3c4f91c
Rename to SignatureSingleDepositOutput
thibault-martinez Oct 6, 2020
de7fe27
Signature module
thibault-martinez Oct 6, 2020
2e5575c
Clean Message and its Builder
thibault-martinez Oct 6, 2020
1e37c19
Remove SignedData pub fields
thibault-martinez Oct 6, 2020
793d43e
Change payload order to respect RFC
thibault-martinez Oct 6, 2020
1fa87ea
UnsignedTransactionBuilder
thibault-martinez Oct 6, 2020
172fb9d
To Bech32 clean
thibault-martinez Oct 6, 2020
ecd9b75
Safety check on Reference
thibault-martinez Oct 6, 2020
f260c16
UTXO safety check
thibault-martinez Oct 6, 2020
e36c30c
Ed25519Address clean
thibault-martinez Oct 6, 2020
e5d653a
WOTS safety checks
thibault-martinez Oct 6, 2020
138d099
Remove Ed25519Signature pub fields
thibault-martinez Oct 6, 2020
7979cec
Make everything no_std again
thibault-martinez Oct 6, 2020
4336496
Fmt
thibault-martinez Oct 6, 2020
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
8 changes: 8 additions & 0 deletions bee-transaction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ homepage = "https://www.iota.org"
[dependencies]
bee-crypto = { git = "https://github.com/iotaledger/bee.git", branch = "dev" }
bee-signing = { git = "https://github.com/iotaledger/bee.git", branch = "dev" }
bee-signing-ext = { git ="https://github.com/wusyong/bee-p", branch = "sign-ext" }
bee-ternary = { git = "https://github.com/iotaledger/bee.git", branch = "dev", features = ["serde1"] }

bech32 = "0.7.2"
bytemuck = "1.2.0"
thiserror = "1.0"

[dev-dependencies]
hex-literal = "0.3.1"
27 changes: 27 additions & 0 deletions bee-transaction/src/atomic/hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020 IOTA Stiftung
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

pub const HASH_LENGTH: usize = 32;

#[derive(Debug, Eq, PartialEq)]
pub struct Hash([u8; HASH_LENGTH]);

impl From<[u8; HASH_LENGTH]> for Hash {
fn from(bytes: [u8; HASH_LENGTH]) -> Self {
Self(bytes)
}
}

impl Hash {
pub fn new(bytes: [u8; HASH_LENGTH]) -> Self {
bytes.into()
}
}
95 changes: 95 additions & 0 deletions bee-transaction/src/atomic/message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2020 IOTA Stiftung
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

use crate::{
atomic::{payload::Payload, Error, Hash},
Vertex,
};

#[derive(Debug)]
pub struct Message {
parent1: Hash,
parent2: Hash,
payload: Payload,
nonce: u64,
}

impl Message {
pub fn builder() -> MessageBuilder {
MessageBuilder::new()
}

pub fn parent1(&self) -> &Hash {
&self.parent1
}

pub fn parent2(&self) -> &Hash {
&self.parent2
}

pub fn payload(&self) -> &Payload {
&self.payload
}

pub fn nonce(&self) -> u64 {
self.nonce
}
}

impl Vertex for Message {
type Hash = Hash;

fn trunk(&self) -> &Self::Hash {
&self.parent1
}

fn branch(&self) -> &Self::Hash {
&self.parent2
}
}

#[derive(Debug, Default)]
pub struct MessageBuilder {
parent1: Option<Hash>,
parent2: Option<Hash>,
payload: Option<Payload>,
}

impl MessageBuilder {
pub fn new() -> Self {
Default::default()
}

pub fn parent1(mut self, parent1: Hash) -> Self {
self.parent1 = Some(parent1);
self
}

pub fn parent2(mut self, parent2: Hash) -> Self {
self.parent2 = Some(parent2);
self
}

pub fn payload(mut self, payload: Payload) -> Self {
self.payload = Some(payload);
self
}

pub fn build(self) -> Result<Message, Error> {
Ok(Message {
parent1: self.parent1.ok_or(Error::MissingField("parent1"))?,
parent2: self.parent2.ok_or(Error::MissingField("parent2"))?,
payload: self.payload.ok_or(Error::MissingField("payload"))?,
// TODO PoW
nonce: 0,
})
}
}
72 changes: 72 additions & 0 deletions bee-transaction/src/atomic/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2020 IOTA Stiftung
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

mod hash;
mod message;

pub mod payload;

pub use hash::{Hash, HASH_LENGTH};
pub use message::{Message, MessageBuilder};

use core::fmt;

#[derive(Debug)]
pub enum Error {
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
AmountError,
CountError,
NoInput,
NoOutput,
DuplicateError,
// TODO add index
InvalidIndex,
InvalidAddress,
InvalidSignature,
OrderError,
HashError,
PathError,
MissingField(&'static str),
SigningError(bee_signing_ext::binary::Error),
SignatureError(bee_signing_ext::SignatureError),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::AmountError => write!(f, "Invalid amount provided."),
Error::CountError => write!(f, "Invalid count number provided."),
Error::NoInput => write!(f, "No input provided."),
Error::NoOutput => write!(f, "No output provided."),
Error::DuplicateError => write!(f, "The object in the set must be unique."),
Error::InvalidIndex => write!(f, "Invalid index provided."),
Error::InvalidAddress => write!(f, "Invalid address provided."),
Error::InvalidSignature => write!(f, "Invalid signature provided."),
Error::OrderError => write!(f, "The vector is not sorted by lexicographical order."),
Error::HashError => write!(f, "The format of provided hash is not correct."),
Error::PathError => write!(f, "The format of provided BIP32 path is not correct."),
Error::MissingField(s) => write!(f, "Missing required field: {}.", s),
Error::SigningError(e) => write!(f, "{}", e),
Error::SignatureError(e) => write!(f, "{}", e),
}
}
}

impl From<bee_signing_ext::binary::Error> for Error {
fn from(error: bee_signing_ext::binary::Error) -> Self {
Error::SigningError(error)
}
}

impl From<bee_signing_ext::SignatureError> for Error {
fn from(error: bee_signing_ext::SignatureError) -> Self {
Error::SignatureError(error)
}
}
27 changes: 27 additions & 0 deletions bee-transaction/src/atomic/payload/indexation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020 IOTA Stiftung
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

pub const TAG_LENGTH: usize = 16;

#[derive(Debug)]
pub struct Indexation([u8; TAG_LENGTH]);

impl From<[u8; TAG_LENGTH]> for Indexation {
fn from(bytes: [u8; TAG_LENGTH]) -> Self {
Self(bytes)
}
}

impl Indexation {
pub fn new(bytes: [u8; TAG_LENGTH]) -> Self {
bytes.into()
}
}
33 changes: 33 additions & 0 deletions bee-transaction/src/atomic/payload/milestone.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2020 IOTA Stiftung
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

use alloc::{boxed::Box, vec::Vec};

#[derive(Debug)]
pub struct Milestone {
index: u32,
timestamp: u64,
// TODO length is 64, change to array when std::array::LengthAtMost32 disappears.
merkle_proof: Box<[u8]>,
// TODO length is 64, change to array when std::array::LengthAtMost32 disappears.
signatures: Vec<Box<[u8]>>,
}

impl Milestone {
pub fn new(index: u32, timestamp: u64, merkle_proof: Box<[u8]>, signatures: Vec<Box<[u8]>>) -> Self {
Self {
index,
timestamp,
merkle_proof,
signatures,
}
}
}
34 changes: 34 additions & 0 deletions bee-transaction/src/atomic/payload/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020 IOTA Stiftung
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

mod indexation;
mod milestone;
mod signed_data;
mod unsigned_data;

pub mod signed_transaction;

pub use indexation::{Indexation, TAG_LENGTH};
pub use milestone::Milestone;
pub use signed_data::SignedData;
pub use signed_transaction::SignedTransaction;
pub use unsigned_data::UnsignedData;

use alloc::boxed::Box;

#[derive(Debug)]
pub enum Payload {
SignedTransaction(Box<SignedTransaction>),
Milestone(Box<Milestone>),
Indexation(Box<Indexation>),
UnsignedData(Box<UnsignedData>),
SignedData(Box<SignedData>),
}
32 changes: 32 additions & 0 deletions bee-transaction/src/atomic/payload/signed_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2020 IOTA Stiftung
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

use alloc::{boxed::Box, vec::Vec};

#[derive(Debug)]
pub struct SignedData {
data: Vec<u8>,
// TODO Hash type ?
public_key: [u8; 32],
// TODO change back to array with length 64.
// TODO what kind of sig ?
signature: Box<[u8]>,
}

impl SignedData {
pub fn new(data: Vec<u8>, public_key: [u8; 32], signature: Box<[u8]>) -> Self {
Self {
data,
public_key,
signature,
}
}
}
16 changes: 16 additions & 0 deletions bee-transaction/src/atomic/payload/signed_transaction/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2020 IOTA Stiftung
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

use core::ops::Range;

const INPUT_OUTPUT_COUNT_MAX: usize = 127;
pub(crate) const INPUT_OUTPUT_COUNT_RANGE: Range<usize> = 1..INPUT_OUTPUT_COUNT_MAX + 1;
pub(crate) const INPUT_OUTPUT_INDEX_RANGE: Range<u8> = 0..INPUT_OUTPUT_COUNT_MAX as u8;
25 changes: 25 additions & 0 deletions bee-transaction/src/atomic/payload/signed_transaction/input/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2020 IOTA Stiftung
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

mod utxo;

pub use utxo::UTXOInput;

#[derive(Debug, Eq, PartialEq)]
pub enum Input {
UTXO(UTXOInput),
}

impl From<UTXOInput> for Input {
fn from(input: UTXOInput) -> Self {
Self::UTXO(input)
}
}
Loading