@xyo-network/xl1-validation 1.15.2 → 1.15.3

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @xyo-network/chain-validation
1
+ # @xyo-network/xl1-validation
2
2
 
3
3
  [![logo][]](https://xyo.network)
4
4
 
@@ -14,18 +14,13 @@ XYO Layer One SDK Validation
14
14
 
15
15
  ## Reference
16
16
 
17
- **@xyo-network/chain-validation**
17
+ **@xyo-network/xl1-validation**
18
18
 
19
19
  ***
20
20
 
21
21
  ## Variables
22
22
 
23
- - [validateBlock](#variables/validateBlock)
24
23
  - [BoundWitnessSignaturesValidator](#variables/BoundWitnessSignaturesValidator)
25
- - [validateHydratedBlock](#variables/validateHydratedBlock)
26
- - [PayloadsInBlockValidator](#variables/PayloadsInBlockValidator)
27
- - [validateHydratedBlockState](#variables/validateHydratedBlockState)
28
- - [RequiredBalanceBlockStateValidator](#variables/RequiredBalanceBlockStateValidator)
29
24
  - [TransactionDurationValidator](#variables/TransactionDurationValidator)
30
25
  - [TransactionElevationValidator](#variables/TransactionElevationValidator)
31
26
  - [TransactionFromValidator](#variables/TransactionFromValidator)
@@ -42,7 +37,7 @@ XYO Layer One SDK Validation
42
37
 
43
38
  ### <a id="BoundWitnessReferencesValidator"></a>BoundWitnessReferencesValidator
44
39
 
45
- [**@xyo-network/chain-validation**](#../README)
40
+ [**@xyo-network/xl1-validation**](#../README)
46
41
 
47
42
  ***
48
43
 
@@ -68,7 +63,7 @@ function BoundWitnessReferencesValidator<T>(allowedSchemas?): HydratedBoundWitne
68
63
 
69
64
  ### <a id="validateTransaction"></a>validateTransaction
70
65
 
71
- [**@xyo-network/chain-validation**](#../README)
66
+ [**@xyo-network/xl1-validation**](#../README)
72
67
 
73
68
  ***
74
69
 
@@ -83,11 +78,11 @@ additionalValidators?): Promise<Error[]>;
83
78
 
84
79
  ### tx
85
80
 
86
- `HydratedTransaction`
81
+ `SignedHydratedTransactionWithStorageMeta`
87
82
 
88
83
  ### chainId?
89
84
 
90
- `Lowercase`\<`string`\>
85
+ `Chain`
91
86
 
92
87
  ### additionalValidators?
93
88
 
@@ -101,37 +96,17 @@ additionalValidators?): Promise<Error[]>;
101
96
 
102
97
  ### <a id="BoundWitnessSignaturesValidator"></a>BoundWitnessSignaturesValidator
103
98
 
104
- [**@xyo-network/chain-validation**](#../README)
99
+ [**@xyo-network/xl1-validation**](#../README)
105
100
 
106
101
  ***
107
102
 
108
103
  ```ts
109
104
  const BoundWitnessSignaturesValidator: BoundWitnessValidationFunction;
110
- ```
111
-
112
- ### <a id="PayloadsInBlockValidator"></a>PayloadsInBlockValidator
113
-
114
- [**@xyo-network/chain-validation**](#../README)
115
-
116
- ***
117
-
118
- ```ts
119
- const PayloadsInBlockValidator: HydratedBlockValidationFunction;
120
- ```
121
-
122
- ### <a id="RequiredBalanceBlockStateValidator"></a>RequiredBalanceBlockStateValidator
123
-
124
- [**@xyo-network/chain-validation**](#../README)
125
-
126
- ***
127
-
128
- ```ts
129
- const RequiredBalanceBlockStateValidator: HydratedBlockStateValidationFunctionV2;
130
105
  ```
131
106
 
132
107
  ### <a id="TransactionDurationValidator"></a>TransactionDurationValidator
133
108
 
134
- [**@xyo-network/chain-validation**](#../README)
109
+ [**@xyo-network/xl1-validation**](#../README)
135
110
 
136
111
  ***
137
112
 
@@ -141,7 +116,7 @@ const TransactionDurationValidator: HydratedTransactionValidationFunction<Transa
141
116
 
142
117
  ### <a id="TransactionElevationValidator"></a>TransactionElevationValidator
143
118
 
144
- [**@xyo-network/chain-validation**](#../README)
119
+ [**@xyo-network/xl1-validation**](#../README)
145
120
 
146
121
  ***
147
122
 
@@ -151,7 +126,7 @@ const TransactionElevationValidator: HydratedTransactionValidationFunction<Trans
151
126
 
152
127
  ### <a id="TransactionFromValidator"></a>TransactionFromValidator
153
128
 
154
- [**@xyo-network/chain-validation**](#../README)
129
+ [**@xyo-network/xl1-validation**](#../README)
155
130
 
156
131
  ***
157
132
 
@@ -161,7 +136,7 @@ const TransactionFromValidator: HydratedTransactionValidationFunction<Transactio
161
136
 
162
137
  ### <a id="TransactionGasValidator"></a>TransactionGasValidator
163
138
 
164
- [**@xyo-network/chain-validation**](#../README)
139
+ [**@xyo-network/xl1-validation**](#../README)
165
140
 
166
141
  ***
167
142
 
@@ -171,7 +146,7 @@ const TransactionGasValidator: HydratedTransactionValidationFunction<Transaction
171
146
 
172
147
  ### <a id="TransactionJsonSchemaValidator"></a>TransactionJsonSchemaValidator
173
148
 
174
- [**@xyo-network/chain-validation**](#../README)
149
+ [**@xyo-network/xl1-validation**](#../README)
175
150
 
176
151
  ***
177
152
 
@@ -181,7 +156,7 @@ const TransactionJsonSchemaValidator: HydratedTransactionValidationFunction<Tran
181
156
 
182
157
  ### <a id="TransactionProtocolValidator"></a>TransactionProtocolValidator
183
158
 
184
- [**@xyo-network/chain-validation**](#../README)
159
+ [**@xyo-network/xl1-validation**](#../README)
185
160
 
186
161
  ***
187
162
 
@@ -189,36 +164,6 @@ const TransactionJsonSchemaValidator: HydratedTransactionValidationFunction<Tran
189
164
  const TransactionProtocolValidator: HydratedTransactionValidationFunction<TransactionBoundWitness>;
190
165
  ```
191
166
 
192
- ### <a id="validateBlock"></a>validateBlock
193
-
194
- [**@xyo-network/chain-validation**](#../README)
195
-
196
- ***
197
-
198
- ```ts
199
- const validateBlock: BlockValidatorFunction;
200
- ```
201
-
202
- ### <a id="validateHydratedBlock"></a>validateHydratedBlock
203
-
204
- [**@xyo-network/chain-validation**](#../README)
205
-
206
- ***
207
-
208
- ```ts
209
- const validateHydratedBlock: HydratedBlockValidationFunction;
210
- ```
211
-
212
- ### <a id="validateHydratedBlockState"></a>validateHydratedBlockState
213
-
214
- [**@xyo-network/chain-validation**](#../README)
215
-
216
- ***
217
-
218
- ```ts
219
- const validateHydratedBlockState: HydratedBlockStateValidationFunctionV2;
220
- ```
221
-
222
167
 
223
168
  ## Maintainers
224
169
 
@@ -237,14 +182,14 @@ const validateHydratedBlockState: HydratedBlockStateValidationFunctionV2;
237
182
 
238
183
  [logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
239
184
 
240
- [npm-badge]: https://img.shields.io/npm/v/@xyo-network/chain-validation.svg
241
- [npm-link]: https://www.npmjs.com/package/@xyo-network/chain-validation
185
+ [npm-badge]: https://img.shields.io/npm/v/@xyo-network/xl1-validation.svg
186
+ [npm-link]: https://www.npmjs.com/package/@xyo-network/xl1-validation
242
187
 
243
- [npm-downloads-badge]: https://img.shields.io/npm/dw/@xyo-network/chain-validation
244
- [npm-license-badge]: https://img.shields.io/npm/l/@xyo-network/chain-validation
188
+ [npm-downloads-badge]: https://img.shields.io/npm/dw/@xyo-network/xl1-validation
189
+ [npm-license-badge]: https://img.shields.io/npm/l/@xyo-network/xl1-validation
245
190
 
246
- [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xyo-network/chain-validation/badge
247
- [jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xyo-network/chain-validation
191
+ [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xyo-network/xl1-validation/badge
192
+ [jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xyo-network/xl1-validation
248
193
 
249
- [socket-badge]: https://socket.dev/api/badge/npm/package/@xyo-network/chain-validation
250
- [socket-link]: https://socket.dev/npm/package/@xyo-network/chain-validation
194
+ [socket-badge]: https://socket.dev/api/badge/npm/package/@xyo-network/xl1-validation
195
+ [socket-link]: https://socket.dev/npm/package/@xyo-network/xl1-validation
@@ -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,GAEzC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,iBAAiB,MAAM,EAAE,KAAG,sCAAsC,CAAC,CAAC,CAsC7G,CAAA"}
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,CAsC7G,CAAA"}
@@ -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 Chain, 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?: Chain,\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 Chain,\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?: Chain,\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,kCAEX,wBAAwCC,mBAAyE,CACjH,CAACC,IAAIC,UAAAA,MAAuD;AAE5D,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,Q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A,CAAA,EAAI;AAE1FL,YAAMM,QAAQf,SAASG;AACvBA,aAAOa,KAAKP,KAAAA;IACd;EACF,SAASQ,IAAI;AACXd,WAAOa,KAAK,IAAIN,oCAAmCR,KAAK,CAAA,GAAIS,SAASC,YAAWV,IAAI,uBAAuBe,EAAAA,CAAAA;EAC7G;AACA,SAAOd;AACT,GAnB8G;;;ACd9G,SAASe,aAAAA,kBAAiB;AAK1B,SAASC,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"],"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,kCAET,wBAAwCC,mBAAyE,CACjH,CAACC,IAAIC,UAAAA,MAAuD;AAE5D,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,QAAQsB,QAAQ;AACrCf,iBAAOG,KAAK,IAAIC,oCAAoCN,IAAIJ,SAASW,WAAW;YAACP;YAAIC;aAAa,mBAAA,CAA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DC,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,3 +1,3 @@
1
- import type { Chain, HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol';
2
- export declare function validateTransaction(tx: SignedHydratedTransactionWithStorageMeta, chainId?: Chain, additionalValidators?: HydratedTransactionValidationFunction[]): Promise<Error[]>;
1
+ import type { ChainId, HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta } from '@xyo-network/xl1-protocol';
2
+ export declare function validateTransaction(tx: SignedHydratedTransactionWithStorageMeta, chainId?: ChainId, additionalValidators?: HydratedTransactionValidationFunction[]): Promise<Error[]>;
3
3
  //# 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,KAAK,EAAE,qCAAqC,EAC5C,wCAAwC,EACzC,MAAM,2BAA2B,CAAA;AAQlC,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,wCAAwC,EAC5C,OAAO,CAAC,EAAE,KAAK,EACf,oBAAoB,GAAE,qCAAqC,EAAO,oBAmBnE"}
1
+ {"version":3,"file":"validateTransaction.d.ts","sourceRoot":"","sources":["../../../src/transaction/validateTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAAE,qCAAqC,EAC9C,wCAAwC,EACzC,MAAM,2BAA2B,CAAA;AAQlC,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,wCAAwC,EAC5C,OAAO,CAAC,EAAE,OAAO,EACjB,oBAAoB,GAAE,qCAAqC,EAAO,oBAmBnE"}
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.2",
4
+ "version": "1.15.3",
5
5
  "description": "XYO Layer One SDK Validation",
6
6
  "homepage": "https://xylabs.com",
7
7
  "bugs": {
@@ -36,32 +36,32 @@
36
36
  "src"
37
37
  ],
38
38
  "dependencies": {
39
- "@xylabs/arraybuffer": "~5.0.11",
40
- "@xylabs/hex": "~5.0.11",
41
- "@xyo-network/boundwitness-builder": "~5.1.3",
42
- "@xyo-network/boundwitness-model": "~5.1.3",
43
- "@xyo-network/boundwitness-validator": "~5.1.3",
44
- "@xyo-network/payload-builder": "~5.1.3",
45
- "@xyo-network/payload-model": "~5.1.3",
46
- "@xyo-network/xl1-protocol": "~1.12.40",
47
- "@xyo-network/xl1-protocol-sdk": "~1.15.2",
48
- "@xyo-network/xl1-schema": "~1.15.2",
39
+ "@xylabs/arraybuffer": "~5.0.12",
40
+ "@xylabs/hex": "~5.0.12",
41
+ "@xyo-network/boundwitness-builder": "~5.1.6",
42
+ "@xyo-network/boundwitness-model": "~5.1.6",
43
+ "@xyo-network/boundwitness-validator": "~5.1.6",
44
+ "@xyo-network/payload-builder": "~5.1.6",
45
+ "@xyo-network/payload-model": "~5.1.6",
46
+ "@xyo-network/xl1-protocol": "~1.12.66",
47
+ "@xyo-network/xl1-protocol-sdk": "~1.15.3",
48
+ "@xyo-network/xl1-schema": "~1.15.3",
49
49
  "ajv": "~8.17.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@types/node": "~24.5.2",
53
- "@xylabs/assert": "~5.0.11",
54
- "@xylabs/promise": "~5.0.11",
55
- "@xylabs/ts-scripts-yarn3": "~7.1.7",
56
- "@xylabs/tsconfig": "~7.1.7",
57
- "@xyo-network/account": "~5.1.3",
58
- "@xyo-network/account-model": "~5.1.3",
59
- "@xyo-network/archivist-memory": "~5.1.3",
60
- "@xyo-network/archivist-model": "~5.1.3",
61
- "@xyo-network/chain-protocol": "~1.15.2",
62
- "@xyo-network/wallet": "~5.1.3",
63
- "eslint": "^9.36.0",
64
- "typescript": "~5.9.2",
52
+ "@types/node": "~24.7.2",
53
+ "@xylabs/assert": "~5.0.12",
54
+ "@xylabs/promise": "~5.0.12",
55
+ "@xylabs/ts-scripts-yarn3": "~7.1.8",
56
+ "@xylabs/tsconfig": "~7.1.8",
57
+ "@xyo-network/account": "~5.1.6",
58
+ "@xyo-network/account-model": "~5.1.6",
59
+ "@xyo-network/archivist-memory": "~5.1.6",
60
+ "@xyo-network/archivist-model": "~5.1.6",
61
+ "@xyo-network/chain-protocol": "~1.15.3",
62
+ "@xyo-network/wallet": "~5.1.6",
63
+ "eslint": "^9.37.0",
64
+ "typescript": "~5.9.3",
65
65
  "vitest": "~3.2.4"
66
66
  },
67
67
  "engines": {
@@ -16,42 +16,42 @@ function getPayloadsFromPayloadArray(payloads: WithHashStorageMeta<Payload>[], h
16
16
 
17
17
  export const BoundWitnessReferencesValidator
18
18
  // eslint-disable-next-line complexity
19
- = <T extends BoundWitness = BoundWitness>(allowedSchemas?: Schema[]): HydratedBoundWitnessValidationFunction<T> => (
20
- [bw, payloadSet]: HydratedBoundWitnessWithHashStorageMeta<T>,
21
- ): Promisable<HydratedBoundWitnessValidationError[]> => {
22
- const errors: HydratedBoundWitnessValidationError[] = []
23
- try {
24
- const payloads = getPayloadsFromPayloadArray(payloadSet, bw.payload_hashes)
25
- if (payloads.length !== bw.payload_hashes.length) {
26
- errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'unable to locate payloads'))
27
- }
19
+ = <T extends BoundWitness = BoundWitness>(allowedSchemas?: Schema[]): HydratedBoundWitnessValidationFunction<T> => (
20
+ [bw, payloadSet]: HydratedBoundWitnessWithHashStorageMeta<T>,
21
+ ): Promisable<HydratedBoundWitnessValidationError[]> => {
22
+ const errors: HydratedBoundWitnessValidationError[] = []
23
+ try {
24
+ const payloads = getPayloadsFromPayloadArray(payloadSet, bw.payload_hashes)
25
+ if (payloads.length !== bw.payload_hashes.length) {
26
+ errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'unable to locate payloads'))
27
+ }
28
28
 
29
- // check if payloads are valid and if their schemas match the declared schemas
30
- for (let payload of payloads) {
31
- if (isAnyPayload(payload)) {
32
- const payloadHashIndex = bw.payload_hashes.indexOf(payload._hash)
33
- const payloadDataHashIndex = bw.payload_hashes.indexOf(payload._dataHash)
34
- const payloadIndex = Math.max(payloadHashIndex, payloadDataHashIndex)
35
- if (payloadIndex === -1) {
36
- errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'payload hash not found'))
37
- }
29
+ // check if payloads are valid and if their schemas match the declared schemas
30
+ for (let payload of payloads) {
31
+ if (isAnyPayload(payload)) {
32
+ const payloadHashIndex = bw.payload_hashes.indexOf(payload._hash)
33
+ const payloadDataHashIndex = bw.payload_hashes.indexOf(payload._dataHash)
34
+ const payloadIndex = Math.max(payloadHashIndex, payloadDataHashIndex)
35
+ if (payloadIndex === -1) {
36
+ errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'payload hash not found'))
37
+ }
38
38
 
39
- const declaredSchema = bw.payload_schemas[payloadIndex]
40
- if (declaredSchema !== payload.schema) {
41
- errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'mismatched schema'))
42
- }
39
+ const declaredSchema = bw.payload_schemas[payloadIndex]
40
+ if (declaredSchema !== payload.schema) {
41
+ errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'mismatched schema'))
42
+ }
43
43
 
44
- if (allowedSchemas && !allowedSchemas.includes(payload.schema)) {
45
- errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], `disallowed schema [${payload.schema}]`))
44
+ if (allowedSchemas && !allowedSchemas.includes(payload.schema)) {
45
+ errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], `disallowed schema [${payload.schema}]`))
46
+ }
47
+ } else {
48
+ errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'invalid payload'))
46
49
  }
47
- } else {
48
- errors.push(new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], 'invalid payload'))
49
50
  }
51
+ } catch (ex) {
52
+ const error = new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], `validation excepted: ${ex}`)
53
+ error.cause = ex
54
+ errors.push(error)
50
55
  }
51
- } catch (ex) {
52
- const error = new HydratedBoundWitnessValidationError(bw?._hash ?? ZERO_HASH, [bw, payloadSet], `validation excepted: ${ex}`)
53
- error.cause = ex
54
- errors.push(error)
56
+ return errors
55
57
  }
56
- return errors
57
- }
@@ -1,5 +1,5 @@
1
1
  import type {
2
- Chain, HydratedTransactionValidationFunction,
2
+ ChainId, HydratedTransactionValidationFunction,
3
3
  SignedHydratedTransactionWithStorageMeta,
4
4
  } from '@xyo-network/xl1-protocol'
5
5
  import { isTransactionBoundWitness } from '@xyo-network/xl1-protocol'
@@ -11,7 +11,7 @@ import {
11
11
 
12
12
  export async function validateTransaction(
13
13
  tx: SignedHydratedTransactionWithStorageMeta,
14
- chainId?: Chain,
14
+ chainId?: ChainId,
15
15
  additionalValidators: HydratedTransactionValidationFunction[] = [],
16
16
  ) {
17
17
  try {
@@ -1,13 +1,13 @@
1
1
  import { ZERO_HASH } from '@xylabs/hex'
2
2
  import type {
3
- Chain,
3
+ ChainId,
4
4
  HydratedTransactionValidationFunction, SignedHydratedTransactionWithStorageMeta, TransactionBoundWitness,
5
5
  } from '@xyo-network/xl1-protocol'
6
6
  import { HydratedTransactionValidationError } from '@xyo-network/xl1-protocol'
7
7
 
8
8
  export const TransactionProtocolValidator: HydratedTransactionValidationFunction<TransactionBoundWitness> = async (
9
9
  tx: SignedHydratedTransactionWithStorageMeta,
10
- chainId?: Chain,
10
+ chainId?: ChainId,
11
11
  ) => {
12
12
  const errors: HydratedTransactionValidationError[] = []
13
13
  try {
@@ -2,7 +2,7 @@ import { hexFromBigInt } from '@xylabs/hex'
2
2
  import { Account } from '@xyo-network/account'
3
3
  import { buildRandomTransaction } from '@xyo-network/chain-protocol'
4
4
  import type {
5
- Chain,
5
+ ChainId,
6
6
  SignedHydratedTransactionWithStorageMeta, TransactionBoundWitness, TransactionFeesHex,
7
7
  } from '@xyo-network/xl1-protocol'
8
8
  import {
@@ -12,7 +12,7 @@ import {
12
12
  import { TransactionGasValidator } from '../TransactionGasValidator.ts'
13
13
 
14
14
  describe('TransactionGasValidator', () => {
15
- let chainId: Chain
15
+ let chainId: ChainId
16
16
  let transaction: SignedHydratedTransactionWithStorageMeta
17
17
 
18
18
  beforeAll(async () => {