@hashgraph/hedera-wallet-connect 2.0.1-canary.7e04cff.0 → 2.0.1-canary.8bde0e3.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 (48) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/lib/dapp/DAppSigner.d.ts +2 -0
  4. package/dist/lib/dapp/DAppSigner.js +16 -2
  5. package/dist/lib/dapp/index.d.ts +7 -5
  6. package/dist/lib/dapp/index.js +36 -4
  7. package/dist/lib/shared/accountInfo.d.ts +30 -0
  8. package/dist/lib/shared/accountInfo.js +1 -0
  9. package/dist/lib/shared/index.d.ts +2 -0
  10. package/dist/lib/shared/index.js +2 -0
  11. package/dist/lib/shared/mirrorNode.d.ts +3 -0
  12. package/dist/lib/shared/mirrorNode.js +17 -0
  13. package/dist/lib/shared/payloads.d.ts +1 -1
  14. package/dist/lib/shared/utils.d.ts +1 -2
  15. package/dist/lib/shared/utils.js +2 -3
  16. package/dist/reown/adapter.d.ts +37 -0
  17. package/dist/reown/adapter.js +255 -0
  18. package/dist/reown/connectors/HederaConnector.d.ts +29 -0
  19. package/dist/reown/connectors/HederaConnector.js +35 -0
  20. package/dist/reown/connectors/index.d.ts +1 -0
  21. package/dist/reown/connectors/index.js +1 -0
  22. package/dist/reown/index.d.ts +4 -0
  23. package/dist/reown/index.js +4 -0
  24. package/dist/reown/providers/EIP155Provider.d.ts +33 -0
  25. package/dist/reown/providers/EIP155Provider.js +187 -0
  26. package/dist/reown/providers/HIP820Provider.d.ts +26 -0
  27. package/dist/reown/providers/HIP820Provider.js +69 -0
  28. package/dist/reown/providers/HederaProvider.d.ts +164 -0
  29. package/dist/reown/providers/HederaProvider.js +471 -0
  30. package/dist/reown/providers/index.d.ts +3 -0
  31. package/dist/reown/providers/index.js +3 -0
  32. package/dist/reown/utils/chains.d.ts +18 -0
  33. package/dist/reown/utils/chains.js +152 -0
  34. package/dist/reown/utils/constants.d.ts +16 -0
  35. package/dist/reown/utils/constants.js +18 -0
  36. package/dist/reown/utils/helpers.d.ts +12 -0
  37. package/dist/reown/utils/helpers.js +25 -0
  38. package/dist/reown/utils/index.d.ts +4 -0
  39. package/dist/reown/utils/index.js +4 -0
  40. package/dist/reown/utils/types.d.ts +9 -0
  41. package/dist/reown/utils/types.js +1 -0
  42. package/dist/reown/wallets/EIP155Wallet.d.ts +46 -0
  43. package/dist/reown/wallets/EIP155Wallet.js +124 -0
  44. package/dist/reown/wallets/HIP820Wallet.d.ts +53 -0
  45. package/dist/reown/wallets/HIP820Wallet.js +236 -0
  46. package/dist/reown/wallets/index.d.ts +2 -0
  47. package/dist/reown/wallets/index.js +2 -0
  48. package/package.json +5 -3
@@ -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,124 @@
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
+ // Populate transaction
32
+ const preparedTransaction = await this.connect(provider).populateTransaction(transaction);
33
+ delete preparedTransaction.from;
34
+ const txObj = Transaction.from(preparedTransaction);
35
+ return this.wallet.signTransaction(txObj);
36
+ }
37
+ eth_sendTransaction(transaction, provider) {
38
+ return this.connect(provider).sendTransaction(transaction);
39
+ }
40
+ eth_sendRawTransaction(rawTransaction, provider) {
41
+ return provider.broadcastTransaction(rawTransaction);
42
+ }
43
+ static init({ privateKey }) {
44
+ const wallet = privateKey ? new Wallet(privateKey) : Wallet.createRandom();
45
+ return new EIP155Wallet(wallet);
46
+ }
47
+ getPrivateKey() {
48
+ return this.wallet.privateKey;
49
+ }
50
+ getEvmAddress() {
51
+ return this.wallet.address;
52
+ }
53
+ async approveSessionRequest(requestEvent) {
54
+ const { params, id } = requestEvent;
55
+ const { chainId, request } = params;
56
+ const networks = Object.values(HederaChainDefinition.EVM);
57
+ const caipNetwork = networks.find((network) => network.caipNetworkId == chainId);
58
+ if (!caipNetwork) {
59
+ return formatJsonRpcError(id, 'Unsupported network');
60
+ }
61
+ switch (request.method) {
62
+ case Eip155JsonRpcMethod.PersonalSign:
63
+ case Eip155JsonRpcMethod.Sign:
64
+ try {
65
+ const message = getSignParamsMessage(request.params);
66
+ const signedMessage = await this.eth_sign(message);
67
+ return formatJsonRpcResult(id, signedMessage);
68
+ }
69
+ catch (error) {
70
+ if (!(error instanceof Error)) {
71
+ return formatJsonRpcError(id, 'Failed to sign message');
72
+ }
73
+ return formatJsonRpcError(id, error.message);
74
+ }
75
+ case Eip155JsonRpcMethod.SignTypedData:
76
+ case Eip155JsonRpcMethod.SignTypedDataV3:
77
+ case Eip155JsonRpcMethod.SignTypedDataV4:
78
+ try {
79
+ const { domain, types, message: data } = getSignTypedDataParamsData(request.params);
80
+ // https://github.com/ethers-io/ethers.js/issues/687#issuecomment-714069471
81
+ delete types.EIP712Domain;
82
+ const signedData = await this.eth_signTypedData(domain, types, data);
83
+ return formatJsonRpcResult(id, signedData);
84
+ }
85
+ catch (error) {
86
+ if (!(error instanceof Error)) {
87
+ return formatJsonRpcError(id, 'Failed to sign typed data');
88
+ }
89
+ return formatJsonRpcError(id, error.message);
90
+ }
91
+ case Eip155JsonRpcMethod.SendRawTransaction:
92
+ case Eip155JsonRpcMethod.SendTransaction:
93
+ try {
94
+ const provider = new JsonRpcProvider(caipNetwork.rpcUrls.default.http[0]);
95
+ const sendTransaction = request.params[0];
96
+ const txResponse = await this[request.method](sendTransaction, provider);
97
+ const txHash = typeof txResponse === 'string' ? txResponse : txResponse === null || txResponse === void 0 ? void 0 : txResponse.hash;
98
+ return formatJsonRpcResult(id, txHash);
99
+ }
100
+ catch (error) {
101
+ return formatJsonRpcError(id, error instanceof Error ? error.message : 'Failed to send transaction');
102
+ }
103
+ case Eip155JsonRpcMethod.SignTransaction:
104
+ try {
105
+ const provider = new JsonRpcProvider(caipNetwork.rpcUrls.default.http[0]);
106
+ const signTransaction = request.params[0];
107
+ const signature = await this.eth_signTransaction(signTransaction, provider);
108
+ return formatJsonRpcResult(id, signature);
109
+ }
110
+ catch (error) {
111
+ if (!(error instanceof Error)) {
112
+ return formatJsonRpcError(id, 'Failed to sign transaction');
113
+ }
114
+ return formatJsonRpcError(id, error.message);
115
+ }
116
+ default:
117
+ throw new Error(getSdkError('INVALID_METHOD').message);
118
+ }
119
+ }
120
+ rejectSessionRequest(requestEvent) {
121
+ const { id } = requestEvent;
122
+ return formatJsonRpcError(id, getSdkError('USER_REJECTED').message);
123
+ }
124
+ }
@@ -0,0 +1,53 @@
1
+ import { Wallet as HederaWallet, AccountId, Transaction, Query, PrivateKey } 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: PrivateKey;
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,236 @@
1
+ import { Buffer } from 'buffer';
2
+ import { getSdkError } from '@walletconnect/utils';
3
+ import { Wallet as HederaWallet, Client, AccountId, PrecheckStatusError, } 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, 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
+ return response;
122
+ }
123
+ rejectSessionRequest(requestEvent) {
124
+ const { id } = requestEvent;
125
+ return formatJsonRpcError(id, getSdkError('USER_REJECTED').message);
126
+ }
127
+ /*
128
+ * JSON RPC Methods
129
+ */
130
+ // 1. hedera_getNodeAddresses
131
+ async hedera_getNodeAddresses(id,
132
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
133
+ _) {
134
+ const nodesAccountIds = this.wallet.getNetwork();
135
+ const nodes = Object.values(nodesAccountIds).map((nodeAccountId) => nodeAccountId.toString());
136
+ return formatJsonRpcResult(id, {
137
+ nodes,
138
+ });
139
+ }
140
+ // 2. hedera_executeTransaction
141
+ async hedera_executeTransaction(id, signedTransaction) {
142
+ try {
143
+ const response = await this.wallet.call(signedTransaction);
144
+ return formatJsonRpcResult(id, response.toJSON());
145
+ }
146
+ catch (e) {
147
+ if (e instanceof PrecheckStatusError) {
148
+ // HIP-820 error format
149
+ return formatJsonRpcError(id, {
150
+ code: 9000,
151
+ message: e.message,
152
+ data: e.status._code.toString(),
153
+ });
154
+ }
155
+ return formatJsonRpcError(id, { code: 9000, message: 'Unknown Error' });
156
+ }
157
+ }
158
+ // 3. hedera_signMessage
159
+ async hedera_signMessage(id, body) {
160
+ // signer takes an array of Uint8Arrays though spec allows for 1 message to be signed
161
+ const signerSignatures = await this.wallet.sign(stringToSignerMessage(body));
162
+ const _signatureMap = proto.SignatureMap.create(signerSignaturesToSignatureMap(signerSignatures));
163
+ const signatureMap = signatureMapToBase64String(_signatureMap);
164
+ return formatJsonRpcResult(id, {
165
+ signatureMap,
166
+ });
167
+ }
168
+ // 4. hedera_signAndExecuteQuery
169
+ async hedera_signAndExecuteQuery(id, body) {
170
+ /*
171
+ * Can be used with return values the have a toBytes method implemented
172
+ * For example:
173
+ * https://github.com/hashgraph/hedera-sdk-js/blob/c4438cbaa38074d8bfc934dba84e3b430344ed89/src/account/AccountInfo.js#L402
174
+ */
175
+ try {
176
+ const queryResult = await body.executeWithSigner(this.wallet);
177
+ let queryResponse = '';
178
+ if (Array.isArray(queryResult)) {
179
+ queryResponse = queryResult
180
+ .map((qr) => Uint8ArrayToBase64String(qr.toBytes()))
181
+ .join(',');
182
+ }
183
+ else {
184
+ queryResponse = Uint8ArrayToBase64String(queryResult.toBytes());
185
+ }
186
+ return formatJsonRpcResult(id, {
187
+ response: queryResponse,
188
+ });
189
+ }
190
+ catch (e) {
191
+ if (e instanceof PrecheckStatusError) {
192
+ // HIP-820 error format
193
+ return formatJsonRpcError(id, {
194
+ code: 9000,
195
+ message: e.message,
196
+ data: e.status._code.toString(),
197
+ });
198
+ }
199
+ return formatJsonRpcError(id, { code: 9000, message: 'Unknown Error' });
200
+ }
201
+ }
202
+ // 5. hedera_signAndExecuteTransaction
203
+ async hedera_signAndExecuteTransaction(id, transaction) {
204
+ // check transaction is incomplete (HIP-745)
205
+ if (!transaction.isFrozen()) {
206
+ // set multiple nodeAccountIds and transactionId if not present
207
+ await transaction.freezeWithSigner(this.wallet);
208
+ }
209
+ const signedTransaction = await transaction.signWithSigner(this.wallet);
210
+ try {
211
+ const response = await signedTransaction.executeWithSigner(this.wallet);
212
+ return formatJsonRpcResult(id, response.toJSON());
213
+ }
214
+ catch (e) {
215
+ if (e instanceof PrecheckStatusError) {
216
+ // HIP-820 error format
217
+ return formatJsonRpcError(id, {
218
+ code: 9000,
219
+ message: e.message,
220
+ data: e.status._code.toString(),
221
+ });
222
+ }
223
+ return formatJsonRpcError(id, { code: 9000, message: 'Unknown Error' });
224
+ }
225
+ }
226
+ // 6. hedera_signTransaction
227
+ async hedera_signTransaction(id, body) {
228
+ const signerSignatures = await this.wallet.sign([body]);
229
+ const _signatureMap = proto.SignatureMap.create(signerSignaturesToSignatureMap(signerSignatures));
230
+ const signatureMap = signatureMapToBase64String(_signatureMap);
231
+ return formatJsonRpcResult(id, {
232
+ signatureMap,
233
+ });
234
+ }
235
+ }
236
+ 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashgraph/hedera-wallet-connect",
3
- "version": "2.0.1-canary.7e04cff.0",
3
+ "version": "2.0.1-canary.8bde0e3.0",
4
4
  "description": "A library to facilitate integrating Hedera with WalletConnect",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,9 +14,11 @@
14
14
  "walletconnect",
15
15
  "reown",
16
16
  "hashgraph",
17
- "hbar",
18
17
  "evm",
19
- "smart contracts"
18
+ "ethereum",
19
+ "smart contracts",
20
+ "hbar",
21
+ "ethers"
20
22
  ],
21
23
  "license": "Apache-2.0",
22
24
  "scripts": {