@hashgraph/hedera-wallet-connect 1.3.7-canary.de9fb58.0 → 1.3.8-canary.304c0c2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. package/dist/{src/lib → lib}/dapp/DAppSigner.d.ts +18 -2
  2. package/dist/{src/lib → lib}/dapp/DAppSigner.js +109 -30
  3. package/dist/{src/lib → lib}/dapp/index.d.ts +4 -0
  4. package/dist/{src/lib → lib}/dapp/index.js +39 -40
  5. package/dist/{src/lib → lib}/shared/logger.d.ts +1 -0
  6. package/dist/{src/lib → lib}/shared/logger.js +3 -0
  7. package/dist/{src/lib → lib}/shared/utils.d.ts +8 -2
  8. package/dist/{src/lib → lib}/shared/utils.js +10 -2
  9. package/package.json +4 -3
  10. package/dist/test/_helpers.d.ts +0 -38
  11. package/dist/test/_helpers.js +0 -95
  12. package/dist/test/dapp/DAppConnector.test.d.ts +0 -1
  13. package/dist/test/dapp/DAppConnector.test.js +0 -232
  14. package/dist/test/dapp/DAppSigner.test.d.ts +0 -1
  15. package/dist/test/dapp/DAppSigner.test.js +0 -625
  16. package/dist/test/shared/logger.test.d.ts +0 -1
  17. package/dist/test/shared/logger.test.js +0 -129
  18. package/dist/test/utils.test.d.ts +0 -1
  19. package/dist/test/utils.test.js +0 -201
  20. package/dist/test/wallet/methods/wallet-executeTransaction.test.d.ts +0 -1
  21. package/dist/test/wallet/methods/wallet-executeTransaction.test.js +0 -43
  22. package/dist/test/wallet/methods/wallet-getNodeAddresses.test.d.ts +0 -1
  23. package/dist/test/wallet/methods/wallet-getNodeAddresses.test.js +0 -40
  24. package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.d.ts +0 -1
  25. package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.js +0 -41
  26. package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.d.ts +0 -1
  27. package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.js +0 -48
  28. package/dist/test/wallet/methods/wallet-signMessage.test.d.ts +0 -1
  29. package/dist/test/wallet/methods/wallet-signMessage.test.js +0 -60
  30. package/dist/test/wallet/methods/wallet-signTransaction.test.d.ts +0 -1
  31. package/dist/test/wallet/methods/wallet-signTransaction.test.js +0 -47
  32. package/dist/test/wallet/wallet-init.test.d.ts +0 -1
  33. package/dist/test/wallet/wallet-init.test.js +0 -53
  34. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  35. /package/dist/{src/index.js → index.js} +0 -0
  36. /package/dist/{src/lib → lib}/index.d.ts +0 -0
  37. /package/dist/{src/lib → lib}/index.js +0 -0
  38. /package/dist/{src/lib → lib}/shared/chainIds.d.ts +0 -0
  39. /package/dist/{src/lib → lib}/shared/chainIds.js +0 -0
  40. /package/dist/{src/lib → lib}/shared/errors.d.ts +0 -0
  41. /package/dist/{src/lib → lib}/shared/errors.js +0 -0
  42. /package/dist/{src/lib → lib}/shared/events.d.ts +0 -0
  43. /package/dist/{src/lib → lib}/shared/events.js +0 -0
  44. /package/dist/{src/lib → lib}/shared/extensionController.d.ts +0 -0
  45. /package/dist/{src/lib → lib}/shared/extensionController.js +0 -0
  46. /package/dist/{src/lib → lib}/shared/index.d.ts +0 -0
  47. /package/dist/{src/lib → lib}/shared/index.js +0 -0
  48. /package/dist/{src/lib → lib}/shared/methods.d.ts +0 -0
  49. /package/dist/{src/lib → lib}/shared/methods.js +0 -0
  50. /package/dist/{src/lib → lib}/shared/payloads.d.ts +0 -0
  51. /package/dist/{src/lib → lib}/shared/payloads.js +0 -0
  52. /package/dist/{src/lib → lib}/wallet/index.d.ts +0 -0
  53. /package/dist/{src/lib → lib}/wallet/index.js +0 -0
  54. /package/dist/{src/lib → lib}/wallet/provider.d.ts +0 -0
  55. /package/dist/{src/lib → lib}/wallet/provider.js +0 -0
  56. /package/dist/{src/lib → lib}/wallet/types.d.ts +0 -0
  57. /package/dist/{src/lib → lib}/wallet/types.js +0 -0
@@ -1,232 +0,0 @@
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 { AccountId, AccountInfoQuery, LedgerId, TopicCreateTransaction } from '@hashgraph/sdk';
21
- import { DAppConnector, HederaJsonRpcMethod, HederaSessionEvent, queryToBase64String, transactionToBase64String, transactionToTransactionBody, transactionBodyToBase64String, DAppSigner, } from '../../src';
22
- import { projectId, dAppMetadata, useJsonFixture, prepareTestTransaction, testUserAccountId, } from '../_helpers';
23
- import Client, { SignClient } from '@walletconnect/sign-client';
24
- describe('DAppConnector', () => {
25
- let connector;
26
- const fakeSession = useJsonFixture('fakeSession');
27
- beforeEach(() => {
28
- connector = new DAppConnector(dAppMetadata, LedgerId.TESTNET, projectId);
29
- });
30
- afterEach(() => {
31
- global.gc && global.gc();
32
- });
33
- describe('constructor', () => {
34
- it('should create a valid class object', () => {
35
- const methods = ['hedera_testMethod', 'any_testMethod'];
36
- const events = [HederaSessionEvent.ChainChanged, HederaSessionEvent.AccountsChanged];
37
- connector = new DAppConnector(dAppMetadata, LedgerId.TESTNET, projectId, methods, events);
38
- expect(connector.dAppMetadata).toBe(dAppMetadata);
39
- expect(connector.network).toBe(LedgerId.TESTNET);
40
- expect(connector.projectId).toBe(projectId);
41
- expect(connector.supportedMethods).toEqual(methods);
42
- expect(connector.supportedEvents).toEqual(events);
43
- });
44
- it('should create a valid class object without passing of methods and events', () => {
45
- connector = new DAppConnector(dAppMetadata, LedgerId.TESTNET, projectId);
46
- expect(connector.dAppMetadata).toBe(dAppMetadata);
47
- expect(connector.network).toBe(LedgerId.TESTNET);
48
- expect(connector.projectId).toBe(projectId);
49
- expect(connector.supportedMethods).toEqual(Object.values(HederaJsonRpcMethod));
50
- expect(connector.supportedEvents).toEqual([]);
51
- });
52
- });
53
- describe('init', () => {
54
- it('should init SignClient correctly', async () => {
55
- var _a, _b, _c;
56
- await connector.init({ logger: 'error' });
57
- expect(connector.walletConnectClient).toBeInstanceOf(Client);
58
- expect((_a = connector.walletConnectClient) === null || _a === void 0 ? void 0 : _a.metadata).toBe(dAppMetadata);
59
- expect((_b = connector.walletConnectClient) === null || _b === void 0 ? void 0 : _b.core.projectId).toBe(projectId);
60
- expect((_c = connector.walletConnectClient) === null || _c === void 0 ? void 0 : _c.core.relayUrl).toBe('wss://relay.walletconnect.com');
61
- });
62
- it('should create signers if there are persisted sessions', async () => {
63
- const mockInit = jest.spyOn(connector, 'init');
64
- const mockSignClient = new SignClient({
65
- logger: 'error',
66
- relayUrl: 'wss://relay.walletconnect.com',
67
- projectId: projectId,
68
- metadata: dAppMetadata,
69
- });
70
- mockInit.mockImplementation(async () => {
71
- connector.signers = [
72
- new DAppSigner(testUserAccountId, mockSignClient, fakeSession.topic, LedgerId.TESTNET),
73
- ];
74
- });
75
- await connector.init({ logger: 'error' });
76
- expect(connector.signers.length).toBeGreaterThan(0);
77
- mockInit.mockRestore();
78
- });
79
- });
80
- describe('disconnect', () => {
81
- it('should disconnect Client from topic', async () => {
82
- connector.walletConnectClient = new SignClient({
83
- logger: 'error',
84
- relayUrl: 'wss://relay.walletconnect.com',
85
- projectId: projectId,
86
- metadata: dAppMetadata,
87
- });
88
- const walletConnectDisconnectSpy = jest.spyOn(connector.walletConnectClient, 'disconnect');
89
- walletConnectDisconnectSpy.mockImplementation(async () => { });
90
- connector.disconnect(fakeSession.topic);
91
- expect(walletConnectDisconnectSpy).toHaveBeenCalled();
92
- expect(walletConnectDisconnectSpy).toHaveBeenCalledTimes(1);
93
- expect(walletConnectDisconnectSpy).toHaveBeenCalledWith(expect.objectContaining({ topic: fakeSession.topic }));
94
- walletConnectDisconnectSpy.mockRestore();
95
- });
96
- });
97
- describe('requests', () => {
98
- let lastSignerRequestMock;
99
- // @ts-ignore
100
- let mockSignClient;
101
- beforeEach(async () => {
102
- mockSignClient = new SignClient({
103
- logger: 'error',
104
- relayUrl: 'wss://relay.walletconnect.com',
105
- projectId: projectId,
106
- metadata: dAppMetadata,
107
- });
108
- connector.signers = [
109
- new DAppSigner(testUserAccountId, mockSignClient, fakeSession.topic, LedgerId.TESTNET),
110
- ];
111
- lastSignerRequestMock = jest.spyOn(connector.signers[0], 'request');
112
- lastSignerRequestMock.mockImplementation(() => { });
113
- });
114
- afterEach(() => {
115
- if (lastSignerRequestMock) {
116
- lastSignerRequestMock.mockRestore();
117
- }
118
- });
119
- describe('getNodeAddresses', () => {
120
- it('should throw an error if there is no active signer', async () => {
121
- connector.signers = [];
122
- await expect(connector.getNodeAddresses()).rejects.toThrow('There is no active session. Connect to the wallet at first.');
123
- });
124
- it('should invoke last signer request with correct params', async () => {
125
- await connector.getNodeAddresses();
126
- expect(lastSignerRequestMock).toHaveBeenCalledWith({
127
- method: HederaJsonRpcMethod.GetNodeAddresses,
128
- params: undefined,
129
- });
130
- });
131
- });
132
- describe('signMessage', () => {
133
- const params = {
134
- message: 'test message',
135
- signerAccountId: `hedera:testnet:${testUserAccountId.toString()}`,
136
- };
137
- it('should throw an error if there are no signers', async () => {
138
- connector.signers = [];
139
- await expect(connector.signMessage(params)).rejects.toThrow('Signer not found for account ID: hedera:testnet:0.0.12345. Did you use the correct format? e.g hedera:<network>:<address>');
140
- });
141
- it('should invoke last signer request with correct params', async () => {
142
- await connector.signMessage(params);
143
- expect(lastSignerRequestMock).toHaveBeenCalledWith({
144
- method: HederaJsonRpcMethod.SignMessage,
145
- params,
146
- });
147
- });
148
- });
149
- describe('executeTransaction', () => {
150
- const transaction = prepareTestTransaction(new TopicCreateTransaction(), { freeze: true });
151
- const params = {
152
- transactionList: transactionToBase64String(transaction),
153
- };
154
- it('should throw an error if there are no signers', async () => {
155
- connector.signers = [];
156
- await expect(connector.executeTransaction(params)).rejects.toThrow('There is no active session. Connect to the wallet at first.');
157
- });
158
- it('should invoke last signer request with correct params', async () => {
159
- await connector.executeTransaction(params);
160
- expect(lastSignerRequestMock).toHaveBeenCalledWith({
161
- method: HederaJsonRpcMethod.ExecuteTransaction,
162
- params,
163
- });
164
- });
165
- });
166
- describe('signAndExecuteQuery', () => {
167
- const query = new AccountInfoQuery().setAccountId(testUserAccountId.toString());
168
- const params = {
169
- signerAccountId: testUserAccountId.toString(),
170
- query: queryToBase64String(query),
171
- };
172
- it('should throw an error if there is no any signer', async () => {
173
- connector.signers = [];
174
- await expect(connector.signAndExecuteQuery(params)).rejects.toThrow('Signer not found for account ID: 0.0.12345. Did you use the correct format? e.g hedera:<network>:<address>');
175
- });
176
- it('should invoke last signer request with correct params', async () => {
177
- await connector.signAndExecuteQuery(params);
178
- expect(lastSignerRequestMock).toHaveBeenCalledWith({
179
- method: HederaJsonRpcMethod.SignAndExecuteQuery,
180
- params,
181
- });
182
- });
183
- });
184
- describe('signAndExecuteTransaction', () => {
185
- const transaction = prepareTestTransaction(new TopicCreateTransaction(), { freeze: true });
186
- const params = {
187
- signerAccountId: testUserAccountId.toString(),
188
- transactionList: transactionToBase64String(transaction),
189
- };
190
- it('should throw an error if there is no any signer', async () => {
191
- connector.signers = [];
192
- await expect(connector.signAndExecuteTransaction(params)).rejects.toThrow('Signer not found for account ID: 0.0.12345. Did you use the correct format? e.g hedera:<network>:<address>');
193
- });
194
- it('should invoke last signer request with correct params', async () => {
195
- await connector.signAndExecuteTransaction(params);
196
- expect(lastSignerRequestMock).toHaveBeenCalledWith({
197
- method: HederaJsonRpcMethod.SignAndExecuteTransaction,
198
- params,
199
- });
200
- });
201
- });
202
- describe('signTransaction', () => {
203
- const transaction = prepareTestTransaction(new TopicCreateTransaction(), { freeze: true });
204
- const params = {
205
- signerAccountId: testUserAccountId.toString(),
206
- transactionBody: transactionBodyToBase64String(transactionToTransactionBody(transaction, AccountId.fromString('0.0.3'))),
207
- };
208
- it('should throw an error if there is no any signer', async () => {
209
- connector.signers = [];
210
- await expect(connector.signTransaction(params)).rejects.toThrow('Signer not found for account ID: 0.0.12345. Did you use the correct format? e.g hedera:<network>:<address>');
211
- });
212
- it('should invoke last signer request with correct params', async () => {
213
- await connector.signTransaction(params);
214
- expect(lastSignerRequestMock).toHaveBeenCalledWith({
215
- method: HederaJsonRpcMethod.SignTransaction,
216
- params,
217
- });
218
- });
219
- });
220
- });
221
- // describe('connect', () => {
222
- // it('should establish connection and create session', async () => {
223
- // connector = new DAppConnector(appMetadata, LedgerId.TESTNET, PROJECT_ID)
224
- // await connector.init()
225
- // expect(connector.walletConnectClient).not.toBeNull()
226
- // await connector.connect((pairing) => {
227
- // console.log('PairingString: ', pairing)
228
- // })
229
- // expect(connector.walletConnectClient?.session.getAll()).toHaveLength(1)
230
- // }, 60_000)
231
- // })
232
- });
@@ -1 +0,0 @@
1
- export {};