@hashgraph/hedera-wallet-connect 1.3.2-0 → 1.3.2-1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. package/README.md +4 -4
  2. package/dist/src/index.d.ts +1 -0
  3. package/dist/src/index.js +20 -0
  4. package/dist/{types/src → src}/lib/dapp/DAppSigner.d.ts +0 -1
  5. package/dist/src/lib/dapp/DAppSigner.js +214 -0
  6. package/dist/{types/src → src}/lib/dapp/index.d.ts +0 -1
  7. package/dist/src/lib/dapp/index.js +431 -0
  8. package/dist/{types/src → src}/lib/index.d.ts +0 -1
  9. package/dist/src/lib/index.js +22 -0
  10. package/dist/{types/src → src}/lib/shared/chainIds.d.ts +0 -1
  11. package/dist/src/lib/shared/chainIds.js +31 -0
  12. package/dist/{types/src → src}/lib/shared/errors.d.ts +0 -1
  13. package/dist/src/lib/shared/errors.js +51 -0
  14. package/dist/{types/src → src}/lib/shared/events.d.ts +0 -1
  15. package/dist/src/lib/shared/events.js +27 -0
  16. package/dist/{types/src → src}/lib/shared/extensionController.d.ts +0 -1
  17. package/dist/src/lib/shared/extensionController.js +42 -0
  18. package/dist/{types/src → src}/lib/shared/index.d.ts +0 -1
  19. package/dist/src/lib/shared/index.js +26 -0
  20. package/dist/{types/src → src}/lib/shared/methods.d.ts +0 -1
  21. package/dist/src/lib/shared/methods.js +32 -0
  22. package/dist/{types/src → src}/lib/shared/payloads.d.ts +0 -1
  23. package/dist/src/lib/shared/payloads.js +20 -0
  24. package/dist/{types/src → src}/lib/shared/utils.d.ts +0 -1
  25. package/dist/src/lib/shared/utils.js +424 -0
  26. package/dist/{types/src → src}/lib/wallet/index.d.ts +0 -1
  27. package/dist/src/lib/wallet/index.js +301 -0
  28. package/dist/{types/src → src}/lib/wallet/provider.d.ts +0 -1
  29. package/dist/src/lib/wallet/provider.js +58 -0
  30. package/dist/{types/src → src}/lib/wallet/types.d.ts +0 -1
  31. package/dist/src/lib/wallet/types.js +20 -0
  32. package/dist/{types/test → test}/_helpers.d.ts +0 -1
  33. package/dist/test/_helpers.js +95 -0
  34. package/dist/test/dapp/DAppConnector.test.d.ts +1 -0
  35. package/dist/test/dapp/DAppConnector.test.js +236 -0
  36. package/dist/test/dapp/DAppSigner.test.d.ts +1 -0
  37. package/dist/test/dapp/DAppSigner.test.js +155 -0
  38. package/dist/test/utils.test.d.ts +1 -0
  39. package/dist/test/utils.test.js +202 -0
  40. package/dist/test/wallet/methods/wallet-executeTransaction.test.d.ts +1 -0
  41. package/dist/test/wallet/methods/wallet-executeTransaction.test.js +43 -0
  42. package/dist/test/wallet/methods/wallet-getNodeAddresses.test.d.ts +1 -0
  43. package/dist/test/wallet/methods/wallet-getNodeAddresses.test.js +40 -0
  44. package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.d.ts +1 -0
  45. package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.js +41 -0
  46. package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.d.ts +1 -0
  47. package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.js +48 -0
  48. package/dist/test/wallet/methods/wallet-signMessage.test.d.ts +1 -0
  49. package/dist/test/wallet/methods/wallet-signMessage.test.js +60 -0
  50. package/dist/test/wallet/methods/wallet-signTransaction.test.d.ts +1 -0
  51. package/dist/test/wallet/methods/wallet-signTransaction.test.js +45 -0
  52. package/dist/test/wallet/wallet-init.test.d.ts +1 -0
  53. package/dist/test/wallet/wallet-init.test.js +53 -0
  54. package/package.json +11 -19
  55. package/dist/browser-cjs-metafile.json +0 -1
  56. package/dist/browser-cjs.js +0 -250
  57. package/dist/browser-esm-metafile.json +0 -1
  58. package/dist/browser-esm.js +0 -250
  59. package/dist/node-cjs-metafile.json +0 -1
  60. package/dist/node-cjs.js +0 -11404
  61. package/dist/node-esm-metafile.json +0 -1
  62. package/dist/node-esm.js +0 -11404
  63. package/dist/types/src/index.d.ts +0 -2
  64. package/dist/types/src/index.d.ts.map +0 -1
  65. package/dist/types/src/lib/dapp/DAppSigner.d.ts.map +0 -1
  66. package/dist/types/src/lib/dapp/index.d.ts.map +0 -1
  67. package/dist/types/src/lib/index.d.ts.map +0 -1
  68. package/dist/types/src/lib/shared/chainIds.d.ts.map +0 -1
  69. package/dist/types/src/lib/shared/errors.d.ts.map +0 -1
  70. package/dist/types/src/lib/shared/events.d.ts.map +0 -1
  71. package/dist/types/src/lib/shared/extensionController.d.ts.map +0 -1
  72. package/dist/types/src/lib/shared/index.d.ts.map +0 -1
  73. package/dist/types/src/lib/shared/methods.d.ts.map +0 -1
  74. package/dist/types/src/lib/shared/payloads.d.ts.map +0 -1
  75. package/dist/types/src/lib/shared/utils.d.ts.map +0 -1
  76. package/dist/types/src/lib/wallet/index.d.ts.map +0 -1
  77. package/dist/types/src/lib/wallet/provider.d.ts.map +0 -1
  78. package/dist/types/src/lib/wallet/types.d.ts.map +0 -1
  79. package/dist/types/test/_helpers.d.ts.map +0 -1
  80. package/dist/types/test/dapp/DAppConnector.test.d.ts +0 -2
  81. package/dist/types/test/dapp/DAppConnector.test.d.ts.map +0 -1
  82. package/dist/types/test/dapp/DAppSigner.test.d.ts +0 -2
  83. package/dist/types/test/dapp/DAppSigner.test.d.ts.map +0 -1
  84. package/dist/types/test/utils.test.d.ts +0 -2
  85. package/dist/types/test/utils.test.d.ts.map +0 -1
  86. package/dist/types/test/wallet/methods/wallet-executeTransaction.test.d.ts +0 -2
  87. package/dist/types/test/wallet/methods/wallet-executeTransaction.test.d.ts.map +0 -1
  88. package/dist/types/test/wallet/methods/wallet-getNodeAddresses.test.d.ts +0 -2
  89. package/dist/types/test/wallet/methods/wallet-getNodeAddresses.test.d.ts.map +0 -1
  90. package/dist/types/test/wallet/methods/wallet-signAndExecuteQuery.test.d.ts +0 -2
  91. package/dist/types/test/wallet/methods/wallet-signAndExecuteQuery.test.d.ts.map +0 -1
  92. package/dist/types/test/wallet/methods/wallet-signAndExecuteTransaction.test.d.ts +0 -2
  93. package/dist/types/test/wallet/methods/wallet-signAndExecuteTransaction.test.d.ts.map +0 -1
  94. package/dist/types/test/wallet/methods/wallet-signMessage.test.d.ts +0 -2
  95. package/dist/types/test/wallet/methods/wallet-signMessage.test.d.ts.map +0 -1
  96. package/dist/types/test/wallet/methods/wallet-signTransaction.test.d.ts +0 -2
  97. package/dist/types/test/wallet/methods/wallet-signTransaction.test.d.ts.map +0 -1
  98. package/dist/types/test/wallet/wallet-init.test.d.ts +0 -2
  99. package/dist/types/test/wallet/wallet-init.test.d.ts.map +0 -1
@@ -0,0 +1,431 @@
1
+ /*
2
+ *
3
+ * Hedera Wallet Connect
4
+ *
5
+ * Copyright (C) 2023 Hedera Hashgraph, LLC
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ */
20
+ import { LedgerId } from '@hashgraph/sdk';
21
+ import QRCodeModal from '@walletconnect/qrcode-modal';
22
+ import { WalletConnectModal } from '@walletconnect/modal';
23
+ import SignClient from '@walletconnect/sign-client';
24
+ import { getSdkError } from '@walletconnect/utils';
25
+ import { HederaJsonRpcMethod, accountAndLedgerFromSession, networkNamespaces, extensionConnect, findExtensions, } from '../shared';
26
+ import { DAppSigner } from './DAppSigner';
27
+ export * from './DAppSigner';
28
+ export class DAppConnector {
29
+ /**
30
+ * Initializes the DAppConnector instance.
31
+ * @param metadata - SignClientTypes.Metadata object for the DApp metadata.
32
+ * @param network - LedgerId representing the network (default: LedgerId.TESTNET).
33
+ * @param projectId - Project ID for the WalletConnect client.
34
+ * @param methods - Array of supported methods for the DApp (optional).
35
+ * @param events - Array of supported events for the DApp (optional).
36
+ * @param chains - Array of supported chains for the DApp (optional).
37
+ */
38
+ constructor(metadata, network, projectId, methods, events, chains) {
39
+ this.network = LedgerId.TESTNET;
40
+ this.supportedMethods = [];
41
+ this.supportedEvents = [];
42
+ this.supportedChains = [];
43
+ this.extensions = [];
44
+ this.onSessionIframeCreated = null;
45
+ this.signers = [];
46
+ this.isInitializing = false;
47
+ this.abortableConnect = async (callback) => {
48
+ return new Promise(async (resolve, reject) => {
49
+ const pairTimeoutMs = 480000;
50
+ const timeout = setTimeout(() => {
51
+ QRCodeModal.close();
52
+ reject(new Error(`Connect timed out after ${pairTimeoutMs}(ms)`));
53
+ }, pairTimeoutMs);
54
+ try {
55
+ return resolve(await callback());
56
+ }
57
+ catch (error) {
58
+ reject(error);
59
+ }
60
+ finally {
61
+ clearTimeout(timeout);
62
+ }
63
+ });
64
+ };
65
+ this.dAppMetadata = metadata;
66
+ this.network = network;
67
+ this.projectId = projectId;
68
+ this.supportedMethods = methods !== null && methods !== void 0 ? methods : Object.values(HederaJsonRpcMethod);
69
+ this.supportedEvents = events !== null && events !== void 0 ? events : [];
70
+ this.supportedChains = chains !== null && chains !== void 0 ? chains : [];
71
+ this.extensions = [];
72
+ this.walletConnectModal = new WalletConnectModal({
73
+ projectId: projectId,
74
+ chains: chains,
75
+ });
76
+ findExtensions((metadata, isIframe) => {
77
+ this.extensions.push(Object.assign(Object.assign({}, metadata), { available: true, availableInIframe: isIframe }));
78
+ });
79
+ }
80
+ /**
81
+ * Initializes the DAppConnector instance.
82
+ * @param logger - `BaseLogger` for logging purposes (optional).
83
+ */
84
+ async init({ logger } = {}) {
85
+ try {
86
+ this.isInitializing = true;
87
+ if (!this.projectId) {
88
+ throw new Error('Project ID is not defined');
89
+ }
90
+ this.walletConnectClient = await SignClient.init({
91
+ logger,
92
+ relayUrl: 'wss://relay.walletconnect.com',
93
+ projectId: this.projectId,
94
+ metadata: this.dAppMetadata,
95
+ });
96
+ const existingSessions = this.walletConnectClient.session.getAll();
97
+ if (existingSessions.length > 0)
98
+ this.signers = existingSessions.flatMap((session) => this.createSigners(session));
99
+ else
100
+ this.checkIframeConnect();
101
+ this.walletConnectClient.on('session_event', (event) => {
102
+ // Handle session events, such as "chainChanged", "accountsChanged", etc.
103
+ console.log(event);
104
+ });
105
+ this.walletConnectClient.on('session_update', ({ topic, params }) => {
106
+ // Handle session update
107
+ const { namespaces } = params;
108
+ const _session = this.walletConnectClient.session.get(topic);
109
+ // Overwrite the `namespaces` of the existing session with the incoming one.
110
+ const updatedSession = Object.assign(Object.assign({}, _session), { namespaces });
111
+ // Integrate the updated session state into your dapp state.
112
+ console.log(updatedSession);
113
+ });
114
+ this.walletConnectClient.on('session_delete', (pairing) => {
115
+ console.log(pairing);
116
+ this.signers = this.signers.filter((signer) => signer.topic !== pairing.topic);
117
+ this.disconnect(pairing.topic);
118
+ // Session was deleted -> reset the dapp state, clean up from user session, etc.
119
+ console.log('Dapp: Session deleted by wallet!');
120
+ });
121
+ this.walletConnectClient.core.pairing.events.on('pairing_delete', (pairing) => {
122
+ // Session was deleted
123
+ console.log(pairing);
124
+ this.signers = this.signers.filter((signer) => signer.topic !== pairing.topic);
125
+ this.disconnect(pairing.topic);
126
+ console.log(`Dapp: Pairing deleted by wallet!`);
127
+ // clean up after the pairing for `topic` was deleted.
128
+ });
129
+ }
130
+ finally {
131
+ this.isInitializing = false;
132
+ }
133
+ }
134
+ getSigner(accountId) {
135
+ const signer = this.signers.find((signer) => signer.getAccountId().equals(accountId));
136
+ if (!signer)
137
+ throw new Error('Signer is not found for this accountId');
138
+ return signer;
139
+ }
140
+ /**
141
+ * Initiates the WalletConnect connection flow using a QR code.
142
+ * @param pairingTopic - The pairing topic for the connection (optional).
143
+ * @returns A Promise that resolves when the connection process is complete.
144
+ */
145
+ async connectQR(pairingTopic) {
146
+ return this.abortableConnect(async () => {
147
+ try {
148
+ const { uri, approval } = await this.connectURI(pairingTopic);
149
+ if (!uri)
150
+ throw new Error('URI is not defined');
151
+ QRCodeModal.open(uri, () => {
152
+ throw new Error('User rejected pairing');
153
+ });
154
+ await this.onSessionConnected(await approval());
155
+ }
156
+ finally {
157
+ QRCodeModal.close();
158
+ }
159
+ });
160
+ }
161
+ /**
162
+ * Initiates the WalletConnect connection flow using a QR code.
163
+ * @param pairingTopic - The pairing topic for the connection (optional).
164
+ * @returns {Promise<SessionTypes.Struct>} - A Promise that resolves when the connection process is complete.
165
+ */
166
+ async openModal(pairingTopic) {
167
+ try {
168
+ const { uri, approval } = await this.connectURI(pairingTopic);
169
+ this.walletConnectModal.openModal({ uri });
170
+ const session = await approval();
171
+ await this.onSessionConnected(session);
172
+ return session;
173
+ }
174
+ finally {
175
+ this.walletConnectModal.closeModal();
176
+ }
177
+ }
178
+ /**
179
+ * Initiates the WallecConnect connection flow using URI.
180
+ * @param pairingTopic - The pairing topic for the connection (optional).
181
+ * @param extensionId - The id for the extension used to connect (optional).
182
+ * @returns A Promise that resolves when the connection process is complete.
183
+ */
184
+ async connect(launchCallback, pairingTopic, extensionId) {
185
+ return this.abortableConnect(async () => {
186
+ var _a;
187
+ const { uri, approval } = await this.connectURI(pairingTopic);
188
+ if (!uri)
189
+ throw new Error('URI is not defined');
190
+ launchCallback(uri);
191
+ const session = await approval();
192
+ if (extensionId) {
193
+ const sessionProperties = Object.assign(Object.assign({}, session.sessionProperties), { extensionId });
194
+ session.sessionProperties = sessionProperties;
195
+ await ((_a = this.walletConnectClient) === null || _a === void 0 ? void 0 : _a.session.update(session.topic, {
196
+ sessionProperties,
197
+ }));
198
+ }
199
+ await this.onSessionConnected(session);
200
+ return session;
201
+ });
202
+ }
203
+ /**
204
+ * Initiates the WallecConnect connection flow sending a message to the extension.
205
+ * @param extensionId - The id for the extension used to connect.
206
+ * @param pairingTopic - The pairing topic for the connection (optional).
207
+ * @returns A Promise that resolves when the connection process is complete.
208
+ */
209
+ async connectExtension(extensionId, pairingTopic) {
210
+ const extension = this.extensions.find((ext) => ext.id === extensionId);
211
+ if (!extension || !extension.available)
212
+ throw new Error('Extension is not available');
213
+ return this.connect((uri) => {
214
+ extensionConnect(extension.id, extension.availableInIframe, uri);
215
+ }, pairingTopic, extension.availableInIframe ? undefined : extensionId);
216
+ }
217
+ /**
218
+ * Initiates the WallecConnect connection if the wallet in iframe mode is detected.
219
+ */
220
+ async checkIframeConnect() {
221
+ const extension = this.extensions.find((ext) => ext.availableInIframe);
222
+ if (extension) {
223
+ const session = await this.connectExtension(extension.id);
224
+ if (this.onSessionIframeCreated)
225
+ this.onSessionIframeCreated(session);
226
+ }
227
+ }
228
+ /**
229
+ * Disconnects the current session associated with the specified topic.
230
+ * @param topic - The topic of the session to disconnect.
231
+ * @returns A Promise that resolves when the session is disconnected.
232
+ */
233
+ async disconnect(topic) {
234
+ await this.walletConnectClient.disconnect({
235
+ topic: topic,
236
+ reason: getSdkError('USER_DISCONNECTED'),
237
+ });
238
+ }
239
+ /**
240
+ * Disconnects all active sessions and pairings.
241
+ *
242
+ * Throws error when WalletConnect is not initialized or there are no active sessions/pairings.
243
+ * @returns A Promise that resolves when all active sessions and pairings are disconnected.
244
+ */
245
+ async disconnectAll() {
246
+ if (!this.walletConnectClient) {
247
+ throw new Error('WalletConnect is not initialized');
248
+ }
249
+ const sessions = this.walletConnectClient.session.getAll();
250
+ const pairings = this.walletConnectClient.core.pairing.getPairings();
251
+ if (!(sessions === null || sessions === void 0 ? void 0 : sessions.length) && !(pairings === null || pairings === void 0 ? void 0 : pairings.length)) {
252
+ throw new Error('There is no active session/pairing. Connect to the wallet at first.');
253
+ }
254
+ const disconnectionPromises = [];
255
+ // disconnect sessions
256
+ for (const session of this.walletConnectClient.session.getAll()) {
257
+ console.log(`Disconnecting from session: ${session}`);
258
+ const promise = this.disconnect(session.topic);
259
+ disconnectionPromises.push(promise);
260
+ }
261
+ // disconnect pairings
262
+ //https://docs.walletconnect.com/api/core/pairing
263
+ for (const pairing of pairings) {
264
+ const promise = this.disconnect(pairing.topic);
265
+ disconnectionPromises.push(promise);
266
+ }
267
+ await Promise.all(disconnectionPromises);
268
+ this.signers = [];
269
+ }
270
+ createSigners(session) {
271
+ const allNamespaceAccounts = accountAndLedgerFromSession(session);
272
+ return allNamespaceAccounts.map(({ account, network }) => {
273
+ var _a;
274
+ return new DAppSigner(account, this.walletConnectClient, session.topic, network, (_a = session.sessionProperties) === null || _a === void 0 ? void 0 : _a.extensionId);
275
+ });
276
+ }
277
+ async onSessionConnected(session) {
278
+ this.signers.push(...this.createSigners(session));
279
+ }
280
+ async connectURI(pairingTopic) {
281
+ if (!this.walletConnectClient) {
282
+ throw new Error('WalletConnect is not initialized');
283
+ }
284
+ return this.walletConnectClient.connect({
285
+ pairingTopic,
286
+ requiredNamespaces: networkNamespaces(this.network, this.supportedMethods, this.supportedEvents),
287
+ });
288
+ }
289
+ async request({ method, params, }) {
290
+ const signer = this.signers[this.signers.length - 1];
291
+ if (!signer) {
292
+ throw new Error('There is no active session. Connect to the wallet at first.');
293
+ }
294
+ return await signer.request({
295
+ method: method,
296
+ params: params,
297
+ });
298
+ }
299
+ /**
300
+ * Retrieves the node addresses associated with the current Hedera network.
301
+ *
302
+ * When there is no active session or an error occurs during the request.
303
+ * @returns Promise\<{@link GetNodeAddressesResult}\>
304
+ */
305
+ async getNodeAddresses() {
306
+ return await this.request({
307
+ method: HederaJsonRpcMethod.GetNodeAddresses,
308
+ params: undefined,
309
+ });
310
+ }
311
+ /**
312
+ * Executes a transaction on the Hedera network.
313
+ *
314
+ * @param {ExecuteTransactionParams} params - The parameters of type {@link ExecuteTransactionParams | `ExecuteTransactionParams`} required for the transaction execution.
315
+ * @param {string[]} params.signedTransaction - Array of Base64-encoded `Transaction`'s
316
+ * @returns Promise\<{@link ExecuteTransactionResult}\>
317
+ * @example
318
+ * Use helper `transactionToBase64String` to encode `Transaction` to Base64 string
319
+ * ```ts
320
+ * const params = {
321
+ * signedTransaction: [transactionToBase64String(transaction)]
322
+ * }
323
+ *
324
+ * const result = await dAppConnector.executeTransaction(params)
325
+ * ```
326
+ */
327
+ async executeTransaction(params) {
328
+ return await this.request({
329
+ method: HederaJsonRpcMethod.ExecuteTransaction,
330
+ params,
331
+ });
332
+ }
333
+ /**
334
+ * Signs a provided `message` with provided `signerAccountId`.
335
+ *
336
+ * @param {SignMessageParams} params - The parameters of type {@link SignMessageParams | `SignMessageParams`} required for signing message.
337
+ * @param {string} params.signerAccountId - a signer Hedera Account identifier in {@link https://hips.hedera.com/hip/hip-30 | HIP-30} (`<nework>:<shard>.<realm>.<num>`) form.
338
+ * @param {string} params.message - a plain UTF-8 string
339
+ * @returns Promise\<{@link SignMessageResult}\>
340
+ * @example
341
+ * ```ts
342
+ * const params = {
343
+ * signerAccountId: '0.0.12345',
344
+ * message: 'Hello World!'
345
+ * }
346
+ *
347
+ * const result = await dAppConnector.signMessage(params)
348
+ * ```
349
+ */
350
+ async signMessage(params) {
351
+ return await this.request({
352
+ method: HederaJsonRpcMethod.SignMessage,
353
+ params,
354
+ });
355
+ }
356
+ /**
357
+ * Signs and send `Query` on the Hedera network.
358
+ *
359
+ * @param {SignAndExecuteQueryParams} params - The parameters of type {@link SignAndExecuteQueryParams | `SignAndExecuteQueryParams`} required for the Query execution.
360
+ * @param {string} params.signerAccountId - a signer Hedera Account identifier in {@link https://hips.hedera.com/hip/hip-30 | HIP-30} (`<nework>:<shard>.<realm>.<num>`) form.
361
+ * @param {string} params.query - `Query` object represented as Base64 string
362
+ * @returns Promise\<{@link SignAndExecuteQueryResult}\>
363
+ * @example
364
+ * Use helper `queryToBase64String` to encode `Query` to Base64 string
365
+ * ```ts
366
+ * const params = {
367
+ * signerAccountId: '0.0.12345',
368
+ * query: queryToBase64String(query),
369
+ * }
370
+ *
371
+ * const result = await dAppConnector.signAndExecuteQuery(params)
372
+ * ```
373
+ */
374
+ async signAndExecuteQuery(params) {
375
+ return await this.request({
376
+ method: HederaJsonRpcMethod.SignAndExecuteQuery,
377
+ params,
378
+ });
379
+ }
380
+ /**
381
+ * Signs and executes Transactions on the Hedera network.
382
+ *
383
+ * @param {SignAndExecuteTransactionParams} params - The parameters of type {@link SignAndExecuteTransactionParams | `SignAndExecuteTransactionParams`} required for `Transaction` signing and execution.
384
+ * @param {string} params.signerAccountId - a signer Hedera Account identifier in {@link https://hips.hedera.com/hip/hip-30 | HIP-30} (`<nework>:<shard>.<realm>.<num>`) form.
385
+ * @param {string[]} params.transaction - Array of Base64-encoded `Transaction`'s
386
+ * @returns Promise\<{@link SignAndExecuteTransactionResult}\>
387
+ * @example
388
+ * Use helper `transactionToBase64String` to encode `Transaction` to Base64 string
389
+ * ```ts
390
+ * const params = {
391
+ * signerAccountId: '0.0.12345'
392
+ * transaction: [transactionToBase64String(transaction)]
393
+ * }
394
+ *
395
+ * const result = await dAppConnector.signAndExecuteTransaction(params)
396
+ * ```
397
+ */
398
+ async signAndExecuteTransaction(params) {
399
+ return await this.request({
400
+ method: HederaJsonRpcMethod.SignAndExecuteTransaction,
401
+ params,
402
+ });
403
+ }
404
+ /**
405
+ * Signs and executes Transactions on the Hedera network.
406
+ *
407
+ * @param {SignTransactionParams} params - The parameters of type {@link SignTransactionParams | `SignTransactionParams`} required for `Transaction` signing.
408
+ * @param {string} params.signerAccountId - a signer Hedera Account identifier in {@link https://hips.hedera.com/hip/hip-30 | HIP-30} (`<nework>:<shard>.<realm>.<num>`) form.
409
+ * @param {string[]} params.transaction - Array of Base64-encoded `Transaction`'s
410
+ * @returns Promise\<{@link SignTransactionResult}\>
411
+ * @example
412
+ * ```ts
413
+ * const transactionBodyObject = transactionToTransactionBody(transaction, AccountId.fromString('0.0.3'))
414
+ * const transactionBody = transactionBodyToBase64String(transactionBodyObject)
415
+ *
416
+ * const params = {
417
+ * signerAccountId: '0.0.12345',
418
+ * transactionBody
419
+ * }
420
+ *
421
+ * const result = await dAppConnector.signTransaction(params)
422
+ * ```
423
+ */
424
+ async signTransaction(params) {
425
+ return await this.request({
426
+ method: HederaJsonRpcMethod.SignTransaction,
427
+ params,
428
+ });
429
+ }
430
+ }
431
+ export default DAppConnector;
@@ -1,4 +1,3 @@
1
1
  export * from './shared';
2
2
  export { default as Wallet } from './wallet';
3
3
  export * from './dapp';
4
- //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,22 @@
1
+ /*
2
+ *
3
+ * Hedera Wallet Connect
4
+ *
5
+ * Copyright (C) 2023 Hedera Hashgraph, LLC
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ */
20
+ export * from './shared';
21
+ export { default as Wallet } from './wallet';
22
+ export * from './dapp';
@@ -9,4 +9,3 @@ export declare enum HederaChainId {
9
9
  Previewnet = "hedera:previewnet",
10
10
  Devnet = "hedera:devnet"
11
11
  }
12
- //# sourceMappingURL=chainIds.d.ts.map
@@ -0,0 +1,31 @@
1
+ /*
2
+ *
3
+ * Hedera Wallet Connect
4
+ *
5
+ * Copyright (C) 2023 Hedera Hashgraph, LLC
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ */
20
+ /**
21
+ * Enum representing different Hedera network chain IDs.
22
+ *
23
+ * @see {@link https://github.com/hashgraph/hedera-improvement-proposal/blob/main/HIP/hip-820.md#specification | HIP-820 Specification}
24
+ */
25
+ export var HederaChainId;
26
+ (function (HederaChainId) {
27
+ HederaChainId["Mainnet"] = "hedera:mainnet";
28
+ HederaChainId["Testnet"] = "hedera:testnet";
29
+ HederaChainId["Previewnet"] = "hedera:previewnet";
30
+ HederaChainId["Devnet"] = "hedera:devnet";
31
+ })(HederaChainId || (HederaChainId = {}));
@@ -46,4 +46,3 @@ export interface HederaJsonRpcError<T = string | number> {
46
46
  * @returns A HederaErrorResponse object with the specified code, message, and additional data.
47
47
  */
48
48
  export declare function getHederaError<T>(key: string, context?: string | number, data?: T): HederaErrorResponse<T>;
49
- //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,51 @@
1
+ /*
2
+ *
3
+ * Hedera Wallet Connect
4
+ *
5
+ * Copyright (C) 2023 Hedera Hashgraph, LLC
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ */
20
+ /**
21
+ * WalletConnect has certain
22
+ * {@link https://github.com/WalletConnect/walletconnect-monorepo/blob/v2.0/packages/utils/src/errors.ts | error code ranges reserved}
23
+ * for WalletConnect use.
24
+ * The following schema uses negative codes to avoid conflicts.
25
+ *
26
+ * @see {@link https://github.com/WalletConnect/walletconnect-monorepo/blob/v2.0/packages/utils/src/errors.ts | WalletConnect Errors}
27
+ */
28
+ /**
29
+ * Object containing specific Hedera errors with their respective codes and messages.
30
+ */
31
+ export const HEDERA_ERRORS = {
32
+ INVALID_PARAMS: {
33
+ code: 9000,
34
+ message: 'INVALID_PARAMS',
35
+ },
36
+ };
37
+ /**
38
+ * Generates a Hedera error response based on the provided key, context, and additional data.
39
+ * @param key - Key representing the specific error type.
40
+ * @param context - Contextual information for the error (optional).
41
+ * @param data - Additional data to include in the error response (optional).
42
+ * @returns A HederaErrorResponse object with the specified code, message, and additional data.
43
+ */
44
+ export function getHederaError(key, context, data) {
45
+ const { code, message } = HEDERA_ERRORS[key];
46
+ return {
47
+ code,
48
+ message: context ? `${message} ${context}` : message,
49
+ data,
50
+ };
51
+ }
@@ -5,4 +5,3 @@ export declare enum HederaSessionEvent {
5
5
  AccountsChanged = "accountsChanged",
6
6
  ChainChanged = "chainChanged"
7
7
  }
8
- //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1,27 @@
1
+ /*
2
+ *
3
+ * Hedera Wallet Connect
4
+ *
5
+ * Copyright (C) 2023 Hedera Hashgraph, LLC
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ */
20
+ /**
21
+ * Represents different events related to a Hedera session.
22
+ */
23
+ export var HederaSessionEvent;
24
+ (function (HederaSessionEvent) {
25
+ HederaSessionEvent["AccountsChanged"] = "accountsChanged";
26
+ HederaSessionEvent["ChainChanged"] = "chainChanged";
27
+ })(HederaSessionEvent || (HederaSessionEvent = {}));
@@ -19,4 +19,3 @@ export declare const findExtensions: (onFound: (_metadata: ExtensionData, isIfra
19
19
  export declare const extensionQuery: () => void;
20
20
  export declare const extensionConnect: (id: string, isIframe: boolean, pairingString: string) => void;
21
21
  export declare const extensionOpen: (id: string) => void;
22
- //# sourceMappingURL=extensionController.d.ts.map
@@ -0,0 +1,42 @@
1
+ export var EVENTS;
2
+ (function (EVENTS) {
3
+ EVENTS["extensionQuery"] = "hedera-extension-query";
4
+ EVENTS["extensionConnect"] = "hedera-extension-connect-";
5
+ EVENTS["extensionOpen"] = "hedera-extension-open-";
6
+ EVENTS["extensionResponse"] = "hedera-extension-response";
7
+ EVENTS["iframeQuery"] = "hedera-iframe-query";
8
+ EVENTS["iframeQueryResponse"] = "hedera-iframe-response";
9
+ EVENTS["iframeConnect"] = "hedera-iframe-connect";
10
+ })(EVENTS || (EVENTS = {}));
11
+ export const findExtensions = (onFound) => {
12
+ if (typeof window === 'undefined')
13
+ return;
14
+ window.addEventListener('message', (event) => {
15
+ var _a, _b;
16
+ if (((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.type) == EVENTS.extensionResponse && event.data.metadata) {
17
+ onFound(event.data.metadata, false);
18
+ }
19
+ if (((_b = event === null || event === void 0 ? void 0 : event.data) === null || _b === void 0 ? void 0 : _b.type) == EVENTS.iframeQueryResponse && event.data.metadata) {
20
+ onFound(event.data.metadata, true);
21
+ }
22
+ });
23
+ setTimeout(() => {
24
+ extensionQuery();
25
+ }, 200);
26
+ };
27
+ export const extensionQuery = () => {
28
+ window.postMessage({ type: EVENTS.extensionQuery }, '*');
29
+ if (window.parent) {
30
+ window.parent.postMessage({ type: EVENTS.iframeQuery }, '*');
31
+ }
32
+ };
33
+ export const extensionConnect = (id, isIframe, pairingString) => {
34
+ if (isIframe) {
35
+ window.parent.postMessage({ type: EVENTS.iframeConnect, pairingString }, '*');
36
+ return;
37
+ }
38
+ window.postMessage({ type: EVENTS.extensionConnect + id, pairingString }, '*');
39
+ };
40
+ export const extensionOpen = (id) => {
41
+ window.postMessage({ type: EVENTS.extensionOpen + id }, '*');
42
+ };
@@ -5,4 +5,3 @@ export * from './methods';
5
5
  export * from './payloads';
6
6
  export * from './utils';
7
7
  export * from './extensionController';
8
- //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,26 @@
1
+ /*
2
+ *
3
+ * Hedera Wallet Connect
4
+ *
5
+ * Copyright (C) 2023 Hedera Hashgraph, LLC
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ */
20
+ export * from './chainIds';
21
+ export * from './errors';
22
+ export * from './events';
23
+ export * from './methods';
24
+ export * from './payloads';
25
+ export * from './utils';
26
+ export * from './extensionController';
@@ -10,4 +10,3 @@ export declare enum HederaJsonRpcMethod {
10
10
  SignAndExecuteTransaction = "hedera_signAndExecuteTransaction",// 5
11
11
  SignTransaction = "hedera_signTransaction"
12
12
  }
13
- //# sourceMappingURL=methods.d.ts.map