@hashgraph/hedera-wallet-connect 2.0.5-canary.7b24ac9.0 → 2.0.5-canary.7ea5475.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 +1 -1
- 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/README.md
CHANGED
|
@@ -121,7 +121,7 @@ await dAppConnector.openModal()
|
|
|
121
121
|
2. Add Hedera dependencies to your project:
|
|
122
122
|
|
|
123
123
|
```sh
|
|
124
|
-
npm install @hashgraph/hedera-wallet-connect
|
|
124
|
+
npm install @hashgraph/hedera-wallet-connect @hashgraph/sdk @walletconnect/universal-provider
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
3. Update `createAppKit` with adapters and a universal provider for Hedera. Note the
|
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.7ea5475.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
|
-
}
|