@xyo-network/boundwitness-model 5.1.24 → 5.2.1

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.
@@ -1,14 +1,48 @@
1
1
  import type { WithStorageMeta } from '@xyo-network/payload-model';
2
2
  import type { BoundWitness, Signed, Unsigned } from './BoundWitness/index.ts';
3
3
  export declare const isBoundWitness: (value: unknown) => value is BoundWitness;
4
- export declare const notBoundWitness: (x?: unknown | null) => x is BoundWitness;
5
- export declare const asBoundWitness: <T extends BoundWitness<{
6
- schema: string;
7
- }> = BoundWitness>(payload?: unknown) => T | undefined;
8
- export declare const asOptionalBoundWitness: (value: import(".store/@xylabs-promise-npm-5.0.37-e0d0dd2b09/package").AnyNonPromise) => BoundWitness | undefined;
4
+ export declare const notBoundWitness: (x?: unknown | null) => x is {
5
+ schema: "network.xyo.boundwitness";
6
+ addresses: import("@xylabs/sdk-js").Address[];
7
+ payload_hashes: import("@xylabs/sdk-js").Hash[];
8
+ payload_schemas: string[];
9
+ previous_hashes: (import("@xylabs/sdk-js").Hash | null)[];
10
+ $signatures: (import("@xylabs/sdk-js").Hex | null)[];
11
+ $destination?: import("@xylabs/sdk-js").Address | undefined;
12
+ $sourceQuery?: import("@xylabs/sdk-js").Hash | undefined;
13
+ };
14
+ export declare const asBoundWitness: <T extends BoundWitness = BoundWitness>(payload?: unknown) => T | undefined;
15
+ export declare const asOptionalBoundWitness: (value: import("@xylabs/sdk-js").AnyNonPromise) => {
16
+ schema: "network.xyo.boundwitness";
17
+ addresses: import("@xylabs/sdk-js").Address[];
18
+ payload_hashes: import("@xylabs/sdk-js").Hash[];
19
+ payload_schemas: string[];
20
+ previous_hashes: (import("@xylabs/sdk-js").Hash | null)[];
21
+ $signatures: (import("@xylabs/sdk-js").Hex | null)[];
22
+ $destination?: import("@xylabs/sdk-js").Address | undefined;
23
+ $sourceQuery?: import("@xylabs/sdk-js").Hash | undefined;
24
+ } | undefined;
9
25
  export declare const isBoundWitnessWithStorageMeta: (value: unknown) => value is WithStorageMeta<BoundWitness>;
10
- export declare const asBoundWitnessWithStorageMeta: (value: import(".store/@xylabs-promise-npm-5.0.37-e0d0dd2b09/package").AnyNonPromise) => WithStorageMeta<BoundWitness> | undefined;
11
- export declare const asOptionalBoundWitnessWithStorageMeta: (value: import(".store/@xylabs-promise-npm-5.0.37-e0d0dd2b09/package").AnyNonPromise) => WithStorageMeta<BoundWitness> | undefined;
26
+ export declare const asBoundWitnessWithStorageMeta: (value: import("@xylabs/sdk-js").AnyNonPromise) => WithStorageMeta<{
27
+ schema: "network.xyo.boundwitness";
28
+ addresses: import("@xylabs/sdk-js").Address[];
29
+ payload_hashes: import("@xylabs/sdk-js").Hash[];
30
+ payload_schemas: string[];
31
+ previous_hashes: (import("@xylabs/sdk-js").Hash | null)[];
32
+ $signatures: (import("@xylabs/sdk-js").Hex | null)[];
33
+ $destination?: import("@xylabs/sdk-js").Address | undefined;
34
+ $sourceQuery?: import("@xylabs/sdk-js").Hash | undefined;
35
+ }> | undefined;
36
+ export declare const asOptionalBoundWitnessWithStorageMeta: (value: import("@xylabs/sdk-js").AnyNonPromise) => WithStorageMeta<{
37
+ schema: "network.xyo.boundwitness";
38
+ addresses: import("@xylabs/sdk-js").Address[];
39
+ payload_hashes: import("@xylabs/sdk-js").Hash[];
40
+ payload_schemas: string[];
41
+ previous_hashes: (import("@xylabs/sdk-js").Hash | null)[];
42
+ $signatures: (import("@xylabs/sdk-js").Hex | null)[];
43
+ $destination?: import("@xylabs/sdk-js").Address | undefined;
44
+ $sourceQuery?: import("@xylabs/sdk-js").Hash | undefined;
45
+ }> | undefined;
12
46
  export declare function isSigned(value: unknown): value is Signed;
13
47
  export declare function isSigned<T extends Unsigned>(value: T): value is Signed<T>;
14
48
  export declare function isUnsigned(value: unknown): value is Unsigned;
@@ -1 +1 @@
1
- {"version":3,"file":"isBoundWitness.d.ts","sourceRoot":"","sources":["../../src/isBoundWitness.ts"],"names":[],"mappings":"AACA,OAA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AM,cAAc,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,YAA8E,CAAA;AAEvI,eAAO,MAAM,eAAe;;;;;;;;;CAA2D,CAAA;AAIvF,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,UAAU,OAAO,kBACjC,CAAA;AAEtD,eAAO,MAAM,sBAAsB;;;;;;;;;aAA+D,CAAA;AAElG,eAAO,MAAM,6BAA6B,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,eAAe,CAAC,YAAY,CACZ,CAAA;AACxF,eAAO,MAAM,6BAA6B;;;;;;;;;cAA+F,CAAA;AACzI,eAAO,MAAM,qCAAqC;;;;;;;;;cAA+F,CAAA;AAEjJ,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAA;AACzD,wBAAgB,QAAQ,CAAC,CAAC,SAAS,QAAQ,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,CAAA;AAO1E,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAA;AAC7D,wBAAgB,UAAU,CAAC,CAAC,SAAS,YAAY,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/boundwitness-model",
3
- "version": "5.1.24",
3
+ "version": "5.2.1",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -36,9 +36,9 @@
36
36
  "!**/*.test.*"
37
37
  ],
38
38
  "dependencies": {
39
- "@xylabs/hex": "~5.0.37",
40
- "@xylabs/object": "~5.0.37",
41
- "@xyo-network/payload-model": "~5.1.24"
39
+ "@xylabs/sdk-js": "~5.0.39",
40
+ "@xyo-network/payload-model": "~5.2.1",
41
+ "zod": "~4.1.12"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "~24.10.1",
@@ -1,66 +1,64 @@
1
- import type {
2
- Address, Hash, Hex,
3
- } from '@xylabs/hex'
4
- import type { EmptyObject, JsonObject } from '@xylabs/object'
5
- import type { Payload, Schema } from '@xyo-network/payload-model'
6
-
7
- import type { BoundWitnessSchema } from './BoundWitnessSchema.ts'
8
-
9
- export interface BoundWitnessRequiredFields {
10
- /** @field Array of signatures by the accounts that are listed in addresses */
11
- addresses: Address[]
12
- payload_hashes: Hash[]
13
- payload_schemas: Schema[]
14
- previous_hashes: (Hash | null)[]
15
- }
16
-
17
- export interface BoundWitnessMeta {
18
- /**
19
- * @field The address to which the query is directed
20
- */
21
- $destination?: Address
22
- /**
23
- * @field The query that initiated the bound witness
24
- */
25
- $sourceQuery?: Hash
26
- }
27
-
28
- export interface BoundWitnessBlockField {
29
- /** @field sequential number (if this boundwitness is part of a multi-party chain) */
30
- block: number
31
- }
32
-
33
- export interface BoundWitnessChainField {
34
- /** @field unique id of a multi-party chain (usually staking contract address) */
35
- chain: Hex
36
- }
37
-
38
- export interface BoundWitnessOptionalFields extends Partial<BoundWitnessBlockField>, Partial<BoundWitnessChainField> {
39
- root: Hash
40
- }
41
-
42
- export interface BoundWitnessFields extends BoundWitnessRequiredFields, Partial<BoundWitnessOptionalFields> {}
43
-
44
- export type UnsignedBoundWitness<T extends EmptyObject | void = void> = Payload<
45
- T extends void ? BoundWitnessFields : BoundWitnessFields & T,
46
- BoundWitnessSchema
47
- > & BoundWitnessMeta
48
-
49
- export type Unsigned<T extends UnsignedBoundWitness = UnsignedBoundWitness> = T & {
50
- $signatures: Hex[]
51
- }
52
-
53
- export type Signed<T extends UnsignedBoundWitness = UnsignedBoundWitness> = T & {
54
- $signatures: Hex[]
55
- }
56
-
57
- export type SignedBoundWitness = Signed<UnsignedBoundWitness>
58
-
59
- export type WithBlock = BoundWitness & BoundWitnessBlockField
60
-
61
- export const hasBlock = (bw: BoundWitness): bw is WithBlock => bw.block !== undefined && typeof bw.block === 'string'
62
- export const asBlock = (bw: BoundWitness): WithBlock => bw as WithBlock
63
-
64
- export type BoundWitness<T extends Payload | EmptyObject | void = void> = Signed<UnsignedBoundWitness<T>>
65
-
66
- export type AnyBoundWitness = BoundWitness<JsonObject>
1
+ import {
2
+ AddressZod, HashZod, HexZod,
3
+ } from '@xylabs/sdk-js'
4
+ import {
5
+ PayloadZod, SchemaZod, StorageMetaZod,
6
+ } from '@xyo-network/payload-model'
7
+ import * as z from 'zod'
8
+
9
+ import { BoundWitnessSchema } from './BoundWitnessSchema.ts'
10
+
11
+ const BoundWitnessRequiredFieldsZod = z.object({
12
+ addresses: z.array(AddressZod),
13
+ payload_hashes: z.array(HashZod),
14
+ payload_schemas: z.array(SchemaZod),
15
+ previous_hashes: z.array(HashZod.nullable()),
16
+ })
17
+
18
+ const BoundWitnessMetaZod = z.object({
19
+ $destination: AddressZod.optional(),
20
+ $sourceQuery: HashZod.optional(),
21
+ $signatures: z.array(z.union([HexZod, z.null()])),
22
+ })
23
+
24
+ export const BoundWitnessZod = PayloadZod
25
+ .extend({ schema: z.literal(BoundWitnessSchema) })
26
+ .extend(BoundWitnessRequiredFieldsZod.shape)
27
+ .extend(BoundWitnessMetaZod.shape)
28
+ .refine(data => data.$signatures.length === data.addresses.length, { message: '$signatures length must equal addresses length' })
29
+
30
+ export type BoundWitness = z.infer<typeof BoundWitnessZod>
31
+
32
+ export const AnyBoundWitnessZod = BoundWitnessZod
33
+ .catchall(z.any())
34
+
35
+ export type AnyBoundWitness = z.infer<typeof AnyBoundWitnessZod>
36
+
37
+ export const UnsignedBoundWitnessZod = BoundWitnessZod.refine(data => data.$signatures.includes(null), { message: 'all $signatures must be null' })
38
+
39
+ export type UnsignedBoundWitness = z.infer<typeof UnsignedBoundWitnessZod>
40
+
41
+ export const AnyUnsignedBoundWitnessZod = UnsignedBoundWitnessZod
42
+ .catchall(z.any())
43
+
44
+ export type AnyUnsignedBoundWitness = z.infer<typeof AnyUnsignedBoundWitnessZod>
45
+
46
+ export const UnsignedBoundWitnessWithStorageMetaZod = UnsignedBoundWitnessZod
47
+ .safeExtend(BoundWitnessRequiredFieldsZod.shape)
48
+ .safeExtend(BoundWitnessMetaZod.shape)
49
+ .safeExtend(StorageMetaZod.shape)
50
+
51
+ export const SignedZod = z.object({ $signatures: z.array(HexZod) })
52
+ export const UnsignedZod = z.object({ $signatures: z.array(z.null()) })
53
+
54
+ export const SignedBoundWitnessZod = BoundWitnessZod.refine(data => !data.$signatures.includes(null), { message: 'all $signatures must not be null' })
55
+
56
+ export const SignedBoundWitnessWithStorageMetaZod = UnsignedBoundWitnessWithStorageMetaZod
57
+
58
+ export const AnySignedBoundWitnessZod = UnsignedBoundWitnessZod.catchall(z.any())
59
+
60
+ export const AnySignedBoundWitnessWithStorageMetaZod = UnsignedBoundWitnessWithStorageMetaZod.catchall(z.any())
61
+
62
+ export type Unsigned<T extends UnsignedBoundWitness = UnsignedBoundWitness> = T & z.infer<typeof UnsignedZod>
63
+
64
+ export type Signed<T extends UnsignedBoundWitness = UnsignedBoundWitness> = T & z.infer<typeof SignedZod>
@@ -1,4 +1,4 @@
1
- import type { Hash } from '@xylabs/hex'
1
+ import type { Hash } from '@xylabs/sdk-js'
2
2
  import type { WithStorageMeta } from '@xyo-network/payload-model'
3
3
  import { isStorageMeta } from '@xyo-network/payload-model'
4
4
 
@@ -10,7 +10,7 @@ export type QueryBoundWitnessFields = {
10
10
  query: Hash
11
11
  }
12
12
 
13
- export type UnsignedQueryBoundWitness = BoundWitness<QueryBoundWitnessFields>
13
+ export type UnsignedQueryBoundWitness = BoundWitness & QueryBoundWitnessFields
14
14
 
15
15
  export type QueryBoundWitness = UnsignedQueryBoundWitness
16
16
 
@@ -1,4 +1,4 @@
1
- import { AsObjectFactory } from '@xylabs/object'
1
+ import { AsObjectFactory } from '@xylabs/sdk-js'
2
2
  import type { WithStorageMeta } from '@xyo-network/payload-model'
3
3
  import {
4
4
  isPayloadOfSchemaType, isStorageMeta, notPayloadOfSchemaType,
@@ -15,7 +15,7 @@ export const notBoundWitness = notPayloadOfSchemaType<BoundWitness>(BoundWitness
15
15
 
16
16
  // TODO: Use AsObjectFactory here to match standard pattern
17
17
  // TODO: Other as identity functions throw if not valid, this one returns undefined with is more of a asOptional behavior
18
- export const asBoundWitness = <T extends BoundWitness<{ schema: string }> = BoundWitness>(payload?: unknown) =>
18
+ export const asBoundWitness = <T extends BoundWitness = BoundWitness>(payload?: unknown) =>
19
19
  isBoundWitness(payload) ? (payload as T) : undefined
20
20
 
21
21
  export const asOptionalBoundWitness = AsObjectFactory.createOptional<BoundWitness>(isBoundWitness)