Skip to content

Commit

Permalink
Update DIDKit HTTP README (#359)
Browse files Browse the repository at this point in the history
Close #358
  • Loading branch information
sbihel committed Jun 14, 2023
1 parent 998f295 commit 73f5f05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 70 deletions.
82 changes: 12 additions & 70 deletions http/README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,22 @@
# DIDKit HTTP

DIDKit exposes its functionality as an HTTP server.
Implementation of the [Verifiable Credentials API](https://w3c-ccg.github.io/vc-api/)
using DIDKit.

## Build
## Usage

```sh
$ cargo build
```
The Docker image is available at
https://github.com/spruceid/didkit/pkgs/container/didkit-http.

## Install
```sh
$ cargo install --path .
```
### Configuration

## CLI
Refer to the [defaults configuration file](./defaults.toml).

### `didkit-http`

Run a DIDKit HTTP server. The command outputs the URL it is listening on,
and runs until interrupted.

#### Options

- `-s, --host <host>` - Hostname to listen on. Default is `127.0.0.1`.
- `-p, --port <port>` - Port to listen on. Default is a random OS-chosen port.
- `-k, --key <key>` - Filename of a JWK to use for issuing credentials and
presentations.
- `-j, --jwk <jwk>` - JWK to use for issuing credentials and presentations.
- `-r, --did-resolver <url>` - [DID resolver HTTP(S) endpoint][did-resolution-https-binding] URL to use for resolving DIDs and dereferencing DID URLs that the built-in resolver does not support. Equivalent to environmental variable `DID_RESOLVER`.

#### Issuer keys

Provide issuer keys using the `-k`/`--key-path` or `-j`/`--jwk` options. If none are provided, issuance functionality will be unavailable. If one is provided, that one will be used to sign all credentials and presentations, regardless of the proof options in the issuance request. If more than one key is provided, the issuance request may identify which key to use for signing by its DID in the `verificationMethod` property of the proof options; if none is identified in that property, the first key is used.

## Rust library

Rust crate `didkit-http` contains DIDKit's HTTP server implementation as a Rust
library. Struct `didkit_http::DIDKitHTTPMakeSvc` implements a Tower
([hyper](https://hyper.rs/))
[Service](https://docs.rs/tower-service/0.3.0/tower_service/trait.Service.html).

## API

### Verifiable Credentials and Verifiable Presentations

The following routes implement [W3C CCG's VC (HTTP) API (vc-http-api)][vc-api] [v0.0.1][vc-http-api-0.0.1]. POST bodies should be `application/json`. Output will be `application/json` on success; on error it will be either `application/json` or plain text. For more details, see [vc-api][].

#### Limits

#### Maximum payload size

DIDKit HTTP's POST endpoints implement a request payload maximum size of 2MB, to protect against resource exhaustion due to excessively large payloads. This limit is in a constant, `MAX_BODY_LENGTH`, but in the future might be made configurable: https://github.com/spruceid/didkit/issues/236.

#### POST `/credentials/issue`

Issue a verifiable credential. The server uses its configured key and the given linked data proof options to generate a proof and append it to the given credential. On success, the resulting verifiable credential is returned, with HTTP status 201.

#### POST `/credentials/verify`

Verify a verifiable credential. The server verifies the given credential with the given linked data proof options. To successfully verify, the credential must contain at least one proof that verifies successfully. Verification results include a list of checks performed, warnings that should be flagged to the user, and errors encountered. On success, the errors list will be empty, and the HTTP status code will be 200.

#### POST `/presentations/prove`

Create a verifiable presentation. Given a presentation and linked data proof options, the server uses its key to generate a proof and append it to the presentation. On success, returns the verifiable presentation and HTTP status 201.

#### POST `/presentations/verify`

Verify a verifiable presentation using the given proof options. Returns a verification result. HTTP status 200 indicates successful verification.

### DIDs (Decentralized Identifiers)

The following route implements the [DID Resolution HTTP(S) Binding][did-http].

#### GET `/identifiers/<uri>`

Resolve a DID to a DID document, or dereference a DID URL to a resource. Parameter `<uri>` is the DID or DID URL to resolve/dereference.
To provide overrides you can either:
- use a configuration file named `didkit-http.toml` which follows the structure
as the defaults files; or
- use environment variables, which are prefixed with `DIDKIT_HTTP_` and follow
the same names, with a separating `_` between sections.

## Security Considerations

Expand Down
4 changes: 4 additions & 0 deletions http/defaults.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[default.http]
# DIDKIT_HTTP_PORT
port = 3000
# DIDKIT_HTTP_ADDRESS
address = [127, 0, 0, 1]
# DIDKIT_HTTP_BODYSIZELIMIT
bodysizelimit = 2097152 # 2MiB

[default.issuer]
# DIDKIT_ISSUER_KEYS = '[<JWK>, <JWK>]'

0 comments on commit 73f5f05

Please sign in to comment.