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

fix!: remove websocket support #966

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"javascript.format.insertSpaceBeforeFunctionParenthesis": false,
"typescript.format.insertSpaceBeforeFunctionParenthesis": false,
"typescript.tsdk": "node_modules/typescript/lib"
}
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