Skip to content

Commit

Permalink
applied suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Nov 5, 2024
1 parent abcbb87 commit aca9517
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/capabilities/src/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const contentServe = capability({
* Capability can be invoked by an agent to record egress data for a given resource.
* It can be derived from any of the `space/content/serve/*` capability that has matching `with`.
*/
export const recordEgress = capability({
export const egressRecord = capability({
can: 'space/content/serve/egress/record',
with: SpaceDID,
nb: Schema.struct({
Expand Down
2 changes: 1 addition & 1 deletion packages/capabilities/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export type UsageReport = InferInvokedCapability<typeof UsageCaps.report>
export type UsageReportSuccess = Record<ProviderDID, UsageData>
export type UsageReportFailure = Ucanto.Failure

export type EgressRecord = InferInvokedCapability<typeof SpaceCaps.recordEgress>
export type EgressRecord = InferInvokedCapability<typeof SpaceCaps.egressRecord>
export type EgressRecordSuccess = {
space: SpaceDID
resource: UnknownLink
Expand Down
6 changes: 3 additions & 3 deletions packages/upload-api/src/space/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { Space } from '@web3-storage/capabilities'

/** @param {API.SpaceServiceContext & API.UsageServiceContext} context */
export const provide = (context) =>
Provider.provide(Space.recordEgress, (input) => recordEgress(input, context))
Provider.provide(Space.egressRecord, (input) => egressRecord(input, context))

/**
* @param {API.Input<Space.recordEgress>} input
* @param {API.Input<Space.egressRecord>} input
* @param {API.SpaceServiceContext & API.UsageServiceContext} context
* @returns {Promise<API.Result<API.EgressRecordSuccess, API.EgressRecordFailure>>}
*/
const recordEgress = async ({ capability, invocation }, context) => {
const egressRecord = async ({ capability, invocation }, context) => {
const provider = /** @type {`did:web:${string}`} */ (
invocation.audience.did()
)
Expand Down
4 changes: 2 additions & 2 deletions packages/upload-api/test/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export const w3Signer = ed25519.parse(
)
export const w3 = w3Signer.withDID('did:web:test.web3.storage')

export const freewaySigner = ed25519.parse(
export const gatewaySigner = ed25519.parse(
'MgCaNpGXCEX0+BxxE4SjSStrxU9Ru/Im+HGNQ/JJx3lDoI+0B3NWjWW3G8OzjbazZjanjM3kgfcZbvpyxv20jHtmcTtg='
)
export const freeway = freewaySigner.withDID('did:web:freeway.web3.storage')
export const gateway = gatewaySigner.withDID('did:web:w3s.link')

/**
* Creates a server for the given service.
Expand Down
10 changes: 5 additions & 5 deletions packages/w3up-client/src/capability/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ export class SpaceClient extends Base {
* @param {API.Delegation[]} [options.proofs]
* @returns {Promise<API.EgressRecordSuccess>}
*/
async recordEgress(egressData, options) {
const out = await recordEgress(
async egressRecord(egressData, options) {
const out = await egressRecord(
{ agent: this.agent },
{ ...egressData },
{ ...options }
)

if (!out.ok) {
throw new Error(
`failed ${SpaceCapabilities.recordEgress.can} invocation`,
`failed ${SpaceCapabilities.egressRecord.can} invocation`,
{
cause: out.error,
}
Expand All @@ -70,12 +70,12 @@ export class SpaceClient extends Base {
* @param {string} [options.nonce]
* @param {API.Delegation[]} [options.proofs]
*/
export const recordEgress = async (
export const egressRecord = async (
{ agent },
{ space, resource, bytes, servedAt },
{ nonce, proofs = [] }
) => {
const receipt = await agent.invokeAndExecute(SpaceCapabilities.recordEgress, {
const receipt = await agent.invokeAndExecute(SpaceCapabilities.egressRecord, {
with: space,
proofs,
nonce,
Expand Down
42 changes: 21 additions & 21 deletions packages/w3up-client/test/capability/space.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AgentData } from '@web3-storage/access/agent'
import { Client } from '../../src/client.js'
import * as Test from '../test.js'
import { Space } from '@web3-storage/capabilities'
import { freewaySigner } from '../../../upload-api/test/helpers/utils.js'
import { gatewaySigner } from '../../../upload-api/test/helpers/utils.js'
import { randomCAR } from '../helpers/random.js'

export const SpaceClient = Test.withContext({
Expand Down Expand Up @@ -70,7 +70,7 @@ export const SpaceClient = Test.withContext({
// 2. Creates a new agent using freewaySigner as the principal
const freewayService = new Client(
await AgentData.create({
principal: freewaySigner,
principal: gatewaySigner,
}),
{
// @ts-ignore
Expand All @@ -82,7 +82,7 @@ export const SpaceClient = Test.withContext({
)

// 3. Alice delegates to the Gateway the ability to record egress
const recordEgressGatewayDelegation = await Space.recordEgress.delegate({
const egressRecordGatewayDelegation = await Space.egressRecord.delegate({
issuer: alice.agent.issuer,
audience: freewayService,
with: space.did(),
Expand All @@ -91,7 +91,7 @@ export const SpaceClient = Test.withContext({
})

const resultDelegation2 = await alice.capability.access.delegate({
delegations: [recordEgressGatewayDelegation],
delegations: [egressRecordGatewayDelegation],
})
assert.ok(resultDelegation2.ok)

Expand All @@ -104,7 +104,7 @@ export const SpaceClient = Test.withContext({
d.issuer.did() === alice.did() &&
d.audience.did() === freewayService.did() &&
d.capabilities.some(
(c) => c.can === Space.recordEgress.can && c.with === space.did()
(c) => c.can === Space.egressRecord.can && c.with === space.did()
)
)
)
Expand All @@ -122,7 +122,7 @@ export const SpaceClient = Test.withContext({
bytes: car.size,
servedAt: new Date().toISOString(),
}
const egressRecord = await freewayService.capability.space.recordEgress(
const egressRecord = await freewayService.capability.space.egressRecord(
egressData,
{
proofs: await freewayService.proofs(),
Expand Down Expand Up @@ -180,7 +180,7 @@ export const SpaceClient = Test.withContext({
// 2. Creates a new agent using freewaySigner as the principal
const freewayService = new Client(
await AgentData.create({
principal: freewaySigner,
principal: gatewaySigner,
}),
{
// @ts-ignore
Expand Down Expand Up @@ -232,7 +232,7 @@ export const SpaceClient = Test.withContext({
bytes: car.size,
servedAt: new Date().toISOString(),
}
const egressRecord = await freewayService.capability.space.recordEgress(
const egressRecord = await freewayService.capability.space.egressRecord(
egressData,
{
proofs: await freewayService.proofs(),
Expand Down Expand Up @@ -290,7 +290,7 @@ export const SpaceClient = Test.withContext({
// 2. Creates a new agent using freewaySigner as the principal
const freewayService = new Client(
await AgentData.create({
principal: freewaySigner,
principal: gatewaySigner,
}),
{
// @ts-ignore
Expand Down Expand Up @@ -347,7 +347,7 @@ export const SpaceClient = Test.withContext({
servedAt: new Date().toISOString(),
}
const egressRecord =
await freewayService.capability.space.recordEgress(egressData, {
await freewayService.capability.space.egressRecord(egressData, {
proofs: await freewayService.proofs(),
})
assert.ok(egressRecord, 'egressRecord should be returned')
Expand Down Expand Up @@ -402,7 +402,7 @@ export const SpaceClient = Test.withContext({
// 2. Creates a new agent using freewaySigner as the principal
const freewayService = new Client(
await AgentData.create({
principal: freewaySigner,
principal: gatewaySigner,
}),
{
// @ts-ignore
Expand All @@ -414,7 +414,7 @@ export const SpaceClient = Test.withContext({
)

// 3. Alice delegates to the Gateway the ability to record egress
const recordEgressGatewayDelegation = await Space.recordEgress.delegate(
const egressRecordGatewayDelegation = await Space.egressRecord.delegate(
{
issuer: alice.agent.issuer,
audience: freewayService,
Expand All @@ -425,7 +425,7 @@ export const SpaceClient = Test.withContext({
)

const resultDelegation2 = await alice.capability.access.delegate({
delegations: [recordEgressGatewayDelegation],
delegations: [egressRecordGatewayDelegation],
})
assert.ok(resultDelegation2.ok)

Expand All @@ -440,7 +440,7 @@ export const SpaceClient = Test.withContext({
d.audience.did() === freewayService.did() &&
d.capabilities.some(
(c) =>
c.can === Space.recordEgress.can && c.with === space.did()
c.can === Space.egressRecord.can && c.with === space.did()
)
)
)
Expand All @@ -459,7 +459,7 @@ export const SpaceClient = Test.withContext({
servedAt: new Date().toISOString(),
}
const egressRecord =
await freewayService.capability.space.recordEgress(egressData, {
await freewayService.capability.space.egressRecord(egressData, {
proofs: await freewayService.proofs(),
})
assert.ok(egressRecord, 'egressRecord should be returned')
Expand Down Expand Up @@ -514,7 +514,7 @@ export const SpaceClient = Test.withContext({
// 2. Creates a new agent using freewaySigner as the principal
const freewayService = new Client(
await AgentData.create({
principal: freewaySigner,
principal: gatewaySigner,
}),
{
// @ts-ignore
Expand All @@ -526,7 +526,7 @@ export const SpaceClient = Test.withContext({
)

// 3. Alice delegates to the Gateway the ability to record egress but without proofs
const recordEgressGatewayDelegation = await Space.recordEgress.delegate({
const egressRecordGatewayDelegation = await Space.egressRecord.delegate({
issuer: alice.agent.issuer,
audience: freewayService,
with: space.did(),
Expand All @@ -535,7 +535,7 @@ export const SpaceClient = Test.withContext({
})

const resultDelegation2 = await alice.capability.access.delegate({
delegations: [recordEgressGatewayDelegation],
delegations: [egressRecordGatewayDelegation],
})
assert.ok(resultDelegation2.ok)

Expand All @@ -548,7 +548,7 @@ export const SpaceClient = Test.withContext({
d.issuer.did() === alice.did() &&
d.audience.did() === freewayService.did() &&
d.capabilities.some(
(c) => c.can === Space.recordEgress.can && c.with === space.did()
(c) => c.can === Space.egressRecord.can && c.with === space.did()
)
)
)
Expand All @@ -558,7 +558,7 @@ export const SpaceClient = Test.withContext({

// 6. FreewayService attempts to invoke egress/record without having the delegation
try {
await freewayService.capability.space.recordEgress(
await freewayService.capability.space.egressRecord(
{
space: space.did(),
resource: car.cid.link(),
Expand All @@ -572,7 +572,7 @@ export const SpaceClient = Test.withContext({
assert.equal(
// @ts-ignore
error.message,
`failed ${Space.recordEgress.can} invocation`,
`failed ${Space.egressRecord.can} invocation`,
'error message should be the same'
)
}
Expand Down

0 comments on commit aca9517

Please sign in to comment.