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

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
@@ -20,4 +20,4 @@ This package is published from the Trilitech-maintained octez.connect repository
20
20
  ## Notes
21
21
 
22
22
  - Trilitech publishes these packages under the `@tezos-x/octez.connect-*` scope
23
- - Release notes, package policy, and the current package list live in the repository README
23
+ - Release notes live on the [GitHub Releases page](https://github.com/trilitech/octez.connect/releases); package policy lives in [CONTRIBUTING.md](https://github.com/trilitech/octez.connect/blob/master/CONTRIBUTING.md) and [MAINTAINERS.md](https://github.com/trilitech/octez.connect/blob/master/MAINTAINERS.md)
@@ -40,9 +40,10 @@ export declare class DAppClient extends Client {
40
40
  protected wcProjectId?: string;
41
41
  protected wcRelayUrl?: string;
42
42
  /**
43
- * WalletConnect is opt-in: only enabled when `walletConnectOptions` is provided
44
- * and `disableWalletConnect` is not set. When false, no WC transport is built,
45
- * listened to, or offered for pairing, and no default projectId is applied.
43
+ * WalletConnect is enabled by default (as in 4.8.x) using the shared
44
+ * DEFAULT_WALLETCONNECT_PROJECT_ID unless `walletConnectOptions` overrides it.
45
+ * Set `disableWalletConnect: true` to opt out. When false, no WC transport is
46
+ * built, listened to, or offered for pairing.
46
47
  */
47
48
  protected isWalletConnectEnabled: boolean;
48
49
  private isGetActiveAccountHandled;
@@ -44,11 +44,12 @@ class DAppClient extends octez_connect_core_1.Client {
44
44
  super(Object.assign({ storage: config && config.storage ? config.storage : new octez_connect_core_1.LocalStorage() }, config));
45
45
  this.events = new events_1.BeaconEventHandler();
46
46
  /**
47
- * WalletConnect is opt-in: only enabled when `walletConnectOptions` is provided
48
- * and `disableWalletConnect` is not set. When false, no WC transport is built,
49
- * listened to, or offered for pairing, and no default projectId is applied.
47
+ * WalletConnect is enabled by default (as in 4.8.x) using the shared
48
+ * DEFAULT_WALLETCONNECT_PROJECT_ID unless `walletConnectOptions` overrides it.
49
+ * Set `disableWalletConnect: true` to opt out. When false, no WC transport is
50
+ * built, listened to, or offered for pairing.
50
51
  */
51
- this.isWalletConnectEnabled = false;
52
+ this.isWalletConnectEnabled = true;
52
53
  this.isGetActiveAccountHandled = false;
53
54
  this.openRequestsOtherTabs = new Set();
54
55
  /**
@@ -69,12 +70,15 @@ class DAppClient extends octez_connect_core_1.Client {
69
70
  this.debounceSetActiveAccount = false;
70
71
  this.multiTabChannel = new octez_connect_core_1.MultiTabChannel('octez.connect-sdk-channel', this.onBCMessageHandler.bind(this), this.onElectedLeaderhandler.bind(this));
71
72
  this.description = config.description;
72
- // WalletConnect is opt-in: only when walletConnectOptions is provided and not
73
- // explicitly disabled. Don't apply the default projectId otherwise (#32).
74
- this.isWalletConnectEnabled =
75
- Boolean(config.walletConnectOptions) && !config.disableWalletConnect;
73
+ // WalletConnect is enabled BY DEFAULT (as in 4.8.x) with the shared
74
+ // ecosystem projectId, so dApps don't have to register with WalletConnect
75
+ // Cloud to offer WC wallets (e.g. Kukai Mobile) — the free tier covers the
76
+ // ecosystem's volume. `walletConnectOptions` overrides the projectId/relay,
77
+ // `disableWalletConnect: true` opts out entirely (e.g. environments where
78
+ // the WC provider cannot run, see #32).
79
+ this.isWalletConnectEnabled = !config.disableWalletConnect;
76
80
  this.wcProjectId = this.isWalletConnectEnabled
77
- ? ((_a = config.walletConnectOptions) === null || _a === void 0 ? void 0 : _a.projectId) || '24469fd0a06df227b6e5f7dc7de0ff4f'
81
+ ? ((_a = config.walletConnectOptions) === null || _a === void 0 ? void 0 : _a.projectId) || octez_connect_core_1.DEFAULT_WALLETCONNECT_PROJECT_ID
78
82
  : undefined;
79
83
  this.wcRelayUrl = this.isWalletConnectEnabled ? (_b = config.walletConnectOptions) === null || _b === void 0 ? void 0 : _b.relayUrl : undefined;
80
84
  this.featuredWallets = config.featuredWallets;
@@ -444,8 +448,8 @@ class DAppClient extends octez_connect_core_1.Client {
444
448
  yield this.addListener(this.postMessageTransport);
445
449
  this.p2pTransport = new DappP2PTransport_1.DappP2PTransport(this.name, keyPair, this.storage, this.matrixNodes, this.iconUrl, this.appUrl);
446
450
  yield this.addListener(this.p2pTransport);
447
- // WalletConnect is opt-in (#32): skip building/listening the transport when
448
- // no walletConnectOptions were provided or it was explicitly disabled.
451
+ // WalletConnect is on by default; skip building/listening the transport
452
+ // only when explicitly disabled via disableWalletConnect (#32).
449
453
  if (this.isWalletConnectEnabled) {
450
454
  const wcOptions = {
451
455
  projectId: this.wcProjectId,
@@ -603,7 +607,8 @@ class DAppClient extends octez_connect_core_1.Client {
603
607
  }
604
608
  else {
605
609
  // The persisted active account was paired over WalletConnect but WC
606
- // is now opt-out/disabled (#32), so there is no matching transport to
610
+ // has since been disabled (`disableWalletConnect`, #32) or failed to
611
+ // initialize, so there is no matching transport to
607
612
  // restore. Without this branch none of the conditions above call
608
613
  // resolve() and the init promise created above never settles, so
609
614
  // init() (and every later call awaiting it) hangs forever. Resolve on
@@ -1175,7 +1180,7 @@ class DAppClient extends octez_connect_core_1.Client {
1175
1180
  // reading response.message.version would always miss and collapse to '0',
1176
1181
  // misrouting v4 responses when no peer is persisted yet.
1177
1182
  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;
1183
+ const walletPeerVersionV3 = (_a = (0, octez_connect_core_1.effectivePeerVersion)(walletPeerV3)) !== null && _a !== void 0 ? _a : response.version;
1179
1184
  const partialAccountInfos = yield blockchain.getAccountInfosFromPermissionResponse(response.message, walletPeerVersionV3);
1180
1185
  const blockchainDataScopes = response.message.blockchainData.scopes;
1181
1186
  const accountInfos = partialAccountInfos.map((p) => ({
@@ -1323,10 +1328,11 @@ class DAppClient extends octez_connect_core_1.Client {
1323
1328
  this.sendMetrics('performance-metrics/save', yield this.buildPayload('connect', 'success'));
1324
1329
  logger.log('requestPermissions', '######## MESSAGE #######');
1325
1330
  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.
1331
+ // Capability-aware peer version (legacy wallets echo the dApp's version
1332
+ // at pairing — see effectivePeerVersion); fall back to the response
1333
+ // envelope version when no peer is persisted yet.
1328
1334
  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;
1335
+ const walletPeerVersion = (_a = (0, octez_connect_core_1.effectivePeerVersion)(walletPeer)) !== null && _a !== void 0 ? _a : message.version;
1330
1336
  // Gate the freshly-paired wallet against the dApp's required minimum (a
1331
1337
  // no-op under the default, permissive minimum). Throws
1332
1338
  // VersionUnsupportedBeaconError when the wallet is too old.
@@ -1949,10 +1955,15 @@ class DAppClient extends octez_connect_core_1.Client {
1949
1955
  });
1950
1956
  }
1951
1957
  // 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.
1958
+ // is below requiredMinimumVersion (or reports a malformed one). Callers pass
1959
+ // the EFFECTIVE version (see effectivePeerVersion): a declared version is
1960
+ // only trusted alongside the v5 `protocolVersion` pairing marker; a
1961
+ // marker-less wallet that declared one counts as '2' (legacy wallets echo
1962
+ // the dApp's version, so the raw peer.version may read deceptively high).
1963
+ // A peer that never reported a version (WalletConnect pairings, legacy
1964
+ // pairings predating versioning) is treated as unknown and allowed through,
1965
+ // so raising the minimum never retroactively breaks an already-paired
1966
+ // session on a pure read.
1956
1967
  assertWalletVersionMeetsMinimum(walletVersion) {
1957
1968
  if (walletVersion === undefined) {
1958
1969
  return;
@@ -2162,13 +2173,16 @@ class DAppClient extends octez_connect_core_1.Client {
2162
2173
  // Enforce the dApp's required minimum before a request leaves the SDK.
2163
2174
  // No-op under the default (permissive) minimum; otherwise rejects an
2164
2175
  // 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);
2176
+ this.assertWalletVersionMeetsMinimum((0, octez_connect_core_1.effectivePeerVersion)(peer));
2177
+ // The wire dialect is negotiated per peer — min(effective peer version,
2178
+ // BEACON_VERSION), floor '2'. The effective version is capability-aware:
2179
+ // legacy wallets ECHO the dApp's version in their pairing response, so
2180
+ // peer.version alone would misread a 4.8.x wallet as v4; only peers that
2181
+ // sent the v5 `protocolVersion` marker are trusted. A wrapped-capable
2182
+ // peer receives the flat requestInput (the unchanged public shape)
2183
+ // mapped onto the wrapped Tezos payload; a legacy peer receives the flat
2184
+ // v2 message it has always spoken. Integrators never see either dialect.
2185
+ const negotiatedVersion = (0, octez_connect_core_1.negotiateEnvelopeVersion)((0, octez_connect_core_1.effectivePeerVersion)(peer));
2172
2186
  const requestSenderId = yield (0, octez_connect_core_1.getSenderId)(yield this.beaconId);
2173
2187
  let request;
2174
2188
  if ((0, octez_connect_core_1.usesWrappedMessages)(negotiatedVersion)) {
@@ -2275,14 +2289,21 @@ class DAppClient extends octez_connect_core_1.Client {
2275
2289
  const account = yield this.getActiveAccount();
2276
2290
  const peer = yield this.getPeer(account);
2277
2291
  // Enforce the dApp's required minimum before a request leaves the SDK.
2278
- this.assertWalletVersionMeetsMinimum(peer === null || peer === void 0 ? void 0 : peer.version);
2292
+ this.assertWalletVersionMeetsMinimum((0, octez_connect_core_1.effectivePeerVersion)(peer));
2293
+ // The envelope carries the version negotiated against the effective
2294
+ // (capability-aware) peer version — see effectivePeerVersion: legacy
2295
+ // wallets echo the dApp's version, so only peers that sent the v5
2296
+ // `protocolVersion` marker are trusted with the v4 dialect. Unlike
2297
+ // makeRequest, this path is wrapper-only (the v3 blockchainData shape
2298
+ // has no flat equivalent), so it floors at '3' instead of '2': a legacy
2299
+ // wallet routes a version-'3' wrapper through its v3 branch, whereas a
2300
+ // '2'-stamped wrapper would be misrouted as flat and silently dropped.
2301
+ const negotiatedVersion = (0, octez_connect_core_1.negotiateEnvelopeVersion)((0, octez_connect_core_1.effectivePeerVersion)(peer));
2279
2302
  const request = {
2280
2303
  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),
2304
+ version: (0, octez_connect_core_1.usesWrappedMessages)(negotiatedVersion)
2305
+ ? negotiatedVersion
2306
+ : String(octez_connect_core_1.MESSAGE_WRAPPED_FROM_VERSION),
2286
2307
  senderId: yield (0, octez_connect_core_1.getSenderId)(yield this.beaconId),
2287
2308
  message: requestInput
2288
2309
  };