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

Refactor @web5/dids to adopt Web5 Spec API changes #406

Merged
merged 6 commits into from
Feb 10, 2024
Merged

Conversation

frankhinek
Copy link
Contributor

@frankhinek frankhinek commented Feb 9, 2024

Summary

This PR brings @web5/dids up to date with the Web5 Spec API described here.

closes #397
closes #398

Details

BearerDid

  • A DID w/ key manager and convenience functions is called a BearerDid
  • BearerDid includes a function getSigner that returns an object/instance with sign() and verify() methods that can be used to sign messages, credentials, or arbitrary data. The object/instance returns also has algorithm and keyId properties that are needed for header properties when creating JWS and JWE. By default, if getSigner is called with no arguments it uses the first verification method found in the DID Document's assertionMethod property. It can optionally be called with a methodId argument to select a specific verification method from the DID document.
{
    uri: "did:method:123",
    document: {}, // DID Document
    metadata: {
        published: boolean
        // method specific properties
    },

    // Instance of `KeyManager` that holds keys for the DID
    keyManager,
    
    // Returns a Signer with `sign()` and `verify()` methods and `algorithm` and `keyId` properties
    getSigner: (params?: { methodId?: string }) => Signer;

    // Returns a `PortableDid` with the properties described above.
    export: () => PortableDid;
}

PortableDid

{
    uri: "did:method:123",
    document: {}, // DID Document
    metadata: {
        published: boolean
        // method specific properties
    }

    // Optional and would be empty if `AwsKeyManager` since keys can't be exported
    privateKeys: [{...jwk}]
}

Additional Changes

  • Delete / eliminate the DID method fromKeyManager(). It was introduced to solve an issue for a PFI partner that is now better solved by import().
  • Delete / eliminate the DID method specific functions toKeys or toPortableDid. It has been replaced by the export() function on the BearerDid instance.
  • Rename load() / fromKeys / fromPortableDid to DidMethod.import()
  • import() must optionally accept a key manager (e.g., AwsKeyManager or LocalKeyManager)
  • just Did = the string and has Did.parse()

@frankhinek frankhinek self-assigned this Feb 9, 2024
Copy link
Contributor

github-actions bot commented Feb 9, 2024

TBDocs Report

✅ No errors or warnings

@web5/api

  • Project entry file: packages/api/src/index.ts

TBDocs Report Updated at 2024-02-09T22:24:12Z 51e3a8f

Copy link

codecov bot commented Feb 9, 2024

Codecov Report

Merging #406 (51e3a8f) into main (ab117f1) will increase coverage by 0.05%.
Report is 1 commits behind head on main.
The diff coverage is 97.33%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #406      +/-   ##
==========================================
+ Coverage   93.25%   93.31%   +0.05%     
==========================================
  Files          77       78       +1     
  Lines       23454    23573     +119     
  Branches     1869     1866       -3     
==========================================
+ Hits        21873    21996     +123     
+ Misses       1542     1537       -5     
- Partials       39       40       +1     
Components Coverage Δ
agent 88.72% <ø> (ø)
api 97.11% <ø> (-0.19%) ⬇️
common 98.67% <ø> (ø)
credentials 94.60% <ø> (ø)
crypto 93.76% <ø> (ø)
dids 97.53% <97.33%> (+0.17%) ⬆️
identity-agent 56.81% <ø> (ø)
crypto-aws-kms 100.00% <ø> (ø)
proxy-agent 58.43% <ø> (ø)
user-agent 55.22% <ø> (ø)

Signed-off-by: Frank Hinek <[email protected]>
Signed-off-by: Frank Hinek <[email protected]>
@frankhinek frankhinek added the package: dids @web5/dids package label Feb 9, 2024
@frankhinek frankhinek marked this pull request as ready for review February 9, 2024 20:15
@frankhinek frankhinek changed the title Portable did Refactor @web5/dids to adopt Web5 Spec API changes Feb 9, 2024
@frankhinek
Copy link
Contributor Author

The failing security audit is for a development dependency that is not in the published artifact to NPM Registry. Issue tracking this has been opened here.

Copy link
Contributor

@nitro-neal nitro-neal left a comment

Choose a reason for hiding this comment

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

Great job once again! Looks just as discussed. 👍

frankhinek and others added 2 commits February 9, 2024 17:12
@frankhinek frankhinek merged commit b9f53a9 into main Feb 10, 2024
33 of 34 checks passed
@frankhinek frankhinek deleted the portable-did branch February 10, 2024 09:11
finn-block pushed a commit that referenced this pull request Mar 19, 2024
* Break out BearerDid/PortableDid and add DidRegistrationResult
* Refactor DIDs package to new API design
* Bump @web5/dids to 0.4.0

---------

Signed-off-by: Frank Hinek <[email protected]>
Co-authored-by: nitro-neal <[email protected]>
finn-block pushed a commit that referenced this pull request Mar 19, 2024
* Break out BearerDid/PortableDid and add DidRegistrationResult
* Refactor DIDs package to new API design
* Bump @web5/dids to 0.4.0

---------

Signed-off-by: Frank Hinek <[email protected]>
Co-authored-by: nitro-neal <[email protected]>
finn-block pushed a commit that referenced this pull request Mar 19, 2024
* Break out BearerDid/PortableDid and add DidRegistrationResult
* Refactor DIDs package to new API design
* Bump @web5/dids to 0.4.0

---------

Signed-off-by: Frank Hinek <[email protected]>
Co-authored-by: nitro-neal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: dids @web5/dids package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename toKeys() and fromKeys() Update PortableDid structure
3 participants