Skip to content

Commit 84e07bb

Browse files
feat(bindings): Add UserSignature and dependent type impls (#74)
* feat(bindings): Add `UserSignature` and dependent type impls * move crypto types into own modules * Update bindings/python/test.py Co-authored-by: Thibault Martinez <[email protected]> * remove arc * call inner fn --------- Co-authored-by: Thibault Martinez <[email protected]> Co-authored-by: Thibault Martinez <[email protected]>
1 parent b017042 commit 84e07bb

File tree

11 files changed

+10305
-3311
lines changed

11 files changed

+10305
-3311
lines changed

bindings/python/lib/iota_sdk_ffi.py

Lines changed: 9168 additions & 3263 deletions
Large diffs are not rendered by default.

bindings/python/test.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from lib.iota_sdk_ffi import GraphQlClient, PaginationFilter, Address, Direction, TransactionsFilter, ObjectId, EventFilter
1+
from lib.iota_sdk_ffi import GraphQlClient, PaginationFilter, Address, Direction, TransactionsFilter, ObjectId, EventFilter, TransactionDigest
22
import asyncio
33

44
async def main():
55
client = GraphQlClient.new_devnet()
66
chain_id = await client.chain_id()
77
print(chain_id)
88

9-
my_address=Address.from_hex("0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f")
9+
my_address = Address.from_hex("0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f")
1010

1111
coins = await client.coins(
1212
my_address,
@@ -19,9 +19,16 @@ async def main():
1919

2020
print(f'Total Balance = {balance}')
2121

22-
filter=TransactionsFilter(at_checkpoint=3, input_object=ObjectId.from_hex("0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f"))
22+
filter = TransactionsFilter(at_checkpoint=3, input_object=ObjectId.from_hex("0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f"))
2323

24-
filter=EventFilter(sender=my_address)
24+
filter = EventFilter(sender=my_address)
25+
26+
txn = await client.transaction(TransactionDigest.from_base58("HT1wvebXV4LUisLa4aJQEyoxt1HEMqznjf5UtStmdxyM"))
27+
28+
if txn is not None:
29+
for sig in txn.signatures():
30+
print("Scheme: ", sig.scheme(), sig.scheme().value)
31+
print("Sender: ", txn.transaction().sender().to_hex())
2532

2633
if __name__ == '__main__':
2734
asyncio.run(main())

crates/iota-sdk-ffi/src/types/checkpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::Arc;
66
use iota_types::GasCostSummary;
77

88
use crate::types::{
9-
crypto::ValidatorCommitteeMember,
9+
crypto::validator::ValidatorCommitteeMember,
1010
digest::{CheckpointContentsDigest, CheckpointDigest, Digest},
1111
};
1212

crates/iota-sdk-ffi/src/types/crypto.rs renamed to crates/iota-sdk-ffi/src/types/crypto/mod.rs

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,16 @@
11
// Copyright (c) 2025 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::sync::Arc;
5-
6-
use crate::error::Result;
7-
8-
/// A member of a Validator Committee
9-
///
10-
/// # BCS
11-
///
12-
/// The BCS serialized form for this type is defined by the following ABNF:
13-
///
14-
/// ```text
15-
/// validator-committee-member = bls-public-key
16-
/// u64 ; stake
17-
/// ```
18-
#[derive(Clone, Debug, uniffi::Record)]
19-
pub struct ValidatorCommitteeMember {
20-
pub public_key: Arc<Bls12381PublicKey>,
21-
pub stake: u64,
22-
}
4+
pub mod multisig;
5+
pub mod passkey;
6+
pub mod validator;
7+
pub mod zklogin;
238

24-
impl From<iota_types::ValidatorCommitteeMember> for ValidatorCommitteeMember {
25-
fn from(value: iota_types::ValidatorCommitteeMember) -> Self {
26-
Self {
27-
public_key: Arc::new(value.public_key.into()),
28-
stake: value.stake,
29-
}
30-
}
31-
}
9+
use std::sync::Arc;
3210

33-
impl From<ValidatorCommitteeMember> for iota_types::ValidatorCommitteeMember {
34-
fn from(value: ValidatorCommitteeMember) -> Self {
35-
Self {
36-
public_key: **value.public_key,
37-
stake: value.stake,
38-
}
39-
}
40-
}
11+
use crate::{error::Result, types::signature::SimpleSignature};
4112

42-
macro_rules! impl_public_key {
13+
macro_rules! impl_crypto_object {
4314
($(#[$meta:meta])* $t:ident) => {
4415
$(#[$meta])*
4516
#[derive(Copy, Clone, Debug, derive_more::From, derive_more::Deref, uniffi::Object)]
@@ -70,7 +41,7 @@ macro_rules! impl_public_key {
7041
};
7142
}
7243

73-
impl_public_key!(
44+
impl_crypto_object!(
7445
/// A bls12381 min-sig public key.
7546
///
7647
/// # BCS
@@ -87,7 +58,7 @@ impl_public_key!(
8758
/// binary form (in bcs) is 97 bytes long vs a more compact 96 bytes.
8859
Bls12381PublicKey
8960
);
90-
impl_public_key!(
61+
impl_crypto_object!(
9162
/// An ed25519 public key.
9263
///
9364
/// # BCS
@@ -99,7 +70,7 @@ impl_public_key!(
9970
/// ```
10071
Ed25519PublicKey
10172
);
102-
impl_public_key!(
73+
impl_crypto_object!(
10374
/// A secp256k1 signature.
10475
///
10576
/// # BCS
@@ -111,7 +82,7 @@ impl_public_key!(
11182
/// ```
11283
Secp256k1PublicKey
11384
);
114-
impl_public_key!(
85+
impl_crypto_object!(
11586
/// A secp256r1 signature.
11687
///
11788
/// # BCS
@@ -123,3 +94,56 @@ impl_public_key!(
12394
/// ```
12495
Secp256r1PublicKey
12596
);
97+
impl_crypto_object!(
98+
/// An ed25519 signature.
99+
///
100+
/// # BCS
101+
///
102+
/// The BCS serialized form for this type is defined by the following ABNF:
103+
///
104+
/// ```text
105+
/// ed25519-signature = 64OCTECT
106+
/// ```
107+
Ed25519Signature
108+
);
109+
impl_crypto_object!(
110+
/// A bls12381 min-sig public key.
111+
///
112+
/// # BCS
113+
///
114+
/// The BCS serialized form for this type is defined by the following ABNF:
115+
///
116+
/// ```text
117+
/// bls-public-key = %x60 96OCTECT
118+
/// ```
119+
///
120+
/// Due to historical reasons, even though a min-sig `Bls12381PublicKey` has a
121+
/// fixed-length of 96, IOTA's binary representation of a min-sig
122+
/// `Bls12381PublicKey` is prefixed with its length meaning its serialized
123+
/// binary form (in bcs) is 97 bytes long vs a more compact 96 bytes.
124+
Bls12381Signature
125+
);
126+
impl_crypto_object!(
127+
/// A secp256k1 public key.
128+
///
129+
/// # BCS
130+
///
131+
/// The BCS serialized form for this type is defined by the following ABNF:
132+
///
133+
/// ```text
134+
/// secp256k1-public-key = 33OCTECT
135+
/// ```
136+
Secp256k1Signature
137+
);
138+
impl_crypto_object!(
139+
/// A secp256r1 public key.
140+
///
141+
/// # BCS
142+
///
143+
/// The BCS serialized form for this type is defined by the following ABNF:
144+
///
145+
/// ```text
146+
/// secp256r1-public-key = 33OCTECT
147+
/// ```
148+
Secp256r1Signature
149+
);

0 commit comments

Comments
 (0)