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

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.
@@ -5228,6 +5228,23 @@ var unifiedEncryptionNetworkSchema = external_exports.string().refine((value) =>
5228
5228
  const network = separator < 0 ? "" : rest.slice(separator + 1);
5229
5229
  return owner.startsWith("did:") && owner.length > 4 && network.length > 0 && !/[:/%?#\s]/.test(network);
5230
5230
  }, { message: "expected canonical TinyCloud encryption network" });
5231
+ var unifiedEncryptionResourceSchema = external_exports.string().refine((value) => {
5232
+ const prefix = "urn:tinycloud:encryption:";
5233
+ if (!value.startsWith(prefix)) return false;
5234
+ const match = /^(did:.+):([^/:?#\s]+)(?:\/(.+))?$/.exec(value.slice(prefix.length));
5235
+ if (match === null) return false;
5236
+ const path = match[3];
5237
+ return path === void 0 || path.split("/").every(
5238
+ (segment) => segment.length > 0 && segment !== "." && segment !== ".." && !/[\\:%?#\s]/.test(segment)
5239
+ );
5240
+ }, { message: "expected a canonical TinyCloud encryption resource" });
5241
+ var unifiedEncryptionKeyPathSchema = external_exports.string().regex(/^share\/[^/]+$/).refine(
5242
+ (value) => {
5243
+ const segment = value.slice("share/".length);
5244
+ return segment !== "." && segment !== ".." && !/[\\:%?#\s]/.test(segment);
5245
+ },
5246
+ { message: "expected an exact share key path" }
5247
+ );
5231
5248
  var unifiedKvCapabilitySchema = external_exports.object({
5232
5249
  kind: external_exports.literal("kv"),
5233
5250
  resource: unifiedResourceSchema,
@@ -5241,7 +5258,7 @@ var unifiedKvCapabilitySchema = external_exports.object({
5241
5258
  }).strict();
5242
5259
  var unifiedEncryptionCapabilitySchema = external_exports.object({
5243
5260
  kind: external_exports.literal("encryption"),
5244
- resource: unifiedEncryptionNetworkSchema,
5261
+ resource: unifiedEncryptionResourceSchema,
5245
5262
  action: external_exports.literal("tinycloud.encryption/decrypt")
5246
5263
  }).strict();
5247
5264
  var unifiedCapabilitySchema = external_exports.union([unifiedKvCapabilitySchema, unifiedEncryptionCapabilitySchema]);
@@ -5250,6 +5267,7 @@ var unifiedContentSourceSchema = external_exports.object({
5250
5267
  kvResource: unifiedResourceSchema,
5251
5268
  selector: external_exports.union([external_exports.literal("exact"), external_exports.literal("prefix")]),
5252
5269
  encryptionNetwork: unifiedEncryptionNetworkSchema,
5270
+ encryptionKeyPath: unifiedEncryptionKeyPathSchema.optional(),
5253
5271
  encryptedSymmetricKeyDigestHex: external_exports.string().regex(/^[0-9a-f]{64}$/),
5254
5272
  keyVersion: external_exports.number().int().positive(),
5255
5273
  mode: external_exports.union([external_exports.literal("mutable"), external_exports.literal("immutable")]),
@@ -5367,16 +5385,21 @@ function validateV3Invariants(value, ctx) {
5367
5385
  if (value.attestedEnforcerBinding.nodeAudience !== value.target.nodeAudience || value.attestedEnforcerBinding.signature.signerDid !== value.attestedEnforcerBinding.nodeAudience || Date.parse(value.attestedEnforcerBinding.expiresAt) < Date.parse(value.expiry)) {
5368
5386
  ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["attestedEnforcerBinding"], message: "enforcer binding does not cover the target and share lifetime" });
5369
5387
  }
5370
- 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) {
5388
+ const encryptionKeyPath = value.contentSource.encryptionKeyPath;
5389
+ if (encryptionKeyPath !== void 0 && encryptionKeyPath !== `share/${value.contentSource.shareId}`) {
5390
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["contentSource", "encryptionKeyPath"], message: "share key path must name this share" });
5391
+ }
5392
+ 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) {
5371
5393
  ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["contentSource"], message: "content source is not bound to policy" });
5372
5394
  }
5373
5395
  if (value.policy.signature.suite !== "Ed25519" || value.policy.signature.signerDid !== value.policy.ownerDid) {
5374
5396
  ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "signature"], message: "policy must be signed by its owner" });
5375
5397
  }
5376
5398
  const kvCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "kv");
5377
- const decryptCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "encryption" && capability.resource === value.encryptionNetwork && capability.action === "tinycloud.encryption/decrypt");
5399
+ const expectedEncryptionResource = encryptionKeyPath === void 0 ? value.encryptionNetwork : `${value.encryptionNetwork}/${encryptionKeyPath}`;
5400
+ const decryptCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "encryption" && capability.resource === expectedEncryptionResource && capability.action === "tinycloud.encryption/decrypt");
5378
5401
  if (value.policy.capabilityCeiling.length !== 2 || kvCapabilities.length !== 1 || decryptCapabilities.length !== 1 || kvCapabilities[0]?.resource !== value.contentSource.kvResource || kvCapabilities[0]?.selector !== value.contentSource.selector) {
5379
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "capabilityCeiling"], message: "policy ceiling must contain exact decrypt network" });
5402
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "capabilityCeiling"], message: "policy ceiling must contain the exact decrypt resource" });
5380
5403
  }
5381
5404
  }
5382
5405
  var unsignedShareEnvelopeV3Schema = unsignedShareEnvelopeV3BaseSchema.superRefine(validateV3Invariants);