@hashgraph/hedera-wallet-connect 2.0.3-canary.3ed25cd.0 → 2.0.4-canary.46d8648.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.
package/README.md CHANGED
@@ -215,7 +215,6 @@ createAppKit({
215
215
 
216
216
  - [Hashpack](https://hashpack.app/)
217
217
  - [Kabila](https://wallet.kabila.app/)
218
- - [Blade](https://bladewallet.io/)
219
218
  - [Dropp](https://dropp.cc/)
220
219
 
221
220
  # Upgrading from v1 to v2
@@ -355,9 +355,17 @@ export class DAppConnector {
355
355
  if (!this.walletConnectClient) {
356
356
  throw new Error('WalletConnect is not initialized');
357
357
  }
358
+ const requiredNamespaces = networkNamespaces(this.network, this.supportedMethods, this.supportedEvents);
359
+ this.logger.debug('V1 DAppConnector: Connecting with params:', {
360
+ network: this.network.toString(),
361
+ pairingTopic,
362
+ requiredNamespaces,
363
+ supportedMethods: this.supportedMethods,
364
+ supportedEvents: this.supportedEvents,
365
+ });
358
366
  return this.walletConnectClient.connect({
359
367
  pairingTopic,
360
- requiredNamespaces: networkNamespaces(this.network, this.supportedMethods, this.supportedEvents),
368
+ requiredNamespaces,
361
369
  });
362
370
  }
363
371
  async request({ method, params, }) {
@@ -16,3 +16,6 @@ export declare class DefaultLogger implements ILogger {
16
16
  info(message: string, ...args: any[]): void;
17
17
  debug(message: string, ...args: any[]): void;
18
18
  }
19
+ export declare function setGlobalLogLevel(level: LogLevel): void;
20
+ export declare function getGlobalLogLevel(): LogLevel;
21
+ export declare function createLogger(name: string, level?: LogLevel): DefaultLogger;
@@ -1,3 +1,4 @@
1
+ var _a;
1
2
  export class DefaultLogger {
2
3
  constructor(logLevel = 'info', name) {
3
4
  this.logLevel = 'info';
@@ -31,3 +32,32 @@ export class DefaultLogger {
31
32
  }
32
33
  }
33
34
  }
35
+ // Global logger configuration
36
+ let globalLogLevel = 'info';
37
+ // Check if environment variable is set
38
+ if (typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.HWC_LOG_LEVEL)) {
39
+ const envLevel = process.env.HWC_LOG_LEVEL.toLowerCase();
40
+ if (['error', 'warn', 'info', 'debug', 'off'].includes(envLevel)) {
41
+ globalLogLevel = envLevel;
42
+ }
43
+ }
44
+ // Check if localStorage is available (browser environment)
45
+ if (typeof localStorage !== 'undefined') {
46
+ const storedLevel = localStorage.getItem('hwc_log_level');
47
+ if (storedLevel && ['error', 'warn', 'info', 'debug', 'off'].includes(storedLevel)) {
48
+ globalLogLevel = storedLevel;
49
+ }
50
+ }
51
+ export function setGlobalLogLevel(level) {
52
+ globalLogLevel = level;
53
+ if (typeof localStorage !== 'undefined') {
54
+ localStorage.setItem('hwc_log_level', level);
55
+ }
56
+ }
57
+ export function getGlobalLogLevel() {
58
+ return globalLogLevel;
59
+ }
60
+ // Factory function to create logger instances
61
+ export function createLogger(name, level) {
62
+ return new DefaultLogger(level || globalLogLevel, name);
63
+ }
@@ -17,7 +17,8 @@ type GetProfileResult = {
17
17
  profileName: string;
18
18
  };
19
19
  export declare class HederaAdapter extends AdapterBlueprint {
20
- constructor(params: AdapterBlueprint.Params);
20
+ private logger;
21
+ constructor(params: HederaAdapter.Params);
21
22
  setUniversalProvider(universalProvider: UniversalProvider): Promise<void>;
22
23
  connect(params: AdapterBlueprint.ConnectParams): Promise<AdapterBlueprint.ConnectResult>;
23
24
  disconnect(_params?: AdapterBlueprint.DisconnectParams): Promise<AdapterBlueprint.DisconnectResult>;
@@ -50,4 +51,9 @@ export declare class HederaAdapter extends AdapterBlueprint {
50
51
  getWalletConnectProvider(): UniversalProvider;
51
52
  walletGetAssets(_params: AdapterBlueprint.WalletGetAssetsParams): Promise<AdapterBlueprint.WalletGetAssetsResponse>;
52
53
  }
54
+ export declare namespace HederaAdapter {
55
+ type Params = AdapterBlueprint.Params & {
56
+ namespaceMode?: 'optional' | 'required';
57
+ };
58
+ }
53
59
  export {};
@@ -6,6 +6,7 @@ import { LedgerId } from '@hashgraph/sdk';
6
6
  import { BrowserProvider, Contract, formatUnits, JsonRpcSigner, parseUnits } from 'ethers';
7
7
  import { HederaConnector } from './connectors';
8
8
  import { hederaNamespace, getAccountBalance } from './utils';
9
+ import { createLogger } from '../lib/shared/logger';
9
10
  export class HederaAdapter extends AdapterBlueprint {
10
11
  constructor(params) {
11
12
  var _a, _b;
@@ -23,6 +24,7 @@ export class HederaAdapter extends AdapterBlueprint {
23
24
  }
24
25
  }
25
26
  super(Object.assign({}, params));
27
+ this.logger = createLogger('HederaAdapter');
26
28
  }
27
29
  async setUniversalProvider(universalProvider) {
28
30
  this.addConnector(new HederaConnector({
@@ -32,6 +34,16 @@ export class HederaAdapter extends AdapterBlueprint {
32
34
  }));
33
35
  }
34
36
  async connect(params) {
37
+ this.logger.debug('connect called with params:', params);
38
+ // Get the WalletConnect connector and ensure it connects with proper namespaces
39
+ const connector = this.getWalletConnectConnector();
40
+ if (connector && 'connectWalletConnect' in connector) {
41
+ this.logger.debug('Calling HederaConnector.connectWalletConnect');
42
+ await connector.connectWalletConnect();
43
+ }
44
+ else {
45
+ this.logger.warn('HederaConnector not found or connectWalletConnect method missing');
46
+ }
35
47
  return Promise.resolve({
36
48
  id: 'WALLET_CONNECT',
37
49
  type: 'WALLET_CONNECT',
@@ -46,7 +58,7 @@ export class HederaAdapter extends AdapterBlueprint {
46
58
  await connector.disconnect();
47
59
  }
48
60
  catch (error) {
49
- console.warn('UniversalAdapter:disconnect - error', error);
61
+ this.logger.warn('disconnect - error', error);
50
62
  }
51
63
  return { connections: [] };
52
64
  }
@@ -10,6 +10,7 @@ export declare class HederaConnector implements ChainAdapterConnector {
10
10
  readonly chain: ChainNamespace;
11
11
  provider: UniversalProvider;
12
12
  protected caipNetworks: CaipNetwork[];
13
+ private logger;
13
14
  constructor({ provider, caipNetworks, namespace }: HederaConnector.Options);
14
15
  get chains(): CaipNetwork[];
15
16
  connectWalletConnect(): Promise<{
@@ -1,12 +1,14 @@
1
1
  import { ConstantsUtil } from '@reown/appkit-common';
2
2
  import { PresetsUtil } from '@reown/appkit-utils';
3
3
  import { createNamespaces } from '../utils';
4
+ import { createLogger } from '../../lib/shared/logger';
4
5
  export class HederaConnector {
5
6
  constructor({ provider, caipNetworks, namespace }) {
6
7
  this.id = ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT;
7
8
  this.name = PresetsUtil.ConnectorNamesMap[ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT];
8
9
  this.type = 'WALLET_CONNECT';
9
10
  this.imageId = PresetsUtil.ConnectorImageIds[ConstantsUtil.CONNECTOR_ID.WALLET_CONNECT];
11
+ this.logger = createLogger('HederaConnector');
10
12
  this.caipNetworks = caipNetworks;
11
13
  this.provider = provider;
12
14
  this.chain = namespace;
@@ -15,11 +17,53 @@ export class HederaConnector {
15
17
  return this.caipNetworks;
16
18
  }
17
19
  async connectWalletConnect() {
20
+ var _a, _b, _c;
21
+ this.logger.debug('connectWalletConnect called for', this.chain);
22
+ this.logger.debug('Provider type:', (_b = (_a = this.provider) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name);
23
+ this.logger.debug('Provider session exists:', !!((_c = this.provider) === null || _c === void 0 ? void 0 : _c.session));
18
24
  const isAuthenticated = await this.authenticate();
25
+ this.logger.debug('Is authenticated:', isAuthenticated);
19
26
  if (!isAuthenticated) {
20
- await this.provider.connect({
21
- optionalNamespaces: createNamespaces(this.caipNetworks),
27
+ // Check for stored connection params from the dApp
28
+ let connectParams = undefined;
29
+ this.logger.debug('Checking for stored params');
30
+ if (typeof window !== 'undefined' && window.sessionStorage) {
31
+ const storedParams = sessionStorage.getItem('hwcV2ConnectionParams');
32
+ this.logger.debug('Stored params in sessionStorage:', storedParams);
33
+ if (storedParams) {
34
+ try {
35
+ connectParams = JSON.parse(storedParams);
36
+ this.logger.info('Using stored connection params from dApp in connector:', connectParams);
37
+ // Don't clear here - let the provider handle it
38
+ }
39
+ catch (e) {
40
+ this.logger.warn('Failed to parse stored connection params in connector:', e);
41
+ }
42
+ }
43
+ }
44
+ // If no stored params, create default namespaces
45
+ if (!connectParams) {
46
+ const namespaces = createNamespaces(this.caipNetworks);
47
+ connectParams = { optionalNamespaces: namespaces };
48
+ this.logger.debug('No stored params, using default namespaces:', connectParams);
49
+ }
50
+ this.logger.debug('Connecting with params:', {
51
+ namespace: this.chain,
52
+ caipNetworks: this.caipNetworks.map((n) => ({
53
+ id: n.id,
54
+ chainNamespace: n.chainNamespace,
55
+ caipNetworkId: n.caipNetworkId,
56
+ name: n.name,
57
+ })),
58
+ connectParams,
22
59
  });
60
+ this.logger.debug('Final params before provider.connect:', connectParams);
61
+ this.logger.debug('Calling provider.connect with params');
62
+ await this.provider.connect(connectParams);
63
+ this.logger.info('Provider.connect completed successfully');
64
+ }
65
+ else {
66
+ this.logger.info('Already authenticated, skipping namespace setup');
23
67
  }
24
68
  return {
25
69
  clientId: await this.provider.client.core.crypto.getClientId(),
@@ -8,6 +8,7 @@ declare class EIP155Provider implements IProvider {
8
8
  namespace: SessionNamespace;
9
9
  httpProviders: RpcProvidersMap;
10
10
  events: EventEmitter;
11
+ private logger;
11
12
  constructor({ client, events, namespace, }: {
12
13
  client: IProvider['client'];
13
14
  events: EventEmitter;
@@ -2,9 +2,11 @@ import { JsonRpcProvider } from '@walletconnect/jsonrpc-provider';
2
2
  import { HttpConnection } from '@walletconnect/jsonrpc-http-connection';
3
3
  import { formatJsonRpcRequest } from '@walletconnect/jsonrpc-utils';
4
4
  import { BUNDLER_URL, getChainId, HederaChainDefinition } from '../utils';
5
+ import { createLogger } from '../../lib/shared/logger';
5
6
  class EIP155Provider {
6
7
  constructor({ client, events, namespace, }) {
7
8
  this.name = 'eip155';
9
+ this.logger = createLogger('EIP155Provider');
8
10
  this.namespace = namespace;
9
11
  this.events = events;
10
12
  this.client = client;
@@ -146,7 +148,7 @@ class EIP155Provider {
146
148
  return await this.getUserOperationReceipt(bundlerUrl, args);
147
149
  }
148
150
  catch (error) {
149
- console.warn('Failed to fetch call status from bundler', error, bundlerUrl);
151
+ this.logger.warn('Failed to fetch call status from bundler', error, bundlerUrl);
150
152
  }
151
153
  }
152
154
  const customUrl = (_b = session.sessionProperties) === null || _b === void 0 ? void 0 : _b.bundler_url;
@@ -155,7 +157,7 @@ class EIP155Provider {
155
157
  return await this.getUserOperationReceipt(customUrl, args);
156
158
  }
157
159
  catch (error) {
158
- console.warn('Failed to fetch call status from custom bundler', error, customUrl);
160
+ this.logger.warn('Failed to fetch call status from custom bundler', error, customUrl);
159
161
  }
160
162
  }
161
163
  if (this.namespace.methods.includes(args.request.method)) {
@@ -11,6 +11,7 @@ export type HederaWalletConnectProviderConfig = {
11
11
  chains: CaipNetwork[];
12
12
  } & UniversalProviderOpts;
13
13
  export declare class HederaProvider extends UniversalProvider {
14
+ private hederaLogger;
14
15
  nativeProvider?: HIP820Provider;
15
16
  eip155Provider?: EIP155Provider;
16
17
  constructor(opts: UniversalProviderOpts);
@@ -157,6 +158,7 @@ export declare class HederaProvider extends UniversalProvider {
157
158
  net_version(): Promise<string>;
158
159
  web3_clientVersion(): Promise<string>;
159
160
  eth_chainId(): Promise<string>;
161
+ connect(params?: any): Promise<any>;
160
162
  pair(pairingTopic: string | undefined): ReturnType<UniversalProvider['pair']>;
161
163
  private initProviders;
162
164
  get rpcProviders(): RpcProviderMap;
@@ -5,23 +5,25 @@ import { HederaJsonRpcMethod, } from '../..';
5
5
  import { getChainsFromApprovedSession, mergeRequiredOptionalNamespaces, } from '../utils';
6
6
  import HIP820Provider from './HIP820Provider';
7
7
  import EIP155Provider from './EIP155Provider';
8
+ import { createLogger } from '../../lib/shared/logger';
8
9
  // Reown AppKit UniversalProvider for HIP-820 & EIP-155 version implementation of the @hashgraph/hedera-wallet-connect DAppConnector
9
10
  export class HederaProvider extends UniversalProvider {
10
11
  constructor(opts) {
11
12
  super(opts);
13
+ this.hederaLogger = createLogger('HederaProvider');
12
14
  }
13
15
  static async init(opts) {
14
- var _a, _b, _c, _d, _e, _f;
16
+ var _a, _b, _c, _d, _e, _f, _g, _h;
15
17
  const provider = new HederaProvider(opts);
16
18
  //@ts-expect-error - private base method
17
19
  await provider.initialize();
18
20
  provider.namespaces = Object.assign(Object.assign({}, (((_a = provider.namespaces) === null || _a === void 0 ? void 0 : _a.eip155)
19
21
  ? {
20
- eip155: Object.assign(Object.assign({}, (_b = provider.namespaces) === null || _b === void 0 ? void 0 : _b.eip155), { rpcMap: (_c = provider.optionalNamespaces) === null || _c === void 0 ? void 0 : _c.eip155.rpcMap }),
22
+ eip155: Object.assign(Object.assign({}, (_b = provider.namespaces) === null || _b === void 0 ? void 0 : _b.eip155), { rpcMap: ((_d = (_c = provider.optionalNamespaces) === null || _c === void 0 ? void 0 : _c.eip155) === null || _d === void 0 ? void 0 : _d.rpcMap) || {} }),
21
23
  }
22
- : {})), (((_d = provider.namespaces) === null || _d === void 0 ? void 0 : _d.hedera)
24
+ : {})), (((_e = provider.namespaces) === null || _e === void 0 ? void 0 : _e.hedera)
23
25
  ? {
24
- hedera: Object.assign(Object.assign({}, (_e = provider.namespaces) === null || _e === void 0 ? void 0 : _e.hedera), { rpcMap: (_f = provider.optionalNamespaces) === null || _f === void 0 ? void 0 : _f.hedera.rpcMap }),
26
+ hedera: Object.assign(Object.assign({}, (_f = provider.namespaces) === null || _f === void 0 ? void 0 : _f.hedera), { rpcMap: ((_h = (_g = provider.optionalNamespaces) === null || _g === void 0 ? void 0 : _g.hedera) === null || _h === void 0 ? void 0 : _h.rpcMap) || {} }),
25
27
  }
26
28
  : {}));
27
29
  if (provider.session)
@@ -411,6 +413,84 @@ export class HederaProvider extends UniversalProvider {
411
413
  async eth_chainId() {
412
414
  return this.request({ method: 'eth_chainId', params: [] });
413
415
  }
416
+ async connect(params) {
417
+ this.hederaLogger.debug('connect called with params:', params);
418
+ // Check for stored connection params from the dApp
419
+ if (!params || (!params.requiredNamespaces && !params.optionalNamespaces)) {
420
+ // Try to get params from sessionStorage (set by the dApp)
421
+ if (typeof window !== 'undefined' && window.sessionStorage) {
422
+ const storedParams = sessionStorage.getItem('hwcV2ConnectionParams');
423
+ this.hederaLogger.debug('Stored params in sessionStorage:', storedParams);
424
+ if (storedParams) {
425
+ try {
426
+ params = JSON.parse(storedParams);
427
+ this.hederaLogger.info('Using stored connection params from dApp:', params);
428
+ // Clear the stored params after using them
429
+ sessionStorage.removeItem('hwcV2ConnectionParams');
430
+ }
431
+ catch (e) {
432
+ this.hederaLogger.warn('Failed to parse stored connection params:', e);
433
+ }
434
+ }
435
+ }
436
+ }
437
+ // If still no params provided or empty namespaces, create default namespaces
438
+ if (!params || (!params.requiredNamespaces && !params.optionalNamespaces)) {
439
+ this.hederaLogger.info('No namespaces provided, creating default namespaces');
440
+ // Create default namespaces based on initialized state
441
+ const defaultNamespaces = {
442
+ hedera: {
443
+ methods: Object.values(HederaJsonRpcMethod),
444
+ chains: ['hedera:testnet', 'hedera:mainnet'],
445
+ events: ['accountsChanged', 'chainChanged'],
446
+ },
447
+ eip155: {
448
+ methods: [
449
+ 'eth_sendTransaction',
450
+ 'eth_signTransaction',
451
+ 'eth_sign',
452
+ 'personal_sign',
453
+ 'eth_signTypedData',
454
+ 'eth_signTypedData_v4',
455
+ 'eth_accounts',
456
+ 'eth_chainId',
457
+ ],
458
+ chains: ['eip155:296', 'eip155:295'],
459
+ events: ['accountsChanged', 'chainChanged'],
460
+ },
461
+ };
462
+ params = Object.assign({ requiredNamespaces: defaultNamespaces }, params);
463
+ this.hederaLogger.debug('Using default namespaces:', params.requiredNamespaces);
464
+ }
465
+ this.hederaLogger.debug('Final params before super.connect:', params);
466
+ // Update the internal namespace properties before connecting
467
+ if (params) {
468
+ if (params.requiredNamespaces) {
469
+ this.hederaLogger.debug('Setting requiredNamespaces:', params.requiredNamespaces);
470
+ // @ts-ignore - accessing private property
471
+ this.requiredNamespaces = params.requiredNamespaces;
472
+ }
473
+ if (params.optionalNamespaces) {
474
+ this.hederaLogger.debug('Setting optionalNamespaces:', params.optionalNamespaces);
475
+ // @ts-ignore - accessing private property
476
+ this.optionalNamespaces = params.optionalNamespaces;
477
+ }
478
+ }
479
+ this.hederaLogger.debug('Calling super.connect with params');
480
+ // Try to directly pass the namespaces to the parent connect
481
+ let result;
482
+ try {
483
+ result = await super.connect(params);
484
+ }
485
+ catch (error) {
486
+ this.hederaLogger.error('Error in super.connect:', error);
487
+ throw error;
488
+ }
489
+ this.hederaLogger.info('super.connect completed successfully');
490
+ this.hederaLogger.debug('Result from super.connect:', result);
491
+ this.initProviders();
492
+ return result;
493
+ }
414
494
  async pair(pairingTopic) {
415
495
  const session = await super.pair(pairingTopic);
416
496
  this.initProviders();
@@ -1,20 +1,41 @@
1
1
  import { AccountBalanceQuery, AccountId, Client, LedgerId, } from '@hashgraph/sdk';
2
+ import { createLogger } from '../../lib/shared/logger';
3
+ const logger = createLogger('AccountUtils');
2
4
  export async function getAccountBalance(ledgerId, address) {
3
5
  const client = ledgerId === LedgerId.TESTNET ? Client.forTestnet() : Client.forMainnet();
4
6
  let accountId;
5
7
  try {
8
+ // First try to parse as a Hedera account ID (e.g., "0.0.12345")
6
9
  accountId = AccountId.fromString(address);
7
10
  }
8
11
  catch (e) {
9
- accountId = AccountId.fromEvmAddress(0, 0, address);
10
- }
11
- if (accountId.num.isZero() && accountId.evmAddress != null) {
12
- await accountId.populateAccountNum(client);
12
+ // If it's an EVM address (starts with 0x), try to get the associated account
13
+ if (address.startsWith('0x')) {
14
+ try {
15
+ accountId = AccountId.fromEvmAddress(0, 0, address);
16
+ // Try to populate the account number from the mirror node
17
+ // This will fail if the EVM address doesn't have an associated Hedera account
18
+ if (accountId.num.isZero() && accountId.evmAddress != null) {
19
+ await accountId.populateAccountNum(client);
20
+ }
21
+ }
22
+ catch (populateError) {
23
+ // If we can't find a Hedera account for this EVM address, return null
24
+ logger.debug('No Hedera account found for EVM address:', address);
25
+ return null;
26
+ }
27
+ }
28
+ else {
29
+ // Not a valid account ID or EVM address
30
+ logger.debug('Invalid address format:', address);
31
+ return null;
32
+ }
13
33
  }
14
34
  try {
15
35
  return await new AccountBalanceQuery().setAccountId(accountId).execute(client);
16
36
  }
17
37
  catch (e) {
38
+ logger.debug('Failed to get account balance:', e);
18
39
  return null;
19
40
  }
20
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashgraph/hedera-wallet-connect",
3
- "version": "2.0.3-canary.3ed25cd.0",
3
+ "version": "2.0.4-canary.46d8648.0",
4
4
  "description": "A library to facilitate integrating Hedera with WalletConnect",
5
5
  "repository": {
6
6
  "type": "git",