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

feat: add blob list and remove into spec #123

Merged
merged 3 commits into from
Apr 22, 2024
Merged
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
220 changes: 220 additions & 0 deletions w3-blob.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
![status:wip](https://img.shields.io/badge/status-wip-orange.svg?style=flat-square)

- [Irakli Gozalishvili](https://github.com/gozala)
- [Vasco Santos](https://github.com/vasco-santos)

## Authors

- [Irakli Gozalishvili](https://github.com/gozala)
- [Vasco Santos](https://github.com/vasco-santos)

## Abstract

Expand Down Expand Up @@ -563,6 +565,224 @@ type LocationCommitment = {
}
```

## List Blob

Authorized agent MAY invoke `/space/content/list/blob` capability on the [space] subject (`sub` field) to list Blobs added to it at the time of invocation.

### List Blob Invocation Example

Shown Invocation example illustrates Alice requesting a page of the list of blobs stored on their space.

```js
{
"cmd": "/space/content/list/blob",
"sub": "did:key:zAlice",
"iss": "did:key:zAlice",
"aud": "did:web:web3.storage",
"args": {
// cursor where to start listing from
"cursor": 'cursor-value-from-previous-invocation',
// size of page
"size": 40,
}
}
```

### List Blob Receipt Example

Shows an example receipt for the above `/space/content/list/blob` capability invocation.

> ℹ️ We use `// "/": "bafy..` comments to denote CID of the parent object.

```js
{ // "/": "bafy..list",
"iss": "did:web:web3.storage",
"aud": "did:key:zAlice",
"cmd": "/ucan/assert/result"
"sub": "did:web:web3.storage",
"args": {
// refers to the invocation from the example
"ran": { "/": "bafy..list" },
"out": {
"ok": {
// cursor where to start listing from on next call
"cursor": "cursor-value-for-next-invocation",
// size of the list
"size": 40,
"results": [
{
"insertedAt": "2024-04-16T15:49:22.638Z",
"blob": {
"size": 100,
"content": { "/": { "bytes": "mEi...sfKg" } },
}
},
// ...
]
}
},
// set of tasks to be scheduled.
"next": []
}
}
```

### List Blob Capability

#### List Blob Capability Schema

```ts
type ListBlob = {
cmd: "/space/content/list/blob"
sub: SpaceDID
args: {
cursor?: string
size?: number
}
}
```

##### List Cursor

The optional `args.cursor` MAY be specified in order to paginate over the list of the added Blobs.

##### List Size

The optional `args.size` MAY be specified to signal desired page size, that is number of items in the result.

### List Blob Receipt

#### List Blob Receipt Schema

```ts
type ListBlobReceipt = {
out: Result<ListBlobOk, ListBlobError>
next: []
}

type ListBlobOk = {
cursor?: string
before?: string
after?: string
size: number
results: ListBlobItem
}

type ListBlobItem = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't want to complicate things here so it's not a request, more of suggestion with an expectation that we'll probably do it sometime in the future instead.

I think we should stop having lists like and instead just return list of receipts instead, we can let client deal with getting / caching receipts locally and deriving timestamps from when receipt was issued.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, actually @alanshaw and I also talked about shifting into that direction later on, and use more the pattern you described recently on a RFC ("our databases should be considered more an index over our receipts"). But for MVP let's make it like store and iterate on this when possible

blob: Blob
insertedAt: ISO8601Date
}

type ISO8601Date = string

type ListBlobError = {
message: string
}
```

##### List Blob Effects

Receipt MUST not have any effects.

## Remove Blob

Authorized agent MAY invoke `/space/content/remove/blob` capability to remove content archive from the subject space (`sub` field).

### Remove Blob Invocation Example

Shown Invocation example illustrates Alice requesting to remove a blob stored on their space.

```js
{
"cmd": "/space/content/remove/blob",
"sub": "did:key:zAlice",
"iss": "did:key:zAlice",
"aud": "did:web:web3.storage",
"args": {
// multihash of the blob as byte array
"content": { "/": { "bytes": "mEi...sfKg" } },
}
}
```

### Remove Blob Receipt Example

Shows an example receipt for the above `/space/content/remove/blob` capability invocation.

> ℹ️ We use `// "/": "bafy..` comments to denote CID of the parent object.

```js
{ // "/": "bafy..remove",
"iss": "did:web:web3.storage",
"aud": "did:key:zAlice",
"cmd": "/ucan/assert/result"
"sub": "did:web:web3.storage",
"args": {
// refers to the invocation from the example
"ran": { "/": "bafy..remove" },
"out": {
"ok": {
// size of the blob in bytes removed from space
"size": 2_097_152,
}
},
// set of tasks to be scheduled.
"next": []
}
}
```

### Remove Blob Capability

#### Remove Blob Capability Schema

```ts
type RemoveBlob = {
cmd: "/space/content/remove/blob"
sub: SpaceDID
args: {
content: Multihash
}
}

type Multihash = bytes
type SpaceDID = string
```

##### Remove Content

The `args.content` field MUST be a [multihash] digest of the blob payload bytes. Implementation SHOULD support SHA2-256 algorithm. Implementation MAY in addition support other hashing algorithms.

### Remove Blob Receipt

#### Remove Blob Receipt Schema

```ts
type RemoveBlobReceipt = {
out: Result<RemoveBlobOk, RemoveBlobError>
next: []
}

type RemoveBlobOk = {
size: number
}

type RemoveBlobError = {
message: string
}
```

##### Remove blob Size

The `out.ok.size` MUST be set to the number of bytes that were freed from the space. It MUST be equal to either:

1. The size of the Blob in bytes.
2. `0` if specified blob is not in space.

##### Remove Blob Effects

Receipt MUST not have any effects.

# Coordination

## Publishing Blob
Expand Down
Loading