trac-msb 0.2.13 → 0.2.15

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.
Files changed (121) hide show
  1. package/.github/workflows/acceptance-tests.yml +38 -0
  2. package/.github/workflows/lint-pr-title.yml +26 -0
  3. package/.github/workflows/publish.yml +33 -0
  4. package/.github/workflows/unit-tests.yml +34 -0
  5. package/package.json +7 -12
  6. package/proto/network.proto +74 -0
  7. package/rpc/rpc_services.js +4 -22
  8. package/scripts/generate-protobufs.js +12 -37
  9. package/src/config/config.js +9 -26
  10. package/src/config/env.js +17 -27
  11. package/src/core/network/Network.js +36 -73
  12. package/src/core/network/protocols/LegacyProtocol.js +11 -21
  13. package/src/core/network/protocols/NetworkMessages.js +17 -38
  14. package/src/core/network/protocols/ProtocolInterface.js +2 -14
  15. package/src/core/network/protocols/ProtocolSession.js +17 -144
  16. package/src/core/network/protocols/V1Protocol.js +18 -37
  17. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +19 -25
  18. package/src/core/network/protocols/legacy/handlers/{LegacyGetRequestHandler.js → GetRequestHandler.js} +6 -6
  19. package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +37 -0
  20. package/src/core/network/protocols/{legacy/handlers/LegacyRoleOperationHandler.js → shared/handlers/RoleOperationHandler.js} +11 -18
  21. package/src/core/network/protocols/{legacy/handlers/LegacySubnetworkOperationHandler.js → shared/handlers/SubnetworkOperationHandler.js} +17 -28
  22. package/src/core/network/protocols/{legacy/handlers/LegacyTransferOperationHandler.js → shared/handlers/TransferOperationHandler.js} +11 -17
  23. package/src/core/network/protocols/{legacy/handlers/BaseStateOperationHandler.js → shared/handlers/base/BaseOperationHandler.js} +12 -23
  24. package/src/core/network/protocols/shared/validators/{PartialBootstrapDeploymentValidator.js → PartialBootstrapDeployment.js} +4 -9
  25. package/src/core/network/protocols/shared/validators/{PartialRoleAccessValidator.js → PartialRoleAccess.js} +17 -51
  26. package/src/core/network/protocols/shared/validators/{PartialTransactionValidator.js → PartialTransaction.js} +7 -21
  27. package/src/core/network/protocols/shared/validators/{PartialTransferValidator.js → PartialTransfer.js} +9 -26
  28. package/src/core/network/protocols/shared/validators/{PartialOperationValidator.js → base/PartialOperation.js} +25 -47
  29. package/src/core/network/protocols/v1/NetworkMessageRouter.js +7 -91
  30. package/src/core/network/services/ConnectionManager.js +94 -146
  31. package/src/core/network/services/MessageOrchestrator.js +27 -151
  32. package/src/core/network/services/TransactionPoolService.js +18 -129
  33. package/src/core/network/services/TransactionRateLimiterService.js +34 -52
  34. package/src/core/network/services/ValidatorObserverService.js +26 -18
  35. package/src/core/state/State.js +19 -70
  36. package/src/index.js +8 -6
  37. package/src/messages/network/v1/NetworkMessageBuilder.js +79 -59
  38. package/src/messages/network/v1/NetworkMessageDirector.js +50 -16
  39. package/src/utils/Scheduler.js +8 -0
  40. package/src/utils/constants.js +5 -71
  41. package/src/utils/helpers.js +1 -10
  42. package/src/utils/normalizers.js +0 -38
  43. package/src/utils/protobuf/network.cjs +840 -0
  44. package/src/utils/protobuf/operationHelpers.js +3 -24
  45. package/tests/acceptance/v1/account/account.test.mjs +2 -8
  46. package/tests/acceptance/v1/tx/tx.test.mjs +1 -23
  47. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +6 -34
  48. package/tests/fixtures/assembleMessage.fixtures.js +8 -7
  49. package/tests/fixtures/networkV1.fixtures.js +28 -2
  50. package/tests/helpers/autobaseTestHelpers.js +5 -2
  51. package/tests/helpers/createTestSignature.js +3 -2
  52. package/tests/helpers/transactionPayloads.mjs +2 -2
  53. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +79 -239
  54. package/tests/unit/messages/network/NetworkMessageDirector.test.js +77 -223
  55. package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +5 -1
  56. package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +5 -1
  57. package/tests/unit/network/ConnectionManager.test.js +191 -0
  58. package/tests/unit/network/networkModule.test.js +1 -4
  59. package/tests/unit/unit.test.js +2 -2
  60. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +2 -2
  61. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +2 -2
  62. package/tests/unit/utils/protobuf/operationHelpers.test.js +4 -2
  63. package/tests/unit/utils/utils.test.js +0 -1
  64. package/proto/network/v1/enums/message_type.proto +0 -16
  65. package/proto/network/v1/enums/result_code.proto +0 -84
  66. package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
  67. package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
  68. package/proto/network/v1/messages/liveness_request.proto +0 -8
  69. package/proto/network/v1/messages/liveness_response.proto +0 -11
  70. package/proto/network/v1/network_message.proto +0 -22
  71. package/src/core/network/protocols/connectionPolicies.js +0 -88
  72. package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +0 -23
  73. package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
  74. package/src/core/network/protocols/v1/V1ProtocolError.js +0 -91
  75. package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +0 -65
  76. package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +0 -389
  77. package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +0 -87
  78. package/src/core/network/protocols/v1/validators/V1BaseOperation.js +0 -211
  79. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +0 -26
  80. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +0 -276
  81. package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +0 -15
  82. package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +0 -17
  83. package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +0 -210
  84. package/src/core/network/services/PendingRequestService.js +0 -172
  85. package/src/core/network/services/TransactionCommitService.js +0 -149
  86. package/src/core/network/services/ValidatorHealthCheckService.js +0 -127
  87. package/src/utils/deepEqualApplyPayload.js +0 -40
  88. package/src/utils/logger.js +0 -25
  89. package/src/utils/protobuf/networkV1.generated.cjs +0 -2460
  90. package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
  91. package/tests/unit/network/ProtocolSession.test.js +0 -127
  92. package/tests/unit/network/services/ConnectionManager.test.js +0 -450
  93. package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
  94. package/tests/unit/network/services/PendingRequestService.test.js +0 -431
  95. package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
  96. package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
  97. package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
  98. package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
  99. package/tests/unit/network/services/services.test.js +0 -17
  100. package/tests/unit/network/utils/v1TestUtils.js +0 -153
  101. package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
  102. package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
  103. package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
  104. package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
  105. package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
  106. package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
  107. package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
  108. package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
  109. package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
  110. package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
  111. package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
  112. package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
  113. package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
  114. package/tests/unit/network/v1/v1.handlers.test.js +0 -15
  115. package/tests/unit/network/v1/v1.test.js +0 -19
  116. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
  117. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
  118. package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
  119. package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
  120. package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
  121. package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
@@ -19,8 +19,6 @@ class NetworkMessageBuilder {
19
19
  #issuerAddress;
20
20
  #resultCode;
21
21
  #data;
22
- #proof;
23
- #timestamp_ledger;
24
22
  #header;
25
23
  #payloadKey;
26
24
  #body;
@@ -87,9 +85,6 @@ class NetworkMessageBuilder {
87
85
  }
88
86
 
89
87
  setData(data) {
90
- // case when response have to be empty.
91
- if (data === undefined || data === null) data = b4a.alloc(0);
92
-
93
88
  if (!b4a.isBuffer(data)) {
94
89
  throw new Error(`Data must be a buffer.`);
95
90
  }
@@ -97,30 +92,6 @@ class NetworkMessageBuilder {
97
92
  return this;
98
93
  }
99
94
 
100
- setProof(proof) {
101
- if (proof === undefined || proof === null) proof = b4a.alloc(0);
102
- if (!b4a.isBuffer(proof)) {
103
- throw new Error(`Proof must be a buffer.`);
104
- }
105
- this.#proof = proof;
106
- return this;
107
- }
108
-
109
- setTimestampLedger(timestamp) {
110
- if (timestamp === undefined || timestamp === null) {
111
- this.#timestamp_ledger = null;
112
- return this;
113
- }
114
-
115
- const value = timestamp instanceof Date ? timestamp.getTime() : timestamp;
116
- if (!Number.isSafeInteger(value) || value < 0) {
117
- throw new Error('timestamp must be a non-negative safe integer or Date.');
118
- }
119
-
120
- this.#timestamp_ledger = value;
121
- return this;
122
- }
123
-
124
95
  #setHeader() {
125
96
  if (!this.#type) throw new Error('Header requires type to be set');
126
97
  if (!this.#id) throw new Error('Header requires id to be set');
@@ -136,6 +107,76 @@ class NetworkMessageBuilder {
136
107
  return this;
137
108
  }
138
109
 
110
+ async #buildValidatorConnectionRequestPayload() {
111
+ const issuer = this.#issuerAddress
112
+ if (!isAddressValid(issuer, this.#config.addressPrefix)) {
113
+ throw new Error('Issuer address must be a valid TRAC address');
114
+ }
115
+
116
+ if (this.#issuerAddress !== this.#wallet.address) {
117
+ throw new Error('Issuer address must be the signer address');
118
+ }
119
+
120
+ const nonce = PeerWallet.generateNonce();
121
+ const tsBuf = timestampToBuffer(this.#timestamp);
122
+ const idBuf = idToBuffer(this.#id);
123
+ const message = createMessage(
124
+ this.#type,
125
+ idBuf,
126
+ tsBuf,
127
+ addressToBuffer(issuer, this.#config.addressPrefix),
128
+ nonce,
129
+ encodeCapabilities(this.#capabilities),
130
+ );
131
+ const hash = await PeerWallet.blake3(message);
132
+ const signature = this.#wallet.sign(hash);
133
+
134
+ this.#payloadKey = 'validator_connection_request';
135
+ this.#body = {
136
+ issuer_address: issuer,
137
+ nonce,
138
+ signature
139
+ };
140
+ }
141
+
142
+ async #buildValidatorConnectionResponsePayload() {
143
+ const issuer = this.#issuerAddress
144
+ if (!isAddressValid(issuer, this.#config.addressPrefix)) {
145
+ throw new Error('Issuer address must be a valid TRAC address');
146
+ }
147
+
148
+ if (this.#issuerAddress === this.#wallet.address) {
149
+ throw new Error('Issuer address must be the different than the signer address');
150
+ }
151
+
152
+ if (this.#resultCode === null || this.#resultCode === undefined) {
153
+ throw new Error('Result code must be set before building validator connection response');
154
+ }
155
+
156
+ const nonce = PeerWallet.generateNonce();
157
+ const tsBuf = timestampToBuffer(this.#timestamp);
158
+ const idBuf = idToBuffer(this.#id);
159
+ const message = createMessage(
160
+ this.#type,
161
+ idBuf,
162
+ tsBuf,
163
+ addressToBuffer(issuer, this.#config.addressPrefix),
164
+ nonce,
165
+ safeWriteUInt32BE(this.#resultCode, 0),
166
+ encodeCapabilities(this.#capabilities),
167
+ );
168
+ const hash = await PeerWallet.blake3(message);
169
+ const signature = this.#wallet.sign(hash);
170
+
171
+ this.#payloadKey = 'validator_connection_response';
172
+ this.#body = {
173
+ issuer_address: issuer,
174
+ nonce,
175
+ signature,
176
+ result: this.#resultCode
177
+ };
178
+ }
179
+
139
180
  async #buildLivenessRequestPayload() {
140
181
  const nonce = PeerWallet.generateNonce();
141
182
  const tsBuf = timestampToBuffer(this.#timestamp);
@@ -217,50 +258,21 @@ class NetworkMessageBuilder {
217
258
  const nonce = PeerWallet.generateNonce();
218
259
  const tsBuf = timestampToBuffer(this.#timestamp);
219
260
  const idBuf = idToBuffer(this.#id);
220
- const proof = b4a.isBuffer(this.#proof) ? this.#proof : b4a.alloc(0);
221
- const hasProof = proof.length > 0;
222
- const timestamp = Number.isSafeInteger(this.#timestamp_ledger) ? this.#timestamp_ledger : 0;
223
- const hasTimestamp = timestamp > 0;
224
-
225
- if (this.#resultCode === ResultCode.OK) {
226
- if (!hasProof || !hasTimestamp) {
227
- throw new Error('Result code OK requires non-empty proof and timestamp > 0.');
228
- }
229
- } else if (this.#resultCode === ResultCode.TX_ACCEPTED_PROOF_UNAVAILABLE) {
230
- if (hasProof) {
231
- throw new Error('Result code TX_ACCEPTED_PROOF_UNAVAILABLE requires empty proof.');
232
- }
233
- if (!hasTimestamp) {
234
- throw new Error('Result code TX_ACCEPTED_PROOF_UNAVAILABLE requires timestamp > 0.');
235
- }
236
- } else {
237
- if (hasProof) {
238
- throw new Error('Non-OK result code requires empty proof.');
239
- }
240
- if (timestamp !== 0) {
241
- throw new Error('Non-OK result code requires timestamp to be 0, except TX_ACCEPTED_PROOF_UNAVAILABLE.');
242
- }
243
- }
244
-
245
261
  const message = createMessage(
246
262
  this.#type,
247
263
  idBuf,
248
264
  tsBuf,
249
265
  nonce,
250
- proof,
251
- timestampToBuffer(timestamp),
252
266
  safeWriteUInt32BE(this.#resultCode, 0),
253
267
  encodeCapabilities(this.#capabilities),
254
268
  );
255
-
256
269
  const hash = await PeerWallet.blake3(message);
257
270
  const signature = this.#wallet.sign(hash);
271
+
258
272
  this.#payloadKey = 'broadcast_transaction_response';
259
273
  this.#body = {
260
274
  nonce,
261
275
  signature,
262
- proof,
263
- timestamp: timestamp,
264
276
  result: this.#resultCode
265
277
  };
266
278
  }
@@ -269,6 +281,14 @@ class NetworkMessageBuilder {
269
281
  this.#setHeader();
270
282
 
271
283
  switch (this.#type) {
284
+ case NetworkOperationType.VALIDATOR_CONNECTION_REQUEST: {
285
+ await this.#buildValidatorConnectionRequestPayload();
286
+ break;
287
+ }
288
+ case NetworkOperationType.VALIDATOR_CONNECTION_RESPONSE: {
289
+ await this.#buildValidatorConnectionResponsePayload();
290
+ break;
291
+ }
272
292
  case NetworkOperationType.LIVENESS_REQUEST: {
273
293
  await this.#buildLivenessRequestPayload();
274
294
  break;
@@ -1,4 +1,4 @@
1
- import {NetworkOperationType} from '../../../utils/constants.js';
1
+ import { NetworkOperationType } from '../../../utils/constants.js';
2
2
 
3
3
  /**
4
4
  * Director for v1 internal network protocol messages.
@@ -13,6 +13,47 @@ class NetworkMessageDirector {
13
13
  this.#builder = builderInstance;
14
14
  }
15
15
 
16
+ /**
17
+ * Build a validator connection request message.
18
+ * @param {string} id
19
+ * @param {string} issuerAddress
20
+ * @param {string[]} capabilities
21
+ * @returns {Promise<object>}
22
+ */
23
+ async buildValidatorConnectionRequest(id, issuerAddress, capabilities) {
24
+ await this.#builder
25
+ .setType(NetworkOperationType.VALIDATOR_CONNECTION_REQUEST)
26
+ .setId(id)
27
+ .setTimestamp()
28
+ .setIssuerAddress(issuerAddress)
29
+ .setCapabilities(capabilities)
30
+ .buildPayload()
31
+
32
+
33
+ return this.#builder.getResult();
34
+ }
35
+
36
+ /**
37
+ * Build a validator connection response message.
38
+ * @param {string} id
39
+ * @param {string} issuerAddress
40
+ * @param {string[]} capabilities
41
+ * @param {number} statusCode
42
+ * @returns {Promise<object>}
43
+ */
44
+ async buildValidatorConnectionResponse(id, issuerAddress, capabilities, statusCode) {
45
+ await this.#builder
46
+ .setType(NetworkOperationType.VALIDATOR_CONNECTION_RESPONSE)
47
+ .setId(id)
48
+ .setTimestamp()
49
+ .setIssuerAddress(issuerAddress)
50
+ .setCapabilities(capabilities)
51
+ .setResultCode(statusCode)
52
+ .buildPayload()
53
+
54
+ return this.#builder.getResult();
55
+ }
56
+
16
57
  /**
17
58
  * Build a liveness request message.
18
59
  * @param {string} id
@@ -20,11 +61,12 @@ class NetworkMessageDirector {
20
61
  * @param {string[]} capabilities
21
62
  * @returns {Promise<object>}
22
63
  */
23
- async buildLivenessRequest(id, capabilities) {
64
+ async buildLivenessRequest(id, data, capabilities) {
24
65
  await this.#builder
25
66
  .setType(NetworkOperationType.LIVENESS_REQUEST)
26
67
  .setId(id)
27
68
  .setTimestamp()
69
+ .setData(data)
28
70
  .setCapabilities(capabilities)
29
71
  .buildPayload();
30
72
 
@@ -34,15 +76,17 @@ class NetworkMessageDirector {
34
76
  /**
35
77
  * Build a liveness response message.
36
78
  * @param {string} id
79
+ * @param {Buffer} data
37
80
  * @param {string[]} capabilities
38
81
  * @param {number} statusCode
39
82
  * @returns {Promise<object>}
40
83
  */
41
- async buildLivenessResponse(id, capabilities, statusCode) {
84
+ async buildLivenessResponse(id, data, capabilities, statusCode) {
42
85
  await this.#builder
43
86
  .setType(NetworkOperationType.LIVENESS_RESPONSE)
44
87
  .setId(id)
45
88
  .setTimestamp()
89
+ .setData(data)
46
90
  .setCapabilities(capabilities)
47
91
  .setResultCode(statusCode)
48
92
  .buildPayload();
@@ -71,28 +115,18 @@ class NetworkMessageDirector {
71
115
 
72
116
  /**
73
117
  * Build a broadcast transaction response message.
74
- *
75
- * Allowed payload variants:
76
- * 1) resultCode === OK - proof must be non-empty and timestamp must be > 0.
77
- * 2) resultCode === TX_ACCEPTED_PROOF_UNAVAILABLE - proof must be empty and timestamp must be > 0.
78
- * 3) resultCode !== OK and resultCode !== TX_ACCEPTED_PROOF_UNAVAILABLE - proof must be empty and timestamp must be 0.
79
- *
80
118
  * @param {string} id
81
119
  * @param {string[]} capabilities
82
- * @param {number} resultCode
83
- * @param {Buffer|null|undefined} proof
84
- * @param {number|Date|null|undefined} timestamp - When transaction has been appended by the validator
120
+ * @param {number} statusCode
85
121
  * @returns {Promise<object>}
86
122
  */
87
- async buildBroadcastTransactionResponse(id, capabilities, resultCode, proof = null, timestamp = null) {
123
+ async buildBroadcastTransactionResponse(id, capabilities, statusCode) {
88
124
  await this.#builder
89
125
  .setType(NetworkOperationType.BROADCAST_TRANSACTION_RESPONSE)
90
126
  .setId(id)
91
127
  .setTimestamp()
92
128
  .setCapabilities(capabilities)
93
- .setProof(proof)
94
- .setTimestampLedger(timestamp)
95
- .setResultCode(resultCode)
129
+ .setResultCode(statusCode)
96
130
  .buildPayload();
97
131
 
98
132
  return this.#builder.getResult();
@@ -42,6 +42,14 @@ class Scheduler {
42
42
  return this.#defaultInterval;
43
43
  }
44
44
 
45
+ get timer() {
46
+ return this.#timer;
47
+ }
48
+
49
+ get currentWorkerRun() {
50
+ return this.#currentWorkerRun;
51
+ }
52
+
45
53
  static #validateDelay(delayMs, scope = 'delayMs') {
46
54
  const ms = Number(delayMs);
47
55
  if (!Number.isFinite(ms) || ms < 0) {
@@ -1,10 +1,8 @@
1
1
  import { OperationType as ApplyOperationType } from './protobuf/applyOperations.cjs';
2
- import networkV1Generated from './protobuf/networkV1.generated.cjs';
2
+ import { MessageType as NetworkMessageType, ResultCode as NetworkResultCode } from './protobuf/network.cjs';
3
3
  import b4a from 'b4a'
4
4
  // TODO: We are going to have a lot of contstants. It would be good, to separate them into different files.
5
5
 
6
- const { MessageType: NetworkMessageType, ResultCode: NetworkResultCode } = networkV1Generated.network.v1;
7
-
8
6
  //ATTENTION - THIS IS USED IN THE APPLY FUNCTION!
9
7
  export const EntryType = Object.freeze({
10
8
  ADMIN: 'admin',
@@ -36,6 +34,8 @@ export const OperationType = Object.freeze({
36
34
  });
37
35
 
38
36
  export const NetworkOperationType = Object.freeze({
37
+ VALIDATOR_CONNECTION_REQUEST: NetworkMessageType.MESSAGE_TYPE_VALIDATOR_CONNECTION_REQUEST,
38
+ VALIDATOR_CONNECTION_RESPONSE: NetworkMessageType.MESSAGE_TYPE_VALIDATOR_CONNECTION_RESPONSE,
39
39
  LIVENESS_REQUEST: NetworkMessageType.MESSAGE_TYPE_LIVENESS_REQUEST,
40
40
  LIVENESS_RESPONSE: NetworkMessageType.MESSAGE_TYPE_LIVENESS_RESPONSE,
41
41
  BROADCAST_TRANSACTION_REQUEST: NetworkMessageType.MESSAGE_TYPE_BROADCAST_TRANSACTION_REQUEST,
@@ -43,68 +43,12 @@ export const NetworkOperationType = Object.freeze({
43
43
  });
44
44
 
45
45
  export const ResultCode = Object.freeze({
46
- UNSPECIFIED: NetworkResultCode.RESULT_CODE_UNSPECIFIED,
47
46
  OK: NetworkResultCode.RESULT_CODE_OK,
48
47
  INVALID_PAYLOAD: NetworkResultCode.RESULT_CODE_INVALID_PAYLOAD,
48
+ UNSUPPORTED_VERSION: NetworkResultCode.RESULT_CODE_UNSUPPORTED_VERSION,
49
49
  RATE_LIMITED: NetworkResultCode.RESULT_CODE_RATE_LIMITED,
50
- SIGNATURE_INVALID: NetworkResultCode.RESULT_CODE_SIGNATURE_INVALID,
51
- UNEXPECTED_ERROR: NetworkResultCode.RESULT_CODE_UNEXPECTED_ERROR,
52
50
  TIMEOUT: NetworkResultCode.RESULT_CODE_TIMEOUT,
53
- NODE_HAS_NO_WRITE_ACCESS: NetworkResultCode.RESULT_CODE_NODE_HAS_NO_WRITE_ACCESS,
54
- TX_ACCEPTED_PROOF_UNAVAILABLE: NetworkResultCode.RESULT_CODE_TX_ACCEPTED_PROOF_UNAVAILABLE,
55
- NODE_OVERLOADED: NetworkResultCode.RESULT_CODE_NODE_OVERLOADED,
56
- TX_ALREADY_PENDING: NetworkResultCode.RESULT_CODE_TX_ALREADY_PENDING,
57
- OPERATION_TYPE_UNKNOWN: NetworkResultCode.RESULT_CODE_OPERATION_TYPE_UNKNOWN,
58
- SCHEMA_VALIDATION_FAILED: NetworkResultCode.RESULT_CODE_SCHEMA_VALIDATION_FAILED,
59
- REQUESTER_ADDRESS_INVALID: NetworkResultCode.RESULT_CODE_REQUESTER_ADDRESS_INVALID,
60
- REQUESTER_PUBLIC_KEY_INVALID: NetworkResultCode.RESULT_CODE_REQUESTER_PUBLIC_KEY_INVALID,
61
- TX_HASH_MISMATCH: NetworkResultCode.RESULT_CODE_TX_HASH_MISMATCH,
62
- TX_SIGNATURE_INVALID: NetworkResultCode.RESULT_CODE_TX_SIGNATURE_INVALID,
63
- TX_EXPIRED: NetworkResultCode.RESULT_CODE_TX_EXPIRED,
64
- TX_ALREADY_EXISTS: NetworkResultCode.RESULT_CODE_TX_ALREADY_EXISTS,
65
- OPERATION_ALREADY_COMPLETED: NetworkResultCode.RESULT_CODE_OPERATION_ALREADY_COMPLETED,
66
- REQUESTER_NOT_FOUND: NetworkResultCode.RESULT_CODE_REQUESTER_NOT_FOUND,
67
- INSUFFICIENT_FEE_BALANCE: NetworkResultCode.RESULT_CODE_INSUFFICIENT_FEE_BALANCE,
68
- EXTERNAL_BOOTSTRAP_EQUALS_MSB_BOOTSTRAP: NetworkResultCode.RESULT_CODE_EXTERNAL_BOOTSTRAP_EQUALS_MSB_BOOTSTRAP,
69
- SELF_VALIDATION_FORBIDDEN: NetworkResultCode.RESULT_CODE_SELF_VALIDATION_FORBIDDEN,
70
- ROLE_NODE_ENTRY_NOT_FOUND: NetworkResultCode.RESULT_CODE_ROLE_NODE_ENTRY_NOT_FOUND,
71
- ROLE_NODE_ALREADY_WRITER: NetworkResultCode.RESULT_CODE_ROLE_NODE_ALREADY_WRITER,
72
- ROLE_NODE_NOT_WHITELISTED: NetworkResultCode.RESULT_CODE_ROLE_NODE_NOT_WHITELISTED,
73
- ROLE_NODE_NOT_WRITER: NetworkResultCode.RESULT_CODE_ROLE_NODE_NOT_WRITER,
74
- ROLE_NODE_IS_INDEXER: NetworkResultCode.RESULT_CODE_ROLE_NODE_IS_INDEXER,
75
- ROLE_ADMIN_ENTRY_MISSING: NetworkResultCode.RESULT_CODE_ROLE_ADMIN_ENTRY_MISSING,
76
- ROLE_INVALID_RECOVERY_CASE: NetworkResultCode.RESULT_CODE_ROLE_INVALID_RECOVERY_CASE,
77
- ROLE_UNKNOWN_OPERATION: NetworkResultCode.RESULT_CODE_ROLE_UNKNOWN_OPERATION,
78
- ROLE_INVALID_WRITER_KEY: NetworkResultCode.RESULT_CODE_ROLE_INVALID_WRITER_KEY,
79
- ROLE_INSUFFICIENT_FEE_BALANCE: NetworkResultCode.RESULT_CODE_ROLE_INSUFFICIENT_FEE_BALANCE,
80
- MSB_BOOTSTRAP_MISMATCH: NetworkResultCode.RESULT_CODE_MSB_BOOTSTRAP_MISMATCH,
81
- EXTERNAL_BOOTSTRAP_NOT_DEPLOYED: NetworkResultCode.RESULT_CODE_EXTERNAL_BOOTSTRAP_NOT_DEPLOYED,
82
- EXTERNAL_BOOTSTRAP_TX_MISSING: NetworkResultCode.RESULT_CODE_EXTERNAL_BOOTSTRAP_TX_MISSING,
83
- EXTERNAL_BOOTSTRAP_MISMATCH: NetworkResultCode.RESULT_CODE_EXTERNAL_BOOTSTRAP_MISMATCH,
84
- BOOTSTRAP_ALREADY_EXISTS: NetworkResultCode.RESULT_CODE_BOOTSTRAP_ALREADY_EXISTS,
85
- TRANSFER_RECIPIENT_ADDRESS_INVALID: NetworkResultCode.RESULT_CODE_TRANSFER_RECIPIENT_ADDRESS_INVALID,
86
- TRANSFER_RECIPIENT_PUBLIC_KEY_INVALID: NetworkResultCode.RESULT_CODE_TRANSFER_RECIPIENT_PUBLIC_KEY_INVALID,
87
- TRANSFER_AMOUNT_TOO_LARGE: NetworkResultCode.RESULT_CODE_TRANSFER_AMOUNT_TOO_LARGE,
88
- TRANSFER_SENDER_NOT_FOUND: NetworkResultCode.RESULT_CODE_TRANSFER_SENDER_NOT_FOUND,
89
- TRANSFER_INSUFFICIENT_BALANCE: NetworkResultCode.RESULT_CODE_TRANSFER_INSUFFICIENT_BALANCE,
90
- TRANSFER_RECIPIENT_BALANCE_OVERFLOW: NetworkResultCode.RESULT_CODE_TRANSFER_RECIPIENT_BALANCE_OVERFLOW,
91
- TX_HASH_INVALID_FORMAT: NetworkResultCode.RESULT_CODE_TX_HASH_INVALID_FORMAT,
92
- INTERNAL_ENQUEUE_VALIDATION_FAILED: NetworkResultCode.RESULT_CODE_INTERNAL_ENQUEUE_VALIDATION_FAILED,
93
- TX_COMMITTED_RECEIPT_MISSING: NetworkResultCode.RESULT_CODE_TX_COMMITTED_RECEIPT_MISSING,
94
- VALIDATOR_RESPONSE_TX_TYPE_INVALID: NetworkResultCode.RESULT_CODE_VALIDATOR_RESPONSE_TX_TYPE_INVALID,
95
- VALIDATOR_RESPONSE_TX_TYPE_UNKNOWN: NetworkResultCode.RESULT_CODE_VALIDATOR_RESPONSE_TX_TYPE_UNKNOWN,
96
- VALIDATOR_RESPONSE_TX_TYPE_UNSUPPORTED: NetworkResultCode.RESULT_CODE_VALIDATOR_RESPONSE_TX_TYPE_UNSUPPORTED,
97
- VALIDATOR_RESPONSE_SCHEMA_INVALID: NetworkResultCode.RESULT_CODE_VALIDATOR_RESPONSE_SCHEMA_INVALID,
98
- PENDING_REQUEST_MISSING_TX_DATA: NetworkResultCode.RESULT_CODE_PENDING_REQUEST_MISSING_TX_DATA,
99
- PROOF_PAYLOAD_MISMATCH: NetworkResultCode.RESULT_CODE_PROOF_PAYLOAD_MISMATCH,
100
- VALIDATOR_WRITER_KEY_NOT_REGISTERED: NetworkResultCode.RESULT_CODE_VALIDATOR_WRITER_KEY_NOT_REGISTERED,
101
- VALIDATOR_ADDRESS_MISMATCH: NetworkResultCode.RESULT_CODE_VALIDATOR_ADDRESS_MISMATCH,
102
- VALIDATOR_NODE_ENTRY_NOT_FOUND: NetworkResultCode.RESULT_CODE_VALIDATOR_NODE_ENTRY_NOT_FOUND,
103
- VALIDATOR_NODE_NOT_WRITER: NetworkResultCode.RESULT_CODE_VALIDATOR_NODE_NOT_WRITER,
104
- VALIDATOR_WRITER_KEY_MISMATCH: NetworkResultCode.RESULT_CODE_VALIDATOR_WRITER_KEY_MISMATCH,
105
- VALIDATOR_TX_OBJECT_INVALID: NetworkResultCode.RESULT_CODE_VALIDATOR_TX_OBJECT_INVALID,
106
- VALIDATOR_VA_MISSING: NetworkResultCode.RESULT_CODE_VALIDATOR_VA_MISSING,
107
- TX_INVALID_PAYLOAD: NetworkResultCode.RESULT_CODE_TX_INVALID_PAYLOAD
51
+ SIGNATURE_INVALID: NetworkResultCode.RESULT_CODE_SIGNATURE_INVALID,
108
52
  });
109
53
 
110
54
  // Role managment constants
@@ -117,7 +61,6 @@ export const EventType = Object.freeze({
117
61
  WARNING: 'warning',
118
62
  VALIDATOR_CONNECTION_READY: 'validator-connection-ready',
119
63
  VALIDATOR_CONNECTION_TIMEOUT: 'validator-connection-timeout',
120
- VALIDATOR_HEALTH_CHECK: 'validator-health-check',
121
64
  });
122
65
 
123
66
  // Role managment constants
@@ -166,13 +109,6 @@ export const BOOTSTRAP_HEXSTRING_LENGTH = 64;
166
109
  // Pool constants
167
110
  export const BATCH_SIZE = 10;
168
111
 
169
- // Operation handler constants
170
- export const MAX_PARTIAL_TX_PAYLOAD_BYTE_SIZE = 3072;
171
- export const V1_PROTOCOL_PAYLOAD_MAX_SIZE = 4096;
172
-
173
- // Transaction Commit Service
174
- export const TRANSACTION_COMMIT_SERVICE_BUFFER_SIZE = 1500;
175
-
176
112
  // Network message constants
177
113
  export const NETWORK_MESSAGE_TYPES = Object.freeze({
178
114
  GET: {
@@ -187,5 +123,3 @@ export const NETWORK_MESSAGE_TYPES = Object.freeze({
187
123
  NODE: 'nodeResponse'
188
124
  },
189
125
  });
190
-
191
- export const NETWORK_CAPABILITIES = Object.freeze(["protocols:v1:legacy"]);
@@ -1,8 +1,7 @@
1
1
  import b4a from "b4a";
2
- import PeerWallet from "trac-wallet";
3
2
  import {bufferToAddress} from "../core/state/utils/address.js";
4
3
  import { EntryType } from "./constants.js";
5
- import { v7 as uuidv7 } from 'uuid';
4
+
6
5
  //TODO: change file name or split functions below into multiple files (Remember to update imports and tests accordingly)
7
6
 
8
7
  export function isHexString(string) {
@@ -96,11 +95,3 @@ export function isTransactionRecordPut(entry) {
96
95
  const is64 = entry.key.length === 64;
97
96
  return isPut && isHex && is64;
98
97
  }
99
-
100
- export function generateUUID() {
101
- return uuidv7();
102
- }
103
-
104
- export function publicKeyToAddress(publicKey, config) {
105
- return PeerWallet.encodeBech32m(config.addressPrefix, b4a.isBuffer(publicKey) ? publicKey : b4a.from(publicKey, typeof publicKey === 'string' ? 'hex' : undefined));
106
- }
@@ -3,7 +3,6 @@ import { normalizeHex } from './helpers.js';
3
3
  import { addressToBuffer, bufferToAddress } from '../core/state/utils/address.js';
4
4
  import b4a from 'b4a';
5
5
  import { bufferToBigInt } from './amountSerialization.js'
6
- import {isBootstrapDeployment, isRoleAccess, isTransaction, isTransfer} from './applyOperations.js';
7
6
 
8
7
  /**
9
8
  * Normalizes the payload for a transfer operation.
@@ -200,40 +199,3 @@ export function normalizeBootstrapDeploymentOperation(payload, config) {
200
199
  bdo: normalizedBdo
201
200
  };
202
201
  }
203
-
204
- /**
205
- * Normalizes an incoming partial operation message based on its operation type.
206
- *
207
- * @param {Object} message The raw incoming message.
208
- * @param {object} config The environment configuration object.
209
- * @returns {Object} Normalized payload.
210
- * @throws {Error} If message is invalid or operation type is unsupported.
211
- */
212
- export function normalizeMessageByOperationType(message, config) {
213
- if (!message || typeof message !== 'object') {
214
- throw new Error('Invalid message for normalization.');
215
- }
216
-
217
- const { type } = message;
218
- if (!Number.isInteger(type) || type <= 0) {
219
- throw new Error('Message type is missing or invalid.');
220
- }
221
-
222
- if (isRoleAccess(type)) {
223
- return normalizeRoleAccessOperation(message, config);
224
- }
225
-
226
- if (isTransaction(type)) {
227
- return normalizeTransactionOperation(message, config);
228
- }
229
-
230
- if (isBootstrapDeployment(type)) {
231
- return normalizeBootstrapDeploymentOperation(message, config);
232
- }
233
-
234
- if (isTransfer(type)) {
235
- return normalizeTransferOperation(message, config);
236
- }
237
-
238
- throw new Error(`Unsupported operation type for normalization: ${type}`);
239
- }