Documentation
¶
Index ¶
- Constants
- func AlgorandAddressToEd25519(address string) (ed25519.PublicKey, error)
- func AlgorandAddressToMultibase(address string) (string, error)
- func DefaultContexts() []string
- func Ed25519ToMultibase(pubkey ed25519.PublicKey) string
- func Ed25519ToX25519(pubkey ed25519.PublicKey) ([]byte, error)
- func ParseDID(did string) (string, error)
- func X25519ToMultibase(pubkey []byte) string
- type ContentMetadata
- type DIDDocument
- type DIDURL
- type DereferencingMetadata
- type DereferencingResult
- type DocumentMetadata
- type NFDProfileEndpoint
- type NfdDIDResolver
- type ResolutionMetadata
- type ResolutionResult
- type Service
- type VerificationMethod
Constants ¶
const ( ContextDIDv1 = "https://www.w3.org/ns/did/v1" ContextEd25519 = "https://w3id.org/security/suites/ed25519-2020/v1" ContextX25519 = "https://w3id.org/security/suites/x25519-2020/v1" MethodPrefix = "did:nfd:" KeyTypeEd25519 = "Ed25519VerificationKey2020" KeyTypeX25519 = "X25519KeyAgreementKey2020" FragmentOwner = "#owner" )
DID JSON-LD Contexts
const ( ContentTypeDIDJSON = "application/did+json" ContentTypeDIDLDJSON = "application/did+ld+json" ContentTypeURIList = "text/uri-list" )
Content types for DID resolution.
const ( ErrorNotFound = "notFound" ErrorInvalidDID = "invalidDid" ErrorInvalidDIDURL = "invalidDidUrl" ErrorDeactivated = "deactivated" ErrorInternalError = "internalError" )
Standard DID resolution error codes per W3C spec.
Variables ¶
This section is empty.
Functions ¶
func AlgorandAddressToEd25519 ¶
AlgorandAddressToEd25519 decodes an Algorand address (58-char base32) to a raw 32-byte Ed25519 public key. Algorand addresses are: base32(pubkey[32] + checksum[4])
func AlgorandAddressToMultibase ¶
AlgorandAddressToMultibase converts an Algorand address directly to a multibase-encoded Ed25519 public key.
func DefaultContexts ¶
func DefaultContexts() []string
DefaultContexts returns the standard JSON-LD contexts for a did:nfd document.
func Ed25519ToMultibase ¶
Ed25519ToMultibase encodes a raw Ed25519 public key as a multibase (base58btc, 'z' prefix) string with the Ed25519 multicodec prefix (0xed, 0x01).
func Ed25519ToX25519 ¶
Ed25519ToX25519 converts an Ed25519 public key to an X25519 public key for key agreement. This uses the birational equivalence between Ed25519 and Curve25519.
func ParseDID ¶
ParseDID validates and extracts the NFD name from a did:nfd string (exported for testing).
func X25519ToMultibase ¶
X25519ToMultibase encodes a raw X25519 public key as a multibase (base58btc, 'z' prefix) string.
Types ¶
type ContentMetadata ¶
type ContentMetadata struct{}
ContentMetadata contains metadata about the dereferenced content.
type DIDDocument ¶
type DIDDocument struct {
Context []string `json:"@context"`
ID string `json:"id"`
Controller string `json:"controller,omitempty"`
VerificationMethod []VerificationMethod `json:"verificationMethod,omitempty"`
Authentication []string `json:"authentication,omitempty"`
AssertionMethod []string `json:"assertionMethod,omitempty"`
KeyAgreement []VerificationMethod `json:"keyAgreement,omitempty"`
Service []Service `json:"service,omitempty"`
AlsoKnownAs []string `json:"alsoKnownAs,omitempty"`
}
DIDDocument represents a W3C DID Core 1.0 Document. See: https://www.w3.org/TR/did-core/
type DIDURL ¶
type DIDURL struct {
DID string // The base DID (e.g., "did:nfd:name.algo")
Fragment string // Fragment without '#' (e.g., "owner"), empty if none
Params map[string]string // Query parameters (e.g., {"service": "web"})
}
DIDURL represents a parsed DID URL with optional fragment and query parameters.
func ParseDIDURL ¶
ParseDIDURL parses a DID URL string into its components: base DID, fragment, and query parameters.
type DereferencingMetadata ¶
type DereferencingMetadata struct {
ContentType string `json:"contentType"`
Error string `json:"error,omitempty"`
}
DereferencingMetadata contains metadata about the dereferencing process.
type DereferencingResult ¶
type DereferencingResult struct {
DereferencingMetadata DereferencingMetadata `json:"dereferencingMetadata"`
ContentStream any `json:"contentStream"`
ContentMetadata ContentMetadata `json:"contentMetadata"`
}
DereferencingResult contains the full DID URL dereferencing output per W3C DID Resolution spec.
func DereferencingErrorResult ¶
func DereferencingErrorResult(errorCode string, contentType string) *DereferencingResult
DereferencingErrorResult returns a DereferencingResult containing only an error.
type DocumentMetadata ¶
type DocumentMetadata struct {
Created string `json:"created,omitempty"`
Updated string `json:"updated,omitempty"`
Deactivated bool `json:"deactivated"`
VersionID string `json:"versionId,omitempty"`
NFDAppID uint64 `json:"nfdAppId,omitempty"`
}
DocumentMetadata contains metadata about the DID document.
type NFDProfileEndpoint ¶
type NFDProfileEndpoint struct {
Name string `json:"name,omitempty"`
Bio string `json:"bio,omitempty"`
Avatar string `json:"avatar,omitempty"`
Banner string `json:"banner,omitempty"`
}
NFDProfileEndpoint represents the structured endpoint for an NFDProfile service.
type NfdDIDResolver ¶
type NfdDIDResolver interface {
Resolve(ctx context.Context, did string) (*ResolutionResult, error)
Dereference(ctx context.Context, didURL string, contentType string) (*DereferencingResult, error)
}
NfdDIDResolver resolves did:nfd identifiers to DID Documents and dereferences DID URLs.
func NewNfdDIDResolver ¶
func NewNfdDIDResolver(client *algod.Client, registryID uint64, cacheTTL time.Duration) NfdDIDResolver
NewNfdDIDResolver creates a new DID resolver backed by an Algorand algod client.
func NewNfdDIDResolverWithFetcher ¶
func NewNfdDIDResolverWithFetcher(fetcher nfd.NfdFetcher, cacheTTL time.Duration) NfdDIDResolver
NewNfdDIDResolverWithFetcher creates a resolver with a custom fetcher (useful for testing).
type ResolutionMetadata ¶
type ResolutionMetadata struct {
ContentType string `json:"contentType"`
Retrieved string `json:"retrieved,omitempty"`
Duration int64 `json:"duration,omitempty"` // milliseconds
Error string `json:"error,omitempty"`
}
ResolutionMetadata contains metadata about the resolution process itself.
func NewResolutionMetadata ¶
func NewResolutionMetadata(contentType string) ResolutionMetadata
NewResolutionMetadata creates metadata with the current timestamp.
type ResolutionResult ¶
type ResolutionResult struct {
DIDDocument *DIDDocument `json:"didDocument"`
ResolutionMetadata ResolutionMetadata `json:"didResolutionMetadata"`
DocumentMetadata DocumentMetadata `json:"didDocumentMetadata"`
}
ResolutionResult contains the full DID resolution output per W3C DID Resolution spec.
func ErrorResult ¶
func ErrorResult(errorCode string, contentType string) *ResolutionResult
ErrorResult returns a ResolutionResult containing only an error.
type Service ¶
type Service struct {
ID string `json:"id"`
Type string `json:"type"`
ServiceEndpoint any `json:"serviceEndpoint"`
}
Service represents a service endpoint associated with a DID subject.
type VerificationMethod ¶
type VerificationMethod struct {
ID string `json:"id"`
Type string `json:"type"`
Controller string `json:"controller"`
PublicKeyMultibase string `json:"publicKeyMultibase"`
BlockchainAccountId string `json:"blockchainAccountId,omitempty"`
}
VerificationMethod represents a cryptographic public key associated with a DID subject.