@xyo-network/chain-validation 1.7.14 → 1.7.16
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/block/validators/JsonSchema.d.ts.map +1 -1
- package/dist/neutral/elevatedPayload/lib/validateTransactionInBlock.d.ts.map +1 -1
- package/dist/neutral/hydratedBlockState/validators/RequiredBalance.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +0 -2
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +56 -307
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +7 -11
- package/src/block/validateBlock.ts +1 -1
- package/src/block/validators/JsonSchema.ts +1 -1
- package/src/elevatedPayload/lib/validateTransactionInBlock.ts +1 -2
- package/src/hydratedBlock/validateHydratedBlock.ts +1 -1
- package/src/hydratedBlockState/validators/RequiredBalance.ts +3 -2
- package/src/index.ts +0 -2
- package/dist/neutral/boundwitness/index.d.ts +0 -2
- package/dist/neutral/boundwitness/index.d.ts.map +0 -1
- package/dist/neutral/boundwitness/validators/BoundWitnessReferences.d.ts +0 -5
- package/dist/neutral/boundwitness/validators/BoundWitnessReferences.d.ts.map +0 -1
- package/dist/neutral/boundwitness/validators/BoundWitnessSignatures.d.ts +0 -3
- package/dist/neutral/boundwitness/validators/BoundWitnessSignatures.d.ts.map +0 -1
- package/dist/neutral/boundwitness/validators/index.d.ts +0 -3
- package/dist/neutral/boundwitness/validators/index.d.ts.map +0 -1
- package/dist/neutral/transaction/index.d.ts +0 -3
- package/dist/neutral/transaction/index.d.ts.map +0 -1
- package/dist/neutral/transaction/validateTransaction.d.ts +0 -4
- package/dist/neutral/transaction/validateTransaction.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/TransactionDurationValidator.d.ts +0 -3
- package/dist/neutral/transaction/validators/TransactionDurationValidator.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/TransactionElevationValidator.d.ts +0 -3
- package/dist/neutral/transaction/validators/TransactionElevationValidator.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/TransactionFromValidator.d.ts +0 -3
- package/dist/neutral/transaction/validators/TransactionFromValidator.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/TransactionGasValidator.d.ts +0 -3
- package/dist/neutral/transaction/validators/TransactionGasValidator.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/TransactionJsonSchemaValidator.d.ts +0 -3
- package/dist/neutral/transaction/validators/TransactionJsonSchemaValidator.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/TransactionProtocolValidator.d.ts +0 -3
- package/dist/neutral/transaction/validators/TransactionProtocolValidator.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/index.d.ts +0 -7
- package/dist/neutral/transaction/validators/index.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/spec/TransactionDurationValidator.spec.d.ts +0 -2
- package/dist/neutral/transaction/validators/spec/TransactionDurationValidator.spec.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/spec/TransactionElevationValidator.spec.d.ts +0 -2
- package/dist/neutral/transaction/validators/spec/TransactionElevationValidator.spec.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/spec/TransactionFromValidator.spec.d.ts +0 -2
- package/dist/neutral/transaction/validators/spec/TransactionFromValidator.spec.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/spec/TransactionGasValidator.spec.d.ts +0 -2
- package/dist/neutral/transaction/validators/spec/TransactionGasValidator.spec.d.ts.map +0 -1
- package/dist/neutral/transaction/validators/spec/TransactionJsonSchemaValidator.spec.d.ts +0 -2
- package/dist/neutral/transaction/validators/spec/TransactionJsonSchemaValidator.spec.d.ts.map +0 -1
- package/src/boundwitness/index.ts +0 -1
- package/src/boundwitness/validators/BoundWitnessReferences.ts +0 -57
- package/src/boundwitness/validators/BoundWitnessSignatures.ts +0 -28
- package/src/boundwitness/validators/index.ts +0 -2
- package/src/transaction/index.ts +0 -2
- package/src/transaction/validateTransaction.ts +0 -33
- package/src/transaction/validators/TransactionDurationValidator.ts +0 -33
- package/src/transaction/validators/TransactionElevationValidator.ts +0 -27
- package/src/transaction/validators/TransactionFromValidator.ts +0 -33
- package/src/transaction/validators/TransactionGasValidator.ts +0 -97
- package/src/transaction/validators/TransactionJsonSchemaValidator.ts +0 -34
- package/src/transaction/validators/TransactionProtocolValidator.ts +0 -20
- package/src/transaction/validators/index.ts +0 -6
- package/src/transaction/validators/spec/TransactionDurationValidator.spec.ts +0 -49
- package/src/transaction/validators/spec/TransactionElevationValidator.spec.ts +0 -39
- package/src/transaction/validators/spec/TransactionFromValidator.spec.ts +0 -43
- package/src/transaction/validators/spec/TransactionGasValidator.spec.ts +0 -88
- package/src/transaction/validators/spec/TransactionJsonSchemaValidator.spec.ts +0 -33
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonSchema.d.ts","sourceRoot":"","sources":["../../../../src/block/validators/JsonSchema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JsonSchema.d.ts","sourceRoot":"","sources":["../../../../src/block/validators/JsonSchema.ts"],"names":[],"mappings":"AAEA,OAAO,EACyC,KAAK,sBAAsB,EAC1E,MAAM,2BAA2B,CAAA;AAElC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAGpC,eAAO,MAAM,wBAAwB,GAAI,aAAY,SAAsD,KAAG,sBA6B7G,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTransactionInBlock.d.ts","sourceRoot":"","sources":["../../../../src/elevatedPayload/lib/validateTransactionInBlock.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,gCAAgC,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"validateTransactionInBlock.d.ts","sourceRoot":"","sources":["../../../../src/elevatedPayload/lib/validateTransactionInBlock.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,gCAAgC,EAAE,MAAM,2BAA2B,CAAA;AAIhG,eAAO,MAAM,0BAA0B,EAAE,gCAkBxC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequiredBalance.d.ts","sourceRoot":"","sources":["../../../../src/hydratedBlockState/validators/RequiredBalance.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RequiredBalance.d.ts","sourceRoot":"","sources":["../../../../src/hydratedBlockState/validators/RequiredBalance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,sCAAsC,EACvC,MAAM,2BAA2B,CAAA;AAMlC,eAAO,MAAM,kCAAkC,EAAE,sCA+ChD,CAAA"}
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -2,115 +2,29 @@ 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
|
|
5
|
+
import { ZERO_HASH as ZERO_HASH5 } from "@xylabs/hex";
|
|
6
6
|
import { BlockValidationError as BlockValidationError5 } from "@xyo-network/xl1-protocol";
|
|
7
|
-
|
|
8
|
-
// src/boundwitness/validators/BoundWitnessReferences.ts
|
|
9
|
-
import { ZERO_HASH } from "@xylabs/hex";
|
|
10
|
-
import { isAnyPayload } from "@xyo-network/payload-model";
|
|
11
|
-
import { HydratedBoundWitnessValidationError } from "@xyo-network/xl1-protocol";
|
|
12
|
-
function getPayloadsFromPayloadArray(payloads, hashes) {
|
|
13
|
-
return hashes.map((hash) => payloads.find((payload) => payload._hash === hash || payload._dataHash === hash));
|
|
14
|
-
}
|
|
15
|
-
__name(getPayloadsFromPayloadArray, "getPayloadsFromPayloadArray");
|
|
16
|
-
var BoundWitnessReferencesValidator = /* @__PURE__ */ __name((allowedSchemas) => ([bw, payloadSet]) => {
|
|
17
|
-
const errors = [];
|
|
18
|
-
try {
|
|
19
|
-
const payloads = getPayloadsFromPayloadArray(payloadSet, bw.payload_hashes);
|
|
20
|
-
if (payloads.length !== bw.payload_hashes.length) {
|
|
21
|
-
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
22
|
-
bw,
|
|
23
|
-
payloadSet
|
|
24
|
-
], "unable to locate payloads"));
|
|
25
|
-
}
|
|
26
|
-
for (let payload of payloads) {
|
|
27
|
-
if (isAnyPayload(payload)) {
|
|
28
|
-
const payloadHashIndex = bw.payload_hashes.indexOf(payload._hash);
|
|
29
|
-
const payloadDataHashIndex = bw.payload_hashes.indexOf(payload._dataHash);
|
|
30
|
-
const payloadIndex = Math.max(payloadHashIndex, payloadDataHashIndex);
|
|
31
|
-
if (payloadIndex === -1) {
|
|
32
|
-
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
33
|
-
bw,
|
|
34
|
-
payloadSet
|
|
35
|
-
], "payload hash not found"));
|
|
36
|
-
}
|
|
37
|
-
const declaredSchema = bw.payload_schemas[payloadIndex];
|
|
38
|
-
if (declaredSchema !== payload.schema) {
|
|
39
|
-
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
40
|
-
bw,
|
|
41
|
-
payloadSet
|
|
42
|
-
], "mismatched schema"));
|
|
43
|
-
}
|
|
44
|
-
if (allowedSchemas && !allowedSchemas.includes(payload.schema)) {
|
|
45
|
-
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
46
|
-
bw,
|
|
47
|
-
payloadSet
|
|
48
|
-
], `disallowed schema [${payload.schema}]`));
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
52
|
-
bw,
|
|
53
|
-
payloadSet
|
|
54
|
-
], "invalid payload"));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
} catch (ex) {
|
|
58
|
-
const error = new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
59
|
-
bw,
|
|
60
|
-
payloadSet
|
|
61
|
-
], `validation excepted: ${ex}`);
|
|
62
|
-
error.cause = ex;
|
|
63
|
-
errors.push(error);
|
|
64
|
-
}
|
|
65
|
-
return errors;
|
|
66
|
-
}, "BoundWitnessReferencesValidator");
|
|
67
|
-
|
|
68
|
-
// src/boundwitness/validators/BoundWitnessSignatures.ts
|
|
69
|
-
import { toArrayBuffer } from "@xylabs/arraybuffer";
|
|
70
|
-
import { ZERO_HASH as ZERO_HASH2 } from "@xylabs/hex";
|
|
71
|
-
import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
|
|
72
|
-
import { BoundWitnessValidator } from "@xyo-network/boundwitness-validator";
|
|
73
|
-
import { BoundWitnessValidationError } from "@xyo-network/xl1-protocol";
|
|
74
|
-
var BoundWitnessSignaturesValidator = /* @__PURE__ */ __name(async (bw) => {
|
|
75
|
-
const errors = [];
|
|
76
|
-
try {
|
|
77
|
-
const dataHash = await BoundWitnessBuilder.dataHash(bw);
|
|
78
|
-
const results = await Promise.all(bw.addresses.map(async (address, index) => {
|
|
79
|
-
return [
|
|
80
|
-
address,
|
|
81
|
-
await BoundWitnessValidator.validateSignature(toArrayBuffer(dataHash), toArrayBuffer(address), toArrayBuffer(bw.$signatures[index]))
|
|
82
|
-
];
|
|
83
|
-
}));
|
|
84
|
-
for (const [, bwErrors] of results) {
|
|
85
|
-
for (const bwError of bwErrors) {
|
|
86
|
-
errors.push(new BoundWitnessValidationError(bw?._hash ?? ZERO_HASH2, bw, "validation errors", bwError));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} catch (ex) {
|
|
90
|
-
errors.push(new BoundWitnessValidationError(bw?._hash ?? ZERO_HASH2, bw, "validation excepted", ex));
|
|
91
|
-
}
|
|
92
|
-
return errors;
|
|
93
|
-
}, "BoundWitnessSignaturesValidator");
|
|
7
|
+
import { BoundWitnessSignaturesValidator } from "@xyo-network/xl1-validation";
|
|
94
8
|
|
|
95
9
|
// src/block/validators/AllowedPayloadSchemas.ts
|
|
96
|
-
import { ZERO_HASH
|
|
10
|
+
import { ZERO_HASH } from "@xylabs/hex";
|
|
97
11
|
import { BlockValidationError, isAllowedBlockPayloadSchema } from "@xyo-network/xl1-protocol";
|
|
98
12
|
var BlockAllowedPayloadSchemasValidator = /* @__PURE__ */ __name((block) => {
|
|
99
13
|
const errors = [];
|
|
100
14
|
try {
|
|
101
15
|
for (const schema of block.payload_schemas) {
|
|
102
16
|
if (!isAllowedBlockPayloadSchema(schema)) {
|
|
103
|
-
errors.push(new BlockValidationError(block?._hash ??
|
|
17
|
+
errors.push(new BlockValidationError(block?._hash ?? ZERO_HASH, block, `payload schema not allowed in block: ${schema}`));
|
|
104
18
|
}
|
|
105
19
|
}
|
|
106
20
|
} catch (ex) {
|
|
107
|
-
errors.push(new BlockValidationError(block?._hash ??
|
|
21
|
+
errors.push(new BlockValidationError(block?._hash ?? ZERO_HASH, block, `validation excepted: ${ex}`, ex));
|
|
108
22
|
}
|
|
109
23
|
return errors;
|
|
110
24
|
}, "BlockAllowedPayloadSchemasValidator");
|
|
111
25
|
|
|
112
26
|
// src/block/validators/Fields.ts
|
|
113
|
-
import { ZERO_HASH as
|
|
27
|
+
import { ZERO_HASH as ZERO_HASH2 } from "@xylabs/hex";
|
|
114
28
|
import { isDefined } from "@xylabs/typeof";
|
|
115
29
|
import { BoundWitnessSchema } from "@xyo-network/boundwitness-model";
|
|
116
30
|
import { BlockValidationError as BlockValidationError2 } from "@xyo-network/xl1-protocol";
|
|
@@ -118,7 +32,7 @@ var BlockFieldsValidator = /* @__PURE__ */ __name((block, chainId) => {
|
|
|
118
32
|
const errors = [];
|
|
119
33
|
try {
|
|
120
34
|
if (isDefined(chainId) && block.chain !== chainId.toLowerCase()) {
|
|
121
|
-
errors.push(new BlockValidationError2(block?._hash ??
|
|
35
|
+
errors.push(new BlockValidationError2(block?._hash ?? ZERO_HASH2, block, "Invalid chain id"));
|
|
122
36
|
}
|
|
123
37
|
const txHashes = [];
|
|
124
38
|
for (let i = 0; i < block.payload_hashes.length; i++) {
|
|
@@ -127,38 +41,38 @@ var BlockFieldsValidator = /* @__PURE__ */ __name((block, chainId) => {
|
|
|
127
41
|
}
|
|
128
42
|
}
|
|
129
43
|
if (new Set(txHashes).size < txHashes.length) {
|
|
130
|
-
errors.push(new BlockValidationError2(block?._hash ??
|
|
44
|
+
errors.push(new BlockValidationError2(block?._hash ?? ZERO_HASH2, block, `Duplicate Transaction Hashes: ${txHashes}`));
|
|
131
45
|
}
|
|
132
46
|
} catch (ex) {
|
|
133
|
-
errors.push(new BlockValidationError2(block?._hash ??
|
|
47
|
+
errors.push(new BlockValidationError2(block?._hash ?? ZERO_HASH2, block, `validation excepted: ${ex}`, ex));
|
|
134
48
|
}
|
|
135
49
|
return errors;
|
|
136
50
|
}, "BlockFieldsValidator");
|
|
137
51
|
|
|
138
52
|
// src/block/validators/JsonSchema.ts
|
|
139
|
-
import { ZERO_HASH as
|
|
140
|
-
import { BlockBoundWitnessWithStorageMetaJsonSchema } from "@xyo-network/chain-schema";
|
|
53
|
+
import { ZERO_HASH as ZERO_HASH3 } from "@xylabs/hex";
|
|
141
54
|
import { BlockValidationError as BlockValidationError3 } from "@xyo-network/xl1-protocol";
|
|
55
|
+
import { BlockBoundWitnessWithStorageMetaJsonSchema } from "@xyo-network/xl1-schema";
|
|
142
56
|
import { Ajv } from "ajv";
|
|
143
57
|
var BlockJsonSchemaValidator = /* @__PURE__ */ __name((jsonSchema = BlockBoundWitnessWithStorageMetaJsonSchema) => {
|
|
144
|
-
const
|
|
58
|
+
const ajv = new Ajv({
|
|
145
59
|
allErrors: true,
|
|
146
60
|
strict: true
|
|
147
61
|
});
|
|
148
|
-
const
|
|
62
|
+
const validate = ajv.compile(jsonSchema);
|
|
149
63
|
return async (block) => {
|
|
150
64
|
const errors = [];
|
|
151
65
|
try {
|
|
152
|
-
await
|
|
153
|
-
if ((
|
|
154
|
-
const error = new BlockValidationError3(block?._hash ??
|
|
66
|
+
await validate(block);
|
|
67
|
+
if ((validate.errors ?? []).length > 0) {
|
|
68
|
+
const error = new BlockValidationError3(block?._hash ?? ZERO_HASH3, block, `failed JSON schema validation: ${ajv.errorsText(validate.errors, {
|
|
155
69
|
separator: "\n"
|
|
156
70
|
})}`);
|
|
157
|
-
error.cause =
|
|
71
|
+
error.cause = validate.errors;
|
|
158
72
|
errors.push(error);
|
|
159
73
|
}
|
|
160
74
|
} catch (ex) {
|
|
161
|
-
const error = new BlockValidationError3(block?._hash ??
|
|
75
|
+
const error = new BlockValidationError3(block?._hash ?? ZERO_HASH3, block, `validation excepted: ${ex}`);
|
|
162
76
|
error.cause = ex;
|
|
163
77
|
errors.push(error);
|
|
164
78
|
}
|
|
@@ -167,7 +81,7 @@ var BlockJsonSchemaValidator = /* @__PURE__ */ __name((jsonSchema = BlockBoundWi
|
|
|
167
81
|
}, "BlockJsonSchemaValidator");
|
|
168
82
|
|
|
169
83
|
// src/block/validators/PreviousHash.ts
|
|
170
|
-
import { isHash, ZERO_HASH as
|
|
84
|
+
import { isHash, ZERO_HASH as ZERO_HASH4 } from "@xylabs/hex";
|
|
171
85
|
import { BlockValidationError as BlockValidationError4 } from "@xyo-network/xl1-protocol";
|
|
172
86
|
var BlockPreviousHashValidator = /* @__PURE__ */ __name((block) => {
|
|
173
87
|
const errors = [];
|
|
@@ -175,17 +89,17 @@ var BlockPreviousHashValidator = /* @__PURE__ */ __name((block) => {
|
|
|
175
89
|
const blockNumber = block.block;
|
|
176
90
|
if (blockNumber > 0n) {
|
|
177
91
|
if (!isHash(block.previous)) {
|
|
178
|
-
errors.push(new BlockValidationError4(block?._hash ??
|
|
92
|
+
errors.push(new BlockValidationError4(block?._hash ?? ZERO_HASH4, block, "previous hash is missing or invalid"));
|
|
179
93
|
}
|
|
180
94
|
} else if (blockNumber === 0) {
|
|
181
95
|
if (block.previous !== null) {
|
|
182
|
-
errors.push(new BlockValidationError4(block?._hash ??
|
|
96
|
+
errors.push(new BlockValidationError4(block?._hash ?? ZERO_HASH4, block, "previous hash should not be set"));
|
|
183
97
|
}
|
|
184
98
|
} else {
|
|
185
|
-
errors.push(new BlockValidationError4(block?._hash ??
|
|
99
|
+
errors.push(new BlockValidationError4(block?._hash ?? ZERO_HASH4, block, "invalid block number"));
|
|
186
100
|
}
|
|
187
101
|
} catch (ex) {
|
|
188
|
-
const error = new BlockValidationError4(block?._hash ??
|
|
102
|
+
const error = new BlockValidationError4(block?._hash ?? ZERO_HASH4, block, `Failed BlockPreviousHashValidator: ${ex}`);
|
|
189
103
|
error.cause = ex;
|
|
190
104
|
errors.push(error);
|
|
191
105
|
}
|
|
@@ -198,7 +112,7 @@ var validateBlock = /* @__PURE__ */ __name(async (block, chainId) => {
|
|
|
198
112
|
try {
|
|
199
113
|
const bwErrors = await BoundWitnessSignaturesValidator(block);
|
|
200
114
|
for (const bwError of bwErrors) {
|
|
201
|
-
errors.push(new BlockValidationError5(block?._hash ??
|
|
115
|
+
errors.push(new BlockValidationError5(block?._hash ?? ZERO_HASH5, block, "BoundWitness validation failed", bwError));
|
|
202
116
|
}
|
|
203
117
|
const validators = [
|
|
204
118
|
BlockFieldsValidator,
|
|
@@ -208,21 +122,22 @@ var validateBlock = /* @__PURE__ */ __name(async (block, chainId) => {
|
|
|
208
122
|
];
|
|
209
123
|
errors.push(...(await Promise.all(validators.map((validator) => validator(block, chainId)))).flat());
|
|
210
124
|
} catch (ex) {
|
|
211
|
-
errors.push(new BlockValidationError5(block?._hash ??
|
|
125
|
+
errors.push(new BlockValidationError5(block?._hash ?? ZERO_HASH5, block, "validation excepted", ex));
|
|
212
126
|
}
|
|
213
127
|
return errors;
|
|
214
128
|
}, "validateBlock");
|
|
215
129
|
|
|
216
130
|
// src/hydratedBlock/validateHydratedBlock.ts
|
|
217
|
-
import { ZERO_HASH as
|
|
131
|
+
import { ZERO_HASH as ZERO_HASH13 } from "@xylabs/hex";
|
|
218
132
|
import { HydratedBlockValidationError as HydratedBlockValidationError2 } from "@xyo-network/xl1-protocol";
|
|
133
|
+
import { BoundWitnessReferencesValidator } from "@xyo-network/xl1-validation";
|
|
219
134
|
|
|
220
135
|
// src/hydratedBlock/validators/Payloads.ts
|
|
221
|
-
import { ZERO_HASH as
|
|
136
|
+
import { ZERO_HASH as ZERO_HASH12 } from "@xylabs/hex";
|
|
222
137
|
import { HydratedBlockValidationError } from "@xyo-network/xl1-protocol";
|
|
223
138
|
|
|
224
139
|
// src/elevatedPayload/validatePayloadInBlock.ts
|
|
225
|
-
import { ZERO_HASH as
|
|
140
|
+
import { ZERO_HASH as ZERO_HASH11 } from "@xylabs/hex";
|
|
226
141
|
import { BoundWitnessSchema as BoundWitnessSchema2 } from "@xyo-network/boundwitness-model";
|
|
227
142
|
import { SchemaSchema } from "@xyo-network/schema-payload-plugin";
|
|
228
143
|
import { ChainStakeIntentSchema, HashSchema, InBlockPayloadValidationError as InBlockPayloadValidationError8, TransferSchema } from "@xyo-network/xl1-protocol";
|
|
@@ -278,14 +193,15 @@ var validateElevatedFromTransaction = /* @__PURE__ */ __name((payload, block) =>
|
|
|
278
193
|
}, "validateElevatedFromTransaction");
|
|
279
194
|
|
|
280
195
|
// src/elevatedPayload/lib/validateTransactionInBlock.ts
|
|
281
|
-
import { ZERO_HASH as
|
|
196
|
+
import { ZERO_HASH as ZERO_HASH6 } from "@xylabs/hex";
|
|
282
197
|
import { isStorageMeta } from "@xyo-network/payload-model";
|
|
283
198
|
import { InBlockPayloadValidationError as InBlockPayloadValidationError3, isTransactionBoundWitness as isTransactionBoundWitness2 } from "@xyo-network/xl1-protocol";
|
|
199
|
+
import { BoundWitnessSignaturesValidator as BoundWitnessSignaturesValidator2 } from "@xyo-network/xl1-validation";
|
|
284
200
|
var validateTransactionInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
285
201
|
const errors = [];
|
|
286
202
|
try {
|
|
287
203
|
if (isTransactionBoundWitness2(payload) && isStorageMeta(payload)) {
|
|
288
|
-
const txErrors = await
|
|
204
|
+
const txErrors = await BoundWitnessSignaturesValidator2(payload);
|
|
289
205
|
for (const txError of txErrors) {
|
|
290
206
|
errors.push(new InBlockPayloadValidationError3(payload._hash, block, payload, `BoundWitnessSignaturesValidator error: ${txError}`, txError));
|
|
291
207
|
}
|
|
@@ -293,7 +209,7 @@ var validateTransactionInBlock = /* @__PURE__ */ __name(async (payload, block) =
|
|
|
293
209
|
errors.push(new InBlockPayloadValidationError3(payload._hash, block, payload, "Payload failed isTransactionBoundWitness or isStorageMeta"));
|
|
294
210
|
}
|
|
295
211
|
} catch (ex) {
|
|
296
|
-
errors.push(new InBlockPayloadValidationError3(payload._hash ??
|
|
212
|
+
errors.push(new InBlockPayloadValidationError3(payload._hash ?? ZERO_HASH6, block, payload, `validation excepted: ${ex}`, ex));
|
|
297
213
|
}
|
|
298
214
|
return errors;
|
|
299
215
|
}, "validateTransactionInBlock");
|
|
@@ -319,7 +235,7 @@ var validateTypedPayloadInBlock = /* @__PURE__ */ __name(async (payload, block,
|
|
|
319
235
|
}, "validateTypedPayloadInBlock");
|
|
320
236
|
|
|
321
237
|
// src/elevatedPayload/payloads/validateChainStakeIntentInBlock.ts
|
|
322
|
-
import { ZERO_HASH as
|
|
238
|
+
import { ZERO_HASH as ZERO_HASH7 } from "@xylabs/hex";
|
|
323
239
|
import { InBlockPayloadValidationError as InBlockPayloadValidationError4, isChainStakeIntent } from "@xyo-network/xl1-protocol";
|
|
324
240
|
var validateChainStakeIntentInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
325
241
|
const errors = [];
|
|
@@ -329,13 +245,13 @@ var validateChainStakeIntentInBlock = /* @__PURE__ */ __name(async (payload, blo
|
|
|
329
245
|
errors.push(new InBlockPayloadValidationError4(payload._hash, block, payload, `validateTypedPayloadInBlock error: ${typedError}`, typedError));
|
|
330
246
|
}
|
|
331
247
|
} catch (ex) {
|
|
332
|
-
errors.push(new InBlockPayloadValidationError4(block[0]?._hash ??
|
|
248
|
+
errors.push(new InBlockPayloadValidationError4(block[0]?._hash ?? ZERO_HASH7, block, payload, `validation excepted: ${ex}`, ex));
|
|
333
249
|
}
|
|
334
250
|
return errors;
|
|
335
251
|
}, "validateChainStakeIntentInBlock");
|
|
336
252
|
|
|
337
253
|
// src/elevatedPayload/payloads/validateHashInBlock.ts
|
|
338
|
-
import { ZERO_HASH as
|
|
254
|
+
import { ZERO_HASH as ZERO_HASH8 } from "@xylabs/hex";
|
|
339
255
|
import { InBlockPayloadValidationError as InBlockPayloadValidationError5, isHashPayload } from "@xyo-network/xl1-protocol";
|
|
340
256
|
var validateHashInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
341
257
|
const errors = [];
|
|
@@ -345,13 +261,13 @@ var validateHashInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
|
345
261
|
errors.push(new InBlockPayloadValidationError5(payload._hash, block, payload, `validateTypedPayloadInBlock error: ${typedError}`, typedError));
|
|
346
262
|
}
|
|
347
263
|
} catch (ex) {
|
|
348
|
-
errors.push(new InBlockPayloadValidationError5(block?.[0]?._hash ??
|
|
264
|
+
errors.push(new InBlockPayloadValidationError5(block?.[0]?._hash ?? ZERO_HASH8, block, payload, `validation excepted: ${ex}`, ex));
|
|
349
265
|
}
|
|
350
266
|
return errors;
|
|
351
267
|
}, "validateHashInBlock");
|
|
352
268
|
|
|
353
269
|
// src/elevatedPayload/payloads/validateSchemaInBlock.ts
|
|
354
|
-
import { ZERO_HASH as
|
|
270
|
+
import { ZERO_HASH as ZERO_HASH9 } from "@xylabs/hex";
|
|
355
271
|
import { isSchemaPayload } from "@xyo-network/schema-payload-plugin";
|
|
356
272
|
import { InBlockPayloadValidationError as InBlockPayloadValidationError6 } from "@xyo-network/xl1-protocol";
|
|
357
273
|
var validateSchemaInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
@@ -362,13 +278,13 @@ var validateSchemaInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
|
362
278
|
errors.push(new InBlockPayloadValidationError6(payload._hash, block, payload, `validateTypedPayloadInBlock error: ${typedError}`, typedError));
|
|
363
279
|
}
|
|
364
280
|
} catch (ex) {
|
|
365
|
-
errors.push(new InBlockPayloadValidationError6(block?.[0]?._hash ??
|
|
281
|
+
errors.push(new InBlockPayloadValidationError6(block?.[0]?._hash ?? ZERO_HASH9, block, payload, `Failed validateSchemaInBlock: ${ex}`, ex));
|
|
366
282
|
}
|
|
367
283
|
return errors;
|
|
368
284
|
}, "validateSchemaInBlock");
|
|
369
285
|
|
|
370
286
|
// src/elevatedPayload/payloads/validateTransferInBlock.ts
|
|
371
|
-
import { ZERO_HASH as
|
|
287
|
+
import { ZERO_HASH as ZERO_HASH10 } from "@xylabs/hex";
|
|
372
288
|
import { InBlockPayloadValidationError as InBlockPayloadValidationError7, isTransfer } from "@xyo-network/xl1-protocol";
|
|
373
289
|
var validateTransferInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
374
290
|
const errors = [];
|
|
@@ -378,7 +294,7 @@ var validateTransferInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
|
378
294
|
errors.push(new InBlockPayloadValidationError7(payload._hash, block, payload, `validateTypedPayloadInBlock error: ${typedError}`, typedError));
|
|
379
295
|
}
|
|
380
296
|
} catch (ex) {
|
|
381
|
-
errors.push(new InBlockPayloadValidationError7(block?.[0]?._hash ??
|
|
297
|
+
errors.push(new InBlockPayloadValidationError7(block?.[0]?._hash ?? ZERO_HASH10, block, payload, `Failed validateTransferInBlock: ${ex}`, ex));
|
|
382
298
|
}
|
|
383
299
|
return errors;
|
|
384
300
|
}, "validateTransferInBlock");
|
|
@@ -398,10 +314,10 @@ var validatePayloadInBlock = /* @__PURE__ */ __name(async (payload, block) => {
|
|
|
398
314
|
if (validator) {
|
|
399
315
|
errors.push(...await validator(payload, block));
|
|
400
316
|
} else {
|
|
401
|
-
errors.push(new InBlockPayloadValidationError8(block?.[0]?._hash ??
|
|
317
|
+
errors.push(new InBlockPayloadValidationError8(block?.[0]?._hash ?? ZERO_HASH11, block, payload, `Unsupported payload schema: ${payload.schema}`));
|
|
402
318
|
}
|
|
403
319
|
} catch (ex) {
|
|
404
|
-
const error = new InBlockPayloadValidationError8(block?.[0]?._hash ??
|
|
320
|
+
const error = new InBlockPayloadValidationError8(block?.[0]?._hash ?? ZERO_HASH11, block, payload, `validation excepted: ${ex}`);
|
|
405
321
|
error.cause = ex;
|
|
406
322
|
errors.push(error);
|
|
407
323
|
}
|
|
@@ -429,27 +345,27 @@ var PayloadsInBlockValidator = /* @__PURE__ */ __name(async ([block, payloads])
|
|
|
429
345
|
payloads
|
|
430
346
|
]);
|
|
431
347
|
for (const payloadInBlockError of payloadInBlockErrors) {
|
|
432
|
-
errors.push(new HydratedBlockValidationError(block?._hash ??
|
|
348
|
+
errors.push(new HydratedBlockValidationError(block?._hash ?? ZERO_HASH12, [
|
|
433
349
|
block,
|
|
434
350
|
payloads
|
|
435
351
|
], `validatePayloadInBlock error: ${payloadInBlockError}`, payloadInBlockError));
|
|
436
352
|
}
|
|
437
353
|
delete remainingPayloads[hash];
|
|
438
354
|
} else {
|
|
439
|
-
errors.push(new HydratedBlockValidationError(block?._hash ??
|
|
355
|
+
errors.push(new HydratedBlockValidationError(block?._hash ?? ZERO_HASH12, [
|
|
440
356
|
block,
|
|
441
357
|
payloads
|
|
442
358
|
], `missing payload ${hash} ${schema}`));
|
|
443
359
|
}
|
|
444
360
|
}
|
|
445
361
|
if (Object.keys(remainingPayloads).length > 0) {
|
|
446
|
-
errors.push(new HydratedBlockValidationError(block?._hash ??
|
|
362
|
+
errors.push(new HydratedBlockValidationError(block?._hash ?? ZERO_HASH12, [
|
|
447
363
|
block,
|
|
448
364
|
payloads
|
|
449
365
|
], `extra payloads ${Object.keys(payloadMap).join(", ")}`));
|
|
450
366
|
}
|
|
451
367
|
} catch (ex) {
|
|
452
|
-
errors.push(new HydratedBlockValidationError(block?._hash ??
|
|
368
|
+
errors.push(new HydratedBlockValidationError(block?._hash ?? ZERO_HASH12, [
|
|
453
369
|
block,
|
|
454
370
|
payloads
|
|
455
371
|
], `Failed PayloadsInBlockValidator: ${ex}`, ex));
|
|
@@ -475,19 +391,18 @@ var validateHydratedBlock = /* @__PURE__ */ __name(async (hydratedBlock, chainId
|
|
|
475
391
|
];
|
|
476
392
|
errors.push(...(await Promise.all(validators.map((v) => v(hydratedBlock, chainId)))).flat());
|
|
477
393
|
} catch (ex) {
|
|
478
|
-
errors.push(new HydratedBlockValidationError2(hydratedBlock?.[0]?._hash ??
|
|
394
|
+
errors.push(new HydratedBlockValidationError2(hydratedBlock?.[0]?._hash ?? ZERO_HASH13, hydratedBlock, `Failed validateHydratedBlock: ${ex}`, ex));
|
|
479
395
|
}
|
|
480
396
|
return errors;
|
|
481
397
|
}, "validateHydratedBlock");
|
|
482
398
|
|
|
483
399
|
// src/hydratedBlockState/validateHydratedBlockState.ts
|
|
484
|
-
import { ZERO_HASH as
|
|
400
|
+
import { ZERO_HASH as ZERO_HASH15 } from "@xylabs/hex";
|
|
485
401
|
import { HydratedBlockStateValidationError as HydratedBlockStateValidationError2 } from "@xyo-network/xl1-protocol";
|
|
486
402
|
|
|
487
403
|
// src/hydratedBlockState/validators/RequiredBalance.ts
|
|
488
|
-
import { ZERO_HASH as
|
|
489
|
-
import { XYO_ZERO_ADDRESS } from "@xyo-network/
|
|
490
|
-
import { AttoXL1, HydratedBlockStateValidationError } from "@xyo-network/xl1-protocol";
|
|
404
|
+
import { ZERO_HASH as ZERO_HASH14 } from "@xylabs/hex";
|
|
405
|
+
import { AttoXL1, HydratedBlockStateValidationError, XYO_ZERO_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
491
406
|
import { netBalancesForPayloads } from "@xyo-network/xl1-protocol-sdk";
|
|
492
407
|
var RequiredBalanceBlockStateValidator = /* @__PURE__ */ __name(async (block, chainId, services) => {
|
|
493
408
|
const errors = [];
|
|
@@ -502,7 +417,7 @@ var RequiredBalanceBlockStateValidator = /* @__PURE__ */ __name(async (block, ch
|
|
|
502
417
|
}
|
|
503
418
|
const previous = block[0].previous;
|
|
504
419
|
if (previous === null) return [
|
|
505
|
-
new HydratedBlockStateValidationError(block?.[0]?._hash ??
|
|
420
|
+
new HydratedBlockStateValidationError(block?.[0]?._hash ?? ZERO_HASH14, chainId, block, "Insufficient funds because first block")
|
|
506
421
|
];
|
|
507
422
|
for (const [address, reqBalance] of Object.entries(requiredBalances)) {
|
|
508
423
|
const result = await services.accountBalance.balances(previous, [
|
|
@@ -510,11 +425,11 @@ var RequiredBalanceBlockStateValidator = /* @__PURE__ */ __name(async (block, ch
|
|
|
510
425
|
]);
|
|
511
426
|
const balance = result[address] ?? AttoXL1(0n);
|
|
512
427
|
if (address !== XYO_ZERO_ADDRESS && reqBalance > balance) {
|
|
513
|
-
errors.push(new HydratedBlockStateValidationError(block?.[0]?._hash ??
|
|
428
|
+
errors.push(new HydratedBlockStateValidationError(block?.[0]?._hash ?? ZERO_HASH14, chainId, block, `insufficient balance for ${address} ${balance} < ${requiredBalances[address]}`));
|
|
514
429
|
}
|
|
515
430
|
}
|
|
516
431
|
} catch (ex) {
|
|
517
|
-
errors.push(new HydratedBlockStateValidationError(block?.[0]?._hash ??
|
|
432
|
+
errors.push(new HydratedBlockStateValidationError(block?.[0]?._hash ?? ZERO_HASH14, chainId, block, `Failed RequiredBalanceBlockStateValidator: ${ex}`, ex));
|
|
518
433
|
}
|
|
519
434
|
return await Promise.resolve(errors);
|
|
520
435
|
}, "RequiredBalanceBlockStateValidator");
|
|
@@ -533,181 +448,15 @@ var validateHydratedBlockState = /* @__PURE__ */ __name(async (hydratedBlock, ch
|
|
|
533
448
|
];
|
|
534
449
|
errors.push(...(await Promise.all(validators.map((v) => v(hydratedBlock, chainId, services)))).flat());
|
|
535
450
|
} catch (ex) {
|
|
536
|
-
errors.push(new HydratedBlockStateValidationError2(hydratedBlock?.[0]?._hash ??
|
|
451
|
+
errors.push(new HydratedBlockStateValidationError2(hydratedBlock?.[0]?._hash ?? ZERO_HASH15, chainId, hydratedBlock, `Failed validateHydratedBlockState: ${ex}`, ex));
|
|
537
452
|
}
|
|
538
453
|
return errors;
|
|
539
454
|
}, "validateHydratedBlockState");
|
|
540
|
-
|
|
541
|
-
// src/transaction/validateTransaction.ts
|
|
542
|
-
import { isTransactionBoundWitness as isTransactionBoundWitness3 } from "@xyo-network/xl1-protocol";
|
|
543
|
-
|
|
544
|
-
// src/transaction/validators/TransactionDurationValidator.ts
|
|
545
|
-
import { ZERO_HASH as ZERO_HASH18 } from "@xylabs/hex";
|
|
546
|
-
import { HydratedTransactionValidationError } from "@xyo-network/xl1-protocol";
|
|
547
|
-
var TransactionDurationValidator = /* @__PURE__ */ __name((tx) => {
|
|
548
|
-
const errors = [];
|
|
549
|
-
try {
|
|
550
|
-
const { exp, nbf } = tx[0];
|
|
551
|
-
if (nbf < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH18, tx, "Transaction nbf must be positive"));
|
|
552
|
-
if (exp < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH18, tx, "Transaction exp must be positive"));
|
|
553
|
-
if (exp <= nbf) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH18, tx, "Transaction exp must greater than nbf"));
|
|
554
|
-
if (exp - nbf > 1e4) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH18, tx, "Transaction exp must not be too far in the future"));
|
|
555
|
-
} catch (ex) {
|
|
556
|
-
errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH18, tx, `Failed TransactionDurationValidator: ${ex}`, ex));
|
|
557
|
-
}
|
|
558
|
-
return errors;
|
|
559
|
-
}, "TransactionDurationValidator");
|
|
560
|
-
|
|
561
|
-
// src/transaction/validators/TransactionElevationValidator.ts
|
|
562
|
-
import { ZERO_HASH as ZERO_HASH19 } from "@xylabs/hex";
|
|
563
|
-
import { extractElevatedHashes } from "@xyo-network/chain-protocol";
|
|
564
|
-
import { HydratedTransactionValidationError as HydratedTransactionValidationError2 } from "@xyo-network/xl1-protocol";
|
|
565
|
-
var TransactionElevationValidator = /* @__PURE__ */ __name((tx) => {
|
|
566
|
-
const errors = [];
|
|
567
|
-
try {
|
|
568
|
-
try {
|
|
569
|
-
extractElevatedHashes(tx);
|
|
570
|
-
} catch {
|
|
571
|
-
errors.push(new HydratedTransactionValidationError2(tx?.[0]?._hash ?? ZERO_HASH19, tx, "Hydrated transaction does not include all script hashes"));
|
|
572
|
-
}
|
|
573
|
-
} catch (ex) {
|
|
574
|
-
errors.push(new HydratedTransactionValidationError2(tx?.[0]?._hash ?? ZERO_HASH19, tx, `Failed TransactionElevationValidator: ${ex}`, ex));
|
|
575
|
-
}
|
|
576
|
-
return errors;
|
|
577
|
-
}, "TransactionElevationValidator");
|
|
578
|
-
|
|
579
|
-
// src/transaction/validators/TransactionFromValidator.ts
|
|
580
|
-
import { asAddress, ZERO_HASH as ZERO_HASH20 } from "@xylabs/hex";
|
|
581
|
-
import { addressesContains } from "@xyo-network/boundwitness-validator";
|
|
582
|
-
import { HydratedTransactionValidationError as HydratedTransactionValidationError3 } from "@xyo-network/xl1-protocol";
|
|
583
|
-
var TransactionFromValidator = /* @__PURE__ */ __name((tx) => {
|
|
584
|
-
const errors = [];
|
|
585
|
-
try {
|
|
586
|
-
const from = asAddress(tx[0].from);
|
|
587
|
-
if (from === void 0) errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ?? ZERO_HASH20, tx, "Transaction from is not a valid address"));
|
|
588
|
-
else if (!addressesContains(tx[0], from)) errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ?? ZERO_HASH20, tx, "Transaction from address must be listed in addresses"));
|
|
589
|
-
} catch (ex) {
|
|
590
|
-
errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ?? ZERO_HASH20, tx, `Failed TransactionFromValidator: ${ex}`, ex));
|
|
591
|
-
}
|
|
592
|
-
return errors;
|
|
593
|
-
}, "TransactionFromValidator");
|
|
594
|
-
|
|
595
|
-
// src/transaction/validators/TransactionGasValidator.ts
|
|
596
|
-
import { hexToBigInt, ZERO_HASH as ZERO_HASH21 } from "@xylabs/hex";
|
|
597
|
-
import { AttoXL1 as AttoXL12, HydratedTransactionValidationError as HydratedTransactionValidationError4, minTransactionFees } from "@xyo-network/xl1-protocol";
|
|
598
|
-
var TransactionGasValidator = /* @__PURE__ */ __name((tx) => {
|
|
599
|
-
const errors = [];
|
|
600
|
-
try {
|
|
601
|
-
if (tx?.[0].fees === void 0) {
|
|
602
|
-
errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, "Missing fees"));
|
|
603
|
-
} else {
|
|
604
|
-
const { base, gasLimit, gasPrice, priority } = parseFees(tx[0].fees);
|
|
605
|
-
if (base === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, "fees.base must be defined and a valid number"));
|
|
606
|
-
else if (base < minTransactionFees.base) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, `fees.base must be >= ${minTransactionFees.base}`));
|
|
607
|
-
if (gasLimit === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, "fees.gasLimit must be defined and a valid number"));
|
|
608
|
-
else if (gasLimit < minTransactionFees.gasLimit) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, `fees.gasLimit must be >= ${minTransactionFees.gasLimit}`));
|
|
609
|
-
if (gasPrice === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, "fees.gasPrice must be defined and a valid number"));
|
|
610
|
-
else if (gasPrice < minTransactionFees.gasPrice) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, `fees.gasPrice must be >= ${minTransactionFees.gasPrice}`));
|
|
611
|
-
if (priority === void 0) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, "fees.priority must be defined and a valid number"));
|
|
612
|
-
else if (priority < minTransactionFees.priority) errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, `fees.priority must be >= ${minTransactionFees.priority}`));
|
|
613
|
-
}
|
|
614
|
-
} catch (ex) {
|
|
615
|
-
errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH21, tx, `Failed TransactionGasValidator: ${ex}`, ex));
|
|
616
|
-
}
|
|
617
|
-
return errors;
|
|
618
|
-
}, "TransactionGasValidator");
|
|
619
|
-
var parseFees = /* @__PURE__ */ __name((fees) => {
|
|
620
|
-
const ret = {};
|
|
621
|
-
const { base, gasLimit, gasPrice, priority } = fees;
|
|
622
|
-
if (base !== void 0) ret.base = AttoXL12(hexToBigInt(base));
|
|
623
|
-
if (gasLimit !== void 0) ret.gasLimit = AttoXL12(hexToBigInt(gasLimit));
|
|
624
|
-
if (gasPrice !== void 0) ret.gasPrice = AttoXL12(hexToBigInt(gasPrice));
|
|
625
|
-
if (priority !== void 0) ret.priority = AttoXL12(hexToBigInt(priority));
|
|
626
|
-
return ret;
|
|
627
|
-
}, "parseFees");
|
|
628
|
-
|
|
629
|
-
// src/transaction/validators/TransactionJsonSchemaValidator.ts
|
|
630
|
-
import { ZERO_HASH as ZERO_HASH22 } from "@xylabs/hex";
|
|
631
|
-
import { TransactionBoundWitnessJsonSchema } from "@xyo-network/chain-schema";
|
|
632
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
633
|
-
import { HydratedTransactionValidationError as HydratedTransactionValidationError5 } from "@xyo-network/xl1-protocol";
|
|
634
|
-
import { Ajv as Ajv2 } from "ajv";
|
|
635
|
-
var ajv = new Ajv2({
|
|
636
|
-
allErrors: true,
|
|
637
|
-
strict: true
|
|
638
|
-
});
|
|
639
|
-
var validate;
|
|
640
|
-
var TransactionJsonSchemaValidator = /* @__PURE__ */ __name((tx) => {
|
|
641
|
-
const errors = [];
|
|
642
|
-
try {
|
|
643
|
-
if (validate === void 0) validate = ajv.compile(TransactionBoundWitnessJsonSchema);
|
|
644
|
-
if (!validate(PayloadBuilder.omitStorageMeta(tx[0]))) {
|
|
645
|
-
const error = new HydratedTransactionValidationError5(tx?.[0]?._hash ?? ZERO_HASH22, tx, `failed JSON schema validation: ${ajv.errorsText(validate.errors, {
|
|
646
|
-
separator: "\n"
|
|
647
|
-
})}`);
|
|
648
|
-
error.cause = validate.errors;
|
|
649
|
-
errors.push(error);
|
|
650
|
-
}
|
|
651
|
-
} catch (ex) {
|
|
652
|
-
errors.push(new HydratedTransactionValidationError5(tx?.[0]?._hash ?? ZERO_HASH22, tx, "validation excepted", ex));
|
|
653
|
-
}
|
|
654
|
-
return errors;
|
|
655
|
-
}, "TransactionJsonSchemaValidator");
|
|
656
|
-
|
|
657
|
-
// src/transaction/validators/TransactionProtocolValidator.ts
|
|
658
|
-
import { ZERO_HASH as ZERO_HASH23 } from "@xylabs/hex";
|
|
659
|
-
import { HydratedTransactionValidationError as HydratedTransactionValidationError6 } from "@xyo-network/xl1-protocol";
|
|
660
|
-
var TransactionProtocolValidator = /* @__PURE__ */ __name(async (tx, chainId) => {
|
|
661
|
-
const errors = [];
|
|
662
|
-
try {
|
|
663
|
-
if (chainId !== void 0 && tx[0].chain !== chainId) {
|
|
664
|
-
errors.push(new HydratedTransactionValidationError6(tx?.[0]?._hash ?? ZERO_HASH23, tx, "invalid chain id"));
|
|
665
|
-
}
|
|
666
|
-
} catch (ex) {
|
|
667
|
-
errors.push(new HydratedTransactionValidationError6(tx?.[0]?._hash ?? ZERO_HASH23, tx, "validation excepted", ex));
|
|
668
|
-
}
|
|
669
|
-
return await Promise.resolve(errors);
|
|
670
|
-
}, "TransactionProtocolValidator");
|
|
671
|
-
|
|
672
|
-
// src/transaction/validateTransaction.ts
|
|
673
|
-
async function validateTransaction(tx, chainId, additionalValidators = []) {
|
|
674
|
-
try {
|
|
675
|
-
if (!isTransactionBoundWitness3(tx[0])) {
|
|
676
|
-
return [
|
|
677
|
-
new Error("failed isTransactionBoundWitness identity check")
|
|
678
|
-
];
|
|
679
|
-
}
|
|
680
|
-
const validators = [
|
|
681
|
-
TransactionProtocolValidator,
|
|
682
|
-
TransactionJsonSchemaValidator,
|
|
683
|
-
TransactionDurationValidator,
|
|
684
|
-
TransactionFromValidator,
|
|
685
|
-
TransactionGasValidator,
|
|
686
|
-
TransactionElevationValidator,
|
|
687
|
-
...additionalValidators
|
|
688
|
-
];
|
|
689
|
-
return (await Promise.all(validators.map((v) => v(tx, chainId)))).flat();
|
|
690
|
-
} catch (ex) {
|
|
691
|
-
return [
|
|
692
|
-
new Error(`Failed TransactionGasValidator: ${ex}`)
|
|
693
|
-
];
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
__name(validateTransaction, "validateTransaction");
|
|
697
455
|
export {
|
|
698
|
-
BoundWitnessReferencesValidator,
|
|
699
|
-
BoundWitnessSignaturesValidator,
|
|
700
456
|
PayloadsInBlockValidator,
|
|
701
457
|
RequiredBalanceBlockStateValidator,
|
|
702
|
-
TransactionDurationValidator,
|
|
703
|
-
TransactionElevationValidator,
|
|
704
|
-
TransactionFromValidator,
|
|
705
|
-
TransactionGasValidator,
|
|
706
|
-
TransactionJsonSchemaValidator,
|
|
707
|
-
TransactionProtocolValidator,
|
|
708
458
|
validateBlock,
|
|
709
459
|
validateHydratedBlock,
|
|
710
|
-
validateHydratedBlockState
|
|
711
|
-
validateTransaction
|
|
460
|
+
validateHydratedBlockState
|
|
712
461
|
};
|
|
713
462
|
//# sourceMappingURL=index.mjs.map
|