StackmateNetwork / stackmate-core

light-weight bitcoin wallet tools for mobile devices.
MIT License
9 stars 2 forks source link

policypath for multisig #17

Closed MrUnfunny closed 2 years ago

MrUnfunny commented 2 years ago

Hey @i5hi, I'm trying to create a multisig transaction but not sure what to pass in policyPath in buildTransaction(). In bdk-cli, we use policies to get policy and use it's id but I'm unable to find something similar here. What should I pass to policyPath in buildTransaction?

i5hi commented 2 years ago

Hey @MrUnfunny

With multisig, or any script that has multiple conditions, you have to specify which condition you are signing for before hand.

More details on this can be found here: https://bitcoindevkit.org/bdk-cli/interface/#policies

Edit: Corrected link

In stackmate-core there is a function called policy_id you can use that to get the value that you have to use with build_tx.

i5hi commented 2 years ago

The policy_id function is not extensively tested against many scripts, but it should work for simple multisigs.

It currently returns the root node is, rather than the id of any specific condition. From what I understand, by specifying the root node id you can sign for any condition. I could be wrong here though.

MrUnfunny commented 2 years ago

Thanks. policy_id is not available in the bindings, that's why I missed it. It returns in form of <boolean>,<policy_id>. Docs say that boolean tells whether policy_path is required.

So, If we are using only multisig descriptor, we don't need to use policyPath?

One more unrelated question. Isn't it possible to use bdk-ffi to create bindings and if it is, Is there any reason why you didn't use it?

i5hi commented 2 years ago

policy path is ONLY required for complex scripts like multisigs. Single sigs don't require it. If you use policy_id and pass a multisig descriptor it will return true, policy_id

So yes, you need policyPath for multisig.

Regarding bdk-ffi:

I started this project last year before bdk-ffi, hence they are two separate projects. If you are building native apps I would suggest using bdk-ffi since they have better bindings to Kotlin and Swift and much higher standard Rust.

This project was a learning process for me.

There was no library that had direct compatibility with dart so I had to do it myself.

To be honest, there is a lot that can improve with stackmate-core. Its a very naive implementation but it is safe and it works so we use it. The project is currently on hold so it might be worth looking into other alternatives.

There is another bdk project that is attempting to create a dart library and preserve the bdk api.

I would recommend joining their discord channel. They are extremely helpful.

MrUnfunny commented 2 years ago

I've joined their discord. You must be talking about bdk-flutter. I'm going through it right now. I think I need to learn more about rust to understand the details 😅 Thanks for the your support.