Merge pull request #2 from INFURA/interface-cleanup

cleanup the main interfaces, document
This commit is contained in:
Michael Muré
2025-05-08 15:21:42 +09:00
committed by GitHub
3 changed files with 25 additions and 29 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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,