trac-msb 0.2.6 → 0.2.8

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 (146) hide show
  1. package/.github/workflows/publish.yml +9 -16
  2. package/docs/networking-dualstack-plan.md +75 -0
  3. package/docs/networking-layer-redesign.md +155 -0
  4. package/msb.mjs +11 -23
  5. package/package.json +2 -3
  6. package/rpc/{create_server.mjs → create_server.js} +2 -2
  7. package/rpc/{handlers.mjs → handlers.js} +5 -5
  8. package/rpc/routes/{index.mjs → index.js} +1 -1
  9. package/rpc/routes/{v1.mjs → v1.js} +1 -1
  10. package/rpc/{rpc_server.mjs → rpc_server.js} +1 -1
  11. package/rpc/rpc_services.js +4 -4
  12. package/src/config/config.js +137 -0
  13. package/src/config/env.js +61 -0
  14. package/src/core/network/Network.js +131 -72
  15. package/src/core/network/identity/NetworkWalletFactory.js +3 -4
  16. package/src/core/network/messaging/NetworkMessages.js +12 -11
  17. package/src/core/network/messaging/handlers/GetRequestHandler.js +5 -4
  18. package/src/core/network/messaging/handlers/ResponseHandler.js +4 -5
  19. package/src/core/network/messaging/handlers/RoleOperationHandler.js +17 -19
  20. package/src/core/network/messaging/handlers/SubnetworkOperationHandler.js +44 -38
  21. package/src/core/network/messaging/handlers/TransferOperationHandler.js +29 -25
  22. package/src/core/network/messaging/handlers/base/BaseOperationHandler.js +20 -21
  23. package/src/core/network/messaging/routes/NetworkMessageRouter.js +24 -20
  24. package/src/core/network/messaging/validators/AdminResponse.js +2 -2
  25. package/src/core/network/messaging/validators/CustomNodeResponse.js +2 -2
  26. package/src/core/network/messaging/validators/PartialBootstrapDeployment.js +3 -3
  27. package/src/core/network/messaging/validators/PartialRoleAccess.js +15 -12
  28. package/src/core/network/messaging/validators/PartialTransaction.js +9 -10
  29. package/src/core/network/messaging/validators/PartialTransfer.js +10 -7
  30. package/src/core/network/messaging/validators/ValidatorResponse.js +2 -2
  31. package/src/core/network/messaging/validators/base/BaseResponse.js +13 -5
  32. package/src/core/network/messaging/validators/base/PartialOperation.js +37 -21
  33. package/src/core/network/services/ConnectionManager.js +248 -62
  34. package/src/core/network/services/MessageOrchestrator.js +83 -0
  35. package/src/core/network/services/TransactionPoolService.js +9 -8
  36. package/src/core/network/services/ValidatorObserverService.js +95 -34
  37. package/src/core/state/State.js +136 -139
  38. package/src/core/state/utils/address.js +18 -16
  39. package/src/core/state/utils/adminEntry.js +17 -16
  40. package/src/core/state/utils/deploymentEntry.js +15 -15
  41. package/src/core/state/utils/transaction.js +3 -95
  42. package/src/index.js +153 -201
  43. package/src/messages/completeStateMessages/CompleteStateMessageBuilder.js +36 -32
  44. package/src/messages/completeStateMessages/CompleteStateMessageOperations.js +39 -42
  45. package/src/messages/partialStateMessages/PartialStateMessageBuilder.js +20 -20
  46. package/src/messages/partialStateMessages/PartialStateMessageOperations.js +29 -22
  47. package/src/utils/check.js +21 -17
  48. package/src/utils/cliCommands.js +11 -11
  49. package/src/utils/constants.js +2 -9
  50. package/src/utils/fileUtils.js +1 -4
  51. package/src/utils/helpers.js +9 -20
  52. package/src/utils/migrationUtils.js +2 -2
  53. package/src/utils/normalizers.js +10 -9
  54. package/tests/acceptance/v1/account/account.test.mjs +2 -2
  55. package/tests/acceptance/v1/balance/balance.test.mjs +1 -1
  56. package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +11 -2
  57. package/tests/acceptance/v1/rpc.test.mjs +9 -9
  58. package/tests/acceptance/v1/tx/tx.test.mjs +4 -2
  59. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +7 -3
  60. package/tests/fixtures/check.fixtures.js +42 -42
  61. package/tests/fixtures/protobuf.fixtures.js +27 -26
  62. package/tests/helpers/StateNetworkFactory.js +3 -5
  63. package/tests/helpers/autobaseTestHelpers.js +48 -2
  64. package/tests/helpers/config.js +3 -0
  65. package/tests/helpers/setupApplyTests.js +89 -82
  66. package/tests/helpers/transactionPayloads.mjs +26 -12
  67. package/tests/integration/apply/addAdmin/addAdminBasic.test.js +10 -9
  68. package/tests/integration/apply/addAdmin/addAdminRecovery.test.js +20 -19
  69. package/tests/integration/apply/addIndexer.test.js +23 -21
  70. package/tests/integration/apply/addWhitelist.test.js +9 -9
  71. package/tests/integration/apply/addWriter.test.js +33 -32
  72. package/tests/integration/apply/banValidator.test.js +16 -9
  73. package/tests/integration/apply/postTx/invalidSubValues.test.js +4 -4
  74. package/tests/integration/apply/postTx/postTx.test.js +7 -33
  75. package/tests/integration/apply/removeIndexer.test.js +11 -7
  76. package/tests/integration/apply/removeWriter.test.js +20 -19
  77. package/tests/integration/apply/transfer.test.js +18 -16
  78. package/tests/unit/messageOperations/assembleAddIndexerMessage.test.js +2 -2
  79. package/tests/unit/messageOperations/assembleAddWriterMessage.test.js +2 -1
  80. package/tests/unit/messageOperations/assembleAdminMessage.test.js +9 -10
  81. package/tests/unit/messageOperations/assembleBanWriterMessage.test.js +3 -2
  82. package/tests/unit/messageOperations/assemblePostTransaction.test.js +25 -43
  83. package/tests/unit/messageOperations/assembleRemoveIndexerMessage.test.js +2 -2
  84. package/tests/unit/messageOperations/assembleRemoveWriterMessage.test.js +2 -2
  85. package/tests/unit/messageOperations/assembleWhitelistMessages.test.js +5 -4
  86. package/tests/unit/messageOperations/commonsStateMessageOperationsTest.js +4 -3
  87. package/tests/unit/network/ConnectionManager.test.js +41 -70
  88. package/tests/unit/network/NetworkWalletFactory.test.js +14 -14
  89. package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +6 -6
  90. package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +8 -8
  91. package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +6 -5
  92. package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +24 -23
  93. package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +10 -16
  94. package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +2 -1
  95. package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +45 -41
  96. package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +3 -7
  97. package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +17 -16
  98. package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +3 -4
  99. package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +2 -1
  100. package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +2 -1
  101. package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +23 -25
  102. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +2 -1
  103. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +19 -18
  104. package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +5 -4
  105. package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +4 -3
  106. package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +2 -1
  107. package/tests/unit/state/apply/common/commonScenarioHelper.js +3 -4
  108. package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +2 -2
  109. package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +2 -2
  110. package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +2 -1
  111. package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +2 -1
  112. package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +2 -1
  113. package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +2 -1
  114. package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +11 -10
  115. package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +6 -5
  116. package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +6 -7
  117. package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +35 -34
  118. package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +44 -43
  119. package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +26 -25
  120. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +2 -1
  121. package/tests/unit/state/stateModule.test.js +0 -1
  122. package/tests/unit/state/stateTestUtils.js +7 -3
  123. package/tests/unit/state/utils/address.test.js +3 -3
  124. package/tests/unit/state/utils/adminEntry.test.js +10 -9
  125. package/tests/unit/utils/check/adminControlOperation.test.js +3 -3
  126. package/tests/unit/utils/check/balanceInitializationOperation.test.js +2 -2
  127. package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +2 -3
  128. package/tests/unit/utils/check/common.test.js +7 -6
  129. package/tests/unit/utils/check/coreAdminOperation.test.js +3 -3
  130. package/tests/unit/utils/check/roleAccessOperation.test.js +3 -2
  131. package/tests/unit/utils/check/transactionOperation.test.js +3 -3
  132. package/tests/unit/utils/check/transferOperation.test.js +3 -3
  133. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +2 -1
  134. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +2 -1
  135. package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +7 -0
  136. package/tests/unit/utils/utils.test.js +0 -1
  137. package/src/core/state/utils/indexerEntry.js +0 -105
  138. package/src/utils/crypto.js +0 -11
  139. package/tests/unit/state/utils/indexerEntry.test.js +0 -83
  140. package/tests/unit/state/utils/transaction.test.js +0 -97
  141. package/tests/unit/utils/crypto/createHash.test.js +0 -15
  142. /package/rpc/{constants.mjs → constants.js} +0 -0
  143. /package/rpc/{cors.mjs → cors.js} +0 -0
  144. /package/rpc/utils/{confirmedParameter.mjs → confirmedParameter.js} +0 -0
  145. /package/rpc/utils/{helpers.mjs → helpers.js} +0 -0
  146. /package/rpc/utils/{url.mjs → url.js} +0 -0
@@ -13,6 +13,7 @@ import nodeEntryUtils, { ZERO_LICENSE } from '../../../../../src/core/state/util
13
13
  import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
14
14
  import addressUtils from '../../../../../src/core/state/utils/address.js';
15
15
  import { buildAddAdminRequesterPayload } from '../addAdmin/addAdminScenarioHelpers.js';
16
+ import { config } from '../../../../helpers/config.js';
16
17
 
17
18
  export async function setupAppendWhitelistScenario(t, { nodes = 2 } = {}) {
18
19
  const context = await setupStateNetwork({
@@ -44,11 +45,11 @@ export async function buildAppendWhitelistPayload(context, readerAddress = null)
44
45
  const adminNode = context.adminBootstrap;
45
46
  const targetAddress = readerAddress ?? selectReaderPeer(context).wallet.address;
46
47
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
47
- return CompleteStateMessageOperations.assembleAppendWhitelistMessages(
48
- adminNode.wallet,
49
- txValidity,
50
- targetAddress
51
- );
48
+ return new CompleteStateMessageOperations(adminNode.wallet, config)
49
+ .assembleAppendWhitelistMessages(
50
+ txValidity,
51
+ targetAddress
52
+ );
52
53
  }
53
54
 
54
55
  export async function buildAppendWhitelistPayloadWithTxValidity(
@@ -58,21 +59,21 @@ export async function buildAppendWhitelistPayloadWithTxValidity(
58
59
  ) {
59
60
  const adminNode = context.adminBootstrap;
60
61
  const targetAddress = readerAddress ?? selectReaderPeer(context).wallet.address;
61
- return CompleteStateMessageOperations.assembleAppendWhitelistMessages(
62
- adminNode.wallet,
63
- txValidity,
64
- targetAddress
65
- );
62
+ return new CompleteStateMessageOperations(adminNode.wallet, config)
63
+ .assembleAppendWhitelistMessages(
64
+ txValidity,
65
+ targetAddress
66
+ );
66
67
  }
67
68
 
68
69
  export async function buildBanWriterPayload(context, readerAddress) {
69
70
  const adminNode = context.adminBootstrap;
70
71
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
71
- return CompleteStateMessageOperations.assembleBanWriterMessage(
72
- adminNode.wallet,
73
- readerAddress,
74
- txValidity
75
- );
72
+ return new CompleteStateMessageOperations(adminNode.wallet, config)
73
+ .assembleBanWriterMessage(
74
+ readerAddress,
75
+ txValidity
76
+ );
76
77
  }
77
78
 
78
79
  export function mutateAppendWhitelistPayloadForInvalidSchema(t, validPayload) {
@@ -146,7 +147,7 @@ export async function assertReaderWhitelisted(
146
147
  const licenseId = lengthEntryUtils.decodeBE(decodedEntry.license);
147
148
  const licenseIndexEntry = await base.view.get(`${EntryType.LICENSE_INDEX}${licenseId}`);
148
149
  t.ok(licenseIndexEntry, 'license index entry exists for reader');
149
- const readerAddressBuffer = addressUtils.addressToBuffer(readerAddress);
150
+ const readerAddressBuffer = addressUtils.addressToBuffer(readerAddress, config.addressPrefix);
150
151
  t.ok(readerAddressBuffer.length > 0, 'reader address encodes to buffer');
151
152
  t.ok(
152
153
  licenseIndexEntry && b4a.equals(licenseIndexEntry.value, readerAddressBuffer),
@@ -11,6 +11,7 @@ import { AUTOBASE_VALUE_ENCODING } from '../../../../../src/utils/constants.js';
11
11
  import { toTerm } from '../../../../../src/core/state/utils/balance.js';
12
12
  import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
13
13
  import { buildAddAdminRequesterPayload } from '../addAdmin/addAdminScenarioHelpers.js';
14
+ import { config } from '../../../../helpers/config.js';
14
15
 
15
16
  export async function setupBalanceInitializationScenario(t, { recipientCount = 2 } = {}) {
16
17
  const context = await setupStateNetwork({
@@ -41,8 +42,7 @@ async function bootstrapAdmin(context) {
41
42
  export async function buildBalanceInitializationPayload(context, recipientAddress, balanceBuffer) {
42
43
  const adminNode = context.adminBootstrap;
43
44
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
44
- const messages = await CompleteStateMessageOperations.assembleBalanceInitializationMessages(
45
- adminNode.wallet,
45
+ const messages = await new CompleteStateMessageOperations(adminNode.wallet, config).assembleBalanceInitializationMessages(
46
46
  txValidity,
47
47
  [[recipientAddress, balanceBuffer]]
48
48
  );
@@ -60,8 +60,7 @@ export async function buildBalanceInitializationPayloadWithTxValidity({
60
60
  }
61
61
 
62
62
  const adminNode = context.adminBootstrap;
63
- const messages = await CompleteStateMessageOperations.assembleBalanceInitializationMessages(
64
- adminNode.wallet,
63
+ const messages = await new CompleteStateMessageOperations(adminNode.wallet, config).assembleBalanceInitializationMessages(
65
64
  mutatedTxValidity,
66
65
  [[decoded.bio.ia, decoded.bio.am]]
67
66
  );
@@ -7,6 +7,7 @@ import setupBalanceInitializationScenario, {
7
7
  buildDefaultBalanceInitializationPayload,
8
8
  assertBalanceInitializationFailureState
9
9
  } from './balanceInitializationScenarioHelpers.js';
10
+ import { config } from '../../../../helpers/config.js';
10
11
 
11
12
  export default function balanceInitializationNodeEntryBalanceUpdateFailureScenario() {
12
13
  new OperationValidationScenarioBase({
@@ -30,7 +31,7 @@ async function applyWithCorruptExistingNodeEntry(context, payload, _t, validPayl
30
31
  const decoded = safeDecodeApplyOperation(validPayload ?? payload);
31
32
  const targetAddressBuffer = decoded?.bio?.ia;
32
33
  const targetAddressString = targetAddressBuffer
33
- ? addressUtils.bufferToAddress(targetAddressBuffer)
34
+ ? addressUtils.bufferToAddress(targetAddressBuffer, config.addressPrefix)
34
35
  : null;
35
36
  if (!targetAddressString || !targetAddressBuffer) {
36
37
  throw new Error('Failed to resolve recipient address for balance update failure scenario.');
@@ -19,6 +19,7 @@ import addressUtils from '../../../../../src/core/state/utils/address.js';
19
19
  import { EntryType } from '../../../../../src/utils/constants.js';
20
20
  import { BALANCE_ZERO, toBalance } from '../../../../../src/core/state/utils/balance.js';
21
21
  import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
22
+ import { config } from '../../../../helpers/config.js';
22
23
 
23
24
  export default function banValidatorBanAndReWhitelistScenario() {
24
25
  test('State.apply banValidator allows re-whitelisting without changing license', async t => {
@@ -93,7 +94,7 @@ export default function banValidatorBanAndReWhitelistScenario() {
93
94
  const licenseId = decodedBefore.license.readUInt32BE();
94
95
  const licenseIndexEntry = await adminPeer.base.view.get(`${EntryType.LICENSE_INDEX}${licenseId}`);
95
96
  t.ok(licenseIndexEntry, 'license index entry persists after re-whitelist');
96
- const addressBuffer = addressUtils.addressToBuffer(validatorPeer.wallet.address);
97
+ const addressBuffer = addressUtils.addressToBuffer(validatorPeer.wallet.address, config.addressPrefix);
97
98
  if (licenseIndexEntry?.value && addressBuffer) {
98
99
  t.ok(
99
100
  b4a.equals(licenseIndexEntry.value, addressBuffer),
@@ -1,4 +1,5 @@
1
1
  import b4a from 'b4a';
2
+ import PeerWallet from 'trac-wallet';
2
3
  import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
3
4
  import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
4
5
  import nodeEntryUtils, { ZERO_LICENSE } from '../../../../../src/core/state/utils/nodeEntry.js';
@@ -10,14 +11,13 @@ import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../
10
11
  import {
11
12
  setupAddWriterScenario,
12
13
  selectWriterPeer,
13
- promotePeerToWriter,
14
- applyWithStakeEntryMutation
14
+ promotePeerToWriter
15
15
  } from '../addWriter/addWriterScenarioHelpers.js';
16
16
  import { setupAdminAndWhitelistedReaderNetwork } from '../common/commonScenarioHelper.js';
17
17
  import { applyWithRequesterEntryRemoval } from '../addWriter/addWriterScenarioHelpers.js';
18
18
  import { createMessage } from '../../../../../src/utils/buffer.js';
19
- import { blake3Hash } from '../../../../../src/utils/crypto.js';
20
- import { NETWORK_ID, OperationType } from '../../../../../src/utils/constants.js';
19
+ import { OperationType } from '../../../../../src/utils/constants.js';
20
+ import { config } from '../../../../helpers/config.js';
21
21
 
22
22
  export async function setupBanValidatorScenario(
23
23
  t,
@@ -62,8 +62,7 @@ export async function buildBanValidatorPayload(
62
62
  /* cover tests */
63
63
  ) {
64
64
  const txValidity = await deriveIndexerSequenceState(adminPeer.base);
65
- return CompleteStateMessageOperations.assembleBanWriterMessage(
66
- adminPeer.wallet,
65
+ return new CompleteStateMessageOperations(adminPeer.wallet, config).assembleBanWriterMessage(
67
66
  validatorPeer.wallet.address,
68
67
  txValidity
69
68
  );
@@ -74,8 +73,7 @@ export async function buildBanValidatorPayloadWithTxValidity(
74
73
  mutatedTxValidity,
75
74
  { adminPeer = context.adminBootstrap, validatorPeer = selectWriterPeer(context) } = {}
76
75
  ) {
77
- return CompleteStateMessageOperations.assembleBanWriterMessage(
78
- adminPeer.wallet,
76
+ return new CompleteStateMessageOperations(adminPeer.wallet, config).assembleBanWriterMessage(
79
77
  validatorPeer.wallet.address,
80
78
  mutatedTxValidity
81
79
  );
@@ -154,8 +152,8 @@ export async function assertBanValidatorSuccessState(
154
152
  const licenseId = lengthEntryUtils.decodeBE(decodedAfter.license);
155
153
  const licenseIndexEntry = await adminPeer.base.view.get(`${EntryType.LICENSE_INDEX}${licenseId}`);
156
154
  t.ok(licenseIndexEntry, 'license index entry persists after banValidator');
157
- if (licenseIndexEntry?.value) {
158
- const validatorAddressBuffer = addressUtils.addressToBuffer(validatorPeer.wallet.address);
155
+ if (licenseIndexEntry?.value) {
156
+ const validatorAddressBuffer = addressUtils.addressToBuffer(validatorPeer.wallet.address, config.addressPrefix);
159
157
  t.ok(
160
158
  b4a.equals(licenseIndexEntry.value, validatorAddressBuffer),
161
159
  'license index still maps to validator address'
@@ -167,8 +165,8 @@ export async function assertBanValidatorSuccessState(
167
165
  const registryKey = EntryType.WRITER_ADDRESS + decodedBefore.wk.toString('hex');
168
166
  const registryEntry = await adminPeer.base.view.get(registryKey);
169
167
  t.ok(registryEntry, 'writer registry entry persists after banValidator');
170
- if (registryEntry?.value) {
171
- const validatorAddressBuffer = addressUtils.addressToBuffer(validatorPeer.wallet.address);
168
+ if (registryEntry?.value) {
169
+ const validatorAddressBuffer = addressUtils.addressToBuffer(validatorPeer.wallet.address, config.addressPrefix);
172
170
  t.ok(
173
171
  b4a.equals(registryEntry.value, validatorAddressBuffer),
174
172
  'writer registry maps writing key to validator address'
@@ -305,13 +303,13 @@ export async function applyInvalidTargetAddressPayload(context, validPayload) {
305
303
  decoded.aco.ia = invalidAddress;
306
304
 
307
305
  const message = createMessage(
308
- NETWORK_ID,
306
+ config.networkId,
309
307
  decoded.aco.txv,
310
308
  decoded.aco.ia,
311
309
  decoded.aco.in,
312
310
  OperationType.BAN_VALIDATOR
313
311
  );
314
- const newHash = await blake3Hash(message);
312
+ const newHash = await PeerWallet.blake3(message);
315
313
  decoded.aco.tx = newHash;
316
314
  decoded.aco.is = adminPeer.wallet.sign(newHash);
317
315
 
@@ -337,15 +335,15 @@ export async function applyInvalidIndexerSequenceStatePayload(context, validPayl
337
335
  }
338
336
 
339
337
  export async function promoteValidatorToIndexer(
340
- context,
341
- { adminPeer = context.adminBootstrap, validatorPeer = selectWriterPeer(context) } = {}
338
+ context,
339
+ { adminPeer = context.adminBootstrap, validatorPeer = selectWriterPeer(context) } = {}
342
340
  ) {
343
- const txValidity = await deriveIndexerSequenceState(adminPeer.base);
344
- const payload = await CompleteStateMessageOperations.assembleAddIndexerMessage(
345
- adminPeer.wallet,
346
- validatorPeer.wallet.address,
347
- txValidity
348
- );
341
+ const txValidity = await deriveIndexerSequenceState(adminPeer.base);
342
+ const payload = await new CompleteStateMessageOperations(adminPeer.wallet, config)
343
+ .assembleAddIndexerMessage(
344
+ validatorPeer.wallet.address,
345
+ txValidity
346
+ );
349
347
 
350
348
  await adminPeer.base.append(payload);
351
349
  await adminPeer.base.update();
@@ -420,7 +418,7 @@ export async function applyWithBanValidatorRoleDecodeFailure(context, invalidPay
420
418
  export async function applyWithBanValidatorWithdrawFailure(context, invalidPayload) {
421
419
  const targetPeer = context.banValidatorScenario?.validatorPeer ?? selectWriterPeer(context);
422
420
  const targetAddress = targetPeer.wallet.address;
423
- const targetBuffer = addressUtils.addressToBuffer(targetAddress);
421
+ const targetBuffer = addressUtils.addressToBuffer(targetAddress, config.addressPrefix);
424
422
  const adminPeer = context.adminBootstrap;
425
423
  const base = adminPeer.base;
426
424
  const originalApply = base._handlers.apply;
@@ -481,13 +479,13 @@ async function assertBanValidatorPayloadMetadata(t, base, payload, { adminAddres
481
479
  t.ok(decodedPayload, 'banValidator payload decodes');
482
480
  if (!decodedPayload) return;
483
481
 
484
- const requesterAddress = addressUtils.bufferToAddress(decodedPayload.address);
482
+ const requesterAddress = addressUtils.bufferToAddress(decodedPayload.address, config.addressPrefix);
485
483
  t.ok(requesterAddress, 'banValidator requester address decodes');
486
484
  if (requesterAddress) {
487
485
  t.is(requesterAddress, adminAddress, 'banValidator payload signed by admin');
488
486
  }
489
487
 
490
- const targetAddressDecoded = addressUtils.bufferToAddress(decodedPayload?.aco?.ia);
488
+ const targetAddressDecoded = addressUtils.bufferToAddress(decodedPayload?.aco?.ia, config.addressPrefix);
491
489
  t.ok(targetAddressDecoded, 'banValidator target address decodes');
492
490
  if (targetAddressDecoded) {
493
491
  t.is(targetAddressDecoded, targetAddress, 'banValidator payload targets expected validator');
@@ -9,6 +9,7 @@ import { initializeBalances, whitelistAddress } from '../common/commonScenarioHe
9
9
  import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
10
10
  import deploymentEntryUtils from '../../../../../src/core/state/utils/deploymentEntry.js';
11
11
  import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
12
+ import { config } from '../../../../helpers/config.js';
12
13
 
13
14
  async function setupDuplicateBootstrapScenario(t) {
14
15
  const context = await setupBootstrapDeploymentScenario(t, { nodes: 4 });
@@ -73,7 +74,7 @@ async function assertDuplicateBootstrapState(t, context, validPayload, invalidPa
73
74
  const deploymentKey = `deployment/${bootstrapHex}`;
74
75
  const deploymentEntry = await validatorPeer.base.view.get(deploymentKey);
75
76
  t.ok(deploymentEntry, 'deployment entry still stored');
76
- const decodedDeployment = deploymentEntry ? deploymentEntryUtils.decode(deploymentEntry.value) : null;
77
+ const decodedDeployment = deploymentEntry ? deploymentEntryUtils.decode(deploymentEntry.value, config.addressLength) : null;
77
78
  t.ok(decodedDeployment, 'deployment entry decodes');
78
79
  if (decodedDeployment?.txHash) {
79
80
  t.is(decodedDeployment.txHash.toString('hex'), firstTxHex, 'deployment entry keeps original tx hash');
@@ -19,6 +19,7 @@ import { toBalance } from '../../../../../src/core/state/utils/balance.js';
19
19
  import { EntryType } from '../../../../../src/utils/constants.js';
20
20
  import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
21
21
  import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
22
+ import { config } from '../../../../helpers/config.js';
22
23
 
23
24
  const DEFAULT_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('10'));
24
25
 
@@ -108,23 +109,23 @@ export async function buildBootstrapDeploymentPayload(context, options = {}) {
108
109
  context.bootstrapDeployment?.txValidity ??
109
110
  (await deriveIndexerSequenceState(validatorPeer.base));
110
111
 
111
- const partial = await PartialStateMessageOperations.assembleBootstrapDeploymentMessage(
112
- deployerPeer.wallet,
113
- externalBootstrap.toString('hex'),
114
- channel.toString('hex'),
115
- txValidity.toString('hex')
116
- );
112
+ const partial = await new PartialStateMessageOperations(deployerPeer.wallet, config)
113
+ .assembleBootstrapDeploymentMessage(
114
+ externalBootstrap.toString('hex'),
115
+ channel.toString('hex'),
116
+ txValidity.toString('hex')
117
+ );
117
118
 
118
- return CompleteStateMessageOperations.assembleCompleteBootstrapDeployment(
119
- validatorPeer.wallet,
119
+ return new CompleteStateMessageOperations(validatorPeer.wallet, config)
120
+ .assembleCompleteBootstrapDeployment(
120
121
  partial.address,
121
- b4a.from(partial.bdo.tx, 'hex'),
122
- b4a.from(partial.bdo.txv, 'hex'),
123
- b4a.from(partial.bdo.bs, 'hex'),
124
- b4a.from(partial.bdo.ic, 'hex'),
125
- b4a.from(partial.bdo.in, 'hex'),
126
- b4a.from(partial.bdo.is, 'hex')
127
- );
122
+ b4a.from(partial.bdo.tx, 'hex'),
123
+ b4a.from(partial.bdo.txv, 'hex'),
124
+ b4a.from(partial.bdo.bs, 'hex'),
125
+ b4a.from(partial.bdo.ic, 'hex'),
126
+ b4a.from(partial.bdo.in, 'hex'),
127
+ b4a.from(partial.bdo.is, 'hex')
128
+ );
128
129
  }
129
130
 
130
131
  export async function buildBootstrapDeploymentPayloadWithTxValidity(context, txValidity, options = {}) {
@@ -173,8 +174,8 @@ export async function assertBootstrapDeploymentSuccessState(
173
174
  t.ok(validatorAddressBuffer, 'payload carries validator address');
174
175
  t.ok(txHashBuffer, 'payload exposes tx hash');
175
176
 
176
- const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer);
177
- const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer);
177
+ const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer, config.addressPrefix);
178
+ const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer, config.addressPrefix);
178
179
 
179
180
  if (requesterAddress) {
180
181
  t.is(requesterAddress, deployerPeer.wallet.address, 'payload signed by expected requester');
@@ -329,7 +330,7 @@ async function assertDeploymentEntry(
329
330
  const deploymentKey = `${EntryType.DEPLOYMENT}${bootstrapBuffer.toString('hex')}`;
330
331
  const deploymentEntry = await base.view.get(deploymentKey);
331
332
  t.ok(deploymentEntry, 'deployment entry stored');
332
- const decodedDeployment = deploymentEntryUtils.decode(deploymentEntry?.value);
333
+ const decodedDeployment = deploymentEntryUtils.decode(deploymentEntry?.value, config.addressLength);
333
334
  t.ok(decodedDeployment?.txHash, 'deployment entry decodes');
334
335
  if (!decodedDeployment || !decodedDeployment.txHash) return;
335
336
 
@@ -1,8 +1,9 @@
1
1
  import b4a from 'b4a';
2
2
  import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
3
3
  import { eventFlush } from '../../../../../helpers/autobaseTestHelpers.js';
4
- import { EntryType, TRAC_ADDRESS_SIZE } from '../../../../../../src/utils/constants.js';
4
+ import { EntryType } from '../../../../../../src/utils/constants.js';
5
5
  import addressUtils from '../../../../../../src/core/state/utils/address.js';
6
+ import { config } from '../../../../../helpers/config.js'
6
7
 
7
8
  export default class AdminConsistencyMismatchScenario extends OperationValidationScenarioBase {
8
9
  constructor({
@@ -39,8 +40,8 @@ async function applyWithMutatedAdminEntry(context, payload) {
39
40
  throw new Error('Admin consistency scenario requires a reader peer with a wallet.');
40
41
  }
41
42
 
42
- const alternateAddressBuffer = addressUtils.addressToBuffer(reader.wallet.address);
43
- if (!alternateAddressBuffer || alternateAddressBuffer.length !== TRAC_ADDRESS_SIZE) {
43
+ const alternateAddressBuffer = addressUtils.addressToBuffer(reader.wallet.address, config.addressPrefix);
44
+ if (!alternateAddressBuffer || alternateAddressBuffer.length !== config.addressLength) {
44
45
  throw new Error('Failed to derive alternate admin address buffer.');
45
46
  }
46
47
 
@@ -85,7 +86,7 @@ function patchAdminEntryMismatch(base, alternateAddressBuffer) {
85
86
 
86
87
  mutatedOnce = true;
87
88
  const mutated = b4a.from(adminEntry.value);
88
- alternateAddressBuffer.copy(mutated, 0, 0, TRAC_ADDRESS_SIZE);
89
+ alternateAddressBuffer.copy(mutated, 0, 0, config.addressLength);
89
90
 
90
91
  return {
91
92
  ...adminEntry,
@@ -1,7 +1,8 @@
1
1
  import b4a from 'b4a';
2
2
  import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
3
3
  import { eventFlush } from '../../../../../helpers/autobaseTestHelpers.js';
4
- import { EntryType, TRAC_ADDRESS_SIZE } from '../../../../../../src/utils/constants.js';
4
+ import { EntryType } from '../../../../../../src/utils/constants.js';
5
+ import { config } from '../../../../../helpers/config.js';
5
6
 
6
7
  const ADMIN_KEY_BUFFER = b4a.from(EntryType.ADMIN);
7
8
 
@@ -97,12 +98,12 @@ function patchAdminEntryAddress(base) {
97
98
  }
98
99
 
99
100
  function mutateAdminAddress(value) {
100
- if (!b4a.isBuffer(value) || value.length < TRAC_ADDRESS_SIZE) {
101
+ if (!b4a.isBuffer(value) || value.length < config.addressLength) {
101
102
  return value;
102
103
  }
103
104
 
104
105
  const mutated = b4a.from(value);
105
- const lastIndex = TRAC_ADDRESS_SIZE - 1;
106
+ const lastIndex = config.addressLength - 1;
106
107
  const asciiP = 'p'.charCodeAt(0);
107
108
  const asciiQ = 'q'.charCodeAt(0);
108
109
  mutated[lastIndex] = mutated[lastIndex] === asciiP ? asciiQ : asciiP;
@@ -4,6 +4,7 @@ import nodeEntryUtils from '../../../../../../../src/core/state/utils/nodeEntry.
4
4
  import addressUtils from '../../../../../../../src/core/state/utils/address.js';
5
5
  import { BALANCE_ZERO } from '../../../../../../../src/core/state/utils/balance.js';
6
6
  import { eventFlush } from '../../../../../../helpers/autobaseTestHelpers.js';
7
+ import { config } from '../../../../../../helpers/config.js'
7
8
 
8
9
  export default class RequesterBalanceScenarioBase extends OperationValidationScenarioBase {
9
10
  constructor({
@@ -76,7 +77,7 @@ function createApplyInvalidPayload({
76
77
  }
77
78
 
78
79
  const targetAddressString = peer.wallet.address;
79
- const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString);
80
+ const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString, config.addressPrefix);
80
81
 
81
82
  const originalDecode = nodeEntryUtils.decode;
82
83
  let shouldFailNextSub = false;
@@ -8,6 +8,7 @@ import {
8
8
  import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
9
9
  import { AUTOBASE_VALUE_ENCODING } from '../../../../../src/utils/constants.js';
10
10
  import { buildAddAdminRequesterPayload } from '../addAdmin/addAdminScenarioHelpers.js';
11
+ import { config } from '../../../../helpers/config.js';
11
12
 
12
13
  /**
13
14
  * Boots a network with an initialized admin node and returns the shared context.
@@ -58,8 +59,7 @@ export async function initializeBalances(context, recipients) {
58
59
  if (!adminNode || !Array.isArray(recipients) || recipients.length === 0) return;
59
60
 
60
61
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
61
- const payloads = await CompleteStateMessageOperations.assembleBalanceInitializationMessages(
62
- adminNode.wallet,
62
+ const payloads = await new CompleteStateMessageOperations(adminNode.wallet, config).assembleBalanceInitializationMessages(
63
63
  txValidity,
64
64
  recipients
65
65
  );
@@ -76,8 +76,7 @@ export async function whitelistAddress(context, address) {
76
76
  if (!adminNode || !address) return;
77
77
 
78
78
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
79
- const payload = await CompleteStateMessageOperations.assembleAppendWhitelistMessages(
80
- adminNode.wallet,
79
+ const payload = await new CompleteStateMessageOperations(adminNode.wallet, config).assembleAppendWhitelistMessages(
81
80
  txValidity,
82
81
  address
83
82
  );
@@ -1,6 +1,7 @@
1
1
  import { eventFlush, deriveIndexerSequenceState } from '../../../../../helpers/autobaseTestHelpers.js';
2
2
  import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
3
3
  import CompleteStateMessageOperations from '../../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
4
+ import { config } from '../../../../../helpers/config.js';
4
5
 
5
6
  export default class InitializationDisabledScenario extends OperationValidationScenarioBase {
6
7
  constructor({
@@ -33,8 +34,7 @@ async function disableInitializationAndApply(context, invalidPayload) {
33
34
  }
34
35
 
35
36
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
36
- const disablePayload = await CompleteStateMessageOperations.assembleDisableInitializationMessage(
37
- adminNode.wallet,
37
+ const disablePayload = await new CompleteStateMessageOperations(adminNode.wallet, config).assembleDisableInitializationMessage(
38
38
  adminNode.base.local.key,
39
39
  txValidity
40
40
  );
@@ -3,7 +3,7 @@ import {
3
3
  safeDecodeApplyOperation,
4
4
  safeEncodeApplyOperation
5
5
  } from '../../../../../../src/utils/protobuf/operationHelpers.js';
6
- import { blake3Hash } from '../../../../../../src/utils/crypto.js';
6
+ import PeerWallet from 'trac-wallet';
7
7
  import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
8
8
 
9
9
  export default class InvalidHashValidationScenario extends OperationValidationScenarioBase {
@@ -32,7 +32,7 @@ async function defaultMutateHash(t, validPayload) {
32
32
  const decodedPayload = safeDecodeApplyOperation(validPayload);
33
33
  t.ok(decodedPayload, 'fixtures decode');
34
34
 
35
- const invalidHash = await blake3Hash(validPayload);
35
+ const invalidHash = await PeerWallet.blake3(validPayload);
36
36
 
37
37
  switch (true) {
38
38
  case Boolean(decodedPayload.cao?.tx):
@@ -2,6 +2,7 @@ import b4a from 'b4a';
2
2
  import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
3
3
  import addressUtils from '../../../../../../src/core/state/utils/address.js';
4
4
  import { eventFlush } from '../../../../../helpers/autobaseTestHelpers.js';
5
+ import { config } from '../../../../../helpers/config.js'
5
6
 
6
7
  export default class RequesterNodeEntryBufferMissingScenario extends OperationValidationScenarioBase {
7
8
  constructor({
@@ -26,7 +27,7 @@ export default class RequesterNodeEntryBufferMissingScenario extends OperationVa
26
27
  }
27
28
 
28
29
  const targetAddressString = peer.wallet.address;
29
- const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString);
30
+ const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString, config.addressPrefix);
30
31
 
31
32
  const originalApply = node.base._handlers.apply;
32
33
  node.base._handlers.apply = async function patchedApply(nodes, view, baseCtx) {
@@ -2,6 +2,7 @@ import b4a from 'b4a';
2
2
  import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
3
3
  import addressUtils from '../../../../../../src/core/state/utils/address.js';
4
4
  import { eventFlush } from '../../../../../helpers/autobaseTestHelpers.js';
5
+ import { config } from '../../../../../helpers/config.js'
5
6
 
6
7
  export default class RequesterNodeEntryDecodeFailureScenario extends OperationValidationScenarioBase {
7
8
  constructor({
@@ -26,7 +27,7 @@ export default class RequesterNodeEntryDecodeFailureScenario extends OperationVa
26
27
  }
27
28
 
28
29
  const targetAddressString = peer.wallet.address;
29
- const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString);
30
+ const targetAddressBuffer = addressUtils.addressToBuffer(targetAddressString, config.addressPrefix);
30
31
 
31
32
  const originalApply = node.base._handlers.apply;
32
33
  node.base._handlers.apply = async function patchedApply(nodes, view, baseCtx) {
@@ -3,6 +3,7 @@ import OperationValidationScenarioBase from '../../base/OperationValidationScena
3
3
  import { safeDecodeApplyOperation } from '../../../../../../../src/utils/protobuf/operationHelpers.js';
4
4
  import addressUtils from '../../../../../../../src/core/state/utils/address.js';
5
5
  import { eventFlush } from '../../../../../../helpers/autobaseTestHelpers.js';
6
+ import { config } from '../../../../../../helpers/config.js'
6
7
 
7
8
  export const ValidatorEntryMutation = {
8
9
  DELETE: Symbol('validator-entry-delete')
@@ -178,7 +179,7 @@ function extractValidatorAddress(payloadBuffer, path) {
178
179
  return null;
179
180
  }
180
181
 
181
- const addressString = addressUtils.bufferToAddress(value);
182
+ const addressString = addressUtils.bufferToAddress(value, config.addressPrefix);
182
183
  if (!addressString) {
183
184
  return null;
184
185
  }
@@ -5,6 +5,7 @@ import { safeDecodeApplyOperation } from '../../../../../../../src/utils/protobu
5
5
  import addressUtils from '../../../../../../../src/core/state/utils/address.js';
6
6
  import { eventFlush } from '../../../../../../helpers/autobaseTestHelpers.js';
7
7
  import { BALANCE_ZERO } from '../../../../../../../src/core/state/utils/balance.js';
8
+ import { config } from '../../../../../../helpers/config.js'
8
9
 
9
10
  const DEFAULT_VALIDATOR_ADDRESS_PATH = ['rao', 'va'];
10
11
  const VALIDATOR_ENTRY_MARK = Symbol('validator-entry-mark');
@@ -285,7 +286,7 @@ function extractValidatorAddress(payloadBuffer, path) {
285
286
  return null;
286
287
  }
287
288
 
288
- const addressString = addressUtils.bufferToAddress(value);
289
+ const addressString = addressUtils.bufferToAddress(value, config.addressPrefix);
289
290
  if (!addressString) {
290
291
  return null;
291
292
  }
@@ -11,6 +11,7 @@ import { AUTOBASE_VALUE_ENCODING, EntryType } from '../../../../../src/utils/con
11
11
  import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
12
12
  import { safeWriteUInt32BE } from '../../../../../src/utils/buffer.js';
13
13
  import { buildAddAdminRequesterPayload } from '../addAdmin/addAdminScenarioHelpers.js';
14
+ import { config } from '../../../../helpers/config.js';
14
15
 
15
16
  export async function setupDisableInitializationScenario(t) {
16
17
  const context = await setupStateNetwork({
@@ -54,20 +55,20 @@ export async function buildDisableInitializationPayload(context) {
54
55
  const adminNode = context.adminBootstrap;
55
56
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
56
57
 
57
- return CompleteStateMessageOperations.assembleDisableInitializationMessage(
58
- adminNode.wallet,
59
- adminNode.base.local.key,
60
- txValidity
61
- );
58
+ return new CompleteStateMessageOperations(adminNode.wallet, config)
59
+ .assembleDisableInitializationMessage(
60
+ adminNode.base.local.key,
61
+ txValidity
62
+ );
62
63
  }
63
64
 
64
65
  export async function buildDisableInitializationPayloadWithTxValidity(context, txValidity) {
65
66
  const adminNode = context.adminBootstrap;
66
- return CompleteStateMessageOperations.assembleDisableInitializationMessage(
67
- adminNode.wallet,
68
- adminNode.base.local.key,
69
- txValidity
70
- );
67
+ return new CompleteStateMessageOperations(adminNode.wallet, config)
68
+ .assembleDisableInitializationMessage(
69
+ adminNode.base.local.key,
70
+ txValidity
71
+ );
71
72
  }
72
73
 
73
74
  export async function assertInitializationDisabledState(t, base, payload) {