# Introduction

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

Dime (Data Integrity Message Envelope) is an open data format to build trust and share data securely within networks of any size and shape. Dime envelopes contain encoded information, including verifiable claims by the sending party and application-specific encrypted data. Digital signatures and end-to-end encryption are used to ensure that data cannot be altered or read by unauthorized parties once created.

The DiME format may be used to support the building of Application-based Public-Key Infrastructures (APKI). APKI aims to move elements of traditional PKIs to the application. This includes trust establishment, authentication, and secure communication, all using public keys used and controlled by the applications themselves.

By establishing an APKI the security and controlled is encapsulated and interwoven into the context and purpose of the application. Some potential use cases for DiME include:

* IoT networks for distributing sensitive data, including collected sensory information, operational instructions, patches, and firmware updates
* Trusted processing and transmission when audit trails and results logging is crucial
* Peer-to-peer messaging systems which messages are linked using cryptography
* &#x20;Distribution of sensitive information and records within any-sized networks
* &#x20;Establishing application-based networks with trusted entities
* &#x20;Traversing trust across different networks using multiple trust roots

Complex cryptography is merged with a modern data format focusing on security, human readability, and ease of use. DiME provides a powerful and flexible data format suitable for the secure foundation of any networked setup.

Additionally, strengths of the DiME format are its modular composition, enabling applications to shape the use for their specific needs. At the same time, it removes the need to build complicated authentication and verification mechanisms, as this is included in the actual transmitted data payloads using appropriate cryptography.

Through its flexible and modular design, DiME may be used in any type of entity network, from centralized to decentralized, where there is a need to either control connected entities through trust or broaden the reach of entities within a network and allow inter-network communication.

### **Guarding principles**

The DiME data format has been designed with a few principles:

* Application-based – enable applications to implement, use, and control the whole trust and security chain
* Make use of modern structures – use modern thinking when designing the format
* Human readability – easy to read for humans, ease troubleshooting
* Minimize options and decisions – less room for mistakes during implementation and usage
* Openness and transparency – important for the overall trust of a system

### **What problems are solved**

According to the latest update of the [OWASP Top 10](https://owasp.org/Top10/), which describes the most common problems and mistakes found in real-world applications, cryptographic failures is in second place.

Cryptographic failures relate to lack of knowledge, skills, and experience in using cryptographic algorithms and set ups correctly. DiME is designed to remove some of those factors and, hopefully, prevent mistakes in cryptographic usage. The format pre-defines usages related to digital signatures (data integrity protection) and end-to-end encryption (data confidentiality protection) without the need of expert knowledge.

Further on, another entry on the OWASP Top 10 is Identity and Authentication Failures, where applications fail to properly identify and authenticate entities making requests. In DiME this is also built in with the help of digital trust by using public keys, much in the same way as traditional Public-Key Infrastructures.

These two aspects form the basis for End-To-End Encryption and Trust (E2EET) which enables applications to both protect sent and received data and verify the identity and trust of any involved parties.

***Thanks for stopping by!***


# Format overview

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

The data format has been designed with inspiration from other modern data formats in use today. Major principles during design have been human readability and ease of use, this to support developers during implementation and making troubleshooting easier.

DiME works with envelopes that contains items and are protected by signatures on diffrent levels, and possibly by diffrent keys. Items may contain additional data like encrypted payloads or application-specific instructions.

<figure><img src="https://1678507575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgRyVH9R66B2nn90QkQ%2Fuploads%2FqF2SCoXYQxiFcUEcR0tZ%2FEnvelope%20structure.png?alt=media&amp;token=a6c9e484-3a75-4492-bb4d-46e4a9c3405e" alt=""><figcaption><p>Visualization of a DiME envelope with multiple items and signatures on different levels</p></figcaption></figure>

A combination of plain text, JSON and Base64 encoding makes up a typical DiME item:

{% code overflow="wrap" %}

```
Di:MSG.eyJhdWQiOiJjYzMwNWY3NC02MWRjLTRlY2UtYmQ1MC1jYTg4NWQwYzM2OWYiLCJleHAiOiIyMDIyLTEwLTIyVDExOjQ0OjU3LjM5Mjk4OFoiLCJpYXQiOiIyMDIyLTEwLTIyVDExOjQ0OjQ3LjM5Mjk4OFoiLCJpc3MiOiJlZjRkNWJmMC1mOWVkLTQzZTktYmE3ZC0wMGNkNDEwYzJmMmMiLCJ1aWQiOiJjNmUwNDE4Yy1mZjgyLTQ0ZTEtYTQ4Ny1mYjQ2NTg3NzBmZWMifQ.UmFjZWNhciBpcyByYWNlY2FyIGJhY2t3YXJkcy4.YjkyMjMwYzBkNTY0YjU0NS4yMWZlNTdjNzY5MDI1ODIwMGM3OTQ0OTJjOTU5MGE3Y2M5ODM4MGJhZDNiZDhmODIyMDNlY2UxNGJhMTE3MTA4YzI5NmU3MzM4MjA5NDk4NzMwMTE5OTU1NGZlNzQ3MGI1NTJmNzBjZjk4YjcxY2JlNzdjYzViNDhkMjliZjcwOA
```

{% endcode %}

Although it may look cryptic, there is many details revealed just by a quick glance. First the header ‘Di’, stating this is a DiME envelope. Then, in this case, it is followed by ’MSG’, indicating there is an attached message item. The following Base64 encoded string can be quickly decoded to reveal easy to read JSON claims.

```json
{
    "aud": "cc305f74-61dc-4ece-bd50-ca885d0c369f",
    "exp": "2022-10-22T11:44:57.392988Z",
    "iat": "2022-10-22T11:44:47.392988Z",
    "iss": "ef4d5bf0-f9ed-43e9-ba7d-00cd410c2f2c",
    "uid": "c6e0418c-ff82-44e1-a487-fb4658770fec"
}
```

The decoded JSON claims contain information that is used to verify and process a DiME item. The claim ‘aud’ indicates the receiver (audience), whereas ‘exp’ (expires at) and ‘iat’ (issued at) specifies when the massage was created and when it will expire. All claims are human readable, including any dates.&#x20;

The DiME data format specifies a series of components known as items. These include:

* Envelope (Di)
* Key (KEY)
* Identity (ID)
* Identity Issuing Request (IIR)
* Data (DAT)
* Message (MSG)
* Tag (TAG)

### Envelope (Di)

The core element of Dime is the Envelope. Although a DiME item, it is more of a wrapping component. Envelopes come in two flavors, anonymous and signed. An anonymous envelope is just a simple way to string together several other Dime items in one easy to manage package. Whereas the signed envelope adds additional integrity protection for all included items inside the Dime envelope.

{% content-ref url="/pages/-MgdkI5NAx9z0K4pXfxp" %}
[Envelopes](/items/envelopes)
{% endcontent-ref %}

### Key (KEY)

This item carries a cryptographic key, which could be a public key pair, a single public key, or a secret key. It includes metadata (claims) for the key. When carrying a public-key pair it forms the bases of an Application-based Public-Key Infrastructure.

{% content-ref url="/pages/-MgdpcsfqaGpIo3z\_AY4" %}
[Key](/items/key)
{% endcontent-ref %}

### Identity (ID)

The Identity item is the core of the authentication mechanisms built into Dime. This is in many ways similar to a X.509 certificate, as it contains information about the subject (holder), a public key, an optional trust chain, and at least one signature to both prove trust and protect the integrity of the information.

{% content-ref url="/pages/-MgRzLTrScpbAhlGB6xa" %}
[Identity](/items/identity)
{% endcontent-ref %}

### Identity Issuing Request (IIR)

The Identity Issuing Request item serves the same purpose as a Certificate Signing Request (CSR) when using X.509 certificates. An entity that wishes to be included in a Dime-based trust chain creates an IIR and a trusted issuer then issue a new identity item and return it to the requesting entity. The returned identity item is then used by the requesting entity to authenticate withing the network.

{% content-ref url="/pages/-MggOe79\_Fvb1JDsOAJP" %}
[Identity Issuing Request](/items/identity-issuing-request)
{% endcontent-ref %}

### Data (DAT)

The Data item is a simple carrier of binary data. Unlike Message there is no target audience and no support for End-To-End Encryption. This may be used to package data into a Dime envelope for integrity protection and trust and then distributed to multiple receivers.

{% content-ref url="/pages/CGrp2X1j8EzL3kg2vhKf" %}
[Data](/items/data)
{% endcontent-ref %}

### Message (MSG)

The message item is used to transmit information inside a DiME-based network. Apart from integrity protection, messages support confidentiality-protected communication using End-To-End Encryption (E2EE), where only the issuer (sender) and the audience (receiver) can read the content.

{% content-ref url="/pages/-MgdpgZYA6Npg5-KX9Jk" %}
[Message](/items/message)
{% endcontent-ref %}

### Tag

Tag items makes it easy to quickly sign one or more DiME items without modifying the signed items. The tags can then be included in a DiME envelope or transmitted separately as proof of verification, reception, or processing.

{% content-ref url="/pages/ICTsUxG2l6sTrJgMB1YT" %}
[Tag](/items/tag)
{% endcontent-ref %}


# Claims

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

DiME uses claims to communicate information to receiving parties. These claims are like other data formats as [JSON Web Tokens (JWT)](https://jwt.io/), although availability and usages may differ.

The first component after the header in a DiME item contains a Base64 encoded JSON string containing claims. Envelopes are an exception to this, where the use of claims is optional.

There are several standardized claims in DiME, all with a specific purpose. Most claims may be used for all types of DiME items, however, there are few exceptions to this.

Even if the data format allows for the use of proprietary or application-specific claims, there is yet no standardized naming convention. At the time being non-standard claims are not officially supported, although this may change over time.

Each standardized claim uses a three-letter abbreviation, referred to as the claim key. The claim key is used in the JSON string as the field name when adding claims. The following table outlines all standard claims, their usage, and any exceptions:

<table><thead><tr><th>Claim</th><th width="80">Key</th><th width="329">Description</th><th>Applies to</th></tr></thead><tbody><tr><td><a href="#ambit">Ambit</a></td><td>amb</td><td>Describes the region, location or boundaries where the item is intended or valid</td><td>All</td></tr><tr><td><a href="#audience-id">Audience ID</a></td><td>aud</td><td>The identifier of the indented receiver, or audience, of the item</td><td>All</td></tr><tr><td><a href="#capability">Capability</a></td><td>cap</td><td>Describes the capabilities, or usages/constrains, of an item</td><td>Identity, Identity Issuing Request, Key</td></tr><tr><td><a href="#common-name">Common Name</a></td><td>cmn</td><td>A common name, or alias, for the item, may be used to simplify manual identification of items</td><td>All</td></tr><tr><td><a href="#context">Context</a></td><td>ctx</td><td>The context for in which the item is to be used or valid</td><td>All</td></tr><tr><td><a href="#expires-at">Expires at</a></td><td>exp</td><td>The date and time when the item should be considered invalid and should no longer be used</td><td>All</td></tr><tr><td><a href="#issued-at">Issued at</a></td><td>iat</td><td>The date and time when the item should be considered valid and only used after (until expires at, if specified)</td><td>All</td></tr><tr><td><a href="#issuer-id">Issuer ID</a></td><td>iss</td><td>The identifier of the issuer of the item</td><td>All</td></tr><tr><td>Issuer URL</td><td>isu</td><td>A URL or other form of resource locator where the issuer identity or public key may be fetched</td><td>All</td></tr><tr><td><a href="#key-id">Key ID</a></td><td>kid</td><td>The identifier of a key that is related to the item</td><td>All</td></tr><tr><td><a href="#item-links">Item links</a></td><td>lnk</td><td>Item links to other items that has been securely linked to the item</td><td>All</td></tr><tr><td><a href="#mime-type">MIME type</a></td><td>mim</td><td>The MIME type of any payload that is attached to the item</td><td>Data, Message</td></tr><tr><td><a href="#methods">Methods</a></td><td>mtd</td><td>Intended for use with external systems and data formats. Will be specified further in the future</td><td>All</td></tr><tr><td><a href="#public-key">Public key</a></td><td>pub</td><td>A public key in raw format</td><td>Identity, Identity Issuing Request, Key, Message</td></tr><tr><td><a href="#principle-information">Principle information</a></td><td>pri</td><td>A key-value object with further information related to the principle related to the item</td><td>Identity, Identity Issuing Request</td></tr><tr><td><a href="#secret-key">Secret key</a></td><td>key</td><td>A secret key in raw format, may be a private key or a shared key</td><td>Key</td></tr><tr><td><a href="#subject-id">Subject ID</a></td><td>sub</td><td>The identifier of the subject related to the item</td><td>All</td></tr><tr><td><a href="#system-name">System name</a></td><td>sys</td><td>The name of the system where the item originated from or belongs to</td><td>All</td></tr><tr><td><a href="#unique-id">Unique ID</a></td><td>uid</td><td>A unique identifier for the item</td><td>All</td></tr></tbody></table>

### Ambit

<table><thead><tr><th width="142">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>amb</td><td>String array (UTF8)</td></tr></tbody></table>

The ambit of an item describes the reach or within what region it may be used. A valid item may be refused if it is being used outside its ambit. The defined ambit and its enforcement is system-specific.

```json
"amb": [ 
    "global", 
    "administration" 
]
```

If ambit is omitted, then it is assumed that the item has no restrictions on where it may be used inside the deployed infrastructure.

### Audience ID

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>aud</td><td>String (UUIDv4)</td></tr></tbody></table>

The audience ID claim specifies the identifier of the receiver, the intended audience, of the a DiME item.

```json
"aud": "34e7081b-8871-467a-a963-7f0eedb42c80"
```

If an item has no direct intended receiver (audience), then this claim may be omitted.

### Capability

<table><thead><tr><th width="142">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>cap</td><td>String array (UTF8)</td></tr></tbody></table>

Capabilities describe the allowed usage of an identity or key. For more information about possible values refer to either [Identity](/items/identity) or [Key](/items/key).

### &#x20;Common Name

<table><thead><tr><th width="422.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>cmn</td><td>String (UTF8)</td></tr></tbody></table>

May be used to simplify manual identification of items where Common Name refers to a particular entity name or alias.&#x20;

```json
"cmn": "Data Integrity Message Envelope"
```

The maximum length of a common name is 84 characters.

### Context

<table><thead><tr><th width="422.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>ctx</td><td>String (UTF8)</td></tr></tbody></table>

This claim is used to provide additional information about the context of the DiME item. This could be used to indicate intention of a message as “request” or “response”, or the use of a particular key.

```json
"ctx": "keep-alive"
```

The maximum length of a context is 84 characters.

### Expires at

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>exp</td><td>String (<a href="https://www.rfc-editor.org/rfc/rfc3339">RFC 3339</a>)</td></tr></tbody></table>

This claim specifies the date when an item expires. The format of the date follows the standard RFC 3339 and UTC must always be used. RFC 3339 is used for its ease of parsing and also since it is human-readable. Items with an expiration date in the past must be discarded, the same applies if the expiration date is before the issued date.

```json
"exp": "2025-11-18T18:06:02.974395Z"
```

### Issued at

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>iat</td><td>String (<a href="https://www.rfc-editor.org/rfc/rfc3339">RFC 3339</a>)</td></tr></tbody></table>

The issued at claim specifies the date when an item was created or issued. The format of the date follows the standard RFC 3339 and UTC must always be used. RFC 3339 is used for its ease of parsing and also since it is human-readable. Items that do include this claim that specifies a date in the future should be discarded, the same applies if the expires at date ("exp") is before the issued date.

### Issuer ID

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>iss</td><td>String (UUIDv4)</td></tr></tbody></table>

This is the unique subject ID of the entity that created or issued an item.&#x20;

```json
"iss": "647589bf-7f7e-4d4c-8174-e3eb366d5a91"
```

### Issuer URL

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>isu</td><td>String (UTF8)</td></tr></tbody></table>

A URL, or part of, that may be used to locate and fetch the issuer identity if needed.

```json
"isu": "https://dime.example.com?id=647589bf-7f7e-4d4c-8174-e3eb366d5a91"
"isu": "?q=647589bf-7f7e-4d4c-8174-e3eb366d5a91"
```

The maximum length of Issuer URL (isu) is 512 characters, although it is recommended to keep this short and use it to build a full URL using other known components.

### Key ID

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>kid</td><td>String (UUIDv4)</td></tr></tbody></table>

The Key ID refers to a unique identifier of a DiME key item. This claim may be used to indicate which key is needed to verify the signature of the item, or which key is needed to decrypt any attached payload.

```json
"kid": "0cef1d8f-54be-4ce0-a669-cd2897ac64e0"
```

Key ID is equal to the value of the unique ID (‘uid’) of a key item.

### Item links

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>lnk</td><td>String (UTF8)</td></tr></tbody></table>

This claim is used to store links to other DiME items in an item. For detailed information refer to [Item links](/cryptography/item-links).

{% code overflow="wrap" %}

```json
"lnk": "KEY.c0eb7bed-591e-4021-970d-e881147fa48d.7df0f3f6122413e83beb5347408d909151d5f956fe973a08357ceaf1c0b83b19"
```

{% endcode %}

### Methods

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>mtd</td><td>String array (UTF8)</td></tr></tbody></table>

This claim will be further specificed in the future. The intention for it is to hold information on how to convert, or adapt a DiME item for the use in external systems using other types of data formats.

An example of this are emerging decentalized solutions for distributing and using public-key pairs.

```json
"mtd":
[
    "furture-specification:and:use"
]
```

### MIME type

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>mim</td><td>String (UTF8)</td></tr></tbody></table>

DiME items that carry arbitrary payloads may use this claim to specify the MIME type of the payload data. This must use the standard format of MIME ([Multipurpose Internet Mail Extensions](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types)) types.

```json
"mim": "text/plain"
```

The MIME type claim is used by [Data](/items/data) and [Message](/items/message).

### Public key

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>pub</td><td>String (UTF8)</td></tr></tbody></table>

This claim holds a public key, which can be used to verify signatures or complete Diffie-Hellman key agreement for shared keys. For that actual format refer to [Key encoding](/encoding/key-encoding).

```json
"pub": "STN.Lo8cQbUU9wiDY1rgDbxYDAzsm8gis7RrDFsnH3BcvbY8wpBNC"
```

The Public key claim is used by [Identity](/items/identity), [Identity Issuing Request](/items/identity-issuing-request), [Key](/items/key) and [Message](/items/message).

### Principle information

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>pri</td><td>JSON object</td></tr></tbody></table>

A simple JSON object with information associated with the subject or holder of an identity. This may be the name of the entity name and organization. Not standard fields have been specified for the DiME data format and this claim is considered to be applicaiton-specific. This may be changed in the future.

The below example should be see as an example of usage as field names and structure is up to the application.&#x20;

```json
  "pri": {
    "entity": "Example subject",
    "location": "Planet Earth",
    "organization": "DiME",
    "domain": [ "dimeformat.io" ],
    "contact": [ "info@dimeformat.io" ]
  }
```

The Principle information claim is used by [Identity](/items/identity) and [Identity Issuing Request](/items/identity-issuing-request).

### Secret key

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>key</td><td>String (UTF8)</td></tr></tbody></table>

The raw data of the secret key, asymmetric or symmetric. For encoding information refer to [Key encoding](/encoding/key-encoding).

```json
"key": "STN.aBjkzKX2B5ZwG1nrbmNFmugZp6o3i6Fk8oVmjtfopvgTPJcPcEMottZji2ejUmMWgEDukLDyFBchTw5KBoKjFF55wCTWk"
```

This claim is used by [Key](/items/key).

### Subject ID

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>sub</td><td>String (UUIDv4)</td></tr></tbody></table>

This is a unique identifier for the entity (subject) that owns, or is associated with, the DiME item. Unlike [Unique ID](#unique-id), this may be reused over time for the same subject or entity. For example, if an entity requests a re-issue of an Identity item, then the Subject ID may remain the same, whereas the Unique ID would change.

```json
"sub": "a6902184-2ba0-4ba0-ab91-ca77da7d05d3"
```

### System name

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>sys</td><td>String (UTF8)</td></tr></tbody></table>

The system claim specifies the network, application scope or system where a DiME item is deployed. It may be used to specify sub-sections within a larger infrastructure.

The usage is application-specific. However, when issuing Identity items from a Identity item the system name will carry over, unless anything else is specified.

```json
"sys": "dimeformat.io"
"sys": "beaa26e7-34b2-4fa2-bdf6-17fec0840a01"
"sys": "NETWORK_DOMAIN:SUBNETWORK_DOMAIN"
```

### Unique ID

<table><thead><tr><th width="158.2173913043478">Claim key</th><th width="260">Format</th></tr></thead><tbody><tr><td>uid</td><td>String (UUIDv4)</td></tr></tbody></table>

This is unique identifier for a DiME item. It must not be reused, not even for items of other DiME item type. A new unique id must be generated at creation, this is also required when reissuing Identity items.

```json
"uid": "c48e4b68-91ac-4c93-ba96-1c35c50761d4"
```

## JSON

DiME holds item claims in a simple JSON structure, as demonstrated previous. To enable simple cross-platform use DiME also uses JSON canonicalization to ensure a consistent order of the claims inside the JSON structure. The JSON Canonicalization Scheme (JCS) is described in [RFC 8785](https://www.rfc-editor.org/rfc/rfc8785).

#### JSON schema

Coming soon...


# Item verification

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

Before a DiME item should be trusted and then used, it must be verified. Verification is an important step and plays a part in the saying "Trust, but verify", or perhaps the more modern version "Never trust, always verify".

There are four steps in the verification of a DiME item, these are:

1. (if available/applicable) verify the issuer of the DiME item
   1. verify that "iss" claim in verified item is equal to "sub" claim identity used to verify
   2. verify the validity (dates) in the issuer identity, see point 2 for required steps
2. (if available) verify any dates in the DiME item
   1. verify that issued at date is passed (if "iat" claim is set)
   2. verify that issued at date is not after expiration date (if "iat" and "exp" claim are set)
   3. verify that expiration date is not passed (if "exp" claim is set)
3. (if available) verify that linked items are valid
4. (if available) verify that the digital signature is correct
   1. if verifying with a trust chain, then each identity in the trust chain to the root must also have their signatures verified

This order is used to ensure that the more expensive verification operations are done later in the verification process, this includes verification of item links and digital signatures. If any steps fail, then the verification must exit with an appropriate error code.

Each verification may be done separately if this is more appropriate. However, it is generally recommended to verify everything in one operation.

### Verify issuer claim

If an DiME item is verified directly using a DiME identity, and thus using the public key inside the identity, then the claim "iss" must contain the same value in both items.

### Verify dates

If any date-based claims are set in an item, then those need to be verified. This following order should be used when verifying:

1. The issued at date must be earlier than the current system date
2. The issued at date must not be later than the expiration date
3. The expiration date must be later than the current system date

Note that it is only necessary to validate those dates that are set in an item. If a date claim is excluded, then the item should be considered to never expire (missing "exp" claim) or have no start date (missing "iat" claim).

Date verification should be done using milliseconds. This may, however, introduce a time synchronization issue when sending instant or short-lived items between entities. For thoughts and solutions to this problem, refer to [Time synchronization](/time-syncronization).

All dates processed must always be in [Coordinated Universal Time](https://en.wikipedia.org/wiki/Coordinated_Universal_Time) (UTC).

### Verify linked items

Linked items need to be verified before an item may be considered complete from an integrity perspective.&#x20;

Multiple items may be linked to one DiME item and it should be possible to verify one or more items at the same time. If not all items linked are verified, then the integrity should be considered partly intact, only if all provided items are verified successfully. Intact integrity is only when all linked items are verified successfully against a complete and matching set of provided items.

If any item in a provided list is verified unsuccessfully, then integrity must be considered broken.

Linked items may be omitted when verifying for trust, which may be the case when the verifying entity do not have access to the original items that are linked.

### Verify signature

Verification of a digital signature is normally the most expensive operation, thus it may be done last, and only if all other previous verification operations have completed successfully.

A provided public key, or locally stored trusted public keys, should be used to verify the integrity of the DiME item towards the signature. The item header together with any base 64 encoded content must be used when generating the signature, and thus, also when verifying the signature.

For additional details of signatures and how they are encoded, refer to [Signature encoding](/encoding/signature-encoding).

### Integrity state results

The following table outlines the integrity state result value for DiME item verification. These state must be used to indicate the result of a verification.&#x20;

<table><thead><tr><th width="247">State name</th><th width="154.33333333333331">Success/failed</th><th>Description</th></tr></thead><tbody><tr><td>Complete</td><td>Success</td><td>All parts of the DiME item was successfully verified and the item may be trusted.</td></tr><tr><td>Partially complete</td><td>Success</td><td>All parts of the DiME item was successfully verified. However, not all linked items where verified, although, those that where was successful.</td></tr><tr><td>Intact</td><td>Success</td><td>All verified parts of the DiME item was successful. However, some parts where skipped, like linked items as no list of items where provided.</td></tr><tr><td>Valid signature</td><td>Success</td><td>The signature of the DiME item was verified successfully. No other parts where verified.</td></tr><tr><td>Valid dates</td><td>Success</td><td>The dates (issued at and/or expires at) in the DiME item were verified successfully. No other parts where verified.</td></tr><tr><td>Valid item links</td><td>Success</td><td>Any linked items where verified successfully against a provided item list. No items where skipped or missing. No other parts where verified.</td></tr><tr><td>Partially valid item links</td><td>Success</td><td>All linked items where verified successfully against a provided item list. Any list, linked items or provided items, may contain items not in the other list. No other parts where verified.</td></tr><tr><td>No signature</td><td>Failed</td><td>Unable to verify the digital signature, as the DiME item did not contain a signature.</td></tr><tr><td>Not trusted</td><td>Failed</td><td>The digital signature could not be successfully verified, and, thus the DiME item must not be trusted.</td></tr><tr><td>Key mismatch</td><td>Failed</td><td>The public key used to verify the DiME item does not match the key pair used to generate the digital signature.</td></tr><tr><td>Issuer mismatch</td><td>Failed</td><td>The issuer ID ("iss") in the DiME identity used when verifying does not match issuer ID ("iss") set in the item verified.</td></tr><tr><td>Used after expired</td><td>Failed</td><td>The expiration date ("exp") set in the DiME item verified has passed, and the item should no longer be used.</td></tr><tr><td>Used before issued</td><td>Failed</td><td>The issued at date ("iat") set in the DiME item has not yet passed, and the item should not be used yet.</td></tr><tr><td>Date mismatch</td><td>Failed</td><td>The dates set in the DiME item verified are incorrect, where the issued at date ("iat") is after the expiration date ("exp").</td></tr><tr><td>Linked item fault</td><td>Failed</td><td>One, or several, linked items could not be verified successfully.</td></tr><tr><td>Linked item mismatch</td><td>Failed</td><td>Provided item list to verify linked items contains additional, non-linked, items.</td></tr><tr><td>Linked item missing</td><td>Failed</td><td>No linked items found when verifying with a provided item list.</td></tr></tbody></table>


# Time syncronization

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

When working with issued at dates and expires at dates as DiME does, problems around time synchronization may start to be apparent. This since a client with a time off with just a few seconds could mean that a message seems to be expired, even if it is still very much valid, or it may look like responses coming in are from the future.

Just like with DiME, there is no built-in solution for problems related to time synchronization in standards such as X.509 for digital certificates. However, for digital certificates, this problem is more minor as certificates are valid for a more extended period.

{% hint style="info" %}
The [DiME reference implementation](/implementations) includes several tools to handle time synchronization issues.
{% endhint %}

There is one situation where the problem may be easily noticed, at the time of creating and signing a new certificate.

However, a newly issued certificate still suffers from a time problem. A recent *notBefore* date may be in the future from the receiving client’s perspective if it is running behind in time to the issuing server. This means that the client may have to wait before starting using it. Some Certificate Authorities (CAs) therefore issue certificates with a *notBefore* date 10 minutes into the past for exactly this reason. These tactics provide a 10-minute error margin for any time differences.

The same solution can be utilized with DiME, where Identities would be issued with an issued at (*iat*) date 10 minutes in the past, from the server’s perspective. This will allow an issued Identity to be used immediately. This assumes that no entity in the network is more than 10 minutes behind the issuing server.

SSL/TLS also avoids the issue of time differences between devices. However, during the handshake, the client and server exchange 32 random bytes where the four first bytes encode the current date. Why is not clearly explained, and perhaps this could be used for understanding the difference in time between the devices. However, many usages do not follow this, so it makes it unreliable as a source for the current time.

Furthermore, neither SSL nor TLS considers the validation of the certificate to be within the scope of the specifications. It is just assumed that the client validates the certificate. This does open for situations where the handshake would fail due to differences in time.

### Synchronizing time

It is not possible to use the 10-minutes-into-the-past solution when sending short-lived messages. Here differences in seconds could still present severe problems.

There are at least two things that need to be done to solve the problem of time differences between devices. Firstly, time needs to be synced between all devices, and secondly, some slack needs to be added when comparing two timestamps.

The simplest solution to synchronize time is to have all networked devices use the same time server (NTP-server). Each device would request the current time from the NTP-server and adjust its local time. Time differences between different time servers tend to be minor, so using different time servers may also be an option.

Sometimes it may not be practical or even possible to use a time server. In this scenario, it would be possible for clients to synchronize their times with a central server.

This approach requires at least three timestamps to synchronize with and would result in a somewhat accurate time between two devices. The client that wishes to synchronize its time with the server would capture its own current time just before requesting a timestamp from the server. Then when the client receives the response with the server’s time, it would capture a second timestamp.

Using these three timestamps, the client would then calculate a delta for how much ahead or behind it is compared to the time from the server.

Firstly, consideration must be given to the round-trip time and any latency, this is done by subtracting the first local timestamp from the second local timestamp and dividing the result by 2. This is an approximation, which turns out to be fairly accurate.

```
TRIP_TIME = (LOCAL_TIME_2 – LOCAL_TIME_1) / 2
```

Then the delta is calculated by subtracting the second local timestamp with the server time and adding the consideration for the request trip time.

```
TIME_DELTA = SERVER_TIME – LOCAL_TIME_2 + TRIP_TIME
```

Once the delta has been calculated it should be added to any timestamps captured by the client. The time will still not be exact between the client and server, but it should not be off by more than a second or so.

### Avoiding edge cases

Even if the time is synchronized between a client and a server, there exists the possibility of improperly disqualifying a received message. This may happen both at the start, issued at, and at the end, expires at, of the validity period if any of the communicating devices are a second or so behind or ahead of the other.

The likelihood of a device being behind or ahead with just one or two seconds is quite high, even if they are time-synchronized. This could be due to the imprecise measurement when calculating the request trip time and if synchronizing on seconds or milliseconds.

To compensate for this impreciseness, it is possible to compare timestamps with a small grace margin, one or two seconds in either direction.

This would mean that the validity period, between the issued date and the expiration date, is extended by a few seconds in either direction.

```
ISSUED_AT – GRACE_MARGIN <= NOW and EXPIRES_AT + GRACE_MARGIN >= NOW
```

Working with a grace margin is only effective if the communicating devices are already time-synchronized. If they are not, its usefulness is limited.

Time is always a problem, which may sometimes create difficult to debug problems or rejections that are hard to explain. Incorporating the ideas outlined here may make working with time a little less frustrating, unfortunately, it won’t solve it altogether.


# Implementations

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

The following official reference implementations are available:

* C#/.NET
  * [Source code (GitHub)](https://github.com/shifteverywhere/dime-dotnet-ref)
  * [Nuget package](https://www.nuget.org/packages/DiME/)
* JAVA
  * [Source code (GitHub)](https://github.com/shifteverywhere/dime-java-ref)
  * [Maven artifact](https://search.maven.org/artifact/io.dimeformat/dime-java-ref/1.2.1/jar)

Apart from reference implementation of the DiME data format, there is also an early implementation of a command-line tool to help in generating DiME items. This tool may be used to generate keys and identities for trust trees, or just to assist working with DiME items in general.

* [DiME Command-line tool](https://github.com/shifteverywhere/dime-tool)

### Code examples

The following code examples are provided in C#.

#### Creating an Identity Issuing Request

In order to include an entity in a trust chain, the entity must first create a public-key pair and an Identity Issuing Request (IIR):

```csharp
var key = Key.Generate(KeyCapability.Sign);
var caps = new List<IdentityCapability> { IdentityCapability.Generic, IdentityCapability.Identify };
var iir = IdentityIssuingRequest.Generate(key, caps);
```

Here a public-key pair and a list of capabilities to be requested are created. These are then used to create the IIR. The IIR then needs to be sent to the issuing entity for the creation of a new Identity item. Note that the secret (private) key inside **key** should never leave the entity where it was generated.

#### Issuing a new Identity item from an IIR

Once an IIR is received from an entity a new Identity item should be generated and issued. This Identity item should be sent back to the requesting entity and later used for authentication purposes, much like a X.509 certificate.

```csharp
var subjectId = Guid.NewGuid();
var allowedCaps = new List<IdentityCapability> { IdentityCapability.Generic, IdentityCapability.Identify };
var identity = iir.Issue(subjectId, Dime.ValidFor1Year, rootKey, rootIdentity, true, caps);
```

The **iir** in the above example would be the Identity Issuing Request received from a requesting entity. The variables **rootKey** and **rootIdentity** are the public keypair and Identity item of the issuing entity. The resulting **identity** contains no sensitive information and may be communicated publicly to be used as part of the authentication of the owning entity.

... more code examples to follow ...


# Licence

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

### MIT License

Copyright (c) 2022 Shift Everywhere AB

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


# Version history

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

<table><thead><tr><th width="115">Version</th><th width="134">Date</th><th>Notes</th></tr></thead><tbody><tr><td>1.000</td><td>2022-10-01</td><td>The first official and public version 1 of the DiME data format specification. </td></tr><tr><td>1.001</td><td>2022-10-25</td><td>'DSC' should be used for specifying the DiME Standard Cryptography suite as header in raw encoded key materials. DSC to use Base 64 encoding.</td></tr><tr><td>1.002</td><td>2022-11-01</td><td>Verification process and integrity state results specified. Added issuer URL claim ("isu").</td></tr><tr><td>1.003</td><td>2023-02-10</td><td>Added Common Name claim ("cmn").</td></tr><tr><td>1.004</td><td>2023-03-08</td><td>Defined 'NaCl' cryptography suite to replace previous suite.</td></tr></tbody></table>

Further changes within the same major version, currently 1, will only be made as long as they do not break existing DiME items. However, changes may not, in some instances, be backwards compatible with existing implementations.


# Envelopes

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

A DiME envelope encapsulates other DiME items. This produces the consistent format for encoded DiME items and always starts with the header 'Di'. All DiME encoded strings are envelopes, no matter if they contain one or more items.

Envelopes may either be unsigned or signed. The main difference is that signed envelopes uses a digital signature to protect the integrity of the content. In some cases this may not be needed, as individual DiME items may themselves be digitally signed, thus making it unnessarcy to sign the encapsulating envelope..

## Unsigned envelope

An unsigned envelope only consists of the header ('Di') and any items within separated by a colon (':'), known as an item separator. Below is an example of an anonymous envelope containing an identity item:

{% code overflow="wrap" %}

```
Di:ID.eyJjYXAiOlsiZ2VuZXJpYyIsImlzc3VlIiwic2VsZiJdLCJleHAiOiIyMDMyLTA5LTMwVDE0OjQxOjUzLjEyMTUwMFoiLCJpYXQiOiIyMDIyLTEwLTAzVDE0OjQxOjUzLjEyMTUwMFoiLCJpc3MiOiJiNDNjNDgyOC0wOTYxLTRiZDYtYjdhYy1lNzZiOTg4YmFmZjAiLCJwdWIiOiJTVE4uZFgycVJtWWZ2eFRNdVZIeml2a1hjUU0zQWROMm44aEhoRkJ2ZnNENDhXVGVzcjRZVSIsInN1YiI6ImI0M2M0ODI4LTA5NjEtNGJkNi1iN2FjLWU3NmI5ODhiYWZmMCIsInN5cyI6ImlvLmRpbWVmb3JtYXQucmVmIiwidWlkIjoiMTU3NGZkZDEtMDRkOC00MjRjLTgyYjItZjkxMDFkNTliYjI3In0.MjY3MDU3ZmQ5N2UyMDNmNi41MjI1NDExMjhhOGNhZTViYWI5MTQ1ZDdjYTFlNWIxMzYyZTU3Mzg5ZjE5NjQyMjhiNjZmZWYwZDdjYmUwYzM0YTM1YzA3YWRmMzIwMWFmNDU1ZmMwNjBiM2E5NmY5MzlkNTQ3ZGIwZGFmZTMzNWJmN2MyZjc1YmFhNjVjNjAwYg
```

{% endcode %}

No separate validation is required for an unsigned envelope. However, items contained within may need to be verified independently.

## Signed envelope

Signed envelopes are DiME envelopes that, besides containing one or more items, also carry a signature at the end that protects the integrity of all enclosed items. The following example shows a signed envelope where the signature is placed after the final item separator (':'):

{% code overflow="wrap" %}

```
Di.eyJjdHgiOiJ0ZXN0LWNvbnRleHQiLCJpYXQiOiIyMDIyLTEwLTIzVDEyOjA3OjM4LjYwNjQ3OVoiLCJpc3MiOiJlZjRkNWJmMC1mOWVkLTQzZTktYmE3ZC0wMGNkNDEwYzJmMmMifQ:DAT.eyJleHAiOiIyMDIyLTEwLTIzVDEyOjA4OjM4LjYwODU4N1oiLCJpYXQiOiIyMDIyLTEwLTIzVDEyOjA3OjM4LjYwODU4N1oiLCJpc3MiOiJjYzMwNWY3NC02MWRjLTRlY2UtYmQ1MC1jYTg4NWQwYzM2OWYiLCJtaW0iOiJ0ZXh0L3BsYWluIiwidWlkIjoiMmJhZTk0MTktYjZiNy00MmE0LWFhM2YtNmVlZTQxMWZhN2IwIn0.UmFjZWNhciBpcyByYWNlY2FyIGJhY2t3YXJkcy4.YjkyMjMwYzBkNTY0YjU0NS5mNGNmYzAyODc4ZWYzZGI5NjkzNThhMTg3OGY2ODE2Y2I1YjI0MmQ0ZmVmNjIwNmRiMTg2YzNjNmE4MjcwYjM5OGMxMzc1Y2U0NGVlZjJmZTczNTE1MzRjZTk3MWU2OTc1MTY0NDNkZDQxMjFhNmU0NGNlYmEwMjFkYTIzODcwYw:YjkyMjMwYzBkNTY0YjU0NS41ZmYyOGU0YzRjYzk3OTE1MjliOGQ2ZmI2YTNjNzE2NmJiZjM4ODk0NjU2Njc5ZjczODM2ZmQ4MGYwYjI3OWY3YzdjMTI3NGFmNDIxYjYzMzY1OTg4MzMyMzAwOGU0NmZiMjE4ZmQzYTA5ZGYwYWM5NzczMzM3YzA5NTI5ZGIwOQ
```

{% endcode %}

The envelope signature should be verified before any processing of items inside a signed envelope. The public key to verify a signature may indicated by claims components following the header ('Di').

### Claims

Claims are information associated with the envelope. These are stored in the component following the header ('Di'). This component is only included if the envelope is signed and, among other things, identified the entity that signed the enveloped and when it was issued.

For more details information around available claims refer to [Claims](#claims).


# Key

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

Key items are used to store or distribute keys within an Application-based Public-Key Infrastructure (APKI). Keys may be signed or unsigned.

Example:

{% code overflow="wrap" %}

```
Di:KEY.eyJjYXAiOlsic2lnbiJdLCJpYXQiOiIyMDIyLTEwLTIzVDEyOjEyOjQwLjM3MDQwM1oiLCJrZXkiOiJTVE4uTFNONk01MTlSNDczd1VINUROcXl6a1FlQ1k0NExzd0w5aXVGUFlvMThqd3hoV3p6NUNWc3NOeVdManhvMWFGZkhSY2dueVA3NVBXTlBxenZZRWVMa3Y2bk1CN1JHIiwicHViIjoiU1ROLjJhdFpRWlc5Z1BSa29MamZwYXhhR29LSHJQYUg3Sksyc1F2QXB6cjlleENZNUhTeVQyIiwidWlkIjoiYzk3YzViYTctNjQ0NC00NzZkLWJlMTMtOTA4NGI5ZGQ1ZmNhIn0
```

{% endcode %}

The header of a DiME key item is always 'KEY' as seen in the above example following the colon (':') after the envelope header ('Di').

Key may contain types with different capabilities and usages. For any public versions, keys intended for distribution, it is vital to remove the 'key' claim, as this hold the sensitive key material for a private or secret key. Apart for removing the 'key' claim, a public version may exactly the same as the original key item.

### Components

A DiME key item consists of several components. Each component is separated by a dot (‘.’), which is referred to as a component separator.

The following components make up a key item:

* Header - always 'KEY'
* Claims - required
* Signature - optional

#### Claims

Claims are information or data related to the key, including the actual public and/or secret key.

Claims inside the key item may be optionally protected by signing the key item.

Example of a decoded claims component:

{% code overflow="wrap" %}

```json
{
    "cap":
    [
        "sign"
    ],
    "iat": "2022-10-03T17:37:02.630038Z",
    "key": "DSC.7VN2b6f0nxqubSU955PuMenLtV6u9ltQr0ovUG0CL0Rfhb9S9IvUapNj58CHcsVwMYr3bOw/aghjECVcua2M+Q",
    "pub": "DSC.X4W/UvSL1GqTY+fAh3LFcDGK92zsP2oIYxAlXLmtjPk",
    "uid": "c8f26b1f-3406-4c29-a47e-b8482780ab64"
}
```

{% endcode %}

As any other DiME items, Key may use many different claims. This section will detail those claims that are specific for keys. For general information about claims refer to [Claims](#claims).

### Capability

The capability ('cap') claim describes the usages that are intended for a key. This will determine what a key may be used for. Capabilities, and combinations thereof, may be limited by the cryptographic suite used, refer to [Suites](/cryptography/profiles) for more information.

The following key capabilities are defined in the DiME data format specification:

* authenticate
* encrypt
* exchange
* sign

```json
"cap":
[
    "sign"
]
```

#### Authenticate

Given to keys that may be used to generate authentication codes. This may be one-time passwords or message authentication codes.

#### Encrypt

Given to keys that are used for symmetric encryption, where the same key is used to encrypt and decrypt a set of data.

#### Exchange

Given to keys that are used for Diffie-Hellman key agreements, where multiple entities need to securely exchange a symmetric a shared key for encryption, or other purposes.

#### Sign

Given to keys that are used to generate digital signatures. Digital signatures may be used to protect the integrity of a set of data, which may be other DiME items.

### Public key

The public key ('pub') claim holds the public key of a public-key pair. For format and encoding information refer to [Key encoding](/encoding/key-encoding).

This claim is only used with keys that have the capability 'sign' or 'exchange'.

### Secret key

The secret key ('key') claim holds either the private key of a public-key pair or a shared encryption key (symmetric).&#x20;

If a public version of a key item is generated, then this claim must be omitted.

### Signature

A DiME key item may be signed to protect its integrity. For additional information about signatures refer to [Signature encoding](/encoding/signature-encoding).


# Identity

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

The identity item is used to identify entities within an Application-based Public-Key Infrastructure (APKI). In many ways it is equivalent to a X.509 certificates.

An Identity item carries information about the owner or holder, refereed to as a subject. A subject may be a device, node or actual individual.

The following is an example of a DiME identity item:

{% code overflow="wrap" %}

```
Di:ID.eyJjYXAiOlsiZ2VuZXJpYyIsImlkZW50aWZ5Il0sImV4cCI6IjIwMjMtMTAtMDNUMTQ6NDE6NTMuMTU2NzY0WiIsImlhdCI6IjIwMjItMTAtMDNUMTQ6NDE6NTMuMTU2NzY0WiIsImlzcyI6ImNlNTc4YjM2LWJhMmMtNGNmMS1hZTVjLTM3YzU2NWFmNmUxMSIsInB1YiI6IlNUTi41c3JlS1hGRE1iYUVUekJkVVVwSzVEYm5vSnJhMUZlN2RlWkRNRmlyeFVnZDZCN3JzIiwic3ViIjoiY2MzMDVmNzQtNjFkYy00ZWNlLWJkNTAtY2E4ODVkMGMzNjlmIiwic3lzIjoiaW8uZGltZWZvcm1hdC5yZWYiLCJ1aWQiOiJlYmE3YzcxOC0wNjBjLTQ4MDgtYjM1MS00Nzc5MzAyNjUwMmQifQ.SUQuZXlKallYQWlPbHNpWjJWdVpYSnBZeUlzSW1sa1pXNTBhV1o1SWl3aWFYTnpkV1VpWFN3aVpYaHdJam9pTWpBeU55MHhNQzB3TWxReE5EbzBNVG8xTXk0eE5EUXpOamhhSWl3aWFXRjBJam9pTWpBeU1pMHhNQzB3TTFReE5EbzBNVG8xTXk0eE5EUXpOamhhSWl3aWFYTnpJam9pWWpRell6UTRNamd0TURrMk1TMDBZbVEyTFdJM1lXTXRaVGMyWWprNE9HSmhabVl3SWl3aWNIVmlJam9pVTFST0xtMXJWVTF2WjJWdmFGVTVRM1YxY0RsVlYzWnhNVEo2VTI5Vk5qUmxURlZYVlZoeE1UbG1PWEJaU2pOaFNsWkdVRU1pTENKemRXSWlPaUpqWlRVM09HSXpOaTFpWVRKakxUUmpaakV0WVdVMVl5MHpOMk0xTmpWaFpqWmxNVEVpTENKemVYTWlPaUpwYnk1a2FXMWxabTl5YldGMExuSmxaaUlzSW5WcFpDSTZJalV5T1RNMlptUTBMV1ZtTldNdE5EbGxOUzA1T1RreUxUSmxaVEJsWkRBeFpETXdNaUo5Lk1qWTNNRFUzWm1RNU4yVXlNRE5tTmk1all6TTNNbU5rWTJFek1EQmtaRFU1TkRZMk5HWmhNMkUxWXpaa00yUTFNakpqTmpSbE9EbG1NalE1TmpjME9EVXdNamN3TlRReFkyVXlOalZrTUdOalpUVmhaVFJsTmpFMk1tUTNNREpqTURFNE1tWTJZalUyTkRKa09ERTVOREUxTW1Oa056ZzNZMlkxTlRFd056Qm1abVV4Tm1aaU0yRXpOemcxTXpFd05B.MDFiODQxNmIzMjk0NmJmYi5jZWQ2ZThkYWMyYWMyOTMzODI5ZDhmZGY3NWE0Y2IwMzE5N2FmNDY3MjVmMDQ2NjE3NDBmZDE5ODJiM2FjZjJmOGNiZmIwNDVlZTk3YWEwYWU0NzZlZDEzMTA5MmU1MTAyNDg1NzU2M2VhYmNhOTc0ZDEwYTIwOGI0YTgxNDgwMg
```

{% endcode %}

The header of a DiME identity item is always 'ID' as seen in the above example following the colon (':') after the envelope header ('Di').

### Components

A DiME identity item consists of several components. Each component is separated by a dot (‘.’), which is referred to as a component separator.

The following components make up an identity item:

* Header - always 'ID'
* Claims - required
* Trust chain - optional
* Signature - required

#### Claims

Claims are information or data related to the identity. These could be unique identifiers, expiration dates, associated public keys, and principle information (additional information about a subject).

Any claims inside an identity item are protected from modification by an encapsulating signature. This signature is generated when the identity is issued, normally by using the private key of the issuing entity.

Example of a decoded claims component:

```json
{
  "amb": 
  [
    "global",
    "adminstration"
  ],
  "cap":
  [
    "generic",
    "identify"
  ],
  "exp": "2023-10-03T14:41:53.156764Z",
  "iat": "2022-10-03T14:41:53.156764Z",
  "iss": "ce578b36-ba2c-4cf1-ae5c-37c565af6e11",
  "pri": 
  {
    "entity": "Example subject",
    "location": "Planet Earth",
    "organization": "DiME",
    "domain": [ "dimeformat.io" ],
    "contact": [ "info@dimeformat.io" ]
  },
  "pub": "DSC.X4W/UvSL1GqTY+fAh3LFcDGK92zsP2oIYxAlXLmtjPk",
  "sub": "cc305f74-61dc-4ece-bd50-ca885d0c369f",
  "sys": "io.dimeformat.ref",
  "uid": "eba7c718-060c-4808-b351-47793026502d"
}
```

As any other DiME items, Identity may use many different claims. This page include those claims that has specific usage for identities. For general information about claims refer to [Claims](#claims).

### Capabilities

An important part of a DiME identity is the capability ('cap') claim. This array of strings specifies what an identity may be used for. The Di:ME specification defines a small number of capabilities that are considered standards.&#x20;

The following capabilities are currently defined:

* generic
* identify
* issue
* prove
* seal
* self
* timestamp

```json
"cap": 
[ 
    "generic", 
    "identify", 
    "issue",
    "prove"
    "seal",
    "self",
    "timestamp" 
]
```

Capabilities are generally requested by a subject through an [Identity Issuing Request](/items/identity-issuing-request) (IIR). The issuing subject will validate the requested capabilities, and if acceptable, issue a Dime identity with the same capabilities.

During issuing of an identity, it is recommended to verify the requested capabilities to ensure that only allowed capabilities are being asked for. Also, it is recommended to make sure that required capabilities are included.

Some requested capabilities may be removed during issuing and others, that may not have been requested, can be added.

#### Generic

The generic capability is normally always present, particularly when no other capability has been requested. Although, when other capabilities are set, the inclusion of generic is not required.

This is given to subjects that have been allowed to connect to a system, but where no or limited authentication have been conducted.

An example may be in an IoT-network which uses Trust-On-First-Use (TOFU) when registering devices automatically. In these cases, full authentication may not be possible. Once a DiME identity with the generic capability has been issued to a device, it may be used for authentication of that device.

#### Identify

The identify capability should be given to entities that have been properly authenticated before issuing an identity. The identity issued may after this point replace the authentication method.

Several DiME identities may be issued to the same subject. First one with a generic capability for the initial connection, then once the subject performed the required authentication, a new identity, containing the identify capability, may be issued. This allows for a system where subjects with different capabilities co-exist and can increase or decrease capabilities over time.

#### Issue

The issue capability is used when a DiME identity should be able to issue other identities from received IIRs. Normally this capability is given to either a root identity or additional issuing identities that are used to register entities within a system.

It is recommended to use this capability only for a limited number of identities within a system. These identities are used to build up the network of registered identities and therefore also the trust within.

Additional issuing identities, issued by one root identity, may be used to create sections within an infrastructure, where the trust chains are different depending on which part a subject belongs to.

#### Prove

The prove capability is used when a entity needs to prove ownership of something, or prove the including to some part of a system.&#x20;

Prove is considered to be more limited to the identify capability, but more authenticated then the generic capability.

#### Seal

The seal capability is intended to use for packaging and integrity protecting artifacts, builds, binary files, documents, or code. Here the signature will be used to verify authenticity of the package and also associate the release or file with the author or supplier.

#### Self

The self capability must only be used with identities that are their own issuer. This happens when an IIR is created with a public-key pair, which is then used to issue a new identity by the same entity (without the use of another identity item).

This capability should only reserved to root identities and a limited amount of other identities responsible for issuing identities.

Identities with the capability self are considered self-issued.

#### Timestamp

The timestamp capability is to be used when locking some noteworthy moment in time, much a notary stamp. This will help to freeze digital assets in time proving that they were valid at the time of signing.

### Principle information

A DiME identity may use the claim for Principle information ('pri'). This allows for application-specific information to be include in the identity item.

The principle information claim is a simple JSON object and may be filled with any type of valid information. No standard fields have been specified for the use of this claim, and is considered to be applicaiton-specific. This may be changed in the future.

```json
"pri": 
{
  "entity": "Example subject",
  "location": "Planet Earth",
  "organization": "DiME",
  "domain": [ "dimeformat.io" ],
  "contact": [ "info@dimeformat.io" ]
}
```

### Trust chain

This component is optional and its usage depends on the system or infrastructure where DiME identities are used.

A normal trust chain consists of two or three identities, a root identity, an optional intermediate identity, and at least one leaf identity. In this chain the root identity is self-signed, the intermediate identity is signed by the root and any leaf identities are signed by the intermediate.

Any number of identities may be added recursively in this component and used appropriately to verify the full trust chain. In the above example using three identities (root, intermediate and leaf) the trust chain component would include the intermediate identity. Here it is assumed that the root identity is distributed separately and most likely beforehand.

### Signature

The final component in an identity item is always the signature. Any identity item that is missing a signature component must always be discarded. The identity item must also be discarded if the signature verification fails.

For additional details around the format of signature see [Signature encoding](/encoding/signature-encoding).


# Identity Issuing Request

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

An Identity Issuing Request (IIR) item serves a similar purpose to a Certificate Signing Request (CSR) when using x.509 certificates. An entity that wants to register and acquire a DiME identity within a system or infrastructure starts by creating an IIR. The IIR is then sent to an issuing entity, that approves the request and issues a new Dime identity.

The following is an example of an IIR item:

{% code overflow="wrap" %}

```
Di:IIR.eyJjYXAiOlsiZ2VuZXJpYyJdLCJpYXQiOiIyMDIyLTEwLTIzVDEzOjMwOjAxLjM2ODI3N1oiLCJwdWIiOiJTVE4uTWY5MjVGblh3Nmp5RmZKSkFFWTZFM0drNUZ3S0Q3ZmtNSHJDc29xVHJjN2VleDU5VSIsInVpZCI6IjQ2MWJkOTk1LTBhOGUtNDI4NS1iNTMyLTVjODllZDFmYWM1NyJ9.YmQ2YmQ5N2I4NDIwMmNiYS5mNzQyNmFhZjJmOWYzOWU0NzBhMmFiY2MwNzkwODEzYjBiNTA5ZjljYzQzMmZiYTgwZWJjZDgwYzI5OGNiMWVmMDgwY2Y3MDUzMWUzOGJkMTJhMWI4ODZhMTYzZWI5YWVjMjk4YzczY2EzYmY2NjYwZDM2YjIxMjE4NjA3YzEwMA
```

{% endcode %}

The header of a DiME identity issuing request item is always 'IIR' as seen in the above example following the colon (':') after the envelope header ('Di').

### Components

A DiME identity issuing request item consists of several components. Each component is separated by a dot (‘.’), which is referred to as a component separator.

The following components make up an identity issuing request item:

* Header - always 'IIR'
* Claims - required
* Signature - required

#### Claims

Claims are information or data related to the entity and identity issuing request. These could be unique identifiers, expiration dates, associated public keys, and principle information (additional information about a subject).

Any claims inside an identity item are protected from modification by an encapsulating signature. This signature is generated when the identity is issued, normally by using the private key of the issuing entity.

Claims used for identity issuing requests are the same as for Identity items, this since an IIR is used to issue an identity. For additional information about claims used for an IIR refer to [Claims](/claims) and the claims section under [Identity](/items/identity#claims).

### Signature

The final component in an identity issuing request item is always the signature. Apart for protecting the integrity of the contained components, the signature also proves the ownership and control of the private key used to generate it. This assumes careful generation, usage and storage of the private key by the requesting entity.

For additional details around the format of signature see [Signature encoding](/encoding/signature-encoding).


# Data

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

The data item specified in for DiME data format may be used to send arbitrary data to entities within the Application-based Public-Key Infrastructure.&#x20;

The following is an example of a DiME data item:

{% code overflow="wrap" %}

```
Di:DAT.eyJjdHgiOiJ0ZXN0LWNvbnRleHQiLCJleHAiOiIyMDIyLTEwLTIzVDEzOjQxOjU3LjcyOTIzMloiLCJpYXQiOiIyMDIyLTEwLTIzVDEzOjQwOjU3LjcyOTIzMloiLCJpc3MiOiJlZjRkNWJmMC1mOWVkLTQzZTktYmE3ZC0wMGNkNDEwYzJmMmMiLCJtaW0iOiJ0ZXh0L3BsYWluIiwidWlkIjoiMGE5NWM2YTUtYmQ3MC00NWZjLTk3ZmItZWQyNWMzODg5OGRlIn0.UmFjZWNhciBpcyByYWNlY2FyIGJhY2t3YXJkcy4
```

{% endcode %}

The header of a DiME data item is always 'DAT' as seen in the above example following the colon (':') after the envelope header ('Di').

### Components

A DiME data item consists of several components. Each component is separated by a dot (‘.’), which is referred to as a component separator.

The following components make up a data item:

* Header - always 'DAT'
* Claims - required
* Payload - required
* Signature - optional

#### Claims

Claims are information or data related to the data item, or its payload. These may include an issued at date, an expiration date and the MIME type of the payload data.

Example of a decoded claims component:

```json
{
    "ctx": "test-context",
    "exp": "2022-10-23T13:41:57.729232Z",
    "iat": "2022-10-23T13:40:57.729232Z",
    "iss": "ef4d5bf0-f9ed-43e9-ba7d-00cd410c2f2c",
    "mim": "text/plain",
    "uid": "0a95c6a5-bd70-45fc-97fb-ed25c38898de"
}
```

As any other DiME items, Data may use many different claims. For general information about claims refer to [Claims](#claims).

### MIME type

The MIME type ('mim') claim holds the type of data that has been attached to the DiME data item. This is an optional field, and its use when paring out the data is applicaiton-specific.

A MIME (Multipurpose Internet Mail Extensions) indicates the nature and format of the attached payload. MIME types are defined and standardized in [RFC 6838](https://datatracker.ietf.org/doc/html/rfc6838).

### Payload

The third component of a DiME data item is the data payload it carries. This may be any type of data, and its format and use is application-specific.

Before including the payload to attach will be Base64 encoded.

### Signature

A DiME data item may be signed to protect its integrity. For additional information about signatures refer to [Signature encoding](/encoding/signature-encoding).


# Message

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

Message items are used to protect the confidentiality and integrity of data that may sent between entities with an Application-based Public-Key Infrastructure.

Apart from the required integrity protection and optional end-to-end encryption, DiME message items are very similar to [Data](/items/data) items.

The follwoing is an example of a DiME data item:

{% code overflow="wrap" %}

```
Di:MSG.eyJhdWQiOiI1YWYyNTAyOC04NDE3LTRhM2MtODMwOC1mMzc3NmRkZWEzMzEiLCJjdHgiOiJ0ZXN0LWNvbnRleHQiLCJleHAiOiIyMDIyLTEwLTE5VDE5OjE1OjA1Ljk0NzE1MVoiLCJpYXQiOiIyMDIyLTEwLTE4VDE5OjE1OjA1Ljk0NzE1MVoiLCJpc3MiOiJmZGM2YTAzNC03ZDIyLTQwZjAtYWVhYy01NTE4MGUyMjRiMTQiLCJ1aWQiOiIzODhlMjRmMS03ZTczLTRjYzktYjdmZi04ZDQyZTJmY2I0NDUifQ.6yFXG/dTFgu/dqQme44TxkIAhHBtkM/DIgHjbk1b0lhhRtnRkE3UTsiipMomRcNdrvqqqtC4JSkrkGYDgojUwT22xjpw.MzFhMDYyN2JlZjk1NjNiZC4yOWMxZTVlYzk4NGQ0ZWUxZDM5YmFhZDFiYzJlOTBhNTIzOWQxMmIwY2IxOTE3YjM4NDBmOGViZmE5ZmM1YTlkZGM2N2U5NTBhYzg1NGI5MTJmMzEyNTQxMDM5Y2I0N2YxZWYzMGE2OTY0NTdjY2IyMWJiMjljNThmOWZlMTYwMw
```

{% endcode %}

The header of a DiME message item is always 'MSG' as seen in the above example following the colon (':') after the envelope header ('Di').

### Components

A DiME message item consists of several components. Each component is separated by a dot (‘.’), which is referred to as a component separator.

The following components make up a data item:

* Header - always 'MSG'
* Claims - required
* Payload - required
* Signature - required

#### Claims

Claims are information or data related to the data item, or its payload. These may include an issued at date, an expiration date and the MIME type of the payload data.

Example of a decoded claims component:

```json
{
    "aud": "5af25028-8417-4a3c-8308-f3776ddea331",
    "ctx": "hello-world",
    "exp": "2022-10-19T19:15:05.947151Z",
    "iat": "2022-10-18T19:15:05.947151Z",
    "iss": "fdc6a034-7d22-40f0-aeac-55180e224b14",
    "pub": "DSC.X4W/UvSL1GqTY+fAh3LFcDGK92zsP2oIYxAlXLmtjPk",
    "uid": "388e24f1-7e73-4cc9-b7ff-8d42e2fcb445"
}
```

Claims used for message items are the same as for data items. For additional information about claims used for a Message refer to [Claims](/claims) and the claims section under [Data](/items/data).

The public key stored in the "pub" claim, is always assumed to have the capability Exchange. For refering to other keys, for example with capability Encrypt, it is recommended to use the key ID claim ("kid"), which would contain the unique id to the key that should be used to decrypt the payload. Key ID may also be used to refer to an external public-key pair for a key exchange.

### **Payload**

As with data items, the third component of message items is the payload data. Unlike data items, message items allows for this data to be end-to-end encrypted.

End-to-end encryption is achieved by using two Key items with the capability 'exchange'. One key is received from the remote entity, and must only be the public version, where as the second key is generated by the sending entity.

The distribution of the keys may happen in many different ways. The public version may be included in the same DiME envelope as the message item, or the Key ID ('kid') claim may be used to refer to a previously distributed key. A third option is to use the Public key ('pub') field of the Message item.

### Signature

The final component in a message item is always the signature. Any message item that is missing a signature component must always be discarded. The message item must also be discarded if the signature verification fails.

For additional details around the format of signature see [Signature encoding](/encoding/signature-encoding).


# Tag

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

The DiME tag item is specifically used to linking external items for the use of proving different application-specific aspects. These aspects may be proof of verification or processing.

Since much of the time DiME envelopes and items are signed and thus protected from modification it is problematic to simply prove processing of those items. This is what the Tag item is used for.

An entity may create a Tag, add links to other items and sign the Tag item. Then it would be possible to add the Tag item to an unsigned envelope containing those other integrity protected items.

The following is an example of a DiME tag item:

{% code overflow="wrap" %}

```
Di:TAG.eyJpc3MiOiJlZjRkNWJmMC1mOWVkLTQzZTktYmE3ZC0wMGNkNDEwYzJmMmMiLCJsbmsiOiJNU0cuYTMxNmMyNjctZGI1MS00MjcxLTljYTQtNjgyNzAzMGM5ZGZhLjM5OTZlYTU5OTk5MGJlNjA2YTkwMGJlODE0ZDhhZjg4NjMyODUwMGU0ZWRhYTI3ZmQzODU2YjY3MjgzZDVhNTQ6S0VZLmEwOWMzM2Q5LWNiYTktNDBhNy04MTBmLTA2ZjkzYTFiYWEzYS4yZTJjMDNiMmJmYTI4ZGI2MzdmMTUxYjJlM2Q1ODVhYzE1ZDUzZDBkM2ZhYmNhMzBjODM1MzkzOWYwNTA0YjJlOklELmNmZDgxZWY5LTIxMTctNDRhMi1iMDFhLWQ1Mjk1MWRlYzdlMS4yN2I0OWRmNTE0NmZlMTA3YmVmZGU1N2ZmNjc4ODIwZGVjNzZhZDQyYTE3MThmYjU4MzgyM2UwNjEwMjc2OGYyIiwidWlkIjoiZTdjZTEwMDUtYTg5Ny00Y2IxLTk1NTctNTk4NjVjY2EwYWEwIn0.YjkyMjMwYzBkNTY0YjU0NS4yMGMxOGIzOTc5OTk3YWQ1ZWQ4MmEzMGY2MGQzN2FmY2UxNjFhMWRhNDc5OTcyZjRkY2E1MGQyMGE0NTg1OGZhNzg0YTU2NWZhOWRmODdlNjUwMDY2MDY3ZDg3YTUyNjIyMjBlMDM0YWFhYWYwZTQ4ODllNGU2ZjAwOWNlMTMwMA
```

{% endcode %}

The header of a DiME tag item is always 'TAG' as seen in the above example following the colon (':') after the envelope header ('Di').

### Components

A DiME tag item consists of several components. Each component is separated by a dot (‘.’), which is referred to as a component separator.

The following components make up a data item:

* Header - always 'TAG'
* Claims - required
* Signature - required

#### Claims

Claims are information or data related to the tag item. For tag items the linked items ('lnk') is specifically used, and required.

Example of a decoded claims component:

{% code overflow="wrap" %}

```json
{
    "iss": "ef4d5bf0-f9ed-43e9-ba7d-00cd410c2f2c",
    "lnk": "MSG.a316c267-db51-4271-9ca4-6827030c9dfa.3996ea599990be606a900be814d8af886328500e4edaa27fd3856b67283d5a54:KEY.a09c33d9-cba9-40a7-810f-06f93a1baa3a.2e2c03b2bfa28db637f151b2e3d585ac15d53d0d3fabca30c8353939f0504b2e:ID.cfd81ef9-2117-44a2-b01a-d52951dec7e1.27b49df5146fe107befde57ff678820dec76ad42a1718fb583823e06102768f2",
    "uid": "e7ce1005-a897-4cb1-9557-59865cca0aa0"
}
```

{% endcode %}

As any other DiME items, Tag may use many different claims. For general information about claims refer to [Claims](#claims).

### Linked items

The linked items ('lnk') claim is used to hold links to other DiME items. These links are used to direclty associate this item with those items, where it is later possible to verify the integrity. This makes it possible to prove the handling of those linked items.

For format and encoding information refer to [Item links](/cryptography/item-links).

### Signature

The final component in a tag item is always the signature. Any tag item that is missing a signature component must always be discarded. The tag item must also be discarded if the signature verification fails.

For additional details around the format of signature see [Signature encoding](/encoding/signature-encoding).


# General encoding

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

DiME items are generally encoded using Base64 and following this structure:

<figure><img src="https://1678507575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgRyVH9R66B2nn90QkQ%2Fuploads%2FZhrgxeRRcdn2DU19tqsu%2FBlank%20diagram.png?alt=media&amp;token=29f65ae4-5db4-4a36-bd21-692d3d3501a1" alt=""><figcaption><p>General DiME item structure and encoding</p></figcaption></figure>

Here the dots (‘.’) are used to separate each part of the DiME item. The position of each component is important:

* First component: the item header
* Second component: Base64 encoded JSON with item claims
* Last component: item signature package

It is possible to include any number of components, separated by additional dots (‘.’), between the second component and the last component. This is the case for several DiME items:

* Identity – include a trust chain as an additional component
* Message/data – include a Base64 encoded application-specific payload as an additional component

A DiME envelope follows a similar pattern, but uses colon (‘:’) to separate items and components:

<figure><img src="https://1678507575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgRyVH9R66B2nn90QkQ%2Fuploads%2F0oY2w7H5uzhqGj2Krd5w%2FEncoding%20-%20Envelope%20encoding.png?alt=media&amp;token=0db40753-77db-421d-bc77-f9dff967aaf9" alt=""><figcaption><p>Envelope structure and encoding</p></figcaption></figure>

The standard Base64 encoding is used, not URL safe.


# Key encoding

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

This section relates on how raw key data is encoded. The encoding of DiME key items is outlined in the previous chapter [General encoding](https://docs.dimeformat.io/encoding/general-encoding). As with the overall DiME item, Base64 is also used to encode raw key material.&#x20;

{% code overflow="wrap" %}

```json
"key": "DSC.7VN2b6f0nxqubSU955PuMenLtV6u9ltQr0ovUG0CL0Rfhb9S9IvUapNj58CHcsVwMYr3bOw/aghjECVcua2M+Q"
"pub": "DSC.X4W/UvSL1GqTY+fAh3LFcDGK92zsP2oIYxAlXLmtjPk"
```

{% endcode %}

The ‘key’ claim contains the secret key whereas the ‘pub’ claim contains the public key. The cryptographic suite used to generate the key is indicated by the initial header (‘DSC’). For more information about suites, see the chapter [Suites](/cryptography/profiles), which details out the use of cryptographic suites.


# Signature encoding

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

DiME supports multiple signatures for any item. This enables the use of many different types of public-key networks, from classic trust trees to Web-of-Trust models.

Any signed DiME item, including envelopes, has a signature attached at the end. For envelopes this is indicated by a final colon (‘:’) followed by a signature package, where other items include the signature package after the final dot (‘.’).

Here is an example of a DiME key item signed by three different keys:

{% code overflow="wrap" %}

```
Di:KEY.eyJjYXAiOlsiZW5jcnlwdCJdLCJpYXQiOiIyMDIyLTEwLTIyVDEyOjA2OjI0LjI5NTU0M1oiLCJrZXkiOiJTVE4uR3lGSjNpMmNicWRwUXpMRTRIOFJ0NWFZZG1LdUt1QXBNa3Jyd3lYaUJDaDQ3RTZuSCIsInVpZCI6IjM0NzRiY2RhLWQxYjItNGQ5OS04YjU4LWI2MzkxNjI0NmE2ZCJ9.MDFiODQxNmIzMjk0NmJmYi44YmFiOWRkYmJiNmU1Y2NlYTViYjI3MWVlMDY5NmY2YTFhODM5ZWQzOWY5YWNjZjZkZGY1YjZiMWFjNGJlZGNkYjNiMWNiYzY0OTY5NWFjMzM2YTg3Njg2ZTBjNmZhOTViZWI1NzA4ZmVkNDE1MDFiYjE1ZTRjNWI1MTZhNGIwYTo4MTk2YWQ2NmE0ODQwMmFiLmE3ZmI1OTAxMzRiMzVjNGQ5ZjM5OWIwYzRkNzJjNmFhZDA5YmExYjAwOWYwMWVkMTgzMmJlNWIwZTc1ZjNiMzVlYzYzN2JlZGRhMGFlMmUwMjZmMGYxNzVlMmRiYWI3OGQ4OGE5MDFlNThjZGFjYmI0ZDM4ZjU1ZDQzYzIzZTA4OjI2NzA1N2ZkOTdlMjAzZjYuMDQ1MTczYzQ0ODQ1MzcwMTczNGE0NWFjNmI2YzNkZTU3MzNhOGYwMzVhMjg1ZmY5YTYxNzc4N2ZkNWJiYTM4NzM2OTljZDlmMjk5OTU2NzJjYzA3NjA5MDIzY2ZiMGM5ZDg2OTE5ZmM2MGEwZGY5ZTNmYjU2YzRjZTU3OTlhMDI
```

{% endcode %}

Copy pasting the Base64 encoded string following the final dot (‘.’) gives:

{% code overflow="wrap" %}

```
MDFiODQxNmIzMjk0NmJmYi44YmFiOWRkYmJiNmU1Y2NlYTViYjI3MWVlMDY5NmY2YTFhODM5ZWQzOWY5YWNjZjZkZGY1YjZiMWFjNGJlZGNkYjNiMWNiYzY0OTY5NWFjMzM2YTg3Njg2ZTBjNmZhOTViZWI1NzA4ZmVkNDE1MDFiYjE1ZTRjNWI1MTZhNGIwYTo4MTk2YWQ2NmE0ODQwMmFiLmE3ZmI1OTAxMzRiMzVjNGQ5ZjM5OWIwYzRkNzJjNmFhZDA5YmExYjAwOWYwMWVkMTgzMmJlNWIwZTc1ZjNiMzVlYzYzN2JlZGRhMGFlMmUwMjZmMGYxNzVlMmRiYWI3OGQ4OGE5MDFlNThjZGFjYmI0ZDM4ZjU1ZDQzYzIzZTA4OjI2NzA1N2ZkOTdlMjAzZjYuMDQ1MTczYzQ0ODQ1MzcwMTczNGE0NWFjNmI2YzNkZTU3MzNhOGYwMzVhMjg1ZmY5YTYxNzc4N2ZkNWJiYTM4NzM2OTljZDlmMjk5OTU2NzJjYzA3NjA5MDIzY2ZiMGM5ZDg2OTE5ZmM2MGEwZGY5ZTNmYjU2YzRjZTU3OTlhMDI
```

{% endcode %}

By Base64 decoding this string gives the actual signatures, each HEXADECIMAL encoded and separated by a colon (‘:’):

{% code overflow="wrap" %}

```
01b8416b32946bfb.8bab9ddbbb6e5ccea5bb271ee0696f6a1a839ed39f9accf6ddf5b6b1ac4bedcdb3b1cbc649695ac336a87686e0c6fa95beb5708fed41501bb15e4c5b516a4b0a:8196ad66a48402ab.a7fb590134b35c4d9f399b0c4d72c6aad09ba1b009f01ed1832be5b0e75f3b35ec637bedda0ae2e026f0f175e2dbab78d88a901e58cdacbb4d38f55d43c23e08:267057fd97e203f6.045173c448453701734a45ac6b6c3de5733a8f035a285ff9a617787fd5bba3873699cd9f29995672cc07609023cfb0c9d86919fc60a0df9e3fb56c4ce5799a02
```

{% endcode %}

The basic components of a signature, separated by a dot (‘.’) are:

* Key name – an identifier for the public key that may be used to verify the signature
* Signature – a digital signature encoded using HEXADECIMAL

The key name is generated by the cryptographic suite associated with the key and may thus have different lengths and formats.

Including the name of the key makes it easier to find the key needed to verify the signature and avoids unnecessary verification with keys that does not match the name.

### Signature scope

The signature scope defines the set of data that is integrity protected by a digital signature. This scope is different depending if the signature if for an envelope or an individual item. For envelopes the scope is for all items that are attached to it, and for items the scope is only for its own data.

All signatures that may be attached to an item or envelope are always excluded from the scope.

<figure><img src="https://1678507575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgRyVH9R66B2nn90QkQ%2Fuploads%2FVtbROPiYcxlG0SqqU71V%2FEncoding%20-%20Verification%20scope%20-%20item.png?alt=media&amp;token=2c90b400-2307-426a-a9c8-133b884f599a" alt=""><figcaption><p>Signature verification scope of a DiME item</p></figcaption></figure>

Note that the character separating the item and the signature(s) is not included in the generation and verification of signatures. For envelopes this refers to the final colon (‘:’) and for other items to the final dot (‘.’).

<figure><img src="https://1678507575-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MgRyVH9R66B2nn90QkQ%2Fuploads%2F67lNtxogfrbKkkRiuBNe%2FEncoding%20-%20Verification%20scope%20-%20envelope.png?alt=media&amp;token=c57bfcd9-37ff-4f14-8697-928ba3e13519" alt=""><figcaption><p>Signature verification scope of a DiME envelope</p></figcaption></figure>

The signature scope is then hashed, creating a thumbprint of the item, which is then used to generate the signature.&#x20;

This means that in most cases envelopes and items do not need to be decoded for generation and verification of signatures. An exception to this may be when a public key, or key identifier, needs to be reteived from the item iself before verifying a signature.


# Thumbprints

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

A thumbprint, also known as a fingerprint or simply a hash, is a secure hash digests of a DiME item or envelope. These are generated by using a secure hash algorithm on the DiME encoded string of an envelope or item.

Thumbprints makes it possible to generate and store a thumbprint of an item, and then re-generate the thumbprint later to understand if an item is the same or if it has changed, all without the need for additional decoding or, depending on the thumbprint scope, signature verification.

Thumbprints are never not stored within a DiME envelope or item, as they should be re-generated when needed. An exception to this is when using [item links](/cryptography/item-links).

By using the following DiME item:

{% code overflow="wrap" %}

```
Di:KEY.eyJjYXAiOlsiZW5jcnlwdCJdLCJpYXQiOiIyMDIyLTEwLTIyVDEyOjI4OjA1LjA0MTI4NVoiLCJrZXkiOiJTVE4uQm1XRnFVVGRZcE1uNVRESkc2NEd5dDVMcm9XTnV0WnNHMmE4RFBIVFk4WGRleU5aayIsInVpZCI6IjZiOGY5NTM2LTljOGUtNDA2NC05NTdhLTM1MjJmNmMzYTkzZiJ9
```

{% endcode %}

… the following thumbprint is generated:

```
f31eecac1bf624d811e3bd09e3da87814b159fbc2b22eaeaf20e50919b373779
```

The above example is using the DiME standard cryptographic suite when generating the thumbprint and it then encoded as HEXADECIMAL.


# Item links

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

In many application usages it may be necessary to refer to previously send messages or other items. An example of this is when requesting data collection where it must be possible from the response trace back to the original request. Another example may be chat messages or sign-offs to sensitive operations.

DiME support cryptographic linking between items. This allows items to be linked together and those links can later be verified to be intact.

The claim field ‘lnk’ is used to hold item links, and may look like this:

{% code overflow="wrap" %}

```json
"lnk": "KEY.c0eb7bed-591e-4021-970d-e881147fa48d.7df0f3f6122413e83beb5347408d909151d5f956fe973a08357ceaf1c0b83b19:MSG.de9cc81d-32cb-4f6b-b90e-db87e003114a.f281b30d6179b94e6182746d0f31c755d8ddc035a1ac740c55283c78ed3282a1"
```

{% endcode %}

In the above example, two items have been linked, one key and one message. An item link consists of the following components, separated by a dot (‘.’):

* Item type – the header used for specific DiME item
* Unique identifier – the unique identifier of the item, as an UUID
* Item thumbprint – a secure hash of the item being linked

Several items may be linked to one item, each item link is separated by a colon (‘:’). Note that to protect the integrity of item links the carrying item needs to be signed.

[The DiME tag item](https://docs.dimeformat.io/items/tag) is closely related to item links, providing a way to separately link items to prove verification, processing or other operations.


# Suites

DiME, the open and trust-based data format building secure Application-based Public-Key Infrastructures (APKIs) in a breeze.

A foundation principle of the DiME design is minimizing options and decisions, and this is equally relevant for the choice of algorithms to use. DiME uses pre-defined cryptographic suits with the intention to remove much of need of detailed understanding and expert knowledge with cryptography.

Currently only one suite has been defined, the "salt" suite (NaCl), based on the popular [Networking and Cryptography library](https://nacl.cr.yp.to/).

<table><thead><tr><th width="254">Usage</th><th width="272">Algorithm</th></tr></thead><tbody><tr><td>Digital signature</td><td><a href="https://en.wikipedia.org/wiki/EdDSA#Ed25519">Ed25519</a> (<a href="https://en.wikipedia.org/wiki/EdDSA">EdDSA</a>)</td></tr><tr><td>Key agreement (exchange)</td><td><a href="https://en.wikipedia.org/wiki/Curve25519">X25519</a> (<a href="https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman">ECDH</a>)</td></tr><tr><td>Secret key encryption</td><td><a href="https://en.wikipedia.org/wiki/ChaCha20-Poly1305#Salsa20-Poly1305_and_XSalsa20-Poly1305">XSalsa20-Poly1305</a> (<a href="https://en.wikipedia.org/wiki/Authenticated_encryption">AE</a>)</td></tr><tr><td>Hash function</td><td><a href="https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2">BLAKE2</a></td></tr></tbody></table>

The suggested implementation of this cryptography suite is the tried and tested [libsodium library](https://doc.libsodium.org/) which has numerous bindings to diffrent languages and plaforms..

Although the DiME format itself does not solve the need to understand and properly use these algorithms, the idea is that the available reference implementation will remove this need.

The use of a specific suite is closely associated with the raw data of keys. Here is an example of an encryption key:

```
NaCl.eDYvQUipW45guJvDoc13iFQkMwNZUJcBaqJWN7JguG5DVfQED
```

As the header of DiME items, the raw key data starts with a header indicating the cryptographic suite used, in this case ‘NaCl’. The header ‘NaCl’ is used for the DiME standard cryptographic suite.


