Feat: add server action for decryption of shares and reconstruct it back to the private key #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feat: add server action for decryption of shares and reconstruct it back to the private key
Main Addition:
I have added a server action that first decrypts all the shares of the user after pulling them from the database via AES, AWS, and GCP decrypt modules. I have also added a new
shamirCombine()
function which I use next to reconstruct the decrypted shares into the original private key of the user.I also fixed some encoding issues that popped up while working on this, by correctly implementing base58 for decoding the private key to a Uint8Array before splitting and also encoding the reconstructed key back to base58 after combining.
Explanation of the Fix:
Before, we were not correctly encoding the private key after generating them from the keyPair before sending it to the
shamirSplit()
function and these faulty shares were being encrypted which further caused errors while combining these shares during reconstruction. We now always encode and decode the private key right from the generation in base58 format which is a popular encoding format for crypto public/ private keys.https://www.npmjs.com/package/bs58
Video Demonstration:
I am currently adding some
console.logs
to show if both the generated private key is the same as the reconstructed one. I will be removing these logs in this PR as it is not good practice to log user's private keys but you can add the same logs which I show in the video to test it out for yourself!server-action-reconstruction.mp4
Issue Number: Resolves #169
🛠️ Type of Change
✅ Checklist
To ensure a smooth review process, please check off each item as you complete it: