@synonymdev/slashtags-url

Slashtags parser and fromatter for documents and actions uris

Usage no npm install needed!

<script type="module">
  import synonymdevSlashtagsUrl from 'https://cdn.skypack.dev/@synonymdev/slashtags-url';
</script>

README

Slashtags URL

Slashtags url utilities for documents and actions

Documents URLs

Document URLs are used for addressing documents by their DocID

Document URL consists of the follwing

<slashtags-docurl> ::= slashtags://docID/[path][?query][#fragment]

Action URLs

Action URLs on the other hand are used to encode a predefined action and its payload.

The first example is the payload for SlashtagsAuth enabled wallets to sign a challenge and send it to a callback url

Action URL consists of the follwing

<slashtags-docurl> ::= slashtags:[actionID][#payload]

For simplicity, Actions are identfied by the encoded string of their DocID, and that is how they should be addressed in the spec when a new action is added.

Usage

Most common use will be parsing an incoming action url

import * as SlashtagsURL from '@synonymdev/slashtags-url';

const handleAction = (actionID, paylaod) => {
  switch (actionID) {
    case 'bi...xyz':
      doSomething(payload);
      break;
    default:
      return;
  }
};

const { actionID, payload } = SlashtagsURL.parse(url);

handleAction(actionID, payload);

Formatting an action url

const actionID = 'b2..xyz';
const payload = { foo: 'bar' };

SlashtagsURL.format(actionID, payload);
// slashtags:b2iaqaamaaqjcaxryobe4ygqqs3cksu74j4rhzpr7kk3lndqg7gim72edpiagor3z/#ugAR7ImNoYWxsZW5nZSI6ImZvbyIsImNiVVJMIjoiaHR0cHM6d3d3LmV4YW1wbGUuY29tIn0

If you need to add more actions that are not available out of the box

SlashtagsURL.addAction(schema);

Formatting a document url

SlashtagsURL.format(docID);
// slashtags://b2iaqaamaaqjcaxryobe4ygqqs3cksu74j4rhzpr7kk3lndqg7gim72edpiagor3z/