@tinycloud/share-sdk 1.0.0-beta.4 → 1.0.0-beta.5

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.
package/dist/index.cjs CHANGED
@@ -6729,10 +6729,23 @@ function publicationResult(input) {
6729
6729
  Object.defineProperty(result, "deliveryMaterial", { enumerable: false, value: input.deliveryMaterial });
6730
6730
  return result;
6731
6731
  }
6732
+ var EMAIL_DOMAIN_PROFILE = { id: "tinycloud.email-domain-proof/v1", version: 1 };
6733
+ var EMAIL_CREDENTIAL_TYPE = { id: "opencredentials.email/v1", version: 1 };
6734
+ var EMAIL_DOMAIN_DESCRIPTOR_DIGEST = "33X5mAkZZgApdD3xh_T-3KS5moop0J2Nloi2nqWsdWY";
6735
+ function assertEmailDomainPolicy(options, domain) {
6736
+ if (!options.actions.every((action) => action === "read" || action === "list") || !options.policyActions.every((action) => action === "tinycloud.kv/get" || action === "tinycloud.kv/list" || action === "tinycloud.kv/metadata")) throw new TypeError("email-domain shares are view-only");
6737
+ if (options.deliveryEmail !== void 0) throw new TypeError("email-domain shares are not emailed");
6738
+ const commitment = options.credentialRequirement;
6739
+ if (commitment === void 0) throw new TypeError("email-domain shares require a credential requirement");
6740
+ if (canonicalize(commitment.profile) !== canonicalize(EMAIL_DOMAIN_PROFILE) || canonicalize(commitment.credentialType) !== canonicalize(EMAIL_CREDENTIAL_TYPE) || commitment.descriptorDigest !== EMAIL_DOMAIN_DESCRIPTOR_DIGEST) throw new TypeError("email-domain shares require the email-domain credential profile");
6741
+ const expected = { type: "TinyCloudCredentialRequirement", version: 1, profile: EMAIL_DOMAIN_PROFILE, credentialType: EMAIL_CREDENTIAL_TYPE, claims: { emailDomain: domain }, maxAgeSeconds: 300 };
6742
+ if (toBase64Url((0, import_sha2562.sha256)(textEncoder.encode(canonicalize(expected)))) !== commitment.requirementDigest) throw new TypeError("credential requirement is not bound to the email domain");
6743
+ }
6732
6744
  async function publishAddressedShare(options) {
6733
6745
  assertSafeInput(options);
6734
6746
  const target = normalizeShareTarget(options.target);
6735
6747
  if (target.kind === "bearer") throw new TypeError("addressed target is required");
6748
+ if (target.kind === "emailDomain") assertEmailDomainPolicy(options, target.domain);
6736
6749
  const expiry = rfc3339Seconds(options.expiresAt);
6737
6750
  const matcher = targetMatcher(target);
6738
6751
  const capabilities = sortCanonical([