Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the DID DHT API #76

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
9 changes: 0 additions & 9 deletions impl/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ import (

var commitHash string

// main godoc
//
// @title The DID DHT Service
// @description The DID DHT Service
// @contact.name TBD
// @contact.url https://github.com/TBD54566975/did-dht-method
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
func main() {
logrus.Info("Starting up...")

Expand Down
323 changes: 323 additions & 0 deletions impl/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,196 @@
definitions:
did.Document:
properties:
'@context': {}
alsoKnownAs:
type: string
assertionMethod:
items: {}
type: array
authentication:
items: {}
type: array
capabilityDelegation:
items: {}
type: array
capabilityInvocation:
items: {}
type: array
controller:
type: string
id:
description: |-
As per https://www.w3.org/TR/did-core/#did-subject intermediate representations of DID Documents do not
require an ID property. The provided test vectors demonstrate IRs. As such, the property is optional.
type: string
keyAgreement:
items: {}
type: array
service:
items:
$ref: '#/definitions/did.Service'
type: array
verificationMethod:
items:
$ref: '#/definitions/github_com_TBD54566975_ssi-sdk_did.VerificationMethod'
type: array
type: object
did.Service:
properties:
accept:
items:
type: string
type: array
id:
type: string
routingKeys:
items:
type: string
type: array
serviceEndpoint:
description: |-
A string, map, or set composed of one or more strings and/or maps
All string values must be valid URIs
type:
type: string
required:
- id
- serviceEndpoint
- type
type: object
github_com_TBD54566975_did-dht-method_internal_did.TypeIndex:
enum:
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
type: integer
x-enum-varnames:
- Discoverable
- Organization
- GovernmentOrganization
- Corporation
- LocalBusiness
- SoftwarePackage
- WebApplication
- FinancialInstitution
github_com_TBD54566975_did-dht-method_pkg_service.TypeMapping:
properties:
type:
type: string
type_index:
$ref: '#/definitions/github_com_TBD54566975_did-dht-method_internal_did.TypeIndex'
required:
- type
- type_index
type: object
github_com_TBD54566975_ssi-sdk_did.VerificationMethod:
properties:
blockchainAccountId:
description: for PKH DIDs - https://github.com/w3c-ccg/did-pkh/blob/90b28ad3c18d63822a8aab3c752302aa64fc9382/did-pkh-method-draft.md
type: string
controller:
type: string
id:
type: string
publicKeyBase58:
type: string
publicKeyJwk:
allOf:
- $ref: '#/definitions/jwx.PublicKeyJWK'
description: must conform to https://datatracker.ietf.org/doc/html/rfc7517
publicKeyMultibase:
description: https://datatracker.ietf.org/doc/html/draft-multiformats-multibase-03
type: string
type:
type: string
required:
- controller
- id
- type
type: object
jwx.PublicKeyJWK:
properties:
alg:
type: string
crv:
type: string
e:
type: string
key_ops:
type: string
kid:
type: string
kty:
type: string
"n":
type: string
use:
type: string
x:
type: string
"y":
type: string
required:
- kty
type: object
pkg_server.GetDIDResponse:
properties:
did:
$ref: '#/definitions/did.Document'
sequence_numbers:
items:
type: integer
type: array
types:
items:
$ref: '#/definitions/github_com_TBD54566975_did-dht-method_internal_did.TypeIndex'
type: array
required:
- did
type: object
pkg_server.GetDIDsForTypeResponse:
properties:
dids:
items:
type: string
type: array
type: object
pkg_server.GetHealthCheckResponse:
properties:
status:
description: Status is always equal to `OK`.
type: string
type: object
pkg_server.GetTypesResponse:
properties:
types:
items:
$ref: '#/definitions/github_com_TBD54566975_did-dht-method_pkg_service.TypeMapping'
type: array
type: object
pkg_server.PublishDIDRequest:
properties:
retention_proof:
type: string
seq:
type: integer
sig:
type: string
v:
type: string
required:
- seq
- sig
- v
type: object
externalDocs:
description: OpenAPI
url: https://swagger.io/resources/open-api/
info:
contact:
email: [email protected]
Expand All @@ -15,6 +201,7 @@ info:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
title: The DID DHT Service
version: "0.1"
paths:
/{id}:
get:
Expand Down Expand Up @@ -83,6 +270,142 @@ paths:
summary: PutRecord a Pkarr record into the DHT
tags:
- Pkarr
/dids/{id}:
get:
consumes:
- application/json
description: Get a DID document
parameters:
- description: ID of the record to get
in: path
name: id
required: true
type: string
responses:
"200":
description: OK
schema:
$ref: '#/definitions/pkg_server.GetDIDResponse'
"400":
description: Invalid request
schema:
type: string
"404":
description: DID not found
schema:
type: string
"500":
description: Internal server error
schema:
type: string
"501":
description: Historical resolution not supported by this gateway
schema:
type: string
summary: Get a DID document
tags:
- DID
put:
consumes:
- application/json
description: Publish a DID document to the DHT
parameters:
- description: ID of the record to get
in: path
name: id
required: true
type: string
responses:
"202":
description: Accepted
schema:
$ref: '#/definitions/pkg_server.PublishDIDRequest'
"400":
description: Invalid request body
schema:
type: string
"401":
description: Invalid signature
schema:
type: string
"409":
description: DID already exists with a higher sequence number
schema:
type: string
"500":
description: Internal server error
schema:
type: string
summary: Publish a DID document
tags:
- DID
/dids/types:
get:
consumes:
- application/json
description: Get a list of supported types
responses:
"200":
description: OK
schema:
$ref: '#/definitions/pkg_server.GetTypesResponse'
"501":
description: Type indexing is not supported by this gateway
schema:
type: string
summary: Get a list of supported types
tags:
- DID
/dids/types/{id}:
get:
consumes:
- application/json
description: Get a list of DIDs for a given type
responses:
"200":
description: OK
schema:
$ref: '#/definitions/pkg_server.GetDIDsForTypeResponse'
"400":
description: Invalid request
schema:
type: string
"404":
description: Type not found
schema:
type: string
"500":
description: Internal server error
schema:
type: string
"501":
description: Type indexing is not supported by this gateway
schema:
type: string
summary: Get a list of DIDs for a given type
tags:
- DID
/difficulty:
get:
consumes:
- application/json
description: Get the current difficulty for the gateway's retention proof feature
responses:
"200":
description: OK
schema:
type: integer
"500":
description: Internal server error
schema:
type: string
"501":
description: Retention proofs are not supported by this gateway
schema:
type: string
summary: Get the current difficulty for the gateway's retention proof feature
tags:
- DID
/health:
get:
consumes:
Expand Down
1 change: 1 addition & 0 deletions impl/internal/did/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
DHTMethod did.Method = "dht"
JSONWebKeyType cryptosuite.LDKeyType = "JsonWebKey"

Discoverable TypeIndex = 0
Organization TypeIndex = 1
GovernmentOrganization TypeIndex = 2
Corporation TypeIndex = 3
Expand Down
19 changes: 19 additions & 0 deletions impl/internal/util/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package util

type InvalidSignatureError struct{}

func (e *InvalidSignatureError) Error() string {
return "invalid signature"
}

type HigherSequenceNumberError struct{}

func (e *HigherSequenceNumberError) Error() string {
return "DID already exists with a higher sequence number"
}

type TypeNotFoundError struct{}

func (e *TypeNotFoundError) Error() string {
return "type not found"
}
Loading
Loading