UNPKG

did-resolver

Version:
257 lines • 8.7 kB
/** * Defines an object type that can be extended with other properties. */ export type Extensible = Record<string, any>; /** * Defines a JSON-LD context entry. */ export type ContextEntry = (string & {}) | Extensible; /** * Defines the result of a DID resolution operation. * * @see {@link Resolvable.resolve} * @see {@link https://www.w3.org/TR/did-core/#did-resolution} */ export interface DIDResolutionResult { '@context'?: 'https://w3id.org/did-resolution/v1' | ContextEntry | ContextEntry[]; didResolutionMetadata: DIDResolutionMetadata; didDocument: DIDDocument | null; didDocumentMetadata: DIDDocumentMetadata; } /** * Describes the options forwarded to the resolver when executing a {@link Resolvable.resolve} operation. * * @see {@link https://www.w3.org/TR/did-core/#did-resolution-options} */ export interface DIDResolutionOptions extends Extensible { accept?: string; cache?: boolean; } /** * Encapsulates the resolution metadata resulting from a {@link Resolvable.resolve} operation. * * @see {@link https://www.w3.org/TR/did-core/#did-resolution-metadata} */ export interface DIDResolutionMetadata extends Extensible { contentType?: string; error?: 'invalidDid' | 'notFound' | 'representationNotSupported' | 'unsupportedDidMethod' | (string & {}); } /** * Represents metadata about the DID document resulting from a {@link Resolvable.resolve} operation. * * @see {@link https://www.w3.org/TR/did-core/#did-document-metadata} */ export interface DIDDocumentMetadata extends Extensible { created?: string; updated?: string; deactivated?: boolean; versionId?: string; nextUpdate?: string; nextVersionId?: string; equivalentId?: string | string[]; canonicalId?: string; } /** * Represents the Verification Relationship between a DID subject and a Verification Method. * * @see {@link https://www.w3.org/TR/did-core/#verification-relationships} */ export declare const VerificationRelationship: { readonly authentication: 'authentication'; readonly assertionMethod: 'assertionMethod'; readonly keyAgreement: 'keyAgreement'; readonly capabilityInvocation: 'capabilityInvocation'; readonly capabilityDelegation: 'capabilityDelegation'; }; export type VerificationRelationship = keyof typeof VerificationRelationship; /** * Backwards-compatibility alias */ export type KeyCapabilitySection = VerificationRelationship; /** * Represents a DID document. * * @see {@link https://www.w3.org/TR/did-core/#did-document-properties} */ export type DIDDocument = { '@context'?: 'https://www.w3.org/ns/did/v1' | ContextEntry | ContextEntry[]; id: string; alsoKnownAs?: string[]; controller?: string | string[]; verificationMethod?: VerificationMethod[]; service?: Service[]; /** * @deprecated */ publicKey?: VerificationMethod[]; } & { [x in VerificationRelationship]?: (string | VerificationMethod)[]; }; /** * Represents a Service entry in a {@link https://www.w3.org/TR/did-core/#did-document-properties | DID document}. * * @see {@link https://www.w3.org/TR/did-core/#services} * @see {@link https://www.w3.org/TR/did-core/#service-properties} */ export interface Service { id: string; type: string; serviceEndpoint: ServiceEndpoint | ServiceEndpoint[]; [x: string]: any; } /** * Represents an endpoint of a Service entry in a DID document. * * @see {@link https://www.w3.org/TR/did-core/#dfn-serviceendpoint} * @see {@link https://www.w3.org/TR/did-core/#services} */ export type ServiceEndpoint = string | Record<string, any>; /** * Encapsulates a JSON web key type that includes only the public properties that * can be used in DID documents. * * The private properties are intentionally omitted to discourage the use * (and accidental disclosure) of private keys in DID documents. * * @see {@link https://www.rfc-editor.org/rfc/rfc7517 | RFC7517 JsonWebKey (JWK)} */ export interface JsonWebKey extends Extensible { alg?: string; crv?: string; e?: string; ext?: boolean; key_ops?: string[]; kid?: string; kty: string; n?: string; use?: string; x?: string; y?: string; } /** * Represents the properties of a Verification Method listed in a DID document. * * This data type includes public key representations that are no longer present in the spec but are still used by * several DID methods / resolvers and kept for backward compatibility. * * @see {@link https://www.w3.org/TR/did-core/#verification-methods} * @see {@link https://www.w3.org/TR/did-core/#verification-method-properties} */ export interface VerificationMethod { id: string; type: string; controller: string; publicKeyJwk?: JsonWebKey; publicKeyMultibase?: string; blockchainAccountId?: string; /** * @deprecated */ publicKeyBase58?: string; /** * @deprecated */ publicKeyBase64?: string; /** * @deprecated */ publicKeyHex?: string; /** * @deprecated */ publicKeyPem?: string; /** * @deprecated */ ethereumAddress?: string; conditionOr?: VerificationMethod[]; conditionAnd?: VerificationMethod[]; threshold?: number; conditionThreshold?: VerificationMethod[]; conditionWeightedThreshold?: ConditionWeightedThreshold[]; conditionDelegated?: string; relationshipParent?: string[]; relationshipChild?: string[]; relationshipSibling?: string[]; } export interface ConditionWeightedThreshold { condition: VerificationMethod; weight: number; } /** * URI params resulting from parsing a DID URI */ export interface Params { [index: string]: string; } /** * An object containing the results of parsing a DID URI string. * * This is forwarded to implementations of particular DID resolvers when calling the `resolve` method. * * @see {@link Resolver} * @see {@link Resolvable.resolve} */ export interface ParsedDID { did: string; didUrl: string; method: string; id: string; path?: string; fragment?: string; query?: string; } /** * Optional parser function that can be attached to a DIDResolver to provide * method-specific validation of the ParsedDID before resolution. */ export type DIDParser = (parsed: ParsedDID) => ParsedDID | null; /** * The DID resolution function that DID Resolver implementations must implement. * Can optionally have a `.parser` property for method-specific DID validation. */ export interface DIDResolver { (did: string, parsed: ParsedDID, resolver: Resolvable, options: DIDResolutionOptions): Promise<DIDResolutionResult>; parser?: DIDParser; } export type WrappedResolver = () => Promise<DIDResolutionResult>; export type DIDCache = (parsed: ParsedDID, resolve: WrappedResolver, options?: DIDResolutionOptions) => Promise<DIDResolutionResult>; export type LegacyDIDResolver = (did: string, parsed: ParsedDID, resolver: Resolvable) => Promise<DIDDocument>; export type ResolverRegistry = Record<string, DIDResolver>; export interface LegacyResolverRegistry { [index: string]: LegacyDIDResolver; } export interface ResolverOptions { cache?: DIDCache | boolean | undefined; legacyResolvers?: LegacyResolverRegistry; } export declare function inMemoryCache(): DIDCache; export declare function noCache(parsed: ParsedDID, resolve: WrappedResolver): Promise<DIDResolutionResult>; /** * Parses a DID URL strictly according to the DID Core v1.0 specification ABNF * (§3.1 DID Syntax, §3.2 DID URL Syntax). Unlike {@link parse}, this method * does not accept legacy DID parameters (`;key=value`) and enforces the * RFC 3986 character sets for path, query, and fragment components. * * @param didUrl - the DID URL string to be parsed * @returns a ParsedDID object, or null if the input does not conform to the spec */ export declare function parse(didUrl: string): ParsedDID | null; export declare function wrapLegacyResolver(resolve: LegacyDIDResolver): DIDResolver; /** * The method signature implemented by this resolver. */ export interface Resolvable { resolve: (didUrl: string, options?: DIDResolutionOptions) => Promise<DIDResolutionResult>; } /** * This implementation of {@link Resolvable} bundles together multiple implementations of {@link DIDResolver} and * presents a single function call to users. */ export declare class Resolver implements Resolvable { private readonly registry; private readonly cache; constructor(registry?: ResolverRegistry, options?: ResolverOptions); resolve(didUrl: string, options?: DIDResolutionOptions): Promise<DIDResolutionResult>; } //# sourceMappingURL=index.d.ts.map