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

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
@@ -17157,6 +17157,7 @@ __export(index_exports, {
17157
17157
  parseExpiry: () => import_sdk_core12.parseExpiry,
17158
17158
  parseNetworkId: () => import_sdk_core17.parseNetworkId,
17159
17159
  parsePkhDid: () => import_sdk_core11.parsePkhDid,
17160
+ parseSecretCatalogKey: () => import_sdk_core16.parseSecretCatalogKey,
17160
17161
  parseSpaceUri: () => import_sdk_core21.parseSpaceUri,
17161
17162
  pkhDid: () => import_sdk_core11.pkhDid,
17162
17163
  principalDid: () => import_sdk_core11.principalDid,
@@ -19108,6 +19109,11 @@ var NodeSecretsService = class {
19108
19109
  if (!permission.ok) return permission;
19109
19110
  return options === void 0 ? this.service.list() : this.service.list(options);
19110
19111
  }
19112
+ async listAll() {
19113
+ const permission = await this.ensurePermission("", void 0, "list");
19114
+ if (!permission.ok) return permission;
19115
+ return this.service.listAll();
19116
+ }
19111
19117
  get service() {
19112
19118
  return this.config.getService();
19113
19119
  }
@@ -19169,7 +19175,11 @@ var NodeSecretsService = class {
19169
19175
  (entry) => manifests.some((candidate) => {
19170
19176
  const resolved = (0, import_sdk_core6.resolveManifest)(candidate);
19171
19177
  return resolved.resources.some(
19172
- (resource) => resource.service === entry.service && spaceMatches(resource.space, entry.space, this.config.resolveSpace) && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
19178
+ (resource) => resource.service === entry.service && spaceMatches(
19179
+ resource.space,
19180
+ entry.space,
19181
+ this.config.resolveSpace
19182
+ ) && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
19173
19183
  );
19174
19184
  })
19175
19185
  );
@@ -22211,63 +22221,19 @@ var _TinyCloudNode = class _TinyCloudNode {
22211
22221
  }
22212
22222
  };
22213
22223
  }
22214
- /** Register a policy that is already bound to an activated owner delegation. */
22215
- async registerOwnerSharePolicy(params) {
22224
+ /** Register a signed policy and sibling roots with this Node's Policy/v3 runtime. */
22225
+ async registerPolicy(params) {
22216
22226
  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
- })
22227
+ return (0, import_sdk_core7.registerPolicyV3)({
22228
+ ...params,
22229
+ nodeOrigin: this.config.host,
22230
+ fetch: globalThis.fetch.bind(globalThis)
22227
22231
  });
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
22232
  }
22240
- /** Authorize a short-lived, one-use v2 delivery using the authenticated invocation chain. */
22233
+ /** @deprecated Policy/v2 delivery transport is retired. Use authorizeShareDeliveryV3. */
22241
22234
  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 });
22235
+ void input;
22236
+ throw new Error("Policy/v2 share delivery is retired; use authorizeShareDeliveryV3");
22271
22237
  }
22272
22238
  /** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
22273
22239
  async authorizeShareDeliveryV3(input) {
@@ -22283,22 +22249,35 @@ var _TinyCloudNode = class _TinyCloudNode {
22283
22249
  shareUrl: input.shareUrl,
22284
22250
  documentName: input.documentName,
22285
22251
  jti: base64UrlEncode(crypto.getRandomValues(new Uint8Array(16))),
22286
- expiresAt: input.expiresAt
22252
+ expiresAt: new Date(input.expiresAt).toISOString().replace(/\.\d{3}Z$/, "Z")
22287
22253
  };
22288
22254
  const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0, import_sdk_core7.canonicalizeEncryptionJson)(body)))));
22289
22255
  const request = { ...body, requestBodyDigest };
22290
22256
  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`, {
22257
+ const response = await fetch(`${this.config.host}/policy/v3/deliveries/authorize`, {
22292
22258
  method: "POST",
22293
22259
  headers: { accept: "application/json", "content-type": "application/json", authorization },
22294
22260
  body: (0, import_sdk_core7.canonicalizeEncryptionJson)(request)
22295
22261
  });
22296
22262
  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()), {
22263
+ const verified = (0, import_sdk_core7.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
22298
22264
  request,
22299
- nodeProof: input.nodeProof,
22265
+ senderKeyDid: this.credentialHolderDid,
22300
22266
  credentialsAudience: input.credentialsAudience
22301
22267
  });
22268
+ void input.nodeProof;
22269
+ const requestDigest = new Uint8Array(await crypto.subtle.digest(
22270
+ "SHA-256",
22271
+ new TextEncoder().encode(`${import_sdk_core7.CREDENTIAL_INVITATION_REQUEST_DOMAIN}${(0, import_sdk_core7.canonicalizeEncryptionJson)(verified.request)}`)
22272
+ ));
22273
+ return {
22274
+ ...verified,
22275
+ proof: {
22276
+ alg: "EdDSA",
22277
+ kid: this.credentialHolderDid,
22278
+ signature: base64UrlEncode(await this.signSessionBytes(requestDigest))
22279
+ }
22280
+ };
22302
22281
  }
22303
22282
  async createRootDelegationForSharing(params, assertActive) {
22304
22283
  try {
@@ -25097,6 +25076,7 @@ var import_sdk_core23 = require("@tinycloud/sdk-core");
25097
25076
  parseExpiry,
25098
25077
  parseNetworkId,
25099
25078
  parsePkhDid,
25079
+ parseSecretCatalogKey,
25100
25080
  parseSpaceUri,
25101
25081
  pkhDid,
25102
25082
  principalDid,