1
1
import { Verifier } from '@ucanto/principal'
2
- import {
3
- capability ,
4
- Schema ,
5
- DID ,
6
- nullable ,
7
- string ,
8
- ok ,
9
- access ,
10
- Unauthorized
11
- } from '@ucanto/validator'
2
+ import { ok , access , Unauthorized } from '@ucanto/validator'
12
3
import { HttpError } from '@web3-storage/gateway-lib/util'
4
+ import * as serve from '../capabilities/serve.js'
13
5
14
6
/**
15
7
* @import * as Ucanto from '@ucanto/interface'
@@ -20,36 +12,6 @@ import { HttpError } from '@web3-storage/gateway-lib/util'
20
12
* @import { SpaceContext, DelegationsStorageContext } from './withAuthorizedSpace.types.js'
21
13
*/
22
14
23
- /**
24
- * "Serve content owned by the subject Space."
25
- *
26
- * A Principal who may `space/content/serve` is permitted to serve any
27
- * content owned by the Space, in the manner of an [IPFS Gateway]. The
28
- * content may be a Blob stored by a Storage Node, or indexed content stored
29
- * within such Blobs (ie, Shards).
30
- *
31
- * Note that the args do not currently specify *what* content should be
32
- * served. Invoking this command does not currently *serve* the content in
33
- * any way, but merely validates the authority to do so. Currently, the
34
- * entirety of a Space must use the same authorization, thus the content does
35
- * not need to be identified. In the future, this command may refer directly
36
- * to a piece of content by CID.
37
- *
38
- * [IPFS Gateway]: https://specs.ipfs.tech/http-gateways/path-gateway/
39
- */
40
- export const serve = capability ( {
41
- can : 'space/content/serve' ,
42
- /**
43
- * The Space which contains the content. This Space will be charged egress
44
- * fees if content is actually retrieved by way of this invocation.
45
- */
46
- with : DID ,
47
- nb : Schema . struct ( {
48
- /** The authorization token, if any, used for this request. */
49
- token : nullable ( string ( ) )
50
- } )
51
- } )
52
-
53
15
/**
54
16
* Attempts to locate the {@link IpfsUrlContext.dataCid}. If it's able to,
55
17
* attempts to authorize the request to access the data.
@@ -134,14 +96,14 @@ const authorize = async (space, ctx) => {
134
96
// Look up delegations that might authorize us to serve the content.
135
97
const relevantDelegationsResult = await ctx . delegationsStorage . find ( {
136
98
audience : ctx . gatewayIdentity . did ( ) ,
137
- can : 'space/content/ serve' ,
99
+ can : serve . transportHttp . can ,
138
100
with : space
139
101
} )
140
102
141
103
if ( relevantDelegationsResult . error ) return relevantDelegationsResult
142
104
143
105
// Create an invocation of the serve capability.
144
- const invocation = await serve
106
+ const invocation = await serve . transportHttp
145
107
. invoke ( {
146
108
issuer : ctx . gatewayIdentity ,
147
109
audience : ctx . gatewayIdentity ,
@@ -155,7 +117,7 @@ const authorize = async (space, ctx) => {
155
117
156
118
// Validate the invocation.
157
119
const accessResult = await access ( invocation , {
158
- capability : serve ,
120
+ capability : serve . transportHttp ,
159
121
authority : ctx . gatewayIdentity ,
160
122
principal : Verifier ,
161
123
validateAuthorization : ( ) => ok ( { } )
0 commit comments