@hashgraph/hedera-wallet-connect 2.0.1-canary.d03f482.0 → 2.0.1-canary.d07e485.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/dist/lib/dapp/DAppSigner.d.ts +0 -2
- package/dist/lib/dapp/DAppSigner.js +2 -16
- package/dist/lib/dapp/index.d.ts +2 -6
- package/dist/lib/dapp/index.js +1 -35
- package/dist/lib/shared/index.d.ts +0 -2
- package/dist/lib/shared/index.js +0 -2
- package/dist/reown/adapter.js +4 -5
- package/dist/reown/utils/account.d.ts +2 -0
- package/dist/reown/utils/account.js +20 -0
- package/dist/reown/utils/index.d.ts +1 -0
- package/dist/reown/utils/index.js +1 -0
- package/package.json +1 -1
- package/dist/lib/shared/accountInfo.d.ts +0 -30
- package/dist/lib/shared/accountInfo.js +0 -1
- package/dist/lib/shared/mirrorNode.d.ts +0 -3
- package/dist/lib/shared/mirrorNode.js +0 -17
@@ -8,7 +8,6 @@ export declare class DAppSigner implements Signer {
|
|
8
8
|
private readonly ledgerId;
|
9
9
|
readonly extensionId?: string | undefined;
|
10
10
|
private logger;
|
11
|
-
private publicKey;
|
12
11
|
constructor(accountId: AccountId, signClient: ISignClient, topic: string, ledgerId?: LedgerId, extensionId?: string | undefined, logLevel?: LogLevel);
|
13
12
|
/**
|
14
13
|
* Sets the logging level for the DAppSigner
|
@@ -23,7 +22,6 @@ export declare class DAppSigner implements Signer {
|
|
23
22
|
}): Promise<T>;
|
24
23
|
getAccountId(): AccountId;
|
25
24
|
getAccountKey(): Key;
|
26
|
-
getAccountKeyAsync(): Promise<Key | null>;
|
27
25
|
getLedgerId(): LedgerId;
|
28
26
|
getNetwork(): {
|
29
27
|
[key: string]: string | AccountId;
|
@@ -19,7 +19,7 @@
|
|
19
19
|
*/
|
20
20
|
import { AccountBalance, AccountInfo, LedgerId, SignerSignature, Transaction, TransactionRecord, Client, PublicKey, TransactionId, TransactionResponse, Query, AccountRecordsQuery, AccountInfoQuery, AccountBalanceQuery, TransactionReceiptQuery, TransactionReceipt, TransactionRecordQuery, } from '@hashgraph/sdk';
|
21
21
|
import { proto } from '@hashgraph/proto';
|
22
|
-
import { HederaJsonRpcMethod, base64StringToSignatureMap, base64StringToUint8Array, ledgerIdToCAIPChainId, queryToBase64String, transactionBodyToBase64String, transactionToBase64String, transactionToTransactionBody, extensionOpen, Uint8ArrayToBase64String, Uint8ArrayToString,
|
22
|
+
import { HederaJsonRpcMethod, base64StringToSignatureMap, base64StringToUint8Array, ledgerIdToCAIPChainId, queryToBase64String, transactionBodyToBase64String, transactionToBase64String, transactionToTransactionBody, extensionOpen, Uint8ArrayToBase64String, Uint8ArrayToString, } from '../shared';
|
23
23
|
import { DefaultLogger } from '../shared/logger';
|
24
24
|
import { SessionNotFoundError } from './SessionNotFoundError';
|
25
25
|
const clients = {};
|
@@ -31,11 +31,6 @@ export class DAppSigner {
|
|
31
31
|
this.ledgerId = ledgerId;
|
32
32
|
this.extensionId = extensionId;
|
33
33
|
this.logger = new DefaultLogger(logLevel);
|
34
|
-
this.publicKey = null;
|
35
|
-
// cache public key from mirror node
|
36
|
-
this.getAccountKeyAsync()
|
37
|
-
.then((key) => (this.publicKey = key))
|
38
|
-
.catch((error) => this.logger.error('Error when receiving a public key:', error.message));
|
39
34
|
}
|
40
35
|
/**
|
41
36
|
* Sets the logging level for the DAppSigner
|
@@ -84,16 +79,7 @@ export class DAppSigner {
|
|
84
79
|
return this.accountId;
|
85
80
|
}
|
86
81
|
getAccountKey() {
|
87
|
-
|
88
|
-
throw new Error('No key was received from the mirror node');
|
89
|
-
}
|
90
|
-
return this.publicKey;
|
91
|
-
}
|
92
|
-
async getAccountKeyAsync() {
|
93
|
-
const accountInfo = await getAccountInfo(this.ledgerId, this.accountId.toString());
|
94
|
-
if (!(accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.key))
|
95
|
-
return null;
|
96
|
-
return PublicKey.fromString(accountInfo.key.key);
|
82
|
+
throw new Error('Method not implemented.');
|
97
83
|
}
|
98
84
|
getLedgerId() {
|
99
85
|
return this.ledgerId;
|
package/dist/lib/dapp/index.d.ts
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
import { AccountId, LedgerId, Transaction } from '@hashgraph/sdk';
|
2
|
-
import {
|
2
|
+
import { SessionTypes, SignClientTypes } from '@walletconnect/types';
|
3
3
|
import { WalletConnectModal } from '@walletconnect/modal';
|
4
4
|
import SignClient from '@walletconnect/sign-client';
|
5
5
|
import { LogLevel } from '../shared/logger';
|
6
6
|
import { GetNodeAddressesResult, ExecuteTransactionParams, ExecuteTransactionResult, SignMessageParams, SignMessageResult, SignAndExecuteQueryResult, SignAndExecuteQueryParams, SignAndExecuteTransactionParams, SignAndExecuteTransactionResult, SignTransactionParams, SignTransactionResult, ExtensionData } from '../shared';
|
7
7
|
import { DAppSigner } from './DAppSigner';
|
8
|
-
import { JsonRpcResult } from '@walletconnect/jsonrpc-types';
|
9
8
|
export * from './DAppSigner';
|
10
9
|
export { SessionNotFoundError } from './SessionNotFoundError';
|
11
10
|
type BaseLogger = 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'fatal';
|
12
11
|
export declare class DAppConnector {
|
13
12
|
private logger;
|
14
|
-
readonly storagePrefix = "hedera-wc/dapp-connector/";
|
15
13
|
dAppMetadata: SignClientTypes.Metadata;
|
16
14
|
network: LedgerId;
|
17
15
|
projectId: string;
|
@@ -108,7 +106,7 @@ export declare class DAppConnector {
|
|
108
106
|
private createSigners;
|
109
107
|
private onSessionConnected;
|
110
108
|
private connectURI;
|
111
|
-
|
109
|
+
private request;
|
112
110
|
/**
|
113
111
|
* Retrieves the node addresses associated with the current Hedera network.
|
114
112
|
*
|
@@ -214,7 +212,5 @@ export declare class DAppConnector {
|
|
214
212
|
private handleSessionUpdate;
|
215
213
|
private handleSessionDelete;
|
216
214
|
private handlePairingDelete;
|
217
|
-
private handleRelayConnected;
|
218
|
-
private verifyLastConnectedInstance;
|
219
215
|
}
|
220
216
|
export default DAppConnector;
|
package/dist/lib/dapp/index.js
CHANGED
@@ -20,8 +20,7 @@
|
|
20
20
|
import { LedgerId, Transaction } from '@hashgraph/sdk';
|
21
21
|
import { WalletConnectModal } from '@walletconnect/modal';
|
22
22
|
import SignClient from '@walletconnect/sign-client';
|
23
|
-
import { getSdkError
|
24
|
-
import { RELAYER_EVENTS } from '@walletconnect/core';
|
23
|
+
import { getSdkError } from '@walletconnect/utils';
|
25
24
|
import { DefaultLogger } from '../shared/logger';
|
26
25
|
import { HederaJsonRpcMethod, accountAndLedgerFromSession, networkNamespaces, extensionConnect, findExtensions, } from '../shared';
|
27
26
|
import { DAppSigner } from './DAppSigner';
|
@@ -39,7 +38,6 @@ export class DAppConnector {
|
|
39
38
|
* @param logLevel - Logging level for the DAppConnector (optional).
|
40
39
|
*/
|
41
40
|
constructor(metadata, network, projectId, methods, events, chains, logLevel = 'debug') {
|
42
|
-
this.storagePrefix = 'hedera-wc/dapp-connector/';
|
43
41
|
this.network = LedgerId.TESTNET;
|
44
42
|
this.supportedMethods = [];
|
45
43
|
this.supportedEvents = [];
|
@@ -112,9 +110,6 @@ export class DAppConnector {
|
|
112
110
|
this.signers = existingSessions.flatMap((session) => this.createSigners(session));
|
113
111
|
else
|
114
112
|
this.checkIframeConnect();
|
115
|
-
//manual call after init before relayer connect event handler is attached
|
116
|
-
this.handleRelayConnected();
|
117
|
-
this.walletConnectClient.core.relayer.on(RELAYER_EVENTS.connect, this.handleRelayConnected.bind(this));
|
118
113
|
this.walletConnectClient.on('session_event', this.handleSessionEvent.bind(this));
|
119
114
|
this.walletConnectClient.on('session_update', this.handleSessionUpdate.bind(this));
|
120
115
|
this.walletConnectClient.on('session_delete', this.handleSessionDelete.bind(this));
|
@@ -384,7 +379,6 @@ export class DAppConnector {
|
|
384
379
|
if (!signer) {
|
385
380
|
throw new Error('There is no active session. Connect to the wallet at first.');
|
386
381
|
}
|
387
|
-
await this.verifyLastConnectedInstance();
|
388
382
|
this.logger.debug(`Using signer: ${signer.getAccountId().toString()}: ${signer.topic} - about to request.`);
|
389
383
|
return await signer.request({
|
390
384
|
method: method,
|
@@ -582,33 +576,5 @@ export class DAppConnector {
|
|
582
576
|
}
|
583
577
|
this.logger.info('Pairing deleted by wallet');
|
584
578
|
}
|
585
|
-
// Store the last connected randomSessionIdentifier
|
586
|
-
async handleRelayConnected() {
|
587
|
-
if (!this.walletConnectClient) {
|
588
|
-
this.logger.error('walletConnectClient not found');
|
589
|
-
return;
|
590
|
-
}
|
591
|
-
const core = this.walletConnectClient.core;
|
592
|
-
const instanceId = core.crypto.randomSessionIdentifier;
|
593
|
-
await core.storage.setItem(this.storagePrefix + 'last-connected-instance', instanceId);
|
594
|
-
}
|
595
|
-
// In the event of another tab being connected after the current one,
|
596
|
-
// the current tab will be forcibly reconnected to the relay so that
|
597
|
-
// a response to the request can be received.
|
598
|
-
// https://github.com/hashgraph/hedera-wallet-connect/issues/387
|
599
|
-
async verifyLastConnectedInstance() {
|
600
|
-
if (!this.walletConnectClient) {
|
601
|
-
this.logger.error('walletConnectClient not found');
|
602
|
-
return;
|
603
|
-
}
|
604
|
-
const core = this.walletConnectClient.core;
|
605
|
-
const instanceId = core.crypto.randomSessionIdentifier;
|
606
|
-
const isOnlineStatus = await isOnline();
|
607
|
-
const lastConnectedInstanceId = await core.storage.getItem(this.storagePrefix + 'last-connected-instance');
|
608
|
-
if (lastConnectedInstanceId != instanceId && isOnlineStatus) {
|
609
|
-
this.logger.info('Forced reconnecting to the relay');
|
610
|
-
await core.relayer.restartTransport();
|
611
|
-
}
|
612
|
-
}
|
613
579
|
}
|
614
580
|
export default DAppConnector;
|
package/dist/lib/shared/index.js
CHANGED
package/dist/reown/adapter.js
CHANGED
@@ -5,8 +5,7 @@ import { ProviderUtil } from '@reown/appkit/store';
|
|
5
5
|
import { LedgerId } from '@hashgraph/sdk';
|
6
6
|
import { BrowserProvider, Contract, formatUnits, JsonRpcSigner, parseUnits } from 'ethers';
|
7
7
|
import { HederaConnector } from './connectors';
|
8
|
-
import { hederaNamespace } from './utils';
|
9
|
-
import { getAccountInfo } from '..';
|
8
|
+
import { hederaNamespace, getAccountBalance } from './utils';
|
10
9
|
export class HederaAdapter extends AdapterBlueprint {
|
11
10
|
constructor(params) {
|
12
11
|
var _a, _b;
|
@@ -73,10 +72,10 @@ export class HederaAdapter extends AdapterBlueprint {
|
|
73
72
|
symbol: '',
|
74
73
|
});
|
75
74
|
}
|
76
|
-
const
|
75
|
+
const accountBalance = await getAccountBalance(caipNetwork.testnet ? LedgerId.TESTNET : LedgerId.MAINNET, address);
|
77
76
|
return Promise.resolve({
|
78
|
-
balance:
|
79
|
-
? formatUnits(
|
77
|
+
balance: accountBalance
|
78
|
+
? formatUnits(accountBalance.hbars.toTinybars().toString(), 8).toString()
|
80
79
|
: '0',
|
81
80
|
decimals: caipNetwork.nativeCurrency.decimals,
|
82
81
|
symbol: caipNetwork.nativeCurrency.symbol,
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { AccountBalanceQuery, AccountId, Client, LedgerId } from '@hashgraph/sdk';
|
2
|
+
export async function getAccountBalance(ledgerId, address) {
|
3
|
+
const client = ledgerId === LedgerId.TESTNET ? Client.forTestnet() : Client.forMainnet();
|
4
|
+
let accountId;
|
5
|
+
try {
|
6
|
+
accountId = AccountId.fromString(address);
|
7
|
+
}
|
8
|
+
catch (e) {
|
9
|
+
accountId = AccountId.fromEvmAddress(0, 0, address);
|
10
|
+
}
|
11
|
+
if (accountId.num.isZero() && accountId.evmAddress != null) {
|
12
|
+
await accountId.populateAccountNum(client);
|
13
|
+
}
|
14
|
+
try {
|
15
|
+
return await new AccountBalanceQuery().setAccountId(accountId).execute(client);
|
16
|
+
}
|
17
|
+
catch (e) {
|
18
|
+
return null;
|
19
|
+
}
|
20
|
+
}
|
package/package.json
CHANGED
@@ -1,30 +0,0 @@
|
|
1
|
-
export interface AccountInfo {
|
2
|
-
account: string;
|
3
|
-
alias: string;
|
4
|
-
auto_renew_period: number;
|
5
|
-
balance: Balance;
|
6
|
-
created_timestamp: string;
|
7
|
-
decline_reward: boolean;
|
8
|
-
deleted: boolean;
|
9
|
-
ethereum_nonce: number;
|
10
|
-
evm_address: string;
|
11
|
-
expiry_timestamp: string;
|
12
|
-
key: Key | null;
|
13
|
-
max_automatic_token_associations: number;
|
14
|
-
memo: string;
|
15
|
-
pending_reward: number;
|
16
|
-
receiver_sig_required: boolean;
|
17
|
-
}
|
18
|
-
export interface Balance {
|
19
|
-
balance: number;
|
20
|
-
timestamp: string;
|
21
|
-
tokens: Token[];
|
22
|
-
}
|
23
|
-
export interface Token {
|
24
|
-
token_id: string;
|
25
|
-
balance: number;
|
26
|
-
}
|
27
|
-
export interface Key {
|
28
|
-
_type: string;
|
29
|
-
key: string;
|
30
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,17 +0,0 @@
|
|
1
|
-
function getMirrorNodeUrl(ledgerId) {
|
2
|
-
return `https://${ledgerId.toString()}.mirrornode.hedera.com`;
|
3
|
-
}
|
4
|
-
export async function getAccountInfo(ledgerId, address) {
|
5
|
-
const mirrorNodeApiUrl = getMirrorNodeUrl(ledgerId);
|
6
|
-
const url = `${mirrorNodeApiUrl}/api/v1/accounts/${address}`;
|
7
|
-
const result = await fetch(url, {
|
8
|
-
headers: {
|
9
|
-
accept: 'application/json',
|
10
|
-
},
|
11
|
-
});
|
12
|
-
if (result.status !== 200) {
|
13
|
-
return null;
|
14
|
-
}
|
15
|
-
const response = await result.json();
|
16
|
-
return response;
|
17
|
-
}
|