@hashgraph/hedera-wallet-connect 1.5.2-canary.93d61f2.0 → 1.5.2-canary.9f9d03e.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.
@@ -16,6 +16,7 @@ export declare class DAppSigner implements Signer {
16
16
  setLogLevel(level: LogLevel): void;
17
17
  private _getHederaClient;
18
18
  private get _signerAccountId();
19
+ private _getRandomNodes;
19
20
  request<T>(request: {
20
21
  method: string;
21
22
  params: any;
@@ -17,7 +17,7 @@
17
17
  * limitations under the License.
18
18
  *
19
19
  */
20
- import { AccountBalance, AccountInfo, LedgerId, SignerSignature, Transaction, TransactionRecord, Client, PublicKey, TransactionId, TransactionResponse, Query, AccountRecordsQuery, AccountInfoQuery, AccountBalanceQuery, TransactionReceiptQuery, TransactionReceipt, TransactionRecordQuery, } from '@hashgraph/sdk';
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, base64StringToSignatureMap, base64StringToUint8Array, ledgerIdToCAIPChainId, queryToBase64String, transactionBodyToBase64String, transactionToBase64String, transactionToTransactionBody, extensionOpen, Uint8ArrayToBase64String, Uint8ArrayToString, } from '../shared';
23
23
  import { DefaultLogger } from '../shared/logger';
@@ -51,6 +51,15 @@ export class DAppSigner {
51
51
  get _signerAccountId() {
52
52
  return `${ledgerIdToCAIPChainId(this.ledgerId)}:${this.accountId.toString()}`;
53
53
  }
54
+ _getRandomNodes(numberOfNodes) {
55
+ const allNodes = Object.values(this._getHederaClient().network).map((o) => typeof o === 'string' ? AccountId.fromString(o) : o);
56
+ // shuffle nodes
57
+ for (let i = allNodes.length - 1; i > 0; i--) {
58
+ const j = Math.floor(Math.random() * (i + 1));
59
+ [allNodes[i], allNodes[j]] = [allNodes[j], allNodes[i]];
60
+ }
61
+ return allNodes.slice(0, numberOfNodes);
62
+ }
54
63
  request(request) {
55
64
  var _a, _b;
56
65
  // Avoid a wallet call if the session is no longer valid
@@ -135,7 +144,9 @@ export class DAppSigner {
135
144
  throw new Error('Method not implemented.');
136
145
  }
137
146
  async populateTransaction(transaction) {
138
- return transaction.setTransactionId(TransactionId.generate(this.getAccountId()));
147
+ return transaction
148
+ .setNodeAccountIds(this._getRandomNodes(10)) // allow retrying on up to 10 nodes
149
+ .setTransactionId(TransactionId.generate(this.getAccountId()));
139
150
  }
140
151
  /**
141
152
  * Prepares a transaction object for signing using a single node account id.
@@ -146,7 +157,12 @@ export class DAppSigner {
146
157
  * @returns transaction - `Transaction` object with signature
147
158
  */
148
159
  async signTransaction(transaction) {
149
- const transactionBody = transactionToTransactionBody(transaction);
160
+ let nodeAccountId;
161
+ if (!transaction.nodeAccountIds || transaction.nodeAccountIds.length === 0)
162
+ nodeAccountId = this._getRandomNodes(1)[0];
163
+ else
164
+ nodeAccountId = transaction.nodeAccountIds[0];
165
+ const transactionBody = transactionToTransactionBody(transaction, nodeAccountId);
150
166
  if (!transactionBody)
151
167
  throw new Error('Failed to serialize transaction body');
152
168
  const transactionBodyBase64 = transactionBodyToBase64String(transactionBody);
@@ -1,6 +1,23 @@
1
1
  import { AccountId, PublicKey, Transaction, LedgerId, Query, SignerSignature } from '@hashgraph/sdk';
2
2
  import { ProposalTypes, SessionTypes } from '@walletconnect/types';
3
3
  import { proto } from '@hashgraph/proto';
4
+ /**
5
+ * Freezes a transaction if it is not already frozen. Transactions must
6
+ * be frozen before they can be converted to bytes.
7
+ *
8
+ * @param transaction - Any instance of a class that extends `Transaction`
9
+ */
10
+ export declare function freezeTransaction<T extends Transaction>(transaction: T): void;
11
+ /**
12
+ * Sets default consensus nodes that a transaction will be submitted to. Node Account ID(s)
13
+ * must be set before a transaction can be frozen. If they have already been set, this
14
+ * function will not modify the transaction.
15
+ * @param transaction - any instance of a class that extends `Transaction`
16
+ *
17
+ * @see {@link https://docs.hedera.com/hedera/networks/testnet/testnet-nodes | Full list of Testnet-nodes}
18
+ * @see {@link https://docs.hedera.com/hedera/networks/mainnet/mainnet-nodes | Full list of Mainnet-nodes}
19
+ */
20
+ export declare function setDefaultNodeAccountIds<T extends Transaction>(transaction: T): void;
4
21
  /**
5
22
  * Converts `Transaction` to a Base64-string.
6
23
  *
@@ -30,10 +47,9 @@ export declare function transactionToBase64String<T extends Transaction>(transac
30
47
  export declare function base64StringToTransaction<T extends Transaction>(transactionBytes: string): T;
31
48
  /**
32
49
  * @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
33
- * @param nodeAccountId - an optional `AccountId` to set the node account ID for the transaction
34
50
  * @returns `string`
35
51
  * */
36
- export declare function transactionToTransactionBody<T extends Transaction>(transaction: T, nodeAccountId?: AccountId | null): proto.ITransactionBody;
52
+ export declare function transactionToTransactionBody<T extends Transaction>(transaction: T, nodeAccountId: AccountId): any;
37
53
  export declare function transactionBodyToBase64String(transactionBody: proto.ITransactionBody): string;
38
54
  /**
39
55
  * @param transactionList - a proto.TransactionList object
@@ -20,6 +20,30 @@
20
20
  import { Buffer } from 'buffer';
21
21
  import { AccountId, Transaction, LedgerId, Query, } from '@hashgraph/sdk';
22
22
  import { proto } from '@hashgraph/proto';
23
+ /**
24
+ * Freezes a transaction if it is not already frozen. Transactions must
25
+ * be frozen before they can be converted to bytes.
26
+ *
27
+ * @param transaction - Any instance of a class that extends `Transaction`
28
+ */
29
+ export function freezeTransaction(transaction) {
30
+ if (!transaction.isFrozen())
31
+ transaction.freeze();
32
+ }
33
+ /**
34
+ * Sets default consensus nodes that a transaction will be submitted to. Node Account ID(s)
35
+ * must be set before a transaction can be frozen. If they have already been set, this
36
+ * function will not modify the transaction.
37
+ * @param transaction - any instance of a class that extends `Transaction`
38
+ *
39
+ * @see {@link https://docs.hedera.com/hedera/networks/testnet/testnet-nodes | Full list of Testnet-nodes}
40
+ * @see {@link https://docs.hedera.com/hedera/networks/mainnet/mainnet-nodes | Full list of Mainnet-nodes}
41
+ */
42
+ export function setDefaultNodeAccountIds(transaction) {
43
+ const isNodeAccountIdNotSet = !transaction.nodeAccountIds || transaction.nodeAccountIds.length === 0;
44
+ if (!transaction.isFrozen() && isNodeAccountIdNotSet)
45
+ transaction.setNodeAccountIds([new AccountId(3), new AccountId(4), new AccountId(5)]);
46
+ }
23
47
  /**
24
48
  * Converts `Transaction` to a Base64-string.
25
49
  *
@@ -29,6 +53,8 @@ import { proto } from '@hashgraph/proto';
29
53
  * @returns Base64 encoded representation of the input `Transaction` object
30
54
  */
31
55
  export function transactionToBase64String(transaction) {
56
+ setDefaultNodeAccountIds(transaction);
57
+ freezeTransaction(transaction);
32
58
  const transactionBytes = transaction.toBytes();
33
59
  return Buffer.from(transactionBytes).toString('base64');
34
60
  }
@@ -55,10 +81,9 @@ export function base64StringToTransaction(transactionBytes) {
55
81
  }
56
82
  /**
57
83
  * @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
58
- * @param nodeAccountId - an optional `AccountId` to set the node account ID for the transaction
59
84
  * @returns `string`
60
85
  * */
61
- export function transactionToTransactionBody(transaction, nodeAccountId = null) {
86
+ export function transactionToTransactionBody(transaction, nodeAccountId) {
62
87
  // This is a private function, though provides the capabilities to construct a proto.TransactionBody
63
88
  //@ts-ignore
64
89
  return transaction._makeTransactionBody(nodeAccountId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashgraph/hedera-wallet-connect",
3
- "version": "1.5.2-canary.93d61f2.0",
3
+ "version": "1.5.2-canary.9f9d03e.0",
4
4
  "description": "A library to facilitate integrating Hedera with WalletConnect",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,8 +22,8 @@
22
22
  "@hashgraph/hedera-wallet-connect": "^1.5.0",
23
23
  "@swc/core": "^1.7.40",
24
24
  "@swc/jest": "^0.2.36",
25
- "@types/jest": "^30.0.0",
26
- "@types/node": "^24.0.3",
25
+ "@types/jest": "^29.5.3",
26
+ "@types/node": "^22.5.0",
27
27
  "@types/react-dom": "^19.0.3",
28
28
  "@walletconnect/modal": "^2.7.0",
29
29
  "@walletconnect/sign-client": "^2.19.1",
@@ -32,7 +32,9 @@
32
32
  "esbuild": "^0.25.0",
33
33
  "esbuild-plugin-copy": "^2.1.1",
34
34
  "eslint-plugin-tsdoc": "^0.4.0",
35
- "jest": "^30.0.0",
35
+ "husky": "^9.0.6",
36
+ "jest": "^29.7.0",
37
+ "lint-staged": "^16.0.0",
36
38
  "lokijs": "^1.5.12",
37
39
  "long": "^5.2.3",
38
40
  "nodemon": "^3.0.3",
@@ -42,18 +44,29 @@
42
44
  "rimraf": "^5.0.5",
43
45
  "ts-node": "^10.9.2",
44
46
  "tweetnacl": "^1.0.3",
47
+ "typedoc": "^0.27.6",
48
+ "typedoc-theme-hierarchy": "^5.0.0",
45
49
  "typescript": "^5.2.2"
46
50
  },
47
51
  "scripts": {
48
52
  "build": "rimraf dist && tsc",
53
+ "build:ts-demo": "node scripts/demos/typescript/build.mjs",
54
+ "build:react-demo": "node scripts/demos/react/build.mjs",
55
+ "build:docs": "typedoc --options typedoc.json",
49
56
  "watch": "nodemon --watch src/lib/ --ext ts --exec \"npm run build\"",
57
+ "dev": "npm run dev:ts-demo",
58
+ "dev:docs": "cd docs && npm run start",
59
+ "dev:ts-demo": "rimraf dist && npm run build && concurrently --raw \"npm run watch\" \"node scripts/demos/typescript/dev.mjs\"",
60
+ "dev:react-demo": "rimraf dist && npm run build && concurrently --raw \"npm run watch\" \"node scripts/demos/react/dev.mjs\"",
50
61
  "test": "jest",
51
62
  "test:watch": "jest --watch",
52
63
  "test:connect": "jest --testMatch '**/DAppConnector.test.ts' --verbose",
53
64
  "test:signer": "jest --testMatch '**/DAppSigner.test.ts' --verbose",
54
65
  "prepublishOnly": "rm -Rf dist && npm run build",
66
+ "prepare": "husky install",
55
67
  "prettier:check": "prettier --check ./src/",
56
68
  "prettier:fix": "prettier --write ./src/",
69
+ "prod:docs-docker": "sh docker-run.sh",
57
70
  "test:sigMap": "jest --testMatch '**/SignatureMapHelpers.test.ts' --verbose",
58
71
  "test:coverage": "jest --coverage",
59
72
  "test:coverage:html": "jest --coverage --coverageReporters='text-summary' --coverageReporters='html'"