-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(capability): add space to location assertion (#84)
# Goals Enable parsing and usage of assertions defined here with responses from the indexer service. # Implementation Add Space DID as an optional field for the AssertLocation # For Discussion *Why ship a change here?* This library contains the best JS definitions of our various assertions. Apart from the missing Space DID, it's the SAME as the assertions defined in go-capabilities. Currently, JS fetching logic for the indexer does NOT understand assertions, and moreover, the locator for the indexing service in the blob-fetcher uses a non-standard approach of using a parsing validator called 'zod' to parse only location claims. We should maintain full definitions for our various assertions across languages and those definitions should maintain parity. Ultimately, they shouldn't live here. Maybe @storacha/capabilities -- i.e. move them to w3up. But that's a problem for another day.
- Loading branch information
1 parent
d72d27f
commit 5212b1a
Showing
5 changed files
with
70 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,16 @@ export const location = capability({ | |
range: Schema.struct({ | ||
offset: Schema.integer(), | ||
length: Schema.integer().optional() | ||
}).optional() | ||
}).optional(), | ||
space: Schema.didBytes().optional() | ||
}), | ||
derives: (claimed, delegated) => ( | ||
and(equalWith(claimed, delegated)) || | ||
and(equalLinkOrDigestContent(claimed, delegated)) || | ||
and(equal(claimed.nb.location, delegated.nb.location, 'location')) || | ||
and(equal(claimed.nb.range?.offset, delegated.nb.range?.offset, 'offset')) || | ||
and(equal(claimed.nb.range?.length, delegated.nb.range?.length, 'length')) || | ||
and(equal(claimed.nb.space, delegated.nb.space, 'space')) || | ||
ok({}) | ||
) | ||
}) | ||
|
@@ -57,7 +59,7 @@ export const index = capability({ | |
with: URI.match({ protocol: 'did:' }), | ||
nb: Schema.struct({ | ||
/** DAG root CID */ | ||
content: Schema.link(), | ||
content: linkOrDigest(), | ||
/** | ||
* Link to a Content Archive that contains the index. | ||
* e.g. `index/sharded/[email protected]` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,51 @@ | ||
import { Link, URI, UnknownLink, Block, MultihashDigest } from '@ucanto/client' | ||
import { Delegation, Capability, Ability, Resource, Caveats } from '@ucanto/client' | ||
import * as Assert from '../capability/assert.js' | ||
import { AssertEquals, AssertInclusion, AssertIndex, AssertLocation, AssertPartition, AssertRelation } from '../capability/api.js' | ||
|
||
type InferCaveats<C extends Capability> = C extends Capability<Ability, Resource, infer NB> ? NB : never | ||
|
||
type InferContent<C extends Caveats> = C extends { content: infer T} ? T : never | ||
|
||
/** A verifiable claim about data. */ | ||
export interface ContentClaim<T extends string> { | ||
/** Subject of the claim e.g. CAR, DAG root etc. */ | ||
readonly content: MultihashDigest | ||
readonly content: InferContent<InferCaveats<AssertLocation | AssertPartition | AssertInclusion | AssertIndex | AssertEquals | AssertRelation>> | ||
/** Discriminator for different types of claims. */ | ||
readonly type: T | ||
/** | ||
* Returns an iterable of all IPLD blocks that are included in this claim. | ||
*/ | ||
export (): IterableIterator<Block> | ||
/** | ||
* Writes the UCAN `Delegation` chain for this claim into a content addressed | ||
* archive (CAR) buffer and returns it. | ||
* Returns the underlying delegation this is based on | ||
*/ | ||
archive (): Promise<Uint8Array> | ||
delegation() : Delegation | ||
} | ||
|
||
/** A claim not known to this library. */ | ||
export interface UnknownClaim extends ContentClaim<'unknown'> {} | ||
|
||
/** A claim that a CID is available at a URL. */ | ||
export interface LocationClaim extends ContentClaim<typeof Assert.location.can> { | ||
readonly location: URI[] | ||
readonly range?: ByteRange | ||
export interface LocationClaim extends ContentClaim<typeof Assert.location.can>, Readonly<InferCaveats<AssertLocation>> { | ||
} | ||
|
||
/** A claim that a CID's graph can be read from the blocks found in parts. */ | ||
export interface PartitionClaim extends ContentClaim<typeof Assert.partition.can> { | ||
/** CIDs CID - the hash of the binary sorted links in the set. */ | ||
readonly blocks?: Link | ||
/** List of archives (CAR CIDs) containing the blocks. */ | ||
readonly parts: Link[] | ||
export interface PartitionClaim extends ContentClaim<typeof Assert.partition.can>, Readonly<InferCaveats<AssertPartition>> { | ||
} | ||
|
||
/** A claim that a CID includes the contents claimed in another CID. */ | ||
export interface InclusionClaim extends ContentClaim<typeof Assert.inclusion.can> { | ||
/** e.g. CARv2 Index CID or Sub-Deal CID (CommP) */ | ||
readonly includes: Link | ||
/** Zero-knowledge proof */ | ||
readonly proof?: Link | ||
export interface InclusionClaim extends ContentClaim<typeof Assert.inclusion.can>, Readonly<InferCaveats<AssertInclusion>> { | ||
} | ||
|
||
/** | ||
* A claim that a content graph can be found in blob(s) that are identified and | ||
* indexed in the given index CID. | ||
*/ | ||
export interface IndexClaim extends ContentClaim<typeof Assert.index.can> { | ||
/** | ||
* Link to a Content Archive that contains the index. | ||
* e.g. `index/sharded/[email protected]` | ||
* @see https://github.com/storacha/specs/blob/main/w3-index.md | ||
*/ | ||
readonly index: Link | ||
export interface IndexClaim extends ContentClaim<typeof Assert.index.can>, Readonly<InferCaveats<AssertIndex>> { | ||
} | ||
|
||
/** A claim that a CID links to other CIDs. */ | ||
export interface RelationClaim extends ContentClaim<typeof Assert.relation.can> { | ||
/** CIDs of blocks this content directly links to. */ | ||
readonly children: UnknownLink[] | ||
/** List of archives (CAR CIDs) containing the blocks. */ | ||
readonly parts: RelationPart[] | ||
} | ||
|
||
/** Part this content and it's children can be read from. */ | ||
export interface RelationPart { | ||
/** Part CID. */ | ||
content: Link | ||
/** CID of contents (CARv2 index) included in this part. */ | ||
includes?: RelationPartInclusion | ||
} | ||
|
||
export interface RelationPartInclusion { | ||
/** Inclusion CID (CARv2 index) */ | ||
content: Link | ||
/** CIDs of parts this index may be found in. */ | ||
parts?: Link[] | ||
export interface RelationClaim extends ContentClaim<typeof Assert.relation.can>, Readonly<InferCaveats<AssertRelation>> { | ||
} | ||
|
||
/** A claim that the same data is referred to by another CID and/or multihash */ | ||
export interface EqualsClaim extends ContentClaim<typeof Assert.equals.can> { | ||
/** A CID that is equivalent to the content CID e.g the Piece CID for that CAR CID */ | ||
readonly equals: UnknownLink | ||
export interface EqualsClaim extends ContentClaim<typeof Assert.equals.can>, Readonly<InferCaveats<AssertEquals>> { | ||
} | ||
|
||
/** Types of claim that are known to this library. */ | ||
|
@@ -103,8 +66,3 @@ export type Claim = | |
| RelationClaim | ||
| EqualsClaim | ||
| UnknownClaim | ||
|
||
export interface ByteRange { | ||
readonly offset: number | ||
readonly length?: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters