- Authors: Daniel Bluhm, Sam Curren
- Status: ACCEPTED
- Since: 2019-05-24
- Status Note:
- Supersedes: HIPE 0021 Message Types
- Start Date: 2018-07-06
- Tags: concept
Define structure of message type strings used in agent to agent communication, describe their resolution to documentation URIs, and offer guidelines for protocol specifications.
A clear convention to follow for agent developers is necessary for interoperability and continued progress as a community.
A "Message Type" is a required attribute of all communications sent between parties. The message type instructs the receiving agent how to interpret the content and what content to expect as part of a given message.
Types are specified within a message using the @type
attribute:
{
`@type`:<message type string>,
// other attributes
}
Message types are URIs that resolve to developer documentation for the message type, as described in Protocol URIs.
We recommend that message types are ledger resolvable DIDs with an endpoint specifier and path. This allows for the document locations to be updated to a new location for a stable definition.
The following was taken from a presentation by Drummond Reed during the Agent Summit. A link to this presentation can be found below in the Reference section.
How to use a DID to identify a digital object that:
- Can be widely referenced.
- Is cryptographically verifiable.
- Is human readable enough for developers.
Use a full DID reference that contains a service name and path.
This DID reference contains a service name (;spec
) followed by a path that expresses the semantics of an example protocol.
did:sov:123456789abcdefghi1234;spec/exampleprotocol/1.0/exampletype
This example DID document shows a service endpoint that includes a name property (emphasized) whose purpose is to enable creation of DID references that can deterministically select that service in order to have an algorithmic transformation into a concrete URI.
{
"@context": "https://w3id.org/did/v1",
"id": "did:example:123456789abcdefghi",
"publicKey": [{
"id": "did:example:123456789abcdefghi#keys-1",
"type": "RsaSigningKey2018",
"owner": "did:example:123456789abcdefghi",
"publicKeyPem": "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n"
}],
"authentication": [{
"type": "RsaSignatureAuthentication2018",
"publicKey": "did:example:123456789abcdefghi#keys-1"
}],
"service": [{
"type": "Document",
"name": "spec", // <--- Name property
"serviceEndpoint": "https://sovrin.org/specs/"
}]
}
This is the full ABNF for a DID:
did-reference = did [ ";" did-service ] [ "/" did-path ] [ "?" did-query ]
[ "#" did-frag ]
did = "did:" method ":" specific-idstring
method = 1*namechar
namechar = %x61-7A / DIGIT
specific-idstring = idstring *( ":" idstring )
idstring = 1*idchar
idchar = ALPHA / DIGIT / "." / "-"
did-service = 1*servchar *( ";" 1*servchar )
servchar = idchar / "=" / "&"
The purpose of the did-service
component that may optionally follow a DID is to enable construction of a DID reference that may be algorithmically transformed into a concrete URL to access the target resource. There are two algorithms for this transformation. Both begin with the same first step:
- Extract the DID plus the
did-service
component from the DID reference. Call this the DID service locator. Call the rest of the DID reference theservice-specific
string.
This algorithm MUST be used if the did-service
component does NOT begin with the string type=
.
- Select the first
service
object whose id property contains an exact match to the DID service locator. - Select the
serviceEndpoint
property of the selectedservice
object. - Extract the value of the
serviceEndpoint
property. Call this the endpoint URL. - Append the service-specific string to the endpoint URL.
- The final result is the concrete URL.
The following agent message is received with a type not known to the developer:
{
'@type': 'did:sov:123456789abcdefghi1234;spec/exampleprotocol/1.0/exampletype',
'attr_a': 5,
'attr_b': 'Gouda'
}
The @type
is extracted, with a DID reference that resolves to the example service
block above:
did:sov:123456789abcdefghi1234;spec/exampleprotocol/1.0/exampletype
A DID resolver would algorithmically transform that DID reference to the following concrete URL:
https://sovrin.org/specs/exampleprotocol/1.0/exampletype
The developer would then be able to load this URL in a browser to discover the meaning of attr_a
and attr_b
.
did:sov:BzCbsNYhMrjHiqZDTUASHg
will be used to namespace protocols defined by the community as "core protocols" or protocols that agents should minimally support.
This DID is currently held by Daniel Hardman. Ownership will be transferred to the correct entity as soon as possible.
Protocols provide a logical grouping for message types. These protocols, along with each type belonging to that protocol, are to be defined in future HIPEs or through means appropriate to subprojects.
Version numbering should essentially follow Semantic Versioning 2.0.0, excluding patch version number. To summarize, a change in the major protocol version number indicates a breaking change while the minor protocol version number indicates non-breaking additions.
These guidelines are guidelines on purpose. There will be situations where a good design will have to choose between conflicting points, or ignore all of them. The goal should always be clear and good design.
Reserved attributes are prefixed with an @
sign, such as @type
. Don't use this prefix for an attribute, even if use of that specific attribute is undefined.
Data, id, and package, are often terrible names. Adjust the name to enhance meaning. For example, use message_id
instead of id
.
Technically, attribute names can be any valid json key (except prefixed with @, as mentioned above). Practically, you should avoid using special characters, including those that need to be escaped. Underscores and dashes [_,-] are totally acceptable, but you should avoid quotation marks, punctuation, and other symbols.
Be consistent with attribute names between the different types within a protocol. Only use the same attribute name for the same data. If the attribute values are similar, but not exactly the same, adjust the name to indicate the difference.
Attributes do not need to be nested under a top level attribute, but can be to organize related attributes. Nesting all message attributes under one top level attribute is not usually a good idea.
Example 1
{
"@type": "did:example:00000;spec/pizzaplace/1.0/pizzaorder",
"content": {
"id": 15,
"name": "combo",
"prepaid?": true,
"ingredients": ["pepperoni", "bell peppers", "anchovies"]
}
}
Suggestions: Ambiguous names, unnecessary nesting, symbols in names.
Example 1 Fixed
{
"@type": "did:example:00000;spec/pizzaplace/1.0/pizzaorder",
"table_id": 15,
"pizza_name": "combo",
"prepaid": true,
"ingredients": ["pepperoni", "bell peppers", "anchovies"]
}
- Drummond Reed's presentation on using DIDs as message type specifiers
- Daniel Hardman's Agent Summit Notes
- Stephen Curran's presentation summarizing the Agent Summit
- DID Spec
- Semantic Versioning
- Core Message Structure
The following lists the implementations (if any) of this RFC. Please do a pull request to add your implementation. If the implementation is open source, include a link to the repo or to the implementation within the repo. Please be consistent in the "Name" field so that a mechanical processing of the RFCs can generate a list of all RFCs supported by an Aries implementation.
Name / Link | Implementation Notes |
---|---|
Indy Cloud Agent - Python | Reference agent implementation contributed by Sovrin Foundation and Community |
Aries Framework - .NET | .NET framework for building agents of all types |
Streetcred.id | Commercial mobile and web app built using Aries Framework - .NET |
Aries Cloud Agent - Python | Contributed by the government of British Columbia. |
Aries Static Agent - Python | Useful for cron jobs and other simple, automated use cases. |
Aries Framework - Go | For building agents, hubs and other DIDComm features in GoLang. |
Connect.Me | Free mobile app from Evernym. Installed via app store on iOS and Android. |
Verity | Commercially licensed enterprise agent, SaaS or on-prem. |