@qorechain/sdk 0.8.0 → 0.8.1

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/README.md CHANGED
@@ -131,8 +131,8 @@ v2: "qorechain-pqc-hybrid-v2" ‖ BE64(len chainId) ‖ chainId ‖ BE32(len B0)
131
131
  ```
132
132
 
133
133
  A network verifies exactly **one** form at any height. `qorechain-diana`
134
- (testnet) switched to v2 at its v3.1.98 upgrade; `qorechain-vladi` (mainnet)
135
- stays on v1 until its own upgrade; chains born later are v2 from genesis. So pass
134
+ (testnet) switched to v2 at its `v3.1.98` upgrade; `qorechain-vladi` (mainnet)
135
+ stays on v1 until its own, named `v3.2.0`; chains born later are v2 from genesis. So pass
136
136
  the network's REST endpoint and let the SDK ask (`signBytesVersion: "auto"`, the
137
137
  default):
138
138
 
@@ -148,8 +148,12 @@ const res = await signAndBroadcastHybrid({
148
148
  });
149
149
  ```
150
150
 
151
- - `"auto"` reads `GET {rest}/cosmos/upgrade/v1beta1/applied_plan/v3.1.98` (v2 when
152
- the applied height is above 0) and caches the answer for about a minute.
151
+ - `"auto"` reads `GET {rest}/cosmos/upgrade/v1beta1/applied_plan/<name>` for each
152
+ name in `SIGN_BYTES_V2_UPGRADES` (`"v3.2.0"`, then `"v3.1.98"`), stopping at the
153
+ first applied height above 0, and caches the answer for about a minute. Both
154
+ names matter: the testnet switched under `v3.1.98` and keeps that record,
155
+ mainnet switches under `v3.2.0`. A client that asks for only one answers v1 on
156
+ the other network, and the chain then refuses every hybrid tx with `pqc` code 21.
153
157
  - On `qorechain-vladi` / `qorechain-diana`, `"auto"` without `rest` — or with a
154
158
  node that cannot be asked — **throws** rather than guess. Force a form with
155
159
  `signBytesVersion: "v1"` or `"v2"`.
package/dist/index.cjs CHANGED
@@ -12705,7 +12705,8 @@ function attachHybridExtension(body, ext, opts = {}) {
12705
12705
  }
12706
12706
 
12707
12707
  // src/tx/signbytes.ts
12708
- var SIGN_BYTES_V2_UPGRADE = "v3.1.98";
12708
+ var SIGN_BYTES_V2_UPGRADE = "v3.2.0";
12709
+ var SIGN_BYTES_V2_UPGRADES = ["v3.2.0", "v3.1.98"];
12709
12710
  var LEGACY_SIGN_BYTES_CHAINS = [
12710
12711
  "qorechain-vladi",
12711
12712
  "qorechain-diana"
@@ -12825,14 +12826,21 @@ function parseAppliedHeight(body) {
12825
12826
  }
12826
12827
  return BigInt(h);
12827
12828
  }
12828
- async function fetchSignBytesV2AppliedHeight(rest, fetchImpl = globalThis.fetch) {
12829
- const url = `${rest.replace(/\/+$/, "")}/cosmos/upgrade/v1beta1/applied_plan/${SIGN_BYTES_V2_UPGRADE}`;
12829
+ async function fetchSignBytesV2AppliedHeight(rest, fetchImpl = globalThis.fetch, upgradeName = SIGN_BYTES_V2_UPGRADE) {
12830
+ const url = `${rest.replace(/\/+$/, "")}/cosmos/upgrade/v1beta1/applied_plan/${upgradeName}`;
12830
12831
  const res = await fetchImpl(url);
12831
12832
  if (!res.ok) {
12832
12833
  throw new Error(`applied_plan query failed: HTTP ${res.status} from ${url}`);
12833
12834
  }
12834
12835
  return parseAppliedHeight(await res.json());
12835
12836
  }
12837
+ async function fetchSignBytesV2AppliedHeightAny(rest, fetchImpl = globalThis.fetch) {
12838
+ for (const name of SIGN_BYTES_V2_UPGRADES) {
12839
+ const height = await fetchSignBytesV2AppliedHeight(rest, fetchImpl, name);
12840
+ if (height > 0n) return height;
12841
+ }
12842
+ return 0n;
12843
+ }
12836
12844
  var cache = /* @__PURE__ */ new Map();
12837
12845
  function clearSignBytesCache() {
12838
12846
  cache.clear();
@@ -12846,7 +12854,7 @@ async function resolveSignBytesVersion(opts) {
12846
12854
  if (!isLegacySignBytesChain(opts.chainId)) return "v2";
12847
12855
  if (!opts.rest) {
12848
12856
  throw new Error(
12849
- `cannot choose the hybrid sign-bytes form for ${opts.chainId} without its REST endpoint: pass rest, or signBytesVersion "v1" (before the ${SIGN_BYTES_V2_UPGRADE} upgrade) or "v2" (after)`
12857
+ `cannot choose the hybrid sign-bytes form for ${opts.chainId} without its REST endpoint: pass rest, or signBytesVersion "v1" (before the ${SIGN_BYTES_V2_UPGRADES.join(" / ")} upgrade) or "v2" (after)`
12850
12858
  );
12851
12859
  }
12852
12860
  const key = `${opts.rest}\0${opts.chainId}`;
@@ -12855,10 +12863,10 @@ async function resolveSignBytesVersion(opts) {
12855
12863
  if (!opts.forceRefresh && hit && Date.now() - hit.at < ttl) return hit.version;
12856
12864
  let height;
12857
12865
  try {
12858
- height = await fetchSignBytesV2AppliedHeight(opts.rest, opts.fetch);
12866
+ height = await fetchSignBytesV2AppliedHeightAny(opts.rest, opts.fetch);
12859
12867
  } catch (e) {
12860
12868
  throw new Error(
12861
- `cannot ask ${opts.rest} whether ${SIGN_BYTES_V2_UPGRADE} is applied (${e.message}); pass signBytesVersion "v1" or "v2"`
12869
+ `cannot ask ${opts.rest} whether any of ${SIGN_BYTES_V2_UPGRADES.join(", ")} is applied (${e.message}); pass signBytesVersion "v1" or "v2"`
12862
12870
  );
12863
12871
  }
12864
12872
  const version = signBytesVersionFor(opts.chainId, height);
@@ -27099,6 +27107,7 @@ exports.QoreHttpError = QoreHttpError;
27099
27107
  exports.QoreTxError = QoreTxError;
27100
27108
  exports.RestClient = RestClient;
27101
27109
  exports.SIGN_BYTES_V2_UPGRADE = SIGN_BYTES_V2_UPGRADE;
27110
+ exports.SIGN_BYTES_V2_UPGRADES = SIGN_BYTES_V2_UPGRADES;
27102
27111
  exports.STATIC_FALLBACK = STATIC_FALLBACK;
27103
27112
  exports.TxClient = TxClient;
27104
27113
  exports.VERSION = VERSION;
@@ -27166,6 +27175,7 @@ exports.explorerBlockUrl = explorerBlockUrl;
27166
27175
  exports.explorerTxUrl = explorerTxUrl;
27167
27176
  exports.feegrant = feegrant;
27168
27177
  exports.fetchSignBytesV2AppliedHeight = fetchSignBytesV2AppliedHeight;
27178
+ exports.fetchSignBytesV2AppliedHeightAny = fetchSignBytesV2AppliedHeightAny;
27169
27179
  exports.formatUnits = formatUnits;
27170
27180
  exports.fromBase = fromBase;
27171
27181
  exports.generateMnemonic = generateMnemonic;