@hashgraph/hedera-wallet-connect 1.5.2-canary.dd48df1.0 → 2.0.0-canary.45f2441.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 (54) hide show
  1. package/README.md +127 -68
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/lib/dapp/DAppSigner.d.ts +2 -1
  5. package/dist/lib/dapp/DAppSigner.js +19 -22
  6. package/dist/lib/dapp/index.d.ts +7 -11
  7. package/dist/lib/dapp/index.js +37 -27
  8. package/dist/lib/shared/accountInfo.d.ts +30 -0
  9. package/dist/lib/shared/accountInfo.js +1 -0
  10. package/dist/lib/shared/index.d.ts +2 -0
  11. package/dist/lib/shared/index.js +2 -0
  12. package/dist/lib/shared/logger.d.ts +2 -1
  13. package/dist/lib/shared/logger.js +6 -5
  14. package/dist/lib/shared/mirrorNode.d.ts +3 -0
  15. package/dist/lib/shared/mirrorNode.js +17 -0
  16. package/dist/lib/shared/payloads.d.ts +1 -5
  17. package/dist/lib/shared/utils.d.ts +2 -20
  18. package/dist/lib/shared/utils.js +3 -30
  19. package/dist/lib/wallet/index.d.ts +8 -8
  20. package/dist/lib/wallet/index.js +7 -2
  21. package/dist/lib/wallet/types.d.ts +5 -5
  22. package/dist/reown/adapter.d.ts +37 -0
  23. package/dist/reown/adapter.js +255 -0
  24. package/dist/reown/connectors/HederaConnector.d.ts +29 -0
  25. package/dist/reown/connectors/HederaConnector.js +35 -0
  26. package/dist/reown/connectors/index.d.ts +1 -0
  27. package/dist/reown/connectors/index.js +1 -0
  28. package/dist/reown/index.d.ts +4 -0
  29. package/dist/reown/index.js +4 -0
  30. package/dist/reown/providers/EIP155Provider.d.ts +33 -0
  31. package/dist/reown/providers/EIP155Provider.js +187 -0
  32. package/dist/reown/providers/HIP820Provider.d.ts +26 -0
  33. package/dist/reown/providers/HIP820Provider.js +69 -0
  34. package/dist/reown/providers/HederaProvider.d.ts +164 -0
  35. package/dist/reown/providers/HederaProvider.js +471 -0
  36. package/dist/reown/providers/index.d.ts +3 -0
  37. package/dist/reown/providers/index.js +3 -0
  38. package/dist/reown/utils/chains.d.ts +18 -0
  39. package/dist/reown/utils/chains.js +152 -0
  40. package/dist/reown/utils/constants.d.ts +16 -0
  41. package/dist/reown/utils/constants.js +18 -0
  42. package/dist/reown/utils/helpers.d.ts +12 -0
  43. package/dist/reown/utils/helpers.js +25 -0
  44. package/dist/reown/utils/index.d.ts +4 -0
  45. package/dist/reown/utils/index.js +4 -0
  46. package/dist/reown/utils/types.d.ts +9 -0
  47. package/dist/reown/utils/types.js +1 -0
  48. package/dist/reown/wallets/EIP155Wallet.d.ts +46 -0
  49. package/dist/reown/wallets/EIP155Wallet.js +136 -0
  50. package/dist/reown/wallets/HIP820Wallet.d.ts +53 -0
  51. package/dist/reown/wallets/HIP820Wallet.js +239 -0
  52. package/dist/reown/wallets/index.d.ts +2 -0
  53. package/dist/reown/wallets/index.js +2 -0
  54. package/package.json +23 -58
@@ -1,28 +1,10 @@
1
1
  import { AccountId, PublicKey, Transaction, LedgerId, Query, SignerSignature } from '@hashgraph/sdk';
2
2
  import { ProposalTypes, SessionTypes } from '@walletconnect/types';
3
3
  import { proto } from '@hashgraph/proto';
4
- /**
5
- * Freezes a transaction if it is not already frozen. Transactions must
6
- * be frozen before they can be converted to bytes.
7
- *
8
- * @param transaction - Any instance of a class that extends `Transaction`
9
- */
10
- export declare function freezeTransaction<T extends Transaction>(transaction: T): void;
11
- /**
12
- * Sets default consensus nodes that a transaction will be submitted to. Node Account ID(s)
13
- * must be set before a transaction can be frozen. If they have already been set, this
14
- * function will not modify the transaction.
15
- * @param transaction - any instance of a class that extends `Transaction`
16
- *
17
- * @see {@link https://docs.hedera.com/hedera/networks/testnet/testnet-nodes | Full list of Testnet-nodes}
18
- * @see {@link https://docs.hedera.com/hedera/networks/mainnet/mainnet-nodes | Full list of Mainnet-nodes}
19
- */
20
- export declare function setDefaultNodeAccountIds<T extends Transaction>(transaction: T): void;
21
4
  /**
22
5
  * Converts `Transaction` to a Base64-string.
23
6
  *
24
- * First converts a transaction to bytes and then encodes it as a Base64-string. Will attempt
25
- * to set default Node Account ID and freeze the transaction before converting.
7
+ * Converts a transaction to bytes and then encodes it as a Base64-string. Allow uncompleted transaction (HIP-745).
26
8
  * @param transaction - Any instance of a class that extends `Transaction`
27
9
  * @returns Base64 encoded representation of the input `Transaction` object
28
10
  */
@@ -49,7 +31,7 @@ export declare function base64StringToTransaction<T extends Transaction>(transac
49
31
  * @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
50
32
  * @returns `string`
51
33
  * */
52
- export declare function transactionToTransactionBody<T extends Transaction>(transaction: T, nodeAccountId: AccountId): any;
34
+ export declare function transactionToTransactionBody<T extends Transaction>(transaction: T): any;
53
35
  export declare function transactionBodyToBase64String(transactionBody: proto.ITransactionBody): string;
54
36
  /**
55
37
  * @param transactionList - a proto.TransactionList object
@@ -20,41 +20,14 @@
20
20
  import { Buffer } from 'buffer';
21
21
  import { AccountId, Transaction, LedgerId, Query, } from '@hashgraph/sdk';
22
22
  import { proto } from '@hashgraph/proto';
23
- /**
24
- * Freezes a transaction if it is not already frozen. Transactions must
25
- * be frozen before they can be converted to bytes.
26
- *
27
- * @param transaction - Any instance of a class that extends `Transaction`
28
- */
29
- export function freezeTransaction(transaction) {
30
- if (!transaction.isFrozen())
31
- transaction.freeze();
32
- }
33
- /**
34
- * Sets default consensus nodes that a transaction will be submitted to. Node Account ID(s)
35
- * must be set before a transaction can be frozen. If they have already been set, this
36
- * function will not modify the transaction.
37
- * @param transaction - any instance of a class that extends `Transaction`
38
- *
39
- * @see {@link https://docs.hedera.com/hedera/networks/testnet/testnet-nodes | Full list of Testnet-nodes}
40
- * @see {@link https://docs.hedera.com/hedera/networks/mainnet/mainnet-nodes | Full list of Mainnet-nodes}
41
- */
42
- export function setDefaultNodeAccountIds(transaction) {
43
- const isNodeAccountIdNotSet = !transaction.nodeAccountIds || transaction.nodeAccountIds.length === 0;
44
- if (!transaction.isFrozen() && isNodeAccountIdNotSet)
45
- transaction.setNodeAccountIds([new AccountId(3), new AccountId(4), new AccountId(5)]);
46
- }
47
23
  /**
48
24
  * Converts `Transaction` to a Base64-string.
49
25
  *
50
- * First converts a transaction to bytes and then encodes it as a Base64-string. Will attempt
51
- * to set default Node Account ID and freeze the transaction before converting.
26
+ * Converts a transaction to bytes and then encodes it as a Base64-string. Allow uncompleted transaction (HIP-745).
52
27
  * @param transaction - Any instance of a class that extends `Transaction`
53
28
  * @returns Base64 encoded representation of the input `Transaction` object
54
29
  */
55
30
  export function transactionToBase64String(transaction) {
56
- setDefaultNodeAccountIds(transaction);
57
- freezeTransaction(transaction);
58
31
  const transactionBytes = transaction.toBytes();
59
32
  return Buffer.from(transactionBytes).toString('base64');
60
33
  }
@@ -83,10 +56,10 @@ export function base64StringToTransaction(transactionBytes) {
83
56
  * @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
84
57
  * @returns `string`
85
58
  * */
86
- export function transactionToTransactionBody(transaction, nodeAccountId) {
59
+ export function transactionToTransactionBody(transaction) {
87
60
  // This is a private function, though provides the capabilities to construct a proto.TransactionBody
88
61
  //@ts-ignore
89
- return transaction._makeTransactionBody(nodeAccountId);
62
+ return transaction._makeTransactionBody(null);
90
63
  }
91
64
  export function transactionBodyToBase64String(transactionBody) {
92
65
  return Uint8ArrayToBase64String(proto.TransactionBody.encode(transactionBody).finish());
@@ -1,4 +1,4 @@
1
- import { Web3Wallet, Web3WalletTypes } from '@walletconnect/web3wallet';
1
+ import { WalletKit, WalletKitTypes } from '@reown/walletkit';
2
2
  import { SessionTypes } from '@walletconnect/types';
3
3
  import { Wallet as HederaWallet, AccountId, Transaction, Query } from '@hashgraph/sdk';
4
4
  import { HederaChainId, HederaSessionEvent, HederaJsonRpcMethod } from '../shared';
@@ -6,16 +6,16 @@ import Provider from './provider';
6
6
  import type { HederaNativeWallet } from './types';
7
7
  export type { HederaNativeWallet } from './types';
8
8
  export { default as WalletProvider } from './provider';
9
- export declare class HederaWeb3Wallet extends Web3Wallet implements HederaNativeWallet {
9
+ export declare class HederaWeb3Wallet extends WalletKit implements HederaNativeWallet {
10
10
  chains: HederaChainId[] | string[];
11
11
  methods: string[];
12
12
  sessionEvents: HederaSessionEvent[] | string[];
13
- constructor(opts: Web3WalletTypes.Options, chains?: HederaChainId[] | string[], methods?: string[], sessionEvents?: HederaSessionEvent[] | string[]);
14
- static create(projectId: string, metadata: Web3WalletTypes.Metadata, chains?: HederaChainId[], methods?: string[], sessionEvents?: HederaSessionEvent[] | string[]): Promise<HederaWeb3Wallet>;
13
+ constructor(opts: WalletKitTypes.Options, chains?: HederaChainId[] | string[], methods?: string[], sessionEvents?: HederaSessionEvent[] | string[]);
14
+ static create(projectId: string, metadata: WalletKitTypes.Metadata, chains?: HederaChainId[], methods?: string[], sessionEvents?: HederaSessionEvent[] | string[]): Promise<HederaWeb3Wallet>;
15
15
  getHederaWallet(chainId: HederaChainId, accountId: AccountId | string, privateKey: string, _provider?: Provider): HederaWallet;
16
- buildAndApproveSession(accounts: string[], { id, params }: Web3WalletTypes.SessionProposal): Promise<SessionTypes.Struct>;
16
+ buildAndApproveSession(accounts: string[], { id, params }: WalletKitTypes.SessionProposal): Promise<SessionTypes.Struct>;
17
17
  validateParam(name: string, value: any, expectedType: string): void;
18
- parseSessionRequest(event: Web3WalletTypes.SessionRequest, shouldThrow?: boolean): {
18
+ parseSessionRequest(event: WalletKitTypes.SessionRequest, shouldThrow?: boolean): {
19
19
  method: HederaJsonRpcMethod;
20
20
  chainId: HederaChainId;
21
21
  id: number;
@@ -23,8 +23,8 @@ export declare class HederaWeb3Wallet extends Web3Wallet implements HederaNative
23
23
  body?: Transaction | Query<any> | string | Uint8Array | undefined;
24
24
  accountId?: AccountId;
25
25
  };
26
- executeSessionRequest(event: Web3WalletTypes.SessionRequest, hederaWallet: HederaWallet): Promise<void>;
27
- rejectSessionRequest(event: Web3WalletTypes.SessionRequest, error: {
26
+ executeSessionRequest(event: WalletKitTypes.SessionRequest, hederaWallet: HederaWallet): Promise<void>;
27
+ rejectSessionRequest(event: WalletKitTypes.SessionRequest, error: {
28
28
  code: number;
29
29
  message: string;
30
30
  }): Promise<void>;
@@ -19,7 +19,7 @@
19
19
  */
20
20
  import { Buffer } from 'buffer';
21
21
  import { Core } from '@walletconnect/core';
22
- import { Web3Wallet } from '@walletconnect/web3wallet';
22
+ import { WalletKit } from '@reown/walletkit';
23
23
  import { buildApprovedNamespaces, getSdkError } from '@walletconnect/utils';
24
24
  import { Wallet as HederaWallet, Client, AccountId } from '@hashgraph/sdk';
25
25
  import { HederaChainId, HederaSessionEvent, HederaJsonRpcMethod, base64StringToQuery, Uint8ArrayToBase64String, stringToSignerMessage, signatureMapToBase64String, signerSignaturesToSignatureMap, base64StringToTransaction, getHederaError, } from '../shared';
@@ -30,7 +30,7 @@ export { default as WalletProvider } from './provider';
30
30
  *
31
31
  * @see {@link https://github.com/WalletConnect/walletconnect-monorepo/blob/v2.0/packages/web3wallet/src/client.ts}
32
32
  */
33
- export class HederaWeb3Wallet extends Web3Wallet {
33
+ export class HederaWeb3Wallet extends WalletKit {
34
34
  /*
35
35
  * Set default values for chains, methods, events
36
36
  */
@@ -269,6 +269,11 @@ export class HederaWeb3Wallet extends Web3Wallet {
269
269
  }
270
270
  // 5. hedera_signAndExecuteTransaction
271
271
  async hedera_signAndExecuteTransaction(id, topic, body, signer) {
272
+ // check transaction is incomplete (HIP-745)
273
+ if (!body.isFrozen()) {
274
+ // set multiple nodeAccountIds and transactionId if not present
275
+ await body.freezeWithSigner(signer);
276
+ }
272
277
  const signedTransaction = await signer.signTransaction(body);
273
278
  const response = {
274
279
  topic,
@@ -1,11 +1,11 @@
1
- import type { Web3WalletTypes } from '@walletconnect/web3wallet';
1
+ import type { WalletKitTypes } from '@reown/walletkit';
2
2
  import type { SessionTypes } from '@walletconnect/types';
3
3
  import type { Transaction, Query, AccountId, Wallet as HederaWallet } from '@hashgraph/sdk';
4
4
  import type { HederaJsonRpcMethod, HederaChainId } from '../shared';
5
5
  import type Provider from './provider';
6
6
  export interface HederaNativeWallet {
7
- buildAndApproveSession(accounts: string[], { id, params }: Web3WalletTypes.SessionProposal): Promise<SessionTypes.Struct>;
8
- parseSessionRequest(event: Web3WalletTypes.SessionRequest, shouldThrow: boolean): {
7
+ buildAndApproveSession(accounts: string[], { id, params }: WalletKitTypes.SessionProposal): Promise<SessionTypes.Struct>;
8
+ parseSessionRequest(event: WalletKitTypes.SessionRequest, shouldThrow: boolean): {
9
9
  method: HederaJsonRpcMethod;
10
10
  chainId: HederaChainId;
11
11
  id: number;
@@ -13,8 +13,8 @@ export interface HederaNativeWallet {
13
13
  body?: Transaction | Query<any> | string | Uint8Array | undefined;
14
14
  accountId?: AccountId;
15
15
  };
16
- executeSessionRequest(event: Web3WalletTypes.SessionRequest, hederaWallet: HederaWallet): Promise<void>;
17
- rejectSessionRequest(event: Web3WalletTypes.SessionRequest, error: {
16
+ executeSessionRequest(event: WalletKitTypes.SessionRequest, hederaWallet: HederaWallet): Promise<void>;
17
+ rejectSessionRequest(event: WalletKitTypes.SessionRequest, error: {
18
18
  code: number;
19
19
  message: string;
20
20
  }): Promise<void>;
@@ -0,0 +1,37 @@
1
+ import { type ChainNamespace } from '@reown/appkit-common';
2
+ import { AdapterBlueprint } from '@reown/appkit/adapters';
3
+ type UniversalProvider = Parameters<AdapterBlueprint['setUniversalProvider']>[0];
4
+ export declare class HederaAdapter extends AdapterBlueprint {
5
+ constructor(params: AdapterBlueprint.Params);
6
+ setUniversalProvider(universalProvider: UniversalProvider): void;
7
+ connect(params: AdapterBlueprint.ConnectParams): Promise<AdapterBlueprint.ConnectResult>;
8
+ disconnect(): Promise<void>;
9
+ getAccounts({ namespace, }: AdapterBlueprint.GetAccountsParams & {
10
+ namespace: ChainNamespace;
11
+ }): Promise<AdapterBlueprint.GetAccountsResult>;
12
+ syncConnectors(): Promise<void>;
13
+ getBalance(params: AdapterBlueprint.GetBalanceParams): Promise<AdapterBlueprint.GetBalanceResult>;
14
+ signMessage(params: AdapterBlueprint.SignMessageParams): Promise<AdapterBlueprint.SignMessageResult>;
15
+ estimateGas(params: AdapterBlueprint.EstimateGasTransactionArgs): Promise<AdapterBlueprint.EstimateGasTransactionResult>;
16
+ sendTransaction(params: AdapterBlueprint.SendTransactionParams): Promise<AdapterBlueprint.SendTransactionResult>;
17
+ writeContract(params: AdapterBlueprint.WriteContractParams): Promise<AdapterBlueprint.WriteContractResult>;
18
+ getEnsAddress(params: AdapterBlueprint.GetEnsAddressParams): Promise<AdapterBlueprint.GetEnsAddressResult>;
19
+ parseUnits(params: AdapterBlueprint.ParseUnitsParams): AdapterBlueprint.ParseUnitsResult;
20
+ formatUnits(params: AdapterBlueprint.FormatUnitsParams): AdapterBlueprint.FormatUnitsResult;
21
+ getCapabilities(params: AdapterBlueprint.GetCapabilitiesParams): Promise<unknown>;
22
+ getProfile(): Promise<AdapterBlueprint.GetProfileResult>;
23
+ grantPermissions(): Promise<unknown>;
24
+ revokePermissions(): Promise<`0x${string}`>;
25
+ syncConnection(params: AdapterBlueprint.SyncConnectionParams): Promise<{
26
+ id: string;
27
+ type: "WALLET_CONNECT";
28
+ chainId: string | number;
29
+ provider: UniversalProvider;
30
+ address: string;
31
+ }>;
32
+ switchNetwork(params: AdapterBlueprint.SwitchNetworkParams): Promise<void>;
33
+ protected getWalletConnectConnector(): ReturnType<AdapterBlueprint['getWalletConnectConnector']>;
34
+ getWalletConnectProvider(): UniversalProvider;
35
+ walletGetAssets(_params: AdapterBlueprint.WalletGetAssetsParams): Promise<AdapterBlueprint.WalletGetAssetsResponse>;
36
+ }
37
+ export {};
@@ -0,0 +1,255 @@
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
+ }
@@ -0,0 +1,29 @@
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 {};
@@ -0,0 +1,35 @@
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
+ }
@@ -0,0 +1 @@
1
+ export * from './HederaConnector';
@@ -0,0 +1 @@
1
+ export * from './HederaConnector';
@@ -0,0 +1,4 @@
1
+ export * from './adapter';
2
+ export * from './providers';
3
+ export * from './utils';
4
+ export * from './wallets';
@@ -0,0 +1,4 @@
1
+ export * from './adapter';
2
+ export * from './providers';
3
+ export * from './utils';
4
+ export * from './wallets';
@@ -0,0 +1,33 @@
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;