@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
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Gets message from various signing request methods by filtering out
3
+ * a value that is not an address (thus is a message).
4
+ * If it is a hex string, it gets converted to utf8 string
5
+ */
6
+ export declare function getSignParamsMessage(params: string[]): string;
7
+ /**
8
+ * Gets data from various signTypedData request methods by filtering out
9
+ * a value that is not an address (thus is data).
10
+ * If data is a string convert it to object
11
+ */
12
+ export declare function getSignTypedDataParamsData(params: string[]): any;
@@ -0,0 +1,25 @@
1
+ import { ethers } from 'ethers';
2
+ /**
3
+ * Gets message from various signing request methods by filtering out
4
+ * a value that is not an address (thus is a message).
5
+ * If it is a hex string, it gets converted to utf8 string
6
+ */
7
+ export function getSignParamsMessage(params) {
8
+ const message = params.filter((p) => !ethers.isAddress(p))[0];
9
+ if (ethers.isHexString(message)) {
10
+ return ethers.toUtf8String(message);
11
+ }
12
+ return message;
13
+ }
14
+ /**
15
+ * Gets data from various signTypedData request methods by filtering out
16
+ * a value that is not an address (thus is data).
17
+ * If data is a string convert it to object
18
+ */
19
+ export function getSignTypedDataParamsData(params) {
20
+ const data = params.filter((p) => !ethers.isAddress(p))[0];
21
+ if (typeof data === 'string') {
22
+ return JSON.parse(data);
23
+ }
24
+ return data;
25
+ }
@@ -0,0 +1,4 @@
1
+ export * from './chains';
2
+ export * from './constants';
3
+ export * from './types';
4
+ export * from './helpers';
@@ -0,0 +1,4 @@
1
+ export * from './chains';
2
+ export * from './constants';
3
+ export * from './types';
4
+ export * from './helpers';
@@ -0,0 +1,9 @@
1
+ import { SignClientTypes } from '@walletconnect/types';
2
+ export interface EthFilter {
3
+ address?: string;
4
+ topics?: Array<string | null>;
5
+ fromBlock?: string;
6
+ toBlock?: string;
7
+ blockHash?: string;
8
+ }
9
+ export type WalletRequestEventArgs = Omit<SignClientTypes.EventArguments['session_request'], 'verifyContext'>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
1
+ import { JsonRpcProvider, BaseWallet as BaseEvmWallet, TransactionResponse, JsonRpcTransactionRequest } from 'ethers';
2
+ import { JsonRpcError, JsonRpcResult } from '@walletconnect/jsonrpc-utils';
3
+ import { Eip155JsonRpcMethod, WalletRequestEventArgs } from '..';
4
+ /**
5
+ * Types
6
+ */
7
+ interface IInitArgs {
8
+ privateKey?: string;
9
+ }
10
+ export interface EIP155WalletInterface {
11
+ getPrivateKey(): string;
12
+ getEvmAddress(): string;
13
+ connect(provider: JsonRpcProvider): BaseEvmWallet;
14
+ approveSessionRequest(requestEvent: WalletRequestEventArgs): Promise<JsonRpcResult<any> | JsonRpcError>;
15
+ rejectSessionRequest(requestEvent: WalletRequestEventArgs): JsonRpcError;
16
+ [Eip155JsonRpcMethod.PersonalSign](message: string): Promise<string>;
17
+ [Eip155JsonRpcMethod.Sign](message: string): Promise<string>;
18
+ [Eip155JsonRpcMethod.SignTypedData](domain: any, types: any, data: any): Promise<string>;
19
+ [Eip155JsonRpcMethod.SignTypedDataV3](domain: any, types: any, data: any): Promise<string>;
20
+ [Eip155JsonRpcMethod.SignTypedDataV4](domain: any, types: any, data: any): Promise<string>;
21
+ [Eip155JsonRpcMethod.SignTransaction](transaction: JsonRpcTransactionRequest, provider: JsonRpcProvider): Promise<string>;
22
+ [Eip155JsonRpcMethod.SendTransaction](transaction: JsonRpcTransactionRequest, provider: JsonRpcProvider): Promise<TransactionResponse>;
23
+ [Eip155JsonRpcMethod.SendRawTransaction](rawTransaction: string, provider: JsonRpcProvider): Promise<TransactionResponse>;
24
+ }
25
+ /**
26
+ * Library
27
+ */
28
+ export declare class EIP155Wallet implements EIP155WalletInterface {
29
+ wallet: BaseEvmWallet;
30
+ constructor(wallet: BaseEvmWallet);
31
+ connect(provider: JsonRpcProvider): BaseEvmWallet;
32
+ personal_sign(message: string): Promise<string>;
33
+ eth_sign(message: string): Promise<string>;
34
+ eth_signTypedData(domain: any, types: any, data: any): Promise<string>;
35
+ eth_signTypedData_v3(domain: any, types: any, data: any): Promise<string>;
36
+ eth_signTypedData_v4(domain: any, types: any, data: any): Promise<string>;
37
+ eth_signTransaction(transaction: JsonRpcTransactionRequest, provider: JsonRpcProvider): Promise<string>;
38
+ eth_sendTransaction(transaction: JsonRpcTransactionRequest, provider: JsonRpcProvider): Promise<TransactionResponse>;
39
+ eth_sendRawTransaction(rawTransaction: string, provider: JsonRpcProvider): Promise<TransactionResponse>;
40
+ static init({ privateKey }: IInitArgs): EIP155Wallet;
41
+ getPrivateKey(): string;
42
+ getEvmAddress(): string;
43
+ approveSessionRequest(requestEvent: WalletRequestEventArgs): Promise<JsonRpcError | JsonRpcResult<string>>;
44
+ rejectSessionRequest(requestEvent: WalletRequestEventArgs): JsonRpcError;
45
+ }
46
+ export {};
@@ -0,0 +1,136 @@
1
+ import { JsonRpcProvider, Wallet, Transaction, } from 'ethers';
2
+ import { formatJsonRpcError, formatJsonRpcResult, } from '@walletconnect/jsonrpc-utils';
3
+ import { getSdkError } from '@walletconnect/utils';
4
+ import { Eip155JsonRpcMethod, HederaChainDefinition, getSignParamsMessage, getSignTypedDataParamsData, } from '..';
5
+ /**
6
+ * Library
7
+ */
8
+ export class EIP155Wallet {
9
+ constructor(wallet) {
10
+ this.wallet = wallet;
11
+ }
12
+ connect(provider) {
13
+ return this.wallet.connect(provider);
14
+ }
15
+ personal_sign(message) {
16
+ return this.eth_sign(message);
17
+ }
18
+ eth_sign(message) {
19
+ return this.wallet.signMessage(message);
20
+ }
21
+ eth_signTypedData(domain, types, data) {
22
+ return this.wallet.signTypedData(domain, types, data);
23
+ }
24
+ eth_signTypedData_v3(domain, types, data) {
25
+ return this.eth_signTypedData(domain, types, data);
26
+ }
27
+ eth_signTypedData_v4(domain, types, data) {
28
+ return this.eth_signTypedData(domain, types, data);
29
+ }
30
+ async eth_signTransaction(transaction, provider) {
31
+ console.log({ transaction });
32
+ // Populate transaction
33
+ const preparedTransaction = await this.connect(provider).populateTransaction(transaction);
34
+ delete preparedTransaction.from;
35
+ const txObj = Transaction.from(preparedTransaction);
36
+ return this.wallet.signTransaction(txObj);
37
+ }
38
+ eth_sendTransaction(transaction, provider) {
39
+ return this.connect(provider).sendTransaction(transaction);
40
+ }
41
+ eth_sendRawTransaction(rawTransaction, provider) {
42
+ return provider.broadcastTransaction(rawTransaction);
43
+ }
44
+ static init({ privateKey }) {
45
+ const wallet = privateKey ? new Wallet(privateKey) : Wallet.createRandom();
46
+ return new EIP155Wallet(wallet);
47
+ }
48
+ getPrivateKey() {
49
+ return this.wallet.privateKey;
50
+ }
51
+ getEvmAddress() {
52
+ return this.wallet.address;
53
+ }
54
+ async approveSessionRequest(requestEvent) {
55
+ const { params, id } = requestEvent;
56
+ const { chainId, request } = params;
57
+ const networks = Object.values(HederaChainDefinition.EVM);
58
+ const caipNetwork = networks.find((network) => network.caipNetworkId == chainId);
59
+ if (!caipNetwork) {
60
+ return formatJsonRpcError(id, 'Unsupported network');
61
+ }
62
+ switch (request.method) {
63
+ case Eip155JsonRpcMethod.PersonalSign:
64
+ case Eip155JsonRpcMethod.Sign:
65
+ try {
66
+ const message = getSignParamsMessage(request.params);
67
+ const signedMessage = await this.eth_sign(message);
68
+ return formatJsonRpcResult(id, signedMessage);
69
+ }
70
+ catch (error) {
71
+ console.error(error);
72
+ if (!(error instanceof Error)) {
73
+ return formatJsonRpcError(id, 'Failed to sign message');
74
+ }
75
+ alert(error.message);
76
+ return formatJsonRpcError(id, error.message);
77
+ }
78
+ case Eip155JsonRpcMethod.SignTypedData:
79
+ case Eip155JsonRpcMethod.SignTypedDataV3:
80
+ case Eip155JsonRpcMethod.SignTypedDataV4:
81
+ try {
82
+ const { domain, types, message: data } = getSignTypedDataParamsData(request.params);
83
+ // https://github.com/ethers-io/ethers.js/issues/687#issuecomment-714069471
84
+ delete types.EIP712Domain;
85
+ const signedData = await this.eth_signTypedData(domain, types, data);
86
+ return formatJsonRpcResult(id, signedData);
87
+ }
88
+ catch (error) {
89
+ console.error(error);
90
+ if (!(error instanceof Error)) {
91
+ return formatJsonRpcError(id, 'Failed to sign typed data');
92
+ }
93
+ alert(error.message);
94
+ return formatJsonRpcError(id, error.message);
95
+ }
96
+ case Eip155JsonRpcMethod.SendRawTransaction:
97
+ case Eip155JsonRpcMethod.SendTransaction:
98
+ try {
99
+ const provider = new JsonRpcProvider(caipNetwork.rpcUrls.default.http[0]);
100
+ const sendTransaction = request.params[0];
101
+ const txResponse = await this[request.method](sendTransaction, provider);
102
+ 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
+ return formatJsonRpcResult(id, txHash);
108
+ }
109
+ catch (error) {
110
+ console.error(error);
111
+ return formatJsonRpcError(id, error instanceof Error ? error.message : 'Failed to send transaction');
112
+ }
113
+ case Eip155JsonRpcMethod.SignTransaction:
114
+ try {
115
+ const provider = new JsonRpcProvider(caipNetwork.rpcUrls.default.http[0]);
116
+ const signTransaction = request.params[0];
117
+ const signature = await this.eth_signTransaction(signTransaction, provider);
118
+ return formatJsonRpcResult(id, signature);
119
+ }
120
+ catch (error) {
121
+ console.error(error);
122
+ if (!(error instanceof Error)) {
123
+ return formatJsonRpcError(id, 'Failed to sign transaction');
124
+ }
125
+ alert(error.message);
126
+ return formatJsonRpcError(id, error.message);
127
+ }
128
+ default:
129
+ throw new Error(getSdkError('INVALID_METHOD').message);
130
+ }
131
+ }
132
+ rejectSessionRequest(requestEvent) {
133
+ const { id } = requestEvent;
134
+ return formatJsonRpcError(id, getSdkError('USER_REJECTED').message);
135
+ }
136
+ }
@@ -0,0 +1,53 @@
1
+ import { Wallet as HederaWallet, AccountId, Transaction, Query } from '@hashgraph/sdk';
2
+ import { JsonRpcError, JsonRpcResult } from '@walletconnect/jsonrpc-utils';
3
+ import { HederaChainId, HederaJsonRpcMethod, GetNodeAddressesResult, ExecuteTransactionResult, SignAndExecuteQueryResult, SignMessageResult, SignAndExecuteTransactionResult, SignTransactionResult, WalletRequestEventArgs } from '../..';
4
+ import Provider from '../../lib/wallet/provider';
5
+ interface IInitArgs {
6
+ chainId: HederaChainId;
7
+ accountId: AccountId | string;
8
+ privateKey: string;
9
+ _provider?: Provider;
10
+ }
11
+ export interface HIP820WalletInterface {
12
+ approveSessionRequest(requestEvent: WalletRequestEventArgs): Promise<JsonRpcResult<any> | JsonRpcError>;
13
+ rejectSessionRequest(requestEvent: WalletRequestEventArgs): JsonRpcError;
14
+ getHederaWallet(): HederaWallet;
15
+ [HederaJsonRpcMethod.GetNodeAddresses](id: number, _: any): Promise<GetNodeAddressesResult>;
16
+ [HederaJsonRpcMethod.ExecuteTransaction](id: number, body: Transaction): Promise<ExecuteTransactionResult | JsonRpcError>;
17
+ [HederaJsonRpcMethod.SignMessage](id: number, body: string): Promise<SignMessageResult>;
18
+ [HederaJsonRpcMethod.SignAndExecuteQuery](id: number, body: Query<any>): Promise<SignAndExecuteQueryResult | JsonRpcError>;
19
+ [HederaJsonRpcMethod.SignAndExecuteTransaction](id: number, body: Transaction): Promise<SignAndExecuteTransactionResult | JsonRpcError>;
20
+ [HederaJsonRpcMethod.SignTransaction](id: number, body: Uint8Array): Promise<SignTransactionResult>;
21
+ }
22
+ export declare class HIP820Wallet implements HIP820WalletInterface {
23
+ wallet: HederaWallet;
24
+ constructor(wallet: HederaWallet);
25
+ getHederaWallet(): HederaWallet;
26
+ static init({ chainId, accountId, privateKey, _provider }: IInitArgs): HIP820Wallet;
27
+ validateParam(name: string, value: any, expectedType: string): void;
28
+ parseSessionRequest(event: WalletRequestEventArgs, shouldThrow?: boolean): {
29
+ method: HederaJsonRpcMethod;
30
+ chainId: HederaChainId;
31
+ id: number;
32
+ topic: string;
33
+ body?: Transaction | Query<any> | string | Uint8Array | undefined;
34
+ accountId?: AccountId;
35
+ };
36
+ approveSessionRequest(event: WalletRequestEventArgs): Promise<JsonRpcResult<any> | JsonRpcError>;
37
+ rejectSessionRequest(requestEvent: WalletRequestEventArgs): JsonRpcError;
38
+ hedera_getNodeAddresses(id: number, _: any): Promise<JsonRpcResult<{
39
+ nodes: string[];
40
+ }>>;
41
+ hedera_executeTransaction(id: number, signedTransaction: Transaction): Promise<ExecuteTransactionResult | JsonRpcError>;
42
+ hedera_signMessage(id: number, body: string): Promise<JsonRpcResult<{
43
+ signatureMap: string;
44
+ }>>;
45
+ hedera_signAndExecuteQuery(id: number, body: Query<any>): Promise<JsonRpcError | JsonRpcResult<{
46
+ response: string;
47
+ }>>;
48
+ hedera_signAndExecuteTransaction(id: number, transaction: Transaction): Promise<JsonRpcError | JsonRpcResult<import("@hashgraph/sdk/lib/transaction/TransactionResponse").TransactionResponseJSON>>;
49
+ hedera_signTransaction(id: number, body: Uint8Array): Promise<JsonRpcResult<{
50
+ signatureMap: string;
51
+ }>>;
52
+ }
53
+ export default HIP820Wallet;
@@ -0,0 +1,239 @@
1
+ import { Buffer } from 'buffer';
2
+ import { getSdkError } from '@walletconnect/utils';
3
+ import { Wallet as HederaWallet, Client, AccountId, PrecheckStatusError, PrivateKey, } from '@hashgraph/sdk';
4
+ import { proto } from '@hashgraph/proto';
5
+ import { formatJsonRpcError, formatJsonRpcResult, } from '@walletconnect/jsonrpc-utils';
6
+ import { HederaJsonRpcMethod, base64StringToQuery, Uint8ArrayToBase64String, stringToSignerMessage, signerSignaturesToSignatureMap, getHederaError, base64StringToTransaction, signatureMapToBase64String, } from '../..';
7
+ import Provider from '../../lib/wallet/provider';
8
+ export class HIP820Wallet {
9
+ /*
10
+ * Set default values for chains, methods, events
11
+ */
12
+ constructor(wallet) {
13
+ this.wallet = wallet;
14
+ }
15
+ /*
16
+ * Hedera Wallet Signer
17
+ */
18
+ getHederaWallet() {
19
+ return this.wallet;
20
+ }
21
+ static init({ chainId, accountId, privateKey, _provider }) {
22
+ const network = chainId.split(':')[1];
23
+ const client = Client.forName(network);
24
+ const provider = _provider !== null && _provider !== void 0 ? _provider : new Provider(client);
25
+ const wallet = new HederaWallet(accountId, PrivateKey.fromStringECDSA(privateKey), provider);
26
+ return new HIP820Wallet(wallet);
27
+ }
28
+ /*
29
+ * Session Requests
30
+ */
31
+ validateParam(name, value, expectedType) {
32
+ if (expectedType === 'array' && Array.isArray(value))
33
+ return;
34
+ if (typeof value === expectedType)
35
+ return;
36
+ throw getHederaError('INVALID_PARAMS', `Invalid paramameter value for ${name}, expected ${expectedType} but got ${typeof value}`);
37
+ }
38
+ parseSessionRequest(event,
39
+ // optional arg to throw error if request is invalid, call with shouldThrow = false when calling from rejectSessionRequest as we only need id and top to send reject response
40
+ shouldThrow = true) {
41
+ const { id, topic } = event;
42
+ const { request: { method, params }, chainId, } = event.params;
43
+ let body;
44
+ // get account id from optional second param for transactions and queries or from transaction id
45
+ // this allows for the case where the requested signer is not the payer, but defaults to the payer if a second param is not provided
46
+ let signerAccountId;
47
+ // First test for valid params for each method
48
+ // then convert params to a body that the respective function expects
49
+ try {
50
+ switch (method) {
51
+ case HederaJsonRpcMethod.GetNodeAddresses: {
52
+ // 1
53
+ if (params)
54
+ throw getHederaError('INVALID_PARAMS');
55
+ break;
56
+ }
57
+ case HederaJsonRpcMethod.ExecuteTransaction: {
58
+ // 2
59
+ const { transactionList } = params;
60
+ this.validateParam('transactionList', transactionList, 'string');
61
+ body = base64StringToTransaction(transactionList);
62
+ break;
63
+ }
64
+ case HederaJsonRpcMethod.SignMessage: {
65
+ // 3
66
+ const { signerAccountId: _accountId, message } = params;
67
+ this.validateParam('signerAccountId', _accountId, 'string');
68
+ this.validateParam('message', message, 'string');
69
+ signerAccountId = AccountId.fromString(_accountId.replace(chainId + ':', ''));
70
+ body = message;
71
+ break;
72
+ }
73
+ case HederaJsonRpcMethod.SignAndExecuteQuery: {
74
+ // 4
75
+ const { signerAccountId: _accountId, query } = params;
76
+ this.validateParam('signerAccountId', _accountId, 'string');
77
+ this.validateParam('query', query, 'string');
78
+ signerAccountId = AccountId.fromString(_accountId.replace(chainId + ':', ''));
79
+ body = base64StringToQuery(query);
80
+ break;
81
+ }
82
+ case HederaJsonRpcMethod.SignAndExecuteTransaction: {
83
+ // 5
84
+ const { signerAccountId: _accountId, transactionList } = params;
85
+ this.validateParam('signerAccountId', _accountId, 'string');
86
+ this.validateParam('transactionList', transactionList, 'string');
87
+ signerAccountId = AccountId.fromString(_accountId.replace(chainId + ':', ''));
88
+ body = base64StringToTransaction(transactionList);
89
+ break;
90
+ }
91
+ case HederaJsonRpcMethod.SignTransaction: {
92
+ // 6
93
+ const { signerAccountId: _accountId, transactionBody } = params;
94
+ this.validateParam('signerAccountId', _accountId, 'string');
95
+ this.validateParam('transactionBody', transactionBody, 'string');
96
+ signerAccountId = AccountId.fromString(_accountId.replace(chainId + ':', ''));
97
+ body = Buffer.from(transactionBody, 'base64');
98
+ break;
99
+ }
100
+ default:
101
+ throw getSdkError('INVALID_METHOD');
102
+ }
103
+ // error parsing request params
104
+ }
105
+ catch (e) {
106
+ if (shouldThrow)
107
+ throw e;
108
+ }
109
+ return {
110
+ method: method,
111
+ chainId: chainId,
112
+ id,
113
+ topic,
114
+ body,
115
+ accountId: signerAccountId,
116
+ };
117
+ }
118
+ async approveSessionRequest(event) {
119
+ const { method, id, body } = this.parseSessionRequest(event);
120
+ const response = await this[method](id, body);
121
+ console.log({ response });
122
+ return response;
123
+ }
124
+ rejectSessionRequest(requestEvent) {
125
+ const { id } = requestEvent;
126
+ return formatJsonRpcError(id, getSdkError('USER_REJECTED').message);
127
+ }
128
+ /*
129
+ * JSON RPC Methods
130
+ */
131
+ // 1. hedera_getNodeAddresses
132
+ async hedera_getNodeAddresses(id,
133
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
134
+ _) {
135
+ const nodesAccountIds = this.wallet.getNetwork();
136
+ const nodes = Object.values(nodesAccountIds).map((nodeAccountId) => nodeAccountId.toString());
137
+ console.log(nodes);
138
+ return formatJsonRpcResult(id, {
139
+ nodes,
140
+ });
141
+ }
142
+ // 2. hedera_executeTransaction
143
+ async hedera_executeTransaction(id, signedTransaction) {
144
+ try {
145
+ const response = await signedTransaction.executeWithSigner(this.wallet);
146
+ return formatJsonRpcResult(id, response.toJSON());
147
+ }
148
+ catch (e) {
149
+ if (e instanceof PrecheckStatusError) {
150
+ // HIP-820 error format
151
+ return formatJsonRpcError(id, {
152
+ code: 9000,
153
+ message: e.message,
154
+ data: e.status._code.toString(),
155
+ });
156
+ }
157
+ return formatJsonRpcError(id, { code: 9000, message: 'Unknown Error' });
158
+ }
159
+ }
160
+ // 3. hedera_signMessage
161
+ async hedera_signMessage(id, body) {
162
+ // signer takes an array of Uint8Arrays though spec allows for 1 message to be signed
163
+ const signerSignatures = await this.wallet.sign(stringToSignerMessage(body));
164
+ const _signatureMap = proto.SignatureMap.create(signerSignaturesToSignatureMap(signerSignatures));
165
+ const signatureMap = signatureMapToBase64String(_signatureMap);
166
+ return formatJsonRpcResult(id, {
167
+ signatureMap,
168
+ });
169
+ }
170
+ // 4. hedera_signAndExecuteQuery
171
+ async hedera_signAndExecuteQuery(id, body) {
172
+ /*
173
+ * Can be used with return values the have a toBytes method implemented
174
+ * For example:
175
+ * https://github.com/hashgraph/hedera-sdk-js/blob/c4438cbaa38074d8bfc934dba84e3b430344ed89/src/account/AccountInfo.js#L402
176
+ */
177
+ try {
178
+ const queryResult = await body.executeWithSigner(this.wallet);
179
+ let queryResponse = '';
180
+ if (Array.isArray(queryResult)) {
181
+ queryResponse = queryResult
182
+ .map((qr) => Uint8ArrayToBase64String(qr.toBytes()))
183
+ .join(',');
184
+ }
185
+ else {
186
+ queryResponse = Uint8ArrayToBase64String(queryResult.toBytes());
187
+ }
188
+ return formatJsonRpcResult(id, {
189
+ response: queryResponse,
190
+ });
191
+ }
192
+ catch (e) {
193
+ if (e instanceof PrecheckStatusError) {
194
+ // HIP-820 error format
195
+ return formatJsonRpcError(id, {
196
+ code: 9000,
197
+ message: e.message,
198
+ data: e.status._code.toString(),
199
+ });
200
+ }
201
+ return formatJsonRpcError(id, { code: 9000, message: 'Unknown Error' });
202
+ }
203
+ }
204
+ // 5. hedera_signAndExecuteTransaction
205
+ async hedera_signAndExecuteTransaction(id, transaction) {
206
+ console.log({ inputTx: JSON.parse(JSON.stringify(transaction)) });
207
+ // check transaction is incomplete (HIP-745)
208
+ if (!transaction.isFrozen()) {
209
+ // set multiple nodeAccountIds and transactionId if not present
210
+ await transaction.freezeWithSigner(this.wallet);
211
+ }
212
+ const signedTransaction = await transaction.signWithSigner(this.wallet);
213
+ try {
214
+ const response = await signedTransaction.executeWithSigner(this.wallet);
215
+ return formatJsonRpcResult(id, response.toJSON());
216
+ }
217
+ catch (e) {
218
+ if (e instanceof PrecheckStatusError) {
219
+ // HIP-820 error format
220
+ return formatJsonRpcError(id, {
221
+ code: 9000,
222
+ message: e.message,
223
+ data: e.status._code.toString(),
224
+ });
225
+ }
226
+ return formatJsonRpcError(id, { code: 9000, message: 'Unknown Error' });
227
+ }
228
+ }
229
+ // 6. hedera_signTransaction
230
+ async hedera_signTransaction(id, body) {
231
+ const signerSignatures = await this.wallet.sign([body]);
232
+ const _signatureMap = proto.SignatureMap.create(signerSignaturesToSignatureMap(signerSignatures));
233
+ const signatureMap = signatureMapToBase64String(_signatureMap);
234
+ return formatJsonRpcResult(id, {
235
+ signatureMap,
236
+ });
237
+ }
238
+ }
239
+ export default HIP820Wallet;
@@ -0,0 +1,2 @@
1
+ export * from './EIP155Wallet';
2
+ export * from './HIP820Wallet';
@@ -0,0 +1,2 @@
1
+ export * from './EIP155Wallet';
2
+ export * from './HIP820Wallet';
package/package.json CHANGED
@@ -1,81 +1,46 @@
1
1
  {
2
2
  "name": "@hashgraph/hedera-wallet-connect",
3
- "version": "1.5.2-canary.dd48df1.0",
4
- "description": "A library to facilitate integrating Hedera with WalletConnect",
3
+ "version": "2.0.0-canary.45f2441.0",
4
+ "description": "A library to facilitate integrating Hedera",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/hashgraph/hedera-wallet-connect.git"
8
8
  },
9
9
  "main": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts",
11
- "author": "Hgraph <support@hgraph.io>",
11
+ "author": "Hgraph <support@hgraph.com>",
12
12
  "keywords": [
13
13
  "hedera",
14
14
  "walletconnect",
15
- "hashgraph"
15
+ "reown",
16
+ "hashgraph",
17
+ "evm",
18
+ "ethereum",
19
+ "smart contracts",
20
+ "hbar",
21
+ "ethers"
16
22
  ],
17
- "overrides": {
18
- "elliptic": "6.6.1"
19
- },
20
23
  "license": "Apache-2.0",
21
- "devDependencies": {
22
- "@hashgraph/hedera-wallet-connect": "^1.5.0",
23
- "@swc/core": "^1.7.40",
24
- "@swc/jest": "^0.2.36",
25
- "@types/jest": "^29.5.3",
26
- "@types/node": "^22.5.0",
27
- "@types/react-dom": "^19.0.3",
28
- "@walletconnect/modal": "^2.7.0",
29
- "@walletconnect/sign-client": "^2.19.1",
30
- "@walletconnect/types": "^2.19.1",
31
- "concurrently": "^9.0.1",
32
- "esbuild": "^0.25.0",
33
- "esbuild-plugin-copy": "^2.1.1",
34
- "eslint-plugin-tsdoc": "^0.4.0",
35
- "husky": "^9.0.6",
36
- "jest": "^29.7.0",
37
- "lint-staged": "^15.1.0",
38
- "lokijs": "^1.5.12",
39
- "long": "^5.2.3",
40
- "nodemon": "^3.0.3",
41
- "prettier": "^3.2.4",
42
- "react": "^19.0.0",
43
- "react-dom": "^19.0.0",
44
- "rimraf": "^5.0.5",
45
- "ts-node": "^10.9.2",
46
- "tweetnacl": "^1.0.3",
47
- "typedoc": "^0.27.6",
48
- "typedoc-theme-hierarchy": "^5.0.0",
49
- "typescript": "^5.2.2"
50
- },
51
24
  "scripts": {
52
25
  "build": "rimraf dist && tsc",
53
- "build:ts-demo": "node scripts/demos/typescript/build.mjs",
54
- "build:react-demo": "node scripts/demos/react/build.mjs",
55
- "build:docs": "typedoc --options typedoc.json",
56
- "watch": "nodemon --watch src/lib/ --ext ts --exec \"npm run build\"",
57
- "dev": "npm run dev:ts-demo",
58
- "dev:docs": "cd docs && npm run start",
59
- "dev:ts-demo": "rimraf dist && npm run build && concurrently --raw \"npm run watch\" \"node scripts/demos/typescript/dev.mjs\"",
60
- "dev:react-demo": "rimraf dist && npm run build && concurrently --raw \"npm run watch\" \"node scripts/demos/react/dev.mjs\"",
26
+ "watch": "nodemon --watch src/ --ext ts --exec \"npm run build\"",
61
27
  "test": "jest",
62
- "test:watch": "jest --watch",
63
- "test:connect": "jest --testMatch '**/DAppConnector.test.ts' --verbose",
64
- "test:signer": "jest --testMatch '**/DAppSigner.test.ts' --verbose",
65
28
  "prepublishOnly": "rm -Rf dist && npm run build",
66
- "prepare": "husky install",
67
29
  "prettier:check": "prettier --check ./src/",
68
- "prettier:fix": "prettier --write ./src/",
69
- "prod:docs-docker": "sh docker-run.sh",
70
- "test:sigMap": "jest --testMatch '**/SignatureMapHelpers.test.ts' --verbose",
71
- "test:coverage": "jest --coverage",
72
- "test:coverage:html": "jest --coverage --coverageReporters='text-summary' --coverageReporters='html'"
30
+ "prettier:fix": "prettier --write ./src/"
73
31
  },
74
32
  "peerDependencies": {
75
33
  "@hashgraph/sdk": "^2.61.0",
76
- "@walletconnect/qrcode-modal": "^1.8.0",
77
- "@walletconnect/types": "^2.19.1",
78
- "@walletconnect/utils": "^2.19.1",
79
- "@walletconnect/web3wallet": "^1.16.0"
34
+ "@reown/appkit": "^1.7.1",
35
+ "@reown/walletkit": "^1.2.3",
36
+ "@walletconnect/modal": "^2.7.0",
37
+ "ethers": "^6.13.5"
38
+ },
39
+ "devDependencies": {
40
+ "@swc/jest": "^0.2.37",
41
+ "jest": "^29.7.0",
42
+ "prettier": "^3.5.3",
43
+ "ts-node": "^10.9.2",
44
+ "typescript": "^5.8.2"
80
45
  }
81
46
  }