@calimero-network/mero-js 22.2.0 → 22.3.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.cjs CHANGED
@@ -7965,8 +7965,24 @@ function nodeReleaseVersionFromImage(osImage) {
7965
7965
  return `${Number(match[1])}.${Number(match[2])}.${Number(match[3])}`;
7966
7966
  }
7967
7967
  async function fetchNodeReleaseVersion(baseUrl, options = {}) {
7968
- const url = `${baseUrl.replace(/\/+$/, "")}/admin-api/tee/info`;
7969
- const response = await (options.fetch ?? fetch)(url, { headers: { accept: "application/json" } });
7968
+ const version = await readNodeReleaseVersion(baseUrl, options.fetch ?? fetch);
7969
+ if (version === void 0) {
7970
+ throw new Error(
7971
+ `${infoUrl(baseUrl)} was refused unsealed: the node requires sealing and is too old to name its release before a session exists. Name the release it runs yourself (createSignedReleaseSealedFetch's \`releaseVersion\`), or upgrade the node`
7972
+ );
7973
+ }
7974
+ return version;
7975
+ }
7976
+ function infoUrl(baseUrl) {
7977
+ return `${baseUrl.replace(/\/+$/, "")}/admin-api/tee/info`;
7978
+ }
7979
+ async function readNodeReleaseVersion(baseUrl, givenFetch) {
7980
+ const url = infoUrl(baseUrl);
7981
+ const response = await givenFetch(url, { headers: { accept: "application/json" } });
7982
+ if (response.status === 403) {
7983
+ const code = await response.json().then((body) => body?.error?.code).catch(() => void 0);
7984
+ if (code === "sealed_required") return void 0;
7985
+ }
7970
7986
  if (!response.ok) throw new Error(`Fetching ${url} failed: HTTP ${response.status}`);
7971
7987
  let osImage;
7972
7988
  try {
@@ -8013,10 +8029,19 @@ function createSignedReleaseVerifier(options) {
8013
8029
  return Object.assign(verifier, { includeCollateral: true });
8014
8030
  }
8015
8031
  function createSignedReleaseSealedFetch(options) {
8016
- const { baseUrl, releaseSource, applicationId, applicationHash, fetch: givenFetch, ...verifierOptions } = options;
8032
+ const {
8033
+ baseUrl,
8034
+ releaseSource,
8035
+ releaseVersion: fallbackVersion,
8036
+ applicationId,
8037
+ applicationHash,
8038
+ fetch: givenFetch,
8039
+ ...verifierOptions
8040
+ } = options;
8041
+ if (fallbackVersion !== void 0) releaseVersion(fallbackVersion, "releaseVersion");
8017
8042
  const baseFetch = givenFetch ?? ((input, init) => fetch(input, init));
8018
8043
  const release = async () => {
8019
- const version = await fetchNodeReleaseVersion(baseUrl, { fetch: baseFetch });
8044
+ const version = fallbackVersion === void 0 ? await fetchNodeReleaseVersion(baseUrl, { fetch: baseFetch }) : await readNodeReleaseVersion(baseUrl, baseFetch) ?? fallbackVersion;
8020
8045
  return typeof releaseSource === "function" ? releaseSource({ baseUrl, version, fetch: baseFetch }) : fetchNodeRelease(cloudNodeReleaseUrl(releaseSource ?? DEFAULT_RELEASE_MIRROR, version), { fetch: baseFetch });
8021
8046
  };
8022
8047
  return createAttestedSealedFetch({