Merge branch 'updates/align-template-enums-with-types' into 'development'

Use bchvmversions, lockingtypes and capabilities from the types package for schema validation

See merge request GeneralProtocols/xo/utils!9
This commit is contained in:
Kuldeep
2026-06-18 16:16:52 +00:00
3 changed files with 738 additions and 725 deletions

1445
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@xo-cash/utils",
"version": "0.0.1",
"version": "0.0.2",
"description": "XO Cash utilities",
"type": "module",
"types": "./dist/index.d.mts",
@@ -44,7 +44,7 @@
],
"dependencies": {
"@bitauth/libauth": "^3.1.0-next.8",
"@xo-cash/types": "0.0.1",
"@xo-cash/types": "0.0.2",
"zod": "^4.3.6"
},
"devDependencies": {

View File

@@ -1,4 +1,5 @@
/* eslint-disable @stylistic/newline-per-chained-call */
import { BchVmVersions, XOTemplateLockingTypes, XOTemplateNftCapabilities, XOTemplatePrimitiveTypes } from '@xo-cash/types';
import { z } from 'zod';
// ============================================================
@@ -9,9 +10,8 @@ import { z } from 'zod';
* Validation schema for a BCH VM version identifier. Defines the set of known BCH VM versions
* that XO templates declare support for.
*
* Zod's `z.enum` requires the exact values to be defined inline because it needs to know each
* specific value at compile time to validate against them. Defining the versions here directly
* satisfies that requirement and allows `z.array(bchVmVersionSchema)` to be used elsewhere
* Uses `BchVmVersions` from `@xo-cash/types` so template validation stays aligned with the
* `BchVmVersion` type.
*
* ```
* {
@@ -19,7 +19,7 @@ import { z } from 'zod';
* }
* ```
*/
export const bchVmVersionSchema = z.enum([ 'BCH_2020_05', 'BCH_2021_05', 'BCH_2022_05', 'BCH_2023_05', 'BCH_2024_05', 'BCH_2025_05', 'BCH_2026_05' ]);
export const bchVmVersionSchema = z.enum(BchVmVersions);
/**
* Validation schema for the capability of a non-fungible token. Defines the three capability
@@ -40,7 +40,7 @@ export const bchVmVersionSchema = z.enum([ 'BCH_2020_05', 'BCH_2021_05', 'BCH_20
* }
* ```
*/
export const xoTemplateNftCapabilitySchema = z.enum([ 'minting', 'mutable', 'none' ]);
export const xoTemplateNftCapabilitySchema = z.enum(XOTemplateNftCapabilities);
/**
* Validation schema for a BCH locking script type. Defines the standard locking script types
@@ -56,13 +56,13 @@ export const xoTemplateNftCapabilitySchema = z.enum([ 'minting', 'mutable', 'non
* }
* ```
*/
export const xoTemplateLockingTypeSchema = z.enum([ 'p2s', 'p2pkh', 'p2sh' ]);
export const xoTemplateLockingTypeSchema = z.enum(XOTemplateLockingTypes);
/**
* Validation schema for a primitive type identifier. Defines the set of primitive types
* that can be declared in an XO template. Used by constants, variables, and data fields.
*/
export const xoTemplatePrimitiveTypeSchema = z.enum([ 'boolean', 'bytes', 'integer', 'bigint', 'string', 'private_key', 'public_key' ]);
export const xoTemplatePrimitiveTypeSchema = z.enum(XOTemplatePrimitiveTypes);
// ============================================================
// Primitives