-
Notifications
You must be signed in to change notification settings - Fork 14
/
deal-tracker.js
41 lines (39 loc) · 932 Bytes
/
deal-tracker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Filecoin Deal Tracker Capabilities
*
* These can be imported directly with:
* ```js
* import * as DealTracker from '@web3-storage/capabilities/filecoin/deal-tracker'
* ```
*
* @module
*/
import { capability, Schema, ok } from '@ucanto/validator'
import { PieceLink } from './lib.js'
import { equalWith, checkLink, and } from '../utils.js'
/**
* Capability allowing a Storefront or Aggregator to obtain deal information
* for a given aggregate piece.
*/
export const dealInfo = capability({
can: 'deal/info',
/**
* DID of the Storefront.
*/
with: Schema.did(),
nb: Schema.struct({
/**
* CID of the piece.
*
* @see https://github.com/filecoin-project/FIPs/pull/758/files
*/
piece: PieceLink,
}),
derives: (claim, from) => {
return (
and(equalWith(claim, from)) ||
and(checkLink(claim.nb.piece, from.nb.piece, 'nb.piece')) ||
ok({})
)
},
})