@xyo-network/boundwitness-wrapper 5.3.22 → 5.3.25

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-wrapper",
3
- "version": "5.3.22",
3
+ "version": "5.3.25",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,47 +30,43 @@
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/boundwitness-validator": "~5.3.22",
42
- "@xyo-network/payload": "~5.3.22",
43
- "@xyo-network/payload-builder": "~5.3.22",
44
- "@xyo-network/payload-model": "~5.3.22",
45
- "@xyo-network/payload-wrapper": "~5.3.22"
39
+ "@xyo-network/boundwitness-model": "~5.3.25",
40
+ "@xyo-network/boundwitness-validator": "~5.3.25",
41
+ "@xyo-network/payload": "~5.3.25",
42
+ "@xyo-network/payload-model": "~5.3.25",
43
+ "@xyo-network/payload-wrapper": "~5.3.25",
44
+ "@xyo-network/payload-builder": "~5.3.25"
46
45
  },
47
46
  "devDependencies": {
48
47
  "@opentelemetry/api": "^1.9.1",
49
48
  "@types/node": "^25.5.0",
50
- "@xylabs/sdk-js": "^5.0.91",
51
- "@xylabs/ts-scripts-common": "~7.6.8",
52
- "@xylabs/ts-scripts-yarn3": "~7.6.8",
53
- "@xylabs/tsconfig": "~7.6.8",
54
- "@xylabs/vitest-extended": "~5.0.91",
55
- "@xyo-network/boundwitness-model": "~5.3.22",
56
- "@xyo-network/boundwitness-validator": "~5.3.22",
57
- "@xyo-network/payload": "~5.3.22",
58
- "@xyo-network/payload-builder": "~5.3.22",
59
- "@xyo-network/payload-model": "~5.3.22",
60
- "@xyo-network/payload-wrapper": "~5.3.22",
49
+ "@xylabs/sdk-js": "^5.0.93",
50
+ "@xylabs/ts-scripts-common": "~7.6.16",
51
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
52
+ "@xylabs/tsconfig": "~7.6.16",
53
+ "@xylabs/vitest-extended": "~5.0.93",
61
54
  "acorn": "^8.16.0",
62
55
  "ajv": "^8.18.0",
63
56
  "axios": "^1.14.0",
64
- "cosmiconfig": "^9.0.1",
65
- "esbuild": "^0.27.4",
66
- "eslint": "^10.1.0",
57
+ "esbuild": "^0.28.0",
67
58
  "ethers": "^6.16.0",
68
- "rollup": "^4.60.1",
69
59
  "tslib": "^2.8.1",
70
60
  "typescript": "~5.9.3",
71
61
  "vite": "^8.0.3",
72
62
  "vitest": "~4.1.2",
73
- "zod": "^4.3.6"
63
+ "zod": "^4.3.6",
64
+ "@xyo-network/boundwitness-model": "~5.3.25",
65
+ "@xyo-network/boundwitness-validator": "~5.3.25",
66
+ "@xyo-network/payload": "~5.3.25",
67
+ "@xyo-network/payload-builder": "~5.3.25",
68
+ "@xyo-network/payload-model": "~5.3.25",
69
+ "@xyo-network/payload-wrapper": "~5.3.25"
74
70
  },
75
71
  "peerDependencies": {
76
72
  "@xylabs/sdk-js": "^5",
@@ -87,4 +83,4 @@
87
83
  "publishConfig": {
88
84
  "access": "public"
89
85
  }
90
- }
86
+ }
@@ -1,223 +0,0 @@
1
- import {
2
- assertEx, isNumber, isObject,
3
- } from '@xylabs/sdk-js'
4
- import {
5
- type Address, asHash, type Hash,
6
- } from '@xylabs/sdk-js'
7
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
8
- import {
9
- asBoundWitness,
10
- BoundWitnessSchema, isBoundWitness,
11
- } from '@xyo-network/boundwitness-model'
12
- import { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'
13
- import { PayloadBuilder } from '@xyo-network/payload-builder'
14
- import type { Payload, WithoutPrivateStorageMeta } from '@xyo-network/payload-model'
15
- import {
16
- isPayloadWrapperBase, PayloadWrapper, PayloadWrapperBase,
17
- } from '@xyo-network/payload-wrapper'
18
-
19
- export const isBoundWitnessWrapper = <T extends BoundWitness = BoundWitness, P extends Payload = Payload>(
20
- value?: unknown,
21
- ): value is BoundWitnessWrapper<T, P> => {
22
- if (isPayloadWrapperBase(value)) {
23
- return typeof (value as BoundWitnessWrapper<T, P>).payloadsDataHashMap === 'function'
24
- }
25
- return false
26
- }
27
-
28
- export class BoundWitnessWrapper<
29
- TBoundWitness extends BoundWitness = BoundWitness,
30
- TPayload extends Payload = Payload,
31
- > extends PayloadWrapperBase<TBoundWitness> {
32
- boundwitness: TBoundWitness
33
- moduleErrors?: Payload[]
34
- payloads: TPayload[] = []
35
-
36
- private _payloadDataMap: Record<Hash, TPayload> | undefined
37
- private _payloadMap: Record<Hash, TPayload> | undefined
38
-
39
- protected constructor(
40
- boundwitness: TBoundWitness,
41
- payloads: TPayload[] = [],
42
- moduleErrors?: Payload[],
43
- ) {
44
- super(boundwitness)
45
- this.boundwitness = boundwitness
46
- this.payloads = payloads
47
- this.moduleErrors = moduleErrors
48
- }
49
-
50
- get addresses() {
51
- return this.boundwitness.addresses
52
- }
53
-
54
- get payloadHashes() {
55
- return this.boundwitness.payload_hashes
56
- }
57
-
58
- get payloadSchemas() {
59
- return this.boundwitness.payload_schemas
60
- }
61
-
62
- get previousHashes() {
63
- return this.boundwitness.previous_hashes
64
- }
65
-
66
- static as<T extends BoundWitness = BoundWitness>(value: unknown) {
67
- return value instanceof BoundWitnessWrapper ? (value as BoundWitnessWrapper<T>) : undefined
68
- }
69
-
70
- static async load(address: Address) {
71
- const wrapper = await PayloadWrapper.load(address)
72
- const payload = wrapper?.payload
73
- assertEx(payload && isBoundWitness(payload), () => 'Attempt to load non-boundwitness')
74
-
75
- const boundWitness: BoundWitness | undefined = payload && isBoundWitness(payload) ? payload : undefined
76
- return boundWitness ? BoundWitnessWrapper.wrap(boundWitness) : null
77
- }
78
-
79
- static parse<T extends BoundWitness = BoundWitness, P extends Payload = Payload>(
80
- obj: unknown,
81
- payloads?: P[],
82
- ): BoundWitnessWrapper<T, P> {
83
- let hydratedObj: T | undefined = undefined
84
- switch (typeof obj) {
85
- case 'string': {
86
- hydratedObj = JSON.parse(obj) as T
87
- break
88
- }
89
- case 'object': {
90
- if (isObject(obj)) {
91
- hydratedObj = obj as unknown as T
92
- }
93
- break
94
- }
95
- }
96
-
97
- if (hydratedObj) {
98
- if (isBoundWitnessWrapper<T, P>(hydratedObj)) {
99
- return hydratedObj as BoundWitnessWrapper<T, P>
100
- }
101
- if (isBoundWitness(hydratedObj)) {
102
- return new BoundWitnessWrapper(hydratedObj, payloads ?? [])
103
- }
104
- }
105
-
106
- throw new Error(`Unable to parse [${typeof obj}]`)
107
- }
108
-
109
- static tryParse<T extends BoundWitness, P extends Payload>(obj: unknown, payloads?: P[]): BoundWitnessWrapper<T, P> | undefined {
110
- if (obj === undefined) return undefined
111
- try {
112
- return this.parse(obj, payloads)
113
- } catch {
114
- return undefined
115
- }
116
- }
117
-
118
- static wrap<T extends BoundWitness, P extends Payload>(
119
- obj: PayloadWrapperBase<T> | WithoutPrivateStorageMeta<T>,
120
- payloads?: P[],
121
- ): BoundWitnessWrapper<T, P> {
122
- switch (typeof obj) {
123
- case 'object': {
124
- if (obj instanceof BoundWitnessWrapper) {
125
- return obj
126
- } else if (obj instanceof PayloadWrapper && obj.schema() === BoundWitnessSchema) {
127
- return BoundWitnessWrapper.parse(obj.payload, payloads)
128
- } else {
129
- return BoundWitnessWrapper.parse(obj, payloads)
130
- }
131
- }
132
- }
133
- }
134
-
135
- static async wrappedDataHashMap<T extends BoundWitness>(
136
- boundWitnesses: (T | BoundWitnessWrapper<T>)[],
137
- ): Promise<Record<string, BoundWitnessWrapper<T>>> {
138
- const result: Record<string, BoundWitnessWrapper<T>> = {}
139
- await Promise.all(
140
- boundWitnesses.map(async (payload) => {
141
- const bw = BoundWitnessWrapper.parse<T, Payload>(payload)
142
- result[await bw.dataHash()] = bw
143
- }),
144
- )
145
- return result
146
- }
147
-
148
- async dig(depth?: number): Promise<BoundWitnessWrapper<TBoundWitness>> {
149
- if (depth === 0) return this
150
-
151
- const innerBoundwitnessIndex: number = this.payloadSchemas.indexOf(BoundWitnessSchema)
152
- if (innerBoundwitnessIndex !== -1) {
153
- const innerBoundwitnessHash = asHash(this.payloadHashes[innerBoundwitnessIndex], true)
154
- const innerBoundwitnessPayload = asBoundWitness(
155
- (await PayloadBuilder.toAllHashMap(this.payloads))[innerBoundwitnessHash],
156
- ) as TBoundWitness | undefined
157
- const innerBoundwitness: BoundWitnessWrapper<TBoundWitness> | undefined
158
- = innerBoundwitnessPayload
159
- ? new BoundWitnessWrapper<TBoundWitness>(innerBoundwitnessPayload, await PayloadBuilder.filterExclude(this.payloads, innerBoundwitnessHash))
160
- : undefined
161
- if (innerBoundwitness) {
162
- return innerBoundwitness.dig(isNumber(depth) ? depth - 1 : undefined)
163
- }
164
- }
165
- assertEx(depth === 0, () => `Dig failed [Remaining Depth: ${depth}]`)
166
- return this
167
- }
168
-
169
- async getMissingPayloads() {
170
- const payloadMap = await this.payloadsDataHashMap()
171
- return this.payloadHashes.filter(hash => !payloadMap[asHash(hash, true)])
172
- }
173
-
174
- async getWrappedPayloads(): Promise<PayloadWrapper<TPayload>[]> {
175
- return await Promise.all(this.payloads.map(payload => PayloadWrapper.wrap(payload)))
176
- }
177
-
178
- hashesBySchema(schema: string) {
179
- const result: string[] = []
180
- for (const [index, payloadSchema] of this.payloadSchemas.entries()) {
181
- if (payloadSchema === schema) {
182
- result.push(asHash(this.payloadHashes[index], true))
183
- }
184
- }
185
- return result
186
- }
187
-
188
- async payloadsByDataHashes(hashes: Hash[]): Promise<TPayload[]> {
189
- const map = await this.payloadsDataHashMap()
190
- return hashes.map(hash => assertEx(map[hash], () => 'Hash not found') as TPayload)
191
- }
192
-
193
- async payloadsByHashes(hashes: Hash[]): Promise<TPayload[]> {
194
- const map = await this.payloadsHashMap()
195
- return hashes.map(hash => assertEx(map[hash], () => 'Hash not found') as TPayload)
196
- }
197
-
198
- payloadsBySchema<T extends TPayload>(schema: string): T[] {
199
- return this.payloads.filter(payload => payload?.schema === schema) as T[]
200
- }
201
-
202
- async payloadsDataHashMap(): Promise<Partial<Record<Hash, TPayload>>> {
203
- this._payloadDataMap = this._payloadDataMap ?? (await PayloadBuilder.toDataHashMap<TPayload>(this.payloads))
204
- return this._payloadDataMap
205
- }
206
-
207
- async payloadsHashMap(): Promise<Partial<Record<Hash, TPayload>>> {
208
- this._payloadMap = this._payloadMap ?? (await PayloadBuilder.toHashMap<TPayload>(this.payloads))
209
- return this._payloadMap
210
- }
211
-
212
- prev(address: Address) {
213
- return this.previousHashes[this.addresses.indexOf(address)]
214
- }
215
-
216
- toResult() {
217
- return [this.boundwitness, this.payloads]
218
- }
219
-
220
- override async validate(): Promise<Error[]> {
221
- return await new BoundWitnessValidator(this.boundwitness).validate()
222
- }
223
- }
@@ -1,67 +0,0 @@
1
- import type { Promisable } from '@xylabs/sdk-js'
2
- import {
3
- asHash, assertEx, exists,
4
- } from '@xylabs/sdk-js'
5
- import type { QueryBoundWitness } from '@xyo-network/boundwitness-model'
6
- import { isQueryBoundWitness } from '@xyo-network/boundwitness-model'
7
- import { PayloadBuilder } from '@xyo-network/payload'
8
- import type { Payload, Query } from '@xyo-network/payload-model'
9
- import { PayloadWrapper } from '@xyo-network/payload-wrapper'
10
-
11
- import { BoundWitnessWrapper } from './BoundWitnessWrapper.ts'
12
-
13
- export class QueryBoundWitnessWrapper<T extends Query = Query> extends BoundWitnessWrapper<QueryBoundWitness> {
14
- private _payloadsWithoutQuery: PayloadWrapper<Payload>[] | undefined
15
- private _query: T | undefined
16
-
17
- static parseQuery<T extends Query = Query>(obj: unknown, payloads?: Payload[]): QueryBoundWitnessWrapper<T> {
18
- assertEx(!Array.isArray(obj), () => 'Array can not be converted to QueryBoundWitnessWrapper')
19
- switch (typeof obj) {
20
- case 'object': {
21
- const castWrapper = obj as QueryBoundWitnessWrapper<T>
22
- /* if (!wrapper.valid) {
23
- console.warn(`Parsed invalid QueryBoundWitness ${JSON.stringify(wrapper.errors.map((error) => error.message))}`)
24
- } */
25
- const result = castWrapper instanceof QueryBoundWitnessWrapper
26
- ? castWrapper
27
- : isQueryBoundWitness(obj)
28
- ? (
29
- new QueryBoundWitnessWrapper<T>(
30
- obj,
31
- payloads,
32
- )
33
- )
34
- : undefined
35
- if (result === undefined) {
36
- throw new Error('Unable to parse. Failed isQueryBoundWitness.')
37
- }
38
- return result
39
- }
40
- }
41
- throw new Error(`Unable to parse [${typeof obj}]`)
42
- }
43
-
44
- static tryParseQuery<T extends Query>(obj: unknown): Promisable<QueryBoundWitnessWrapper<T> | undefined> {
45
- if (obj === undefined) return undefined
46
- try {
47
- return this.parseQuery<T>(obj)
48
- } catch {
49
- return undefined
50
- }
51
- }
52
-
53
- async getPayloadsWithoutQuery(): Promise<PayloadWrapper<Payload>[]> {
54
- this._payloadsWithoutQuery
55
- = this._payloadsWithoutQuery
56
- ?? (await Promise.all(
57
- (await PayloadBuilder.filterExclude(this.payloads, asHash(this.payload.query, true))).map(payload => PayloadWrapper.wrap(payload)).filter(exists),
58
- ))
59
- return this._payloadsWithoutQuery
60
- }
61
-
62
- async getQuery(): Promise<T> {
63
- const payloadMap = await this.payloadsDataHashMap()
64
- this._query = this._query ?? (payloadMap[asHash(this.boundwitness.query, true)] as T | undefined)
65
- return assertEx(this._query, () => `Missing Query [${JSON.stringify(this.boundwitness)}]`)
66
- }
67
- }
package/src/SchemaType.ts DELETED
@@ -1,36 +0,0 @@
1
- import {
2
- AddressRegEx, HashRegEx, HexRegExMinMax,
3
- } from '@xylabs/sdk-js'
4
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
5
- import { SchemaRegEx } from '@xyo-network/payload-model'
6
- import { payloadJsonSchema } from '@xyo-network/payload-wrapper'
7
- import type { JSONSchemaType } from 'ajv'
8
-
9
- export const SignatureRegEx = HexRegExMinMax(64, 64)
10
-
11
- export const boundWitnessProperties: JSONSchemaType<BoundWitness>['properties'] = {
12
- ...payloadJsonSchema.properties,
13
- addresses: { items: { type: 'string', pattern: AddressRegEx.source }, type: 'array' },
14
- payload_hashes: { items: { type: 'string', pattern: HashRegEx.source }, type: 'array' },
15
- payload_schemas: { items: { type: 'string', pattern: SchemaRegEx.source }, type: 'array' },
16
- previous_hashes: {
17
- items: {
18
- type: 'string', pattern: HashRegEx.source, nullable: true,
19
- },
20
- type: 'array',
21
- },
22
- root: { type: 'string', pattern: HashRegEx.source },
23
- $destination: { items: { type: 'string', pattern: HashRegEx.source }, type: 'array' },
24
- $sourceQuery: { type: 'string', pattern: HashRegEx.source },
25
- $sources: { items: { type: 'string', pattern: HashRegEx.source }, type: 'array' },
26
- $signatures: { items: { type: 'string', pattern: SignatureRegEx.source }, type: 'array' },
27
- }
28
-
29
- export const boundWitnessJsonSchema: JSONSchemaType<BoundWitness> = {
30
- ...payloadJsonSchema,
31
- $id: 'https://schemas.xyo.network/2.0/boundwitness',
32
- additionalProperties: false,
33
- properties: boundWitnessProperties,
34
- required: [...payloadJsonSchema.required, 'addresses', 'payload_hashes', 'payload_schemas', 'previous_hashes'],
35
- type: 'object',
36
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './BoundWitnessWrapper.ts'
2
- export * from './QueryBoundWitnessWrapper.ts'
3
- export * from './SchemaType.ts'