@hashgraph/hedera-wallet-connect 2.0.5-canary.0d28c4b.0 → 2.0.5-canary.23bcc25.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/package.json +3 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -21
- package/dist/lib/dapp/DAppSigner.d.ts +0 -60
- package/dist/lib/dapp/DAppSigner.js +0 -344
- package/dist/lib/dapp/SessionNotFoundError.d.ts +0 -3
- package/dist/lib/dapp/SessionNotFoundError.js +0 -6
- package/dist/lib/dapp/index.d.ts +0 -216
- package/dist/lib/dapp/index.js +0 -588
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/index.js +0 -22
- package/dist/lib/shared/chainIds.d.ts +0 -11
- package/dist/lib/shared/chainIds.js +0 -31
- package/dist/lib/shared/errors.d.ts +0 -48
- package/dist/lib/shared/errors.js +0 -51
- package/dist/lib/shared/events.d.ts +0 -7
- package/dist/lib/shared/events.js +0 -27
- package/dist/lib/shared/extensionController.d.ts +0 -21
- package/dist/lib/shared/extensionController.js +0 -42
- package/dist/lib/shared/index.d.ts +0 -7
- package/dist/lib/shared/index.js +0 -26
- package/dist/lib/shared/logger.d.ts +0 -21
- package/dist/lib/shared/logger.js +0 -63
- package/dist/lib/shared/methods.d.ts +0 -12
- package/dist/lib/shared/methods.js +0 -32
- package/dist/lib/shared/payloads.d.ts +0 -101
- package/dist/lib/shared/payloads.js +0 -20
- package/dist/lib/shared/utils.d.ts +0 -280
- package/dist/lib/shared/utils.js +0 -461
- package/dist/lib/wallet/index.d.ts +0 -39
- package/dist/lib/wallet/index.js +0 -306
- package/dist/lib/wallet/provider.d.ts +0 -17
- package/dist/lib/wallet/provider.js +0 -58
- package/dist/lib/wallet/types.d.ts +0 -31
- package/dist/lib/wallet/types.js +0 -20
- package/dist/reown/adapter.d.ts +0 -59
- package/dist/reown/adapter.js +0 -290
- package/dist/reown/connectors/HederaConnector.d.ts +0 -29
- package/dist/reown/connectors/HederaConnector.js +0 -32
- package/dist/reown/connectors/index.d.ts +0 -1
- package/dist/reown/connectors/index.js +0 -1
- package/dist/reown/index.d.ts +0 -4
- package/dist/reown/index.js +0 -4
- package/dist/reown/providers/EIP155Provider.d.ts +0 -33
- package/dist/reown/providers/EIP155Provider.js +0 -187
- package/dist/reown/providers/HIP820Provider.d.ts +0 -26
- package/dist/reown/providers/HIP820Provider.js +0 -67
- package/dist/reown/providers/HederaProvider.d.ts +0 -166
- package/dist/reown/providers/HederaProvider.js +0 -506
- package/dist/reown/providers/index.d.ts +0 -3
- package/dist/reown/providers/index.js +0 -3
- package/dist/reown/utils/account.d.ts +0 -2
- package/dist/reown/utils/account.js +0 -41
- package/dist/reown/utils/chains.d.ts +0 -18
- package/dist/reown/utils/chains.js +0 -152
- package/dist/reown/utils/constants.d.ts +0 -16
- package/dist/reown/utils/constants.js +0 -18
- package/dist/reown/utils/helpers.d.ts +0 -12
- package/dist/reown/utils/helpers.js +0 -25
- package/dist/reown/utils/index.d.ts +0 -5
- package/dist/reown/utils/index.js +0 -5
- package/dist/reown/utils/types.d.ts +0 -9
- package/dist/reown/utils/types.js +0 -1
- package/dist/reown/wallets/EIP155Wallet.d.ts +0 -46
- package/dist/reown/wallets/EIP155Wallet.js +0 -124
- package/dist/reown/wallets/HIP820Wallet.d.ts +0 -53
- package/dist/reown/wallets/HIP820Wallet.js +0 -236
- package/dist/reown/wallets/index.d.ts +0 -2
- package/dist/reown/wallets/index.js +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hashgraph/hedera-wallet-connect",
|
|
3
|
-
"version": "2.0.5-canary.
|
|
3
|
+
"version": "2.0.5-canary.23bcc25.0",
|
|
4
4
|
"description": "A library to facilitate integrating Hedera with WalletConnect",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@hashgraph/sdk": "^2.63.0",
|
|
32
|
-
"@reown/appkit": "
|
|
32
|
+
"@reown/appkit": "1.8.10",
|
|
33
|
+
"@reown/appkit-controllers": "1.8.10",
|
|
33
34
|
"@reown/walletkit": "^1.2.8",
|
|
34
35
|
"@walletconnect/modal": "^2.7.0",
|
|
35
36
|
"ethers": "^6.13.5"
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,21 +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';
|
|
21
|
-
export * from './reown';
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Signer, AccountBalance, AccountId, AccountInfo, Executable, Key, LedgerId, SignerSignature, Transaction, TransactionRecord } from '@hashgraph/sdk';
|
|
2
|
-
import type { CoreTypes, ISignClient } from '@walletconnect/types';
|
|
3
|
-
import { LogLevel } from '../shared/logger';
|
|
4
|
-
export declare class DAppSigner implements Signer {
|
|
5
|
-
private readonly accountId;
|
|
6
|
-
private readonly signClient;
|
|
7
|
-
readonly topic: string;
|
|
8
|
-
private readonly ledgerId;
|
|
9
|
-
readonly extensionId?: string | undefined;
|
|
10
|
-
private logger;
|
|
11
|
-
constructor(accountId: AccountId, signClient: ISignClient, topic: string, ledgerId?: LedgerId, extensionId?: string | undefined, logLevel?: LogLevel);
|
|
12
|
-
/**
|
|
13
|
-
* Sets the logging level for the DAppSigner
|
|
14
|
-
* @param level - The logging level to set
|
|
15
|
-
*/
|
|
16
|
-
setLogLevel(level: LogLevel): void;
|
|
17
|
-
private _getHederaClient;
|
|
18
|
-
private get _signerAccountId();
|
|
19
|
-
request<T>(request: {
|
|
20
|
-
method: string;
|
|
21
|
-
params: any;
|
|
22
|
-
}): Promise<T>;
|
|
23
|
-
getAccountId(): AccountId;
|
|
24
|
-
getAccountKey(): Key;
|
|
25
|
-
getLedgerId(): LedgerId;
|
|
26
|
-
getNetwork(): {
|
|
27
|
-
[key: string]: string | AccountId;
|
|
28
|
-
};
|
|
29
|
-
getMirrorNetwork(): string[];
|
|
30
|
-
getAccountBalance(): Promise<AccountBalance>;
|
|
31
|
-
getAccountInfo(): Promise<AccountInfo>;
|
|
32
|
-
getAccountRecords(): Promise<TransactionRecord[]>;
|
|
33
|
-
getMetadata(): CoreTypes.Metadata;
|
|
34
|
-
sign(data: Uint8Array[], signOptions?: {
|
|
35
|
-
encoding?: 'utf-8' | 'base64';
|
|
36
|
-
}): Promise<SignerSignature[]>;
|
|
37
|
-
checkTransaction<T extends Transaction>(transaction: T): Promise<T>;
|
|
38
|
-
populateTransaction<T extends Transaction>(transaction: T): Promise<T>;
|
|
39
|
-
/**
|
|
40
|
-
* Prepares a transaction object for signing using a single node account id.
|
|
41
|
-
* If the transaction object does not already have a node account id,
|
|
42
|
-
* generate a random node account id using the Hedera SDK client
|
|
43
|
-
*
|
|
44
|
-
* @param transaction - Any instance of a class that extends `Transaction`
|
|
45
|
-
* @returns transaction - `Transaction` object with signature
|
|
46
|
-
*/
|
|
47
|
-
signTransaction<T extends Transaction>(transaction: T): Promise<T>;
|
|
48
|
-
private _tryExecuteTransactionRequest;
|
|
49
|
-
private _parseQueryResponse;
|
|
50
|
-
/**
|
|
51
|
-
* Executes a free receipt query without signing a transaction.
|
|
52
|
-
* Enables the DApp to fetch the receipt of a transaction without making a new request
|
|
53
|
-
* to the wallet.
|
|
54
|
-
* @param request - The query to execute
|
|
55
|
-
* @returns The result of the query
|
|
56
|
-
*/
|
|
57
|
-
private executeReceiptQueryFromRequest;
|
|
58
|
-
private _tryExecuteQueryRequest;
|
|
59
|
-
call<RequestT, ResponseT, OutputT>(request: Executable<RequestT, ResponseT, OutputT>): Promise<OutputT>;
|
|
60
|
-
}
|
|
@@ -1,344 +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 { AccountBalance, AccountInfo, LedgerId, SignerSignature, Transaction, TransactionRecord, Client, PublicKey, TransactionId, TransactionResponse, Query, AccountRecordsQuery, AccountInfoQuery, AccountBalanceQuery, TransactionReceiptQuery, TransactionReceipt, TransactionRecordQuery, } from '@hashgraph/sdk';
|
|
21
|
-
import { proto } from '@hashgraph/proto';
|
|
22
|
-
import { HederaJsonRpcMethod, base64StringToSignatureMap, base64StringToUint8Array, ledgerIdToCAIPChainId, queryToBase64String, transactionBodyToBase64String, transactionToBase64String, transactionToTransactionBody, extensionOpen, Uint8ArrayToBase64String, Uint8ArrayToString, } from '../shared';
|
|
23
|
-
import { DefaultLogger } from '../shared/logger';
|
|
24
|
-
import { SessionNotFoundError } from './SessionNotFoundError';
|
|
25
|
-
const clients = {};
|
|
26
|
-
export class DAppSigner {
|
|
27
|
-
constructor(accountId, signClient, topic, ledgerId = LedgerId.MAINNET, extensionId, logLevel = 'debug') {
|
|
28
|
-
this.accountId = accountId;
|
|
29
|
-
this.signClient = signClient;
|
|
30
|
-
this.topic = topic;
|
|
31
|
-
this.ledgerId = ledgerId;
|
|
32
|
-
this.extensionId = extensionId;
|
|
33
|
-
this.logger = new DefaultLogger(logLevel);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Sets the logging level for the DAppSigner
|
|
37
|
-
* @param level - The logging level to set
|
|
38
|
-
*/
|
|
39
|
-
setLogLevel(level) {
|
|
40
|
-
if (this.logger instanceof DefaultLogger) {
|
|
41
|
-
this.logger.setLogLevel(level);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
_getHederaClient() {
|
|
45
|
-
const ledgerIdString = this.ledgerId.toString();
|
|
46
|
-
if (!clients[ledgerIdString]) {
|
|
47
|
-
clients[ledgerIdString] = Client.forName(ledgerIdString);
|
|
48
|
-
}
|
|
49
|
-
return clients[ledgerIdString];
|
|
50
|
-
}
|
|
51
|
-
get _signerAccountId() {
|
|
52
|
-
return `${ledgerIdToCAIPChainId(this.ledgerId)}:${this.accountId.toString()}`;
|
|
53
|
-
}
|
|
54
|
-
request(request) {
|
|
55
|
-
var _a, _b;
|
|
56
|
-
// Avoid a wallet call if the session is no longer valid
|
|
57
|
-
if (!((_b = (_a = this === null || this === void 0 ? void 0 : this.signClient) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.get(this.topic))) {
|
|
58
|
-
this.logger.error('Session no longer exists, signer will be removed. Please reconnect to the wallet.');
|
|
59
|
-
// Notify DAppConnector to remove this signer
|
|
60
|
-
this.signClient.emit({
|
|
61
|
-
topic: this.topic,
|
|
62
|
-
event: {
|
|
63
|
-
name: 'session_delete',
|
|
64
|
-
data: { topic: this.topic },
|
|
65
|
-
},
|
|
66
|
-
chainId: ledgerIdToCAIPChainId(this.ledgerId),
|
|
67
|
-
});
|
|
68
|
-
throw new SessionNotFoundError('Session no longer exists. Please reconnect to the wallet.');
|
|
69
|
-
}
|
|
70
|
-
if (this.extensionId)
|
|
71
|
-
extensionOpen(this.extensionId);
|
|
72
|
-
return this.signClient.request({
|
|
73
|
-
topic: this.topic,
|
|
74
|
-
request,
|
|
75
|
-
chainId: ledgerIdToCAIPChainId(this.ledgerId),
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
getAccountId() {
|
|
79
|
-
return this.accountId;
|
|
80
|
-
}
|
|
81
|
-
getAccountKey() {
|
|
82
|
-
throw new Error('Method not implemented.');
|
|
83
|
-
}
|
|
84
|
-
getLedgerId() {
|
|
85
|
-
return this.ledgerId;
|
|
86
|
-
}
|
|
87
|
-
getNetwork() {
|
|
88
|
-
return this._getHederaClient().network;
|
|
89
|
-
}
|
|
90
|
-
getMirrorNetwork() {
|
|
91
|
-
return this._getHederaClient().mirrorNetwork;
|
|
92
|
-
}
|
|
93
|
-
getAccountBalance() {
|
|
94
|
-
return this.call(new AccountBalanceQuery().setAccountId(this.accountId));
|
|
95
|
-
}
|
|
96
|
-
getAccountInfo() {
|
|
97
|
-
return this.call(new AccountInfoQuery().setAccountId(this.accountId));
|
|
98
|
-
}
|
|
99
|
-
getAccountRecords() {
|
|
100
|
-
return this.call(new AccountRecordsQuery().setAccountId(this.accountId));
|
|
101
|
-
}
|
|
102
|
-
getMetadata() {
|
|
103
|
-
return this.signClient.metadata;
|
|
104
|
-
}
|
|
105
|
-
async sign(data, signOptions = {
|
|
106
|
-
encoding: 'utf-8',
|
|
107
|
-
}) {
|
|
108
|
-
try {
|
|
109
|
-
const messageToSign = signOptions.encoding === 'base64'
|
|
110
|
-
? Uint8ArrayToBase64String(data[0])
|
|
111
|
-
: Uint8ArrayToString(data[0]);
|
|
112
|
-
const { signatureMap } = await this.request({
|
|
113
|
-
method: HederaJsonRpcMethod.SignMessage,
|
|
114
|
-
params: {
|
|
115
|
-
signerAccountId: this._signerAccountId,
|
|
116
|
-
message: messageToSign,
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
const sigmap = base64StringToSignatureMap(signatureMap);
|
|
120
|
-
const signerSignature = new SignerSignature({
|
|
121
|
-
accountId: this.getAccountId(),
|
|
122
|
-
publicKey: PublicKey.fromBytes(sigmap.sigPair[0].pubKeyPrefix),
|
|
123
|
-
signature: sigmap.sigPair[0].ed25519 ||
|
|
124
|
-
sigmap.sigPair[0].ECDSASecp256k1,
|
|
125
|
-
});
|
|
126
|
-
this.logger.debug('Data signed successfully');
|
|
127
|
-
return [signerSignature];
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
this.logger.error('Error signing data:', error);
|
|
131
|
-
throw error;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async checkTransaction(transaction) {
|
|
135
|
-
throw new Error('Method not implemented.');
|
|
136
|
-
}
|
|
137
|
-
async populateTransaction(transaction) {
|
|
138
|
-
return transaction.setTransactionId(TransactionId.generate(this.getAccountId()));
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Prepares a transaction object for signing using a single node account id.
|
|
142
|
-
* If the transaction object does not already have a node account id,
|
|
143
|
-
* generate a random node account id using the Hedera SDK client
|
|
144
|
-
*
|
|
145
|
-
* @param transaction - Any instance of a class that extends `Transaction`
|
|
146
|
-
* @returns transaction - `Transaction` object with signature
|
|
147
|
-
*/
|
|
148
|
-
async signTransaction(transaction) {
|
|
149
|
-
var _a, _b;
|
|
150
|
-
// Ensure transaction is frozen with node account IDs before signing
|
|
151
|
-
// This is required so the transaction can be executed later by any client
|
|
152
|
-
if (!transaction.isFrozen()) {
|
|
153
|
-
transaction.freezeWith(this._getHederaClient());
|
|
154
|
-
}
|
|
155
|
-
// Extract the first node account ID from the frozen transaction to preserve it in the transaction body
|
|
156
|
-
const nodeAccountId = (_b = (_a = transaction.nodeAccountIds) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : null;
|
|
157
|
-
const transactionBody = transactionToTransactionBody(transaction, nodeAccountId);
|
|
158
|
-
if (!transactionBody)
|
|
159
|
-
throw new Error('Failed to serialize transaction body');
|
|
160
|
-
const transactionBodyBase64 = transactionBodyToBase64String(transactionBody);
|
|
161
|
-
const { signatureMap } = await this.request({
|
|
162
|
-
method: HederaJsonRpcMethod.SignTransaction,
|
|
163
|
-
params: {
|
|
164
|
-
signerAccountId: this._signerAccountId,
|
|
165
|
-
transactionBody: transactionBodyBase64,
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
const sigMap = base64StringToSignatureMap(signatureMap);
|
|
169
|
-
// Get the original transaction bytes to preserve the full transaction structure
|
|
170
|
-
// including all node account IDs
|
|
171
|
-
const originalTransactionBytes = transaction.toBytes();
|
|
172
|
-
const originalTransactionList = proto.TransactionList.decode(originalTransactionBytes);
|
|
173
|
-
// Add the signature to all transactions in the list
|
|
174
|
-
// Each transaction in the list corresponds to a different node
|
|
175
|
-
const signedTransactionList = originalTransactionList.transactionList.map((tx) => {
|
|
176
|
-
// Check if the transaction has signedTransactionBytes (frozen transactions)
|
|
177
|
-
if (tx.signedTransactionBytes) {
|
|
178
|
-
// Decode the SignedTransaction to access the bodyBytes and existing sigMap
|
|
179
|
-
const signedTx = proto.SignedTransaction.decode(tx.signedTransactionBytes);
|
|
180
|
-
const existingSigMap = signedTx.sigMap || proto.SignatureMap.create({});
|
|
181
|
-
// Merge the new signatures with existing signatures
|
|
182
|
-
const mergedSigPairs = [...(existingSigMap.sigPair || []), ...(sigMap.sigPair || [])];
|
|
183
|
-
// Create updated SignedTransaction with merged signatures
|
|
184
|
-
const updatedSignedTx = proto.SignedTransaction.encode({
|
|
185
|
-
bodyBytes: signedTx.bodyBytes,
|
|
186
|
-
sigMap: proto.SignatureMap.create({
|
|
187
|
-
sigPair: mergedSigPairs,
|
|
188
|
-
}),
|
|
189
|
-
}).finish();
|
|
190
|
-
return {
|
|
191
|
-
signedTransactionBytes: updatedSignedTx,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
// Transaction has bodyBytes and sigMap at the top level (not frozen)
|
|
196
|
-
const existingSigMap = tx.sigMap || proto.SignatureMap.create({});
|
|
197
|
-
// Merge the new signatures with existing signatures
|
|
198
|
-
const mergedSigPairs = [...(existingSigMap.sigPair || []), ...(sigMap.sigPair || [])];
|
|
199
|
-
return Object.assign(Object.assign({}, tx), { sigMap: Object.assign(Object.assign({}, existingSigMap), { sigPair: mergedSigPairs }) });
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
// Encode the signed transaction list back to bytes
|
|
203
|
-
const signedBytes = proto.TransactionList.encode({
|
|
204
|
-
transactionList: signedTransactionList,
|
|
205
|
-
}).finish();
|
|
206
|
-
return Transaction.fromBytes(signedBytes);
|
|
207
|
-
}
|
|
208
|
-
async _tryExecuteTransactionRequest(request) {
|
|
209
|
-
try {
|
|
210
|
-
const requestToBytes = request.toBytes();
|
|
211
|
-
this.logger.debug('Creating transaction from bytes', requestToBytes, request);
|
|
212
|
-
const transaction = Transaction.fromBytes(requestToBytes);
|
|
213
|
-
this.logger.debug('Executing transaction request', transaction);
|
|
214
|
-
const result = await this.request({
|
|
215
|
-
method: HederaJsonRpcMethod.SignAndExecuteTransaction,
|
|
216
|
-
params: {
|
|
217
|
-
signerAccountId: this._signerAccountId,
|
|
218
|
-
transactionList: transactionToBase64String(transaction),
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
this.logger.debug('Transaction request completed successfully');
|
|
222
|
-
return { result: TransactionResponse.fromJSON(result) };
|
|
223
|
-
}
|
|
224
|
-
catch (error) {
|
|
225
|
-
this.logger.error('Error executing transaction request:', error);
|
|
226
|
-
return { error };
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
async _parseQueryResponse(query, base64EncodedQueryResponse) {
|
|
230
|
-
if (query instanceof AccountRecordsQuery) {
|
|
231
|
-
const base64EncodedQueryResponseSplit = base64EncodedQueryResponse.split(',');
|
|
232
|
-
const data = base64EncodedQueryResponseSplit.map((o) => base64StringToUint8Array(o));
|
|
233
|
-
return data.map((o) => TransactionRecord.fromBytes(o));
|
|
234
|
-
}
|
|
235
|
-
const data = base64StringToUint8Array(base64EncodedQueryResponse);
|
|
236
|
-
if (query instanceof AccountBalanceQuery) {
|
|
237
|
-
return AccountBalance.fromBytes(data);
|
|
238
|
-
}
|
|
239
|
-
else if (query instanceof AccountInfoQuery) {
|
|
240
|
-
return AccountInfo.fromBytes(data);
|
|
241
|
-
}
|
|
242
|
-
else if (query instanceof TransactionReceiptQuery) {
|
|
243
|
-
return TransactionReceipt.fromBytes(data);
|
|
244
|
-
}
|
|
245
|
-
else if (query instanceof TransactionRecordQuery) {
|
|
246
|
-
return TransactionRecord.fromBytes(data);
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
throw new Error('Unsupported query type');
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Executes a free receipt query without signing a transaction.
|
|
254
|
-
* Enables the DApp to fetch the receipt of a transaction without making a new request
|
|
255
|
-
* to the wallet.
|
|
256
|
-
* @param request - The query to execute
|
|
257
|
-
* @returns The result of the query
|
|
258
|
-
*/
|
|
259
|
-
async executeReceiptQueryFromRequest(request) {
|
|
260
|
-
try {
|
|
261
|
-
const isMainnet = this.ledgerId === LedgerId.MAINNET;
|
|
262
|
-
const client = isMainnet ? Client.forMainnet() : Client.forTestnet();
|
|
263
|
-
const receipt = TransactionReceiptQuery.fromBytes(request.toBytes());
|
|
264
|
-
const result = await receipt.execute(client);
|
|
265
|
-
return { result };
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
return { error };
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
async _tryExecuteQueryRequest(request) {
|
|
272
|
-
try {
|
|
273
|
-
const isReceiptQuery = request instanceof TransactionReceiptQuery;
|
|
274
|
-
if (isReceiptQuery) {
|
|
275
|
-
this.logger.debug('Attempting to execute free receipt query', request);
|
|
276
|
-
const result = await this.executeReceiptQueryFromRequest(request);
|
|
277
|
-
if (!(result === null || result === void 0 ? void 0 : result.error)) {
|
|
278
|
-
return { result: result.result };
|
|
279
|
-
}
|
|
280
|
-
this.logger.error('Error executing free receipt query. Sending to wallet.', result.error);
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Note, should we be converting these to specific query types?
|
|
284
|
-
* Left alone to avoid changing the API for other requests.
|
|
285
|
-
*/
|
|
286
|
-
const query = isReceiptQuery
|
|
287
|
-
? TransactionReceiptQuery.fromBytes(request.toBytes())
|
|
288
|
-
: Query.fromBytes(request.toBytes());
|
|
289
|
-
this.logger.debug('Executing query request', query, queryToBase64String(query), isReceiptQuery);
|
|
290
|
-
const result = await this.request({
|
|
291
|
-
method: HederaJsonRpcMethod.SignAndExecuteQuery,
|
|
292
|
-
params: {
|
|
293
|
-
signerAccountId: this._signerAccountId,
|
|
294
|
-
query: queryToBase64String(query),
|
|
295
|
-
},
|
|
296
|
-
});
|
|
297
|
-
this.logger.debug('Query request completed successfully', result);
|
|
298
|
-
return { result: this._parseQueryResponse(query, result.response) };
|
|
299
|
-
}
|
|
300
|
-
catch (error) {
|
|
301
|
-
this.logger.error('Error executing query request:', error);
|
|
302
|
-
return { error };
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
async call(request) {
|
|
306
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
307
|
-
const isReceiptQuery = request instanceof TransactionReceiptQuery;
|
|
308
|
-
let txResult = undefined;
|
|
309
|
-
// a receipt query is a free query and we should not execute a transaction.
|
|
310
|
-
if (!isReceiptQuery) {
|
|
311
|
-
txResult = await this._tryExecuteTransactionRequest(request);
|
|
312
|
-
if (txResult.result) {
|
|
313
|
-
return txResult.result;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
const queryResult = await this._tryExecuteQueryRequest(request);
|
|
317
|
-
if (queryResult.result) {
|
|
318
|
-
return queryResult.result;
|
|
319
|
-
}
|
|
320
|
-
if (isReceiptQuery) {
|
|
321
|
-
throw new Error('Error executing receipt query: \n' +
|
|
322
|
-
JSON.stringify({
|
|
323
|
-
queryError: {
|
|
324
|
-
name: (_a = queryResult.error) === null || _a === void 0 ? void 0 : _a.name,
|
|
325
|
-
message: (_b = queryResult.error) === null || _b === void 0 ? void 0 : _b.message,
|
|
326
|
-
stack: (_c = queryResult.error) === null || _c === void 0 ? void 0 : _c.stack,
|
|
327
|
-
},
|
|
328
|
-
}));
|
|
329
|
-
}
|
|
330
|
-
throw new Error('Error executing transaction or query: \n' +
|
|
331
|
-
JSON.stringify({
|
|
332
|
-
txError: {
|
|
333
|
-
name: (_d = txResult === null || txResult === void 0 ? void 0 : txResult.error) === null || _d === void 0 ? void 0 : _d.name,
|
|
334
|
-
message: (_e = txResult === null || txResult === void 0 ? void 0 : txResult.error) === null || _e === void 0 ? void 0 : _e.message,
|
|
335
|
-
stack: (_f = txResult === null || txResult === void 0 ? void 0 : txResult.error) === null || _f === void 0 ? void 0 : _f.stack,
|
|
336
|
-
},
|
|
337
|
-
queryError: {
|
|
338
|
-
name: (_g = queryResult.error) === null || _g === void 0 ? void 0 : _g.name,
|
|
339
|
-
message: (_h = queryResult.error) === null || _h === void 0 ? void 0 : _h.message,
|
|
340
|
-
stack: (_j = queryResult.error) === null || _j === void 0 ? void 0 : _j.stack,
|
|
341
|
-
},
|
|
342
|
-
}, null, 2));
|
|
343
|
-
}
|
|
344
|
-
}
|
package/dist/lib/dapp/index.d.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { AccountId, LedgerId, Transaction } from '@hashgraph/sdk';
|
|
2
|
-
import { SessionTypes, SignClientTypes } from '@walletconnect/types';
|
|
3
|
-
import { WalletConnectModal } from '@walletconnect/modal';
|
|
4
|
-
import SignClient from '@walletconnect/sign-client';
|
|
5
|
-
import { LogLevel } from '../shared/logger';
|
|
6
|
-
import { GetNodeAddressesResult, ExecuteTransactionParams, ExecuteTransactionResult, SignMessageParams, SignMessageResult, SignAndExecuteQueryResult, SignAndExecuteQueryParams, SignAndExecuteTransactionParams, SignAndExecuteTransactionResult, SignTransactionParams, SignTransactionResult, ExtensionData } from '../shared';
|
|
7
|
-
import { DAppSigner } from './DAppSigner';
|
|
8
|
-
export * from './DAppSigner';
|
|
9
|
-
export { SessionNotFoundError } from './SessionNotFoundError';
|
|
10
|
-
type BaseLogger = 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'fatal';
|
|
11
|
-
export declare class DAppConnector {
|
|
12
|
-
private logger;
|
|
13
|
-
dAppMetadata: SignClientTypes.Metadata;
|
|
14
|
-
network: LedgerId;
|
|
15
|
-
projectId: string;
|
|
16
|
-
supportedMethods: string[];
|
|
17
|
-
supportedEvents: string[];
|
|
18
|
-
supportedChains: string[];
|
|
19
|
-
extensions: ExtensionData[];
|
|
20
|
-
onSessionIframeCreated: ((session: SessionTypes.Struct) => void) | null;
|
|
21
|
-
walletConnectClient: SignClient | undefined;
|
|
22
|
-
walletConnectModal: WalletConnectModal;
|
|
23
|
-
signers: DAppSigner[];
|
|
24
|
-
isInitializing: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Initializes the DAppConnector instance.
|
|
27
|
-
* @param metadata - SignClientTypes.Metadata object for the DApp metadata.
|
|
28
|
-
* @param network - LedgerId representing the network (default: LedgerId.TESTNET).
|
|
29
|
-
* @param projectId - Project ID for the WalletConnect client.
|
|
30
|
-
* @param methods - Array of supported methods for the DApp (optional).
|
|
31
|
-
* @param events - Array of supported events for the DApp (optional).
|
|
32
|
-
* @param chains - Array of supported chains for the DApp (optional).
|
|
33
|
-
* @param logLevel - Logging level for the DAppConnector (optional).
|
|
34
|
-
*/
|
|
35
|
-
constructor(metadata: SignClientTypes.Metadata, network: LedgerId, projectId: string, methods?: string[], events?: string[], chains?: string[], logLevel?: LogLevel);
|
|
36
|
-
/**
|
|
37
|
-
* Sets the logging level for the DAppConnector
|
|
38
|
-
* @param level - The logging level to set
|
|
39
|
-
*/
|
|
40
|
-
setLogLevel(level: LogLevel): void;
|
|
41
|
-
/**
|
|
42
|
-
* Initializes the DAppConnector instance.
|
|
43
|
-
* @param logger - `BaseLogger` for logging purposes (optional).
|
|
44
|
-
*/
|
|
45
|
-
init({ logger }?: {
|
|
46
|
-
logger?: BaseLogger;
|
|
47
|
-
}): Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* Retrieves a DAppSigner for the specified Hedera Account ID.
|
|
50
|
-
*
|
|
51
|
-
* @param {AccountId} accountId - The Hedera Account ID to find the associated signer.
|
|
52
|
-
* @returns {DAppSigner} - The signer object of type {@link DAppSigner} corresponding to the provided account ID.
|
|
53
|
-
* @throws {Error} - If no signer is found for the provided account ID.
|
|
54
|
-
*/
|
|
55
|
-
getSigner(accountId: AccountId): DAppSigner;
|
|
56
|
-
/**
|
|
57
|
-
* Initiates the WalletConnect connection flow using a QR code.
|
|
58
|
-
* @param pairingTopic - The pairing topic for the connection (optional).
|
|
59
|
-
* @param throwErrorOnReject - Whether to show an error when the user rejects the pairing (default: false).
|
|
60
|
-
* @returns {Promise<SessionTypes.Struct>} - A Promise that resolves when the connection process is complete.
|
|
61
|
-
*/
|
|
62
|
-
openModal(pairingTopic?: string, throwErrorOnReject?: boolean): Promise<SessionTypes.Struct>;
|
|
63
|
-
/**
|
|
64
|
-
* Initiates the WallecConnect connection flow using URI.
|
|
65
|
-
* @param pairingTopic - The pairing topic for the connection (optional).
|
|
66
|
-
* @param extensionId - The id for the extension used to connect (optional).
|
|
67
|
-
* @returns A Promise that resolves when the connection process is complete.
|
|
68
|
-
*/
|
|
69
|
-
connect(launchCallback: (uri: string) => void, pairingTopic?: string, extensionId?: string): Promise<SessionTypes.Struct>;
|
|
70
|
-
/**
|
|
71
|
-
* Initiates the WallecConnect connection flow sending a message to the extension.
|
|
72
|
-
* @param extensionId - The id for the extension used to connect.
|
|
73
|
-
* @param pairingTopic - The pairing topic for the connection (optional).
|
|
74
|
-
* @returns A Promise that resolves when the connection process is complete.
|
|
75
|
-
*/
|
|
76
|
-
connectExtension(extensionId: string, pairingTopic?: string): Promise<SessionTypes.Struct>;
|
|
77
|
-
/**
|
|
78
|
-
* Validates the session by checking if the session exists and is valid.
|
|
79
|
-
* Also ensures the signer exists for the session.
|
|
80
|
-
* @param topic - The topic of the session to validate.
|
|
81
|
-
* @returns {boolean} - True if the session exists and has a valid signer, false otherwise.
|
|
82
|
-
*/
|
|
83
|
-
private validateSession;
|
|
84
|
-
/**
|
|
85
|
-
* Validates the session and refreshes the signers by removing the invalid ones.
|
|
86
|
-
*/
|
|
87
|
-
private validateAndRefreshSigners;
|
|
88
|
-
/**
|
|
89
|
-
* Initiates the WallecConnect connection if the wallet in iframe mode is detected.
|
|
90
|
-
*/
|
|
91
|
-
private checkIframeConnect;
|
|
92
|
-
private abortableConnect;
|
|
93
|
-
/**
|
|
94
|
-
* Disconnects the current session associated with the specified topic.
|
|
95
|
-
* @param topic - The topic of the session to disconnect.
|
|
96
|
-
* @returns A Promise that resolves when the session is disconnected.
|
|
97
|
-
*/
|
|
98
|
-
disconnect(topic: string): Promise<boolean>;
|
|
99
|
-
/**
|
|
100
|
-
* Disconnects all active sessions and pairings.
|
|
101
|
-
*
|
|
102
|
-
* Throws error when WalletConnect is not initialized or there are no active sessions/pairings.
|
|
103
|
-
* @returns A Promise that resolves when all active sessions and pairings are disconnected.
|
|
104
|
-
*/
|
|
105
|
-
disconnectAll(): Promise<void>;
|
|
106
|
-
private createSigners;
|
|
107
|
-
private onSessionConnected;
|
|
108
|
-
private connectURI;
|
|
109
|
-
private request;
|
|
110
|
-
/**
|
|
111
|
-
* Retrieves the node addresses associated with the current Hedera network.
|
|
112
|
-
*
|
|
113
|
-
* When there is no active session or an error occurs during the request.
|
|
114
|
-
* @returns Promise\<{@link GetNodeAddressesResult}\>
|
|
115
|
-
*/
|
|
116
|
-
getNodeAddresses(): Promise<GetNodeAddressesResult>;
|
|
117
|
-
/**
|
|
118
|
-
* Executes a transaction on the Hedera network.
|
|
119
|
-
*
|
|
120
|
-
* @param {ExecuteTransactionParams} params - The parameters of type {@link ExecuteTransactionParams | `ExecuteTransactionParams`} required for the transaction execution.
|
|
121
|
-
* @param {string[]} params.signedTransaction - Array of Base64-encoded `Transaction`'s
|
|
122
|
-
* @returns Promise\<{@link ExecuteTransactionResult}\>
|
|
123
|
-
* @example
|
|
124
|
-
* Use helper `transactionToBase64String` to encode `Transaction` to Base64 string
|
|
125
|
-
* ```ts
|
|
126
|
-
* const params = {
|
|
127
|
-
* signedTransaction: [transactionToBase64String(transaction)]
|
|
128
|
-
* }
|
|
129
|
-
*
|
|
130
|
-
* const result = await dAppConnector.executeTransaction(params)
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
executeTransaction(params: ExecuteTransactionParams): Promise<ExecuteTransactionResult>;
|
|
134
|
-
/**
|
|
135
|
-
* Signs a provided `message` with provided `signerAccountId`.
|
|
136
|
-
*
|
|
137
|
-
* @param {SignMessageParams} params - The parameters of type {@link SignMessageParams | `SignMessageParams`} required for signing message.
|
|
138
|
-
* @param {string} params.signerAccountId - a signer Hedera Account identifier in {@link https://hips.hedera.com/hip/hip-30 | HIP-30} (`<nework>:<shard>.<realm>.<num>`) form.
|
|
139
|
-
* @param {string} params.message - a plain UTF-8 string
|
|
140
|
-
* @returns Promise\<{@link SignMessageResult}\>
|
|
141
|
-
* @example
|
|
142
|
-
* ```ts
|
|
143
|
-
* const params = {
|
|
144
|
-
* signerAccountId: 'hedera:testnet:0.0.12345',
|
|
145
|
-
* message: 'Hello World!'
|
|
146
|
-
* }
|
|
147
|
-
*
|
|
148
|
-
* const result = await dAppConnector.signMessage(params)
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
signMessage(params: SignMessageParams): Promise<SignMessageResult>;
|
|
152
|
-
/**
|
|
153
|
-
* Signs and send `Query` on the Hedera network.
|
|
154
|
-
*
|
|
155
|
-
* @param {SignAndExecuteQueryParams} params - The parameters of type {@link SignAndExecuteQueryParams | `SignAndExecuteQueryParams`} required for the Query execution.
|
|
156
|
-
* @param {string} params.signerAccountId - a signer Hedera Account identifier in {@link https://hips.hedera.com/hip/hip-30 | HIP-30} (`<nework>:<shard>.<realm>.<num>`) form.
|
|
157
|
-
* @param {string} params.query - `Query` object represented as Base64 string
|
|
158
|
-
* @returns Promise\<{@link SignAndExecuteQueryResult}\>
|
|
159
|
-
* @example
|
|
160
|
-
* Use helper `queryToBase64String` to encode `Query` to Base64 string
|
|
161
|
-
* ```ts
|
|
162
|
-
* const params = {
|
|
163
|
-
* signerAccountId: '0.0.12345',
|
|
164
|
-
* query: queryToBase64String(query),
|
|
165
|
-
* }
|
|
166
|
-
*
|
|
167
|
-
* const result = await dAppConnector.signAndExecuteQuery(params)
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
signAndExecuteQuery(params: SignAndExecuteQueryParams): Promise<SignAndExecuteQueryResult>;
|
|
171
|
-
/**
|
|
172
|
-
* Signs and executes Transactions on the Hedera network.
|
|
173
|
-
*
|
|
174
|
-
* @param {SignAndExecuteTransactionParams} params - The parameters of type {@link SignAndExecuteTransactionParams | `SignAndExecuteTransactionParams`} required for `Transaction` signing and execution.
|
|
175
|
-
* @param {string} params.signerAccountId - a signer Hedera Account identifier in {@link https://hips.hedera.com/hip/hip-30 | HIP-30} (`<nework>:<shard>.<realm>.<num>`) form.
|
|
176
|
-
* @param {string[]} params.transaction - Array of Base64-encoded `Transaction`'s
|
|
177
|
-
* @returns Promise\<{@link SignAndExecuteTransactionResult}\>
|
|
178
|
-
* @example
|
|
179
|
-
* Use helper `transactionToBase64String` to encode `Transaction` to Base64 string
|
|
180
|
-
* ```ts
|
|
181
|
-
* const params = {
|
|
182
|
-
* signerAccountId: '0.0.12345'
|
|
183
|
-
* transaction: [transactionToBase64String(transaction)]
|
|
184
|
-
* }
|
|
185
|
-
*
|
|
186
|
-
* const result = await dAppConnector.signAndExecuteTransaction(params)
|
|
187
|
-
* ```
|
|
188
|
-
*/
|
|
189
|
-
signAndExecuteTransaction(params: SignAndExecuteTransactionParams): Promise<SignAndExecuteTransactionResult>;
|
|
190
|
-
/**
|
|
191
|
-
* Signs and executes Transactions on the Hedera network.
|
|
192
|
-
*
|
|
193
|
-
* @param {SignTransactionParams} params - The parameters of type {@link SignTransactionParams | `SignTransactionParams`} required for `Transaction` signing.
|
|
194
|
-
* @param {string} params.signerAccountId - a signer Hedera Account identifier in {@link https://hips.hedera.com/hip/hip-30 | HIP-30} (`<nework>:<shard>.<realm>.<num>`) form.
|
|
195
|
-
* @param {Transaction | string} params.transactionBody - a built Transaction object, or a base64 string of a transaction body( HIP-820).
|
|
196
|
-
* HIP-820 calls for a base64 encoded proto.TransactionBody and many wallets support a serialized Transaction object generated by the Hedera Javascript SDK.
|
|
197
|
-
* Both options are supported here for backwards compatibility.
|
|
198
|
-
* @returns Promise\<{@link SignTransactionResult}\>
|
|
199
|
-
* @example
|
|
200
|
-
* ```ts
|
|
201
|
-
*
|
|
202
|
-
* const params = {
|
|
203
|
-
* signerAccountId: '0.0.12345',
|
|
204
|
-
* transactionBody
|
|
205
|
-
* }
|
|
206
|
-
*
|
|
207
|
-
* const result = await dAppConnector.signTransaction(params)
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
signTransaction(params: SignTransactionParams): Promise<Transaction | SignTransactionResult>;
|
|
211
|
-
private handleSessionEvent;
|
|
212
|
-
private handleSessionUpdate;
|
|
213
|
-
private handleSessionDelete;
|
|
214
|
-
private handlePairingDelete;
|
|
215
|
-
}
|
|
216
|
-
export default DAppConnector;
|