Skip to content

Commit

Permalink
Merge branch 'main' into release-please--branches--main--components--…
Browse files Browse the repository at this point in the history
…upload-api
  • Loading branch information
travis authored Oct 10, 2023
2 parents 57dc402 + 81abb05 commit decdbc6
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 1,820 deletions.
2 changes: 1 addition & 1 deletion .github/release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages/access-client": "15.3.0",
"packages/filecoin-api": "1.4.4",
"packages/filecoin-client": "1.3.0",
"packages/capabilities": "9.4.0",
"packages/capabilities": "9.5.0",
"packages/upload-api": "5.9.0",
"packages/upload-client": "9.4.1",
"packages/w3up-client": "8.0.3",
Expand Down
13 changes: 1 addition & 12 deletions packages/access-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"type": "module",
"types": "dist/src/index.d.ts",
"main": "src/index.js",
"bin": {
"w3access": "./src/cli/index.js"
},
"scripts": {
"lint": "tsc --build && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"build": "tsc --build",
Expand Down Expand Up @@ -71,18 +68,11 @@
"@web3-storage/did-mailto": "workspace:^",
"bigint-mod-arith": "^3.1.2",
"conf": "10.2.0",
"inquirer": "^9.1.4",
"isomorphic-ws": "^5.0.0",
"kysely": "^0.23.4",
"multiformats": "^12.1.2",
"one-webcrypto": "^1.0.3",
"ora": "^6.1.2",
"p-defer": "^4.0.0",
"p-wait-for": "^5.0.0",
"type-fest": "^3.3.0",
"uint8arrays": "^4.0.6",
"ws": "^8.12.0",
"zod": "^3.20.2"
"uint8arrays": "^4.0.6"
},
"devDependencies": {
"@types/assert": "^1.5.6",
Expand All @@ -97,7 +87,6 @@
"hd-scripts": "^4.0.0",
"mocha": "^10.2.0",
"playwright-test": "^12.3.4",
"sade": "^1.8.1",
"sinon": "^15.0.3",
"typescript": "5.2.2",
"watch": "^1.0.2"
Expand Down
71 changes: 1 addition & 70 deletions packages/access-client/src/agent-use-cases.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { addSpacesFromDelegations, Agent as AccessAgent } from './agent.js'
import * as Ucanto from '@ucanto/interface'
import * as Access from '@web3-storage/capabilities/access'
import { bytesToDelegations, stringToDelegation } from './encoding.js'
import { bytesToDelegations } 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 * as ucanto from '@ucanto/core'
import { DID as DIDValidator } from '@ucanto/validator'
Expand Down Expand Up @@ -130,43 +129,6 @@ export async function pollAccessClaimUntil(
}
}

/**
* @param {AccessAgent} access
* @param {object} [opts]
* @param {AbortSignal} [opts.signal]
* @deprecated - use waitForAuthorizationOnSocket
*/
export async function waitForDelegationOnSocket(access, opts) {
const ws = new Websocket(access.url, 'validate-ws')
await ws.open(opts)

ws.send({
did: access.did(),
})

try {
const msg = await ws.awaitMsg(opts)

if (msg.type === 'timeout') {
await ws.close(1000, 'agent got timeout waiting for validation')
throw new Error('Email validation timed out.')
}

if (msg.type === 'delegation') {
const delegation = stringToDelegation(msg.delegation)
await ws.close(1000, 'received delegation, agent is done with ws')
return delegation
}
} catch (error) {
if (error instanceof AbortError) {
await ws.close(1000, 'AbortError: agent failed to get delegation')
throw new TypeError('Failed to get delegation', { cause: error })
}
throw error
}
throw new TypeError('Failed to get delegation')
}

/**
* @template [T={}]
* @typedef {{ signal?: AbortSignal } & T} AuthorizationWaiterOpts
Expand All @@ -176,19 +138,6 @@ export async function waitForDelegationOnSocket(access, opts) {
* @typedef {(accessAgent: AccessAgent, opts: AuthorizationWaiterOpts<U>) => Promise<Iterable<Ucanto.Delegation>>} AuthorizationWaiter
*/

/**
* Wait for the authorization process to complete by waiting on a
* well-known websocket endpoint for the access-api server to
* receive and forward a session delegation from the authorization
* email flow.
*
* @type AuthorizationWaiter
*/
export async function waitForAuthorizationOnSocket(access, opts = {}) {
const delegation = await waitForDelegationOnSocket(access, opts)
return [delegation]
}

/**
* Wait for authorization process to complete by polling executions of the
* `access/claim` capability and waiting for the result to include
Expand Down Expand Up @@ -260,24 +209,6 @@ export async function authorizeWaitAndClaim(accessAgent, email, opts) {
})
}

/**
* 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]
* @deprecated use authorizeWaitAndClaim directly going forward, passing it the expectAuthorization: waitForAuthorizationOnSocket to replicate this function's behavior
*/
export async function authorizeWithSocket(access, email, opts) {
return authorizeWaitAndClaim(access, email, {
...opts,
expectAuthorization: waitForAuthorizationOnSocket,
})
}

/**
* Invokes voucher/redeem for the free tier, wait on the websocket for the voucher/claim and invokes it
*
Expand Down
9 changes: 0 additions & 9 deletions packages/access-client/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as Ucanto from '@ucanto/interface'
import * as CAR from '@ucanto/transport/car'
import * as HTTP from '@ucanto/transport/http'
import * as ucanto from '@ucanto/core'
import { Peer } from './awake/peer.js'
import * as Space from '@web3-storage/capabilities/space'
import * as Access from '@web3-storage/capabilities/access'

Expand Down Expand Up @@ -562,14 +561,6 @@ export class Agent {
)
}

/**
*
* @param {import('../src/awake/types').Channel} channel
*/
peer(channel) {
return new Peer({ agent: this, channel })
}

/**
* Get Space information from Access service
*
Expand Down
Loading

0 comments on commit decdbc6

Please sign in to comment.