@hashgraph/hedera-wallet-connect 2.0.1-canary.3ca89d4.0 → 2.0.1-canary.45f4fe0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +16 -16
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -1
  4. package/dist/lib/dapp/DAppSigner.d.ts +0 -2
  5. package/dist/lib/dapp/DAppSigner.js +2 -16
  6. package/dist/lib/dapp/index.d.ts +5 -7
  7. package/dist/lib/dapp/index.js +4 -36
  8. package/dist/lib/shared/index.d.ts +0 -2
  9. package/dist/lib/shared/index.js +0 -2
  10. package/dist/lib/shared/payloads.d.ts +1 -1
  11. package/dist/lib/shared/utils.d.ts +3 -2
  12. package/dist/lib/shared/utils.js +4 -3
  13. package/package.json +10 -11
  14. package/dist/lib/shared/accountInfo.d.ts +0 -30
  15. package/dist/lib/shared/accountInfo.js +0 -1
  16. package/dist/lib/shared/mirrorNode.d.ts +0 -3
  17. package/dist/lib/shared/mirrorNode.js +0 -17
  18. package/dist/reown/adapter.d.ts +0 -37
  19. package/dist/reown/adapter.js +0 -255
  20. package/dist/reown/connectors/HederaConnector.d.ts +0 -29
  21. package/dist/reown/connectors/HederaConnector.js +0 -35
  22. package/dist/reown/connectors/index.d.ts +0 -1
  23. package/dist/reown/connectors/index.js +0 -1
  24. package/dist/reown/index.d.ts +0 -4
  25. package/dist/reown/index.js +0 -4
  26. package/dist/reown/providers/EIP155Provider.d.ts +0 -33
  27. package/dist/reown/providers/EIP155Provider.js +0 -187
  28. package/dist/reown/providers/HIP820Provider.d.ts +0 -26
  29. package/dist/reown/providers/HIP820Provider.js +0 -69
  30. package/dist/reown/providers/HederaProvider.d.ts +0 -164
  31. package/dist/reown/providers/HederaProvider.js +0 -471
  32. package/dist/reown/providers/index.d.ts +0 -3
  33. package/dist/reown/providers/index.js +0 -3
  34. package/dist/reown/utils/chains.d.ts +0 -18
  35. package/dist/reown/utils/chains.js +0 -152
  36. package/dist/reown/utils/constants.d.ts +0 -16
  37. package/dist/reown/utils/constants.js +0 -18
  38. package/dist/reown/utils/helpers.d.ts +0 -12
  39. package/dist/reown/utils/helpers.js +0 -25
  40. package/dist/reown/utils/index.d.ts +0 -4
  41. package/dist/reown/utils/index.js +0 -4
  42. package/dist/reown/utils/types.d.ts +0 -9
  43. package/dist/reown/utils/types.js +0 -1
  44. package/dist/reown/wallets/EIP155Wallet.d.ts +0 -46
  45. package/dist/reown/wallets/EIP155Wallet.js +0 -136
  46. package/dist/reown/wallets/HIP820Wallet.d.ts +0 -53
  47. package/dist/reown/wallets/HIP820Wallet.js +0 -239
  48. package/dist/reown/wallets/index.d.ts +0 -2
  49. package/dist/reown/wallets/index.js +0 -2
@@ -1,239 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- export * from './EIP155Wallet';
2
- export * from './HIP820Wallet';
@@ -1,2 +0,0 @@
1
- export * from './EIP155Wallet';
2
- export * from './HIP820Wallet';