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

chore: remove deprecated space and voucher capabilities #861

Merged
merged 1 commit into from
Aug 11, 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
90 changes: 2 additions & 88 deletions packages/access-client/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ 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 { URI } from '@ucanto/validator'
import { Peer } from './awake/peer.js'
import * as Space from '@web3-storage/capabilities/space'
import * as Voucher from '@web3-storage/capabilities/voucher'
import * as Access from '@web3-storage/capabilities/access'

import { Signer } from '@ucanto/principal/ed25519'
Expand All @@ -22,10 +20,7 @@ import {
canDelegateCapability,
} from './delegations.js'
import { AgentData, getSessionProofs } from './agent-data.js'
import {
addProviderAndDelegateToAccount,
waitForDelegationOnSocket,
} from './agent-use-cases.js'
import { addProviderAndDelegateToAccount } from './agent-use-cases.js'

export { AgentData }
export * from './agent-use-cases.js'
Expand Down Expand Up @@ -394,88 +389,7 @@ export class Agent {
* @param {Ucanto.DID<'web'>} [opts.provider] - provider to register - defaults to this.connection.id
*/
async registerSpace(email, opts = {}) {
// if the client passes `provider` use the new space registration flow
if (opts.provider) {
return await addProviderAndDelegateToAccount(
this,
this.#data,
email,
opts
)
}

const space = opts.space ?? this.currentSpace()
const service = this.connection.id
const spaceMeta = space ? this.#data.spaces.get(space) : undefined

if (!space || !spaceMeta) {
throw new Error('No space selected')
}

if (spaceMeta && spaceMeta.isRegistered) {
throw new Error('Space already registered with web3.storage.')
}

const inv = await this.invokeAndExecute(Voucher.claim, {
nb: {
identity: URI.from(`mailto:${email}`),
product: 'product:free',
service: service.did(),
},
})

if (inv && inv.out.error) {
throw new Error('Voucher claim failed', { cause: inv })
}

const voucherRedeem =
/** @type {Ucanto.Delegation<[import('./types').VoucherRedeem]>} */ (
await this.#waitForDelegation(opts)
)
await this.addProof(voucherRedeem)
const delegationToService = await this.delegate({
abilities: ['*'],
audience: service,
expiration: Infinity,
audienceMeta: {
name: 'w3access',
type: 'service',
},
})

const accInv = await this.invokeAndExecute(Voucher.redeem, {
with: URI.from(service.did()),
nb: {
space,
identity: voucherRedeem.capabilities[0].nb.identity,
product: voucherRedeem.capabilities[0].nb.product,
},
proofs: [delegationToService],
facts: [
{
space: spaceMeta,
agent: this.meta,
},
],
})

if (accInv && accInv.out.error) {
throw new Error('Space registration failed', { cause: accInv })
}

spaceMeta.isRegistered = true

this.#data.addSpace(space, spaceMeta)
this.#data.removeDelegation(voucherRedeem.cid)
}

/**
*
* @param {object} [opts]
* @param {AbortSignal} [opts.signal]
*/
async #waitForDelegation(opts) {
return waitForDelegationOnSocket(this, opts)
return await addProviderAndDelegateToAccount(this, this.#data, email, opts)
}

/**
Expand Down
7 changes: 0 additions & 7 deletions packages/access-client/test/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ export function createServer(handlers = {}) {
},
}
}),
recover: Server.provide(Space.recover, async ({ capability }) => {
return {
ok: {
recover: true,
},
}
}),
},
...handlers,
},
Expand Down
6 changes: 0 additions & 6 deletions packages/capabilities/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as Space from './space.js'
import * as Top from './top.js'
import * as Store from './store.js'
import * as Upload from './upload.js'
import * as Voucher from './voucher.js'
import * as Access from './access.js'
import * as Utils from './utils.js'
import * as Consumer from './consumer.js'
Expand All @@ -20,7 +19,6 @@ export {
Top,
Store,
Upload,
Voucher,
Consumer,
Customer,
Console,
Expand All @@ -36,8 +34,6 @@ export const abilitiesAsStrings = [
Provider.add.can,
Space.space.can,
Space.info.can,
Space.recover.can,
Space.recoverValidation.can,
Upload.upload.can,
Upload.add.can,
Upload.remove.can,
Expand All @@ -46,8 +42,6 @@ export const abilitiesAsStrings = [
Store.add.can,
Store.remove.can,
Store.list.can,
Voucher.claim.can,
Voucher.redeem.can,
Access.access.can,
Access.authorize.can,
Access.session.can,
Expand Down
27 changes: 2 additions & 25 deletions packages/capabilities/src/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*/

import * as Store from './store.js'
import { capability, URI, Schema, ok, fail } from '@ucanto/validator'
import { canDelegateURI, equalWith, and } from './utils.js'
import { capability, Schema, ok, fail } from '@ucanto/validator'
import { equalWith } from './utils.js'
import * as Upload from './upload.js'
export { top } from './top.js'

Expand Down Expand Up @@ -45,29 +45,6 @@ export const info = Store.add
derives: equalWith,
})

export const recoverValidation = capability({
can: 'space/recover-validation',
with: SpaceDID,
nb: Schema.struct({
identity: URI.match({ protocol: 'mailto:' }),
}),
})

export const recover = capability({
can: 'space/recover',
with: Schema.did(),
nb: Schema.struct({
identity: URI.match({ protocol: 'mailto:' }),
}),
derives: (child, parent) => {
return (
and(equalWith(child, parent)) ||
and(canDelegateURI(child.nb.identity, parent.nb.identity)) ||
ok({})
)
},
})

export const allocate = capability({
can: 'space/allocate',
with: SpaceDID,
Expand Down
14 changes: 1 addition & 13 deletions packages/capabilities/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import * as Ucanto from '@ucanto/interface'
import type { Schema } from '@ucanto/core'
import { InferInvokedCapability, Unit, DID, DIDKey } from '@ucanto/interface'
import type { PieceLink } from '@web3-storage/data-segment'
import { space, info, recover, recoverValidation } from './space.js'
import { space, info } from './space.js'
import * as provider from './provider.js'
import { top } from './top.js'
import { add, list, remove, store } from './store.js'
import * as UploadCaps from './upload.js'
import { claim, redeem } from './voucher.js'
import * as AccessCaps from './access.js'
import * as CustomerCaps from './customer.js'
import * as ConsumerCaps from './consumer.js'
Expand Down Expand Up @@ -154,10 +153,6 @@ export type RateLimitListFailure = Ucanto.Failure
// Space
export type Space = InferInvokedCapability<typeof space>
export type SpaceInfo = InferInvokedCapability<typeof info>
export type SpaceRecoverValidation = InferInvokedCapability<
typeof recoverValidation
>
export type SpaceRecover = InferInvokedCapability<typeof recover>

// filecoin
export type FILECOIN_PROCESSING_STATUS = 'pending' | 'done'
Expand Down Expand Up @@ -205,9 +200,6 @@ export interface ChainTrackerInfoFailure extends Ucanto.Failure {
// TODO
}

// Voucher Protocol
export type VoucherRedeem = InferInvokedCapability<typeof redeem>
export type VoucherClaim = InferInvokedCapability<typeof claim>
// Upload
export type Upload = InferInvokedCapability<typeof UploadCaps.upload>
export type UploadAdd = InferInvokedCapability<typeof UploadCaps.add>
Expand Down Expand Up @@ -239,8 +231,6 @@ export type AbilitiesArray = [
ProviderAdd['can'],
Space['can'],
SpaceInfo['can'],
SpaceRecover['can'],
SpaceRecoverValidation['can'],
Upload['can'],
UploadAdd['can'],
UploadRemove['can'],
Expand All @@ -249,8 +239,6 @@ export type AbilitiesArray = [
StoreAdd['can'],
StoreRemove['can'],
StoreList['can'],
VoucherClaim['can'],
VoucherRedeem['can'],
Access['can'],
AccessAuthorize['can'],
AccessSession['can'],
Expand Down
114 changes: 0 additions & 114 deletions packages/capabilities/src/voucher.js

This file was deleted.

Loading
Loading