bitauth icon indicating copy to clipboard operation
bitauth copied to clipboard

Support encoding to / decoding from mnemonic versions of SINs

Open jesstelford opened this issue 10 years ago • 4 comments

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?

jesstelford avatar Jul 01 '14 20:07 jesstelford

... 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 avatar Jul 01 '14 20:07 44203

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

pnagurny avatar Jul 01 '14 20:07 pnagurny

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> }

ryanxcharles avatar Jul 02 '14 01:07 ryanxcharles

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.

devrandom avatar Jul 02 '14 01:07 devrandom