@xyo-network/xl1-validation 1.15.9 → 1.15.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/index.mjs +56 -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/TransactionTransfersValidator.d.ts +15 -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 +8 -6
- package/src/transaction/validateTransaction.ts +10 -3
- package/src/transaction/validators/TransactionProtocolValidator.ts +2 -2
- package/src/transaction/validators/TransactionTransfersValidator.ts +74 -0
- package/src/transaction/validators/index.ts +1 -0
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,56 @@ 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 { HydratedTransactionValidationError as HydratedTransactionValidationError7, isTransfer } from "@xyo-network/xl1-protocol";
|
|
225
|
+
import { completedStepRewardAddress, derivedReceiveAddress, elevatedPayloads } from "@xyo-network/xl1-protocol-sdk";
|
|
226
|
+
var SelfSignerValidator = /* @__PURE__ */ __name((signer, signee) => signer === signee, "SelfSignerValidator");
|
|
227
|
+
var CompletedStepRewardAddressValidatorFactory = /* @__PURE__ */ __name((allowedSigners) => (signer, signee, context) => {
|
|
228
|
+
const step = context?.step;
|
|
229
|
+
if (isDefined(step)) {
|
|
230
|
+
const contextAddress = completedStepRewardAddress(step);
|
|
231
|
+
return allowedSigners.includes(signer) && signee === contextAddress;
|
|
232
|
+
} else {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}, "CompletedStepRewardAddressValidatorFactory");
|
|
236
|
+
var DerivedReceiveAddressValidatorFactory = /* @__PURE__ */ __name((allowedSigners, allowedScope) => (signer, signee, context) => {
|
|
237
|
+
const { address, scope } = context ?? {};
|
|
238
|
+
if (scope !== allowedScope) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
if (isDefined(address)) {
|
|
242
|
+
const derivedAddress = derivedReceiveAddress(address, scope);
|
|
243
|
+
return allowedSigners.includes(signer) && signee === derivedAddress;
|
|
244
|
+
} else {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
}, "DerivedReceiveAddressValidatorFactory");
|
|
248
|
+
function TransactionTransfersValidatorFactory(signerValidators = [
|
|
249
|
+
SelfSignerValidator
|
|
250
|
+
]) {
|
|
251
|
+
return async (hydratedTx) => {
|
|
252
|
+
const errors = [];
|
|
253
|
+
const signer = hydratedTx[0].from;
|
|
254
|
+
try {
|
|
255
|
+
const payloads = elevatedPayloads(hydratedTx);
|
|
256
|
+
const transfers = payloads.filter(isTransfer);
|
|
257
|
+
for (const transfer of transfers) {
|
|
258
|
+
if (isUndefined(signerValidators.find((v) => v(signer, transfer.from, transfer.context)))) {
|
|
259
|
+
errors.push(new HydratedTransactionValidationError7(hydratedTx[0]._hash, hydratedTx, `transfer from address ${transfer.from} is not authorized by signer ${signer}`));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
} catch (ex) {
|
|
263
|
+
errors.push(new HydratedTransactionValidationError7(hydratedTx[0]._hash, hydratedTx, "validation excepted", ex));
|
|
264
|
+
}
|
|
265
|
+
return await Promise.resolve(errors);
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
__name(TransactionTransfersValidatorFactory, "TransactionTransfersValidatorFactory");
|
|
269
|
+
|
|
222
270
|
// src/transaction/validateTransaction.ts
|
|
223
|
-
async function validateTransaction(tx,
|
|
271
|
+
async function validateTransaction(tx, context, additionalValidators = []) {
|
|
224
272
|
try {
|
|
225
273
|
if (!isTransactionBoundWitness(tx[0])) {
|
|
226
274
|
return [
|
|
@@ -235,7 +283,7 @@ async function validateTransaction(tx, chainId, additionalValidators = []) {
|
|
|
235
283
|
TransactionElevationValidator,
|
|
236
284
|
...additionalValidators
|
|
237
285
|
];
|
|
238
|
-
return (await Promise.all(validators.map((v) => v(tx,
|
|
286
|
+
return (await Promise.all(validators.map((v) => v(tx, context)))).flat();
|
|
239
287
|
} catch (ex) {
|
|
240
288
|
return [
|
|
241
289
|
new Error(`Failed TransactionGasValidator: ${ex}`)
|
|
@@ -246,12 +294,16 @@ __name(validateTransaction, "validateTransaction");
|
|
|
246
294
|
export {
|
|
247
295
|
BoundWitnessReferencesValidator,
|
|
248
296
|
BoundWitnessSignaturesValidator,
|
|
297
|
+
CompletedStepRewardAddressValidatorFactory,
|
|
298
|
+
DerivedReceiveAddressValidatorFactory,
|
|
299
|
+
SelfSignerValidator,
|
|
249
300
|
TransactionDurationValidator,
|
|
250
301
|
TransactionElevationValidator,
|
|
251
302
|
TransactionFromValidator,
|
|
252
303
|
TransactionGasValidator,
|
|
253
304
|
TransactionJsonSchemaValidator,
|
|
254
305
|
TransactionProtocolValidator,
|
|
306
|
+
TransactionTransfersValidatorFactory,
|
|
255
307
|
validateTransaction
|
|
256
308
|
};
|
|
257
309
|
//# 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\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} 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\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 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,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,cAAMc,mBAAmBT,GAAGG,eAAeO,QAAQf,QAAQC,KAAK;AAChE,cAAMe,uBAAuBX,GAAGG,eAAeO,QAAQf,QAAQE,SAAS;AACxE,cAAMe,eAAeC,KAAKC,IAAIL,kBAAkBE,oBAAAA;AAChD,YAAIC,iBAAiB,IAAI;AACvBV,iBAAOG,KAAK,IAAIC,oCAAoCN,IAAIJ,SAASW,WAAW;YAACP;YAAIC;aAAa,wBAAA,CAAA;QAChG;AAEA,cAAMc,i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C,sCAAAA,2CAA0C;AAE5C,IAAMC,+BAA+F,8BAC1GC,IACAC,YAAAA;AAEA,QAAMC,SAA+C,CAAA;AACrD,MAAI;AACF,QAAID,YAAYE,UAAaH,GAAG,CAAA,EAAGI,UAAUH,SAAS;AACpDC,aAAOG,KAAK,IAAIC,oCAAmCN,KAAK,CAAA,GAAIO,SAASC,YAAWR,IAAI,kBAAA,CAAA;IACtF;EACF,SAASS,IAAI;AACXP,WAAOG,KAAK,IAAIC,oCAAmCN,KAAK,CAAA,GAAIO,SAASC,YAAWR,IAAI,uBAAuBS,EAAAA,CAAAA;EAC7G;AACA,SAAO,MAAMC,QAAQC,QAAQT,MAAAA;AAC/B,GAb4G;;;ANI5G,eAAsBU,oBACpBC,IACAC,SACAC,uBAAgE,CAAA,GAAE;AAElE,MAAI;AACF,QAAI,CAACC,0BAA0BH,GAAG,CAAA,CAAE,GAAG;AACrC,aAAO;QAAC,IAAII,MAAM,iDAAA;;IACpB;AAEA,UAAMC,aAAsD;MAC1DC;MACAC;MACAC;MACAC;MACAC;SACGR;;AAEL,YAAQ,MAAMS,QAAQC,IAAIP,WAAWQ,IAAIC,CAAAA,MAAKA,EAAEd,IAAIC,OAAAA,CAAAA,CAAAA,GAAYc,KAAI;EACtE,SAASC,IAAI;AACX,WAAO;MAAE,IAAIZ,MAAM,mCAAmCY,EAAAA,EAAI;;EAC5D;AACF;AAtBsBjB;","names":["ZERO_HASH","isAnyPayload","HydratedBoundWitnessValidationError","getPayloadsFromPayloadArray","payloads","hashes","map","hash","find","payload","_hash","_dataHash","BoundWitnessReferencesValidator","allowedSchemas","bw","payloadSet","errors","payload_hashes","length","push","HydratedBoundWitnessValidationError","ZERO_HASH","isAnyPayload","payloadHashIndex","indexOf","payloadDataHashIndex","payloadIndex","Math","max","declaredSchema","payload_schemas","schema","includes","ex","error","cause","toArrayBuffer","ZERO_HASH","BoundWitnessBuilder","BoundWitnessValidator","BoundWitnessValidationError","BoundWitnessSignaturesValidator","bw","errors","dataHash","BoundWitnessBuilder","results","Promise","all","addresses","map","address","index","BoundWitnessValidator","validateSignature","toArrayBuffer","$signatures","bwErrors","bwError","push","BoundWitnessValidationError","_hash","ZERO_HASH","ex","isTransactionBoundWitness","ZERO_HASH","HydratedTransactionValidationError","TransactionDurationValidator","tx","errors","exp","nbf","push","HydratedTransactionValidationError","_hash","ZERO_HASH","ex","ZERO_HASH","HydratedTransactionValidationError","extractElevatedHashes","TransactionElevationValidator","tx","errors","extractElevatedHashes","push","HydratedTransactionValidationError","_hash","ZERO_HASH","ex","asAddress","ZERO_HASH","addressesContains","HydratedTransactionValidationError","TransactionFromValidator","tx","errors","from","asAddress","undefined","push","HydratedTransactionValidationError","_hash","ZERO_HASH","addressesContains","ex","hexToBigInt","ZERO_HASH","AttoXL1","HydratedTransactionValidationError","minTransactionFees","TransactionGasValidator","tx","errors","fees","undefined","push","HydratedTransactionValidationError","_hash","ZERO_HASH","base","gasLimit","gasPrice","priority","parseFees","minTransactionFees","ex","ret","AttoXL1","hexToBigInt","ZERO_HASH","PayloadBuilder","HydratedTransactionValidationError","TransactionBoundWitnessJsonSchema","Ajv","ajv","Ajv","allErrors","strict","validate","TransactionJsonSchemaValidator","tx","errors","undefined","compile","TransactionBoundWitnessJsonSchema","PayloadBuilder","omitStorageMeta","error","HydratedTransactionValidationError","_hash","ZERO_HASH","errorsText","separator","cause","push","ex","ZERO_HASH","HydratedTransactionValidationError","TransactionProtocolValidator","tx","chainId","errors","undefined","chain","push","HydratedTransactionValidationError","_hash","ZERO_HASH","ex","Promise","resolve","validateTransaction","tx","chainId","additionalValidators","isTransactionBoundWitness","Error","validators","TransactionProtocolValidator","TransactionDurationValidator","TransactionFromValidator","TransactionGasValidator","TransactionElevationValidator","Promise","all","map","v","flat","ex"]}
|
|
1
|
+
{"version":3,"sources":["../../src/boundwitness/validators/BoundWitnessReferences.ts","../../src/boundwitness/validators/BoundWitnessSignatures.ts","../../src/transaction/validateTransaction.ts","../../src/transaction/validators/TransactionDurationValidator.ts","../../src/transaction/validators/TransactionElevationValidator.ts","../../src/transaction/validators/TransactionFromValidator.ts","../../src/transaction/validators/TransactionGasValidator.ts","../../src/transaction/validators/TransactionJsonSchemaValidator.ts","../../src/transaction/validators/TransactionProtocolValidator.ts","../../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 type {\n HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, StepIdentity, TransactionBoundWitness,\n Transfer,\n} from '@xyo-network/xl1-protocol'\nimport { HydratedTransactionValidationError, isTransfer } from '@xyo-network/xl1-protocol'\nimport {\n completedStepRewardAddress, derivedReceiveAddress, elevatedPayloads,\n} from '@xyo-network/xl1-protocol-sdk'\n\nexport type SignerValidator = (signer: Address, signee: Address, context?: { address?: Address; scope?: string; 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 = (allowedSigners: 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 allowedSigners.includes(signer) && signee === contextAddress\n } else {\n return false\n }\n}\n\nexport const DerivedReceiveAddressValidatorFactory = (allowedSigners: Address[], allowedScope: string): SignerValidator => (\n signer: Address,\n signee: Address,\n context?: { address?: Address; 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 } 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,cAAMc,mBAAmBT,GAAGG,eAAeO,QAAQf,QAAQC,KAAK;AAChE,cAAMe,uBAAuBX,GAAGG,eAAeO,QAAQf,QAAQE,SAAS;AACxE,cAAMe,eAAeC,KAAKC,IAAIL,kBAAkBE,oBAAAA;AAChD,YAAIC,iBAAiB,IAAI;AACvBV,iBAAOG,KAAK,IAAIC,oCAAoCN,IAAIJ,SAASW,WAAW;YAACP;YAAIC;aAAa,wBAAA,CAAA;QAChG;AAEA,cAAMc,iBAAiBf,GAAGgB,gBAAgBJ,YAAAA;AAC1C,YAAIG,mBAAmBpB,QAAQ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AA+C,CAAA;AACrD,UAAMnB,SAASkB,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,EAAE7B,QAAQ0B,SAASN,MAAMM,SAAStB,OAAO,CAAA,CAAA,GAAK;AACvFe,iBAAOW,KAAK,IAAIC,oCACdb,WAAW,CAAA,EAAGc,OACdd,YACA,yBAAyBQ,SAASN,IAAI,gCAAgCpB,MAAAA,EAAQ,CAAA;QAElF;MACF;IACF,SAASiC,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;;;AP9BhB,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","HydratedTransactionValidationError","isTransfer","completedStepRewardAddress","derivedReceiveAddress","elevatedPayloads","SelfSignerValidator","signer","signee","CompletedStepRewardAddressValidatorFactory","allowedSigners","context","step","isDefined","contextAddress","completedStepRewardAddress","includes","DerivedReceiveAddressValidatorFactory","allowedScope","address","scope","derivedAddress","derivedReceiveAddress","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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
address?: Address;
|
|
5
|
+
scope?: string;
|
|
6
|
+
step?: StepIdentity;
|
|
7
|
+
}) => boolean;
|
|
8
|
+
export type SignerMapping = Map<Address, Address[]>;
|
|
9
|
+
export declare const SelfSignerValidator: SignerValidator;
|
|
10
|
+
export declare const CompletedStepRewardAddressValidatorFactory: (allowedSigners: Address[]) => SignerValidator;
|
|
11
|
+
export declare const DerivedReceiveAddressValidatorFactory: (allowedSigners: Address[], allowedScope: string) => SignerValidator;
|
|
12
|
+
export declare function TransactionTransfersValidatorFactory(signerValidators?: SignerValidator[]): HydratedTransactionValidationFunction<TransactionBoundWitness, {
|
|
13
|
+
step?: StepIdentity;
|
|
14
|
+
}>;
|
|
15
|
+
//# 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;AAE1C,OAAO,KAAK,EACV,qCAAqC,EAA4C,YAAY,EAAE,uBAAuB,EAEvH,MAAM,2BAA2B,CAAA;AAMlC,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,KAAK,OAAO,CAAA;AAEjJ,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;AAEnD,eAAO,MAAM,mBAAmB,EAAE,eAAyE,CAAA;AAE3G,eAAO,MAAM,0CAA0C,GAAI,gBAAgB,OAAO,EAAE,KAAG,eAYtF,CAAA;AAED,eAAO,MAAM,qCAAqC,GAAI,gBAAgB,OAAO,EAAE,EAAE,cAAc,MAAM,KAAG,eAevG,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.11",
|
|
5
5
|
"description": "XYO Layer One SDK Validation",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -38,27 +38,29 @@
|
|
|
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",
|
|
44
45
|
"@xyo-network/payload-builder": "~5.1.6",
|
|
45
46
|
"@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.
|
|
47
|
+
"@xyo-network/xl1-protocol": "~1.12.81",
|
|
48
|
+
"@xyo-network/xl1-protocol-sdk": "~1.15.11",
|
|
49
|
+
"@xyo-network/xl1-schema": "~1.15.11",
|
|
49
50
|
"ajv": "~8.17.1"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@types/node": "~24.
|
|
53
|
+
"@types/node": "~24.9.1",
|
|
53
54
|
"@xylabs/assert": "~5.0.12",
|
|
54
55
|
"@xylabs/promise": "~5.0.12",
|
|
55
56
|
"@xylabs/ts-scripts-yarn3": "~7.1.8",
|
|
56
57
|
"@xylabs/tsconfig": "~7.1.8",
|
|
58
|
+
"@xylabs/typeof": "~5.0.12",
|
|
57
59
|
"@xyo-network/account": "~5.1.6",
|
|
58
60
|
"@xyo-network/account-model": "~5.1.6",
|
|
59
61
|
"@xyo-network/archivist-memory": "~5.1.6",
|
|
60
62
|
"@xyo-network/archivist-model": "~5.1.6",
|
|
61
|
-
"@xyo-network/chain-protocol": "~1.15.
|
|
63
|
+
"@xyo-network/chain-protocol": "~1.15.11",
|
|
62
64
|
"@xyo-network/wallet": "~5.1.6",
|
|
63
65
|
"eslint": "^9.38.0",
|
|
64
66
|
"typescript": "~5.9.3",
|
|
@@ -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
|
}
|
|
@@ -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,74 @@
|
|
|
1
|
+
import type { Address } from '@xylabs/hex'
|
|
2
|
+
import { isDefined, isUndefined } from '@xylabs/typeof'
|
|
3
|
+
import type {
|
|
4
|
+
HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, StepIdentity, TransactionBoundWitness,
|
|
5
|
+
Transfer,
|
|
6
|
+
} from '@xyo-network/xl1-protocol'
|
|
7
|
+
import { HydratedTransactionValidationError, isTransfer } from '@xyo-network/xl1-protocol'
|
|
8
|
+
import {
|
|
9
|
+
completedStepRewardAddress, derivedReceiveAddress, elevatedPayloads,
|
|
10
|
+
} from '@xyo-network/xl1-protocol-sdk'
|
|
11
|
+
|
|
12
|
+
export type SignerValidator = (signer: Address, signee: Address, context?: { address?: Address; scope?: string; step?: StepIdentity }) => boolean
|
|
13
|
+
|
|
14
|
+
export type SignerMapping = Map<Address, Address[]>
|
|
15
|
+
|
|
16
|
+
export const SelfSignerValidator: SignerValidator = (signer: Address, signee: Address) => signer === signee
|
|
17
|
+
|
|
18
|
+
export const CompletedStepRewardAddressValidatorFactory = (allowedSigners: Address[]): SignerValidator => (
|
|
19
|
+
signer: Address,
|
|
20
|
+
signee: Address,
|
|
21
|
+
context?: { step?: StepIdentity },
|
|
22
|
+
) => {
|
|
23
|
+
const step = context?.step
|
|
24
|
+
if (isDefined(step)) {
|
|
25
|
+
const contextAddress = completedStepRewardAddress(step)
|
|
26
|
+
return allowedSigners.includes(signer) && signee === contextAddress
|
|
27
|
+
} else {
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const DerivedReceiveAddressValidatorFactory = (allowedSigners: Address[], allowedScope: string): SignerValidator => (
|
|
33
|
+
signer: Address,
|
|
34
|
+
signee: Address,
|
|
35
|
+
context?: { address?: Address; scope?: string },
|
|
36
|
+
) => {
|
|
37
|
+
const { address, scope } = context ?? {}
|
|
38
|
+
if (scope !== allowedScope) {
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
41
|
+
if (isDefined(address)) {
|
|
42
|
+
const derivedAddress = derivedReceiveAddress(address, scope)
|
|
43
|
+
return allowedSigners.includes(signer) && signee === derivedAddress
|
|
44
|
+
} else {
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function TransactionTransfersValidatorFactory(
|
|
50
|
+
signerValidators: SignerValidator[] = [SelfSignerValidator],
|
|
51
|
+
): HydratedTransactionValidationFunction<TransactionBoundWitness, { step?: StepIdentity }> {
|
|
52
|
+
return async (
|
|
53
|
+
hydratedTx: SignedHydratedTransactionWithStorageMeta,
|
|
54
|
+
) => {
|
|
55
|
+
const errors: HydratedTransactionValidationError[] = []
|
|
56
|
+
const signer = hydratedTx[0].from
|
|
57
|
+
try {
|
|
58
|
+
const payloads = elevatedPayloads(hydratedTx)
|
|
59
|
+
const transfers = payloads.filter(isTransfer) as Transfer[]
|
|
60
|
+
for (const transfer of transfers) {
|
|
61
|
+
if (isUndefined(signerValidators.find(v => v(signer, transfer.from, transfer.context)))) {
|
|
62
|
+
errors.push(new HydratedTransactionValidationError(
|
|
63
|
+
hydratedTx[0]._hash,
|
|
64
|
+
hydratedTx,
|
|
65
|
+
`transfer from address ${transfer.from} is not authorized by signer ${signer}`,
|
|
66
|
+
))
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch (ex) {
|
|
70
|
+
errors.push(new HydratedTransactionValidationError(hydratedTx[0]._hash, hydratedTx, 'validation excepted', ex))
|
|
71
|
+
}
|
|
72
|
+
return await Promise.resolve(errors)
|
|
73
|
+
}
|
|
74
|
+
}
|