Skip to content
Merged
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
38,546 changes: 21,543 additions & 17,003 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.go

Large diffs are not rendered by default.

2,594 changes: 2,364 additions & 230 deletions bindings/go/iota_sdk_ffi/iota_sdk_ffi.h

Large diffs are not rendered by default.

28,126 changes: 16,196 additions & 11,930 deletions bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt

Large diffs are not rendered by default.

24,743 changes: 14,505 additions & 10,238 deletions bindings/python/lib/iota_sdk_ffi.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions crates/iota-sdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

use base64ct::Encoding;

mod macros;

pub mod crypto;
pub mod error;
pub mod faucet;
Expand All @@ -18,6 +20,8 @@ pub mod transaction_builder;
pub mod types;
pub mod uniffi_helpers;

pub(crate) use macros::*;

uniffi::setup_scaffolding!();

#[uniffi::export]
Expand Down
43 changes: 43 additions & 0 deletions crates/iota-sdk-ffi/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

macro_rules! export_iota_types_bcs_conversion {
($($name:ty),+ $(,)?) => {
paste::paste! {$(
/// Create this type 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 this type 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_rules! export_iota_types_objects_bcs_conversion {
($($name:ty),+ $(,)?) => {
paste::paste! {$(
/// Create this type from BCS encoded bytes.
#[uniffi::export]
pub fn [< $name:snake _from_bcs >](bcs: Vec<u8>) -> crate::error::Result<$name> {
Ok($name(bcs::from_bytes::<iota_types::$name>(&bcs)?))
}

/// Convert this type to BCS encoded bytes.
#[uniffi::export]
pub fn [< $name:snake _to_bcs >](data: std::sync::Arc<$name>) -> crate::error::Result<Vec<u8>> {
Ok(bcs::to_bytes(&data.0)?)
}
)+}
}
}

pub(crate) use export_iota_types_bcs_conversion;
pub(crate) use export_iota_types_objects_bcs_conversion;
9 changes: 8 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 @@ -88,3 +93,5 @@ macro_rules! named_address {
}

named_address!(ZERO, STD_LIB, FRAMEWORK, SYSTEM);

crate::export_iota_types_objects_bcs_conversion!(Address);
26 changes: 25 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,10 @@ use std::sync::Arc;

use iota_types::GasCostSummary;

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

pub type CheckpointSequenceNumber = u64;
pub type CheckpointTimestamp = u64;
Expand Down Expand Up @@ -276,6 +279,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 @@ -322,3 +337,12 @@ impl From<EndOfEpochData> for iota_types::EndOfEpochData {
}
}
}

crate::export_iota_types_objects_bcs_conversion!(
CheckpointSummary,
CheckpointContents,
CheckpointTransactionInfo,
CheckpointCommitment
);

crate::export_iota_types_bcs_conversion!(EndOfEpochData);
11 changes: 11 additions & 0 deletions crates/iota-sdk-ffi/src/types/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,14 @@ impl_crypto_object!(
/// ```
Secp256r1Signature
);

crate::export_iota_types_objects_bcs_conversion!(
Ed25519PublicKey,
Bls12381PublicKey,
Secp256k1PublicKey,
Secp256r1PublicKey,
Ed25519Signature,
Bls12381Signature,
Secp256k1Signature,
Secp256r1Signature,
);
8 changes: 8 additions & 0 deletions crates/iota-sdk-ffi/src/types/crypto/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,11 @@ impl MultisigMember {
self.0.weight()
}
}

crate::export_iota_types_objects_bcs_conversion!(
MultisigMemberSignature,
MultisigMemberPublicKey,
MultisigAggregatedSignature,
MultisigCommittee,
MultisigMember
);
2 changes: 2 additions & 0 deletions crates/iota-sdk-ffi/src/types/crypto/passkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ impl PasskeyPublicKey {
self.0.derive_address().into()
}
}

crate::export_iota_types_objects_bcs_conversion!(PasskeyAuthenticator);
11 changes: 11 additions & 0 deletions crates/iota-sdk-ffi/src/types/crypto/zklogin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,14 @@ pub struct Jwk {
/// Algorithm parameter, <https://datatracker.ietf.org/doc/html/rfc7517#section-4.4>
pub alg: String,
}

crate::export_iota_types_objects_bcs_conversion!(
ZkLoginAuthenticator,
ZkLoginPublicIdentifier,
ZkLoginProof,
CircomG1,
CircomG2,
Bn254FieldElement
);

crate::export_iota_types_bcs_conversion!(ZkLoginClaim, JwkId, Jwk);
2 changes: 2 additions & 0 deletions crates/iota-sdk-ffi/src/types/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ impl Digest {
self.0.to_base58()
}
}

crate::export_iota_types_objects_bcs_conversion!(Digest);
8 changes: 7 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,10 @@ use iota_graphql_client::query_types::{
};
use iota_types::{Identifier, StructTag};

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

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

crate::export_iota_types_bcs_conversion!(Event);
crate::export_iota_types_objects_bcs_conversion!(TransactionEvents);
14 changes: 13 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,10 @@ use std::sync::Arc;

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

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

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

crate::export_iota_types_bcs_conversion!(
ExecutionStatus,
ExecutionError,
MoveLocation,
CommandArgumentError,
PackageUpgradeError,
TypeArgumentError
);
2 changes: 2 additions & 0 deletions crates/iota-sdk-ffi/src/types/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ pub struct GasCostSummary {
/// system.
pub non_refundable_storage_fee: u64,
}

crate::export_iota_types_bcs_conversion!(GasCostSummary);
10 changes: 10 additions & 0 deletions crates/iota-sdk-ffi/src/types/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,3 +651,13 @@ impl GenesisObject {
self.0.data().clone().into()
}
}

crate::export_iota_types_bcs_conversion!(ObjectReference, TypeOrigin, UpgradeInfo, MoveStruct);
crate::export_iota_types_objects_bcs_conversion!(
ObjectId,
Object,
ObjectData,
MovePackage,
Owner,
GenesisObject
);
2 changes: 2 additions & 0 deletions crates/iota-sdk-ffi/src/types/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,5 @@ impl SimpleSignature {
(*self.0.as_secp256r1_pub_key()).into()
}
}

crate::export_iota_types_objects_bcs_conversion!(UserSignature, SimpleSignature);
2 changes: 2 additions & 0 deletions crates/iota-sdk-ffi/src/types/struct_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ impl StructTag {
self.0.address().into()
}
}

crate::export_iota_types_objects_bcs_conversion!(Identifier, StructTag);
61 changes: 39 additions & 22 deletions crates/iota-sdk-ffi/src/types/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,11 @@ impl Transaction {
self.0.signing_digest_hex()
}

/// Serialize the transaction as a `Vec<u8>` of BCS bytes.
pub fn to_bcs(&self) -> Vec<u8> {
self.0.to_bcs()
}

/// Serialize the transaction as a base64-encoded string.
pub fn to_base64(&self) -> String {
self.0.to_base64()
}

/// Deserialize a transaction from a `Vec<u8>` of BCS bytes.
#[uniffi::constructor]
pub fn from_bcs(bytes: Vec<u8>) -> Result<Self> {
Ok(Transaction(iota_types::Transaction::from_bcs(&bytes)?))
}

/// Deserialize a transaction from a base64-encoded string.
#[uniffi::constructor]
pub fn from_base64(base64: String) -> Result<Self> {
Expand Down Expand Up @@ -170,22 +159,11 @@ impl TransactionV1 {
self.0.signing_digest_hex()
}

/// Serialize the transaction as a `Vec<u8>` of BCS bytes.
pub fn to_bcs(&self) -> Vec<u8> {
self.0.to_bcs()
}

/// Serialize the transaction as a base64-encoded string.
pub fn to_base64(&self) -> String {
self.0.to_base64()
}

/// Deserialize a transaction from a `Vec<u8>` of BCS bytes.
#[uniffi::constructor]
pub fn from_bcs(bytes: Vec<u8>) -> Result<Self> {
Ok(Self(iota_types::TransactionV1::from_bcs(&bytes)?))
}

/// Deserialize a transaction from a base64-encoded string.
#[uniffi::constructor]
pub fn from_base64(bytes: String) -> Result<Self> {
Expand Down Expand Up @@ -1729,3 +1707,42 @@ impl MoveCall {
.collect()
}
}

crate::export_iota_types_objects_bcs_conversion!(
Transaction,
TransactionV1,
TransactionKind,
ProgrammableTransaction,
Input,
Command,
TransferObjects,
SplitCoins,
MergeCoins,
Publish,
MakeMoveVector,
Upgrade,
ConsensusCommitPrologueV1,
ConsensusDeterminedVersionAssignments,
CancelledTransaction,
VersionAssignment,
GenesisTransaction,
ChangeEpoch,
SystemPackage,
ChangeEpochV2,
ExecutionTimeObservation,
ExecutionTimeObservations,
ValidatorExecutionTimeObservation,
ExecutionTimeObservationKey,
TransactionEffects,
Argument,
MoveCall,
);
crate::export_iota_types_bcs_conversion!(
SignedTransaction,
AuthenticatorStateExpire,
AuthenticatorStateUpdateV1,
ActiveJwk,
RandomnessStateUpdate,
GasPayment,
TransactionExpiration,
);
10 changes: 10 additions & 0 deletions crates/iota-sdk-ffi/src/types/transaction/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,13 @@ pub enum IdOperation {
Created,
Deleted,
}

crate::export_iota_types_bcs_conversion!(
TransactionEffectsV1,
ChangedObject,
UnchangedSharedObject,
UnchangedSharedKind,
ObjectIn,
ObjectOut,
IdOperation
);
2 changes: 2 additions & 0 deletions crates/iota-sdk-ffi/src/types/type_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,5 @@ impl TypeTag {
Self(iota_types::TypeTag::Struct(Box::new(struct_tag.0.clone())))
}
}

crate::export_iota_types_objects_bcs_conversion!(TypeTag);
3 changes: 3 additions & 0 deletions crates/iota-sdk-ffi/src/types/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,6 @@ impl ValidatorAggregatedSignature {
Ok(bytes)
}
}

crate::export_iota_types_bcs_conversion!(ValidatorCommittee, ValidatorCommitteeMember);
crate::export_iota_types_objects_bcs_conversion!(ValidatorSignature, ValidatorAggregatedSignature);