@hashgraph/hedera-wallet-connect 2.0.1-canary.3ca89d4.0 → 2.0.1-canary.45f4fe0.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 (49) hide show
  1. package/README.md +16 -16
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -1
  4. package/dist/lib/dapp/DAppSigner.d.ts +0 -2
  5. package/dist/lib/dapp/DAppSigner.js +2 -16
  6. package/dist/lib/dapp/index.d.ts +5 -7
  7. package/dist/lib/dapp/index.js +4 -36
  8. package/dist/lib/shared/index.d.ts +0 -2
  9. package/dist/lib/shared/index.js +0 -2
  10. package/dist/lib/shared/payloads.d.ts +1 -1
  11. package/dist/lib/shared/utils.d.ts +3 -2
  12. package/dist/lib/shared/utils.js +4 -3
  13. package/package.json +10 -11
  14. package/dist/lib/shared/accountInfo.d.ts +0 -30
  15. package/dist/lib/shared/accountInfo.js +0 -1
  16. package/dist/lib/shared/mirrorNode.d.ts +0 -3
  17. package/dist/lib/shared/mirrorNode.js +0 -17
  18. package/dist/reown/adapter.d.ts +0 -37
  19. package/dist/reown/adapter.js +0 -255
  20. package/dist/reown/connectors/HederaConnector.d.ts +0 -29
  21. package/dist/reown/connectors/HederaConnector.js +0 -35
  22. package/dist/reown/connectors/index.d.ts +0 -1
  23. package/dist/reown/connectors/index.js +0 -1
  24. package/dist/reown/index.d.ts +0 -4
  25. package/dist/reown/index.js +0 -4
  26. package/dist/reown/providers/EIP155Provider.d.ts +0 -33
  27. package/dist/reown/providers/EIP155Provider.js +0 -187
  28. package/dist/reown/providers/HIP820Provider.d.ts +0 -26
  29. package/dist/reown/providers/HIP820Provider.js +0 -69
  30. package/dist/reown/providers/HederaProvider.d.ts +0 -164
  31. package/dist/reown/providers/HederaProvider.js +0 -471
  32. package/dist/reown/providers/index.d.ts +0 -3
  33. package/dist/reown/providers/index.js +0 -3
  34. package/dist/reown/utils/chains.d.ts +0 -18
  35. package/dist/reown/utils/chains.js +0 -152
  36. package/dist/reown/utils/constants.d.ts +0 -16
  37. package/dist/reown/utils/constants.js +0 -18
  38. package/dist/reown/utils/helpers.d.ts +0 -12
  39. package/dist/reown/utils/helpers.js +0 -25
  40. package/dist/reown/utils/index.d.ts +0 -4
  41. package/dist/reown/utils/index.js +0 -4
  42. package/dist/reown/utils/types.d.ts +0 -9
  43. package/dist/reown/utils/types.js +0 -1
  44. package/dist/reown/wallets/EIP155Wallet.d.ts +0 -46
  45. package/dist/reown/wallets/EIP155Wallet.js +0 -136
  46. package/dist/reown/wallets/HIP820Wallet.d.ts +0 -53
  47. package/dist/reown/wallets/HIP820Wallet.js +0 -239
  48. package/dist/reown/wallets/index.d.ts +0 -2
  49. package/dist/reown/wallets/index.js +0 -2
@@ -1,255 +0,0 @@
1
- import { CoreHelperUtil, WcHelpersUtil } from '@reown/appkit';
2
- import { isReownName } from '@reown/appkit-common';
3
- import { AdapterBlueprint } from '@reown/appkit/adapters';
4
- import { ProviderUtil } from '@reown/appkit/store';
5
- import { LedgerId } from '@hashgraph/sdk';
6
- import { BrowserProvider, Contract, formatUnits, JsonRpcSigner, parseUnits } from 'ethers';
7
- import { HederaConnector } from './connectors';
8
- import { hederaNamespace } from './utils';
9
- import { getAccountInfo } from '..';
10
- export class HederaAdapter extends AdapterBlueprint {
11
- constructor(params) {
12
- var _a, _b;
13
- if (params.namespace !== hederaNamespace && params.namespace !== 'eip155') {
14
- throw new Error('Namespace must be "hedera" or "eip155"');
15
- }
16
- if (params.namespace == 'eip155') {
17
- if ((_a = params.networks) === null || _a === void 0 ? void 0 : _a.some((n) => n.chainNamespace != 'eip155')) {
18
- throw new Error('Invalid networks for eip155 namespace');
19
- }
20
- }
21
- else {
22
- if ((_b = params.networks) === null || _b === void 0 ? void 0 : _b.some((n) => n.chainNamespace != hederaNamespace)) {
23
- throw new Error('Invalid networks for hedera namespace');
24
- }
25
- }
26
- super(Object.assign({}, params));
27
- }
28
- setUniversalProvider(universalProvider) {
29
- this.addConnector(new HederaConnector({
30
- provider: universalProvider,
31
- caipNetworks: this.caipNetworks || [],
32
- namespace: this.namespace,
33
- }));
34
- }
35
- async connect(params) {
36
- return Promise.resolve({
37
- id: 'WALLET_CONNECT',
38
- type: 'WALLET_CONNECT',
39
- chainId: Number(params.chainId),
40
- provider: this.provider,
41
- address: '',
42
- });
43
- }
44
- async disconnect() {
45
- try {
46
- const connector = this.getWalletConnectConnector();
47
- await connector.disconnect();
48
- }
49
- catch (error) {
50
- console.warn('UniversalAdapter:disconnect - error', error);
51
- }
52
- }
53
- async getAccounts({ namespace, }) {
54
- var _a, _b, _c, _d;
55
- const provider = this.provider;
56
- const addresses = (((_d = (_c = (_b = (_a = provider === null || provider === void 0 ? void 0 : provider.session) === null || _a === void 0 ? void 0 : _a.namespaces) === null || _b === void 0 ? void 0 : _b[namespace]) === null || _c === void 0 ? void 0 : _c.accounts) === null || _d === void 0 ? void 0 : _d.map((account) => {
57
- const [, , address] = account.split(':');
58
- return address;
59
- }).filter((address, index, self) => self.indexOf(address) === index)) || []);
60
- return Promise.resolve({
61
- accounts: addresses.map((address) => CoreHelperUtil.createAccount(namespace, address, 'eoa')),
62
- });
63
- }
64
- async syncConnectors() {
65
- return Promise.resolve();
66
- }
67
- async getBalance(params) {
68
- const { address, caipNetwork } = params;
69
- if (!caipNetwork) {
70
- return Promise.resolve({
71
- balance: '0',
72
- decimals: 0,
73
- symbol: '',
74
- });
75
- }
76
- const accountInfo = await getAccountInfo(caipNetwork.testnet ? LedgerId.TESTNET : LedgerId.MAINNET, address);
77
- return Promise.resolve({
78
- balance: (accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.balance)
79
- ? formatUnits(accountInfo.balance.balance, 8).toString()
80
- : '0',
81
- decimals: caipNetwork.nativeCurrency.decimals,
82
- symbol: caipNetwork.nativeCurrency.symbol,
83
- });
84
- }
85
- async signMessage(params) {
86
- const { provider, message, address } = params;
87
- if (!provider) {
88
- throw new Error('Provider is undefined');
89
- }
90
- const hederaProvider = provider;
91
- let signature = '';
92
- if (this.namespace === hederaNamespace) {
93
- const response = await hederaProvider.hedera_signMessage({
94
- signerAccountId: address,
95
- message,
96
- });
97
- signature = response.signatureMap;
98
- }
99
- else {
100
- signature = await hederaProvider.eth_signMessage(message, address);
101
- }
102
- return { signature };
103
- }
104
- async estimateGas(params) {
105
- const { provider, caipNetwork, address } = params;
106
- if (this.namespace !== 'eip155') {
107
- throw new Error('Namespace is not eip155');
108
- }
109
- if (!provider) {
110
- throw new Error('Provider is undefined');
111
- }
112
- const hederaProvider = provider;
113
- const result = await hederaProvider.eth_estimateGas({
114
- data: params.data,
115
- to: params.to,
116
- address: address,
117
- }, address, Number(caipNetwork === null || caipNetwork === void 0 ? void 0 : caipNetwork.id));
118
- return { gas: result };
119
- }
120
- async sendTransaction(params) {
121
- var _a;
122
- if (!params.provider) {
123
- throw new Error('Provider is undefined');
124
- }
125
- const hederaProvider = params.provider;
126
- if (this.namespace == 'eip155') {
127
- const tx = await hederaProvider.eth_sendTransaction({
128
- value: params.value,
129
- to: params.to,
130
- data: params.data,
131
- gas: params.gas,
132
- gasPrice: params.gasPrice,
133
- address: params.address,
134
- }, params.address, Number((_a = params.caipNetwork) === null || _a === void 0 ? void 0 : _a.id));
135
- return { hash: tx };
136
- }
137
- else {
138
- throw new Error('Namespace is not eip155');
139
- }
140
- }
141
- async writeContract(params) {
142
- if (!params.provider) {
143
- throw new Error('Provider is undefined');
144
- }
145
- if (this.namespace !== 'eip155') {
146
- throw new Error('Namespace is not eip155');
147
- }
148
- const { provider, caipNetwork, caipAddress, abi, tokenAddress, method, args } = params;
149
- const browserProvider = new BrowserProvider(provider, Number(caipNetwork === null || caipNetwork === void 0 ? void 0 : caipNetwork.id));
150
- const signer = new JsonRpcSigner(browserProvider, caipAddress);
151
- const contract = new Contract(tokenAddress, abi, signer);
152
- if (!contract || !method) {
153
- throw new Error('Contract method is undefined');
154
- }
155
- const contractMethod = contract[method];
156
- if (contractMethod) {
157
- const result = await contractMethod(...args);
158
- return { hash: result };
159
- }
160
- else
161
- throw new Error('Contract method is undefined');
162
- }
163
- async getEnsAddress(params) {
164
- if (this.namespace !== 'eip155') {
165
- throw new Error('Namespace is not eip155');
166
- }
167
- const { name, caipNetwork } = params;
168
- if (caipNetwork) {
169
- if (isReownName(name)) {
170
- return {
171
- address: (await WcHelpersUtil.resolveReownName(name)) || false,
172
- };
173
- }
174
- }
175
- return { address: false };
176
- }
177
- parseUnits(params) {
178
- return parseUnits(params.value, params.decimals);
179
- }
180
- formatUnits(params) {
181
- return formatUnits(params.value, params.decimals);
182
- }
183
- async getCapabilities(params) {
184
- var _a, _b;
185
- if (this.namespace !== 'eip155') {
186
- throw new Error('Namespace is not eip155');
187
- }
188
- const provider = ProviderUtil.getProvider('eip155');
189
- if (!provider) {
190
- throw new Error('Provider is undefined');
191
- }
192
- const walletCapabilitiesString = (_b = (_a = provider.session) === null || _a === void 0 ? void 0 : _a.sessionProperties) === null || _b === void 0 ? void 0 : _b['capabilities'];
193
- if (walletCapabilitiesString) {
194
- try {
195
- const walletCapabilities = JSON.parse(walletCapabilitiesString);
196
- const accountCapabilities = walletCapabilities[params];
197
- if (accountCapabilities) {
198
- return accountCapabilities;
199
- }
200
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
201
- }
202
- catch (error) {
203
- throw new Error('Error parsing wallet capabilities');
204
- }
205
- }
206
- return await provider.request({
207
- method: 'wallet_getCapabilities',
208
- params: [params],
209
- });
210
- }
211
- // Not supported
212
- async getProfile() {
213
- return Promise.resolve({
214
- profileImage: '',
215
- profileName: '',
216
- });
217
- }
218
- // Not supported
219
- async grantPermissions() {
220
- return Promise.resolve({});
221
- }
222
- // Not supported
223
- async revokePermissions() {
224
- return Promise.resolve('0x');
225
- }
226
- async syncConnection(params) {
227
- return Promise.resolve({
228
- id: 'WALLET_CONNECT',
229
- type: 'WALLET_CONNECT',
230
- chainId: params.chainId,
231
- provider: this.provider,
232
- address: '',
233
- });
234
- }
235
- async switchNetwork(params) {
236
- const { caipNetwork } = params;
237
- const connector = this.getWalletConnectConnector();
238
- connector.provider.setDefaultChain(caipNetwork.caipNetworkId);
239
- }
240
- getWalletConnectConnector() {
241
- const connector = this.connectors.find((c) => c.type == 'WALLET_CONNECT');
242
- if (!connector) {
243
- throw new Error('WalletConnectConnector not found');
244
- }
245
- return connector;
246
- }
247
- getWalletConnectProvider() {
248
- const connector = this.connectors.find((c) => c.type === 'WALLET_CONNECT');
249
- const provider = connector === null || connector === void 0 ? void 0 : connector.provider;
250
- return provider;
251
- }
252
- async walletGetAssets(_params) {
253
- return Promise.resolve({});
254
- }
255
- }
@@ -1,29 +0,0 @@
1
- import type { SessionTypes } from '@walletconnect/types';
2
- import { CaipNetwork, ChainNamespace } from '@reown/appkit-common';
3
- import { AdapterBlueprint, type ChainAdapterConnector } from '@reown/appkit/adapters';
4
- type UniversalProvider = Parameters<AdapterBlueprint['setUniversalProvider']>[0];
5
- export declare class HederaConnector implements ChainAdapterConnector {
6
- readonly id: "walletConnect";
7
- readonly name: string;
8
- readonly type = "WALLET_CONNECT";
9
- readonly imageId: string;
10
- readonly chain: ChainNamespace;
11
- provider: UniversalProvider;
12
- protected caipNetworks: CaipNetwork[];
13
- constructor({ provider, caipNetworks, namespace }: HederaConnector.Options);
14
- get chains(): CaipNetwork[];
15
- connectWalletConnect(): Promise<{
16
- clientId: string;
17
- session: SessionTypes.Struct;
18
- }>;
19
- disconnect(): Promise<void>;
20
- authenticate(): Promise<boolean>;
21
- }
22
- export declare namespace HederaConnector {
23
- type Options = {
24
- provider: UniversalProvider;
25
- caipNetworks: CaipNetwork[];
26
- namespace: 'hedera' | 'eip155';
27
- };
28
- }
29
- export {};
@@ -1,35 +0,0 @@
1
- import { ConstantsUtil } from '@reown/appkit-common';
2
- import { PresetsUtil } from '@reown/appkit-utils';
3
- import { createNamespaces } from '../utils';
4
- export class HederaConnector {
5
- constructor({ provider, caipNetworks, namespace }) {
6
- this.id = ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT;
7
- this.name = PresetsUtil.ConnectorNamesMap[ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT];
8
- this.type = 'WALLET_CONNECT';
9
- this.imageId = PresetsUtil.ConnectorImageIds[ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT];
10
- this.caipNetworks = caipNetworks;
11
- this.provider = provider;
12
- this.chain = namespace;
13
- }
14
- get chains() {
15
- return this.caipNetworks;
16
- }
17
- async connectWalletConnect() {
18
- const isAuthenticated = await this.authenticate();
19
- if (!isAuthenticated) {
20
- await this.provider.connect({
21
- optionalNamespaces: createNamespaces(this.caipNetworks),
22
- });
23
- }
24
- return {
25
- clientId: await this.provider.client.core.crypto.getClientId(),
26
- session: this.provider.session,
27
- };
28
- }
29
- async disconnect() {
30
- await this.provider.disconnect();
31
- }
32
- async authenticate() {
33
- return false;
34
- }
35
- }
@@ -1 +0,0 @@
1
- export * from './HederaConnector';
@@ -1 +0,0 @@
1
- export * from './HederaConnector';
@@ -1,4 +0,0 @@
1
- export * from './adapter';
2
- export * from './providers';
3
- export * from './utils';
4
- export * from './wallets';
@@ -1,4 +0,0 @@
1
- export * from './adapter';
2
- export * from './providers';
3
- export * from './utils';
4
- export * from './wallets';
@@ -1,33 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import Client from '@walletconnect/universal-provider/node_modules/@walletconnect/sign-client';
3
- import { SessionTypes } from '@walletconnect/types';
4
- import { IProvider, SessionNamespace, RpcProvidersMap, RequestParams, Namespace } from '@walletconnect/universal-provider';
5
- declare class EIP155Provider implements IProvider {
6
- name: string;
7
- client: Client;
8
- chainId: number;
9
- namespace: SessionNamespace;
10
- httpProviders: RpcProvidersMap;
11
- events: EventEmitter;
12
- constructor({ client, events, namespace, }: {
13
- client: IProvider['client'];
14
- events: EventEmitter;
15
- namespace: Namespace;
16
- });
17
- request<T = unknown>(args: RequestParams): Promise<T>;
18
- updateNamespace(namespace: SessionTypes.Namespace): void;
19
- setDefaultChain(chainId: string, rpcUrl?: string | undefined): void;
20
- requestAccounts(): string[];
21
- getDefaultChain(): string;
22
- private createHttpProvider;
23
- private setHttpProvider;
24
- private createHttpProviders;
25
- private getAccounts;
26
- private getHttpProvider;
27
- private switchChain;
28
- private isChainApproved;
29
- private getCallStatus;
30
- private getUserOperationReceipt;
31
- private getBundlerUrl;
32
- }
33
- export default EIP155Provider;
@@ -1,187 +0,0 @@
1
- import { JsonRpcProvider } from '@walletconnect/jsonrpc-provider';
2
- import { HttpConnection } from '@walletconnect/jsonrpc-http-connection';
3
- import { formatJsonRpcRequest } from '@walletconnect/jsonrpc-utils';
4
- import { BUNDLER_URL, getChainId, HederaChainDefinition } from '../utils';
5
- class EIP155Provider {
6
- constructor({ client, events, namespace, }) {
7
- this.name = 'eip155';
8
- this.namespace = namespace;
9
- this.events = events;
10
- this.client = client;
11
- this.httpProviders = this.createHttpProviders();
12
- this.chainId = parseInt(this.getDefaultChain());
13
- }
14
- async request(args) {
15
- switch (args.request.method) {
16
- case 'eth_requestAccounts':
17
- return this.getAccounts();
18
- case 'eth_accounts':
19
- return this.getAccounts();
20
- case 'wallet_switchEthereumChain': {
21
- return (await this.switchChain(args));
22
- }
23
- case 'eth_chainId':
24
- return parseInt(this.getDefaultChain());
25
- case 'wallet_getCallsStatus':
26
- return (await this.getCallStatus(args));
27
- default:
28
- break;
29
- }
30
- if (this.namespace.methods.includes(args.request.method)) {
31
- return await this.client.request(args);
32
- }
33
- return this.getHttpProvider().request(args.request);
34
- }
35
- updateNamespace(namespace) {
36
- this.namespace = Object.assign(this.namespace, namespace);
37
- }
38
- setDefaultChain(chainId, rpcUrl) {
39
- // http provider exists so just set the chainId
40
- if (!this.httpProviders[chainId]) {
41
- this.setHttpProvider(parseInt(chainId), rpcUrl);
42
- }
43
- this.chainId = parseInt(chainId);
44
- this.events.emit('default_chain_changed', `${this.name}:${chainId}`);
45
- }
46
- requestAccounts() {
47
- return this.getAccounts();
48
- }
49
- getDefaultChain() {
50
- if (this.chainId)
51
- return this.chainId.toString();
52
- if (this.namespace.defaultChain)
53
- return this.namespace.defaultChain;
54
- const chainId = this.namespace.chains[0];
55
- if (!chainId)
56
- throw new Error(`ChainId not found`);
57
- return chainId.split(':')[1];
58
- }
59
- // ---------- Private ----------------------------------------------- //
60
- createHttpProvider(chainId, rpcUrl) {
61
- if (!chainId)
62
- return undefined;
63
- const { Testnet, Mainnet } = HederaChainDefinition.EVM;
64
- const caipNetwork = [Mainnet, Testnet].find((network) => network.id == chainId);
65
- const rpc = (caipNetwork === null || caipNetwork === void 0 ? void 0 : caipNetwork.rpcUrls.default.http[0]) || rpcUrl;
66
- if (!rpc) {
67
- throw new Error(`No RPC url provided for chainId: ${chainId}`);
68
- }
69
- const http = new JsonRpcProvider(new HttpConnection(rpc, false));
70
- return http;
71
- }
72
- setHttpProvider(chainId, rpcUrl) {
73
- const http = this.createHttpProvider(chainId, rpcUrl);
74
- if (http) {
75
- this.httpProviders[chainId] = http;
76
- }
77
- }
78
- createHttpProviders() {
79
- const http = {};
80
- this.namespace.chains.forEach((chain) => {
81
- var _a;
82
- const parsedChain = parseInt(getChainId(chain));
83
- http[parsedChain] = this.createHttpProvider(parsedChain, (_a = this.namespace.rpcMap) === null || _a === void 0 ? void 0 : _a[chain]);
84
- });
85
- return http;
86
- }
87
- getAccounts() {
88
- const accounts = this.namespace.accounts;
89
- if (!accounts) {
90
- return [];
91
- }
92
- return Array.from(new Set(accounts
93
- .filter((account) => account.split(':')[1] === this.chainId.toString())
94
- .map((account) => account.split(':')[2])));
95
- }
96
- getHttpProvider() {
97
- const chain = this.chainId;
98
- const http = this.httpProviders[chain];
99
- if (typeof http === 'undefined') {
100
- throw new Error(`JSON-RPC provider for ${chain} not found`);
101
- }
102
- return http;
103
- }
104
- async switchChain(args) {
105
- var _a, _b;
106
- let hexChainId = args.request.params
107
- ? (_a = args.request.params[0]) === null || _a === void 0 ? void 0 : _a.chainId
108
- : '0x0';
109
- hexChainId = hexChainId.startsWith('0x') ? hexChainId : `0x${hexChainId}`;
110
- const parsedChainId = parseInt(hexChainId, 16);
111
- // if chainId is already approved, switch locally
112
- if (this.isChainApproved(parsedChainId)) {
113
- this.setDefaultChain(`${parsedChainId}`);
114
- }
115
- else if (this.namespace.methods.includes('wallet_switchEthereumChain')) {
116
- // try to switch chain within the wallet
117
- await this.client.request({
118
- topic: args.topic,
119
- request: {
120
- method: args.request.method,
121
- params: [
122
- {
123
- chainId: hexChainId,
124
- },
125
- ],
126
- },
127
- chainId: (_b = this.namespace.chains) === null || _b === void 0 ? void 0 : _b[0], // Sending a previously unapproved chainId will cause namespace validation failure so we must set request chainId to the first chainId in the namespace to avoid it
128
- });
129
- this.setDefaultChain(`${parsedChainId}`);
130
- }
131
- else {
132
- throw new Error(`Failed to switch to chain 'eip155:${parsedChainId}'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method.`);
133
- }
134
- return null;
135
- }
136
- isChainApproved(chainId) {
137
- return this.namespace.chains.includes(`${this.name}:${chainId}`);
138
- }
139
- async getCallStatus(args) {
140
- var _a, _b;
141
- const session = this.client.session.get(args.topic);
142
- const bundlerName = (_a = session.sessionProperties) === null || _a === void 0 ? void 0 : _a.bundler_name;
143
- if (bundlerName) {
144
- const bundlerUrl = this.getBundlerUrl(args.chainId, bundlerName);
145
- try {
146
- return await this.getUserOperationReceipt(bundlerUrl, args);
147
- }
148
- catch (error) {
149
- console.warn('Failed to fetch call status from bundler', error, bundlerUrl);
150
- }
151
- }
152
- const customUrl = (_b = session.sessionProperties) === null || _b === void 0 ? void 0 : _b.bundler_url;
153
- if (customUrl) {
154
- try {
155
- return await this.getUserOperationReceipt(customUrl, args);
156
- }
157
- catch (error) {
158
- console.warn('Failed to fetch call status from custom bundler', error, customUrl);
159
- }
160
- }
161
- if (this.namespace.methods.includes(args.request.method)) {
162
- return await this.client.request(args);
163
- }
164
- throw new Error('Fetching call status not approved by the wallet.');
165
- }
166
- async getUserOperationReceipt(bundlerUrl, args) {
167
- var _a, _b;
168
- const url = new URL(bundlerUrl);
169
- const response = await fetch(url, {
170
- method: 'POST',
171
- headers: {
172
- 'Content-Type': 'application/json',
173
- },
174
- body: JSON.stringify(formatJsonRpcRequest('eth_getUserOperationReceipt', [
175
- (_b = (_a = args.request) === null || _a === void 0 ? void 0 : _a.params) === null || _b === void 0 ? void 0 : _b[0],
176
- ])),
177
- });
178
- if (!response.ok) {
179
- throw new Error(`Failed to fetch user operation receipt - ${response.status}`);
180
- }
181
- return await response.json();
182
- }
183
- getBundlerUrl(cap2ChainId, bundlerName) {
184
- return `${BUNDLER_URL}?projectId=${this.client.core.projectId}&chainId=${cap2ChainId}&bundler=${bundlerName}`;
185
- }
186
- }
187
- export default EIP155Provider;
@@ -1,26 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { DAppSigner } from '../..';
3
- import { SessionNamespace, RequestParams, IProvider } from '@walletconnect/universal-provider';
4
- import { SessionTypes } from '@walletconnect/types';
5
- import { Transaction } from '@hashgraph/sdk';
6
- declare class HIP820Provider implements IProvider {
7
- events: EventEmitter;
8
- client: IProvider['client'];
9
- namespace: SessionNamespace;
10
- chainId: string;
11
- constructor(opts: {
12
- namespace: SessionNamespace;
13
- client: IProvider['client'];
14
- events: EventEmitter;
15
- });
16
- get httpProviders(): {};
17
- updateNamespace(namespace: SessionTypes.Namespace): void;
18
- request<T = unknown>(args: RequestParams): Promise<T>;
19
- signTransaction<T extends Transaction>(transaction: T, topic: string): Promise<T>;
20
- requestAccounts(): string[];
21
- setDefaultChain(chainId: string): void;
22
- getDefaultChain(): string;
23
- getSigner(topic: string): DAppSigner;
24
- getSigners(topic: string): DAppSigner[];
25
- }
26
- export default HIP820Provider;
@@ -1,69 +0,0 @@
1
- import { CAIPChainIdToLedgerId, DAppSigner } from '../..';
2
- import { AccountId } from '@hashgraph/sdk';
3
- class HIP820Provider {
4
- constructor(opts) {
5
- this.namespace = opts.namespace;
6
- this.chainId = this.getDefaultChain();
7
- this.events = opts.events;
8
- this.client = opts.client;
9
- }
10
- get httpProviders() {
11
- return {};
12
- }
13
- updateNamespace(namespace) {
14
- this.namespace = Object.assign(this.namespace, namespace);
15
- }
16
- request(args) {
17
- return this.getSigner(args.topic).request({
18
- method: args.request.method,
19
- params: args.request.params,
20
- });
21
- }
22
- async signTransaction(transaction, topic) {
23
- return this.getSigner(topic).signTransaction(transaction);
24
- }
25
- requestAccounts() {
26
- const accounts = this.namespace.accounts;
27
- if (!accounts) {
28
- return [];
29
- }
30
- return Array.from(new Set(accounts
31
- // get the accounts from the active chain
32
- .filter((account) => account.split(':')[1] === this.chainId.toString())
33
- // remove namespace & chainId from the string
34
- .map((account) => account.split(':')[2])));
35
- }
36
- setDefaultChain(chainId) {
37
- this.chainId = chainId;
38
- this.namespace.defaultChain = chainId;
39
- }
40
- getDefaultChain() {
41
- if (this.chainId)
42
- return this.chainId;
43
- if (this.namespace.defaultChain)
44
- return this.namespace.defaultChain;
45
- const chainId = this.namespace.chains[0];
46
- if (!chainId)
47
- throw new Error(`ChainId not found`);
48
- return chainId.split(':')[1];
49
- }
50
- // create signer on demand
51
- getSigner(topic) {
52
- return this.getSigners(topic)[0];
53
- }
54
- getSigners(topic) {
55
- var _a;
56
- const accounts = (_a = this.namespace.accounts) === null || _a === void 0 ? void 0 : _a.map((account) => {
57
- const [chain, network, acc] = account.split(':');
58
- return {
59
- ledgerId: CAIPChainIdToLedgerId(`${chain}:${network}`),
60
- accountId: AccountId.fromString(acc),
61
- };
62
- });
63
- if (!accounts) {
64
- throw new Error('Accounts not found');
65
- }
66
- return accounts.map(({ accountId, ledgerId }) => new DAppSigner(accountId, this.client, topic, ledgerId));
67
- }
68
- }
69
- export default HIP820Provider;