trac-msb 0.2.26 → 0.3.0-beta.2
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.
- package/SECURITY.md +2 -2
- package/cli/commandHandler.js +317 -20
- package/cli/handlers.js +9 -1
- package/cli/interactive.js +4 -3
- package/cli/tokenSupplyAudit.js +90 -0
- package/msb.mjs +1 -0
- package/package.json +15 -6
- package/rpc/create_server.js +12 -3
- package/rpc/handlers.js +121 -0
- package/rpc/routes/v1.js +12 -0
- package/src/codecs/apply/applyOperationCodec.js +334 -0
- package/src/codecs/apply/applyOperations.generated.cjs +6380 -0
- package/src/codecs/consensus/v1/consensusV1.generated.cjs +3508 -0
- package/src/codecs/consensus/v1/consensusV1OperationCodec.js +161 -0
- package/src/codecs/consensus/v1/vdfConfigCodec.js +83 -0
- package/src/{utils/protobuf → codecs/network/v1}/networkV1.generated.cjs +664 -393
- package/src/codecs/network/v1/networkV1OperationCodec.js +25 -0
- package/src/codecs/protobufRuntime.cjs +95 -0
- package/src/codecs/state/escrowEntryCodec.js +45 -0
- package/src/codecs/state/state.generated.cjs +659 -0
- package/src/config/args.js +0 -1
- package/src/config/config.js +41 -7
- package/src/config/env.js +33 -9
- package/src/core/consensus/epochAppenderSelection/EpochAppenderSelectionError.js +55 -0
- package/src/core/consensus/epochAppenderSelection/EpochAppenderSelectionOperations.js +118 -0
- package/src/core/consensus/epochAppenderSelection/EpochAppenderSelector.js +1042 -0
- package/src/core/consensus/epochAppenderSelection/createEpochAppenderSelector.js +23 -0
- package/src/core/consensus/epochAppenderSelection/epochAppenderSelectionLedgerReader.js +274 -0
- package/src/core/consensus/epochAppenderSelection/epochAppenderSelectionState.js +488 -0
- package/src/core/consensus/epochAppenderSelection/epochAppenderSelectionStorage.js +93 -0
- package/src/core/consensus/quorum.js +11 -0
- package/src/core/consensus/services/EpochCoordinationRound.js +839 -0
- package/src/core/consensus/services/EpochCoordinatorOperations.js +211 -0
- package/src/core/consensus/services/EpochCoordinatorService.js +335 -0
- package/src/core/consensus/services/EpochRoundListeners.js +116 -0
- package/src/core/consensus/services/EpochStateMachine.js +141 -0
- package/src/core/consensus/services/VDFBare.js +291 -0
- package/src/core/consensus/services/VDFNode.js +111 -0
- package/src/core/consensus/services/VDFProgressWatchdog.js +79 -0
- package/src/core/consensus/services/VDFService.js +87 -0
- package/src/core/consensus/services/VDFServiceManager.js +147 -0
- package/src/core/consensus/services/createVDFService.js +16 -0
- package/src/core/consensus/services/vdf-guardian.js +32 -0
- package/src/core/consensus/services/vdf-worker.js +90 -0
- package/src/core/network/Network.js +327 -238
- package/src/core/network/protocols/consensus/IndexerMessages.js +72 -0
- package/src/core/network/protocols/consensus/v1/ConsensusV1ConnectionPolicy.js +57 -0
- package/src/core/network/protocols/consensus/v1/ConsensusV1MessageRouter.js +147 -0
- package/src/core/network/protocols/consensus/v1/ConsensusV1Protocol.js +72 -0
- package/src/core/network/protocols/consensus/v1/IndexerPendingRequestService.js +108 -0
- package/src/core/network/protocols/consensus/v1/V1ConsensusProtocolError.js +29 -0
- package/src/core/network/protocols/consensus/v1/handlers/V1EpochAppendOperationHandler.js +68 -0
- package/src/core/network/protocols/consensus/v1/handlers/V1EpochProofProposalOperationHandler.js +226 -0
- package/src/core/network/protocols/consensus/v1/validators/ConsensusValidationSchema.js +192 -0
- package/src/core/network/protocols/consensus/v1/validators/V1BaseConsensusOperation.js +428 -0
- package/src/core/network/protocols/consensus/v1/validators/V1EpochAppendReply.js +47 -0
- package/src/core/network/protocols/consensus/v1/validators/V1EpochAppendRequest.js +17 -0
- package/src/core/network/protocols/consensus/v1/validators/V1EpochProofProposalApproval.js +116 -0
- package/src/core/network/protocols/consensus/v1/validators/V1EpochProofProposalRequest.js +152 -0
- package/src/core/network/protocols/consensus/v1/validators/consensusValidationSchemaHelpers.js +145 -0
- package/src/core/network/protocols/shared/ConnectionOperationHandler.js +27 -0
- package/src/core/network/protocols/{NetworkMessages.js → validators/ValidatorMessages.js} +24 -14
- package/src/core/network/protocols/{ProtocolSession.js → validators/ValidatorProtocolSession.js} +22 -25
- package/src/core/network/protocols/{legacy/NetworkMessageRouter.js → validators/legacy/ValidatorLegacyMessageRouter.js} +6 -6
- package/src/core/network/protocols/{LegacyProtocol.js → validators/legacy/ValidatorLegacyProtocol.js} +9 -7
- package/src/core/network/protocols/{legacy → validators/legacy}/handlers/BaseStateOperationHandler.js +1 -1
- package/src/core/network/protocols/{legacy → validators/legacy}/handlers/LegacyGetRequestHandler.js +5 -5
- package/src/core/network/protocols/{legacy → validators/legacy}/handlers/LegacyRoleOperationHandler.js +5 -5
- package/src/core/network/protocols/{legacy → validators/legacy}/handlers/LegacySubnetworkOperationHandler.js +5 -5
- package/src/core/network/protocols/{legacy → validators/legacy}/handlers/LegacyTransferOperationHandler.js +5 -5
- package/src/core/network/protocols/{ProtocolInterface.js → validators/shared/ValidatorProtocolInterface.js} +5 -5
- package/src/core/network/protocols/{shared → validators/shared}/validators/PartialBootstrapDeploymentValidator.js +1 -1
- package/src/core/network/protocols/validators/shared/validators/PartialHtlcValidator.js +325 -0
- package/src/core/network/protocols/{shared → validators/shared}/validators/PartialOperationValidator.js +44 -21
- package/src/core/network/protocols/{shared → validators/shared}/validators/PartialRoleAccessValidator.js +3 -3
- package/src/core/network/protocols/{shared → validators/shared}/validators/PartialTransactionValidator.js +3 -3
- package/src/core/network/protocols/{shared → validators/shared}/validators/PartialTransferValidator.js +4 -4
- package/src/core/network/protocols/{v1 → validators/v1}/V1ProtocolError.js +1 -1
- package/src/core/network/{services/PendingRequestService.js → protocols/validators/v1/ValidatorPendingRequestService.js} +19 -82
- package/src/core/network/protocols/{v1/NetworkMessageRouter.js → validators/v1/ValidatorV1MessageRouter.js} +9 -9
- package/src/core/network/protocols/{V1Protocol.js → validators/v1/ValidatorV1Protocol.js} +10 -8
- package/src/core/network/protocols/{connectionPolicies.js → validators/v1/connectionPolicies.js} +1 -1
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/V1BaseOperationHandler.js +6 -23
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/V1BroadcastTransactionOperationHandler.js +14 -9
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/V1LivenessOperationHandler.js +5 -4
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +3 -3
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +44 -1
- package/src/core/network/protocols/{v1 → validators/v1}/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +1 -1
- package/src/core/network/protocols/{v1 → validators/v1}/validators/V1BaseOperation.js +19 -15
- package/src/core/network/protocols/{v1 → validators/v1}/validators/V1BroadcastTransactionRequest.js +2 -2
- package/src/core/network/protocols/{v1 → validators/v1}/validators/V1BroadcastTransactionResponse.js +34 -18
- package/src/core/network/protocols/{v1 → validators/v1}/validators/V1ValidationSchema.js +3 -3
- package/src/core/network/services/IndexerConnectionManager.js +88 -0
- package/src/core/network/services/TransactionPoolService.js +11 -18
- package/src/core/network/services/TransactionRateLimiterService.js +1 -1
- package/src/core/network/services/ValidatorConnectionManager.js +163 -0
- package/src/core/network/services/{MessageOrchestrator.js → ValidatorMessageOrchestrator.js} +34 -42
- package/src/core/network/services/ValidatorObserverService.js +21 -36
- package/src/core/network/shared/BasePendingRequestService.js +67 -0
- package/src/core/network/shared/PeerConnectionManager.js +185 -0
- package/src/core/state/State.js +1803 -159
- package/src/core/state/StateEventQueue.js +69 -0
- package/src/core/state/utils/address.js +10 -6
- package/src/core/state/utils/epochProof.js +109 -0
- package/src/core/state/utils/escrowEntry.js +178 -0
- package/src/core/state/validators/StateValidationSchema.js +757 -0
- package/src/core/state/validators/stateValidationRules.js +312 -0
- package/src/index.js +280 -67
- package/src/messages/consensus/v1/ConsensusMessageBuilder.js +368 -0
- package/src/messages/consensus/v1/ConsensusMessageDirector.js +142 -0
- package/src/messages/consensus/v1/consensusMessageFactory.js +12 -0
- package/src/messages/consensus/v1/epochAppendMessage.js +58 -0
- package/src/messages/network/v1/NetworkMessageBuilder.js +15 -7
- package/src/messages/state/ApplyStateMessageBuilder.js +499 -13
- package/src/messages/state/ApplyStateMessageDirector.js +261 -2
- package/src/utils/StateMachine.js +125 -0
- package/src/utils/applyOperations.js +45 -2
- package/src/utils/buffer.js +239 -59
- package/src/utils/consensusConfig.js +76 -0
- package/src/utils/constants.js +174 -73
- package/src/utils/helpers.js +0 -25
- package/src/utils/htlcLock.js +122 -0
- package/src/utils/logger.js +10 -4
- package/src/utils/migrationUtils.js +2 -1
- package/src/utils/normalizers.js +113 -0
- package/src/utils/scheduler/SchedulableService.js +107 -0
- package/src/utils/{Scheduler.js → scheduler/Scheduler.js} +56 -17
- package/src/core/network/services/ConnectionManager.js +0 -406
- package/src/utils/check.js +0 -525
- package/src/utils/protobuf/applyOperations.cjs +0 -1373
- package/src/utils/protobuf/operationHelpers.js +0 -81
- /package/src/core/network/protocols/{legacy → validators/legacy}/handlers/LegacyResponseHandler.js +0 -0
- /package/src/core/network/protocols/{legacy → validators/legacy}/validators/ValidatorResponse.js +0 -0
- /package/src/core/network/protocols/{legacy → validators/legacy}/validators/base/BaseResponse.js +0 -0
- /package/src/core/network/protocols/{v1 → validators/v1}/validators/V1LivenessRequest.js +0 -0
- /package/src/core/network/protocols/{v1 → validators/v1}/validators/V1LivenessResponse.js +0 -0
package/src/utils/check.js
DELETED
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
import Validator from 'fastest-validator';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
OperationType,
|
|
6
|
-
WRITER_BYTE_LENGTH,
|
|
7
|
-
NONCE_BYTE_LENGTH,
|
|
8
|
-
SIGNATURE_BYTE_LENGTH,
|
|
9
|
-
HASH_BYTE_LENGTH,
|
|
10
|
-
BOOTSTRAP_BYTE_LENGTH,
|
|
11
|
-
CHANNEL_BYTE_LENGTH,
|
|
12
|
-
AMOUNT_BYTE_LENGTH,
|
|
13
|
-
} from './constants.js';
|
|
14
|
-
//TODO: ATTENTION - CURRENT IMPLEMENTATION UTILIZES `custom` FOR MULTIPLE TIMES IN MANY SCHEMAS. IT SHOULD BE CLEANED UP
|
|
15
|
-
// TO UTILIZE ONLY ONE FUNCTION COMMON FOR ALL THE SCHEMAS. CREATE A TICKED P2/P3.
|
|
16
|
-
|
|
17
|
-
class Check {
|
|
18
|
-
#validator;
|
|
19
|
-
#validateCoreAdminOperationSchema
|
|
20
|
-
#validateAdminControlOperationSchema
|
|
21
|
-
#validateRoleAccessOperationSchema
|
|
22
|
-
#validateBootstrapDeploymentSchema;
|
|
23
|
-
#validateTransactionOperationSchema
|
|
24
|
-
#validateTransferOperationSchema
|
|
25
|
-
#validateBalanceInitializationSchema
|
|
26
|
-
#config
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @param {Config} config
|
|
30
|
-
**/
|
|
31
|
-
constructor(config) {
|
|
32
|
-
this.#config = config
|
|
33
|
-
|
|
34
|
-
this.#validator = new Validator({
|
|
35
|
-
useNewCustomCheckerFunction: true,
|
|
36
|
-
messages: {
|
|
37
|
-
buffer: "The '{field}' field must be a Buffer! Actual: {actual}",
|
|
38
|
-
bufferLength: "The '{field}' field must be a Buffer with length {expected}! Actual: {actual}",
|
|
39
|
-
nonZeroBuffer: "The '{field}' field must not be an empty or zero-filled Buffer!",
|
|
40
|
-
emptyBuffer: "The '{field}' field must not be an empty Buffer!",
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
const isBuffer = b4a.isBuffer;
|
|
44
|
-
this.#validator.add("buffer", function ({ schema, messages }, _path, _context) {
|
|
45
|
-
return {
|
|
46
|
-
source:
|
|
47
|
-
`
|
|
48
|
-
if (!${isBuffer}(value)) {
|
|
49
|
-
${this.makeError({ type: "buffer", actual: "value", messages })}
|
|
50
|
-
}
|
|
51
|
-
if (value.length !== ${schema.length}) {
|
|
52
|
-
${this.makeError({
|
|
53
|
-
type: "bufferLength",
|
|
54
|
-
expected: schema.length,
|
|
55
|
-
actual: "value.length",
|
|
56
|
-
messages
|
|
57
|
-
})}
|
|
58
|
-
}
|
|
59
|
-
let isEmpty = true;
|
|
60
|
-
for (let i = 0; i < value.length; i++) {
|
|
61
|
-
if (value[i] !== 0) {
|
|
62
|
-
isEmpty = false;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (isEmpty) {
|
|
67
|
-
${this.makeError({ type: "emptyBuffer", actual: "value", messages })}
|
|
68
|
-
}
|
|
69
|
-
return value;
|
|
70
|
-
`
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
this.#validator.add("buffer_amount", function ({ schema, messages }, _path, _context) {
|
|
75
|
-
return {
|
|
76
|
-
source:
|
|
77
|
-
`
|
|
78
|
-
if (!${isBuffer}(value)) {
|
|
79
|
-
${this.makeError({ type: "buffer", actual: "value", messages })}
|
|
80
|
-
}
|
|
81
|
-
if (value.length !== ${schema.length}) {
|
|
82
|
-
${this.makeError({
|
|
83
|
-
type: "bufferLength",
|
|
84
|
-
expected: schema.length,
|
|
85
|
-
actual: "value.length",
|
|
86
|
-
messages
|
|
87
|
-
})}
|
|
88
|
-
}
|
|
89
|
-
return value;
|
|
90
|
-
`
|
|
91
|
-
};
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.#validateCoreAdminOperationSchema = this.#compileCoreAdminOperationSchema();
|
|
96
|
-
this.#validateAdminControlOperationSchema = this.#compileAdminControlOperationSchema();
|
|
97
|
-
this.#validateRoleAccessOperationSchema = this.#compileRoleAccessOperationSchema();
|
|
98
|
-
this.#validateBootstrapDeploymentSchema = this.#compileBootstrapDeploymentSchema();
|
|
99
|
-
this.#validateTransactionOperationSchema = this.#compileTransactionOperationSchema();
|
|
100
|
-
this.#validateTransferOperationSchema = this.#compileTransferOperationSchema();
|
|
101
|
-
this.#validateBalanceInitializationSchema = this.#compileBalanceInitializationSchema();
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Complete by default - no writer needed
|
|
106
|
-
#compileCoreAdminOperationSchema() {
|
|
107
|
-
const addressLength = this.#config.addressLength
|
|
108
|
-
const schema = {
|
|
109
|
-
$$strict: true,
|
|
110
|
-
type: {
|
|
111
|
-
type: 'number',
|
|
112
|
-
required: true,
|
|
113
|
-
custom: (value, errors) => {
|
|
114
|
-
const allowedTypes = [
|
|
115
|
-
OperationType.ADD_ADMIN,
|
|
116
|
-
OperationType.DISABLE_INITIALIZATION,
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
if (!allowedTypes.includes(value)) {
|
|
120
|
-
errors.push({
|
|
121
|
-
type: 'valueNotAllowed',
|
|
122
|
-
actual: value,
|
|
123
|
-
expected: allowedTypes,
|
|
124
|
-
field: 'type',
|
|
125
|
-
message: `Operation type must be one of: ${allowedTypes.join(', ')}`
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
return value;
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
address: {type: 'buffer', length: addressLength, required: true}, // invoker adddress (admin)
|
|
132
|
-
cao: {
|
|
133
|
-
strict: true,
|
|
134
|
-
type: 'object',
|
|
135
|
-
props: {
|
|
136
|
-
tx: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx hash
|
|
137
|
-
txv: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx validity
|
|
138
|
-
iw: { type: 'buffer', length: WRITER_BYTE_LENGTH, required: true }, // writer key of the admin
|
|
139
|
-
in: { type: 'buffer', length: NONCE_BYTE_LENGTH, required: true }, // nonce
|
|
140
|
-
is: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, required: true }, // signature
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
return this.#validator.compile(schema);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
validateCoreAdminOperation(operation) {
|
|
148
|
-
return this.#validateCoreAdminOperationSchema(operation) === true;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
#compileBalanceInitializationSchema() {
|
|
152
|
-
const schema = {
|
|
153
|
-
$$strict: true,
|
|
154
|
-
type: {
|
|
155
|
-
type: 'number',
|
|
156
|
-
required: true,
|
|
157
|
-
custom: (value, errors) => {
|
|
158
|
-
if (value !== OperationType.BALANCE_INITIALIZATION) {
|
|
159
|
-
errors.push({
|
|
160
|
-
type: 'valueNotAllowed',
|
|
161
|
-
actual: value,
|
|
162
|
-
expected: OperationType.BALANCE_INITIALIZATION,
|
|
163
|
-
field: 'type',
|
|
164
|
-
message: `Operation type must be ${OperationType.BALANCE_INITIALIZATION} (BALANCE_INITIALIZATION)`
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
return value;
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
address: { type: 'buffer', length: this.#config.addressLength, required: true },
|
|
171
|
-
bio: {
|
|
172
|
-
strict: true,
|
|
173
|
-
type: 'object',
|
|
174
|
-
props: {
|
|
175
|
-
tx: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx hash
|
|
176
|
-
txv: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx validity
|
|
177
|
-
ia: { type: 'buffer', length: this.#config.addressLength, required: true }, // selected address to specific operation.
|
|
178
|
-
am: { type: 'buffer', length: AMOUNT_BYTE_LENGTH, required: true }, // amount to transfer
|
|
179
|
-
in: { type: 'buffer', length: NONCE_BYTE_LENGTH, required: true }, // nonce of the invoker
|
|
180
|
-
is: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, required: true }, // signature of the invoker
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
return this.#validator.compile(schema);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
validateBalanceInitialization(operation) {
|
|
188
|
-
return this.#validateBalanceInitializationSchema(operation) === true;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Complete by default - no writer needed
|
|
192
|
-
#compileAdminControlOperationSchema() {
|
|
193
|
-
const schema = {
|
|
194
|
-
$$strict: true,
|
|
195
|
-
type: {
|
|
196
|
-
type: 'number',
|
|
197
|
-
required: true,
|
|
198
|
-
custom: (value, errors) => {
|
|
199
|
-
const allowedTypes = [
|
|
200
|
-
OperationType.APPEND_WHITELIST,
|
|
201
|
-
OperationType.ADD_INDEXER,
|
|
202
|
-
OperationType.REMOVE_INDEXER,
|
|
203
|
-
OperationType.BAN_VALIDATOR
|
|
204
|
-
];
|
|
205
|
-
|
|
206
|
-
if (!allowedTypes.includes(value)) {
|
|
207
|
-
errors.push({
|
|
208
|
-
type: 'valueNotAllowed',
|
|
209
|
-
actual: value,
|
|
210
|
-
expected: allowedTypes,
|
|
211
|
-
field: 'type',
|
|
212
|
-
message: `Operation type must be one of: ${allowedTypes.join(', ')}`
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
return value;
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
address: {type: 'buffer', length: this.#config.addressLength, required: true}, // invoker adddress (admin)
|
|
219
|
-
aco: {
|
|
220
|
-
strict: true,
|
|
221
|
-
type: 'object',
|
|
222
|
-
props: {
|
|
223
|
-
tx: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx hash
|
|
224
|
-
txv: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx validity
|
|
225
|
-
ia: { type: 'buffer', length: this.#config.addressLength, required: true }, // incoming address - selected address for specific operation
|
|
226
|
-
in: { type: 'buffer', length: NONCE_BYTE_LENGTH, required: true }, // nonce
|
|
227
|
-
is: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, required: true }, // signature
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
return this.#validator.compile(schema);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
validateAdminControlOperation(operation) {
|
|
235
|
-
return this.#validateAdminControlOperationSchema(operation) === true;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
#compileRoleAccessOperationSchema() {
|
|
239
|
-
const schema = {
|
|
240
|
-
$$strict: true,
|
|
241
|
-
type: {
|
|
242
|
-
type: 'number',
|
|
243
|
-
required: true,
|
|
244
|
-
custom: (value, errors) => {
|
|
245
|
-
const allowedTypes = [
|
|
246
|
-
OperationType.ADD_WRITER,
|
|
247
|
-
OperationType.REMOVE_WRITER,
|
|
248
|
-
OperationType.ADMIN_RECOVERY
|
|
249
|
-
];
|
|
250
|
-
|
|
251
|
-
if (!allowedTypes.includes(value)) {
|
|
252
|
-
errors.push({
|
|
253
|
-
type: 'valueNotAllowed',
|
|
254
|
-
actual: value,
|
|
255
|
-
expected: allowedTypes,
|
|
256
|
-
field: 'type',
|
|
257
|
-
message: `Operation type must be one of: ${allowedTypes.join(', ')}`
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
return value;
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
address: {type: 'buffer', length: this.#config.addressLength, required: true},
|
|
264
|
-
rao: {
|
|
265
|
-
strict: true,
|
|
266
|
-
type: 'object',
|
|
267
|
-
props: {
|
|
268
|
-
tx: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx hash
|
|
269
|
-
txv: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx validity
|
|
270
|
-
iw: { type: 'buffer', length: WRITER_BYTE_LENGTH, required: true }, // writing key of the invoker
|
|
271
|
-
in: { type: 'buffer', length: NONCE_BYTE_LENGTH, required: true }, // nonce of the invoker
|
|
272
|
-
is: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, required: true }, // signature
|
|
273
|
-
va: { type: 'buffer', length: this.#config.addressLength, optional: true },
|
|
274
|
-
vn: { type: 'buffer', length: NONCE_BYTE_LENGTH, optional: true },
|
|
275
|
-
vs: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, optional: true }
|
|
276
|
-
|
|
277
|
-
},
|
|
278
|
-
custom: (value, errors) => {
|
|
279
|
-
if (!value || typeof value !== 'object') return value;
|
|
280
|
-
const { vn, vs, va } = value;
|
|
281
|
-
const vnPresent = vn !== undefined
|
|
282
|
-
const vsPresent = vs !== undefined
|
|
283
|
-
const vaPresent = va !== undefined
|
|
284
|
-
|
|
285
|
-
const fieldsPresent = [vnPresent, vsPresent, vaPresent].filter(Boolean).length;
|
|
286
|
-
|
|
287
|
-
if (fieldsPresent > 0 && fieldsPresent < 3) {
|
|
288
|
-
errors.push({
|
|
289
|
-
type: 'conditionalDependency',
|
|
290
|
-
field: 'bdo',
|
|
291
|
-
message: 'Fields "vn", "vs", and "va" must all be present if any one is provided'
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
if (vn === null || vs === null || va === null) {
|
|
295
|
-
errors.push({
|
|
296
|
-
type: 'buffer',
|
|
297
|
-
field: 'bdo',
|
|
298
|
-
message: 'Validator fields cannot be null, must be a Buffer or undefined'
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return value;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
return this.#validator.compile(schema);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
validateRoleAccessOperation(operation) {
|
|
310
|
-
return this.#validateRoleAccessOperationSchema(operation) === true;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
#compileTransactionOperationSchema() {
|
|
314
|
-
const schema = {
|
|
315
|
-
$$strict: true,
|
|
316
|
-
type: {
|
|
317
|
-
type: 'number',
|
|
318
|
-
required: true,
|
|
319
|
-
custom: (value, errors) => { // more secure than enum
|
|
320
|
-
if (value !== OperationType.TX) {
|
|
321
|
-
errors.push({
|
|
322
|
-
type: 'valueNotAllowed',
|
|
323
|
-
actual: value,
|
|
324
|
-
expected: OperationType.TX,
|
|
325
|
-
field: 'type',
|
|
326
|
-
message: `Operation type must be ${OperationType.TX} (TX)`
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
return value;
|
|
330
|
-
}
|
|
331
|
-
},
|
|
332
|
-
address: {type: 'buffer', length: this.#config.addressLength, required: true}, // invoker address
|
|
333
|
-
txo: {
|
|
334
|
-
strict: true,
|
|
335
|
-
type: 'object',
|
|
336
|
-
props: {
|
|
337
|
-
tx: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx hash
|
|
338
|
-
txv: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx validity
|
|
339
|
-
iw: { type: 'buffer', length: WRITER_BYTE_LENGTH, required: true }, // Writing key of the requesting node (external subnetwork)
|
|
340
|
-
ch: { type: 'buffer', length: NONCE_BYTE_LENGTH, required: true }, // Content hash (hash of the transaction's data)
|
|
341
|
-
bs: { type: 'buffer', length: BOOTSTRAP_BYTE_LENGTH, required: true }, // External bootstrap contract
|
|
342
|
-
mbs: { type: 'buffer', length: BOOTSTRAP_BYTE_LENGTH, required: true }, // MSB bootstrap key
|
|
343
|
-
in: { type: 'buffer', length: NONCE_BYTE_LENGTH, required: true }, // Nonce of the requesting node
|
|
344
|
-
is: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, required: true }, // Requester's signature
|
|
345
|
-
va: { type: 'buffer', length: this.#config.addressLength, optional: true }, //validator address
|
|
346
|
-
vn: { type: 'buffer', length: NONCE_BYTE_LENGTH, optional: true }, //validator nonce
|
|
347
|
-
vs: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, optional: true }, //validator signature
|
|
348
|
-
},
|
|
349
|
-
custom: (value, errors) => {
|
|
350
|
-
if (!value || typeof value !== 'object') return value;
|
|
351
|
-
const { vn, vs, va } = value;
|
|
352
|
-
const vnPresent = vn !== undefined;
|
|
353
|
-
const vsPresent = vs !== undefined;
|
|
354
|
-
const vaPresent = va !== undefined;
|
|
355
|
-
|
|
356
|
-
const fieldsPresent = [vnPresent, vsPresent, vaPresent].filter(Boolean).length;
|
|
357
|
-
|
|
358
|
-
if (fieldsPresent > 0 && fieldsPresent < 3) {
|
|
359
|
-
errors.push({
|
|
360
|
-
type: 'conditionalDependency',
|
|
361
|
-
field: 'bdo',
|
|
362
|
-
message: 'Fields "vn", "vs", and "va" must all be present if any one is provided'
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
if (vn === null || vs === null || va === null) {
|
|
366
|
-
errors.push({
|
|
367
|
-
type: 'buffer',
|
|
368
|
-
field: 'bdo',
|
|
369
|
-
message: 'Validator fields cannot be null, must be a Buffer or undefined'
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
return value;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
return this.#validator.compile(schema);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
validateTransactionOperation(op) {
|
|
381
|
-
return this.#validateTransactionOperationSchema(op) === true;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
#compileBootstrapDeploymentSchema() {
|
|
385
|
-
const schema = {
|
|
386
|
-
$$strict: true,
|
|
387
|
-
type: {
|
|
388
|
-
type: 'number',
|
|
389
|
-
required: true,
|
|
390
|
-
custom: (value, errors) => {
|
|
391
|
-
if (value !== OperationType.BOOTSTRAP_DEPLOYMENT) {
|
|
392
|
-
errors.push({
|
|
393
|
-
type: 'valueNotAllowed',
|
|
394
|
-
actual: value,
|
|
395
|
-
expected: OperationType.BOOTSTRAP_DEPLOYMENT,
|
|
396
|
-
field: 'type',
|
|
397
|
-
message: `Operation type must be ${OperationType.BOOTSTRAP_DEPLOYMENT} (BOOTSTRAP_DEPLOYMENT)`
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
return value;
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
address: {type: 'buffer', length: this.#config.addressLength, required: true},
|
|
404
|
-
bdo: {
|
|
405
|
-
|
|
406
|
-
strict: true,
|
|
407
|
-
type: "object",
|
|
408
|
-
props: {
|
|
409
|
-
tx: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true },
|
|
410
|
-
txv: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true },
|
|
411
|
-
bs: { type: 'buffer', length: BOOTSTRAP_BYTE_LENGTH, required: true },
|
|
412
|
-
ic: { type: 'buffer', length: CHANNEL_BYTE_LENGTH, required: true },
|
|
413
|
-
in: { type: 'buffer', length: NONCE_BYTE_LENGTH, required: true },
|
|
414
|
-
is: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, required: true },
|
|
415
|
-
va: { type: 'buffer', length: this.#config.addressLength, optional: true },
|
|
416
|
-
vn: { type: 'buffer', length: NONCE_BYTE_LENGTH, optional: true },
|
|
417
|
-
vs: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, optional: true },
|
|
418
|
-
},
|
|
419
|
-
custom: (value, errors) => {
|
|
420
|
-
if (!value || typeof value !== 'object') return value;
|
|
421
|
-
const { vn, vs, va } = value;
|
|
422
|
-
const vnPresent = vn !== undefined
|
|
423
|
-
const vsPresent = vs !== undefined
|
|
424
|
-
const vaPresent = va !== undefined
|
|
425
|
-
|
|
426
|
-
const fieldsPresent = [vnPresent, vsPresent, vaPresent].filter(Boolean).length;
|
|
427
|
-
|
|
428
|
-
if (fieldsPresent > 0 && fieldsPresent < 3) {
|
|
429
|
-
errors.push({
|
|
430
|
-
type: 'conditionalDependency',
|
|
431
|
-
field: 'bdo',
|
|
432
|
-
message: 'Fields "vn", "vs", and "va" must all be present if any one is provided'
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
if (vn === null || vs === null || va === null) {
|
|
436
|
-
errors.push({
|
|
437
|
-
type: 'buffer',
|
|
438
|
-
field: 'bdo',
|
|
439
|
-
message: 'Validator fields cannot be null, must be a Buffer or undefined'
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
return value;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
return this.#validator.compile(schema);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
validateBootstrapDeploymentOperation(op) {
|
|
451
|
-
return this.#validateBootstrapDeploymentSchema(op) === true;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
#compileTransferOperationSchema() {
|
|
455
|
-
const schema = {
|
|
456
|
-
$$strict: true,
|
|
457
|
-
type: {
|
|
458
|
-
type: 'number',
|
|
459
|
-
required: true,
|
|
460
|
-
custom: (value, errors) => {
|
|
461
|
-
if (value !== OperationType.TRANSFER) {
|
|
462
|
-
errors.push({
|
|
463
|
-
type: 'valueNotAllowed',
|
|
464
|
-
actual: value,
|
|
465
|
-
expected: OperationType.TRANSFER,
|
|
466
|
-
field: 'type',
|
|
467
|
-
message: `Operation type must be ${OperationType.TRANSFER} (TRANSFER)`
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
return value;
|
|
471
|
-
}
|
|
472
|
-
},
|
|
473
|
-
address: {type: 'buffer', length: this.#config.addressLength, required: true},
|
|
474
|
-
tro: {
|
|
475
|
-
strict: true,
|
|
476
|
-
type: 'object',
|
|
477
|
-
props: {
|
|
478
|
-
tx: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx hash
|
|
479
|
-
txv: { type: 'buffer', length: HASH_BYTE_LENGTH, required: true }, // tx validity
|
|
480
|
-
to: { type: 'buffer', length: this.#config.addressLength, required: true }, // recipient address
|
|
481
|
-
am: { type: 'buffer_amount', length: AMOUNT_BYTE_LENGTH, required: true }, // amount to transfer
|
|
482
|
-
in: { type: 'buffer', length: NONCE_BYTE_LENGTH, required: true }, // nonce of the invoker
|
|
483
|
-
is: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, required: true }, // signature of the invoker
|
|
484
|
-
va: { type: 'buffer', length: this.#config.addressLength, optional: true }, // validator address
|
|
485
|
-
vn: { type: 'buffer', length: NONCE_BYTE_LENGTH, optional: true }, // validator nonce
|
|
486
|
-
vs: { type: 'buffer', length: SIGNATURE_BYTE_LENGTH, optional: true } // validator signature
|
|
487
|
-
|
|
488
|
-
},
|
|
489
|
-
custom: (value, errors) => {
|
|
490
|
-
if (!value || typeof value !== 'object') return value;
|
|
491
|
-
const { vn, vs, va } = value;
|
|
492
|
-
const vnPresent = vn !== undefined
|
|
493
|
-
const vsPresent = vs !== undefined
|
|
494
|
-
const vaPresent = va !== undefined
|
|
495
|
-
|
|
496
|
-
const fieldsPresent = [vnPresent, vsPresent, vaPresent].filter(Boolean).length;
|
|
497
|
-
|
|
498
|
-
if (fieldsPresent > 0 && fieldsPresent < 3) {
|
|
499
|
-
errors.push({
|
|
500
|
-
type: 'conditionalDependency',
|
|
501
|
-
field: 'tro',
|
|
502
|
-
message: 'Fields "vn", "vs", and "va" must all be present if any one is provided'
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
if (vn === null || vs === null || va === null) {
|
|
506
|
-
errors.push({
|
|
507
|
-
type: 'buffer',
|
|
508
|
-
field: 'tro',
|
|
509
|
-
message: 'Validator fields cannot be null, must be a Buffer or undefined'
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
return value;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
return this.#validator.compile(schema);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
validateTransferOperation(op) {
|
|
521
|
-
return this.#validateTransferOperationSchema(op) === true;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
export default Check;
|