diff --git a/interfaces.go b/interfaces.go index 8af60fc..65c5356 100644 --- a/interfaces.go +++ b/interfaces.go @@ -7,21 +7,23 @@ import ( // DID is a decoded (i.e. from a string) Decentralized Identifier. type DID interface { + // Method returns the name of the DID method (e.g. "key" for did:key). Method() string - // TODO: below might be only for DID URLs, is it relevant here? - Path() string - Query() url.Values - Fragment() string - + // Document resolves the DID into a DID Document usable for e.g. signature check. + // This can be simply expanding the DID into a Document, or involve external resolution. Document() (Document, error) - String() string // return the full DID URL, with path, query, fragment - // ResolutionIsExpensive returns true if resolving to a Document is an expensive operation, e.g. requiring - // an external HTTP request. By contrast, a self-contained DID (e.g. did:key) can be resolved cheaply without - // an external call. This can be an indication whether to cache the resolved state. + // String returns the string representation of the DID. + String() string + + // ResolutionIsExpensive returns true if resolving to a Document is an expensive operation, + // e.g. requiring an external HTTP request. By contrast, a self-contained DID (e.g. did:key) + // can be resolved cheaply without an external call. + // This can be an indication whether to cache the resolved state. ResolutionIsExpensive() bool + // Equal returns true if this and the given DID are the same. Equal(DID) bool } @@ -29,6 +31,9 @@ type DID interface { type Document interface { json.Marshaler + // Context is the set of JSON-LD context documents. + Context() []string + // ID is the identifier of the Document, which is the DID itself. ID() DID @@ -36,7 +41,7 @@ type Document interface { Controllers() []DID // AlsoKnownAs returns an optional set of URL describing ???TODO - AlsoKnownAs() []url.URL + AlsoKnownAs() []*url.URL // VerificationMethods returns all the VerificationMethod known in the document. VerificationMethods() map[string]VerificationMethod diff --git a/methods/did-key/document.go b/methods/did-key/document.go index b86b6e4..7984a6e 100644 --- a/methods/did-key/document.go +++ b/methods/did-key/document.go @@ -32,11 +32,7 @@ func (d document) MarshalJSON() ([]byte, error) { CapabilityInvocation []string `json:"capabilityInvocation,omitempty"` CapabilityDelegation []string `json:"capabilityDelegation,omitempty"` }{ - Context: stringSet( - did.JsonLdContext, - d.signature.JsonLdContext(), - d.keyAgreement.JsonLdContext(), - ), + Context: d.Context(), ID: d.id.String(), AlsoKnownAs: nil, VerificationMethod: []did.VerificationMethod{d.signature}, @@ -48,6 +44,14 @@ func (d document) MarshalJSON() ([]byte, error) { }) } +func (d document) Context() []string { + return stringSet( + did.JsonLdContext, + d.signature.JsonLdContext(), + d.keyAgreement.JsonLdContext(), + ) +} + func (d document) ID() did.DID { return d.id } @@ -57,7 +61,7 @@ func (d document) Controllers() []did.DID { return nil } -func (d document) AlsoKnownAs() []url.URL { +func (d document) AlsoKnownAs() []*url.URL { return nil } diff --git a/methods/did-key/key.go b/methods/did-key/key.go index ddf5744..37db891 100644 --- a/methods/did-key/key.go +++ b/methods/did-key/key.go @@ -3,7 +3,6 @@ package didkey import ( "crypto" "fmt" - "net/url" "strings" mbase "github.com/multiformats/go-multibase" @@ -104,18 +103,6 @@ func (d DidKey) Method() string { return "key" } -func (d DidKey) Path() string { - return "" -} - -func (d DidKey) Query() url.Values { - return nil -} - -func (d DidKey) Fragment() string { - return "" -} - func (d DidKey) Document() (did.Document, error) { return document{ id: d,