@xyo-network/chain-validation 1.5.30 → 1.5.31
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/dist/neutral/index.mjs +126 -76
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/block/validateBlock.d.ts.map +1 -1
- package/dist/types/block/validators/AllowedPayloadSchemas.d.ts.map +1 -1
- package/dist/types/block/validators/Fields.d.ts +1 -1
- package/dist/types/block/validators/Fields.d.ts.map +1 -1
- package/dist/types/block/validators/JsonSchema.d.ts +1 -1
- package/dist/types/block/validators/JsonSchema.d.ts.map +1 -1
- package/dist/types/block/validators/PreviousHash.d.ts.map +1 -1
- package/dist/types/boundwitness/validators/BoundWitnessReferences.d.ts.map +1 -1
- package/dist/types/boundwitness/validators/BoundWitnessSignatures.d.ts.map +1 -1
- package/dist/types/elevatedPayload/payloads/validateSchemaInBlock.d.ts.map +1 -1
- package/dist/types/elevatedPayload/payloads/validateTransferInBlock.d.ts +1 -1
- package/dist/types/elevatedPayload/payloads/validateTransferInBlock.d.ts.map +1 -1
- package/dist/types/elevatedPayload/validatePayloadInBlock.d.ts.map +1 -1
- package/dist/types/hydratedBlock/validateHydratedBlock.d.ts +2 -2
- package/dist/types/hydratedBlock/validateHydratedBlock.d.ts.map +1 -1
- package/dist/types/hydratedBlock/validators/Payloads.d.ts +2 -2
- package/dist/types/hydratedBlock/validators/Payloads.d.ts.map +1 -1
- package/dist/types/hydratedBlockState/validateHydratedBlockState.d.ts.map +1 -1
- package/dist/types/hydratedBlockState/validators/RequiredBalance.d.ts.map +1 -1
- package/dist/types/transaction/validateTransaction.d.ts +2 -2
- package/dist/types/transaction/validateTransaction.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionDurationValidator.d.ts +2 -2
- package/dist/types/transaction/validators/TransactionDurationValidator.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionElevationValidator.d.ts +2 -2
- package/dist/types/transaction/validators/TransactionElevationValidator.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionFromValidator.d.ts +2 -2
- package/dist/types/transaction/validators/TransactionFromValidator.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionGasValidator.d.ts +2 -2
- package/dist/types/transaction/validators/TransactionGasValidator.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionJsonSchemaValidator.d.ts +2 -2
- package/dist/types/transaction/validators/TransactionJsonSchemaValidator.d.ts.map +1 -1
- package/dist/types/transaction/validators/TransactionProtocolValidator.d.ts +2 -2
- package/dist/types/transaction/validators/TransactionProtocolValidator.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/block/validateBlock.ts +3 -2
- package/src/block/validators/AllowedPayloadSchemas.ts +4 -4
- package/src/block/validators/Fields.ts +7 -5
- package/src/block/validators/JsonSchema.ts +7 -6
- package/src/block/validators/PreviousHash.ts +6 -5
- package/src/boundwitness/validators/BoundWitnessReferences.ts +9 -8
- package/src/boundwitness/validators/BoundWitnessSignatures.ts +5 -4
- package/src/elevatedPayload/payloads/validateChainStakeIntentInBlock.ts +4 -4
- package/src/elevatedPayload/payloads/validateHashInBlock.ts +4 -4
- package/src/elevatedPayload/payloads/validateSchemaInBlock.ts +3 -2
- package/src/elevatedPayload/payloads/validateTransferInBlock.ts +6 -4
- package/src/elevatedPayload/validatePayloadInBlock.ts +6 -5
- package/src/hydratedBlock/validateHydratedBlock.ts +7 -6
- package/src/hydratedBlock/validators/Payloads.ts +7 -6
- package/src/hydratedBlockState/validateHydratedBlockState.ts +7 -2
- package/src/hydratedBlockState/validators/RequiredBalance.ts +13 -4
- package/src/transaction/validateTransaction.ts +5 -5
- package/src/transaction/validators/TransactionDurationValidator.ts +12 -11
- package/src/transaction/validators/TransactionElevationValidator.ts +8 -8
- package/src/transaction/validators/TransactionFromValidator.ts +10 -9
- package/src/transaction/validators/TransactionGasValidator.ts +42 -18
- package/src/transaction/validators/TransactionJsonSchemaValidator.ts +9 -9
- package/src/transaction/validators/TransactionProtocolValidator.ts +9 -8
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
+
// src/block/validateBlock.ts
|
|
5
|
+
import { BlockValidationError as BlockValidationError5 } from "@xyo-network/xl1-protocol";
|
|
6
|
+
|
|
4
7
|
// src/boundwitness/validators/BoundWitnessReferences.ts
|
|
5
8
|
import { isAnyPayload } from "@xyo-network/payload-model";
|
|
9
|
+
import { HydratedBoundWitnessValidationError } from "@xyo-network/xl1-protocol";
|
|
6
10
|
function getPayloadsFromPayloadArray(payloads, hashes) {
|
|
7
11
|
return hashes.map((hash) => payloads.find((payload) => payload._hash === hash || payload._dataHash === hash));
|
|
8
12
|
}
|
|
@@ -12,7 +16,10 @@ var BoundWitnessReferencesValidator = /* @__PURE__ */ __name((allowedSchemas) =>
|
|
|
12
16
|
try {
|
|
13
17
|
const payloads = getPayloadsFromPayloadArray(payloadSet, bw.payload_hashes);
|
|
14
18
|
if (payloads.length !== bw.payload_hashes.length) {
|
|
15
|
-
errors.push(new
|
|
19
|
+
errors.push(new HydratedBoundWitnessValidationError([
|
|
20
|
+
bw,
|
|
21
|
+
payloadSet
|
|
22
|
+
], "unable to locate payloads"));
|
|
16
23
|
}
|
|
17
24
|
for (let payload of payloads) {
|
|
18
25
|
if (isAnyPayload(payload)) {
|
|
@@ -20,21 +27,36 @@ var BoundWitnessReferencesValidator = /* @__PURE__ */ __name((allowedSchemas) =>
|
|
|
20
27
|
const payloadDataHashIndex = bw.payload_hashes.indexOf(payload._dataHash);
|
|
21
28
|
const payloadIndex = Math.max(payloadHashIndex, payloadDataHashIndex);
|
|
22
29
|
if (payloadIndex === -1) {
|
|
23
|
-
errors.push(new
|
|
30
|
+
errors.push(new HydratedBoundWitnessValidationError([
|
|
31
|
+
bw,
|
|
32
|
+
payloadSet
|
|
33
|
+
], "payload hash not found"));
|
|
24
34
|
}
|
|
25
35
|
const declaredSchema = bw.payload_schemas[payloadIndex];
|
|
26
36
|
if (declaredSchema !== payload.schema) {
|
|
27
|
-
errors.push(new
|
|
37
|
+
errors.push(new HydratedBoundWitnessValidationError([
|
|
38
|
+
bw,
|
|
39
|
+
payloadSet
|
|
40
|
+
], "mismatched schema"));
|
|
28
41
|
}
|
|
29
42
|
if (allowedSchemas && !allowedSchemas.includes(payload.schema)) {
|
|
30
|
-
errors.push(new
|
|
43
|
+
errors.push(new HydratedBoundWitnessValidationError([
|
|
44
|
+
bw,
|
|
45
|
+
payloadSet
|
|
46
|
+
], `disallowed schema [${payload.schema}]`));
|
|
31
47
|
}
|
|
32
48
|
} else {
|
|
33
|
-
errors.push(new
|
|
49
|
+
errors.push(new HydratedBoundWitnessValidationError([
|
|
50
|
+
bw,
|
|
51
|
+
payloadSet
|
|
52
|
+
], "invalid payload"));
|
|
34
53
|
}
|
|
35
54
|
}
|
|
36
55
|
} catch (ex) {
|
|
37
|
-
errors.push(new
|
|
56
|
+
errors.push(new HydratedBoundWitnessValidationError([
|
|
57
|
+
bw,
|
|
58
|
+
payloadSet
|
|
59
|
+
], "validation excepted"), ex);
|
|
38
60
|
}
|
|
39
61
|
return errors;
|
|
40
62
|
}, "BoundWitnessReferencesValidator");
|
|
@@ -43,6 +65,7 @@ var BoundWitnessReferencesValidator = /* @__PURE__ */ __name((allowedSchemas) =>
|
|
|
43
65
|
import { toArrayBuffer } from "@xylabs/arraybuffer";
|
|
44
66
|
import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
|
|
45
67
|
import { BoundWitnessValidator } from "@xyo-network/boundwitness-validator";
|
|
68
|
+
import { BoundWitnessValidationError } from "@xyo-network/xl1-protocol";
|
|
46
69
|
var BoundWitnessSignaturesValidator = /* @__PURE__ */ __name(async (bw) => {
|
|
47
70
|
const errors = [];
|
|
48
71
|
try {
|
|
@@ -57,23 +80,23 @@ var BoundWitnessSignaturesValidator = /* @__PURE__ */ __name(async (bw) => {
|
|
|
57
80
|
errors.push(...bwErrors);
|
|
58
81
|
}
|
|
59
82
|
} catch (ex) {
|
|
60
|
-
errors.push(new
|
|
83
|
+
errors.push(new BoundWitnessValidationError(bw, "validation excepted"), ex);
|
|
61
84
|
}
|
|
62
85
|
return errors;
|
|
63
86
|
}, "BoundWitnessSignaturesValidator");
|
|
64
87
|
|
|
65
88
|
// src/block/validators/AllowedPayloadSchemas.ts
|
|
66
|
-
import { isAllowedBlockPayloadSchema } from "@xyo-network/xl1-protocol";
|
|
89
|
+
import { BlockValidationError, isAllowedBlockPayloadSchema } from "@xyo-network/xl1-protocol";
|
|
67
90
|
var BlockAllowedPayloadSchemasValidator = /* @__PURE__ */ __name((block) => {
|
|
68
91
|
const errors = [];
|
|
69
92
|
try {
|
|
70
93
|
for (const schema of block.payload_schemas) {
|
|
71
94
|
if (!isAllowedBlockPayloadSchema(schema)) {
|
|
72
|
-
errors.push(new
|
|
95
|
+
errors.push(new BlockValidationError(block, `payload schema not allowed in block: ${schema}`));
|
|
73
96
|
}
|
|
74
97
|
}
|
|
75
98
|
} catch (e) {
|
|
76
|
-
errors.push(new
|
|
99
|
+
errors.push(new BlockValidationError(block, `Failed BlockAllowedPayloadSchemasValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
77
100
|
}
|
|
78
101
|
return errors;
|
|
79
102
|
}, "BlockAllowedPayloadSchemasValidator");
|
|
@@ -81,11 +104,12 @@ var BlockAllowedPayloadSchemasValidator = /* @__PURE__ */ __name((block) => {
|
|
|
81
104
|
// src/block/validators/Fields.ts
|
|
82
105
|
import { isDefined } from "@xylabs/typeof";
|
|
83
106
|
import { BoundWitnessSchema } from "@xyo-network/boundwitness-model";
|
|
107
|
+
import { BlockValidationError as BlockValidationError2 } from "@xyo-network/xl1-protocol";
|
|
84
108
|
var BlockFieldsValidator = /* @__PURE__ */ __name((block, chainId) => {
|
|
85
109
|
const errors = [];
|
|
86
110
|
try {
|
|
87
111
|
if (isDefined(chainId) && block.chain !== chainId.toLowerCase()) {
|
|
88
|
-
errors.push(new
|
|
112
|
+
errors.push(new BlockValidationError2(block, "Invalid chain id"));
|
|
89
113
|
}
|
|
90
114
|
const txHashes = [];
|
|
91
115
|
for (let i = 0; i < block.payload_hashes.length; i++) {
|
|
@@ -94,16 +118,17 @@ var BlockFieldsValidator = /* @__PURE__ */ __name((block, chainId) => {
|
|
|
94
118
|
}
|
|
95
119
|
}
|
|
96
120
|
if (new Set(txHashes).size < txHashes.length) {
|
|
97
|
-
errors.push(new
|
|
121
|
+
errors.push(new BlockValidationError2(block, `Duplicate Transaction Hashes: ${txHashes}`));
|
|
98
122
|
}
|
|
99
123
|
} catch (e) {
|
|
100
|
-
errors.push(new
|
|
124
|
+
errors.push(new BlockValidationError2(block, `Failed BlockFieldsValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
101
125
|
}
|
|
102
126
|
return errors;
|
|
103
127
|
}, "BlockFieldsValidator");
|
|
104
128
|
|
|
105
129
|
// src/block/validators/JsonSchema.ts
|
|
106
130
|
import { BlockBoundWitnessWithStorageMetaJsonSchema } from "@xyo-network/chain-schema";
|
|
131
|
+
import { BlockValidationError as BlockValidationError3 } from "@xyo-network/xl1-protocol";
|
|
107
132
|
import { Ajv } from "ajv";
|
|
108
133
|
var BlockJsonSchemaValidator = /* @__PURE__ */ __name((jsonSchema = BlockBoundWitnessWithStorageMetaJsonSchema) => async (block) => {
|
|
109
134
|
const errors = [];
|
|
@@ -115,35 +140,35 @@ var BlockJsonSchemaValidator = /* @__PURE__ */ __name((jsonSchema = BlockBoundWi
|
|
|
115
140
|
const validate2 = ajv2.compile(jsonSchema);
|
|
116
141
|
await validate2(block);
|
|
117
142
|
if ((validate2.errors ?? []).length > 0) {
|
|
118
|
-
const error = new
|
|
119
|
-
error.
|
|
120
|
-
errors.push(error);
|
|
143
|
+
const error = new BlockValidationError3(block, "failed JSON schema validation: ");
|
|
144
|
+
errors.push(error, ...validate2.errors?.map((e) => new Error(` ${e.instancePath} ${e.message ?? ""}`)) ?? []);
|
|
121
145
|
}
|
|
122
146
|
} catch (e) {
|
|
123
|
-
errors.push(new
|
|
147
|
+
errors.push(new BlockValidationError3(block, `Failed BlockJsonSchemaValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
124
148
|
}
|
|
125
149
|
return errors;
|
|
126
150
|
}, "BlockJsonSchemaValidator");
|
|
127
151
|
|
|
128
152
|
// src/block/validators/PreviousHash.ts
|
|
129
153
|
import { isHash } from "@xylabs/hex";
|
|
154
|
+
import { BlockValidationError as BlockValidationError4 } from "@xyo-network/xl1-protocol";
|
|
130
155
|
var BlockPreviousHashValidator = /* @__PURE__ */ __name((block) => {
|
|
131
156
|
const errors = [];
|
|
132
157
|
try {
|
|
133
158
|
const blockNumber = block.block;
|
|
134
159
|
if (blockNumber > 0n) {
|
|
135
160
|
if (!isHash(block.previous)) {
|
|
136
|
-
errors.push(new
|
|
161
|
+
errors.push(new BlockValidationError4(block, "previous hash is missing or invalid"));
|
|
137
162
|
}
|
|
138
163
|
} else if (blockNumber === 0) {
|
|
139
164
|
if (block.previous !== null) {
|
|
140
|
-
errors.push(new
|
|
165
|
+
errors.push(new BlockValidationError4(block, "previous hash should not be set"));
|
|
141
166
|
}
|
|
142
167
|
} else {
|
|
143
|
-
errors.push(new
|
|
168
|
+
errors.push(new BlockValidationError4(block, "invalid block number"));
|
|
144
169
|
}
|
|
145
170
|
} catch (e) {
|
|
146
|
-
errors.push(new
|
|
171
|
+
errors.push(new BlockValidationError4(block, `Failed BlockPreviousHashValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
147
172
|
}
|
|
148
173
|
return errors;
|
|
149
174
|
}, "BlockPreviousHashValidator");
|
|
@@ -161,15 +186,21 @@ var validateBlock = /* @__PURE__ */ __name(async (block, chainId) => {
|
|
|
161
186
|
];
|
|
162
187
|
errors.push(...(await Promise.all(validators.map((validator) => validator(block, chainId)))).flat());
|
|
163
188
|
} catch (ex) {
|
|
164
|
-
errors.push(new
|
|
189
|
+
errors.push(new BlockValidationError5(block, "validation excepted"), ex);
|
|
165
190
|
}
|
|
166
191
|
return errors;
|
|
167
192
|
}, "validateBlock");
|
|
168
193
|
|
|
194
|
+
// src/hydratedBlock/validateHydratedBlock.ts
|
|
195
|
+
import { HydratedBlockValidationError as HydratedBlockValidationError2 } from "@xyo-network/xl1-protocol";
|
|
196
|
+
|
|
197
|
+
// src/hydratedBlock/validators/Payloads.ts
|
|
198
|
+
import { HydratedBlockValidationError } from "@xyo-network/xl1-protocol";
|
|
199
|
+
|
|
169
200
|
// src/elevatedPayload/validatePayloadInBlock.ts
|
|
170
201
|
import { BoundWitnessSchema as BoundWitnessSchema2 } from "@xyo-network/boundwitness-model";
|
|
171
202
|
import { SchemaSchema } from "@xyo-network/schema-payload-plugin";
|
|
172
|
-
import { ChainStakeIntentSchema, HashSchema, TransferSchema } from "@xyo-network/xl1-protocol";
|
|
203
|
+
import { ChainStakeIntentSchema, HashSchema, InBlockPayloadValidationError as InBlockPayloadValidationError5, TransferSchema } from "@xyo-network/xl1-protocol";
|
|
173
204
|
|
|
174
205
|
// src/elevatedPayload/lib/isElevatedFromBlock.ts
|
|
175
206
|
import { isTransactionBoundWitness } from "@xyo-network/xl1-protocol";
|
|
@@ -257,49 +288,50 @@ var validateTypedPayloadInBlock = /* @__PURE__ */ __name(async (payload, block,
|
|
|
257
288
|
}, "validateTypedPayloadInBlock");
|
|
258
289
|
|
|
259
290
|
// src/elevatedPayload/payloads/validateChainStakeIntentInBlock.ts
|
|
260
|
-
import { isChainStakeIntent } from "@xyo-network/xl1-protocol";
|
|
291
|
+
import { InBlockPayloadValidationError, isChainStakeIntent } from "@xyo-network/xl1-protocol";
|
|
261
292
|
var validateChainStakeIntentInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
262
293
|
const errors = [];
|
|
263
294
|
try {
|
|
264
295
|
errors.push(...await validateTypedPayloadInBlock(payload, block, isChainStakeIntent));
|
|
265
296
|
} catch (e) {
|
|
266
|
-
errors.push(new
|
|
297
|
+
errors.push(new InBlockPayloadValidationError(block, payload, `Failed validateChainStakeIntentInBlock: ${e instanceof Error ? e.message : String(e)}`));
|
|
267
298
|
}
|
|
268
299
|
return errors;
|
|
269
300
|
}, "validateChainStakeIntentInBlock");
|
|
270
301
|
|
|
271
302
|
// src/elevatedPayload/payloads/validateHashInBlock.ts
|
|
272
|
-
import { isHashPayload } from "@xyo-network/xl1-protocol";
|
|
303
|
+
import { InBlockPayloadValidationError as InBlockPayloadValidationError2, isHashPayload } from "@xyo-network/xl1-protocol";
|
|
273
304
|
var validateHashInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
274
305
|
const errors = [];
|
|
275
306
|
try {
|
|
276
307
|
errors.push(...await validateTypedPayloadInBlock(payload, block, isHashPayload));
|
|
277
308
|
} catch (e) {
|
|
278
|
-
errors.push(new
|
|
309
|
+
errors.push(new InBlockPayloadValidationError2(block, payload, `Failed validateHashInBlock: ${e instanceof Error ? e.message : String(e)}`));
|
|
279
310
|
}
|
|
280
311
|
return errors;
|
|
281
312
|
}, "validateHashInBlock");
|
|
282
313
|
|
|
283
314
|
// src/elevatedPayload/payloads/validateSchemaInBlock.ts
|
|
284
315
|
import { isSchemaPayload } from "@xyo-network/schema-payload-plugin";
|
|
316
|
+
import { InBlockPayloadValidationError as InBlockPayloadValidationError3 } from "@xyo-network/xl1-protocol";
|
|
285
317
|
var validateSchemaInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
286
318
|
const errors = [];
|
|
287
319
|
try {
|
|
288
320
|
errors.push(...await validateTypedPayloadInBlock(payload, block, isSchemaPayload));
|
|
289
321
|
} catch (e) {
|
|
290
|
-
errors.push(new
|
|
322
|
+
errors.push(new InBlockPayloadValidationError3(block, payload, `Failed validateSchemaInBlock: ${e instanceof Error ? e.message : String(e)}`));
|
|
291
323
|
}
|
|
292
324
|
return errors;
|
|
293
325
|
}, "validateSchemaInBlock");
|
|
294
326
|
|
|
295
327
|
// src/elevatedPayload/payloads/validateTransferInBlock.ts
|
|
296
|
-
import { isTransfer } from "@xyo-network/xl1-protocol";
|
|
328
|
+
import { InBlockPayloadValidationError as InBlockPayloadValidationError4, isTransfer } from "@xyo-network/xl1-protocol";
|
|
297
329
|
var validateTransferInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
298
330
|
const errors = [];
|
|
299
331
|
try {
|
|
300
332
|
errors.push(...await validateTypedPayloadInBlock(payload, block, isTransfer));
|
|
301
333
|
} catch (e) {
|
|
302
|
-
errors.push(new
|
|
334
|
+
errors.push(new InBlockPayloadValidationError4(block, payload, `Failed validateTransferInBlock: ${e instanceof Error ? e.message : String(e)}`));
|
|
303
335
|
}
|
|
304
336
|
return errors;
|
|
305
337
|
}, "validateTransferInBlock");
|
|
@@ -319,10 +351,10 @@ var validatePayloadInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
|
319
351
|
if (validator) {
|
|
320
352
|
errors.push(...await validator(payload, block));
|
|
321
353
|
} else {
|
|
322
|
-
errors.push(new
|
|
354
|
+
errors.push(new InBlockPayloadValidationError5(block, payload, `Unsupported payload schema: ${payload.schema}`));
|
|
323
355
|
}
|
|
324
356
|
} catch (e) {
|
|
325
|
-
errors.push(new
|
|
357
|
+
errors.push(new InBlockPayloadValidationError5(block, payload, `Failed validatePayloadInBlock: ${e instanceof Error ? e.message : String(e)}`));
|
|
326
358
|
}
|
|
327
359
|
return errors;
|
|
328
360
|
}, "validatePayloadInBlock");
|
|
@@ -349,14 +381,23 @@ var PayloadsInBlockValidator = /* @__PURE__ */ __name(async ([block, payloads])
|
|
|
349
381
|
]));
|
|
350
382
|
delete remainingPayloads[hash];
|
|
351
383
|
} else {
|
|
352
|
-
errors.push(new
|
|
384
|
+
errors.push(new HydratedBlockValidationError([
|
|
385
|
+
block,
|
|
386
|
+
payloads
|
|
387
|
+
], `missing payload ${hash} ${schema}`));
|
|
353
388
|
}
|
|
354
389
|
}
|
|
355
390
|
if (Object.keys(remainingPayloads).length > 0) {
|
|
356
|
-
errors.push(new
|
|
391
|
+
errors.push(new HydratedBlockValidationError([
|
|
392
|
+
block,
|
|
393
|
+
payloads
|
|
394
|
+
], `extra payloads ${Object.keys(payloadMap).join(", ")}`));
|
|
357
395
|
}
|
|
358
396
|
} catch (e) {
|
|
359
|
-
errors.push(new
|
|
397
|
+
errors.push(new HydratedBlockValidationError([
|
|
398
|
+
block,
|
|
399
|
+
payloads
|
|
400
|
+
], `Failed PayloadsInBlockValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
360
401
|
}
|
|
361
402
|
return errors;
|
|
362
403
|
}, "PayloadsInBlockValidator");
|
|
@@ -373,15 +414,19 @@ var validateHydratedBlock = /* @__PURE__ */ __name(async (hydratedBlock, chainId
|
|
|
373
414
|
];
|
|
374
415
|
errors.push(...(await Promise.all(validators.map((v) => v(hydratedBlock, chainId)))).flat());
|
|
375
416
|
} catch (e) {
|
|
376
|
-
errors.push(new
|
|
417
|
+
errors.push(new HydratedBlockValidationError2(hydratedBlock, `Failed validateHydratedBlock: ${e instanceof Error ? e.message : String(e)}`));
|
|
377
418
|
}
|
|
378
419
|
return errors;
|
|
379
420
|
}, "validateHydratedBlock");
|
|
380
421
|
|
|
422
|
+
// src/hydratedBlockState/validateHydratedBlockState.ts
|
|
423
|
+
import { HydratedBlockStateValidationError as HydratedBlockStateValidationError2 } from "@xyo-network/xl1-protocol";
|
|
424
|
+
|
|
381
425
|
// src/hydratedBlockState/validators/RequiredBalance.ts
|
|
382
426
|
import { hexToBigInt } from "@xylabs/hex";
|
|
383
427
|
import { netBalancesForPayloads } from "@xyo-network/chain-protocol";
|
|
384
428
|
import { XYO_ZERO_ADDRESS } from "@xyo-network/chain-utils";
|
|
429
|
+
import { HydratedBlockStateValidationError } from "@xyo-network/xl1-protocol";
|
|
385
430
|
var RequiredBalanceBlockStateValidator = /* @__PURE__ */ __name(async (block, chainId, services) => {
|
|
386
431
|
const errors = [];
|
|
387
432
|
try {
|
|
@@ -395,16 +440,16 @@ var RequiredBalanceBlockStateValidator = /* @__PURE__ */ __name(async (block, ch
|
|
|
395
440
|
}
|
|
396
441
|
const previous = block[0].previous;
|
|
397
442
|
if (previous === null) return [
|
|
398
|
-
new
|
|
443
|
+
new HydratedBlockStateValidationError(chainId, block, "Insufficient funds because first block")
|
|
399
444
|
];
|
|
400
445
|
for (const [address, reqBalance] of Object.entries(requiredBalances)) {
|
|
401
446
|
const balance = hexToBigInt(services.accountBalance.getBalance(address));
|
|
402
447
|
if (address !== XYO_ZERO_ADDRESS && reqBalance > balance) {
|
|
403
|
-
errors.push(new
|
|
448
|
+
errors.push(new HydratedBlockStateValidationError(chainId, block, `insufficient balance for ${address} ${balance} < ${requiredBalances[address]}`));
|
|
404
449
|
}
|
|
405
450
|
}
|
|
406
451
|
} catch (e) {
|
|
407
|
-
errors.push(new
|
|
452
|
+
errors.push(new HydratedBlockStateValidationError(chainId, block, `Failed RequiredBalanceBlockStateValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
408
453
|
}
|
|
409
454
|
return await Promise.resolve(errors);
|
|
410
455
|
}, "RequiredBalanceBlockStateValidator");
|
|
@@ -420,7 +465,7 @@ var validateHydratedBlockState = /* @__PURE__ */ __name(async (hydratedBlock, ch
|
|
|
420
465
|
];
|
|
421
466
|
errors.push(...(await Promise.all(validators.map((v) => v(hydratedBlock, chainId, services)))).flat());
|
|
422
467
|
} catch (e) {
|
|
423
|
-
errors.push(new
|
|
468
|
+
errors.push(new HydratedBlockStateValidationError2(chainId, hydratedBlock, `Failed validateHydratedBlockState: ${e instanceof Error ? e.message : String(e)}`));
|
|
424
469
|
}
|
|
425
470
|
return errors;
|
|
426
471
|
}, "validateHydratedBlockState");
|
|
@@ -429,32 +474,34 @@ var validateHydratedBlockState = /* @__PURE__ */ __name(async (hydratedBlock, ch
|
|
|
429
474
|
import { isTransactionBoundWitness as isTransactionBoundWitness3 } from "@xyo-network/xl1-protocol";
|
|
430
475
|
|
|
431
476
|
// src/transaction/validators/TransactionDurationValidator.ts
|
|
432
|
-
|
|
477
|
+
import { HydratedTransactionValidationError } from "@xyo-network/xl1-protocol";
|
|
478
|
+
var TransactionDurationValidator = /* @__PURE__ */ __name((tx) => {
|
|
433
479
|
const errors = [];
|
|
434
480
|
try {
|
|
435
|
-
const { exp, nbf } = tx;
|
|
436
|
-
if (nbf < 0) errors.push(new
|
|
437
|
-
if (exp < 0) errors.push(new
|
|
438
|
-
if (exp <= nbf) errors.push(new
|
|
439
|
-
if (exp - nbf > 1e4) errors.push(new
|
|
481
|
+
const { exp, nbf } = tx[0];
|
|
482
|
+
if (nbf < 0) errors.push(new HydratedTransactionValidationError(tx, "Transaction nbf must be positive"));
|
|
483
|
+
if (exp < 0) errors.push(new HydratedTransactionValidationError(tx, "Transaction exp must be positive"));
|
|
484
|
+
if (exp <= nbf) errors.push(new HydratedTransactionValidationError(tx, "Transaction exp must greater than nbf"));
|
|
485
|
+
if (exp - nbf > 1e4) errors.push(new HydratedTransactionValidationError(tx, "Transaction exp must not be too far in the future"));
|
|
440
486
|
} catch (e) {
|
|
441
|
-
errors.push(new
|
|
487
|
+
errors.push(new HydratedTransactionValidationError(tx, `Failed TransactionDurationValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
442
488
|
}
|
|
443
489
|
return errors;
|
|
444
490
|
}, "TransactionDurationValidator");
|
|
445
491
|
|
|
446
492
|
// src/transaction/validators/TransactionElevationValidator.ts
|
|
447
493
|
import { extractElevatedHashes } from "@xyo-network/chain-protocol";
|
|
494
|
+
import { HydratedTransactionValidationError as HydratedTransactionValidationError2 } from "@xyo-network/xl1-protocol";
|
|
448
495
|
var TransactionElevationValidator = /* @__PURE__ */ __name((tx) => {
|
|
449
496
|
const errors = [];
|
|
450
497
|
try {
|
|
451
498
|
try {
|
|
452
499
|
extractElevatedHashes(tx);
|
|
453
500
|
} catch {
|
|
454
|
-
errors.push(new
|
|
501
|
+
errors.push(new HydratedTransactionValidationError2(tx, "Hydrated transaction does not include all script hashes"));
|
|
455
502
|
}
|
|
456
503
|
} catch (e) {
|
|
457
|
-
errors.push(new
|
|
504
|
+
errors.push(new HydratedTransactionValidationError2(tx, `Failed TransactionElevationValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
458
505
|
}
|
|
459
506
|
return errors;
|
|
460
507
|
}, "TransactionElevationValidator");
|
|
@@ -462,39 +509,40 @@ var TransactionElevationValidator = /* @__PURE__ */ __name((tx) => {
|
|
|
462
509
|
// src/transaction/validators/TransactionFromValidator.ts
|
|
463
510
|
import { asAddress } from "@xylabs/hex";
|
|
464
511
|
import { addressesContains } from "@xyo-network/boundwitness-validator";
|
|
465
|
-
|
|
512
|
+
import { HydratedTransactionValidationError as HydratedTransactionValidationError3 } from "@xyo-network/xl1-protocol";
|
|
513
|
+
var TransactionFromValidator = /* @__PURE__ */ __name((tx) => {
|
|
466
514
|
const errors = [];
|
|
467
515
|
try {
|
|
468
|
-
const from = asAddress(tx.from);
|
|
469
|
-
if (from === void 0) errors.push(new
|
|
470
|
-
else if (!addressesContains(tx, from)) errors.push(new
|
|
516
|
+
const from = asAddress(tx[0].from);
|
|
517
|
+
if (from === void 0) errors.push(new HydratedTransactionValidationError3(tx, "Transaction from is not a valid address"));
|
|
518
|
+
else if (!addressesContains(tx[0], from)) errors.push(new HydratedTransactionValidationError3(tx, "Transaction from address must be listed in addresses"));
|
|
471
519
|
} catch (e) {
|
|
472
|
-
errors.push(new
|
|
520
|
+
errors.push(new HydratedTransactionValidationError3(tx, `Failed TransactionFromValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
473
521
|
}
|
|
474
522
|
return errors;
|
|
475
523
|
}, "TransactionFromValidator");
|
|
476
524
|
|
|
477
525
|
// src/transaction/validators/TransactionGasValidator.ts
|
|
478
526
|
import { hexToBigInt as hexToBigInt2 } from "@xylabs/hex";
|
|
479
|
-
import { AttoXL1, minTransactionFees } from "@xyo-network/xl1-protocol";
|
|
480
|
-
var TransactionGasValidator = /* @__PURE__ */ __name((
|
|
527
|
+
import { AttoXL1, HydratedTransactionValidationError as HydratedTransactionValidationError4, minTransactionFees } from "@xyo-network/xl1-protocol";
|
|
528
|
+
var TransactionGasValidator = /* @__PURE__ */ __name((tx) => {
|
|
481
529
|
const errors = [];
|
|
482
530
|
try {
|
|
483
|
-
if (tx?.fees === void 0) {
|
|
484
|
-
errors.push(new
|
|
531
|
+
if (tx?.[0].fees === void 0) {
|
|
532
|
+
errors.push(new HydratedTransactionValidationError4(tx, "Missing fees"));
|
|
485
533
|
} else {
|
|
486
|
-
const { base, gasLimit, gasPrice, priority } = parseFees(tx.fees);
|
|
487
|
-
if (base === void 0) errors.push(new
|
|
488
|
-
else if (base < minTransactionFees.base) errors.push(new
|
|
489
|
-
if (gasLimit === void 0) errors.push(new
|
|
490
|
-
else if (gasLimit < minTransactionFees.gasLimit) errors.push(new
|
|
491
|
-
if (gasPrice === void 0) errors.push(new
|
|
492
|
-
else if (gasPrice < minTransactionFees.gasPrice) errors.push(new
|
|
493
|
-
if (priority === void 0) errors.push(new
|
|
494
|
-
else if (priority < minTransactionFees.priority) errors.push(new
|
|
534
|
+
const { base, gasLimit, gasPrice, priority } = parseFees(tx[0].fees);
|
|
535
|
+
if (base === void 0) errors.push(new HydratedTransactionValidationError4(tx, "fees.base must be defined and a valid number"));
|
|
536
|
+
else if (base < minTransactionFees.base) errors.push(new HydratedTransactionValidationError4(tx, `fees.base must be >= ${minTransactionFees.base}`));
|
|
537
|
+
if (gasLimit === void 0) errors.push(new HydratedTransactionValidationError4(tx, "fees.gasLimit must be defined and a valid number"));
|
|
538
|
+
else if (gasLimit < minTransactionFees.gasLimit) errors.push(new HydratedTransactionValidationError4(tx, `fees.gasLimit must be >= ${minTransactionFees.gasLimit}`));
|
|
539
|
+
if (gasPrice === void 0) errors.push(new HydratedTransactionValidationError4(tx, "fees.gasPrice must be defined and a valid number"));
|
|
540
|
+
else if (gasPrice < minTransactionFees.gasPrice) errors.push(new HydratedTransactionValidationError4(tx, `fees.gasPrice must be >= ${minTransactionFees.gasPrice}`));
|
|
541
|
+
if (priority === void 0) errors.push(new HydratedTransactionValidationError4(tx, "fees.priority must be defined and a valid number"));
|
|
542
|
+
else if (priority < minTransactionFees.priority) errors.push(new HydratedTransactionValidationError4(tx, `fees.priority must be >= ${minTransactionFees.priority}`));
|
|
495
543
|
}
|
|
496
544
|
} catch (e) {
|
|
497
|
-
errors.push(new
|
|
545
|
+
errors.push(new HydratedTransactionValidationError4(tx, `Failed TransactionGasValidator: ${e instanceof Error ? e.message : String(e)}`));
|
|
498
546
|
}
|
|
499
547
|
return errors;
|
|
500
548
|
}, "TransactionGasValidator");
|
|
@@ -511,36 +559,38 @@ var parseFees = /* @__PURE__ */ __name((fees) => {
|
|
|
511
559
|
// src/transaction/validators/TransactionJsonSchemaValidator.ts
|
|
512
560
|
import { TransactionBoundWitnessJsonSchema } from "@xyo-network/chain-schema";
|
|
513
561
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
562
|
+
import { HydratedTransactionValidationError as HydratedTransactionValidationError5 } from "@xyo-network/xl1-protocol";
|
|
514
563
|
import { Ajv as Ajv2 } from "ajv";
|
|
515
564
|
var ajv = new Ajv2({
|
|
516
565
|
allErrors: true,
|
|
517
566
|
strict: true
|
|
518
567
|
});
|
|
519
568
|
var validate;
|
|
520
|
-
var TransactionJsonSchemaValidator = /* @__PURE__ */ __name((
|
|
569
|
+
var TransactionJsonSchemaValidator = /* @__PURE__ */ __name((tx) => {
|
|
521
570
|
const errors = [];
|
|
522
571
|
try {
|
|
523
572
|
if (validate === void 0) validate = ajv.compile(TransactionBoundWitnessJsonSchema);
|
|
524
|
-
if (!validate(PayloadBuilder.omitStorageMeta(tx))) {
|
|
525
|
-
const error = new
|
|
573
|
+
if (!validate(PayloadBuilder.omitStorageMeta(tx[0]))) {
|
|
574
|
+
const error = new HydratedTransactionValidationError5(tx, "failed JSON schema validation");
|
|
526
575
|
error.cause = validate.errors;
|
|
527
576
|
errors.push(error);
|
|
528
577
|
}
|
|
529
578
|
} catch (ex) {
|
|
530
|
-
errors.push(new
|
|
579
|
+
errors.push(new HydratedTransactionValidationError5(tx, "validation excepted"), ex);
|
|
531
580
|
}
|
|
532
581
|
return errors;
|
|
533
582
|
}, "TransactionJsonSchemaValidator");
|
|
534
583
|
|
|
535
584
|
// src/transaction/validators/TransactionProtocolValidator.ts
|
|
536
|
-
|
|
585
|
+
import { HydratedTransactionValidationError as HydratedTransactionValidationError6 } from "@xyo-network/xl1-protocol";
|
|
586
|
+
var TransactionProtocolValidator = /* @__PURE__ */ __name(async (tx, chainId) => {
|
|
537
587
|
const errors = [];
|
|
538
588
|
try {
|
|
539
|
-
if (chainId !== void 0 && tx.chain !== chainId) {
|
|
540
|
-
errors.push(new
|
|
589
|
+
if (chainId !== void 0 && tx[0].chain !== chainId) {
|
|
590
|
+
errors.push(new HydratedTransactionValidationError6(tx, "invalid chain id"));
|
|
541
591
|
}
|
|
542
592
|
} catch (ex) {
|
|
543
|
-
errors.push(new
|
|
593
|
+
errors.push(new HydratedTransactionValidationError6(tx, "validation excepted"), ex);
|
|
544
594
|
}
|
|
545
595
|
return await Promise.resolve(errors);
|
|
546
596
|
}, "TransactionProtocolValidator");
|