@xyo-network/chain-validation 1.7.8 → 1.7.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json.schemastore.org/package.json",
3
3
  "name": "@xyo-network/chain-validation",
4
- "version": "1.7.8",
4
+ "version": "1.7.10",
5
5
  "description": "XYO Layer One SDK Validation",
6
6
  "homepage": "https://xylabs.com",
7
7
  "bugs": {
@@ -23,45 +23,47 @@
23
23
  "exports": {
24
24
  ".": {
25
25
  "types": "./dist/neutral/index.d.ts",
26
+ "source": "./src/index.ts",
26
27
  "default": "./dist/neutral/index.mjs"
27
28
  },
28
29
  "./package.json": "./package.json"
29
30
  },
30
31
  "module": "./dist/neutral/index.mjs",
32
+ "source": "./src/index.ts",
31
33
  "types": "./dist/neutral/index.d.ts",
32
- "scripts": {
33
- "deploy": "echo Deploy not allowed!",
34
- "deploy3": "echo Deploy3 not allowed!"
35
- },
34
+ "files": [
35
+ "dist",
36
+ "src"
37
+ ],
36
38
  "dependencies": {
37
39
  "@xylabs/arraybuffer": "^4.13.21",
38
40
  "@xylabs/hex": "^4.13.21",
39
41
  "@xylabs/typeof": "^4.13.21",
40
- "@xyo-network/boundwitness-builder": "^4.1.5",
41
- "@xyo-network/boundwitness-model": "^4.1.5",
42
- "@xyo-network/boundwitness-validator": "^4.1.5",
43
- "@xyo-network/chain-protocol": "^1.7.8",
44
- "@xyo-network/chain-schema": "^1.7.8",
45
- "@xyo-network/chain-utils": "^1.7.8",
46
- "@xyo-network/payload-builder": "^4.1.5",
47
- "@xyo-network/payload-model": "^4.1.5",
48
- "@xyo-network/schema-payload-plugin": "^4.1.5",
49
- "@xyo-network/xl1-protocol": "^1.7.5",
50
- "@xyo-network/xl1-protocol-sdk": "^1.7.8",
42
+ "@xyo-network/boundwitness-builder": "^4.1.6",
43
+ "@xyo-network/boundwitness-model": "^4.1.6",
44
+ "@xyo-network/boundwitness-validator": "^4.1.6",
45
+ "@xyo-network/chain-protocol": "^1.7.10",
46
+ "@xyo-network/chain-schema": "^1.7.10",
47
+ "@xyo-network/chain-utils": "^1.7.10",
48
+ "@xyo-network/payload-builder": "^4.1.6",
49
+ "@xyo-network/payload-model": "^4.1.6",
50
+ "@xyo-network/schema-payload-plugin": "^4.1.6",
51
+ "@xyo-network/xl1-protocol": "^1.7.10",
52
+ "@xyo-network/xl1-protocol-sdk": "^1.7.10",
51
53
  "ajv": "^8.17.1"
52
54
  },
53
55
  "devDependencies": {
54
- "@types/node": "^24.0.14",
56
+ "@types/node": "^24.0.15",
55
57
  "@xylabs/assert": "^4.13.21",
56
58
  "@xylabs/promise": "^4.13.21",
57
59
  "@xylabs/ts-scripts-yarn3": "^7.0.0",
58
60
  "@xylabs/tsconfig": "^7.0.0",
59
- "@xyo-network/account": "^4.1.5",
60
- "@xyo-network/account-model": "^4.1.5",
61
- "@xyo-network/archivist-memory": "^4.1.5",
62
- "@xyo-network/archivist-model": "^4.1.5",
63
- "@xyo-network/wallet": "^4.1.5",
64
- "@xyo-network/xl1-protocol-sdk": "^1.7.8",
61
+ "@xyo-network/account": "^4.1.6",
62
+ "@xyo-network/account-model": "^4.1.6",
63
+ "@xyo-network/archivist-memory": "^4.1.6",
64
+ "@xyo-network/archivist-model": "^4.1.6",
65
+ "@xyo-network/wallet": "^4.1.6",
66
+ "@xyo-network/xl1-protocol-sdk": "^1.7.10",
65
67
  "knip": "^5.62.0",
66
68
  "typescript": "^5.8.3",
67
69
  "vitest": "^3.2.4"
@@ -0,0 +1,33 @@
1
+ import { assertEx } from '@xylabs/assert'
2
+ import { asAddress } from '@xylabs/hex'
3
+ import type { AccountInstance } from '@xyo-network/account-model'
4
+ import { createGenesisBlock } from '@xyo-network/chain-protocol'
5
+ import { HDWallet } from '@xyo-network/wallet'
6
+ import type { HydratedBlock } from '@xyo-network/xl1-protocol'
7
+ import {
8
+ afterAll, beforeAll, describe, expect, it, vi,
9
+ } from 'vitest'
10
+
11
+ import { validateHydratedBlock } from '../validateHydratedBlock.ts'
12
+
13
+ describe('validateHydratedBlock', () => {
14
+ const genesisBlockRewardAddress = assertEx(asAddress('1111111111111111111111111111111111111111'))
15
+ const genesisBlockRewardAmount = 1_000_000_000n
16
+ const mockTimestamp = 1_234_567_890_000
17
+ const nextContractAddress = assertEx(asAddress('ebcA0d7C02491f84597CE4BdA7a4D4dBE663f008'))
18
+ const phrase = 'plug garden dish upper ski silent off desert course one add lazy skill skate nurse'
19
+ let result: HydratedBlock
20
+ beforeAll(async () => {
21
+ vi.spyOn(Date, 'now').mockReturnValue(mockTimestamp)
22
+ const initialBlockProducer: AccountInstance = await HDWallet.fromPhrase(phrase)
23
+ result = await createGenesisBlock(initialBlockProducer, nextContractAddress, genesisBlockRewardAmount, genesisBlockRewardAddress)
24
+ })
25
+ afterAll(() => {
26
+ vi.restoreAllMocks()
27
+ })
28
+
29
+ it('should validate genesis block', async () => {
30
+ const validation = await validateHydratedBlock(result, nextContractAddress)
31
+ expect(validation.length).toBe(0)
32
+ })
33
+ })
@@ -0,0 +1,49 @@
1
+ import { Account } from '@xyo-network/account'
2
+ import type { AccountInstance } from '@xyo-network/account-model'
3
+ import { buildTransaction } from '@xyo-network/xl1-protocol-sdk'
4
+ import {
5
+ beforeAll, describe, expect, it,
6
+ } from 'vitest'
7
+
8
+ import { TransactionDurationValidator } from '../TransactionDurationValidator.ts'
9
+
10
+ describe('TransactionDurationValidator', () => {
11
+ const chain = 'a82920051db4fcbb804463440dd45e03f72442fd'
12
+ let signer: AccountInstance
13
+ beforeAll(async () => {
14
+ signer = await Account.random()
15
+ })
16
+ describe('with valid duration', () => {
17
+ it('should return no errors', async () => {
18
+ const hydratedTransaction = await buildTransaction(chain, [], [], signer, 0, 1000)
19
+ const errors = await TransactionDurationValidator(hydratedTransaction, chain)
20
+ expect(errors.length).toBe(0)
21
+ })
22
+ })
23
+ describe('with invalid', () => {
24
+ describe('nbf', () => {
25
+ it('should return error if nbf too low', async () => {
26
+ const hydratedTransaction = await buildTransaction(chain, [], [], signer, -1, 1000)
27
+ const errors = await TransactionDurationValidator(hydratedTransaction, chain)
28
+ expect(errors.length).toBeGreaterThan(0)
29
+ })
30
+ })
31
+ describe('exp', () => {
32
+ it('should return error if exp less than nbf', async () => {
33
+ const hydratedTransaction = await buildTransaction(chain, [], [], signer, 1, 0)
34
+ const errors = await TransactionDurationValidator(hydratedTransaction, chain)
35
+ expect(errors.length).toBeGreaterThan(0)
36
+ })
37
+ it('should return error if exp is equal to nbf', async () => {
38
+ const hydratedTransaction = await buildTransaction(chain, [], [], signer, 0, 0)
39
+ const errors = await TransactionDurationValidator(hydratedTransaction, chain)
40
+ expect(errors.length).toBeGreaterThan(0)
41
+ })
42
+ it('should return error if exp too high', async () => {
43
+ const hydratedTransaction = await buildTransaction(chain, [], [], signer, 0, Number.MAX_SAFE_INTEGER)
44
+ const errors = await TransactionDurationValidator(hydratedTransaction, chain)
45
+ expect(errors.length).toBeGreaterThan(0)
46
+ })
47
+ })
48
+ })
49
+ })
@@ -0,0 +1,39 @@
1
+ import { Account } from '@xyo-network/account'
2
+ import type { AccountInstance } from '@xyo-network/account-model'
3
+ import { buildRandomTransaction } from '@xyo-network/chain-protocol'
4
+ import type { HydratedTransaction, TransactionBoundWitness } from '@xyo-network/xl1-protocol'
5
+ import { buildTransaction } from '@xyo-network/xl1-protocol-sdk'
6
+ import {
7
+ beforeAll, describe, expect, it,
8
+ } from 'vitest'
9
+
10
+ import { TransactionElevationValidator } from '../TransactionElevationValidator.ts'
11
+
12
+ describe('TransactionDurationValidator', () => {
13
+ const chain = 'a82920051db4fcbb804463440dd45e03f72442fd'
14
+ let signer: AccountInstance
15
+ beforeAll(async () => {
16
+ signer = await Account.random()
17
+ })
18
+ describe('should return no errors', () => {
19
+ it('if all script hash payloads are supplied', async () => {
20
+ const tx = await buildRandomTransaction(chain, [], signer)
21
+ const result = await TransactionElevationValidator(tx, chain)
22
+ expect(result.length).toBe(0)
23
+ })
24
+ it('when no payloads referenced in script hash', async () => {
25
+ const sample = await buildRandomTransaction(chain, [], signer)
26
+ const tx = await buildTransaction(chain, [], sample[1], signer, 1, 2)
27
+ const result = await TransactionElevationValidator(tx, chain)
28
+ expect(result.length).toBe(0)
29
+ })
30
+ })
31
+ describe('should return errors', () => {
32
+ it('if not all script hash payloads are supplied', async () => {
33
+ const [bw] = await buildRandomTransaction(chain, [], signer)
34
+ const tx = [bw, []] as HydratedTransaction<TransactionBoundWitness>
35
+ const result = await TransactionElevationValidator(tx, chain)
36
+ expect(result.length).toBe(1)
37
+ })
38
+ })
39
+ })
@@ -0,0 +1,43 @@
1
+ import { Account } from '@xyo-network/account'
2
+ import type { AccountInstance } from '@xyo-network/account-model'
3
+ import type { WithStorageMeta } from '@xyo-network/payload-model'
4
+ import type { HydratedTransaction, TransactionBoundWitness } from '@xyo-network/xl1-protocol'
5
+ import { buildTransaction } from '@xyo-network/xl1-protocol-sdk'
6
+ import {
7
+ beforeAll,
8
+ beforeEach,
9
+ describe, expect, it,
10
+ } from 'vitest'
11
+
12
+ import { TransactionFromValidator } from '../TransactionFromValidator.ts'
13
+
14
+ describe('TransactionFromValidator', () => {
15
+ const chain = 'a82920051db4fcbb804463440dd45e03f72442fd'
16
+ let signer: AccountInstance
17
+ beforeAll(async () => {
18
+ signer = await Account.random()
19
+ })
20
+ describe('with from empty', () => {
21
+ let hydratedTransaction: HydratedTransaction
22
+ beforeEach(async () => {
23
+ const transaction = await buildTransaction(chain, [], [], signer, 0, Number.MAX_SAFE_INTEGER)
24
+ const { from, ...tx } = transaction[0]
25
+ hydratedTransaction = [tx as WithStorageMeta<TransactionBoundWitness>, transaction[1]]
26
+ })
27
+ it('should return error', async () => {
28
+ const errors = await TransactionFromValidator(hydratedTransaction, chain)
29
+ expect(errors.length).toBeGreaterThan(0)
30
+ })
31
+ })
32
+ describe('with from not in addresses', () => {
33
+ let hydratedTransaction: HydratedTransaction
34
+ beforeEach(async () => {
35
+ const from = await Account.random()
36
+ hydratedTransaction = await buildTransaction(chain, [], [], signer, 0, Number.MAX_SAFE_INTEGER, from.address)
37
+ })
38
+ it('should return error', async () => {
39
+ const errors = await TransactionFromValidator(hydratedTransaction, chain)
40
+ expect(errors.length).toBeGreaterThan(0)
41
+ })
42
+ })
43
+ })
@@ -0,0 +1,88 @@
1
+ import { type Address, hexFromBigInt } from '@xylabs/hex'
2
+ import { Account } from '@xyo-network/account'
3
+ import { buildRandomTransaction } from '@xyo-network/chain-protocol'
4
+ import type {
5
+ HydratedTransaction, TransactionBoundWitness, TransactionFeesHex,
6
+ } from '@xyo-network/xl1-protocol'
7
+ import {
8
+ beforeAll, beforeEach, describe, expect, it,
9
+ } from 'vitest'
10
+
11
+ import { TransactionGasValidator } from '../TransactionGasValidator.ts'
12
+
13
+ describe('TransactionGasValidator', () => {
14
+ let chainId: Address
15
+ let transaction: HydratedTransaction
16
+
17
+ beforeAll(async () => {
18
+ chainId = (await Account.random()).address
19
+ })
20
+
21
+ beforeEach(async () => {
22
+ transaction = await buildRandomTransaction(chainId)
23
+ })
24
+
25
+ describe('with valid transaction', () => {
26
+ it('should return no errors for valid fees', async () => {
27
+ const result = await TransactionGasValidator(transaction, chainId)
28
+ expect(result).toEqual([])
29
+ })
30
+ })
31
+
32
+ describe('with invalid transaction', () => {
33
+ describe('fees', () => {
34
+ it('should return an error if fees are missing', async () => {
35
+ delete (transaction[0] as Partial<TransactionBoundWitness>).fees
36
+ const result = await TransactionGasValidator(transaction, chainId)
37
+ expect(result[0].message).toEqual('Missing fees')
38
+ })
39
+ })
40
+
41
+ describe('base', () => {
42
+ it('should return an error if fees.base is undefined', async () => {
43
+ delete (transaction[0].fees as Partial<TransactionFeesHex>)?.base
44
+ const result = await TransactionGasValidator(transaction, chainId)
45
+ expect(result[0].message).toEqual('fees.base must be defined and a valid number')
46
+ })
47
+ it('should return an error if fees.base is less than or equal to 0', async () => {
48
+ transaction[0].fees.base = hexFromBigInt(0n)
49
+ const result = await TransactionGasValidator(transaction, chainId)
50
+ expect(result.length).toEqual(1)
51
+ })
52
+ })
53
+
54
+ describe('gasLimit', () => {
55
+ it('should return an error if fees.gasLimit is undefined', async () => {
56
+ delete (transaction[0].fees as Partial<TransactionFeesHex>)?.gasLimit
57
+ const result = await TransactionGasValidator(transaction, chainId)
58
+ expect(result[0].message).toEqual('fees.gasLimit must be defined and a valid number')
59
+ })
60
+ it('should return an error if fees.gasLimit is less than or equal to 0', async () => {
61
+ transaction[0].fees.gasLimit = hexFromBigInt(0n)
62
+ const result = await TransactionGasValidator(transaction, chainId)
63
+ expect(result.length).toEqual(1)
64
+ })
65
+ })
66
+ })
67
+
68
+ describe('gasPrice', () => {
69
+ it('should return an error if fees.gasPrice is undefined', async () => {
70
+ delete (transaction[0].fees as Partial<TransactionFeesHex>)?.gasPrice
71
+ const result = await TransactionGasValidator(transaction, chainId)
72
+ expect(result[0].message).toEqual('fees.gasPrice must be defined and a valid number')
73
+ })
74
+ it('should return an error if fees.gasPrice is less than or equal to 0', async () => {
75
+ transaction[0].fees.gasPrice = hexFromBigInt(0n)
76
+ const result = await TransactionGasValidator(transaction, chainId)
77
+ expect(result.length).toEqual(1)
78
+ })
79
+ })
80
+
81
+ describe('priority', () => {
82
+ it('should return an error if fees.priority is undefined', async () => {
83
+ delete (transaction[0].fees as Partial<TransactionFeesHex>)?.priority
84
+ const result = await TransactionGasValidator(transaction, chainId)
85
+ expect(result[0].message).toEqual('fees.priority must be defined and a valid number')
86
+ })
87
+ })
88
+ })
@@ -0,0 +1,33 @@
1
+ import { buildRandomTransaction } from '@xyo-network/chain-protocol'
2
+ import type { HydratedTransaction } from '@xyo-network/xl1-protocol'
3
+ import {
4
+ beforeEach, describe, expect, it,
5
+ } from 'vitest'
6
+
7
+ import { TransactionJsonSchemaValidator } from '../TransactionJsonSchemaValidator.ts'
8
+
9
+ describe('TransactionJsonSchemaValidator', () => {
10
+ const chain = 'a82920051db4fcbb804463440dd45e03f72442fd'
11
+
12
+ describe('with valid transaction', () => {
13
+ let hydratedTransaction: HydratedTransaction
14
+ beforeEach(async () => {
15
+ hydratedTransaction = await buildRandomTransaction(chain)
16
+ })
17
+ it('should return no errors', async () => {
18
+ const errors = await TransactionJsonSchemaValidator(hydratedTransaction, chain)
19
+ expect(errors).toEqual([])
20
+ })
21
+ })
22
+ describe('with invalid transaction', () => {
23
+ let hydratedTransaction: HydratedTransaction
24
+ beforeEach(async () => {
25
+ hydratedTransaction = await buildRandomTransaction(chain)
26
+ hydratedTransaction[0].chain = 'invalid'
27
+ })
28
+ it('should return error', async () => {
29
+ const errors = await TransactionJsonSchemaValidator(hydratedTransaction, chain)
30
+ expect(errors.length).toBeGreaterThan(0)
31
+ })
32
+ })
33
+ })
package/xy.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
- const config: XyTsupConfig = {
3
- compile: {
4
- browser: {},
5
- node: {},
6
- neutral: { src: true },
7
- },
8
- }
9
-
10
- export default config