@hashgraph/hedera-wallet-connect 2.0.1-canary.fa5a378.0 → 2.0.3-canary.1dfc9b7.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.
package/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  This library provides tools and recommendations on how to integrate Hedera into an application
4
4
  that requires communication with a wallet that supports Hedera. There are 2 different paths to
5
5
  integrate Hedera in this context. Both approaches use the
6
- [WalletConnect](https://walletconnect.network/) network to send messages from apps to wallets.
6
+ [WalletConnect](https://walletconnect.network/) network to send messages from apps to wallets
7
+ and back.
7
8
 
8
9
  ## Hedera APIs
9
10
 
@@ -21,9 +22,9 @@ Hedera gRPC and REST API calls.
21
22
  ## Ethereum JSON-RPC vs. Hedera JSON-RPC vs. Hedera JSON-RPC Relay
22
23
 
23
24
  When integrating, app developers can choose to use the Hedera native approach and send
24
- transactions to wallets over the WalletConnect relays using the JSON-RPC spec defined for Hedera
25
- native transactions or use Ethereum JSON-RPC calls sent to a Hedera JSON-RPC Relay provider
26
- which then communicates with Hedera consensus and mirror nodes.
25
+ transactions to wallets over the WalletConnect network using the JSON-RPC spec defined for
26
+ Hedera native transactions or use Ethereum JSON-RPC calls sent to a Hedera JSON-RPC Relay
27
+ provider which then communicates with Hedera consensus and mirror nodes.
27
28
 
28
29
  On a high level, JSON-RPC is a type of API stucture, such as SOAP, gRPC, REST, GraphQL, etc. In
29
30
  the Hedera ecosystem, there are distinct concepts regarding JSON-RPC APIs to consider:
@@ -41,7 +42,9 @@ For more information see:
41
42
  - [Ethereum JSON-RPC Specification ](https://ethereum.github.io/execution-apis/api-documentation/)
42
43
  - [Hedera JSON-RPC relay](https://docs.hedera.com/hedera/core-concepts/smart-contracts/json-rpc-relay)
43
44
  - [Hedera Native JSON-RPC spec for WalletConnect](https://docs.reown.com/advanced/multichain/rpc-reference/hedera-rpc)
44
- - [@hashgraph/sdk](https://www.npmjs.com/package/@hashgraph/sdk)
45
+ - [Hedera Javascript SDK](https://www.npmjs.com/package/@hashgraph/sdk)
46
+ - [Reown Docs](https://docs.reown.com/overview)
47
+ - [WalletConnect Network](https://walletconnect.network/)
45
48
 
46
49
  # Getting started
47
50
 
@@ -49,13 +52,14 @@ In addition to choosing between the Hedera native JSON-RPC spec and the Ethereum
49
52
  when building with javascript/typescript, there are 2 supported options to utilize the
50
53
  WalletConnect network to send information from apps to wallets and back.
51
54
 
52
- This README assumes a basic understanding of how to create transactions on Hedera and focusses
55
+ This README assumes an understanding of Hedera as well as the WalletConnect network and focusses
53
56
  on how to send a payload to a wallet for processing and presentation to an end user that is a
54
57
  Hedera account holder. We recommend reviewing the [Hedera Docs](https://docs.hedera.com/) and
55
58
  first submitting transactions directly to the Hedera network without requiring interaction with
56
- a [Wallet](#hedera-wallets) when integrating Hedera for the first time.
59
+ a [Wallet](#hedera-wallets) when integrating Hedera for the first time. We also recommend
60
+ reviewing the [Reown docs](https://docs.reown.com/overview).
57
61
 
58
- ## Using this library and WalletConnect libraries directly
62
+ ## Using this library and underlying WalletConnect libraries directly
59
63
 
60
64
  1. Add Hedera dependencies to your project:
61
65
 
@@ -117,7 +121,7 @@ await dAppConnector.openModal()
117
121
  2. Add Hedera dependencies to your project:
118
122
 
119
123
  ```sh
120
- npm install @hashgraph/hedera-wallet-connect@2.0.0-canary.811af2f.0 @hashgraph/sdk @walletconnect/universal-provider
124
+ npm install @hashgraph/hedera-wallet-connect@2.0.1-canary.24fffa7.0 @hashgraph/sdk @walletconnect/universal-provider
121
125
  ```
122
126
 
123
127
  3. Update `createAppKit` with adapters and a universal provider for Hedera. Note the
@@ -229,6 +233,6 @@ While minimal, the main breaking changes are:
229
233
 
230
234
  - remove setting node id's within this library for transactions
231
235
 
232
- - initially, a transaction created by the Hedera javascript SDK needed to have a node id or
233
- set of node id's set to be able to serialize into bytes to be passed sent over a network and
234
- deserialized by the SDK.
236
+ - initially, a transaction created by the Hedera Javascript SDK needed to have one or more
237
+ consensus node ids set to be able to serialize into bytes, sent over a network, and
238
+ deserialized by the SDK
@@ -8,7 +8,6 @@ export declare class DAppSigner implements Signer {
8
8
  private readonly ledgerId;
9
9
  readonly extensionId?: string | undefined;
10
10
  private logger;
11
- private publicKey;
12
11
  constructor(accountId: AccountId, signClient: ISignClient, topic: string, ledgerId?: LedgerId, extensionId?: string | undefined, logLevel?: LogLevel);
13
12
  /**
14
13
  * Sets the logging level for the DAppSigner
@@ -23,7 +22,6 @@ export declare class DAppSigner implements Signer {
23
22
  }): Promise<T>;
24
23
  getAccountId(): AccountId;
25
24
  getAccountKey(): Key;
26
- getAccountKeyAsync(): Promise<Key | null>;
27
25
  getLedgerId(): LedgerId;
28
26
  getNetwork(): {
29
27
  [key: string]: string | AccountId;
@@ -19,7 +19,7 @@
19
19
  */
20
20
  import { AccountBalance, AccountInfo, LedgerId, SignerSignature, Transaction, TransactionRecord, Client, PublicKey, TransactionId, TransactionResponse, Query, AccountRecordsQuery, AccountInfoQuery, AccountBalanceQuery, TransactionReceiptQuery, TransactionReceipt, TransactionRecordQuery, } from '@hashgraph/sdk';
21
21
  import { proto } from '@hashgraph/proto';
22
- import { HederaJsonRpcMethod, base64StringToSignatureMap, base64StringToUint8Array, ledgerIdToCAIPChainId, queryToBase64String, transactionBodyToBase64String, transactionToBase64String, transactionToTransactionBody, extensionOpen, Uint8ArrayToBase64String, Uint8ArrayToString, getAccountInfo, } from '../shared';
22
+ import { HederaJsonRpcMethod, base64StringToSignatureMap, base64StringToUint8Array, ledgerIdToCAIPChainId, queryToBase64String, transactionBodyToBase64String, transactionToBase64String, transactionToTransactionBody, extensionOpen, Uint8ArrayToBase64String, Uint8ArrayToString, } from '../shared';
23
23
  import { DefaultLogger } from '../shared/logger';
24
24
  import { SessionNotFoundError } from './SessionNotFoundError';
25
25
  const clients = {};
@@ -31,11 +31,6 @@ export class DAppSigner {
31
31
  this.ledgerId = ledgerId;
32
32
  this.extensionId = extensionId;
33
33
  this.logger = new DefaultLogger(logLevel);
34
- this.publicKey = null;
35
- // cache public key from mirror node
36
- this.getAccountKeyAsync()
37
- .then((key) => (this.publicKey = key))
38
- .catch((error) => this.logger.error('Error when receiving a public key:', error.message));
39
34
  }
40
35
  /**
41
36
  * Sets the logging level for the DAppSigner
@@ -84,16 +79,7 @@ export class DAppSigner {
84
79
  return this.accountId;
85
80
  }
86
81
  getAccountKey() {
87
- if (this.publicKey == null) {
88
- throw new Error('No key was received from the mirror node');
89
- }
90
- return this.publicKey;
91
- }
92
- async getAccountKeyAsync() {
93
- const accountInfo = await getAccountInfo(this.ledgerId, this.accountId.toString());
94
- if (!(accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.key))
95
- return null;
96
- return PublicKey.fromString(accountInfo.key.key);
82
+ throw new Error('Method not implemented.');
97
83
  }
98
84
  getLedgerId() {
99
85
  return this.ledgerId;
@@ -1,11 +1,10 @@
1
1
  import { AccountId, LedgerId, Transaction } from '@hashgraph/sdk';
2
- import { EngineTypes, SessionTypes, SignClientTypes } from '@walletconnect/types';
2
+ import { SessionTypes, SignClientTypes } from '@walletconnect/types';
3
3
  import { WalletConnectModal } from '@walletconnect/modal';
4
4
  import SignClient from '@walletconnect/sign-client';
5
5
  import { LogLevel } from '../shared/logger';
6
6
  import { GetNodeAddressesResult, ExecuteTransactionParams, ExecuteTransactionResult, SignMessageParams, SignMessageResult, SignAndExecuteQueryResult, SignAndExecuteQueryParams, SignAndExecuteTransactionParams, SignAndExecuteTransactionResult, SignTransactionParams, SignTransactionResult, ExtensionData } from '../shared';
7
7
  import { DAppSigner } from './DAppSigner';
8
- import { JsonRpcResult } from '@walletconnect/jsonrpc-types';
9
8
  export * from './DAppSigner';
10
9
  export { SessionNotFoundError } from './SessionNotFoundError';
11
10
  type BaseLogger = 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'fatal';
@@ -23,7 +22,6 @@ export declare class DAppConnector {
23
22
  walletConnectModal: WalletConnectModal;
24
23
  signers: DAppSigner[];
25
24
  isInitializing: boolean;
26
- private storagePrefix;
27
25
  /**
28
26
  * Initializes the DAppConnector instance.
29
27
  * @param metadata - SignClientTypes.Metadata object for the DApp metadata.
@@ -108,7 +106,7 @@ export declare class DAppConnector {
108
106
  private createSigners;
109
107
  private onSessionConnected;
110
108
  private connectURI;
111
- request<Req extends EngineTypes.RequestParams, Res extends JsonRpcResult>({ method, params, }: Req['request']): Promise<Res>;
109
+ private request;
112
110
  /**
113
111
  * Retrieves the node addresses associated with the current Hedera network.
114
112
  *
@@ -194,7 +192,9 @@ export declare class DAppConnector {
194
192
  *
195
193
  * @param {SignTransactionParams} params - The parameters of type {@link SignTransactionParams | `SignTransactionParams`} required for `Transaction` signing.
196
194
  * @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.
197
- * @param {Transaction} params.transactionBody - a Transaction object built with the @hashgraph/sdk
195
+ * @param {Transaction | string} params.transactionBody - a built Transaction object, or a base64 string of a transaction body( HIP-820).
196
+ * HIP-820 calls for a base64 encoded proto.TransactionBody and many wallets support a serialized Transaction object generated by the Hedera Javascript SDK.
197
+ * Both options are supported here for backwards compatibility.
198
198
  * @returns Promise\<{@link SignTransactionResult}\>
199
199
  * @example
200
200
  * ```ts
@@ -212,7 +212,5 @@ export declare class DAppConnector {
212
212
  private handleSessionUpdate;
213
213
  private handleSessionDelete;
214
214
  private handlePairingDelete;
215
- private handleRelayConnected;
216
- private verifyLastConnectedInstance;
217
215
  }
218
216
  export default DAppConnector;
@@ -20,8 +20,7 @@
20
20
  import { LedgerId, Transaction } from '@hashgraph/sdk';
21
21
  import { WalletConnectModal } from '@walletconnect/modal';
22
22
  import SignClient from '@walletconnect/sign-client';
23
- import { getSdkError, isOnline } from '@walletconnect/utils';
24
- import { RELAYER_EVENTS } from '@walletconnect/core';
23
+ import { getSdkError } from '@walletconnect/utils';
25
24
  import { DefaultLogger } from '../shared/logger';
26
25
  import { HederaJsonRpcMethod, accountAndLedgerFromSession, networkNamespaces, extensionConnect, findExtensions, } from '../shared';
27
26
  import { DAppSigner } from './DAppSigner';
@@ -47,7 +46,6 @@ export class DAppConnector {
47
46
  this.onSessionIframeCreated = null;
48
47
  this.signers = [];
49
48
  this.isInitializing = false;
50
- this.storagePrefix = 'hedera-wc/dapp-connector/';
51
49
  this.abortableConnect = async (callback) => {
52
50
  return new Promise(async (resolve, reject) => {
53
51
  const pairTimeoutMs = 480000;
@@ -112,9 +110,6 @@ export class DAppConnector {
112
110
  this.signers = existingSessions.flatMap((session) => this.createSigners(session));
113
111
  else
114
112
  this.checkIframeConnect();
115
- //manual call after init before relayer connect event handler is attached
116
- this.handleRelayConnected();
117
- this.walletConnectClient.core.relayer.on(RELAYER_EVENTS.connect, this.handleRelayConnected.bind(this));
118
113
  this.walletConnectClient.on('session_event', this.handleSessionEvent.bind(this));
119
114
  this.walletConnectClient.on('session_update', this.handleSessionUpdate.bind(this));
120
115
  this.walletConnectClient.on('session_delete', this.handleSessionDelete.bind(this));
@@ -384,7 +379,6 @@ export class DAppConnector {
384
379
  if (!signer) {
385
380
  throw new Error('There is no active session. Connect to the wallet at first.');
386
381
  }
387
- await this.verifyLastConnectedInstance();
388
382
  this.logger.debug(`Using signer: ${signer.getAccountId().toString()}: ${signer.topic} - about to request.`);
389
383
  return await signer.request({
390
384
  method: method,
@@ -501,7 +495,9 @@ export class DAppConnector {
501
495
  *
502
496
  * @param {SignTransactionParams} params - The parameters of type {@link SignTransactionParams | `SignTransactionParams`} required for `Transaction` signing.
503
497
  * @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.transactionBody - a Transaction object built with the @hashgraph/sdk
498
+ * @param {Transaction | string} params.transactionBody - a built Transaction object, or a base64 string of a transaction body( HIP-820).
499
+ * HIP-820 calls for a base64 encoded proto.TransactionBody and many wallets support a serialized Transaction object generated by the Hedera Javascript SDK.
500
+ * Both options are supported here for backwards compatibility.
505
501
  * @returns Promise\<{@link SignTransactionResult}\>
506
502
  * @example
507
503
  * ```ts
@@ -580,33 +576,5 @@ export class DAppConnector {
580
576
  }
581
577
  this.logger.info('Pairing deleted by wallet');
582
578
  }
583
- // Store the last connected randomSessionIdentifier
584
- async handleRelayConnected() {
585
- if (!this.walletConnectClient) {
586
- this.logger.error('walletConnectClient not found');
587
- return;
588
- }
589
- const core = this.walletConnectClient.core;
590
- const instanceId = core.crypto.randomSessionIdentifier;
591
- await core.storage.setItem(this.storagePrefix + 'last-connected-instance', instanceId);
592
- }
593
- // In the event of another tab being connected after the current one,
594
- // the current tab will be forcibly reconnected to the relay so that
595
- // a response to the request can be received.
596
- // https://github.com/hashgraph/hedera-wallet-connect/issues/387
597
- async verifyLastConnectedInstance() {
598
- if (!this.walletConnectClient) {
599
- this.logger.error('walletConnectClient not found');
600
- return;
601
- }
602
- const core = this.walletConnectClient.core;
603
- const instanceId = core.crypto.randomSessionIdentifier;
604
- const isOnlineStatus = await isOnline();
605
- const lastConnectedInstanceId = await core.storage.getItem(this.storagePrefix + 'last-connected-instance');
606
- if (lastConnectedInstanceId != instanceId && isOnlineStatus) {
607
- this.logger.info('Forced reconnecting to the relay');
608
- await core.relayer.restartTransport();
609
- }
610
- }
611
579
  }
612
580
  export default DAppConnector;
@@ -5,5 +5,3 @@ export * from './methods';
5
5
  export * from './payloads';
6
6
  export * from './utils';
7
7
  export * from './extensionController';
8
- export * from './mirrorNode';
9
- export * from './accountInfo';
@@ -24,5 +24,3 @@ export * from './methods';
24
24
  export * from './payloads';
25
25
  export * from './utils';
26
26
  export * from './extensionController';
27
- export * from './mirrorNode';
28
- export * from './accountInfo';
@@ -84,7 +84,7 @@ export interface SignAndExecuteTransactionResponse extends EngineTypes.RespondPa
84
84
  }
85
85
  export interface SignTransactionParams {
86
86
  signerAccountId: string;
87
- transactionBody: Transaction;
87
+ transactionBody: Transaction | string;
88
88
  }
89
89
  export interface SignTransactionRequest extends EngineTypes.RequestParams {
90
90
  request: {
@@ -4,7 +4,7 @@ import { proto } from '@hashgraph/proto';
4
4
  /**
5
5
  * Converts `Transaction` to a Base64-string.
6
6
  *
7
- * Converts a transaction to bytes and then encodes it as a Base64-string. Allow uncompleted transaction (HIP-745).
7
+ * Converts a transaction to bytes and then encodes it as a Base64-string. Allow incomplete transaction (HIP-745).
8
8
  * @param transaction - Any instance of a class that extends `Transaction`
9
9
  * @returns Base64 encoded representation of the input `Transaction` object
10
10
  */
@@ -29,9 +29,10 @@ export declare function transactionToBase64String<T extends Transaction>(transac
29
29
  export declare function base64StringToTransaction<T extends Transaction>(transactionBytes: string): T;
30
30
  /**
31
31
  * @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
32
+ * @param nodeAccountId - an optional `AccountId` to set the node account ID for the transaction
32
33
  * @returns `string`
33
34
  * */
34
- export declare function transactionToTransactionBody<T extends Transaction>(transaction: T): any;
35
+ export declare function transactionToTransactionBody<T extends Transaction>(transaction: T, nodeAccountId?: AccountId | null): proto.ITransactionBody;
35
36
  export declare function transactionBodyToBase64String(transactionBody: proto.ITransactionBody): string;
36
37
  /**
37
38
  * @param transactionList - a proto.TransactionList object
@@ -23,7 +23,7 @@ import { proto } from '@hashgraph/proto';
23
23
  /**
24
24
  * Converts `Transaction` to a Base64-string.
25
25
  *
26
- * Converts a transaction to bytes and then encodes it as a Base64-string. Allow uncompleted transaction (HIP-745).
26
+ * Converts a transaction to bytes and then encodes it as a Base64-string. Allow incomplete transaction (HIP-745).
27
27
  * @param transaction - Any instance of a class that extends `Transaction`
28
28
  * @returns Base64 encoded representation of the input `Transaction` object
29
29
  */
@@ -54,12 +54,13 @@ export function base64StringToTransaction(transactionBytes) {
54
54
  }
55
55
  /**
56
56
  * @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
57
+ * @param nodeAccountId - an optional `AccountId` to set the node account ID for the transaction
57
58
  * @returns `string`
58
59
  * */
59
- export function transactionToTransactionBody(transaction) {
60
+ export function transactionToTransactionBody(transaction, nodeAccountId = null) {
60
61
  // This is a private function, though provides the capabilities to construct a proto.TransactionBody
61
62
  //@ts-ignore
62
- return transaction._makeTransactionBody(null);
63
+ return transaction._makeTransactionBody(nodeAccountId);
63
64
  }
64
65
  export function transactionBodyToBase64String(transactionBody) {
65
66
  return Uint8ArrayToBase64String(proto.TransactionBody.encode(transactionBody).finish());
@@ -1,25 +1,41 @@
1
+ import { CaipNetwork } from '@reown/appkit';
1
2
  import { type ChainNamespace } from '@reown/appkit-common';
2
3
  import { AdapterBlueprint } from '@reown/appkit/adapters';
3
4
  type UniversalProvider = Parameters<AdapterBlueprint['setUniversalProvider']>[0];
5
+ type AdapterSendTransactionParams = AdapterBlueprint.SendTransactionParams & {
6
+ address: string;
7
+ };
8
+ type GetEnsAddressParams = {
9
+ name: string;
10
+ caipNetwork?: CaipNetwork;
11
+ };
12
+ type GetEnsAddressResult = {
13
+ address: string | false;
14
+ };
15
+ type GetProfileResult = {
16
+ profileImage: string;
17
+ profileName: string;
18
+ };
4
19
  export declare class HederaAdapter extends AdapterBlueprint {
5
20
  constructor(params: AdapterBlueprint.Params);
6
- setUniversalProvider(universalProvider: UniversalProvider): void;
21
+ setUniversalProvider(universalProvider: UniversalProvider): Promise<void>;
7
22
  connect(params: AdapterBlueprint.ConnectParams): Promise<AdapterBlueprint.ConnectResult>;
8
- disconnect(): Promise<void>;
23
+ disconnect(_params?: AdapterBlueprint.DisconnectParams): Promise<AdapterBlueprint.DisconnectResult>;
9
24
  getAccounts({ namespace, }: AdapterBlueprint.GetAccountsParams & {
10
25
  namespace: ChainNamespace;
11
26
  }): Promise<AdapterBlueprint.GetAccountsResult>;
12
27
  syncConnectors(): Promise<void>;
28
+ syncConnections(_params: AdapterBlueprint.SyncConnectionsParams): Promise<void>;
13
29
  getBalance(params: AdapterBlueprint.GetBalanceParams): Promise<AdapterBlueprint.GetBalanceResult>;
14
30
  signMessage(params: AdapterBlueprint.SignMessageParams): Promise<AdapterBlueprint.SignMessageResult>;
15
31
  estimateGas(params: AdapterBlueprint.EstimateGasTransactionArgs): Promise<AdapterBlueprint.EstimateGasTransactionResult>;
16
- sendTransaction(params: AdapterBlueprint.SendTransactionParams): Promise<AdapterBlueprint.SendTransactionResult>;
32
+ sendTransaction(params: AdapterSendTransactionParams): Promise<AdapterBlueprint.SendTransactionResult>;
17
33
  writeContract(params: AdapterBlueprint.WriteContractParams): Promise<AdapterBlueprint.WriteContractResult>;
18
- getEnsAddress(params: AdapterBlueprint.GetEnsAddressParams): Promise<AdapterBlueprint.GetEnsAddressResult>;
34
+ getEnsAddress(params: GetEnsAddressParams): Promise<GetEnsAddressResult>;
19
35
  parseUnits(params: AdapterBlueprint.ParseUnitsParams): AdapterBlueprint.ParseUnitsResult;
20
36
  formatUnits(params: AdapterBlueprint.FormatUnitsParams): AdapterBlueprint.FormatUnitsResult;
21
37
  getCapabilities(params: AdapterBlueprint.GetCapabilitiesParams): Promise<unknown>;
22
- getProfile(): Promise<AdapterBlueprint.GetProfileResult>;
38
+ getProfile(): Promise<GetProfileResult>;
23
39
  grantPermissions(): Promise<unknown>;
24
40
  revokePermissions(): Promise<`0x${string}`>;
25
41
  syncConnection(params: AdapterBlueprint.SyncConnectionParams): Promise<{
@@ -5,8 +5,7 @@ import { ProviderUtil } from '@reown/appkit/store';
5
5
  import { LedgerId } from '@hashgraph/sdk';
6
6
  import { BrowserProvider, Contract, formatUnits, JsonRpcSigner, parseUnits } from 'ethers';
7
7
  import { HederaConnector } from './connectors';
8
- import { hederaNamespace } from './utils';
9
- import { getAccountInfo } from '..';
8
+ import { hederaNamespace, getAccountBalance } from './utils';
10
9
  export class HederaAdapter extends AdapterBlueprint {
11
10
  constructor(params) {
12
11
  var _a, _b;
@@ -25,10 +24,10 @@ export class HederaAdapter extends AdapterBlueprint {
25
24
  }
26
25
  super(Object.assign({}, params));
27
26
  }
28
- setUniversalProvider(universalProvider) {
27
+ async setUniversalProvider(universalProvider) {
29
28
  this.addConnector(new HederaConnector({
30
29
  provider: universalProvider,
31
- caipNetworks: this.caipNetworks || [],
30
+ caipNetworks: this.getCaipNetworks() || [],
32
31
  namespace: this.namespace,
33
32
  }));
34
33
  }
@@ -41,7 +40,7 @@ export class HederaAdapter extends AdapterBlueprint {
41
40
  address: '',
42
41
  });
43
42
  }
44
- async disconnect() {
43
+ async disconnect(_params) {
45
44
  try {
46
45
  const connector = this.getWalletConnectConnector();
47
46
  await connector.disconnect();
@@ -49,6 +48,7 @@ export class HederaAdapter extends AdapterBlueprint {
49
48
  catch (error) {
50
49
  console.warn('UniversalAdapter:disconnect - error', error);
51
50
  }
51
+ return { connections: [] };
52
52
  }
53
53
  async getAccounts({ namespace, }) {
54
54
  var _a, _b, _c, _d;
@@ -64,6 +64,9 @@ export class HederaAdapter extends AdapterBlueprint {
64
64
  async syncConnectors() {
65
65
  return Promise.resolve();
66
66
  }
67
+ async syncConnections(_params) {
68
+ return Promise.resolve();
69
+ }
67
70
  async getBalance(params) {
68
71
  const { address, caipNetwork } = params;
69
72
  if (!caipNetwork) {
@@ -73,10 +76,10 @@ export class HederaAdapter extends AdapterBlueprint {
73
76
  symbol: '',
74
77
  });
75
78
  }
76
- const accountInfo = await getAccountInfo(caipNetwork.testnet ? LedgerId.TESTNET : LedgerId.MAINNET, address);
79
+ const accountBalance = await getAccountBalance(caipNetwork.testnet ? LedgerId.TESTNET : LedgerId.MAINNET, address);
77
80
  return Promise.resolve({
78
- balance: (accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.balance)
79
- ? formatUnits(accountInfo.balance.balance, 8).toString()
81
+ balance: accountBalance
82
+ ? formatUnits(accountBalance.hbars.toTinybars().toString(), 8).toString()
80
83
  : '0',
81
84
  decimals: caipNetwork.nativeCurrency.decimals,
82
85
  symbol: caipNetwork.nativeCurrency.symbol,
@@ -1,10 +1,9 @@
1
1
  import { EventEmitter } from 'events';
2
- import Client from '@walletconnect/universal-provider/node_modules/@walletconnect/sign-client';
3
2
  import { SessionTypes } from '@walletconnect/types';
4
3
  import { IProvider, SessionNamespace, RpcProvidersMap, RequestParams, Namespace } from '@walletconnect/universal-provider';
5
4
  declare class EIP155Provider implements IProvider {
6
5
  name: string;
7
- client: Client;
6
+ client: IProvider['client'];
8
7
  chainId: number;
9
8
  namespace: SessionNamespace;
10
9
  httpProviders: RpcProvidersMap;
@@ -0,0 +1,2 @@
1
+ import { AccountBalance, LedgerId } from '@hashgraph/sdk';
2
+ export declare function getAccountBalance(ledgerId: LedgerId, address: string): Promise<AccountBalance | null>;
@@ -0,0 +1,20 @@
1
+ import { AccountBalanceQuery, AccountId, Client, LedgerId, } from '@hashgraph/sdk';
2
+ export async function getAccountBalance(ledgerId, address) {
3
+ const client = ledgerId === LedgerId.TESTNET ? Client.forTestnet() : Client.forMainnet();
4
+ let accountId;
5
+ try {
6
+ accountId = AccountId.fromString(address);
7
+ }
8
+ catch (e) {
9
+ accountId = AccountId.fromEvmAddress(0, 0, address);
10
+ }
11
+ if (accountId.num.isZero() && accountId.evmAddress != null) {
12
+ await accountId.populateAccountNum(client);
13
+ }
14
+ try {
15
+ return await new AccountBalanceQuery().setAccountId(accountId).execute(client);
16
+ }
17
+ catch (e) {
18
+ return null;
19
+ }
20
+ }
@@ -2,3 +2,4 @@ export * from './chains';
2
2
  export * from './constants';
3
3
  export * from './types';
4
4
  export * from './helpers';
5
+ export * from './account';
@@ -2,3 +2,4 @@ export * from './chains';
2
2
  export * from './constants';
3
3
  export * from './types';
4
4
  export * from './helpers';
5
+ export * from './account';
@@ -28,7 +28,6 @@ export class EIP155Wallet {
28
28
  return this.eth_signTypedData(domain, types, data);
29
29
  }
30
30
  async eth_signTransaction(transaction, provider) {
31
- console.log({ transaction });
32
31
  // Populate transaction
33
32
  const preparedTransaction = await this.connect(provider).populateTransaction(transaction);
34
33
  delete preparedTransaction.from;
@@ -68,11 +67,9 @@ export class EIP155Wallet {
68
67
  return formatJsonRpcResult(id, signedMessage);
69
68
  }
70
69
  catch (error) {
71
- console.error(error);
72
70
  if (!(error instanceof Error)) {
73
71
  return formatJsonRpcError(id, 'Failed to sign message');
74
72
  }
75
- alert(error.message);
76
73
  return formatJsonRpcError(id, error.message);
77
74
  }
78
75
  case Eip155JsonRpcMethod.SignTypedData:
@@ -86,11 +83,9 @@ export class EIP155Wallet {
86
83
  return formatJsonRpcResult(id, signedData);
87
84
  }
88
85
  catch (error) {
89
- console.error(error);
90
86
  if (!(error instanceof Error)) {
91
87
  return formatJsonRpcError(id, 'Failed to sign typed data');
92
88
  }
93
- alert(error.message);
94
89
  return formatJsonRpcError(id, error.message);
95
90
  }
96
91
  case Eip155JsonRpcMethod.SendRawTransaction:
@@ -100,14 +95,9 @@ export class EIP155Wallet {
100
95
  const sendTransaction = request.params[0];
101
96
  const txResponse = await this[request.method](sendTransaction, provider);
102
97
  const txHash = typeof txResponse === 'string' ? txResponse : txResponse === null || txResponse === void 0 ? void 0 : txResponse.hash;
103
- const txReceipt = await txResponse.wait();
104
- console.log(`Transaction broadcasted on chain ${chainId} , ${{
105
- txHash,
106
- }}, status: ${txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.status}`);
107
98
  return formatJsonRpcResult(id, txHash);
108
99
  }
109
100
  catch (error) {
110
- console.error(error);
111
101
  return formatJsonRpcError(id, error instanceof Error ? error.message : 'Failed to send transaction');
112
102
  }
113
103
  case Eip155JsonRpcMethod.SignTransaction:
@@ -118,11 +108,9 @@ export class EIP155Wallet {
118
108
  return formatJsonRpcResult(id, signature);
119
109
  }
120
110
  catch (error) {
121
- console.error(error);
122
111
  if (!(error instanceof Error)) {
123
112
  return formatJsonRpcError(id, 'Failed to sign transaction');
124
113
  }
125
- alert(error.message);
126
114
  return formatJsonRpcError(id, error.message);
127
115
  }
128
116
  default:
@@ -1,11 +1,11 @@
1
- import { Wallet as HederaWallet, AccountId, Transaction, Query } from '@hashgraph/sdk';
1
+ import { Wallet as HederaWallet, AccountId, Transaction, Query, PrivateKey } from '@hashgraph/sdk';
2
2
  import { JsonRpcError, JsonRpcResult } from '@walletconnect/jsonrpc-utils';
3
3
  import { HederaChainId, HederaJsonRpcMethod, GetNodeAddressesResult, ExecuteTransactionResult, SignAndExecuteQueryResult, SignMessageResult, SignAndExecuteTransactionResult, SignTransactionResult, WalletRequestEventArgs } from '../..';
4
4
  import Provider from '../../lib/wallet/provider';
5
5
  interface IInitArgs {
6
6
  chainId: HederaChainId;
7
7
  accountId: AccountId | string;
8
- privateKey: string;
8
+ privateKey: PrivateKey;
9
9
  _provider?: Provider;
10
10
  }
11
11
  export interface HIP820WalletInterface {
@@ -1,6 +1,6 @@
1
1
  import { Buffer } from 'buffer';
2
2
  import { getSdkError } from '@walletconnect/utils';
3
- import { Wallet as HederaWallet, Client, AccountId, PrecheckStatusError, PrivateKey, } from '@hashgraph/sdk';
3
+ import { Wallet as HederaWallet, Client, AccountId, PrecheckStatusError, } from '@hashgraph/sdk';
4
4
  import { proto } from '@hashgraph/proto';
5
5
  import { formatJsonRpcError, formatJsonRpcResult, } from '@walletconnect/jsonrpc-utils';
6
6
  import { HederaJsonRpcMethod, base64StringToQuery, Uint8ArrayToBase64String, stringToSignerMessage, signerSignaturesToSignatureMap, getHederaError, base64StringToTransaction, signatureMapToBase64String, } from '../..';
@@ -22,7 +22,7 @@ export class HIP820Wallet {
22
22
  const network = chainId.split(':')[1];
23
23
  const client = Client.forName(network);
24
24
  const provider = _provider !== null && _provider !== void 0 ? _provider : new Provider(client);
25
- const wallet = new HederaWallet(accountId, PrivateKey.fromStringECDSA(privateKey), provider);
25
+ const wallet = new HederaWallet(accountId, privateKey, provider);
26
26
  return new HIP820Wallet(wallet);
27
27
  }
28
28
  /*
@@ -118,7 +118,6 @@ export class HIP820Wallet {
118
118
  async approveSessionRequest(event) {
119
119
  const { method, id, body } = this.parseSessionRequest(event);
120
120
  const response = await this[method](id, body);
121
- console.log({ response });
122
121
  return response;
123
122
  }
124
123
  rejectSessionRequest(requestEvent) {
@@ -134,7 +133,6 @@ export class HIP820Wallet {
134
133
  _) {
135
134
  const nodesAccountIds = this.wallet.getNetwork();
136
135
  const nodes = Object.values(nodesAccountIds).map((nodeAccountId) => nodeAccountId.toString());
137
- console.log(nodes);
138
136
  return formatJsonRpcResult(id, {
139
137
  nodes,
140
138
  });
@@ -142,7 +140,7 @@ export class HIP820Wallet {
142
140
  // 2. hedera_executeTransaction
143
141
  async hedera_executeTransaction(id, signedTransaction) {
144
142
  try {
145
- const response = await signedTransaction.executeWithSigner(this.wallet);
143
+ const response = await this.wallet.call(signedTransaction);
146
144
  return formatJsonRpcResult(id, response.toJSON());
147
145
  }
148
146
  catch (e) {
@@ -203,7 +201,6 @@ export class HIP820Wallet {
203
201
  }
204
202
  // 5. hedera_signAndExecuteTransaction
205
203
  async hedera_signAndExecuteTransaction(id, transaction) {
206
- console.log({ inputTx: JSON.parse(JSON.stringify(transaction)) });
207
204
  // check transaction is incomplete (HIP-745)
208
205
  if (!transaction.isFrozen()) {
209
206
  // set multiple nodeAccountIds and transactionId if not present
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hashgraph/hedera-wallet-connect",
3
- "version": "2.0.1-canary.fa5a378.0",
4
- "description": "A library to facilitate integrating Hedera",
3
+ "version": "2.0.3-canary.1dfc9b7.0",
4
+ "description": "A library to facilitate integrating Hedera with WalletConnect",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/hashgraph/hedera-wallet-connect.git"
@@ -14,31 +14,30 @@
14
14
  "walletconnect",
15
15
  "reown",
16
16
  "hashgraph",
17
- "evm",
18
- "ethereum",
19
- "smart contracts",
20
17
  "hbar",
21
- "ethers"
18
+ "evm",
19
+ "smart contracts"
22
20
  ],
23
21
  "license": "Apache-2.0",
24
22
  "scripts": {
25
23
  "build": "rimraf dist && tsc",
26
24
  "watch": "nodemon --watch src/ --ext ts --exec \"npm run build\"",
27
- "test": "jest",
28
- "prepublishOnly": "rm -Rf dist && npm run build",
25
+ "test": "jest --coverage",
26
+ "prepublishOnly": "rm -Rf dist && npm run test && npm run build",
29
27
  "prettier:check": "prettier --check ./src/",
30
28
  "prettier:fix": "prettier --write ./src/"
31
29
  },
32
30
  "peerDependencies": {
33
- "@hashgraph/sdk": "^2.61.0",
34
- "@reown/appkit": "^1.7.1",
35
- "@reown/walletkit": "^1.2.3",
31
+ "@hashgraph/sdk": "^2.63.0",
32
+ "@reown/appkit": "^1.7.16",
33
+ "@reown/walletkit": "^1.2.8",
36
34
  "@walletconnect/modal": "^2.7.0",
37
35
  "ethers": "^6.13.5"
38
36
  },
39
37
  "devDependencies": {
40
38
  "@swc/jest": "^0.2.37",
41
- "jest": "^29.7.0",
39
+ "@types/jest": "^30.0.0",
40
+ "jest": "^30.0.3",
42
41
  "prettier": "^3.5.3",
43
42
  "ts-node": "^10.9.2",
44
43
  "typescript": "^5.8.2"
@@ -1,30 +0,0 @@
1
- export interface AccountInfo {
2
- account: string;
3
- alias: string;
4
- auto_renew_period: number;
5
- balance: Balance;
6
- created_timestamp: string;
7
- decline_reward: boolean;
8
- deleted: boolean;
9
- ethereum_nonce: number;
10
- evm_address: string;
11
- expiry_timestamp: string;
12
- key: Key | null;
13
- max_automatic_token_associations: number;
14
- memo: string;
15
- pending_reward: number;
16
- receiver_sig_required: boolean;
17
- }
18
- export interface Balance {
19
- balance: number;
20
- timestamp: string;
21
- tokens: Token[];
22
- }
23
- export interface Token {
24
- token_id: string;
25
- balance: number;
26
- }
27
- export interface Key {
28
- _type: string;
29
- key: string;
30
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { LedgerId } from '@hashgraph/sdk';
2
- import { AccountInfo } from '.';
3
- export declare function getAccountInfo(ledgerId: LedgerId, address: string): Promise<AccountInfo | null>;
@@ -1,17 +0,0 @@
1
- function getMirrorNodeUrl(ledgerId) {
2
- return `https://${ledgerId.toString()}.mirrornode.hedera.com`;
3
- }
4
- export async function getAccountInfo(ledgerId, address) {
5
- const mirrorNodeApiUrl = getMirrorNodeUrl(ledgerId);
6
- const url = `${mirrorNodeApiUrl}/api/v1/accounts/${address}`;
7
- const result = await fetch(url, {
8
- headers: {
9
- accept: 'application/json',
10
- },
11
- });
12
- if (result.status !== 200) {
13
- return null;
14
- }
15
- const response = await result.json();
16
- return response;
17
- }