From d6ab4e3afd605a14385b3a96e95576dffafe53d9 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 14 Oct 2025 15:19:11 +0200 Subject: [PATCH 1/7] chore(generate_ed25519_address): add `*PublicKey::to_flagged_bytes` and harmonize examples --- .../examples/generate_ed25519_address/main.go | 6 +- bindings/go/iota_sdk_ffi/iota_sdk_ffi.go | 69 +++++++++++++++ bindings/go/iota_sdk_ffi/iota_sdk_ffi.h | 33 +++++++ .../kotlin/examples/GenerateEd25519Address.kt | 5 +- bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt | 87 +++++++++++++++++++ .../examples/generate_ed25519_address.py | 5 +- bindings/python/lib/iota_sdk_ffi.py | 87 +++++++++++++++++++ crates/iota-sdk-ffi/src/types/crypto/mod.rs | 15 ++++ crates/iota-sdk-types/src/crypto/ed25519.rs | 9 ++ crates/iota-sdk-types/src/crypto/secp256k1.rs | 9 ++ crates/iota-sdk-types/src/crypto/secp256r1.rs | 9 ++ .../examples/generate_ed25519_address.rs | 7 +- 12 files changed, 326 insertions(+), 15 deletions(-) diff --git a/bindings/go/examples/generate_ed25519_address/main.go b/bindings/go/examples/generate_ed25519_address/main.go index acae6236a..9c25a14c0 100644 --- a/bindings/go/examples/generate_ed25519_address/main.go +++ b/bindings/go/examples/generate_ed25519_address/main.go @@ -16,13 +16,11 @@ func main() { panic(err) } publicKey := privateKey.PublicKey() + flaggedPublicKey := publicKey.ToFlaggedBytes() address := publicKey.DeriveAddress() - publicKeyBytes := publicKey.ToBytes() - - flaggedPublicKey := append([]byte{byte(sdk.SignatureSchemeEd25519)}, publicKeyBytes...) fmt.Println("Private Key:", privateKeyBech32) - fmt.Println("Public Key:", sdk.Base64Encode(publicKeyBytes)) + fmt.Println("Public Key:", sdk.Base64Encode(publicKey.ToBytes())) fmt.Println("Public Key With Flag:", sdk.Base64Encode(flaggedPublicKey)) fmt.Println("Address:", address.ToHex()) } diff --git a/bindings/go/iota_sdk_ffi/iota_sdk_ffi.go b/bindings/go/iota_sdk_ffi/iota_sdk_ffi.go index 4ae3d2f71..0e5e8cfce 100644 --- a/bindings/go/iota_sdk_ffi/iota_sdk_ffi.go +++ b/bindings/go/iota_sdk_ffi/iota_sdk_ffi.go @@ -1097,6 +1097,15 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes() + }) + if checksum != 31806 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_ed25519signature_to_bytes() }) @@ -2906,6 +2915,15 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes() + }) + if checksum != 42834 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_secp256k1signature_to_bytes() }) @@ -3104,6 +3122,15 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_flagged_bytes() + }) + if checksum != 14205 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_flagged_bytes: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_secp256r1signature_to_bytes() }) @@ -10616,6 +10643,8 @@ type Ed25519PublicKeyInterface interface { // Return the flag for this signature scheme Scheme() SignatureScheme ToBytes() []byte + // Returns the bytes with signature scheme flag prepended + ToFlaggedBytes() []byte } // An ed25519 public key. // @@ -10700,6 +10729,18 @@ func (_self *Ed25519PublicKey) ToBytes() []byte { } })) } + +// Returns the bytes with signature scheme flag prepended +func (_self *Ed25519PublicKey) ToFlaggedBytes() []byte { + _pointer := _self.ffiObject.incrementPointer("*Ed25519PublicKey") + defer _self.ffiObject.decrementPointer() + return FfiConverterBytesINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_ed25519publickey_to_flagged_bytes( + _pointer,_uniffiStatus), + } + })) +} func (object *Ed25519PublicKey) Destroy() { runtime.SetFinalizer(object, nil) object.ffiObject.destroy() @@ -18974,6 +19015,8 @@ type Secp256k1PublicKeyInterface interface { // Return the flag for this signature scheme Scheme() SignatureScheme ToBytes() []byte + // Returns the bytes with signature scheme flag prepended + ToFlaggedBytes() []byte } // A secp256k1 signature. // @@ -19059,6 +19102,18 @@ func (_self *Secp256k1PublicKey) ToBytes() []byte { } })) } + +// Returns the bytes with signature scheme flag prepended +func (_self *Secp256k1PublicKey) ToFlaggedBytes() []byte { + _pointer := _self.ffiObject.incrementPointer("*Secp256k1PublicKey") + defer _self.ffiObject.decrementPointer() + return FfiConverterBytesINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_to_flagged_bytes( + _pointer,_uniffiStatus), + } + })) +} func (object *Secp256k1PublicKey) Destroy() { runtime.SetFinalizer(object, nil) object.ffiObject.destroy() @@ -19807,6 +19862,8 @@ type Secp256r1PublicKeyInterface interface { // Return the flag for this signature scheme Scheme() SignatureScheme ToBytes() []byte + // Returns the bytes with signature scheme flag prepended + ToFlaggedBytes() []byte } // A secp256r1 signature. // @@ -19892,6 +19949,18 @@ func (_self *Secp256r1PublicKey) ToBytes() []byte { } })) } + +// Returns the bytes with signature scheme flag prepended +func (_self *Secp256r1PublicKey) ToFlaggedBytes() []byte { + _pointer := _self.ffiObject.incrementPointer("*Secp256r1PublicKey") + defer _self.ffiObject.decrementPointer() + return FfiConverterBytesINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_to_flagged_bytes( + _pointer,_uniffiStatus), + } + })) +} func (object *Secp256r1PublicKey) Destroy() { runtime.SetFinalizer(object, nil) object.ffiObject.destroy() diff --git a/bindings/go/iota_sdk_ffi/iota_sdk_ffi.h b/bindings/go/iota_sdk_ffi/iota_sdk_ffi.h index 3084d4de9..664cf62f3 100644 --- a/bindings/go/iota_sdk_ffi/iota_sdk_ffi.h +++ b/bindings/go/iota_sdk_ffi/iota_sdk_ffi.h @@ -1270,6 +1270,11 @@ RustBuffer uniffi_iota_sdk_ffi_fn_method_ed25519publickey_scheme(void* ptr, Rust RustBuffer uniffi_iota_sdk_ffi_fn_method_ed25519publickey_to_bytes(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_ED25519PUBLICKEY_TO_FLAGGED_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_ED25519PUBLICKEY_TO_FLAGGED_BYTES +RustBuffer uniffi_iota_sdk_ffi_fn_method_ed25519publickey_to_flagged_bytes(void* ptr, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CLONE_ED25519SIGNATURE #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CLONE_ED25519SIGNATURE void* uniffi_iota_sdk_ffi_fn_clone_ed25519signature(void* ptr, RustCallStatus *out_status @@ -3420,6 +3425,11 @@ RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_scheme(void* ptr, Ru RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_to_bytes(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256K1PUBLICKEY_TO_FLAGGED_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256K1PUBLICKEY_TO_FLAGGED_BYTES +RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_to_flagged_bytes(void* ptr, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CLONE_SECP256K1SIGNATURE #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CLONE_SECP256K1SIGNATURE void* uniffi_iota_sdk_ffi_fn_clone_secp256k1signature(void* ptr, RustCallStatus *out_status @@ -3659,6 +3669,11 @@ RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_scheme(void* ptr, Ru RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_to_bytes(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256R1PUBLICKEY_TO_FLAGGED_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256R1PUBLICKEY_TO_FLAGGED_BYTES +RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_to_flagged_bytes(void* ptr, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CLONE_SECP256R1SIGNATURE #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CLONE_SECP256R1SIGNATURE void* uniffi_iota_sdk_ffi_fn_clone_secp256r1signature(void* ptr, RustCallStatus *out_status @@ -5906,6 +5921,12 @@ uint16_t uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_scheme(void #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ED25519PUBLICKEY_TO_BYTES uint16_t uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_bytes(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ED25519PUBLICKEY_TO_FLAGGED_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ED25519PUBLICKEY_TO_FLAGGED_BYTES +uint16_t uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ED25519SIGNATURE_TO_BYTES @@ -7112,6 +7133,12 @@ uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_scheme(void #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256K1PUBLICKEY_TO_BYTES uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_bytes(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256K1PUBLICKEY_TO_FLAGGED_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256K1PUBLICKEY_TO_FLAGGED_BYTES +uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256K1SIGNATURE_TO_BYTES @@ -7244,6 +7271,12 @@ uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_scheme(void #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256R1PUBLICKEY_TO_BYTES uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_bytes(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256R1PUBLICKEY_TO_FLAGGED_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256R1PUBLICKEY_TO_FLAGGED_BYTES +uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_flagged_bytes(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256R1SIGNATURE_TO_BYTES diff --git a/bindings/kotlin/examples/GenerateEd25519Address.kt b/bindings/kotlin/examples/GenerateEd25519Address.kt index b0dc07cd8..5d102617c 100644 --- a/bindings/kotlin/examples/GenerateEd25519Address.kt +++ b/bindings/kotlin/examples/GenerateEd25519Address.kt @@ -9,12 +9,11 @@ fun main() { val privateKey = Ed25519PrivateKey.generate() val privateKeyBech32 = privateKey.toBech32() val publicKey = privateKey.publicKey() - val publicKeyBytes = publicKey.toBytes() - val flaggedPublicKey = byteArrayOf((publicKey.scheme().ordinal + 1).toByte()) + publicKeyBytes + val flaggedPublicKey = publicKey.toFlaggedBytes() val address = publicKey.deriveAddress() println("Private Key: ${privateKeyBech32}") - println("Public Key: ${base64Encode(publicKeyBytes)}") + println("Public Key: ${base64Encode(publicKey.toBytes())}") println("Public Key With Flag: ${base64Encode(flaggedPublicKey)}") println("Address: ${address.toHex()}") } diff --git a/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt b/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt index 647c4d864..7ca43d833 100644 --- a/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt +++ b/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt @@ -2383,6 +2383,12 @@ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback { + + + + + + @@ -2569,6 +2575,8 @@ fun uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_scheme( ): Short fun uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_bytes( ): Short +fun uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes( +): Short fun uniffi_iota_sdk_ffi_checksum_method_ed25519signature_to_bytes( ): Short fun uniffi_iota_sdk_ffi_checksum_method_ed25519verifyingkey_public_key( @@ -2971,6 +2979,8 @@ fun uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_scheme( ): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_bytes( ): Short +fun uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes( +): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256k1signature_to_bytes( ): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256k1verifier_verify_simple( @@ -3015,6 +3025,8 @@ fun uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_scheme( ): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_bytes( ): Short +fun uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_flagged_bytes( +): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256r1signature_to_bytes( ): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256r1verifier_verify_simple( @@ -4268,6 +4280,8 @@ fun uniffi_iota_sdk_ffi_fn_method_ed25519publickey_scheme(`ptr`: Pointer,uniffi_ ): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_ed25519publickey_to_bytes(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_ed25519publickey_to_flagged_bytes(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_clone_ed25519signature(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_iota_sdk_ffi_fn_free_ed25519signature(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, @@ -5118,6 +5132,8 @@ fun uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_scheme(`ptr`: Pointer,uniff ): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_to_bytes(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_to_flagged_bytes(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_clone_secp256k1signature(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_iota_sdk_ffi_fn_free_secp256k1signature(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, @@ -5212,6 +5228,8 @@ fun uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_scheme(`ptr`: Pointer,uniff ): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_to_bytes(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_to_flagged_bytes(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_clone_secp256r1signature(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_iota_sdk_ffi_fn_free_secp256r1signature(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, @@ -6168,6 +6186,9 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_bytes() != 16656.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes() != 31806.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519signature_to_bytes() != 31911.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -6771,6 +6792,9 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_bytes() != 49170.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes() != 42834.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1signature_to_bytes() != 49705.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -6837,6 +6861,9 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_bytes() != 21066.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_flagged_bytes() != 14205.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1signature_to_bytes() != 64948.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -16099,6 +16126,11 @@ public interface Ed25519PublicKeyInterface { fun `toBytes`(): kotlin.ByteArray + /** + * Returns the bytes with signature scheme flag prepended + */ + fun `toFlaggedBytes`(): kotlin.ByteArray + companion object } @@ -16243,6 +16275,21 @@ open class Ed25519PublicKey: Disposable, AutoCloseable, Ed25519PublicKeyInterfac + /** + * Returns the bytes with signature scheme flag prepended + */override fun `toFlaggedBytes`(): kotlin.ByteArray { + return FfiConverterByteArray.lift( + callWithPointer { + uniffiRustCall() { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_ed25519publickey_to_flagged_bytes( + it, _status) +} + } + ) + } + + + companion object { @@ -32141,6 +32188,11 @@ public interface Secp256k1PublicKeyInterface { fun `toBytes`(): kotlin.ByteArray + /** + * Returns the bytes with signature scheme flag prepended + */ + fun `toFlaggedBytes`(): kotlin.ByteArray + companion object } @@ -32286,6 +32338,21 @@ open class Secp256k1PublicKey: Disposable, AutoCloseable, Secp256k1PublicKeyInte + /** + * Returns the bytes with signature scheme flag prepended + */override fun `toFlaggedBytes`(): kotlin.ByteArray { + return FfiConverterByteArray.lift( + callWithPointer { + uniffiRustCall() { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_to_flagged_bytes( + it, _status) +} + } + ) + } + + + companion object { @@ -33871,6 +33938,11 @@ public interface Secp256r1PublicKeyInterface { fun `toBytes`(): kotlin.ByteArray + /** + * Returns the bytes with signature scheme flag prepended + */ + fun `toFlaggedBytes`(): kotlin.ByteArray + companion object } @@ -34016,6 +34088,21 @@ open class Secp256r1PublicKey: Disposable, AutoCloseable, Secp256r1PublicKeyInte + /** + * Returns the bytes with signature scheme flag prepended + */override fun `toFlaggedBytes`(): kotlin.ByteArray { + return FfiConverterByteArray.lift( + callWithPointer { + uniffiRustCall() { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_to_flagged_bytes( + it, _status) +} + } + ) + } + + + companion object { diff --git a/bindings/python/examples/generate_ed25519_address.py b/bindings/python/examples/generate_ed25519_address.py index f09d681be..fd502c666 100644 --- a/bindings/python/examples/generate_ed25519_address.py +++ b/bindings/python/examples/generate_ed25519_address.py @@ -8,12 +8,11 @@ def main(): private_key = Ed25519PrivateKey.generate() private_key_bech32 = private_key.to_bech32() public_key = private_key.public_key() - public_key_bytes = public_key.to_bytes() - flagged_public_key = bytes([public_key.scheme().value]) + public_key_bytes + flagged_public_key = public_key.to_flagged_bytes() address = public_key.derive_address() print(f"Private Key: {private_key_bech32}") - print(f"Public Key: {base64_encode(public_key_bytes)}") + print(f"Public Key: {base64_encode(public_key.to_bytes())}") print(f"Public Key With Flag: {base64_encode(flagged_public_key)}") print(f"Address: {address.to_hex()}") diff --git a/bindings/python/lib/iota_sdk_ffi.py b/bindings/python/lib/iota_sdk_ffi.py index 93cea885b..21182c0df 100644 --- a/bindings/python/lib/iota_sdk_ffi.py +++ b/bindings/python/lib/iota_sdk_ffi.py @@ -625,6 +625,8 @@ def _uniffi_check_api_checksums(lib): raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_bytes() != 16656: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes() != 31806: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519signature_to_bytes() != 31911: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519verifyingkey_public_key() != 55026: @@ -1027,6 +1029,8 @@ def _uniffi_check_api_checksums(lib): raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_bytes() != 49170: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes() != 42834: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1signature_to_bytes() != 49705: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1verifier_verify_simple() != 36777: @@ -1071,6 +1075,8 @@ def _uniffi_check_api_checksums(lib): raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_bytes() != 21066: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_flagged_bytes() != 14205: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1signature_to_bytes() != 64948: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1verifier_verify_simple() != 18491: @@ -2945,6 +2951,11 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519publickey_to_bytes.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519publickey_to_flagged_bytes.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519publickey_to_flagged_bytes.restype = _UniffiRustBuffer _UniffiLib.uniffi_iota_sdk_ffi_fn_clone_ed25519signature.argtypes = ( ctypes.c_void_p, ctypes.POINTER(_UniffiRustCallStatus), @@ -5132,6 +5143,11 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_to_bytes.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_to_flagged_bytes.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_to_flagged_bytes.restype = _UniffiRustBuffer _UniffiLib.uniffi_iota_sdk_ffi_fn_clone_secp256k1signature.argtypes = ( ctypes.c_void_p, ctypes.POINTER(_UniffiRustCallStatus), @@ -5376,6 +5392,11 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_to_bytes.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_to_flagged_bytes.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_to_flagged_bytes.restype = _UniffiRustBuffer _UniffiLib.uniffi_iota_sdk_ffi_fn_clone_secp256r1signature.argtypes = ( ctypes.c_void_p, ctypes.POINTER(_UniffiRustCallStatus), @@ -7431,6 +7452,9 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_bytes.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_bytes.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519signature_to_bytes.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519signature_to_bytes.restype = ctypes.c_uint16 @@ -8034,6 +8058,9 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_bytes.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_bytes.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1signature_to_bytes.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1signature_to_bytes.restype = ctypes.c_uint16 @@ -8100,6 +8127,9 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_bytes.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_bytes.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_flagged_bytes.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_flagged_bytes.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1signature_to_bytes.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1signature_to_bytes.restype = ctypes.c_uint16 @@ -26240,6 +26270,12 @@ def scheme(self, ): raise NotImplementedError def to_bytes(self, ): + raise NotImplementedError + def to_flagged_bytes(self, ): + """ + Returns the bytes with signature scheme flag prepended + """ + raise NotImplementedError # Ed25519PublicKey is a Rust-only trait - it's a wrapper around a Rust implementation. class Ed25519PublicKey(): @@ -26343,6 +26379,19 @@ def to_bytes(self, ) -> "bytes": + def to_flagged_bytes(self, ) -> "bytes": + """ + Returns the bytes with signature scheme flag prepended + """ + + return _UniffiConverterBytes.lift( + _uniffi_rust_call(_UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519publickey_to_flagged_bytes,self._uniffi_clone_pointer(),) + ) + + + + + class _UniffiConverterTypeEd25519PublicKey: @@ -35099,6 +35148,12 @@ def scheme(self, ): raise NotImplementedError def to_bytes(self, ): + raise NotImplementedError + def to_flagged_bytes(self, ): + """ + Returns the bytes with signature scheme flag prepended + """ + raise NotImplementedError # Secp256k1PublicKey is a Rust-only trait - it's a wrapper around a Rust implementation. class Secp256k1PublicKey(): @@ -35203,6 +35258,19 @@ def to_bytes(self, ) -> "bytes": + def to_flagged_bytes(self, ) -> "bytes": + """ + Returns the bytes with signature scheme flag prepended + """ + + return _UniffiConverterBytes.lift( + _uniffi_rust_call(_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1publickey_to_flagged_bytes,self._uniffi_clone_pointer(),) + ) + + + + + class _UniffiConverterTypeSecp256k1PublicKey: @@ -35936,6 +36004,12 @@ def scheme(self, ): raise NotImplementedError def to_bytes(self, ): + raise NotImplementedError + def to_flagged_bytes(self, ): + """ + Returns the bytes with signature scheme flag prepended + """ + raise NotImplementedError # Secp256r1PublicKey is a Rust-only trait - it's a wrapper around a Rust implementation. class Secp256r1PublicKey(): @@ -36040,6 +36114,19 @@ def to_bytes(self, ) -> "bytes": + def to_flagged_bytes(self, ) -> "bytes": + """ + Returns the bytes with signature scheme flag prepended + """ + + return _UniffiConverterBytes.lift( + _uniffi_rust_call(_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1publickey_to_flagged_bytes,self._uniffi_clone_pointer(),) + ) + + + + + class _UniffiConverterTypeSecp256r1PublicKey: diff --git a/crates/iota-sdk-ffi/src/types/crypto/mod.rs b/crates/iota-sdk-ffi/src/types/crypto/mod.rs index 4cbbc167e..06537e3a0 100644 --- a/crates/iota-sdk-ffi/src/types/crypto/mod.rs +++ b/crates/iota-sdk-ffi/src/types/crypto/mod.rs @@ -91,6 +91,11 @@ impl Ed25519PublicKey { pub fn scheme(&self) -> SignatureScheme { self.0.scheme() } + + /// Returns the bytes with signature scheme flag prepended + pub fn to_flagged_bytes(&self) -> Vec { + self.0.to_flagged_bytes() + } } impl_crypto_object!( @@ -123,6 +128,11 @@ impl Secp256k1PublicKey { pub fn scheme(&self) -> SignatureScheme { self.0.scheme() } + + /// Returns the bytes with signature scheme flag prepended + pub fn to_flagged_bytes(&self) -> Vec { + self.0.to_flagged_bytes() + } } impl_crypto_object!( @@ -155,6 +165,11 @@ impl Secp256r1PublicKey { pub fn scheme(&self) -> SignatureScheme { self.0.scheme() } + + /// Returns the bytes with signature scheme flag prepended + pub fn to_flagged_bytes(&self) -> Vec { + self.0.to_flagged_bytes() + } } impl_crypto_object!( diff --git a/crates/iota-sdk-types/src/crypto/ed25519.rs b/crates/iota-sdk-types/src/crypto/ed25519.rs index 15be29266..d1bb3002e 100644 --- a/crates/iota-sdk-types/src/crypto/ed25519.rs +++ b/crates/iota-sdk-types/src/crypto/ed25519.rs @@ -64,6 +64,15 @@ impl Ed25519PublicKey { pub fn from_bytes>(bytes: T) -> Result { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } + + /// Returns the bytes with signature scheme flag prepended + pub fn to_flagged_bytes(&self) -> Vec { + let key_bytes = self.as_bytes(); + let mut bytes = Vec::with_capacity(1 + key_bytes.len()); + bytes.push(self.scheme().to_u8()); + bytes.extend_from_slice(&key_bytes); + bytes + } } impl std::str::FromStr for Ed25519PublicKey { diff --git a/crates/iota-sdk-types/src/crypto/secp256k1.rs b/crates/iota-sdk-types/src/crypto/secp256k1.rs index 03b8adcda..6aa33d6f6 100644 --- a/crates/iota-sdk-types/src/crypto/secp256k1.rs +++ b/crates/iota-sdk-types/src/crypto/secp256k1.rs @@ -66,6 +66,15 @@ impl Secp256k1PublicKey { pub fn from_bytes>(bytes: T) -> Result { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } + + /// Returns the bytes with signature scheme flag prepended + pub fn to_flagged_bytes(&self) -> Vec { + let key_bytes = self.as_bytes(); + let mut bytes = Vec::with_capacity(1 + key_bytes.len()); + bytes.push(self.scheme().to_u8()); + bytes.extend_from_slice(&key_bytes); + bytes + } } impl std::str::FromStr for Secp256k1PublicKey { diff --git a/crates/iota-sdk-types/src/crypto/secp256r1.rs b/crates/iota-sdk-types/src/crypto/secp256r1.rs index 0537702de..f8a847aa5 100644 --- a/crates/iota-sdk-types/src/crypto/secp256r1.rs +++ b/crates/iota-sdk-types/src/crypto/secp256r1.rs @@ -66,6 +66,15 @@ impl Secp256r1PublicKey { pub fn from_bytes>(bytes: T) -> Result { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } + + /// Returns the bytes with signature scheme flag prepended + pub fn to_flagged_bytes(&self) -> Vec { + let key_bytes = self.as_bytes(); + let mut bytes = Vec::with_capacity(1 + key_bytes.len()); + bytes.push(self.scheme().to_u8()); + bytes.extend_from_slice(&key_bytes); + bytes + } } impl std::str::FromStr for Secp256r1PublicKey { diff --git a/crates/iota-sdk/examples/generate_ed25519_address.rs b/crates/iota-sdk/examples/generate_ed25519_address.rs index b12b0ea92..98f3fe76b 100644 --- a/crates/iota-sdk/examples/generate_ed25519_address.rs +++ b/crates/iota-sdk/examples/generate_ed25519_address.rs @@ -9,14 +9,11 @@ fn main() { let private_key = Ed25519PrivateKey::generate(OsRng); let private_key_bech32 = private_key.to_bech32().unwrap(); let public_key = private_key.public_key(); + let flagged_public_key = Base64::encode_string(&public_key.to_flagged_bytes()); let address = public_key.derive_address(); - let mut flagged_public_key = vec![public_key.scheme().to_u8()]; - flagged_public_key.extend_from_slice(public_key.as_bytes()); - let encoded_public_key = Base64::encode_string(&flagged_public_key); - println!("Private Key: {private_key_bech32}"); println!("Public Key: {public_key}"); - println!("Public Key With Flag: {encoded_public_key}"); + println!("Public Key With Flag: {flagged_public_key}"); println!("Address: {address}"); } From 328e5edc81963fe96f4cebc1adad3062e60cf97e Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 14 Oct 2025 15:23:47 +0200 Subject: [PATCH 2/7] clibby --- crates/iota-sdk-types/src/crypto/ed25519.rs | 2 +- crates/iota-sdk-types/src/crypto/secp256k1.rs | 2 +- crates/iota-sdk-types/src/crypto/secp256r1.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/iota-sdk-types/src/crypto/ed25519.rs b/crates/iota-sdk-types/src/crypto/ed25519.rs index d1bb3002e..e8badd70a 100644 --- a/crates/iota-sdk-types/src/crypto/ed25519.rs +++ b/crates/iota-sdk-types/src/crypto/ed25519.rs @@ -70,7 +70,7 @@ impl Ed25519PublicKey { let key_bytes = self.as_bytes(); let mut bytes = Vec::with_capacity(1 + key_bytes.len()); bytes.push(self.scheme().to_u8()); - bytes.extend_from_slice(&key_bytes); + bytes.extend_from_slice(key_bytes); bytes } } diff --git a/crates/iota-sdk-types/src/crypto/secp256k1.rs b/crates/iota-sdk-types/src/crypto/secp256k1.rs index 6aa33d6f6..d98e4ed07 100644 --- a/crates/iota-sdk-types/src/crypto/secp256k1.rs +++ b/crates/iota-sdk-types/src/crypto/secp256k1.rs @@ -72,7 +72,7 @@ impl Secp256k1PublicKey { let key_bytes = self.as_bytes(); let mut bytes = Vec::with_capacity(1 + key_bytes.len()); bytes.push(self.scheme().to_u8()); - bytes.extend_from_slice(&key_bytes); + bytes.extend_from_slice(key_bytes); bytes } } diff --git a/crates/iota-sdk-types/src/crypto/secp256r1.rs b/crates/iota-sdk-types/src/crypto/secp256r1.rs index f8a847aa5..e7b9245c5 100644 --- a/crates/iota-sdk-types/src/crypto/secp256r1.rs +++ b/crates/iota-sdk-types/src/crypto/secp256r1.rs @@ -72,7 +72,7 @@ impl Secp256r1PublicKey { let key_bytes = self.as_bytes(); let mut bytes = Vec::with_capacity(1 + key_bytes.len()); bytes.push(self.scheme().to_u8()); - bytes.extend_from_slice(&key_bytes); + bytes.extend_from_slice(key_bytes); bytes } } From f1e919bb51a3dc9892d636b17b0863464c192d32 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 16 Oct 2025 16:10:04 +0200 Subject: [PATCH 3/7] fix kt bindings --- bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt b/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt index 61798d15a..903503196 100644 --- a/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt +++ b/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt @@ -2396,8 +2396,6 @@ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback { -<<<<<<< HEAD -======= @@ -2426,7 +2424,12 @@ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback { ->>>>>>> sdk-bindings + + + + + + // For large crates we prevent `MethodTooLargeException` (see #2340) // N.B. the name of the extension is very misleading, since it is // rather `InterfaceTooLargeException`, caused by too many methods From d34923e8aaa318029662948b667c9b0764357465 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 21 Oct 2025 14:54:02 +0200 Subject: [PATCH 4/7] add PublicKeyExt trait --- crates/iota-crypto/src/simple.rs | 2 +- crates/iota-sdk-ffi/src/types/crypto/mod.rs | 2 +- crates/iota-sdk-types/src/crypto/ed25519.rs | 20 ++++++++++-------- crates/iota-sdk-types/src/crypto/mod.rs | 20 ++++++++++++++++++ crates/iota-sdk-types/src/crypto/secp256k1.rs | 20 ++++++++++-------- crates/iota-sdk-types/src/crypto/secp256r1.rs | 20 ++++++++++-------- crates/iota-sdk-types/src/crypto/signature.rs | 21 ------------------- crates/iota-sdk-types/src/hash.rs | 2 +- crates/iota-sdk-types/src/lib.rs | 2 +- .../examples/generate_ed25519_address.rs | 1 + 10 files changed, 58 insertions(+), 52 deletions(-) diff --git a/crates/iota-crypto/src/simple.rs b/crates/iota-crypto/src/simple.rs index 8830d74d3..12ba37c78 100644 --- a/crates/iota-crypto/src/simple.rs +++ b/crates/iota-crypto/src/simple.rs @@ -78,7 +78,7 @@ pub use keypair::{SimpleKeypair, SimpleVerifyingKey}; )] mod keypair { use iota_sdk_types::{ - MultisigMemberPublicKey, SignatureScheme, SimpleSignature, UserSignature, + MultisigMemberPublicKey, PublicKeyExt, SignatureScheme, SimpleSignature, UserSignature, }; use signature::{Signer, Verifier}; diff --git a/crates/iota-sdk-ffi/src/types/crypto/mod.rs b/crates/iota-sdk-ffi/src/types/crypto/mod.rs index 06537e3a0..77c672168 100644 --- a/crates/iota-sdk-ffi/src/types/crypto/mod.rs +++ b/crates/iota-sdk-ffi/src/types/crypto/mod.rs @@ -7,7 +7,7 @@ pub mod zklogin; use std::sync::Arc; -use iota_types::SignatureScheme; +use iota_types::{PublicKeyExt, SignatureScheme}; use crate::{ error::Result, diff --git a/crates/iota-sdk-types/src/crypto/ed25519.rs b/crates/iota-sdk-types/src/crypto/ed25519.rs index e8badd70a..4fa07669a 100644 --- a/crates/iota-sdk-types/src/crypto/ed25519.rs +++ b/crates/iota-sdk-types/src/crypto/ed25519.rs @@ -4,6 +4,8 @@ //! Implementation of ed25519 public-key cryptogrophy. +use crate::crypto::{PublicKeyExt, SignatureScheme}; + /// An ed25519 public key. /// /// # BCS @@ -56,22 +58,22 @@ impl Ed25519PublicKey { pub const fn inner(&self) -> &[u8; Self::LENGTH] { &self.0 } +} - pub const fn as_bytes(&self) -> &[u8] { +impl PublicKeyExt for Ed25519PublicKey { + // Returns the public key as bytes. + fn as_bytes(&self) -> &[u8] { &self.0 } - pub fn from_bytes>(bytes: T) -> Result { + /// Tries to create an Ed25519PublicKey from bytes. + fn from_bytes>(bytes: T) -> Result { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } - /// Returns the bytes with signature scheme flag prepended - pub fn to_flagged_bytes(&self) -> Vec { - let key_bytes = self.as_bytes(); - let mut bytes = Vec::with_capacity(1 + key_bytes.len()); - bytes.push(self.scheme().to_u8()); - bytes.extend_from_slice(key_bytes); - bytes + /// Returns the flag for this signature scheme. + fn scheme(&self) -> SignatureScheme { + SignatureScheme::Ed25519 } } diff --git a/crates/iota-sdk-types/src/crypto/mod.rs b/crates/iota-sdk-types/src/crypto/mod.rs index a1867df82..3bc036bc5 100644 --- a/crates/iota-sdk-types/src/crypto/mod.rs +++ b/crates/iota-sdk-types/src/crypto/mod.rs @@ -151,3 +151,23 @@ impl_base64_helper!(Base64Array34, Base64Display34, Base64FromStr34, test34, 34) impl_base64_helper!(Base64Array48, Base64Display48, Base64FromStr48, test48, 48); impl_base64_helper!(Base64Array64, Base64Display64, Base64FromStr64, test64, 64); impl_base64_helper!(Base64Array96, Base64Display96, Base64FromStr96, test96, 96); + +pub trait PublicKeyExt: Sized { + // Returns the public key as bytes. + fn as_bytes(&self) -> &[u8]; + + /// Tries to create a PublicKey from bytes. + fn from_bytes>(bytes: T) -> Result; + + /// Returns the flag for this signature scheme. + fn scheme(&self) -> SignatureScheme; + + /// Returns the bytes with signature scheme flag prepended + fn to_flagged_bytes(&self) -> Vec { + let key_bytes = self.as_bytes(); + let mut bytes = Vec::with_capacity(1 + key_bytes.len()); + bytes.push(self.scheme().to_u8()); + bytes.extend_from_slice(key_bytes); + bytes + } +} diff --git a/crates/iota-sdk-types/src/crypto/secp256k1.rs b/crates/iota-sdk-types/src/crypto/secp256k1.rs index d98e4ed07..c99b25bf2 100644 --- a/crates/iota-sdk-types/src/crypto/secp256k1.rs +++ b/crates/iota-sdk-types/src/crypto/secp256k1.rs @@ -4,6 +4,8 @@ //! Implementation of secp256k1 public-key cryptogrophy. +use crate::crypto::{PublicKeyExt, SignatureScheme}; + /// A secp256k1 public key. /// /// # BCS @@ -58,22 +60,22 @@ impl Secp256k1PublicKey { pub const fn inner(&self) -> &[u8; Self::LENGTH] { &self.0 } +} - pub const fn as_bytes(&self) -> &[u8] { +impl PublicKeyExt for Secp256k1PublicKey { + // Returns the public key as bytes. + fn as_bytes(&self) -> &[u8] { &self.0 } - pub fn from_bytes>(bytes: T) -> Result { + /// Tries to create a Secp256k1PublicKey from bytes. + fn from_bytes>(bytes: T) -> Result { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } - /// Returns the bytes with signature scheme flag prepended - pub fn to_flagged_bytes(&self) -> Vec { - let key_bytes = self.as_bytes(); - let mut bytes = Vec::with_capacity(1 + key_bytes.len()); - bytes.push(self.scheme().to_u8()); - bytes.extend_from_slice(key_bytes); - bytes + /// Returns the flag for this signature scheme. + fn scheme(&self) -> SignatureScheme { + SignatureScheme::Secp256k1 } } diff --git a/crates/iota-sdk-types/src/crypto/secp256r1.rs b/crates/iota-sdk-types/src/crypto/secp256r1.rs index e7b9245c5..876df0dd8 100644 --- a/crates/iota-sdk-types/src/crypto/secp256r1.rs +++ b/crates/iota-sdk-types/src/crypto/secp256r1.rs @@ -4,6 +4,8 @@ //! Implementation of secp256r1 public-key cryptogrophy. +use crate::crypto::{PublicKeyExt, SignatureScheme}; + /// A secp256r1 public key. /// /// # BCS @@ -58,22 +60,22 @@ impl Secp256r1PublicKey { pub const fn inner(&self) -> &[u8; Self::LENGTH] { &self.0 } +} - pub const fn as_bytes(&self) -> &[u8] { +impl PublicKeyExt for Secp256r1PublicKey { + // Returns the public key as bytes. + fn as_bytes(&self) -> &[u8] { &self.0 } - pub fn from_bytes>(bytes: T) -> Result { + /// Tries to create a Secp256r1PublicKey from bytes. + fn from_bytes>(bytes: T) -> Result { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } - /// Returns the bytes with signature scheme flag prepended - pub fn to_flagged_bytes(&self) -> Vec { - let key_bytes = self.as_bytes(); - let mut bytes = Vec::with_capacity(1 + key_bytes.len()); - bytes.push(self.scheme().to_u8()); - bytes.extend_from_slice(key_bytes); - bytes + /// Returns the flag for this signature scheme. + fn scheme(&self) -> SignatureScheme { + SignatureScheme::Secp256r1 } } diff --git a/crates/iota-sdk-types/src/crypto/signature.rs b/crates/iota-sdk-types/src/crypto/signature.rs index 12d8caa3c..d1dc67fac 100644 --- a/crates/iota-sdk-types/src/crypto/signature.rs +++ b/crates/iota-sdk-types/src/crypto/signature.rs @@ -263,27 +263,6 @@ impl SignatureScheme { } } -impl Ed25519PublicKey { - /// Return the flag for this signature scheme - pub fn scheme(&self) -> SignatureScheme { - SignatureScheme::Ed25519 - } -} - -impl Secp256k1PublicKey { - /// Return the flag for this signature scheme - pub fn scheme(&self) -> SignatureScheme { - SignatureScheme::Secp256k1 - } -} - -impl Secp256r1PublicKey { - /// Return the flag for this signature scheme - pub fn scheme(&self) -> SignatureScheme { - SignatureScheme::Secp256r1 - } -} - impl super::ZkLoginPublicIdentifier { /// Return the flag for this signature scheme pub fn scheme(&self) -> SignatureScheme { diff --git a/crates/iota-sdk-types/src/hash.rs b/crates/iota-sdk-types/src/hash.rs index 899583235..54a66ed51 100644 --- a/crates/iota-sdk-types/src/hash.rs +++ b/crates/iota-sdk-types/src/hash.rs @@ -4,7 +4,7 @@ use blake2::Digest as DigestTrait; -use crate::{Address, Digest}; +use crate::{Address, Digest, PublicKeyExt}; type Blake2b256 = blake2::Blake2b; diff --git a/crates/iota-sdk-types/src/lib.rs b/crates/iota-sdk-types/src/lib.rs index ff0e632f7..63389f3ad 100644 --- a/crates/iota-sdk-types/src/lib.rs +++ b/crates/iota-sdk-types/src/lib.rs @@ -139,7 +139,7 @@ pub use crypto::{ Ed25519Signature, Intent, IntentAppId, IntentScope, IntentVersion, InvalidSignatureScheme, InvalidZkLoginAuthenticatorError, Jwk, JwkId, MultisigAggregatedSignature, MultisigCommittee, MultisigMember, MultisigMemberPublicKey, MultisigMemberSignature, PasskeyAuthenticator, - PasskeyPublicKey, Secp256k1PublicKey, Secp256k1Signature, Secp256r1PublicKey, + PasskeyPublicKey, PublicKeyExt, Secp256k1PublicKey, Secp256k1Signature, Secp256r1PublicKey, Secp256r1Signature, SignatureScheme, SimpleSignature, UserSignature, ZkLoginAuthenticator, ZkLoginClaim, ZkLoginInputs, ZkLoginProof, ZkLoginPublicIdentifier, }; diff --git a/crates/iota-sdk/examples/generate_ed25519_address.rs b/crates/iota-sdk/examples/generate_ed25519_address.rs index 98f3fe76b..aa9337d2b 100644 --- a/crates/iota-sdk/examples/generate_ed25519_address.rs +++ b/crates/iota-sdk/examples/generate_ed25519_address.rs @@ -3,6 +3,7 @@ use base64ct::{Base64, Encoding}; use iota_crypto::{PrivateKeyExt, ed25519::Ed25519PrivateKey}; +use iota_types::PublicKeyExt; use rand::rngs::OsRng; fn main() { From 5e0d9e53f60968b2f315213823724a5edfc7579d Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 21 Oct 2025 15:58:30 +0200 Subject: [PATCH 5/7] docs nits --- crates/iota-sdk-types/src/crypto/ed25519.rs | 2 +- crates/iota-sdk-types/src/crypto/mod.rs | 2 +- crates/iota-sdk-types/src/crypto/secp256k1.rs | 2 +- crates/iota-sdk-types/src/crypto/secp256r1.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/iota-sdk-types/src/crypto/ed25519.rs b/crates/iota-sdk-types/src/crypto/ed25519.rs index 4fa07669a..039056f1b 100644 --- a/crates/iota-sdk-types/src/crypto/ed25519.rs +++ b/crates/iota-sdk-types/src/crypto/ed25519.rs @@ -71,7 +71,7 @@ impl PublicKeyExt for Ed25519PublicKey { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } - /// Returns the flag for this signature scheme. + /// Returns the signature scheme for this public key. fn scheme(&self) -> SignatureScheme { SignatureScheme::Ed25519 } diff --git a/crates/iota-sdk-types/src/crypto/mod.rs b/crates/iota-sdk-types/src/crypto/mod.rs index 3bc036bc5..24fde1a0b 100644 --- a/crates/iota-sdk-types/src/crypto/mod.rs +++ b/crates/iota-sdk-types/src/crypto/mod.rs @@ -159,7 +159,7 @@ pub trait PublicKeyExt: Sized { /// Tries to create a PublicKey from bytes. fn from_bytes>(bytes: T) -> Result; - /// Returns the flag for this signature scheme. + /// Returns the signature scheme for this public key. fn scheme(&self) -> SignatureScheme; /// Returns the bytes with signature scheme flag prepended diff --git a/crates/iota-sdk-types/src/crypto/secp256k1.rs b/crates/iota-sdk-types/src/crypto/secp256k1.rs index c99b25bf2..a09469e9e 100644 --- a/crates/iota-sdk-types/src/crypto/secp256k1.rs +++ b/crates/iota-sdk-types/src/crypto/secp256k1.rs @@ -73,7 +73,7 @@ impl PublicKeyExt for Secp256k1PublicKey { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } - /// Returns the flag for this signature scheme. + /// Returns the signature scheme for this public key. fn scheme(&self) -> SignatureScheme { SignatureScheme::Secp256k1 } diff --git a/crates/iota-sdk-types/src/crypto/secp256r1.rs b/crates/iota-sdk-types/src/crypto/secp256r1.rs index 876df0dd8..0c9e5cf83 100644 --- a/crates/iota-sdk-types/src/crypto/secp256r1.rs +++ b/crates/iota-sdk-types/src/crypto/secp256r1.rs @@ -73,7 +73,7 @@ impl PublicKeyExt for Secp256r1PublicKey { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } - /// Returns the flag for this signature scheme. + /// Returns the signature scheme for this public key. fn scheme(&self) -> SignatureScheme { SignatureScheme::Secp256r1 } From 5b791182581eac38db0f15f2e194f37378530f2b Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 21 Oct 2025 16:01:53 +0200 Subject: [PATCH 6/7] docs nits --- bindings/go/iota_sdk_ffi/iota_sdk_ffi.go | 30 ++++++++++---------- bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt | 30 ++++++++++---------- bindings/python/lib/iota_sdk_ffi.py | 30 ++++++++++---------- crates/iota-sdk-ffi/src/types/crypto/mod.rs | 10 +++---- 4 files changed, 50 insertions(+), 50 deletions(-) diff --git a/bindings/go/iota_sdk_ffi/iota_sdk_ffi.go b/bindings/go/iota_sdk_ffi/iota_sdk_ffi.go index 45a166a09..578bcc69c 100644 --- a/bindings/go/iota_sdk_ffi/iota_sdk_ffi.go +++ b/bindings/go/iota_sdk_ffi/iota_sdk_ffi.go @@ -1091,7 +1091,7 @@ func uniffiCheckChecksums() { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_scheme() }) - if checksum != 141 { + if checksum != 3041 { // If this happens try cleaning and rebuilding your project panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_scheme: UniFFI API checksum mismatch") } @@ -1109,7 +1109,7 @@ func uniffiCheckChecksums() { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes() }) - if checksum != 31806 { + if checksum != 62359 { // If this happens try cleaning and rebuilding your project panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes: UniFFI API checksum mismatch") } @@ -2945,7 +2945,7 @@ func uniffiCheckChecksums() { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_scheme() }) - if checksum != 798 { + if checksum != 60874 { // If this happens try cleaning and rebuilding your project panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_scheme: UniFFI API checksum mismatch") } @@ -2963,7 +2963,7 @@ func uniffiCheckChecksums() { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes() }) - if checksum != 42834 { + if checksum != 46673 { // If this happens try cleaning and rebuilding your project panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes: UniFFI API checksum mismatch") } @@ -3152,7 +3152,7 @@ func uniffiCheckChecksums() { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_scheme() }) - if checksum != 12227 { + if checksum != 48083 { // If this happens try cleaning and rebuilding your project panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_scheme: UniFFI API checksum mismatch") } @@ -10896,10 +10896,10 @@ type Ed25519PublicKeyInterface interface { // // `hash(32-byte ed25519 public key)` DeriveAddress() *Address - // Return the flag for this signature scheme + // Returns the signature scheme for this public key. Scheme() SignatureScheme ToBytes() []byte - // Returns the bytes with signature scheme flag prepended + // Returns the bytes with signature scheme flag prepended. ToFlaggedBytes() []byte } // An ed25519 public key. @@ -10963,7 +10963,7 @@ func (_self *Ed25519PublicKey) DeriveAddress() *Address { })) } -// Return the flag for this signature scheme +// Returns the signature scheme for this public key. func (_self *Ed25519PublicKey) Scheme() SignatureScheme { _pointer := _self.ffiObject.incrementPointer("*Ed25519PublicKey") defer _self.ffiObject.decrementPointer() @@ -10986,7 +10986,7 @@ func (_self *Ed25519PublicKey) ToBytes() []byte { })) } -// Returns the bytes with signature scheme flag prepended +// Returns the bytes with signature scheme flag prepended. func (_self *Ed25519PublicKey) ToFlaggedBytes() []byte { _pointer := _self.ffiObject.incrementPointer("*Ed25519PublicKey") defer _self.ffiObject.decrementPointer() @@ -19423,10 +19423,10 @@ type Secp256k1PublicKeyInterface interface { // // `hash( 0x01 || 33-byte secp256k1 public key)` DeriveAddress() *Address - // Return the flag for this signature scheme + // Returns the signature scheme for this public key. Scheme() SignatureScheme ToBytes() []byte - // Returns the bytes with signature scheme flag prepended + // Returns the bytes with signature scheme flag prepended. ToFlaggedBytes() []byte } // A secp256k1 signature. @@ -19491,7 +19491,7 @@ func (_self *Secp256k1PublicKey) DeriveAddress() *Address { })) } -// Return the flag for this signature scheme +// Returns the signature scheme for this public key. func (_self *Secp256k1PublicKey) Scheme() SignatureScheme { _pointer := _self.ffiObject.incrementPointer("*Secp256k1PublicKey") defer _self.ffiObject.decrementPointer() @@ -19514,7 +19514,7 @@ func (_self *Secp256k1PublicKey) ToBytes() []byte { })) } -// Returns the bytes with signature scheme flag prepended +// Returns the bytes with signature scheme flag prepended. func (_self *Secp256k1PublicKey) ToFlaggedBytes() []byte { _pointer := _self.ffiObject.incrementPointer("*Secp256k1PublicKey") defer _self.ffiObject.decrementPointer() @@ -20270,7 +20270,7 @@ type Secp256r1PublicKeyInterface interface { // // `hash( 0x02 || 33-byte secp256r1 public key)` DeriveAddress() *Address - // Return the flag for this signature scheme + // Returns the signature scheme for this public key. Scheme() SignatureScheme ToBytes() []byte // Returns the bytes with signature scheme flag prepended @@ -20338,7 +20338,7 @@ func (_self *Secp256r1PublicKey) DeriveAddress() *Address { })) } -// Return the flag for this signature scheme +// Returns the signature scheme for this public key. func (_self *Secp256r1PublicKey) Scheme() SignatureScheme { _pointer := _self.ffiObject.incrementPointer("*Secp256r1PublicKey") defer _self.ffiObject.decrementPointer() diff --git a/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt b/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt index 48a278689..0674d7575 100644 --- a/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt +++ b/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt @@ -6381,13 +6381,13 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_derive_address() != 37757.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_scheme() != 141.toShort()) { + if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_scheme() != 3041.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_bytes() != 16656.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes() != 31806.toShort()) { + if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes() != 62359.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519signature_to_bytes() != 31911.toShort()) { @@ -6999,13 +6999,13 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_derive_address() != 48490.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_scheme() != 798.toShort()) { + if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_scheme() != 60874.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_bytes() != 49170.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes() != 42834.toShort()) { + if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes() != 46673.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1signature_to_bytes() != 49705.toShort()) { @@ -7068,7 +7068,7 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_derive_address() != 27344.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_scheme() != 12227.toShort()) { + if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_scheme() != 48083.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_bytes() != 21066.toShort()) { @@ -16396,14 +16396,14 @@ public interface Ed25519PublicKeyInterface { fun `deriveAddress`(): Address /** - * Return the flag for this signature scheme + * Returns the signature scheme for this public key. */ fun `scheme`(): SignatureScheme fun `toBytes`(): kotlin.ByteArray /** - * Returns the bytes with signature scheme flag prepended + * Returns the bytes with signature scheme flag prepended. */ fun `toFlaggedBytes`(): kotlin.ByteArray @@ -16525,7 +16525,7 @@ open class Ed25519PublicKey: Disposable, AutoCloseable, Ed25519PublicKeyInterfac /** - * Return the flag for this signature scheme + * Returns the signature scheme for this public key. */override fun `scheme`(): SignatureScheme { return FfiConverterTypeSignatureScheme.lift( callWithPointer { @@ -16552,7 +16552,7 @@ open class Ed25519PublicKey: Disposable, AutoCloseable, Ed25519PublicKeyInterfac /** - * Returns the bytes with signature scheme flag prepended + * Returns the bytes with signature scheme flag prepended. */override fun `toFlaggedBytes`(): kotlin.ByteArray { return FfiConverterByteArray.lift( callWithPointer { @@ -32781,14 +32781,14 @@ public interface Secp256k1PublicKeyInterface { fun `deriveAddress`(): Address /** - * Return the flag for this signature scheme + * Returns the signature scheme for this public key. */ fun `scheme`(): SignatureScheme fun `toBytes`(): kotlin.ByteArray /** - * Returns the bytes with signature scheme flag prepended + * Returns the bytes with signature scheme flag prepended. */ fun `toFlaggedBytes`(): kotlin.ByteArray @@ -32911,7 +32911,7 @@ open class Secp256k1PublicKey: Disposable, AutoCloseable, Secp256k1PublicKeyInte /** - * Return the flag for this signature scheme + * Returns the signature scheme for this public key. */override fun `scheme`(): SignatureScheme { return FfiConverterTypeSignatureScheme.lift( callWithPointer { @@ -32938,7 +32938,7 @@ open class Secp256k1PublicKey: Disposable, AutoCloseable, Secp256k1PublicKeyInte /** - * Returns the bytes with signature scheme flag prepended + * Returns the bytes with signature scheme flag prepended. */override fun `toFlaggedBytes`(): kotlin.ByteArray { return FfiConverterByteArray.lift( callWithPointer { @@ -34531,7 +34531,7 @@ public interface Secp256r1PublicKeyInterface { fun `deriveAddress`(): Address /** - * Return the flag for this signature scheme + * Returns the signature scheme for this public key. */ fun `scheme`(): SignatureScheme @@ -34661,7 +34661,7 @@ open class Secp256r1PublicKey: Disposable, AutoCloseable, Secp256r1PublicKeyInte /** - * Return the flag for this signature scheme + * Returns the signature scheme for this public key. */override fun `scheme`(): SignatureScheme { return FfiConverterTypeSignatureScheme.lift( callWithPointer { diff --git a/bindings/python/lib/iota_sdk_ffi.py b/bindings/python/lib/iota_sdk_ffi.py index 60157fae2..be31d4003 100644 --- a/bindings/python/lib/iota_sdk_ffi.py +++ b/bindings/python/lib/iota_sdk_ffi.py @@ -623,11 +623,11 @@ def _uniffi_check_api_checksums(lib): raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_derive_address() != 37757: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_scheme() != 141: + if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_scheme() != 3041: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_bytes() != 16656: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes() != 31806: + if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519publickey_to_flagged_bytes() != 62359: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519signature_to_bytes() != 31911: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") @@ -1035,11 +1035,11 @@ def _uniffi_check_api_checksums(lib): raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_derive_address() != 48490: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_scheme() != 798: + if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_scheme() != 60874: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_bytes() != 49170: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes() != 42834: + if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1publickey_to_flagged_bytes() != 46673: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1signature_to_bytes() != 49705: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") @@ -1081,7 +1081,7 @@ def _uniffi_check_api_checksums(lib): raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_derive_address() != 27344: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_scheme() != 12227: + if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_scheme() != 48083: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1publickey_to_bytes() != 21066: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") @@ -26557,7 +26557,7 @@ def derive_address(self, ): raise NotImplementedError def scheme(self, ): """ - Return the flag for this signature scheme + Returns the signature scheme for this public key. """ raise NotImplementedError @@ -26565,7 +26565,7 @@ def to_bytes(self, ): raise NotImplementedError def to_flagged_bytes(self, ): """ - Returns the bytes with signature scheme flag prepended + Returns the bytes with signature scheme flag prepended. """ raise NotImplementedError @@ -26651,7 +26651,7 @@ def derive_address(self, ) -> "Address": def scheme(self, ) -> "SignatureScheme": """ - Return the flag for this signature scheme + Returns the signature scheme for this public key. """ return _UniffiConverterTypeSignatureScheme.lift( @@ -26673,7 +26673,7 @@ def to_bytes(self, ) -> "bytes": def to_flagged_bytes(self, ) -> "bytes": """ - Returns the bytes with signature scheme flag prepended + Returns the bytes with signature scheme flag prepended. """ return _UniffiConverterBytes.lift( @@ -35584,7 +35584,7 @@ def derive_address(self, ): raise NotImplementedError def scheme(self, ): """ - Return the flag for this signature scheme + Returns the signature scheme for this public key. """ raise NotImplementedError @@ -35592,7 +35592,7 @@ def to_bytes(self, ): raise NotImplementedError def to_flagged_bytes(self, ): """ - Returns the bytes with signature scheme flag prepended + Returns the bytes with signature scheme flag prepended. """ raise NotImplementedError @@ -35679,7 +35679,7 @@ def derive_address(self, ) -> "Address": def scheme(self, ) -> "SignatureScheme": """ - Return the flag for this signature scheme + Returns the signature scheme for this public key. """ return _UniffiConverterTypeSignatureScheme.lift( @@ -35701,7 +35701,7 @@ def to_bytes(self, ) -> "bytes": def to_flagged_bytes(self, ) -> "bytes": """ - Returns the bytes with signature scheme flag prepended + Returns the bytes with signature scheme flag prepended. """ return _UniffiConverterBytes.lift( @@ -36440,7 +36440,7 @@ def derive_address(self, ): raise NotImplementedError def scheme(self, ): """ - Return the flag for this signature scheme + Returns the signature scheme for this public key. """ raise NotImplementedError @@ -36535,7 +36535,7 @@ def derive_address(self, ) -> "Address": def scheme(self, ) -> "SignatureScheme": """ - Return the flag for this signature scheme + Returns the signature scheme for this public key. """ return _UniffiConverterTypeSignatureScheme.lift( diff --git a/crates/iota-sdk-ffi/src/types/crypto/mod.rs b/crates/iota-sdk-ffi/src/types/crypto/mod.rs index 77c672168..10796b359 100644 --- a/crates/iota-sdk-ffi/src/types/crypto/mod.rs +++ b/crates/iota-sdk-ffi/src/types/crypto/mod.rs @@ -87,12 +87,12 @@ impl Ed25519PublicKey { self.0.derive_address().into() } - /// Return the flag for this signature scheme + /// Returns the signature scheme for this public key. pub fn scheme(&self) -> SignatureScheme { self.0.scheme() } - /// Returns the bytes with signature scheme flag prepended + /// Returns the bytes with signature scheme flag prepended. pub fn to_flagged_bytes(&self) -> Vec { self.0.to_flagged_bytes() } @@ -124,12 +124,12 @@ impl Secp256k1PublicKey { self.0.derive_address().into() } - /// Return the flag for this signature scheme + /// Returns the signature scheme for this public key. pub fn scheme(&self) -> SignatureScheme { self.0.scheme() } - /// Returns the bytes with signature scheme flag prepended + /// Returns the bytes with signature scheme flag prepended. pub fn to_flagged_bytes(&self) -> Vec { self.0.to_flagged_bytes() } @@ -161,7 +161,7 @@ impl Secp256r1PublicKey { self.0.derive_address().into() } - /// Return the flag for this signature scheme + /// Returns the signature scheme for this public key. pub fn scheme(&self) -> SignatureScheme { self.0.scheme() } From 3a6a08cc3e6d7c4604efc1d0fd318345c1733370 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 21 Oct 2025 16:39:15 +0200 Subject: [PATCH 7/7] FromBytesErr --- crates/iota-sdk-types/src/crypto/ed25519.rs | 6 ++++-- crates/iota-sdk-types/src/crypto/mod.rs | 6 ++++-- crates/iota-sdk-types/src/crypto/secp256k1.rs | 6 ++++-- crates/iota-sdk-types/src/crypto/secp256r1.rs | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/crates/iota-sdk-types/src/crypto/ed25519.rs b/crates/iota-sdk-types/src/crypto/ed25519.rs index 039056f1b..e85493b8e 100644 --- a/crates/iota-sdk-types/src/crypto/ed25519.rs +++ b/crates/iota-sdk-types/src/crypto/ed25519.rs @@ -61,13 +61,15 @@ impl Ed25519PublicKey { } impl PublicKeyExt for Ed25519PublicKey { - // Returns the public key as bytes. + type FromBytesErr = std::array::TryFromSliceError; + + /// Returns the public key as bytes. fn as_bytes(&self) -> &[u8] { &self.0 } /// Tries to create an Ed25519PublicKey from bytes. - fn from_bytes>(bytes: T) -> Result { + fn from_bytes>(bytes: T) -> Result { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } diff --git a/crates/iota-sdk-types/src/crypto/mod.rs b/crates/iota-sdk-types/src/crypto/mod.rs index 24fde1a0b..091131a46 100644 --- a/crates/iota-sdk-types/src/crypto/mod.rs +++ b/crates/iota-sdk-types/src/crypto/mod.rs @@ -153,11 +153,13 @@ impl_base64_helper!(Base64Array64, Base64Display64, Base64FromStr64, test64, 64) impl_base64_helper!(Base64Array96, Base64Display96, Base64FromStr96, test96, 96); pub trait PublicKeyExt: Sized { - // Returns the public key as bytes. + type FromBytesErr; + + /// Returns the public key as bytes. fn as_bytes(&self) -> &[u8]; /// Tries to create a PublicKey from bytes. - fn from_bytes>(bytes: T) -> Result; + fn from_bytes>(bytes: T) -> Result; /// Returns the signature scheme for this public key. fn scheme(&self) -> SignatureScheme; diff --git a/crates/iota-sdk-types/src/crypto/secp256k1.rs b/crates/iota-sdk-types/src/crypto/secp256k1.rs index a09469e9e..cad2366c7 100644 --- a/crates/iota-sdk-types/src/crypto/secp256k1.rs +++ b/crates/iota-sdk-types/src/crypto/secp256k1.rs @@ -63,13 +63,15 @@ impl Secp256k1PublicKey { } impl PublicKeyExt for Secp256k1PublicKey { - // Returns the public key as bytes. + type FromBytesErr = std::array::TryFromSliceError; + + /// Returns the public key as bytes. fn as_bytes(&self) -> &[u8] { &self.0 } /// Tries to create a Secp256k1PublicKey from bytes. - fn from_bytes>(bytes: T) -> Result { + fn from_bytes>(bytes: T) -> Result { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) } diff --git a/crates/iota-sdk-types/src/crypto/secp256r1.rs b/crates/iota-sdk-types/src/crypto/secp256r1.rs index 0c9e5cf83..153c48c03 100644 --- a/crates/iota-sdk-types/src/crypto/secp256r1.rs +++ b/crates/iota-sdk-types/src/crypto/secp256r1.rs @@ -63,13 +63,15 @@ impl Secp256r1PublicKey { } impl PublicKeyExt for Secp256r1PublicKey { - // Returns the public key as bytes. + type FromBytesErr = std::array::TryFromSliceError; + + /// Returns the public key as bytes. fn as_bytes(&self) -> &[u8] { &self.0 } /// Tries to create a Secp256r1PublicKey from bytes. - fn from_bytes>(bytes: T) -> Result { + fn from_bytes>(bytes: T) -> Result { <[u8; Self::LENGTH]>::try_from(bytes.as_ref()).map(Self) }