lightsail-network / java-stellar-sdk

The Java Stellar SDK library provides APIs to build transactions and connect to Horizon and Soroban-RPC Server.
https://javadoc.io/doc/network.lightsail/stellar-sdk
Apache License 2.0
176 stars 162 forks source link

SEP-0005 (and BIP-39) #74

Closed PegasusWallet closed 5 years ago

PegasusWallet commented 6 years ago

99% of the code is already done in BitcoinJ and really just a matter of rewriting the Key derivation to use the right "ed25519 seed" instead of "Bitcoin seed"

@bartekn Do you already have something planned or should I go ahead and prepare a PR ?

bartekn commented 6 years ago

Not sure how BitcoinJ works internally but if there are no add-ons it is most likely using secp256k1 curve whereas Stellar is using ed25519. So it's not only about changing the seed.

Anyway, if you decide to do it I think we should have another package for key derivation that allows developers to generate a secret seed for a given mnemonic seed and key path that can later be used to create a Keypair object.

PegasusWallet commented 6 years ago

Yes indeed there is actually a bit more work that what I thought. secp256k1 is heavily hardcoded in bitcoinj code using spongycastle (which does not even support ed25519 but only curve25519) and all the interesting classes are final which makes it difficult to reuse the code.

I have a working code that allows me to

I can match all the testing vector in the SEP-0005 document.

(This is an example to generate an account for index 0) https://imgur.com/a/1YSO7

But for now I'm using the entire BitcoinJ library + modified some of the classes. I will need to clean it up and only extract the usefull class to be able to create a PR

elucidsoft commented 6 years ago

Hey guys, I wrote a .NET version of BIP39 based on the Javascript one. It's fully functional, we plan to integrate this into our .NET SDK. But could you use this as a starting point for the Java version maybe? It has zero external dependencies which were one of the goals, so it does not depend on any external frameworks.

https://github.com/elucidsoft/dotnetstandard-bip39

bartekn commented 6 years ago

@elucidsoft I glanced at your repository and it seems there's the same problem I mentioned in my first comment. Specifically:

Not sure how BitcoinJ works internally but if there are no add-ons it is most likely using secp256k1 curve whereas Stellar is using ed25519.

Also, what do you mean by saying:

But could you use this as a starting point for the Java version maybe?

elucidsoft commented 6 years ago

That's a non issue with ed25519. Mainly what I meant was to remove the dependency issue you have with BitcoinJ.

bartekn commented 6 years ago

OK, I understand now. Your .NET package implement BIP-39 but to derive Stellar addresses you also need BIP-32 (actually SLIP-0010) with ed25519. This is the harder part.

More info in SEP-0005.

elucidsoft commented 6 years ago

Ok so I finally got some time to work on this, I have published the results here https://github.com/elucidsoft/dotnetstandard-bip32/tree/master

It's working and all the unit tests mentioned in the spec are passing.

elucidsoft commented 6 years ago

So I went ahead and built a tiny little HD Wallet Project as well with a bunch of unit tests that combines BIP39 and BIP32 together to demonstrate it working. https://github.com/elucidsoft/dotnetstandard-stellar-hd-wallet

MicicFilip commented 5 years ago

@PegasusWallet Could you be kind and share the source where you translate BIP39 seeds to a valid Stellar KeyPair? Thanks in advance

elucidsoft commented 5 years ago

All source is on my GitHub

On Wed, Oct 24, 2018, 8:41 AM Filip Mićić notifications@github.com wrote:

@PegasusWallet https://github.com/PegasusWallet Could you be kind and share the source where you translate BIP32 seeds to a valid Stellar KeyPair? Thanks in advance

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stellar/java-stellar-sdk/issues/74#issuecomment-432638970, or mute the thread https://github.com/notifications/unsubscribe-auth/AANRUJmciH0vY9x-82AZXe8gAlC1G6sPks5uoGALgaJpZM4Ruclp .

MicicFilip commented 5 years ago

Thank you @elucidsoft , but I was asking about @PegasusWallet source code. Because of the Java implementation

bartekn commented 5 years ago

Closed in #148.