@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.
package/dist/index.cjs CHANGED
@@ -8914,6 +8914,33 @@ function createError2(code3, message, cause, meta) {
8914
8914
  meta
8915
8915
  };
8916
8916
  }
8917
+ function rootDelegationSigningError(err6) {
8918
+ const cause = err6 instanceof Error ? err6 : void 0;
8919
+ const code3 = err6 && typeof err6 === "object" && "code" in err6 ? String(err6.code ?? "") : "";
8920
+ const name2 = err6 instanceof Error ? err6.name : "";
8921
+ const message = err6 instanceof Error ? err6.message : String(err6 ?? "");
8922
+ const aborted = code3 === DelegationErrorCodes.ABORTED || name2 === "AbortError" || /\bcancell?ed\b|\brejected\b|user denied/i.test(message);
8923
+ if (aborted) {
8924
+ return createError2(
8925
+ DelegationErrorCodes.ABORTED,
8926
+ "The signature that authorizes this sharing link was cancelled. Approve the signing prompt to finish creating the link.",
8927
+ cause
8928
+ );
8929
+ }
8930
+ const timedOut = code3 === DelegationErrorCodes.TIMEOUT || name2 === "TimeoutError" || /timed out|timeout/i.test(message);
8931
+ if (timedOut) {
8932
+ return createError2(
8933
+ DelegationErrorCodes.TIMEOUT,
8934
+ "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.",
8935
+ cause
8936
+ );
8937
+ }
8938
+ return createError2(
8939
+ DelegationErrorCodes.PERMISSION_DENIED,
8940
+ "The active session ReCap does not authorize this sharing delegation.",
8941
+ cause
8942
+ );
8943
+ }
8917
8944
  function base64UrlEncode2(data) {
8918
8945
  let base642;
8919
8946
  if (typeof btoa !== "undefined") {
@@ -9132,14 +9159,7 @@ var SharingService = class {
9132
9159
  };
9133
9160
  }
9134
9161
  } catch (err6) {
9135
- return {
9136
- ok: false,
9137
- error: createError2(
9138
- DelegationErrorCodes.PERMISSION_DENIED,
9139
- "The active session ReCap does not authorize this sharing delegation.",
9140
- err6 instanceof Error ? err6 : void 0
9141
- )
9142
- };
9162
+ return { ok: false, error: rootDelegationSigningError(err6) };
9143
9163
  }
9144
9164
  } else {
9145
9165
  return {
@@ -10106,6 +10126,10 @@ async function createPolicyEnforcementDelegation(input) {
10106
10126
  spaceId: input.spaceId,
10107
10127
  path: input.path,
10108
10128
  actions: [...input.actions],
10129
+ ...input.decryption === void 0 ? {} : {
10130
+ decryptionNetworkId: input.decryption.networkId,
10131
+ decryptionAction: input.decryption.action
10132
+ },
10109
10133
  contentSourceDigest: input.contentSourceDigest,
10110
10134
  expiresAt: input.expiresAt
10111
10135
  };
@@ -10125,7 +10149,9 @@ function computeOwnerShareRegistrationCid(registration) {
10125
10149
  function validateOwnerSharePolicyRegistration(value, expected) {
10126
10150
  if (cid(expected.policy.bytes) !== expected.policy.cid) throw new Error("submitted owner-share policy bytes do not match its CID");
10127
10151
  const root = assertObject(value, ["registration", "proof"], "owner-share registration response");
10128
- const registration = assertObject(root.registration, ["registrationCid", "policyCid", "ownerDelegationCid", "enforcementDelegationCid", "ownerDid", "shareKeyDid", "enforcerDid", "shareId", "recipientMatcher", "target", "resource", "actions", "contentSource", "contentSourceDigest", "registeredAt", "expiresAt"], "owner-share registration");
10152
+ const rawRegistration = root.registration;
10153
+ const hasDecryption = typeof rawRegistration === "object" && rawRegistration !== null && Object.prototype.hasOwnProperty.call(rawRegistration, "decryption");
10154
+ 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");
10129
10155
  const proof = assertObject(root.proof, ["alg", "kid", "signature"], "owner-share registration proof");
10130
10156
  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");
10131
10157
  let policyValue;
@@ -10141,7 +10167,9 @@ function validateOwnerSharePolicyRegistration(value, expected) {
10141
10167
  const registrationTarget = registration.target;
10142
10168
  const registrationResource = registration.resource;
10143
10169
  const enforcementFacts = expected.enforcementDelegation.facts;
10144
- 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");
10170
+ const decryption = policy.decryption;
10171
+ const decryptionMatches = decryption === void 0 ? registration.decryption === void 0 : registration.decryption !== void 0 && canonicalizeSignedObjectUnsigned(decryption) === canonicalizeSignedObjectUnsigned(registration.decryption);
10172
+ 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");
10145
10173
  if (typeof registration.registrationCid !== "string" || typeof registration.expiresAt !== "string" || typeof registration.registeredAt !== "string") throw new Error("owner-share registration timestamps are invalid");
10146
10174
  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");
10147
10175
  const { registrationCid: _registrationCid, ...registrationCore } = registration;