Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ bcs = "0.1.6"
cfg-if = "1.0.0"
fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "69d496c71fb37e3d22fe85e5bbfd4256d61422b9", package = "fastcrypto" }
hyper = "1"
iota-sdk = { git = "https://github.com/iotaledger/iota.git", package = "iota-sdk", tag = "v1.20.1" }
iota-sdk = { git = "https://github.com/iotaledger/iota.git", package = "iota-sdk", rev = "96196f0da231883ec69cda04892c600ef6afa982" }
iota-sdk-types = { git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "e19c78a1bee17e0bf85fcd5b16a2f080cef26274", features = ["hash", "serde", "schemars"] }
move-binary-format = { git = "https://github.com/iotaledger/iota.git", package = "move-binary-format", tag = "v1.20.1" }
move-core-types = { git = "https://github.com/iotaledger/iota.git", package = "move-core-types", tag = "v1.20.1" }
move-bytecode-utils = { git = "https://github.com/iotaledger/iota.git", package = "move-bytecode-utils", tag = "v1.20.1" }
move-binary-format = { git = "https://github.com/iotaledger/iota.git", package = "move-binary-format", rev = "96196f0da231883ec69cda04892c600ef6afa982" }
move-core-types = { git = "https://github.com/iotaledger/iota.git", package = "move-core-types", rev = "96196f0da231883ec69cda04892c600ef6afa982" }
move-bytecode-utils = { git = "https://github.com/iotaledger/iota.git", package = "move-bytecode-utils", rev = "96196f0da231883ec69cda04892c600ef6afa982" }
phf = { version = "0.11.2", features = ["macros"] }
secret-storage = { git = "https://github.com/iotaledger/secret-storage.git", default-features = false, tag = "v0.3.0" }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive", "rc"] }
Expand Down
16 changes: 8 additions & 8 deletions bindings/wasm/iota_interaction_ts/package-lock.json

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

2 changes: 1 addition & 1 deletion bindings/wasm/iota_interaction_ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"wasm-opt": "^1.4.0"
},
"peerDependencies": {
"@iota/iota-sdk": "^1.11.0"
"@iota/iota-sdk": "^1.13.0"
},
"engines": {
"node": ">=20"
Expand Down
4 changes: 2 additions & 2 deletions iota_interaction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ thiserror.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
hyper.workspace = true
iota-sdk = { git = "https://github.com/iotaledger/iota.git", package = "iota-sdk", tag = "v1.20.1" }
move-core-types = { git = "https://github.com/iotaledger/iota.git", package = "move-core-types", tag = "v1.20.1" }
iota-sdk = { git = "https://github.com/iotaledger/iota.git", package = "iota-sdk", rev = "96196f0da231883ec69cda04892c600ef6afa982" }
move-core-types = { git = "https://github.com/iotaledger/iota.git", package = "move-core-types", rev = "96196f0da231883ec69cda04892c600ef6afa982" }
tokio = { workspace = true, optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
15 changes: 14 additions & 1 deletion iota_interaction/src/sdk_types/iota_types/auth_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,21 @@ pub struct AuthContext {
tx_inputs: Vec<MoveCallArg>,
/// The authentication commands to be executed sequentially.
tx_commands: Vec<MoveCommand>,
/// The BCS-serialized `TransactionData` bytes.
tx_data_bytes: Vec<u8>,
}

impl AuthContext {
pub fn new_from_components(
auth_digest: MoveAuthenticatorDigest,
ptb: &ProgrammableTransaction,
tx_data_bytes: Vec<u8>,
) -> Self {
Self {
auth_digest,
tx_inputs: ptb.inputs.iter().map(MoveCallArg::from).collect(),
tx_commands: ptb.commands.iter().map(MoveCommand::from).collect(),
tx_data_bytes,
}
}

Expand All @@ -72,6 +76,7 @@ impl AuthContext {
auth_digest: MoveAuthenticatorDigest::default(),
tx_inputs: Vec::new(),
tx_commands: Vec::new(),
tx_data_bytes: Vec::new(),
}
}

Expand All @@ -87,6 +92,10 @@ impl AuthContext {
&self.tx_commands
}

pub fn tx_data_bytes(&self) -> &Vec<u8> {
&self.tx_data_bytes
}

pub fn to_bcs_bytes(&self) -> Vec<u8> {
bcs::to_bytes(&self).unwrap()
}
Expand Down Expand Up @@ -136,10 +145,12 @@ impl AuthContext {
auth_digest: MoveAuthenticatorDigest,
tx_inputs: Vec<MoveCallArg>,
tx_commands: Vec<MoveCommand>,
tx_data_bytes: Vec<u8>,
) {
self.auth_digest = auth_digest;
self.tx_inputs = tx_inputs;
self.tx_commands = tx_commands;
self.tx_data_bytes = tx_data_bytes;
}
}

Expand Down Expand Up @@ -197,7 +208,8 @@ mod tests {
}))],
};

let ctx = AuthContext::new_from_components(MoveAuthenticatorDigest::default(), &ptb);
let ctx =
AuthContext::new_from_components(MoveAuthenticatorDigest::default(), &ptb, vec![]);

assert_eq!(ctx.tx_inputs().len(), 1);
assert_eq!(ctx.tx_commands().len(), 1);
Expand Down Expand Up @@ -231,6 +243,7 @@ mod tests {
MoveAuthenticatorDigest::default(),
vec![MoveCallArg::Pure(vec![1])],
vec![],
vec![],
);
let non_empty_bytes = ctx.to_bcs_bytes();

Expand Down
86 changes: 82 additions & 4 deletions iota_interaction/src/sdk_types/iota_types/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ use std::str::FromStr;
use std::string::String;
use std::vec::Vec;

use anyhow::anyhow;
use anyhow::{anyhow, bail};
use fastcrypto::encoding::{decode_bytes_hex, Encoding, Hex};
use fastcrypto::hash::HashFunction;
use rand::Rng;
use schemars::JsonSchema;
use serde::ser::Error;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_with::{DeserializeAs, SerializeAs, serde_as};
use Result;

use iota_sdk_types::crypto::HashingIntentScope;

use crate::move_core_types::account_address::AccountAddress;
use crate::move_core_types::identifier::IdentStr;
use crate::move_core_types::language_storage::{ModuleId, StructTag, TypeTag};
Expand All @@ -35,7 +37,7 @@ use super::dynamic_field::DynamicFieldInfo;
use super::error::{IotaError, IotaResult};
use super::gas_coin::{GasCoin, GAS};
use super::governance::{StakedIota, STAKED_IOTA_STRUCT_NAME, STAKING_POOL_MODULE_NAME};
use super::iota_serde::{to_iota_struct_tag_string, HexAccountAddress, Readable};
use super::iota_serde::{to_custom_deser_error, to_iota_struct_tag_string, Readable};
use super::object::Owner;
use super::stardust::output::Nft;
use super::timelock::timelock::{self, TimeLock};
Expand Down Expand Up @@ -691,6 +693,55 @@ impl ObjectID {
}
}

/// Create an ObjectID from `TransactionDigest` and `creation_num`.
/// Caller is responsible for ensuring that `creation_num` is fresh
pub fn derive_id(digest: TransactionDigest, creation_num: u64) -> Self {
let mut hasher = DefaultHash::default();
hasher.update([HashingIntentScope::RegularObjectId as u8]);
hasher.update(digest);
hasher.update(creation_num.to_le_bytes());
let hash = hasher.finalize();

// truncate into an ObjectID.
// OK to access slice because digest should never be shorter than
// ObjectID::LENGTH.
ObjectID::try_from(&hash.as_ref()[0..ObjectID::LENGTH]).unwrap()
}

/// Increment the ObjectID by one, assuming the ObjectID hex is a number
/// represented as an array of bytes
pub fn next_increment(&self) -> Result<ObjectID, anyhow::Error> {
let mut prev_val = self.to_vec();
let mx = [0xFF; Self::LENGTH];

if prev_val == mx {
bail!("Increment will cause overflow");
}

// This logic increments the integer representation of an ObjectID u8 array
for idx in (0..Self::LENGTH).rev() {
if prev_val[idx] == 0xFF {
prev_val[idx] = 0;
} else {
prev_val[idx] += 1;
break;
};
}
ObjectID::try_from(prev_val.clone()).map_err(|w| w.into())
}

/// Create `count` object IDs starting with one at `offset`
pub fn in_range(offset: ObjectID, count: u64) -> Result<Vec<ObjectID>, anyhow::Error> {
let mut ret = Vec::new();
let mut prev = offset;
for o in 0..count {
if o != 0 {
prev = prev.next_increment()?;
}
ret.push(prev);
}
Ok(ret)
}

/// Return the full hex string with 0x prefix without removing trailing 0s.
/// Prefer this over [fn to_hex_literal] if the string needs to be fully
Expand Down Expand Up @@ -797,6 +848,33 @@ impl From<IotaAddress> for AccountAddress {
}
}

/// Hex serde for AccountAddress
struct HexAccountAddress;

impl SerializeAs<AccountAddress> for HexAccountAddress {
fn serialize_as<S>(value: &AccountAddress, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
Hex::serialize_as(value, serializer)
}
}

impl<'de> DeserializeAs<'de, AccountAddress> for HexAccountAddress {
fn deserialize_as<D>(deserializer: D) -> Result<AccountAddress, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
if s.starts_with("0x") {
AccountAddress::from_hex_literal(&s)
} else {
AccountAddress::from_hex(&s)
}
.map_err(to_custom_deser_error::<'de, D, _>)
}
}

impl fmt::Display for MoveObjectType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
let s: StructTag = self.clone().into();
Expand Down
25 changes: 25 additions & 0 deletions iota_interaction/src/sdk_types/iota_types/digests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ impl fmt::UpperHex for CheckpointContentsDigest {
}
}

/// A transaction will have a (unique) digest.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema)]
pub struct TransactionDigest(Digest);

Expand Down Expand Up @@ -261,6 +262,30 @@ impl TransactionDigest {
}
}

impl AsRef<[u8]> for TransactionDigest {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}

impl AsRef<[u8; 32]> for TransactionDigest {
fn as_ref(&self) -> &[u8; 32] {
self.0.as_ref()
}
}

impl From<TransactionDigest> for [u8; 32] {
fn from(digest: TransactionDigest) -> Self {
digest.into_inner()
}
}

impl From<[u8; 32]> for TransactionDigest {
fn from(digest: [u8; 32]) -> Self {
Self::new(digest)
}
}

impl fmt::Display for TransactionDigest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
Expand Down
35 changes: 2 additions & 33 deletions iota_interaction/src/sdk_types/iota_types/iota_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::result::Result::Ok;
use std::str::FromStr;
use std::string::{String, ToString};

use fastcrypto::encoding::Hex;
use schemars::JsonSchema;
use serde::de::{Deserializer, Error};
use serde::ser::{Error as SerError, Serializer};
Expand Down Expand Up @@ -91,7 +90,7 @@ impl From<u64> for ProtocolVersion {
// -----------------------------------------------------------------------------------------

#[inline]
fn to_custom_error<'de, D, E>(e: E) -> D::Error
pub(crate) fn to_custom_deser_error<'de, D, E>(e: E) -> D::Error
where
E: Debug,
D: Deserializer<'de>,
Expand Down Expand Up @@ -153,37 +152,6 @@ impl<'de, R, H, T> DeserializeAs<'de, T> for Readable<H, R>
}
}

/// custom serde for AccountAddress
pub struct HexAccountAddress;

impl SerializeAs<AccountAddress> for HexAccountAddress {
fn serialize_as<S>(value: &AccountAddress, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
Hex::serialize_as(value, serializer)
}
}

impl<'de> DeserializeAs<'de, AccountAddress> for HexAccountAddress {
fn deserialize_as<D>(deserializer: D) -> Result<AccountAddress, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
if s.starts_with("0x") {
AccountAddress::from_hex_literal(&s)
} else {
AccountAddress::from_hex(&s)
}
.map_err(to_custom_error::<'de, D, _>)
}
}

/// Serializes a bitmap according to the roaring bitmap on-disk standard.
/// <https://github.com/RoaringBitmap/RoaringFormatSpec>
pub struct IotaBitmap;

pub struct IotaStructTag;

impl SerializeAs<StructTag> for IotaStructTag {
Expand Down Expand Up @@ -398,3 +366,4 @@ impl<'de> DeserializeAs<'de, ProtocolVersion> for AsProtocolVersion {
Ok(ProtocolVersion::from(*b))
}
}

4 changes: 2 additions & 2 deletions iota_interaction/src/sdk_types/iota_types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use crate::move_core_types::language_storage::TypeTag;
use super::base_types::{EpochId, IotaAddress, ObjectID, ObjectRef, SequenceNumber};
use super::error::{UserInputError, UserInputResult};
use super::{
IOTA_AUTHENTICATOR_STATE_OBJECT_ID, IOTA_AUTHENTICATOR_STATE_OBJECT_SHARED_VERSION, IOTA_CLOCK_OBJECT_ID,
IOTA_CLOCK_OBJECT_SHARED_VERSION, IOTA_SYSTEM_STATE_OBJECT_ID, IOTA_SYSTEM_STATE_OBJECT_SHARED_VERSION,
IOTA_CLOCK_OBJECT_ID, IOTA_CLOCK_OBJECT_SHARED_VERSION, IOTA_SYSTEM_STATE_OBJECT_ID,
IOTA_SYSTEM_STATE_OBJECT_SHARED_VERSION,
};

pub const TEST_ONLY_GAS_UNIT_FOR_TRANSFER: u64 = 10_000;
Expand Down
2 changes: 1 addition & 1 deletion product_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async-trait.workspace = true
bcs = { workspace = true, optional = true }
cfg-if.workspace = true
fastcrypto = { workspace = true, optional = true }
iota-keys = { package = "iota-keys", git = "https://github.com/iotaledger/iota.git", tag = "v1.20.1", optional = true }
iota-keys = { package = "iota-keys", git = "https://github.com/iotaledger/iota.git", rev = "96196f0da231883ec69cda04892c600ef6afa982", optional = true }
iota-sdk-types = { workspace = true, features = ["serde"] }
itertools = { version = "0.13.0", optional = true }
lazy_static = { version = "1.5.0", optional = true }
Expand Down
Loading