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

API Changes #1

Open
lukechilds opened this issue Aug 30, 2020 · 2 comments
Open

API Changes #1

lukechilds opened this issue Aug 30, 2020 · 2 comments

Comments

@lukechilds
Copy link
Member

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
Copy link
Member

junderw commented Aug 30, 2020

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

  • you can pass a password to toMnemonic(), so not 3 steps, but 2.
  • aezeed is referring to the phrase format itself. I call it mnemonic because that's what people are used to.
  • CipherSeed is referring to the data structure encoded in the aezeed
  • also I was mimicing the API for the aezeed package in LND (go)
  • I'm open to any suggestions, but I think the internal data structure should be its own class like it is now. but you are right the API is a tad awkward
  • maybe remove some of the static methods and make them exported functions alongside the CipherSeed

@junderw
Copy link
Member

junderw commented Aug 30, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants