@calimero-network/mero-js 27.3.0 → 27.4.0

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.mjs CHANGED
@@ -1000,6 +1000,7 @@ var NODE_RELEASE_SIGNER = Object.freeze({
1000
1000
  });
1001
1001
  var MEASUREMENTS = ["mrtd", "rtmr0", "rtmr1", "rtmr2", "rtmr3"];
1002
1002
  var DEFAULT_RELEASE_MIRROR = "https://cloud.calimero.network";
1003
+ var DEFAULT_COLLATERAL_MIRROR = `${DEFAULT_RELEASE_MIRROR}/api/tee/pcs`;
1003
1004
  async function verifySignedNodeRelease(publishedMrtds, bundle, options = {}) {
1004
1005
  const body = typeof publishedMrtds === "string" ? new TextEncoder().encode(publishedMrtds) : publishedMrtds;
1005
1006
  await verifyCosignBundle(
@@ -1164,6 +1165,34 @@ async function releaseFor(version, policy, fetchImpl) {
1164
1165
  if (source === "github") return fetchGithubNodeRelease(version, { fetch: fetchImpl });
1165
1166
  return fetchNodeRelease(cloudNodeReleaseUrl(source ?? DEFAULT_RELEASE_MIRROR, version), { fetch: fetchImpl });
1166
1167
  }
1168
+ function defaultCollateral(policy) {
1169
+ const source = policy.collateralSource ?? DEFAULT_COLLATERAL_MIRROR;
1170
+ if (source === "intel") {
1171
+ return async (quote) => (await dcap("getCollateralFromPcs"))(quote);
1172
+ }
1173
+ return async (quote) => (await dcap("getCollateral"))(source, quote);
1174
+ }
1175
+ function freshCollateral(fetch2, policy) {
1176
+ const maxDays = policy.maxCollateralAgeDays;
1177
+ if (maxDays === void 0) return fetch2;
1178
+ return async (quote) => {
1179
+ const collateral = await fetch2(quote);
1180
+ let issued;
1181
+ try {
1182
+ issued = Date.parse(JSON.parse(collateral.tcb_info).issueDate ?? "");
1183
+ } catch {
1184
+ issued = Number.NaN;
1185
+ }
1186
+ if (!Number.isFinite(issued)) throw new Error("The quote's collateral names no TCB info issue date");
1187
+ const ageDays = ((policy.now ?? Date.now)() - issued) / 864e5;
1188
+ if (ageDays > maxDays) {
1189
+ throw new Error(
1190
+ `The quote's collateral was issued ${Math.floor(ageDays)} days ago, more than the ${maxDays} this client accepts`
1191
+ );
1192
+ }
1193
+ return collateral;
1194
+ };
1195
+ }
1167
1196
  async function verifyRelease(doc, args, policy, fetchImpl) {
1168
1197
  const version = claimedRelease(doc, policy.minReleaseVersion);
1169
1198
  const trusted = await trustSignedRelease({
@@ -1174,7 +1203,7 @@ async function verifyRelease(doc, args, policy, fetchImpl) {
1174
1203
  identity: policy.identity,
1175
1204
  issuer: policy.issuer
1176
1205
  });
1177
- const fetchCollateral = policy.fetchCollateral ?? (async (quote) => (await dcap("getCollateralFromPcs"))(quote));
1206
+ const fetchCollateral = freshCollateral(policy.fetchCollateral ?? defaultCollateral(policy), policy);
1178
1207
  const verifier = createQuoteVerifier({
1179
1208
  dcapVerify: policy.dcapVerify ?? await dcap("verify"),
1180
1209
  fetchCollateral,
@@ -2869,6 +2898,7 @@ export {
2869
2898
  ConfirmCancelled,
2870
2899
  ConfirmRequired,
2871
2900
  ConsentStale,
2901
+ DEFAULT_COLLATERAL_MIRROR,
2872
2902
  DEFAULT_ORG_CAPABILITIES,
2873
2903
  DEFAULT_RELEASE_MIRROR,
2874
2904
  GITHUB_RELEASES,
@@ -2909,6 +2939,7 @@ export {
2909
2939
  fetchAttestedKey,
2910
2940
  fetchGithubNodeRelease,
2911
2941
  fetchNodeRelease,
2942
+ freshCollateral,
2912
2943
  fromB64url,
2913
2944
  generateOwnerKey,
2914
2945
  orgCapabilities,