Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ test-strategy = "0.4.0"
thiserror = "2.0"
tokio = "1.40.0"

iota-crypto = { version = "0.0.1-alpha.1", package = "iota-sdk-crypto", path = "crates/iota-sdk-crypto", default-features = false }
iota-graphql-client = { version = "0.0.1-alpha.1", package = "iota-sdk-graphql-client", path = "crates/iota-sdk-graphql-client", default-features = false }
iota-graphql-client-build = { version = "0.0.1-alpha.1", package = "iota-sdk-graphql-client-build", path = "crates/iota-sdk-graphql-client-build", default-features = false }
iota-transaction-builder = { version = "0.0.1-alpha.1", package = "iota-sdk-transaction-builder", path = "crates/iota-sdk-transaction-builder", default-features = false }
iota-types = { version = "0.0.1-alpha.1", package = "iota-sdk-types", path = "crates/iota-sdk-types", default-features = false }
iota-ledger = { package = "iota-ledger", path = "crates/iota-ledger", default-features = false }
iota-ledger-signer = { package = "iota-ledger-signer", path = "crates/iota-ledger-signer", default-features = false }
iota-sdk = { package = "iota-sdk", path = "crates/iota-sdk", default-features = false }
iota-crypto = { package = "iota-sdk-crypto", path = "crates/iota-sdk-crypto", default-features = false }
iota-graphql-client = { package = "iota-sdk-graphql-client", path = "crates/iota-sdk-graphql-client", default-features = false }
iota-graphql-client-build = { package = "iota-sdk-graphql-client-build", path = "crates/iota-sdk-graphql-client-build", default-features = false }
iota-transaction-builder = { package = "iota-sdk-transaction-builder", path = "crates/iota-sdk-transaction-builder", default-features = false }
iota-types = { package = "iota-sdk-types", path = "crates/iota-sdk-types", default-features = false }
65 changes: 65 additions & 0 deletions bindings/go/examples/ledger/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

package main

import (
"fmt"
"log"

"github.com/iotaledger/iota-rust-sdk/bindings/go/iota_sdk"
)

type AsyncSigner struct {
ledger *iota_sdk.LedgerSigner
}

func (signer *AsyncSigner) Sign(transaction *iota_sdk.Transaction) (iota_sdk.TransactionSignerFnOutput, error) {
fmt.Println("BEFORE")
signature, err := signer.ledger.SignTransaction(transaction)
fmt.Println("AFTER")
return iota_sdk.TransactionSignerFnOutput{Signature: signature}, err
}

func main() {
ledger, err := iota_sdk.LedgerSignerNewWithDefault("m/44'/4218'/0'/1'/0'")

if err != nil {
log.Fatalf("Failed to create ledger: %v", err)
}

address, err := ledger.GetAddress()

if err != nil {
log.Fatalf("Failed to get address: %v", err)
}

fmt.Println("Address:", address.ToHex())

// Request funds from faucet
faucet := iota_sdk.FaucetClientNewLocalnet()
_, err = faucet.RequestAndWait(address)
if err.(*iota_sdk.SdkFfiError) != nil {
log.Fatalf("Failed to request faucet: %v", err)
}

client := iota_sdk.GraphQlClientNewLocalnet()

recipientAddress, err := iota_sdk.AddressFromHex("0x0000a4984bd495d4346fa208ddff4f5d5e5ad48c21dec631ddebc99809f16900")
if err != nil {
log.Fatalf("Failed to parse recipient address: %v", err)
}

builder := iota_sdk.NewTransactionBuilder(address).WithClient(client)
builder.SendIota(recipientAddress, iota_sdk.PtbArgumentU64(1000))

signer := iota_sdk.NewTransactionSigner(&AsyncSigner{ledger: ledger})
waitFor := iota_sdk.WaitForTxFinalized
effects, err := builder.Execute(signer, &waitFor)
if err.(*iota_sdk.SdkFfiError) != nil {
log.Fatalf("Failed to execute: %v", err)
}
log.Printf("Digest: %s", iota_sdk.HexEncode((*effects).Digest().ToBytes()))
log.Printf("Transaction status: %v", (*effects).AsV1().Status)
log.Printf("Effects: %+v", (*effects).AsV1())
}
242 changes: 242 additions & 0 deletions bindings/go/iota_sdk/iota_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4169,6 +4169,33 @@ func uniffiCheckChecksums() {
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_ledgersigner_get_address()
})
if checksum != 5173 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_ledgersigner_get_address: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_ledgersigner_get_public_key()
})
if checksum != 26320 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_ledgersigner_get_public_key: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_ledgersigner_sign_transaction()
})
if checksum != 39180 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_method_ledgersigner_sign_transaction: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_method_makemovevector_elements()
})
Expand Down Expand Up @@ -8147,6 +8174,15 @@ func uniffiCheckChecksums() {
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_constructor_ledgersigner_new_with_default()
})
if checksum != 16447 {
// If this happens try cleaning and rebuilding your project
panic("iota_sdk_ffi: uniffi_iota_sdk_ffi_checksum_constructor_ledgersigner_new_with_default: UniFFI API checksum mismatch")
}
}
{
checksum := rustCall(func(_uniffiStatus *C.RustCallStatus) C.uint16_t {
return C.uniffi_iota_sdk_ffi_checksum_constructor_makemovevector_new()
})
Expand Down Expand Up @@ -18697,6 +18733,212 @@ func (_ FfiDestroyerInput) Destroy(value *Input) {



type LedgerSignerInterface interface {
GetAddress() (*Address, error)
GetPublicKey() (*Ed25519PublicKey, error)
SignTransaction(transaction *Transaction) (*UserSignature, error)
}
type LedgerSigner struct {
ffiObject FfiObject
}


func LedgerSignerNewWithDefault(path string) (*LedgerSigner, error) {
_uniffiRV, _uniffiErr := rustCallWithError[LedgerSignerError](FfiConverterLedgerSignerError{},func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer {
return C.uniffi_iota_sdk_ffi_fn_constructor_ledgersigner_new_with_default(FfiConverterStringINSTANCE.Lower(path),_uniffiStatus)
})
if _uniffiErr != nil {
var _uniffiDefaultValue *LedgerSigner
return _uniffiDefaultValue, _uniffiErr
} else {
return FfiConverterLedgerSignerINSTANCE.Lift(_uniffiRV), nil
}
}



func (_self *LedgerSigner) GetAddress() (*Address, error) {
_pointer := _self.ffiObject.incrementPointer("*LedgerSigner")
defer _self.ffiObject.decrementPointer()
_uniffiRV, _uniffiErr := rustCallWithError[LedgerSignerError](FfiConverterLedgerSignerError{},func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer {
return C.uniffi_iota_sdk_ffi_fn_method_ledgersigner_get_address(
_pointer,_uniffiStatus)
})
if _uniffiErr != nil {
var _uniffiDefaultValue *Address
return _uniffiDefaultValue, _uniffiErr
} else {
return FfiConverterAddressINSTANCE.Lift(_uniffiRV), nil
}
}

func (_self *LedgerSigner) GetPublicKey() (*Ed25519PublicKey, error) {
_pointer := _self.ffiObject.incrementPointer("*LedgerSigner")
defer _self.ffiObject.decrementPointer()
_uniffiRV, _uniffiErr := rustCallWithError[LedgerSignerError](FfiConverterLedgerSignerError{},func(_uniffiStatus *C.RustCallStatus) unsafe.Pointer {
return C.uniffi_iota_sdk_ffi_fn_method_ledgersigner_get_public_key(
_pointer,_uniffiStatus)
})
if _uniffiErr != nil {
var _uniffiDefaultValue *Ed25519PublicKey
return _uniffiDefaultValue, _uniffiErr
} else {
return FfiConverterEd25519PublicKeyINSTANCE.Lift(_uniffiRV), nil
}
}

func (_self *LedgerSigner) SignTransaction(transaction *Transaction) (*UserSignature, error) {
_pointer := _self.ffiObject.incrementPointer("*LedgerSigner")
defer _self.ffiObject.decrementPointer()
res, err :=uniffiRustCallAsync[LedgerSignerError](
FfiConverterLedgerSignerErrorINSTANCE,
// completeFn
func(handle C.uint64_t, status *C.RustCallStatus) unsafe.Pointer {
res := C.ffi_iota_sdk_ffi_rust_future_complete_pointer(handle, status)
return res
},
// liftFn
func(ffi unsafe.Pointer) *UserSignature {
return FfiConverterUserSignatureINSTANCE.Lift(ffi)
},
C.uniffi_iota_sdk_ffi_fn_method_ledgersigner_sign_transaction(
_pointer,FfiConverterTransactionINSTANCE.Lower(transaction)),
// pollFn
func (handle C.uint64_t, continuation C.UniffiRustFutureContinuationCallback, data C.uint64_t) {
C.ffi_iota_sdk_ffi_rust_future_poll_pointer(handle, continuation, data)
},
// freeFn
func (handle C.uint64_t) {
C.ffi_iota_sdk_ffi_rust_future_free_pointer(handle)
},
)

return res, err
}
func (object *LedgerSigner) Destroy() {
runtime.SetFinalizer(object, nil)
object.ffiObject.destroy()
}

type FfiConverterLedgerSigner struct {}

var FfiConverterLedgerSignerINSTANCE = FfiConverterLedgerSigner{}


func (c FfiConverterLedgerSigner) Lift(pointer unsafe.Pointer) *LedgerSigner {
result := &LedgerSigner {
newFfiObject(
pointer,
func(pointer unsafe.Pointer, status *C.RustCallStatus) unsafe.Pointer {
return C.uniffi_iota_sdk_ffi_fn_clone_ledgersigner(pointer, status)
},
func(pointer unsafe.Pointer, status *C.RustCallStatus) {
C.uniffi_iota_sdk_ffi_fn_free_ledgersigner(pointer, status)
},
),
}
runtime.SetFinalizer(result, (*LedgerSigner).Destroy)
return result
}

func (c FfiConverterLedgerSigner) Read(reader io.Reader) *LedgerSigner {
return c.Lift(unsafe.Pointer(uintptr(readUint64(reader))))
}

func (c FfiConverterLedgerSigner) Lower(value *LedgerSigner) unsafe.Pointer {
// TODO: this is bad - all synchronization from ObjectRuntime.go is discarded here,
// because the pointer will be decremented immediately after this function returns,
// and someone will be left holding onto a non-locked pointer.
pointer := value.ffiObject.incrementPointer("*LedgerSigner")
defer value.ffiObject.decrementPointer()
return pointer

}

func (c FfiConverterLedgerSigner) Write(writer io.Writer, value *LedgerSigner) {
writeUint64(writer, uint64(uintptr(c.Lower(value))))
}

type FfiDestroyerLedgerSigner struct {}

func (_ FfiDestroyerLedgerSigner) Destroy(value *LedgerSigner) {
value.Destroy()
}



type LedgerSignerErrorInterface interface {
}
type LedgerSignerError struct {
ffiObject FfiObject
}



func (object *LedgerSignerError) Destroy() {
runtime.SetFinalizer(object, nil)
object.ffiObject.destroy()
}

type FfiConverterLedgerSignerError struct {}

var FfiConverterLedgerSignerErrorINSTANCE = FfiConverterLedgerSignerError{}



func (_self LedgerSignerError) Error() string {
return "LedgerSignerError"
}

func (_self *LedgerSignerError) AsError() error {
if _self == nil {
return nil
} else {
return _self
}
}
func (c FfiConverterLedgerSignerError) Lift(pointer unsafe.Pointer) *LedgerSignerError {
result := &LedgerSignerError {
newFfiObject(
pointer,
func(pointer unsafe.Pointer, status *C.RustCallStatus) unsafe.Pointer {
return C.uniffi_iota_sdk_ffi_fn_clone_ledgersignererror(pointer, status)
},
func(pointer unsafe.Pointer, status *C.RustCallStatus) {
C.uniffi_iota_sdk_ffi_fn_free_ledgersignererror(pointer, status)
},
),
}
runtime.SetFinalizer(result, (*LedgerSignerError).Destroy)
return result
}

func (c FfiConverterLedgerSignerError) Read(reader io.Reader) *LedgerSignerError {
return c.Lift(unsafe.Pointer(uintptr(readUint64(reader))))
}

func (c FfiConverterLedgerSignerError) Lower(value *LedgerSignerError) unsafe.Pointer {
// TODO: this is bad - all synchronization from ObjectRuntime.go is discarded here,
// because the pointer will be decremented immediately after this function returns,
// and someone will be left holding onto a non-locked pointer.
pointer := value.ffiObject.incrementPointer("*LedgerSignerError")
defer value.ffiObject.decrementPointer()
return pointer

}

func (c FfiConverterLedgerSignerError) Write(writer io.Writer, value *LedgerSignerError) {
writeUint64(writer, uint64(uintptr(c.Lower(value))))
}

type FfiDestroyerLedgerSignerError struct {}

func (_ FfiDestroyerLedgerSignerError) Destroy(value *LedgerSignerError) {
value.Destroy()
}



// Command to build a move vector out of a set of individual elements
//
// # BCS
Expand Down
Loading
Loading