Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4,936 changes: 4,910 additions & 26 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.go

Large diffs are not rendered by default.

2,167 changes: 2,156 additions & 11 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.h

Large diffs are not rendered by default.

5,051 changes: 4,989 additions & 62 deletions bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt

Large diffs are not rendered by default.

4,867 changes: 4,841 additions & 26 deletions bindings/python/lib/iota_sdk_ffi.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/iota-sdk-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ base64ct = { version = "1.6.0", features = ["alloc", "std"] }
bcs = "0.1.6"
derive_more = { version = "2.0", features = ["from", "deref", "display"] }
hex = "0.4.3"
paste = "1.0"
primitive-types = { version = "0.14", features = ["impl-serde"] }
rand = "0.8"
roaring = { version = "0.11.2", default-features = false }
Expand Down
40 changes: 40 additions & 0 deletions crates/iota-sdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,43 @@ pub fn hex_encode(input: &[u8]) -> String {
pub fn hex_decode(input: String) -> crate::error::Result<Vec<u8>> {
Ok(hex::decode(input)?)
}

#[macro_export]
macro_rules! export_record_enum_bcs_conversion {
($($name:ident),+ $(,)?) => {
paste::paste! {$(
/// Create `$name` from BCS encoded bytes.
#[uniffi::export]
pub fn [< $name:snake _from_bcs >](bcs: Vec<u8>) -> crate::error::Result<$name> {
let data = bcs::from_bytes::<iota_types::$name>(&bcs)?;
Ok(data.into())
}

/// Convert `$name` to BCS encoded bytes.
#[uniffi::export]
pub fn [< $name:snake _to_bcs >](data: $name) -> crate::error::Result<Vec<u8>> {
let data: iota_types::$name = data.into();
Ok(bcs::to_bytes(&data)?)
}
)+}
}
}

#[macro_export]
macro_rules! export_object_bcs_conversion {
($($name:ident),+ $(,)?) => {$(
#[uniffi::export]
impl $name {
/// Create this type from BCS encoded bytes.
#[uniffi::constructor]
pub fn from_bcs(bcs: Vec<u8>) -> crate::error::Result<Self> {
Ok(Self(bcs::from_bytes::<iota_types::$name>(&bcs)?))
}

/// Convert this type to BCS encoded bytes.
pub fn to_bcs(&self) -> crate::error::Result<Vec<u8>> {
Ok(bcs::to_bytes(&self.0)?)
}
}
)+}
}
16 changes: 15 additions & 1 deletion crates/iota-sdk-ffi/src/types/address.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// Copyright (c) 2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crate::error::Result;
use base64ct::Encoding;

use crate::{
base64_encode,
error::{Result, SdkFfiError},
};

/// Unique identifier for an Account on the IOTA blockchain.
///
Expand Down Expand Up @@ -71,6 +76,11 @@ impl Address {
Ok(Self(iota_types::Address::from_hex(hex)?))
}

#[uniffi::constructor]
pub fn from_bcs(bcs: Vec<u8>) -> Result<Self> {
Ok(Self(bcs::from_bytes::<iota_types::Address>(&bcs)?))
}

#[uniffi::constructor]
pub fn generate() -> Self {
let mut rng = rand::thread_rng();
Expand All @@ -84,4 +94,8 @@ impl Address {
pub fn to_hex(&self) -> String {
self.0.to_hex()
}

pub fn to_bcs(&self) -> Result<Vec<u8>> {
Ok(bcs::to_bytes(&self.0)?)
}
}
27 changes: 26 additions & 1 deletion crates/iota-sdk-ffi/src/types/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use std::sync::Arc;

use iota_types::GasCostSummary;

use crate::types::{digest::Digest, signature::UserSignature, validator::ValidatorCommitteeMember};
use crate::{
error::Result,
export_object_bcs_conversion, export_record_enum_bcs_conversion,
types::{digest::Digest, signature::UserSignature, validator::ValidatorCommitteeMember},
};

pub type CheckpointSequenceNumber = u64;
pub type CheckpointTimestamp = u64;
Expand Down Expand Up @@ -272,6 +276,18 @@ impl CheckpointCommitment {
}
}

/// Data, which when included in a [`CheckpointSummary`], signals the end of an
/// `Epoch`.
///
/// # BCS
///
/// The BCS serialized form for this type is defined by the following ABNF:
///
/// ```text
/// end-of-epoch-data = (vector validator-committee-member) ; next_epoch_committee
/// u64 ; next_epoch_protocol_version
/// (vector checkpoint-commitment) ; epoch_commitments
/// ```
#[derive(uniffi::Record)]
pub struct EndOfEpochData {
pub next_epoch_committee: Vec<ValidatorCommitteeMember>,
Expand Down Expand Up @@ -318,3 +334,12 @@ impl From<EndOfEpochData> for iota_types::EndOfEpochData {
}
}
}

export_object_bcs_conversion!(
CheckpointSummary,
CheckpointContents,
CheckpointTransactionInfo,
CheckpointCommitment
);

export_record_enum_bcs_conversion!(EndOfEpochData);
12 changes: 12 additions & 0 deletions crates/iota-sdk-ffi/src/types/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use iota_types::SignatureScheme;

use crate::{
error::Result,
export_object_bcs_conversion,
types::{address::Address, signature::SimpleSignature},
};

Expand Down Expand Up @@ -210,3 +211,14 @@ impl_crypto_object!(
/// ```
Secp256r1Signature
);

export_object_bcs_conversion!(
Ed25519PublicKey,
Bls12381PublicKey,
Secp256k1PublicKey,
Secp256r1PublicKey,
Ed25519Signature,
Bls12381Signature,
Secp256k1Signature,
Secp256r1Signature,
);
23 changes: 17 additions & 6 deletions crates/iota-sdk-ffi/src/types/crypto/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ use std::sync::Arc;

use iota_types::SignatureScheme;

use crate::types::{
address::Address,
crypto::{
Ed25519PublicKey, Ed25519Signature, Secp256k1PublicKey, Secp256k1Signature,
Secp256r1PublicKey, Secp256r1Signature,
zklogin::{ZkLoginAuthenticator, ZkLoginPublicIdentifier},
use crate::{
export_object_bcs_conversion,
types::{
address::Address,
crypto::{
Ed25519PublicKey, Ed25519Signature, Secp256k1PublicKey, Secp256k1Signature,
Secp256r1PublicKey, Secp256r1Signature,
zklogin::{ZkLoginAuthenticator, ZkLoginPublicIdentifier},
},
},
};

Expand Down Expand Up @@ -410,3 +413,11 @@ impl MultisigMember {
self.0.weight()
}
}

export_object_bcs_conversion!(
MultisigMemberSignature,
MultisigMemberPublicKey,
MultisigAggregatedSignature,
MultisigCommittee,
MultisigMember
);
3 changes: 3 additions & 0 deletions crates/iota-sdk-ffi/src/types/crypto/passkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use iota_crypto::Verifier;

use crate::{
error::Result,
export_object_bcs_conversion,
types::{address::Address, crypto::Secp256r1PublicKey, signature::SimpleSignature},
};

Expand Down Expand Up @@ -113,3 +114,5 @@ impl PasskeyPublicKey {
self.0.derive_address().into()
}
}

export_object_bcs_conversion!(PasskeyAuthenticator);
12 changes: 12 additions & 0 deletions crates/iota-sdk-ffi/src/types/crypto/zklogin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use iota_types::{Jwk, JwkId, ZkLoginClaim};

use crate::{
error::{Result, SdkFfiError},
export_object_bcs_conversion, export_record_enum_bcs_conversion,
types::{address::Address, signature::SimpleSignature},
};

Expand Down Expand Up @@ -430,3 +431,14 @@ pub struct Jwk {
/// Algorithm parameter, <https://datatracker.ietf.org/doc/html/rfc7517#section-4.4>
pub alg: String,
}

export_object_bcs_conversion!(
ZkLoginAuthenticator,
ZkLoginPublicIdentifier,
ZkLoginProof,
CircomG1,
CircomG2,
Bn254FieldElement
);

export_record_enum_bcs_conversion!(ZkLoginClaim, JwkId, Jwk);
4 changes: 3 additions & 1 deletion crates/iota-sdk-ffi/src/types/digest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crate::error::Result;
use crate::{error::Result, export_object_bcs_conversion};

/// A 32-byte Blake2b256 hash output.
///
Expand Down Expand Up @@ -46,3 +46,5 @@ impl Digest {
self.0.to_base58()
}
}

export_object_bcs_conversion!(Digest);
9 changes: 8 additions & 1 deletion crates/iota-sdk-ffi/src/types/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ use iota_graphql_client::query_types::{
};
use iota_types::{Identifier, StructTag};

use crate::types::{address::Address, digest::Digest, object::ObjectId};
use crate::{
error::Result,
export_object_bcs_conversion, export_record_enum_bcs_conversion,
types::{address::Address, digest::Digest, object::ObjectId},
};

/// An event
///
Expand Down Expand Up @@ -141,3 +145,6 @@ impl TransactionEvents {
self.0.digest().into()
}
}

export_record_enum_bcs_conversion!(Event);
export_object_bcs_conversion!(TransactionEvents);
15 changes: 14 additions & 1 deletion crates/iota-sdk-ffi/src/types/execution_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use std::sync::Arc;

use iota_types::{CommandArgumentError, Identifier, TypeArgumentError};

use crate::types::{address::Address, digest::Digest, object::ObjectId};
use crate::{
error::Result,
export_record_enum_bcs_conversion,
types::{address::Address, digest::Digest, object::ObjectId},
};

/// The status of an executed Transaction
///
Expand Down Expand Up @@ -756,3 +760,12 @@ pub enum TypeArgumentError {
/// A type provided did not match the specified constraint
ConstraintNotSatisfied,
}

export_record_enum_bcs_conversion!(
ExecutionStatus,
ExecutionError,
MoveLocation,
CommandArgumentError,
PackageUpgradeError,
TypeArgumentError
);
4 changes: 4 additions & 0 deletions crates/iota-sdk-ffi/src/types/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use iota_types::GasCostSummary;

use crate::export_record_enum_bcs_conversion;

/// Summary of gas charges.
///
/// Storage is charged independently of computation.
Expand Down Expand Up @@ -55,3 +57,5 @@ pub struct GasCostSummary {
/// system.
pub non_refundable_storage_fee: u64,
}

export_record_enum_bcs_conversion!(GasCostSummary);
11 changes: 11 additions & 0 deletions crates/iota-sdk-ffi/src/types/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub type Version = iota_types::Version;

use crate::{
error::Result,
export_object_bcs_conversion, export_record_enum_bcs_conversion,
types::{
address::Address,
digest::Digest,
Expand Down Expand Up @@ -636,3 +637,13 @@ impl GenesisObject {
self.0.data().clone().into()
}
}

export_record_enum_bcs_conversion!(ObjectReference, TypeOrigin, UpgradeInfo, MoveStruct);
export_object_bcs_conversion!(
ObjectId,
Object,
ObjectData,
MovePackage,
Owner,
GenesisObject
);
3 changes: 3 additions & 0 deletions crates/iota-sdk-ffi/src/types/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use iota_types::{SignatureScheme, ZkLoginClaim};

use crate::{
error::Result,
export_object_bcs_conversion, export_record_enum_bcs_conversion,
types::crypto::{
Ed25519PublicKey, Ed25519Signature, Secp256k1PublicKey, Secp256k1Signature,
Secp256r1PublicKey, Secp256r1Signature, multisig::MultisigAggregatedSignature,
Expand Down Expand Up @@ -319,3 +320,5 @@ impl SimpleSignature {
(*self.0.as_secp256r1_pub_key()).into()
}
}

export_object_bcs_conversion!(UserSignature, SimpleSignature);
3 changes: 3 additions & 0 deletions crates/iota-sdk-ffi/src/types/struct_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::Arc;

use crate::{
error::Result,
export_object_bcs_conversion,
types::{address::Address, type_tag::TypeTag},
};

Expand Down Expand Up @@ -106,3 +107,5 @@ impl StructTag {
self.0.address().into()
}
}

export_object_bcs_conversion!(Identifier, StructTag);
Loading
Loading