@hashgraph/hedera-wallet-connect 2.0.4 → 2.0.5-canary.09073be.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.
Files changed (69) hide show
  1. package/package.json +1 -1
  2. package/dist/index.d.ts +0 -2
  3. package/dist/index.js +0 -21
  4. package/dist/lib/dapp/DAppSigner.d.ts +0 -60
  5. package/dist/lib/dapp/DAppSigner.js +0 -344
  6. package/dist/lib/dapp/SessionNotFoundError.d.ts +0 -3
  7. package/dist/lib/dapp/SessionNotFoundError.js +0 -6
  8. package/dist/lib/dapp/index.d.ts +0 -216
  9. package/dist/lib/dapp/index.js +0 -588
  10. package/dist/lib/index.d.ts +0 -3
  11. package/dist/lib/index.js +0 -22
  12. package/dist/lib/shared/chainIds.d.ts +0 -11
  13. package/dist/lib/shared/chainIds.js +0 -31
  14. package/dist/lib/shared/errors.d.ts +0 -48
  15. package/dist/lib/shared/errors.js +0 -51
  16. package/dist/lib/shared/events.d.ts +0 -7
  17. package/dist/lib/shared/events.js +0 -27
  18. package/dist/lib/shared/extensionController.d.ts +0 -21
  19. package/dist/lib/shared/extensionController.js +0 -42
  20. package/dist/lib/shared/index.d.ts +0 -7
  21. package/dist/lib/shared/index.js +0 -26
  22. package/dist/lib/shared/logger.d.ts +0 -21
  23. package/dist/lib/shared/logger.js +0 -63
  24. package/dist/lib/shared/methods.d.ts +0 -12
  25. package/dist/lib/shared/methods.js +0 -32
  26. package/dist/lib/shared/payloads.d.ts +0 -101
  27. package/dist/lib/shared/payloads.js +0 -20
  28. package/dist/lib/shared/utils.d.ts +0 -280
  29. package/dist/lib/shared/utils.js +0 -461
  30. package/dist/lib/wallet/index.d.ts +0 -39
  31. package/dist/lib/wallet/index.js +0 -306
  32. package/dist/lib/wallet/provider.d.ts +0 -17
  33. package/dist/lib/wallet/provider.js +0 -58
  34. package/dist/lib/wallet/types.d.ts +0 -31
  35. package/dist/lib/wallet/types.js +0 -20
  36. package/dist/reown/adapter.d.ts +0 -59
  37. package/dist/reown/adapter.js +0 -290
  38. package/dist/reown/connectors/HederaConnector.d.ts +0 -29
  39. package/dist/reown/connectors/HederaConnector.js +0 -32
  40. package/dist/reown/connectors/index.d.ts +0 -1
  41. package/dist/reown/connectors/index.js +0 -1
  42. package/dist/reown/index.d.ts +0 -4
  43. package/dist/reown/index.js +0 -4
  44. package/dist/reown/providers/EIP155Provider.d.ts +0 -33
  45. package/dist/reown/providers/EIP155Provider.js +0 -187
  46. package/dist/reown/providers/HIP820Provider.d.ts +0 -26
  47. package/dist/reown/providers/HIP820Provider.js +0 -67
  48. package/dist/reown/providers/HederaProvider.d.ts +0 -166
  49. package/dist/reown/providers/HederaProvider.js +0 -506
  50. package/dist/reown/providers/index.d.ts +0 -3
  51. package/dist/reown/providers/index.js +0 -3
  52. package/dist/reown/utils/account.d.ts +0 -2
  53. package/dist/reown/utils/account.js +0 -41
  54. package/dist/reown/utils/chains.d.ts +0 -18
  55. package/dist/reown/utils/chains.js +0 -152
  56. package/dist/reown/utils/constants.d.ts +0 -16
  57. package/dist/reown/utils/constants.js +0 -18
  58. package/dist/reown/utils/helpers.d.ts +0 -12
  59. package/dist/reown/utils/helpers.js +0 -25
  60. package/dist/reown/utils/index.d.ts +0 -5
  61. package/dist/reown/utils/index.js +0 -5
  62. package/dist/reown/utils/types.d.ts +0 -9
  63. package/dist/reown/utils/types.js +0 -1
  64. package/dist/reown/wallets/EIP155Wallet.d.ts +0 -46
  65. package/dist/reown/wallets/EIP155Wallet.js +0 -124
  66. package/dist/reown/wallets/HIP820Wallet.d.ts +0 -53
  67. package/dist/reown/wallets/HIP820Wallet.js +0 -236
  68. package/dist/reown/wallets/index.d.ts +0 -2
  69. package/dist/reown/wallets/index.js +0 -2
@@ -1,166 +0,0 @@
1
- import { TransactionRequest } from 'ethers';
2
- import { CaipNetwork, RequestArguments } from '@reown/appkit';
3
- import type { EstimateGasTransactionArgs, SendTransactionArgs, WriteContractArgs } from '@reown/appkit';
4
- import UniversalProvider, { RpcProviderMap, UniversalProviderOpts } from '@walletconnect/universal-provider';
5
- import { Transaction } from '@hashgraph/sdk';
6
- import { ExecuteTransactionParams, SignMessageParams, SignAndExecuteQueryParams, SignAndExecuteTransactionParams, SignTransactionParams } from '../..';
7
- import { EthFilter } from '../utils';
8
- import HIP820Provider from './HIP820Provider';
9
- import EIP155Provider from './EIP155Provider';
10
- export type HederaWalletConnectProviderConfig = {
11
- chains: CaipNetwork[];
12
- } & UniversalProviderOpts;
13
- export declare class HederaProvider extends UniversalProvider {
14
- private hederaLogger;
15
- nativeProvider?: HIP820Provider;
16
- eip155Provider?: EIP155Provider;
17
- constructor(opts: UniversalProviderOpts);
18
- static init(opts: UniversalProviderOpts): Promise<HederaProvider>;
19
- emit(event: string, data?: unknown): void;
20
- getAccountAddresses(): string[];
21
- request<T = unknown>(args: RequestArguments, chain?: string | undefined, expiry?: number | undefined): Promise<T>;
22
- /**
23
- * Retrieves the node addresses associated with the current Hedera network.
24
- *
25
- * When there is no active session or an error occurs during the request.
26
- * @returns Promise\<{@link GetNodeAddressesResult}\>
27
- */
28
- hedera_getNodeAddresses(): Promise<{
29
- nodes: string[];
30
- }>;
31
- /**
32
- * Executes a transaction on the Hedera network.
33
- *
34
- * @param {ExecuteTransactionParams} params - The parameters of type {@link ExecuteTransactionParams | `ExecuteTransactionParams`} required for the transaction execution.
35
- * @param {string[]} params.signedTransaction - Array of Base64-encoded `Transaction`'s
36
- * @returns Promise\<{@link ExecuteTransactionResult}\>
37
- * @example
38
- * Use helper `transactionToBase64String` to encode `Transaction` to Base64 string
39
- * ```ts
40
- * const params = {
41
- * signedTransaction: [transactionToBase64String(transaction)]
42
- * }
43
- *
44
- * const result = await dAppConnector.executeTransaction(params)
45
- * ```
46
- */
47
- hedera_executeTransaction(params: ExecuteTransactionParams): Promise<import("@hashgraph/sdk/lib/transaction/TransactionResponse").TransactionResponseJSON>;
48
- /**
49
- * Signs a provided `message` with provided `signerAccountId`.
50
- *
51
- * @param {SignMessageParams} params - The parameters of type {@link SignMessageParams | `SignMessageParams`} required for signing message.
52
- * @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.
53
- * @param {string} params.message - a plain UTF-8 string
54
- * @returns Promise\<{@link SignMessageResult}\>
55
- * @example
56
- * ```ts
57
- * const params = {
58
- * signerAccountId: 'hedera:testnet:0.0.12345',
59
- * message: 'Hello World!'
60
- * }
61
- *
62
- * const result = await dAppConnector.signMessage(params)
63
- * ```
64
- */
65
- hedera_signMessage(params: SignMessageParams): Promise<{
66
- signatureMap: string;
67
- }>;
68
- /**
69
- * Signs and send `Query` on the Hedera network.
70
- *
71
- * @param {SignAndExecuteQueryParams} params - The parameters of type {@link SignAndExecuteQueryParams | `SignAndExecuteQueryParams`} required for the Query execution.
72
- * @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.
73
- * @param {string} params.query - `Query` object represented as Base64 string
74
- * @returns Promise\<{@link SignAndExecuteQueryResult}\>
75
- * @example
76
- * Use helper `queryToBase64String` to encode `Query` to Base64 string
77
- * ```ts
78
- * const params = {
79
- * signerAccountId: '0.0.12345',
80
- * query: queryToBase64String(query),
81
- * }
82
- *
83
- * const result = await dAppConnector.signAndExecuteQuery(params)
84
- * ```
85
- */
86
- hedera_signAndExecuteQuery(params: SignAndExecuteQueryParams): Promise<{
87
- response: string;
88
- }>;
89
- /**
90
- * Signs and executes Transactions on the Hedera network.
91
- *
92
- * @param {SignAndExecuteTransactionParams} params - The parameters of type {@link SignAndExecuteTransactionParams | `SignAndExecuteTransactionParams`} required for `Transaction` signing and execution.
93
- * @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.
94
- * @param {string[]} params.transaction - Array of Base64-encoded `Transaction`'s
95
- * @returns Promise\<{@link SignAndExecuteTransactionResult}\>
96
- * @example
97
- * Use helper `transactionToBase64String` to encode `Transaction` to Base64 string
98
- * ```ts
99
- * const params = {
100
- * signerAccountId: '0.0.12345'
101
- * transaction: [transactionToBase64String(transaction)]
102
- * }
103
- *
104
- * const result = await dAppConnector.signAndExecuteTransaction(params)
105
- * ```
106
- */
107
- hedera_signAndExecuteTransaction(params: SignAndExecuteTransactionParams): Promise<import("@hashgraph/sdk/lib/transaction/TransactionResponse").TransactionResponseJSON>;
108
- /**
109
- * Signs and executes Transactions on the Hedera network.
110
- *
111
- * @param {SignTransactionParams} params - The parameters of type {@link SignTransactionParams | `SignTransactionParams`} required for `Transaction` signing.
112
- * @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.
113
- * @param {Transaction} params.transactionBody - a Transaction object built with the @hgraph/sdk
114
- * @returns Promise\<{@link SignTransactionResult}\>
115
- * @example
116
- * ```ts
117
- *
118
- * const params = {
119
- * signerAccountId: '0.0.12345',
120
- * transactionBody
121
- * }
122
- *
123
- * const result = await dAppConnector.signTransaction(params)
124
- * ```
125
- */
126
- hedera_signTransaction(params: SignTransactionParams): Promise<Transaction>;
127
- eth_signMessage(message: string, address: string): Promise<`0x${string}`>;
128
- eth_estimateGas(data: EstimateGasTransactionArgs, address: string, networkId: number): Promise<bigint>;
129
- eth_sendTransaction(data: SendTransactionArgs, address: string, networkId: number): Promise<`0x${string}`>;
130
- eth_writeContract(data: WriteContractArgs, address: string, chainId: number): Promise<string>;
131
- eth_blockNumber(): Promise<string>;
132
- eth_call(tx: TransactionRequest, block?: string): Promise<string>;
133
- eth_feeHistory(blockCount: number, newestBlock: string, rewardPercentiles: number[]): Promise<string>;
134
- eth_gasPrice(): Promise<string>;
135
- eth_getBlockByHash(hash: string, fullTx?: boolean): Promise<string>;
136
- eth_getBlockByNumber(block: string, fullTx?: boolean): Promise<unknown>;
137
- eth_getBlockTransactionCountByHash(hash: string): Promise<string>;
138
- eth_getBlockTransactionCountByNumber(block: string): Promise<string>;
139
- eth_getCode(address: string, block?: string): Promise<string>;
140
- eth_getFilterLogs(filterId: string): Promise<string>;
141
- eth_getFilterChanges(filterId: string): Promise<string>;
142
- eth_getLogs(filter: EthFilter): Promise<string>;
143
- eth_getStorageAt(address: string, position: string, block?: string): Promise<string>;
144
- eth_getTransactionByBlockHashAndIndex(hash: string, index: string): Promise<string>;
145
- eth_getTransactionByBlockNumberAndIndex(block: string, index: string): Promise<string>;
146
- eth_getTransactionByHash(hash: string): Promise<string>;
147
- eth_getTransactionCount(address: string, block?: string): Promise<string>;
148
- eth_getTransactionReceipt(hash: string): Promise<string>;
149
- eth_hashrate(): Promise<string>;
150
- eth_maxPriorityFeePerGas(): Promise<string>;
151
- eth_mining(): Promise<string>;
152
- eth_newBlockFilter(): Promise<string>;
153
- eth_newFilter(filter: EthFilter): Promise<string>;
154
- eth_submitWork(params: string[]): Promise<string>;
155
- eth_syncing(): Promise<string>;
156
- eth_uninstallFilter(filterId: string): Promise<string>;
157
- net_listening(): Promise<string>;
158
- net_version(): Promise<string>;
159
- web3_clientVersion(): Promise<string>;
160
- eth_chainId(): Promise<string>;
161
- connect(params?: any): Promise<any>;
162
- pair(pairingTopic: string | undefined): ReturnType<UniversalProvider['pair']>;
163
- private initProviders;
164
- get rpcProviders(): RpcProviderMap;
165
- set rpcProviders(_: RpcProviderMap);
166
- }
@@ -1,506 +0,0 @@
1
- import { BrowserProvider, Contract, JsonRpcSigner, hexlify, isHexString, toQuantity, toUtf8Bytes, } from 'ethers';
2
- import UniversalProvider from '@walletconnect/universal-provider';
3
- import { Transaction } from '@hashgraph/sdk';
4
- import { HederaJsonRpcMethod, } from '../..';
5
- import { getChainsFromApprovedSession, mergeRequiredOptionalNamespaces, } from '../utils';
6
- import HIP820Provider from './HIP820Provider';
7
- import EIP155Provider from './EIP155Provider';
8
- import { createLogger } from '../../lib/shared/logger';
9
- // Reown AppKit UniversalProvider for HIP-820 & EIP-155 version implementation of the @hashgraph/hedera-wallet-connect DAppConnector
10
- export class HederaProvider extends UniversalProvider {
11
- constructor(opts) {
12
- super(opts);
13
- this.hederaLogger = createLogger('HederaProvider');
14
- }
15
- static async init(opts) {
16
- var _a, _b;
17
- const provider = new HederaProvider(opts);
18
- //@ts-expect-error
19
- await provider.initialize();
20
- provider.namespaces = Object.assign(Object.assign({}, (((_a = provider.providerOpts) === null || _a === void 0 ? void 0 : _a.optionalNamespaces) || {})), (((_b = provider.providerOpts) === null || _b === void 0 ? void 0 : _b.requiredNamespaces) || {}));
21
- if (provider.session)
22
- provider.initProviders();
23
- return provider;
24
- }
25
- emit(event, data) {
26
- this.events.emit(event, data);
27
- }
28
- getAccountAddresses() {
29
- if (!this.session) {
30
- throw new Error('Not initialized. Please call connect()');
31
- }
32
- return Object.values(this.session.namespaces).flatMap((namespace) => { var _a; return (_a = namespace.accounts.map((account) => account.split(':')[2])) !== null && _a !== void 0 ? _a : []; });
33
- }
34
- async request(args, chain, expiry) {
35
- var _a, _b, _c, _d, _e;
36
- if (!this.session || !this.namespaces) {
37
- throw new Error('Please call connect() before request()');
38
- }
39
- let chainId = chain;
40
- if (Object.values(HederaJsonRpcMethod).includes(args.method)) {
41
- if (!this.nativeProvider) {
42
- throw new Error('nativeProvider not initialized. Please call connect()');
43
- }
44
- chainId = chainId !== null && chainId !== void 0 ? chainId : (_a = this.namespaces.hedera) === null || _a === void 0 ? void 0 : _a.chains[0];
45
- return (_b = this.nativeProvider) === null || _b === void 0 ? void 0 : _b.request({
46
- request: Object.assign({}, args),
47
- chainId: chainId,
48
- topic: this.session.topic,
49
- expiry,
50
- });
51
- }
52
- else {
53
- if (!this.eip155Provider) {
54
- throw new Error('eip155Provider not initialized');
55
- }
56
- chainId = chainId !== null && chainId !== void 0 ? chainId : (_d = (_c = this.namespaces) === null || _c === void 0 ? void 0 : _c.eip155) === null || _d === void 0 ? void 0 : _d.chains[0];
57
- return (_e = this.eip155Provider) === null || _e === void 0 ? void 0 : _e.request({
58
- request: Object.assign({}, args),
59
- chainId: chainId,
60
- topic: this.session.topic,
61
- expiry,
62
- });
63
- }
64
- }
65
- /**
66
- * Retrieves the node addresses associated with the current Hedera network.
67
- *
68
- * When there is no active session or an error occurs during the request.
69
- * @returns Promise\<{@link GetNodeAddressesResult}\>
70
- */
71
- async hedera_getNodeAddresses() {
72
- return await this.request({
73
- method: HederaJsonRpcMethod.GetNodeAddresses,
74
- params: undefined,
75
- });
76
- }
77
- /**
78
- * Executes a transaction on the Hedera network.
79
- *
80
- * @param {ExecuteTransactionParams} params - The parameters of type {@link ExecuteTransactionParams | `ExecuteTransactionParams`} required for the transaction execution.
81
- * @param {string[]} params.signedTransaction - Array of Base64-encoded `Transaction`'s
82
- * @returns Promise\<{@link ExecuteTransactionResult}\>
83
- * @example
84
- * Use helper `transactionToBase64String` to encode `Transaction` to Base64 string
85
- * ```ts
86
- * const params = {
87
- * signedTransaction: [transactionToBase64String(transaction)]
88
- * }
89
- *
90
- * const result = await dAppConnector.executeTransaction(params)
91
- * ```
92
- */
93
- async hedera_executeTransaction(params) {
94
- return await this.request({
95
- method: HederaJsonRpcMethod.ExecuteTransaction,
96
- params,
97
- });
98
- }
99
- /**
100
- * Signs a provided `message` with provided `signerAccountId`.
101
- *
102
- * @param {SignMessageParams} params - The parameters of type {@link SignMessageParams | `SignMessageParams`} required for signing message.
103
- * @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.
104
- * @param {string} params.message - a plain UTF-8 string
105
- * @returns Promise\<{@link SignMessageResult}\>
106
- * @example
107
- * ```ts
108
- * const params = {
109
- * signerAccountId: 'hedera:testnet:0.0.12345',
110
- * message: 'Hello World!'
111
- * }
112
- *
113
- * const result = await dAppConnector.signMessage(params)
114
- * ```
115
- */
116
- async hedera_signMessage(params) {
117
- return await this.request({
118
- method: HederaJsonRpcMethod.SignMessage,
119
- params,
120
- });
121
- }
122
- /**
123
- * Signs and send `Query` on the Hedera network.
124
- *
125
- * @param {SignAndExecuteQueryParams} params - The parameters of type {@link SignAndExecuteQueryParams | `SignAndExecuteQueryParams`} required for the Query execution.
126
- * @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.
127
- * @param {string} params.query - `Query` object represented as Base64 string
128
- * @returns Promise\<{@link SignAndExecuteQueryResult}\>
129
- * @example
130
- * Use helper `queryToBase64String` to encode `Query` to Base64 string
131
- * ```ts
132
- * const params = {
133
- * signerAccountId: '0.0.12345',
134
- * query: queryToBase64String(query),
135
- * }
136
- *
137
- * const result = await dAppConnector.signAndExecuteQuery(params)
138
- * ```
139
- */
140
- async hedera_signAndExecuteQuery(params) {
141
- return await this.request({
142
- method: HederaJsonRpcMethod.SignAndExecuteQuery,
143
- params,
144
- });
145
- }
146
- /**
147
- * Signs and executes Transactions on the Hedera network.
148
- *
149
- * @param {SignAndExecuteTransactionParams} params - The parameters of type {@link SignAndExecuteTransactionParams | `SignAndExecuteTransactionParams`} required for `Transaction` signing and execution.
150
- * @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.
151
- * @param {string[]} params.transaction - Array of Base64-encoded `Transaction`'s
152
- * @returns Promise\<{@link SignAndExecuteTransactionResult}\>
153
- * @example
154
- * Use helper `transactionToBase64String` to encode `Transaction` to Base64 string
155
- * ```ts
156
- * const params = {
157
- * signerAccountId: '0.0.12345'
158
- * transaction: [transactionToBase64String(transaction)]
159
- * }
160
- *
161
- * const result = await dAppConnector.signAndExecuteTransaction(params)
162
- * ```
163
- */
164
- async hedera_signAndExecuteTransaction(params) {
165
- return await this.request({
166
- method: HederaJsonRpcMethod.SignAndExecuteTransaction,
167
- params,
168
- });
169
- }
170
- /**
171
- * Signs and executes Transactions on the Hedera network.
172
- *
173
- * @param {SignTransactionParams} params - The parameters of type {@link SignTransactionParams | `SignTransactionParams`} required for `Transaction` signing.
174
- * @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.
175
- * @param {Transaction} params.transactionBody - a Transaction object built with the @hgraph/sdk
176
- * @returns Promise\<{@link SignTransactionResult}\>
177
- * @example
178
- * ```ts
179
- *
180
- * const params = {
181
- * signerAccountId: '0.0.12345',
182
- * transactionBody
183
- * }
184
- *
185
- * const result = await dAppConnector.signTransaction(params)
186
- * ```
187
- */
188
- async hedera_signTransaction(params) {
189
- var _a, _b, _c;
190
- if (!this.session) {
191
- throw new Error('Session not initialized. Please call connect()');
192
- }
193
- if (!this.nativeProvider) {
194
- throw new Error('nativeProvider not initialized. Please call connect()');
195
- }
196
- if (!((params === null || params === void 0 ? void 0 : params.transactionBody) instanceof Transaction)) {
197
- throw new Error('Transaction sent in incorrect format. Ensure transaction body is a Transaction object.');
198
- }
199
- 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();
200
- const isValidSigner = (_c = this.nativeProvider) === null || _c === void 0 ? void 0 : _c.requestAccounts().includes(signerAccountId !== null && signerAccountId !== void 0 ? signerAccountId : '');
201
- if (!isValidSigner) {
202
- throw new Error(`Signer not found for account ${signerAccountId}`);
203
- }
204
- return (await this.nativeProvider.signTransaction(params.transactionBody, this.session.topic));
205
- }
206
- async eth_signMessage(message, address) {
207
- const hexMessage = isHexString(message) ? message : hexlify(toUtf8Bytes(message));
208
- const signature = await this.request({
209
- method: 'personal_sign',
210
- params: [hexMessage, address],
211
- });
212
- return signature;
213
- }
214
- async eth_estimateGas(data, address, networkId) {
215
- if (!address) {
216
- throw new Error('estimateGas - address is undefined');
217
- }
218
- if (data.chainNamespace !== 'eip155') {
219
- throw new Error('estimateGas - chainNamespace is not eip155');
220
- }
221
- const txParams = {
222
- from: data.address,
223
- to: data.to,
224
- data: data.data,
225
- type: 0,
226
- };
227
- const browserProvider = new BrowserProvider(this, networkId);
228
- const signer = new JsonRpcSigner(browserProvider, address);
229
- return await signer.estimateGas(txParams);
230
- }
231
- async eth_sendTransaction(data, address, networkId) {
232
- if (!address) {
233
- throw new Error('sendTransaction - address is undefined');
234
- }
235
- if (data.chainNamespace !== 'eip155') {
236
- throw new Error('sendTransaction - chainNamespace is not eip155');
237
- }
238
- const txParams = {
239
- to: data.to,
240
- value: data.value,
241
- gasLimit: data.gas,
242
- gasPrice: data.gasPrice,
243
- data: data.data,
244
- type: 0,
245
- };
246
- const browserProvider = new BrowserProvider(this, networkId);
247
- const signer = new JsonRpcSigner(browserProvider, address);
248
- const txResponse = await signer.sendTransaction(txParams);
249
- const txReceipt = await txResponse.wait();
250
- return (txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.hash) || null;
251
- }
252
- async eth_writeContract(data, address, chainId) {
253
- if (!address) {
254
- throw new Error('writeContract - address is undefined');
255
- }
256
- const browserProvider = new BrowserProvider(this, chainId);
257
- const signer = new JsonRpcSigner(browserProvider, address);
258
- const contract = new Contract(data.tokenAddress, data.abi, signer);
259
- if (!contract || !data.method) {
260
- throw new Error('Contract method is undefined');
261
- }
262
- const method = contract[data.method];
263
- if (method) {
264
- return (await method(...data.args));
265
- }
266
- throw new Error('Contract method is undefined');
267
- }
268
- // Returns the latest block number
269
- async eth_blockNumber() {
270
- return this.request({ method: 'eth_blockNumber', params: [] });
271
- }
272
- // Executes a call with the given transaction request and block identifier
273
- async eth_call(tx, block = 'latest') {
274
- return this.request({ method: 'eth_call', params: [tx, block] });
275
- }
276
- // Returns fee history data for the given parameters
277
- async eth_feeHistory(blockCount, newestBlock, rewardPercentiles) {
278
- return this.request({
279
- method: 'eth_feeHistory',
280
- params: [toQuantity(blockCount), newestBlock, rewardPercentiles],
281
- });
282
- }
283
- // Returns the current gas price
284
- async eth_gasPrice() {
285
- return this.request({ method: 'eth_gasPrice', params: [] });
286
- }
287
- // Returns block details by hash, optionally including full transactions
288
- async eth_getBlockByHash(hash, fullTx = false) {
289
- return this.request({ method: 'eth_getBlockByHash', params: [hash, fullTx] });
290
- }
291
- // Returns block details by block number, optionally including full transactions
292
- async eth_getBlockByNumber(block, fullTx = false) {
293
- return this.request({ method: 'eth_getBlockByNumber', params: [block, fullTx] });
294
- }
295
- // Returns the number of transactions in a block identified by its hash
296
- async eth_getBlockTransactionCountByHash(hash) {
297
- return this.request({
298
- method: 'eth_getBlockTransactionCountByHash',
299
- params: [hash],
300
- });
301
- }
302
- // Returns the number of transactions in a block identified by its number
303
- async eth_getBlockTransactionCountByNumber(block) {
304
- return this.request({
305
- method: 'eth_getBlockTransactionCountByNumber',
306
- params: [block],
307
- });
308
- }
309
- // Returns the contract code at the specified address and block
310
- async eth_getCode(address, block = 'latest') {
311
- return this.request({ method: 'eth_getCode', params: [address, block] });
312
- }
313
- // Returns filter logs based on the provided filter object
314
- async eth_getFilterLogs(filterId) {
315
- return this.request({ method: 'eth_getFilterLogs', params: [filterId] });
316
- }
317
- // Returns filter changes for the given filter ID
318
- async eth_getFilterChanges(filterId) {
319
- return this.request({ method: 'eth_getFilterChanges', params: [filterId] });
320
- }
321
- // Returns logs based on the provided filter object
322
- async eth_getLogs(filter) {
323
- return this.request({ method: 'eth_getLogs', params: [filter] });
324
- }
325
- // Returns storage data at a specific address and position for a given block
326
- async eth_getStorageAt(address, position, block = 'latest') {
327
- return this.request({
328
- method: 'eth_getStorageAt',
329
- params: [address, position, block],
330
- });
331
- }
332
- // Returns a transaction from a block by its hash and index
333
- async eth_getTransactionByBlockHashAndIndex(hash, index) {
334
- return await this.request({
335
- method: 'eth_getTransactionByBlockHashAndIndex',
336
- params: [hash, index],
337
- });
338
- }
339
- // Returns a transaction from a block by its number and index
340
- async eth_getTransactionByBlockNumberAndIndex(block, index) {
341
- return this.request({
342
- method: 'eth_getTransactionByBlockNumberAndIndex',
343
- params: [block, index],
344
- });
345
- }
346
- // Returns transaction details by its hash
347
- async eth_getTransactionByHash(hash) {
348
- return this.request({ method: 'eth_getTransactionByHash', params: [hash] });
349
- }
350
- // Returns the transaction count for a given address and block
351
- async eth_getTransactionCount(address, block = 'latest') {
352
- return this.request({
353
- method: 'eth_getTransactionCount',
354
- params: [address, block],
355
- });
356
- }
357
- // Returns the transaction receipt for a given transaction hash
358
- async eth_getTransactionReceipt(hash) {
359
- return this.request({ method: 'eth_getTransactionReceipt', params: [hash] });
360
- }
361
- // Returns the current hashrate
362
- async eth_hashrate() {
363
- return this.request({ method: 'eth_hashrate', params: [] });
364
- }
365
- // Returns the max priority fee per gas
366
- async eth_maxPriorityFeePerGas() {
367
- return this.request({ method: 'eth_maxPriorityFeePerGas', params: [] });
368
- }
369
- // Returns the mining status
370
- async eth_mining() {
371
- return this.request({ method: 'eth_mining', params: [] });
372
- }
373
- // Creates a new block filter and returns its ID
374
- async eth_newBlockFilter() {
375
- return this.request({ method: 'eth_newBlockFilter', params: [] });
376
- }
377
- // Creates a new filter based on the provided filter object and returns its ID
378
- async eth_newFilter(filter) {
379
- return this.request({ method: 'eth_newFilter', params: [filter] });
380
- }
381
- // Submits work for mining (dummy parameters) and returns the result
382
- async eth_submitWork(params) {
383
- return this.request({ method: 'eth_submitWork', params });
384
- }
385
- // Returns the syncing status
386
- async eth_syncing() {
387
- return this.request({ method: 'eth_syncing', params: [] });
388
- }
389
- // Uninstalls the filter with the given ID
390
- async eth_uninstallFilter(filterId) {
391
- return this.request({ method: 'eth_uninstallFilter', params: [filterId] });
392
- }
393
- // Returns the network listening status
394
- async net_listening() {
395
- return this.request({ method: 'net_listening', params: [] });
396
- }
397
- // Returns the current network version
398
- async net_version() {
399
- return this.request({ method: 'net_version', params: [] });
400
- }
401
- // Returns the client version string
402
- async web3_clientVersion() {
403
- return this.request({ method: 'web3_clientVersion', params: [] });
404
- }
405
- async eth_chainId() {
406
- return this.request({ method: 'eth_chainId', params: [] });
407
- }
408
- async connect(params) {
409
- this.hederaLogger.debug('connect called with params:', params);
410
- // Update the internal namespace properties before connecting
411
- if (params) {
412
- if (params.requiredNamespaces) {
413
- this.hederaLogger.debug('Setting requiredNamespaces:', params.requiredNamespaces);
414
- // @ts-ignore - accessing private property
415
- this.requiredNamespaces = params.requiredNamespaces;
416
- }
417
- if (params.optionalNamespaces) {
418
- this.hederaLogger.debug('Setting optionalNamespaces:', params.requiredNamespaces);
419
- // @ts-ignore - accessing private property
420
- this.optionalNamespaces = params.optionalNamespaces;
421
- }
422
- if (params.namespaces) {
423
- this.hederaLogger.debug('Setting namespaces:', params.namespaces);
424
- // @ts-ignore - accessing private property
425
- this.namespaces = params.namespaces;
426
- }
427
- }
428
- this.hederaLogger.debug('Calling super.connect with params');
429
- // Try to directly pass the namespaces to the parent connect
430
- let result;
431
- try {
432
- result = await super.connect(params);
433
- }
434
- catch (error) {
435
- this.hederaLogger.error('Error in super.connect:', error);
436
- throw error;
437
- }
438
- this.hederaLogger.info('super.connect completed successfully');
439
- this.hederaLogger.debug('Result from super.connect:', result);
440
- this.initProviders();
441
- return result;
442
- }
443
- async pair(pairingTopic) {
444
- console.log(pairingTopic);
445
- //@ts-expect-error
446
- console.log(this.requiredNamespaces);
447
- const session = await super.pair(pairingTopic);
448
- this.initProviders();
449
- return session;
450
- }
451
- initProviders() {
452
- if (!this.client) {
453
- throw new Error('Sign Client not initialized');
454
- }
455
- if (!this.session || !this.namespaces) {
456
- return {};
457
- }
458
- const namespaces = Object.keys(this.namespaces);
459
- const providers = {};
460
- namespaces.forEach((namespace) => {
461
- var _a, _b, _c, _d;
462
- const accounts = ((_b = (_a = this.session) === null || _a === void 0 ? void 0 : _a.namespaces[namespace]) === null || _b === void 0 ? void 0 : _b.accounts) || [];
463
- const approvedChains = getChainsFromApprovedSession(accounts);
464
- const mergedNamespaces = mergeRequiredOptionalNamespaces(this.namespaces, this.optionalNamespaces);
465
- const combinedNamespace = Object.assign(Object.assign(Object.assign({}, mergedNamespaces[namespace]), { accounts, chains: approvedChains }), (((_d = (_c = this.optionalNamespaces) === null || _c === void 0 ? void 0 : _c[namespace]) === null || _d === void 0 ? void 0 : _d.rpcMap) && {
466
- rpcMap: this.optionalNamespaces[namespace].rpcMap,
467
- }));
468
- switch (namespace) {
469
- case 'hedera': {
470
- const provider = new HIP820Provider({
471
- namespace: combinedNamespace,
472
- events: this.events,
473
- client: this.client,
474
- });
475
- this.nativeProvider = provider;
476
- providers[namespace] = provider;
477
- break;
478
- }
479
- case 'eip155': {
480
- const provider = new EIP155Provider({
481
- namespace: combinedNamespace,
482
- events: this.events,
483
- client: this.client,
484
- });
485
- this.eip155Provider = provider;
486
- providers[namespace] = provider;
487
- break;
488
- }
489
- default:
490
- throw new Error(`Unsupported namespace: ${namespace}`);
491
- }
492
- });
493
- return providers;
494
- }
495
- // @ts-expect-error - override base rpcProviders logic
496
- get rpcProviders() {
497
- if (!this.nativeProvider && !this.eip155Provider) {
498
- return this.initProviders();
499
- }
500
- return {
501
- hedera: this.nativeProvider,
502
- eip155: this.eip155Provider,
503
- };
504
- }
505
- set rpcProviders(_) { }
506
- }
@@ -1,3 +0,0 @@
1
- export * from './HIP820Provider';
2
- export * from './EIP155Provider';
3
- export * from './HederaProvider';
@@ -1,3 +0,0 @@
1
- export * from './HIP820Provider';
2
- export * from './EIP155Provider';
3
- export * from './HederaProvider';
@@ -1,2 +0,0 @@
1
- import { AccountBalance, LedgerId } from '@hashgraph/sdk';
2
- export declare function getAccountBalance(ledgerId: LedgerId, address: string): Promise<AccountBalance | null>;