bitcoinjs / aezeed

A package for encoding, decoding, and generating mnemonics of the aezeed specification. (WIP)
MIT License
14 stars 2 forks source link

API Changes #1

Open lukechilds opened 3 years ago

lukechilds commented 3 years ago

Thanks for this Jon! This actually came in really helpful for something I was working on.

Could I suggest a few API changes that I think make it a little simpler to use?

To generate a mnemonic there are currently three steps involved and it involves generating a seed, encrypting it with the default password, decrypting it, and then re-encrypting with a user supplied password.

const seed = CipherSeed.random();
CipherSeed {
  entropy: <Buffer 00 3f ec 3f c0 8b 5f e5 85 62 0d 46 83 6d a2 fd>,
  salt: <Buffer 17 97 44 7e 2f>,
  internalVersion: 0,
  birthday: 4256
}
const mnemonic = seed.toMnemonic();
'abandon program category judge luggage guitar crash naive close refuse salmon royal question school giraffe spell engine obvious total material title trash together meat'
const mnemonicWithPassword = CipherSeed.changePassword(mnemonic, null, 'my password');
'abandon brain finish guide nose bamboo early weird figure birth egg bargain safe alley diesel acquire tackle judge total material title plate blush bargain'

The high scrypt params also make this quite slow.

Would be great if it could be done with just:

const mnemonic = CipherSeed.generateMnemonic();
'abandon program category judge luggage guitar crash naive close refuse salmon royal question school giraffe spell engine obvious total material title trash together meat'

// or

const mnemonicWithPassword = CipherSeed.generateMnemonic({password: 'my password'});
'abandon brain finish guide nose bamboo early weird figure birth egg bargain safe alley diesel acquire tackle judge total material title plate blush bargain'

// or

const mnemonicWithPassword = CipherSeed.generateMnemonic({
  password: 'my password',
  internalVersion: 0,
});
'abandon brain finish guide nose bamboo early weird figure birth egg bargain safe alley diesel acquire tackle judge total material title plate blush bargain'

It then becomes a single command, with or without a passphrase, and avoids extra encryption/decryption.

Also maybe

CipherSeed.changePassword(mnemonic, oldPassword, newPassword);

could be:

CipherSeed.changePassword(mnemonic, {oldPassword, newPassword});

That way if the old password is the default, instead of having to pass in null params like:

CipherSeed.changePassword(mnemonic, null, 'my password')

You can just skip them and pass in the properties you care about like:

CipherSeed.changePassword(mnemonic, {newPassword: 'my password'})

Also why is the exported class called CipherSeed? Maybe Aezeed would be a better name?

Let me know what you think and if you're interested in a PR for any of these.

junderw commented 3 years ago

Some of my comments from our chat: (posted for sharing purposes)

junderw commented 3 years ago

I think maybe we should mimic the BIP39 API except instead of inserting Buffers and getting out mnemonic strings it should be inserting CipherSeeds and getting out mnemonic strings.