@tinycloud/sdk-core 3.8.0-beta.5 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -426,6 +426,7 @@ interface UnifiedContentSource {
426
426
  readonly kvResource: string;
427
427
  readonly selector: UnifiedResourceSelector;
428
428
  readonly encryptionNetwork: string;
429
+ readonly encryptionKeyPath?: string;
429
430
  readonly encryptedSymmetricKeyDigestHex: string;
430
431
  readonly keyVersion: number;
431
432
  readonly mode: "mutable" | "immutable";
@@ -426,6 +426,7 @@ interface UnifiedContentSource {
426
426
  readonly kvResource: string;
427
427
  readonly selector: UnifiedResourceSelector;
428
428
  readonly encryptionNetwork: string;
429
+ readonly encryptionKeyPath?: string;
429
430
  readonly encryptedSymmetricKeyDigestHex: string;
430
431
  readonly keyVersion: number;
431
432
  readonly mode: "mutable" | "immutable";
@@ -189,7 +189,11 @@ var DelegationErrorCodes = {
189
189
  KV_SERVICE_UNAVAILABLE: "KV_SERVICE_UNAVAILABLE",
190
190
  DATA_FETCH_FAILED: "DATA_FETCH_FAILED",
191
191
  VALIDATION_ERROR: "VALIDATION_ERROR",
192
- UNSUPPORTED_OPERATION: "UNSUPPORTED_OPERATION"
192
+ UNSUPPORTED_OPERATION: "UNSUPPORTED_OPERATION",
193
+ /** The node answered 503: the delegation chain is too deep to evaluate right now. Retry later. */
194
+ CHAIN_TOO_DEEP: "CHAIN_TOO_DEEP",
195
+ /** The node answered 400 "invalid delegation query cursor": malformed, foreign or from another filter. Start the listing again without it. */
196
+ INVALID_CURSOR: "INVALID_CURSOR"
193
197
  };
194
198
  var DelegationSchema = import_zod.z.object({
195
199
  /** Content identifier (CID) of the delegation */
@@ -266,7 +270,7 @@ var AccountDelegationPageSchema = import_zod.z.object({
266
270
  nextCursor: import_zod.z.string().optional()
267
271
  }).strict();
268
272
  var AccountDelegationQueryOptionsSchema = import_zod.z.object({
269
- direction: import_zod.z.enum(["granted", "received", "all"]).optional(),
273
+ direction: import_zod.z.enum(["granted", "received", "all", "issued"]).optional(),
270
274
  status: import_zod.z.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]).optional(),
271
275
  space: import_zod.z.string().trim().min(1).optional(),
272
276
  limit: import_zod.z.number().int().min(1).max(100).optional(),
@@ -452,6 +456,8 @@ var DelegationManagerConfigSchema = import_zod.z.object({
452
456
  ).optional(),
453
457
  /** Optional owner-signed authorization for direct CID revocation */
454
458
  signOwnerRevocation: import_zod.z.custom().optional(),
459
+ /** Optional signer for proofless invocations by the session's own did:key (issued-delegation list and revoke) */
460
+ sessionInvocationSigner: import_zod.z.custom().optional(),
455
461
  /** Optional custom fetch implementation */
456
462
  fetch: import_zod.z.unknown().refine(
457
463
  (val) => val === void 0 || typeof val === "function",
@@ -547,7 +553,7 @@ var CreateDelegationWasmResultSchema = import_zod.z.object({
547
553
  resources: import_zod.z.array(DelegatedResourceSchema)
548
554
  });
549
555
 
550
- // src/delegations/DelegationManager.ts
556
+ // src/delegations/shared.ts
551
557
  var DelegationAction = {
552
558
  REVOKE: "tinycloud.delegation/revoke",
553
559
  STATUS: "tinycloud.delegation/status",
@@ -564,6 +570,8 @@ function createError(code3, message, cause, meta) {
564
570
  meta
565
571
  };
566
572
  }
573
+
574
+ // src/delegations/DelegationManager.ts
567
575
  async function readInvokedJson(response, action) {
568
576
  const text = await response.text();
569
577
  if (text.trim() === "") {
@@ -586,11 +594,13 @@ var DelegationManager = class {
586
594
  * @param config - Configuration including hosts, session, and invoke function
587
595
  */
588
596
  constructor(config) {
597
+ this.issuedState = { issuedQuerySupported: false };
589
598
  this.hosts = config.hosts;
590
599
  this.session = config.session;
591
600
  this.invoke = config.invoke;
592
601
  this.invokeAny = config.invokeAny;
593
602
  this.signOwnerRevocation = config.signOwnerRevocation;
603
+ this.sessionInvocationSigner = config.sessionInvocationSigner;
594
604
  this.fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
595
605
  this.accountSpaceId = config.accountSpaceId;
596
606
  }
@@ -833,6 +843,7 @@ var DelegationManager = class {
833
843
  )
834
844
  };
835
845
  }
846
+ if (validated.data.direction === "issued") return this.queryIssued(validated.data);
836
847
  if (!this.invokeAny) {
837
848
  return {
838
849
  ok: false,
@@ -914,6 +925,45 @@ var DelegationManager = class {
914
925
  };
915
926
  }
916
927
  }
928
+ /** The state the lazily loaded issued-delegation module reads and updates. */
929
+ issuedContext() {
930
+ return {
931
+ host: this.host,
932
+ fetchFn: this.fetchFn,
933
+ sessionInvocationSigner: this.sessionInvocationSigner,
934
+ state: this.issuedState
935
+ };
936
+ }
937
+ /**
938
+ * Lists the delegations this session's own key issued (`direction: "issued"`).
939
+ * The implementation loads on first use.
940
+ */
941
+ async queryIssued(options) {
942
+ const issued = await import("@tinycloud/sdk-core/delegations/issued");
943
+ return issued.queryIssued(this.issuedContext(), options);
944
+ }
945
+ /**
946
+ * Every delegation this session's key issued, following `nextCursor` until
947
+ * it is absent. `maxItems` stops early once that many are collected;
948
+ * `untilCid` stops after the page that contains that delegation. Items come
949
+ * in CID order (each carries `issuedAt`). The implementation loads on first use.
950
+ */
951
+ async queryAllIssued(options = {}) {
952
+ const issued = await import("@tinycloud/sdk-core/delegations/issued");
953
+ return issued.queryAllIssued((page) => this.query(page), options);
954
+ }
955
+ /**
956
+ * Revokes a delegation this session's key issued, with no proof: a UCAN
957
+ * signed by the session's own did:key carrying `urn:cid:<cid>` and
958
+ * `tinycloud.delegation/revoke`. Revoking a delegation that is already revoked
959
+ * succeeds. A refusal (the key is not the delegator) carries the node's
960
+ * message; 503 means the chain is too deep right now, retry later.
961
+ * The implementation loads on first use.
962
+ */
963
+ async revokeIssued(cid2) {
964
+ const issued = await import("@tinycloud/sdk-core/delegations/issued");
965
+ return issued.revokeIssued(this.issuedContext(), cid2);
966
+ }
917
967
  /**
918
968
  * Gets the full delegation chain for a given delegation.
919
969
  *
@@ -1251,6 +1301,7 @@ function validateSharingServiceConfig(data) {
1251
1301
  var import_ms = __toESM(require("ms"), 1);
1252
1302
  var import_bootstrap = require("@tinycloud/bootstrap");
1253
1303
  var import_sdk_services = require("@tinycloud/sdk-services");
1304
+ var import_resource = require("@tinycloud/sdk-services/encryption/resource");
1254
1305
  var SERVICE_SHORT_TO_LONG = Object.freeze({
1255
1306
  kv: "tinycloud.kv",
1256
1307
  space: "tinycloud.space",
@@ -1335,6 +1386,7 @@ function principalDid(didUrl) {
1335
1386
  }
1336
1387
 
1337
1388
  // src/capabilities.ts
1389
+ var import_resource2 = require("@tinycloud/sdk-services/encryption/resource");
1338
1390
  var CaveatedDelegationUnsupportedError = class extends Error {
1339
1391
  constructor(entries) {
1340
1392
  super(
@@ -2560,7 +2612,7 @@ var hashes = { ...sha2_browser_exports, ...identity_exports2 };
2560
2612
  var import_ed255194 = require("@noble/curves/ed25519");
2561
2613
 
2562
2614
  // src/delegations/ShareRecipientClient.ts
2563
- var import_sdk_services3 = require("@tinycloud/sdk-services");
2615
+ var import_sdk_services4 = require("@tinycloud/sdk-services");
2564
2616
  var import_ed255193 = require("@noble/curves/ed25519");
2565
2617
  var import_sha2564 = require("@noble/hashes/sha256");
2566
2618
 
@@ -3641,6 +3693,7 @@ var import_sha2563 = require("@noble/hashes/sha256");
3641
3693
  var import_blake32 = require("@noble/hashes/blake3");
3642
3694
  var import_ed255192 = require("@noble/curves/ed25519");
3643
3695
  var import_zod4 = require("zod");
3696
+ var import_sdk_services3 = require("@tinycloud/sdk-services");
3644
3697
 
3645
3698
  // src/policy/errors.ts
3646
3699
  var SignedObjectProfileError = class extends Error {
@@ -4187,9 +4240,9 @@ function redactedCode(error) {
4187
4240
  if (error instanceof ShareConflict) return error.code;
4188
4241
  const code3 = error && typeof error === "object" && "code" in error ? error.code : void 0;
4189
4242
  if (typeof code3 !== "string") return "SHARE_INVALID";
4190
- if (code3 === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED || code3 === "412") return "SHARE_CONFLICT";
4191
- if (code3 === import_sdk_services3.ErrorCodes.NODE_BUSY || code3 === import_sdk_services3.ErrorCodes.REQUEST_TIMEOUT) return "SHARE_OFFLINE";
4192
- if (code3 === import_sdk_services3.ErrorCodes.OUTCOME_UNKNOWN) return "SHARE_WRITE_FAILED";
4243
+ if (code3 === import_sdk_services4.ErrorCodes.KV_PRECONDITION_FAILED || code3 === "412") return "SHARE_CONFLICT";
4244
+ if (code3 === import_sdk_services4.ErrorCodes.NODE_BUSY || code3 === import_sdk_services4.ErrorCodes.REQUEST_TIMEOUT) return "SHARE_OFFLINE";
4245
+ if (code3 === import_sdk_services4.ErrorCodes.OUTCOME_UNKNOWN) return "SHARE_WRITE_FAILED";
4193
4246
  if (code3 === "KV_NOT_FOUND" || code3 === "NOT_FOUND" || code3 === "404") return "SHARE_NOT_FOUND";
4194
4247
  if (code3.includes("EXPIRED") || code3 === "expired") return "SHARE_EXPIRED";
4195
4248
  if (code3.includes("REVOK")) return "SHARE_REVOKED";
@@ -4428,7 +4481,7 @@ var ShareRecipientClient = class {
4428
4481
  if (portableDelegation !== void 0 && kv !== void 0) {
4429
4482
  const result2 = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
4430
4483
  if (!result2.ok) {
4431
- if (result2.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
4484
+ if (result2.error.code === import_sdk_services4.ErrorCodes.KV_PRECONDITION_FAILED) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
4432
4485
  throw result2.error;
4433
4486
  }
4434
4487
  return { etag: result2.data.headers.etag };
@@ -4436,7 +4489,7 @@ var ShareRecipientClient = class {
4436
4489
  if (policySession !== void 0) return this.nativeSave(envelope, policySession, resolvedPath, bytes2, input);
4437
4490
  const result = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
4438
4491
  if (!result.ok) {
4439
- if (result.error.code === import_sdk_services3.ErrorCodes.KV_PRECONDITION_FAILED) throw new ShareConflict(resolvedPath, result.error.meta?.etag);
4492
+ if (result.error.code === import_sdk_services4.ErrorCodes.KV_PRECONDITION_FAILED) throw new ShareConflict(resolvedPath, result.error.meta?.etag);
4440
4493
  throw result.error;
4441
4494
  }
4442
4495
  return { etag: result.data.headers.etag };
@@ -4520,8 +4573,8 @@ var ShareRecipientClient = class {
4520
4573
  if (this.options.createKVService !== void 0) {
4521
4574
  return this.options.createKVService({ hosts: [origin], session, invoke, fetch: this.fetchFn });
4522
4575
  }
4523
- const context = new import_sdk_services3.ServiceContext({ hosts: [origin], session, invoke, fetch: this.fetchFn });
4524
- const service = new import_sdk_services3.KVService({ prefix: "" });
4576
+ const context = new import_sdk_services4.ServiceContext({ hosts: [origin], session, invoke, fetch: this.fetchFn });
4577
+ const service = new import_sdk_services4.KVService({ prefix: "" });
4525
4578
  context.registerService("kv", service);
4526
4579
  service.initialize(context);
4527
4580
  return service;