Skip to content

Commit e215652

Browse files
committed
feat: add delegated credential lifecycle and private storage
1 parent 906bee5 commit e215652

10 files changed

Lines changed: 4050 additions & 10 deletions

‎packages/core/sdk/src/core-schema.ts‎

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,131 @@ export const coreTables = defineTables({
197197
["tenant", "external_id"],
198198
),
199199

200+
// Delegated credentials are deliberately tenant-scoped and are only exposed
201+
// through the delegation service. They are not owner rows: the row belongs
202+
// to the grant, while the effective subject is an immutable field inside it.
203+
// `scope` contains the exact consent snapshot; it is never re-expanded from
204+
// mutable toolkit rows during dispatch.
205+
credential_delegation: (() => {
206+
const out = tenantExecutorTable(
207+
"credential_delegation",
208+
{
209+
id: keyColumn("id"),
210+
label: keyColumn("label"),
211+
created_by: keyColumn("created_by"),
212+
credential_id: keyColumn("credential_id"),
213+
credential_kind: keyColumn("credential_kind"),
214+
adapter: keyColumn("adapter"),
215+
issuer: textColumn("issuer"),
216+
audience: textColumn("audience"),
217+
credential_subject: textColumn("credential_subject"),
218+
credential_ref: keyColumn("credential_ref"),
219+
issued_key_ref: nullableKeyColumn("issued_key_ref"),
220+
key_hash: nullableKeyColumn("key_hash"),
221+
actor_subject: keyColumn("actor_subject"),
222+
effective_subject: keyColumn("effective_subject"),
223+
toolkit_membership: jsonColumn("toolkit_membership"),
224+
scope: jsonColumn("scope"),
225+
scope_version: keyColumn("scope_version"),
226+
expires_at: bigintColumn("expires_at"),
227+
revoked_at: nullableBigintColumn("revoked_at"),
228+
revoke_reason: nullableTextColumn("revoke_reason"),
229+
created_at: dateColumn("created_at"),
230+
last_used_at: nullableBigintColumn("last_used_at"),
231+
},
232+
["tenant", "id"],
233+
);
234+
out.unique("credential_delegation_binding_uidx", [
235+
"tenant",
236+
"adapter",
237+
"issuer",
238+
"audience",
239+
"credential_subject",
240+
"credential_ref",
241+
]);
242+
// Provider/local key references are the durable revocation and rotation
243+
// handle. Keep them unique inside a tenant even when a malformed adapter
244+
// attempts to present the same reference under a different tuple.
245+
out.unique("credential_delegation_issued_key_ref_uidx", ["tenant", "issued_key_ref"]);
246+
return out;
247+
})(),
248+
249+
// Single-use proof challenges. Only the digest is persisted; proof material
250+
// is supplied by the host adapter and is never written to this table.
251+
delegation_challenge: tenantExecutorTable(
252+
"delegation_challenge",
253+
{
254+
id: keyColumn("id"),
255+
created_by: keyColumn("created_by"),
256+
label: keyColumn("label"),
257+
credential_id: nullableKeyColumn("credential_id"),
258+
credential_kind: nullableKeyColumn("credential_kind"),
259+
adapter: keyColumn("adapter"),
260+
issuer: nullableTextColumn("issuer"),
261+
audience: nullableTextColumn("audience"),
262+
credential_subject: nullableTextColumn("credential_subject"),
263+
credential_ref: nullableKeyColumn("credential_ref"),
264+
actor_subject: nullableKeyColumn("actor_subject"),
265+
effective_subject: keyColumn("effective_subject"),
266+
scope: jsonColumn("scope"),
267+
proof_hash: keyColumn("proof_hash"),
268+
expires_at: bigintColumn("expires_at"),
269+
grant_expires_at: bigintColumn("grant_expires_at"),
270+
proof_consumed_at: nullableBigintColumn("proof_consumed_at"),
271+
consent_consumed_at: nullableBigintColumn("consent_consumed_at"),
272+
created_at: dateColumn("created_at"),
273+
},
274+
["tenant", "id"],
275+
),
276+
277+
// Append-only operational audit. The service accepts identifiers and
278+
// outcomes only; arguments, results, tokens, and authorization headers are
279+
// intentionally absent from this schema.
280+
delegation_audit: tenantExecutorTable(
281+
"delegation_audit",
282+
{
283+
id: keyColumn("id"),
284+
grant_id: nullableKeyColumn("grant_id"),
285+
credential_id: nullableKeyColumn("credential_id"),
286+
actor_subject: keyColumn("actor_subject"),
287+
effective_subject: keyColumn("effective_subject"),
288+
action: keyColumn("action"),
289+
tool: nullableTextColumn("tool"),
290+
outcome: keyColumn("outcome"),
291+
request_id: nullableTextColumn("request_id"),
292+
execution_id: nullableTextColumn("execution_id"),
293+
occurred_at: dateColumn("occurred_at"),
294+
},
295+
["tenant", "id"],
296+
),
297+
298+
// Durable target-owned notices for grants created by another subject. The
299+
// service writes these in the same transaction as the grant, so a notice
300+
// failure cannot leave an active delegated credential without a notification.
301+
delegation_notification: (() => {
302+
const out = tenantExecutorTable(
303+
"delegation_notification",
304+
{
305+
id: keyColumn("id"),
306+
grant_id: keyColumn("grant_id"),
307+
credential_id: keyColumn("credential_id"),
308+
created_by: keyColumn("created_by"),
309+
target_subject: keyColumn("target_subject"),
310+
label: keyColumn("label"),
311+
credential_kind: keyColumn("credential_kind"),
312+
created_at: dateColumn("created_at"),
313+
read_at: nullableBigintColumn("read_at"),
314+
},
315+
["tenant", "id"],
316+
);
317+
out.unique("delegation_notification_grant_target_uidx", [
318+
"tenant",
319+
"grant_id",
320+
"target_subject",
321+
]);
322+
return out;
323+
})(),
324+
200325
// THE saved credential, one per (owner, integration, name). Resolves each named
201326
// input via `provider` + the `item_ids` map (variable → provider item id). A
202327
// single-secret connection is `{ "token": <id> }`; an apiKey method with two
@@ -444,6 +569,10 @@ export type CoreSchema = typeof coreTables;
444569

445570
export type IntegrationRow = FumaRow<CoreSchema["integration"]>;
446571
export type SubjectRow = FumaRow<CoreSchema["subject"]>;
572+
export type CredentialDelegationRow = FumaRow<CoreSchema["credential_delegation"]>;
573+
export type DelegationChallengeRow = FumaRow<CoreSchema["delegation_challenge"]>;
574+
export type DelegationAuditRow = FumaRow<CoreSchema["delegation_audit"]>;
575+
export type DelegationNotificationRow = FumaRow<CoreSchema["delegation_notification"]>;
447576
export type ConnectionRow = FumaRow<CoreSchema["connection"]>;
448577
export type OAuthClientRow = FumaRow<CoreSchema["oauth_client"]>;
449578
export type OAuthSessionRow = FumaRow<CoreSchema["oauth_session"]>;

0 commit comments

Comments
 (0)