bdk-ffi icon indicating copy to clipboard operation
bdk-ffi copied to clipboard

Explore KMP as viable library

Open thunderbiscuit opened this issue 2 years ago • 5 comments

I'm quite confident we should be able to build a Kotlin Multiplatform using the bdk-android and bdk-swift libraries.

I'm starting to explore this a bit more and will share an example repo soon.

thunderbiscuit avatar Nov 16 '22 19:11 thunderbiscuit

Some interesting links:

  1. https://touchlab.github.io/KMMBridge/intro
  2. https://engineering.premise.com/kotlin-multiplatform-at-premise-b28d85825c9f

thunderbiscuit avatar Nov 16 '22 19:11 thunderbiscuit

Also relevant to this conversation: https://gitlab.com/trixnity/uniffi-kotlin-multiplatform-bindings

thunderbiscuit avatar Jan 10 '23 20:01 thunderbiscuit

I have something sorta working in this repo. Only Kotlin side at the moment. I'd love to pair program the iOS side of this if anyone is interested!

There is probably a few different ways to go about this (for example I have not tried trixnity's kmp bindings plugin yet.

A few small things I still need to figure out:

  1. It appears you can't use data classes directly (no big deal but it's a slight change from the standard bdk-android) You basically just transform data classes into normal classes. Attempting to use the expect/actual construct will throw
expect data class ElectrumConfig {}
// Modifier 'data' is incompatible with 'expect'
  1. You can't seem to use expect/actual on sealed classes. This is what gets used on the bdk-android side to represent enums variants that contain data structures. For example, the BlockchainConfig type in bdk-android is:
// bdk-android
sealed class BlockchainConfig {
    data class Electrum(val config: ElectrumConfig) : BlockchainConfig()
    data class Esplora(val config: EsploraConfig) : BlockchainConfig()
    data class Rpc(val config: RpcConfig) : BlockchainConfig()   
}

But I don't think you can use the expect/actual construct on inner classes

// bdk-kmp
// doesn't work: Modifier 'expect' is not applicable to 'nested class' 
expect sealed class BlockchainConfig {
    expect class Electrum(val config: ElectrumConfig) : BlockchainConfig()
    expect class Esplora(val config: EsploraConfig) : BlockchainConfig()
    expect class Rpc(val config: RpcConfig) : BlockchainConfig()   
}

thunderbiscuit avatar Feb 16 '23 17:02 thunderbiscuit

New link related to the plugin: https://github.com/wireapp/core-crypto/pull/214.

thunderbiscuit avatar Mar 23 '23 12:03 thunderbiscuit

I have something sorta working in this repo. Only Kotlin side at the moment. I'd love to pair program the iOS side of this if anyone is interested!

Happy to pair program the iOS side if this is still something you're interested in working on-

reez avatar Apr 30 '24 01:04 reez