@hashgraph/hedera-wallet-connect 1.3.7-canary.a38890b.0 → 1.3.7-canary.d60d7af.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/dapp → dapp}/index.d.ts +4 -0
  2. package/dist/{src/lib/dapp → dapp}/index.js +38 -39
  3. package/package.json +1 -1
  4. package/dist/src/index.d.ts +0 -1
  5. package/dist/src/index.js +0 -20
  6. package/dist/test/_helpers.d.ts +0 -38
  7. package/dist/test/_helpers.js +0 -95
  8. package/dist/test/dapp/DAppConnector.test.d.ts +0 -1
  9. package/dist/test/dapp/DAppConnector.test.js +0 -232
  10. package/dist/test/dapp/DAppSigner.test.d.ts +0 -1
  11. package/dist/test/dapp/DAppSigner.test.js +0 -625
  12. package/dist/test/shared/logger.test.d.ts +0 -1
  13. package/dist/test/shared/logger.test.js +0 -129
  14. package/dist/test/utils.test.d.ts +0 -1
  15. package/dist/test/utils.test.js +0 -201
  16. package/dist/test/wallet/methods/wallet-executeTransaction.test.d.ts +0 -1
  17. package/dist/test/wallet/methods/wallet-executeTransaction.test.js +0 -43
  18. package/dist/test/wallet/methods/wallet-getNodeAddresses.test.d.ts +0 -1
  19. package/dist/test/wallet/methods/wallet-getNodeAddresses.test.js +0 -40
  20. package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.d.ts +0 -1
  21. package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.js +0 -41
  22. package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.d.ts +0 -1
  23. package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.js +0 -48
  24. package/dist/test/wallet/methods/wallet-signMessage.test.d.ts +0 -1
  25. package/dist/test/wallet/methods/wallet-signMessage.test.js +0 -60
  26. package/dist/test/wallet/methods/wallet-signTransaction.test.d.ts +0 -1
  27. package/dist/test/wallet/methods/wallet-signTransaction.test.js +0 -47
  28. package/dist/test/wallet/wallet-init.test.d.ts +0 -1
  29. package/dist/test/wallet/wallet-init.test.js +0 -53
  30. /package/dist/{src/lib/dapp → dapp}/DAppSigner.d.ts +0 -0
  31. /package/dist/{src/lib/dapp → dapp}/DAppSigner.js +0 -0
  32. /package/dist/{src/lib/index.d.ts → index.d.ts} +0 -0
  33. /package/dist/{src/lib/index.js → index.js} +0 -0
  34. /package/dist/{src/lib/shared → shared}/chainIds.d.ts +0 -0
  35. /package/dist/{src/lib/shared → shared}/chainIds.js +0 -0
  36. /package/dist/{src/lib/shared → shared}/errors.d.ts +0 -0
  37. /package/dist/{src/lib/shared → shared}/errors.js +0 -0
  38. /package/dist/{src/lib/shared → shared}/events.d.ts +0 -0
  39. /package/dist/{src/lib/shared → shared}/events.js +0 -0
  40. /package/dist/{src/lib/shared → shared}/extensionController.d.ts +0 -0
  41. /package/dist/{src/lib/shared → shared}/extensionController.js +0 -0
  42. /package/dist/{src/lib/shared → shared}/index.d.ts +0 -0
  43. /package/dist/{src/lib/shared → shared}/index.js +0 -0
  44. /package/dist/{src/lib/shared → shared}/logger.d.ts +0 -0
  45. /package/dist/{src/lib/shared → shared}/logger.js +0 -0
  46. /package/dist/{src/lib/shared → shared}/methods.d.ts +0 -0
  47. /package/dist/{src/lib/shared → shared}/methods.js +0 -0
  48. /package/dist/{src/lib/shared → shared}/payloads.d.ts +0 -0
  49. /package/dist/{src/lib/shared → shared}/payloads.js +0 -0
  50. /package/dist/{src/lib/shared → shared}/utils.d.ts +0 -0
  51. /package/dist/{src/lib/shared → shared}/utils.js +0 -0
  52. /package/dist/{src/lib/wallet → wallet}/index.d.ts +0 -0
  53. /package/dist/{src/lib/wallet → wallet}/index.js +0 -0
  54. /package/dist/{src/lib/wallet → wallet}/provider.d.ts +0 -0
  55. /package/dist/{src/lib/wallet → wallet}/provider.js +0 -0
  56. /package/dist/{src/lib/wallet → wallet}/types.d.ts +0 -0
  57. /package/dist/{src/lib/wallet → wallet}/types.js +0 -0
@@ -211,5 +211,9 @@ export declare class DAppConnector {
211
211
  * ```
212
212
  */
213
213
  signTransaction(params: SignTransactionParams): Promise<SignTransactionResult>;
214
+ private handleSessionEvent;
215
+ private handleSessionUpdate;
216
+ private handleSessionDelete;
217
+ private handlePairingDelete;
214
218
  }
215
219
  export default DAppConnector;
@@ -110,45 +110,10 @@ export class DAppConnector {
110
110
  this.signers = existingSessions.flatMap((session) => this.createSigners(session));
111
111
  else
112
112
  this.checkIframeConnect();
113
- this.walletConnectClient.on('session_event', (event) => {
114
- // Handle session events, such as "chainChanged", "accountsChanged", etc.
115
- this.logger.debug('Session event received:', event);
116
- this.validateAndRefreshSigners();
117
- });
118
- this.walletConnectClient.on('session_update', ({ topic, params }) => {
119
- // Handle session update
120
- const { namespaces } = params;
121
- const _session = this.walletConnectClient.session.get(topic);
122
- // Overwrite the `namespaces` of the existing session with the incoming one.
123
- const updatedSession = Object.assign(Object.assign({}, _session), { namespaces });
124
- // Integrate the updated session state into your dapp state.
125
- this.logger.info('Session updated:', updatedSession);
126
- this.signers = this.signers.filter((signer) => signer.topic !== topic);
127
- this.signers.push(...this.createSigners(updatedSession));
128
- });
129
- this.walletConnectClient.on('session_delete', (pairing) => {
130
- this.logger.info('Session deleted:', pairing);
131
- this.signers = this.signers.filter((signer) => signer.topic !== pairing.topic);
132
- // Session was deleted -> reset the dapp state, clean up from user session, etc.
133
- try {
134
- this.disconnect(pairing.topic);
135
- }
136
- catch (e) {
137
- this.logger.error('Error disconnecting session:', e);
138
- }
139
- this.logger.info('Session deleted by wallet');
140
- });
141
- this.walletConnectClient.core.pairing.events.on('pairing_delete', (pairing) => {
142
- this.logger.info('Pairing deleted:', pairing);
143
- this.signers = this.signers.filter((signer) => signer.topic !== pairing.topic);
144
- try {
145
- this.disconnect(pairing.topic);
146
- }
147
- catch (e) {
148
- this.logger.error('Error disconnecting pairing:', e);
149
- }
150
- this.logger.info('Pairing deleted by wallet');
151
- });
113
+ this.walletConnectClient.on('session_event', this.handleSessionEvent.bind(this));
114
+ this.walletConnectClient.on('session_update', this.handleSessionUpdate.bind(this));
115
+ this.walletConnectClient.on('session_delete', this.handleSessionDelete.bind(this));
116
+ this.walletConnectClient.core.pairing.events.on('pairing_delete', this.handlePairingDelete.bind(this));
152
117
  }
153
118
  catch (e) {
154
119
  this.logger.error('Error initializing DAppConnector:', e);
@@ -542,5 +507,39 @@ export class DAppConnector {
542
507
  params,
543
508
  });
544
509
  }
510
+ handleSessionEvent(args) {
511
+ this.logger.debug('Session event received:', args);
512
+ this.validateAndRefreshSigners();
513
+ }
514
+ handleSessionUpdate({ topic, params, }) {
515
+ const { namespaces } = params;
516
+ const _session = this.walletConnectClient.session.get(topic);
517
+ const updatedSession = Object.assign(Object.assign({}, _session), { namespaces });
518
+ this.logger.info('Session updated:', updatedSession);
519
+ this.signers = this.signers.filter((signer) => signer.topic !== topic);
520
+ this.signers.push(...this.createSigners(updatedSession));
521
+ }
522
+ handleSessionDelete(event) {
523
+ this.logger.info('Session deleted:', event);
524
+ this.signers = this.signers.filter((signer) => signer.topic !== event.topic);
525
+ try {
526
+ this.disconnect(event.topic);
527
+ }
528
+ catch (e) {
529
+ this.logger.error('Error disconnecting session:', e);
530
+ }
531
+ this.logger.info('Session deleted by wallet');
532
+ }
533
+ handlePairingDelete(event) {
534
+ this.logger.info('Pairing deleted:', event);
535
+ this.signers = this.signers.filter((signer) => signer.topic !== event.topic);
536
+ try {
537
+ this.disconnect(event.topic);
538
+ }
539
+ catch (e) {
540
+ this.logger.error('Error disconnecting pairing:', e);
541
+ }
542
+ this.logger.info('Pairing deleted by wallet');
543
+ }
545
544
  }
546
545
  export default DAppConnector;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashgraph/hedera-wallet-connect",
3
- "version": "1.3.7-canary.a38890b.0",
3
+ "version": "1.3.7-canary.d60d7af.0",
4
4
  "description": "A library to facilitate integrating Hedera with WalletConnect",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
1
- export * from './lib';
package/dist/src/index.js DELETED
@@ -1,20 +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
- export * from './lib';
@@ -1,38 +0,0 @@
1
- import { AccountId, Query, Transaction, TransactionId } from '@hashgraph/sdk';
2
- export declare const projectId = "ce06497abf4102004138a10edd29c921";
3
- export declare const walletMetadata: {
4
- name: string;
5
- url: string;
6
- description: string;
7
- icons: string[];
8
- };
9
- export declare const dAppMetadata: {
10
- name: string;
11
- url: string;
12
- description: string;
13
- icons: string[];
14
- };
15
- export declare const requestId = 1;
16
- export declare const requestTopic = "test-topic";
17
- export declare const defaultAccountNumber = 12345;
18
- export declare const defaultNodeId = 3;
19
- export declare const testUserAccountId: AccountId;
20
- export declare const testNodeAccountId: AccountId;
21
- /** Fixed to a specific timestamp */
22
- export declare const testTransactionId: TransactionId;
23
- type TransactionOptions = {
24
- setNodeAccountIds?: boolean;
25
- setTransactionId?: boolean;
26
- freeze?: boolean;
27
- operatorAccountId?: number;
28
- };
29
- export declare function prepareTestTransaction<T extends Transaction = Transaction>(transaction: T, options?: TransactionOptions): T;
30
- type QueryOptions = {
31
- setNodeAccountIds?: boolean;
32
- };
33
- export declare function prepareTestQuery<Q extends Query<OutputT>, OutputT>(query: Q, options?: QueryOptions): Q;
34
- export declare const testPrivateKeyECDSA = "3030020100300706052b8104000a042204203ce31ffad30d6db47c315bbea08232aad2266d8800a12aa3d8a812486e782759";
35
- export declare const testPrivateKeyED25519 = "302e020100300506032b657004220420133eefea772add1f995c96bccf42b08b76daf67665f0c4c5ae308fae9275c142";
36
- export declare function useJsonFixture(filename: string): any;
37
- export declare function writeJsonFixture(filename: string, data: any): void;
38
- export {};
@@ -1,95 +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 fs from 'fs';
21
- import path from 'path';
22
- import { AccountId, TransactionId } from '@hashgraph/sdk';
23
- export const projectId = 'ce06497abf4102004138a10edd29c921';
24
- export const walletMetadata = {
25
- name: 'Wallet Test',
26
- url: 'https://dapp.hedera.app',
27
- description: 'Hedera Hashgraph Wallet Example.',
28
- icons: [
29
- 'https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8xNFwvMTQzMTI3XC9wcm9qZWN0c1wvMTgwMjE1XC9hc3NldHNcL2M3XC8zNDU0ODY3XC85ZjM1NDliYmE5MGQ2NDA0OGU0NzlhZTNiMzkyYzY4Yy0xNTY2NTkxOTQ4LmpwZyJ9:frontify:v_zJvQTCjtNploUvnSpk8S5NJB4R5eei6f7ERL2KSeQ?width=800',
30
- ],
31
- };
32
- export const dAppMetadata = {
33
- name: 'dApp Test',
34
- url: 'https://dapp.hedera.app',
35
- description: 'Hedera Hashgraph dApp Example.',
36
- icons: [
37
- 'https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8xNFwvMTQzMTI3XC9wcm9qZWN0c1wvMTgwMjE1XC9hc3NldHNcL2M3XC8zNDU0ODY3XC85ZjM1NDliYmE5MGQ2NDA0OGU0NzlhZTNiMzkyYzY4Yy0xNTY2NTkxOTQ4LmpwZyJ9:frontify:v_zJvQTCjtNploUvnSpk8S5NJB4R5eei6f7ERL2KSeQ?width=800',
38
- ],
39
- };
40
- export const requestId = 1;
41
- export const requestTopic = 'test-topic';
42
- export const defaultAccountNumber = 12345;
43
- export const defaultNodeId = 3;
44
- export const testUserAccountId = new AccountId(defaultAccountNumber);
45
- export const testNodeAccountId = new AccountId(defaultNodeId);
46
- /** Fixed to a specific timestamp */
47
- export const testTransactionId = TransactionId.fromString(`0.0.${defaultAccountNumber}@1691705630.325343432`);
48
- export function prepareTestTransaction(transaction, options) {
49
- const selectedOptions = Object.assign({
50
- // defaults
51
- freeze: false, setNodeAccountIds: true, setTransactionId: true, operatorAccountId: defaultAccountNumber }, options);
52
- if (selectedOptions.setNodeAccountIds) {
53
- transaction.setNodeAccountIds([testNodeAccountId]);
54
- }
55
- if (selectedOptions.setTransactionId) {
56
- let transactionId = testTransactionId;
57
- if (selectedOptions.operatorAccountId &&
58
- selectedOptions.operatorAccountId !== defaultAccountNumber) {
59
- transactionId = TransactionId.generate(new AccountId(selectedOptions.operatorAccountId));
60
- }
61
- transaction.setTransactionId(transactionId);
62
- }
63
- if (selectedOptions.freeze) {
64
- transaction.freeze();
65
- }
66
- return transaction;
67
- }
68
- export function prepareTestQuery(query, options) {
69
- const selectedOptions = Object.assign({
70
- // defaults
71
- setNodeAccountIds: true }, options);
72
- if (selectedOptions.setNodeAccountIds) {
73
- query.setNodeAccountIds([testNodeAccountId]);
74
- }
75
- return query;
76
- }
77
- // from PrivateKey.generateECDSA().toStringDer()
78
- export const testPrivateKeyECDSA = '3030020100300706052b8104000a042204203ce31ffad30d6db47c315bbea08232aad2266d8800a12aa3d8a812486e782759';
79
- // from PrivateKey.generateED25519().toStringDer()
80
- export const testPrivateKeyED25519 = '302e020100300506032b657004220420133eefea772add1f995c96bccf42b08b76daf67665f0c4c5ae308fae9275c142';
81
- /** JSON fixture helpers */
82
- const FIXTURES_PATH = 'test/_fixtures';
83
- const filenameWithJsonExtension = (filename) => {
84
- const file = /\.json$/.test(filename) ? filename : filename + '.json';
85
- return path.join(FIXTURES_PATH, file);
86
- };
87
- export function useJsonFixture(filename) {
88
- const filepath = filenameWithJsonExtension(filename);
89
- const data = fs.readFileSync(filepath).toString();
90
- return JSON.parse(data);
91
- }
92
- export function writeJsonFixture(filename, data) {
93
- const filepath = filenameWithJsonExtension(filename);
94
- fs.writeFileSync(filepath, JSON.stringify(data, null, 2));
95
- }
@@ -1 +0,0 @@
1
- export {};
@@ -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 {};