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 Crypto Algorithm, KeyManager, and KMS to crypto package #152

Merged
merged 41 commits into from
Jul 10, 2023
Merged

Conversation

frankhinek
Copy link
Contributor

@frankhinek frankhinek commented Jul 9, 2023

This PR adds a significant amount of functionality to the crypto package but does so in a way that very minimal changes were made to existing functionality. Once merged, these capabilities will be incrementally used across the Web5.js SDK.

Note
There are no changes to any external web5.*.* APIs.

common package

  • Adds Convert utility to convert between data and encoding types.
  • Adds Multicodec utility to make it easier to add and remove Multicodec prefixes, primarily used in the generation of DID identifiers.
  • Adds a MemoryStore implementation that can be used for prototyping or testing key/value stores used by any project.
  • Adds Type utilities: isArrayBufferSlice, isDefined, and universalTypeOf

crypto package

  • The crypto package previously had a dependency on multiformats but the inclusion of the functionality that required this dependency was not crypto specific. As a result, the common functionality was moved to the common package in the form of the new Multicodec implementation and the DID-specific functionality was moved to the dids package in the form of a new keyToMultibaseId function.
  • Adds crypto algorithms API as a base that can be extended for concrete implementations of block and stream ciphers, digital signature algorithms, etc.
  • Adds concrete implementations of crypto algorithms, including AES-CTR, ECDH (secp256k1 & X25519), ECDSA (secp256k1), and EdDSA (Ed25519).
  • Adds crypto primitive implementations that can be used to create a variety of crypto systems/suites, including AES-CTR, AES-GCM, ConcatKDF, Ed25519, secp256k1, X25519, and XChaCha20.
  • Adds a KeyManager implementation that can be used by Web5 Apps/Agents to provide a common interface to generate, encrypt, decrypt, sign, verify, etc. methods without directly interacting with private key material. Can support multiple KMS implementations once implemented (e.g., AWS, GCP) but includes a default KMS that can be backed by a key-value store.
  • Adds a default KeyManagementSystem implementation that can be backed by a key-value store.
  • Adds a verity of utilities, including: checkValidProperty, checkRequiredProperty, isBufferKeyPair, isCryptoKeyPair, isManagedKey, isManagedKeyPair, and randomUuid.

dids package

  • The DidKeyApi implementation previously depended on multicodec and multibase functionality in the crypto package that wasn't crypto specific. To reduce unnecessary dependencies in the crypto package, the common functionality was moved to the common package in the form of the new Multicodec implementation and the DID-specific functionality was moved to the dids package in the form of a new keyToMultibaseId function.
  • As a result of the changes mentioned in the prior bullet, a few minor changes were made the to DidKeyApi implementation to import the needed functionality.

frankhinek added 30 commits July 9, 2023 09:58
Signed-off-by: Frank Hinek <[email protected]>
Signed-off-by: Frank Hinek <[email protected]>
Signed-off-by: Frank Hinek <[email protected]>
Signed-off-by: Frank Hinek <[email protected]>
Signed-off-by: Frank Hinek <[email protected]>
Signed-off-by: Frank Hinek <[email protected]>
@frankhinek frankhinek added the enhancement New feature or request label Jul 9, 2023
@frankhinek frankhinek requested a review from csuwildcat as a code owner July 9, 2023 16:51
@frankhinek frankhinek self-assigned this Jul 9, 2023
@frankhinek frankhinek requested a review from mistermoe as a code owner July 9, 2023 16:51
@codecov
Copy link

codecov bot commented Jul 9, 2023

Codecov Report

Merging #152 (a233276) into main (e57ed99) will increase coverage by 16.13%.
The diff coverage is 98.57%.

@@             Coverage Diff             @@
##             main     #152       +/-   ##
===========================================
+ Coverage   65.57%   81.71%   +16.13%     
===========================================
  Files          33       69       +36     
  Lines        3553     6862     +3309     
  Branches      198      567      +369     
===========================================
+ Hits         2330     5607     +3277     
- Misses       1221     1253       +32     
  Partials        2        2               
Components Coverage Δ
common 92.69% <93.40%> (+92.69%) ⬆️
credentials 0.00% <ø> (ø)
crypto 95.24% <99.81%> (+77.87%) ⬆️
dids 50.20% <100.00%> (+1.58%) ⬆️
web5 81.54% <ø> (ø)
web5-agent 0.00% <ø> (ø)
web5-proxy-agent 0.00% <ø> (ø)
web5-user-agent 79.60% <ø> (ø)

Copy link
Contributor

@mistermoe mistermoe left a comment

Choose a reason for hiding this comment

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

so excited

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

Successfully merging this pull request may close these issues.

2 participants