@hashgraph/hedera-wallet-connect 1.3.8-canary.a98a883.0 → 1.3.8-canary.bff54fe.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,6 @@ import { AccountBalance, AccountId, AccountInfo, LedgerId, SignerSignature, Tran
|
|
21
21
|
import { proto } from '@hashgraph/proto';
|
22
22
|
import { HederaJsonRpcMethod, base64StringToSignatureMap, base64StringToUint8Array, ledgerIdToCAIPChainId, queryToBase64String, transactionBodyToBase64String, transactionToBase64String, transactionToTransactionBody, extensionOpen, Uint8ArrayToBase64String, Uint8ArrayToString, } from '../shared';
|
23
23
|
import { DefaultLogger } from '../shared/logger';
|
24
|
-
import { SessionNotFoundError } from './SessionNotFoundError';
|
25
24
|
const clients = {};
|
26
25
|
export class DAppSigner {
|
27
26
|
constructor(accountId, signClient, topic, ledgerId = LedgerId.MAINNET, extensionId, logLevel = 'debug') {
|
@@ -61,10 +60,6 @@ export class DAppSigner {
|
|
61
60
|
return allNodes.slice(0, numberOfNodes);
|
62
61
|
}
|
63
62
|
request(request) {
|
64
|
-
// Avoid a wallet call if the session is no longer valid
|
65
|
-
if (!this.signClient.session.get(this.topic)) {
|
66
|
-
throw new SessionNotFoundError('Session no longer exists. Please reconnect to the wallet.');
|
67
|
-
}
|
68
63
|
if (this.extensionId)
|
69
64
|
extensionOpen(this.extensionId);
|
70
65
|
return this.signClient.request({
|
@@ -169,10 +164,6 @@ export class DAppSigner {
|
|
169
164
|
}
|
170
165
|
async _tryExecuteTransactionRequest(request) {
|
171
166
|
try {
|
172
|
-
// Verify session is still valid before proceeding
|
173
|
-
if (!this.signClient.session.get(this.topic)) {
|
174
|
-
throw new Error('Session no longer exists. Please reconnect to the wallet.');
|
175
|
-
}
|
176
167
|
const requestToBytes = request.toBytes();
|
177
168
|
this.logger.debug('Creating transaction from bytes', requestToBytes, request);
|
178
169
|
const transaction = Transaction.fromBytes(requestToBytes);
|
@@ -188,22 +179,7 @@ export class DAppSigner {
|
|
188
179
|
return { result: TransactionResponse.fromJSON(result) };
|
189
180
|
}
|
190
181
|
catch (error) {
|
191
|
-
|
192
|
-
if (error instanceof SessionNotFoundError) {
|
193
|
-
this.logger.error('Session was deleted, removing signer');
|
194
|
-
// Notify DAppConnector to remove this signer
|
195
|
-
this.signClient.emit({
|
196
|
-
topic: this.topic,
|
197
|
-
event: {
|
198
|
-
name: 'session_delete',
|
199
|
-
data: { topic: this.topic },
|
200
|
-
},
|
201
|
-
chainId: ledgerIdToCAIPChainId(this.ledgerId),
|
202
|
-
});
|
203
|
-
}
|
204
|
-
else {
|
205
|
-
this.logger.error('Error executing transaction request:', error);
|
206
|
-
}
|
182
|
+
this.logger.error('Error executing transaction request:', error);
|
207
183
|
return { error };
|
208
184
|
}
|
209
185
|
}
|
@@ -279,7 +255,6 @@ export class DAppSigner {
|
|
279
255
|
return { result: this._parseQueryResponse(query, result.response) };
|
280
256
|
}
|
281
257
|
catch (error) {
|
282
|
-
this.logger.error('Error executing query request:', error);
|
283
258
|
return { error };
|
284
259
|
}
|
285
260
|
}
|
package/dist/lib/dapp/index.d.ts
CHANGED
@@ -79,10 +79,9 @@ export declare class DAppConnector {
|
|
79
79
|
*/
|
80
80
|
connectExtension(extensionId: string, pairingTopic?: string): Promise<SessionTypes.Struct>;
|
81
81
|
/**
|
82
|
-
* Validates the session by checking if the session exists
|
83
|
-
* Also ensures the signer exists for the session.
|
82
|
+
* Validates the session by checking if the session exists.
|
84
83
|
* @param topic - The topic of the session to validate.
|
85
|
-
* @returns {boolean} - True if the session exists
|
84
|
+
* @returns {boolean} - True if the session exists, false otherwise.
|
86
85
|
*/
|
87
86
|
private validateSession;
|
88
87
|
/**
|
package/dist/lib/dapp/index.js
CHANGED
@@ -113,8 +113,6 @@ export class DAppConnector {
|
|
113
113
|
this.walletConnectClient.on('session_event', this.handleSessionEvent.bind(this));
|
114
114
|
this.walletConnectClient.on('session_update', this.handleSessionUpdate.bind(this));
|
115
115
|
this.walletConnectClient.on('session_delete', this.handleSessionDelete.bind(this));
|
116
|
-
// Listen for custom session_delete events from DAppSigner
|
117
|
-
this.walletConnectClient.core.events.on('session_delete', this.handleSessionDelete.bind(this));
|
118
116
|
this.walletConnectClient.core.pairing.events.on('pairing_delete', this.handlePairingDelete.bind(this));
|
119
117
|
}
|
120
118
|
catch (e) {
|
@@ -219,10 +217,9 @@ export class DAppConnector {
|
|
219
217
|
}, pairingTopic, extension.availableInIframe ? undefined : extensionId);
|
220
218
|
}
|
221
219
|
/**
|
222
|
-
* Validates the session by checking if the session exists
|
223
|
-
* Also ensures the signer exists for the session.
|
220
|
+
* Validates the session by checking if the session exists.
|
224
221
|
* @param topic - The topic of the session to validate.
|
225
|
-
* @returns {boolean} - True if the session exists
|
222
|
+
* @returns {boolean} - True if the session exists, false otherwise.
|
226
223
|
*/
|
227
224
|
validateSession(topic) {
|
228
225
|
try {
|
@@ -231,23 +228,11 @@ export class DAppConnector {
|
|
231
228
|
}
|
232
229
|
const session = this.walletConnectClient.session.get(topic);
|
233
230
|
if (!session) {
|
234
|
-
// If session doesn't exist but we have a signer for it, clean up
|
235
|
-
const hasSigner = this.signers.some((signer) => signer.topic === topic);
|
236
|
-
if (hasSigner) {
|
237
|
-
this.handleSessionDelete({ topic });
|
238
|
-
}
|
239
|
-
return false;
|
240
|
-
}
|
241
|
-
// Verify we have a signer for this session
|
242
|
-
const hasSigner = this.signers.some((signer) => signer.topic === topic);
|
243
|
-
if (!hasSigner) {
|
244
|
-
this.logger.warn(`Session exists but no signer found for topic: ${topic}`);
|
245
231
|
return false;
|
246
232
|
}
|
247
233
|
return true;
|
248
234
|
}
|
249
|
-
catch (
|
250
|
-
this.logger.error('Error validating session:', e);
|
235
|
+
catch (_a) {
|
251
236
|
return false;
|
252
237
|
}
|
253
238
|
}
|
@@ -536,24 +521,14 @@ export class DAppConnector {
|
|
536
521
|
}
|
537
522
|
handleSessionDelete(event) {
|
538
523
|
this.logger.info('Session deleted:', event);
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
return false;
|
546
|
-
});
|
547
|
-
// prevent emitting disconnected event if signers is untouched.
|
548
|
-
if (deletedSigner) {
|
549
|
-
try {
|
550
|
-
this.disconnect(event.topic);
|
551
|
-
}
|
552
|
-
catch (e) {
|
553
|
-
this.logger.error('Error disconnecting session:', e);
|
554
|
-
}
|
555
|
-
this.logger.info('Session deleted and signer removed');
|
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);
|
556
530
|
}
|
531
|
+
this.logger.info('Session deleted by wallet');
|
557
532
|
}
|
558
533
|
handlePairingDelete(event) {
|
559
534
|
this.logger.info('Pairing deleted:', event);
|
package/package.json
CHANGED