capability-uri
v0.4.1
Published
Capability URI scheme specification and reference implementation
Downloads
3
Readme
capability-uri
Stability: 1 - Experimental
Contributors
Contents
Overview
This module documents the capability URI scheme and provides a reference implementation for generating and parsing capability URIs.
Capability URI Scheme
The "cpblty" scheme is used to identify capabilities.
There are two types of "cpblty" URIs. They are distinguished by the mechanism used to identify the authority responsible for resolving the capability.
The first type of capability URI uses IP address or DNS resolution to identify authority.
The second type of capability URI uses first path part of the URI to identify the authority responsible for resolving the capability, allowing for non-IP and non-DNS resolution mechanisms.
The scheme-specific syntax and semantics of capability URIs are as follows:
capability_URI = "cpblty:" "//" authority "/#" capability_token
/ "cpblty:" capability_authority [ "@" authority_scheme ] ":" capability_token
authority_scheme = ALPHA *( ALPHA / DIGIT / "-" / "_" )
capability_authority = base64url
capability_token = "CPBLTY" version "-" base64url
The semantics are such that the identified authority
is the domain containing
the capability specified by the capability_token
. For full specification of authority
,
see RFC 3986, Section 3.2 - Authority.
Alternatively, the capability_authority
, in combination with optional authority_scheme
,
is the authority containing the capability specified by the capability_token
.
The string CPBLTY
is a well-known string to facilitate searches for leaked capabilities.
version
is the numeric version of capability_token
used. base64url
is URL-safe base64
encoded bytes of the specified capability.
Examples
Capability URI using example.com
registered DNS name to designate authority:
cpblty://example.com/#CPBLTY1-IbwNerN4Dw4BYlpYc4Az-pNBWen_WsdrTrpb-HmMiJOEHvCv1xHKBn2Q
Capability URI using DkDvHuU78RZGUeNs3Q-Wsw
authority to be interpreted using a
custom my_dht
resolution scheme:
cpblty:DkDvHuU78RZGUeNs3Q-Wsw@my_dht:CPBLTY1-IbwNerN4Dw4BYlpYc4Az-pNBWen_WsdrTrpb-HmMiJOEHvCv1xHKBn2Q
Capability URI using DkDvHuU78RZGUeNs3Q-Wsw
authority with an implied resolution scheme:
cpblty:DkDvHuU78RZGUeNs3Q-Wsw:CPBLTY1-IbwNerN4Dw4BYlpYc4Az-pNBWen_WsdrTrpb-HmMiJOEHvCv1xHKBn2Q
Installation
npm install capability-uri
Tests
npm test
Usage
const CapabilityToken = require("capability-token");
const CapabilityURI = require("capability-uri");
const crypto = require("crypto");
const UrlSafeBase64 = require("urlsafe-base64");
const uri1 = CapabilityURI.parse(`cpblty://example.com/#${new CapabilityToken().serialize()}`);
console.log(uri1);
console.log(uri1.serialize());
const uri2 = new CapabilityURI(
{
authority: "example.com",
capabilityToken: new CapabilityToken()
}
);
console.log(uri2);
console.log(uri2.serialize());
const uri3 = new CapabilityURI(
{
capabilityAuthority: UrlSafeBase64.encode(crypto.randomBytes(64)),
capabilityToken: new CapabilityToken()
}
);
console.log(uri3);
console.log(uri3.serialize());
const uri4 = new CapabilityURI(
{
authorityScheme: "dht",
capabilityAuthority: UrlSafeBase64.encode(crypto.randomBytes(64)),
capabilityToken: new CapabilityToken()
}
);
console.log(uri4);
console.log(uri4.serialize());
Documentation
CapabilityURI
IP/DNS Capability URI
authority
: String Domain containing the capability specified by thecapabilityToken
. For full specification ofauthority
, see RFC 3986, Section 3.2 - Authority.capabilityToken
: CapabilityTokenCapabilityToken
instance.
Other Capability URI
authorityScheme
: String (Default: undefined) Optional authority scheme.capabilityAuthority
: String Base64url encoded authority containing the capability specified by thecapabilityToken
.capabilityToken
: CapabilityTokenCapabilityToken
instance.
Public API
CapabilityURI.parse(uri)
uri
: String String capability URI to parse.- Return: CapabilityURI Parsed capability URI, either IP/DNS type or Other type.
new CapabilityURI(config)
config
: Object configuration.authority
: String Domain containing the capability specified by thecapabilityToken
. For full specification ofauthority
, see RFC 3986, Section 3.2 - Authority. Mutually exclusive withcapabilityAuthority
.authorityScheme
: String (Default: undefined) Optional authority scheme.capabilityAuthority
: String Base64url encoded authority containing the capability specified by thecapabilityToken
. Mutually exclusive withauthority
.capabilityToken
: CapabilityTokenCapabilityToken
instance.
- Return: CapabilityURI Capability URI instance as configured.
Creates a new CapabilityURI
instance as configured.
capabilityUri.serialize()
- Return: String Capability URI.
Serializes capabilityUri
into a string in URI format.
Releases
Policy
We follow the semantic versioning policy (semver.org) with a caveat:
Given a version number MAJOR.MINOR.PATCH, increment the:
MAJOR version when you make incompatible API changes, MINOR version when you add functionality in a backwards-compatible manner, and PATCH version when you make backwards-compatible bug fixes.
caveat: Major version zero is a special case indicating development version that may make incompatible API changes without incrementing MAJOR version.