@hashgraph/hedera-wallet-connect 1.4.1-canary.c00acf4.0 → 1.4.2-canary.dd8e029.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,21 +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, signer will be removed. Please reconnect to the wallet.');
68
- // Notify DAppConnector to remove this signer
69
- this.signClient.emit({
70
- topic: this.topic,
71
- event: {
72
- name: 'session_delete',
73
- data: { topic: this.topic },
74
- },
75
- chainId: ledgerIdToCAIPChainId(this.ledgerId),
76
- });
77
- throw new SessionNotFoundError('Session no longer exists. Please reconnect to the wallet.');
78
- }
79
63
  if (this.extensionId)
80
64
  extensionOpen(this.extensionId);
81
65
  return this.signClient.request({
@@ -271,7 +255,6 @@ export class DAppSigner {
271
255
  return { result: this._parseQueryResponse(query, result.response) };
272
256
  }
273
257
  catch (error) {
274
- this.logger.error('Error executing query request:', error);
275
258
  return { error };
276
259
  }
277
260
  }
@@ -1,12 +1,10 @@
1
- import { AccountId, LedgerId } from '@hashgraph/sdk';
1
+ import { AccountId, LedgerId, Transaction } 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
- import { GetNodeAddressesResult, ExecuteTransactionParams, ExecuteTransactionResult, SignMessageParams, SignMessageResult, SignAndExecuteQueryResult, SignAndExecuteQueryParams, SignAndExecuteTransactionParams, SignAndExecuteTransactionResult, SignTransactionParams, ExtensionData } from '../shared';
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';
9
- export { SessionNotFoundError } from './SessionNotFoundError';
10
8
  type BaseLogger = 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'fatal';
11
9
  export declare class DAppConnector {
12
10
  private logger;
@@ -32,12 +30,12 @@ export declare class DAppConnector {
32
30
  * @param chains - Array of supported chains for the DApp (optional).
33
31
  * @param logLevel - Logging level for the DAppConnector (optional).
34
32
  */
35
- 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');
36
34
  /**
37
35
  * Sets the logging level for the DAppConnector
38
36
  * @param level - The logging level to set
39
37
  */
40
- setLogLevel(level: LogLevel): void;
38
+ setLogLevel(level: 'error' | 'warn' | 'info' | 'debug'): void;
41
39
  /**
42
40
  * Initializes the DAppConnector instance.
43
41
  * @param logger - `BaseLogger` for logging purposes (optional).
@@ -81,10 +79,9 @@ export declare class DAppConnector {
81
79
  */
82
80
  connectExtension(extensionId: string, pairingTopic?: string): Promise<SessionTypes.Struct>;
83
81
  /**
84
- * Validates the session by checking if the session exists and is valid.
85
- * Also ensures the signer exists for the session.
82
+ * Validates the session by checking if the session exists.
86
83
  * @param topic - The topic of the session to validate.
87
- * @returns {boolean} - True if the session exists and has a valid signer, false otherwise.
84
+ * @returns {boolean} - True if the session exists, false otherwise.
88
85
  */
89
86
  private validateSession;
90
87
  /**
@@ -198,20 +195,21 @@ export declare class DAppConnector {
198
195
  *
199
196
  * @param {SignTransactionParams} params - The parameters of type {@link SignTransactionParams | `SignTransactionParams`} required for `Transaction` signing.
200
197
  * @param {string} params.signerAccountId - a signer Hedera Account identifier in {@link https://hips.hedera.com/hip/hip-30 | HIP-30} (`<nework>:<shard>.<realm>.<num>`) form.
201
- * @param {Transaction} params.transaction - a built Transaction.
198
+ * @param {Transaction | string} params.transactionBody - a built Transaction object, or a base64 string of a transaction body (deprecated).
199
+ * @deprecated Using string for params.transactionBody is deprecated and will be removed in a future version. Please migrate to using Transaction objects directly.
202
200
  * @returns Promise\<{@link SignTransactionResult}\>
203
201
  * @example
204
202
  * ```ts
205
203
  *
206
204
  * const params = {
207
205
  * signerAccountId: '0.0.12345',
208
- * transaction
206
+ * transactionBody
209
207
  * }
210
208
  *
211
209
  * const result = await dAppConnector.signTransaction(params)
212
210
  * ```
213
211
  */
214
- signTransaction(params: SignTransactionParams): Promise<import("@hashgraph/sdk").Transaction>;
212
+ signTransaction(params: SignTransactionParams): Promise<Transaction | SignTransactionResult>;
215
213
  private handleSessionEvent;
216
214
  private handleSessionUpdate;
217
215
  private handleSessionDelete;
@@ -17,7 +17,7 @@
17
17
  * limitations under the License.
18
18
  *
19
19
  */
20
- import { LedgerId } from '@hashgraph/sdk';
20
+ import { LedgerId, Transaction } from '@hashgraph/sdk';
21
21
  import QRCodeModal from '@walletconnect/qrcode-modal';
22
22
  import { WalletConnectModal } from '@walletconnect/modal';
23
23
  import SignClient from '@walletconnect/sign-client';
@@ -26,7 +26,6 @@ import { DefaultLogger } from '../shared/logger';
26
26
  import { HederaJsonRpcMethod, accountAndLedgerFromSession, networkNamespaces, extensionConnect, findExtensions, } from '../shared';
27
27
  import { DAppSigner } from './DAppSigner';
28
28
  export * from './DAppSigner';
29
- export { SessionNotFoundError } from './SessionNotFoundError';
30
29
  export class DAppConnector {
31
30
  /**
32
31
  * Initializes the DAppConnector instance.
@@ -114,8 +113,6 @@ export class DAppConnector {
114
113
  this.walletConnectClient.on('session_event', this.handleSessionEvent.bind(this));
115
114
  this.walletConnectClient.on('session_update', this.handleSessionUpdate.bind(this));
116
115
  this.walletConnectClient.on('session_delete', this.handleSessionDelete.bind(this));
117
- // Listen for custom session_delete events from DAppSigner
118
- this.walletConnectClient.core.events.on('session_delete', this.handleSessionDelete.bind(this));
119
116
  this.walletConnectClient.core.pairing.events.on('pairing_delete', this.handlePairingDelete.bind(this));
120
117
  }
121
118
  catch (e) {
@@ -220,10 +217,9 @@ export class DAppConnector {
220
217
  }, pairingTopic, extension.availableInIframe ? undefined : extensionId);
221
218
  }
222
219
  /**
223
- * Validates the session by checking if the session exists and is valid.
224
- * Also ensures the signer exists for the session.
220
+ * Validates the session by checking if the session exists.
225
221
  * @param topic - The topic of the session to validate.
226
- * @returns {boolean} - True if the session exists and has a valid signer, false otherwise.
222
+ * @returns {boolean} - True if the session exists, false otherwise.
227
223
  */
228
224
  validateSession(topic) {
229
225
  try {
@@ -231,23 +227,12 @@ export class DAppConnector {
231
227
  return false;
232
228
  }
233
229
  const session = this.walletConnectClient.session.get(topic);
234
- const hasSigner = this.signers.some((signer) => signer.topic === topic);
235
230
  if (!session) {
236
- // If session doesn't exist but we have a signer for it, clean up
237
- if (hasSigner) {
238
- this.logger.warn(`Signer exists but no session found for topic: ${topic}`);
239
- this.handleSessionDelete({ topic });
240
- }
241
- return false;
242
- }
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
  }
@@ -501,14 +486,15 @@ export class DAppConnector {
501
486
  *
502
487
  * @param {SignTransactionParams} params - The parameters of type {@link SignTransactionParams | `SignTransactionParams`} required for `Transaction` signing.
503
488
  * @param {string} params.signerAccountId - a signer Hedera Account identifier in {@link https://hips.hedera.com/hip/hip-30 | HIP-30} (`<nework>:<shard>.<realm>.<num>`) form.
504
- * @param {Transaction} params.transaction - a built Transaction.
489
+ * @param {Transaction | string} params.transactionBody - a built Transaction object, or a base64 string of a transaction body (deprecated).
490
+ * @deprecated Using string for params.transactionBody is deprecated and will be removed in a future version. Please migrate to using Transaction objects directly.
505
491
  * @returns Promise\<{@link SignTransactionResult}\>
506
492
  * @example
507
493
  * ```ts
508
494
  *
509
495
  * const params = {
510
496
  * signerAccountId: '0.0.12345',
511
- * transaction
497
+ * transactionBody
512
498
  * }
513
499
  *
514
500
  * const result = await dAppConnector.signTransaction(params)
@@ -516,15 +502,25 @@ export class DAppConnector {
516
502
  */
517
503
  async signTransaction(params) {
518
504
  var _a, _b;
519
- const signerAccountId = (_b = (_a = params === null || params === void 0 ? void 0 : params.signerAccountId) === null || _a === void 0 ? void 0 : _a.split(':')) === null || _b === void 0 ? void 0 : _b.pop();
520
- const accountSigner = this.signers.find((signer) => { var _a; return ((_a = signer === null || signer === void 0 ? void 0 : signer.getAccountId()) === null || _a === void 0 ? void 0 : _a.toString()) === signerAccountId; });
521
- if (!accountSigner) {
522
- throw new Error(`No signer found for account ${signerAccountId}`);
505
+ if (typeof (params === null || params === void 0 ? void 0 : params.transactionBody) === 'string') {
506
+ this.logger.warn('Transaction body is a string. This is not recommended, please migrate to passing a transaction object directly.');
507
+ return await this.request({
508
+ method: HederaJsonRpcMethod.SignTransaction,
509
+ params,
510
+ });
523
511
  }
524
- if (!(params === null || params === void 0 ? void 0 : params.transaction)) {
525
- throw new Error('No transaction provided');
512
+ if ((params === null || params === void 0 ? void 0 : params.transactionBody) instanceof Transaction) {
513
+ const signerAccountId = (_b = (_a = params === null || params === void 0 ? void 0 : params.signerAccountId) === null || _a === void 0 ? void 0 : _a.split(':')) === null || _b === void 0 ? void 0 : _b.pop();
514
+ const accountSigner = this.signers.find((signer) => { var _a; return ((_a = signer === null || signer === void 0 ? void 0 : signer.getAccountId()) === null || _a === void 0 ? void 0 : _a.toString()) === signerAccountId; });
515
+ if (!accountSigner) {
516
+ throw new Error(`No signer found for account ${signerAccountId}`);
517
+ }
518
+ if (!(params === null || params === void 0 ? void 0 : params.transactionBody)) {
519
+ throw new Error('No transaction provided');
520
+ }
521
+ return await accountSigner.signTransaction(params.transactionBody);
526
522
  }
527
- return await accountSigner.signTransaction(params.transaction);
523
+ throw new Error('Transaction sent in incorrect format. Ensure transaction body is either a base64 transaction body or Transaction object.');
528
524
  }
529
525
  handleSessionEvent(args) {
530
526
  this.logger.debug('Session event received:', args);
@@ -540,24 +536,14 @@ export class DAppConnector {
540
536
  }
541
537
  handleSessionDelete(event) {
542
538
  this.logger.info('Session deleted:', event);
543
- let deletedSigner = false;
544
- this.signers = this.signers.filter((signer) => {
545
- if (signer.topic !== event.topic) {
546
- return true;
547
- }
548
- deletedSigner = true;
549
- return false;
550
- });
551
- // prevent emitting disconnected event if signers is untouched.
552
- if (deletedSigner) {
553
- try {
554
- this.disconnect(event.topic);
555
- }
556
- catch (e) {
557
- this.logger.error('Error disconnecting session:', e);
558
- }
559
- this.logger.info('Session deleted and signer removed');
539
+ this.signers = this.signers.filter((signer) => signer.topic !== event.topic);
540
+ try {
541
+ this.disconnect(event.topic);
542
+ }
543
+ catch (e) {
544
+ this.logger.error('Error disconnecting session:', e);
560
545
  }
546
+ this.logger.info('Session deleted by wallet');
561
547
  }
562
548
  handlePairingDelete(event) {
563
549
  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;
@@ -84,7 +84,11 @@ export interface SignAndExecuteTransactionResponse extends EngineTypes.RespondPa
84
84
  }
85
85
  export interface SignTransactionParams {
86
86
  signerAccountId: string;
87
- transaction: Transaction;
87
+ /**
88
+ * @deprecated Using string for transactionBody is deprecated and will be removed in a future version.
89
+ * Please migrate to using Transaction objects directly.
90
+ */
91
+ transactionBody: Transaction | string;
88
92
  }
89
93
  export interface SignTransactionRequest extends EngineTypes.RequestParams {
90
94
  request: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashgraph/hedera-wallet-connect",
3
- "version": "1.4.1-canary.c00acf4.0",
3
+ "version": "1.4.2-canary.dd8e029.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
- }