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

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,129 +0,0 @@
1
- import { DefaultLogger } from '../../src/lib/shared/logger';
2
- describe('DefaultLogger', () => {
3
- let logger;
4
- let consoleErrorSpy;
5
- let consoleWarnSpy;
6
- let consoleInfoSpy;
7
- let consoleDebugSpy;
8
- beforeEach(() => {
9
- // Create fresh spies for each test
10
- consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
11
- consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
12
- consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
13
- consoleDebugSpy = jest.spyOn(console, 'debug').mockImplementation();
14
- });
15
- afterEach(() => {
16
- // Clean up spies
17
- consoleErrorSpy.mockRestore();
18
- consoleWarnSpy.mockRestore();
19
- consoleInfoSpy.mockRestore();
20
- consoleDebugSpy.mockRestore();
21
- });
22
- describe('constructor', () => {
23
- it('should set default log level to info', () => {
24
- logger = new DefaultLogger();
25
- logger.error('test');
26
- logger.warn('test');
27
- logger.info('test');
28
- logger.debug('test');
29
- expect(consoleErrorSpy).toHaveBeenCalledWith('[ERROR] test');
30
- expect(consoleWarnSpy).toHaveBeenCalledWith('[WARN] test');
31
- expect(consoleInfoSpy).toHaveBeenCalledWith('[INFO] test');
32
- expect(consoleDebugSpy).not.toHaveBeenCalled();
33
- });
34
- it('should respect custom log level', () => {
35
- logger = new DefaultLogger('debug');
36
- logger.error('test');
37
- logger.warn('test');
38
- logger.info('test');
39
- logger.debug('test');
40
- expect(consoleErrorSpy).toHaveBeenCalledWith('[ERROR] test');
41
- expect(consoleWarnSpy).toHaveBeenCalledWith('[WARN] test');
42
- expect(consoleInfoSpy).toHaveBeenCalledWith('[INFO] test');
43
- expect(consoleDebugSpy).toHaveBeenCalledWith('[DEBUG] test');
44
- });
45
- });
46
- describe('setLogLevel', () => {
47
- beforeEach(() => {
48
- logger = new DefaultLogger();
49
- });
50
- it('should update log level', () => {
51
- logger.setLogLevel('error');
52
- logger.error('test');
53
- logger.warn('test');
54
- logger.info('test');
55
- logger.debug('test');
56
- expect(consoleErrorSpy).toHaveBeenCalledWith('[ERROR] test');
57
- expect(consoleWarnSpy).not.toHaveBeenCalled();
58
- expect(consoleInfoSpy).not.toHaveBeenCalled();
59
- expect(consoleDebugSpy).not.toHaveBeenCalled();
60
- });
61
- });
62
- describe('logging methods', () => {
63
- describe('error level', () => {
64
- beforeEach(() => {
65
- logger = new DefaultLogger('error');
66
- });
67
- it('should only log errors', () => {
68
- logger.error('test error');
69
- logger.warn('test warn');
70
- logger.info('test info');
71
- logger.debug('test debug');
72
- expect(consoleErrorSpy).toHaveBeenCalledWith('[ERROR] test error');
73
- expect(consoleWarnSpy).not.toHaveBeenCalled();
74
- expect(consoleInfoSpy).not.toHaveBeenCalled();
75
- expect(consoleDebugSpy).not.toHaveBeenCalled();
76
- });
77
- it('should handle additional arguments', () => {
78
- const error = new Error('test');
79
- logger.error('test error', { details: 'more info' }, error);
80
- expect(consoleErrorSpy).toHaveBeenCalledWith('[ERROR] test error', { details: 'more info' }, error);
81
- });
82
- });
83
- describe('warn level', () => {
84
- beforeEach(() => {
85
- logger = new DefaultLogger('warn');
86
- });
87
- it('should log errors and warnings', () => {
88
- logger.error('test error');
89
- logger.warn('test warn');
90
- logger.info('test info');
91
- logger.debug('test debug');
92
- expect(consoleErrorSpy).toHaveBeenCalledWith('[ERROR] test error');
93
- expect(consoleWarnSpy).toHaveBeenCalledWith('[WARN] test warn');
94
- expect(consoleInfoSpy).not.toHaveBeenCalled();
95
- expect(consoleDebugSpy).not.toHaveBeenCalled();
96
- });
97
- });
98
- describe('info level', () => {
99
- beforeEach(() => {
100
- logger = new DefaultLogger('info');
101
- });
102
- it('should log errors, warnings, and info', () => {
103
- logger.error('test error');
104
- logger.warn('test warn');
105
- logger.info('test info');
106
- logger.debug('test debug');
107
- expect(consoleErrorSpy).toHaveBeenCalledWith('[ERROR] test error');
108
- expect(consoleWarnSpy).toHaveBeenCalledWith('[WARN] test warn');
109
- expect(consoleInfoSpy).toHaveBeenCalledWith('[INFO] test info');
110
- expect(consoleDebugSpy).not.toHaveBeenCalled();
111
- });
112
- });
113
- describe('debug level', () => {
114
- beforeEach(() => {
115
- logger = new DefaultLogger('debug');
116
- });
117
- it('should log all levels', () => {
118
- logger.error('test error');
119
- logger.warn('test warn');
120
- logger.info('test info');
121
- logger.debug('test debug');
122
- expect(consoleErrorSpy).toHaveBeenCalledWith('[ERROR] test error');
123
- expect(consoleWarnSpy).toHaveBeenCalledWith('[WARN] test warn');
124
- expect(consoleInfoSpy).toHaveBeenCalledWith('[INFO] test info');
125
- expect(consoleDebugSpy).toHaveBeenCalledWith('[DEBUG] test debug');
126
- });
127
- });
128
- });
129
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,201 +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, Query, TopicCreateTransaction, } from '@hashgraph/sdk';
21
- import { transactionToBase64String, freezeTransaction, setDefaultNodeAccountIds, base64StringToTransaction, base64StringToUint8Array, Uint8ArrayToBase64String, base64StringToQuery, queryToBase64String, EIPChainIdToLedgerId, ledgerIdToEIPChainId, CAIPChainIdToLedgerId, HederaChainId, ledgerIdToCAIPChainId, networkNameToCAIPChainId, networkNameToEIPChainId, networkNamespaces, HederaSessionEvent, } from '../src';
22
- import { prepareTestTransaction, testUserAccountId, useJsonFixture } from './_helpers';
23
- describe(freezeTransaction.name, () => {
24
- it('should freeze an unfrozen transaction', () => {
25
- const txn = prepareTestTransaction(new TopicCreateTransaction());
26
- expect(txn.isFrozen()).toBe(false);
27
- freezeTransaction(txn);
28
- expect(txn.isFrozen()).toBe(true);
29
- });
30
- it('should have no effect on a frozen transaction', () => {
31
- const txn = prepareTestTransaction(new TopicCreateTransaction());
32
- txn.freeze();
33
- expect(txn.isFrozen()).toBe(true);
34
- freezeTransaction(txn);
35
- expect(txn.isFrozen()).toBe(true);
36
- });
37
- });
38
- describe(setDefaultNodeAccountIds.name, () => {
39
- it('should set default node account ids if none are set', () => {
40
- var _a;
41
- const txn = new TopicCreateTransaction();
42
- expect(txn.nodeAccountIds).toBeNull();
43
- setDefaultNodeAccountIds(txn);
44
- const result = (_a = txn.nodeAccountIds) === null || _a === void 0 ? void 0 : _a.map((id) => id.toString());
45
- expect(result).toEqual(['0.0.3', '0.0.4', '0.0.5']);
46
- });
47
- it('should do nothing if node account ids are already set', () => {
48
- var _a;
49
- const txn = new TopicCreateTransaction();
50
- txn.setNodeAccountIds([new AccountId(4)]);
51
- setDefaultNodeAccountIds(txn);
52
- const result = (_a = txn.nodeAccountIds) === null || _a === void 0 ? void 0 : _a.map((id) => id.toString());
53
- expect(result).toEqual(['0.0.4']);
54
- });
55
- });
56
- describe(transactionToBase64String.name, () => {
57
- it('should convert a transaction to a base64 encoded string', () => {
58
- const txn = prepareTestTransaction(new TopicCreateTransaction());
59
- const result = transactionToBase64String(txn);
60
- const { expected } = useJsonFixture('transactionToBase64StringResult');
61
- expect(result).toBe(expected);
62
- });
63
- });
64
- describe(base64StringToTransaction.name, () => {
65
- it('should create a transaction from a base64 string', () => {
66
- const txn = prepareTestTransaction(new TopicCreateTransaction());
67
- txn.setTransactionMemo('I should be restored');
68
- const str = transactionToBase64String(txn);
69
- const resultWithParam = base64StringToTransaction(str);
70
- const resultWithoutParam = base64StringToTransaction(str);
71
- expect(resultWithParam).toBeInstanceOf(TopicCreateTransaction);
72
- expect(resultWithoutParam).toBeInstanceOf(TopicCreateTransaction);
73
- expect(resultWithParam.transactionMemo).toBe('I should be restored');
74
- });
75
- });
76
- describe(`Uint8Array helpers`, () => {
77
- let uInt8Array;
78
- describe(base64StringToUint8Array.name, () => {
79
- it('should decode base64 string to Uint8Array', async () => {
80
- const base64String = btoa('Hello World!');
81
- uInt8Array = base64StringToUint8Array(base64String);
82
- expect(uInt8Array).toBeInstanceOf(Uint8Array);
83
- expect(Array.from(uInt8Array)).toEqual([
84
- 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33,
85
- ]);
86
- });
87
- });
88
- describe(Uint8ArrayToBase64String.name, () => {
89
- it('should encode Uint8Array to base64 string', async () => {
90
- const base64String = Uint8ArrayToBase64String(uInt8Array);
91
- expect(typeof base64String).toBe('string');
92
- expect(base64String).toBe('SGVsbG8gV29ybGQh');
93
- expect(atob(base64String)).toBe('Hello World!');
94
- });
95
- });
96
- });
97
- describe(`Query helpers`, () => {
98
- let base64Query;
99
- describe(queryToBase64String.name, () => {
100
- it('should encode Query to base64 string', async () => {
101
- const query = new AccountInfoQuery().setAccountId(testUserAccountId);
102
- base64Query = queryToBase64String(query);
103
- expect(typeof base64Query).toBe('string');
104
- expect(base64Query).toEqual('Sg0KAhAAEgcIABAAGLlg');
105
- });
106
- });
107
- describe(base64StringToQuery.name, () => {
108
- it('should decode base64 string to Query', async () => {
109
- var _a;
110
- const query = base64StringToQuery(base64Query);
111
- expect(query).toBeInstanceOf(Query);
112
- expect(query).toBeInstanceOf(AccountInfoQuery);
113
- expect((_a = query.accountId) === null || _a === void 0 ? void 0 : _a.toString()).toBe(testUserAccountId.toString());
114
- });
115
- });
116
- });
117
- describe(EIPChainIdToLedgerId.name, () => {
118
- it('should convert a EIP chain id to a LedgerId object', async () => {
119
- const mainnetLedgerId = EIPChainIdToLedgerId(295);
120
- const testnetLedgerId = EIPChainIdToLedgerId(296);
121
- const previewnetLedgerId = EIPChainIdToLedgerId(297);
122
- const localnodeLedgerId = EIPChainIdToLedgerId(298);
123
- const localnodeLedgerIdWithRandomId = EIPChainIdToLedgerId(999);
124
- expect(mainnetLedgerId).toBe(LedgerId.MAINNET);
125
- expect(testnetLedgerId).toBe(LedgerId.TESTNET);
126
- expect(previewnetLedgerId).toBe(LedgerId.PREVIEWNET);
127
- expect(localnodeLedgerId).toBe(LedgerId.LOCAL_NODE);
128
- expect(localnodeLedgerIdWithRandomId).toBe(LedgerId.LOCAL_NODE);
129
- });
130
- });
131
- describe(ledgerIdToEIPChainId.name, () => {
132
- it('should convert a LedgerId object to a EIP chain id', async () => {
133
- const mainnetChainId = ledgerIdToEIPChainId(LedgerId.MAINNET);
134
- const testnetChainId = ledgerIdToEIPChainId(LedgerId.TESTNET);
135
- const previewnetChainId = ledgerIdToEIPChainId(LedgerId.PREVIEWNET);
136
- const localnodeChainId = ledgerIdToEIPChainId(LedgerId.LOCAL_NODE);
137
- expect(mainnetChainId).toBe(295);
138
- expect(testnetChainId).toBe(296);
139
- expect(previewnetChainId).toBe(297);
140
- expect(localnodeChainId).toBe(298);
141
- });
142
- });
143
- describe(networkNameToEIPChainId.name, () => {
144
- it('should convert a network name to a EIP chain id', async () => {
145
- const mainnetChainId = networkNameToEIPChainId('mainnet');
146
- const testnetChainId = networkNameToEIPChainId('testnet');
147
- const previewnetChainId = networkNameToEIPChainId('previewnet');
148
- const localnodeChainId = networkNameToEIPChainId('devnet');
149
- expect(mainnetChainId).toBe(295);
150
- expect(testnetChainId).toBe(296);
151
- expect(previewnetChainId).toBe(297);
152
- expect(localnodeChainId).toBe(298);
153
- });
154
- });
155
- describe(CAIPChainIdToLedgerId.name, () => {
156
- it('should convert a CAIP chain id to a LedgerId object', async () => {
157
- const mainnetLedgerId = CAIPChainIdToLedgerId(HederaChainId.Mainnet);
158
- const testnetLedgerId = CAIPChainIdToLedgerId(HederaChainId.Testnet);
159
- const previewnetLedgerId = CAIPChainIdToLedgerId(HederaChainId.Previewnet);
160
- const localnodeLedgerId = CAIPChainIdToLedgerId(HederaChainId.Devnet);
161
- expect(mainnetLedgerId).toBe(LedgerId.MAINNET);
162
- expect(testnetLedgerId).toBe(LedgerId.TESTNET);
163
- expect(previewnetLedgerId).toBe(LedgerId.PREVIEWNET);
164
- expect(localnodeLedgerId).toBe(LedgerId.LOCAL_NODE);
165
- });
166
- });
167
- describe(ledgerIdToCAIPChainId.name, () => {
168
- it('should convert a LedgerId object to a CAIP chain id', async () => {
169
- const mainnetChainId = ledgerIdToCAIPChainId(LedgerId.MAINNET);
170
- const testnetChainId = ledgerIdToCAIPChainId(LedgerId.TESTNET);
171
- const previewnetChainId = ledgerIdToCAIPChainId(LedgerId.PREVIEWNET);
172
- const localnodeChainId = ledgerIdToCAIPChainId(LedgerId.LOCAL_NODE);
173
- expect(mainnetChainId).toBe(HederaChainId.Mainnet);
174
- expect(testnetChainId).toBe(HederaChainId.Testnet);
175
- expect(previewnetChainId).toBe(HederaChainId.Previewnet);
176
- expect(localnodeChainId).toBe(HederaChainId.Devnet);
177
- });
178
- });
179
- describe(networkNameToCAIPChainId.name, () => {
180
- it('should convert a network name to a CAIP chain id', async () => {
181
- const mainnetChainId = networkNameToCAIPChainId('mainnet');
182
- const testnetChainId = networkNameToCAIPChainId('testnet');
183
- const previewnetChainId = networkNameToCAIPChainId('previewnet');
184
- const localnodeChainId = networkNameToCAIPChainId('devnet');
185
- expect(mainnetChainId).toBe(HederaChainId.Mainnet);
186
- expect(testnetChainId).toBe(HederaChainId.Testnet);
187
- expect(previewnetChainId).toBe(HederaChainId.Previewnet);
188
- expect(localnodeChainId).toBe(HederaChainId.Devnet);
189
- });
190
- });
191
- describe(networkNamespaces.name, () => {
192
- it('should create a `ProposalTypes.RequiredNamespaces` object for a given ledgerId', async () => {
193
- const methods = ['hedera_signMessage'];
194
- const events = Object.values(HederaSessionEvent);
195
- const testnetNamespaces = networkNamespaces(LedgerId.TESTNET, methods, events);
196
- expect(testnetNamespaces.hedera).not.toBe(undefined);
197
- expect(testnetNamespaces.hedera.methods).toBe(methods);
198
- expect(testnetNamespaces.hedera.events).toBe(events);
199
- expect(testnetNamespaces.hedera.chains).toEqual([HederaChainId.Testnet]);
200
- });
201
- });
@@ -1,43 +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 { TopicCreateTransaction } from '@hashgraph/sdk';
21
- import { HederaChainId, Wallet } from '../../../src';
22
- import { prepareTestTransaction, projectId, requestId, requestTopic, testPrivateKeyECDSA, testUserAccountId, useJsonFixture, walletMetadata, } from '../../_helpers';
23
- describe(Wallet.name, () => {
24
- describe('executeTransaction', () => {
25
- it('should execute signed transaction, returning the transaction response', async () => {
26
- try {
27
- const wallet = await Wallet.create(projectId, walletMetadata);
28
- const hederaWallet = wallet.getHederaWallet(HederaChainId.Testnet, testUserAccountId.toString(), testPrivateKeyECDSA);
29
- const signerCallMock = jest.spyOn(hederaWallet, 'call');
30
- signerCallMock.mockImplementation(async () => { }); // Mocking the 'call' method to do nothing
31
- const transaction = prepareTestTransaction(new TopicCreateTransaction(), {
32
- freeze: true,
33
- });
34
- const signTransaction = await hederaWallet.signTransaction(transaction);
35
- const respondSessionRequestSpy = jest.spyOn(wallet, 'respondSessionRequest');
36
- await wallet.hedera_executeTransaction(requestId, requestTopic, signTransaction, hederaWallet);
37
- const mockResponse = useJsonFixture('methods/executeTransactionSuccess');
38
- expect(respondSessionRequestSpy).toHaveBeenCalledWith(mockResponse);
39
- }
40
- catch (err) { }
41
- }, 15000);
42
- });
43
- });
@@ -1,40 +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 { HederaChainId, Wallet } from '../../../src';
21
- import { projectId, requestId, requestTopic, testPrivateKeyECDSA, testUserAccountId, useJsonFixture, walletMetadata, } from '../../_helpers';
22
- describe(Wallet.name, () => {
23
- describe('getNodeAddresses', () => {
24
- it('should return array of nodes addresses', async () => {
25
- const wallet = await Wallet.create(projectId, walletMetadata);
26
- const hederaWallet = wallet.getHederaWallet(HederaChainId.Testnet, testUserAccountId.toString(), testPrivateKeyECDSA);
27
- const respondSessionRequestSpy = jest.spyOn(wallet, 'respondSessionRequest');
28
- try {
29
- await wallet.hedera_getNodeAddresses(requestId, requestTopic, null, hederaWallet);
30
- }
31
- catch (err) { }
32
- const mockResponse = useJsonFixture('methods/getNodeAddressesSuccess');
33
- const callArguments = respondSessionRequestSpy.mock.calls[0][0];
34
- const response = callArguments;
35
- response.response.result.nodes.sort();
36
- mockResponse.response.result.nodes.sort();
37
- expect(response).toEqual(mockResponse);
38
- }, 15000);
39
- });
40
- });
@@ -1,41 +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 { AccountInfoQuery } from '@hashgraph/sdk';
21
- import { HederaChainId, Wallet, base64StringToUint8Array, } from '../../../src';
22
- import { projectId, requestId, requestTopic, testPrivateKeyECDSA, testUserAccountId, useJsonFixture, walletMetadata, } from '../../_helpers';
23
- describe(Wallet.name, () => {
24
- describe('signAndExecuteQuery', () => {
25
- it('should sign and execute query, returning the query response', async () => {
26
- const wallet = await Wallet.create(projectId, walletMetadata);
27
- const hederaWallet = wallet.getHederaWallet(HederaChainId.Testnet, testUserAccountId.toString(), testPrivateKeyECDSA);
28
- const query = new AccountInfoQuery().setAccountId(testUserAccountId);
29
- const respondSessionRequestSpy = jest.spyOn(wallet, 'respondSessionRequest');
30
- const signerCallMock = jest.spyOn(query, 'executeWithSigner');
31
- const toBytes = () => base64StringToUint8Array(btoa('Hello World!'));
32
- signerCallMock.mockImplementation(async () => ({ toBytes }));
33
- try {
34
- await wallet.hedera_signAndExecuteQuery(requestId, requestTopic, query, hederaWallet);
35
- }
36
- catch (err) { }
37
- const mockResponse = useJsonFixture('methods/signAndExecuteQuerySuccess');
38
- expect(respondSessionRequestSpy).toHaveBeenCalledWith(mockResponse);
39
- }, 15000);
40
- });
41
- });
@@ -1,48 +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 { TopicCreateTransaction } from '@hashgraph/sdk';
21
- import { HederaChainId, Wallet } from '../../../src';
22
- import { prepareTestTransaction, projectId, requestId, requestTopic, testPrivateKeyECDSA, testUserAccountId, useJsonFixture, walletMetadata, } from '../../_helpers';
23
- describe(Wallet.name, () => {
24
- describe('signAndExecuteTransaction', () => {
25
- it('should sign and execute, returning the transaction response', async () => {
26
- try {
27
- const wallet = await Wallet.create(projectId, walletMetadata);
28
- const hederaWallet = wallet.getHederaWallet(HederaChainId.Testnet, testUserAccountId.toString(), testPrivateKeyECDSA);
29
- const signerCallMock = jest.spyOn(hederaWallet, 'call');
30
- signerCallMock.mockImplementation(async () => {
31
- return {
32
- nodeId: '0.0.3',
33
- transactionHash: 'uO6obRah/zbL1Wn1ZVd5unos7kbsI8G5bHifKGVWUGZPiCafQzr/hdlEJyUiKLw9',
34
- transactionId: '0.0.12345@1691705630.325343432',
35
- };
36
- }); // Mocking the 'call' method to do nothing
37
- const transaction = prepareTestTransaction(new TopicCreateTransaction(), {
38
- freeze: true,
39
- });
40
- const respondSessionRequestSpy = jest.spyOn(wallet, 'respondSessionRequest');
41
- await wallet.hedera_signAndExecuteTransaction(requestId, requestTopic, transaction, hederaWallet);
42
- const mockResponse = useJsonFixture('methods/signAndExecuteTransactionSuccess');
43
- expect(respondSessionRequestSpy).toHaveBeenCalledWith(mockResponse);
44
- }
45
- catch (err) { }
46
- }, 15000);
47
- });
48
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,60 +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 { HederaChainId, Wallet } from '../../../src';
21
- import { testPrivateKeyECDSA, testPrivateKeyED25519, testUserAccountId, walletMetadata, projectId, } from '../../_helpers';
22
- describe(Wallet.name, () => {
23
- describe('signMessage', () => {
24
- // [private key type, private key, expected value]
25
- const testCases = [
26
- [
27
- 'ECDSA',
28
- testPrivateKeyECDSA,
29
- 'CmUKIQJ4J53yGuPNMGEGJ7HkI+u3QFxUuAOa9VLEtFj7Y6qNMzJAp3vxT7kRPE9HFFm/bbArGYDQ+psNWZC70rdW2bE1L86REC5xavtsalXfGaZ7FsdkWwPg4GBUKuzmr1eFTcYdNg==',
30
- ],
31
- [
32
- 'ED25519',
33
- testPrivateKeyED25519,
34
- 'CmQKIKLvE3YbZEplGhpKxmbq+6xBnJcoL4r1wz9Y1zLnPlpVGkBtfDTfBZGf/MUbovYyLUjORErDGhDYbzPFoAbkMwRrpw2ouDRmn6Dd6A06k6yM/FhZ/VjdHVhQUd+fxv1cZqUM',
35
- ],
36
- ];
37
- test.each(testCases)('should decode message bytes and sign with: %p', async (_, privateKey, expected) => {
38
- const wallet = await Wallet.create(projectId, walletMetadata);
39
- const id = 1;
40
- const topic = 'test-topic';
41
- const hederaWallet = wallet.getHederaWallet(HederaChainId.Testnet, testUserAccountId.toString(), privateKey);
42
- const respondSessionRequestSpy = jest.spyOn(wallet, 'respondSessionRequest');
43
- try {
44
- await wallet.hedera_signMessage(id, topic, 'Hello Future', hederaWallet);
45
- }
46
- catch (err) { }
47
- const mockResponse = {
48
- topic,
49
- response: {
50
- jsonrpc: '2.0',
51
- id,
52
- result: {
53
- signatureMap: expected,
54
- },
55
- },
56
- };
57
- expect(respondSessionRequestSpy).toHaveBeenCalledWith(mockResponse);
58
- });
59
- });
60
- });
@@ -1,47 +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 { TransferTransaction, Hbar, AccountId } from '@hashgraph/sdk';
21
- import { HederaChainId, Wallet, transactionToTransactionBody, } from '../../../src';
22
- import { projectId, requestId, requestTopic, testPrivateKeyECDSA, testUserAccountId, useJsonFixture, walletMetadata, } from '../../_helpers';
23
- describe(Wallet.name, () => {
24
- describe('signTransaction', () => {
25
- it('should sign a transaction and return without executing', async () => {
26
- try {
27
- const wallet = await Wallet.create(projectId, walletMetadata);
28
- const hederaWallet = wallet.getHederaWallet(HederaChainId.Testnet, testUserAccountId.toString(), testPrivateKeyECDSA);
29
- const transaction = new TransferTransaction()
30
- .setMaxTransactionFee(new Hbar(1))
31
- .addHbarTransfer('0.0.123', new Hbar(10))
32
- .addHbarTransfer('0.0.321', new Hbar(-10));
33
- const transactionBody = transactionToTransactionBody(transaction, AccountId.fromString('0.0.3'));
34
- if (!transactionBody)
35
- throw new Error('Failed to create transaction body');
36
- const respondSessionRequestSpy = jest.spyOn(wallet, 'respondSessionRequest');
37
- const response = await wallet.hedera_signTransaction(requestId, requestTopic, transactionBody, hederaWallet);
38
- console.log(response);
39
- const mockResponse = useJsonFixture('methods/signTransactionSuccess');
40
- mockResponse.response.result;
41
- respondSessionRequestSpy;
42
- expect(respondSessionRequestSpy).toHaveBeenCalledWith(mockResponse);
43
- }
44
- catch (err) { }
45
- }, 15000);
46
- });
47
- });
@@ -1 +0,0 @@
1
- export {};