@hashgraph/hedera-wallet-connect 1.3.6 → 1.3.7-canary.14806a9.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{lib/dapp → dapp}/DAppSigner.d.ts +15 -1
- package/dist/{lib/dapp → dapp}/DAppSigner.js +105 -28
- package/dist/{lib/dapp → dapp}/index.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/{lib/shared → shared}/logger.d.ts +1 -0
- package/dist/{lib/shared → shared}/logger.js +3 -0
- package/package.json +3 -3
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/index.js +0 -22
- /package/dist/{lib/dapp → dapp}/index.d.ts +0 -0
- /package/dist/{lib/shared → shared}/chainIds.d.ts +0 -0
- /package/dist/{lib/shared → shared}/chainIds.js +0 -0
- /package/dist/{lib/shared → shared}/errors.d.ts +0 -0
- /package/dist/{lib/shared → shared}/errors.js +0 -0
- /package/dist/{lib/shared → shared}/events.d.ts +0 -0
- /package/dist/{lib/shared → shared}/events.js +0 -0
- /package/dist/{lib/shared → shared}/extensionController.d.ts +0 -0
- /package/dist/{lib/shared → shared}/extensionController.js +0 -0
- /package/dist/{lib/shared → shared}/index.d.ts +0 -0
- /package/dist/{lib/shared → shared}/index.js +0 -0
- /package/dist/{lib/shared → shared}/methods.d.ts +0 -0
- /package/dist/{lib/shared → shared}/methods.js +0 -0
- /package/dist/{lib/shared → shared}/payloads.d.ts +0 -0
- /package/dist/{lib/shared → shared}/payloads.js +0 -0
- /package/dist/{lib/shared → shared}/utils.d.ts +0 -0
- /package/dist/{lib/shared → shared}/utils.js +0 -0
- /package/dist/{lib/wallet → wallet}/index.d.ts +0 -0
- /package/dist/{lib/wallet → wallet}/index.js +0 -0
- /package/dist/{lib/wallet → wallet}/provider.d.ts +0 -0
- /package/dist/{lib/wallet → wallet}/provider.js +0 -0
- /package/dist/{lib/wallet → wallet}/types.d.ts +0 -0
- /package/dist/{lib/wallet → wallet}/types.js +0 -0
@@ -6,7 +6,13 @@ export declare class DAppSigner implements Signer {
|
|
6
6
|
readonly topic: string;
|
7
7
|
private readonly ledgerId;
|
8
8
|
readonly extensionId?: string | undefined;
|
9
|
-
|
9
|
+
private logger;
|
10
|
+
constructor(accountId: AccountId, signClient: ISignClient, topic: string, ledgerId?: LedgerId, extensionId?: string | undefined, logLevel?: 'error' | 'warn' | 'info' | 'debug');
|
11
|
+
/**
|
12
|
+
* Sets the logging level for the DAppSigner
|
13
|
+
* @param level - The logging level to set
|
14
|
+
*/
|
15
|
+
setLogLevel(level: 'error' | 'warn' | 'info' | 'debug'): void;
|
10
16
|
private _getHederaClient;
|
11
17
|
private get _signerAccountId();
|
12
18
|
private _getRandomNodes;
|
@@ -39,6 +45,14 @@ export declare class DAppSigner implements Signer {
|
|
39
45
|
signTransaction<T extends Transaction>(transaction: T): Promise<T>;
|
40
46
|
private _tryExecuteTransactionRequest;
|
41
47
|
private _parseQueryResponse;
|
48
|
+
/**
|
49
|
+
* Executes a free receipt query without signing a transaction.
|
50
|
+
* Enables the DApp to fetch the receipt of a transaction without making a new request
|
51
|
+
* to the wallet.
|
52
|
+
* @param request - The query to execute
|
53
|
+
* @returns The result of the query
|
54
|
+
*/
|
55
|
+
private executeReceiptQueryFromRequest;
|
42
56
|
private _tryExecuteQueryRequest;
|
43
57
|
call<RequestT, ResponseT, OutputT>(request: Executable<RequestT, ResponseT, OutputT>): Promise<OutputT>;
|
44
58
|
}
|
@@ -20,14 +20,25 @@
|
|
20
20
|
import { AccountBalance, AccountId, 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
22
|
import { HederaJsonRpcMethod, Uint8ArrayToBase64String, base64StringToSignatureMap, base64StringToUint8Array, ledgerIdToCAIPChainId, queryToBase64String, transactionBodyToBase64String, transactionToBase64String, transactionToTransactionBody, extensionOpen, } from '../shared';
|
23
|
+
import { DefaultLogger } from '../shared/logger';
|
23
24
|
const clients = {};
|
24
25
|
export class DAppSigner {
|
25
|
-
constructor(accountId, signClient, topic, ledgerId = LedgerId.MAINNET, extensionId) {
|
26
|
+
constructor(accountId, signClient, topic, ledgerId = LedgerId.MAINNET, extensionId, logLevel = 'debug') {
|
26
27
|
this.accountId = accountId;
|
27
28
|
this.signClient = signClient;
|
28
29
|
this.topic = topic;
|
29
30
|
this.ledgerId = ledgerId;
|
30
31
|
this.extensionId = extensionId;
|
32
|
+
this.logger = new DefaultLogger(logLevel);
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* Sets the logging level for the DAppSigner
|
36
|
+
* @param level - The logging level to set
|
37
|
+
*/
|
38
|
+
setLogLevel(level) {
|
39
|
+
if (this.logger instanceof DefaultLogger) {
|
40
|
+
this.logger.setLogLevel(level);
|
41
|
+
}
|
31
42
|
}
|
32
43
|
_getHederaClient() {
|
33
44
|
const ledgerIdString = this.ledgerId.toString();
|
@@ -85,21 +96,29 @@ export class DAppSigner {
|
|
85
96
|
return this.signClient.metadata;
|
86
97
|
}
|
87
98
|
async sign(data, signOptions) {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
sigmap.sigPair[0].
|
101
|
-
|
102
|
-
|
99
|
+
this.logger.debug('Signing data');
|
100
|
+
try {
|
101
|
+
const { signatureMap } = await this.request({
|
102
|
+
method: HederaJsonRpcMethod.SignMessage,
|
103
|
+
params: {
|
104
|
+
signerAccountId: this._signerAccountId,
|
105
|
+
message: Uint8ArrayToBase64String(data[0]),
|
106
|
+
},
|
107
|
+
});
|
108
|
+
const sigmap = base64StringToSignatureMap(signatureMap);
|
109
|
+
const signerSignature = new SignerSignature({
|
110
|
+
accountId: this.getAccountId(),
|
111
|
+
publicKey: PublicKey.fromBytes(sigmap.sigPair[0].pubKeyPrefix),
|
112
|
+
signature: sigmap.sigPair[0].ed25519 ||
|
113
|
+
sigmap.sigPair[0].ECDSASecp256k1,
|
114
|
+
});
|
115
|
+
this.logger.debug('Data signed successfully');
|
116
|
+
return [signerSignature];
|
117
|
+
}
|
118
|
+
catch (error) {
|
119
|
+
this.logger.error('Error signing data:', error);
|
120
|
+
throw error;
|
121
|
+
}
|
103
122
|
}
|
104
123
|
async checkTransaction(transaction) {
|
105
124
|
throw new Error('Method not implemented.');
|
@@ -141,7 +160,10 @@ export class DAppSigner {
|
|
141
160
|
}
|
142
161
|
async _tryExecuteTransactionRequest(request) {
|
143
162
|
try {
|
144
|
-
const
|
163
|
+
const requestToBytes = request.toBytes();
|
164
|
+
this.logger.debug('Creating transaction from bytes', requestToBytes, request);
|
165
|
+
const transaction = Transaction.fromBytes(requestToBytes);
|
166
|
+
this.logger.debug('Executing transaction request', transaction);
|
145
167
|
const result = await this.request({
|
146
168
|
method: HederaJsonRpcMethod.SignAndExecuteTransaction,
|
147
169
|
params: {
|
@@ -149,9 +171,11 @@ export class DAppSigner {
|
|
149
171
|
transactionList: transactionToBase64String(transaction),
|
150
172
|
},
|
151
173
|
});
|
174
|
+
this.logger.debug('Transaction request completed successfully');
|
152
175
|
return { result: TransactionResponse.fromJSON(result) };
|
153
176
|
}
|
154
177
|
catch (error) {
|
178
|
+
this.logger.error('Error executing transaction request:', error);
|
155
179
|
return { error };
|
156
180
|
}
|
157
181
|
}
|
@@ -178,9 +202,46 @@ export class DAppSigner {
|
|
178
202
|
throw new Error('Unsupported query type');
|
179
203
|
}
|
180
204
|
}
|
205
|
+
/**
|
206
|
+
* Executes a free receipt query without signing a transaction.
|
207
|
+
* Enables the DApp to fetch the receipt of a transaction without making a new request
|
208
|
+
* to the wallet.
|
209
|
+
* @param request - The query to execute
|
210
|
+
* @returns The result of the query
|
211
|
+
*/
|
212
|
+
async executeReceiptQueryFromRequest(request) {
|
213
|
+
try {
|
214
|
+
const isMainnet = this.ledgerId === LedgerId.MAINNET;
|
215
|
+
const client = isMainnet ? Client.forMainnet() : Client.forTestnet();
|
216
|
+
const receipt = TransactionReceiptQuery.fromBytes(request.toBytes());
|
217
|
+
const result = await receipt.execute(client);
|
218
|
+
return { result };
|
219
|
+
}
|
220
|
+
catch (error) {
|
221
|
+
return { error };
|
222
|
+
}
|
223
|
+
}
|
181
224
|
async _tryExecuteQueryRequest(request) {
|
182
225
|
try {
|
183
|
-
const
|
226
|
+
const isReceiptQuery = request instanceof TransactionReceiptQuery;
|
227
|
+
if (isReceiptQuery) {
|
228
|
+
this.logger.debug('Attempting to execute free receipt query', request);
|
229
|
+
const result = await this.executeReceiptQueryFromRequest(request);
|
230
|
+
if (!(result === null || result === void 0 ? void 0 : result.error)) {
|
231
|
+
return { result: result.result };
|
232
|
+
}
|
233
|
+
else {
|
234
|
+
this.logger.error('Error executing free receipt query. Sending to wallet.', result.error);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
/**
|
238
|
+
* Note, should we be converting these to specific query types?
|
239
|
+
* Left alone to avoid changing the API for other requests.
|
240
|
+
*/
|
241
|
+
const query = isReceiptQuery
|
242
|
+
? TransactionReceiptQuery.fromBytes(request.toBytes())
|
243
|
+
: Query.fromBytes(request.toBytes());
|
244
|
+
this.logger.debug('Executing query request', query, queryToBase64String(query), isReceiptQuery);
|
184
245
|
const result = await this.request({
|
185
246
|
method: HederaJsonRpcMethod.SignAndExecuteQuery,
|
186
247
|
params: {
|
@@ -188,6 +249,7 @@ export class DAppSigner {
|
|
188
249
|
query: queryToBase64String(query),
|
189
250
|
},
|
190
251
|
});
|
252
|
+
this.logger.debug('Query request completed successfully', result);
|
191
253
|
return { result: this._parseQueryResponse(query, result.response) };
|
192
254
|
}
|
193
255
|
catch (error) {
|
@@ -195,27 +257,42 @@ export class DAppSigner {
|
|
195
257
|
}
|
196
258
|
}
|
197
259
|
async call(request) {
|
198
|
-
var _a, _b, _c, _d, _e, _f;
|
199
|
-
const
|
200
|
-
|
201
|
-
|
260
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
261
|
+
const isReceiptQuery = request instanceof TransactionReceiptQuery;
|
262
|
+
let txResult = undefined;
|
263
|
+
// a receipt query is a free query and we should not execute a transaction.
|
264
|
+
if (!isReceiptQuery) {
|
265
|
+
txResult = await this._tryExecuteTransactionRequest(request);
|
266
|
+
if (txResult.result) {
|
267
|
+
return txResult.result;
|
268
|
+
}
|
202
269
|
}
|
203
270
|
const queryResult = await this._tryExecuteQueryRequest(request);
|
204
271
|
if (queryResult.result) {
|
205
272
|
return queryResult.result;
|
206
273
|
}
|
207
274
|
// TODO: make this error more usable
|
275
|
+
if (isReceiptQuery) {
|
276
|
+
throw new Error('Error executing receipt query: \n' +
|
277
|
+
JSON.stringify({
|
278
|
+
queryError: {
|
279
|
+
name: (_a = queryResult.error) === null || _a === void 0 ? void 0 : _a.name,
|
280
|
+
message: (_b = queryResult.error) === null || _b === void 0 ? void 0 : _b.message,
|
281
|
+
stack: (_c = queryResult.error) === null || _c === void 0 ? void 0 : _c.stack,
|
282
|
+
},
|
283
|
+
}));
|
284
|
+
}
|
208
285
|
throw new Error('Error executing transaction or query: \n' +
|
209
286
|
JSON.stringify({
|
210
287
|
txError: {
|
211
|
-
name: (
|
212
|
-
message: (
|
213
|
-
stack: (
|
288
|
+
name: (_d = txResult === null || txResult === void 0 ? void 0 : txResult.error) === null || _d === void 0 ? void 0 : _d.name,
|
289
|
+
message: (_e = txResult === null || txResult === void 0 ? void 0 : txResult.error) === null || _e === void 0 ? void 0 : _e.message,
|
290
|
+
stack: (_f = txResult === null || txResult === void 0 ? void 0 : txResult.error) === null || _f === void 0 ? void 0 : _f.stack,
|
214
291
|
},
|
215
292
|
queryError: {
|
216
|
-
name: (
|
217
|
-
message: (
|
218
|
-
stack: (
|
293
|
+
name: (_g = queryResult.error) === null || _g === void 0 ? void 0 : _g.name,
|
294
|
+
message: (_h = queryResult.error) === null || _h === void 0 ? void 0 : _h.message,
|
295
|
+
stack: (_j = queryResult.error) === null || _j === void 0 ? void 0 : _j.stack,
|
219
296
|
},
|
220
297
|
}, null, 2));
|
221
298
|
}
|
@@ -309,7 +309,7 @@ export class DAppConnector {
|
|
309
309
|
const allNamespaceAccounts = accountAndLedgerFromSession(session);
|
310
310
|
return allNamespaceAccounts.map(({ account, network }) => {
|
311
311
|
var _a;
|
312
|
-
return new DAppSigner(account, this.walletConnectClient, session.topic, network, (_a = session.sessionProperties) === null || _a === void 0 ? void 0 : _a.extensionId);
|
312
|
+
return new DAppSigner(account, this.walletConnectClient, session.topic, network, (_a = session.sessionProperties) === null || _a === void 0 ? void 0 : _a.extensionId, this.logger instanceof DefaultLogger ? this.logger.getLogLevel() : 'debug');
|
313
313
|
});
|
314
314
|
}
|
315
315
|
async onSessionConnected(session) {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -8,6 +8,7 @@ export declare class DefaultLogger implements ILogger {
|
|
8
8
|
private logLevel;
|
9
9
|
constructor(logLevel?: 'error' | 'warn' | 'info' | 'debug');
|
10
10
|
setLogLevel(level: 'error' | 'warn' | 'info' | 'debug'): void;
|
11
|
+
getLogLevel(): 'error' | 'warn' | 'info' | 'debug';
|
11
12
|
error(message: string, ...args: any[]): void;
|
12
13
|
warn(message: string, ...args: any[]): void;
|
13
14
|
info(message: string, ...args: any[]): void;
|
@@ -6,6 +6,9 @@ export class DefaultLogger {
|
|
6
6
|
setLogLevel(level) {
|
7
7
|
this.logLevel = level;
|
8
8
|
}
|
9
|
+
getLogLevel() {
|
10
|
+
return this.logLevel;
|
11
|
+
}
|
9
12
|
error(message, ...args) {
|
10
13
|
if (['error', 'warn', 'info', 'debug'].includes(this.logLevel)) {
|
11
14
|
console.error(`[ERROR] ${message}`, ...args);
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hashgraph/hedera-wallet-connect",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.7-canary.14806a9.0",
|
4
4
|
"description": "A library to facilitate integrating Hedera with WalletConnect",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
7
7
|
"url": "git+https://github.com/hashgraph/hedera-wallet-connect.git"
|
8
8
|
},
|
9
|
-
"main": "./dist/index.js",
|
10
|
-
"types": "./dist/index.d.ts",
|
9
|
+
"main": "./dist/src/index.js",
|
10
|
+
"types": "./dist/src/index.d.ts",
|
11
11
|
"author": "Hgraph <support@hgraph.io>",
|
12
12
|
"keywords": [
|
13
13
|
"hedera",
|
package/dist/lib/index.d.ts
DELETED
package/dist/lib/index.js
DELETED
@@ -1,22 +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 './shared';
|
21
|
-
export { default as Wallet } from './wallet';
|
22
|
-
export * from './dapp';
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|