diff --git a/bindings/go/examples/generate_ed25519_address/main.go b/bindings/go/examples/generate_ed25519_address/main.go index 2e25ba4b5..acae6236a 100644 --- a/bindings/go/examples/generate_ed25519_address/main.go +++ b/bindings/go/examples/generate_ed25519_address/main.go @@ -11,17 +11,17 @@ import ( func main() { privateKey := sdk.Ed25519PrivateKeyGenerate() + privateKeyBech32, err := privateKey.ToBech32() + if err != nil { + panic(err) + } publicKey := privateKey.PublicKey() address := publicKey.DeriveAddress() publicKeyBytes := publicKey.ToBytes() flaggedPublicKey := append([]byte{byte(sdk.SignatureSchemeEd25519)}, publicKeyBytes...) - privateKeyDer, err := privateKey.ToDer() - if err != nil { - panic(err) - } - fmt.Println("Private Key:", sdk.Base64Encode(privateKeyDer)) + fmt.Println("Private Key:", privateKeyBech32) fmt.Println("Public Key:", sdk.Base64Encode(publicKeyBytes)) 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 fd9db43bf..71476f741 100644 --- a/bindings/go/iota_sdk_ffi/iota_sdk_ffi.go +++ b/bindings/go/iota_sdk_ffi/iota_sdk_ffi.go @@ -998,6 +998,24 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bech32() + }) + if checksum != 64514 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bech32: UniFFI API checksum mismatch") + } + } + { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bytes() + }) + if checksum != 26261 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bytes: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_der() }) @@ -2663,6 +2681,24 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bech32() + }) + if checksum != 60488 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bech32: UniFFI API checksum mismatch") + } + } + { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bytes() + }) + if checksum != 18583 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bytes: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_der() }) @@ -2843,6 +2879,24 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bech32() + }) + if checksum != 4230 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bech32: UniFFI API checksum mismatch") + } + } + { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bytes() + }) + if checksum != 8648 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bytes: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_der() }) @@ -3023,6 +3077,24 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bech32() + }) + if checksum != 4776 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bech32: UniFFI API checksum mismatch") + } + } + { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bytes() + }) + if checksum != 1555 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bytes: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_der() }) @@ -4652,6 +4724,15 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_bech32() + }) + if checksum != 16842 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_bech32: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_der() }) @@ -5417,6 +5498,15 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_bech32() + }) + if checksum != 34529 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_bech32: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_der() }) @@ -5543,6 +5633,15 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_bech32() + }) + if checksum != 7016 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_bech32: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_der() }) @@ -5669,6 +5768,24 @@ func uniffiCheckChecksums() { } } { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bech32() + }) + if checksum != 51811 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bech32: UniFFI API checksum mismatch") + } + } + { + checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { + return C.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bytes() + }) + if checksum != 9299 { + // If this happens try cleaning and rebuilding your project + panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bytes: UniFFI API checksum mismatch") + } + } + { checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t { return C.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_der() }) @@ -9536,6 +9653,11 @@ func (_ FfiDestroyerDigest) Destroy(value *Digest) { type Ed25519PrivateKeyInterface interface { PublicKey() *Ed25519PublicKey Scheme() SignatureScheme + // Encode this private key as `flag || privkey` in Bech32 starting with + // "iotaprivkey" to a string. + ToBech32() (string, error) + // Serialize this private key to bytes. + ToBytes() []byte // Serialize this private key as DER-encoded PKCS#8 ToDer() ([]byte, error) // Serialize this private key as PEM-encoded PKCS#8 @@ -9561,6 +9683,20 @@ func NewEd25519PrivateKey(bytes []byte) (*Ed25519PrivateKey, error) { } +// Decode a private key from `flag || privkey` in Bech32 starting with +// "iotaprivkey". +func Ed25519PrivateKeyFromBech32(value string) (*Ed25519PrivateKey, error) { + _uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer { + return C.uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_bech32(FfiConverterStringINSTANCE.Lower(value),_uniffiStatus) + }) + if _uniffiErr != nil { + var _uniffiDefaultValue *Ed25519PrivateKey + return _uniffiDefaultValue, _uniffiErr + } else { + return FfiConverterEd25519PrivateKeyINSTANCE.Lift(_uniffiRV), nil + } +} + // Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary // format). func Ed25519PrivateKeyFromDer(bytes []byte) (*Ed25519PrivateKey, error) { @@ -9616,6 +9752,37 @@ func (_self *Ed25519PrivateKey) Scheme() SignatureScheme { })) } +// Encode this private key as `flag || privkey` in Bech32 starting with +// "iotaprivkey" to a string. +func (_self *Ed25519PrivateKey) ToBech32() (string, error) { + _pointer := _self.ffiObject.incrementPointer("*Ed25519PrivateKey") + defer _self.ffiObject.decrementPointer() + _uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bech32( + _pointer,_uniffiStatus), + } + }) + if _uniffiErr != nil { + var _uniffiDefaultValue string + return _uniffiDefaultValue, _uniffiErr + } else { + return FfiConverterStringINSTANCE.Lift(_uniffiRV), nil + } +} + +// Serialize this private key to bytes. +func (_self *Ed25519PrivateKey) ToBytes() []byte { + _pointer := _self.ffiObject.incrementPointer("*Ed25519PrivateKey") + defer _self.ffiObject.decrementPointer() + return FfiConverterBytesINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bytes( + _pointer,_uniffiStatus), + } + })) +} + // Serialize this private key as DER-encoded PKCS#8 func (_self *Ed25519PrivateKey) ToDer() ([]byte, error) { _pointer := _self.ffiObject.incrementPointer("*Ed25519PrivateKey") @@ -17002,6 +17169,11 @@ func (_ FfiDestroyerPublish) Destroy(value *Publish) { type Secp256k1PrivateKeyInterface interface { PublicKey() *Secp256k1PublicKey Scheme() SignatureScheme + // Encode this private key as `flag || privkey` in Bech32 starting with + // "iotaprivkey" to a string. + ToBech32() (string, error) + // Serialize this private key to bytes. + ToBytes() []byte // Serialize this private key as DER-encoded PKCS#8 ToDer() ([]byte, error) // Serialize this private key as PEM-encoded PKCS#8 @@ -17027,6 +17199,20 @@ func NewSecp256k1PrivateKey(bytes []byte) (*Secp256k1PrivateKey, error) { } +// Decode a private key from `flag || privkey` in Bech32 starting with +// "iotaprivkey". +func Secp256k1PrivateKeyFromBech32(value string) (*Secp256k1PrivateKey, error) { + _uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer { + return C.uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_bech32(FfiConverterStringINSTANCE.Lower(value),_uniffiStatus) + }) + if _uniffiErr != nil { + var _uniffiDefaultValue *Secp256k1PrivateKey + return _uniffiDefaultValue, _uniffiErr + } else { + return FfiConverterSecp256k1PrivateKeyINSTANCE.Lift(_uniffiRV), nil + } +} + // Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary // format). func Secp256k1PrivateKeyFromDer(bytes []byte) (*Secp256k1PrivateKey, error) { @@ -17082,6 +17268,37 @@ func (_self *Secp256k1PrivateKey) Scheme() SignatureScheme { })) } +// Encode this private key as `flag || privkey` in Bech32 starting with +// "iotaprivkey" to a string. +func (_self *Secp256k1PrivateKey) ToBech32() (string, error) { + _pointer := _self.ffiObject.incrementPointer("*Secp256k1PrivateKey") + defer _self.ffiObject.decrementPointer() + _uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bech32( + _pointer,_uniffiStatus), + } + }) + if _uniffiErr != nil { + var _uniffiDefaultValue string + return _uniffiDefaultValue, _uniffiErr + } else { + return FfiConverterStringINSTANCE.Lift(_uniffiRV), nil + } +} + +// Serialize this private key to bytes. +func (_self *Secp256k1PrivateKey) ToBytes() []byte { + _pointer := _self.ffiObject.incrementPointer("*Secp256k1PrivateKey") + defer _self.ffiObject.decrementPointer() + return FfiConverterBytesINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bytes( + _pointer,_uniffiStatus), + } + })) +} + // Serialize this private key as DER-encoded PKCS#8 func (_self *Secp256k1PrivateKey) ToDer() ([]byte, error) { _pointer := _self.ffiObject.incrementPointer("*Secp256k1PrivateKey") @@ -17777,6 +17994,11 @@ type Secp256r1PrivateKeyInterface interface { // Get the public key corresponding to this private key. PublicKey() *Secp256r1PublicKey Scheme() SignatureScheme + // Encode this private key as `flag || privkey` in Bech32 starting with + // "iotaprivkey" to a string. + ToBech32() (string, error) + // Serialize this private key to bytes. + ToBytes() []byte // Serialize this private key as DER-encoded PKCS#8 ToDer() ([]byte, error) // Serialize this private key as PEM-encoded PKCS#8 @@ -17805,6 +18027,20 @@ func NewSecp256r1PrivateKey(bytes []byte) (*Secp256r1PrivateKey, error) { } +// Decode a private key from `flag || privkey` in Bech32 starting with +// "iotaprivkey". +func Secp256r1PrivateKeyFromBech32(value string) (*Secp256r1PrivateKey, error) { + _uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer { + return C.uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_bech32(FfiConverterStringINSTANCE.Lower(value),_uniffiStatus) + }) + if _uniffiErr != nil { + var _uniffiDefaultValue *Secp256r1PrivateKey + return _uniffiDefaultValue, _uniffiErr + } else { + return FfiConverterSecp256r1PrivateKeyINSTANCE.Lift(_uniffiRV), nil + } +} + // Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary // format). func Secp256r1PrivateKeyFromDer(bytes []byte) (*Secp256r1PrivateKey, error) { @@ -17862,6 +18098,37 @@ func (_self *Secp256r1PrivateKey) Scheme() SignatureScheme { })) } +// Encode this private key as `flag || privkey` in Bech32 starting with +// "iotaprivkey" to a string. +func (_self *Secp256r1PrivateKey) ToBech32() (string, error) { + _pointer := _self.ffiObject.incrementPointer("*Secp256r1PrivateKey") + defer _self.ffiObject.decrementPointer() + _uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bech32( + _pointer,_uniffiStatus), + } + }) + if _uniffiErr != nil { + var _uniffiDefaultValue string + return _uniffiDefaultValue, _uniffiErr + } else { + return FfiConverterStringINSTANCE.Lift(_uniffiRV), nil + } +} + +// Serialize this private key to bytes. +func (_self *Secp256r1PrivateKey) ToBytes() []byte { + _pointer := _self.ffiObject.incrementPointer("*Secp256r1PrivateKey") + defer _self.ffiObject.decrementPointer() + return FfiConverterBytesINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bytes( + _pointer,_uniffiStatus), + } + })) +} + // Serialize this private key as DER-encoded PKCS#8 func (_self *Secp256r1PrivateKey) ToDer() ([]byte, error) { _pointer := _self.ffiObject.incrementPointer("*Secp256r1PrivateKey") @@ -18559,6 +18826,11 @@ func (_ FfiDestroyerSecp256r1VerifyingKey) Destroy(value *Secp256r1VerifyingKey) type SimpleKeypairInterface interface { PublicKey() *MultisigMemberPublicKey Scheme() SignatureScheme + // Encode a SimpleKeypair as `flag || privkey` in Bech32 starting with + // "iotaprivkey" to a string. Note that the pubkey is not encoded. + ToBech32() (string, error) + // Encode a SimpleKeypair as `flag || privkey` in bytes + ToBytes() []byte // Serialize this private key as DER-encoded PKCS#8 ToDer() ([]byte, error) // Serialize this private key as DER-encoded PKCS#8 @@ -18571,6 +18843,34 @@ type SimpleKeypair struct { } +// Decode a SimpleKeypair from `flag || privkey` in Bech32 starting with +// "iotaprivkey" to SimpleKeypair. The public key is computed directly from +// the private key bytes. +func SimpleKeypairFromBech32(value string) (*SimpleKeypair, error) { + _uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer { + return C.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bech32(FfiConverterStringINSTANCE.Lower(value),_uniffiStatus) + }) + if _uniffiErr != nil { + var _uniffiDefaultValue *SimpleKeypair + return _uniffiDefaultValue, _uniffiErr + } else { + return FfiConverterSimpleKeypairINSTANCE.Lift(_uniffiRV), nil + } +} + +// Decode a SimpleKeypair from `flag || privkey` bytes +func SimpleKeypairFromBytes(bytes []byte) (*SimpleKeypair, error) { + _uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer { + return C.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bytes(FfiConverterBytesINSTANCE.Lower(bytes),_uniffiStatus) + }) + if _uniffiErr != nil { + var _uniffiDefaultValue *SimpleKeypair + return _uniffiDefaultValue, _uniffiErr + } else { + return FfiConverterSimpleKeypairINSTANCE.Lift(_uniffiRV), nil + } +} + // Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary // format). func SimpleKeypairFromDer(bytes []byte) (*SimpleKeypair, error) { @@ -18620,6 +18920,37 @@ func (_self *SimpleKeypair) Scheme() SignatureScheme { })) } +// Encode a SimpleKeypair as `flag || privkey` in Bech32 starting with +// "iotaprivkey" to a string. Note that the pubkey is not encoded. +func (_self *SimpleKeypair) ToBech32() (string, error) { + _pointer := _self.ffiObject.incrementPointer("*SimpleKeypair") + defer _self.ffiObject.decrementPointer() + _uniffiRV, _uniffiErr := rustCallWithError[SdkFfiError](FfiConverterSdkFfiError{},func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bech32( + _pointer,_uniffiStatus), + } + }) + if _uniffiErr != nil { + var _uniffiDefaultValue string + return _uniffiDefaultValue, _uniffiErr + } else { + return FfiConverterStringINSTANCE.Lift(_uniffiRV), nil + } +} + +// Encode a SimpleKeypair as `flag || privkey` in bytes +func (_self *SimpleKeypair) ToBytes() []byte { + _pointer := _self.ffiObject.incrementPointer("*SimpleKeypair") + defer _self.ffiObject.decrementPointer() + return FfiConverterBytesINSTANCE.Lift(rustCall(func(_uniffiStatus *C.RustCallStatus) RustBufferI { + return GoRustBuffer { + inner: C.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bytes( + _pointer,_uniffiStatus), + } + })) +} + // Serialize this private key as DER-encoded PKCS#8 func (_self *SimpleKeypair) ToDer() ([]byte, error) { _pointer := _self.ffiObject.incrementPointer("*SimpleKeypair") diff --git a/bindings/go/iota_sdk_ffi/iota_sdk_ffi.h b/bindings/go/iota_sdk_ffi/iota_sdk_ffi.h index 5e8c04ece..a2e7ea895 100644 --- a/bindings/go/iota_sdk_ffi/iota_sdk_ffi.h +++ b/bindings/go/iota_sdk_ffi/iota_sdk_ffi.h @@ -1129,6 +1129,11 @@ void* uniffi_iota_sdk_ffi_fn_clone_ed25519privatekey(void* ptr, RustCallStatus * void uniffi_iota_sdk_ffi_fn_free_ed25519privatekey(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_ED25519PRIVATEKEY_FROM_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_ED25519PRIVATEKEY_FROM_BECH32 +void* uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_bech32(RustBuffer value, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_ED25519PRIVATEKEY_FROM_DER #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_ED25519PRIVATEKEY_FROM_DER void* uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_der(RustBuffer bytes, RustCallStatus *out_status @@ -1160,6 +1165,16 @@ void* uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_public_key(void* ptr, Rust RustBuffer uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_scheme(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_ED25519PRIVATEKEY_TO_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_ED25519PRIVATEKEY_TO_BECH32 +RustBuffer uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bech32(void* ptr, RustCallStatus *out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_ED25519PRIVATEKEY_TO_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_ED25519PRIVATEKEY_TO_BYTES +RustBuffer uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bytes(void* ptr, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_ED25519PRIVATEKEY_TO_DER #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_ED25519PRIVATEKEY_TO_DER RustBuffer uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_der(void* ptr, RustCallStatus *out_status @@ -2916,6 +2931,11 @@ void* uniffi_iota_sdk_ffi_fn_clone_secp256k1privatekey(void* ptr, RustCallStatus void uniffi_iota_sdk_ffi_fn_free_secp256k1privatekey(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SECP256K1PRIVATEKEY_FROM_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SECP256K1PRIVATEKEY_FROM_BECH32 +void* uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_bech32(RustBuffer value, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SECP256K1PRIVATEKEY_FROM_DER #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SECP256K1PRIVATEKEY_FROM_DER void* uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_der(RustBuffer bytes, RustCallStatus *out_status @@ -2947,6 +2967,16 @@ void* uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_public_key(void* ptr, Ru RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_scheme(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256K1PRIVATEKEY_TO_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256K1PRIVATEKEY_TO_BECH32 +RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bech32(void* ptr, RustCallStatus *out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256K1PRIVATEKEY_TO_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256K1PRIVATEKEY_TO_BYTES +RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bytes(void* ptr, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256K1PRIVATEKEY_TO_DER #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256K1PRIVATEKEY_TO_DER RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_der(void* ptr, RustCallStatus *out_status @@ -3140,6 +3170,11 @@ void* uniffi_iota_sdk_ffi_fn_clone_secp256r1privatekey(void* ptr, RustCallStatus void uniffi_iota_sdk_ffi_fn_free_secp256r1privatekey(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SECP256R1PRIVATEKEY_FROM_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SECP256R1PRIVATEKEY_FROM_BECH32 +void* uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_bech32(RustBuffer value, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SECP256R1PRIVATEKEY_FROM_DER #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SECP256R1PRIVATEKEY_FROM_DER void* uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_der(RustBuffer bytes, RustCallStatus *out_status @@ -3171,6 +3206,16 @@ void* uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_public_key(void* ptr, Ru RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_scheme(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256R1PRIVATEKEY_TO_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256R1PRIVATEKEY_TO_BECH32 +RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bech32(void* ptr, RustCallStatus *out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256R1PRIVATEKEY_TO_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256R1PRIVATEKEY_TO_BYTES +RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bytes(void* ptr, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256R1PRIVATEKEY_TO_DER #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SECP256R1PRIVATEKEY_TO_DER RustBuffer uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_der(void* ptr, RustCallStatus *out_status @@ -3364,6 +3409,16 @@ void* uniffi_iota_sdk_ffi_fn_clone_simplekeypair(void* ptr, RustCallStatus *out_ void uniffi_iota_sdk_ffi_fn_free_simplekeypair(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_BECH32 +void* uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bech32(RustBuffer value, RustCallStatus *out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_BYTES +void* uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bytes(RustBuffer bytes, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_DER #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_DER void* uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_der(RustBuffer bytes, RustCallStatus *out_status @@ -3384,6 +3439,16 @@ void* uniffi_iota_sdk_ffi_fn_method_simplekeypair_public_key(void* ptr, RustCall RustBuffer uniffi_iota_sdk_ffi_fn_method_simplekeypair_scheme(void* ptr, RustCallStatus *out_status ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SIMPLEKEYPAIR_TO_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SIMPLEKEYPAIR_TO_BECH32 +RustBuffer uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bech32(void* ptr, RustCallStatus *out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SIMPLEKEYPAIR_TO_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SIMPLEKEYPAIR_TO_BYTES +RustBuffer uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bytes(void* ptr, RustCallStatus *out_status +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SIMPLEKEYPAIR_TO_DER #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_METHOD_SIMPLEKEYPAIR_TO_DER RustBuffer uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_der(void* ptr, RustCallStatus *out_status @@ -5378,6 +5443,18 @@ uint16_t uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_public_key(void #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ED25519PRIVATEKEY_SCHEME uint16_t uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_scheme(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ED25519PRIVATEKEY_TO_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ED25519PRIVATEKEY_TO_BECH32 +uint16_t uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bech32(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ED25519PRIVATEKEY_TO_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ED25519PRIVATEKEY_TO_BYTES +uint16_t uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bytes(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_ED25519PRIVATEKEY_TO_DER @@ -6488,6 +6565,18 @@ uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_public_key(void #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256K1PRIVATEKEY_SCHEME uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_scheme(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256K1PRIVATEKEY_TO_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256K1PRIVATEKEY_TO_BECH32 +uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bech32(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256K1PRIVATEKEY_TO_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256K1PRIVATEKEY_TO_BYTES +uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bytes(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256K1PRIVATEKEY_TO_DER @@ -6608,6 +6697,18 @@ uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_public_key(void #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256R1PRIVATEKEY_SCHEME uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_scheme(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256R1PRIVATEKEY_TO_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256R1PRIVATEKEY_TO_BECH32 +uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bech32(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256R1PRIVATEKEY_TO_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256R1PRIVATEKEY_TO_BYTES +uint16_t uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bytes(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SECP256R1PRIVATEKEY_TO_DER @@ -6728,6 +6829,18 @@ uint16_t uniffi_iota_sdk_ffi_checksum_method_simplekeypair_public_key(void #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SIMPLEKEYPAIR_SCHEME uint16_t uniffi_iota_sdk_ffi_checksum_method_simplekeypair_scheme(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SIMPLEKEYPAIR_TO_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SIMPLEKEYPAIR_TO_BECH32 +uint16_t uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bech32(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SIMPLEKEYPAIR_TO_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SIMPLEKEYPAIR_TO_BYTES +uint16_t uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bytes(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_METHOD_SIMPLEKEYPAIR_TO_DER @@ -7814,6 +7927,12 @@ uint16_t uniffi_iota_sdk_ffi_checksum_constructor_digest_from_bytes(void #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_DIGEST_GENERATE uint16_t uniffi_iota_sdk_ffi_checksum_constructor_digest_generate(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_ED25519PRIVATEKEY_FROM_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_ED25519PRIVATEKEY_FROM_BECH32 +uint16_t uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_bech32(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_ED25519PRIVATEKEY_FROM_DER @@ -8324,6 +8443,12 @@ uint16_t uniffi_iota_sdk_ffi_checksum_constructor_programmabletransaction_new(vo #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_PUBLISH_NEW uint16_t uniffi_iota_sdk_ffi_checksum_constructor_publish_new(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SECP256K1PRIVATEKEY_FROM_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SECP256K1PRIVATEKEY_FROM_BECH32 +uint16_t uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_bech32(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SECP256K1PRIVATEKEY_FROM_DER @@ -8408,6 +8533,12 @@ uint16_t uniffi_iota_sdk_ffi_checksum_constructor_secp256k1verifyingkey_from_pem #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SECP256K1VERIFYINGKEY_NEW uint16_t uniffi_iota_sdk_ffi_checksum_constructor_secp256k1verifyingkey_new(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SECP256R1PRIVATEKEY_FROM_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SECP256R1PRIVATEKEY_FROM_BECH32 +uint16_t uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_bech32(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SECP256R1PRIVATEKEY_FROM_DER @@ -8492,6 +8623,18 @@ uint16_t uniffi_iota_sdk_ffi_checksum_constructor_secp256r1verifyingkey_from_pem #define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SECP256R1VERIFYINGKEY_NEW uint16_t uniffi_iota_sdk_ffi_checksum_constructor_secp256r1verifyingkey_new(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_BECH32 +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_BECH32 +uint16_t uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bech32(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_BYTES +#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_BYTES +uint16_t uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bytes(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_CHECKSUM_CONSTRUCTOR_SIMPLEKEYPAIR_FROM_DER diff --git a/bindings/kotlin/examples/GenerateEd25519Address.kt b/bindings/kotlin/examples/GenerateEd25519Address.kt index daca13e93..b0dc07cd8 100644 --- a/bindings/kotlin/examples/GenerateEd25519Address.kt +++ b/bindings/kotlin/examples/GenerateEd25519Address.kt @@ -7,12 +7,13 @@ import kotlin.io.println 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 address = publicKey.deriveAddress() - println("Private Key: ${base64Encode(privateKey.toDer())}") + println("Private Key: ${privateKeyBech32}") println("Public Key: ${base64Encode(publicKeyBytes)}") 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 2771da575..524b2b0a5 100644 --- a/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt +++ b/bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt @@ -2193,6 +2193,32 @@ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback { + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2371,6 +2397,10 @@ fun uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_public_key( ): Short fun uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_scheme( ): Short +fun uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bech32( +): Short +fun uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bytes( +): Short fun uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_der( ): Short fun uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_pem( @@ -2741,6 +2771,10 @@ fun uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_public_key( ): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_scheme( ): Short +fun uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bech32( +): Short +fun uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bytes( +): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_der( ): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_pem( @@ -2781,6 +2815,10 @@ fun uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_public_key( ): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_scheme( ): Short +fun uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bech32( +): Short +fun uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bytes( +): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_der( ): Short fun uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_pem( @@ -2821,6 +2859,10 @@ fun uniffi_iota_sdk_ffi_checksum_method_simplekeypair_public_key( ): Short fun uniffi_iota_sdk_ffi_checksum_method_simplekeypair_scheme( ): Short +fun uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bech32( +): Short +fun uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bytes( +): Short fun uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_der( ): Short fun uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_pem( @@ -3183,6 +3225,8 @@ fun uniffi_iota_sdk_ffi_checksum_constructor_digest_from_bytes( ): Short fun uniffi_iota_sdk_ffi_checksum_constructor_digest_generate( ): Short +fun uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_bech32( +): Short fun uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_der( ): Short fun uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_pem( @@ -3353,6 +3397,8 @@ fun uniffi_iota_sdk_ffi_checksum_constructor_programmabletransaction_new( ): Short fun uniffi_iota_sdk_ffi_checksum_constructor_publish_new( ): Short +fun uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_bech32( +): Short fun uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_der( ): Short fun uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_pem( @@ -3381,6 +3427,8 @@ fun uniffi_iota_sdk_ffi_checksum_constructor_secp256k1verifyingkey_from_pem( ): Short fun uniffi_iota_sdk_ffi_checksum_constructor_secp256k1verifyingkey_new( ): Short +fun uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_bech32( +): Short fun uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_der( ): Short fun uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_pem( @@ -3409,6 +3457,10 @@ fun uniffi_iota_sdk_ffi_checksum_constructor_secp256r1verifyingkey_from_pem( ): Short fun uniffi_iota_sdk_ffi_checksum_constructor_secp256r1verifyingkey_new( ): Short +fun uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bech32( +): Short +fun uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bytes( +): Short fun uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_der( ): Short fun uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_pem( @@ -3868,6 +3920,8 @@ fun uniffi_iota_sdk_ffi_fn_clone_ed25519privatekey(`ptr`: Pointer,uniffi_out_err ): Pointer fun uniffi_iota_sdk_ffi_fn_free_ed25519privatekey(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Unit +fun uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_bech32(`value`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Pointer fun uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_der(`bytes`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_pem(`s`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, @@ -3880,6 +3934,10 @@ fun uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_public_key(`ptr`: Pointer,un ): Pointer fun uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_scheme(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bech32(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bytes(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_der(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_pem(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, @@ -4574,6 +4632,8 @@ fun uniffi_iota_sdk_ffi_fn_clone_secp256k1privatekey(`ptr`: Pointer,uniffi_out_e ): Pointer fun uniffi_iota_sdk_ffi_fn_free_secp256k1privatekey(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Unit +fun uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_bech32(`value`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Pointer fun uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_der(`bytes`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_pem(`s`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, @@ -4586,6 +4646,10 @@ fun uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_public_key(`ptr`: Pointer, ): Pointer fun uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_scheme(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bech32(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bytes(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_der(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_pem(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, @@ -4662,6 +4726,8 @@ fun uniffi_iota_sdk_ffi_fn_clone_secp256r1privatekey(`ptr`: Pointer,uniffi_out_e ): Pointer fun uniffi_iota_sdk_ffi_fn_free_secp256r1privatekey(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Unit +fun uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_bech32(`value`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Pointer fun uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_der(`bytes`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_pem(`s`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, @@ -4674,6 +4740,10 @@ fun uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_public_key(`ptr`: Pointer, ): Pointer fun uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_scheme(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bech32(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bytes(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_der(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_pem(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, @@ -4750,6 +4820,10 @@ fun uniffi_iota_sdk_ffi_fn_clone_simplekeypair(`ptr`: Pointer,uniffi_out_err: Un ): Pointer fun uniffi_iota_sdk_ffi_fn_free_simplekeypair(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): Unit +fun uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bech32(`value`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Pointer +fun uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bytes(`bytes`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, +): Pointer fun uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_der(`bytes`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, ): Pointer fun uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_pem(`s`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, @@ -4758,6 +4832,10 @@ fun uniffi_iota_sdk_ffi_fn_method_simplekeypair_public_key(`ptr`: Pointer,uniffi ): Pointer fun uniffi_iota_sdk_ffi_fn_method_simplekeypair_scheme(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bech32(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue +fun uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bytes(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, +): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_der(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue fun uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_pem(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, @@ -5607,6 +5685,12 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_scheme() != 8128.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bech32() != 64514.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bytes() != 26261.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_der() != 61433.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -6162,6 +6246,12 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_scheme() != 60810.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bech32() != 60488.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bytes() != 18583.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_der() != 65507.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -6222,6 +6312,12 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_scheme() != 20973.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bech32() != 4230.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bytes() != 8648.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_der() != 48507.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -6282,6 +6378,12 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_scheme() != 19826.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bech32() != 4776.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bytes() != 1555.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_der() != 22161.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -6825,6 +6927,9 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_constructor_digest_generate() != 8094.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_bech32() != 16842.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_der() != 42838.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -7080,6 +7185,9 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_constructor_publish_new() != 4785.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_bech32() != 34529.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_der() != 45448.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -7122,6 +7230,9 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1verifyingkey_new() != 16080.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_bech32() != 7016.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_der() != 63595.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -7164,6 +7275,12 @@ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) { if (lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1verifyingkey_new() != 57317.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bech32() != 51811.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bytes() != 9299.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } if (lib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_der() != 24923.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } @@ -14796,6 +14913,17 @@ public interface Ed25519PrivateKeyInterface { fun `scheme`(): SignatureScheme + /** + * Encode this private key as `flag || privkey` in Bech32 starting with + * "iotaprivkey" to a string. + */ + fun `toBech32`(): kotlin.String + + /** + * Serialize this private key to bytes. + */ + fun `toBytes`(): kotlin.ByteArray + /** * Serialize this private key as DER-encoded PKCS#8 */ @@ -14931,6 +15059,38 @@ open class Ed25519PrivateKey: Disposable, AutoCloseable, Ed25519PrivateKeyInterf + /** + * Encode this private key as `flag || privkey` in Bech32 starting with + * "iotaprivkey" to a string. + */ + @Throws(SdkFfiException::class)override fun `toBech32`(): kotlin.String { + return FfiConverterString.lift( + callWithPointer { + uniffiRustCallWithError(SdkFfiException) { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bech32( + it, _status) +} + } + ) + } + + + + /** + * Serialize this private key to bytes. + */override fun `toBytes`(): kotlin.ByteArray { + return FfiConverterByteArray.lift( + callWithPointer { + uniffiRustCall() { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bytes( + it, _status) +} + } + ) + } + + + /** * Serialize this private key as DER-encoded PKCS#8 */ @@ -15018,6 +15178,21 @@ open class Ed25519PrivateKey: Disposable, AutoCloseable, Ed25519PrivateKeyInterf companion object { + /** + * Decode a private key from `flag || privkey` in Bech32 starting with + * "iotaprivkey". + */ + @Throws(SdkFfiException::class) fun `fromBech32`(`value`: kotlin.String): Ed25519PrivateKey { + return FfiConverterTypeEd25519PrivateKey.lift( + uniffiRustCallWithError(SdkFfiException) { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_bech32( + FfiConverterString.lower(`value`),_status) +} + ) + } + + + /** * Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary * format). @@ -29310,6 +29485,17 @@ public interface Secp256k1PrivateKeyInterface { fun `scheme`(): SignatureScheme + /** + * Encode this private key as `flag || privkey` in Bech32 starting with + * "iotaprivkey" to a string. + */ + fun `toBech32`(): kotlin.String + + /** + * Serialize this private key to bytes. + */ + fun `toBytes`(): kotlin.ByteArray + /** * Serialize this private key as DER-encoded PKCS#8 */ @@ -29445,6 +29631,38 @@ open class Secp256k1PrivateKey: Disposable, AutoCloseable, Secp256k1PrivateKeyIn + /** + * Encode this private key as `flag || privkey` in Bech32 starting with + * "iotaprivkey" to a string. + */ + @Throws(SdkFfiException::class)override fun `toBech32`(): kotlin.String { + return FfiConverterString.lift( + callWithPointer { + uniffiRustCallWithError(SdkFfiException) { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bech32( + it, _status) +} + } + ) + } + + + + /** + * Serialize this private key to bytes. + */override fun `toBytes`(): kotlin.ByteArray { + return FfiConverterByteArray.lift( + callWithPointer { + uniffiRustCall() { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bytes( + it, _status) +} + } + ) + } + + + /** * Serialize this private key as DER-encoded PKCS#8 */ @@ -29532,6 +29750,21 @@ open class Secp256k1PrivateKey: Disposable, AutoCloseable, Secp256k1PrivateKeyIn companion object { + /** + * Decode a private key from `flag || privkey` in Bech32 starting with + * "iotaprivkey". + */ + @Throws(SdkFfiException::class) fun `fromBech32`(`value`: kotlin.String): Secp256k1PrivateKey { + return FfiConverterTypeSecp256k1PrivateKey.lift( + uniffiRustCallWithError(SdkFfiException) { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_bech32( + FfiConverterString.lower(`value`),_status) +} + ) + } + + + /** * Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary * format). @@ -30958,6 +31191,17 @@ public interface Secp256r1PrivateKeyInterface { fun `scheme`(): SignatureScheme + /** + * Encode this private key as `flag || privkey` in Bech32 starting with + * "iotaprivkey" to a string. + */ + fun `toBech32`(): kotlin.String + + /** + * Serialize this private key to bytes. + */ + fun `toBytes`(): kotlin.ByteArray + /** * Serialize this private key as DER-encoded PKCS#8 */ @@ -31105,6 +31349,38 @@ open class Secp256r1PrivateKey: Disposable, AutoCloseable, Secp256r1PrivateKeyIn + /** + * Encode this private key as `flag || privkey` in Bech32 starting with + * "iotaprivkey" to a string. + */ + @Throws(SdkFfiException::class)override fun `toBech32`(): kotlin.String { + return FfiConverterString.lift( + callWithPointer { + uniffiRustCallWithError(SdkFfiException) { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bech32( + it, _status) +} + } + ) + } + + + + /** + * Serialize this private key to bytes. + */override fun `toBytes`(): kotlin.ByteArray { + return FfiConverterByteArray.lift( + callWithPointer { + uniffiRustCall() { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bytes( + it, _status) +} + } + ) + } + + + /** * Serialize this private key as DER-encoded PKCS#8 */ @@ -31201,6 +31477,21 @@ open class Secp256r1PrivateKey: Disposable, AutoCloseable, Secp256r1PrivateKeyIn companion object { + /** + * Decode a private key from `flag || privkey` in Bech32 starting with + * "iotaprivkey". + */ + @Throws(SdkFfiException::class) fun `fromBech32`(`value`: kotlin.String): Secp256r1PrivateKey { + return FfiConverterTypeSecp256r1PrivateKey.lift( + uniffiRustCallWithError(SdkFfiException) { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_bech32( + FfiConverterString.lower(`value`),_status) +} + ) + } + + + /** * Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary * format). @@ -32627,6 +32918,17 @@ public interface SimpleKeypairInterface { fun `scheme`(): SignatureScheme + /** + * Encode a SimpleKeypair as `flag || privkey` in Bech32 starting with + * "iotaprivkey" to a string. Note that the pubkey is not encoded. + */ + fun `toBech32`(): kotlin.String + + /** + * Encode a SimpleKeypair as `flag || privkey` in bytes + */ + fun `toBytes`(): kotlin.ByteArray + /** * Serialize this private key as DER-encoded PKCS#8 */ @@ -32751,6 +33053,38 @@ open class SimpleKeypair: Disposable, AutoCloseable, SimpleKeypairInterface + /** + * Encode a SimpleKeypair as `flag || privkey` in Bech32 starting with + * "iotaprivkey" to a string. Note that the pubkey is not encoded. + */ + @Throws(SdkFfiException::class)override fun `toBech32`(): kotlin.String { + return FfiConverterString.lift( + callWithPointer { + uniffiRustCallWithError(SdkFfiException) { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bech32( + it, _status) +} + } + ) + } + + + + /** + * Encode a SimpleKeypair as `flag || privkey` in bytes + */override fun `toBytes`(): kotlin.ByteArray { + return FfiConverterByteArray.lift( + callWithPointer { + uniffiRustCall() { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bytes( + it, _status) +} + } + ) + } + + + /** * Serialize this private key as DER-encoded PKCS#8 */ @@ -32812,6 +33146,36 @@ open class SimpleKeypair: Disposable, AutoCloseable, SimpleKeypairInterface companion object { + /** + * Decode a SimpleKeypair from `flag || privkey` in Bech32 starting with + * "iotaprivkey" to SimpleKeypair. The public key is computed directly from + * the private key bytes. + */ + @Throws(SdkFfiException::class) fun `fromBech32`(`value`: kotlin.String): SimpleKeypair { + return FfiConverterTypeSimpleKeypair.lift( + uniffiRustCallWithError(SdkFfiException) { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bech32( + FfiConverterString.lower(`value`),_status) +} + ) + } + + + + /** + * Decode a SimpleKeypair from `flag || privkey` bytes + */ + @Throws(SdkFfiException::class) fun `fromBytes`(`bytes`: kotlin.ByteArray): SimpleKeypair { + return FfiConverterTypeSimpleKeypair.lift( + uniffiRustCallWithError(SdkFfiException) { _status -> + UniffiLib.INSTANCE.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bytes( + FfiConverterByteArray.lower(`bytes`),_status) +} + ) + } + + + /** * Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary * format). diff --git a/bindings/python/examples/generate_ed25519_address.py b/bindings/python/examples/generate_ed25519_address.py index 8b1884177..f09d681be 100644 --- a/bindings/python/examples/generate_ed25519_address.py +++ b/bindings/python/examples/generate_ed25519_address.py @@ -6,12 +6,13 @@ 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 address = public_key.derive_address() - print(f"Private Key: {base64_encode(private_key.to_der())}") + print(f"Private Key: {private_key_bech32}") print(f"Public Key: {base64_encode(public_key_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 a5af6946d..82b41c54a 100644 --- a/bindings/python/lib/iota_sdk_ffi.py +++ b/bindings/python/lib/iota_sdk_ffi.py @@ -603,6 +603,10 @@ 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_ed25519privatekey_scheme() != 8128: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bech32() != 64514: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bytes() != 26261: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_der() != 61433: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_pem() != 34166: @@ -973,6 +977,10 @@ 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_secp256k1privatekey_scheme() != 60810: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bech32() != 60488: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bytes() != 18583: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_der() != 65507: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_pem() != 12369: @@ -1013,6 +1021,10 @@ 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_secp256r1privatekey_scheme() != 20973: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bech32() != 4230: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bytes() != 8648: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_der() != 48507: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_pem() != 34634: @@ -1053,6 +1065,10 @@ 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_simplekeypair_scheme() != 19826: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bech32() != 4776: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bytes() != 1555: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_der() != 22161: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_pem() != 18854: @@ -1415,6 +1431,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_constructor_digest_generate() != 8094: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_bech32() != 16842: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_der() != 42838: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_pem() != 53776: @@ -1585,6 +1603,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_constructor_publish_new() != 4785: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_bech32() != 34529: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_der() != 45448: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_pem() != 20937: @@ -1613,6 +1633,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_constructor_secp256k1verifyingkey_new() != 16080: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_bech32() != 7016: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_der() != 63595: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_pem() != 28166: @@ -1641,6 +1663,10 @@ 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_constructor_secp256r1verifyingkey_new() != 57317: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bech32() != 51811: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + if lib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bytes() != 9299: + raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_der() != 24923: raise InternalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") if lib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_pem() != 2041: @@ -2643,6 +2669,11 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_free_ed25519privatekey.restype = None +_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_bech32.argtypes = ( + _UniffiRustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_bech32.restype = ctypes.c_void_p _UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_der.argtypes = ( _UniffiRustBuffer, ctypes.POINTER(_UniffiRustCallStatus), @@ -2672,6 +2703,16 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_scheme.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bech32.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bech32.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bytes.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bytes.restype = _UniffiRustBuffer _UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_der.argtypes = ( ctypes.c_void_p, ctypes.POINTER(_UniffiRustCallStatus), @@ -4466,6 +4507,11 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_free_secp256k1privatekey.restype = None +_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_bech32.argtypes = ( + _UniffiRustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_bech32.restype = ctypes.c_void_p _UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_der.argtypes = ( _UniffiRustBuffer, ctypes.POINTER(_UniffiRustCallStatus), @@ -4495,6 +4541,16 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_scheme.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bech32.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bech32.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bytes.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bytes.restype = _UniffiRustBuffer _UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_der.argtypes = ( ctypes.c_void_p, ctypes.POINTER(_UniffiRustCallStatus), @@ -4695,6 +4751,11 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_free_secp256r1privatekey.restype = None +_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_bech32.argtypes = ( + _UniffiRustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_bech32.restype = ctypes.c_void_p _UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_der.argtypes = ( _UniffiRustBuffer, ctypes.POINTER(_UniffiRustCallStatus), @@ -4724,6 +4785,16 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_scheme.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bech32.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bech32.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bytes.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bytes.restype = _UniffiRustBuffer _UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_der.argtypes = ( ctypes.c_void_p, ctypes.POINTER(_UniffiRustCallStatus), @@ -4924,6 +4995,16 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_free_simplekeypair.restype = None +_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bech32.argtypes = ( + _UniffiRustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bech32.restype = ctypes.c_void_p +_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bytes.argtypes = ( + _UniffiRustBuffer, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bytes.restype = ctypes.c_void_p _UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_der.argtypes = ( _UniffiRustBuffer, ctypes.POINTER(_UniffiRustCallStatus), @@ -4944,6 +5025,16 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): ctypes.POINTER(_UniffiRustCallStatus), ) _UniffiLib.uniffi_iota_sdk_ffi_fn_method_simplekeypair_scheme.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bech32.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bech32.restype = _UniffiRustBuffer +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bytes.argtypes = ( + ctypes.c_void_p, + ctypes.POINTER(_UniffiRustCallStatus), +) +_UniffiLib.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bytes.restype = _UniffiRustBuffer _UniffiLib.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_der.argtypes = ( ctypes.c_void_p, ctypes.POINTER(_UniffiRustCallStatus), @@ -6768,6 +6859,12 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_scheme.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_scheme.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bech32.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bech32.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bytes.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_bytes.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_der.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_ed25519privatekey_to_der.restype = ctypes.c_uint16 @@ -7323,6 +7420,12 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_scheme.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_scheme.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bech32.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bech32.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bytes.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_bytes.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_der.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256k1privatekey_to_der.restype = ctypes.c_uint16 @@ -7383,6 +7486,12 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_scheme.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_scheme.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bech32.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bech32.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bytes.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_bytes.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_der.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_secp256r1privatekey_to_der.restype = ctypes.c_uint16 @@ -7443,6 +7552,12 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_scheme.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_scheme.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bech32.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bech32.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bytes.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_bytes.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_der.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_method_simplekeypair_to_der.restype = ctypes.c_uint16 @@ -7986,6 +8101,9 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_digest_generate.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_digest_generate.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_bech32.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_bech32.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_der.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_ed25519privatekey_from_der.restype = ctypes.c_uint16 @@ -8241,6 +8359,9 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_publish_new.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_publish_new.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_bech32.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_bech32.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_der.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1privatekey_from_der.restype = ctypes.c_uint16 @@ -8283,6 +8404,9 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1verifyingkey_new.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256k1verifyingkey_new.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_bech32.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_bech32.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_der.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1privatekey_from_der.restype = ctypes.c_uint16 @@ -8325,6 +8449,12 @@ class _UniffiForeignFutureStructVoid(ctypes.Structure): _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1verifyingkey_new.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_secp256r1verifyingkey_new.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bech32.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bech32.restype = ctypes.c_uint16 +_UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bytes.argtypes = ( +) +_UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_bytes.restype = ctypes.c_uint16 _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_der.argtypes = ( ) _UniffiLib.uniffi_iota_sdk_ffi_checksum_constructor_simplekeypair_from_der.restype = ctypes.c_uint16 @@ -24654,6 +24784,19 @@ class Ed25519PrivateKeyProtocol(typing.Protocol): def public_key(self, ): raise NotImplementedError def scheme(self, ): + raise NotImplementedError + def to_bech32(self, ): + """ + Encode this private key as `flag || privkey` in Bech32 starting with + "iotaprivkey" to a string. + """ + + raise NotImplementedError + def to_bytes(self, ): + """ + Serialize this private key to bytes. + """ + raise NotImplementedError def to_der(self, ): """ @@ -24702,6 +24845,20 @@ def _make_instance_(cls, pointer): inst._pointer = pointer return inst @classmethod + def from_bech32(cls, value: "str"): + """ + Decode a private key from `flag || privkey` in Bech32 starting with + "iotaprivkey". + """ + + _UniffiConverterString.check_lower(value) + + # Call the (fallible) function before creating any half-baked object instances. + pointer = _uniffi_rust_call_with_error(_UniffiConverterTypeSdkFfiError,_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_ed25519privatekey_from_bech32, + _UniffiConverterString.lower(value)) + return cls._make_instance_(pointer) + + @classmethod def from_der(cls, bytes: "bytes"): """ Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary @@ -24754,6 +24911,33 @@ def scheme(self, ) -> "SignatureScheme": + def to_bech32(self, ) -> "str": + """ + Encode this private key as `flag || privkey` in Bech32 starting with + "iotaprivkey" to a string. + """ + + return _UniffiConverterString.lift( + _uniffi_rust_call_with_error(_UniffiConverterTypeSdkFfiError,_UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bech32,self._uniffi_clone_pointer(),) + ) + + + + + + def to_bytes(self, ) -> "bytes": + """ + Serialize this private key to bytes. + """ + + return _UniffiConverterBytes.lift( + _uniffi_rust_call(_UniffiLib.uniffi_iota_sdk_ffi_fn_method_ed25519privatekey_to_bytes,self._uniffi_clone_pointer(),) + ) + + + + + def to_der(self, ) -> "bytes": """ Serialize this private key as DER-encoded PKCS#8 @@ -32564,6 +32748,19 @@ class Secp256k1PrivateKeyProtocol(typing.Protocol): def public_key(self, ): raise NotImplementedError def scheme(self, ): + raise NotImplementedError + def to_bech32(self, ): + """ + Encode this private key as `flag || privkey` in Bech32 starting with + "iotaprivkey" to a string. + """ + + raise NotImplementedError + def to_bytes(self, ): + """ + Serialize this private key to bytes. + """ + raise NotImplementedError def to_der(self, ): """ @@ -32612,6 +32809,20 @@ def _make_instance_(cls, pointer): inst._pointer = pointer return inst @classmethod + def from_bech32(cls, value: "str"): + """ + Decode a private key from `flag || privkey` in Bech32 starting with + "iotaprivkey". + """ + + _UniffiConverterString.check_lower(value) + + # Call the (fallible) function before creating any half-baked object instances. + pointer = _uniffi_rust_call_with_error(_UniffiConverterTypeSdkFfiError,_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_secp256k1privatekey_from_bech32, + _UniffiConverterString.lower(value)) + return cls._make_instance_(pointer) + + @classmethod def from_der(cls, bytes: "bytes"): """ Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary @@ -32664,6 +32875,33 @@ def scheme(self, ) -> "SignatureScheme": + def to_bech32(self, ) -> "str": + """ + Encode this private key as `flag || privkey` in Bech32 starting with + "iotaprivkey" to a string. + """ + + return _UniffiConverterString.lift( + _uniffi_rust_call_with_error(_UniffiConverterTypeSdkFfiError,_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bech32,self._uniffi_clone_pointer(),) + ) + + + + + + def to_bytes(self, ) -> "bytes": + """ + Serialize this private key to bytes. + """ + + return _UniffiConverterBytes.lift( + _uniffi_rust_call(_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256k1privatekey_to_bytes,self._uniffi_clone_pointer(),) + ) + + + + + def to_der(self, ) -> "bytes": """ Serialize this private key as DER-encoded PKCS#8 @@ -33315,6 +33553,19 @@ def public_key(self, ): raise NotImplementedError def scheme(self, ): + raise NotImplementedError + def to_bech32(self, ): + """ + Encode this private key as `flag || privkey` in Bech32 starting with + "iotaprivkey" to a string. + """ + + raise NotImplementedError + def to_bytes(self, ): + """ + Serialize this private key to bytes. + """ + raise NotImplementedError def to_der(self, ): """ @@ -33375,6 +33626,20 @@ def _make_instance_(cls, pointer): inst._pointer = pointer return inst @classmethod + def from_bech32(cls, value: "str"): + """ + Decode a private key from `flag || privkey` in Bech32 starting with + "iotaprivkey". + """ + + _UniffiConverterString.check_lower(value) + + # Call the (fallible) function before creating any half-baked object instances. + pointer = _uniffi_rust_call_with_error(_UniffiConverterTypeSdkFfiError,_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_secp256r1privatekey_from_bech32, + _UniffiConverterString.lower(value)) + return cls._make_instance_(pointer) + + @classmethod def from_der(cls, bytes: "bytes"): """ Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary @@ -33435,6 +33700,33 @@ def scheme(self, ) -> "SignatureScheme": + def to_bech32(self, ) -> "str": + """ + Encode this private key as `flag || privkey` in Bech32 starting with + "iotaprivkey" to a string. + """ + + return _UniffiConverterString.lift( + _uniffi_rust_call_with_error(_UniffiConverterTypeSdkFfiError,_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bech32,self._uniffi_clone_pointer(),) + ) + + + + + + def to_bytes(self, ) -> "bytes": + """ + Serialize this private key to bytes. + """ + + return _UniffiConverterBytes.lift( + _uniffi_rust_call(_UniffiLib.uniffi_iota_sdk_ffi_fn_method_secp256r1privatekey_to_bytes,self._uniffi_clone_pointer(),) + ) + + + + + def to_der(self, ) -> "bytes": """ Serialize this private key as DER-encoded PKCS#8 @@ -34094,6 +34386,19 @@ class SimpleKeypairProtocol(typing.Protocol): def public_key(self, ): raise NotImplementedError def scheme(self, ): + raise NotImplementedError + def to_bech32(self, ): + """ + Encode a SimpleKeypair as `flag || privkey` in Bech32 starting with + "iotaprivkey" to a string. Note that the pubkey is not encoded. + """ + + raise NotImplementedError + def to_bytes(self, ): + """ + Encode a SimpleKeypair as `flag || privkey` in bytes + """ + raise NotImplementedError def to_der(self, ): """ @@ -34136,6 +34441,34 @@ def _make_instance_(cls, pointer): inst._pointer = pointer return inst @classmethod + def from_bech32(cls, value: "str"): + """ + Decode a SimpleKeypair from `flag || privkey` in Bech32 starting with + "iotaprivkey" to SimpleKeypair. The public key is computed directly from + the private key bytes. + """ + + _UniffiConverterString.check_lower(value) + + # Call the (fallible) function before creating any half-baked object instances. + pointer = _uniffi_rust_call_with_error(_UniffiConverterTypeSdkFfiError,_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bech32, + _UniffiConverterString.lower(value)) + return cls._make_instance_(pointer) + + @classmethod + def from_bytes(cls, bytes: "bytes"): + """ + Decode a SimpleKeypair from `flag || privkey` bytes + """ + + _UniffiConverterBytes.check_lower(bytes) + + # Call the (fallible) function before creating any half-baked object instances. + pointer = _uniffi_rust_call_with_error(_UniffiConverterTypeSdkFfiError,_UniffiLib.uniffi_iota_sdk_ffi_fn_constructor_simplekeypair_from_bytes, + _UniffiConverterBytes.lower(bytes)) + return cls._make_instance_(pointer) + + @classmethod def from_der(cls, bytes: "bytes"): """ Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary @@ -34182,6 +34515,33 @@ def scheme(self, ) -> "SignatureScheme": + def to_bech32(self, ) -> "str": + """ + Encode a SimpleKeypair as `flag || privkey` in Bech32 starting with + "iotaprivkey" to a string. Note that the pubkey is not encoded. + """ + + return _UniffiConverterString.lift( + _uniffi_rust_call_with_error(_UniffiConverterTypeSdkFfiError,_UniffiLib.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bech32,self._uniffi_clone_pointer(),) + ) + + + + + + def to_bytes(self, ) -> "bytes": + """ + Encode a SimpleKeypair as `flag || privkey` in bytes + """ + + return _UniffiConverterBytes.lift( + _uniffi_rust_call(_UniffiLib.uniffi_iota_sdk_ffi_fn_method_simplekeypair_to_bytes,self._uniffi_clone_pointer(),) + ) + + + + + def to_der(self, ) -> "bytes": """ Serialize this private key as DER-encoded PKCS#8 diff --git a/crates/iota-crypto/Cargo.toml b/crates/iota-crypto/Cargo.toml index 415de4ebf..3818ad075 100644 --- a/crates/iota-crypto/Cargo.toml +++ b/crates/iota-crypto/Cargo.toml @@ -28,6 +28,7 @@ ed25519 = ["dep:ed25519-dalek", "dep:rand_core"] secp256r1 = ["dep:p256", "dep:rand_core"] passkey = ["secp256r1", "dep:sha2"] secp256k1 = ["dep:k256", "dep:rand_core", "signature/std"] +bech32 = ["dep:bech32", "signature/std"] zklogin = [ "dep:ark-bn254", "dep:ark-ff", @@ -57,6 +58,7 @@ bls12381 = ["dep:blst", "dep:rand_core", "dep:roaring", "signature/std"] [dependencies] iota-sdk-types = { path = "../iota-sdk-types", default-features = false, features = ["hash", "serde"] } signature = "2.2" +thiserror = "2.0" # RNG support rand_core = { version = "0.6.4", optional = true } @@ -94,9 +96,13 @@ pkcs8 = { version = "0.10", optional = true, features = ["std"] } blst = { version = "0.3.13", optional = true } roaring = { version = "0.11.2", optional = true } +# bech32 encoding support +bech32 = { version = "0.11.0", optional = true } + [dev-dependencies] bcs = { version = "0.1.6" } hex = "0.4.3" +rand = "0.8.5" serde_json = { version = "1.0.128" } # proptest support in tests diff --git a/crates/iota-crypto/src/ed25519.rs b/crates/iota-crypto/src/ed25519.rs index 32af94d83..d583fa166 100644 --- a/crates/iota-crypto/src/ed25519.rs +++ b/crates/iota-crypto/src/ed25519.rs @@ -111,6 +111,27 @@ impl Ed25519PrivateKey { } } +impl crate::PrivateKeyExt for Ed25519PrivateKey { + const SCHEME: SignatureScheme = SignatureScheme::Ed25519; + + /// Return the raw 32-byte private key + fn to_bytes(&self) -> Vec { + self.0.to_bytes().to_vec() + } + + fn from_raw_bytes(bytes: &[u8]) -> Result { + if bytes.len() != Self::LENGTH { + return Err(crate::PrivateKeyError::InvalidScheme( + "invalid ed25519 key length".to_string(), + )); + } + + let mut arr = [0u8; Self::LENGTH]; + arr.copy_from_slice(bytes); + Ok(Self::new(arr)) + } +} + impl Signer for Ed25519PrivateKey { fn try_sign(&self, msg: &[u8]) -> Result { self.0 diff --git a/crates/iota-crypto/src/lib.rs b/crates/iota-crypto/src/lib.rs index fb2641fac..faead6f81 100644 --- a/crates/iota-crypto/src/lib.rs +++ b/crates/iota-crypto/src/lib.rs @@ -7,6 +7,24 @@ use iota_sdk_types::{PersonalMessage, Transaction, UserSignature}; pub use signature::{Error as SignatureError, Signer, Verifier}; +/// Error type for private key encoding/decoding operations +#[derive(thiserror::Error, Debug)] +#[non_exhaustive] +pub enum PrivateKeyError { + /// Empty input data + #[error("empty data: {0}")] + EmptyData(String), + /// Invalid signature scheme + #[error("invalid signature scheme: {0}")] + InvalidScheme(String), + /// Bech32 encoding/decoding error + #[error("bech32 error: {0}")] + Bech32(String), + /// HRP (Human Readable Part) error + #[error("bech32 HRP error: {0}")] + Bech32Hrp(String), +} + #[cfg(feature = "bls12381")] #[cfg_attr(doc_cfg, doc(cfg(feature = "bls12381")))] pub mod bls12381; @@ -154,3 +172,100 @@ impl> IotaVerifier for T { self.verify(&message, signature) } } + +/// Bech32 prefix for IOTA private keys +#[cfg(feature = "bech32")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "bech32")))] +pub const IOTA_PRIV_KEY_PREFIX: &str = "iotaprivkey"; + +/// Extension trait for private key types +pub trait PrivateKeyExt { + /// The signature scheme for this key type + const SCHEME: iota_sdk_types::SignatureScheme; + + /// Returns the signature scheme for this private key + fn scheme(&self) -> iota_sdk_types::SignatureScheme { + Self::SCHEME + } + + /// Returns the raw bytes of this private key + fn to_bytes(&self) -> Vec; + + /// Creates an instance from raw key bytes (without scheme flag) + fn from_raw_bytes(bytes: &[u8]) -> Result + where + Self: Sized; + + /// Returns the bytes with signature scheme flag prepended + fn to_flagged_bytes(&self) -> Vec { + let key_bytes = self.to_bytes(); + let mut bytes = Vec::with_capacity(1 + key_bytes.len()); + bytes.push(self.scheme().to_u8()); + bytes.extend_from_slice(&key_bytes); + bytes + } + + /// Creates an instance from bytes that include the signature scheme flag + fn from_flagged_bytes(bytes: &[u8]) -> Result + where + Self: Sized, + { + if bytes.is_empty() { + return Err(PrivateKeyError::EmptyData("flagged bytes".to_string())); + } + + let flag = iota_sdk_types::SignatureScheme::from_byte(bytes[0]) + .map_err(|e| PrivateKeyError::InvalidScheme(format!("{e:?}")))?; + + if flag != Self::SCHEME { + return Err(PrivateKeyError::InvalidScheme(format!( + "expected {:?}, got {flag:?}", + Self::SCHEME + ))); + } + + let key_bytes = &bytes[1..]; + Self::from_raw_bytes(key_bytes) + } + + /// Encode this private key in Bech32 format with "iotaprivkey" prefix + #[cfg(feature = "bech32")] + fn to_bech32(&self) -> Result { + use bech32::Hrp; + + let hrp = Hrp::parse(IOTA_PRIV_KEY_PREFIX) + .map_err(|e| PrivateKeyError::Bech32Hrp(format!("{e}")))?; + + let bytes = self.to_flagged_bytes(); + + bech32::encode::(hrp, &bytes) + .map_err(|e| PrivateKeyError::Bech32(format!("encoding failed: {e}"))) + } + + /// Decode a private key from Bech32 format with "iotaprivkey" prefix + #[cfg(feature = "bech32")] + fn from_bech32(value: &str) -> Result + where + Self: Sized, + { + use bech32::Hrp; + + let expected_hrp = Hrp::parse(IOTA_PRIV_KEY_PREFIX) + .map_err(|e| PrivateKeyError::Bech32Hrp(format!("{e}")))?; + + let (hrp, data) = bech32::decode(value) + .map_err(|e| PrivateKeyError::Bech32(format!("decoding failed: {e}")))?; + + if hrp != expected_hrp { + return Err(PrivateKeyError::Bech32Hrp(format!( + "expected {IOTA_PRIV_KEY_PREFIX}, got {hrp}" + ))); + } + + if data.is_empty() { + return Err(PrivateKeyError::EmptyData("bech32 data".to_string())); + } + + Self::from_flagged_bytes(&data) + } +} diff --git a/crates/iota-crypto/src/secp256k1.rs b/crates/iota-crypto/src/secp256k1.rs index 8bf7751df..bc599a087 100644 --- a/crates/iota-crypto/src/secp256k1.rs +++ b/crates/iota-crypto/src/secp256k1.rs @@ -13,7 +13,7 @@ use signature::{Signer, Verifier}; use crate::SignatureError; -#[derive(Clone)] +#[derive(Clone, Eq, PartialEq)] pub struct Secp256k1PrivateKey(SigningKey); impl std::fmt::Debug for Secp256k1PrivateKey { @@ -116,6 +116,26 @@ impl Secp256k1PrivateKey { } } +impl crate::PrivateKeyExt for Secp256k1PrivateKey { + const SCHEME: SignatureScheme = SignatureScheme::Secp256k1; + + fn to_bytes(&self) -> Vec { + self.0.to_bytes().as_slice().to_vec() + } + + fn from_raw_bytes(bytes: &[u8]) -> Result { + if bytes.len() != Self::LENGTH { + return Err(crate::PrivateKeyError::InvalidScheme( + "invalid secp256k1 key length".to_string(), + )); + } + + let mut arr = [0u8; Self::LENGTH]; + arr.copy_from_slice(bytes); + Self::new(arr).map_err(|e| crate::PrivateKeyError::InvalidScheme(e.to_string())) + } +} + impl Signer for Secp256k1PrivateKey { fn try_sign(&self, message: &[u8]) -> Result { let signature: k256::ecdsa::Signature = self.0.try_sign(message)?; diff --git a/crates/iota-crypto/src/secp256r1.rs b/crates/iota-crypto/src/secp256r1.rs index 5ccab877d..96e48a395 100644 --- a/crates/iota-crypto/src/secp256r1.rs +++ b/crates/iota-crypto/src/secp256r1.rs @@ -13,7 +13,7 @@ use signature::{Signer, Verifier}; use crate::SignatureError; -#[derive(Clone)] +#[derive(Clone, Eq, PartialEq)] pub struct Secp256r1PrivateKey(SigningKey); impl std::fmt::Debug for Secp256r1PrivateKey { @@ -116,6 +116,26 @@ impl Secp256r1PrivateKey { } } +impl crate::PrivateKeyExt for Secp256r1PrivateKey { + const SCHEME: SignatureScheme = SignatureScheme::Secp256r1; + + fn to_bytes(&self) -> Vec { + self.0.to_bytes().as_slice().to_vec() + } + + fn from_raw_bytes(bytes: &[u8]) -> Result { + if bytes.len() != Self::LENGTH { + return Err(crate::PrivateKeyError::InvalidScheme( + "invalid secp256r1 key length".to_string(), + )); + } + + let mut arr = [0u8; Self::LENGTH]; + arr.copy_from_slice(bytes); + Ok(Self::new(arr)) + } +} + impl Signer for Secp256r1PrivateKey { fn try_sign(&self, message: &[u8]) -> Result { let signature: p256::ecdsa::Signature = self.0.try_sign(message)?; diff --git a/crates/iota-crypto/src/simple.rs b/crates/iota-crypto/src/simple.rs index 2c35db68e..1fbc69566 100644 --- a/crates/iota-crypto/src/simple.rs +++ b/crates/iota-crypto/src/simple.rs @@ -82,7 +82,7 @@ mod keypair { }; use signature::{Signer, Verifier}; - use crate::SignatureError; + use crate::{PrivateKeyExt, SignatureError}; #[derive(Debug, Clone)] pub struct SimpleKeypair { @@ -136,6 +136,82 @@ mod keypair { self.verifying_key().public_key() } + /// Encode a SimpleKeypair as `flag || privkey` in bytes + pub fn to_bytes(&self) -> Vec { + let mut bytes = Vec::new(); + bytes.push(self.scheme().to_u8()); + + match &self.inner { + #[cfg(feature = "ed25519")] + InnerKeypair::Ed25519(private_key) => { + bytes.extend_from_slice(&private_key.to_bytes()); + } + #[cfg(feature = "secp256k1")] + InnerKeypair::Secp256k1(private_key) => { + bytes.extend_from_slice(&private_key.to_bytes()); + } + #[cfg(feature = "secp256r1")] + InnerKeypair::Secp256r1(private_key) => { + bytes.extend_from_slice(&private_key.to_bytes()); + } + } + + bytes + } + + /// Decode a SimpleKeypair from `flag || privkey` bytes + pub fn from_bytes(bytes: &[u8]) -> Result { + if bytes.is_empty() { + return Err(SignatureError::from_source("empty bytes")); + } + + let flag = SignatureScheme::from_byte(bytes[0]).map_err(|e| { + SignatureError::from_source(format!("invalid signature scheme: {:?}", e)) + })?; + let key_bytes = &bytes[1..]; + + match flag { + #[cfg(feature = "ed25519")] + SignatureScheme::Ed25519 => { + if key_bytes.len() != crate::ed25519::Ed25519PrivateKey::LENGTH { + return Err(SignatureError::from_source("invalid ed25519 key length")); + } + let mut arr = [0u8; crate::ed25519::Ed25519PrivateKey::LENGTH]; + arr.copy_from_slice(key_bytes); + Ok(Self { + inner: InnerKeypair::Ed25519(crate::ed25519::Ed25519PrivateKey::new(arr)), + }) + } + #[cfg(feature = "secp256k1")] + SignatureScheme::Secp256k1 => { + if key_bytes.len() != crate::secp256k1::Secp256k1PrivateKey::LENGTH { + return Err(SignatureError::from_source("invalid secp256k1 key length")); + } + let mut arr = [0u8; crate::secp256k1::Secp256k1PrivateKey::LENGTH]; + arr.copy_from_slice(key_bytes); + crate::secp256k1::Secp256k1PrivateKey::new(arr) + .map(InnerKeypair::Secp256k1) + .map(|inner| Self { inner }) + } + #[cfg(feature = "secp256r1")] + SignatureScheme::Secp256r1 => { + if key_bytes.len() != crate::secp256r1::Secp256r1PrivateKey::LENGTH { + return Err(SignatureError::from_source("invalid secp256r1 key length")); + } + let mut arr = [0u8; crate::secp256r1::Secp256r1PrivateKey::LENGTH]; + arr.copy_from_slice(key_bytes); + Ok(Self { + inner: InnerKeypair::Secp256r1(crate::secp256r1::Secp256r1PrivateKey::new( + arr, + )), + }) + } + _ => Err(SignatureError::from_source( + "unsupported signature scheme for SimpleKeypair", + )), + } + } + #[cfg(feature = "pem")] #[cfg_attr(doc_cfg, doc(cfg(feature = "pem")))] /// Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary @@ -461,6 +537,42 @@ mod keypair { } } } + + impl crate::PrivateKeyExt for SimpleKeypair { + // SimpleKeypair doesn't have a single scheme since it can contain any scheme + // We provide a dummy value since we override all methods + const SCHEME: SignatureScheme = SignatureScheme::Ed25519; + + fn scheme(&self) -> SignatureScheme { + self.scheme() + } + + fn to_bytes(&self) -> Vec { + // For SimpleKeypair, to_bytes() already returns flagged bytes + // We need the raw key bytes without the flag for the trait + match &self.inner { + #[cfg(feature = "ed25519")] + InnerKeypair::Ed25519(private_key) => private_key.to_bytes().to_vec(), + #[cfg(feature = "secp256k1")] + InnerKeypair::Secp256k1(private_key) => private_key.to_bytes().as_slice().to_vec(), + #[cfg(feature = "secp256r1")] + InnerKeypair::Secp256r1(private_key) => private_key.to_bytes().as_slice().to_vec(), + } + } + + fn from_raw_bytes(_bytes: &[u8]) -> Result { + // SimpleKeypair can't be created from raw bytes without knowing the scheme + // This should not be called since SimpleKeypair overrides from_flagged_bytes + Err(crate::PrivateKeyError::InvalidScheme( + "SimpleKeypair should use from_bytes instead".to_string(), + )) + } + + fn from_flagged_bytes(bytes: &[u8]) -> Result { + Self::from_bytes(bytes) + .map_err(|e| crate::PrivateKeyError::InvalidScheme(e.to_string())) + } + } } #[cfg(test)] @@ -469,6 +581,7 @@ mod test { use super::*; use crate::{ + PrivateKeyExt, ed25519::{Ed25519PrivateKey, Ed25519VerifyingKey}, secp256k1::{Secp256k1PrivateKey, Secp256k1VerifyingKey}, secp256r1::{Secp256r1PrivateKey, Secp256r1VerifyingKey}, @@ -626,4 +739,68 @@ mod test { let from_pem = SimpleVerifyingKey::from_pem(&pem).unwrap(); assert_eq!(pem, from_pem.to_pem().unwrap()); } + + #[cfg(feature = "bech32")] + #[test] + fn test_bech32_roundtrip_ed25519() { + use rand::{SeedableRng, rngs::StdRng}; + + let keypair: SimpleKeypair = Ed25519PrivateKey::generate(StdRng::from_seed([1; 32])).into(); + let encoded = keypair.to_bech32().unwrap(); + let decoded = SimpleKeypair::from_bech32(&encoded).unwrap(); + assert_eq!(keypair.public_key(), decoded.public_key()); + + // Verify it encodes to the same string + let re_encoded = decoded.to_bech32().unwrap(); + assert_eq!(encoded, re_encoded); + } + + #[cfg(feature = "bech32")] + #[test] + fn test_bech32_roundtrip_secp256k1() { + use rand::{SeedableRng, rngs::StdRng}; + + let keypair: SimpleKeypair = + Secp256k1PrivateKey::generate(StdRng::from_seed([2; 32])).into(); + let encoded = keypair.to_bech32().unwrap(); + let decoded = SimpleKeypair::from_bech32(&encoded).unwrap(); + assert_eq!(keypair.public_key(), decoded.public_key()); + + // Verify it encodes to the same string + let re_encoded = decoded.to_bech32().unwrap(); + assert_eq!(encoded, re_encoded); + } + + #[cfg(feature = "bech32")] + #[test] + fn test_bech32_roundtrip_secp256r1() { + use rand::{SeedableRng, rngs::StdRng}; + + let keypair: SimpleKeypair = + Secp256r1PrivateKey::generate(StdRng::from_seed([3; 32])).into(); + let encoded = keypair.to_bech32().unwrap(); + let decoded = SimpleKeypair::from_bech32(&encoded).unwrap(); + assert_eq!(keypair.public_key(), decoded.public_key()); + + // Verify it encodes to the same string + let re_encoded = decoded.to_bech32().unwrap(); + assert_eq!(encoded, re_encoded); + } + + #[cfg(feature = "bech32")] + #[test] + fn test_bech32_invalid_hrp() { + let invalid_hrp = + "invalidprivkey1qzdlfxn2qa2lj5uprl8pyhexs02sg2wrhdy7qaq50cqgnffw4c247zslwv6"; + let result = SimpleKeypair::from_bech32(invalid_hrp); + assert!(result.is_err()); + } + + #[cfg(feature = "bech32")] + #[test] + fn test_bech32_invalid_data() { + let invalid_data = "iotaprivkey1invalid"; + let result = SimpleKeypair::from_bech32(invalid_data); + assert!(result.is_err()); + } } diff --git a/crates/iota-graphql-client/Cargo.toml b/crates/iota-graphql-client/Cargo.toml index 511c5b57f..6b0a9da43 100644 --- a/crates/iota-graphql-client/Cargo.toml +++ b/crates/iota-graphql-client/Cargo.toml @@ -27,7 +27,7 @@ url = "2.5.3" [dev-dependencies] hex = "0.4.3" -iota-crypto = { path = "../iota-crypto", features = ["ed25519", "pem"] } +iota-crypto = { path = "../iota-crypto", features = ["ed25519", "pem", "bech32"] } iota-transaction-builder = { path = "../iota-transaction-builder" } iota-types = { package = "iota-sdk-types", path = "../iota-sdk-types", features = ["serde", "rand", "hash"] } rand = "0.8.5" diff --git a/crates/iota-graphql-client/examples/generate_ed25519_address.rs b/crates/iota-graphql-client/examples/generate_ed25519_address.rs index 3e3b9d670..b12b0ea92 100644 --- a/crates/iota-graphql-client/examples/generate_ed25519_address.rs +++ b/crates/iota-graphql-client/examples/generate_ed25519_address.rs @@ -2,11 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 use base64ct::{Base64, Encoding}; -use iota_crypto::ed25519::Ed25519PrivateKey; +use iota_crypto::{PrivateKeyExt, ed25519::Ed25519PrivateKey}; use rand::rngs::OsRng; 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 address = public_key.derive_address(); @@ -14,10 +15,7 @@ fn main() { flagged_public_key.extend_from_slice(public_key.as_bytes()); let encoded_public_key = Base64::encode_string(&flagged_public_key); - println!( - "Private Key: {}", - Base64::encode_string(&private_key.to_der().unwrap()) - ); + println!("Private Key: {private_key_bech32}"); println!("Public Key: {public_key}"); println!("Public Key With Flag: {encoded_public_key}"); println!("Address: {address}"); diff --git a/crates/iota-sdk-ffi/Cargo.toml b/crates/iota-sdk-ffi/Cargo.toml index 200944d9a..884cde6d1 100644 --- a/crates/iota-sdk-ffi/Cargo.toml +++ b/crates/iota-sdk-ffi/Cargo.toml @@ -26,7 +26,7 @@ serde_json = "1.0.95" tokio = { version = "1.36.0", features = ["time"] } uniffi = { version = "0.29", features = ["cli", "tokio"] } -iota-crypto = { path = "../iota-crypto", features = ["bls12381", "ed25519", "secp256r1", "passkey", "secp256k1", "zklogin", "pem"] } +iota-crypto = { path = "../iota-crypto", features = ["bls12381", "ed25519", "secp256r1", "passkey", "secp256k1", "zklogin", "pem", "bech32"] } iota-graphql-client = { path = "../iota-graphql-client" } iota-transaction-builder = { path = "../iota-transaction-builder" } iota-types = { package = "iota-sdk-types", path = "../iota-sdk-types", features = ["hash", "rand"] } diff --git a/crates/iota-sdk-ffi/src/crypto/ed25519.rs b/crates/iota-sdk-ffi/src/crypto/ed25519.rs index 70356a9f3..a6e302395 100644 --- a/crates/iota-sdk-ffi/src/crypto/ed25519.rs +++ b/crates/iota-sdk-ffi/src/crypto/ed25519.rs @@ -1,6 +1,7 @@ // Copyright (c) 2025 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use iota_crypto::PrivateKeyExt; use iota_types::SignatureScheme; use rand::rngs::OsRng; @@ -66,6 +67,24 @@ impl Ed25519PrivateKey { Ok(self.0.to_pem()?) } + /// Serialize this private key to bytes. + pub fn to_bytes(&self) -> Vec { + self.0.to_bytes().to_vec() + } + + /// Encode this private key as `flag || privkey` in Bech32 starting with + /// "iotaprivkey" to a string. + pub fn to_bech32(&self) -> Result { + Ok(self.0.to_bech32()?) + } + + /// Decode a private key from `flag || privkey` in Bech32 starting with + /// "iotaprivkey". + #[uniffi::constructor] + pub fn from_bech32(value: &str) -> Result { + Ok(iota_crypto::ed25519::Ed25519PrivateKey::from_bech32(value)?.into()) + } + pub fn try_sign(&self, message: &[u8]) -> Result { Ok(iota_crypto::Signer::::try_sign(&self.0, message)?.into()) } diff --git a/crates/iota-sdk-ffi/src/crypto/secp256k1.rs b/crates/iota-sdk-ffi/src/crypto/secp256k1.rs index 4a17a9b94..942b9ca5c 100644 --- a/crates/iota-sdk-ffi/src/crypto/secp256k1.rs +++ b/crates/iota-sdk-ffi/src/crypto/secp256k1.rs @@ -1,6 +1,7 @@ // Copyright (c) 2025 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use iota_crypto::PrivateKeyExt; use iota_types::SignatureScheme; use rand::rngs::OsRng; @@ -66,6 +67,24 @@ impl Secp256k1PrivateKey { Ok(self.0.to_pem()?) } + /// Serialize this private key to bytes. + pub fn to_bytes(&self) -> Vec { + self.0.to_bytes().to_vec() + } + + /// Encode this private key as `flag || privkey` in Bech32 starting with + /// "iotaprivkey" to a string. + pub fn to_bech32(&self) -> Result { + Ok(self.0.to_bech32()?) + } + + /// Decode a private key from `flag || privkey` in Bech32 starting with + /// "iotaprivkey". + #[uniffi::constructor] + pub fn from_bech32(value: &str) -> Result { + Ok(iota_crypto::secp256k1::Secp256k1PrivateKey::from_bech32(value)?.into()) + } + pub fn try_sign(&self, message: &[u8]) -> Result { Ok( iota_crypto::Signer::::try_sign(&self.0, message)? diff --git a/crates/iota-sdk-ffi/src/crypto/secp256r1.rs b/crates/iota-sdk-ffi/src/crypto/secp256r1.rs index 5b0dbd4e0..8dc25a8a8 100644 --- a/crates/iota-sdk-ffi/src/crypto/secp256r1.rs +++ b/crates/iota-sdk-ffi/src/crypto/secp256r1.rs @@ -3,7 +3,7 @@ use std::sync::Arc; -use iota_crypto::{Signer, Verifier}; +use iota_crypto::{PrivateKeyExt, Signer, Verifier}; use iota_types::SignatureScheme; use rand::rngs::OsRng; @@ -88,6 +88,24 @@ impl Secp256r1PrivateKey { pub fn to_pem(&self) -> Result { Ok(self.0.to_pem()?) } + + /// Serialize this private key to bytes. + pub fn to_bytes(&self) -> Vec { + self.0.to_bytes().to_vec() + } + + /// Encode this private key as `flag || privkey` in Bech32 starting with + /// "iotaprivkey" to a string. + pub fn to_bech32(&self) -> Result { + Ok(self.0.to_bech32()?) + } + + /// Decode a private key from `flag || privkey` in Bech32 starting with + /// "iotaprivkey". + #[uniffi::constructor] + pub fn from_bech32(value: &str) -> Result { + Ok(iota_crypto::secp256r1::Secp256r1PrivateKey::from_bech32(value)?.into()) + } } #[derive(derive_more::From, uniffi::Object)] diff --git a/crates/iota-sdk-ffi/src/crypto/simple.rs b/crates/iota-sdk-ffi/src/crypto/simple.rs index 1f0e619a7..7df1b8ae9 100644 --- a/crates/iota-sdk-ffi/src/crypto/simple.rs +++ b/crates/iota-sdk-ffi/src/crypto/simple.rs @@ -1,14 +1,13 @@ // Copyright (c) 2025 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use iota_crypto::{Signer, Verifier}; +use iota_crypto::{PrivateKeyExt, Signer, Verifier}; use iota_types::SignatureScheme; use crate::{ error::Result, types::{crypto::multisig::MultisigMemberPublicKey, signature::SimpleSignature}, }; - #[derive(derive_more::From, uniffi::Object)] pub struct SimpleVerifier(iota_crypto::simple::SimpleVerifier); @@ -41,6 +40,31 @@ impl SimpleKeypair { self.verifying_key().public_key() } + /// Encode a SimpleKeypair as `flag || privkey` in bytes + pub fn to_bytes(&self) -> Vec { + self.0.to_bytes() + } + + /// Decode a SimpleKeypair from `flag || privkey` bytes + #[uniffi::constructor] + pub fn from_bytes(bytes: &[u8]) -> Result { + Ok(iota_crypto::simple::SimpleKeypair::from_bytes(bytes)?.into()) + } + + /// Encode a SimpleKeypair as `flag || privkey` in Bech32 starting with + /// "iotaprivkey" to a string. Note that the pubkey is not encoded. + pub fn to_bech32(&self) -> Result { + Ok(self.0.to_bech32()?) + } + + /// Decode a SimpleKeypair from `flag || privkey` in Bech32 starting with + /// "iotaprivkey" to SimpleKeypair. The public key is computed directly from + /// the private key bytes. + #[uniffi::constructor] + pub fn from_bech32(value: &str) -> Result { + Ok(iota_crypto::simple::SimpleKeypair::from_bech32(value)?.into()) + } + /// Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary /// format). #[uniffi::constructor]