@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.
@@ -1,5 +1,5 @@
1
1
  import { CompactUcanAuthorization, UnifiedContentSource } from '@tinycloud/share-envelope';
2
- import { A as AddressedOwnerRootInput, a as AddressedOwnerRootReceipt, b as AddressedPublishAuthority } from './addressed-publish-BP6nsgRq.cjs';
2
+ import { A as AddressedOwnerRootInput, a as AddressedOwnerRootReceipt, b as AddressedPublishAuthority } from './addressed-publish-BcvisG4a.cjs';
3
3
  import { C as CreateOwnerDelegationParams, g as OwnerDelegationReceipt, D as DelegatedShareKey } from './owner-policy-aPmXIR3e.cjs';
4
4
  import './authorization-CmP1skO8.cjs';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { CompactUcanAuthorization, UnifiedContentSource } from '@tinycloud/share-envelope';
2
- import { A as AddressedOwnerRootInput, a as AddressedOwnerRootReceipt, b as AddressedPublishAuthority } from './addressed-publish-CpkwV-Au.js';
2
+ import { A as AddressedOwnerRootInput, a as AddressedOwnerRootReceipt, b as AddressedPublishAuthority } from './addressed-publish-CwTTn9Jn.js';
3
3
  import { C as CreateOwnerDelegationParams, g as OwnerDelegationReceipt, D as DelegatedShareKey } from './owner-policy-aPmXIR3e.js';
4
4
  import './authorization-CmP1skO8.js';
5
5
 
@@ -5232,6 +5232,23 @@ var unifiedEncryptionNetworkSchema = external_exports.string().refine((value) =>
5232
5232
  const network = separator < 0 ? "" : rest.slice(separator + 1);
5233
5233
  return owner.startsWith("did:") && owner.length > 4 && network.length > 0 && !/[:/%?#\s]/.test(network);
5234
5234
  }, { message: "expected canonical TinyCloud encryption network" });
5235
+ var unifiedEncryptionResourceSchema = external_exports.string().refine((value) => {
5236
+ const prefix = "urn:tinycloud:encryption:";
5237
+ if (!value.startsWith(prefix)) return false;
5238
+ const match = /^(did:.+):([^/:?#\s]+)(?:\/(.+))?$/.exec(value.slice(prefix.length));
5239
+ if (match === null) return false;
5240
+ const path = match[3];
5241
+ return path === void 0 || path.split("/").every(
5242
+ (segment) => segment.length > 0 && segment !== "." && segment !== ".." && !/[\\:%?#\s]/.test(segment)
5243
+ );
5244
+ }, { message: "expected a canonical TinyCloud encryption resource" });
5245
+ var unifiedEncryptionKeyPathSchema = external_exports.string().regex(/^share\/[^/]+$/).refine(
5246
+ (value) => {
5247
+ const segment = value.slice("share/".length);
5248
+ return segment !== "." && segment !== ".." && !/[\\:%?#\s]/.test(segment);
5249
+ },
5250
+ { message: "expected an exact share key path" }
5251
+ );
5235
5252
  var unifiedKvCapabilitySchema = external_exports.object({
5236
5253
  kind: external_exports.literal("kv"),
5237
5254
  resource: unifiedResourceSchema,
@@ -5245,7 +5262,7 @@ var unifiedKvCapabilitySchema = external_exports.object({
5245
5262
  }).strict();
5246
5263
  var unifiedEncryptionCapabilitySchema = external_exports.object({
5247
5264
  kind: external_exports.literal("encryption"),
5248
- resource: unifiedEncryptionNetworkSchema,
5265
+ resource: unifiedEncryptionResourceSchema,
5249
5266
  action: external_exports.literal("tinycloud.encryption/decrypt")
5250
5267
  }).strict();
5251
5268
  var unifiedCapabilitySchema = external_exports.union([unifiedKvCapabilitySchema, unifiedEncryptionCapabilitySchema]);
@@ -5254,6 +5271,7 @@ var unifiedContentSourceSchema = external_exports.object({
5254
5271
  kvResource: unifiedResourceSchema,
5255
5272
  selector: external_exports.union([external_exports.literal("exact"), external_exports.literal("prefix")]),
5256
5273
  encryptionNetwork: unifiedEncryptionNetworkSchema,
5274
+ encryptionKeyPath: unifiedEncryptionKeyPathSchema.optional(),
5257
5275
  encryptedSymmetricKeyDigestHex: external_exports.string().regex(/^[0-9a-f]{64}$/),
5258
5276
  keyVersion: external_exports.number().int().positive(),
5259
5277
  mode: external_exports.union([external_exports.literal("mutable"), external_exports.literal("immutable")]),
@@ -5371,16 +5389,21 @@ function validateV3Invariants(value, ctx) {
5371
5389
  if (value.attestedEnforcerBinding.nodeAudience !== value.target.nodeAudience || value.attestedEnforcerBinding.signature.signerDid !== value.attestedEnforcerBinding.nodeAudience || Date.parse(value.attestedEnforcerBinding.expiresAt) < Date.parse(value.expiry)) {
5372
5390
  ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["attestedEnforcerBinding"], message: "enforcer binding does not cover the target and share lifetime" });
5373
5391
  }
5374
- 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) {
5392
+ const encryptionKeyPath = value.contentSource.encryptionKeyPath;
5393
+ if (encryptionKeyPath !== void 0 && encryptionKeyPath !== `share/${value.contentSource.shareId}`) {
5394
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["contentSource", "encryptionKeyPath"], message: "share key path must name this share" });
5395
+ }
5396
+ 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) {
5375
5397
  ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["contentSource"], message: "content source is not bound to policy" });
5376
5398
  }
5377
5399
  if (value.policy.signature.suite !== "Ed25519" || value.policy.signature.signerDid !== value.policy.ownerDid) {
5378
5400
  ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "signature"], message: "policy must be signed by its owner" });
5379
5401
  }
5380
5402
  const kvCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "kv");
5381
- const decryptCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "encryption" && capability.resource === value.encryptionNetwork && capability.action === "tinycloud.encryption/decrypt");
5403
+ const expectedEncryptionResource = encryptionKeyPath === void 0 ? value.encryptionNetwork : `${value.encryptionNetwork}/${encryptionKeyPath}`;
5404
+ const decryptCapabilities = value.policy.capabilityCeiling.filter((capability) => capability.kind === "encryption" && capability.resource === expectedEncryptionResource && capability.action === "tinycloud.encryption/decrypt");
5382
5405
  if (value.policy.capabilityCeiling.length !== 2 || kvCapabilities.length !== 1 || decryptCapabilities.length !== 1 || kvCapabilities[0]?.resource !== value.contentSource.kvResource || kvCapabilities[0]?.selector !== value.contentSource.selector) {
5383
- ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "capabilityCeiling"], message: "policy ceiling must contain exact decrypt network" });
5406
+ ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["policy", "capabilityCeiling"], message: "policy ceiling must contain the exact decrypt resource" });
5384
5407
  }
5385
5408
  }
5386
5409
  var unsignedShareEnvelopeV3Schema = unsignedShareEnvelopeV3BaseSchema.superRefine(validateV3Invariants);