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

Add Shamir's secret sharing protocol #1010

Closed
tupui opened this issue Dec 12, 2024 · 6 comments · Fixed by #1012
Closed

Add Shamir's secret sharing protocol #1010

tupui opened this issue Dec 12, 2024 · 6 comments · Fixed by #1012

Comments

@tupui
Copy link
Contributor

tupui commented Dec 12, 2024

Is your feature request related to a problem? Please describe.

Keeping secrets can be hard and if someone finds the paper wallet, it's compromised.

Describe the solution you'd like

I would like to propose to add a helper function to split the secret key using the Shamir protocol. The PyCryptodome library has an implementation we could leverage.

We could propose the following APIs:

Keypair.secret.to_shamir(n, k)
Keypair.from_shamir(...)

Of course, naming and input parameters should be worked on.

As usual, I am happy to make a PR if wanted 😃

Describe alternatives you've considered

If not suitable in this library, I will add the feature on my higher level Soroban API library.

Additional context

https://pycryptodome.readthedocs.io/en/latest/src/protocol/ss.html

@overcat
Copy link
Member

overcat commented Dec 13, 2024

Hi @tupui, this is a very good proposal, but I suggest we build this feature based on python-shamir-mnemonic. I think we can trust the implementation provided by Trezor. We just need to add two functions: generate_shamir_mnemonic_phrase and from_shamir_mnemonic_phrase.

BTW. SLIP-39 was drafted by Trezor, so I hope that when using the same shamir mnemonic, the Python SDK and Trezor wallet can generate consistent keypair.

@overcat
Copy link
Member

overcat commented Dec 13, 2024

Keeping secrets can be hard and if someone finds the paper wallet, it's compromised.

In addition, for the existing BIP-39 method, I strongly recommend adding an extra passphrase (aka. 25th word) and memorizing it, which can alleviate this concern to some extent.

@tupui
Copy link
Contributor Author

tupui commented Dec 16, 2024

Awesome, I can take a shot at it if you want 😃

I like the 25 words hack. Wondering if this should get into the API in a way or not. But that's another discussion.

@overcat
Copy link
Member

overcat commented Dec 16, 2024

Hi @tupui, The 25th word is not hack; it is something from the BIP-39 standard, so we have already included support for it, please check https://github.com/StellarCN/py-stellar-base/tree/c5d656f13e63c4049e5cd6c81f396541b96c9833/stellar_sdk/keypair.py#L241-L242

SLIP-39 also has a similar concept, so if you are willing to add SLIP-39 support to this SDK, please also include support for passphrase.

@tupui
Copy link
Contributor Author

tupui commented Dec 17, 2024

I had a Quick Look at the Trezor repo and I two thing caught my eyes:

  1. There is not much activity on the repo (vs pycryptodome)
  2. They have a disclaimer saying this should not be used in prod

Now I am not sure how much we should be concerned about that. Do you have some thoughts there?

@overcat
Copy link
Member

overcat commented Dec 18, 2024

Hi @tupui, I personally prefer using the Trezor library; I believe the risks involved are acceptable, but I suggest configuring this feature as an optional one.

Of course, I don't oppose implementing this feature based on pycryptodome, but if you want to do it using pycryptodome, I recommend creating a brand-new Python package that implements SLIP-39 using pycryptodome, and then we can introduce this package into the SDK. What do you think? This way, other users can also more easily use this new package. However, I estimate that this will require a considerable amount of effort.

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