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
@@ -3,15 +3,14 @@ import sinon from 'sinon';
3
3
  import b4a from 'b4a';
4
4
 
5
5
  import PeerWallet from 'trac-wallet';
6
- import { TRAC_NETWORK_MSB_MAINNET_PREFIX } from 'trac-wallet/constants.js';
7
-
8
6
  import NetworkWalletFactory, { EphemeralWallet } from '../../../src/core/network/identity/NetworkWalletFactory.js';
9
7
  import { errorMessageIncludes } from '../../helpers/regexHelper.js';
10
8
  import { testKeyPair1, testKeyPair2 } from '../../fixtures/apply.fixtures.js';
9
+ import { config } from '../../helpers/config.js';
11
10
 
12
11
  test('NetworkWalletFactory.provide returns wallet when enabled', async t => {
13
12
  const publicKey = b4a.from(testKeyPair2.publicKey, 'hex');
14
- const address = PeerWallet.encodeBech32m(TRAC_NETWORK_MSB_MAINNET_PREFIX, publicKey);
13
+ const address = PeerWallet.encodeBech32m(config.addressPrefix, publicKey);
15
14
  const signResult = b4a.from('abcd', 'hex');
16
15
  const wallet = {
17
16
  publicKey,
@@ -20,7 +19,7 @@ test('NetworkWalletFactory.provide returns wallet when enabled', async t => {
20
19
  verify: sinon.stub().returns(true)
21
20
  };
22
21
 
23
- const provider = NetworkWalletFactory.provide({ wallet, enableWallet: true });
22
+ const provider = NetworkWalletFactory.provide({ wallet, enableWallet: true, networkPrefix: config.addressPrefix });
24
23
  const message = b4a.from('00112233', 'hex');
25
24
  const signature = provider.sign(message);
26
25
 
@@ -39,7 +38,7 @@ test('NetworkWalletFactory.provide returns wallet when enabled', async t => {
39
38
  test('NetworkWalletFactory.provide requires both public and secret keys when wallet disabled', async t => {
40
39
  const publicKey = b4a.from(testKeyPair1.publicKey, 'hex');
41
40
  await t.exception(
42
- () => NetworkWalletFactory.provide({ enableWallet: false, keyPair: { publicKey } }),
41
+ () => NetworkWalletFactory.provide({ enableWallet: false, keyPair: { publicKey }, networkPrefix: config.addressPrefix }),
43
42
  errorMessageIncludes('keyPair with publicKey and secretKey is required')
44
43
  );
45
44
  });
@@ -50,7 +49,8 @@ test('NetworkWalletFactory.provide rejects non-buffer inputs', async t => {
50
49
  () =>
51
50
  NetworkWalletFactory.provide({
52
51
  enableWallet: false,
53
- keyPair: { publicKey: 'not-a-buffer', secretKey }
52
+ keyPair: { publicKey: 'not-a-buffer', secretKey },
53
+ networkPrefix: config.addressPrefix
54
54
  }),
55
55
  errorMessageIncludes('must be a Buffer')
56
56
  );
@@ -65,7 +65,7 @@ test('NetworkWalletFactory.provide propagates invalid public key length errors',
65
65
  NetworkWalletFactory.provide({
66
66
  enableWallet: false,
67
67
  keyPair: { publicKey: invalidPublicKey, secretKey },
68
- networkPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX
68
+ networkPrefix: config.addressPrefix
69
69
  }),
70
70
  errorMessageIncludes('Invalid public key')
71
71
  );
@@ -79,14 +79,14 @@ test('NetworkWalletFactory.provide derives address and signs payloads from keyPa
79
79
  const provider = NetworkWalletFactory.provide({
80
80
  enableWallet: false,
81
81
  keyPair,
82
- networkPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX
82
+ networkPrefix: config.addressPrefix
83
83
  });
84
84
  const message = b4a.from('123455555', 'hex');
85
85
  const signature = provider.sign(message);
86
86
 
87
87
  t.is(
88
88
  provider.address,
89
- PeerWallet.encodeBech32m(TRAC_NETWORK_MSB_MAINNET_PREFIX, provider.publicKey)
89
+ PeerWallet.encodeBech32m(config.addressPrefix, provider.publicKey)
90
90
  );
91
91
  t.ok(PeerWallet.verify(signature, message, provider.publicKey));
92
92
  t.ok(provider.verify(signature, message));
@@ -104,7 +104,7 @@ test('NetworkWalletFactory handles falsy address derivation results', async t =>
104
104
  NetworkWalletFactory.provide({
105
105
  enableWallet: false,
106
106
  keyPair,
107
- networkPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX
107
+ networkPrefix: config.addressPrefix
108
108
  }),
109
109
  errorMessageIncludes('failed to derive address')
110
110
  );
@@ -124,7 +124,7 @@ test('NetworkWalletFactory propagates encoder exceptions', async t => {
124
124
  NetworkWalletFactory.provide({
125
125
  enableWallet: false,
126
126
  keyPair,
127
- networkPrefix: TRAC_NETWORK_MSB_MAINNET_PREFIX
127
+ networkPrefix: config.addressPrefix
128
128
  }),
129
129
  errorMessageIncludes('test exception')
130
130
  );
@@ -137,12 +137,12 @@ test('EphemeralWallet exposes wallet like interface', async t => {
137
137
  publicKey: b4a.from(testKeyPair1.publicKey, 'hex'),
138
138
  secretKey: b4a.from(testKeyPair1.secretKey, 'hex')
139
139
  };
140
- const wallet = new EphemeralWallet(keyPair, TRAC_NETWORK_MSB_MAINNET_PREFIX);
140
+ const wallet = new EphemeralWallet(keyPair, config.addressPrefix);
141
141
  const message = b4a.from('feedface', 'hex');
142
142
  const signature = wallet.sign(message);
143
143
 
144
144
  t.alike(wallet.publicKey, keyPair.publicKey);
145
- t.is(wallet.address, PeerWallet.encodeBech32m(TRAC_NETWORK_MSB_MAINNET_PREFIX, keyPair.publicKey));
145
+ t.is(wallet.address, PeerWallet.encodeBech32m(config.addressPrefix, keyPair.publicKey));
146
146
  t.ok(PeerWallet.verify(signature, message, wallet.publicKey));
147
147
  t.ok(wallet.verify(signature, message));
148
148
  });
@@ -150,7 +150,7 @@ test('EphemeralWallet exposes wallet like interface', async t => {
150
150
  test('EphemeralWallet requires both public and secret keys', async t => {
151
151
  const publicKey = b4a.from(testKeyPair1.publicKey, 'hex');
152
152
  await t.exception(
153
- () => new EphemeralWallet({ publicKey }, TRAC_NETWORK_MSB_MAINNET_PREFIX),
153
+ () => new EphemeralWallet({ publicKey }, config.addressPrefix),
154
154
  errorMessageIncludes('keyPair with publicKey and secretKey is required')
155
155
  );
156
156
  });
@@ -6,8 +6,8 @@ import {
6
6
  import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
7
7
  import { toTerm } from '../../../../../src/core/state/utils/balance.js';
8
8
  import CompleteStateMessageOperations from '../../../../../src/messages/completeStateMessages/CompleteStateMessageOperations.js';
9
-
10
9
  import { setupAddAdminScenario, assertAdminState } from './addAdminScenarioHelpers.js';
10
+ import { config } from '../../../../helpers/config.js';
11
11
 
12
12
  export default function addAdminHappyPathScenario() {
13
13
  test('State.apply addAdmin bootstraps admin node - happy path', async t => {
@@ -17,11 +17,11 @@ export default function addAdminHappyPathScenario() {
17
17
  const reader = readerNodes[0];
18
18
 
19
19
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
20
- const addAdminPayload = await CompleteStateMessageOperations.assembleAddAdminMessage(
21
- adminNode.wallet,
22
- adminNode.base.local.key,
23
- txValidity
24
- );
20
+ const addAdminPayload = await new CompleteStateMessageOperations(adminNode.wallet, config)
21
+ .assembleAddAdminMessage(
22
+ adminNode.base.local.key,
23
+ txValidity
24
+ );
25
25
 
26
26
  await adminNode.base.append(addAdminPayload);
27
27
  await adminNode.base.update();
@@ -17,12 +17,12 @@ import {
17
17
  ADMIN_INITIAL_BALANCE,
18
18
  ADMIN_INITIAL_STAKED_BALANCE
19
19
  } from '../../../../../src/utils/constants.js';
20
- import { createSignature } from '../../../../helpers/createTestSignature.js';
21
20
  import adminEntryUtils from '../../../../../src/core/state/utils/adminEntry.js';
22
21
  import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
23
22
  import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
24
23
  import addressUtils from '../../../../../src/core/state/utils/address.js';
25
24
  import { safeWriteUInt32BE } from '../../../../../src/utils/buffer.js';
25
+ import { config } from '../../../../helpers/config.js';
26
26
 
27
27
  export async function setupAddAdminScenario(t) {
28
28
  const context = await setupStateNetwork({
@@ -42,11 +42,11 @@ export async function setupAddAdminScenario(t) {
42
42
  export async function buildAddAdminRequesterPayload(context) {
43
43
  const adminNode = context.adminBootstrap;
44
44
  const txValidity = await deriveIndexerSequenceState(adminNode.base);
45
- return CompleteStateMessageOperations.assembleAddAdminMessage(
46
- adminNode.wallet,
47
- adminNode.base.local.key,
48
- txValidity
49
- );
45
+ return new CompleteStateMessageOperations(adminNode.wallet, config)
46
+ .assembleAddAdminMessage(
47
+ adminNode.base.local.key,
48
+ txValidity
49
+ );
50
50
  }
51
51
 
52
52
  export async function assertAddAdminRequesterFailureState(t, context) {
@@ -103,7 +103,7 @@ export async function assertAdminState(t, base, wallet, writingKey, payload) {
103
103
  const adminEntryRecord = await base.view.get(EntryType.ADMIN);
104
104
  t.ok(adminEntryRecord, 'admin entry should exist');
105
105
 
106
- const decodedAdminEntry = adminEntryUtils.decode(adminEntryRecord.value);
106
+ const decodedAdminEntry = adminEntryUtils.decode(adminEntryRecord.value, config.addressPrefix);
107
107
  t.ok(decodedAdminEntry, 'admin entry decodes');
108
108
  t.is(decodedAdminEntry.address, wallet.address, 'admin entry stores wallet address');
109
109
  t.ok(b4a.equals(decodedAdminEntry.wk, writingKey), 'admin entry stores writing key');
@@ -126,7 +126,7 @@ export async function assertAdminState(t, base, wallet, writingKey, payload) {
126
126
  'admin license id assigned'
127
127
  );
128
128
 
129
- const adminAddressBuffer = addressUtils.addressToBuffer(wallet.address);
129
+ const adminAddressBuffer = addressUtils.addressToBuffer(wallet.address, config.addressPrefix);
130
130
  t.ok(adminAddressBuffer.length > 0, 'admin address encoded as buffer');
131
131
  const writerRegistry = await base.view.get(EntryType.WRITER_ADDRESS + writingKey.toString('hex'));
132
132
  t.ok(writerRegistry, 'writer registry entry exists');
@@ -23,6 +23,7 @@ import addAdminEntryExistsScenario from './adminEntryExistsScenario.js';
23
23
  import addAdminNonBootstrapNodeScenario from './nonBootstrapNodeScenario.js';
24
24
  import addAdminNodeEntryInitializationFailureScenario from './nodeEntryInitializationFailureScenario.js';
25
25
  import addAdminEntryEncodingFailureScenario from './adminEntryEncodingFailureScenario.js';
26
+ import { config } from '../../../../helpers/config.js';
26
27
 
27
28
  // happy path
28
29
  addAdminHappyPathScenario();
@@ -128,11 +129,11 @@ new TransactionValidityMismatchScenario({
128
129
  assertStateUnchanged: assertAddAdminRequesterFailureState,
129
130
  rebuildPayloadWithTxValidity: ({ context, mutatedTxValidity }) => {
130
131
  const adminNode = context.adminBootstrap;
131
- return CompleteStateMessageOperations.assembleAddAdminMessage(
132
- adminNode.wallet,
133
- adminNode.base.local.key,
134
- mutatedTxValidity
135
- );
132
+ return new CompleteStateMessageOperations(adminNode.wallet, config)
133
+ .assembleAddAdminMessage(
134
+ adminNode.base.local.key,
135
+ mutatedTxValidity
136
+ );
136
137
  },
137
138
  expectedLogs: ['Transaction was not executed.']
138
139
  }).performScenario();
@@ -12,6 +12,7 @@ import transactionUtils from '../../../../../src/core/state/utils/transaction.js
12
12
  import addressUtils from '../../../../../src/core/state/utils/address.js';
13
13
  import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
14
14
  import nodeRoleUtils from '../../../../../src/core/state/utils/roles.js';
15
+ import { config } from '../../../../helpers/config.js';
15
16
 
16
17
  export function selectIndexerCandidatePeer(context, offset = 0) {
17
18
  return selectWriterPeer(context, offset);
@@ -50,11 +51,11 @@ export async function buildAddIndexerPayload(
50
51
  }
51
52
 
52
53
  const txValidity = await deriveIndexerSequenceState(adminPeer.base);
53
- return CompleteStateMessageOperations.assembleAddIndexerMessage(
54
- adminPeer.wallet,
55
- writerPeer.wallet.address,
56
- txValidity
57
- );
54
+ return new CompleteStateMessageOperations(adminPeer.wallet, config)
55
+ .assembleAddIndexerMessage(
56
+ writerPeer.wallet.address,
57
+ txValidity
58
+ );
58
59
  }
59
60
 
60
61
  export async function applyWithIndexerRoleUpdateFailure(context, invalidPayload) {
@@ -98,11 +99,11 @@ export async function buildAddIndexerPayloadWithTxValidity(
98
99
  throw new Error('buildAddIndexerPayloadWithTxValidity requires an admin peer.');
99
100
  }
100
101
 
101
- return CompleteStateMessageOperations.assembleAddIndexerMessage(
102
- adminPeer.wallet,
103
- writerPeer.wallet.address,
104
- mutatedTxValidity
105
- );
102
+ return new CompleteStateMessageOperations(adminPeer.wallet, config)
103
+ .assembleAddIndexerMessage(
104
+ writerPeer.wallet.address,
105
+ mutatedTxValidity
106
+ );
106
107
  }
107
108
 
108
109
  export function ensureIndexerRegistration(base, writingKey) {
@@ -146,11 +147,11 @@ export async function buildRemoveIndexerPayload(
146
147
  }
147
148
 
148
149
  const txValidity = await deriveIndexerSequenceState(adminPeer.base);
149
- return CompleteStateMessageOperations.assembleRemoveIndexerMessage(
150
- adminPeer.wallet,
151
- indexerPeer.wallet.address,
152
- txValidity
153
- );
150
+ return new CompleteStateMessageOperations(adminPeer.wallet, config)
151
+ .assembleRemoveIndexerMessage(
152
+ indexerPeer.wallet.address,
153
+ txValidity
154
+ );
154
155
  }
155
156
 
156
157
  export async function buildRemoveIndexerPayloadWithTxValidity(
@@ -168,11 +169,11 @@ export async function buildRemoveIndexerPayloadWithTxValidity(
168
169
  throw new Error('buildRemoveIndexerPayloadWithTxValidity requires an admin peer.');
169
170
  }
170
171
 
171
- return CompleteStateMessageOperations.assembleRemoveIndexerMessage(
172
- adminPeer.wallet,
173
- indexerPeer.wallet.address,
174
- mutatedTxValidity
175
- );
172
+ return new CompleteStateMessageOperations(adminPeer.wallet, config)
173
+ .assembleRemoveIndexerMessage(
174
+ indexerPeer.wallet.address,
175
+ mutatedTxValidity
176
+ );
176
177
  }
177
178
 
178
179
  export async function assertAddIndexerSuccessState(
@@ -299,7 +300,7 @@ async function assertAddIndexerPayloadMetadata(t, base, payload, expectedAdminAd
299
300
 
300
301
  const requesterAddressBuffer = decodedOperation.address;
301
302
  t.ok(requesterAddressBuffer, 'addIndexer payload contains requester address');
302
- const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer);
303
+ const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer, config.addressPrefix);
303
304
  t.ok(requesterAddress, 'addIndexer requester address decodes');
304
305
  if (requesterAddress) {
305
306
  t.is(requesterAddress, expectedAdminAddress, 'addIndexer payload signed by admin');
@@ -307,7 +308,7 @@ async function assertAddIndexerPayloadMetadata(t, base, payload, expectedAdminAd
307
308
 
308
309
  const candidateAddressBuffer = decodedOperation?.aco?.ia;
309
310
  t.ok(candidateAddressBuffer, 'addIndexer payload contains candidate address');
310
- const candidateAddress = addressUtils.bufferToAddress(candidateAddressBuffer);
311
+ const candidateAddress = addressUtils.bufferToAddress(candidateAddressBuffer, config.addressPrefix);
311
312
  t.ok(candidateAddress, 'addIndexer candidate address decodes');
312
313
  if (candidateAddress) {
313
314
  t.is(candidateAddress, expectedCandidate, 'addIndexer payload nominates expected writer');
@@ -403,7 +404,7 @@ export async function applyWithPretenderRoleMutation(context, invalidPayload, ro
403
404
  if (typeof key === 'string' ? key !== address : true) {
404
405
  // string path comparison; buffer path is unlikely for address entries here
405
406
  if (b4a.isBuffer(key)) {
406
- const addrBuf = addressUtils.addressToBuffer(address);
407
+ const addrBuf = addressUtils.addressToBuffer(address, config.addressPrefix);
407
408
  if (!addrBuf || !b4a.equals(addrBuf, key)) {
408
409
  return originalGet(key);
409
410
  }
@@ -4,7 +4,6 @@ import CompleteStateMessageOperations from '../../../../../src/messages/complete
4
4
  import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
5
5
  import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
6
6
  import nodeEntryUtils, { ZERO_LICENSE } from '../../../../../src/core/state/utils/nodeEntry.js';
7
- import nodeRoleUtils from '../../../../../src/core/state/utils/roles.js';
8
7
  import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
9
8
  import addressUtils from '../../../../../src/core/state/utils/address.js';
10
9
  import { EntryType } from '../../../../../src/utils/constants.js';
@@ -17,6 +16,7 @@ import {
17
16
  } from '../../../../../src/core/state/utils/balance.js';
18
17
  import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
19
18
  import { setupAdminAndWhitelistedReaderNetwork } from '../common/commonScenarioHelper.js';
19
+ import { config } from '../../../../helpers/config.js';
20
20
 
21
21
  const DEFAULT_WRITER_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('10'));
22
22
  const STAKE_ENTRY_MARK = Symbol('stake-entry-mark');
@@ -105,14 +105,12 @@ export async function buildAddWriterPayload(
105
105
  ) {
106
106
  const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
107
107
  const writingKey = writerKeyBuffer ?? readerPeer.base.local.key;
108
- const partial = await PartialStateMessageOperations.assembleAddWriterMessage(
109
- readerPeer.wallet,
108
+ const partial = await new PartialStateMessageOperations(readerPeer.wallet, config).assembleAddWriterMessage(
110
109
  writingKey.toString('hex'),
111
110
  txValidity.toString('hex')
112
111
  );
113
112
 
114
- return CompleteStateMessageOperations.assembleAddWriterMessage(
115
- validatorPeer.wallet,
113
+ return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleAddWriterMessage(
116
114
  partial.address,
117
115
  b4a.from(partial.rao.tx, 'hex'),
118
116
  b4a.from(partial.rao.txv, 'hex'),
@@ -136,14 +134,12 @@ export async function buildAddWriterPayloadWithTxValidity(
136
134
  }
137
135
 
138
136
  const writingKey = writerKeyBuffer ?? readerPeer.base.local.key;
139
- const partial = await PartialStateMessageOperations.assembleAddWriterMessage(
140
- readerPeer.wallet,
137
+ const partial = await new PartialStateMessageOperations(readerPeer.wallet, config).assembleAddWriterMessage(
141
138
  writingKey.toString('hex'),
142
139
  mutatedTxValidity.toString('hex')
143
140
  );
144
141
 
145
- return CompleteStateMessageOperations.assembleAddWriterMessage(
146
- validatorPeer.wallet,
142
+ return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleAddWriterMessage(
147
143
  partial.address,
148
144
  b4a.from(partial.rao.tx, 'hex'),
149
145
  mutatedTxValidity,
@@ -163,14 +159,12 @@ export async function buildRemoveWriterPayload(
163
159
  ) {
164
160
  const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
165
161
  const writerKey = writerKeyBuffer ?? readerPeer.base.local.key;
166
- const partial = await PartialStateMessageOperations.assembleRemoveWriterMessage(
167
- readerPeer.wallet,
162
+ const partial = await new PartialStateMessageOperations(readerPeer.wallet, config).assembleRemoveWriterMessage(
168
163
  writerKey.toString('hex'),
169
164
  txValidity.toString('hex')
170
165
  );
171
166
 
172
- return CompleteStateMessageOperations.assembleRemoveWriterMessage(
173
- validatorPeer.wallet,
167
+ return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleRemoveWriterMessage(
174
168
  partial.address,
175
169
  b4a.from(partial.rao.tx, 'hex'),
176
170
  b4a.from(partial.rao.txv, 'hex'),
@@ -207,7 +201,7 @@ export async function assertAddWriterSuccessState(
207
201
  }
208
202
 
209
203
  const writerAddress = readerPeer.wallet.address;
210
- const writerAddressBuffer = addressUtils.addressToBuffer(writerAddress);
204
+ const writerAddressBuffer = addressUtils.addressToBuffer(writerAddress, config.addressPrefix);
211
205
  const writingKey = writerKeyBuffer ?? readerPeer.base.local.key;
212
206
  const writingKeyHex = writingKey.toString('hex');
213
207
 
@@ -588,7 +582,7 @@ async function assertWriterDowngradedEntry(
588
582
  'writer liquid balance matches expected amount after downgrade'
589
583
  );
590
584
  }
591
- const addressBuffer = addressUtils.addressToBuffer(address);
585
+ const addressBuffer = addressUtils.addressToBuffer(address, config.addressPrefix);
592
586
  const writerRegistryEntry = await base.view.get(
593
587
  EntryType.WRITER_ADDRESS + writingKey.toString('hex')
594
588
  );
@@ -654,7 +648,7 @@ async function withPeerEntryOverrideOnApply({
654
648
  const node = assertWritableNode(selectNode(context));
655
649
  const base = node.base;
656
650
  const targetAddress = targetPeer.wallet.address;
657
- const targetBuffer = addressUtils.addressToBuffer(targetAddress);
651
+ const targetBuffer = addressUtils.addressToBuffer(targetAddress, config.addressPrefix);
658
652
  const originalApply = base._handlers.apply;
659
653
 
660
654
  base._handlers.apply = async function patchedApply(nodes, view, baseCtx) {
@@ -12,6 +12,7 @@ import { initializeBalances, whitelistAddress } from '../common/commonScenarioHe
12
12
  import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
13
13
  import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
14
14
  import addressUtils from '../../../../../src/core/state/utils/address.js';
15
+ import { config } from '../../../../helpers/config.js';
15
16
 
16
17
  export default function addWriterValidatorRewardScenario() {
17
18
  test(
@@ -97,7 +98,7 @@ function assertPayloadValidator(t, payload, validatorAddress) {
97
98
  t.ok(decoded, 'validator reward payload decodes');
98
99
  const validatorBuffer = decoded?.rao?.va;
99
100
  t.ok(validatorBuffer, 'payload carries validator address');
100
- const expected = addressUtils.addressToBuffer(validatorAddress);
101
+ const expected = addressUtils.addressToBuffer(validatorAddress, config.addressPrefix);
101
102
  t.ok(
102
103
  b4a.equals(validatorBuffer, expected),
103
104
  'payload validator address matches processing writer'
@@ -2,7 +2,6 @@ import b4a from 'b4a';
2
2
  import adminEntryUtils from '../../../../../src/core/state/utils/adminEntry.js';
3
3
  import nodeEntryUtils, { setWritingKey } from '../../../../../src/core/state/utils/nodeEntry.js';
4
4
  import { EntryType } from '../../../../../src/utils/constants.js';
5
- import { blake3Hash } from '../../../../../src/utils/crypto.js';
6
5
  import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
7
6
  import { deriveIndexerSequenceState, eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
8
7
  import PartialStateMessageOperations from '../../../../../src/messages/partialStateMessages/PartialStateMessageOperations.js';
@@ -16,8 +15,8 @@ import { promotePeerToWriter } from '../addWriter/addWriterScenarioHelpers.js';
16
15
  import { buildAddIndexerPayload } from '../addIndexer/addIndexerScenarioHelpers.js';
17
16
  import { toBalance, BALANCE_FEE } from '../../../../../src/core/state/utils/balance.js';
18
17
  import lengthEntryUtils from '../../../../../src/core/state/utils/lengthEntry.js';
19
- import * as bufferUtils from '../../../../../src/utils/buffer.js';
20
18
  import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
19
+ import { config } from '../../../../helpers/config.js';
21
20
 
22
21
  export const DEFAULT_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('50'));
23
22
  export const TRANSFER_AMOUNT = bigIntTo16ByteBuffer(decimalStringToBigInt('1'));
@@ -91,21 +90,21 @@ export async function buildAdminRecoveryPayload(context) {
91
90
  const { adminPeer, validatorPeer1, newAdminWriterKey } = context.adminRecovery;
92
91
  const txValidity = await deriveIndexerSequenceState(validatorPeer1.base);
93
92
 
94
- const partial = await PartialStateMessageOperations.assembleAdminRecoveryMessage(
95
- adminPeer.wallet,
96
- b4a.toString(newAdminWriterKey, 'hex'),
97
- b4a.toString(txValidity, 'hex')
98
- );
93
+ const partial = await new PartialStateMessageOperations(adminPeer.wallet, config)
94
+ .assembleAdminRecoveryMessage(
95
+ b4a.toString(newAdminWriterKey, 'hex'),
96
+ b4a.toString(txValidity, 'hex')
97
+ );
99
98
 
100
- return CompleteStateMessageOperations.assembleAdminRecoveryMessage(
101
- validatorPeer1.wallet,
102
- partial.address,
103
- b4a.from(partial.rao.tx, 'hex'),
104
- b4a.from(partial.rao.txv, 'hex'),
105
- b4a.from(partial.rao.iw, 'hex'),
106
- b4a.from(partial.rao.in, 'hex'),
107
- b4a.from(partial.rao.is, 'hex')
108
- );
99
+ return new CompleteStateMessageOperations(validatorPeer1.wallet, config)
100
+ .assembleAdminRecoveryMessage(
101
+ partial.address,
102
+ b4a.from(partial.rao.tx, 'hex'),
103
+ b4a.from(partial.rao.txv, 'hex'),
104
+ b4a.from(partial.rao.iw, 'hex'),
105
+ b4a.from(partial.rao.in, 'hex'),
106
+ b4a.from(partial.rao.is, 'hex')
107
+ );
109
108
  }
110
109
 
111
110
  export async function buildAdminRecoveryPayloadWithTxValidity(context, mutatedTxValidity) {
@@ -114,21 +113,21 @@ export async function buildAdminRecoveryPayloadWithTxValidity(context, mutatedTx
114
113
  }
115
114
 
116
115
  const { adminPeer, validatorPeer1, newAdminWriterKey } = context.adminRecovery;
117
- const partial = await PartialStateMessageOperations.assembleAdminRecoveryMessage(
118
- adminPeer.wallet,
119
- b4a.toString(newAdminWriterKey, 'hex'),
120
- b4a.toString(mutatedTxValidity, 'hex')
121
- );
122
-
123
- return CompleteStateMessageOperations.assembleAdminRecoveryMessage(
124
- validatorPeer1.wallet,
125
- partial.address,
126
- b4a.from(partial.rao.tx, 'hex'),
127
- mutatedTxValidity,
128
- b4a.from(partial.rao.iw, 'hex'),
129
- b4a.from(partial.rao.in, 'hex'),
130
- b4a.from(partial.rao.is, 'hex')
131
- );
116
+ const partial = await new PartialStateMessageOperations(adminPeer.wallet, config)
117
+ .assembleAdminRecoveryMessage(
118
+ b4a.toString(newAdminWriterKey, 'hex'),
119
+ b4a.toString(mutatedTxValidity, 'hex')
120
+ );
121
+
122
+ return new CompleteStateMessageOperations(validatorPeer1.wallet, config)
123
+ .assembleAdminRecoveryMessage(
124
+ partial.address,
125
+ b4a.from(partial.rao.tx, 'hex'),
126
+ mutatedTxValidity,
127
+ b4a.from(partial.rao.iw, 'hex'),
128
+ b4a.from(partial.rao.in, 'hex'),
129
+ b4a.from(partial.rao.is, 'hex')
130
+ );
132
131
  }
133
132
 
134
133
  export async function applyAdminRecovery(context, payload) {
@@ -517,15 +516,13 @@ export async function applyTransferSeries(context, count = TRANSFER_COUNT) {
517
516
 
518
517
  async function buildSimpleTransferPayload({ requesterPeer, validatorPeer, recipientPeer, amount }) {
519
518
  const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
520
- const partial = await PartialStateMessageOperations.assembleTransferOperationMessage(
521
- requesterPeer.wallet,
519
+ const partial = await new PartialStateMessageOperations(requesterPeer.wallet, config).assembleTransferOperationMessage(
522
520
  recipientPeer.wallet.address,
523
521
  b4a.toString(amount, 'hex'),
524
522
  b4a.toString(txValidity, 'hex')
525
523
  );
526
524
 
527
- return CompleteStateMessageOperations.assembleCompleteTransferOperationMessage(
528
- validatorPeer.wallet,
525
+ return new CompleteStateMessageOperations(validatorPeer.wallet, config).assembleCompleteTransferOperationMessage(
529
526
  partial.address,
530
527
  b4a.from(partial.tro.tx, 'hex'),
531
528
  b4a.from(partial.tro.txv, 'hex'),
@@ -548,7 +545,7 @@ export async function assertAdminRecoverySuccessState(t, context, { viewBase } =
548
545
  const adminEntry = await base.view.get(EntryType.ADMIN);
549
546
  t.ok(adminEntry, 'admin entry exists');
550
547
 
551
- const decodedAdminEntry = adminEntryUtils.decode(adminEntry.value);
548
+ const decodedAdminEntry = adminEntryUtils.decode(adminEntry.value, config.addressPrefix);
552
549
  t.ok(decodedAdminEntry, 'admin entry decodes');
553
550
  t.ok(b4a.equals(decodedAdminEntry.wk, newAdminWriterKey), 'admin writer key updated');
554
551
 
@@ -597,7 +594,7 @@ export async function assertAdminRecoveryFailureState(t, context, { skipSync } =
597
594
  const adminEntry = await adminPeer.base.view.get(EntryType.ADMIN);
598
595
  t.ok(adminEntry, 'admin entry persists');
599
596
 
600
- const decodedAdminEntry = adminEntryUtils.decode(adminEntry.value);
597
+ const decodedAdminEntry = adminEntryUtils.decode(adminEntry.value, config.addressPrefix);
601
598
  t.ok(decodedAdminEntry, 'admin entry decodes');
602
599
  t.ok(b4a.equals(decodedAdminEntry.wk, oldAdminWriterKey), 'admin writer key remains unchanged');
603
600
 
@@ -767,15 +764,22 @@ export async function applyWithIndexerSequenceFailure(context, payload) {
767
764
  }
768
765
 
769
766
  export async function applyWithIndexerSequenceCorruption(context, payload) {
770
- const cryptoUtils = await import('../../../../../src/utils/crypto.js');
771
- const originalHash = cryptoUtils.blake3Hash;
772
- cryptoUtils.blake3Hash = async () => {
767
+ const { PeerWallet } = await import('trac-wallet');
768
+ const originalHash = PeerWallet.blake3;
769
+ const originalHashSafe = PeerWallet.blake3Safe;
770
+
771
+ PeerWallet.blake3 = async () => {
773
772
  throw new Error('forced indexer sequence state failure');
774
773
  };
774
+ PeerWallet.blake3Safe = async () => {
775
+ return b4a.alloc(0);
776
+ }
777
+
775
778
  try {
776
779
  await applyAdminRecoveryViaValidator(context, payload);
777
780
  } finally {
778
- cryptoUtils.blake3Hash = originalHash;
781
+ PeerWallet.blake3 = originalHash;
782
+ PeerWallet.blake3Safe = originalHashSafe;
779
783
  }
780
784
  }
781
785
 
@@ -4,17 +4,13 @@ import {
4
4
  setupAdminRecoveryScenario,
5
5
  buildAdminRecoveryPayload,
6
6
  assertAdminRecoveryFailureState,
7
- assertAdminRecoverySuccessState,
8
7
  applyAdminRecoveryViaValidator,
9
8
  buildAdminRecoveryPayloadWithTxValidity,
10
9
  applyWithMissingComponentBypass,
11
10
  applyWithRoleAccessBypass,
12
11
  applyWithRegisteredWriterKey,
13
12
  applyWithIndexerSequenceFailure,
14
- applyWithIndexerSequenceCorruption,
15
13
  applyWithAdminEntryMutation,
16
- applyWithAdminNodeEntryMutation,
17
- cloneIndexers,
18
14
  applyWithAdminEncodeFailure,
19
15
  applyWithAdminBalanceDecodeFailure,
20
16
  applyWithInvalidRequesterMessage,
@@ -51,7 +47,7 @@ import ValidatorConsistencyScenarioBase, {
51
47
  } from '../common/validatorConsistency/base/validatorConsistencyScenarioBase.js';
52
48
  import adminEntryUtils from '../../../../../src/core/state/utils/adminEntry.js';
53
49
  import addressUtils from '../../../../../src/core/state/utils/address.js';
54
- import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
50
+ import { config } from '../../../../helpers/config.js';
55
51
 
56
52
  adminRecoveryHappyPathScenario();
57
53
 
@@ -299,8 +295,8 @@ new OperationValidationScenarioBase({
299
295
  mutatePayload: (_t, payload) => payload,
300
296
  applyInvalidPayload: async (context, invalidPayload) => {
301
297
  const otherAddress = context.adminRecovery.validatorPeer2.wallet.address;
302
- const otherAddressBuffer = addressUtils.addressToBuffer(otherAddress);
303
- const mutatedEntry = adminEntryUtils.encode(otherAddressBuffer, context.adminRecovery.oldAdminWriterKey);
298
+ const otherAddressBuffer = addressUtils.addressToBuffer(otherAddress, config.addressPrefix);
299
+ const mutatedEntry = adminEntryUtils.encode(otherAddressBuffer, context.adminRecovery.oldAdminWriterKey, config.addressPrefix);
304
300
  return applyWithAdminEntryMutation(context, invalidPayload, () => ({ value: mutatedEntry }));
305
301
  },
306
302
  expectedLogs: ['Admin public key does not match the node public key.']