Skip to content

Commit

Permalink
Revert "feat: fix canDelegateCapability et al"
Browse files Browse the repository at this point in the history
This reverts commit 78cb8bf.
  • Loading branch information
travis committed Mar 14, 2023
1 parent 78cb8bf commit f4ad371
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 57 deletions.
2 changes: 1 addition & 1 deletion packages/access-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@ipld/dag-cbor": "^9.0.0",
"@ipld/dag-ucan": "^3.2.0",
"@ucanto/client": "^5.1.0",
"@ucanto/core": "file:../../../ucanto/packages/core",
"@ucanto/core": "^5.1.0",
"@ucanto/interface": "^6.0.0",
"@ucanto/principal": "^5.1.0",
"@ucanto/transport": "^5.1.0",
Expand Down
24 changes: 5 additions & 19 deletions packages/access-client/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,9 @@ export class Agent {
expiration: Infinity,
})

const providerResult = await this.addProvider(signer)
if (providerResult.error) {
throw new Error(providerResult.message, { cause: providerResult })
}
const delegateSpaceAccessResult = await this.delegateSpaceAccessToAccount(
signer
)
if (delegateSpaceAccessResult.error) {
// @ts-ignore it's very weird that this is throwing an error but line 338 above does not - ignore for now
throw new Error(delegateSpaceAccessResult.message, {
cause: delegateSpaceAccessResult,
})
}
await this.addProvider(signer)
await this.delegateSpaceAccessToAccount(signer)

/** @type {import('./types').SpaceMeta} */
const meta = { isRegistered: true }
// eslint-disable-next-line eqeqeq
Expand Down Expand Up @@ -571,10 +561,6 @@ export class Agent {

await this.addProof(sessionDelegation)
this.#data.setSessionPrincipal(sessionPrincipal)

// claim delegations here because we will need an ucan/attest from the service to
// pair with the session delegation we just claimed to make it work
await this.claimDelegations()
}

async claimDelegations() {
Expand Down Expand Up @@ -627,7 +613,7 @@ export class Agent {
throw new Error('cannot add provider, please authorize first')
}

return this.invokeAndExecute(Provider.add, {
return await this.invokeAndExecute(Provider.add, {
audience: this.connection.id,
with: sessionPrincipal.did(),
proofs: this.proofs([
Expand Down Expand Up @@ -659,7 +645,7 @@ export class Agent {

const spaceSaysAccountCanAdminSpace =
await createSpaceSaysAccountCanAdminSpace(space, sessionPrincipal)
return this.invokeAndExecute(Access.delegate, {
return await this.invokeAndExecute(Access.delegate, {
audience: this.connection.id,
with: space.did(),
expiration: Infinity,
Expand Down
22 changes: 8 additions & 14 deletions packages/access-client/src/delegations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-ignore
// eslint-disable-next-line no-unused-vars
import * as Ucanto from '@ucanto/interface'
import * as ucanto from '@ucanto/core'
import { canDelegateAbility } from '@web3-storage/capabilities/utils'

/**
Expand Down Expand Up @@ -45,9 +44,7 @@ export function validate(delegation, opts) {
} = opts ?? {}

if (checkAudience && delegation.audience.did() !== checkAudience.did()) {
throw new Error(
`Delegation audience ${delegation.audience.did()} does not match required DID ${checkAudience.did()}`
)
throw new Error(`Delegation audience does not match required DID.`)
}

if (checkIsExpired && isExpired(delegation)) {
Expand All @@ -65,16 +62,13 @@ export function validate(delegation, opts) {
* @param {import('@ucanto/interface').Capability} child
*/
export function canDelegateCapability(delegation, child) {
// @ts-ignore ignore this until we bring in ucanto as a normal dependency rather than linking to a local version
const allowsCapabilities = ucanto.Delegation.allows(delegation)
if (allowsCapabilities[child.with]) {
const cans = /** @type {import('@ucanto/interface').Ability[]} */ (
Object.keys(allowsCapabilities[child.with])
)
for (const can of cans) {
if (canDelegateAbility(can, child.can)) {
return true
}
for (const parent of delegation.capabilities) {
// TODO is this right?
if (
(parent.with === child.with || parent.with === 'ucan:*') &&
canDelegateAbility(parent.can, child.can)
) {
return true
}
}
return false
Expand Down
25 changes: 2 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f4ad371

Please sign in to comment.