TBD54566975 / web5-js

Monorepo for the Web5 JS TypeScript implementation
https://tbd54566975.github.io/web5-js/
Apache License 2.0
135 stars 56 forks source link

PermissionsApi for Agent, `permissions` API for `Web5` #833

Closed LiranCohen closed 3 months ago

LiranCohen commented 3 months ago

This refactors a lot of what's in https://github.com/TBD54566975/web5-js/pull/824 with regards to creating/fetching grants.

Satisfies: https://github.com/TBD54566975/web5-js/issues/827

PermissionsApi

Introduces a PermissionsApi interface and an AgentPermissionsApi concrete implementation.

The interface implements the following methods fetchGrants, fetchRequests, isGrantRevoked, createGrant, createRequest, createRevocation as convenience methods for dealing with the built-in permission protocol records.

The AgentPermissionsApi implements an additional static method matchGrantFromArray which was moved from a PermissionsUtil class, which is used to find the appropriate grant to use when authoring a message.

dwn.connected

A Private API usedin a connected state to find and cache the correct grants to use for the request.

dwn.permissions

A Permissions API which implements request, grant, queryRequests, and queryGrants that a user can utilize

The Web5 permissions api introduces 3 helper classes to represent permissions:

PermissionRequest

Class to represent a permission request record. It implements convenience methods similar to the Record class where you can store(), import() or send() the underlying request record. Additionally a grant() method will create a PermissionGrant object.

PermissionGrant

Class to represent a grant record. It implements convenience methods similar to the Record class where you can store(), import() or send() the underlying grant record. Additionally a revoke() method will create a GrantRevocation object, and isRevoked() will check if the underlying grant has been revoked.

GrantRevocation

Class to represent a permission grant revocation record. It implements convenience methods similar to the Record class where you can store() or send() the underlying revocation record.

changeset-bot[bot] commented 3 months ago

🦋 Changeset detected

Latest commit: 2b0eda3d0d3dc0d8efc6353548da16793e3888e2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages | Name | Type | | -------------------- | ----- | | @web5/api | Patch | | @web5/identity-agent | Patch | | @web5/proxy-agent | Patch | | @web5/user-agent | Patch | | @web5/agent | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 99.76134% with 3 lines in your changes missing coverage. Please review.

Project coverage is 93.29%. Comparing base (e93f109) to head (2b0eda3).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## lirancohen/grants-web5 #833 +/- ## =========================================================== + Coverage 0 93.29% +93.29% =========================================================== Files 0 115 +115 Lines 0 32550 +32550 Branches 0 2560 +2560 =========================================================== + Hits 0 30369 +30369 - Misses 0 2143 +2143 - Partials 0 38 +38 ``` | [Components](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | Coverage Δ | | |---|---|---| | [agent](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | `86.88% <100.00%> (∅)` | | | [api](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | `99.53% <100.00%> (∅)` | | | [common](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | `98.68% <ø> (∅)` | | | [credentials](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | `94.95% <ø> (∅)` | | | [crypto](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | `93.88% <ø> (∅)` | | | [dids](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | `97.77% <ø> (∅)` | | | [identity-agent](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | `96.42% <90.90%> (∅)` | | | [crypto-aws-kms](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | `100.00% <ø> (∅)` | | | [proxy-agent](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | `96.42% <90.90%> (∅)` | | | [user-agent](https://app.codecov.io/gh/TBD54566975/web5-js/pull/833/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TBD54566975) | `96.42% <90.90%> (∅)` | |
github-actions[bot] commented 3 months ago

TBDocs Report

✅ No errors or warnings

@web5/api

@web5/crypto

@web5/crypto-aws-kms

@web5/dids

@web5/credentials


TBDocs Report Updated at 2024-08-12T20:26:41Z 20f317d