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 access/delegate capability parser exported from @web3-storage/capabilities #420

Merged
merged 17 commits into from
Feb 7, 2023

Conversation

gobengo
Copy link
Contributor

@gobengo gobengo commented Feb 1, 2023

@gobengo gobengo changed the title add access/delegate capability parser exported from @web3-storage/capabilities feat: add access/delegate capability parser exported from @web3-storage/capabilities Feb 1, 2023
@gobengo gobengo marked this pull request as ready for review February 2, 2023 00:19
*
* @template {Types.Ability} A
* @template {Types.URI} R
* @typedef {Types.ParsedCapability<A, R, { delegations?: Types.Failure | Schema.Dictionary<string, Types.Link<unknown, number, number, 0 | 1>> }>} ParsedAccessDelegate
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use this below on lines 159, 160. @Gozala lmk if there is some better way of inferring this type. It's possible I can't just infer it from delegate because it's also used in the definition of delegate (derives) so there is a circularity?

Copy link
Contributor

Choose a reason for hiding this comment

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

delegations should not be Failure, ucanto will not create parsed capability like that. It will either parse successfully or just fail, it will never partially fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @typedef {Types.ParsedCapability<A, R, { delegations?: Types.Failure | Schema.Dictionary<string, Types.Link<unknown, number, number, 0 | 1>> }>} ParsedAccessDelegate
* @typedef {Types.ParsedCapability<A, R, { delegations?: Schema.Dictionary<string, Types.Link<unknown, number, number, 0 | 1>> }>} ParsedAccessDelegate

Does this not work ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Gozala and I met together, and realized I needed to add this type assertion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I proposed this in ucanto to make the type assertion unnecessary storacha/ucanto#215

function subsetsNbDelegations(claim, proof) {
/** @param {ParsedAccessDelegate} ucan */
const nbDelegationsCids = (ucan) =>
new Set(Object.values(ucan.nb.delegations || {}).map(String))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: can you hoist this function, to the top level since it does not enclose anything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hoisted in d03e081

Copy link
Contributor

@Gozala Gozala left a comment

Choose a reason for hiding this comment

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

Overall looks good, put bunch of comments but ones I'd like to see addressed before landing are:

  1. Remove one layer of set wrapper new Set(new Set(...
  2. Adjustment to how tests are generated so it's easier to follow what going on.

Thanks

const nbDelegationsCids = (ucan) =>
new Set(Object.values(ucan.nb.delegations || {}).map(String))
const missingProofs = setDifference(
new Set(nbDelegationsCids(claim)),
Copy link
Contributor

Choose a reason for hiding this comment

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

You create a set and then pass it into a set constructor, which seems unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

audience: bob,
capabilities: [{ can: 'store/*', with: alice.did() }],
})
const validInvocations = [
Copy link
Contributor

Choose a reason for hiding this comment

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

This is really hard to follow and if one of the cases fails the whole test will fail as well. Could you generate tests instead meaning have loop that calls it ? It would be easier to follow and failure in one case will not fail the whole suite.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// correct cid
[bobCanStoreAllWithAlice.cid.toString(), bobCanStoreAllWithAlice.cid],
// not a cid at all
['thisIsNotACid', bobCanStoreAllWithAlice.cid],
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 I'm starting to wonder if the whole dict is a good idea here, but then if we chose list it also may not be ordered.

@gobengo gobengo requested review from Gozala and removed request for hugomrdias February 6, 2023 23:21
Copy link
Contributor

@Gozala Gozala left a comment

Choose a reason for hiding this comment

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

Suggested minor changes, feel free to land as is or change a bit and then land.

packages/capabilities/test/capabilities/access.test.js Outdated Show resolved Hide resolved
packages/capabilities/test/capabilities/access.test.js Outdated Show resolved Hide resolved
gobengo and others added 2 commits February 7, 2023 14:13
Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
@gobengo gobengo merged commit e8e2b1a into main Feb 7, 2023
@gobengo gobengo deleted the 1675210470-define-access-delegate-cap branch February 7, 2023 22:25
travis pushed a commit that referenced this pull request Feb 10, 2023
🤖 I have created a release *beep* *boop*
---


##
[2.3.0](capabilities-v2.2.0...capabilities-v2.3.0)
(2023-02-10)


### Features

* add `pre` caveat to `store/list` and `upload/list`
([#423](#423))
([a0f6d28](a0f6d28))
* add access/delegate capability parser exported from
@web3-storage/capabilities
([#420](#420))
([e8e2b1a](e8e2b1a))
* add support for access/authorize and update
([#392](#392))
([9c8ca0b](9c8ca0b)),
closes [#386](#386)
* define access/claim in @web3-storage/capabilities
([#409](#409))
([4d72ba3](4d72ba3))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
gobengo added a commit that referenced this pull request Feb 24, 2023
Note:
* this is a superset of
#420
* that defines the `access/delegate` capability parsers that this PR
adds handlers for in access-api
  * my intention is to land that #420 before this

Motivation:
* part of #425
gobengo added a commit that referenced this pull request Apr 11, 2023
…ge/capabilities (#420)

Motivation:
* #414

---------

Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
gobengo pushed a commit that referenced this pull request Apr 11, 2023
🤖 I have created a release *beep* *boop*
---


##
[2.3.0](capabilities-v2.2.0...capabilities-v2.3.0)
(2023-02-10)


### Features

* add `pre` caveat to `store/list` and `upload/list`
([#423](#423))
([9cce414](9cce414))
* add access/delegate capability parser exported from
@web3-storage/capabilities
([#420](#420))
([7834cf2](7834cf2))
* add support for access/authorize and update
([#392](#392))
([bf41071](bf41071)),
closes [#386](#386)
* define access/claim in @web3-storage/capabilities
([#409](#409))
([2fb34dd](2fb34dd))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
gobengo added a commit that referenced this pull request Apr 11, 2023
Note:
* this is a superset of
#420
* that defines the `access/delegate` capability parsers that this PR
adds handlers for in access-api
  * my intention is to land that #420 before this

Motivation:
* part of #425
Peeja pushed a commit to storacha/upload-service that referenced this pull request Jan 17, 2025
Pass the value of the VITE_W3UP_PROVIDER env variable along to
registerSpace. This lets us configure the provider used during space
registration at the app level.
Peeja pushed a commit to storacha/upload-service that referenced this pull request Jan 29, 2025
Pass the value of the VITE_W3UP_PROVIDER env variable along to
registerSpace. This lets us configure the provider used during space
registration at the app level.
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.

2 participants