@tinycloud/node-sdk 3.0.0-beta.6 → 3.0.0-beta.7

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
@@ -22211,63 +22211,19 @@ var _TinyCloudNode = class _TinyCloudNode {
22211
22211
  }
22212
22212
  };
22213
22213
  }
22214
- /** Register a policy that is already bound to an activated owner delegation. */
22215
- async registerOwnerSharePolicy(params) {
22214
+ /** Register a signed policy and sibling roots with this Node's Policy/v3 runtime. */
22215
+ async registerPolicy(params) {
22216
22216
  this._serviceGraph.assertActive();
22217
- if (params.policy.bytes.byteLength > 2 * 1024 * 1024) throw new Error("Owner share policy is too large");
22218
- const response = await fetch(`${this.config.host}/share/v2/policies`, {
22219
- method: "POST",
22220
- headers: { "content-type": "application/json", accept: "application/json" },
22221
- body: JSON.stringify({
22222
- policy: { bytes: base64UrlEncode(params.policy.bytes), cid: params.policy.cid, proof: params.policy.proof },
22223
- ownerDelegation: { cid: params.ownerDelegation.delegationCid, dagCbor: base64UrlEncode(params.ownerDelegation.signedDagCbor) },
22224
- enforcementDelegation: params.enforcementDelegation,
22225
- contentSourceDigest: params.contentSourceDigest
22226
- })
22217
+ return (0, import_sdk_core7.registerPolicyV3)({
22218
+ ...params,
22219
+ nodeOrigin: this.config.host,
22220
+ fetch: globalThis.fetch.bind(globalThis)
22227
22221
  });
22228
- if (!response.ok) {
22229
- let code = "";
22230
- try {
22231
- const body = await response.clone().json();
22232
- if (typeof body.error?.code === "string") code = ` ${body.error.code}`;
22233
- } catch {
22234
- }
22235
- throw new Error(`Owner share policy registration failed: ${response.status}${code}`);
22236
- }
22237
- const responseBytes = new Uint8Array(await response.arrayBuffer());
22238
- return (0, import_sdk_core7.validateOwnerSharePolicyRegistrationBytes)(responseBytes, params);
22239
22222
  }
22240
- /** Authorize a short-lived, one-use v2 delivery using the authenticated invocation chain. */
22223
+ /** @deprecated Policy/v2 delivery transport is retired. Use authorizeShareDeliveryV3. */
22241
22224
  async authorizeShareDelivery(input) {
22242
- const session = this.currentTinyCloudSession();
22243
- const serviceSession = this._serviceContext?.session;
22244
- if (!session || !serviceSession) throw new Error("Share delivery requires an authenticated session");
22245
- const body = {
22246
- envelopeCid: input.envelopeCid,
22247
- shareCid: input.shareCid,
22248
- shareId: input.shareId,
22249
- registrationCid: input.registrationCid,
22250
- policyCid: input.policyCid,
22251
- delegationCid: input.delegationCid,
22252
- enforcementDelegationCid: input.enforcementDelegationCid,
22253
- recipientEmail: input.recipientEmail,
22254
- shareUrl: input.shareUrl,
22255
- documentName: input.documentName,
22256
- jti: base64UrlEncode(crypto.getRandomValues(new Uint8Array(16))),
22257
- idempotencyKey: input.idempotencyKey,
22258
- expiresAt: input.expiresAt
22259
- };
22260
- const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0, import_sdk_core7.canonicalizeEncryptionJson)(body)))));
22261
- const request = { ...body, requestBodyDigest };
22262
- const authorization = authorizationHeader(this.invokeAnyWithRuntimePermissions(serviceSession, [{ spaceId: session.spaceId, service: "kv", path: input.resourcePath, action: "tinycloud.kv/get" }]));
22263
- const response = await fetch(`${this.config.host}/share/v2/deliveries/authorize`, {
22264
- method: "POST",
22265
- headers: { accept: "application/json", "content-type": "application/json", authorization },
22266
- body: (0, import_sdk_core7.canonicalizeEncryptionJson)(request)
22267
- });
22268
- if (!response.ok) throw new Error(`Share delivery authorization failed: ${response.status}`);
22269
- const responseBytes = new Uint8Array(await response.arrayBuffer());
22270
- return (0, import_sdk_core7.validateShareDeliveryAuthorizationBytes)(responseBytes, { request, nodeProof: input.nodeProof, credentialsAudience: input.credentialsAudience });
22225
+ void input;
22226
+ throw new Error("Policy/v2 share delivery is retired; use authorizeShareDeliveryV3");
22271
22227
  }
22272
22228
  /** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
22273
22229
  async authorizeShareDeliveryV3(input) {
@@ -22283,22 +22239,35 @@ var _TinyCloudNode = class _TinyCloudNode {
22283
22239
  shareUrl: input.shareUrl,
22284
22240
  documentName: input.documentName,
22285
22241
  jti: base64UrlEncode(crypto.getRandomValues(new Uint8Array(16))),
22286
- expiresAt: input.expiresAt
22242
+ expiresAt: new Date(input.expiresAt).toISOString().replace(/\.\d{3}Z$/, "Z")
22287
22243
  };
22288
22244
  const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0, import_sdk_core7.canonicalizeEncryptionJson)(body)))));
22289
22245
  const request = { ...body, requestBodyDigest };
22290
22246
  const authorization = authorizationHeader(this.invokeAnyWithRuntimePermissions(serviceSession, [{ spaceId: session.spaceId, service: "kv", path: input.resourcePath, action: "tinycloud.kv/get" }]));
22291
- const response = await fetch(`${this.config.host}/share/v3/deliveries/authorize`, {
22247
+ const response = await fetch(`${this.config.host}/policy/v3/deliveries/authorize`, {
22292
22248
  method: "POST",
22293
22249
  headers: { accept: "application/json", "content-type": "application/json", authorization },
22294
22250
  body: (0, import_sdk_core7.canonicalizeEncryptionJson)(request)
22295
22251
  });
22296
22252
  if (!response.ok) throw new Error(`V3 share delivery authorization failed: ${response.status}`);
22297
- return (0, import_sdk_core7.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
22253
+ const verified = (0, import_sdk_core7.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
22298
22254
  request,
22299
- nodeProof: input.nodeProof,
22255
+ senderKeyDid: this.credentialHolderDid,
22300
22256
  credentialsAudience: input.credentialsAudience
22301
22257
  });
22258
+ void input.nodeProof;
22259
+ const requestDigest = new Uint8Array(await crypto.subtle.digest(
22260
+ "SHA-256",
22261
+ new TextEncoder().encode(`${import_sdk_core7.CREDENTIAL_INVITATION_REQUEST_DOMAIN}${(0, import_sdk_core7.canonicalizeEncryptionJson)(verified.request)}`)
22262
+ ));
22263
+ return {
22264
+ ...verified,
22265
+ proof: {
22266
+ alg: "EdDSA",
22267
+ kid: this.credentialHolderDid,
22268
+ signature: base64UrlEncode(await this.signSessionBytes(requestDigest))
22269
+ }
22270
+ };
22302
22271
  }
22303
22272
  async createRootDelegationForSharing(params, assertActive) {
22304
22273
  try {