@hashgraph/hedera-wallet-connect 1.3.6-canary.1df28dc.0 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{src/lib → lib}/dapp/DAppSigner.d.ts +2 -1
- package/dist/{src/lib → lib}/dapp/DAppSigner.js +3 -0
- package/dist/{src/lib → lib}/dapp/index.d.ts +24 -3
- package/dist/{src/lib → lib}/dapp/index.js +143 -46
- package/dist/lib/shared/logger.d.ts +15 -0
- package/dist/lib/shared/logger.js +29 -0
- package/dist/{src/lib → lib}/shared/utils.d.ts +2 -2
- package/dist/{src/lib → lib}/shared/utils.js +2 -2
- package/package.json +7 -4
- 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/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/index.js → index.js} +0 -0
- /package/dist/{src/lib → lib}/index.d.ts +0 -0
- /package/dist/{src/lib → lib}/index.js +0 -0
- /package/dist/{src/lib → lib}/shared/chainIds.d.ts +0 -0
- /package/dist/{src/lib → lib}/shared/chainIds.js +0 -0
- /package/dist/{src/lib → lib}/shared/errors.d.ts +0 -0
- /package/dist/{src/lib → lib}/shared/errors.js +0 -0
- /package/dist/{src/lib → lib}/shared/events.d.ts +0 -0
- /package/dist/{src/lib → lib}/shared/events.js +0 -0
- /package/dist/{src/lib → lib}/shared/extensionController.d.ts +0 -0
- /package/dist/{src/lib → lib}/shared/extensionController.js +0 -0
- /package/dist/{src/lib → lib}/shared/index.d.ts +0 -0
- /package/dist/{src/lib → lib}/shared/index.js +0 -0
- /package/dist/{src/lib → lib}/shared/methods.d.ts +0 -0
- /package/dist/{src/lib → lib}/shared/methods.js +0 -0
- /package/dist/{src/lib → lib}/shared/payloads.d.ts +0 -0
- /package/dist/{src/lib → lib}/shared/payloads.js +0 -0
- /package/dist/{src/lib → lib}/wallet/index.d.ts +0 -0
- /package/dist/{src/lib → lib}/wallet/index.js +0 -0
- /package/dist/{src/lib → lib}/wallet/provider.d.ts +0 -0
- /package/dist/{src/lib → lib}/wallet/provider.js +0 -0
- /package/dist/{src/lib → lib}/wallet/types.d.ts +0 -0
- /package/dist/{src/lib → lib}/wallet/types.js +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Signer, AccountBalance, AccountId, AccountInfo, Executable, Key, LedgerId, SignerSignature, Transaction, TransactionRecord } from '@hashgraph/sdk';
|
2
|
-
import type { ISignClient } from '@walletconnect/types';
|
2
|
+
import type { CoreTypes, ISignClient } from '@walletconnect/types';
|
3
3
|
export declare class DAppSigner implements Signer {
|
4
4
|
private readonly accountId;
|
5
5
|
private readonly signClient;
|
@@ -24,6 +24,7 @@ export declare class DAppSigner implements Signer {
|
|
24
24
|
getAccountBalance(): Promise<AccountBalance>;
|
25
25
|
getAccountInfo(): Promise<AccountInfo>;
|
26
26
|
getAccountRecords(): Promise<TransactionRecord[]>;
|
27
|
+
getMetadata(): CoreTypes.Metadata;
|
27
28
|
sign(data: Uint8Array[], signOptions?: Record<string, any>): Promise<SignerSignature[]>;
|
28
29
|
checkTransaction<T extends Transaction>(transaction: T): Promise<T>;
|
29
30
|
populateTransaction<T extends Transaction>(transaction: T): Promise<T>;
|
@@ -81,6 +81,9 @@ export class DAppSigner {
|
|
81
81
|
getAccountRecords() {
|
82
82
|
return this.call(new AccountRecordsQuery().setAccountId(this.accountId));
|
83
83
|
}
|
84
|
+
getMetadata() {
|
85
|
+
return this.signClient.metadata;
|
86
|
+
}
|
84
87
|
async sign(data, signOptions) {
|
85
88
|
const { signatureMap } = await this.request({
|
86
89
|
method: HederaJsonRpcMethod.SignMessage,
|
@@ -7,6 +7,7 @@ import { DAppSigner } from './DAppSigner';
|
|
7
7
|
export * from './DAppSigner';
|
8
8
|
type BaseLogger = 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'fatal';
|
9
9
|
export declare class DAppConnector {
|
10
|
+
private logger;
|
10
11
|
dAppMetadata: SignClientTypes.Metadata;
|
11
12
|
network: LedgerId;
|
12
13
|
projectId: string;
|
@@ -27,8 +28,14 @@ export declare class DAppConnector {
|
|
27
28
|
* @param methods - Array of supported methods for the DApp (optional).
|
28
29
|
* @param events - Array of supported events for the DApp (optional).
|
29
30
|
* @param chains - Array of supported chains for the DApp (optional).
|
31
|
+
* @param logLevel - Logging level for the DAppConnector (optional).
|
30
32
|
*/
|
31
|
-
constructor(metadata: SignClientTypes.Metadata, network: LedgerId, projectId: string, methods?: string[], events?: string[], chains?: string[]);
|
33
|
+
constructor(metadata: SignClientTypes.Metadata, network: LedgerId, projectId: string, methods?: string[], events?: string[], chains?: string[], logLevel?: 'error' | 'warn' | 'info' | 'debug');
|
34
|
+
/**
|
35
|
+
* Sets the logging level for the DAppConnector
|
36
|
+
* @param level - The logging level to set
|
37
|
+
*/
|
38
|
+
setLogLevel(level: 'error' | 'warn' | 'info' | 'debug'): void;
|
32
39
|
/**
|
33
40
|
* Initializes the DAppConnector instance.
|
34
41
|
* @param logger - `BaseLogger` for logging purposes (optional).
|
@@ -71,6 +78,16 @@ export declare class DAppConnector {
|
|
71
78
|
* @returns A Promise that resolves when the connection process is complete.
|
72
79
|
*/
|
73
80
|
connectExtension(extensionId: string, pairingTopic?: string): Promise<SessionTypes.Struct>;
|
81
|
+
/**
|
82
|
+
* Validates the session by checking if the session exists.
|
83
|
+
* @param topic - The topic of the session to validate.
|
84
|
+
* @returns {boolean} - True if the session exists, false otherwise.
|
85
|
+
*/
|
86
|
+
private validateSession;
|
87
|
+
/**
|
88
|
+
* Validates the session and refreshes the signers by removing the invalid ones.
|
89
|
+
*/
|
90
|
+
private validateAndRefreshSigners;
|
74
91
|
/**
|
75
92
|
* Initiates the WallecConnect connection if the wallet in iframe mode is detected.
|
76
93
|
*/
|
@@ -81,7 +98,7 @@ export declare class DAppConnector {
|
|
81
98
|
* @param topic - The topic of the session to disconnect.
|
82
99
|
* @returns A Promise that resolves when the session is disconnected.
|
83
100
|
*/
|
84
|
-
disconnect(topic: string): Promise<
|
101
|
+
disconnect(topic: string): Promise<boolean>;
|
85
102
|
/**
|
86
103
|
* Disconnects all active sessions and pairings.
|
87
104
|
*
|
@@ -127,7 +144,7 @@ export declare class DAppConnector {
|
|
127
144
|
* @example
|
128
145
|
* ```ts
|
129
146
|
* const params = {
|
130
|
-
* signerAccountId: '0.0.12345',
|
147
|
+
* signerAccountId: 'hedera:testnet:0.0.12345',
|
131
148
|
* message: 'Hello World!'
|
132
149
|
* }
|
133
150
|
*
|
@@ -194,5 +211,9 @@ export declare class DAppConnector {
|
|
194
211
|
* ```
|
195
212
|
*/
|
196
213
|
signTransaction(params: SignTransactionParams): Promise<SignTransactionResult>;
|
214
|
+
private handleSessionEvent;
|
215
|
+
private handleSessionUpdate;
|
216
|
+
private handleSessionDelete;
|
217
|
+
private handlePairingDelete;
|
197
218
|
}
|
198
219
|
export default DAppConnector;
|
@@ -22,6 +22,7 @@ import QRCodeModal from '@walletconnect/qrcode-modal';
|
|
22
22
|
import { WalletConnectModal } from '@walletconnect/modal';
|
23
23
|
import SignClient from '@walletconnect/sign-client';
|
24
24
|
import { getSdkError } from '@walletconnect/utils';
|
25
|
+
import { DefaultLogger } from '../shared/logger';
|
25
26
|
import { HederaJsonRpcMethod, accountAndLedgerFromSession, networkNamespaces, extensionConnect, findExtensions, } from '../shared';
|
26
27
|
import { DAppSigner } from './DAppSigner';
|
27
28
|
export * from './DAppSigner';
|
@@ -34,8 +35,9 @@ export class DAppConnector {
|
|
34
35
|
* @param methods - Array of supported methods for the DApp (optional).
|
35
36
|
* @param events - Array of supported events for the DApp (optional).
|
36
37
|
* @param chains - Array of supported chains for the DApp (optional).
|
38
|
+
* @param logLevel - Logging level for the DAppConnector (optional).
|
37
39
|
*/
|
38
|
-
constructor(metadata, network, projectId, methods, events, chains) {
|
40
|
+
constructor(metadata, network, projectId, methods, events, chains, logLevel = 'debug') {
|
39
41
|
this.network = LedgerId.TESTNET;
|
40
42
|
this.supportedMethods = [];
|
41
43
|
this.supportedEvents = [];
|
@@ -62,6 +64,7 @@ export class DAppConnector {
|
|
62
64
|
}
|
63
65
|
});
|
64
66
|
};
|
67
|
+
this.logger = new DefaultLogger(logLevel);
|
65
68
|
this.dAppMetadata = metadata;
|
66
69
|
this.network = network;
|
67
70
|
this.projectId = projectId;
|
@@ -77,6 +80,15 @@ export class DAppConnector {
|
|
77
80
|
this.extensions.push(Object.assign(Object.assign({}, metadata), { available: true, availableInIframe: isIframe }));
|
78
81
|
});
|
79
82
|
}
|
83
|
+
/**
|
84
|
+
* Sets the logging level for the DAppConnector
|
85
|
+
* @param level - The logging level to set
|
86
|
+
*/
|
87
|
+
setLogLevel(level) {
|
88
|
+
if (this.logger instanceof DefaultLogger) {
|
89
|
+
this.logger.setLogLevel(level);
|
90
|
+
}
|
91
|
+
}
|
80
92
|
/**
|
81
93
|
* Initializes the DAppConnector instance.
|
82
94
|
* @param logger - `BaseLogger` for logging purposes (optional).
|
@@ -98,43 +110,13 @@ export class DAppConnector {
|
|
98
110
|
this.signers = existingSessions.flatMap((session) => this.createSigners(session));
|
99
111
|
else
|
100
112
|
this.checkIframeConnect();
|
101
|
-
this.walletConnectClient.on('session_event', (
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
const _session = this.walletConnectClient.session.get(topic);
|
109
|
-
// Overwrite the `namespaces` of the existing session with the incoming one.
|
110
|
-
const updatedSession = Object.assign(Object.assign({}, _session), { namespaces });
|
111
|
-
// Integrate the updated session state into your dapp state.
|
112
|
-
console.log(updatedSession);
|
113
|
-
});
|
114
|
-
this.walletConnectClient.on('session_delete', (pairing) => {
|
115
|
-
console.log(pairing);
|
116
|
-
this.signers = this.signers.filter((signer) => signer.topic !== pairing.topic);
|
117
|
-
// Session was deleted -> reset the dapp state, clean up from user session, etc.
|
118
|
-
try {
|
119
|
-
this.disconnect(pairing.topic);
|
120
|
-
}
|
121
|
-
catch (e) {
|
122
|
-
console.error(e);
|
123
|
-
}
|
124
|
-
console.log('Dapp: Session deleted by wallet!');
|
125
|
-
});
|
126
|
-
this.walletConnectClient.core.pairing.events.on('pairing_delete', (pairing) => {
|
127
|
-
console.log(pairing);
|
128
|
-
this.signers = this.signers.filter((signer) => signer.topic !== pairing.topic);
|
129
|
-
try {
|
130
|
-
this.disconnect(pairing.topic);
|
131
|
-
}
|
132
|
-
catch (e) {
|
133
|
-
console.error(e);
|
134
|
-
}
|
135
|
-
console.log(`Dapp: Pairing deleted by wallet!`);
|
136
|
-
// clean up after the pairing for `topic` was deleted.
|
137
|
-
});
|
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));
|
117
|
+
}
|
118
|
+
catch (e) {
|
119
|
+
this.logger.error('Error initializing DAppConnector:', e);
|
138
120
|
}
|
139
121
|
finally {
|
140
122
|
this.isInitializing = false;
|
@@ -148,6 +130,9 @@ export class DAppConnector {
|
|
148
130
|
* @throws {Error} - If no signer is found for the provided account ID.
|
149
131
|
*/
|
150
132
|
getSigner(accountId) {
|
133
|
+
if (this.isInitializing) {
|
134
|
+
throw new Error('DAppConnector is not initialized yet. Try again later.');
|
135
|
+
}
|
151
136
|
const signer = this.signers.find((signer) => signer.getAccountId().equals(accountId));
|
152
137
|
if (!signer)
|
153
138
|
throw new Error('Signer is not found for this accountId');
|
@@ -231,6 +216,32 @@ export class DAppConnector {
|
|
231
216
|
extensionConnect(extension.id, extension.availableInIframe, uri);
|
232
217
|
}, pairingTopic, extension.availableInIframe ? undefined : extensionId);
|
233
218
|
}
|
219
|
+
/**
|
220
|
+
* Validates the session by checking if the session exists.
|
221
|
+
* @param topic - The topic of the session to validate.
|
222
|
+
* @returns {boolean} - True if the session exists, false otherwise.
|
223
|
+
*/
|
224
|
+
validateSession(topic) {
|
225
|
+
try {
|
226
|
+
if (!this.walletConnectClient) {
|
227
|
+
return false;
|
228
|
+
}
|
229
|
+
const session = this.walletConnectClient.session.get(topic);
|
230
|
+
if (!session) {
|
231
|
+
return false;
|
232
|
+
}
|
233
|
+
return true;
|
234
|
+
}
|
235
|
+
catch (_a) {
|
236
|
+
return false;
|
237
|
+
}
|
238
|
+
}
|
239
|
+
/**
|
240
|
+
* Validates the session and refreshes the signers by removing the invalid ones.
|
241
|
+
*/
|
242
|
+
validateAndRefreshSigners() {
|
243
|
+
this.signers = this.signers.filter((signer) => this.validateSession(signer.topic));
|
244
|
+
}
|
234
245
|
/**
|
235
246
|
* Initiates the WallecConnect connection if the wallet in iframe mode is detected.
|
236
247
|
*/
|
@@ -248,10 +259,20 @@ export class DAppConnector {
|
|
248
259
|
* @returns A Promise that resolves when the session is disconnected.
|
249
260
|
*/
|
250
261
|
async disconnect(topic) {
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
262
|
+
try {
|
263
|
+
if (!this.walletConnectClient) {
|
264
|
+
throw new Error('WalletConnect is not initialized');
|
265
|
+
}
|
266
|
+
await this.walletConnectClient.disconnect({
|
267
|
+
topic: topic,
|
268
|
+
reason: getSdkError('USER_DISCONNECTED'),
|
269
|
+
});
|
270
|
+
return true;
|
271
|
+
}
|
272
|
+
catch (e) {
|
273
|
+
this.logger.error('Either the session was already disconnected or the topic is invalid', e);
|
274
|
+
return false;
|
275
|
+
}
|
255
276
|
}
|
256
277
|
/**
|
257
278
|
* Disconnects all active sessions and pairings.
|
@@ -271,7 +292,7 @@ export class DAppConnector {
|
|
271
292
|
const disconnectionPromises = [];
|
272
293
|
// disconnect sessions
|
273
294
|
for (const session of this.walletConnectClient.session.getAll()) {
|
274
|
-
|
295
|
+
this.logger.info(`Disconnecting from session: ${session}`);
|
275
296
|
const promise = this.disconnect(session.topic);
|
276
297
|
disconnectionPromises.push(promise);
|
277
298
|
}
|
@@ -292,7 +313,34 @@ export class DAppConnector {
|
|
292
313
|
});
|
293
314
|
}
|
294
315
|
async onSessionConnected(session) {
|
295
|
-
this.
|
316
|
+
const newSigners = this.createSigners(session);
|
317
|
+
// Filter out any existing signers with duplicate AccountIds
|
318
|
+
for (const newSigner of newSigners) {
|
319
|
+
// We check if any signers have the same account, extension + metadata name.
|
320
|
+
const existingSigners = this.signers.filter((currentSigner) => {
|
321
|
+
var _a, _b;
|
322
|
+
const matchingAccountId = ((_a = currentSigner === null || currentSigner === void 0 ? void 0 : currentSigner.getAccountId()) === null || _a === void 0 ? void 0 : _a.toString()) === ((_b = newSigner === null || newSigner === void 0 ? void 0 : newSigner.getAccountId()) === null || _b === void 0 ? void 0 : _b.toString());
|
323
|
+
const matchingExtensionId = newSigner.extensionId === currentSigner.extensionId;
|
324
|
+
const newSignerMetadata = newSigner.getMetadata();
|
325
|
+
const existingSignerMetadata = currentSigner.getMetadata();
|
326
|
+
const metadataNameMatch = (newSignerMetadata === null || newSignerMetadata === void 0 ? void 0 : newSignerMetadata.name) === (existingSignerMetadata === null || existingSignerMetadata === void 0 ? void 0 : existingSignerMetadata.name);
|
327
|
+
if (currentSigner.topic === newSigner.topic) {
|
328
|
+
this.logger.error('The topic was already connected. This is a weird error. Please report it.', newSigner.getAccountId().toString());
|
329
|
+
}
|
330
|
+
return matchingAccountId && matchingExtensionId && metadataNameMatch;
|
331
|
+
});
|
332
|
+
// Any dupes get disconnected + removed from the signers array.
|
333
|
+
for (const existingSigner of existingSigners) {
|
334
|
+
this.logger.debug(`Disconnecting duplicate signer for account ${existingSigner.getAccountId().toString()}`);
|
335
|
+
await this.disconnect(existingSigner.topic);
|
336
|
+
this.signers = this.signers.filter((s) => s.topic !== existingSigner.topic);
|
337
|
+
}
|
338
|
+
}
|
339
|
+
// Add new signers after all duplicates have been cleaned up
|
340
|
+
this.signers.push(...newSigners);
|
341
|
+
this.logger.debug(`Current signers after connection: ${this.signers
|
342
|
+
.map((s) => `${s.getAccountId().toString()}:${s.topic}`)
|
343
|
+
.join(', ')}`);
|
296
344
|
}
|
297
345
|
async connectURI(pairingTopic) {
|
298
346
|
if (!this.walletConnectClient) {
|
@@ -304,10 +352,25 @@ export class DAppConnector {
|
|
304
352
|
});
|
305
353
|
}
|
306
354
|
async request({ method, params, }) {
|
307
|
-
|
355
|
+
var _a, _b, _c;
|
356
|
+
let signer;
|
357
|
+
this.logger.debug(`Requesting method: ${method} with params: ${JSON.stringify(params)}`);
|
358
|
+
if (params === null || params === void 0 ? void 0 : params.signerAccountId) {
|
359
|
+
// Extract the actual account ID from the hedera:<network>:<address> format
|
360
|
+
const actualAccountId = (_b = (_a = params === null || params === void 0 ? void 0 : params.signerAccountId) === null || _a === void 0 ? void 0 : _a.split(':')) === null || _b === void 0 ? void 0 : _b.pop();
|
361
|
+
signer = this.signers.find((s) => { var _a; return ((_a = s === null || s === void 0 ? void 0 : s.getAccountId()) === null || _a === void 0 ? void 0 : _a.toString()) === actualAccountId; });
|
362
|
+
this.logger.debug(`Found signer: ${(_c = signer === null || signer === void 0 ? void 0 : signer.getAccountId()) === null || _c === void 0 ? void 0 : _c.toString()}`);
|
363
|
+
if (!signer) {
|
364
|
+
throw new Error(`Signer not found for account ID: ${params === null || params === void 0 ? void 0 : params.signerAccountId}. Did you use the correct format? e.g hedera:<network>:<address> `);
|
365
|
+
}
|
366
|
+
}
|
367
|
+
else {
|
368
|
+
signer = this.signers[this.signers.length - 1];
|
369
|
+
}
|
308
370
|
if (!signer) {
|
309
371
|
throw new Error('There is no active session. Connect to the wallet at first.');
|
310
372
|
}
|
373
|
+
this.logger.debug(`Using signer: ${signer.getAccountId().toString()}: ${signer.topic} - about to request.`);
|
311
374
|
return await signer.request({
|
312
375
|
method: method,
|
313
376
|
params: params,
|
@@ -357,7 +420,7 @@ export class DAppConnector {
|
|
357
420
|
* @example
|
358
421
|
* ```ts
|
359
422
|
* const params = {
|
360
|
-
* signerAccountId: '0.0.12345',
|
423
|
+
* signerAccountId: 'hedera:testnet:0.0.12345',
|
361
424
|
* message: 'Hello World!'
|
362
425
|
* }
|
363
426
|
*
|
@@ -444,5 +507,39 @@ export class DAppConnector {
|
|
444
507
|
params,
|
445
508
|
});
|
446
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
|
+
}
|
447
544
|
}
|
448
545
|
export default DAppConnector;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export interface ILogger {
|
2
|
+
error(message: string, ...args: any[]): void;
|
3
|
+
warn(message: string, ...args: any[]): void;
|
4
|
+
info(message: string, ...args: any[]): void;
|
5
|
+
debug(message: string, ...args: any[]): void;
|
6
|
+
}
|
7
|
+
export declare class DefaultLogger implements ILogger {
|
8
|
+
private logLevel;
|
9
|
+
constructor(logLevel?: 'error' | 'warn' | 'info' | 'debug');
|
10
|
+
setLogLevel(level: 'error' | 'warn' | 'info' | 'debug'): void;
|
11
|
+
error(message: string, ...args: any[]): void;
|
12
|
+
warn(message: string, ...args: any[]): void;
|
13
|
+
info(message: string, ...args: any[]): void;
|
14
|
+
debug(message: string, ...args: any[]): void;
|
15
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
export class DefaultLogger {
|
2
|
+
constructor(logLevel = 'info') {
|
3
|
+
this.logLevel = 'info';
|
4
|
+
this.logLevel = logLevel;
|
5
|
+
}
|
6
|
+
setLogLevel(level) {
|
7
|
+
this.logLevel = level;
|
8
|
+
}
|
9
|
+
error(message, ...args) {
|
10
|
+
if (['error', 'warn', 'info', 'debug'].includes(this.logLevel)) {
|
11
|
+
console.error(`[ERROR] ${message}`, ...args);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
warn(message, ...args) {
|
15
|
+
if (['warn', 'info', 'debug'].includes(this.logLevel)) {
|
16
|
+
console.warn(`[WARN] ${message}`, ...args);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
info(message, ...args) {
|
20
|
+
if (['info', 'debug'].includes(this.logLevel)) {
|
21
|
+
console.info(`[INFO] ${message}`, ...args);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
debug(message, ...args) {
|
25
|
+
if (this.logLevel === 'debug') {
|
26
|
+
console.debug(`[DEBUG] ${message}`, ...args);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
@@ -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): any;
|
53
|
+
export declare function transactionBodyToBase64String(transactionBody: proto.ITransactionBody): 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._makeTransactionBody(nodeAccountId);
|
90
90
|
}
|
91
91
|
export function transactionBodyToBase64String(transactionBody) {
|
92
|
-
return Uint8ArrayToBase64String(transactionBody);
|
92
|
+
return Uint8ArrayToBase64String(proto.TransactionBody.encode(transactionBody).finish());
|
93
93
|
}
|
94
94
|
/**
|
95
95
|
* @param transactionList - a proto.TransactionList object
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hashgraph/hedera-wallet-connect",
|
3
|
-
"version": "1.3.6
|
3
|
+
"version": "1.3.6",
|
4
4
|
"description": "A library to facilitate integrating Hedera with WalletConnect",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
7
7
|
"url": "git+https://github.com/hashgraph/hedera-wallet-connect.git"
|
8
8
|
},
|
9
|
-
"main": "./dist/
|
10
|
-
"types": "./dist/
|
9
|
+
"main": "./dist/index.js",
|
10
|
+
"types": "./dist/index.d.ts",
|
11
11
|
"author": "Hgraph <support@hgraph.io>",
|
12
12
|
"keywords": [
|
13
13
|
"hedera",
|
@@ -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/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 {};
|