@tinycloud/node-sdk 3.6.1 → 3.7.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
@@ -25249,8 +25249,14 @@ var _TinyCloudNode = class _TinyCloudNode {
25249
25249
  fetch: globalThis.fetch.bind(globalThis)
25250
25250
  });
25251
25251
  }
25252
- /** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
25252
+ /**
25253
+ * Authorize one short-lived v3 delivery. `shareUrl` is the short `/s/<id>#v=4&k=…&c=…` link: the node fetches the
25254
+ * sealed body by id and opens it with the link's key, so the body of the request carries the link and nothing else
25255
+ * of the share. `envelope` is the signed v3 envelope the sender holds; it checks the node's admission here and is
25256
+ * not sent.
25257
+ */
25253
25258
  async authorizeShareDeliveryV3(input) {
25259
+ const envelopeRef = await (0, import_sdk_core10.shortDeliveryLinkBodyCid)(input.shareUrl, input.trustedOrigins);
25254
25260
  const session = this.currentTinyCloudSession();
25255
25261
  const serviceSession = this._serviceContext?.session;
25256
25262
  if (!session || !serviceSession) throw new Error("Share delivery requires an authenticated session");
@@ -25260,15 +25266,12 @@ var _TinyCloudNode = class _TinyCloudNode {
25260
25266
  }
25261
25267
  const jtiDigest = new Uint8Array(await crypto.subtle.digest("SHA-256", idempotencyBytes));
25262
25268
  const body = {
25263
- envelope: input.envelope,
25264
- sealedEnvelope: input.sealedEnvelope,
25265
- envelopeKey: input.envelopeKey,
25266
- shareCid: input.shareCid,
25267
25269
  recipientEmail: input.recipientEmail,
25268
25270
  shareUrl: input.shareUrl,
25269
25271
  documentName: input.documentName,
25270
25272
  jti: base64UrlEncode(jtiDigest.slice(0, 16)),
25271
- expiresAt: new Date(input.expiresAt).toISOString().replace(/\.\d{3}Z$/, "Z")
25273
+ // Re-normalised through Date, so the sent value is always `YYYY-MM-DDTHH:mm:ss.SSSZ` (UTC, three digits).
25274
+ expiresAt: new Date(input.expiresAt).toISOString()
25272
25275
  };
25273
25276
  const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0, import_sdk_core10.canonicalizeEncryptionJson)(body)))));
25274
25277
  const request = { ...body, requestBodyDigest };
@@ -25278,9 +25281,16 @@ var _TinyCloudNode = class _TinyCloudNode {
25278
25281
  headers: { accept: "application/json", "content-type": "application/json", authorization },
25279
25282
  body: (0, import_sdk_core10.canonicalizeEncryptionJson)(request)
25280
25283
  });
25281
- if (!response.ok) throw await (0, import_sdk_core10.httpResponseError)(response, "V3 share delivery authorization failed");
25282
- const verified = (0, import_sdk_core10.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
25284
+ if (response.status === 400 || response.status === 422) throw new import_sdk_core10.ShareDeliveryRefusedError();
25285
+ if (!response.ok) {
25286
+ const reply = await response.text().catch(() => response.statusText);
25287
+ const body2 = (await (0, import_sdk_core10.withoutShareLink)(reply, input.shareUrl)).trim().slice(0, 512);
25288
+ throw Object.assign(new Error(`V3 share delivery authorization failed: HTTP ${response.status}${body2 ? ` - ${body2}` : ""}`), { status: response.status });
25289
+ }
25290
+ const verified = await (0, import_sdk_core10.verifyShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
25283
25291
  request,
25292
+ envelope: input.envelope,
25293
+ envelopeRef,
25284
25294
  senderKeyDid: this.credentialHolderDid,
25285
25295
  deliveryAudience: input.deliveryAudience
25286
25296
  });