@hashgraph/hedera-wallet-connect 1.3.8-canary.6c8147c.0 → 1.3.8-canary.89f529f.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.
@@ -1,6 +1,5 @@
1
1
  import { Signer, AccountBalance, AccountId, AccountInfo, Executable, Key, LedgerId, SignerSignature, Transaction, TransactionRecord } from '@hashgraph/sdk';
2
2
  import type { CoreTypes, ISignClient } from '@walletconnect/types';
3
- import { LogLevel } from '../shared/logger';
4
3
  export declare class DAppSigner implements Signer {
5
4
  private readonly accountId;
6
5
  private readonly signClient;
@@ -8,12 +7,12 @@ export declare class DAppSigner implements Signer {
8
7
  private readonly ledgerId;
9
8
  readonly extensionId?: string | undefined;
10
9
  private logger;
11
- constructor(accountId: AccountId, signClient: ISignClient, topic: string, ledgerId?: LedgerId, extensionId?: string | undefined, logLevel?: LogLevel);
10
+ constructor(accountId: AccountId, signClient: ISignClient, topic: string, ledgerId?: LedgerId, extensionId?: string | undefined, logLevel?: 'error' | 'warn' | 'info' | 'debug');
12
11
  /**
13
12
  * Sets the logging level for the DAppSigner
14
13
  * @param level - The logging level to set
15
14
  */
16
- setLogLevel(level: LogLevel): void;
15
+ setLogLevel(level: 'error' | 'warn' | 'info' | 'debug'): void;
17
16
  private _getHederaClient;
18
17
  private get _signerAccountId();
19
18
  private _getRandomNodes;
@@ -21,7 +21,6 @@ import { AccountBalance, AccountId, AccountInfo, LedgerId, SignerSignature, Tran
21
21
  import { proto } from '@hashgraph/proto';
22
22
  import { HederaJsonRpcMethod, base64StringToSignatureMap, base64StringToUint8Array, ledgerIdToCAIPChainId, queryToBase64String, transactionBodyToBase64String, transactionToBase64String, transactionToTransactionBody, extensionOpen, Uint8ArrayToBase64String, Uint8ArrayToString, } from '../shared';
23
23
  import { DefaultLogger } from '../shared/logger';
24
- import { SessionNotFoundError } from './SessionNotFoundError';
25
24
  const clients = {};
26
25
  export class DAppSigner {
27
26
  constructor(accountId, signClient, topic, ledgerId = LedgerId.MAINNET, extensionId, logLevel = 'debug') {
@@ -61,12 +60,6 @@ export class DAppSigner {
61
60
  return allNodes.slice(0, numberOfNodes);
62
61
  }
63
62
  request(request) {
64
- var _a, _b;
65
- // Avoid a wallet call if the session is no longer valid
66
- if (!((_b = (_a = this === null || this === void 0 ? void 0 : this.signClient) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.get(this.topic))) {
67
- this.logger.error('Session no longer exists. Please reconnect to the wallet.');
68
- throw new SessionNotFoundError('Session no longer exists. Please reconnect to the wallet.');
69
- }
70
63
  if (this.extensionId)
71
64
  extensionOpen(this.extensionId);
72
65
  return this.signClient.request({
@@ -171,10 +164,6 @@ export class DAppSigner {
171
164
  }
172
165
  async _tryExecuteTransactionRequest(request) {
173
166
  try {
174
- // Verify session is still valid before proceeding
175
- if (!this.signClient.session.get(this.topic)) {
176
- throw new Error('Session no longer exists. Please reconnect to the wallet.');
177
- }
178
167
  const requestToBytes = request.toBytes();
179
168
  this.logger.debug('Creating transaction from bytes', requestToBytes, request);
180
169
  const transaction = Transaction.fromBytes(requestToBytes);
@@ -190,22 +179,7 @@ export class DAppSigner {
190
179
  return { result: TransactionResponse.fromJSON(result) };
191
180
  }
192
181
  catch (error) {
193
- // Check if error is due to session being deleted
194
- if (error instanceof SessionNotFoundError) {
195
- this.logger.error('Session was deleted, removing signer');
196
- // Notify DAppConnector to remove this signer
197
- this.signClient.emit({
198
- topic: this.topic,
199
- event: {
200
- name: 'session_delete',
201
- data: { topic: this.topic },
202
- },
203
- chainId: ledgerIdToCAIPChainId(this.ledgerId),
204
- });
205
- }
206
- else {
207
- this.logger.error('Error executing transaction request:', error);
208
- }
182
+ this.logger.error('Error executing transaction request:', error);
209
183
  return { error };
210
184
  }
211
185
  }
@@ -281,7 +255,6 @@ export class DAppSigner {
281
255
  return { result: this._parseQueryResponse(query, result.response) };
282
256
  }
283
257
  catch (error) {
284
- this.logger.error('Error executing query request:', error);
285
258
  return { error };
286
259
  }
287
260
  }
@@ -2,7 +2,6 @@ import { AccountId, LedgerId } from '@hashgraph/sdk';
2
2
  import { SessionTypes, SignClientTypes } from '@walletconnect/types';
3
3
  import { WalletConnectModal } from '@walletconnect/modal';
4
4
  import SignClient from '@walletconnect/sign-client';
5
- import { LogLevel } from '../shared/logger';
6
5
  import { GetNodeAddressesResult, ExecuteTransactionParams, ExecuteTransactionResult, SignMessageParams, SignMessageResult, SignAndExecuteQueryResult, SignAndExecuteQueryParams, SignAndExecuteTransactionParams, SignAndExecuteTransactionResult, SignTransactionParams, SignTransactionResult, ExtensionData } from '../shared';
7
6
  import { DAppSigner } from './DAppSigner';
8
7
  export * from './DAppSigner';
@@ -31,12 +30,12 @@ export declare class DAppConnector {
31
30
  * @param chains - Array of supported chains for the DApp (optional).
32
31
  * @param logLevel - Logging level for the DAppConnector (optional).
33
32
  */
34
- constructor(metadata: SignClientTypes.Metadata, network: LedgerId, projectId: string, methods?: string[], events?: string[], chains?: string[], logLevel?: LogLevel);
33
+ constructor(metadata: SignClientTypes.Metadata, network: LedgerId, projectId: string, methods?: string[], events?: string[], chains?: string[], logLevel?: 'error' | 'warn' | 'info' | 'debug');
35
34
  /**
36
35
  * Sets the logging level for the DAppConnector
37
36
  * @param level - The logging level to set
38
37
  */
39
- setLogLevel(level: LogLevel): void;
38
+ setLogLevel(level: 'error' | 'warn' | 'info' | 'debug'): void;
40
39
  /**
41
40
  * Initializes the DAppConnector instance.
42
41
  * @param logger - `BaseLogger` for logging purposes (optional).
@@ -80,10 +79,9 @@ export declare class DAppConnector {
80
79
  */
81
80
  connectExtension(extensionId: string, pairingTopic?: string): Promise<SessionTypes.Struct>;
82
81
  /**
83
- * Validates the session by checking if the session exists and is valid.
84
- * Also ensures the signer exists for the session.
82
+ * Validates the session by checking if the session exists.
85
83
  * @param topic - The topic of the session to validate.
86
- * @returns {boolean} - True if the session exists and has a valid signer, false otherwise.
84
+ * @returns {boolean} - True if the session exists, false otherwise.
87
85
  */
88
86
  private validateSession;
89
87
  /**
@@ -113,8 +113,6 @@ export class DAppConnector {
113
113
  this.walletConnectClient.on('session_event', this.handleSessionEvent.bind(this));
114
114
  this.walletConnectClient.on('session_update', this.handleSessionUpdate.bind(this));
115
115
  this.walletConnectClient.on('session_delete', this.handleSessionDelete.bind(this));
116
- // Listen for custom session_delete events from DAppSigner
117
- this.walletConnectClient.core.events.on('session_delete', this.handleSessionDelete.bind(this));
118
116
  this.walletConnectClient.core.pairing.events.on('pairing_delete', this.handlePairingDelete.bind(this));
119
117
  }
120
118
  catch (e) {
@@ -219,10 +217,9 @@ export class DAppConnector {
219
217
  }, pairingTopic, extension.availableInIframe ? undefined : extensionId);
220
218
  }
221
219
  /**
222
- * Validates the session by checking if the session exists and is valid.
223
- * Also ensures the signer exists for the session.
220
+ * Validates the session by checking if the session exists.
224
221
  * @param topic - The topic of the session to validate.
225
- * @returns {boolean} - True if the session exists and has a valid signer, false otherwise.
222
+ * @returns {boolean} - True if the session exists, false otherwise.
226
223
  */
227
224
  validateSession(topic) {
228
225
  try {
@@ -231,23 +228,11 @@ export class DAppConnector {
231
228
  }
232
229
  const session = this.walletConnectClient.session.get(topic);
233
230
  if (!session) {
234
- // If session doesn't exist but we have a signer for it, clean up
235
- const hasSigner = this.signers.some((signer) => signer.topic === topic);
236
- if (hasSigner) {
237
- this.handleSessionDelete({ topic });
238
- }
239
- return false;
240
- }
241
- // Verify we have a signer for this session
242
- const hasSigner = this.signers.some((signer) => signer.topic === topic);
243
- if (!hasSigner) {
244
- this.logger.warn(`Session exists but no signer found for topic: ${topic}`);
245
231
  return false;
246
232
  }
247
233
  return true;
248
234
  }
249
- catch (e) {
250
- this.logger.error('Error validating session:', e);
235
+ catch (_a) {
251
236
  return false;
252
237
  }
253
238
  }
@@ -536,24 +521,14 @@ export class DAppConnector {
536
521
  }
537
522
  handleSessionDelete(event) {
538
523
  this.logger.info('Session deleted:', event);
539
- let deletedSigner = false;
540
- this.signers = this.signers.filter((signer) => {
541
- if (signer.topic !== event.topic) {
542
- return true;
543
- }
544
- deletedSigner = true;
545
- return false;
546
- });
547
- // prevent emitting disconnected event if signers is untouched.
548
- if (deletedSigner) {
549
- try {
550
- this.disconnect(event.topic);
551
- }
552
- catch (e) {
553
- this.logger.error('Error disconnecting session:', e);
554
- }
555
- this.logger.info('Session deleted and signer removed');
524
+ this.signers = this.signers.filter((signer) => signer.topic !== event.topic);
525
+ try {
526
+ this.disconnect(event.topic);
527
+ }
528
+ catch (e) {
529
+ this.logger.error('Error disconnecting session:', e);
556
530
  }
531
+ this.logger.info('Session deleted by wallet');
557
532
  }
558
533
  handlePairingDelete(event) {
559
534
  this.logger.info('Pairing deleted:', event);
@@ -4,12 +4,11 @@ export interface ILogger {
4
4
  info(message: string, ...args: any[]): void;
5
5
  debug(message: string, ...args: any[]): void;
6
6
  }
7
- export type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'off';
8
7
  export declare class DefaultLogger implements ILogger {
9
8
  private logLevel;
10
- constructor(logLevel?: LogLevel);
11
- setLogLevel(level: LogLevel): void;
12
- getLogLevel(): LogLevel;
9
+ constructor(logLevel?: 'error' | 'warn' | 'info' | 'debug');
10
+ setLogLevel(level: 'error' | 'warn' | 'info' | 'debug'): void;
11
+ getLogLevel(): 'error' | 'warn' | 'info' | 'debug';
13
12
  error(message: string, ...args: any[]): void;
14
13
  warn(message: string, ...args: any[]): void;
15
14
  info(message: string, ...args: any[]): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashgraph/hedera-wallet-connect",
3
- "version": "1.3.8-canary.6c8147c.0",
3
+ "version": "1.3.8-canary.89f529f.0",
4
4
  "description": "A library to facilitate integrating Hedera with WalletConnect",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,3 +0,0 @@
1
- export declare class SessionNotFoundError extends Error {
2
- constructor(message: string);
3
- }
@@ -1,6 +0,0 @@
1
- export class SessionNotFoundError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = 'SessionNotFoundError';
5
- }
6
- }