@tinycloud/share-sdk 1.4.4 → 1.5.0-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.
package/dist/index.cjs CHANGED
@@ -5874,6 +5874,7 @@ function canonicalMailbox(value) {
5874
5874
  if (local.length > 64 || !/^[a-z0-9#$&'*+/=?^_`{|}~-]+(?:\.[a-z0-9#$&'*+/=?^_`{|}~-]+)*$/.test(local) || !isCanonicalEmailDomain(domain)) return void 0;
5875
5875
  return Object.freeze({ email, domain });
5876
5876
  }
5877
+ var POLICY_ROOT_MAX_LIFETIME_SECONDS = 31 * 24 * 60 * 60;
5877
5878
  async function signCompactUcanAuthorization(input) {
5878
5879
  if (input.notBefore >= input.expiresAt || input.expiresAt - input.notBefore > 60) {
5879
5880
  throw new TypeError("compact invocation lifetime must be between one and 60 seconds");
@@ -6633,7 +6634,7 @@ function canonicalKeyHashHex(encryptedSymmetricKey) {
6633
6634
  }
6634
6635
  function pathBoundSessionPermissions(input) {
6635
6636
  const encryptionNetwork = assertNetwork(input.encryptionNetwork);
6636
- return [{ service: "tinycloud.encryption", path: `${encryptionNetwork}/share/`, actions: ["tinycloud.encryption/decrypt", "tinycloud.encryption/key.create"] }];
6637
+ return [{ service: "tinycloud.encryption", path: `${encryptionNetwork}/share/`, actions: ["tinycloud.encryption/decrypt"] }];
6637
6638
  }
6638
6639
  function planPathBoundShare(input) {
6639
6640
  const keyPath = pathBoundKeyPath(input.shareId);
@@ -6644,9 +6645,7 @@ function planPathBoundShare(input) {
6644
6645
  encryptionNetwork,
6645
6646
  keyPath,
6646
6647
  keyResource,
6647
- requiredPermissions: [{ service: "tinycloud.encryption", path: keyResource, actions: ["tinycloud.encryption/key.create"] }],
6648
- sessionPermissions: pathBoundSessionPermissions({ encryptionNetwork }),
6649
- registrationPermissions: [{ service: "tinycloud.encryption", path: `${encryptionNetwork}/share/`, actions: ["tinycloud.encryption/decrypt"] }],
6648
+ registrationPermissions: pathBoundSessionPermissions({ encryptionNetwork }),
6650
6649
  encryptOptions: (extra) => ({ networkId: encryptionNetwork, ...extra?.metadata === void 0 ? {} : { metadata: { ...extra.metadata } } })
6651
6650
  };
6652
6651
  }
@@ -6700,34 +6699,11 @@ function bindPathBoundContentSource(input) {
6700
6699
  initialCiphertextDigestHex: hex2((0, import_sha2562.sha256)(expected))
6701
6700
  };
6702
6701
  }
6703
- function isUnauthorized(error) {
6704
- const value = error;
6705
- return value !== null && typeof value === "object" && (value.status === 401 || value.status === 403 || value.code === "PERMISSION_DENIED" || value.code === "AUTH_UNAUTHORIZED");
6706
- }
6707
6702
  async function encryptAddressedShareContent(input) {
6708
6703
  const { plan, keys } = input;
6709
6704
  const byteLength = input.plaintext.byteLength;
6710
- let receipt;
6711
- try {
6712
- receipt = await keys.createKey(plan.keyPath, { networkId: plan.encryptionNetwork });
6713
- } catch (error) {
6714
- if (isUnauthorized(error)) {
6715
- const status = error.status;
6716
- throw new AddressedContentSourceError(
6717
- "key-not-authorized",
6718
- `the owner session does not hold tinycloud.encryption/key.create on ${plan.keyResource} (the node answers "Unauthorized Action: ${plan.keyResource} / tinycloud.encryption/key.create"); hold it either at sign-in (put plan.sessionPermissions in the manifest: key.create on ${plan.encryptionNetwork}/share/) or per share (requestPermissions(plan.requiredPermissions)) before creating the key` + (status === 403 ? "; if the owner signs in through OpenKey, the request must come from a first-party TinyCloud origin" : "")
6719
- );
6720
- }
6721
- throw error;
6722
- }
6723
- if (receipt.networkId !== plan.encryptionNetwork || receipt.keyPath !== plan.keyPath || receipt.state !== void 0 && receipt.state !== "active") {
6724
- throw new AddressedContentSourceError("key-receipt-mismatch", "the created key does not match this share");
6725
- }
6726
6705
  const envelope = await keys.encrypt(plan.keyPath, input.plaintext, plan.encryptOptions(input.metadata === void 0 ? void 0 : { metadata: input.metadata }));
6727
6706
  assertEnvelope(plan, envelope);
6728
- if (receipt.keyVersion !== void 0 && envelope.keyVersion !== receipt.keyVersion) {
6729
- throw new AddressedContentSourceError("key-receipt-mismatch", "the envelope key version does not match the created key");
6730
- }
6731
6707
  const storedBytes = pathBoundStoredBytes(envelope);
6732
6708
  return { envelope, storedBytes, byteLength };
6733
6709
  }