Skip to content

Instantly share code, notes, and snippets.

@puckipedia
Last active January 17, 2018 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puckipedia/fcd9c7e12d9d50897b9a16179abbd58a to your computer and use it in GitHub Desktop.
Save puckipedia/fcd9c7e12d9d50897b9a16179abbd58a to your computer and use it in GitHub Desktop.
{
    "id": "https://example.com/activity",
    "type": "Create",
    "to": "https://example.com/followers",
    "published": "2018-01-17T16:23:08Z",
    "object": {
        "id": "https://example.com/status",
        "type": "Note",
        "to": "https://example.com/followers",
        "tag": [{
                "type": "Mention",
                "name": "@example",
                "href": "https://example.com/"
            },
            {
                "type": "Mention",
                "name": "@other",
                "href": "https://other.example.com/"
            }
        ],
        "sensitive": false,
        "published": "2018-01-17T16:23:08Z",
        "inReplyTo": "https://other.example.com/status",
        "content": "beep boop",
        "cc": [
            "https://other.example.com/",
            "https://www.w3.org/ns/activitystreams#Public"
        ],
        "attributedTo": "https://example.com/",
    },
    "cc": [
            "https://other.example.com/",
            "https://www.w3.org/ns/activitystreams#Public"
    ],
    "actor": "https://example.com/",
    "@context": [
        "https://www.w3.org/ns/activitystreams",
        "https://puckipedia.com/render/context"
    ]
}

https://example.com/activity

{
    "id": "https://example.com/activity",
    "type": "Create",
    "to": "https://example.com/followers",
    "published": "2018-01-17T16:23:08Z",
    "object": "https://example.com/status",
    "cc": [
            "https://other.example.com/",
            "https://www.w3.org/ns/activitystreams#Public"
    ],
    "actor": "https://example.com/",
    "@context": [
        "https://www.w3.org/ns/activitystreams",
        "https://puckipedia.com/render/context"
    ]
}

https://example.com/status

{
    "id": "https://example.com/status",
    "type": "Note",
    "to": "https://example.com/followers",
    "tag": [{
            "type": "Mention",
            "name": "@example",
            "href": "https://example.com/"
        },
        {
            "type": "Mention",
            "name": "@other",
            "href": "https://other.example.com/"
        }
    ],
    "sensitive": false,
    "published": "2018-01-17T16:23:08Z",
    "inReplyTo": "https://other.example.com/status",
    "content": "beep boop",
    "cc": [
        "https://other.example.com/",
        "https://www.w3.org/ns/activitystreams#Public"
    ],
    "attributedTo": "https://example.com/",
    "@context": [
        "https://www.w3.org/ns/activitystreams",
        "https://puckipedia.com/render/context"
    ]
}

JSON-LD signatures applied to ActivityPub

(note: this is currently inconsistent with what Mastodon applies. This is a suggestion, for now at least)

Currently, JSON-LD Signatures are defined to apply to an entire document. However, this will not work when stored in a database, as you'd have to exactly unflatten everything back from how it was. This might be difficult, or even impossible. So, my suggestion:

  1. Define items as an empty set, and toProcess as a queue containing the root object.

  2. While toProcess has an item:

    1. Remove an item from the queue, and iterate over every predicate containing it
    2. If the predicate contains a sub object, add it to toProcess.
    3. If the sub object also has an @id predicate, add it to items
  3. For each item in items:

    1. Clone the object, and replace all predicates that contain a sub object with an @id predicate with just its @id
    2. Sign this cloned object, and add this signature to the original object.

To validate the signatures, you can basically do the same, but instead of signing you validate the signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment