-
Notifications
You must be signed in to change notification settings - Fork 36
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
Deterministic secrets and restore from seed phrase 🔥 #91
Conversation
First note, can we update the example in the description? I don't really know where |
I was getting confused with some of the variable names, help me out here:
One thing to note, what happens if there is a conflict? I imagine that the same note can be signed for with different amounts (i.e. Should mints be guarding against this case themselves? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Only nitpicks I have are about variable naming!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work. Only nitpick is that count
variable, but consider this my ACK.
What bip32 paths were used for secrets and blinding factors? |
We haven't officially specced this in a NUT yet but we're now using the same path for two implementations. Source: cashubtc/nutshell#131 |
One remark to the example code:
It is unclear where the mint.keys comes from, yet it is crucial for the code to run. Initializing wallet without keys is possible and if seed is provided causes low-level failure:
Suggestion is that keys param is validated for presence if seed is provided. |
For deterministic seed based wallet, there seems to be a bug when creating blinded messages with counter that is passed into the derivation path. Bug causes the messages to keep and send having the duplicate _B, subsequently being refused by the mint validation when passed to the /split service. Log showing the issue:
|
Performance issue - creating a CashuWallet instance with seed takes 9 - 10 seconds on mobile device.
caused by:
In case of more then one instances for different mints, method runs mutiple times even seed is the same. |
Wow that's pretty long. I guess we should give the option to instantiate from seed instead from mnemonic. Or what do you suggest? |
It is measired in dev mode, but still will be half of that in prod. |
Actually seed2mnemonic makes no sense as the seed is derived using PBKDF function. Sorry for confusion. So perhaps to store both the seed and the derived key in wallet secure store is a way to go. |
Yes i think we have to store both in that case. Mnemonic for showing, seed for improved performance. |
That means, the wallet needs to be initialized with seed, and not mnemonic, and we need to expose the seed somehow, maybe as a secondary step after creating a mnemonic as a separate function |
I found out the hopefully final issue causing the duplicate _B messages passed from wallet to the mint causing failure. In case there are gaps in proof sequence vs the counter it is not enough to set the initial counter after the restore to the number of recreated proofs (spent or not). To be safe against gaps, I believe the counter needs to be set to upper limit of the used recovery interval (e.g. 50 for 1...50) and then further incremented by the number of recovered (only unspent/pending) proofs. If ack, this should be explicitly named / mentioned in the docs as not following it breaks further wallet operations. There is related fix on the nutshell mint side pending (to prevent such duplicate messages account for as spent by mint) |
@callebtc there are still requested changes pending from you. Can you take a look and check if it's ok now? And then let's merge this badboy! |
new feature: Deterministic secrets and restore from seed phrase 🔥
Description
This PR introduces the functionality for creating ecash derived from a seed. This allows for a backup and restore scheme where the wallet owner only needs to store the 12 words seed phrase to restore his ecash.
Changes
External changes
generateNewMnemonic()
for creating new mnemonicsmnemonic
param to pass mnemonic toCashuWallet
constructorcount
param to all functions that create tokens, to pass the current state of the derivation pathInternal changes
mnemonic
andcount
are presentcreateblankOutputs
to reduce duplicate codeThere are no breaking changes, deterministic secrets is opt in. By ommiting
count
ormnemonic
params, ecash will be generated randomly.how it works
presentation slides --> https://det-sec.gandlaf.com/
Usage
PR Tasks
npm run test
--> no failing unit testsnpm run format