@xyo-network/boundwitness-validator 5.3.22 → 5.3.24

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/boundwitness-validator",
3
- "version": "5.3.22",
3
+ "version": "5.3.24",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,48 +30,44 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
35
  "!**/*.test.*",
37
36
  "README.md"
38
37
  ],
39
38
  "dependencies": {
40
- "@xyo-network/boundwitness-model": "~5.3.22",
41
- "@xyo-network/elliptic": "~5.3.22",
42
- "@xyo-network/payload": "~5.3.22",
43
- "@xyo-network/payload-model": "~5.3.22",
44
- "@xyo-network/payload-validator": "~5.3.22"
39
+ "@xyo-network/boundwitness-model": "~5.3.24",
40
+ "@xyo-network/payload": "~5.3.24",
41
+ "@xyo-network/payload-validator": "~5.3.24",
42
+ "@xyo-network/elliptic": "~5.3.24",
43
+ "@xyo-network/payload-model": "~5.3.24"
45
44
  },
46
45
  "devDependencies": {
47
46
  "@opentelemetry/api": "^1.9.1",
48
47
  "@types/node": "^25.5.0",
49
- "@xylabs/sdk-js": "^5.0.91",
50
- "@xylabs/ts-scripts-common": "~7.6.8",
51
- "@xylabs/ts-scripts-yarn3": "~7.6.8",
52
- "@xylabs/tsconfig": "~7.6.8",
53
- "@xylabs/vitest-extended": "~5.0.91",
54
- "@xyo-network/boundwitness-builder": "~5.3.22",
55
- "@xyo-network/boundwitness-model": "~5.3.22",
56
- "@xyo-network/elliptic": "~5.3.22",
57
- "@xyo-network/payload": "~5.3.22",
58
- "@xyo-network/payload-model": "~5.3.22",
59
- "@xyo-network/payload-validator": "~5.3.22",
60
- "@xyo-network/schema-name-validator": "~5.3.22",
61
- "@xyo-network/wallet": "~5.3.22",
62
- "@xyo-network/wallet-model": "~5.3.22",
48
+ "@xylabs/sdk-js": "^5.0.93",
49
+ "@xylabs/ts-scripts-common": "~7.6.16",
50
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
51
+ "@xylabs/tsconfig": "~7.6.16",
52
+ "@xylabs/vitest-extended": "~5.0.93",
63
53
  "acorn": "^8.16.0",
64
54
  "axios": "^1.14.0",
65
- "cosmiconfig": "^9.0.1",
66
- "esbuild": "^0.27.4",
67
- "eslint": "^10.1.0",
55
+ "esbuild": "^0.28.0",
68
56
  "ethers": "^6.16.0",
69
- "rollup": "^4.60.1",
70
57
  "tslib": "^2.8.1",
71
58
  "typescript": "~5.9.3",
72
59
  "vite": "^8.0.3",
73
60
  "vitest": "~4.1.2",
74
- "zod": "^4.3.6"
61
+ "zod": "^4.3.6",
62
+ "@xyo-network/boundwitness-model": "~5.3.24",
63
+ "@xyo-network/elliptic": "~5.3.24",
64
+ "@xyo-network/payload": "~5.3.24",
65
+ "@xyo-network/boundwitness-builder": "~5.3.24",
66
+ "@xyo-network/payload-model": "~5.3.24",
67
+ "@xyo-network/payload-validator": "~5.3.24",
68
+ "@xyo-network/wallet": "~5.3.24",
69
+ "@xyo-network/wallet-model": "~5.3.24",
70
+ "@xyo-network/schema-name-validator": "~5.3.24"
75
71
  },
76
72
  "peerDependencies": {
77
73
  "@xylabs/sdk-js": "^5",
@@ -82,4 +78,4 @@
82
78
  "publishConfig": {
83
79
  "access": "public"
84
80
  }
85
- }
81
+ }
package/src/Validator.ts DELETED
@@ -1,124 +0,0 @@
1
- import {
2
- asAddress, toArrayBuffer,
3
- uniq, validateType,
4
- } from '@xylabs/sdk-js'
5
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
6
- import { BoundWitnessSchema } from '@xyo-network/boundwitness-model'
7
- import { Elliptic } from '@xyo-network/elliptic'
8
- import { PayloadBuilder } from '@xyo-network/payload'
9
- import { PayloadValidator } from '@xyo-network/payload-validator'
10
-
11
- const validateArraysSameLength = (a: unknown[], b: unknown[], message = 'Array length mismatch') => {
12
- return a.length == b.length ? [] : [new Error(`${message} []`)]
13
- }
14
-
15
- export class BoundWitnessValidator<T extends BoundWitness = BoundWitness> extends PayloadValidator<T> {
16
- protected get expectedSchema(): string {
17
- return BoundWitnessSchema
18
- }
19
-
20
- static async validateSignature(hash: ArrayBufferLike, address: ArrayBufferLike, signature?: ArrayBufferLike): Promise<Error[]> {
21
- if (!signature) {
22
- return [new Error(`Missing signature [${address}]`)]
23
- }
24
- if (!(await Elliptic.verify(hash, signature, address))) {
25
- return [new Error(`Invalid signature [${address}]`)]
26
- }
27
- return []
28
- }
29
-
30
- addresses(): Error[] {
31
- const errors: Error[] = [...this.addressesUniqueness()]
32
- // const { addresses } = this.obj
33
- // if (!addresses?.length) errors.push(new Error('addresses missing [at least one address required]'))
34
- return errors
35
- }
36
-
37
- addressesUniqueness(): Error[] {
38
- const errors: Error[] = []
39
- const { addresses = [] } = this.obj
40
- const uniqAddresses = uniq(addresses)
41
- if (addresses?.length !== uniqAddresses?.length) errors.push(new Error('addresses must be unique'))
42
- return errors
43
- }
44
-
45
- previousHashes() {
46
- const errors: Error[] = []
47
- return errors
48
- }
49
-
50
- schema(): Error[] {
51
- const errors: Error[] = []
52
- if (this.obj.schema !== this.expectedSchema) {
53
- errors.push(new Error(`invalid schema [${this.expectedSchema} !== ${this.obj.schema}]`))
54
- }
55
- return errors
56
- }
57
-
58
- schemas(): Error[] {
59
- const errors: Error[] = []
60
- const Schemas = this.obj.payload_schemas
61
- if (Schemas) {
62
- const schemaValidators = Schemas.map((schema: string) => {
63
- return PayloadValidator.schemaNameValidatorFactory?.(schema)
64
- })
65
- for (const validator of schemaValidators) {
66
- if (validator) {
67
- errors.push(...validator.all())
68
- }
69
- }
70
- }
71
- return errors
72
- }
73
-
74
- async signatures(): Promise<Error[]> {
75
- return [
76
- ...validateArraysSameLength(this.obj.$signatures ?? [], this.obj.addresses ?? [], 'Length mismatch: address/signature'),
77
- ...(
78
- await Promise.all(
79
- this.obj.addresses?.map<Promise<Error[]>>(async (address, index) =>
80
- BoundWitnessValidator.validateSignature(
81
- toArrayBuffer(await PayloadBuilder.dataHash(this.payload)),
82
- toArrayBuffer(asAddress(address, true)),
83
- toArrayBuffer(this.obj.$signatures?.[index] ?? undefined),
84
- )) ?? [],
85
- )
86
- ).flat(),
87
- ]
88
- }
89
-
90
- override async validate() {
91
- return [
92
- ...(await this.signatures()),
93
- ...this.addresses(),
94
- ...this.validateArrayLengths(),
95
- ...this.schemas(),
96
- ...this.previousHashes(),
97
- ...this.schema(),
98
- ...(await super.validate()),
99
- ]
100
- }
101
-
102
- validateArrayLengths(): Error[] {
103
- const errors: Error[] = [...this.validatePayloadHashesLength()]
104
- return errors
105
- }
106
-
107
- validatePayloadHashesLength(): Error[] {
108
- const errors: Error[] = [...this.validateArrayLength('payload_hashes', 'payload_schemas')]
109
- return errors
110
- }
111
-
112
- private validateArrayLength(fieldName: string, compareArrayName: string): Error[] {
113
- const errors: Error[] = []
114
-
115
- const [array, arrayErrors] = validateType('array', this.stringKeyObj[fieldName] as [], true)
116
- const [compareArray, compareArrayErrors] = validateType('array', this.stringKeyObj[compareArrayName] as [], true)
117
-
118
- if (array?.length !== compareArray?.length) {
119
- errors.push(new Error(`${fieldName}/${compareArrayName} count mismatch [${array?.length} !== ${compareArray?.length}]`))
120
- }
121
-
122
- return [...arrayErrors, ...compareArrayErrors, ...errors]
123
- }
124
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './lib/index.ts'
2
- export * from './Validator.ts'
@@ -1,14 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
3
-
4
- import { boundWitnessArrayPropertyContains } from '../util/index.ts'
5
-
6
- /**
7
- * Checks if the boundwitness contains the addresses
8
- * @param bw The boundwitness to check
9
- * @param addresses The address to check for
10
- * @returns True if the boundwitness contains the addresses
11
- */
12
- export const addressesContains = (bw: BoundWitness, address: Address): boolean => {
13
- return boundWitnessArrayPropertyContains(bw, 'addresses', address)
14
- }
@@ -1,14 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
3
-
4
- import { boundWitnessArrayPropertyContainsAll } from '../util/index.ts'
5
-
6
- /**
7
- * Checks if the boundwitness contains all of the addresses
8
- * @param bw The boundwitness to check
9
- * @param addresses The addresses to check for
10
- * @returns True if the boundwitness contains all of the addresses
11
- */
12
- export const addressesContainsAll = (bw: BoundWitness, addresses: Address[]): boolean => {
13
- return boundWitnessArrayPropertyContainsAll(bw, 'addresses', addresses)
14
- }
@@ -1,16 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
3
-
4
- import { boundWitnessArrayPropertyContainsAny } from '../util/index.ts'
5
-
6
- /**
7
- * Checks if the boundwitness contains any of the addresses. If the addresses array
8
- * is empty, it will return true. This is to match the behavior or addressesContainsAll
9
- * which will return true if the addresses array is empty.
10
- * @param bw The boundwitness to check
11
- * @param addresses The addresses to check for
12
- * @returns True if the boundwitness contains any of the addresses
13
- */
14
- export const addressesContainsAny = (bw: BoundWitness, addresses: Address[]): boolean => {
15
- return boundWitnessArrayPropertyContainsAny(bw, 'addresses', addresses)
16
- }
@@ -1,3 +0,0 @@
1
- export * from './addressesContains.ts'
2
- export * from './addressesContainsAll.ts'
3
- export * from './addressesContainsAny.ts'
package/src/lib/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './addresses/index.ts'
2
- export * from './payloadHashes/index.ts'
3
- export * from './payloadSchemas/index.ts'
@@ -1,3 +0,0 @@
1
- export * from './payloadHashesContains.ts'
2
- export * from './payloadHashesContainsAll.ts'
3
- export * from './payloadHashesContainsAny.ts'
@@ -1,14 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
3
-
4
- import { boundWitnessArrayPropertyContains } from '../util/index.ts'
5
-
6
- /**
7
- * Checks if the boundwitness contains the payload hash
8
- * @param bw The boundwitness to check
9
- * @param payloadHash The payload hash to check for
10
- * @returns True if the boundwitness contains the payload hash
11
- */
12
- export const payloadHashesContains = (bw: BoundWitness, payloadHash: Hash): boolean => {
13
- return boundWitnessArrayPropertyContains(bw, 'payload_hashes', payloadHash)
14
- }
@@ -1,14 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
3
-
4
- import { boundWitnessArrayPropertyContainsAll } from '../util/index.ts'
5
-
6
- /**
7
- * Checks if the boundwitness contains all of the payload hashes
8
- * @param bw The boundwitness to check
9
- * @param payloadHashes The payload hashes to check for
10
- * @returns True if the boundwitness contains all of the payload hashes
11
- */
12
- export const payloadHashesContainsAll = (bw: BoundWitness, payloadHashes: Hash[]): boolean => {
13
- return boundWitnessArrayPropertyContainsAll(bw, 'payload_hashes', payloadHashes)
14
- }
@@ -1,16 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
3
-
4
- import { boundWitnessArrayPropertyContainsAny } from '../util/index.ts'
5
-
6
- /**
7
- * Checks if the boundwitness contains any of the payload hashes. If the payload hashes array
8
- * is empty, it will return true. This is to match the behavior or payload hashesContainsAll
9
- * which will return true if the payload hashes array is empty.
10
- * @param bw The boundwitness to check
11
- * @param payloadHashes The payload hashes to check for
12
- * @returns True if the boundwitness contains any of the payload hashes
13
- */
14
- export const payloadHashesContainsAny = (bw: BoundWitness, payloadHashes: Hash[]): boolean => {
15
- return boundWitnessArrayPropertyContainsAny(bw, 'payload_hashes', payloadHashes)
16
- }
@@ -1,3 +0,0 @@
1
- export * from './payloadSchemasContains.ts'
2
- export * from './payloadSchemasContainsAll.ts'
3
- export * from './payloadSchemasContainsAny.ts'
@@ -1,14 +0,0 @@
1
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
2
- import type { Schema } from '@xyo-network/payload-model'
3
-
4
- import { boundWitnessArrayPropertyContains } from '../util/index.ts'
5
-
6
- /**
7
- * Checks if the boundwitness contains the payload schema
8
- * @param bw The boundwitness to check
9
- * @param schema The payload schema to check for
10
- * @returns True if the boundwitness contains the payload schema
11
- */
12
- export const payloadSchemasContains = (bw: BoundWitness, schema: Schema): boolean => {
13
- return boundWitnessArrayPropertyContains(bw, 'payload_schemas', schema)
14
- }
@@ -1,14 +0,0 @@
1
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
2
- import type { Schema } from '@xyo-network/payload-model'
3
-
4
- import { boundWitnessArrayPropertyContainsAll } from '../util/index.ts'
5
-
6
- /**
7
- * Checks if the boundwitness contains all of the payload schemas
8
- * @param bw The boundwitness to check
9
- * @param payloadSchemas The payload schemas to check for
10
- * @returns True if the boundwitness contains all of the payload schemas
11
- */
12
- export const payloadSchemasContainsAll = (bw: BoundWitness, payloadSchemas: Schema[]): boolean => {
13
- return boundWitnessArrayPropertyContainsAll(bw, 'payload_schemas', payloadSchemas)
14
- }
@@ -1,16 +0,0 @@
1
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
2
- import type { Schema } from '@xyo-network/payload-model'
3
-
4
- import { boundWitnessArrayPropertyContainsAny } from '../util/index.ts'
5
-
6
- /**
7
- * Checks if the boundwitness contains any of the payload schemas. If the payload schemas array
8
- * is empty, it will return true. This is to match the behavior or payload schemasContainsAll
9
- * which will return true if the payload schemas array is empty.
10
- * @param bw The boundwitness to check
11
- * @param payloadSchemas The payload schemas to check for
12
- * @returns True if the boundwitness contains any of the payload schemas
13
- */
14
- export const payloadSchemasContainsAny = (bw: BoundWitness, payloadSchemas: Schema[]): boolean => {
15
- return boundWitnessArrayPropertyContainsAny(bw, 'payload_schemas', payloadSchemas)
16
- }
@@ -1,17 +0,0 @@
1
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
2
-
3
- /**
4
- * The properties of a boundwitness that are string-like arrays
5
- */
6
- export type BoundWitnessArrayProperty = keyof Pick<BoundWitness,
7
- 'addresses'
8
- // 'error_hashes' |
9
- | 'payload_hashes'
10
- | 'payload_schemas'
11
- // 'previous_hashes'
12
- >
13
-
14
- /**
15
- * The value of the underlying array type for the BoundWitness array property
16
- */
17
- export type BoundWitnessArrayPropertyValue<P extends BoundWitnessArrayProperty> = BoundWitness[P] extends (infer T)[] ? T : never
@@ -1,19 +0,0 @@
1
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
2
-
3
- import type { BoundWitnessArrayProperty, BoundWitnessArrayPropertyValue } from './BoundWitnessArrayProperty.ts'
4
-
5
- /**
6
- * Checks if the boundwitness contains the addresses
7
- * @param bw The boundwitness
8
- * @param prop The boundwitness property to check
9
- * @param value The value to check for in the property
10
- * @returns True if the boundwitness property contains the value
11
- */
12
- export const boundWitnessArrayPropertyContains = <P extends BoundWitnessArrayProperty>(
13
- bw: BoundWitness,
14
- prop: P,
15
- value: BoundWitnessArrayPropertyValue<P>,
16
-
17
- ): boolean => {
18
- return (bw[prop] as BoundWitnessArrayPropertyValue<P>[])?.includes(value)
19
- }
@@ -1,18 +0,0 @@
1
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
2
-
3
- import type { BoundWitnessArrayProperty, BoundWitnessArrayPropertyValue } from './BoundWitnessArrayProperty.ts'
4
-
5
- /**
6
- * Checks if the boundwitness property contains all of the values
7
- * @param bw The boundwitness
8
- * @param prop The boundwitness property to check
9
- * @param values The values to check for in the property
10
- * @returns True if the boundwitness contains all of the values in the property
11
- */
12
- export const boundWitnessArrayPropertyContainsAll = <P extends BoundWitnessArrayProperty>(
13
- bw: BoundWitness,
14
- prop: P,
15
- values: BoundWitnessArrayPropertyValue<P>[],
16
- ): boolean => {
17
- return values.every(v => (bw[prop] as BoundWitnessArrayPropertyValue<P>[])?.includes(v))
18
- }
@@ -1,21 +0,0 @@
1
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
2
-
3
- import type { BoundWitnessArrayProperty, BoundWitnessArrayPropertyValue } from './BoundWitnessArrayProperty.ts'
4
-
5
- /**
6
- * Checks if the boundwitness contains any of the values in the property. If the values array
7
- * is empty, it will return true. This is to match the behavior or boundWitnessContainsAll
8
- * which will return true if the values array is empty.
9
- * @param bw The boundwitness
10
- * @param prop The boundwitness property to check
11
- * @param value The values to check for in the property
12
- * @returns True if the boundwitness contains any of the values in the property
13
- */
14
- export const boundWitnessArrayPropertyContainsAny = <P extends BoundWitnessArrayProperty>(
15
- bw: BoundWitness,
16
- prop: P,
17
- values: BoundWitnessArrayPropertyValue<P>[],
18
- ): boolean => {
19
- if (values.length === 0) return true
20
- return values.some(value => (bw[prop] as BoundWitnessArrayPropertyValue<P>[])?.includes(value))
21
- }
@@ -1,3 +0,0 @@
1
- export * from './boundWitnessArrayPropertyContains.ts'
2
- export * from './boundWitnessArrayPropertyContainsAll.ts'
3
- export * from './boundWitnessArrayPropertyContainsAny.ts'