Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Supporting DID links to sphere content #51

Open
gordonbrander opened this issue Apr 28, 2023 · 5 comments
Open

Supporting DID links to sphere content #51

gordonbrander opened this issue Apr 28, 2023 · 5 comments
Assignees

Comments

@gordonbrander
Copy link
Collaborator

gordonbrander commented Apr 28, 2023

Recently the team has been discussing the value of supporting a did link form for sphere content. This has many upsides.

DIDs are identifiers (stable and globally unique). Slashlinks are locators (they tell you how to find stuff), but not identifiers. Given that slashlinks dereference to sphere DIDs under the hood, it would be a nice fallback if slashlinks could reference DIDs directly. It would also be nice if that form were a stable identifier.

This choice has cascading effects on the UX of Subconscious, the UX of writing Subtext, the parsing of Subtext, and more. Design is navigating tradeoffs by values. To that end, This note is an attempt to explore and reflect on these interconnected aspects, how they intersect with the design values of Subtext, and to find a balance of tradeoffs that best suit our values.

Values:

  • DIDs are an important modular interface.
    • If DIDs are a lego dot, then supporting them means you can click together with many other systems.
  • DIDs are not user-friendly, but @petnames are.
  • Conformability. E.g. Leaning into valid did syntax makes us conformable to a large number of other systems.
    • Reduces corner cases, sharp edges, surprises.
  • Subtext should be simple to write, simple to read, simple to parse.
  • The best Subtext syntax is no syntax (e.g. auto-linking http URLs).
    • The second best syntax is what you would write anyway (e.g. > blockquote).
    • The third best syntax is popular syntax from existing systems (e.g. _italic_ or @handles).
    • Subtext is less like Markdown, more like the auto-syntax you get in a social media site. We should not support deep structure or features.
  • Things like URLs should just work when you paste them into Subtext...
    • ...Within the limits of keeping parsing simple and unambiguous.
    • E.g. we only auto-link URLs starting with http:// or https:// for this reason.

Previously-resolved tradeoffs:

@gordonbrander gordonbrander self-assigned this Apr 28, 2023
@gordonbrander
Copy link
Collaborator Author

gordonbrander commented Apr 28, 2023

It is worth noting that these are both structurally valid DID URLs:

did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK/foo
did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK@petname/foo

However,

  • Other consumers of did:key won't know what to do with the path part.
  • Slashlinks allow for UTF-8 characters, so we would have to percent-encode to make slashlinks valid DID URLs.
    • We could ofc just allow UTF-8 directly in Subtext, and percent-encode when parsing.

References:

@gordonbrander
Copy link
Collaborator Author

gordonbrander commented Apr 28, 2023

One approach we could take is to only allow "absolute" did links, without petnames.

did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK/slug

To traverse from one sphere to another, you would "absolutize" the slashlink, at each step, so there is never a traversal path. This keeps the did path simple. This is in keeping with the idea that the did is an "unknown", so the petnames in their address book do not provide much information security.

This is a valid DID URL, with caveats:

  • Other consumers of did:key won't know what to do with the path part.
  • Slashlinks allow for UTF-8 characters, so we would have to percent-encode to make slashlinks valid DID URLs.
    • We could ofc just allow UTF-8 directly in Subtext, and percent-encode when parsing.

Regex for whole match (markup would require two regex cases, one for did, one for petname slashlink)

(?:(?<did>did:key:[a-zA-Z0-9_\-%]+)|(?<petname>@[\w\-]+(?:\.[\w\-]+)*))?(?<slug>\/[\w\-]+(?:\/[\w\-]+)*)?

@gordonbrander
Copy link
Collaborator Author

gordonbrander commented Apr 28, 2023

Another approach could be to allow slashlinks after a did, with or without petnames.

did:key:[email protected]/slug

This gets visually complicated quickly. The petnames in the path are not really providing much value.

I believe this is a valid DID URL, with same caveats as above.

gordonbrander added a commit to subconsciousnetwork/subconscious that referenced this issue May 8, 2023
DIDs are the only stable way to address 3p content, since the petname
for that content could change. To index 3p content, we need to introduce
the concept of an "absolute" slashlink (a slashlink that is rooted to a
did, rather than a petname).

To put it another way, Slashlinks are locators. We also need a stable
identifier.

This PR introduces several new types to resolve the issue:

- `Peer` is an enum that can be either a Did or a Petname. It makes
Slashlink a type that holds a peer and a slug. This concept mirrors the
[Subtext Rust
parser](https://github.com/subconsciousnetwork/subtext/blob/9d61c0461568d1d6168537955a91221ff1ebc34f/parsers/rust/subtext/src/slashlink.rs#L4)
and Noosphere's treatment of Slashlink types.
- `Slashlink` now contains a `Peer` and a `Slug`.
- `Link`, a type containing a `Did` and `Slug`, which provides a stable
identifier for indexing.

We use `Slashlink` wherever we can, and in the few cases where we need
an identifier (database), we resolve the `Slashlink` to a `Link` at
point of use.

This PR also updates the way the database indexes content to use DIDs.

Note this PR deliberately does not address the markup form of
did-slashlinks, only the datatype. For markup form, we are tracking here
subconsciousnetwork/subtext#51

Lays groundwork toward #323, #551, #518

## Limitations

This PR will not correctly re-relativize the slashlinks of 3P content
saved to the database. So if you put something in the database and then
query it again, you'll get a slashlink with a did, instead of a petname.

To get nice petname-slashlinks, we'll need to integrate a new FFI
function to get a petname from a did
subconsciousnetwork/noosphere#358.

However, this PR does not yet index 3P content. It just updates the
system so we can. We should be safe to land it, and then start indexing
3P content once we get the new `DID -> Petname` FFI.
@bmann
Copy link

bmann commented May 10, 2023

This is interesting, but possibly premature? Other systems mostly don't know what to do with DIDs at all, and haven't thought about the interfaces.

Maybe @-syntax is correct? So either @petname (which resolves to a DID) or @did:key (which may get looked up and replaced with a label or a petname).

Also: what about other mentions that themselves resolve to a DID? So, @bmann.ca has an _atproto subdomain / TXT record which contains a DID.

@boris.fission.name contains a _did subdomain / TXT record.

DNS flavoured links that resolve to DIDs at well known locations could be a good start?

@gordonbrander
Copy link
Collaborator Author

gordonbrander commented May 11, 2023

Did slashlink syntax

I'm strongly partial to

did:key:abc123/slug
(<did>|<petname>)<slug>

If DID, no petname. If petname, no DID. Rationale:

  • Disallowing petnames after DIDs makes did-form slashlinks unambiguous unique identifiers
    • Also <did><petname><slug> is a bit weird, because it's backwards. Did is root, but is at the front, whereas in petnames, the root is at the end.
    • Also <did><petname><slug> satisfies none of the UX goals of petnames
      • A did with petnames is so complicated it may as well be a black box to the user
      • If it's a DID, it's "anonymous" to you, and its address book is not to be trusted anyway
  • It’s a valid DID-URL, assuming you percent-encode any Unicode chars on the backend (even if not all clients know what to do with the path part)

I like not having the @ for did-slashlinks, but I can see the other side of it. did:method is enough for us to sniff out supported did methods in the text. However, since we are "hijacking" the path-part of DID-URLs for addressing sphere content, I could imagine the leading @ being useful for disambiguating this use. Another possibility might be a custom DID method. Going to mull on this for a bit.

For now, we have implemented did:key:abc123/slug style slashlinks for database indexing in the app, but are not exposing them on the user-facing markup side until we work this out a bit more. See subconsciousnetwork/subconscious#561

DNS names

Worth noting that @boris.fission.name creates an ambiguity with potential @boris.fission.name petnames. This ambiguity might be worth coping with for the utility of bridging to DNS. It's also possible to bridge to DNS via making com, org, name, etc, spheres with address books to DNS.

I'm not sure if this decision should belong to Subtext, or the app implementing it. Spec'ing this into subtext seems like too much app domain knowledge leaking back into a markup spec. Perhaps if we pursue it, it could belong to an "extension spec".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants