Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support encoding to / decoding from mnemonic versions of SINs #4

Open
jesstelford opened this issue Jul 1, 2014 · 4 comments
Open

Comments

@jesstelford
Copy link

Just like electrum provides mnemonic versions of private keys, it would be great if Bitauth could provide this too, directly within the library itself.

This would make memorizing the key much easier for the end user, allowing them to carry their identity with them across devices with minimum friction.

For example, provide two more methods:

bitauth.decodeSinMnemonic(String) -> String - Would take in the mnemonic string as an argument, and output the raw SIN as the return value. This method would be used internally by:

bitauth.getPublicKeyFromPrivateKeyMnemonic(String) -> String - Would take in the mnemonic string as an argument, and output the public key.

I'm not certain at which point the mnemonic should be generated. I considered inside bitauth. generateSin(), but it seems it would be out of place there - thoughts on how you would go about it?

@44203 44203 self-assigned this Jul 1, 2014
@44203
Copy link
Contributor

44203 commented Jul 1, 2014

... and i accidentally deleted my comment, while trying to edit it. Go me.

I think this would be great, but it might make more sense to implement the mnemonic generation in bitcore and pass through an options object from bitauth like:

bitauth.generateSin({ mnemonic: true });

I'd like to hear @ryanxcharles thoughts on this.

As far as the proposed methods for decodeSinMnemonic() and getPublicKeyFromPrivateKeyMnemonic(), I'm all for it. Maybe @pnagurny wants to chime in?

@44203 44203 removed their assignment Jul 1, 2014
@pnagurny
Copy link
Contributor

pnagurny commented Jul 1, 2014

Yeah I agree it should probably be in bitcore first, and then we can pass it through.

@ryanxcharles
Copy link
Contributor

Thanks to @devrandom, bitcore supports BIP39. This is a way of converting secure random entropy into a mnemonic seed. Note that you must derive your private keys this way from the start, since the private key is the hash of the mnemonic. You can't convert an existing private key into a mnemonic using BIP39. Here's an example session where I generate a new random mnemonic and use that to make a Key:

> var m = bitcore.BIP39.mnemonic(bitcore.BIP39WordlistEn, 256);
undefined
> m;
'crew spider exit material night hurdle fetch wealth situate put risk entire shy range uniform season distance creek mercy castle unusual oak pilot need'
> var key = new bitcore.Key();
undefined
> key.private = bitcore.BIP39.mnemonic2seed(m).slice(0, 32);
<Buffer f7 c9 8c 10 6c b5 c1 d1 5a 80 8f 6c 0e 29 01 df a4 66 c1 78 b1 34 58 89 b2 70 af 65 0a 79 74 18>
> key.regenerateSync();
undefined
> key;
{ compressed: true,
  public: <SlowBuffer 02 1e aa 0b 37 1d 8d 2b 13 17 c7 1b d2 1e 18 09 f3 34 a1 50 58 ee 95 c4 89 aa 41 87 5b c3 95 2b e0>,
  private: <SlowBuffer f7 c9 8c 10 6c b5 c1 d1 5a 80 8f 6c 0e 29 01 df a4 66 c1 78 b1 34 58 89 b2 70 af 65 0a 79 74 18> }

@devrandom
Copy link

Nice use of BIP39!

BTW, I wonder if it would be appropriate for SINKeys to be generated using BIP32. You'd have just one secret for convenient backups while allowing the creation of any number of unlinkable credentials for different apps.

bitjson pushed a commit that referenced this issue Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants