Skip to content
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
5 changes: 4 additions & 1 deletion src/lib/vana/capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
type AccessRequestStatus,
} from "@opendatalabs/vana-sdk/server";

import { shouldUseEnclaveRead } from "./enclave";

/**
* A DCR requesting multiple scopes mints ONE grant covering all of them, so
* readiness is a grant-level check, not a single-scope match. Direct reads
Expand All @@ -17,7 +19,8 @@ export function assertGrantReadReady(
if (
(status.status !== "approved" && status.status !== "ready_for_read") ||
!status.grantId ||
(options.requirePersonalServerUrl !== false && !status.personalServerUrl)
((options.requirePersonalServerUrl ?? !shouldUseEnclaveRead(status)) &&
!status.personalServerUrl)
) {
throw new AccessNotApprovedError("The approved grant is not ready to read.");
}
Expand Down
16 changes: 16 additions & 0 deletions test/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1208,3 +1208,19 @@ test("marks JSON responses as non-cacheable", async () => {
assert.equal(response.headers.get("Cache-Control"), "no-store");
assert.deepEqual(await response.json(), { error: "Sanitized failure" });
});

test("accepts the URL-less enclave grant used by the consent return page", () => {
assert.doesNotThrow(() => assertGrantReadReady({
status: "ready_for_read",
grantId: `0x${"a".repeat(64)}`,
delivery: "enclave",
scopes: ["spotify.profile"],
}));
});

test("still rejects unapproved or missing enclave grants and explicit URL requirements", () => {
const enclave = { status: "ready_for_read" as const, delivery: "enclave" as const, grantId: "0xgrant" };
assert.throws(() => assertGrantReadReady({ ...enclave, status: "pending" }), AccessNotApprovedError);
assert.throws(() => assertGrantReadReady({ ...enclave, grantId: undefined }), AccessNotApprovedError);
assert.throws(() => assertGrantReadReady(enclave, { requirePersonalServerUrl: true }), AccessNotApprovedError);
});