@tezos-x/octez.connect-dapp 5.0.1 → 5.0.2

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.
@@ -1175,7 +1175,7 @@ class DAppClient extends octez_connect_core_1.Client {
1175
1175
  // reading response.message.version would always miss and collapse to '0',
1176
1176
  // misrouting v4 responses when no peer is persisted yet.
1177
1177
  const walletPeerV3 = yield this.getPeer();
1178
- const walletPeerVersionV3 = (_a = walletPeerV3 === null || walletPeerV3 === void 0 ? void 0 : walletPeerV3.version) !== null && _a !== void 0 ? _a : response.version;
1178
+ const walletPeerVersionV3 = (_a = (0, octez_connect_core_1.effectivePeerVersion)(walletPeerV3)) !== null && _a !== void 0 ? _a : response.version;
1179
1179
  const partialAccountInfos = yield blockchain.getAccountInfosFromPermissionResponse(response.message, walletPeerVersionV3);
1180
1180
  const blockchainDataScopes = response.message.blockchainData.scopes;
1181
1181
  const accountInfos = partialAccountInfos.map((p) => ({
@@ -1323,10 +1323,11 @@ class DAppClient extends octez_connect_core_1.Client {
1323
1323
  this.sendMetrics('performance-metrics/save', yield this.buildPayload('connect', 'success'));
1324
1324
  logger.log('requestPermissions', '######## MESSAGE #######');
1325
1325
  logger.log('requestPermissions', message);
1326
- // walletPeer.version is the negotiated pairing version; fall back to the
1327
- // response envelope version when no peer is persisted yet.
1326
+ // Capability-aware peer version (legacy wallets echo the dApp's version
1327
+ // at pairing — see effectivePeerVersion); fall back to the response
1328
+ // envelope version when no peer is persisted yet.
1328
1329
  const walletPeer = yield this.getPeer();
1329
- const walletPeerVersion = (_a = walletPeer === null || walletPeer === void 0 ? void 0 : walletPeer.version) !== null && _a !== void 0 ? _a : message.version;
1330
+ const walletPeerVersion = (_a = (0, octez_connect_core_1.effectivePeerVersion)(walletPeer)) !== null && _a !== void 0 ? _a : message.version;
1330
1331
  // Gate the freshly-paired wallet against the dApp's required minimum (a
1331
1332
  // no-op under the default, permissive minimum). Throws
1332
1333
  // VersionUnsupportedBeaconError when the wallet is too old.
@@ -1949,10 +1950,15 @@ class DAppClient extends octez_connect_core_1.Client {
1949
1950
  });
1950
1951
  }
1951
1952
  // Throws VersionUnsupportedBeaconError when a wallet that reported a version
1952
- // is below requiredMinimumVersion (or reports a malformed one). A peer that
1953
- // never reported a version (legacy pairing predating versioning) is treated
1954
- // as unknown and allowed through, so raising the minimum never retroactively
1955
- // breaks an already-paired session on a pure read.
1953
+ // is below requiredMinimumVersion (or reports a malformed one). Callers pass
1954
+ // the EFFECTIVE version (see effectivePeerVersion): a declared version is
1955
+ // only trusted alongside the v5 `protocolVersion` pairing marker; a
1956
+ // marker-less wallet that declared one counts as '2' (legacy wallets echo
1957
+ // the dApp's version, so the raw peer.version may read deceptively high).
1958
+ // A peer that never reported a version (WalletConnect pairings, legacy
1959
+ // pairings predating versioning) is treated as unknown and allowed through,
1960
+ // so raising the minimum never retroactively breaks an already-paired
1961
+ // session on a pure read.
1956
1962
  assertWalletVersionMeetsMinimum(walletVersion) {
1957
1963
  if (walletVersion === undefined) {
1958
1964
  return;
@@ -2162,13 +2168,16 @@ class DAppClient extends octez_connect_core_1.Client {
2162
2168
  // Enforce the dApp's required minimum before a request leaves the SDK.
2163
2169
  // No-op under the default (permissive) minimum; otherwise rejects an
2164
2170
  // under-minimum wallet with VersionUnsupportedBeaconError.
2165
- this.assertWalletVersionMeetsMinimum(peer === null || peer === void 0 ? void 0 : peer.version);
2166
- // The wire dialect is negotiated per peer — min(peer.version,
2167
- // BEACON_VERSION), floor '2'. A wrapped-capable peer (>= 3) receives the
2168
- // flat requestInput (the unchanged public shape) mapped onto the wrapped
2169
- // Tezos payload; a legacy peer receives the flat v2 message it has
2170
- // always spoken. Integrators never see either dialect.
2171
- const negotiatedVersion = (0, octez_connect_core_1.negotiateEnvelopeVersion)(peer === null || peer === void 0 ? void 0 : peer.version);
2171
+ this.assertWalletVersionMeetsMinimum((0, octez_connect_core_1.effectivePeerVersion)(peer));
2172
+ // The wire dialect is negotiated per peer — min(effective peer version,
2173
+ // BEACON_VERSION), floor '2'. The effective version is capability-aware:
2174
+ // legacy wallets ECHO the dApp's version in their pairing response, so
2175
+ // peer.version alone would misread a 4.8.x wallet as v4; only peers that
2176
+ // sent the v5 `protocolVersion` marker are trusted. A wrapped-capable
2177
+ // peer receives the flat requestInput (the unchanged public shape)
2178
+ // mapped onto the wrapped Tezos payload; a legacy peer receives the flat
2179
+ // v2 message it has always spoken. Integrators never see either dialect.
2180
+ const negotiatedVersion = (0, octez_connect_core_1.negotiateEnvelopeVersion)((0, octez_connect_core_1.effectivePeerVersion)(peer));
2172
2181
  const requestSenderId = yield (0, octez_connect_core_1.getSenderId)(yield this.beaconId);
2173
2182
  let request;
2174
2183
  if ((0, octez_connect_core_1.usesWrappedMessages)(negotiatedVersion)) {
@@ -2275,14 +2284,21 @@ class DAppClient extends octez_connect_core_1.Client {
2275
2284
  const account = yield this.getActiveAccount();
2276
2285
  const peer = yield this.getPeer(account);
2277
2286
  // Enforce the dApp's required minimum before a request leaves the SDK.
2278
- this.assertWalletVersionMeetsMinimum(peer === null || peer === void 0 ? void 0 : peer.version);
2287
+ this.assertWalletVersionMeetsMinimum((0, octez_connect_core_1.effectivePeerVersion)(peer));
2288
+ // The envelope carries the version negotiated against the effective
2289
+ // (capability-aware) peer version — see effectivePeerVersion: legacy
2290
+ // wallets echo the dApp's version, so only peers that sent the v5
2291
+ // `protocolVersion` marker are trusted with the v4 dialect. Unlike
2292
+ // makeRequest, this path is wrapper-only (the v3 blockchainData shape
2293
+ // has no flat equivalent), so it floors at '3' instead of '2': a legacy
2294
+ // wallet routes a version-'3' wrapper through its v3 branch, whereas a
2295
+ // '2'-stamped wrapper would be misrouted as flat and silently dropped.
2296
+ const negotiatedVersion = (0, octez_connect_core_1.negotiateEnvelopeVersion)((0, octez_connect_core_1.effectivePeerVersion)(peer));
2279
2297
  const request = {
2280
2298
  id: messageId,
2281
- // The envelope carries the version negotiated against the peer:
2282
- // min(peer.version, BEACON_VERSION), floor '3'. A v3 wallet treats any
2283
- // version >= 3 as a wrapped message; a v4 wallet reaches its
2284
- // multi-network branch only when it declared v4 at pairing.
2285
- version: (0, octez_connect_core_1.negotiateEnvelopeVersion)(peer === null || peer === void 0 ? void 0 : peer.version),
2299
+ version: (0, octez_connect_core_1.usesWrappedMessages)(negotiatedVersion)
2300
+ ? negotiatedVersion
2301
+ : String(octez_connect_core_1.MESSAGE_WRAPPED_FROM_VERSION),
2286
2302
  senderId: yield (0, octez_connect_core_1.getSenderId)(yield this.beaconId),
2287
2303
  message: requestInput
2288
2304
  };