@xyo-network/xl1-validation 1.9.0 → 1.10.0
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 +136 -83
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +26 -27
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/boundwitness/validators/BoundWitnessReferences.ts
|
|
5
2
|
import { ZERO_HASH } from "@xylabs/hex";
|
|
6
3
|
import { isAnyPayload } from "@xyo-network/payload-model";
|
|
@@ -8,16 +5,12 @@ import { HydratedBoundWitnessValidationError } from "@xyo-network/xl1-protocol";
|
|
|
8
5
|
function getPayloadsFromPayloadArray(payloads, hashes) {
|
|
9
6
|
return hashes.map((hash) => payloads.find((payload) => payload._hash === hash || payload._dataHash === hash));
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
var BoundWitnessReferencesValidator = /* @__PURE__ */ __name((allowedSchemas) => ([bw, payloadSet]) => {
|
|
8
|
+
var BoundWitnessReferencesValidator = (allowedSchemas) => ([bw, payloadSet]) => {
|
|
13
9
|
const errors = [];
|
|
14
10
|
try {
|
|
15
11
|
const payloads = getPayloadsFromPayloadArray(payloadSet, bw.payload_hashes);
|
|
16
12
|
if (payloads.length !== bw.payload_hashes.length) {
|
|
17
|
-
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
18
|
-
bw,
|
|
19
|
-
payloadSet
|
|
20
|
-
], "unable to locate payloads"));
|
|
13
|
+
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], "unable to locate payloads"));
|
|
21
14
|
}
|
|
22
15
|
for (let payload of payloads) {
|
|
23
16
|
if (isAnyPayload(payload)) {
|
|
@@ -25,41 +18,26 @@ var BoundWitnessReferencesValidator = /* @__PURE__ */ __name((allowedSchemas) =>
|
|
|
25
18
|
const payloadDataHashIndex = bw.payload_hashes.indexOf(payload._dataHash);
|
|
26
19
|
const payloadIndex = Math.max(payloadHashIndex, payloadDataHashIndex);
|
|
27
20
|
if (payloadIndex === -1) {
|
|
28
|
-
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
29
|
-
bw,
|
|
30
|
-
payloadSet
|
|
31
|
-
], "payload hash not found"));
|
|
21
|
+
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], "payload hash not found"));
|
|
32
22
|
}
|
|
33
23
|
const declaredSchema = bw.payload_schemas[payloadIndex];
|
|
34
24
|
if (declaredSchema !== payload.schema) {
|
|
35
|
-
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
36
|
-
bw,
|
|
37
|
-
payloadSet
|
|
38
|
-
], "mismatched schema"));
|
|
25
|
+
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], "mismatched schema"));
|
|
39
26
|
}
|
|
40
27
|
if (allowedSchemas && !allowedSchemas.includes(payload.schema)) {
|
|
41
|
-
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
42
|
-
bw,
|
|
43
|
-
payloadSet
|
|
44
|
-
], `disallowed schema [${payload.schema}]`));
|
|
28
|
+
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], `disallowed schema [${payload.schema}]`));
|
|
45
29
|
}
|
|
46
30
|
} else {
|
|
47
|
-
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
48
|
-
bw,
|
|
49
|
-
payloadSet
|
|
50
|
-
], "invalid payload"));
|
|
31
|
+
errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], "invalid payload"));
|
|
51
32
|
}
|
|
52
33
|
}
|
|
53
34
|
} catch (ex) {
|
|
54
|
-
const error = new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [
|
|
55
|
-
bw,
|
|
56
|
-
payloadSet
|
|
57
|
-
], `validation excepted: ${ex}`);
|
|
35
|
+
const error = new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], `validation excepted: ${ex}`);
|
|
58
36
|
error.cause = ex;
|
|
59
37
|
errors.push(error);
|
|
60
38
|
}
|
|
61
39
|
return errors;
|
|
62
|
-
}
|
|
40
|
+
};
|
|
63
41
|
|
|
64
42
|
// src/boundwitness/validators/BoundWitnessSignatures.ts
|
|
65
43
|
import { toArrayBuffer } from "@xylabs/arraybuffer";
|
|
@@ -67,15 +45,12 @@ import { ZERO_HASH as ZERO_HASH2 } from "@xylabs/hex";
|
|
|
67
45
|
import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
|
|
68
46
|
import { BoundWitnessValidator } from "@xyo-network/boundwitness-validator";
|
|
69
47
|
import { BoundWitnessValidationError } from "@xyo-network/xl1-protocol";
|
|
70
|
-
var BoundWitnessSignaturesValidator =
|
|
48
|
+
var BoundWitnessSignaturesValidator = async (bw) => {
|
|
71
49
|
const errors = [];
|
|
72
50
|
try {
|
|
73
51
|
const dataHash = await BoundWitnessBuilder.dataHash(bw);
|
|
74
52
|
const results = await Promise.all(bw.addresses.map(async (address, index) => {
|
|
75
|
-
return [
|
|
76
|
-
address,
|
|
77
|
-
await BoundWitnessValidator.validateSignature(toArrayBuffer(dataHash), toArrayBuffer(address), toArrayBuffer(bw.$signatures[index]))
|
|
78
|
-
];
|
|
53
|
+
return [address, await BoundWitnessValidator.validateSignature(toArrayBuffer(dataHash), toArrayBuffer(address), toArrayBuffer(bw.$signatures[index]))];
|
|
79
54
|
}));
|
|
80
55
|
for (const [, bwErrors] of results) {
|
|
81
56
|
for (const bwError of bwErrors) {
|
|
@@ -86,7 +61,7 @@ var BoundWitnessSignaturesValidator = /* @__PURE__ */ __name(async (bw) => {
|
|
|
86
61
|
errors.push(new BoundWitnessValidationError(bw?._hash ?? ZERO_HASH2, bw, "validation excepted", ex));
|
|
87
62
|
}
|
|
88
63
|
return errors;
|
|
89
|
-
}
|
|
64
|
+
};
|
|
90
65
|
|
|
91
66
|
// src/transaction/validateTransaction.ts
|
|
92
67
|
import { isTransactionBoundWitness } from "@xyo-network/xl1-protocol";
|
|
@@ -94,25 +69,34 @@ import { isTransactionBoundWitness } from "@xyo-network/xl1-protocol";
|
|
|
94
69
|
// src/transaction/validators/TransactionDurationValidator.ts
|
|
95
70
|
import { ZERO_HASH as ZERO_HASH3 } from "@xylabs/hex";
|
|
96
71
|
import { HydratedTransactionValidationError } from "@xyo-network/xl1-protocol";
|
|
97
|
-
var TransactionDurationValidator =
|
|
72
|
+
var TransactionDurationValidator = (tx) => {
|
|
98
73
|
const errors = [];
|
|
99
74
|
try {
|
|
100
75
|
const { exp, nbf } = tx[0];
|
|
101
76
|
if (nbf < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH3, tx, "Transaction nbf must be positive"));
|
|
102
77
|
if (exp < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH3, tx, "Transaction exp must be positive"));
|
|
103
78
|
if (exp <= nbf) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH3, tx, "Transaction exp must greater than nbf"));
|
|
104
|
-
if (exp - nbf > 1e4) errors.push(new HydratedTransactionValidationError(
|
|
79
|
+
if (exp - nbf > 1e4) errors.push(new HydratedTransactionValidationError(
|
|
80
|
+
tx?.[0]?._hash ?? ZERO_HASH3,
|
|
81
|
+
tx,
|
|
82
|
+
"Transaction exp must not be too far in the future"
|
|
83
|
+
));
|
|
105
84
|
} catch (ex) {
|
|
106
|
-
errors.push(new HydratedTransactionValidationError(
|
|
85
|
+
errors.push(new HydratedTransactionValidationError(
|
|
86
|
+
tx?.[0]?._hash ?? ZERO_HASH3,
|
|
87
|
+
tx,
|
|
88
|
+
`Failed TransactionDurationValidator: ${ex}`,
|
|
89
|
+
ex
|
|
90
|
+
));
|
|
107
91
|
}
|
|
108
92
|
return errors;
|
|
109
|
-
}
|
|
93
|
+
};
|
|
110
94
|
|
|
111
95
|
// src/transaction/validators/TransactionElevationValidator.ts
|
|
112
96
|
import { ZERO_HASH as ZERO_HASH4 } from "@xylabs/hex";
|
|
113
97
|
import { HydratedTransactionValidationError as HydratedTransactionValidationError2 } from "@xyo-network/xl1-protocol";
|
|
114
98
|
import { extractElevatedHashes } from "@xyo-network/xl1-protocol-sdk";
|
|
115
|
-
var TransactionElevationValidator =
|
|
99
|
+
var TransactionElevationValidator = (tx) => {
|
|
116
100
|
const errors = [];
|
|
117
101
|
try {
|
|
118
102
|
try {
|
|
@@ -121,60 +105,135 @@ var TransactionElevationValidator = /* @__PURE__ */ __name((tx) => {
|
|
|
121
105
|
errors.push(new HydratedTransactionValidationError2(tx?.[0]?._hash ?? ZERO_HASH4, tx, "Hydrated transaction does not include all script hashes"));
|
|
122
106
|
}
|
|
123
107
|
} catch (ex) {
|
|
124
|
-
errors.push(new HydratedTransactionValidationError2(
|
|
108
|
+
errors.push(new HydratedTransactionValidationError2(
|
|
109
|
+
tx?.[0]?._hash ?? ZERO_HASH4,
|
|
110
|
+
tx,
|
|
111
|
+
`Failed TransactionElevationValidator: ${ex}`,
|
|
112
|
+
ex
|
|
113
|
+
));
|
|
125
114
|
}
|
|
126
115
|
return errors;
|
|
127
|
-
}
|
|
116
|
+
};
|
|
128
117
|
|
|
129
118
|
// src/transaction/validators/TransactionFromValidator.ts
|
|
130
119
|
import { asAddress, ZERO_HASH as ZERO_HASH5 } from "@xylabs/hex";
|
|
131
120
|
import { addressesContains } from "@xyo-network/boundwitness-validator";
|
|
132
121
|
import { HydratedTransactionValidationError as HydratedTransactionValidationError3 } from "@xyo-network/xl1-protocol";
|
|
133
|
-
var TransactionFromValidator =
|
|
122
|
+
var TransactionFromValidator = (tx) => {
|
|
134
123
|
const errors = [];
|
|
135
124
|
try {
|
|
136
125
|
const from = asAddress(tx[0].from);
|
|
137
|
-
if (from === void 0) errors.push(new HydratedTransactionValidationError3(
|
|
138
|
-
|
|
126
|
+
if (from === void 0) errors.push(new HydratedTransactionValidationError3(
|
|
127
|
+
tx?.[0]?._hash ?? ZERO_HASH5,
|
|
128
|
+
tx,
|
|
129
|
+
"Transaction from is not a valid address"
|
|
130
|
+
));
|
|
131
|
+
else if (!addressesContains(tx[0], from)) errors.push(new HydratedTransactionValidationError3(
|
|
132
|
+
tx?.[0]?._hash ?? ZERO_HASH5,
|
|
133
|
+
tx,
|
|
134
|
+
"Transaction from address must be listed in addresses"
|
|
135
|
+
));
|
|
139
136
|
} catch (ex) {
|
|
140
|
-
errors.push(new HydratedTransactionValidationError3(
|
|
137
|
+
errors.push(new HydratedTransactionValidationError3(
|
|
138
|
+
tx?.[0]?._hash ?? ZERO_HASH5,
|
|
139
|
+
tx,
|
|
140
|
+
`Failed TransactionFromValidator: ${ex}`,
|
|
141
|
+
ex
|
|
142
|
+
));
|
|
141
143
|
}
|
|
142
144
|
return errors;
|
|
143
|
-
}
|
|
145
|
+
};
|
|
144
146
|
|
|
145
147
|
// src/transaction/validators/TransactionGasValidator.ts
|
|
146
148
|
import { hexToBigInt, ZERO_HASH as ZERO_HASH6 } from "@xylabs/hex";
|
|
147
|
-
import {
|
|
148
|
-
|
|
149
|
+
import {
|
|
150
|
+
AttoXL1,
|
|
151
|
+
HydratedTransactionValidationError as HydratedTransactionValidationError4,
|
|
152
|
+
minTransactionFees
|
|
153
|
+
} from "@xyo-network/xl1-protocol";
|
|
154
|
+
var TransactionGasValidator = (tx) => {
|
|
149
155
|
const errors = [];
|
|
150
156
|
try {
|
|
151
157
|
if (tx?.[0].fees === void 0) {
|
|
152
|
-
errors.push(new HydratedTransactionValidationError4(
|
|
158
|
+
errors.push(new HydratedTransactionValidationError4(
|
|
159
|
+
tx?.[0]?._hash ?? ZERO_HASH6,
|
|
160
|
+
tx,
|
|
161
|
+
"Missing fees"
|
|
162
|
+
));
|
|
153
163
|
} else {
|
|
154
|
-
const {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
const {
|
|
165
|
+
base,
|
|
166
|
+
gasLimit,
|
|
167
|
+
gasPrice,
|
|
168
|
+
priority
|
|
169
|
+
} = parseFees(tx[0].fees);
|
|
170
|
+
if (base === void 0) errors.push(new HydratedTransactionValidationError4(
|
|
171
|
+
tx?.[0]?._hash ?? ZERO_HASH6,
|
|
172
|
+
tx,
|
|
173
|
+
"fees.base must be defined and a valid number"
|
|
174
|
+
));
|
|
175
|
+
else if (base < minTransactionFees.base) errors.push(new HydratedTransactionValidationError4(
|
|
176
|
+
tx?.[0]?._hash ?? ZERO_HASH6,
|
|
177
|
+
tx,
|
|
178
|
+
`fees.base must be >= ${minTransactionFees.base}`
|
|
179
|
+
));
|
|
180
|
+
if (gasLimit === void 0) errors.push(new HydratedTransactionValidationError4(
|
|
181
|
+
tx?.[0]?._hash ?? ZERO_HASH6,
|
|
182
|
+
tx,
|
|
183
|
+
"fees.gasLimit must be defined and a valid number"
|
|
184
|
+
));
|
|
185
|
+
else if (gasLimit < minTransactionFees.gasLimit) errors.push(new HydratedTransactionValidationError4(
|
|
186
|
+
tx?.[0]?._hash ?? ZERO_HASH6,
|
|
187
|
+
tx,
|
|
188
|
+
`fees.gasLimit must be >= ${minTransactionFees.gasLimit}`
|
|
189
|
+
));
|
|
190
|
+
if (gasPrice === void 0) errors.push(
|
|
191
|
+
new HydratedTransactionValidationError4(
|
|
192
|
+
tx?.[0]?._hash ?? ZERO_HASH6,
|
|
193
|
+
tx,
|
|
194
|
+
"fees.gasPrice must be defined and a valid number"
|
|
195
|
+
)
|
|
196
|
+
);
|
|
197
|
+
else if (gasPrice < minTransactionFees.gasPrice) errors.push(new HydratedTransactionValidationError4(
|
|
198
|
+
tx?.[0]?._hash ?? ZERO_HASH6,
|
|
199
|
+
tx,
|
|
200
|
+
`fees.gasPrice must be >= ${minTransactionFees.gasPrice}`
|
|
201
|
+
));
|
|
202
|
+
if (priority === void 0) errors.push(new HydratedTransactionValidationError4(
|
|
203
|
+
tx?.[0]?._hash ?? ZERO_HASH6,
|
|
204
|
+
tx,
|
|
205
|
+
"fees.priority must be defined and a valid number"
|
|
206
|
+
));
|
|
207
|
+
else if (priority < minTransactionFees.priority) errors.push(new HydratedTransactionValidationError4(
|
|
208
|
+
tx?.[0]?._hash ?? ZERO_HASH6,
|
|
209
|
+
tx,
|
|
210
|
+
`fees.priority must be >= ${minTransactionFees.priority}`
|
|
211
|
+
));
|
|
163
212
|
}
|
|
164
213
|
} catch (ex) {
|
|
165
|
-
errors.push(new HydratedTransactionValidationError4(
|
|
214
|
+
errors.push(new HydratedTransactionValidationError4(
|
|
215
|
+
tx?.[0]?._hash ?? ZERO_HASH6,
|
|
216
|
+
tx,
|
|
217
|
+
`Failed TransactionGasValidator: ${ex}`,
|
|
218
|
+
ex
|
|
219
|
+
));
|
|
166
220
|
}
|
|
167
221
|
return errors;
|
|
168
|
-
}
|
|
169
|
-
var parseFees =
|
|
222
|
+
};
|
|
223
|
+
var parseFees = (fees) => {
|
|
170
224
|
const ret = {};
|
|
171
|
-
const {
|
|
225
|
+
const {
|
|
226
|
+
base,
|
|
227
|
+
gasLimit,
|
|
228
|
+
gasPrice,
|
|
229
|
+
priority
|
|
230
|
+
} = fees;
|
|
172
231
|
if (base !== void 0) ret.base = AttoXL1(hexToBigInt(base));
|
|
173
232
|
if (gasLimit !== void 0) ret.gasLimit = AttoXL1(hexToBigInt(gasLimit));
|
|
174
233
|
if (gasPrice !== void 0) ret.gasPrice = AttoXL1(hexToBigInt(gasPrice));
|
|
175
234
|
if (priority !== void 0) ret.priority = AttoXL1(hexToBigInt(priority));
|
|
176
235
|
return ret;
|
|
177
|
-
}
|
|
236
|
+
};
|
|
178
237
|
|
|
179
238
|
// src/transaction/validators/TransactionJsonSchemaValidator.ts
|
|
180
239
|
import { ZERO_HASH as ZERO_HASH7 } from "@xylabs/hex";
|
|
@@ -182,19 +241,18 @@ import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
|
182
241
|
import { HydratedTransactionValidationError as HydratedTransactionValidationError5 } from "@xyo-network/xl1-protocol";
|
|
183
242
|
import { TransactionBoundWitnessJsonSchema } from "@xyo-network/xl1-schema";
|
|
184
243
|
import { Ajv } from "ajv";
|
|
185
|
-
var ajv = new Ajv({
|
|
186
|
-
allErrors: true,
|
|
187
|
-
strict: true
|
|
188
|
-
});
|
|
244
|
+
var ajv = new Ajv({ allErrors: true, strict: true });
|
|
189
245
|
var validate;
|
|
190
|
-
var TransactionJsonSchemaValidator =
|
|
246
|
+
var TransactionJsonSchemaValidator = (tx) => {
|
|
191
247
|
const errors = [];
|
|
192
248
|
try {
|
|
193
249
|
if (validate === void 0) validate = ajv.compile(TransactionBoundWitnessJsonSchema);
|
|
194
250
|
if (!validate(PayloadBuilder.omitStorageMeta(tx[0]))) {
|
|
195
|
-
const error = new HydratedTransactionValidationError5(
|
|
196
|
-
|
|
197
|
-
|
|
251
|
+
const error = new HydratedTransactionValidationError5(
|
|
252
|
+
tx?.[0]?._hash ?? ZERO_HASH7,
|
|
253
|
+
tx,
|
|
254
|
+
`failed JSON schema validation: ${ajv.errorsText(validate.errors, { separator: "\n" })}`
|
|
255
|
+
);
|
|
198
256
|
error.cause = validate.errors;
|
|
199
257
|
errors.push(error);
|
|
200
258
|
}
|
|
@@ -202,12 +260,12 @@ var TransactionJsonSchemaValidator = /* @__PURE__ */ __name((tx) => {
|
|
|
202
260
|
errors.push(new HydratedTransactionValidationError5(tx?.[0]?._hash ?? ZERO_HASH7, tx, "validation excepted", ex));
|
|
203
261
|
}
|
|
204
262
|
return errors;
|
|
205
|
-
}
|
|
263
|
+
};
|
|
206
264
|
|
|
207
265
|
// src/transaction/validators/TransactionProtocolValidator.ts
|
|
208
266
|
import { ZERO_HASH as ZERO_HASH8 } from "@xylabs/hex";
|
|
209
267
|
import { HydratedTransactionValidationError as HydratedTransactionValidationError6 } from "@xyo-network/xl1-protocol";
|
|
210
|
-
var TransactionProtocolValidator =
|
|
268
|
+
var TransactionProtocolValidator = async (tx, chainId) => {
|
|
211
269
|
const errors = [];
|
|
212
270
|
try {
|
|
213
271
|
if (chainId !== void 0 && tx[0].chain !== chainId) {
|
|
@@ -217,15 +275,13 @@ var TransactionProtocolValidator = /* @__PURE__ */ __name(async (tx, chainId) =>
|
|
|
217
275
|
errors.push(new HydratedTransactionValidationError6(tx?.[0]?._hash ?? ZERO_HASH8, tx, "validation excepted", ex));
|
|
218
276
|
}
|
|
219
277
|
return await Promise.resolve(errors);
|
|
220
|
-
}
|
|
278
|
+
};
|
|
221
279
|
|
|
222
280
|
// src/transaction/validateTransaction.ts
|
|
223
281
|
async function validateTransaction(tx, chainId, additionalValidators = []) {
|
|
224
282
|
try {
|
|
225
283
|
if (!isTransactionBoundWitness(tx[0])) {
|
|
226
|
-
return [
|
|
227
|
-
new Error("failed isTransactionBoundWitness identity check")
|
|
228
|
-
];
|
|
284
|
+
return [new Error("failed isTransactionBoundWitness identity check")];
|
|
229
285
|
}
|
|
230
286
|
const validators = [
|
|
231
287
|
TransactionProtocolValidator,
|
|
@@ -237,12 +293,9 @@ async function validateTransaction(tx, chainId, additionalValidators = []) {
|
|
|
237
293
|
];
|
|
238
294
|
return (await Promise.all(validators.map((v) => v(tx, chainId)))).flat();
|
|
239
295
|
} catch (ex) {
|
|
240
|
-
return [
|
|
241
|
-
new Error(`Failed TransactionGasValidator: ${ex}`)
|
|
242
|
-
];
|
|
296
|
+
return [new Error(`Failed TransactionGasValidator: ${ex}`)];
|
|
243
297
|
}
|
|
244
298
|
}
|
|
245
|
-
__name(validateTransaction, "validateTransaction");
|
|
246
299
|
export {
|
|
247
300
|
BoundWitnessReferencesValidator,
|
|
248
301
|
BoundWitnessSignaturesValidator,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/boundwitness/validators/BoundWitnessReferences.ts","../../src/boundwitness/validators/BoundWitnessSignatures.ts","../../src/transaction/validateTransaction.ts","../../src/transaction/validators/TransactionDurationValidator.ts","../../src/transaction/validators/TransactionElevationValidator.ts","../../src/transaction/validators/TransactionFromValidator.ts","../../src/transaction/validators/TransactionGasValidator.ts","../../src/transaction/validators/TransactionJsonSchemaValidator.ts","../../src/transaction/validators/TransactionProtocolValidator.ts"],"sourcesContent":["import { type Hash, ZERO_HASH } from '@xylabs/hex'\nimport type { Promisable } from '@xylabs/promise'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport type {\n Payload,\n Schema,\n WithHashStorageMeta,\n} from '@xyo-network/payload-model'\nimport { isAnyPayload } from '@xyo-network/payload-model'\nimport type { HydratedBoundWitnessValidationFunction, HydratedBoundWitnessWithHashStorageMeta } from '@xyo-network/xl1-protocol'\nimport { HydratedBoundWitnessValidationError } from '@xyo-network/xl1-protocol'\n\nfunction getPayloadsFromPayloadArray(payloads: WithHashStorageMeta<Payload>[], hashes: Hash[]): (WithHashStorageMeta<Payload> | undefined)[] {\n return hashes.map(hash => payloads.find(payload => payload._hash === hash || payload._dataHash === hash))\n}\n\nexport const BoundWitnessReferencesValidator\n// eslint-disable-next-line complexity\n= <T extends BoundWitness = BoundWitness>(allowedSchemas?: Schema[]): HydratedBoundWitnessValidationFunction<T> => (\n [bw, payloadSet]: HydratedBoundWitnessWithHashStorageMeta<T>,\n): Promisable<HydratedBoundWitnessValidationError[]> => {\n const errors: HydratedBoundWitnessValidationError[] = []\n try {\n const payloads = getPayloadsFromPayloadArray(payloadSet, bw.payload_hashes)\n if (payloads.length !== bw.payload_hashes.length) {\n errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'unable to locate payloads'))\n }\n\n // check if payloads are valid and if their schemas match the declared schemas\n for (let payload of payloads) {\n if (isAnyPayload(payload)) {\n const payloadHashIndex = bw.payload_hashes.indexOf(payload._hash)\n const payloadDataHashIndex = bw.payload_hashes.indexOf(payload._dataHash)\n const payloadIndex = Math.max(payloadHashIndex, payloadDataHashIndex)\n if (payloadIndex === -1) {\n errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'payload hash not found'))\n }\n\n const declaredSchema = bw.payload_schemas[payloadIndex]\n if (declaredSchema !== payload.schema) {\n errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'mismatched schema'))\n }\n\n if (allowedSchemas && !allowedSchemas.includes(payload.schema)) {\n errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], `disallowed schema [${payload.schema}]`))\n }\n } else {\n errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'invalid payload'))\n }\n }\n } catch (ex) {\n const error = new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], `validation excepted: ${ex}`)\n error.cause = ex\n errors.push(error)\n }\n return errors\n}\n","import { toArrayBuffer } from '@xylabs/arraybuffer'\nimport { type Address, ZERO_HASH } from '@xylabs/hex'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'\nimport type { WithStorageMeta } from '@xyo-network/payload-model'\nimport type { BoundWitnessValidationFunction } from '@xyo-network/xl1-protocol'\nimport { BoundWitnessValidationError } from '@xyo-network/xl1-protocol'\n\nexport const BoundWitnessSignaturesValidator: BoundWitnessValidationFunction = async (\n bw: BoundWitness,\n) => {\n const errors: BoundWitnessValidationError[] = []\n try {\n const dataHash = await BoundWitnessBuilder.dataHash(bw)\n const results: [Address, Error[]][] = await Promise.all(bw.addresses.map(async (address, index) => {\n return [address, await BoundWitnessValidator.validateSignature(toArrayBuffer(dataHash), toArrayBuffer(address), toArrayBuffer(bw.$signatures[index]))]\n }))\n for (const [, bwErrors] of results) {\n for (const bwError of bwErrors) {\n errors.push(new BoundWitnessValidationError((bw as WithStorageMeta<BoundWitness>)?._hash ?? ZERO_HASH, bw, 'validation errors', bwError))\n }\n }\n } catch (ex) {\n errors.push(new BoundWitnessValidationError((bw as WithStorageMeta<BoundWitness>)?._hash ?? ZERO_HASH, bw, 'validation excepted', ex))\n }\n return errors\n}\n","import type { Address } from '@xylabs/hex'\nimport type { HydratedTransaction, HydratedTransactionValidationFunction } from '@xyo-network/xl1-protocol'\nimport { isTransactionBoundWitness } from '@xyo-network/xl1-protocol'\n\nimport {\n TransactionDurationValidator,\n TransactionElevationValidator, TransactionFromValidator, TransactionGasValidator, TransactionProtocolValidator,\n} from './validators/index.ts'\n\nexport async function validateTransaction(\n tx: HydratedTransaction,\n chainId?: Address,\n additionalValidators: HydratedTransactionValidationFunction[] = [],\n) {\n try {\n if (!isTransactionBoundWitness(tx[0])) {\n return [new Error('failed isTransactionBoundWitness identity check')]\n }\n\n const validators: HydratedTransactionValidationFunction[] = [\n TransactionProtocolValidator,\n TransactionDurationValidator,\n TransactionFromValidator,\n TransactionGasValidator,\n TransactionElevationValidator,\n ...additionalValidators,\n ]\n return (await Promise.all(validators.map(v => v(tx, chainId)))).flat()\n } catch (ex) {\n return [(new Error(`Failed TransactionGasValidator: ${ex}`))]\n }\n}\n","import { ZERO_HASH } from '@xylabs/hex'\nimport type {\n HydratedTransaction, HydratedTransactionValidationFunction, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\n// eslint-disable-next-line complexity\nexport const TransactionDurationValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransaction,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n const { exp, nbf } = tx[0]\n if (nbf < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'Transaction nbf must be positive'))\n\n if (exp < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'Transaction exp must be positive'))\n if (exp <= nbf) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'Transaction exp must greater than nbf'))\n if (exp - nbf > 10_000) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'Transaction exp must not be too far in the future',\n ))\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `Failed TransactionDurationValidator: ${ex}`,\n ex,\n ))\n }\n\n return errors\n}\n","import { ZERO_HASH } from '@xylabs/hex'\nimport type {\n HydratedTransaction, HydratedTransactionValidationFunction, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\nimport { extractElevatedHashes } from '@xyo-network/xl1-protocol-sdk'\n\nexport const TransactionElevationValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransaction,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n try {\n extractElevatedHashes(tx)\n } catch {\n errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'Hydrated transaction does not include all script hashes'))\n }\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `Failed TransactionElevationValidator: ${ex}`,\n ex,\n ))\n }\n return errors\n}\n","import { asAddress, ZERO_HASH } from '@xylabs/hex'\nimport { addressesContains } from '@xyo-network/boundwitness-validator'\nimport type {\n HydratedTransaction, HydratedTransactionValidationFunction, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\nexport const TransactionFromValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransaction,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n const from = asAddress(tx[0].from)\n if (from === undefined)errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'Transaction from is not a valid address',\n ))\n else if (!addressesContains(tx[0], from)) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'Transaction from address must be listed in addresses',\n ))\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `Failed TransactionFromValidator: ${ex}`,\n ex,\n ))\n }\n return errors\n}\n","import { hexToBigInt, ZERO_HASH } from '@xylabs/hex'\nimport type {\n HydratedTransaction,\n HydratedTransactionValidationFunction,\n TransactionBoundWitness, TransactionFeesBigInt, TransactionFeesHex,\n} from '@xyo-network/xl1-protocol'\nimport {\n AttoXL1,\n HydratedTransactionValidationError,\n minTransactionFees,\n} from '@xyo-network/xl1-protocol'\n\n// eslint-disable-next-line complexity\nexport const TransactionGasValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransaction,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n if (tx?.[0].fees === undefined) {\n errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'Missing fees',\n ))\n } else {\n const {\n base, gasLimit, gasPrice, priority,\n } = parseFees(tx[0].fees)\n\n if (base === undefined) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'fees.base must be defined and a valid number',\n ))\n else if (base < minTransactionFees.base) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `fees.base must be >= ${minTransactionFees.base}`,\n ))\n\n if (gasLimit === undefined) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'fees.gasLimit must be defined and a valid number',\n ))\n else if (gasLimit < minTransactionFees.gasLimit) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `fees.gasLimit must be >= ${minTransactionFees.gasLimit}`,\n ))\n\n if (gasPrice === undefined) errors.push(\n new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'fees.gasPrice must be defined and a valid number',\n ),\n )\n else if (gasPrice < minTransactionFees.gasPrice) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `fees.gasPrice must be >= ${minTransactionFees.gasPrice}`,\n ))\n\n if (priority === undefined) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'fees.priority must be defined and a valid number',\n ))\n else if (priority < minTransactionFees.priority) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `fees.priority must be >= ${minTransactionFees.priority}`,\n ))\n }\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `Failed TransactionGasValidator: ${ex}`,\n ex,\n ))\n }\n return errors\n}\n\nconst parseFees = (fees: TransactionFeesHex): Partial<TransactionFeesBigInt> => {\n const ret: Partial<TransactionFeesBigInt> = {}\n const {\n base, gasLimit, gasPrice, priority,\n } = fees\n if (base !== undefined) ret.base = AttoXL1(hexToBigInt(base))\n if (gasLimit !== undefined) ret.gasLimit = AttoXL1(hexToBigInt(gasLimit))\n if (gasPrice !== undefined) ret.gasPrice = AttoXL1(hexToBigInt(gasPrice))\n if (priority !== undefined) ret.priority = AttoXL1(hexToBigInt(priority))\n return ret\n}\n","import { ZERO_HASH } from '@xylabs/hex'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type {\n HydratedTransaction, HydratedTransactionValidationFunction, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\nimport { TransactionBoundWitnessJsonSchema } from '@xyo-network/xl1-schema'\nimport type { ValidateFunction } from 'ajv'\nimport { Ajv } from 'ajv'\n\nconst ajv = new Ajv({ allErrors: true, strict: true })\n\nlet validate: ValidateFunction<TransactionBoundWitness> | undefined\n\nexport const TransactionJsonSchemaValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransaction,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n if (validate === undefined) validate = ajv.compile(TransactionBoundWitnessJsonSchema)\n if (!validate(PayloadBuilder.omitStorageMeta(tx[0]))) {\n const error = new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `failed JSON schema validation: ${ajv.errorsText(validate.errors, { separator: '\\n' })}`,\n )\n error.cause = validate.errors\n errors.push(error)\n }\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'validation excepted', ex))\n }\n return errors\n}\n","import { type Address, ZERO_HASH } from '@xylabs/hex'\nimport type {\n HydratedTransaction, HydratedTransactionValidationFunction, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\nexport const TransactionProtocolValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = async (\n tx: HydratedTransaction,\n chainId?: Address,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n if (chainId !== undefined && tx[0].chain !== chainId) {\n errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'invalid chain id'))\n }\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'validation excepted', ex))\n }\n return await Promise.resolve(errors)\n}\n"],"mappings":";;;;AAAA,SAAoBA,iBAAiB;AAQrC,SAASC,oBAAoB;AAE7B,SAASC,2CAA2C;AAEpD,SAASC,4BAA4BC,UAA0CC,QAAc;AAC3F,SAAOA,OAAOC,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5G,eAAsBU,oBACpBC,IACAC,SACAC,uBAAgE,CAAA,GAAE;AAElE,MAAI;AACF,QAAI,CAACC,0BAA0BH,GAAG,CAAA,CAAE,GAAG;AACrC,aAAO;QAAC,IAAII,MAAM,iDAAA;;IACpB;AAEA,UAAMC,aAAsD;MAC1DC;MACAC;MACAC;MACAC;MACAC;SACGR;;AAEL,YAAQ,MAAMS,QAAQC,IAAIP,WAAWQ,IAAIC,CAAAA,MAAKA,EAAEd,IAAIC,OAAAA,CAAAA,CAAAA,GAAYc,KAAI;EACtE,SAASC,IAAI;AACX,WAAO;MAAE,IAAIZ,MAAM,mCAAmCY,EAAAA,EAAI;;EAC5D;AACF;AAtBsBjB;","names":["ZERO_HASH","isAnyPayload","HydratedBoundWitnessValidationError","getPayloadsFromPayloadArray","payloads","hashes","map","hash","find","payload","_hash","_dataHash","BoundWitnessReferencesValidator","allowedSchemas","bw","payloadSet","errors","payload_hashes","length","push","HydratedBoundWitnessValidationError","ZERO_HASH","isAnyPayload","payloadHashIndex","indexOf","payloadDataHashIndex","payloadIndex","Math","max","declaredSchema","payload_schemas","schema","includes","ex","error","cause","toArrayBuffer","ZERO_HASH","BoundWitnessBuilder","BoundWitnessValidator","BoundWitnessValidationError","BoundWitnessSignaturesValidator","bw","errors","dataHash","BoundWitnessBuilder","results","Promise","all","addresses","map","address","index","BoundWitnessValidator","validateSignature","toArrayBuffer","$signatures","bwErrors","bwError","push","BoundWitnessValidationError","_hash","ZERO_HASH","ex","isTransactionBoundWitness","ZERO_HASH","HydratedTransactionValidationError","TransactionDurationValidator","tx","errors","exp","nbf","push","HydratedTransactionValidationError","_hash","ZERO_HASH","ex","ZERO_HASH","HydratedTransactionValidationError","extractElevatedHashes","TransactionElevationValidator","tx","errors","extractElevatedHashes","push","HydratedTransactionValidationError","_hash","ZERO_HASH","ex","asAddress","ZERO_HASH","addressesContains","HydratedTransactionValidationError","TransactionFromValidator","tx","errors","from","asAddress","undefined","push","HydratedTransactionValidationError","_hash","ZERO_HASH","addressesContains","ex","hexToBigInt","ZERO_HASH","AttoXL1","HydratedTransactionValidationError","minTransactionFees","TransactionGasValidator","tx","errors","fees","undefined","push","HydratedTransactionValidationError","_hash","ZERO_HASH","base","gasLimit","gasPrice","priority","parseFees","minTransactionFees","ex","ret","AttoXL1","hexToBigInt","ZERO_HASH","PayloadBuilder","HydratedTransactionValidationError","TransactionBoundWitnessJsonSchema","Ajv","ajv","Ajv","allErrors","strict","validate","TransactionJsonSchemaValidator","tx","errors","undefined","compile","TransactionBoundWitnessJsonSchema","PayloadBuilder","omitStorageMeta","error","HydratedTransactionValidationError","_hash","ZERO_HASH","errorsText","separator","cause","push","ex","ZERO_HASH","HydratedTransactionValidationError","TransactionProtocolValidator","tx","chainId","errors","undefined","chain","push","HydratedTransactionValidationError","_hash","ZERO_HASH","ex","Promise","resolve","validateTransaction","tx","chainId","additionalValidators","isTransactionBoundWitness","Error","validators","TransactionProtocolValidator","TransactionDurationValidator","TransactionFromValidator","TransactionGasValidator","TransactionElevationValidator","Promise","all","map","v","flat","ex"]}
|
|
1
|
+
{"version":3,"sources":["../../src/boundwitness/validators/BoundWitnessReferences.ts","../../src/boundwitness/validators/BoundWitnessSignatures.ts","../../src/transaction/validateTransaction.ts","../../src/transaction/validators/TransactionDurationValidator.ts","../../src/transaction/validators/TransactionElevationValidator.ts","../../src/transaction/validators/TransactionFromValidator.ts","../../src/transaction/validators/TransactionGasValidator.ts","../../src/transaction/validators/TransactionJsonSchemaValidator.ts","../../src/transaction/validators/TransactionProtocolValidator.ts"],"sourcesContent":["import { type Hash, ZERO_HASH } from '@xylabs/hex'\nimport type { Promisable } from '@xylabs/promise'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport type {\n Payload,\n Schema,\n WithHashStorageMeta,\n} from '@xyo-network/payload-model'\nimport { isAnyPayload } from '@xyo-network/payload-model'\nimport type { HydratedBoundWitnessValidationFunction, HydratedBoundWitnessWithHashStorageMeta } from '@xyo-network/xl1-protocol'\nimport { HydratedBoundWitnessValidationError } from '@xyo-network/xl1-protocol'\n\nfunction getPayloadsFromPayloadArray(payloads: WithHashStorageMeta<Payload>[], hashes: Hash[]): (WithHashStorageMeta<Payload> | undefined)[] {\n return hashes.map(hash => payloads.find(payload => payload._hash === hash || payload._dataHash === hash))\n}\n\nexport const BoundWitnessReferencesValidator\n// eslint-disable-next-line complexity\n= <T extends BoundWitness = BoundWitness>(allowedSchemas?: Schema[]): HydratedBoundWitnessValidationFunction<T> => (\n [bw, payloadSet]: HydratedBoundWitnessWithHashStorageMeta<T>,\n): Promisable<HydratedBoundWitnessValidationError[]> => {\n const errors: HydratedBoundWitnessValidationError[] = []\n try {\n const payloads = getPayloadsFromPayloadArray(payloadSet, bw.payload_hashes)\n if (payloads.length !== bw.payload_hashes.length) {\n errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'unable to locate payloads'))\n }\n\n // check if payloads are valid and if their schemas match the declared schemas\n for (let payload of payloads) {\n if (isAnyPayload(payload)) {\n const payloadHashIndex = bw.payload_hashes.indexOf(payload._hash)\n const payloadDataHashIndex = bw.payload_hashes.indexOf(payload._dataHash)\n const payloadIndex = Math.max(payloadHashIndex, payloadDataHashIndex)\n if (payloadIndex === -1) {\n errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'payload hash not found'))\n }\n\n const declaredSchema = bw.payload_schemas[payloadIndex]\n if (declaredSchema !== payload.schema) {\n errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'mismatched schema'))\n }\n\n if (allowedSchemas && !allowedSchemas.includes(payload.schema)) {\n errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], `disallowed schema [${payload.schema}]`))\n }\n } else {\n errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'invalid payload'))\n }\n }\n } catch (ex) {\n const error = new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], `validation excepted: ${ex}`)\n error.cause = ex\n errors.push(error)\n }\n return errors\n}\n","import { toArrayBuffer } from '@xylabs/arraybuffer'\nimport { type Address, ZERO_HASH } from '@xylabs/hex'\nimport { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'\nimport type { WithStorageMeta } from '@xyo-network/payload-model'\nimport type { BoundWitnessValidationFunction } from '@xyo-network/xl1-protocol'\nimport { BoundWitnessValidationError } from '@xyo-network/xl1-protocol'\n\nexport const BoundWitnessSignaturesValidator: BoundWitnessValidationFunction = async (\n bw: BoundWitness,\n) => {\n const errors: BoundWitnessValidationError[] = []\n try {\n const dataHash = await BoundWitnessBuilder.dataHash(bw)\n const results: [Address, Error[]][] = await Promise.all(bw.addresses.map(async (address, index) => {\n return [address, await BoundWitnessValidator.validateSignature(toArrayBuffer(dataHash), toArrayBuffer(address), toArrayBuffer(bw.$signatures[index]))]\n }))\n for (const [, bwErrors] of results) {\n for (const bwError of bwErrors) {\n errors.push(new BoundWitnessValidationError((bw as WithStorageMeta<BoundWitness>)?._hash ?? ZERO_HASH, bw, 'validation errors', bwError))\n }\n }\n } catch (ex) {\n errors.push(new BoundWitnessValidationError((bw as WithStorageMeta<BoundWitness>)?._hash ?? ZERO_HASH, bw, 'validation excepted', ex))\n }\n return errors\n}\n","import type { Address } from '@xylabs/hex'\nimport type { HydratedTransaction, HydratedTransactionValidationFunction } from '@xyo-network/xl1-protocol'\nimport { isTransactionBoundWitness } from '@xyo-network/xl1-protocol'\n\nimport {\n TransactionDurationValidator,\n TransactionElevationValidator, TransactionFromValidator, TransactionGasValidator, TransactionProtocolValidator,\n} from './validators/index.ts'\n\nexport async function validateTransaction(\n tx: HydratedTransaction,\n chainId?: Address,\n additionalValidators: HydratedTransactionValidationFunction[] = [],\n) {\n try {\n if (!isTransactionBoundWitness(tx[0])) {\n return [new Error('failed isTransactionBoundWitness identity check')]\n }\n\n const validators: HydratedTransactionValidationFunction[] = [\n TransactionProtocolValidator,\n TransactionDurationValidator,\n TransactionFromValidator,\n TransactionGasValidator,\n TransactionElevationValidator,\n ...additionalValidators,\n ]\n return (await Promise.all(validators.map(v => v(tx, chainId)))).flat()\n } catch (ex) {\n return [(new Error(`Failed TransactionGasValidator: ${ex}`))]\n }\n}\n","import { ZERO_HASH } from '@xylabs/hex'\nimport type {\n HydratedTransaction, HydratedTransactionValidationFunction, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\n// eslint-disable-next-line complexity\nexport const TransactionDurationValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransaction,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n const { exp, nbf } = tx[0]\n if (nbf < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'Transaction nbf must be positive'))\n\n if (exp < 0) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'Transaction exp must be positive'))\n if (exp <= nbf) errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'Transaction exp must greater than nbf'))\n if (exp - nbf > 10_000) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'Transaction exp must not be too far in the future',\n ))\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `Failed TransactionDurationValidator: ${ex}`,\n ex,\n ))\n }\n\n return errors\n}\n","import { ZERO_HASH } from '@xylabs/hex'\nimport type {\n HydratedTransaction, HydratedTransactionValidationFunction, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\nimport { extractElevatedHashes } from '@xyo-network/xl1-protocol-sdk'\n\nexport const TransactionElevationValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransaction,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n try {\n extractElevatedHashes(tx)\n } catch {\n errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'Hydrated transaction does not include all script hashes'))\n }\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `Failed TransactionElevationValidator: ${ex}`,\n ex,\n ))\n }\n return errors\n}\n","import { asAddress, ZERO_HASH } from '@xylabs/hex'\nimport { addressesContains } from '@xyo-network/boundwitness-validator'\nimport type {\n HydratedTransaction, HydratedTransactionValidationFunction, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\nexport const TransactionFromValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransaction,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n const from = asAddress(tx[0].from)\n if (from === undefined)errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'Transaction from is not a valid address',\n ))\n else if (!addressesContains(tx[0], from)) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'Transaction from address must be listed in addresses',\n ))\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `Failed TransactionFromValidator: ${ex}`,\n ex,\n ))\n }\n return errors\n}\n","import { hexToBigInt, ZERO_HASH } from '@xylabs/hex'\nimport type {\n HydratedTransaction,\n HydratedTransactionValidationFunction,\n TransactionBoundWitness, TransactionFeesBigInt, TransactionFeesHex,\n} from '@xyo-network/xl1-protocol'\nimport {\n AttoXL1,\n HydratedTransactionValidationError,\n minTransactionFees,\n} from '@xyo-network/xl1-protocol'\n\n// eslint-disable-next-line complexity\nexport const TransactionGasValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransaction,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n if (tx?.[0].fees === undefined) {\n errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'Missing fees',\n ))\n } else {\n const {\n base, gasLimit, gasPrice, priority,\n } = parseFees(tx[0].fees)\n\n if (base === undefined) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'fees.base must be defined and a valid number',\n ))\n else if (base < minTransactionFees.base) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `fees.base must be >= ${minTransactionFees.base}`,\n ))\n\n if (gasLimit === undefined) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'fees.gasLimit must be defined and a valid number',\n ))\n else if (gasLimit < minTransactionFees.gasLimit) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `fees.gasLimit must be >= ${minTransactionFees.gasLimit}`,\n ))\n\n if (gasPrice === undefined) errors.push(\n new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'fees.gasPrice must be defined and a valid number',\n ),\n )\n else if (gasPrice < minTransactionFees.gasPrice) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `fees.gasPrice must be >= ${minTransactionFees.gasPrice}`,\n ))\n\n if (priority === undefined) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n 'fees.priority must be defined and a valid number',\n ))\n else if (priority < minTransactionFees.priority) errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `fees.priority must be >= ${minTransactionFees.priority}`,\n ))\n }\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `Failed TransactionGasValidator: ${ex}`,\n ex,\n ))\n }\n return errors\n}\n\nconst parseFees = (fees: TransactionFeesHex): Partial<TransactionFeesBigInt> => {\n const ret: Partial<TransactionFeesBigInt> = {}\n const {\n base, gasLimit, gasPrice, priority,\n } = fees\n if (base !== undefined) ret.base = AttoXL1(hexToBigInt(base))\n if (gasLimit !== undefined) ret.gasLimit = AttoXL1(hexToBigInt(gasLimit))\n if (gasPrice !== undefined) ret.gasPrice = AttoXL1(hexToBigInt(gasPrice))\n if (priority !== undefined) ret.priority = AttoXL1(hexToBigInt(priority))\n return ret\n}\n","import { ZERO_HASH } from '@xylabs/hex'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type {\n HydratedTransaction, HydratedTransactionValidationFunction, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\nimport { TransactionBoundWitnessJsonSchema } from '@xyo-network/xl1-schema'\nimport type { ValidateFunction } from 'ajv'\nimport { Ajv } from 'ajv'\n\nconst ajv = new Ajv({ allErrors: true, strict: true })\n\nlet validate: ValidateFunction<TransactionBoundWitness> | undefined\n\nexport const TransactionJsonSchemaValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransaction,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n if (validate === undefined) validate = ajv.compile(TransactionBoundWitnessJsonSchema)\n if (!validate(PayloadBuilder.omitStorageMeta(tx[0]))) {\n const error = new HydratedTransactionValidationError(\n tx?.[0]?._hash ?? ZERO_HASH,\n tx,\n `failed JSON schema validation: ${ajv.errorsText(validate.errors, { separator: '\\n' })}`,\n )\n error.cause = validate.errors\n errors.push(error)\n }\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'validation excepted', ex))\n }\n return errors\n}\n","import { type Address, ZERO_HASH } from '@xylabs/hex'\nimport type {\n HydratedTransaction, HydratedTransactionValidationFunction, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\nexport const TransactionProtocolValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = async (\n tx: HydratedTransaction,\n chainId?: Address,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n if (chainId !== undefined && tx[0].chain !== chainId) {\n errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'invalid chain id'))\n }\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'validation excepted', ex))\n }\n return await Promise.resolve(errors)\n}\n"],"mappings":";AAAA,SAAoB,iBAAiB;AAQrC,SAAS,oBAAoB;AAE7B,SAAS,2CAA2C;AAEpD,SAAS,4BAA4B,UAA0C,QAA8D;AAC3I,SAAO,OAAO,IAAI,UAAQ,SAAS,KAAK,aAAW,QAAQ,UAAU,QAAQ,QAAQ,cAAc,IAAI,CAAC;AAC1G;AAEO,IAAM,kCAEX,CAAwC,mBAAyE,CACjH,CAAC,IAAI,UAAU,MACuC;AACtD,QAAM,SAAgD,CAAC;AACvD,MAAI;AACF,UAAM,WAAW,4BAA4B,YAAY,GAAG,cAAc;AAC1E,QAAI,SAAS,WAAW,GAAG,eAAe,QAAQ;AAChD,aAAO,KAAK,IAAI,oCAAoC,IAAI,SAAS,WAAW,CAAC,IAAI,UAAU,GAAG,2BAA2B,CAAC;AAAA,IAC5H;AAGA,aAAS,WAAW,UAAU;AAC5B,UAAI,aAAa,OAAO,GAAG;AACzB,cAAM,mBAAmB,GAAG,eAAe,QAAQ,QAAQ,KAAK;AAChE,cAAM,uBAAuB,GAAG,eAAe,QAAQ,QAAQ,SAAS;AACxE,cAAM,eAAe,KAAK,IAAI,kBAAkB,oBAAoB;AACpE,YAAI,iBAAiB,IAAI;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AK,KAAK;AAAA,IACnB;AAAA,EACF,SAAS,IAAI;AACX,WAAO,KAAK,IAAIC,oCAAmC,KAAK,CAAC,GAAG,SAASD,YAAW,IAAI,uBAAuB,EAAE,CAAC;AAAA,EAChH;AACA,SAAO;AACT;;;ACjCA,SAAuB,aAAAE,kBAAiB;AAIxC,SAAS,sCAAAC,2CAA0C;AAE5C,IAAM,+BAA+F,OAC1G,IACA,YACG;AACH,QAAM,SAA+C,CAAC;AACtD,MAAI;AACF,QAAI,YAAY,UAAa,GAAG,CAAC,EAAE,UAAU,SAAS;AACpD,aAAO,KAAK,IAAIA,oCAAmC,KAAK,CAAC,GAAG,SAASD,YAAW,IAAI,kBAAkB,CAAC;AAAA,IACzG;AAAA,EACF,SAAS,IAAI;AACX,WAAO,KAAK,IAAIC,oCAAmC,KAAK,CAAC,GAAG,SAASD,YAAW,IAAI,uBAAuB,EAAE,CAAC;AAAA,EAChH;AACA,SAAO,MAAM,QAAQ,QAAQ,MAAM;AACrC;;;ANVA,eAAsB,oBACpB,IACA,SACA,uBAAgE,CAAC,GACjE;AACA,MAAI;AACF,QAAI,CAAC,0BAA0B,GAAG,CAAC,CAAC,GAAG;AACrC,aAAO,CAAC,IAAI,MAAM,iDAAiD,CAAC;AAAA,IACtE;AAEA,UAAM,aAAsD;AAAA,MAC1D;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL;AACA,YAAQ,MAAM,QAAQ,IAAI,WAAW,IAAI,OAAK,EAAE,IAAI,OAAO,CAAC,CAAC,GAAG,KAAK;AAAA,EACvE,SAAS,IAAI;AACX,WAAO,CAAE,IAAI,MAAM,mCAAmC,EAAE,EAAE,CAAE;AAAA,EAC9D;AACF;","names":["ZERO_HASH","ZERO_HASH","ZERO_HASH","HydratedTransactionValidationError","ZERO_HASH","HydratedTransactionValidationError","ZERO_HASH","HydratedTransactionValidationError","ZERO_HASH","HydratedTransactionValidationError","ZERO_HASH","HydratedTransactionValidationError"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/xl1-validation",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.10.0",
|
|
5
5
|
"description": "XYO Layer One SDK Validation",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -36,34 +36,33 @@
|
|
|
36
36
|
"src"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@xylabs/arraybuffer": "
|
|
40
|
-
"@xylabs/hex": "
|
|
41
|
-
"@xyo-network/boundwitness-builder": "
|
|
42
|
-
"@xyo-network/boundwitness-model": "
|
|
43
|
-
"@xyo-network/boundwitness-validator": "
|
|
44
|
-
"@xyo-network/payload-builder": "
|
|
45
|
-
"@xyo-network/payload-model": "
|
|
46
|
-
"@xyo-network/xl1-protocol": "
|
|
47
|
-
"@xyo-network/xl1-protocol-sdk": "
|
|
48
|
-
"@xyo-network/xl1-schema": "
|
|
49
|
-
"ajv": "
|
|
39
|
+
"@xylabs/arraybuffer": "~5.0.2",
|
|
40
|
+
"@xylabs/hex": "~5.0.2",
|
|
41
|
+
"@xyo-network/boundwitness-builder": "~5.0.0",
|
|
42
|
+
"@xyo-network/boundwitness-model": "~5.0.0",
|
|
43
|
+
"@xyo-network/boundwitness-validator": "~5.0.0",
|
|
44
|
+
"@xyo-network/payload-builder": "~5.0.0",
|
|
45
|
+
"@xyo-network/payload-model": "~5.0.0",
|
|
46
|
+
"@xyo-network/xl1-protocol": "~1.9.3",
|
|
47
|
+
"@xyo-network/xl1-protocol-sdk": "~1.10.0",
|
|
48
|
+
"@xyo-network/xl1-schema": "~1.10.0",
|
|
49
|
+
"ajv": "~8.17.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/node": "
|
|
53
|
-
"@xylabs/assert": "
|
|
54
|
-
"@xylabs/promise": "
|
|
55
|
-
"@xylabs/ts-scripts-yarn3": "
|
|
56
|
-
"@xylabs/tsconfig": "
|
|
57
|
-
"@xyo-network/account": "
|
|
58
|
-
"@xyo-network/account-model": "
|
|
59
|
-
"@xyo-network/archivist-memory": "
|
|
60
|
-
"@xyo-network/archivist-model": "
|
|
61
|
-
"@xyo-network/chain-protocol": "
|
|
62
|
-
"@xyo-network/wallet": "
|
|
63
|
-
"@xyo-network/xl1-protocol-sdk": "
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"vitest": "^3.2.4"
|
|
52
|
+
"@types/node": "~24.2.0",
|
|
53
|
+
"@xylabs/assert": "~5.0.2",
|
|
54
|
+
"@xylabs/promise": "~5.0.2",
|
|
55
|
+
"@xylabs/ts-scripts-yarn3": "~7.0.3",
|
|
56
|
+
"@xylabs/tsconfig": "~7.0.3",
|
|
57
|
+
"@xyo-network/account": "~5.0.0",
|
|
58
|
+
"@xyo-network/account-model": "~5.0.0",
|
|
59
|
+
"@xyo-network/archivist-memory": "~5.0.0",
|
|
60
|
+
"@xyo-network/archivist-model": "~5.0.0",
|
|
61
|
+
"@xyo-network/chain-protocol": "~1.10.0",
|
|
62
|
+
"@xyo-network/wallet": "~5.0.0",
|
|
63
|
+
"@xyo-network/xl1-protocol-sdk": "~1.10.0",
|
|
64
|
+
"typescript": "~5.9.2",
|
|
65
|
+
"vitest": "~3.2.4"
|
|
67
66
|
},
|
|
68
67
|
"engines": {
|
|
69
68
|
"node": ">=22.3 <23"
|