@hashgraph/hedera-wallet-connect 1.3.7-canary.813a6d2.0 → 1.3.7-canary.9fbf780.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/dist/{src/lib/dapp → dapp}/DAppSigner.d.ts +15 -1
  2. package/dist/{src/lib/dapp → dapp}/DAppSigner.js +106 -30
  3. package/dist/{src/lib/dapp → dapp}/index.d.ts +4 -0
  4. package/dist/{src/lib/dapp → dapp}/index.js +43 -47
  5. package/dist/{src/lib/shared → shared}/logger.d.ts +1 -0
  6. package/dist/{src/lib/shared → shared}/logger.js +3 -0
  7. package/package.json +5 -2
  8. package/dist/src/index.d.ts +0 -1
  9. package/dist/src/index.js +0 -20
  10. package/dist/test/_helpers.d.ts +0 -38
  11. package/dist/test/_helpers.js +0 -95
  12. package/dist/test/dapp/DAppConnector.test.d.ts +0 -1
  13. package/dist/test/dapp/DAppConnector.test.js +0 -234
  14. package/dist/test/dapp/DAppSigner.test.d.ts +0 -1
  15. package/dist/test/dapp/DAppSigner.test.js +0 -155
  16. package/dist/test/utils.test.d.ts +0 -1
  17. package/dist/test/utils.test.js +0 -201
  18. package/dist/test/wallet/methods/wallet-executeTransaction.test.d.ts +0 -1
  19. package/dist/test/wallet/methods/wallet-executeTransaction.test.js +0 -43
  20. package/dist/test/wallet/methods/wallet-getNodeAddresses.test.d.ts +0 -1
  21. package/dist/test/wallet/methods/wallet-getNodeAddresses.test.js +0 -40
  22. package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.d.ts +0 -1
  23. package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.js +0 -41
  24. package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.d.ts +0 -1
  25. package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.js +0 -48
  26. package/dist/test/wallet/methods/wallet-signMessage.test.d.ts +0 -1
  27. package/dist/test/wallet/methods/wallet-signMessage.test.js +0 -60
  28. package/dist/test/wallet/methods/wallet-signTransaction.test.d.ts +0 -1
  29. package/dist/test/wallet/methods/wallet-signTransaction.test.js +0 -47
  30. package/dist/test/wallet/wallet-init.test.d.ts +0 -1
  31. package/dist/test/wallet/wallet-init.test.js +0 -53
  32. /package/dist/{src/lib/index.d.ts → index.d.ts} +0 -0
  33. /package/dist/{src/lib/index.js → index.js} +0 -0
  34. /package/dist/{src/lib/shared → shared}/chainIds.d.ts +0 -0
  35. /package/dist/{src/lib/shared → shared}/chainIds.js +0 -0
  36. /package/dist/{src/lib/shared → shared}/errors.d.ts +0 -0
  37. /package/dist/{src/lib/shared → shared}/errors.js +0 -0
  38. /package/dist/{src/lib/shared → shared}/events.d.ts +0 -0
  39. /package/dist/{src/lib/shared → shared}/events.js +0 -0
  40. /package/dist/{src/lib/shared → shared}/extensionController.d.ts +0 -0
  41. /package/dist/{src/lib/shared → shared}/extensionController.js +0 -0
  42. /package/dist/{src/lib/shared → shared}/index.d.ts +0 -0
  43. /package/dist/{src/lib/shared → shared}/index.js +0 -0
  44. /package/dist/{src/lib/shared → shared}/methods.d.ts +0 -0
  45. /package/dist/{src/lib/shared → shared}/methods.js +0 -0
  46. /package/dist/{src/lib/shared → shared}/payloads.d.ts +0 -0
  47. /package/dist/{src/lib/shared → shared}/payloads.js +0 -0
  48. /package/dist/{src/lib/shared → shared}/utils.d.ts +0 -0
  49. /package/dist/{src/lib/shared → shared}/utils.js +0 -0
  50. /package/dist/{src/lib/wallet → wallet}/index.d.ts +0 -0
  51. /package/dist/{src/lib/wallet → wallet}/index.js +0 -0
  52. /package/dist/{src/lib/wallet → wallet}/provider.d.ts +0 -0
  53. /package/dist/{src/lib/wallet → wallet}/provider.js +0 -0
  54. /package/dist/{src/lib/wallet → wallet}/types.d.ts +0 -0
  55. /package/dist/{src/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
- constructor(accountId: AccountId, signClient: ISignClient, topic: string, ledgerId?: LedgerId, extensionId?: string | undefined);
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();
@@ -49,9 +60,8 @@ export class DAppSigner {
49
60
  return allNodes.slice(0, numberOfNodes);
50
61
  }
51
62
  request(request) {
52
- if (this.extensionId) {
63
+ if (this.extensionId)
53
64
  extensionOpen(this.extensionId);
54
- }
55
65
  return this.signClient.request({
56
66
  topic: this.topic,
57
67
  request,
@@ -86,21 +96,29 @@ export class DAppSigner {
86
96
  return this.signClient.metadata;
87
97
  }
88
98
  async sign(data, signOptions) {
89
- const { signatureMap } = await this.request({
90
- method: HederaJsonRpcMethod.SignMessage,
91
- params: {
92
- signerAccountId: this._signerAccountId,
93
- message: Uint8ArrayToBase64String(data[0]),
94
- },
95
- });
96
- const sigmap = base64StringToSignatureMap(signatureMap);
97
- const signerSignature = new SignerSignature({
98
- accountId: this.getAccountId(),
99
- publicKey: PublicKey.fromBytes(sigmap.sigPair[0].pubKeyPrefix),
100
- signature: sigmap.sigPair[0].ed25519 ||
101
- sigmap.sigPair[0].ECDSASecp256k1,
102
- });
103
- return [signerSignature];
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
+ }
104
122
  }
105
123
  async checkTransaction(transaction) {
106
124
  throw new Error('Method not implemented.');
@@ -142,7 +160,10 @@ export class DAppSigner {
142
160
  }
143
161
  async _tryExecuteTransactionRequest(request) {
144
162
  try {
145
- const transaction = Transaction.fromBytes(request.toBytes());
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);
146
167
  const result = await this.request({
147
168
  method: HederaJsonRpcMethod.SignAndExecuteTransaction,
148
169
  params: {
@@ -150,9 +171,11 @@ export class DAppSigner {
150
171
  transactionList: transactionToBase64String(transaction),
151
172
  },
152
173
  });
174
+ this.logger.debug('Transaction request completed successfully');
153
175
  return { result: TransactionResponse.fromJSON(result) };
154
176
  }
155
177
  catch (error) {
178
+ this.logger.error('Error executing transaction request:', error);
156
179
  return { error };
157
180
  }
158
181
  }
@@ -179,9 +202,46 @@ export class DAppSigner {
179
202
  throw new Error('Unsupported query type');
180
203
  }
181
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
+ }
182
224
  async _tryExecuteQueryRequest(request) {
183
225
  try {
184
- const query = Query.fromBytes(request.toBytes());
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);
185
245
  const result = await this.request({
186
246
  method: HederaJsonRpcMethod.SignAndExecuteQuery,
187
247
  params: {
@@ -189,6 +249,7 @@ export class DAppSigner {
189
249
  query: queryToBase64String(query),
190
250
  },
191
251
  });
252
+ this.logger.debug('Query request completed successfully', result);
192
253
  return { result: this._parseQueryResponse(query, result.response) };
193
254
  }
194
255
  catch (error) {
@@ -196,27 +257,42 @@ export class DAppSigner {
196
257
  }
197
258
  }
198
259
  async call(request) {
199
- var _a, _b, _c, _d, _e, _f;
200
- const txResult = await this._tryExecuteTransactionRequest(request);
201
- if (txResult.result) {
202
- return txResult.result;
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
+ }
203
269
  }
204
270
  const queryResult = await this._tryExecuteQueryRequest(request);
205
271
  if (queryResult.result) {
206
272
  return queryResult.result;
207
273
  }
208
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
+ }
209
285
  throw new Error('Error executing transaction or query: \n' +
210
286
  JSON.stringify({
211
287
  txError: {
212
- name: (_a = txResult.error) === null || _a === void 0 ? void 0 : _a.name,
213
- message: (_b = txResult.error) === null || _b === void 0 ? void 0 : _b.message,
214
- stack: (_c = txResult.error) === null || _c === void 0 ? void 0 : _c.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,
215
291
  },
216
292
  queryError: {
217
- name: (_d = queryResult.error) === null || _d === void 0 ? void 0 : _d.name,
218
- message: (_e = queryResult.error) === null || _e === void 0 ? void 0 : _e.message,
219
- stack: (_f = queryResult.error) === null || _f === void 0 ? void 0 : _f.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,
220
296
  },
221
297
  }, null, 2));
222
298
  }
@@ -211,5 +211,9 @@ export declare class DAppConnector {
211
211
  * ```
212
212
  */
213
213
  signTransaction(params: SignTransactionParams): Promise<SignTransactionResult>;
214
+ private handleSessionEvent;
215
+ private handleSessionUpdate;
216
+ private handleSessionDelete;
217
+ private handlePairingDelete;
214
218
  }
215
219
  export default DAppConnector;
@@ -99,59 +99,21 @@ export class DAppConnector {
99
99
  if (!this.projectId) {
100
100
  throw new Error('Project ID is not defined');
101
101
  }
102
- const signClient = await SignClient.init({
102
+ this.walletConnectClient = await SignClient.init({
103
103
  logger,
104
104
  relayUrl: 'wss://relay.walletconnect.com',
105
105
  projectId: this.projectId,
106
106
  metadata: this.dAppMetadata,
107
107
  });
108
- this.walletConnectClient = signClient;
109
108
  const existingSessions = this.walletConnectClient.session.getAll();
110
- if (existingSessions.length > 0) {
109
+ if (existingSessions.length > 0)
111
110
  this.signers = existingSessions.flatMap((session) => this.createSigners(session));
112
- }
113
- else {
114
- await this.checkIframeConnect();
115
- }
116
- this.walletConnectClient.on('session_event', (event) => {
117
- // Handle session events, such as "chainChanged", "accountsChanged", etc.
118
- this.logger.debug('Session event received:', event);
119
- this.validateAndRefreshSigners();
120
- });
121
- this.walletConnectClient.on('session_update', ({ topic, params }) => {
122
- // Handle session update
123
- const { namespaces } = params;
124
- const _session = this.walletConnectClient.session.get(topic);
125
- // Overwrite the `namespaces` of the existing session with the incoming one.
126
- const updatedSession = Object.assign(Object.assign({}, _session), { namespaces });
127
- // Integrate the updated session state into your dapp state.
128
- this.logger.info('Session updated:', updatedSession);
129
- this.signers = this.signers.filter((signer) => signer.topic !== topic);
130
- this.signers.push(...this.createSigners(updatedSession));
131
- });
132
- this.walletConnectClient.on('session_delete', (pairing) => {
133
- this.logger.info('Session deleted:', pairing);
134
- this.signers = this.signers.filter((signer) => signer.topic !== pairing.topic);
135
- // Session was deleted -> reset the dapp state, clean up from user session, etc.
136
- try {
137
- this.disconnect(pairing.topic);
138
- }
139
- catch (e) {
140
- this.logger.error('Error disconnecting session:', e);
141
- }
142
- this.logger.info('Session deleted by wallet');
143
- });
144
- this.walletConnectClient.core.pairing.events.on('pairing_delete', (pairing) => {
145
- this.logger.info('Pairing deleted:', pairing);
146
- this.signers = this.signers.filter((signer) => signer.topic !== pairing.topic);
147
- try {
148
- this.disconnect(pairing.topic);
149
- }
150
- catch (e) {
151
- this.logger.error('Error disconnecting pairing:', e);
152
- }
153
- this.logger.info('Pairing deleted by wallet');
154
- });
111
+ else
112
+ this.checkIframeConnect();
113
+ this.walletConnectClient.on('session_event', this.handleSessionEvent.bind(this));
114
+ this.walletConnectClient.on('session_update', this.handleSessionUpdate.bind(this));
115
+ this.walletConnectClient.on('session_delete', this.handleSessionDelete.bind(this));
116
+ this.walletConnectClient.core.pairing.events.on('pairing_delete', this.handlePairingDelete.bind(this));
155
117
  }
156
118
  catch (e) {
157
119
  this.logger.error('Error initializing DAppConnector:', e);
@@ -347,7 +309,7 @@ export class DAppConnector {
347
309
  const allNamespaceAccounts = accountAndLedgerFromSession(session);
348
310
  return allNamespaceAccounts.map(({ account, network }) => {
349
311
  var _a;
350
- 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');
351
313
  });
352
314
  }
353
315
  async onSessionConnected(session) {
@@ -545,5 +507,39 @@ export class DAppConnector {
545
507
  params,
546
508
  });
547
509
  }
510
+ handleSessionEvent(args) {
511
+ this.logger.debug('Session event received:', args);
512
+ this.validateAndRefreshSigners();
513
+ }
514
+ handleSessionUpdate({ topic, params, }) {
515
+ const { namespaces } = params;
516
+ const _session = this.walletConnectClient.session.get(topic);
517
+ const updatedSession = Object.assign(Object.assign({}, _session), { namespaces });
518
+ this.logger.info('Session updated:', updatedSession);
519
+ this.signers = this.signers.filter((signer) => signer.topic !== topic);
520
+ this.signers.push(...this.createSigners(updatedSession));
521
+ }
522
+ handleSessionDelete(event) {
523
+ this.logger.info('Session deleted:', event);
524
+ this.signers = this.signers.filter((signer) => signer.topic !== event.topic);
525
+ try {
526
+ this.disconnect(event.topic);
527
+ }
528
+ catch (e) {
529
+ this.logger.error('Error disconnecting session:', e);
530
+ }
531
+ this.logger.info('Session deleted by wallet');
532
+ }
533
+ handlePairingDelete(event) {
534
+ this.logger.info('Pairing deleted:', event);
535
+ this.signers = this.signers.filter((signer) => signer.topic !== event.topic);
536
+ try {
537
+ this.disconnect(event.topic);
538
+ }
539
+ catch (e) {
540
+ this.logger.error('Error disconnecting pairing:', e);
541
+ }
542
+ this.logger.info('Pairing deleted by wallet');
543
+ }
548
544
  }
549
545
  export default DAppConnector;
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashgraph/hedera-wallet-connect",
3
- "version": "1.3.7-canary.813a6d2.0",
3
+ "version": "1.3.7-canary.9fbf780.0",
4
4
  "description": "A library to facilitate integrating Hedera with WalletConnect",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,6 +32,7 @@
32
32
  "husky": "^9.0.6",
33
33
  "jest": "^29.7.0",
34
34
  "lint-staged": "^15.1.0",
35
+ "long": "^5.2.3",
35
36
  "lokijs": "^1.5.12",
36
37
  "nodemon": "^3.0.3",
37
38
  "prettier": "^3.2.4",
@@ -61,7 +62,9 @@
61
62
  "prettier:check": "prettier --check ./src/",
62
63
  "prettier:fix": "prettier --write ./src/",
63
64
  "prod:docs-docker": "sh docker-run.sh",
64
- "test:sigMap": "jest --testMatch '**/SignatureMapHelpers.test.ts' --verbose"
65
+ "test:sigMap": "jest --testMatch '**/SignatureMapHelpers.test.ts' --verbose",
66
+ "test:coverage": "jest --coverage",
67
+ "test:coverage:html": "jest --coverage --coverageReporters='text-summary' --coverageReporters='html'"
65
68
  },
66
69
  "peerDependencies": {
67
70
  "@hashgraph/sdk": "^2.40.0",
@@ -1 +0,0 @@
1
- export * from './lib';
package/dist/src/index.js DELETED
@@ -1,20 +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';
@@ -1,38 +0,0 @@
1
- import { AccountId, Query, Transaction, TransactionId } from '@hashgraph/sdk';
2
- export declare const projectId = "ce06497abf4102004138a10edd29c921";
3
- export declare const walletMetadata: {
4
- name: string;
5
- url: string;
6
- description: string;
7
- icons: string[];
8
- };
9
- export declare const dAppMetadata: {
10
- name: string;
11
- url: string;
12
- description: string;
13
- icons: string[];
14
- };
15
- export declare const requestId = 1;
16
- export declare const requestTopic = "test-topic";
17
- export declare const defaultAccountNumber = 12345;
18
- export declare const defaultNodeId = 3;
19
- export declare const testUserAccountId: AccountId;
20
- export declare const testNodeAccountId: AccountId;
21
- /** Fixed to a specific timestamp */
22
- export declare const testTransactionId: TransactionId;
23
- type TransactionOptions = {
24
- setNodeAccountIds?: boolean;
25
- setTransactionId?: boolean;
26
- freeze?: boolean;
27
- operatorAccountId?: number;
28
- };
29
- export declare function prepareTestTransaction<T extends Transaction = Transaction>(transaction: T, options?: TransactionOptions): T;
30
- type QueryOptions = {
31
- setNodeAccountIds?: boolean;
32
- };
33
- export declare function prepareTestQuery<Q extends Query<OutputT>, OutputT>(query: Q, options?: QueryOptions): Q;
34
- export declare const testPrivateKeyECDSA = "3030020100300706052b8104000a042204203ce31ffad30d6db47c315bbea08232aad2266d8800a12aa3d8a812486e782759";
35
- export declare const testPrivateKeyED25519 = "302e020100300506032b657004220420133eefea772add1f995c96bccf42b08b76daf67665f0c4c5ae308fae9275c142";
36
- export declare function useJsonFixture(filename: string): any;
37
- export declare function writeJsonFixture(filename: string, data: any): void;
38
- export {};
@@ -1,95 +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 fs from 'fs';
21
- import path from 'path';
22
- import { AccountId, TransactionId } from '@hashgraph/sdk';
23
- export const projectId = 'ce06497abf4102004138a10edd29c921';
24
- export const walletMetadata = {
25
- name: 'Wallet Test',
26
- url: 'https://dapp.hedera.app',
27
- description: 'Hedera Hashgraph Wallet Example.',
28
- icons: [
29
- 'https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8xNFwvMTQzMTI3XC9wcm9qZWN0c1wvMTgwMjE1XC9hc3NldHNcL2M3XC8zNDU0ODY3XC85ZjM1NDliYmE5MGQ2NDA0OGU0NzlhZTNiMzkyYzY4Yy0xNTY2NTkxOTQ4LmpwZyJ9:frontify:v_zJvQTCjtNploUvnSpk8S5NJB4R5eei6f7ERL2KSeQ?width=800',
30
- ],
31
- };
32
- export const dAppMetadata = {
33
- name: 'dApp Test',
34
- url: 'https://dapp.hedera.app',
35
- description: 'Hedera Hashgraph dApp Example.',
36
- icons: [
37
- 'https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8xNFwvMTQzMTI3XC9wcm9qZWN0c1wvMTgwMjE1XC9hc3NldHNcL2M3XC8zNDU0ODY3XC85ZjM1NDliYmE5MGQ2NDA0OGU0NzlhZTNiMzkyYzY4Yy0xNTY2NTkxOTQ4LmpwZyJ9:frontify:v_zJvQTCjtNploUvnSpk8S5NJB4R5eei6f7ERL2KSeQ?width=800',
38
- ],
39
- };
40
- export const requestId = 1;
41
- export const requestTopic = 'test-topic';
42
- export const defaultAccountNumber = 12345;
43
- export const defaultNodeId = 3;
44
- export const testUserAccountId = new AccountId(defaultAccountNumber);
45
- export const testNodeAccountId = new AccountId(defaultNodeId);
46
- /** Fixed to a specific timestamp */
47
- export const testTransactionId = TransactionId.fromString(`0.0.${defaultAccountNumber}@1691705630.325343432`);
48
- export function prepareTestTransaction(transaction, options) {
49
- const selectedOptions = Object.assign({
50
- // defaults
51
- freeze: false, setNodeAccountIds: true, setTransactionId: true, operatorAccountId: defaultAccountNumber }, options);
52
- if (selectedOptions.setNodeAccountIds) {
53
- transaction.setNodeAccountIds([testNodeAccountId]);
54
- }
55
- if (selectedOptions.setTransactionId) {
56
- let transactionId = testTransactionId;
57
- if (selectedOptions.operatorAccountId &&
58
- selectedOptions.operatorAccountId !== defaultAccountNumber) {
59
- transactionId = TransactionId.generate(new AccountId(selectedOptions.operatorAccountId));
60
- }
61
- transaction.setTransactionId(transactionId);
62
- }
63
- if (selectedOptions.freeze) {
64
- transaction.freeze();
65
- }
66
- return transaction;
67
- }
68
- export function prepareTestQuery(query, options) {
69
- const selectedOptions = Object.assign({
70
- // defaults
71
- setNodeAccountIds: true }, options);
72
- if (selectedOptions.setNodeAccountIds) {
73
- query.setNodeAccountIds([testNodeAccountId]);
74
- }
75
- return query;
76
- }
77
- // from PrivateKey.generateECDSA().toStringDer()
78
- export const testPrivateKeyECDSA = '3030020100300706052b8104000a042204203ce31ffad30d6db47c315bbea08232aad2266d8800a12aa3d8a812486e782759';
79
- // from PrivateKey.generateED25519().toStringDer()
80
- export const testPrivateKeyED25519 = '302e020100300506032b657004220420133eefea772add1f995c96bccf42b08b76daf67665f0c4c5ae308fae9275c142';
81
- /** JSON fixture helpers */
82
- const FIXTURES_PATH = 'test/_fixtures';
83
- const filenameWithJsonExtension = (filename) => {
84
- const file = /\.json$/.test(filename) ? filename : filename + '.json';
85
- return path.join(FIXTURES_PATH, file);
86
- };
87
- export function useJsonFixture(filename) {
88
- const filepath = filenameWithJsonExtension(filename);
89
- const data = fs.readFileSync(filepath).toString();
90
- return JSON.parse(data);
91
- }
92
- export function writeJsonFixture(filename, data) {
93
- const filepath = filenameWithJsonExtension(filename);
94
- fs.writeFileSync(filepath, JSON.stringify(data, null, 2));
95
- }
@@ -1 +0,0 @@
1
- export {};