Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support query endpoint discovery #1212

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,46 +305,43 @@ export const defaultContext = ["https://www.w3.org/2018/credentials/v1"];

export const defaultCredentialTypes = ["VerifiableCredential"];

type LegacyEndpoints = Partial<{
derivationService: UrlString;
issuerService: UrlString;
statusService: UrlString;
verifierService: UrlString;
queryService: UrlString;
}>;

/**
* A Verifiable Credential API configuration details.
*/
export type VerifiableCredentialApiConfiguration =
// Legacy endpoints
Partial<{
export type VerifiableCredentialApiConfiguration = LegacyEndpoints & {
// Spec-compliant endpoints, available in the `specCompliant` object
specCompliant: Partial<{
derivationService: UrlString;
issuerService: UrlString;
issuerCredentialAll: UrlString;
holderPresentationAll: UrlString;
statusService: UrlString;
verifierService: UrlString;
}> & {
// Spec-compliant endpoints, available in the `specCompliant` object
specCompliant: Partial<{
derivationService: UrlString;
issuerService: UrlString;
issuerCredentialAll: UrlString;
holderPresentationAll: UrlString;
statusService: UrlString;
credentialVerifierService: UrlString;
presentationVerifierService: UrlString;
queryService: UrlString;
exchangeService: UrlString;
proveService: UrlString;
}>;
} & {
// Legacy endpoints, available in the `legacy` object too to ease transition
legacy: Partial<{
derivationService: UrlString;
issuerService: UrlString;
statusService: UrlString;
verifierService: UrlString;
}>;
};
credentialVerifierService: UrlString;
presentationVerifierService: UrlString;
queryService: UrlString;
exchangeService: UrlString;
proveService: UrlString;
}>;
} & {
// Legacy endpoints, available in the `legacy` object too to ease transition
legacy: LegacyEndpoints;
};

// Solid VC URIs
const SOLID_VC_NS = "http://www.w3.org/ns/solid/vc#";
const SOLID_VC_DERIVATION_SERVICE = SOLID_VC_NS.concat("derivationService");
const SOLID_VC_ISSUER_SERVICE = SOLID_VC_NS.concat("issuerService");
const SOLID_VC_STATUS_SERVICE = SOLID_VC_NS.concat("statusService");
const SOLID_VC_VERIFIER_SERVICE = SOLID_VC_NS.concat("verifierService");
const SOLID_VC_QUERY_SERVICE = SOLID_VC_NS.concat("queryService");

async function discoverLegacyEndpoints(
vcServiceUrl: UrlString,
Expand All @@ -368,6 +365,8 @@ async function discoverLegacyEndpoints(
undefined,
issuerService:
getIri(wellKnownRootBlankNode, SOLID_VC_ISSUER_SERVICE) ?? undefined,
queryService:
getIri(wellKnownRootBlankNode, SOLID_VC_QUERY_SERVICE) ?? undefined,
statusService:
getIri(wellKnownRootBlankNode, SOLID_VC_STATUS_SERVICE) ?? undefined,
verifierService:
Expand Down
32 changes: 31 additions & 1 deletion src/common/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const mockVcWellKnown = (options: {
statusPresent?: boolean;
verifierPresent?: boolean;
derivationPresent?: boolean;
queryPresent?: boolean;
}): SolidClient.SolidDataset & SolidClient.WithServerResourceInfo => {
const wellKnown = buildThing();
if (options.issuerPresent) {
Expand All @@ -73,6 +74,12 @@ const mockVcWellKnown = (options: {
`${MOCKED_VC_SERVICE}/derive`,
);
}
if (options.queryPresent) {
wellKnown.addIri(
"http://www.w3.org/ns/solid/vc#queryService",
`${MOCKED_VC_SERVICE}/query`,
);
}
return setThing(
mockSolidDatasetFrom("https://vc-service.iri/.well-known/solid"),
wellKnown.build(),
Expand Down Expand Up @@ -169,6 +176,23 @@ describe("getVerifiableCredentialApiConfiguration", () => {
);
});

it("returns the IRI of the query service if present", async () => {
const clientModule = jest.requireMock(
"@inrupt/solid-client",
) as jest.Mocked<typeof SolidClient>;
clientModule.getSolidDataset.mockResolvedValueOnce(
mockVcWellKnown({ queryPresent: true }),
);
const result = await getVerifiableCredentialApiConfiguration(
"https://some.example.wellknown.iri",
);
expect(result).toEqual(
expect.objectContaining({
queryService: `${MOCKED_VC_SERVICE}/query`,
}),
);
});

it("returns the IRI of multiple services if present", async () => {
const clientModule = jest.requireMock(
"@inrupt/solid-client",
Expand Down Expand Up @@ -200,14 +224,19 @@ describe("getVerifiableCredentialApiConfiguration", () => {
expect(result.issuerService).toBeUndefined();
expect(result.statusService).toBeUndefined();
expect(result.verifierService).toBeUndefined();
expect(result.queryService).toBeUndefined();
});

it("makes the legacy endpoints available on the legacy object", async () => {
const clientModule = jest.requireMock(
"@inrupt/solid-client",
) as jest.Mocked<typeof SolidClient>;
clientModule.getSolidDataset.mockResolvedValueOnce(
mockVcWellKnown({ derivationPresent: true, issuerPresent: true }),
mockVcWellKnown({
derivationPresent: true,
issuerPresent: true,
queryPresent: true,
}),
);
const result = await getVerifiableCredentialApiConfiguration(
"https://some.example.wellknown.iri",
Expand All @@ -216,6 +245,7 @@ describe("getVerifiableCredentialApiConfiguration", () => {
expect(result.derivationService).toStrictEqual(
result.legacy.derivationService,
);
expect(result.queryService).toStrictEqual(result.legacy.queryService);
});
});

Expand Down
Loading