@hashgraph/hedera-wallet-connect 1.3.7-canary.813a6d2.0 → 1.3.7-canary.a9c215c.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{src/lib/dapp → dapp}/DAppSigner.js +1 -2
- package/dist/{src/lib/dapp → dapp}/index.d.ts +4 -0
- package/dist/{src/lib/dapp → dapp}/index.js +42 -46
- package/dist/{src/lib/shared → shared}/utils.d.ts +2 -2
- package/dist/{src/lib/shared → shared}/utils.js +2 -2
- package/package.json +5 -2
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -20
- package/dist/test/_helpers.d.ts +0 -38
- package/dist/test/_helpers.js +0 -95
- package/dist/test/dapp/DAppConnector.test.d.ts +0 -1
- package/dist/test/dapp/DAppConnector.test.js +0 -234
- package/dist/test/dapp/DAppSigner.test.d.ts +0 -1
- package/dist/test/dapp/DAppSigner.test.js +0 -155
- package/dist/test/utils.test.d.ts +0 -1
- package/dist/test/utils.test.js +0 -201
- package/dist/test/wallet/methods/wallet-executeTransaction.test.d.ts +0 -1
- package/dist/test/wallet/methods/wallet-executeTransaction.test.js +0 -43
- package/dist/test/wallet/methods/wallet-getNodeAddresses.test.d.ts +0 -1
- package/dist/test/wallet/methods/wallet-getNodeAddresses.test.js +0 -40
- package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.d.ts +0 -1
- package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.js +0 -41
- package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.d.ts +0 -1
- package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.js +0 -48
- package/dist/test/wallet/methods/wallet-signMessage.test.d.ts +0 -1
- package/dist/test/wallet/methods/wallet-signMessage.test.js +0 -60
- package/dist/test/wallet/methods/wallet-signTransaction.test.d.ts +0 -1
- package/dist/test/wallet/methods/wallet-signTransaction.test.js +0 -47
- package/dist/test/wallet/wallet-init.test.d.ts +0 -1
- package/dist/test/wallet/wallet-init.test.js +0 -53
- /package/dist/{src/lib/dapp → dapp}/DAppSigner.d.ts +0 -0
- /package/dist/{src/lib/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/lib/index.js → index.js} +0 -0
- /package/dist/{src/lib/shared → shared}/chainIds.d.ts +0 -0
- /package/dist/{src/lib/shared → shared}/chainIds.js +0 -0
- /package/dist/{src/lib/shared → shared}/errors.d.ts +0 -0
- /package/dist/{src/lib/shared → shared}/errors.js +0 -0
- /package/dist/{src/lib/shared → shared}/events.d.ts +0 -0
- /package/dist/{src/lib/shared → shared}/events.js +0 -0
- /package/dist/{src/lib/shared → shared}/extensionController.d.ts +0 -0
- /package/dist/{src/lib/shared → shared}/extensionController.js +0 -0
- /package/dist/{src/lib/shared → shared}/index.d.ts +0 -0
- /package/dist/{src/lib/shared → shared}/index.js +0 -0
- /package/dist/{src/lib/shared → shared}/logger.d.ts +0 -0
- /package/dist/{src/lib/shared → shared}/logger.js +0 -0
- /package/dist/{src/lib/shared → shared}/methods.d.ts +0 -0
- /package/dist/{src/lib/shared → shared}/methods.js +0 -0
- /package/dist/{src/lib/shared → shared}/payloads.d.ts +0 -0
- /package/dist/{src/lib/shared → shared}/payloads.js +0 -0
- /package/dist/{src/lib/wallet → wallet}/index.d.ts +0 -0
- /package/dist/{src/lib/wallet → wallet}/index.js +0 -0
- /package/dist/{src/lib/wallet → wallet}/provider.d.ts +0 -0
- /package/dist/{src/lib/wallet → wallet}/provider.js +0 -0
- /package/dist/{src/lib/wallet → wallet}/types.d.ts +0 -0
- /package/dist/{src/lib/wallet → wallet}/types.js +0 -0
@@ -49,9 +49,8 @@ export class DAppSigner {
|
|
49
49
|
return allNodes.slice(0, numberOfNodes);
|
50
50
|
}
|
51
51
|
request(request) {
|
52
|
-
if (this.extensionId)
|
52
|
+
if (this.extensionId)
|
53
53
|
extensionOpen(this.extensionId);
|
54
|
-
}
|
55
54
|
return this.signClient.request({
|
56
55
|
topic: this.topic,
|
57
56
|
request,
|
@@ -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;
|
@@ -99,59 +99,21 @@ export class DAppConnector {
|
|
99
99
|
if (!this.projectId) {
|
100
100
|
throw new Error('Project ID is not defined');
|
101
101
|
}
|
102
|
-
|
102
|
+
this.walletConnectClient = await SignClient.init({
|
103
103
|
logger,
|
104
104
|
relayUrl: 'wss://relay.walletconnect.com',
|
105
105
|
projectId: this.projectId,
|
106
106
|
metadata: this.dAppMetadata,
|
107
107
|
});
|
108
|
-
this.walletConnectClient = signClient;
|
109
108
|
const existingSessions = this.walletConnectClient.session.getAll();
|
110
|
-
if (existingSessions.length > 0)
|
109
|
+
if (existingSessions.length > 0)
|
111
110
|
this.signers = existingSessions.flatMap((session) => this.createSigners(session));
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
this.walletConnectClient.on('
|
117
|
-
|
118
|
-
this.logger.debug('Session event received:', event);
|
119
|
-
this.validateAndRefreshSigners();
|
120
|
-
});
|
121
|
-
this.walletConnectClient.on('session_update', ({ topic, params }) => {
|
122
|
-
// Handle session update
|
123
|
-
const { namespaces } = params;
|
124
|
-
const _session = this.walletConnectClient.session.get(topic);
|
125
|
-
// Overwrite the `namespaces` of the existing session with the incoming one.
|
126
|
-
const updatedSession = Object.assign(Object.assign({}, _session), { namespaces });
|
127
|
-
// Integrate the updated session state into your dapp state.
|
128
|
-
this.logger.info('Session updated:', updatedSession);
|
129
|
-
this.signers = this.signers.filter((signer) => signer.topic !== topic);
|
130
|
-
this.signers.push(...this.createSigners(updatedSession));
|
131
|
-
});
|
132
|
-
this.walletConnectClient.on('session_delete', (pairing) => {
|
133
|
-
this.logger.info('Session deleted:', pairing);
|
134
|
-
this.signers = this.signers.filter((signer) => signer.topic !== pairing.topic);
|
135
|
-
// Session was deleted -> reset the dapp state, clean up from user session, etc.
|
136
|
-
try {
|
137
|
-
this.disconnect(pairing.topic);
|
138
|
-
}
|
139
|
-
catch (e) {
|
140
|
-
this.logger.error('Error disconnecting session:', e);
|
141
|
-
}
|
142
|
-
this.logger.info('Session deleted by wallet');
|
143
|
-
});
|
144
|
-
this.walletConnectClient.core.pairing.events.on('pairing_delete', (pairing) => {
|
145
|
-
this.logger.info('Pairing deleted:', pairing);
|
146
|
-
this.signers = this.signers.filter((signer) => signer.topic !== pairing.topic);
|
147
|
-
try {
|
148
|
-
this.disconnect(pairing.topic);
|
149
|
-
}
|
150
|
-
catch (e) {
|
151
|
-
this.logger.error('Error disconnecting pairing:', e);
|
152
|
-
}
|
153
|
-
this.logger.info('Pairing deleted by wallet');
|
154
|
-
});
|
111
|
+
else
|
112
|
+
this.checkIframeConnect();
|
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));
|
155
117
|
}
|
156
118
|
catch (e) {
|
157
119
|
this.logger.error('Error initializing DAppConnector:', e);
|
@@ -545,5 +507,39 @@ export class DAppConnector {
|
|
545
507
|
params,
|
546
508
|
});
|
547
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
|
+
}
|
548
544
|
}
|
549
545
|
export default DAppConnector;
|
@@ -49,8 +49,8 @@ export declare function base64StringToTransaction<T extends Transaction>(transac
|
|
49
49
|
* @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
|
50
50
|
* @returns `string`
|
51
51
|
* */
|
52
|
-
export declare function transactionToTransactionBody<T extends Transaction>(transaction: T, nodeAccountId: AccountId):
|
53
|
-
export declare function transactionBodyToBase64String(transactionBody:
|
52
|
+
export declare function transactionToTransactionBody<T extends Transaction>(transaction: T, nodeAccountId: AccountId): Uint8Array | null | undefined;
|
53
|
+
export declare function transactionBodyToBase64String(transactionBody: Uint8Array): string;
|
54
54
|
/**
|
55
55
|
* @param transactionList - a proto.TransactionList object
|
56
56
|
* @returns `string`
|
@@ -86,10 +86,10 @@ export function base64StringToTransaction(transactionBytes) {
|
|
86
86
|
export function transactionToTransactionBody(transaction, nodeAccountId) {
|
87
87
|
// This is a private function, though provides the capabilities to construct a proto.TransactionBody
|
88
88
|
//@ts-ignore
|
89
|
-
return transaction.
|
89
|
+
return transaction._signedTransactions.current.bodyBytes;
|
90
90
|
}
|
91
91
|
export function transactionBodyToBase64String(transactionBody) {
|
92
|
-
return Uint8ArrayToBase64String(
|
92
|
+
return Uint8ArrayToBase64String(transactionBody);
|
93
93
|
}
|
94
94
|
/**
|
95
95
|
* @param transactionList - a proto.TransactionList object
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hashgraph/hedera-wallet-connect",
|
3
|
-
"version": "1.3.7-canary.
|
3
|
+
"version": "1.3.7-canary.a9c215c.0",
|
4
4
|
"description": "A library to facilitate integrating Hedera with WalletConnect",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -32,6 +32,7 @@
|
|
32
32
|
"husky": "^9.0.6",
|
33
33
|
"jest": "^29.7.0",
|
34
34
|
"lint-staged": "^15.1.0",
|
35
|
+
"long": "^5.2.3",
|
35
36
|
"lokijs": "^1.5.12",
|
36
37
|
"nodemon": "^3.0.3",
|
37
38
|
"prettier": "^3.2.4",
|
@@ -61,7 +62,9 @@
|
|
61
62
|
"prettier:check": "prettier --check ./src/",
|
62
63
|
"prettier:fix": "prettier --write ./src/",
|
63
64
|
"prod:docs-docker": "sh docker-run.sh",
|
64
|
-
"test:sigMap": "jest --testMatch '**/SignatureMapHelpers.test.ts' --verbose"
|
65
|
+
"test:sigMap": "jest --testMatch '**/SignatureMapHelpers.test.ts' --verbose",
|
66
|
+
"test:coverage": "jest --coverage",
|
67
|
+
"test:coverage:html": "jest --coverage --coverageReporters='text-summary' --coverageReporters='html'"
|
65
68
|
},
|
66
69
|
"peerDependencies": {
|
67
70
|
"@hashgraph/sdk": "^2.40.0",
|
package/dist/src/index.d.ts
DELETED
@@ -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';
|
package/dist/test/_helpers.d.ts
DELETED
@@ -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 {};
|
package/dist/test/_helpers.js
DELETED
@@ -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,234 +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, } from '../../src';
|
22
|
-
import { projectId, dAppMetadata, useJsonFixture, prepareTestTransaction, testUserAccountId, } from '../_helpers';
|
23
|
-
import Client 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 a persisted sessions', async () => {
|
63
|
-
const checkPersistedStateSpy = jest.spyOn(connector, 'checkPersistedState');
|
64
|
-
checkPersistedStateSpy.mockReturnValue([fakeSession]);
|
65
|
-
await connector.init({ logger: 'error' });
|
66
|
-
expect(checkPersistedStateSpy).toHaveBeenCalled();
|
67
|
-
expect(connector.signers[0].getAccountId().toString()).toBe(fakeSession.namespaces.hedera.accounts[0].split(':')[2]);
|
68
|
-
expect(connector.signers[0].topic).toBe(fakeSession.topic);
|
69
|
-
expect(connector.signers[0].getLedgerId()).toBe(LedgerId.TESTNET);
|
70
|
-
checkPersistedStateSpy.mockRestore();
|
71
|
-
});
|
72
|
-
});
|
73
|
-
describe('disconnect', () => {
|
74
|
-
beforeEach(async () => {
|
75
|
-
const checkPersistedStateSpy = jest.spyOn(connector, 'checkPersistedState');
|
76
|
-
checkPersistedStateSpy.mockReturnValue([fakeSession]);
|
77
|
-
await connector.init({ logger: 'error' });
|
78
|
-
checkPersistedStateSpy.mockRestore();
|
79
|
-
});
|
80
|
-
it('should disconnect Client from topic', async () => {
|
81
|
-
const walletConnectDisconnectSpy = jest.spyOn(connector.walletConnectClient, 'disconnect');
|
82
|
-
walletConnectDisconnectSpy.mockImplementation(async () => { });
|
83
|
-
connector.disconnect(fakeSession.topic);
|
84
|
-
expect(walletConnectDisconnectSpy).toHaveBeenCalled();
|
85
|
-
expect(walletConnectDisconnectSpy).toHaveBeenCalledTimes(1);
|
86
|
-
expect(walletConnectDisconnectSpy).toHaveBeenCalledWith(expect.objectContaining({ topic: fakeSession.topic }));
|
87
|
-
walletConnectDisconnectSpy.mockRestore();
|
88
|
-
});
|
89
|
-
});
|
90
|
-
describe('requests', () => {
|
91
|
-
let lastSignerRequestMock;
|
92
|
-
beforeEach(async () => {
|
93
|
-
const checkPersistedStateSpy = jest.spyOn(connector, 'checkPersistedState');
|
94
|
-
checkPersistedStateSpy.mockReturnValue([fakeSession]);
|
95
|
-
await connector.init({ logger: 'error' });
|
96
|
-
checkPersistedStateSpy.mockRestore();
|
97
|
-
lastSignerRequestMock = jest.spyOn(connector.signers[0], 'request');
|
98
|
-
lastSignerRequestMock.mockImplementation(() => { });
|
99
|
-
});
|
100
|
-
afterEach(() => {
|
101
|
-
lastSignerRequestMock.mockRestore();
|
102
|
-
});
|
103
|
-
// 1
|
104
|
-
describe(DAppConnector.prototype.getNodeAddresses, () => {
|
105
|
-
it('should throw an error if there is no any signer', async () => {
|
106
|
-
connector.signers = [];
|
107
|
-
await expect(connector.getNodeAddresses()).rejects.toThrow('There is no active session. Connect to the wallet at first.');
|
108
|
-
});
|
109
|
-
it('should invoke last signer request with correct params', async () => {
|
110
|
-
await connector.getNodeAddresses();
|
111
|
-
expect(lastSignerRequestMock).toHaveBeenCalled();
|
112
|
-
expect(lastSignerRequestMock).toHaveBeenCalledTimes(1);
|
113
|
-
expect(lastSignerRequestMock).toHaveBeenCalledWith({
|
114
|
-
method: HederaJsonRpcMethod.GetNodeAddresses,
|
115
|
-
params: undefined,
|
116
|
-
});
|
117
|
-
});
|
118
|
-
});
|
119
|
-
// 2
|
120
|
-
describe(DAppConnector.prototype.executeTransaction, () => {
|
121
|
-
const transaction = prepareTestTransaction(new TopicCreateTransaction(), { freeze: true });
|
122
|
-
const params = {
|
123
|
-
transactionList: transactionToBase64String(transaction),
|
124
|
-
};
|
125
|
-
it('should throw an error if there is no any signer', async () => {
|
126
|
-
connector.signers = [];
|
127
|
-
await expect(connector.executeTransaction(params)).rejects.toThrow('There is no active session. Connect to the wallet at first.');
|
128
|
-
});
|
129
|
-
it('should invoke last signer request with correct params', async () => {
|
130
|
-
await connector.executeTransaction(params);
|
131
|
-
expect(lastSignerRequestMock).toHaveBeenCalled();
|
132
|
-
expect(lastSignerRequestMock).toHaveBeenCalledTimes(1);
|
133
|
-
expect(lastSignerRequestMock).toHaveBeenCalledWith({
|
134
|
-
method: HederaJsonRpcMethod.ExecuteTransaction,
|
135
|
-
params,
|
136
|
-
});
|
137
|
-
});
|
138
|
-
});
|
139
|
-
// 3
|
140
|
-
describe(DAppConnector.prototype.signMessage, () => {
|
141
|
-
const params = {
|
142
|
-
message: 'test message',
|
143
|
-
signerAccountId: testUserAccountId.toString(),
|
144
|
-
};
|
145
|
-
it('should throw an error if there is no any signer', async () => {
|
146
|
-
connector.signers = [];
|
147
|
-
await expect(connector.signMessage(params)).rejects.toThrow('There is no active session. Connect to the wallet at first.');
|
148
|
-
});
|
149
|
-
it('should invoke last signer request with correct params', async () => {
|
150
|
-
await connector.signMessage(params);
|
151
|
-
expect(lastSignerRequestMock).toHaveBeenCalled();
|
152
|
-
expect(lastSignerRequestMock).toHaveBeenCalledTimes(1);
|
153
|
-
expect(lastSignerRequestMock).toHaveBeenCalledWith({
|
154
|
-
method: HederaJsonRpcMethod.SignMessage,
|
155
|
-
params,
|
156
|
-
});
|
157
|
-
});
|
158
|
-
});
|
159
|
-
// 4
|
160
|
-
describe(DAppConnector.prototype.signAndExecuteQuery, () => {
|
161
|
-
const query = new AccountInfoQuery().setAccountId(testUserAccountId.toString());
|
162
|
-
const params = {
|
163
|
-
signerAccountId: testUserAccountId.toString(),
|
164
|
-
query: queryToBase64String(query),
|
165
|
-
};
|
166
|
-
it('should throw an error if there is no any signer', async () => {
|
167
|
-
connector.signers = [];
|
168
|
-
await expect(connector.signAndExecuteQuery(params)).rejects.toThrow('There is no active session. Connect to the wallet at first.');
|
169
|
-
});
|
170
|
-
it('should invoke last signer request with correct params', async () => {
|
171
|
-
await connector.signAndExecuteQuery(params);
|
172
|
-
expect(lastSignerRequestMock).toHaveBeenCalled();
|
173
|
-
expect(lastSignerRequestMock).toHaveBeenCalledTimes(1);
|
174
|
-
expect(lastSignerRequestMock).toHaveBeenCalledWith({
|
175
|
-
method: HederaJsonRpcMethod.SignAndExecuteQuery,
|
176
|
-
params,
|
177
|
-
});
|
178
|
-
});
|
179
|
-
});
|
180
|
-
// 5
|
181
|
-
describe(DAppConnector.prototype.signAndExecuteTransaction, () => {
|
182
|
-
const transaction = prepareTestTransaction(new TopicCreateTransaction(), { freeze: true });
|
183
|
-
const params = {
|
184
|
-
signerAccountId: testUserAccountId.toString(),
|
185
|
-
transactionList: transactionToBase64String(transaction),
|
186
|
-
};
|
187
|
-
it('should throw an error if there is no any signer', async () => {
|
188
|
-
connector.signers = [];
|
189
|
-
await expect(connector.signAndExecuteTransaction(params)).rejects.toThrow('There is no active session. Connect to the wallet at first.');
|
190
|
-
});
|
191
|
-
it('should invoke last signer request with correct params', async () => {
|
192
|
-
await connector.signAndExecuteTransaction(params);
|
193
|
-
expect(lastSignerRequestMock).toHaveBeenCalled();
|
194
|
-
expect(lastSignerRequestMock).toHaveBeenCalledTimes(1);
|
195
|
-
expect(lastSignerRequestMock).toHaveBeenCalledWith({
|
196
|
-
method: HederaJsonRpcMethod.SignAndExecuteTransaction,
|
197
|
-
params,
|
198
|
-
});
|
199
|
-
});
|
200
|
-
});
|
201
|
-
// 6
|
202
|
-
describe(DAppConnector.prototype.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('There is no active session. Connect to the wallet at first.');
|
211
|
-
});
|
212
|
-
it('should invoke last signer request with correct params', async () => {
|
213
|
-
await connector.signTransaction(params);
|
214
|
-
expect(lastSignerRequestMock).toHaveBeenCalled();
|
215
|
-
expect(lastSignerRequestMock).toHaveBeenCalledTimes(1);
|
216
|
-
expect(lastSignerRequestMock).toHaveBeenCalledWith({
|
217
|
-
method: HederaJsonRpcMethod.SignTransaction,
|
218
|
-
params,
|
219
|
-
});
|
220
|
-
});
|
221
|
-
});
|
222
|
-
});
|
223
|
-
// describe('connect', () => {
|
224
|
-
// it('should establish connection and create session', async () => {
|
225
|
-
// connector = new DAppConnector(appMetadata, LedgerId.TESTNET, PROJECT_ID)
|
226
|
-
// await connector.init()
|
227
|
-
// expect(connector.walletConnectClient).not.toBeNull()
|
228
|
-
// await connector.connect((pairing) => {
|
229
|
-
// console.log('PairingString: ', pairing)
|
230
|
-
// })
|
231
|
-
// expect(connector.walletConnectClient?.session.getAll()).toHaveLength(1)
|
232
|
-
// }, 60_000)
|
233
|
-
// })
|
234
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|