@xyo-network/xl1-validation 3.0.13 → 3.0.14

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.
@@ -134,11 +134,95 @@ var BoundWitnessSignaturesValidator = async (bw) => {
134
134
  import { ZERO_HASH as ZERO_HASH10 } from "@xylabs/sdk-js";
135
135
  import { HydratedTransactionValidationError as HydratedTransactionValidationError9, isTransactionBoundWitness } from "@xyo-network/xl1-protocol-lib";
136
136
 
137
+ // src/transaction/validators/SignerAuthorization.ts
138
+ import { XyoAddressZod } from "@xyo-network/sdk-js";
139
+ import { z } from "zod";
140
+
141
+ // src/transaction/validators/TransactionTransfersValidator.ts
142
+ import { isDefined, isUndefined } from "@xylabs/sdk-js";
143
+ import {
144
+ derivedReceiveAddress,
145
+ elevatedPayloads,
146
+ HydratedTransactionValidationError,
147
+ isTransfer as isTransfer2,
148
+ rewardAddressFromStepIdentity
149
+ } from "@xyo-network/xl1-protocol-lib";
150
+ var SelfSignerValidator = (signer, signee) => signer === signee;
151
+ var CompletedStepRewardAddressValidatorFactory = (allowedSigners) => (signer, signee, context) => {
152
+ const step = context?.step;
153
+ if (isDefined(step)) {
154
+ const contextAddress = rewardAddressFromStepIdentity(step);
155
+ return allowedSigners.includes(signer) && signee === contextAddress;
156
+ }
157
+ return false;
158
+ };
159
+ var DerivedReceiveAddressValidatorFactory = (allowedSigners, allowedScope) => (signer, signee, context) => {
160
+ const { address, scope } = context ?? {};
161
+ if (scope !== allowedScope) {
162
+ return false;
163
+ }
164
+ if (isDefined(address)) {
165
+ const derivedAddress = derivedReceiveAddress(address, scope);
166
+ return allowedSigners.includes(signer) && signee === derivedAddress;
167
+ }
168
+ return false;
169
+ };
170
+ function TransactionTransfersValidatorFactory(signerValidators = [SelfSignerValidator]) {
171
+ return async (context, hydratedTx) => {
172
+ const errors = [];
173
+ const signer = hydratedTx[0].from;
174
+ try {
175
+ const payloads = elevatedPayloads(hydratedTx);
176
+ const transfers = payloads.filter(isTransfer2);
177
+ for (const transfer of transfers) {
178
+ if (isUndefined(signerValidators.find((v) => v(signer, transfer.from, transfer.context)))) {
179
+ errors.push(new HydratedTransactionValidationError(
180
+ hydratedTx[0]._hash,
181
+ hydratedTx,
182
+ `transfer from address ${transfer.from} is not authorized by signer ${signer}`
183
+ ));
184
+ }
185
+ }
186
+ } catch (ex) {
187
+ errors.push(new HydratedTransactionValidationError(hydratedTx[0]._hash, hydratedTx, "validation excepted", ex));
188
+ }
189
+ return await Promise.resolve(errors);
190
+ };
191
+ }
192
+
193
+ // src/transaction/validators/SignerAuthorization.ts
194
+ var CompletedStepRewardAuthorizationZod = z.object({
195
+ type: z.literal("completedStepReward"),
196
+ signers: z.array(XyoAddressZod)
197
+ }).describe("Authorizes signers for completed-step-reward addresses");
198
+ var DerivedReceiveAuthorizationZod = z.object({
199
+ type: z.literal("derivedReceive"),
200
+ scope: z.string(),
201
+ signers: z.array(XyoAddressZod)
202
+ }).describe("Authorizes signers for derived-receive addresses within a scope");
203
+ var SignerAuthorizationZod = z.discriminatedUnion("type", [
204
+ CompletedStepRewardAuthorizationZod,
205
+ DerivedReceiveAuthorizationZod
206
+ ]);
207
+ function signerValidatorFromAuthorization(authorization) {
208
+ switch (authorization.type) {
209
+ case "completedStepReward": {
210
+ return CompletedStepRewardAddressValidatorFactory(authorization.signers);
211
+ }
212
+ case "derivedReceive": {
213
+ return DerivedReceiveAddressValidatorFactory(authorization.signers, authorization.scope);
214
+ }
215
+ }
216
+ }
217
+ function signerValidatorsFromAuthorizations(authorizations = []) {
218
+ return [SelfSignerValidator, ...authorizations.map(signerValidatorFromAuthorization)];
219
+ }
220
+
137
221
  // src/transaction/validators/TransactionBoundWitnessValidator.ts
138
222
  import { ZERO_HASH as ZERO_HASH3 } from "@xylabs/sdk-js";
139
223
  import { BoundWitnessValidator as BoundWitnessValidator2 } from "@xyo-network/sdk-js";
140
- import { HydratedTransactionValidationError } from "@xyo-network/xl1-protocol-lib";
141
- var error = (tx, message) => new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH3, tx, message);
224
+ import { HydratedTransactionValidationError as HydratedTransactionValidationError2 } from "@xyo-network/xl1-protocol-lib";
225
+ var error = (tx, message) => new HydratedTransactionValidationError2(tx?.[0]?._hash ?? ZERO_HASH3, tx, message);
142
226
  var checkSignaturesShape = (tx) => {
143
227
  const bw = tx[0];
144
228
  if (bw.$signatures === void 0) {
@@ -160,21 +244,21 @@ var TransactionBoundWitnessValidator = async (context, tx) => {
160
244
 
161
245
  // src/transaction/validators/TransactionDurationValidator.ts
162
246
  import { ZERO_HASH as ZERO_HASH4 } from "@xylabs/sdk-js";
163
- import { HydratedTransactionValidationError as HydratedTransactionValidationError2 } from "@xyo-network/xl1-protocol-lib";
247
+ import { HydratedTransactionValidationError as HydratedTransactionValidationError3 } from "@xyo-network/xl1-protocol-lib";
164
248
  var TransactionDurationValidator = (context, tx) => {
165
249
  const errors = [];
166
250
  try {
167
251
  const { exp, nbf } = tx[0];
168
- if (nbf < 0) errors.push(new HydratedTransactionValidationError2(tx?.[0]?._hash ?? ZERO_HASH4, tx, "Transaction nbf must be positive"));
169
- if (exp < 0) errors.push(new HydratedTransactionValidationError2(tx?.[0]?._hash ?? ZERO_HASH4, tx, "Transaction exp must be positive"));
170
- if (exp <= nbf) errors.push(new HydratedTransactionValidationError2(tx?.[0]?._hash ?? ZERO_HASH4, tx, "Transaction exp must greater than nbf"));
171
- if (exp - nbf > 1e4) errors.push(new HydratedTransactionValidationError2(
252
+ if (nbf < 0) errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ?? ZERO_HASH4, tx, "Transaction nbf must be positive"));
253
+ if (exp < 0) errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ?? ZERO_HASH4, tx, "Transaction exp must be positive"));
254
+ if (exp <= nbf) errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ?? ZERO_HASH4, tx, "Transaction exp must greater than nbf"));
255
+ if (exp - nbf > 1e4) errors.push(new HydratedTransactionValidationError3(
172
256
  tx?.[0]?._hash ?? ZERO_HASH4,
173
257
  tx,
174
258
  "Transaction exp must not be too far in the future"
175
259
  ));
176
260
  } catch (ex) {
177
- errors.push(new HydratedTransactionValidationError2(
261
+ errors.push(new HydratedTransactionValidationError3(
178
262
  tx?.[0]?._hash ?? ZERO_HASH4,
179
263
  tx,
180
264
  `Failed TransactionDurationValidator: ${String(ex)}`,
@@ -186,17 +270,17 @@ var TransactionDurationValidator = (context, tx) => {
186
270
 
187
271
  // src/transaction/validators/TransactionElevationValidator.ts
188
272
  import { ZERO_HASH as ZERO_HASH5 } from "@xylabs/sdk-js";
189
- import { extractElevatedHashes, HydratedTransactionValidationError as HydratedTransactionValidationError3 } from "@xyo-network/xl1-protocol-lib";
273
+ import { extractElevatedHashes, HydratedTransactionValidationError as HydratedTransactionValidationError4 } from "@xyo-network/xl1-protocol-lib";
190
274
  var TransactionElevationValidator = (context, tx) => {
191
275
  const errors = [];
192
276
  try {
193
277
  try {
194
278
  extractElevatedHashes(tx);
195
279
  } catch {
196
- errors.push(new HydratedTransactionValidationError3(tx?.[0]?._hash ?? ZERO_HASH5, tx, "Hydrated transaction does not include all script hashes"));
280
+ errors.push(new HydratedTransactionValidationError4(tx?.[0]?._hash ?? ZERO_HASH5, tx, "Hydrated transaction does not include all script hashes"));
197
281
  }
198
282
  } catch (ex) {
199
- errors.push(new HydratedTransactionValidationError3(
283
+ errors.push(new HydratedTransactionValidationError4(
200
284
  tx?.[0]?._hash ?? ZERO_HASH5,
201
285
  tx,
202
286
  `Failed TransactionElevationValidator: ${String(ex)}`,
@@ -209,23 +293,23 @@ var TransactionElevationValidator = (context, tx) => {
209
293
  // src/transaction/validators/TransactionFromValidator.ts
210
294
  import { ZERO_HASH as ZERO_HASH6 } from "@xylabs/sdk-js";
211
295
  import { addressesContains, asXyoAddress } from "@xyo-network/sdk-js";
212
- import { HydratedTransactionValidationError as HydratedTransactionValidationError4 } from "@xyo-network/xl1-protocol-lib";
296
+ import { HydratedTransactionValidationError as HydratedTransactionValidationError5 } from "@xyo-network/xl1-protocol-lib";
213
297
  var TransactionFromValidator = (context, tx) => {
214
298
  const errors = [];
215
299
  try {
216
300
  const from = asXyoAddress(tx[0].from);
217
- if (from === void 0) errors.push(new HydratedTransactionValidationError4(
301
+ if (from === void 0) errors.push(new HydratedTransactionValidationError5(
218
302
  tx?.[0]?._hash ?? ZERO_HASH6,
219
303
  tx,
220
304
  "Transaction from is not a valid address"
221
305
  ));
222
- else if (!addressesContains(tx[0], from)) errors.push(new HydratedTransactionValidationError4(
306
+ else if (!addressesContains(tx[0], from)) errors.push(new HydratedTransactionValidationError5(
223
307
  tx?.[0]?._hash ?? ZERO_HASH6,
224
308
  tx,
225
309
  "Transaction from address must be listed in addresses"
226
310
  ));
227
311
  } catch (ex) {
228
- errors.push(new HydratedTransactionValidationError4(
312
+ errors.push(new HydratedTransactionValidationError5(
229
313
  tx?.[0]?._hash ?? ZERO_HASH6,
230
314
  tx,
231
315
  `Failed TransactionFromValidator: ${String(ex)}`,
@@ -239,14 +323,14 @@ var TransactionFromValidator = (context, tx) => {
239
323
  import { hexToBigInt as hexToBigInt2, ZERO_HASH as ZERO_HASH7 } from "@xylabs/sdk-js";
240
324
  import {
241
325
  AttoXL1,
242
- HydratedTransactionValidationError as HydratedTransactionValidationError5,
326
+ HydratedTransactionValidationError as HydratedTransactionValidationError6,
243
327
  minTransactionFees
244
328
  } from "@xyo-network/xl1-protocol-lib";
245
329
  var TransactionGasValidator = (context, tx) => {
246
330
  const errors = [];
247
331
  try {
248
332
  if (tx?.[0].fees === void 0) {
249
- errors.push(new HydratedTransactionValidationError5(
333
+ errors.push(new HydratedTransactionValidationError6(
250
334
  tx?.[0]?._hash ?? ZERO_HASH7,
251
335
  tx,
252
336
  "Missing fees"
@@ -258,51 +342,51 @@ var TransactionGasValidator = (context, tx) => {
258
342
  gasPrice,
259
343
  priority
260
344
  } = parseFees(tx[0].fees);
261
- if (base === void 0) errors.push(new HydratedTransactionValidationError5(
345
+ if (base === void 0) errors.push(new HydratedTransactionValidationError6(
262
346
  tx?.[0]?._hash ?? ZERO_HASH7,
263
347
  tx,
264
348
  "fees.base must be defined and a valid number"
265
349
  ));
266
- else if (base < minTransactionFees.base) errors.push(new HydratedTransactionValidationError5(
350
+ else if (base < minTransactionFees.base) errors.push(new HydratedTransactionValidationError6(
267
351
  tx?.[0]?._hash ?? ZERO_HASH7,
268
352
  tx,
269
353
  `fees.base must be >= ${minTransactionFees.base}`
270
354
  ));
271
- if (gasLimit === void 0) errors.push(new HydratedTransactionValidationError5(
355
+ if (gasLimit === void 0) errors.push(new HydratedTransactionValidationError6(
272
356
  tx?.[0]?._hash ?? ZERO_HASH7,
273
357
  tx,
274
358
  "fees.gasLimit must be defined and a valid number"
275
359
  ));
276
- else if (gasLimit < minTransactionFees.gasLimit) errors.push(new HydratedTransactionValidationError5(
360
+ else if (gasLimit < minTransactionFees.gasLimit) errors.push(new HydratedTransactionValidationError6(
277
361
  tx?.[0]?._hash ?? ZERO_HASH7,
278
362
  tx,
279
363
  `fees.gasLimit must be >= ${minTransactionFees.gasLimit}`
280
364
  ));
281
365
  if (gasPrice === void 0) errors.push(
282
- new HydratedTransactionValidationError5(
366
+ new HydratedTransactionValidationError6(
283
367
  tx?.[0]?._hash ?? ZERO_HASH7,
284
368
  tx,
285
369
  "fees.gasPrice must be defined and a valid number"
286
370
  )
287
371
  );
288
- else if (gasPrice < minTransactionFees.gasPrice) errors.push(new HydratedTransactionValidationError5(
372
+ else if (gasPrice < minTransactionFees.gasPrice) errors.push(new HydratedTransactionValidationError6(
289
373
  tx?.[0]?._hash ?? ZERO_HASH7,
290
374
  tx,
291
375
  `fees.gasPrice must be >= ${minTransactionFees.gasPrice}`
292
376
  ));
293
- if (priority === void 0) errors.push(new HydratedTransactionValidationError5(
377
+ if (priority === void 0) errors.push(new HydratedTransactionValidationError6(
294
378
  tx?.[0]?._hash ?? ZERO_HASH7,
295
379
  tx,
296
380
  "fees.priority must be defined and a valid number"
297
381
  ));
298
- else if (priority < minTransactionFees.priority) errors.push(new HydratedTransactionValidationError5(
382
+ else if (priority < minTransactionFees.priority) errors.push(new HydratedTransactionValidationError6(
299
383
  tx?.[0]?._hash ?? ZERO_HASH7,
300
384
  tx,
301
385
  `fees.priority must be >= ${minTransactionFees.priority}`
302
386
  ));
303
387
  }
304
388
  } catch (ex) {
305
- errors.push(new HydratedTransactionValidationError5(
389
+ errors.push(new HydratedTransactionValidationError6(
306
390
  tx?.[0]?._hash ?? ZERO_HASH7,
307
391
  tx,
308
392
  `Failed TransactionGasValidator: ${String(ex)}`,
@@ -329,7 +413,7 @@ var parseFees = (fees) => {
329
413
  // src/transaction/validators/TransactionJsonSchemaValidator.ts
330
414
  import { ZERO_HASH as ZERO_HASH8 } from "@xylabs/sdk-js";
331
415
  import { PayloadBuilder } from "@xyo-network/sdk-js";
332
- import { HydratedTransactionValidationError as HydratedTransactionValidationError6 } from "@xyo-network/xl1-protocol-lib";
416
+ import { HydratedTransactionValidationError as HydratedTransactionValidationError7 } from "@xyo-network/xl1-protocol-lib";
333
417
  import { TransactionBoundWitnessJsonSchema } from "@xyo-network/xl1-schema";
334
418
  import { Ajv } from "ajv";
335
419
  var ajv = new Ajv({ allErrors: true, strict: true });
@@ -339,7 +423,7 @@ var TransactionJsonSchemaValidator = (context, tx) => {
339
423
  try {
340
424
  validate ??= ajv.compile(TransactionBoundWitnessJsonSchema);
341
425
  if (!validate(PayloadBuilder.omitStorageMeta(tx[0]))) {
342
- const error2 = new HydratedTransactionValidationError6(
426
+ const error2 = new HydratedTransactionValidationError7(
343
427
  tx?.[0]?._hash ?? ZERO_HASH8,
344
428
  tx,
345
429
  `failed JSON schema validation: ${ajv.errorsText(validate.errors, { separator: "\n" })}`,
@@ -348,78 +432,26 @@ var TransactionJsonSchemaValidator = (context, tx) => {
348
432
  errors.push(error2);
349
433
  }
350
434
  } catch (ex) {
351
- errors.push(new HydratedTransactionValidationError6(tx?.[0]?._hash ?? ZERO_HASH8, tx, "validation excepted", ex));
435
+ errors.push(new HydratedTransactionValidationError7(tx?.[0]?._hash ?? ZERO_HASH8, tx, "validation excepted", ex));
352
436
  }
353
437
  return errors;
354
438
  };
355
439
 
356
440
  // src/transaction/validators/TransactionProtocolValidator.ts
357
441
  import { ZERO_HASH as ZERO_HASH9 } from "@xylabs/sdk-js";
358
- import { HydratedTransactionValidationError as HydratedTransactionValidationError7 } from "@xyo-network/xl1-protocol-lib";
442
+ import { HydratedTransactionValidationError as HydratedTransactionValidationError8 } from "@xyo-network/xl1-protocol-lib";
359
443
  var TransactionProtocolValidator = async (context, tx) => {
360
444
  const errors = [];
361
445
  try {
362
446
  if (context?.chainId !== void 0 && tx[0].chain !== context.chainId) {
363
- errors.push(new HydratedTransactionValidationError7(tx?.[0]?._hash ?? ZERO_HASH9, tx, `invalid chain id [${context.chainId}, ${tx[0].chain}]`));
447
+ errors.push(new HydratedTransactionValidationError8(tx?.[0]?._hash ?? ZERO_HASH9, tx, `invalid chain id [${context.chainId}, ${tx[0].chain}]`));
364
448
  }
365
449
  } catch (ex) {
366
- errors.push(new HydratedTransactionValidationError7(tx?.[0]?._hash ?? ZERO_HASH9, tx, "validation excepted", ex));
450
+ errors.push(new HydratedTransactionValidationError8(tx?.[0]?._hash ?? ZERO_HASH9, tx, "validation excepted", ex));
367
451
  }
368
452
  return await Promise.resolve(errors);
369
453
  };
370
454
 
371
- // src/transaction/validators/TransactionTransfersValidator.ts
372
- import { isDefined, isUndefined } from "@xylabs/sdk-js";
373
- import {
374
- derivedReceiveAddress,
375
- elevatedPayloads,
376
- HydratedTransactionValidationError as HydratedTransactionValidationError8,
377
- isTransfer as isTransfer2,
378
- rewardAddressFromStepIdentity
379
- } from "@xyo-network/xl1-protocol-lib";
380
- var SelfSignerValidator = (signer, signee) => signer === signee;
381
- var CompletedStepRewardAddressValidatorFactory = (allowedSigners) => (signer, signee, context) => {
382
- const step = context?.step;
383
- if (isDefined(step)) {
384
- const contextAddress = rewardAddressFromStepIdentity(step);
385
- return allowedSigners.includes(signer) && signee === contextAddress;
386
- }
387
- return false;
388
- };
389
- var DerivedReceiveAddressValidatorFactory = (allowedSigners, allowedScope) => (signer, signee, context) => {
390
- const { address, scope } = context ?? {};
391
- if (scope !== allowedScope) {
392
- return false;
393
- }
394
- if (isDefined(address)) {
395
- const derivedAddress = derivedReceiveAddress(address, scope);
396
- return allowedSigners.includes(signer) && signee === derivedAddress;
397
- }
398
- return false;
399
- };
400
- function TransactionTransfersValidatorFactory(signerValidators = [SelfSignerValidator]) {
401
- return async (context, hydratedTx) => {
402
- const errors = [];
403
- const signer = hydratedTx[0].from;
404
- try {
405
- const payloads = elevatedPayloads(hydratedTx);
406
- const transfers = payloads.filter(isTransfer2);
407
- for (const transfer of transfers) {
408
- if (isUndefined(signerValidators.find((v) => v(signer, transfer.from, transfer.context)))) {
409
- errors.push(new HydratedTransactionValidationError8(
410
- hydratedTx[0]._hash,
411
- hydratedTx,
412
- `transfer from address ${transfer.from} is not authorized by signer ${signer}`
413
- ));
414
- }
415
- }
416
- } catch (ex) {
417
- errors.push(new HydratedTransactionValidationError8(hydratedTx[0]._hash, hydratedTx, "validation excepted", ex));
418
- }
419
- return await Promise.resolve(errors);
420
- };
421
- }
422
-
423
455
  // src/transaction/validateTransaction.ts
424
456
  var validateTransaction = async (context, tx, additionalValidators) => {
425
457
  try {
@@ -457,8 +489,11 @@ export {
457
489
  BoundWitnessReferencesValidator,
458
490
  BoundWitnessSignaturesValidator,
459
491
  CompletedStepRewardAddressValidatorFactory,
492
+ CompletedStepRewardAuthorizationZod,
460
493
  DerivedReceiveAddressValidatorFactory,
494
+ DerivedReceiveAuthorizationZod,
461
495
  SelfSignerValidator,
496
+ SignerAuthorizationZod,
462
497
  TransactionBoundWitnessValidator,
463
498
  TransactionDurationValidator,
464
499
  TransactionElevationValidator,
@@ -468,6 +503,7 @@ export {
468
503
  TransactionProtocolValidator,
469
504
  TransactionTransfersValidatorFactory,
470
505
  accumulateOutflows,
506
+ signerValidatorsFromAuthorizations,
471
507
  validateTransaction
472
508
  };
473
509
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/block/validators/BlockCumulativeBalanceValidator.ts", "../../src/boundwitness/validators/BoundWitnessReferences.ts", "../../src/boundwitness/validators/BoundWitnessSignatures.ts", "../../src/transaction/validateTransaction.ts", "../../src/transaction/validators/TransactionBoundWitnessValidator.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", "../../src/transaction/validators/TransactionTransfersValidator.ts"],
4
- "sourcesContent": ["import { type Hex, hexToBigInt } from '@xylabs/sdk-js'\nimport type { XyoAddress } from '@xyo-network/sdk-js'\nimport type {\n HydratedBlockStateValidationFunction,\n HydratedBlockWithHashMeta,\n TransactionBoundWitnessWithHashMeta,\n} from '@xyo-network/xl1-protocol-lib'\nimport {\n HydratedBlockStateValidationError,\n isTransactionBoundWitnessWithHashMeta,\n isTransfer,\n XYO_ZERO_ADDRESS,\n} from '@xyo-network/xl1-protocol-lib'\n\n/** Compute the maximum fee commitment for a transaction (base + priority + gasLimit). */\nfunction maxTransactionFeeCost(tx: TransactionBoundWitnessWithHashMeta): bigint {\n const {\n base, gasLimit, priority,\n } = tx.fees\n return hexToBigInt(base) + hexToBigInt(priority) + hexToBigInt(gasLimit)\n}\n\nfunction accumulateTransferOutflows(\n payload: HydratedBlockWithHashMeta[1][number],\n txPayloadHashes: Set<string>,\n outflows: Record<XyoAddress, bigint>,\n): void {\n if (!txPayloadHashes.has(payload._hash) || !isTransfer(payload)) return\n const { from } = payload\n for (const [to, amount] of Object.entries(payload.transfers) as [XyoAddress, Hex][]) {\n if (to !== from) {\n outflows[from] = (outflows[from] ?? 0n) + hexToBigInt(amount)\n }\n }\n}\n\n/** Accumulate outflows per address from fees and transfers in the given transactions. */\nexport function accumulateOutflows(\n transactions: TransactionBoundWitnessWithHashMeta[],\n payloads: HydratedBlockWithHashMeta[1],\n): Record<XyoAddress, bigint> {\n const outflows: Record<XyoAddress, bigint> = {}\n\n for (const tx of transactions) {\n // Fee cost charged to the transaction sender\n const feeCost = maxTransactionFeeCost(tx)\n const feePayer = tx.from\n outflows[feePayer] = (outflows[feePayer] ?? 0n) + feeCost\n\n // Find transfer payloads belonging to this transaction\n const txPayloadHashes = new Set(tx.payload_hashes)\n for (const payload of payloads) {\n accumulateTransferOutflows(payload, txPayloadHashes, outflows)\n }\n }\n\n return outflows\n}\n\n/** Creates a block state validator that checks cumulative outflows per address do not exceed pre-block balances. */\nexport function BlockCumulativeBalanceValidatorFactory(): HydratedBlockStateValidationFunction {\n return async (context, hydratedBlock) => {\n const [blockBw, payloads] = hydratedBlock\n\n // Find all transactions in the block\n const transactions = payloads.filter(isTransactionBoundWitnessWithHashMeta)\n\n if (transactions.length === 0) return []\n\n const outflows = accumulateOutflows(transactions, payloads)\n\n // Query pre-block balances for all addresses with outflows\n const addresses = Object.keys(outflows) as XyoAddress[]\n if (addresses.length === 0) return []\n\n const balances = await context.accountBalance.accountBalances(addresses)\n\n // Check each address\n const chainId = await context.chainIdAtBlockNumber(blockBw.block)\n const errors: HydratedBlockStateValidationError[] = []\n for (const address of addresses) {\n if (address === XYO_ZERO_ADDRESS) continue // Skip zero address as it's used for burn transactions and doesn't have a balance\n // TODO: Add specific validation for block reward transfer\n const balance = balances[address] ?? 0n\n const totalOutflow = outflows[address]\n if (totalOutflow > balance) {\n errors.push(new HydratedBlockStateValidationError(\n blockBw._hash,\n chainId,\n hydratedBlock,\n `Cumulative outflow for address ${address} exceeds available balance: outflow ${totalOutflow} > balance ${balance}`,\n ))\n }\n }\n\n return errors\n }\n}\n", "import type { Hash, Promisable } from '@xylabs/sdk-js'\nimport { ZERO_HASH } from '@xylabs/sdk-js'\nimport type {\n BoundWitness,\n Payload,\n Schema,\n WithHashMeta,\n} from '@xyo-network/sdk-js'\nimport { isAnyPayload } from '@xyo-network/sdk-js'\nimport type { HydratedBoundWitnessValidationFunction, HydratedBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol-lib'\nimport { HydratedBoundWitnessValidationError } from '@xyo-network/xl1-protocol-lib'\n\nfunction getPayloadsFromPayloadArray(payloads: WithHashMeta<Payload>[], hashes: Hash[]): (WithHashMeta<Payload> | undefined)[] {\n return hashes.map(hash => payloads.find(payload => payload._hash === hash || payload._dataHash === hash))\n}\n\n/** Creates a validator that checks all payload references in a BoundWitness are present, have matching schemas, and optionally conform to an allowed schema list. */\nexport const BoundWitnessReferencesValidator\n\n = <T extends BoundWitness = BoundWitness>(allowedSchemas?: Schema[]): HydratedBoundWitnessValidationFunction<T> => (\n [bw, payloadSet]: HydratedBoundWitnessWithHashMeta<T>,\n // eslint-disable-next-line complexity\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 (const 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: ${String(ex)}`, ex)\n errors.push(error)\n }\n return errors\n }\n", "import { toArrayBuffer, ZERO_HASH } from '@xylabs/sdk-js'\nimport type {\n BoundWitness, WithStorageMeta, XyoAddress,\n} from '@xyo-network/sdk-js'\nimport { BoundWitnessBuilder, BoundWitnessValidator } from '@xyo-network/sdk-js'\nimport type { BoundWitnessValidationFunction } from '@xyo-network/xl1-protocol-lib'\nimport { BoundWitnessValidationError } from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that all signatures on a BoundWitness are cryptographically valid for their corresponding addresses. */\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: [XyoAddress, Error[]][] = await Promise.all(bw.addresses.map(async (address, index) => {\n return [address, await BoundWitnessValidator.validateSignature(\n toArrayBuffer(dataHash),\n address,\n toArrayBuffer(bw.$signatures[index] ?? undefined),\n )]\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 { ZERO_HASH } from '@xylabs/sdk-js'\nimport type { BoundWitness, WithHashMeta } from '@xyo-network/sdk-js'\nimport type {\n HydratedTransactionValidationFunction,\n HydratedTransactionValidationFunctionContext,\n HydratedTransactionWithHashMeta,\n} from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError, isTransactionBoundWitness } from '@xyo-network/xl1-protocol-lib'\n\nimport {\n TransactionBoundWitnessValidator,\n TransactionDurationValidator,\n TransactionElevationValidator, TransactionFromValidator, TransactionGasValidator, TransactionProtocolValidator,\n} from './validators/index.ts'\n\n/** Validates a hydrated transaction using built-in validators plus any additional validators provided. */\nexport const validateTransaction: HydratedTransactionValidationFunction = async (\n context: HydratedTransactionValidationFunctionContext,\n tx: HydratedTransactionWithHashMeta,\n additionalValidators?: HydratedTransactionValidationFunction[],\n): Promise<HydratedTransactionValidationError[]> => {\n try {\n if (!isTransactionBoundWitness(tx[0])) {\n const castTx = tx.at(0) as WithHashMeta<BoundWitness> | undefined\n return [new HydratedTransactionValidationError(\n castTx?._hash ?? ZERO_HASH,\n tx,\n 'failed isTransactionBoundWitness identity check',\n )]\n }\n\n const validators: HydratedTransactionValidationFunction<HydratedTransactionValidationFunctionContext>[] = [\n TransactionProtocolValidator,\n TransactionDurationValidator,\n TransactionFromValidator,\n TransactionGasValidator,\n TransactionElevationValidator,\n TransactionBoundWitnessValidator,\n ...(additionalValidators ?? []),\n ]\n const validationResults = await Promise.all(validators.map(async v => v(context, tx)))\n return validationResults.flat()\n } catch (ex) {\n const castTx = tx?.[0] as WithHashMeta<BoundWitness> | undefined\n return [new HydratedTransactionValidationError(\n castTx?._hash ?? ZERO_HASH,\n tx,\n 'Failed TransactionGasValidator: ' + (ex as Error).message,\n ex,\n )]\n }\n}\n", "import { ZERO_HASH } from '@xylabs/sdk-js'\nimport { BoundWitnessValidator } from '@xyo-network/sdk-js'\nimport type { HydratedTransactionValidationFunction, HydratedTransactionWithHashMeta } from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\n\nconst error = (tx: HydratedTransactionWithHashMeta, message: string): HydratedTransactionValidationError =>\n new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, message)\n\n// Friendly pre-check for the wallet bug we want to surface clearly: signatures\n// emitted under `signatures` instead of `$signatures`. The downstream\n// BoundWitnessValidator would also catch the missing/mismatched signatures,\n// but its message (\"Length mismatch: address/signature\", \"Missing signature\n// [<address>]\") doesn't hint at the actual root cause.\nconst checkSignaturesShape = (tx: HydratedTransactionWithHashMeta): HydratedTransactionValidationError[] => {\n const bw = tx[0] as unknown as Record<string, unknown>\n if (bw.$signatures === undefined) {\n return Array.isArray(bw.signatures)\n ? [error(tx, 'BoundWitness has `signatures` but expected `$signatures` (signatures must be in the meta-prefixed `$signatures` key)')]\n : [error(tx, 'BoundWitness is missing `$signatures`')]\n }\n return []\n}\n\n/**\n * Validates the transaction's BoundWitness wholistically by delegating to\n * `BoundWitnessValidator.validate()`. This covers:\n * - signatures: length matches addresses, every signature is cryptographically\n * valid for its corresponding address against the BW data hash\n * - addresses: uniqueness\n * - array length parity: payload_hashes vs payload_schemas\n * - schemas: per-schema name validators\n * - top-level schema check\n * - PayloadValidator.schemaName check\n *\n * Also emits a friendly diagnostic when the common wallet bug of\n * `signatures` vs `$signatures` is detected, so the failure points at the\n * actual root cause instead of buried length/missing-signature errors.\n */\nexport const TransactionBoundWitnessValidator: HydratedTransactionValidationFunction = async (\n context,\n tx,\n) => {\n try {\n const shapeErrors = checkSignaturesShape(tx)\n if (shapeErrors.length > 0) return shapeErrors\n const bwValidator = new BoundWitnessValidator(tx[0])\n const bwErrors = await bwValidator.validate()\n return bwErrors.map(e => error(tx, `BoundWitness validation: ${e.message}`))\n } catch (ex) {\n return [error(tx, `Failed TransactionBoundWitnessValidator: ${String(ex)}`)]\n }\n}\n", "import { ZERO_HASH } from '@xylabs/sdk-js'\nimport type { HydratedTransactionValidationFunction } from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that transaction timing fields (nbf and exp) are positive, correctly ordered, and within allowed duration limits. */\nexport const TransactionDurationValidator: HydratedTransactionValidationFunction = (\n context,\n tx,\n// eslint-disable-next-line complexity\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: ${String(ex)}`,\n ex,\n ))\n }\n\n return errors\n}\n", "import { ZERO_HASH } from '@xylabs/sdk-js'\nimport type { HydratedTransactionValidationFunction } from '@xyo-network/xl1-protocol-lib'\nimport { extractElevatedHashes, HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that a hydrated transaction includes all required elevated script hashes. */\nexport const TransactionElevationValidator: HydratedTransactionValidationFunction = (\n context,\n tx,\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: ${String(ex)}`,\n ex,\n ))\n }\n return errors\n}\n", "import { ZERO_HASH } from '@xylabs/sdk-js'\nimport { addressesContains, asXyoAddress } from '@xyo-network/sdk-js'\nimport type { HydratedTransactionValidationFunction } from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that the transaction's from field is a valid address and is included in the BoundWitness addresses. */\nexport const TransactionFromValidator: HydratedTransactionValidationFunction = (\n context,\n tx,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n const from = asXyoAddress(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: ${String(ex)}`,\n ex,\n ))\n }\n return errors\n}\n", "import { hexToBigInt, ZERO_HASH } from '@xylabs/sdk-js'\nimport type {\n HydratedTransactionValidationFunction,\n TransactionFeesBigInt, TransactionFeesHex,\n} from '@xyo-network/xl1-protocol-lib'\nimport {\n AttoXL1,\n HydratedTransactionValidationError,\n minTransactionFees,\n} from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that transaction fee fields (base, gasLimit, gasPrice, priority) are present and meet minimum requirements. */\nexport const TransactionGasValidator: HydratedTransactionValidationFunction = (\n context,\n tx,\n// eslint-disable-next-line complexity\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: ${String(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/sdk-js'\nimport { PayloadBuilder } from '@xyo-network/sdk-js'\nimport type { HydratedTransactionValidationFunction, TransactionBoundWitness } from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\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\n/** Validates a transaction against the TransactionBoundWitness JSON schema using AJV. */\nexport const TransactionJsonSchemaValidator: HydratedTransactionValidationFunction = (\n context,\n tx,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n 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 validate.errors,\n )\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 { ZERO_HASH } from '@xylabs/sdk-js'\nimport type {\n ChainId,\n HydratedTransactionValidationFunction,\n} from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that the transaction's chain ID matches the expected chain ID from the validation context. */\nexport const TransactionProtocolValidator: HydratedTransactionValidationFunction = async (\n context: { chainId?: ChainId },\n tx,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n if (context?.chainId !== undefined && tx[0].chain !== context.chainId) {\n errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, `invalid chain id [${context.chainId}, ${tx[0].chain}]`))\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", "import { isDefined, isUndefined } from '@xylabs/sdk-js'\nimport type { XyoAddress } from '@xyo-network/sdk-js'\nimport type {\n HydratedTransactionValidationFunction, StepIdentity,\n Transfer,\n} from '@xyo-network/xl1-protocol-lib'\nimport {\n derivedReceiveAddress,\n elevatedPayloads,\n HydratedTransactionValidationError,\n isTransfer,\n rewardAddressFromStepIdentity,\n} from '@xyo-network/xl1-protocol-lib'\n\n/** Function type that checks whether a signer is authorized to sign for a given signee address. */\nexport type SignerValidator = (signer: XyoAddress, signee: XyoAddress, context?: { address?: XyoAddress; scope?: string; step?: StepIdentity }) => boolean\n\n/** Maps addresses to their list of authorized signer addresses. */\nexport type SignerMapping = Map<XyoAddress, XyoAddress[]>\n\n/** A signer validator that only allows an address to sign for itself. */\nexport const SelfSignerValidator: SignerValidator = (signer: XyoAddress, signee: XyoAddress) => signer === signee\n\n/** Creates a signer validator that authorizes specified signers to sign for completed step reward addresses. */\nexport const CompletedStepRewardAddressValidatorFactory = (allowedSigners: XyoAddress[]): SignerValidator => (\n signer: XyoAddress,\n signee: XyoAddress,\n context?: { step?: StepIdentity },\n) => {\n const step = context?.step\n if (isDefined(step)) {\n const contextAddress = rewardAddressFromStepIdentity(step)\n return allowedSigners.includes(signer) && signee === contextAddress\n }\n return false\n}\n\n/** Creates a signer validator that authorizes specified signers to sign for derived receive addresses within a given scope. */\nexport const DerivedReceiveAddressValidatorFactory = (allowedSigners: XyoAddress[], allowedScope: string): SignerValidator => (\n signer: XyoAddress,\n signee: XyoAddress,\n context?: { address?: XyoAddress; scope?: string },\n) => {\n const { address, scope } = context ?? {}\n if (scope !== allowedScope) {\n return false\n }\n if (isDefined(address)) {\n const derivedAddress = derivedReceiveAddress(address, scope)\n return allowedSigners.includes(signer) && signee === derivedAddress\n }\n return false\n}\n\n/** Creates a transaction validator that checks all transfers are authorized by the transaction signer. */\nexport function TransactionTransfersValidatorFactory(\n signerValidators: SignerValidator[] = [SelfSignerValidator],\n): HydratedTransactionValidationFunction {\n return async (\n context,\n hydratedTx,\n ) => {\n const errors: HydratedTransactionValidationError[] = []\n const signer = hydratedTx[0].from\n try {\n const payloads = elevatedPayloads(hydratedTx)\n const transfers = payloads.filter(isTransfer) as Transfer[]\n for (const transfer of transfers) {\n if (isUndefined(signerValidators.find(v => v(signer, transfer.from, transfer.context)))) {\n errors.push(new HydratedTransactionValidationError(\n hydratedTx[0]._hash,\n hydratedTx,\n `transfer from address ${transfer.from} is not authorized by signer ${signer}`,\n ))\n }\n }\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(hydratedTx[0]._hash, hydratedTx, 'validation excepted', ex))\n }\n return await Promise.resolve(errors)\n }\n}\n"],
5
- "mappings": ";AAAA,SAAmB,mBAAmB;AAOtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,sBAAsB,IAAiD;AAC9E,QAAM;AAAA,IACJ;AAAA,IAAM;AAAA,IAAU;AAAA,EAClB,IAAI,GAAG;AACP,SAAO,YAAY,IAAI,IAAI,YAAY,QAAQ,IAAI,YAAY,QAAQ;AACzE;AAEA,SAAS,2BACP,SACA,iBACA,UACM;AACN,MAAI,CAAC,gBAAgB,IAAI,QAAQ,KAAK,KAAK,CAAC,WAAW,OAAO,EAAG;AACjE,QAAM,EAAE,KAAK,IAAI;AACjB,aAAW,CAAC,IAAI,MAAM,KAAK,OAAO,QAAQ,QAAQ,SAAS,GAA0B;AACnF,QAAI,OAAO,MAAM;AACf,eAAS,IAAI,KAAK,SAAS,IAAI,KAAK,MAAM,YAAY,MAAM;AAAA,IAC9D;AAAA,EACF;AACF;AAGO,SAAS,mBACd,cACA,UAC4B;AAC5B,QAAM,WAAuC,CAAC;AAE9C,aAAW,MAAM,cAAc;AA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AAoG;AAAA,MACxG;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAI,wBAAwB,CAAC;AAAA,IAC/B;AACA,UAAM,oBAAoB,MAAM,QAAQ,IAAI,WAAW,IAAI,OAAM,MAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AACrF,WAAO,kBAAkB,KAAK;AAAA,EAChC,SAAS,IAAI;AACX,UAAM,SAAS,KAAK,CAAC;AACrB,WAAO,CAAC,IAAID;AAAA,MACV,QAAQ,SAASC;AAAA,MACjB;AAAA,MACA,qCAAsC,GAAa;AAAA,MACnD;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
6
- "names": ["error", "ZERO_HASH", "ZERO_HASH", "HydratedTransactionValidationError", "ZERO_HASH", "BoundWitnessValidator", "ZERO_HASH", "HydratedTransactionValidationError", "ZERO_HASH", "HydratedTransactionValidationError", "ZERO_HASH", "HydratedTransactionValidationError", "hexToBigInt", "ZERO_HASH", "HydratedTransactionValidationError", "ZERO_HASH", "HydratedTransactionValidationError", "error", "ZERO_HASH", "HydratedTransactionValidationError", "HydratedTransactionValidationError", "isTransfer", "HydratedTransactionValidationError", "ZERO_HASH"]
3
+ "sources": ["../../src/block/validators/BlockCumulativeBalanceValidator.ts", "../../src/boundwitness/validators/BoundWitnessReferences.ts", "../../src/boundwitness/validators/BoundWitnessSignatures.ts", "../../src/transaction/validateTransaction.ts", "../../src/transaction/validators/SignerAuthorization.ts", "../../src/transaction/validators/TransactionTransfersValidator.ts", "../../src/transaction/validators/TransactionBoundWitnessValidator.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"],
4
+ "sourcesContent": ["import { type Hex, hexToBigInt } from '@xylabs/sdk-js'\nimport type { XyoAddress } from '@xyo-network/sdk-js'\nimport type {\n HydratedBlockStateValidationFunction,\n HydratedBlockWithHashMeta,\n TransactionBoundWitnessWithHashMeta,\n} from '@xyo-network/xl1-protocol-lib'\nimport {\n HydratedBlockStateValidationError,\n isTransactionBoundWitnessWithHashMeta,\n isTransfer,\n XYO_ZERO_ADDRESS,\n} from '@xyo-network/xl1-protocol-lib'\n\n/** Compute the maximum fee commitment for a transaction (base + priority + gasLimit). */\nfunction maxTransactionFeeCost(tx: TransactionBoundWitnessWithHashMeta): bigint {\n const {\n base, gasLimit, priority,\n } = tx.fees\n return hexToBigInt(base) + hexToBigInt(priority) + hexToBigInt(gasLimit)\n}\n\nfunction accumulateTransferOutflows(\n payload: HydratedBlockWithHashMeta[1][number],\n txPayloadHashes: Set<string>,\n outflows: Record<XyoAddress, bigint>,\n): void {\n if (!txPayloadHashes.has(payload._hash) || !isTransfer(payload)) return\n const { from } = payload\n for (const [to, amount] of Object.entries(payload.transfers) as [XyoAddress, Hex][]) {\n if (to !== from) {\n outflows[from] = (outflows[from] ?? 0n) + hexToBigInt(amount)\n }\n }\n}\n\n/** Accumulate outflows per address from fees and transfers in the given transactions. */\nexport function accumulateOutflows(\n transactions: TransactionBoundWitnessWithHashMeta[],\n payloads: HydratedBlockWithHashMeta[1],\n): Record<XyoAddress, bigint> {\n const outflows: Record<XyoAddress, bigint> = {}\n\n for (const tx of transactions) {\n // Fee cost charged to the transaction sender\n const feeCost = maxTransactionFeeCost(tx)\n const feePayer = tx.from\n outflows[feePayer] = (outflows[feePayer] ?? 0n) + feeCost\n\n // Find transfer payloads belonging to this transaction\n const txPayloadHashes = new Set(tx.payload_hashes)\n for (const payload of payloads) {\n accumulateTransferOutflows(payload, txPayloadHashes, outflows)\n }\n }\n\n return outflows\n}\n\n/** Creates a block state validator that checks cumulative outflows per address do not exceed pre-block balances. */\nexport function BlockCumulativeBalanceValidatorFactory(): HydratedBlockStateValidationFunction {\n return async (context, hydratedBlock) => {\n const [blockBw, payloads] = hydratedBlock\n\n // Find all transactions in the block\n const transactions = payloads.filter(isTransactionBoundWitnessWithHashMeta)\n\n if (transactions.length === 0) return []\n\n const outflows = accumulateOutflows(transactions, payloads)\n\n // Query pre-block balances for all addresses with outflows\n const addresses = Object.keys(outflows) as XyoAddress[]\n if (addresses.length === 0) return []\n\n const balances = await context.accountBalance.accountBalances(addresses)\n\n // Check each address\n const chainId = await context.chainIdAtBlockNumber(blockBw.block)\n const errors: HydratedBlockStateValidationError[] = []\n for (const address of addresses) {\n if (address === XYO_ZERO_ADDRESS) continue // Skip zero address as it's used for burn transactions and doesn't have a balance\n // TODO: Add specific validation for block reward transfer\n const balance = balances[address] ?? 0n\n const totalOutflow = outflows[address]\n if (totalOutflow > balance) {\n errors.push(new HydratedBlockStateValidationError(\n blockBw._hash,\n chainId,\n hydratedBlock,\n `Cumulative outflow for address ${address} exceeds available balance: outflow ${totalOutflow} > balance ${balance}`,\n ))\n }\n }\n\n return errors\n }\n}\n", "import type { Hash, Promisable } from '@xylabs/sdk-js'\nimport { ZERO_HASH } from '@xylabs/sdk-js'\nimport type {\n BoundWitness,\n Payload,\n Schema,\n WithHashMeta,\n} from '@xyo-network/sdk-js'\nimport { isAnyPayload } from '@xyo-network/sdk-js'\nimport type { HydratedBoundWitnessValidationFunction, HydratedBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol-lib'\nimport { HydratedBoundWitnessValidationError } from '@xyo-network/xl1-protocol-lib'\n\nfunction getPayloadsFromPayloadArray(payloads: WithHashMeta<Payload>[], hashes: Hash[]): (WithHashMeta<Payload> | undefined)[] {\n return hashes.map(hash => payloads.find(payload => payload._hash === hash || payload._dataHash === hash))\n}\n\n/** Creates a validator that checks all payload references in a BoundWitness are present, have matching schemas, and optionally conform to an allowed schema list. */\nexport const BoundWitnessReferencesValidator\n\n = <T extends BoundWitness = BoundWitness>(allowedSchemas?: Schema[]): HydratedBoundWitnessValidationFunction<T> => (\n [bw, payloadSet]: HydratedBoundWitnessWithHashMeta<T>,\n // eslint-disable-next-line complexity\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 (const 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: ${String(ex)}`, ex)\n errors.push(error)\n }\n return errors\n }\n", "import { toArrayBuffer, ZERO_HASH } from '@xylabs/sdk-js'\nimport type {\n BoundWitness, WithStorageMeta, XyoAddress,\n} from '@xyo-network/sdk-js'\nimport { BoundWitnessBuilder, BoundWitnessValidator } from '@xyo-network/sdk-js'\nimport type { BoundWitnessValidationFunction } from '@xyo-network/xl1-protocol-lib'\nimport { BoundWitnessValidationError } from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that all signatures on a BoundWitness are cryptographically valid for their corresponding addresses. */\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: [XyoAddress, Error[]][] = await Promise.all(bw.addresses.map(async (address, index) => {\n return [address, await BoundWitnessValidator.validateSignature(\n toArrayBuffer(dataHash),\n address,\n toArrayBuffer(bw.$signatures[index] ?? undefined),\n )]\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 { ZERO_HASH } from '@xylabs/sdk-js'\nimport type { BoundWitness, WithHashMeta } from '@xyo-network/sdk-js'\nimport type {\n HydratedTransactionValidationFunction,\n HydratedTransactionValidationFunctionContext,\n HydratedTransactionWithHashMeta,\n} from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError, isTransactionBoundWitness } from '@xyo-network/xl1-protocol-lib'\n\nimport {\n TransactionBoundWitnessValidator,\n TransactionDurationValidator,\n TransactionElevationValidator, TransactionFromValidator, TransactionGasValidator, TransactionProtocolValidator,\n} from './validators/index.ts'\n\n/** Validates a hydrated transaction using built-in validators plus any additional validators provided. */\nexport const validateTransaction: HydratedTransactionValidationFunction = async (\n context: HydratedTransactionValidationFunctionContext,\n tx: HydratedTransactionWithHashMeta,\n additionalValidators?: HydratedTransactionValidationFunction[],\n): Promise<HydratedTransactionValidationError[]> => {\n try {\n if (!isTransactionBoundWitness(tx[0])) {\n const castTx = tx.at(0) as WithHashMeta<BoundWitness> | undefined\n return [new HydratedTransactionValidationError(\n castTx?._hash ?? ZERO_HASH,\n tx,\n 'failed isTransactionBoundWitness identity check',\n )]\n }\n\n const validators: HydratedTransactionValidationFunction<HydratedTransactionValidationFunctionContext>[] = [\n TransactionProtocolValidator,\n TransactionDurationValidator,\n TransactionFromValidator,\n TransactionGasValidator,\n TransactionElevationValidator,\n TransactionBoundWitnessValidator,\n ...(additionalValidators ?? []),\n ]\n const validationResults = await Promise.all(validators.map(async v => v(context, tx)))\n return validationResults.flat()\n } catch (ex) {\n const castTx = tx?.[0] as WithHashMeta<BoundWitness> | undefined\n return [new HydratedTransactionValidationError(\n castTx?._hash ?? ZERO_HASH,\n tx,\n 'Failed TransactionGasValidator: ' + (ex as Error).message,\n ex,\n )]\n }\n}\n", "import { XyoAddressZod } from '@xyo-network/sdk-js'\nimport { z } from 'zod'\n\nimport type { SignerValidator } from './TransactionTransfersValidator.ts'\nimport {\n CompletedStepRewardAddressValidatorFactory, DerivedReceiveAddressValidatorFactory, SelfSignerValidator,\n} from './TransactionTransfersValidator.ts'\n\n/** Authorizes the listed signers to sign for completed-step-reward addresses. */\nexport const CompletedStepRewardAuthorizationZod = z.object({\n type: z.literal('completedStepReward'),\n signers: z.array(XyoAddressZod),\n}).describe('Authorizes signers for completed-step-reward addresses')\n\n/** Authorizes the listed signers to sign for derived-receive addresses within a scope. */\nexport const DerivedReceiveAuthorizationZod = z.object({\n type: z.literal('derivedReceive'),\n scope: z.string(),\n signers: z.array(XyoAddressZod),\n}).describe('Authorizes signers for derived-receive addresses within a scope')\n\n/** A single signer authorization, discriminated by `type` (the deriving-function selector). */\nexport const SignerAuthorizationZod = z.discriminatedUnion('type', [\n CompletedStepRewardAuthorizationZod,\n DerivedReceiveAuthorizationZod,\n])\n\nexport type CompletedStepRewardAuthorization = z.infer<typeof CompletedStepRewardAuthorizationZod>\nexport type DerivedReceiveAuthorization = z.infer<typeof DerivedReceiveAuthorizationZod>\nexport type SignerAuthorization = z.infer<typeof SignerAuthorizationZod>\n\n/**\n * Registry mapping an authorization `type` to the SignerValidator factory that enforces it.\n * The exhaustive switch keeps each variant's params type-safe; add a new address family by\n * adding a union variant above and a case here.\n */\nfunction signerValidatorFromAuthorization(authorization: SignerAuthorization): SignerValidator {\n switch (authorization.type) {\n case 'completedStepReward': {\n return CompletedStepRewardAddressValidatorFactory(authorization.signers)\n }\n case 'derivedReceive': {\n return DerivedReceiveAddressValidatorFactory(authorization.signers, authorization.scope)\n }\n }\n}\n\n/**\n * Builds the `SignerValidator[]` consumed by `TransactionTransfersValidatorFactory` from a list\n * of authorizations. `SelfSignerValidator` is ALWAYS included so ordinary self-transfers pass;\n * an empty `authorizations` list therefore means \"self only\" \u2014 deny-all for reward/escrow families.\n */\nexport function signerValidatorsFromAuthorizations(authorizations: SignerAuthorization[] = []): SignerValidator[] {\n return [SelfSignerValidator, ...authorizations.map(signerValidatorFromAuthorization)]\n}\n", "import { isDefined, isUndefined } from '@xylabs/sdk-js'\nimport type { XyoAddress } from '@xyo-network/sdk-js'\nimport type {\n HydratedTransactionValidationFunction, StepIdentity,\n Transfer,\n} from '@xyo-network/xl1-protocol-lib'\nimport {\n derivedReceiveAddress,\n elevatedPayloads,\n HydratedTransactionValidationError,\n isTransfer,\n rewardAddressFromStepIdentity,\n} from '@xyo-network/xl1-protocol-lib'\n\n/** Function type that checks whether a signer is authorized to sign for a given signee address. */\nexport type SignerValidator = (signer: XyoAddress, signee: XyoAddress, context?: { address?: XyoAddress; scope?: string; step?: StepIdentity }) => boolean\n\n/** A signer validator that only allows an address to sign for itself. */\nexport const SelfSignerValidator: SignerValidator = (signer: XyoAddress, signee: XyoAddress) => signer === signee\n\n/** Creates a signer validator that authorizes specified signers to sign for completed step reward addresses. */\nexport const CompletedStepRewardAddressValidatorFactory = (allowedSigners: XyoAddress[]): SignerValidator => (\n signer: XyoAddress,\n signee: XyoAddress,\n context?: { step?: StepIdentity },\n) => {\n const step = context?.step\n if (isDefined(step)) {\n const contextAddress = rewardAddressFromStepIdentity(step)\n return allowedSigners.includes(signer) && signee === contextAddress\n }\n return false\n}\n\n/** Creates a signer validator that authorizes specified signers to sign for derived receive addresses within a given scope. */\nexport const DerivedReceiveAddressValidatorFactory = (allowedSigners: XyoAddress[], allowedScope: string): SignerValidator => (\n signer: XyoAddress,\n signee: XyoAddress,\n context?: { address?: XyoAddress; scope?: string },\n) => {\n const { address, scope } = context ?? {}\n if (scope !== allowedScope) {\n return false\n }\n if (isDefined(address)) {\n const derivedAddress = derivedReceiveAddress(address, scope)\n return allowedSigners.includes(signer) && signee === derivedAddress\n }\n return false\n}\n\n/** Creates a transaction validator that checks all transfers are authorized by the transaction signer. */\nexport function TransactionTransfersValidatorFactory(\n signerValidators: SignerValidator[] = [SelfSignerValidator],\n): HydratedTransactionValidationFunction {\n return async (\n context,\n hydratedTx,\n ) => {\n const errors: HydratedTransactionValidationError[] = []\n const signer = hydratedTx[0].from\n try {\n const payloads = elevatedPayloads(hydratedTx)\n const transfers = payloads.filter(isTransfer) as Transfer[]\n for (const transfer of transfers) {\n if (isUndefined(signerValidators.find(v => v(signer, transfer.from, transfer.context)))) {\n errors.push(new HydratedTransactionValidationError(\n hydratedTx[0]._hash,\n hydratedTx,\n `transfer from address ${transfer.from} is not authorized by signer ${signer}`,\n ))\n }\n }\n } catch (ex) {\n errors.push(new HydratedTransactionValidationError(hydratedTx[0]._hash, hydratedTx, 'validation excepted', ex))\n }\n return await Promise.resolve(errors)\n }\n}\n", "import { ZERO_HASH } from '@xylabs/sdk-js'\nimport { BoundWitnessValidator } from '@xyo-network/sdk-js'\nimport type { HydratedTransactionValidationFunction, HydratedTransactionWithHashMeta } from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\n\nconst error = (tx: HydratedTransactionWithHashMeta, message: string): HydratedTransactionValidationError =>\n new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, message)\n\n// Friendly pre-check for the wallet bug we want to surface clearly: signatures\n// emitted under `signatures` instead of `$signatures`. The downstream\n// BoundWitnessValidator would also catch the missing/mismatched signatures,\n// but its message (\"Length mismatch: address/signature\", \"Missing signature\n// [<address>]\") doesn't hint at the actual root cause.\nconst checkSignaturesShape = (tx: HydratedTransactionWithHashMeta): HydratedTransactionValidationError[] => {\n const bw = tx[0] as unknown as Record<string, unknown>\n if (bw.$signatures === undefined) {\n return Array.isArray(bw.signatures)\n ? [error(tx, 'BoundWitness has `signatures` but expected `$signatures` (signatures must be in the meta-prefixed `$signatures` key)')]\n : [error(tx, 'BoundWitness is missing `$signatures`')]\n }\n return []\n}\n\n/**\n * Validates the transaction's BoundWitness wholistically by delegating to\n * `BoundWitnessValidator.validate()`. This covers:\n * - signatures: length matches addresses, every signature is cryptographically\n * valid for its corresponding address against the BW data hash\n * - addresses: uniqueness\n * - array length parity: payload_hashes vs payload_schemas\n * - schemas: per-schema name validators\n * - top-level schema check\n * - PayloadValidator.schemaName check\n *\n * Also emits a friendly diagnostic when the common wallet bug of\n * `signatures` vs `$signatures` is detected, so the failure points at the\n * actual root cause instead of buried length/missing-signature errors.\n */\nexport const TransactionBoundWitnessValidator: HydratedTransactionValidationFunction = async (\n context,\n tx,\n) => {\n try {\n const shapeErrors = checkSignaturesShape(tx)\n if (shapeErrors.length > 0) return shapeErrors\n const bwValidator = new BoundWitnessValidator(tx[0])\n const bwErrors = await bwValidator.validate()\n return bwErrors.map(e => error(tx, `BoundWitness validation: ${e.message}`))\n } catch (ex) {\n return [error(tx, `Failed TransactionBoundWitnessValidator: ${String(ex)}`)]\n }\n}\n", "import { ZERO_HASH } from '@xylabs/sdk-js'\nimport type { HydratedTransactionValidationFunction } from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that transaction timing fields (nbf and exp) are positive, correctly ordered, and within allowed duration limits. */\nexport const TransactionDurationValidator: HydratedTransactionValidationFunction = (\n context,\n tx,\n// eslint-disable-next-line complexity\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: ${String(ex)}`,\n ex,\n ))\n }\n\n return errors\n}\n", "import { ZERO_HASH } from '@xylabs/sdk-js'\nimport type { HydratedTransactionValidationFunction } from '@xyo-network/xl1-protocol-lib'\nimport { extractElevatedHashes, HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that a hydrated transaction includes all required elevated script hashes. */\nexport const TransactionElevationValidator: HydratedTransactionValidationFunction = (\n context,\n tx,\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: ${String(ex)}`,\n ex,\n ))\n }\n return errors\n}\n", "import { ZERO_HASH } from '@xylabs/sdk-js'\nimport { addressesContains, asXyoAddress } from '@xyo-network/sdk-js'\nimport type { HydratedTransactionValidationFunction } from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that the transaction's from field is a valid address and is included in the BoundWitness addresses. */\nexport const TransactionFromValidator: HydratedTransactionValidationFunction = (\n context,\n tx,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n const from = asXyoAddress(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: ${String(ex)}`,\n ex,\n ))\n }\n return errors\n}\n", "import { hexToBigInt, ZERO_HASH } from '@xylabs/sdk-js'\nimport type {\n HydratedTransactionValidationFunction,\n TransactionFeesBigInt, TransactionFeesHex,\n} from '@xyo-network/xl1-protocol-lib'\nimport {\n AttoXL1,\n HydratedTransactionValidationError,\n minTransactionFees,\n} from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that transaction fee fields (base, gasLimit, gasPrice, priority) are present and meet minimum requirements. */\nexport const TransactionGasValidator: HydratedTransactionValidationFunction = (\n context,\n tx,\n// eslint-disable-next-line complexity\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: ${String(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/sdk-js'\nimport { PayloadBuilder } from '@xyo-network/sdk-js'\nimport type { HydratedTransactionValidationFunction, TransactionBoundWitness } from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\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\n/** Validates a transaction against the TransactionBoundWitness JSON schema using AJV. */\nexport const TransactionJsonSchemaValidator: HydratedTransactionValidationFunction = (\n context,\n tx,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n 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 validate.errors,\n )\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 { ZERO_HASH } from '@xylabs/sdk-js'\nimport type {\n ChainId,\n HydratedTransactionValidationFunction,\n} from '@xyo-network/xl1-protocol-lib'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol-lib'\n\n/** Validates that the transaction's chain ID matches the expected chain ID from the validation context. */\nexport const TransactionProtocolValidator: HydratedTransactionValidationFunction = async (\n context: { chainId?: ChainId },\n tx,\n) => {\n const errors: HydratedTransactionValidationError[] = []\n try {\n if (context?.chainId !== undefined && tx[0].chain !== context.chainId) {\n errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, `invalid chain id [${context.chainId}, ${tx[0].chain}]`))\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"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AClD,MAAI;AACF,QAAI,CAAC,0BAA0B,GAAG,CAAC,CAAC,GAAG;AACrC,YAAM,SAAS,GAAG,GAAG,CAAC;AACtB,aAAO,CAAC,IAAIE;AAAA,QACV,QAAQ,SAASC;AAAA,QACjB;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,UAAM,aAAoG;AAAA,MACxG;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAI,wBAAwB,CAAC;AAAA,IAC/B;AACA,UAAM,oBAAoB,MAAM,QAAQ,IAAI,WAAW,IAAI,OAAM,MAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AACrF,WAAO,kBAAkB,KAAK;AAAA,EAChC,SAAS,IAAI;AACX,UAAM,SAAS,KAAK,CAAC;AACrB,WAAO,CAAC,IAAID;AAAA,MACV,QAAQ,SAASC;AAAA,MACjB;AAAA,MACA,qCAAsC,GAAa;AAAA,MACnD;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
6
+ "names": ["error", "ZERO_HASH", "ZERO_HASH", "HydratedTransactionValidationError", "isTransfer", "ZERO_HASH", "BoundWitnessValidator", "HydratedTransactionValidationError", "ZERO_HASH", "HydratedTransactionValidationError", "ZERO_HASH", "HydratedTransactionValidationError", "ZERO_HASH", "HydratedTransactionValidationError", "hexToBigInt", "ZERO_HASH", "HydratedTransactionValidationError", "ZERO_HASH", "HydratedTransactionValidationError", "error", "ZERO_HASH", "HydratedTransactionValidationError", "HydratedTransactionValidationError", "ZERO_HASH"]
7
7
  }
@@ -0,0 +1,48 @@
1
+ import { z } from 'zod';
2
+ import type { SignerValidator } from './TransactionTransfersValidator.ts';
3
+ /** Authorizes the listed signers to sign for completed-step-reward addresses. */
4
+ export declare const CompletedStepRewardAuthorizationZod: z.ZodObject<{
5
+ type: z.ZodLiteral<"completedStepReward">;
6
+ signers: z.ZodArray<import("zod/mini").ZodMiniUnion<readonly [import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniTransform<Lowercase<string> & {
7
+ readonly __hex: true;
8
+ } & {
9
+ readonly __address: true;
10
+ }, string>>, import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniTransform<import("@xyo-network/sdk-js").XyoQuantAddress, string>>]>>;
11
+ }, z.core.$strip>;
12
+ /** Authorizes the listed signers to sign for derived-receive addresses within a scope. */
13
+ export declare const DerivedReceiveAuthorizationZod: z.ZodObject<{
14
+ type: z.ZodLiteral<"derivedReceive">;
15
+ scope: z.ZodString;
16
+ signers: z.ZodArray<import("zod/mini").ZodMiniUnion<readonly [import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniTransform<Lowercase<string> & {
17
+ readonly __hex: true;
18
+ } & {
19
+ readonly __address: true;
20
+ }, string>>, import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniTransform<import("@xyo-network/sdk-js").XyoQuantAddress, string>>]>>;
21
+ }, z.core.$strip>;
22
+ /** A single signer authorization, discriminated by `type` (the deriving-function selector). */
23
+ export declare const SignerAuthorizationZod: z.ZodDiscriminatedUnion<[z.ZodObject<{
24
+ type: z.ZodLiteral<"completedStepReward">;
25
+ signers: z.ZodArray<import("zod/mini").ZodMiniUnion<readonly [import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniTransform<Lowercase<string> & {
26
+ readonly __hex: true;
27
+ } & {
28
+ readonly __address: true;
29
+ }, string>>, import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniTransform<import("@xyo-network/sdk-js").XyoQuantAddress, string>>]>>;
30
+ }, z.core.$strip>, z.ZodObject<{
31
+ type: z.ZodLiteral<"derivedReceive">;
32
+ scope: z.ZodString;
33
+ signers: z.ZodArray<import("zod/mini").ZodMiniUnion<readonly [import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniTransform<Lowercase<string> & {
34
+ readonly __hex: true;
35
+ } & {
36
+ readonly __address: true;
37
+ }, string>>, import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniTransform<import("@xyo-network/sdk-js").XyoQuantAddress, string>>]>>;
38
+ }, z.core.$strip>], "type">;
39
+ export type CompletedStepRewardAuthorization = z.infer<typeof CompletedStepRewardAuthorizationZod>;
40
+ export type DerivedReceiveAuthorization = z.infer<typeof DerivedReceiveAuthorizationZod>;
41
+ export type SignerAuthorization = z.infer<typeof SignerAuthorizationZod>;
42
+ /**
43
+ * Builds the `SignerValidator[]` consumed by `TransactionTransfersValidatorFactory` from a list
44
+ * of authorizations. `SelfSignerValidator` is ALWAYS included so ordinary self-transfers pass;
45
+ * an empty `authorizations` list therefore means "self only" — deny-all for reward/escrow families.
46
+ */
47
+ export declare function signerValidatorsFromAuthorizations(authorizations?: SignerAuthorization[]): SignerValidator[];
48
+ //# sourceMappingURL=SignerAuthorization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignerAuthorization.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/SignerAuthorization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AAKzE,iFAAiF;AACjF,eAAO,MAAM,mCAAmC;;;;;;;iBAGqB,CAAA;AAErE,0FAA0F;AAC1F,eAAO,MAAM,8BAA8B;;;;;;;;iBAImC,CAAA;AAE9E,+FAA+F;AAC/F,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;2BAGjC,CAAA;AAEF,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mCAAmC,CAAC,CAAA;AAClG,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;AACxF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAkBxE;;;;GAIG;AACH,wBAAgB,kCAAkC,CAAC,cAAc,GAAE,mBAAmB,EAAO,GAAG,eAAe,EAAE,CAEhH"}
@@ -6,8 +6,6 @@ export type SignerValidator = (signer: XyoAddress, signee: XyoAddress, context?:
6
6
  scope?: string;
7
7
  step?: StepIdentity;
8
8
  }) => boolean;
9
- /** Maps addresses to their list of authorized signer addresses. */
10
- export type SignerMapping = Map<XyoAddress, XyoAddress[]>;
11
9
  /** A signer validator that only allows an address to sign for itself. */
12
10
  export declare const SelfSignerValidator: SignerValidator;
13
11
  /** Creates a signer validator that authorizes specified signers to sign for completed step reward addresses. */
@@ -1 +1 @@
1
- {"version":3,"file":"TransactionTransfersValidator.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/TransactionTransfersValidator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EACV,qCAAqC,EAAE,YAAY,EAEpD,MAAM,+BAA+B,CAAA;AAStC,mGAAmG;AACnG,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,UAAU,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,KAAK,OAAO,CAAA;AAE1J,mEAAmE;AACnE,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,CAAC,CAAA;AAEzD,yEAAyE;AACzE,eAAO,MAAM,mBAAmB,EAAE,eAA+E,CAAA;AAEjH,gHAAgH;AAChH,eAAO,MAAM,0CAA0C,GAAI,gBAAgB,UAAU,EAAE,KAAG,eAWzF,CAAA;AAED,+HAA+H;AAC/H,eAAO,MAAM,qCAAqC,GAAI,gBAAgB,UAAU,EAAE,EAAE,cAAc,MAAM,KAAG,eAc1G,CAAA;AAED,0GAA0G;AAC1G,wBAAgB,oCAAoC,CAClD,gBAAgB,GAAE,eAAe,EAA0B,GAC1D,qCAAqC,CAwBvC"}
1
+ {"version":3,"file":"TransactionTransfersValidator.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/TransactionTransfersValidator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EACV,qCAAqC,EAAE,YAAY,EAEpD,MAAM,+BAA+B,CAAA;AAStC,mGAAmG;AACnG,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,UAAU,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,KAAK,OAAO,CAAA;AAE1J,yEAAyE;AACzE,eAAO,MAAM,mBAAmB,EAAE,eAA+E,CAAA;AAEjH,gHAAgH;AAChH,eAAO,MAAM,0CAA0C,GAAI,gBAAgB,UAAU,EAAE,KAAG,eAWzF,CAAA;AAED,+HAA+H;AAC/H,eAAO,MAAM,qCAAqC,GAAI,gBAAgB,UAAU,EAAE,EAAE,cAAc,MAAM,KAAG,eAc1G,CAAA;AAED,0GAA0G;AAC1G,wBAAgB,oCAAoC,CAClD,gBAAgB,GAAE,eAAe,EAA0B,GAC1D,qCAAqC,CAwBvC"}
@@ -1,3 +1,4 @@
1
+ export * from './SignerAuthorization.ts';
1
2
  export * from './TransactionBoundWitnessValidator.ts';
2
3
  export * from './TransactionDurationValidator.ts';
3
4
  export * from './TransactionElevationValidator.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAA;AACrD,cAAc,mCAAmC,CAAA;AACjD,cAAc,oCAAoC,CAAA;AAClD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,qCAAqC,CAAA;AACnD,cAAc,mCAAmC,CAAA;AACjD,cAAc,oCAAoC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,uCAAuC,CAAA;AACrD,cAAc,mCAAmC,CAAA;AACjD,cAAc,oCAAoC,CAAA;AAClD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,qCAAqC,CAAA;AACnD,cAAc,mCAAmC,CAAA;AACjD,cAAc,oCAAoC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/xl1-validation",
3
- "version": "3.0.13",
3
+ "version": "3.0.14",
4
4
  "description": "XYO Layer One SDK Validation",
5
5
  "homepage": "https://xylabs.com",
6
6
  "bugs": {
@@ -34,8 +34,8 @@
34
34
  "README.md"
35
35
  ],
36
36
  "dependencies": {
37
- "@xyo-network/xl1-protocol-lib": "~3.0.13",
38
- "@xyo-network/xl1-schema": "~3.0.13"
37
+ "@xyo-network/xl1-protocol-lib": "~3.0.14",
38
+ "@xyo-network/xl1-schema": "~3.0.14"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@bitauth/libauth": "~3.0.0",