import type { DatasetCore } from "@rdfjs/types"; import type { DatasetWithId, Iri, VerifiableCredential, VerifiableCredentialBase, VerifiablePresentation } from "../common/common"; import { type ParseOptions } from "../parser/jsonld"; /** * Based on https://w3c-ccg.github.io/vp-request-spec/#query-by-example. */ export type QueryByExample = { type: "QueryByExample"; credentialQuery: { required?: boolean; reason?: string; example: Partial & { credentialSchema?: { id: string; type: string; }; trustedIssuer?: { required: boolean; issuer: string; }[]; }; }[]; }; /** * A VP request is a standard way of getting a Verifiable Presentation matching * the requestor's needs. * * Note: Currently, only the QueryByExample type is implemented, but support for * other query types may be added in the future. */ export type VerifiablePresentationRequest = { query: QueryByExample[]; challenge?: string; domain?: string; }; /** * @hidden */ export interface ParsedVerifiablePresentation extends VerifiablePresentation, DatasetCore { verifiableCredential: VerifiableCredential[]; } export type MinimalPresentation = { verifiableCredential: DatasetWithId[]; } & DatasetCore; /** * Send a Verifiable Presentation Request to a query endpoint in order to retrieve * all Verifiable Credentials matching the query, wrapped in a single Presentation. * * @example The following shows how to query for credentials of a certain type. Adding * a reason to the request is helpful when interacting with a user. The resulting * Verifiable Presentation will wrap zero or more Verifiable Credentials. * * ``` * const verifiablePresentation = await query( "https://example.org/query", { query: [{ type: "QueryByExample", credentialQuery: [ { reason: "Some reason", example: { type: ["SomeCredentialType"], }, }, ], }] }, { fetch: session.fetch } ); * ``` * * @param queryEndpoint URL of the query endpoint. * @param vpRequest VP Request object, compliant with https://w3c-ccg.github.io/vp-request-spec * @param options Options object, including an authenticated `fetch`. * @returns The resulting Verifiable Presentation wrapping all the Credentials matching the query. */ export declare function query(queryEndpoint: Iri, vpRequest: VerifiablePresentationRequest, options: ParseOptions & { fetch?: typeof fetch; returnLegacyJsonld: false; normalize?: (vc: VerifiableCredentialBase) => VerifiableCredentialBase; }): Promise; /** * @deprecated Use RDFJS API instead of relying on the JSON structure by setting `returnLegacyJsonld` to false */ export declare function query(queryEndpoint: Iri, vpRequest: VerifiablePresentationRequest, options?: ParseOptions & { fetch?: typeof fetch; returnLegacyJsonld?: true; normalize?: (vc: VerifiableCredentialBase) => VerifiableCredentialBase; }): Promise; /** * @deprecated Use RDFJS API instead of relying on the JSON structure by setting `returnLegacyJsonld` to false */ export declare function query(queryEndpoint: Iri, vpRequest: VerifiablePresentationRequest, options?: ParseOptions & { fetch?: typeof fetch; returnLegacyJsonld?: boolean; normalize?: (vc: VerifiableCredentialBase) => VerifiableCredentialBase; }): Promise;