@tinycloud/share-sdk 1.4.1-beta.2 → 1.4.1-beta.4

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.
@@ -1,3 +1,3 @@
1
- export { f as ShareMetadata, r as ShareRecipientClient, u as inspectShare } from './web-recipient-entry-Bn3yRB7g.cjs';
1
+ export { f as ShareMetadata, r as ShareRecipientClient, u as inspectShare } from './web-recipient-entry-DF_BMFq8.cjs';
2
2
  import '@tinycloud/share-envelope';
3
3
  import './authorization-CmP1skO8.cjs';
@@ -1,3 +1,3 @@
1
- export { f as ShareMetadata, r as ShareRecipientClient, u as inspectShare } from './web-recipient-entry-CTFoIH8l.js';
1
+ export { f as ShareMetadata, r as ShareRecipientClient, u as inspectShare } from './web-recipient-entry-mcC6d4ao.js';
2
2
  import '@tinycloud/share-envelope';
3
3
  import './authorization-CmP1skO8.js';
@@ -6218,6 +6218,10 @@ function matchesInitialCiphertextDigest(bytes, expected) {
6218
6218
  function canonicalHashHex(value) {
6219
6219
  return hex2(sha2563(new TextEncoder().encode(canonicalize(value))));
6220
6220
  }
6221
+ function registeredWrappedKeyDigest(encryptedSymmetricKey, pathBound) {
6222
+ const rawDigest = hex2(sha2563(fromBase64(encryptedSymmetricKey, "v3 encrypted symmetric key")));
6223
+ return pathBound ? rawDigest : canonicalHashHex(encryptedSymmetricKey);
6224
+ }
6221
6225
  async function aesGcmDecrypt(key, blob, aad) {
6222
6226
  if (key.length !== 32 || blob.length < 28) throw new Error("encrypted content is malformed");
6223
6227
  const cryptoKey = await crypto.subtle.importKey("raw", key, "AES-GCM", false, ["decrypt"]);
@@ -6244,7 +6248,7 @@ function parseV3InlineEncryptedEnvelope(bytes, expected) {
6244
6248
  const record = value;
6245
6249
  const allowed = ["v", "networkId", "keyPath", "alg", "keyVersion", "encryptedSymmetricKey", "encryptedSymmetricKeyHash", "ciphertext", "aad", "metadata"];
6246
6250
  const source = expected.contentSource;
6247
- if (Object.keys(record).some((key) => !allowed.includes(key)) || record.v !== (source.encryptionKeyPath === void 0 ? 1 : 2) || record.networkId !== source.encryptionNetwork || record.networkId !== expected.encryptionNetwork || record.keyPath !== source.encryptionKeyPath || record.keyPath !== void 0 && record.keyPath !== `share/${expected.shareId}` || record.alg !== "x25519-aes256gcm/v1" || record.keyVersion !== source.keyVersion || typeof record.encryptedSymmetricKey !== "string" || typeof record.encryptedSymmetricKeyHash !== "string" || hex2(sha2563(fromBase64(record.encryptedSymmetricKey, "v3 encrypted symmetric key"))) !== source.encryptedSymmetricKeyDigestHex || record.encryptedSymmetricKeyHash !== canonicalHashHex(record.encryptedSymmetricKey) || typeof record.ciphertext !== "string" || record.aad !== void 0 && typeof record.aad !== "string" || record.metadata !== void 0 && (record.metadata === null || typeof record.metadata !== "object" || Array.isArray(record.metadata) || Object.values(record.metadata).some((entry) => typeof entry !== "string"))) {
6251
+ if (Object.keys(record).some((key) => !allowed.includes(key)) || record.v !== (source.encryptionKeyPath === void 0 ? 1 : 2) || record.networkId !== source.encryptionNetwork || record.networkId !== expected.encryptionNetwork || record.keyPath !== source.encryptionKeyPath || record.keyPath !== void 0 && record.keyPath !== `share/${expected.shareId}` || record.alg !== "x25519-aes256gcm/v1" || record.keyVersion !== source.keyVersion || typeof record.encryptedSymmetricKey !== "string" || typeof record.encryptedSymmetricKeyHash !== "string" || registeredWrappedKeyDigest(record.encryptedSymmetricKey, source.encryptionKeyPath !== void 0) !== source.encryptedSymmetricKeyDigestHex || record.encryptedSymmetricKeyHash !== canonicalHashHex(record.encryptedSymmetricKey) || typeof record.ciphertext !== "string" || record.aad !== void 0 && typeof record.aad !== "string" || record.metadata !== void 0 && (record.metadata === null || typeof record.metadata !== "object" || Array.isArray(record.metadata) || Object.values(record.metadata).some((entry) => typeof entry !== "string"))) {
6248
6252
  throw new Error("encrypted content envelope binding is invalid");
6249
6253
  }
6250
6254
  return record;
@@ -6365,7 +6369,11 @@ var ShareRecipientClient = class {
6365
6369
  this.session = { sessionId: delegation.sessionCid, expiresAt: new Date(compact.payload.exp * 1e3).toISOString(), actions: envelope.actions, resource: envelope.resource };
6366
6370
  return this.session;
6367
6371
  }
6368
- /** Decrypt unscoped v1 or path-bound v2 content, independently checking canonical and registered raw-key digests. */
6372
+ /**
6373
+ * Decrypt unscoped v1 or path-bound v2 content. The wrapped-key digest is compared by source kind: the raw-byte digest
6374
+ * when the source has `encryptionKeyPath`, the canonical hash for a no-path source. The envelope's own canonical hash
6375
+ * is checked independently either way.
6376
+ */
6369
6377
  async decryptV3Content(bytes) {
6370
6378
  const envelope = this.options.envelope;
6371
6379
  const signer = this.nativeSigner ?? this.signer;