Skip to content

Commit eb08514

Browse files
committed
Merge branch 'main' into feat/tf-compoenents-dev
2 parents c010c8e + 1d3480d commit eb08514

14 files changed

Lines changed: 163 additions & 83 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ bcs = "0.1.6"
2222
cfg-if = "1.0.0"
2323
fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "69d496c71fb37e3d22fe85e5bbfd4256d61422b9", package = "fastcrypto" }
2424
hyper = "1"
25-
iota-sdk = { git = "https://github.com/iotaledger/iota.git", package = "iota-sdk", tag = "v1.19.1" }
26-
iota-sdk-types = { git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "d8cdab6ab3f2fd9ba8059ba56e80ba950badc88d", features = ["hash", "serde", "schemars"] }
27-
move-binary-format = { git = "https://github.com/iotaledger/iota.git", package = "move-binary-format", tag = "v1.19.1" }
28-
move-core-types = { git = "https://github.com/iotaledger/iota.git", package = "move-core-types", tag = "v1.19.1" }
29-
move-bytecode-utils = { git = "https://github.com/iotaledger/iota.git", package = "move-bytecode-utils", tag = "v1.19.1" }
25+
iota-sdk = { git = "https://github.com/iotaledger/iota.git", package = "iota-sdk", rev = "96196f0da231883ec69cda04892c600ef6afa982" }
26+
iota-sdk-types = { git = "https://github.com/iotaledger/iota-rust-sdk.git", rev = "e19c78a1bee17e0bf85fcd5b16a2f080cef26274", features = ["hash", "serde", "schemars"] }
27+
move-binary-format = { git = "https://github.com/iotaledger/iota.git", package = "move-binary-format", rev = "96196f0da231883ec69cda04892c600ef6afa982" }
28+
move-core-types = { git = "https://github.com/iotaledger/iota.git", package = "move-core-types", rev = "96196f0da231883ec69cda04892c600ef6afa982" }
29+
move-bytecode-utils = { git = "https://github.com/iotaledger/iota.git", package = "move-bytecode-utils", rev = "96196f0da231883ec69cda04892c600ef6afa982" }
3030
phf = { version = "0.11.2", features = ["macros"] }
3131
secret-storage = { git = "https://github.com/iotaledger/secret-storage.git", default-features = false, tag = "v0.3.0" }
3232
serde = { version = "1.0", default-features = false, features = ["alloc", "derive", "rc"] }

bindings/wasm/iota_interaction_ts/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "iota_interaction_ts"
3-
version = "0.8.14"
3+
version = "0.8.16"
44
authors.workspace = true
55
edition.workspace = true
66
homepage.workspace = true
@@ -25,7 +25,7 @@ fastcrypto.workspace = true
2525
futures = { version = "0.3" }
2626
hyper = "1"
2727
iota-sdk = { version = "1.1.5", default-features = false, features = ["serde", "std"] }
28-
iota_interaction = { version = "0.8.14", path = "../../../iota_interaction", default-features = false }
28+
iota_interaction = { version = "0.8.16", path = "../../../iota_interaction", default-features = false }
2929
js-sys = { version = "=0.3.85" }
3030
json-proof-token = { version = "0.3.5", optional = true }
3131
sd-jwt-payload = { version = "0.2.1", default-features = false, features = ["sha"], optional = true }

bindings/wasm/iota_interaction_ts/package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/wasm/iota_interaction_ts/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "IOTA Foundation <info@iota.org>",
44
"description": "WASM bindings importing types from the IOTA Client typescript SDK to be used in Rust",
55
"homepage": "https://www.iota.org",
6-
"version": "0.12.0",
6+
"version": "0.13.0",
77
"license": "Apache-2.0",
88
"repository": {
99
"type": "git",
@@ -40,7 +40,7 @@
4040
"wasm-opt": "^1.4.0"
4141
},
4242
"peerDependencies": {
43-
"@iota/iota-sdk": "^1.11.0"
43+
"@iota/iota-sdk": "^1.13.0"
4444
},
4545
"engines": {
4646
"node": ">=20"

iota_interaction/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "iota_interaction"
3-
version = "0.8.14"
3+
version = "0.8.16"
44
authors.workspace = true
55
edition.workspace = true
66
homepage.workspace = true
@@ -31,8 +31,8 @@ thiserror.workspace = true
3131

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

3838
[target.'cfg(target_arch = "wasm32")'.dependencies]

iota_interaction/src/sdk_types/iota_json_rpc_types/iota_move.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl From<MoveValue> for IotaMoveValue {
105105
tag: _,
106106
fields,
107107
}) => IotaMoveValue::Variant(IotaMoveVariant {
108-
type_: type_.clone(),
108+
type_,
109109
variant: variant_name.to_string(),
110110
fields: fields
111111
.into_iter()

iota_interaction/src/sdk_types/iota_types/auth_context/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,21 @@ pub struct AuthContext {
5353
tx_inputs: Vec<MoveCallArg>,
5454
/// The authentication commands to be executed sequentially.
5555
tx_commands: Vec<MoveCommand>,
56+
/// The BCS-serialized `TransactionData` bytes.
57+
tx_data_bytes: Vec<u8>,
5658
}
5759

5860
impl AuthContext {
5961
pub fn new_from_components(
6062
auth_digest: MoveAuthenticatorDigest,
6163
ptb: &ProgrammableTransaction,
64+
tx_data_bytes: Vec<u8>,
6265
) -> Self {
6366
Self {
6467
auth_digest,
6568
tx_inputs: ptb.inputs.iter().map(MoveCallArg::from).collect(),
6669
tx_commands: ptb.commands.iter().map(MoveCommand::from).collect(),
70+
tx_data_bytes,
6771
}
6872
}
6973

@@ -72,6 +76,7 @@ impl AuthContext {
7276
auth_digest: MoveAuthenticatorDigest::default(),
7377
tx_inputs: Vec::new(),
7478
tx_commands: Vec::new(),
79+
tx_data_bytes: Vec::new(),
7580
}
7681
}
7782

@@ -87,6 +92,10 @@ impl AuthContext {
8792
&self.tx_commands
8893
}
8994

95+
pub fn tx_data_bytes(&self) -> &Vec<u8> {
96+
&self.tx_data_bytes
97+
}
98+
9099
pub fn to_bcs_bytes(&self) -> Vec<u8> {
91100
bcs::to_bytes(&self).unwrap()
92101
}
@@ -136,10 +145,12 @@ impl AuthContext {
136145
auth_digest: MoveAuthenticatorDigest,
137146
tx_inputs: Vec<MoveCallArg>,
138147
tx_commands: Vec<MoveCommand>,
148+
tx_data_bytes: Vec<u8>,
139149
) {
140150
self.auth_digest = auth_digest;
141151
self.tx_inputs = tx_inputs;
142152
self.tx_commands = tx_commands;
153+
self.tx_data_bytes = tx_data_bytes;
143154
}
144155
}
145156

@@ -197,7 +208,8 @@ mod tests {
197208
}))],
198209
};
199210

200-
let ctx = AuthContext::new_from_components(MoveAuthenticatorDigest::default(), &ptb);
211+
let ctx =
212+
AuthContext::new_from_components(MoveAuthenticatorDigest::default(), &ptb, vec![]);
201213

202214
assert_eq!(ctx.tx_inputs().len(), 1);
203215
assert_eq!(ctx.tx_commands().len(), 1);
@@ -231,6 +243,7 @@ mod tests {
231243
MoveAuthenticatorDigest::default(),
232244
vec![MoveCallArg::Pure(vec![1])],
233245
vec![],
246+
vec![],
234247
);
235248
let non_empty_bytes = ctx.to_bcs_bytes();
236249

iota_interaction/src/sdk_types/iota_types/base_types.rs

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ use std::str::FromStr;
1212
use std::string::String;
1313
use std::vec::Vec;
1414

15-
use anyhow::anyhow;
15+
use anyhow::{anyhow, bail};
1616
use fastcrypto::encoding::{decode_bytes_hex, Encoding, Hex};
1717
use fastcrypto::hash::HashFunction;
1818
use rand::Rng;
1919
use schemars::JsonSchema;
2020
use serde::ser::Error;
21-
use serde::{Deserialize, Serialize};
22-
use serde_with::serde_as;
21+
use serde::{Deserialize, Deserializer, Serialize, Serializer};
22+
use serde_with::{DeserializeAs, SerializeAs, serde_as};
2323
use Result;
2424

25+
use iota_sdk_types::crypto::HashingIntentScope;
26+
2527
use crate::move_core_types::account_address::AccountAddress;
2628
use crate::move_core_types::identifier::IdentStr;
2729
use crate::move_core_types::language_storage::{ModuleId, StructTag, TypeTag};
@@ -35,7 +37,7 @@ use super::dynamic_field::DynamicFieldInfo;
3537
use super::error::{IotaError, IotaResult};
3638
use super::gas_coin::{GasCoin, GAS};
3739
use super::governance::{StakedIota, STAKED_IOTA_STRUCT_NAME, STAKING_POOL_MODULE_NAME};
38-
use super::iota_serde::{to_iota_struct_tag_string, HexAccountAddress, Readable};
40+
use super::iota_serde::{to_custom_deser_error, to_iota_struct_tag_string, Readable};
3941
use super::object::Owner;
4042
use super::stardust::output::Nft;
4143
use super::timelock::timelock::{self, TimeLock};
@@ -691,6 +693,55 @@ impl ObjectID {
691693
}
692694
}
693695

696+
/// Create an ObjectID from `TransactionDigest` and `creation_num`.
697+
/// Caller is responsible for ensuring that `creation_num` is fresh
698+
pub fn derive_id(digest: TransactionDigest, creation_num: u64) -> Self {
699+
let mut hasher = DefaultHash::default();
700+
hasher.update([HashingIntentScope::RegularObjectId as u8]);
701+
hasher.update(digest);
702+
hasher.update(creation_num.to_le_bytes());
703+
let hash = hasher.finalize();
704+
705+
// truncate into an ObjectID.
706+
// OK to access slice because digest should never be shorter than
707+
// ObjectID::LENGTH.
708+
ObjectID::try_from(&hash.as_ref()[0..ObjectID::LENGTH]).unwrap()
709+
}
710+
711+
/// Increment the ObjectID by one, assuming the ObjectID hex is a number
712+
/// represented as an array of bytes
713+
pub fn next_increment(&self) -> Result<ObjectID, anyhow::Error> {
714+
let mut prev_val = self.to_vec();
715+
let mx = [0xFF; Self::LENGTH];
716+
717+
if prev_val == mx {
718+
bail!("Increment will cause overflow");
719+
}
720+
721+
// This logic increments the integer representation of an ObjectID u8 array
722+
for idx in (0..Self::LENGTH).rev() {
723+
if prev_val[idx] == 0xFF {
724+
prev_val[idx] = 0;
725+
} else {
726+
prev_val[idx] += 1;
727+
break;
728+
};
729+
}
730+
ObjectID::try_from(prev_val.clone()).map_err(|w| w.into())
731+
}
732+
733+
/// Create `count` object IDs starting with one at `offset`
734+
pub fn in_range(offset: ObjectID, count: u64) -> Result<Vec<ObjectID>, anyhow::Error> {
735+
let mut ret = Vec::new();
736+
let mut prev = offset;
737+
for o in 0..count {
738+
if o != 0 {
739+
prev = prev.next_increment()?;
740+
}
741+
ret.push(prev);
742+
}
743+
Ok(ret)
744+
}
694745

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

851+
/// Hex serde for AccountAddress
852+
struct HexAccountAddress;
853+
854+
impl SerializeAs<AccountAddress> for HexAccountAddress {
855+
fn serialize_as<S>(value: &AccountAddress, serializer: S) -> Result<S::Ok, S::Error>
856+
where
857+
S: Serializer,
858+
{
859+
Hex::serialize_as(value, serializer)
860+
}
861+
}
862+
863+
impl<'de> DeserializeAs<'de, AccountAddress> for HexAccountAddress {
864+
fn deserialize_as<D>(deserializer: D) -> Result<AccountAddress, D::Error>
865+
where
866+
D: Deserializer<'de>,
867+
{
868+
let s = String::deserialize(deserializer)?;
869+
if s.starts_with("0x") {
870+
AccountAddress::from_hex_literal(&s)
871+
} else {
872+
AccountAddress::from_hex(&s)
873+
}
874+
.map_err(to_custom_deser_error::<'de, D, _>)
875+
}
876+
}
877+
800878
impl fmt::Display for MoveObjectType {
801879
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
802880
let s: StructTag = self.clone().into();

iota_interaction/src/sdk_types/iota_types/crypto.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ use std::hash::Hash;
55
use std::str::FromStr;
66

77
use derive_more::{AsMut, AsRef, From};
8-
use enum_dispatch::enum_dispatch;
8+
pub use enum_dispatch::enum_dispatch;
99
use eyre::{eyre, Report};
10-
use fastcrypto::bls12381::min_sig::{
10+
pub use fastcrypto::traits::{
11+
Authenticator, EncodeDecodeBase64, KeyPair as KeypairTraits, Signer, ToFromBytes, VerifyingKey,
12+
};
13+
pub use fastcrypto::bls12381::min_sig::{
1114
BLS12381AggregateSignature, BLS12381AggregateSignatureAsBytes, BLS12381KeyPair, BLS12381PrivateKey,
1215
BLS12381PublicKey, BLS12381Signature,
1316
};
@@ -19,9 +22,6 @@ use fastcrypto::error::{FastCryptoError, FastCryptoResult};
1922
use fastcrypto::hash::{Blake2b256, HashFunction};
2023
use fastcrypto::secp256k1::{Secp256k1KeyPair, Secp256k1PublicKey, Secp256k1PublicKeyAsBytes, Secp256k1Signature};
2124
use fastcrypto::secp256r1::{Secp256r1KeyPair, Secp256r1PublicKey, Secp256r1PublicKeyAsBytes, Secp256r1Signature};
22-
use fastcrypto::traits::{
23-
Authenticator, EncodeDecodeBase64, KeyPair as KeypairTraits, Signer, ToFromBytes, VerifyingKey,
24-
};
2525
use fastcrypto_zkp::zk_login_utils::Bn254FrElement;
2626
use iota_sdk_types::crypto::IntentMessage;
2727
use schemars::JsonSchema;

iota_interaction/src/sdk_types/iota_types/digests.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ impl fmt::UpperHex for CheckpointContentsDigest {
211211
}
212212
}
213213

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

@@ -261,6 +262,30 @@ impl TransactionDigest {
261262
}
262263
}
263264

265+
impl AsRef<[u8]> for TransactionDigest {
266+
fn as_ref(&self) -> &[u8] {
267+
self.0.as_ref()
268+
}
269+
}
270+
271+
impl AsRef<[u8; 32]> for TransactionDigest {
272+
fn as_ref(&self) -> &[u8; 32] {
273+
self.0.as_ref()
274+
}
275+
}
276+
277+
impl From<TransactionDigest> for [u8; 32] {
278+
fn from(digest: TransactionDigest) -> Self {
279+
digest.into_inner()
280+
}
281+
}
282+
283+
impl From<[u8; 32]> for TransactionDigest {
284+
fn from(digest: [u8; 32]) -> Self {
285+
Self::new(digest)
286+
}
287+
}
288+
264289
impl fmt::Display for TransactionDigest {
265290
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
266291
fmt::Display::fmt(&self.0, f)

0 commit comments

Comments
 (0)