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