-
Notifications
You must be signed in to change notification settings - Fork 22
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: define ucan/revoke capability #943
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a5c0163
feat: define ucan/revoke capability
Gozala 0dd834c
fix: type errors
Gozala 177f52a
Apply suggestions from code review
Gozala 97b943d
Merge remote-tracking branch 'origin/main' into feat/ucan/revoke
Gozala b620f08
fix: update tests to latest ucanto
Gozala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* UCAN core capabilities. | ||
*/ | ||
|
||
import { capability, Schema } from '@ucanto/validator' | ||
import { equalWith, checkLink, and } from './utils.js' | ||
|
||
export const UCANLink = Schema.link({ | ||
version: 1, | ||
}) | ||
|
||
/** | ||
* Capability can only be delegated (but not invoked) allowing audience to | ||
* derived any `store/` prefixed capability for the (memory) space identified | ||
* by DID in the `with` field. | ||
*/ | ||
export const ucan = capability({ | ||
can: 'ucan/*', | ||
with: Schema.did(), | ||
derives: equalWith, | ||
}) | ||
|
||
/** | ||
* `ucan/revoke` capability is a replacement for the | ||
* [UCAN Revocation](https://github.com/ucan-wg/spec#66-revocation) that had | ||
* been proposed to a UCAN working group and had a tentative support from | ||
* members. | ||
*/ | ||
export const revoke = capability({ | ||
can: 'ucan/revoke', | ||
/** | ||
* With MUST be a DID of the UCAN issuer that is in the proof chain of the | ||
* delegation been revoked. | ||
*/ | ||
with: Schema.did(), | ||
nb: Schema.struct({ | ||
/** | ||
* Link of the UCAN been revoked, it MUST be a UCAN be either issued by a | ||
* principal matching `with` field or depend on the delegation issued by | ||
* the principal matching `with` field. | ||
* | ||
* Alternatively `with` field MAY match the `audience` of the this UCAN, | ||
Gozala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* which would imply that that delegate is revoking capabilities delegated | ||
* to it. This allows delegate to proof that it is unable to invoke | ||
Gozala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* delegated capabilities. | ||
*/ | ||
delegation: UCANLink, | ||
}), | ||
derives: (claim, from) => | ||
and(equalWith(claim, from)) ?? | ||
checkLink(claim.nb.delegation, from.nb.delegation, 'nb.delegation'), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
import assert from 'assert' | ||
import { access } from '@ucanto/validator' | ||
import { Verifier } from '@ucanto/principal/ed25519' | ||
import * as UCAN from '../../src/ucan.js' | ||
import { alice, bob, service, mallory } from '../helpers/fixtures.js' | ||
import { delegate, parseLink, API } from '@ucanto/core' | ||
|
||
/** @type {API.UCANLink} */ | ||
const delegation = parseLink( | ||
'bafyreieicjmit6d6ubkd2mw7snpx33ijquxcjetp4fvbjr2dkdonvr5dpe' | ||
) | ||
|
||
describe('ucan/* capabilities', () => { | ||
describe('ucan/revoke', () => { | ||
it('owner can issue revocation', async () => { | ||
const revoke = UCAN.revoke.invoke({ | ||
issuer: alice, | ||
audience: service, | ||
with: alice.did(), | ||
nb: { | ||
delegation, | ||
}, | ||
}) | ||
|
||
const result = await access(await revoke.delegate(), { | ||
capability: UCAN.revoke, | ||
principal: Verifier, | ||
authority: service, | ||
}) | ||
|
||
assert.ok(result.ok) | ||
}) | ||
|
||
it('delegate can issue revocation', async () => { | ||
const revoke = UCAN.revoke.invoke({ | ||
issuer: bob, | ||
audience: service, | ||
with: alice.did(), | ||
nb: { | ||
delegation, | ||
}, | ||
proofs: [ | ||
await UCAN.revoke.delegate({ | ||
issuer: alice, | ||
audience: bob, | ||
with: alice.did(), | ||
}), | ||
], | ||
}) | ||
|
||
const result = await access(await revoke.delegate(), { | ||
capability: UCAN.revoke, | ||
principal: Verifier, | ||
authority: service, | ||
}) | ||
|
||
assert.ok(result.ok) | ||
}) | ||
|
||
it('non delegate can not issue revocation', async () => { | ||
const proof = await delegate({ | ||
issuer: alice, | ||
audience: bob, | ||
capabilities: [ | ||
{ | ||
with: alice.did(), | ||
can: 'console/log', | ||
}, | ||
], | ||
}) | ||
|
||
const revoke = UCAN.revoke.invoke({ | ||
issuer: mallory, | ||
audience: service, | ||
with: alice.did(), | ||
nb: { | ||
delegation: proof.cid, | ||
}, | ||
proofs: [ | ||
await UCAN.revoke.delegate({ | ||
issuer: alice, | ||
audience: bob, | ||
with: alice.did(), | ||
}), | ||
], | ||
}) | ||
|
||
const result = await access(await revoke.delegate(), { | ||
capability: UCAN.revoke, | ||
principal: Verifier, | ||
authority: service, | ||
}) | ||
|
||
assert.ok(result.error) | ||
}) | ||
|
||
it('can be derived from ucan/*', async () => { | ||
const revoke = UCAN.revoke.invoke({ | ||
issuer: bob, | ||
audience: service, | ||
with: alice.did(), | ||
nb: { | ||
delegation, | ||
}, | ||
proofs: [ | ||
await UCAN.ucan.delegate({ | ||
issuer: alice, | ||
with: alice.did(), | ||
audience: bob, | ||
}), | ||
], | ||
}) | ||
|
||
const result = await access(await revoke.delegate(), { | ||
capability: UCAN.revoke, | ||
principal: Verifier, | ||
authority: service, | ||
}) | ||
|
||
assert.ok(result.ok) | ||
}) | ||
|
||
it('with field must match', async () => { | ||
const revoke = UCAN.revoke.invoke({ | ||
issuer: bob, | ||
audience: service, | ||
with: mallory.did(), | ||
nb: { | ||
delegation, | ||
}, | ||
proofs: [ | ||
await UCAN.ucan.delegate({ | ||
issuer: alice, | ||
with: alice.did(), | ||
audience: bob, | ||
}), | ||
], | ||
}) | ||
|
||
const result = await access(await revoke.delegate(), { | ||
capability: UCAN.revoke, | ||
principal: Verifier, | ||
authority: service, | ||
}) | ||
|
||
assert.ok(result.error) | ||
}) | ||
|
||
it('nb.delegation field must match', async () => { | ||
const revoke = UCAN.revoke.invoke({ | ||
issuer: bob, | ||
audience: service, | ||
with: alice.did(), | ||
nb: { | ||
delegation, | ||
}, | ||
proofs: [ | ||
await UCAN.revoke.delegate({ | ||
issuer: alice, | ||
with: alice.did(), | ||
audience: bob, | ||
nb: { | ||
delegation: parseLink('bafkqaaa'), | ||
}, | ||
}), | ||
], | ||
}) | ||
|
||
const result = await access(await revoke.delegate(), { | ||
capability: UCAN.revoke, | ||
principal: Verifier, | ||
authority: service, | ||
}) | ||
|
||
assert.ok(result.error) | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this always the DID of the issuer of the "context CID" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is otherwise anyone could request a revocation. Put it differently that is how we infer context / scope CID, by walking up the chain and finding a proof that corresponds to
with
.