@xyo-network/xl1-validation 1.15.8 → 1.15.10
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/boundwitness/validators/BoundWitnessReferences.d.ts.map +1 -1
- package/dist/neutral/index.mjs +43 -4
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/transaction/validateTransaction.d.ts +6 -2
- package/dist/neutral/transaction/validateTransaction.d.ts.map +1 -1
- package/dist/neutral/transaction/validators/TransactionDurationValidator.d.ts.map +1 -1
- package/dist/neutral/transaction/validators/TransactionGasValidator.d.ts.map +1 -1
- package/dist/neutral/transaction/validators/TransactionTransfersValidator.d.ts +12 -0
- package/dist/neutral/transaction/validators/TransactionTransfersValidator.d.ts.map +1 -0
- package/dist/neutral/transaction/validators/index.d.ts +1 -0
- package/dist/neutral/transaction/validators/index.d.ts.map +1 -1
- package/package.json +10 -7
- package/src/boundwitness/validators/BoundWitnessReferences.ts +2 -1
- package/src/transaction/validateTransaction.ts +10 -3
- package/src/transaction/validators/TransactionDurationValidator.ts +1 -1
- package/src/transaction/validators/TransactionGasValidator.ts +1 -1
- package/src/transaction/validators/TransactionProtocolValidator.ts +2 -2
- package/src/transaction/validators/TransactionTransfersValidator.ts +55 -0
- package/src/transaction/validators/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BoundWitnessReferences.d.ts","sourceRoot":"","sources":["../../../../src/boundwitness/validators/BoundWitnessReferences.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,KAAK,EAEV,MAAM,EAEP,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EAAE,sCAAsC,EAA2C,MAAM,2BAA2B,CAAA;AAOhI,eAAO,MAAM,+BAA+B,GAEvC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,iBAAiB,MAAM,EAAE,KAAG,sCAAsC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"BoundWitnessReferences.d.ts","sourceRoot":"","sources":["../../../../src/boundwitness/validators/BoundWitnessReferences.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,KAAK,EAEV,MAAM,EAEP,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EAAE,sCAAsC,EAA2C,MAAM,2BAA2B,CAAA;AAOhI,eAAO,MAAM,+BAA+B,GAEvC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,iBAAiB,MAAM,EAAE,KAAG,sCAAsC,CAAC,CAAC,CAuC7G,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -207,10 +207,10 @@ var TransactionJsonSchemaValidator = /* @__PURE__ */ __name((tx) => {
|
|
|
207
207
|
// src/transaction/validators/TransactionProtocolValidator.ts
|
|
208
208
|
import { ZERO_HASH as ZERO_HASH8 } from "@xylabs/hex";
|
|
209
209
|
import { HydratedTransactionValidationError as HydratedTransactionValidationError6 } from "@xyo-network/xl1-protocol";
|
|
210
|
-
var TransactionProtocolValidator = /* @__PURE__ */ __name(async (tx,
|
|
210
|
+
var TransactionProtocolValidator = /* @__PURE__ */ __name(async (tx, context) => {
|
|
211
211
|
const errors = [];
|
|
212
212
|
try {
|
|
213
|
-
if (chainId !== void 0 && tx[0].chain !== chainId) {
|
|
213
|
+
if (context?.chainId !== void 0 && tx[0].chain !== context.chainId) {
|
|
214
214
|
errors.push(new HydratedTransactionValidationError6(tx?.[0]?._hash ?? ZERO_HASH8, tx, "invalid chain id"));
|
|
215
215
|
}
|
|
216
216
|
} catch (ex) {
|
|
@@ -219,8 +219,44 @@ var TransactionProtocolValidator = /* @__PURE__ */ __name(async (tx, chainId) =>
|
|
|
219
219
|
return await Promise.resolve(errors);
|
|
220
220
|
}, "TransactionProtocolValidator");
|
|
221
221
|
|
|
222
|
+
// src/transaction/validators/TransactionTransfersValidator.ts
|
|
223
|
+
import { isDefined, isUndefined } from "@xylabs/typeof";
|
|
224
|
+
import { completedStepRewardAddress, elevatedPayloads } from "@xyo-network/chain-protocol";
|
|
225
|
+
import { HydratedTransactionValidationError as HydratedTransactionValidationError7, isTransfer } from "@xyo-network/xl1-protocol";
|
|
226
|
+
var SelfSignerValidator = /* @__PURE__ */ __name((signer, signee) => signer === signee, "SelfSignerValidator");
|
|
227
|
+
var CompletedStepRewardAddressValidatorFactory = /* @__PURE__ */ __name((redeemers) => (signer, signee, context) => {
|
|
228
|
+
const step = context?.step;
|
|
229
|
+
if (isDefined(step)) {
|
|
230
|
+
const contextAddress = completedStepRewardAddress(step);
|
|
231
|
+
return redeemers.includes(signer) && signee === contextAddress;
|
|
232
|
+
} else {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}, "CompletedStepRewardAddressValidatorFactory");
|
|
236
|
+
function TransactionTransfersValidatorFactory(signerValidators = [
|
|
237
|
+
SelfSignerValidator
|
|
238
|
+
]) {
|
|
239
|
+
return async (hydratedTx) => {
|
|
240
|
+
const errors = [];
|
|
241
|
+
const signer = hydratedTx[0].from;
|
|
242
|
+
try {
|
|
243
|
+
const payloads = elevatedPayloads(hydratedTx);
|
|
244
|
+
const transfers = payloads.filter(isTransfer);
|
|
245
|
+
for (const transfer of transfers) {
|
|
246
|
+
if (isUndefined(signerValidators.find((v) => v(signer, transfer.from, transfer.context)))) {
|
|
247
|
+
errors.push(new HydratedTransactionValidationError7(hydratedTx[0]._hash, hydratedTx, `transfer from address ${transfer.from} is not authorized by signer ${signer}`));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
} catch (ex) {
|
|
251
|
+
errors.push(new HydratedTransactionValidationError7(hydratedTx[0]._hash, hydratedTx, "validation excepted", ex));
|
|
252
|
+
}
|
|
253
|
+
return await Promise.resolve(errors);
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
__name(TransactionTransfersValidatorFactory, "TransactionTransfersValidatorFactory");
|
|
257
|
+
|
|
222
258
|
// src/transaction/validateTransaction.ts
|
|
223
|
-
async function validateTransaction(tx,
|
|
259
|
+
async function validateTransaction(tx, context, additionalValidators = []) {
|
|
224
260
|
try {
|
|
225
261
|
if (!isTransactionBoundWitness(tx[0])) {
|
|
226
262
|
return [
|
|
@@ -235,7 +271,7 @@ async function validateTransaction(tx, chainId, additionalValidators = []) {
|
|
|
235
271
|
TransactionElevationValidator,
|
|
236
272
|
...additionalValidators
|
|
237
273
|
];
|
|
238
|
-
return (await Promise.all(validators.map((v) => v(tx,
|
|
274
|
+
return (await Promise.all(validators.map((v) => v(tx, context)))).flat();
|
|
239
275
|
} catch (ex) {
|
|
240
276
|
return [
|
|
241
277
|
new Error(`Failed TransactionGasValidator: ${ex}`)
|
|
@@ -246,12 +282,15 @@ __name(validateTransaction, "validateTransaction");
|
|
|
246
282
|
export {
|
|
247
283
|
BoundWitnessReferencesValidator,
|
|
248
284
|
BoundWitnessSignaturesValidator,
|
|
285
|
+
CompletedStepRewardAddressValidatorFactory,
|
|
286
|
+
SelfSignerValidator,
|
|
249
287
|
TransactionDurationValidator,
|
|
250
288
|
TransactionElevationValidator,
|
|
251
289
|
TransactionFromValidator,
|
|
252
290
|
TransactionGasValidator,
|
|
253
291
|
TransactionJsonSchemaValidator,
|
|
254
292
|
TransactionProtocolValidator,
|
|
293
|
+
TransactionTransfersValidatorFactory,
|
|
255
294
|
validateTransaction
|
|
256
295
|
};
|
|
257
296
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -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 {\n ChainId, HydratedTransactionValidationFunction,\n SignedHydratedTransactionWithStorageMeta,\n} 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: SignedHydratedTransactionWithStorageMeta,\n chainId?: ChainId,\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 HydratedTransactionValidationFunction, HydratedTransactionWithStorageMeta, 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: HydratedTransactionWithStorageMeta,\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 HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, 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: SignedHydratedTransactionWithStorageMeta,\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 HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\nexport const TransactionFromValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: SignedHydratedTransactionWithStorageMeta,\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 HydratedTransactionValidationFunction,\n SignedHydratedTransactionWithStorageMeta,\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: SignedHydratedTransactionWithStorageMeta,\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 HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, 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: SignedHydratedTransactionWithStorageMeta,\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 { ZERO_HASH } from '@xylabs/hex'\nimport type {\n ChainId,\n HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\nexport const TransactionProtocolValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = async (\n tx: SignedHydratedTransactionWithStorageMeta,\n chainId?: ChainId,\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,IAAIC,CAAAA,SAAQH,SAASI,KAAKC,CAAAA,YAAWA,QAAQC,UAAUH,QAAQE,QAAQE,cAAcJ,IAAAA,CAAAA;AACrG;AAFSJ;AAIF,IAAMS,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AC,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","../../src/transaction/validators/TransactionTransfersValidator.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\n = <T extends BoundWitness = BoundWitness>(allowedSchemas?: Schema[]): HydratedBoundWitnessValidationFunction<T> => (\n [bw, payloadSet]: HydratedBoundWitnessWithHashStorageMeta<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 (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 {\n ChainId, HydratedTransactionValidationFunction,\n SignedHydratedTransactionWithStorageMeta,\n StepIdentity,\n TransactionBoundWitness,\n} 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 type ValidateTransactionContext = {\n chainId?: ChainId\n step?: StepIdentity\n}\n\nexport async function validateTransaction(\n tx: SignedHydratedTransactionWithStorageMeta,\n context?: ValidateTransactionContext,\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<TransactionBoundWitness, ValidateTransactionContext>[] = [\n TransactionProtocolValidator,\n TransactionDurationValidator,\n TransactionFromValidator,\n TransactionGasValidator,\n TransactionElevationValidator,\n ...additionalValidators,\n ]\n return (await Promise.all(validators.map(v => v(tx, context)))).flat()\n } catch (ex) {\n return [(new Error(`Failed TransactionGasValidator: ${ex}`))]\n }\n}\n","import { ZERO_HASH } from '@xylabs/hex'\nimport type {\n HydratedTransactionValidationFunction, HydratedTransactionWithStorageMeta, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\nexport const TransactionDurationValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: HydratedTransactionWithStorageMeta,\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: ${ex}`,\n ex,\n ))\n }\n\n return errors\n}\n","import { ZERO_HASH } from '@xylabs/hex'\nimport type {\n HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, 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: SignedHydratedTransactionWithStorageMeta,\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 HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\nexport const TransactionFromValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: SignedHydratedTransactionWithStorageMeta,\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 HydratedTransactionValidationFunction,\n SignedHydratedTransactionWithStorageMeta,\n TransactionBoundWitness, TransactionFeesBigInt, TransactionFeesHex,\n} from '@xyo-network/xl1-protocol'\nimport {\n AttoXL1,\n HydratedTransactionValidationError,\n minTransactionFees,\n} from '@xyo-network/xl1-protocol'\n\nexport const TransactionGasValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (\n tx: SignedHydratedTransactionWithStorageMeta,\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: ${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 HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, 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: SignedHydratedTransactionWithStorageMeta,\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 { ZERO_HASH } from '@xylabs/hex'\nimport type {\n ChainId,\n HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, TransactionBoundWitness,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'\n\nexport const TransactionProtocolValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = async (\n tx: SignedHydratedTransactionWithStorageMeta,\n context?: { chainId?: ChainId },\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'))\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 type { Address } from '@xylabs/hex'\nimport { isDefined, isUndefined } from '@xylabs/typeof'\nimport { completedStepRewardAddress, elevatedPayloads } from '@xyo-network/chain-protocol'\nimport type {\n HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, StepIdentity, TransactionBoundWitness,\n Transfer,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError, isTransfer } from '@xyo-network/xl1-protocol'\n\nexport type SignerValidator = (signer: Address, signee: Address, context?: { step?: StepIdentity }) => boolean\n\nexport type SignerMapping = Map<Address, Address[]>\n\nexport const SelfSignerValidator: SignerValidator = (signer: Address, signee: Address) => signer === signee\n\nexport const CompletedStepRewardAddressValidatorFactory = (redeemers: Address[]): SignerValidator => (\n signer: Address,\n signee: Address,\n context?: { step?: StepIdentity },\n) => {\n const step = context?.step\n if (isDefined(step)) {\n const contextAddress = completedStepRewardAddress(step)\n return redeemers.includes(signer) && signee === contextAddress\n } else {\n return false\n }\n}\n\nexport function TransactionTransfersValidatorFactory(\n signerValidators: SignerValidator[] = [SelfSignerValidator],\n): HydratedTransactionValidationFunction<TransactionBoundWitness, { step?: StepIdentity }> {\n return async (\n hydratedTx: SignedHydratedTransactionWithStorageMeta,\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"],"mappings":";;;;AAAA,SAAoBA,iBAAiB;AAQrC,SAASC,oBAAoB;AAE7B,SAASC,2CAA2C;AAEpD,SAASC,4BAA4BC,UAA0CC,QAAc;AAC3F,SAAOA,OAAOC,IAAIC,CAAAA,SAAQH,SAASI,KAAKC,CAAAA,YAAWA,QAAQC,UAAUH,QAAQE,QAAQE,cAAcJ,IAAAA,CAAAA;AACrG;AAFSJ;AAIF,IAAMS,kCAET,wBAAwCC,mBAAyE,CACjH,CAACC,IAAIC,UAAAA,MAAuD;AAG5D,QAAMC,SAAgD,CAAA;AACtD,MAAI;AACF,UAAMZ,WAAWD,4BAA4BY,YAAYD,GAAGG,cAAc;AAC1E,QAAIb,SAASc,WAAWJ,GAAGG,eAAeC,QAAQ;AAChDF,aAAOG,KAAK,IAAIC,oCAAoCN,IAAIJ,SAASW,WAAW;QAACP;QAAIC;SAAa,2BAAA,CAAA;IAChG;AAGA,aAASN,WAAWL,UAAU;AAC5B,UAAIkB,aAAab,OAAAA,GAAU;AACzB,cA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AAEA,UAAMC,SAA+C,CAAA;AACrD,UAAMb,SAASY,WAAW,CAAA,EAAGE;AAC7B,QAAI;AACF,YAAMC,WAAWC,iBAAiBJ,UAAAA;AAClC,YAAMK,YAAYF,SAASG,OAAOC,UAAAA;AAClC,iBAAWC,YAAYH,WAAW;AAChC,YAAII,YAAYV,iBAAiBW,KAAKC,CAAAA,MAAKA,EAAEvB,QAAQoB,SAASN,MAAMM,SAAShB,OAAO,CAAA,CAAA,GAAK;AACvFS,iBAAOW,KAAK,IAAIC,oCACdb,WAAW,CAAA,EAAGc,OACdd,YACA,yBAAyBQ,SAASN,IAAI,gCAAgCd,MAAAA,EAAQ,CAAA;QAElF;MACF;IACF,SAAS2B,IAAI;AACXd,aAAOW,KAAK,IAAIC,oCAAmCb,WAAW,CAAA,EAAGc,OAAOd,YAAY,uBAAuBe,EAAAA,CAAAA;IAC7G;AACA,WAAO,MAAMC,QAAQC,QAAQhB,MAAAA;EAC/B;AACF;AAzBgBH;;;APXhB,eAAsBoB,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,aAA2G;MAC/GC;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","context","errors","chainId","undefined","chain","push","HydratedTransactionValidationError","_hash","ZERO_HASH","ex","Promise","resolve","isDefined","isUndefined","completedStepRewardAddress","elevatedPayloads","HydratedTransactionValidationError","isTransfer","SelfSignerValidator","signer","signee","CompletedStepRewardAddressValidatorFactory","redeemers","context","step","isDefined","contextAddress","completedStepRewardAddress","includes","TransactionTransfersValidatorFactory","signerValidators","hydratedTx","errors","from","payloads","elevatedPayloads","transfers","filter","isTransfer","transfer","isUndefined","find","v","push","HydratedTransactionValidationError","_hash","ex","Promise","resolve","validateTransaction","tx","context","additionalValidators","isTransactionBoundWitness","Error","validators","TransactionProtocolValidator","TransactionDurationValidator","TransactionFromValidator","TransactionGasValidator","TransactionElevationValidator","Promise","all","map","v","flat","ex"]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import type { ChainId, HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol';
|
|
2
|
-
export
|
|
1
|
+
import type { ChainId, HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, StepIdentity } from '@xyo-network/xl1-protocol';
|
|
2
|
+
export type ValidateTransactionContext = {
|
|
3
|
+
chainId?: ChainId;
|
|
4
|
+
step?: StepIdentity;
|
|
5
|
+
};
|
|
6
|
+
export declare function validateTransaction(tx: SignedHydratedTransactionWithStorageMeta, context?: ValidateTransactionContext, additionalValidators?: HydratedTransactionValidationFunction[]): Promise<Error[]>;
|
|
3
7
|
//# sourceMappingURL=validateTransaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTransaction.d.ts","sourceRoot":"","sources":["../../../src/transaction/validateTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAAE,qCAAqC,EAC9C,wCAAwC,
|
|
1
|
+
{"version":3,"file":"validateTransaction.d.ts","sourceRoot":"","sources":["../../../src/transaction/validateTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAAE,qCAAqC,EAC9C,wCAAwC,EACxC,YAAY,EAEb,MAAM,2BAA2B,CAAA;AAQlC,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,CAAC,EAAE,YAAY,CAAA;CACpB,CAAA;AAED,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,wCAAwC,EAC5C,OAAO,CAAC,EAAE,0BAA0B,EACpC,oBAAoB,GAAE,qCAAqC,EAAO,oBAmBnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionDurationValidator.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/TransactionDurationValidator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qCAAqC,EAAsC,uBAAuB,EACnG,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"TransactionDurationValidator.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/TransactionDurationValidator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qCAAqC,EAAsC,uBAAuB,EACnG,MAAM,2BAA2B,CAAA;AAGlC,eAAO,MAAM,4BAA4B,EAAE,qCAAqC,CAAC,uBAAuB,CA0BvG,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionGasValidator.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/TransactionGasValidator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qCAAqC,EAErC,uBAAuB,EACxB,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"TransactionGasValidator.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/TransactionGasValidator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qCAAqC,EAErC,uBAAuB,EACxB,MAAM,2BAA2B,CAAA;AAOlC,eAAO,MAAM,uBAAuB,EAAE,qCAAqC,CAAC,uBAAuB,CAwElG,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Address } from '@xylabs/hex';
|
|
2
|
+
import type { HydratedTransactionValidationFunction, StepIdentity, TransactionBoundWitness } from '@xyo-network/xl1-protocol';
|
|
3
|
+
export type SignerValidator = (signer: Address, signee: Address, context?: {
|
|
4
|
+
step?: StepIdentity;
|
|
5
|
+
}) => boolean;
|
|
6
|
+
export type SignerMapping = Map<Address, Address[]>;
|
|
7
|
+
export declare const SelfSignerValidator: SignerValidator;
|
|
8
|
+
export declare const CompletedStepRewardAddressValidatorFactory: (redeemers: Address[]) => SignerValidator;
|
|
9
|
+
export declare function TransactionTransfersValidatorFactory(signerValidators?: SignerValidator[]): HydratedTransactionValidationFunction<TransactionBoundWitness, {
|
|
10
|
+
step?: StepIdentity;
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=TransactionTransfersValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactionTransfersValidator.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/TransactionTransfersValidator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,KAAK,EACV,qCAAqC,EAA4C,YAAY,EAAE,uBAAuB,EAEvH,MAAM,2BAA2B,CAAA;AAGlC,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,KAAK,OAAO,CAAA;AAE9G,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;AAEnD,eAAO,MAAM,mBAAmB,EAAE,eAAyE,CAAA;AAE3G,eAAO,MAAM,0CAA0C,GAAI,WAAW,OAAO,EAAE,KAAG,eAYjF,CAAA;AAED,wBAAgB,oCAAoC,CAClD,gBAAgB,GAAE,eAAe,EAA0B,GAC1D,qCAAqC,CAAC,uBAAuB,EAAE;IAAE,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,CAAC,CAuBzF"}
|
|
@@ -4,4 +4,5 @@ export * from './TransactionFromValidator.ts';
|
|
|
4
4
|
export * from './TransactionGasValidator.ts';
|
|
5
5
|
export * from './TransactionJsonSchemaValidator.ts';
|
|
6
6
|
export * from './TransactionProtocolValidator.ts';
|
|
7
|
+
export * from './TransactionTransfersValidator.ts';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA;AACjD,cAAc,oCAAoC,CAAA;AAClD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,qCAAqC,CAAA;AACnD,cAAc,mCAAmC,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transaction/validators/index.ts"],"names":[],"mappings":"AAAA,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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/xl1-validation",
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.10",
|
|
5
5
|
"description": "XYO Layer One SDK Validation",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -38,29 +38,32 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@xylabs/arraybuffer": "~5.0.12",
|
|
40
40
|
"@xylabs/hex": "~5.0.12",
|
|
41
|
+
"@xylabs/typeof": "~5.0.12",
|
|
41
42
|
"@xyo-network/boundwitness-builder": "~5.1.6",
|
|
42
43
|
"@xyo-network/boundwitness-model": "~5.1.6",
|
|
43
44
|
"@xyo-network/boundwitness-validator": "~5.1.6",
|
|
45
|
+
"@xyo-network/chain-protocol": "~1.15.10",
|
|
44
46
|
"@xyo-network/payload-builder": "~5.1.6",
|
|
45
47
|
"@xyo-network/payload-model": "~5.1.6",
|
|
46
|
-
"@xyo-network/xl1-protocol": "~1.12.
|
|
47
|
-
"@xyo-network/xl1-protocol-sdk": "~1.15.
|
|
48
|
-
"@xyo-network/xl1-schema": "~1.15.
|
|
48
|
+
"@xyo-network/xl1-protocol": "~1.12.81",
|
|
49
|
+
"@xyo-network/xl1-protocol-sdk": "~1.15.10",
|
|
50
|
+
"@xyo-network/xl1-schema": "~1.15.10",
|
|
49
51
|
"ajv": "~8.17.1"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
|
-
"@types/node": "~24.
|
|
54
|
+
"@types/node": "~24.9.1",
|
|
53
55
|
"@xylabs/assert": "~5.0.12",
|
|
54
56
|
"@xylabs/promise": "~5.0.12",
|
|
55
57
|
"@xylabs/ts-scripts-yarn3": "~7.1.8",
|
|
56
58
|
"@xylabs/tsconfig": "~7.1.8",
|
|
59
|
+
"@xylabs/typeof": "~5.0.12",
|
|
57
60
|
"@xyo-network/account": "~5.1.6",
|
|
58
61
|
"@xyo-network/account-model": "~5.1.6",
|
|
59
62
|
"@xyo-network/archivist-memory": "~5.1.6",
|
|
60
63
|
"@xyo-network/archivist-model": "~5.1.6",
|
|
61
|
-
"@xyo-network/chain-protocol": "~1.15.
|
|
64
|
+
"@xyo-network/chain-protocol": "~1.15.10",
|
|
62
65
|
"@xyo-network/wallet": "~5.1.6",
|
|
63
|
-
"eslint": "^9.
|
|
66
|
+
"eslint": "^9.38.0",
|
|
64
67
|
"typescript": "~5.9.3",
|
|
65
68
|
"vitest": "~3.2.4"
|
|
66
69
|
},
|
|
@@ -15,9 +15,10 @@ function getPayloadsFromPayloadArray(payloads: WithHashStorageMeta<Payload>[], h
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export const BoundWitnessReferencesValidator
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
= <T extends BoundWitness = BoundWitness>(allowedSchemas?: Schema[]): HydratedBoundWitnessValidationFunction<T> => (
|
|
20
20
|
[bw, payloadSet]: HydratedBoundWitnessWithHashStorageMeta<T>,
|
|
21
|
+
// eslint-disable-next-line complexity
|
|
21
22
|
): Promisable<HydratedBoundWitnessValidationError[]> => {
|
|
22
23
|
const errors: HydratedBoundWitnessValidationError[] = []
|
|
23
24
|
try {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ChainId, HydratedTransactionValidationFunction,
|
|
3
3
|
SignedHydratedTransactionWithStorageMeta,
|
|
4
|
+
StepIdentity,
|
|
5
|
+
TransactionBoundWitness,
|
|
4
6
|
} from '@xyo-network/xl1-protocol'
|
|
5
7
|
import { isTransactionBoundWitness } from '@xyo-network/xl1-protocol'
|
|
6
8
|
|
|
@@ -9,9 +11,14 @@ import {
|
|
|
9
11
|
TransactionElevationValidator, TransactionFromValidator, TransactionGasValidator, TransactionProtocolValidator,
|
|
10
12
|
} from './validators/index.ts'
|
|
11
13
|
|
|
14
|
+
export type ValidateTransactionContext = {
|
|
15
|
+
chainId?: ChainId
|
|
16
|
+
step?: StepIdentity
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
export async function validateTransaction(
|
|
13
20
|
tx: SignedHydratedTransactionWithStorageMeta,
|
|
14
|
-
|
|
21
|
+
context?: ValidateTransactionContext,
|
|
15
22
|
additionalValidators: HydratedTransactionValidationFunction[] = [],
|
|
16
23
|
) {
|
|
17
24
|
try {
|
|
@@ -19,7 +26,7 @@ export async function validateTransaction(
|
|
|
19
26
|
return [new Error('failed isTransactionBoundWitness identity check')]
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
const validators: HydratedTransactionValidationFunction[] = [
|
|
29
|
+
const validators: HydratedTransactionValidationFunction<TransactionBoundWitness, ValidateTransactionContext>[] = [
|
|
23
30
|
TransactionProtocolValidator,
|
|
24
31
|
TransactionDurationValidator,
|
|
25
32
|
TransactionFromValidator,
|
|
@@ -27,7 +34,7 @@ export async function validateTransaction(
|
|
|
27
34
|
TransactionElevationValidator,
|
|
28
35
|
...additionalValidators,
|
|
29
36
|
]
|
|
30
|
-
return (await Promise.all(validators.map(v => v(tx,
|
|
37
|
+
return (await Promise.all(validators.map(v => v(tx, context)))).flat()
|
|
31
38
|
} catch (ex) {
|
|
32
39
|
return [(new Error(`Failed TransactionGasValidator: ${ex}`))]
|
|
33
40
|
}
|
|
@@ -4,9 +4,9 @@ import type {
|
|
|
4
4
|
} from '@xyo-network/xl1-protocol'
|
|
5
5
|
import { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'
|
|
6
6
|
|
|
7
|
-
// eslint-disable-next-line complexity
|
|
8
7
|
export const TransactionDurationValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (
|
|
9
8
|
tx: HydratedTransactionWithStorageMeta,
|
|
9
|
+
// eslint-disable-next-line complexity
|
|
10
10
|
) => {
|
|
11
11
|
const errors: HydratedTransactionValidationError[] = []
|
|
12
12
|
try {
|
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
minTransactionFees,
|
|
11
11
|
} from '@xyo-network/xl1-protocol'
|
|
12
12
|
|
|
13
|
-
// eslint-disable-next-line complexity
|
|
14
13
|
export const TransactionGasValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = (
|
|
15
14
|
tx: SignedHydratedTransactionWithStorageMeta,
|
|
15
|
+
// eslint-disable-next-line complexity
|
|
16
16
|
) => {
|
|
17
17
|
const errors: HydratedTransactionValidationError[] = []
|
|
18
18
|
try {
|
|
@@ -7,11 +7,11 @@ import { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'
|
|
|
7
7
|
|
|
8
8
|
export const TransactionProtocolValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = async (
|
|
9
9
|
tx: SignedHydratedTransactionWithStorageMeta,
|
|
10
|
-
chainId?: ChainId,
|
|
10
|
+
context?: { chainId?: ChainId },
|
|
11
11
|
) => {
|
|
12
12
|
const errors: HydratedTransactionValidationError[] = []
|
|
13
13
|
try {
|
|
14
|
-
if (chainId !== undefined && tx[0].chain !== chainId) {
|
|
14
|
+
if (context?.chainId !== undefined && tx[0].chain !== context.chainId) {
|
|
15
15
|
errors.push(new HydratedTransactionValidationError(tx?.[0]?._hash ?? ZERO_HASH, tx, 'invalid chain id'))
|
|
16
16
|
}
|
|
17
17
|
} catch (ex) {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Address } from '@xylabs/hex'
|
|
2
|
+
import { isDefined, isUndefined } from '@xylabs/typeof'
|
|
3
|
+
import { completedStepRewardAddress, elevatedPayloads } from '@xyo-network/chain-protocol'
|
|
4
|
+
import type {
|
|
5
|
+
HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, StepIdentity, TransactionBoundWitness,
|
|
6
|
+
Transfer,
|
|
7
|
+
} from '@xyo-network/xl1-protocol'
|
|
8
|
+
import { HydratedTransactionValidationError, isTransfer } from '@xyo-network/xl1-protocol'
|
|
9
|
+
|
|
10
|
+
export type SignerValidator = (signer: Address, signee: Address, context?: { step?: StepIdentity }) => boolean
|
|
11
|
+
|
|
12
|
+
export type SignerMapping = Map<Address, Address[]>
|
|
13
|
+
|
|
14
|
+
export const SelfSignerValidator: SignerValidator = (signer: Address, signee: Address) => signer === signee
|
|
15
|
+
|
|
16
|
+
export const CompletedStepRewardAddressValidatorFactory = (redeemers: Address[]): SignerValidator => (
|
|
17
|
+
signer: Address,
|
|
18
|
+
signee: Address,
|
|
19
|
+
context?: { step?: StepIdentity },
|
|
20
|
+
) => {
|
|
21
|
+
const step = context?.step
|
|
22
|
+
if (isDefined(step)) {
|
|
23
|
+
const contextAddress = completedStepRewardAddress(step)
|
|
24
|
+
return redeemers.includes(signer) && signee === contextAddress
|
|
25
|
+
} else {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function TransactionTransfersValidatorFactory(
|
|
31
|
+
signerValidators: SignerValidator[] = [SelfSignerValidator],
|
|
32
|
+
): HydratedTransactionValidationFunction<TransactionBoundWitness, { step?: StepIdentity }> {
|
|
33
|
+
return async (
|
|
34
|
+
hydratedTx: SignedHydratedTransactionWithStorageMeta,
|
|
35
|
+
) => {
|
|
36
|
+
const errors: HydratedTransactionValidationError[] = []
|
|
37
|
+
const signer = hydratedTx[0].from
|
|
38
|
+
try {
|
|
39
|
+
const payloads = elevatedPayloads(hydratedTx)
|
|
40
|
+
const transfers = payloads.filter(isTransfer) as Transfer[]
|
|
41
|
+
for (const transfer of transfers) {
|
|
42
|
+
if (isUndefined(signerValidators.find(v => v(signer, transfer.from, transfer.context)))) {
|
|
43
|
+
errors.push(new HydratedTransactionValidationError(
|
|
44
|
+
hydratedTx[0]._hash,
|
|
45
|
+
hydratedTx,
|
|
46
|
+
`transfer from address ${transfer.from} is not authorized by signer ${signer}`,
|
|
47
|
+
))
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} catch (ex) {
|
|
51
|
+
errors.push(new HydratedTransactionValidationError(hydratedTx[0]._hash, hydratedTx, 'validation excepted', ex))
|
|
52
|
+
}
|
|
53
|
+
return await Promise.resolve(errors)
|
|
54
|
+
}
|
|
55
|
+
}
|