@taquito/wallet-connect 24.3.0-beta.1 → 24.3.0-beta.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
@@ -10,6 +10,7 @@ _Documentation can be found [here](https://taquito.io/docs/walletconnect)_
10
10
 
11
11
  `@taquito/wallet-connect` is an npm package that provides developers a way to connect a dapp built with Taquito to a wallet giving the freedom to the users of the dapp to choose the wallet via the WalletConnect/Reown protocol. The `WalletConnect` class implements the `WalletProvider` interface, providing an alternative to `BeaconWallet`.
12
12
  Note: Currently, a QR code is displayed to establish a connection with a wallet. As more Tezos wallets integrate with WalletConnect, we plan showing a list of available wallets alongside the QR code.
13
+ Note: The current QR pairing flow still relies on the legacy WalletConnect modal package. We plan to replace that modal integration in a future release.
13
14
 
14
15
  ## Install
15
16
 
@@ -39,7 +40,7 @@ const wallet = await WalletConnect.init({
39
40
 
40
41
  await wallet.requestPermissions({
41
42
  permissionScope: {
42
- networks: [NetworkType.GHOSTNET],
43
+ networks: [NetworkType.SHADOWNET],
43
44
  events: [],
44
45
  methods: [
45
46
  PermissionScopeMethods.TEZOS_SEND,
@@ -53,6 +54,8 @@ const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL');
53
54
  Tezos.setWalletProvider(wallet);
54
55
  ```
55
56
 
57
+ Existing sessions can be restored with `configureWithExistingSessionKey()`. Restored sessions are validated before activation, so invalid or stale non-Tezos session data may be rejected during restore.
58
+
56
59
  ## Additional Info
57
60
 
58
61
  See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing and versioning.
@@ -40,18 +40,20 @@ class WalletConnect {
40
40
  this.walletConnectModal = WalletConnectModal;
41
41
  this.signClient.on('session_delete', ({ topic }) => {
42
42
  if (this.session?.topic === topic) {
43
- this.session = undefined;
43
+ this.clearState();
44
44
  }
45
45
  });
46
46
  this.signClient.on('session_expire', ({ topic }) => {
47
47
  if (this.session?.topic === topic) {
48
- this.session = undefined;
48
+ this.clearState();
49
49
  }
50
50
  });
51
51
  this.signClient.on('session_update', ({ params, topic }) => {
52
52
  if (this.session?.topic === topic) {
53
- this.session.namespaces = params.namespaces;
54
- // TODO determine if we need validation on the namespace here
53
+ this.activateSession({
54
+ ...this.session,
55
+ namespaces: params.namespaces,
56
+ }, undefined, false);
55
57
  }
56
58
  });
57
59
  this.signClient.on('session_event', () => {
@@ -95,10 +97,11 @@ class WalletConnect {
95
97
  */
96
98
  async requestPermissions(connectParams) {
97
99
  // TODO when Tezos wallets will officially support wallet connect, we need to provide a default value for registryUrl
100
+ let approvedSession;
98
101
  try {
99
102
  const chains = connectParams.permissionScope.networks.map((network) => `${TEZOS_PLACEHOLDER}:${network}`);
100
103
  const { uri, approval } = await this.signClient.connect({
101
- requiredNamespaces: {
104
+ optionalNamespaces: {
102
105
  [TEZOS_PLACEHOLDER]: {
103
106
  chains,
104
107
  methods: connectParams.permissionScope.methods,
@@ -113,7 +116,7 @@ class WalletConnect {
113
116
  chains,
114
117
  });
115
118
  }
116
- this.session = await approval();
119
+ approvedSession = await approval();
117
120
  }
118
121
  catch (error) {
119
122
  throw new errors_1.ConnectionFailed(error);
@@ -121,8 +124,7 @@ class WalletConnect {
121
124
  finally {
122
125
  this.walletConnectModal.closeModal();
123
126
  }
124
- this.validateReceivedNamespace(connectParams.permissionScope, this.session.namespaces);
125
- this.setDefaultAccountAndNetwork();
127
+ this.activateSession(approvedSession, connectParams.permissionScope);
126
128
  }
127
129
  /**
128
130
  * Access all existing active pairings
@@ -147,8 +149,7 @@ class WalletConnect {
147
149
  if (!sessions.includes(key)) {
148
150
  throw new errors_1.InvalidSessionKey(key);
149
151
  }
150
- this.session = this.signClient.session.get(key);
151
- this.setDefaultAccountAndNetwork();
152
+ this.activateSession(this.signClient.session.get(key));
152
153
  }
153
154
  async disconnect() {
154
155
  if (this.session) {
@@ -304,14 +305,28 @@ class WalletConnect {
304
305
  }
305
306
  return this.activeNetwork;
306
307
  }
307
- setDefaultAccountAndNetwork() {
308
- const activeAccount = this.getAccounts();
309
- if (activeAccount.length === 1) {
310
- this.activeAccount = activeAccount[0];
308
+ activateSession(session, permissionScope, resetActiveState = true) {
309
+ this.session = session;
310
+ if (permissionScope) {
311
+ this.validateReceivedNamespace(permissionScope, session.namespaces);
311
312
  }
312
- const activeNetwork = this.getNetworks();
313
- if (activeNetwork.length === 1) {
314
- this.activeNetwork = activeNetwork[0];
313
+ else {
314
+ this.validateRestoredNamespace(session.namespaces);
315
+ }
316
+ if (resetActiveState) {
317
+ this.activeAccount = undefined;
318
+ this.activeNetwork = undefined;
319
+ }
320
+ this.reconcileActiveAccountAndNetwork();
321
+ }
322
+ reconcileActiveAccountAndNetwork() {
323
+ const accounts = this.getAccounts();
324
+ if (!this.activeAccount || !accounts.includes(this.activeAccount)) {
325
+ this.activeAccount = accounts.length === 1 ? accounts[0] : undefined;
326
+ }
327
+ const networks = this.getNetworks();
328
+ if (!this.activeNetwork || !networks.includes(this.activeNetwork)) {
329
+ this.activeNetwork = networks.length === 1 ? networks[0] : undefined;
315
330
  }
316
331
  }
317
332
  clearState() {
@@ -358,6 +373,14 @@ class WalletConnect {
358
373
  throw new errors_1.InvalidReceivedSessionNamespace('All methods must be approved', (0, utils_1.getSdkError)('USER_REJECTED_METHODS').code, 'incomplete', missingMethods);
359
374
  }
360
375
  }
376
+ validateRestoredNamespace(receivedNamespaces) {
377
+ const tezosNamespace = receivedNamespaces[TEZOS_PLACEHOLDER];
378
+ if (!tezosNamespace) {
379
+ this.clearState();
380
+ throw new errors_1.InvalidSession('Tezos not found in namespaces');
381
+ }
382
+ this.validateAccounts(this.getChainsFromAccounts(tezosNamespace.accounts), tezosNamespace.accounts);
383
+ }
361
384
  validateEvents(requiredEvents, receivedEvents) {
362
385
  const missingEvents = [];
363
386
  requiredEvents.forEach((method) => {
@@ -375,7 +398,6 @@ class WalletConnect {
375
398
  this.clearState();
376
399
  throw new errors_1.InvalidReceivedSessionNamespace('Accounts must not be empty', (0, utils_1.getSdkError)('USER_REJECTED_CHAINS').code, 'incomplete');
377
400
  }
378
- const receivedChains = [];
379
401
  const invalidChains = [];
380
402
  const missingChains = [];
381
403
  const invalidChainsNamespace = [];
@@ -387,10 +409,6 @@ class WalletConnect {
387
409
  if (accountId[0] !== TEZOS_PLACEHOLDER) {
388
410
  invalidChainsNamespace.push(chain);
389
411
  }
390
- const network = accountId[1];
391
- if (!receivedChains.includes(network)) {
392
- receivedChains.push(network);
393
- }
394
412
  });
395
413
  if (invalidChains.length > 0) {
396
414
  this.clearState();
@@ -400,6 +418,7 @@ class WalletConnect {
400
418
  this.clearState();
401
419
  throw new errors_1.InvalidReceivedSessionNamespace('Accounts must be defined in matching namespace', (0, utils_1.getSdkError)('UNSUPPORTED_ACCOUNTS').code, 'invalid', invalidChainsNamespace);
402
420
  }
421
+ const receivedChains = this.getChainsFromAccounts(receivedAccounts);
403
422
  requiredNetwork.forEach((network) => {
404
423
  if (!receivedChains.includes(network)) {
405
424
  missingChains.push(network);
@@ -418,24 +437,19 @@ class WalletConnect {
418
437
  throw new errors_1.InvalidSession('Tezos not found in namespaces');
419
438
  }
420
439
  }
421
- getTezosRequiredNamespace() {
422
- if (TEZOS_PLACEHOLDER in this.getSession().requiredNamespaces) {
423
- return this.getSession().requiredNamespaces[TEZOS_PLACEHOLDER];
424
- }
425
- else {
426
- throw new errors_1.InvalidSession('Tezos not found in requiredNamespaces');
427
- }
428
- }
429
440
  validateNetworkAndAccount(network, account) {
430
441
  if (!this.getTezosNamespace().accounts.includes(`${TEZOS_PLACEHOLDER}:${network}:${account}`)) {
431
442
  throw new errors_1.InvalidNetworkOrAccount(network, account);
432
443
  }
433
444
  }
434
445
  getPermittedMethods() {
435
- return this.getTezosRequiredNamespace().methods;
446
+ return this.getTezosNamespace().methods;
436
447
  }
437
448
  getPermittedNetwork() {
438
- return this.getTezosRequiredNamespace().chains.map((chain) => chain.split(':')[1]);
449
+ return this.getChainsFromAccounts(this.getTezosNamespace().accounts);
450
+ }
451
+ getChainsFromAccounts(accounts) {
452
+ return [...new Set(accounts.map((account) => account.split(':')[1]))];
439
453
  }
440
454
  formatParameters(params) {
441
455
  const formatedParams = params;
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT!
5
5
  exports.VERSION = {
6
- "commitHash": "05df48fee92f846cba793920d6fa829afd6a1847",
7
- "version": "24.3.0-beta.1"
6
+ "commitHash": "a312cd3f4fc0ab0fb3351bfffe6ad855772cb077",
7
+ "version": "24.3.0-beta.3"
8
8
  };
@@ -181,18 +181,20 @@ class WalletConnect {
181
181
  this.walletConnectModal = WalletConnectModal;
182
182
  this.signClient.on('session_delete', ({ topic }) => {
183
183
  if (this.session?.topic === topic) {
184
- this.session = undefined;
184
+ this.clearState();
185
185
  }
186
186
  });
187
187
  this.signClient.on('session_expire', ({ topic }) => {
188
188
  if (this.session?.topic === topic) {
189
- this.session = undefined;
189
+ this.clearState();
190
190
  }
191
191
  });
192
192
  this.signClient.on('session_update', ({ params, topic }) => {
193
193
  if (this.session?.topic === topic) {
194
- this.session.namespaces = params.namespaces;
195
- // TODO determine if we need validation on the namespace here
194
+ this.activateSession({
195
+ ...this.session,
196
+ namespaces: params.namespaces,
197
+ }, undefined, false);
196
198
  }
197
199
  });
198
200
  this.signClient.on('session_event', () => {
@@ -236,10 +238,11 @@ class WalletConnect {
236
238
  */
237
239
  async requestPermissions(connectParams) {
238
240
  // TODO when Tezos wallets will officially support wallet connect, we need to provide a default value for registryUrl
241
+ let approvedSession;
239
242
  try {
240
243
  const chains = connectParams.permissionScope.networks.map((network) => `${TEZOS_PLACEHOLDER}:${network}`);
241
244
  const { uri, approval } = await this.signClient.connect({
242
- requiredNamespaces: {
245
+ optionalNamespaces: {
243
246
  [TEZOS_PLACEHOLDER]: {
244
247
  chains,
245
248
  methods: connectParams.permissionScope.methods,
@@ -254,7 +257,7 @@ class WalletConnect {
254
257
  chains,
255
258
  });
256
259
  }
257
- this.session = await approval();
260
+ approvedSession = await approval();
258
261
  }
259
262
  catch (error) {
260
263
  throw new ConnectionFailed(error);
@@ -262,8 +265,7 @@ class WalletConnect {
262
265
  finally {
263
266
  this.walletConnectModal.closeModal();
264
267
  }
265
- this.validateReceivedNamespace(connectParams.permissionScope, this.session.namespaces);
266
- this.setDefaultAccountAndNetwork();
268
+ this.activateSession(approvedSession, connectParams.permissionScope);
267
269
  }
268
270
  /**
269
271
  * Access all existing active pairings
@@ -288,8 +290,7 @@ class WalletConnect {
288
290
  if (!sessions.includes(key)) {
289
291
  throw new InvalidSessionKey(key);
290
292
  }
291
- this.session = this.signClient.session.get(key);
292
- this.setDefaultAccountAndNetwork();
293
+ this.activateSession(this.signClient.session.get(key));
293
294
  }
294
295
  async disconnect() {
295
296
  if (this.session) {
@@ -445,14 +446,28 @@ class WalletConnect {
445
446
  }
446
447
  return this.activeNetwork;
447
448
  }
448
- setDefaultAccountAndNetwork() {
449
- const activeAccount = this.getAccounts();
450
- if (activeAccount.length === 1) {
451
- this.activeAccount = activeAccount[0];
449
+ activateSession(session, permissionScope, resetActiveState = true) {
450
+ this.session = session;
451
+ if (permissionScope) {
452
+ this.validateReceivedNamespace(permissionScope, session.namespaces);
452
453
  }
453
- const activeNetwork = this.getNetworks();
454
- if (activeNetwork.length === 1) {
455
- this.activeNetwork = activeNetwork[0];
454
+ else {
455
+ this.validateRestoredNamespace(session.namespaces);
456
+ }
457
+ if (resetActiveState) {
458
+ this.activeAccount = undefined;
459
+ this.activeNetwork = undefined;
460
+ }
461
+ this.reconcileActiveAccountAndNetwork();
462
+ }
463
+ reconcileActiveAccountAndNetwork() {
464
+ const accounts = this.getAccounts();
465
+ if (!this.activeAccount || !accounts.includes(this.activeAccount)) {
466
+ this.activeAccount = accounts.length === 1 ? accounts[0] : undefined;
467
+ }
468
+ const networks = this.getNetworks();
469
+ if (!this.activeNetwork || !networks.includes(this.activeNetwork)) {
470
+ this.activeNetwork = networks.length === 1 ? networks[0] : undefined;
456
471
  }
457
472
  }
458
473
  clearState() {
@@ -499,6 +514,14 @@ class WalletConnect {
499
514
  throw new InvalidReceivedSessionNamespace('All methods must be approved', getSdkError('USER_REJECTED_METHODS').code, 'incomplete', missingMethods);
500
515
  }
501
516
  }
517
+ validateRestoredNamespace(receivedNamespaces) {
518
+ const tezosNamespace = receivedNamespaces[TEZOS_PLACEHOLDER];
519
+ if (!tezosNamespace) {
520
+ this.clearState();
521
+ throw new InvalidSession('Tezos not found in namespaces');
522
+ }
523
+ this.validateAccounts(this.getChainsFromAccounts(tezosNamespace.accounts), tezosNamespace.accounts);
524
+ }
502
525
  validateEvents(requiredEvents, receivedEvents) {
503
526
  const missingEvents = [];
504
527
  requiredEvents.forEach((method) => {
@@ -516,7 +539,6 @@ class WalletConnect {
516
539
  this.clearState();
517
540
  throw new InvalidReceivedSessionNamespace('Accounts must not be empty', getSdkError('USER_REJECTED_CHAINS').code, 'incomplete');
518
541
  }
519
- const receivedChains = [];
520
542
  const invalidChains = [];
521
543
  const missingChains = [];
522
544
  const invalidChainsNamespace = [];
@@ -528,10 +550,6 @@ class WalletConnect {
528
550
  if (accountId[0] !== TEZOS_PLACEHOLDER) {
529
551
  invalidChainsNamespace.push(chain);
530
552
  }
531
- const network = accountId[1];
532
- if (!receivedChains.includes(network)) {
533
- receivedChains.push(network);
534
- }
535
553
  });
536
554
  if (invalidChains.length > 0) {
537
555
  this.clearState();
@@ -541,6 +559,7 @@ class WalletConnect {
541
559
  this.clearState();
542
560
  throw new InvalidReceivedSessionNamespace('Accounts must be defined in matching namespace', getSdkError('UNSUPPORTED_ACCOUNTS').code, 'invalid', invalidChainsNamespace);
543
561
  }
562
+ const receivedChains = this.getChainsFromAccounts(receivedAccounts);
544
563
  requiredNetwork.forEach((network) => {
545
564
  if (!receivedChains.includes(network)) {
546
565
  missingChains.push(network);
@@ -559,24 +578,19 @@ class WalletConnect {
559
578
  throw new InvalidSession('Tezos not found in namespaces');
560
579
  }
561
580
  }
562
- getTezosRequiredNamespace() {
563
- if (TEZOS_PLACEHOLDER in this.getSession().requiredNamespaces) {
564
- return this.getSession().requiredNamespaces[TEZOS_PLACEHOLDER];
565
- }
566
- else {
567
- throw new InvalidSession('Tezos not found in requiredNamespaces');
568
- }
569
- }
570
581
  validateNetworkAndAccount(network, account) {
571
582
  if (!this.getTezosNamespace().accounts.includes(`${TEZOS_PLACEHOLDER}:${network}:${account}`)) {
572
583
  throw new InvalidNetworkOrAccount(network, account);
573
584
  }
574
585
  }
575
586
  getPermittedMethods() {
576
- return this.getTezosRequiredNamespace().methods;
587
+ return this.getTezosNamespace().methods;
577
588
  }
578
589
  getPermittedNetwork() {
579
- return this.getTezosRequiredNamespace().chains.map((chain) => chain.split(':')[1]);
590
+ return this.getChainsFromAccounts(this.getTezosNamespace().accounts);
591
+ }
592
+ getChainsFromAccounts(accounts) {
593
+ return [...new Set(accounts.map((account) => account.split(':')[1]))];
580
594
  }
581
595
  formatParameters(params) {
582
596
  const formatedParams = params;
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-wallet-connect.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"taquito-wallet-connect.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -182,18 +182,20 @@
182
182
  this.walletConnectModal = WalletConnectModal;
183
183
  this.signClient.on('session_delete', ({ topic }) => {
184
184
  if (this.session?.topic === topic) {
185
- this.session = undefined;
185
+ this.clearState();
186
186
  }
187
187
  });
188
188
  this.signClient.on('session_expire', ({ topic }) => {
189
189
  if (this.session?.topic === topic) {
190
- this.session = undefined;
190
+ this.clearState();
191
191
  }
192
192
  });
193
193
  this.signClient.on('session_update', ({ params, topic }) => {
194
194
  if (this.session?.topic === topic) {
195
- this.session.namespaces = params.namespaces;
196
- // TODO determine if we need validation on the namespace here
195
+ this.activateSession({
196
+ ...this.session,
197
+ namespaces: params.namespaces,
198
+ }, undefined, false);
197
199
  }
198
200
  });
199
201
  this.signClient.on('session_event', () => {
@@ -237,10 +239,11 @@
237
239
  */
238
240
  async requestPermissions(connectParams) {
239
241
  // TODO when Tezos wallets will officially support wallet connect, we need to provide a default value for registryUrl
242
+ let approvedSession;
240
243
  try {
241
244
  const chains = connectParams.permissionScope.networks.map((network) => `${TEZOS_PLACEHOLDER}:${network}`);
242
245
  const { uri, approval } = await this.signClient.connect({
243
- requiredNamespaces: {
246
+ optionalNamespaces: {
244
247
  [TEZOS_PLACEHOLDER]: {
245
248
  chains,
246
249
  methods: connectParams.permissionScope.methods,
@@ -255,7 +258,7 @@
255
258
  chains,
256
259
  });
257
260
  }
258
- this.session = await approval();
261
+ approvedSession = await approval();
259
262
  }
260
263
  catch (error) {
261
264
  throw new ConnectionFailed(error);
@@ -263,8 +266,7 @@
263
266
  finally {
264
267
  this.walletConnectModal.closeModal();
265
268
  }
266
- this.validateReceivedNamespace(connectParams.permissionScope, this.session.namespaces);
267
- this.setDefaultAccountAndNetwork();
269
+ this.activateSession(approvedSession, connectParams.permissionScope);
268
270
  }
269
271
  /**
270
272
  * Access all existing active pairings
@@ -289,8 +291,7 @@
289
291
  if (!sessions.includes(key)) {
290
292
  throw new InvalidSessionKey(key);
291
293
  }
292
- this.session = this.signClient.session.get(key);
293
- this.setDefaultAccountAndNetwork();
294
+ this.activateSession(this.signClient.session.get(key));
294
295
  }
295
296
  async disconnect() {
296
297
  if (this.session) {
@@ -446,14 +447,28 @@
446
447
  }
447
448
  return this.activeNetwork;
448
449
  }
449
- setDefaultAccountAndNetwork() {
450
- const activeAccount = this.getAccounts();
451
- if (activeAccount.length === 1) {
452
- this.activeAccount = activeAccount[0];
450
+ activateSession(session, permissionScope, resetActiveState = true) {
451
+ this.session = session;
452
+ if (permissionScope) {
453
+ this.validateReceivedNamespace(permissionScope, session.namespaces);
453
454
  }
454
- const activeNetwork = this.getNetworks();
455
- if (activeNetwork.length === 1) {
456
- this.activeNetwork = activeNetwork[0];
455
+ else {
456
+ this.validateRestoredNamespace(session.namespaces);
457
+ }
458
+ if (resetActiveState) {
459
+ this.activeAccount = undefined;
460
+ this.activeNetwork = undefined;
461
+ }
462
+ this.reconcileActiveAccountAndNetwork();
463
+ }
464
+ reconcileActiveAccountAndNetwork() {
465
+ const accounts = this.getAccounts();
466
+ if (!this.activeAccount || !accounts.includes(this.activeAccount)) {
467
+ this.activeAccount = accounts.length === 1 ? accounts[0] : undefined;
468
+ }
469
+ const networks = this.getNetworks();
470
+ if (!this.activeNetwork || !networks.includes(this.activeNetwork)) {
471
+ this.activeNetwork = networks.length === 1 ? networks[0] : undefined;
457
472
  }
458
473
  }
459
474
  clearState() {
@@ -500,6 +515,14 @@
500
515
  throw new InvalidReceivedSessionNamespace('All methods must be approved', utils.getSdkError('USER_REJECTED_METHODS').code, 'incomplete', missingMethods);
501
516
  }
502
517
  }
518
+ validateRestoredNamespace(receivedNamespaces) {
519
+ const tezosNamespace = receivedNamespaces[TEZOS_PLACEHOLDER];
520
+ if (!tezosNamespace) {
521
+ this.clearState();
522
+ throw new InvalidSession('Tezos not found in namespaces');
523
+ }
524
+ this.validateAccounts(this.getChainsFromAccounts(tezosNamespace.accounts), tezosNamespace.accounts);
525
+ }
503
526
  validateEvents(requiredEvents, receivedEvents) {
504
527
  const missingEvents = [];
505
528
  requiredEvents.forEach((method) => {
@@ -517,7 +540,6 @@
517
540
  this.clearState();
518
541
  throw new InvalidReceivedSessionNamespace('Accounts must not be empty', utils.getSdkError('USER_REJECTED_CHAINS').code, 'incomplete');
519
542
  }
520
- const receivedChains = [];
521
543
  const invalidChains = [];
522
544
  const missingChains = [];
523
545
  const invalidChainsNamespace = [];
@@ -529,10 +551,6 @@
529
551
  if (accountId[0] !== TEZOS_PLACEHOLDER) {
530
552
  invalidChainsNamespace.push(chain);
531
553
  }
532
- const network = accountId[1];
533
- if (!receivedChains.includes(network)) {
534
- receivedChains.push(network);
535
- }
536
554
  });
537
555
  if (invalidChains.length > 0) {
538
556
  this.clearState();
@@ -542,6 +560,7 @@
542
560
  this.clearState();
543
561
  throw new InvalidReceivedSessionNamespace('Accounts must be defined in matching namespace', utils.getSdkError('UNSUPPORTED_ACCOUNTS').code, 'invalid', invalidChainsNamespace);
544
562
  }
563
+ const receivedChains = this.getChainsFromAccounts(receivedAccounts);
545
564
  requiredNetwork.forEach((network) => {
546
565
  if (!receivedChains.includes(network)) {
547
566
  missingChains.push(network);
@@ -560,24 +579,19 @@
560
579
  throw new InvalidSession('Tezos not found in namespaces');
561
580
  }
562
581
  }
563
- getTezosRequiredNamespace() {
564
- if (TEZOS_PLACEHOLDER in this.getSession().requiredNamespaces) {
565
- return this.getSession().requiredNamespaces[TEZOS_PLACEHOLDER];
566
- }
567
- else {
568
- throw new InvalidSession('Tezos not found in requiredNamespaces');
569
- }
570
- }
571
582
  validateNetworkAndAccount(network, account) {
572
583
  if (!this.getTezosNamespace().accounts.includes(`${TEZOS_PLACEHOLDER}:${network}:${account}`)) {
573
584
  throw new InvalidNetworkOrAccount(network, account);
574
585
  }
575
586
  }
576
587
  getPermittedMethods() {
577
- return this.getTezosRequiredNamespace().methods;
588
+ return this.getTezosNamespace().methods;
578
589
  }
579
590
  getPermittedNetwork() {
580
- return this.getTezosRequiredNamespace().chains.map((chain) => chain.split(':')[1]);
591
+ return this.getChainsFromAccounts(this.getTezosNamespace().accounts);
592
+ }
593
+ getChainsFromAccounts(accounts) {
594
+ return [...new Set(accounts.map((account) => account.split(':')[1]))];
581
595
  }
582
596
  formatParameters(params) {
583
597
  const formatedParams = params;
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-wallet-connect.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"taquito-wallet-connect.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -122,20 +122,22 @@ export declare class WalletConnect implements WalletProvider {
122
122
  \* @throws ActiveNetworkUnspecified thorwn when there are multiple Tezos netwroks in the session and none is set as the active one
123
123
  */
124
124
  getActiveNetwork(): string;
125
- private setDefaultAccountAndNetwork;
125
+ private activateSession;
126
+ private reconcileActiveAccountAndNetwork;
126
127
  private clearState;
127
128
  getSession(): SessionTypes.Struct;
128
129
  isActiveSession(): boolean;
129
130
  ping(): void;
130
131
  private validateReceivedNamespace;
131
132
  private validateMethods;
133
+ private validateRestoredNamespace;
132
134
  private validateEvents;
133
135
  private validateAccounts;
134
136
  private getTezosNamespace;
135
- private getTezosRequiredNamespace;
136
137
  private validateNetworkAndAccount;
137
138
  private getPermittedMethods;
138
139
  private getPermittedNetwork;
140
+ private getChainsFromAccounts;
139
141
  private formatParameters;
140
142
  private removeDefaultLimits;
141
143
  mapTransferParamsToWalletParams(params: () => Promise<WalletTransferParams>): Promise<Partial<RPCTransferOperation> | Partial<RPCTransferTicketOperation> | Partial<RPCOriginationOperation> | Partial<RPCDelegateOperation> | Partial<RPCIncreasePaidStorageOperation> | Partial<RPCRegisterGlobalConstantOperation>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taquito/wallet-connect",
3
- "version": "24.3.0-beta.1",
3
+ "version": "24.3.0-beta.3",
4
4
  "description": "WalletConnect integration for Taquito applications.",
5
5
  "keywords": [
6
6
  "taquito",
@@ -14,7 +14,6 @@
14
14
  "module": "dist/taquito-wallet-connect.es6.js",
15
15
  "typings": "dist/types/taquito-wallet-connect.d.ts",
16
16
  "files": [
17
- "signature.json",
18
17
  "dist"
19
18
  ],
20
19
  "publishConfig": {
@@ -39,9 +38,9 @@
39
38
  "node": ">=22"
40
39
  },
41
40
  "scripts": {
42
- "test": "jest --coverage",
43
- "test:watch": "jest --coverage --watch",
44
- "test:prod": "npm run lint && npm run test -- --no-cache",
41
+ "test": "vitest run --config ./vitest.config.ts",
42
+ "test:watch": "vitest --config ./vitest.config.ts",
43
+ "test:prod": "npm run lint && npm run test",
45
44
  "lint": "eslint --ext .js,.ts .",
46
45
  "precommit": "lint-staged",
47
46
  "prebuild": "rimraf dist",
@@ -55,62 +54,35 @@
55
54
  "eslint --fix"
56
55
  ]
57
56
  },
58
- "jest": {
59
- "transform": {
60
- ".(ts|tsx)": "ts-jest"
61
- },
62
- "testEnvironment": "node",
63
- "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
64
- "moduleFileExtensions": [
65
- "ts",
66
- "tsx",
67
- "js"
68
- ],
69
- "moduleNameMapper": {
70
- "^@taquito/taquito$": "<rootDir>/../taquito/src/taquito.ts"
71
- },
72
- "coveragePathIgnorePatterns": [
73
- "/node_modules/",
74
- "/test/"
75
- ],
76
- "collectCoverageFrom": [
77
- "src/**/*.{js,ts}"
78
- ]
79
- },
80
57
  "dependencies": {
81
- "@taquito/taquito": "^24.3.0-beta.1",
58
+ "@taquito/taquito": "^24.3.0-beta.3",
82
59
  "@walletconnect/modal": "^2.7.0",
83
- "@walletconnect/sign-client": "^2.16.2",
84
- "@walletconnect/types": "^2.16.2",
85
- "@walletconnect/utils": "^2.16.2"
60
+ "@walletconnect/sign-client": "^2.23.9",
61
+ "@walletconnect/types": "^2.23.9",
62
+ "@walletconnect/utils": "^2.23.9"
86
63
  },
87
64
  "devDependencies": {
88
65
  "@types/bluebird": "^3.5.42",
89
- "@types/chrome": "0.0.171",
90
- "@types/jest": "^29.5.12",
91
- "@types/node": "^20",
66
+ "@types/chrome": "0.1.40",
67
+ "@types/node": "^22.0.0",
92
68
  "@types/pino": "^7.0.5",
93
69
  "@types/ws": "^8.5.12",
94
70
  "@typescript-eslint/eslint-plugin": "^6.21.0",
95
71
  "@typescript-eslint/parser": "^6.21.0",
96
72
  "colors": "^1.4.0",
97
- "coveralls": "^3.1.1",
98
73
  "cross-env": "^7.0.3",
99
74
  "eslint": "^8.57.0",
100
- "jest": "^29.7.0",
101
- "jest-config": "^29.7.0",
102
75
  "lint-staged": "^15.2.7",
103
76
  "lodash.camelcase": "^4.3.0",
104
77
  "prettier": "^3.3.3",
105
78
  "prompt": "^1.3.0",
106
79
  "replace-in-file": "^8.1.0",
107
80
  "rimraf": "^6.0.1",
108
- "rollup": "^4.19.1",
81
+ "rollup": "^4.60.1",
109
82
  "rollup-plugin-json": "^4.0.0",
110
83
  "rollup-plugin-polyfill-node": "^0.13.0",
111
- "rollup-plugin-typescript2": "^0.36.0",
84
+ "rollup-plugin-typescript2": "^0.37.0",
112
85
  "shelljs": "^0.8.5",
113
- "ts-jest": "^29.2.3",
114
86
  "ts-node": "^10.9.2",
115
87
  "ts-toolbelt": "^9.6.0",
116
88
  "typescript": "^5.9.3"