@hashgraph/hedera-wallet-connect 2.0.4 → 2.0.5-canary.09073be.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/package.json +1 -1
  2. package/dist/index.d.ts +0 -2
  3. package/dist/index.js +0 -21
  4. package/dist/lib/dapp/DAppSigner.d.ts +0 -60
  5. package/dist/lib/dapp/DAppSigner.js +0 -344
  6. package/dist/lib/dapp/SessionNotFoundError.d.ts +0 -3
  7. package/dist/lib/dapp/SessionNotFoundError.js +0 -6
  8. package/dist/lib/dapp/index.d.ts +0 -216
  9. package/dist/lib/dapp/index.js +0 -588
  10. package/dist/lib/index.d.ts +0 -3
  11. package/dist/lib/index.js +0 -22
  12. package/dist/lib/shared/chainIds.d.ts +0 -11
  13. package/dist/lib/shared/chainIds.js +0 -31
  14. package/dist/lib/shared/errors.d.ts +0 -48
  15. package/dist/lib/shared/errors.js +0 -51
  16. package/dist/lib/shared/events.d.ts +0 -7
  17. package/dist/lib/shared/events.js +0 -27
  18. package/dist/lib/shared/extensionController.d.ts +0 -21
  19. package/dist/lib/shared/extensionController.js +0 -42
  20. package/dist/lib/shared/index.d.ts +0 -7
  21. package/dist/lib/shared/index.js +0 -26
  22. package/dist/lib/shared/logger.d.ts +0 -21
  23. package/dist/lib/shared/logger.js +0 -63
  24. package/dist/lib/shared/methods.d.ts +0 -12
  25. package/dist/lib/shared/methods.js +0 -32
  26. package/dist/lib/shared/payloads.d.ts +0 -101
  27. package/dist/lib/shared/payloads.js +0 -20
  28. package/dist/lib/shared/utils.d.ts +0 -280
  29. package/dist/lib/shared/utils.js +0 -461
  30. package/dist/lib/wallet/index.d.ts +0 -39
  31. package/dist/lib/wallet/index.js +0 -306
  32. package/dist/lib/wallet/provider.d.ts +0 -17
  33. package/dist/lib/wallet/provider.js +0 -58
  34. package/dist/lib/wallet/types.d.ts +0 -31
  35. package/dist/lib/wallet/types.js +0 -20
  36. package/dist/reown/adapter.d.ts +0 -59
  37. package/dist/reown/adapter.js +0 -290
  38. package/dist/reown/connectors/HederaConnector.d.ts +0 -29
  39. package/dist/reown/connectors/HederaConnector.js +0 -32
  40. package/dist/reown/connectors/index.d.ts +0 -1
  41. package/dist/reown/connectors/index.js +0 -1
  42. package/dist/reown/index.d.ts +0 -4
  43. package/dist/reown/index.js +0 -4
  44. package/dist/reown/providers/EIP155Provider.d.ts +0 -33
  45. package/dist/reown/providers/EIP155Provider.js +0 -187
  46. package/dist/reown/providers/HIP820Provider.d.ts +0 -26
  47. package/dist/reown/providers/HIP820Provider.js +0 -67
  48. package/dist/reown/providers/HederaProvider.d.ts +0 -166
  49. package/dist/reown/providers/HederaProvider.js +0 -506
  50. package/dist/reown/providers/index.d.ts +0 -3
  51. package/dist/reown/providers/index.js +0 -3
  52. package/dist/reown/utils/account.d.ts +0 -2
  53. package/dist/reown/utils/account.js +0 -41
  54. package/dist/reown/utils/chains.d.ts +0 -18
  55. package/dist/reown/utils/chains.js +0 -152
  56. package/dist/reown/utils/constants.d.ts +0 -16
  57. package/dist/reown/utils/constants.js +0 -18
  58. package/dist/reown/utils/helpers.d.ts +0 -12
  59. package/dist/reown/utils/helpers.js +0 -25
  60. package/dist/reown/utils/index.d.ts +0 -5
  61. package/dist/reown/utils/index.js +0 -5
  62. package/dist/reown/utils/types.d.ts +0 -9
  63. package/dist/reown/utils/types.js +0 -1
  64. package/dist/reown/wallets/EIP155Wallet.d.ts +0 -46
  65. package/dist/reown/wallets/EIP155Wallet.js +0 -124
  66. package/dist/reown/wallets/HIP820Wallet.d.ts +0 -53
  67. package/dist/reown/wallets/HIP820Wallet.js +0 -236
  68. package/dist/reown/wallets/index.d.ts +0 -2
  69. package/dist/reown/wallets/index.js +0 -2
@@ -1,236 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- export * from './EIP155Wallet';
2
- export * from './HIP820Wallet';
@@ -1,2 +0,0 @@
1
- export * from './EIP155Wallet';
2
- export * from './HIP820Wallet';