Skip to content

Commit

Permalink
remove hooks from spec (#270)
Browse files Browse the repository at this point in the history
Co-authored-by: Andor Kesselman <[email protected]>
  • Loading branch information
andorsk and Andor Kesselman authored Dec 13, 2023
1 parent 350c3e3 commit 242a8a4
Showing 1 changed file with 1 addition and 130 deletions.
131 changes: 1 addition & 130 deletions spec/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Decentralized Web Node
~ [Henry Tsai](https://www.linkedin.com/in/henry-tsai-6b884014/) (Microsoft)
~ [XinAn Xu](https://www.linkedin.com/in/xinan-xu-b868a326/) (Microsoft)
~ [Moe Jangda](https://www.linkedin.com/in/moejangda/) (Block)
~ [Andor Kesselman](https://www.linkedin.com/in/andorsk/) (Benri)

**Participate:**
~ [GitHub repo](https://github.com/decentralized-identity/decentralized-web-node)
Expand Down Expand Up @@ -743,15 +744,6 @@ The following properties and values are defined for the Feature Detection object
- `PermissionsRequest`
- `PermissionsGrant`
- `PermissionsRevoke`
- The object ****MAY**** contain a `hooks` property. If the property is not present,
it indicates the Decentralized Web Node implementation does not support any methods of the interface. If the
property is present, its value ****MUST**** be an object that ****MAY**** include any of the
following properties, wherein a boolean `true` value indicates support for the interface
method, while a boolean `false` value or omission of the property indicates the interface
method is not supported:
- `HooksWrite`
- `HooksQuery`
- `HooksDelete`
- The object ****MAY**** contain a `messaging` property, and its value ****MAY**** be an object composed of the following:
- The object ****MAY**** contain a `batching` property, and if present its value ****MUST**** be a boolean indicating whether the Decentralized Web Node handles multiple messages in a single request. The absence of this property ****shall**** indicate that the Decentralized Web Node ****does**** support multiple messages in a single request, thus if an implementer does not support multiple messages in a request, they ****MUST**** include this property and explicitly set its value to `false`.

Expand Down Expand Up @@ -1418,7 +1410,6 @@ of authorized capabilities to others, if allowed by the owner of a Decentralized
- The object ****MAY**** contain a `schema` property, and its value ****Must**** be a URI string that indicates the schema of the associated data.
- The object ****MAY**** contain a `protocol` property, and its value ****Must**** be a URI that denotes the Protocol an object is a part of.
- The object ****MAY**** contain a `protocolVersion` property, and its value ****Must**** be a [SemVer](https://semver.org/) string that denotes the version of the Protocol the object is a part of.
- The object ****MAY**** contain a `recordId` property, and its value ****Must**** be the deterministic ID for the logical Hook record.
- The object ****MAY**** contain a `contextId` property, and its value ****Must**** be the deterministic ID for a contextually linked set of objects.
- The object ****MAY**** contain a [`conditions` property](#permission-conditions){ id=permission-conditions }, and its value ****Must**** be an object of the following properties:
- The object ****MAY**** contain an `attestation` property, and if present its value ****Must**** be a `string` representing the signing conditions detailed below. If the property is not present it ****MUST**** be evaluated as if it were set to the value `optional`.
Expand Down Expand Up @@ -1609,126 +1600,6 @@ The `PermissionQuery` method exists to facilitate lookup of any retained Permiss
- `delegatedFrom`
- all properties of `scope` objects

### Hooks

Many apps and services require the ability to subscribe to types and subsets of data that enters an individual's DWeb Node to act on it, with the ability to respond to the entity that initiated the write or modification to the data. The most common mechanism known to developers that does the first half this is Web Hooks. Web Hooks are one-way pushes of data to subscribed entities, but do not account for responding to the entities that trigger their invocations.

DWeb Node Hooks aim to not only allow permissioned subscribers to be notified of new data, but also optionally respond to the entity's request that triggers their invocation. This allows a subscribed entity to process the data and send back responses to the entity who may be waiting on results.

#### `HooksWrite`

`HooksWrite` messages are JSON objects that include general [Message Descriptor](#message-descriptors) properties and the following additional properties, which ****must**** be composed as follows:

- The message object ****MUST**** contain a `recordId` property, and its value ****MUST**** be the `recordId` of the logical record the entry corresponds with. If the message is the initial entry for a new Hook being set, the value ****MUST**** be set to the resulting string from the [_Record ID Generation Process_](#recordid-generation).
- The message object ****MUST**** contain a `descriptor` property, and its value ****MUST**** be a JSON object composed as follows:
- The object ****MUST**** contain an `interface` property, and its value ****MUST**** be the string `Hooks`.
- The object ****MUST**** contain a `method` property, and its value ****MUST**** be the string `Write`.
- The object ****MAY**** contain a `parentId` property, and its value ****MUST**** be a [Version 1 CID](https://docs.ipfs.io/concepts/content-addressing/#identifier-formats) for the previous `HooksWrite` in the chain.
- The object ****MUST**** contain a `uri` property, and its value ****MUST**** be a URI string.
- The object ****MAY**** contain a `filter` property, and if present its value ****MUST**** be an object that ****MAY**** contain the following properties:
- The object ****MAY**** contain a `recordId` property that references a logical record.
- The object ****MAY**** contain a `contextId`, and if present its value ****MUST**** be the deterministic ID for a contextually linked set of objects.
- The object ****MAY**** contain a `schema` property, and if present its value ****Must**** be a URI string that indicates the schema of the associated data.
- The object ****MAY**** contain a `protocol` property, and its value ****Must**** be a URI that denotes the Protocol an object is a part of.
- If the object contains a `protocol` property the object ****MUST**** also contain a `protocolVersion` property, and its value ****Must**** be a [SemVer](https://semver.org/) string that denotes the version of the Protocol the object is a part of.
- The object ****MAY**** contain a `dataFormat` property, and its value ****MUST**** be a string that indicates the format of the data in accordance with its MIME type designation. The most common format is JSON, which is indicated by setting the value of the `dataFormat` property to `application/json`.

Adding a hook for social media postings:

```json
{ // Message
"descriptor": {
"interface": "Hooks",
"method": "Write",
"hookId": "234452-563658-5563-63546",
"uri": "https://some-domain.com/dwn-hook",
"filter": {
"protocol": "https://example.com/protocols/social-media",
"schema": "https://schema.org/SocialMediaPosting"
}
}
}
```

Updating a previously added hook:

```json
{ // Message
"descriptor": {
"parentId": CID_OF_PREVIOUS_INSTANCE,
"interface": "Hooks",
"method": "Write",
"hookId": "234452-563658-5563-63546",
"uri": "https://a-different-domain.com/new/path",
"filter": {
"protocol": "https://example.com/protocols/social-media",
"schema": "https://schema.org/SocialMediaPosting"
}
}
}
```

##### `HooksWrite` Ingest Instructions

If the `parentId` property:
- ****IS NOT**** present, index the CID of the hook for future evaluation and cease processing.
- ****IS**** present, delete the hook referenced by the `parentId` and index the CID of the new version of the hook for future evaluation and cease processing.

#### `HooksQuery`

`HooksQuery` messages are JSON objects that include general [Message Descriptor](#message-descriptors) properties and the following additional properties, which ****must**** be composed as follows:

- The message object ****MUST**** contain a `descriptor` property, and its value ****MUST**** be a JSON object composed as follows:
- The object ****MUST**** contain an `interface` property, and its value ****MUST**** be the string `Hooks`
- The object ****MUST**** contain a `method` property, and its value ****MUST**** be the string `Query`.
- The object ****MAY**** contain a `filter` property, and if present its value ****MUST**** be an object that ****MAY**** contains at least one of the following properties:
- The object ****MAY**** contain a `writer` property, and its value ****MUST**** be the DID string from which hooks were written. Querying by writer can be important in cases where a writer wants to view all the hooks they have set against a target DID's DWeb Nodes.
- The object ****MAY**** contain a `recordId` property, and its value ****MUST**** be a the deterministic ID for the logical Hook record. This would be used to fetch a specific hook, as one might do to determine whether it exists in the target DWeb Node.
- The object ****MAY**** contain a `active` property, and its value ****MUST**** be a boolean value, wherein `true` indicates that only active hooks should be returned (the last `HooksWrite`, assuming there is no proceeding `HooksDelete`), and `false` indicates that only inactive hooks records should be returned (the last `HooksDelete`). The omission of this property shall mean that all active and inactive hook records are to be returned (the last `HooksWrite` or `HooksDelete` for each `recordId`).

Get all active hooks Alice has written:

```json
{ // Message
"descriptor": {
"interface": "Hooks",
"method": "Query",
"filter": {
"writer": "did:example:alice",
"active": true
}
}
}
```

#### `HooksDelete`

`HooksWrite` messages are JSON objects that include general [Message Descriptor](#message-descriptors) properties and the following additional properties, which ****must**** be composed as follows:

- The message object ****MUST**** contain a `descriptor` property, and its value ****MUST**** be a JSON object composed as follows:
- The object ****MUST**** contain an `interface` property, and its value ****MUST**** be the string `Hooks`
- The object ****MUST**** contain a `method` property, and its value ****MUST**** be the string `Delete`.
- The object ****MUST**** contain a `recordId` property, and its value ****MUST**** be the deterministic ID for the logical Hook record.
- The object ****MAY**** contain a `parentId` property, and its value ****MUST**** be a [Version 1 CID](https://docs.ipfs.io/concepts/content-addressing/#identifier-formats) of the `descriptor` for the previous `HooksWrite` in the chain.

Deleting a hook:

```json
{ // Message
"descriptor": {
"interface": "Hooks",
"method": "Delete",
"recordId": "234452-563658-5563-63546",
"parentId": CID_OF_HOOK_INSTANCE_TO_DELETE
}
}
```

##### `HooksDelete` Ingest Instructions

1. If the `parentId` or `recordId` properties are ****IS NOT**** present, discard the object and return a [Message-Level Status Coding](#message-level-status-coding) error response of 400.
2. If the `parentId` property ****IS**** present and the message indicated by the CID has the same `recordId` property value, delete the hook message referenced by the `parentId`, and retain the `HooksDelete` message as a tombstone.

### Sync

The Sync interface and its methods allow different Decentralized Web Nodes to communicate and sync on the state of the data they contain, including replication of messages and files.
Expand Down

0 comments on commit 242a8a4

Please sign in to comment.