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

feat: add cookbook recipe how to generate keys #223

Merged
merged 14 commits into from
Aug 1, 2023

Conversation

trusch
Copy link
Contributor

@trusch trusch commented Mar 3, 2023

This adds a cookbook recipe how to generate all keys necessary for the following recipes, so a user can start at zero.

fixes KILTProtocol/ticket#2373

How to test:

Build the docs and go to the DID section of the cookbook. The very first item is new and explains how to generate keys.

Checklist:

  • I have verified that the code works
  • I have verified that the code is easy to understand
    • If not, I have left a well-balanced amount of inline comments
  • I have left the code in a better state
  • I have documented the changes (where applicable)

@trusch trusch requested a review from weichweich March 3, 2023 10:16
Copy link
Contributor

@weichweich weichweich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Some small things... Could you explain what happens in the the code?

  • how are the keys generated?
    • why are some using derivation paths?
    • why use the base mnemonic for the authentication key?

Could you also add links to the places where this might be interesting? e.g. DID creation?

@trusch trusch requested a review from weichweich March 23, 2023 09:25
@trusch
Copy link
Contributor Author

trusch commented Mar 23, 2023

@weichweich I addressed all of your comments, PTAL :)

@trusch trusch force-pushed the feat/key-generation-recipe branch from 10553b9 to 89dba2e Compare March 23, 2023 09:53
@aws-amplify-eu-central-1
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-223.d3oeht7cvddn19.amplifyapp.com

Copy link
Contributor

@weichweich weichweich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still would like to see something that explains the derivation paths.

Copy link
Member

@ntn-x2 ntn-x2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add a mention to Sporran, explaining that the derivation path shown is the same Sporran uses, it's good to go!

// This allows us to restore all keys related to this DID from a single mnemonic seed phrase.
// The chosen derivation pathes can be anything, but here we use the purpuse of the keys to be generated.
const authenticationKey = baseSignerKey.derive(
'//authentication'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we follow the way Sporran does it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was about to update this. This would mean that our current accounts and DIDs used in the testing would break but hopefully fix itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though we already have this in the utils folder in the core_features. Therefore, I would take over this PR and sort it out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is good to make it consistent with the workshop, that is already using the derivation paths from sporran.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I was going to basically copy pasta it in.

Comment on lines 10 to 12
Creating a DID (like in [Light DID Creation](./01_light_did_creation.md) or [Full DID Creation](./02_full_did_creation.md)) requires the generation of some keying material for keys that are to be used for authentication and encryption.

The following is an example of how to create a a set of keypairs suitable for generating a KILT DID from it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like this:

Suggested change
Creating a DID (like in [Light DID Creation](./01_light_did_creation.md) or [Full DID Creation](./02_full_did_creation.md)) requires the generation of some keying material for keys that are to be used for authentication and encryption.
The following is an example of how to create a a set of keypairs suitable for generating a KILT DID from it.
Creating a Decentralized Identifier (DID) in the KILT network involves generating keying material for authentication and encryption. In this guide, we'll demonstrate how to create a set of key pairs suitable for generating a KILT DID.
Before we proceed, it's important to note that this example assumes the usage of the @kiltprotocol/sdk-js library along with the @polkadot/util-crypto library for cryptographic operations. Additionally, we want to emphasize the significance of securely storing keys and the mnemonic seed phrase. For production use, ensure that private keys are encrypted and stored safely, while also creating a backup of the mnemonic seed phrase.
Below is an example code snippet illustrating the key pair generation for a KILT DID:

Also please explain the reason for the derivation paths

Maybe like that:

In the example provided, we derive different types of keys from a single account using derivation paths. This approach allows us to generate various key pairs for authentication, key agreement, assertion methods, and capability delegation from one mnemonic seed phrase. Using derivation paths simplifies key management, ensuring that a single mnemonic seed serves as the basis for multiple keys associated with a DID. This method improves efficiency while maintaining security. However, it's essential to handle and store private keys securely to prevent unauthorized access and ensure the overall integrity and privacy of the decentralized identity system.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soooo much 🤖

@Dudleyneedham Dudleyneedham force-pushed the feat/key-generation-recipe branch 2 times, most recently from e02e592 to a9895e8 Compare August 1, 2023 09:10
Copy link
Contributor

@weichweich weichweich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Dudleyneedham Dudleyneedham merged commit 827222a into master Aug 1, 2023
6 checks passed
@Dudleyneedham Dudleyneedham deleted the feat/key-generation-recipe branch August 1, 2023 10:59
Dudleyneedham added a commit that referenced this pull request Aug 2, 2023
* feat: add cookbook recipe how to generate keys (taken from the workshop section)

* fix broken test

* run prettier

* try to fix test

* prettier

* try to fix test

* prettier

* add more explanations about derivation pathes

* feat: updating to match sporran and updating naming throughout to match

* lint: updating the linting

* feat: removal of the mention of light did

* feat: adding remarks and suggestions for better text

* Update docs/develop/01_sdk/02_cookbook/01_dids/00_generate_keys.md

Co-authored-by: Albrecht <[email protected]>

---------

Co-authored-by: dudleyneedham <[email protected]>
Co-authored-by: Skedley <[email protected]>
Co-authored-by: Albrecht <[email protected]>
Dudleyneedham added a commit that referenced this pull request Aug 4, 2023
* feat: add cookbook recipe how to generate keys (taken from the workshop section)

* fix broken test

* run prettier

* try to fix test

* prettier

* try to fix test

* prettier

* add more explanations about derivation pathes

* feat: updating to match sporran and updating naming throughout to match

* lint: updating the linting

* feat: removal of the mention of light did

* feat: adding remarks and suggestions for better text

* Update docs/develop/01_sdk/02_cookbook/01_dids/00_generate_keys.md

Co-authored-by: Albrecht <[email protected]>

---------

Co-authored-by: dudleyneedham <[email protected]>
Co-authored-by: Skedley <[email protected]>
Co-authored-by: Albrecht <[email protected]>
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

Successfully merging this pull request may close these issues.

5 participants