@tinycloud/share-sdk 1.4.1-beta.0 → 1.4.1-beta.1

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.
@@ -5278,6 +5278,23 @@ var unifiedEncryptionNetworkSchema = external_exports.string().refine((value) =>
5278
5278
  const network = separator < 0 ? "" : rest.slice(separator + 1);
5279
5279
  return owner.startsWith("did:") && owner.length > 4 && network.length > 0 && !/[:/%?#\s]/.test(network);
5280
5280
  }, { message: "expected canonical TinyCloud encryption network" });
5281
+ var unifiedEncryptionResourceSchema = external_exports.string().refine((value) => {
5282
+ const prefix = "urn:tinycloud:encryption:";
5283
+ if (!value.startsWith(prefix)) return false;
5284
+ const match = /^(did:.+):([^/:?#\s]+)(?:\/(.+))?$/.exec(value.slice(prefix.length));
5285
+ if (match === null) return false;
5286
+ const path = match[3];
5287
+ return path === void 0 || path.split("/").every(
5288
+ (segment) => segment.length > 0 && segment !== "." && segment !== ".." && !/[\\:%?#\s]/.test(segment)
5289
+ );
5290
+ }, { message: "expected a canonical TinyCloud encryption resource" });
5291
+ var unifiedEncryptionKeyPathSchema = external_exports.string().regex(/^share\/[^/]+$/).refine(
5292
+ (value) => {
5293
+ const segment = value.slice("share/".length);
5294
+ return segment !== "." && segment !== ".." && !/[\\:%?#\s]/.test(segment);
5295
+ },
5296
+ { message: "expected an exact share key path" }
5297
+ );
5281
5298
  var unifiedKvCapabilitySchema = external_exports.object({
5282
5299
  kind: external_exports.literal("kv"),
5283
5300
  resource: unifiedResourceSchema,
@@ -5291,7 +5308,7 @@ var unifiedKvCapabilitySchema = external_exports.object({
5291
5308
  }).strict();
5292
5309
  var unifiedEncryptionCapabilitySchema = external_exports.object({
5293
5310
  kind: external_exports.literal("encryption"),
5294
- resource: unifiedEncryptionNetworkSchema,
5311
+ resource: unifiedEncryptionResourceSchema,
5295
5312
  action: external_exports.literal("tinycloud.encryption/decrypt")
5296
5313
  }).strict();
5297
5314
  var unifiedCapabilitySchema = external_exports.union([unifiedKvCapabilitySchema, unifiedEncryptionCapabilitySchema]);
@@ -5300,6 +5317,7 @@ var unifiedContentSourceSchema = external_exports.object({
5300
5317
  kvResource: unifiedResourceSchema,
5301
5318
  selector: external_exports.union([external_exports.literal("exact"), external_exports.literal("prefix")]),
5302
5319
  encryptionNetwork: unifiedEncryptionNetworkSchema,
5320
+ encryptionKeyPath: unifiedEncryptionKeyPathSchema.optional(),
5303
5321
  encryptedSymmetricKeyDigestHex: external_exports.string().regex(/^[0-9a-f]{64}$/),
5304
5322
  keyVersion: external_exports.number().int().positive(),
5305
5323
  mode: external_exports.union([external_exports.literal("mutable"), external_exports.literal("immutable")]),
@@ -5417,16 +5435,21 @@ function validateV3Invariants(value, ctx) {
5417
5435
  if (value.attestedEnforcerBinding.nodeAudience !== value.target.nodeAudience || value.attestedEnforcerBinding.signature.signerDid !== value.attestedEnforcerBinding.nodeAudience || Date.parse(value.attestedEnforcerBinding.expiresAt) < Date.parse(value.expiry)) {
5418
5436
  ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["attestedEnforcerBinding"], message: "enforcer binding does not cover the target and share lifetime" });
5419
5437
  }
5420
- if (value.policy.contentSource.shareId !== value.contentSource.shareId || value.policy.contentSource.kvResource !== value.contentSource.kvResource || value.policy.contentSource.selector !== value.contentSource.selector || value.policy.contentSource.encryptionNetwork !== value.encryptionNetwork || value.policy.contentSource.encryptedSymmetricKeyDigestHex !== value.contentSource.encryptedSymmetricKeyDigestHex || value.policy.contentSource.keyVersion !== value.contentSource.keyVersion || value.policy.contentSource.mode !== value.contentSource.mode || value.policy.contentSource.initialCiphertextDigestHex !== value.contentSource.initialCiphertextDigestHex) {
5438
+ const encryptionKeyPath = value.contentSource.encryptionKeyPath;
5439
+ if (encryptionKeyPath !== void 0 && encryptionKeyPath !== `share/${value.contentSource.shareId}`) {
5440
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["contentSource", "encryptionKeyPath"], message: "share key path must name this share" });
5441
+ }
5442
+ if (value.policy.contentSource.shareId !== value.contentSource.shareId || value.policy.contentSource.kvResource !== value.contentSource.kvResource || value.policy.contentSource.selector !== value.contentSource.selector || value.policy.contentSource.encryptionNetwork !== value.encryptionNetwork || value.policy.contentSource.encryptionKeyPath !== encryptionKeyPath || value.policy.contentSource.encryptedSymmetricKeyDigestHex !== value.contentSource.encryptedSymmetricKeyDigestHex || value.policy.contentSource.keyVersion !== value.contentSource.keyVersion || value.policy.contentSource.mode !== value.contentSource.mode || value.policy.contentSource.initialCiphertextDigestHex !== value.contentSource.initialCiphertextDigestHex) {
5421
5443
  ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["contentSource"], message: "content source is not bound to policy" });
5422
5444
  }
5423
5445
  if (value.policy.signature.suite !== "Ed25519" || value.policy.signature.signerDid !== value.policy.ownerDid) {
5424
5446
  ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "signature"], message: "policy must be signed by its owner" });
5425
5447
  }
5426
5448
  const kvCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "kv");
5427
- const decryptCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "encryption" && capability.resource === value.encryptionNetwork && capability.action === "tinycloud.encryption/decrypt");
5449
+ const expectedEncryptionResource = encryptionKeyPath === void 0 ? value.encryptionNetwork : `${value.encryptionNetwork}/${encryptionKeyPath}`;
5450
+ const decryptCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "encryption" && capability.resource === expectedEncryptionResource && capability.action === "tinycloud.encryption/decrypt");
5428
5451
  if (value.policy.capabilityCeiling.length !== 2 || kvCapabilities.length !== 1 || decryptCapabilities.length !== 1 || kvCapabilities[0]?.resource !== value.contentSource.kvResource || kvCapabilities[0]?.selector !== value.contentSource.selector) {
5429
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "capabilityCeiling"], message: "policy ceiling must contain exact decrypt network" });
5452
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "capabilityCeiling"], message: "policy ceiling must contain the exact decrypt resource" });
5430
5453
  }
5431
5454
  }
5432
5455
  var unsignedShareEnvelopeV3Schema = unsignedShareEnvelopeV3BaseSchema.superRefine(validateV3Invariants);