Skip to content

Commit

Permalink
fix: @web3-storage/access/agent no longer exports authorizeWithPollCl…
Browse files Browse the repository at this point in the history
…aim (#656)

Motivation:
* #633

Note:
* this was an unintentional addition to our package exports and not an
intentional addition to our public API, so this PR conventional commit
message is not marked as a breaking api change
* I notified the only person I expect to have relied on it
#602 (comment)
  • Loading branch information
gobengo authored Mar 28, 2023
1 parent 0af39a4 commit 5d78a5a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
33 changes: 32 additions & 1 deletion packages/access-api/test/access-client-agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
addSpacesFromDelegations,
Agent as AccessAgent,
authorizeAndWait,
authorizeWithPollClaim,
claimAccess,
createDidMailtoFromEmail,
expectNewClaimableDelegations,
Expand Down Expand Up @@ -616,3 +615,35 @@ async function testSessionAuthorization(service, access, account, emails) {
function thisEmailDidMailto() {
return createDidMailtoFromEmail(this.email)
}

/**
* Request authorization of a session allowing this agent to issue UCANs
* signed by the passed email address.
*
* @param {AccessAgent} access
* @param {`${string}@${string}`} email
* @param {object} [opts]
* @param {AbortSignal} [opts.signal]
* @param {Iterable<{ can: Ucanto.Ability }>} [opts.capabilities]
*/
export async function authorizeWithPollClaim(access, email, opts) {
const expectAuthorization = () =>
expectNewClaimableDelegations(access, access.issuer.did(), {
abort: opts?.signal,
}).then((claimed) => {
if (
![...claimed].some((d) =>
d.capabilities.some((d) => d.can === w3caps.Access.session.can)
)
) {
throw new Error(
`claimed new delegations, but none were a session proof`
)
}
return [...claimed]
})
await authorizeAndWait(access, email, {
...opts,
expectAuthorization,
})
}
30 changes: 1 addition & 29 deletions packages/access-client/src/agent-use-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { bytesToDelegations, stringToDelegation } from './encoding.js'
import { Provider } from '@web3-storage/capabilities'
import * as w3caps from '@web3-storage/capabilities'
import { Websocket, AbortError } from './utils/ws.js'
import { AgentData, isSessionProof } from './agent-data.js'
import { AgentData } from './agent-data.js'
import * as ucanto from '@ucanto/core'
import { DID as DIDValidator } from '@ucanto/validator'

Expand Down Expand Up @@ -237,34 +237,6 @@ export async function authorizeWithSocket(access, email, opts) {
await claimAccess(access, access.issuer.did(), { addProofs: true })
}

/**
* Request authorization of a session allowing this agent to issue UCANs
* signed by the passed email address.
*
* @param {AccessAgent} access
* @param {`${string}@${string}`} email
* @param {object} [opts]
* @param {AbortSignal} [opts.signal]
* @param {Iterable<{ can: Ucanto.Ability }>} [opts.capabilities]
*/
export async function authorizeWithPollClaim(access, email, opts) {
const expectAuthorization = () =>
expectNewClaimableDelegations(access, access.issuer.did(), {
abort: opts?.signal,
}).then((claimed) => {
if (![...claimed].some((d) => isSessionProof(d))) {
throw new Error(
`claimed new delegations, but none were a session proof`
)
}
return [...claimed]
})
await authorizeAndWait(access, email, {
...opts,
expectAuthorization,
})
}

/**
* Invokes voucher/redeem for the free tier, wait on the websocket for the voucher/claim and invokes it
*
Expand Down

0 comments on commit 5d78a5a

Please sign in to comment.