@tinycloud/sdk-core 2.10.0 → 2.11.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.
@@ -4742,6 +4742,33 @@ function createError2(code3, message, cause, meta) {
4742
4742
  meta
4743
4743
  };
4744
4744
  }
4745
+ function rootDelegationSigningError(err) {
4746
+ const cause = err instanceof Error ? err : void 0;
4747
+ const code3 = err && typeof err === "object" && "code" in err ? String(err.code ?? "") : "";
4748
+ const name2 = err instanceof Error ? err.name : "";
4749
+ const message = err instanceof Error ? err.message : String(err ?? "");
4750
+ const aborted = code3 === DelegationErrorCodes.ABORTED || name2 === "AbortError" || /\bcancell?ed\b|\brejected\b|user denied/i.test(message);
4751
+ if (aborted) {
4752
+ return createError2(
4753
+ DelegationErrorCodes.ABORTED,
4754
+ "The signature that authorizes this sharing link was cancelled. Approve the signing prompt to finish creating the link.",
4755
+ cause
4756
+ );
4757
+ }
4758
+ const timedOut = code3 === DelegationErrorCodes.TIMEOUT || name2 === "TimeoutError" || /timed out|timeout/i.test(message);
4759
+ if (timedOut) {
4760
+ return createError2(
4761
+ DelegationErrorCodes.TIMEOUT,
4762
+ "Timed out waiting for the signature that authorizes this sharing link. Creating a long-lived link re-opens the signing prompt after sign-in; if you did not see one, check for a blocked popup or a hidden signing frame, then try again.",
4763
+ cause
4764
+ );
4765
+ }
4766
+ return createError2(
4767
+ DelegationErrorCodes.PERMISSION_DENIED,
4768
+ "The active session ReCap does not authorize this sharing delegation.",
4769
+ cause
4770
+ );
4771
+ }
4745
4772
  function base64UrlEncode(data) {
4746
4773
  let base642;
4747
4774
  if (typeof btoa !== "undefined") {
@@ -4960,14 +4987,7 @@ var SharingService = class {
4960
4987
  };
4961
4988
  }
4962
4989
  } catch (err) {
4963
- return {
4964
- ok: false,
4965
- error: createError2(
4966
- DelegationErrorCodes.PERMISSION_DENIED,
4967
- "The active session ReCap does not authorize this sharing delegation.",
4968
- err instanceof Error ? err : void 0
4969
- )
4970
- };
4990
+ return { ok: false, error: rootDelegationSigningError(err) };
4971
4991
  }
4972
4992
  } else {
4973
4993
  return {
@@ -6171,6 +6191,10 @@ async function createPolicyEnforcementDelegation(input) {
6171
6191
  spaceId: input.spaceId,
6172
6192
  path: input.path,
6173
6193
  actions: [...input.actions],
6194
+ ...input.decryption === void 0 ? {} : {
6195
+ decryptionNetworkId: input.decryption.networkId,
6196
+ decryptionAction: input.decryption.action
6197
+ },
6174
6198
  contentSourceDigest: input.contentSourceDigest,
6175
6199
  expiresAt: input.expiresAt
6176
6200
  };
@@ -6190,7 +6214,9 @@ function computeOwnerShareRegistrationCid(registration) {
6190
6214
  function validateOwnerSharePolicyRegistration(value, expected) {
6191
6215
  if (cid(expected.policy.bytes) !== expected.policy.cid) throw new Error("submitted owner-share policy bytes do not match its CID");
6192
6216
  const root = assertObject(value, ["registration", "proof"], "owner-share registration response");
6193
- const registration = assertObject(root.registration, ["registrationCid", "policyCid", "ownerDelegationCid", "enforcementDelegationCid", "ownerDid", "shareKeyDid", "enforcerDid", "shareId", "recipientMatcher", "target", "resource", "actions", "contentSource", "contentSourceDigest", "registeredAt", "expiresAt"], "owner-share registration");
6217
+ const rawRegistration = root.registration;
6218
+ const hasDecryption = typeof rawRegistration === "object" && rawRegistration !== null && Object.prototype.hasOwnProperty.call(rawRegistration, "decryption");
6219
+ const registration = assertObject(root.registration, ["registrationCid", "policyCid", "ownerDelegationCid", "enforcementDelegationCid", "ownerDid", "shareKeyDid", "enforcerDid", "shareId", "recipientMatcher", "target", "resource", "actions", ...hasDecryption ? ["decryption"] : [], "contentSource", "contentSourceDigest", "registeredAt", "expiresAt"], "owner-share registration");
6194
6220
  const proof = assertObject(root.proof, ["alg", "kid", "signature"], "owner-share registration proof");
6195
6221
  if (registration.policyCid !== expected.policy.cid || registration.ownerDelegationCid !== expected.ownerDelegation.delegationCid || registration.enforcementDelegationCid !== expected.enforcementDelegation.cid || registration.contentSourceDigest !== expected.contentSourceDigest) throw new Error("owner-share registration is not bound to the submitted chain");
6196
6222
  let policyValue;
@@ -6206,7 +6232,9 @@ function validateOwnerSharePolicyRegistration(value, expected) {
6206
6232
  const registrationTarget = registration.target;
6207
6233
  const registrationResource = registration.resource;
6208
6234
  const enforcementFacts = expected.enforcementDelegation.facts;
6209
- if (typeof target?.origin !== "string" || typeof target.nodeAudience !== "string" || typeof target.enforcerDid !== "string" || typeof target.spaceId !== "string" || typeof resource?.kind !== "string" || !["exact", "prefix"].includes(resource.kind) || typeof resource?.path !== "string" || !Array.isArray(policy.actions) || policy.ownerDid !== registration.ownerDid || policy.shareKeyDid !== registration.shareKeyDid || policy.shareId !== registration.shareId || canonicalizeSignedObjectUnsigned(policy.recipientMatcher) !== canonicalizeSignedObjectUnsigned(registration.recipientMatcher) || target.origin !== registrationTarget.origin || target.nodeAudience !== registrationTarget.nodeAudience || target.enforcerDid !== registration.enforcerDid || target.spaceId !== registrationTarget.spaceId || resource.kind !== registrationResource.kind || resource.path !== registrationResource.path || canonicalizeSignedObjectUnsigned(policy.actions) !== canonicalizeSignedObjectUnsigned(registration.actions) || canonicalizeSignedObjectUnsigned(policy.contentSource) !== canonicalizeSignedObjectUnsigned(registration.contentSource) || policy.expiresAt !== registration.expiresAt || policy.contentSourceDigest !== registration.contentSourceDigest || enforcementFacts.ownerDelegationCid !== registration.ownerDelegationCid || enforcementFacts.policyCid !== registration.policyCid || enforcementFacts.shareKeyDid !== registration.shareKeyDid || enforcementFacts.enforcerDid !== registration.enforcerDid || enforcementFacts.nodeAudience !== registrationTarget.nodeAudience || enforcementFacts.spaceId !== registrationTarget.spaceId || enforcementFacts.path !== registrationResource.path || canonicalizeSignedObjectUnsigned(enforcementFacts.actions) !== canonicalizeSignedObjectUnsigned(registration.actions) || enforcementFacts.expiresAt !== registration.expiresAt) throw new Error("owner-share registration is not bound to the canonical policy");
6235
+ const decryption = policy.decryption;
6236
+ const decryptionMatches = decryption === void 0 ? registration.decryption === void 0 : registration.decryption !== void 0 && canonicalizeSignedObjectUnsigned(decryption) === canonicalizeSignedObjectUnsigned(registration.decryption);
6237
+ if (typeof target?.origin !== "string" || typeof target.nodeAudience !== "string" || typeof target.enforcerDid !== "string" || typeof target.spaceId !== "string" || typeof resource?.kind !== "string" || !["exact", "prefix"].includes(resource.kind) || typeof resource?.path !== "string" || !Array.isArray(policy.actions) || policy.ownerDid !== registration.ownerDid || policy.shareKeyDid !== registration.shareKeyDid || policy.shareId !== registration.shareId || canonicalizeSignedObjectUnsigned(policy.recipientMatcher) !== canonicalizeSignedObjectUnsigned(registration.recipientMatcher) || target.origin !== registrationTarget.origin || target.nodeAudience !== registrationTarget.nodeAudience || target.enforcerDid !== registration.enforcerDid || target.spaceId !== registrationTarget.spaceId || resource.kind !== registrationResource.kind || resource.path !== registrationResource.path || canonicalizeSignedObjectUnsigned(policy.actions) !== canonicalizeSignedObjectUnsigned(registration.actions) || !decryptionMatches || canonicalizeSignedObjectUnsigned(policy.contentSource) !== canonicalizeSignedObjectUnsigned(registration.contentSource) || policy.expiresAt !== registration.expiresAt || policy.contentSourceDigest !== registration.contentSourceDigest || enforcementFacts.ownerDelegationCid !== registration.ownerDelegationCid || enforcementFacts.policyCid !== registration.policyCid || enforcementFacts.shareKeyDid !== registration.shareKeyDid || enforcementFacts.enforcerDid !== registration.enforcerDid || enforcementFacts.nodeAudience !== registrationTarget.nodeAudience || enforcementFacts.spaceId !== registrationTarget.spaceId || enforcementFacts.path !== registrationResource.path || canonicalizeSignedObjectUnsigned(enforcementFacts.actions) !== canonicalizeSignedObjectUnsigned(registration.actions) || enforcementFacts.decryptionNetworkId !== decryption?.networkId || enforcementFacts.decryptionAction !== decryption?.action || enforcementFacts.expiresAt !== registration.expiresAt) throw new Error("owner-share registration is not bound to the canonical policy");
6210
6238
  if (typeof registration.registrationCid !== "string" || typeof registration.expiresAt !== "string" || typeof registration.registeredAt !== "string") throw new Error("owner-share registration timestamps are invalid");
6211
6239
  if (new Date(registration.expiresAt).toISOString() !== registration.expiresAt || Date.parse(registration.expiresAt) <= Date.now()) throw new Error("owner-share registration is expired or non-canonical");
6212
6240
  const { registrationCid: _registrationCid, ...registrationCore } = registration;