@xo-cash/utils 0.0.1 → 0.0.2-development.15414951647
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/dist/index.d.mts +104 -102
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +12 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { XOTemplate } from "@xo-cash/types";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { $ZodIssue } from "zod/v4/core";
|
|
3
|
-
import { XOTemplate } from "@xo-cash/types";
|
|
4
4
|
|
|
5
5
|
//#region source/extended-json.d.ts
|
|
6
6
|
/**
|
|
@@ -99,9 +99,8 @@ declare const parseTemplate: (inputTemplate: string | XOTemplate) => XOTemplate;
|
|
|
99
99
|
* Validation schema for a BCH VM version identifier. Defines the set of known BCH VM versions
|
|
100
100
|
* that XO templates declare support for.
|
|
101
101
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* satisfies that requirement and allows `z.array(bchVmVersionSchema)` to be used elsewhere
|
|
102
|
+
* Uses `BchVmVersions` from `@xo-cash/types` so template validation stays aligned with the
|
|
103
|
+
* `BchVmVersion` type.
|
|
105
104
|
*
|
|
106
105
|
* ```
|
|
107
106
|
* {
|
|
@@ -110,13 +109,13 @@ declare const parseTemplate: (inputTemplate: string | XOTemplate) => XOTemplate;
|
|
|
110
109
|
* ```
|
|
111
110
|
*/
|
|
112
111
|
declare const bchVmVersionSchema: z.ZodEnum<{
|
|
113
|
-
BCH_2020_05: "BCH_2020_05";
|
|
114
|
-
BCH_2021_05: "BCH_2021_05";
|
|
115
|
-
BCH_2022_05: "BCH_2022_05";
|
|
116
|
-
BCH_2023_05: "BCH_2023_05";
|
|
117
|
-
BCH_2024_05: "BCH_2024_05";
|
|
118
|
-
BCH_2025_05: "BCH_2025_05";
|
|
119
|
-
BCH_2026_05: "BCH_2026_05";
|
|
112
|
+
readonly BCH_2020_05: "BCH_2020_05";
|
|
113
|
+
readonly BCH_2021_05: "BCH_2021_05";
|
|
114
|
+
readonly BCH_2022_05: "BCH_2022_05";
|
|
115
|
+
readonly BCH_2023_05: "BCH_2023_05";
|
|
116
|
+
readonly BCH_2024_05: "BCH_2024_05";
|
|
117
|
+
readonly BCH_2025_05: "BCH_2025_05";
|
|
118
|
+
readonly BCH_2026_05: "BCH_2026_05";
|
|
120
119
|
}>;
|
|
121
120
|
/**
|
|
122
121
|
* Validation schema for the capability of a non-fungible token. Defines the three capability
|
|
@@ -138,9 +137,9 @@ declare const bchVmVersionSchema: z.ZodEnum<{
|
|
|
138
137
|
* ```
|
|
139
138
|
*/
|
|
140
139
|
declare const xoTemplateNftCapabilitySchema: z.ZodEnum<{
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
readonly NONE: "none";
|
|
141
|
+
readonly MUTABLE: "mutable";
|
|
142
|
+
readonly MINTING: "minting";
|
|
144
143
|
}>;
|
|
145
144
|
/**
|
|
146
145
|
* Validation schema for a BCH locking script type. Defines the standard locking script types
|
|
@@ -157,22 +156,22 @@ declare const xoTemplateNftCapabilitySchema: z.ZodEnum<{
|
|
|
157
156
|
* ```
|
|
158
157
|
*/
|
|
159
158
|
declare const xoTemplateLockingTypeSchema: z.ZodEnum<{
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
readonly P2S: "p2s";
|
|
160
|
+
readonly P2PKH: "p2pkh";
|
|
161
|
+
readonly P2SH: "p2sh";
|
|
163
162
|
}>;
|
|
164
163
|
/**
|
|
165
164
|
* Validation schema for a primitive type identifier. Defines the set of primitive types
|
|
166
165
|
* that can be declared in an XO template. Used by constants, variables, and data fields.
|
|
167
166
|
*/
|
|
168
167
|
declare const xoTemplatePrimitiveTypeSchema: z.ZodEnum<{
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
readonly BOOLEAN: "boolean";
|
|
169
|
+
readonly BYTES: "bytes";
|
|
170
|
+
readonly INTEGER: "integer";
|
|
171
|
+
readonly BIGINT: "bigint";
|
|
172
|
+
readonly STRING: "string";
|
|
173
|
+
readonly PRIVATE_KEY: "private_key";
|
|
174
|
+
readonly PUBLIC_KEY: "public_key";
|
|
176
175
|
}>;
|
|
177
176
|
/**
|
|
178
177
|
* Validation schema for byte array fields i.e. Uint8Array instance.
|
|
@@ -183,11 +182,11 @@ declare const uint8ArraySchema: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<
|
|
|
183
182
|
*/
|
|
184
183
|
declare const satoshisSchema: z.ZodBigInt;
|
|
185
184
|
/** Maximum character length for name fields on view properties. */
|
|
186
|
-
declare const VIEW_PROPERTIES_NAME_MAX_LENGTH =
|
|
185
|
+
declare const VIEW_PROPERTIES_NAME_MAX_LENGTH = 1000;
|
|
187
186
|
/** Maximum character length for description fields on view properties. */
|
|
188
187
|
declare const VIEW_PROPERTIES_DESCRIPTION_MAX_LENGTH = 5000;
|
|
189
188
|
/** Maximum character length for icon fields on view properties. */
|
|
190
|
-
declare const VIEW_PROPERTIES_ICON_MAX_LENGTH =
|
|
189
|
+
declare const VIEW_PROPERTIES_ICON_MAX_LENGTH = 1000;
|
|
191
190
|
/**
|
|
192
191
|
* Validation schema for view properties shared across many template elements i.e. name, description, icon.
|
|
193
192
|
* Extended by most other schemas in this file.
|
|
@@ -388,13 +387,14 @@ declare const xoTemplateRoleSlotSchema: z.ZodObject<{
|
|
|
388
387
|
* {
|
|
389
388
|
* "actions": {
|
|
390
389
|
* "[id]": {
|
|
391
|
-
* "requirements": { "participants": [], "secrets": [] } ← this schema
|
|
390
|
+
* "requirements": { "variables": [], "participants": [], "secrets": [] } ← this schema
|
|
392
391
|
* }
|
|
393
392
|
* }
|
|
394
393
|
* }
|
|
395
394
|
* ```
|
|
396
395
|
*/
|
|
397
396
|
declare const xoTemplateActionRequirementsSchema: z.ZodObject<{
|
|
397
|
+
variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
398
398
|
participants: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
399
399
|
role: z.ZodString;
|
|
400
400
|
slots: z.ZodObject<{
|
|
@@ -430,6 +430,7 @@ declare const xoTemplateActionSchema: z.ZodObject<{
|
|
|
430
430
|
}, z.core.$strict>>;
|
|
431
431
|
}, z.core.$strict>>>;
|
|
432
432
|
requirements: z.ZodOptional<z.ZodObject<{
|
|
433
|
+
variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
433
434
|
participants: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
434
435
|
role: z.ZodString;
|
|
435
436
|
slots: z.ZodObject<{
|
|
@@ -460,9 +461,9 @@ declare const xoTemplateActionSchema: z.ZodObject<{
|
|
|
460
461
|
*/
|
|
461
462
|
declare const xoTemplateNonFungibleTokenDetailsSchema: z.ZodObject<{
|
|
462
463
|
capability: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
464
|
+
readonly NONE: "none";
|
|
465
|
+
readonly MUTABLE: "mutable";
|
|
466
|
+
readonly MINTING: "minting";
|
|
466
467
|
}>, z.ZodString]>>;
|
|
467
468
|
commitment: z.ZodOptional<z.ZodString>;
|
|
468
469
|
}, z.core.$strict>;
|
|
@@ -484,9 +485,9 @@ declare const xoTemplateTokenSchema: z.ZodObject<{
|
|
|
484
485
|
amount: z.ZodOptional<z.ZodUnion<readonly [z.ZodBigInt, z.ZodString, z.ZodNull]>>;
|
|
485
486
|
nft: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
486
487
|
capability: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
488
|
+
readonly NONE: "none";
|
|
489
|
+
readonly MUTABLE: "mutable";
|
|
490
|
+
readonly MINTING: "minting";
|
|
490
491
|
}>, z.ZodString]>>;
|
|
491
492
|
commitment: z.ZodOptional<z.ZodString>;
|
|
492
493
|
}, z.core.$strict>>>;
|
|
@@ -579,9 +580,9 @@ declare const xoTemplateLockingScriptSchema: z.ZodObject<{
|
|
|
579
580
|
description: z.ZodString;
|
|
580
581
|
icon: z.ZodOptional<z.ZodString>;
|
|
581
582
|
lockingType: z.ZodOptional<z.ZodEnum<{
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
583
|
+
readonly P2S: "p2s";
|
|
584
|
+
readonly P2PKH: "p2pkh";
|
|
585
|
+
readonly P2SH: "p2sh";
|
|
585
586
|
}>>;
|
|
586
587
|
lockingBytecode: z.ZodString;
|
|
587
588
|
unlockingBytecode: z.ZodOptional<z.ZodString>;
|
|
@@ -653,9 +654,9 @@ declare const xoTemplateInputSchema: z.ZodObject<{
|
|
|
653
654
|
amount: z.ZodOptional<z.ZodUnion<readonly [z.ZodBigInt, z.ZodString, z.ZodNull]>>;
|
|
654
655
|
nft: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
655
656
|
capability: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
657
|
+
readonly NONE: "none";
|
|
658
|
+
readonly MUTABLE: "mutable";
|
|
659
|
+
readonly MINTING: "minting";
|
|
659
660
|
}>, z.ZodString]>>;
|
|
660
661
|
commitment: z.ZodOptional<z.ZodString>;
|
|
661
662
|
}, z.core.$strict>>>;
|
|
@@ -736,9 +737,9 @@ declare const xoTemplateOutputSchema: z.ZodObject<{
|
|
|
736
737
|
amount: z.ZodOptional<z.ZodUnion<readonly [z.ZodBigInt, z.ZodString, z.ZodNull]>>;
|
|
737
738
|
nft: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
738
739
|
capability: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
740
|
+
readonly NONE: "none";
|
|
741
|
+
readonly MUTABLE: "mutable";
|
|
742
|
+
readonly MINTING: "minting";
|
|
742
743
|
}>, z.ZodString]>>;
|
|
743
744
|
commitment: z.ZodOptional<z.ZodString>;
|
|
744
745
|
}, z.core.$strict>>>;
|
|
@@ -826,7 +827,7 @@ declare const xoTemplateTransactionSchema: z.ZodObject<{
|
|
|
826
827
|
description: z.ZodString;
|
|
827
828
|
icon: z.ZodOptional<z.ZodString>;
|
|
828
829
|
version: z.ZodOptional<z.ZodNumber>;
|
|
829
|
-
locktime: z.ZodOptional<z.ZodNumber
|
|
830
|
+
locktime: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
830
831
|
inputs: z.ZodArray<z.ZodObject<{
|
|
831
832
|
input: z.ZodString;
|
|
832
833
|
inputIndex: z.ZodOptional<z.ZodNumber>;
|
|
@@ -866,13 +867,13 @@ declare const xoTemplateConstantSchema: z.ZodObject<{
|
|
|
866
867
|
description: z.ZodString;
|
|
867
868
|
icon: z.ZodOptional<z.ZodString>;
|
|
868
869
|
type: z.ZodEnum<{
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
870
|
+
readonly BOOLEAN: "boolean";
|
|
871
|
+
readonly BYTES: "bytes";
|
|
872
|
+
readonly INTEGER: "integer";
|
|
873
|
+
readonly BIGINT: "bigint";
|
|
874
|
+
readonly STRING: "string";
|
|
875
|
+
readonly PRIVATE_KEY: "private_key";
|
|
876
|
+
readonly PUBLIC_KEY: "public_key";
|
|
876
877
|
}>;
|
|
877
878
|
value: z.ZodUnknown;
|
|
878
879
|
hint: z.ZodOptional<z.ZodString>;
|
|
@@ -890,13 +891,13 @@ declare const xoTemplateConstantSchema: z.ZodObject<{
|
|
|
890
891
|
*/
|
|
891
892
|
declare const xoTemplateDataSchema: z.ZodObject<{
|
|
892
893
|
type: z.ZodEnum<{
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
894
|
+
readonly BOOLEAN: "boolean";
|
|
895
|
+
readonly BYTES: "bytes";
|
|
896
|
+
readonly INTEGER: "integer";
|
|
897
|
+
readonly BIGINT: "bigint";
|
|
898
|
+
readonly STRING: "string";
|
|
899
|
+
readonly PRIVATE_KEY: "private_key";
|
|
900
|
+
readonly PUBLIC_KEY: "public_key";
|
|
900
901
|
}>;
|
|
901
902
|
value: z.ZodUnknown;
|
|
902
903
|
hint: z.ZodOptional<z.ZodString>;
|
|
@@ -942,13 +943,13 @@ declare const xoTemplateVariableSchema: z.ZodObject<{
|
|
|
942
943
|
description: z.ZodString;
|
|
943
944
|
icon: z.ZodOptional<z.ZodString>;
|
|
944
945
|
type: z.ZodOptional<z.ZodEnum<{
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
946
|
+
readonly BOOLEAN: "boolean";
|
|
947
|
+
readonly BYTES: "bytes";
|
|
948
|
+
readonly INTEGER: "integer";
|
|
949
|
+
readonly BIGINT: "bigint";
|
|
950
|
+
readonly STRING: "string";
|
|
951
|
+
readonly PRIVATE_KEY: "private_key";
|
|
952
|
+
readonly PUBLIC_KEY: "public_key";
|
|
952
953
|
}>>;
|
|
953
954
|
hint: z.ZodOptional<z.ZodString>;
|
|
954
955
|
importDefaultValue: z.ZodOptional<z.ZodObject<{
|
|
@@ -1026,13 +1027,13 @@ declare const xoTemplateSchema: z.ZodObject<{
|
|
|
1026
1027
|
$schema: z.ZodString;
|
|
1027
1028
|
version: z.ZodOptional<z.ZodString>;
|
|
1028
1029
|
supported: z.ZodArray<z.ZodEnum<{
|
|
1029
|
-
BCH_2020_05: "BCH_2020_05";
|
|
1030
|
-
BCH_2021_05: "BCH_2021_05";
|
|
1031
|
-
BCH_2022_05: "BCH_2022_05";
|
|
1032
|
-
BCH_2023_05: "BCH_2023_05";
|
|
1033
|
-
BCH_2024_05: "BCH_2024_05";
|
|
1034
|
-
BCH_2025_05: "BCH_2025_05";
|
|
1035
|
-
BCH_2026_05: "BCH_2026_05";
|
|
1030
|
+
readonly BCH_2020_05: "BCH_2020_05";
|
|
1031
|
+
readonly BCH_2021_05: "BCH_2021_05";
|
|
1032
|
+
readonly BCH_2022_05: "BCH_2022_05";
|
|
1033
|
+
readonly BCH_2023_05: "BCH_2023_05";
|
|
1034
|
+
readonly BCH_2024_05: "BCH_2024_05";
|
|
1035
|
+
readonly BCH_2025_05: "BCH_2025_05";
|
|
1036
|
+
readonly BCH_2026_05: "BCH_2026_05";
|
|
1036
1037
|
}>>;
|
|
1037
1038
|
defaults: z.ZodOptional<z.ZodObject<{
|
|
1038
1039
|
change: z.ZodOptional<z.ZodObject<{
|
|
@@ -1074,6 +1075,7 @@ declare const xoTemplateSchema: z.ZodObject<{
|
|
|
1074
1075
|
}, z.core.$strict>>;
|
|
1075
1076
|
}, z.core.$strict>>>;
|
|
1076
1077
|
requirements: z.ZodOptional<z.ZodObject<{
|
|
1078
|
+
variables: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1077
1079
|
participants: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1078
1080
|
role: z.ZodString;
|
|
1079
1081
|
slots: z.ZodObject<{
|
|
@@ -1089,13 +1091,13 @@ declare const xoTemplateSchema: z.ZodObject<{
|
|
|
1089
1091
|
}, z.core.$strict>>;
|
|
1090
1092
|
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
1091
1093
|
type: z.ZodEnum<{
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1094
|
+
readonly BOOLEAN: "boolean";
|
|
1095
|
+
readonly BYTES: "bytes";
|
|
1096
|
+
readonly INTEGER: "integer";
|
|
1097
|
+
readonly BIGINT: "bigint";
|
|
1098
|
+
readonly STRING: "string";
|
|
1099
|
+
readonly PRIVATE_KEY: "private_key";
|
|
1100
|
+
readonly PUBLIC_KEY: "public_key";
|
|
1099
1101
|
}>;
|
|
1100
1102
|
value: z.ZodUnknown;
|
|
1101
1103
|
hint: z.ZodOptional<z.ZodString>;
|
|
@@ -1105,7 +1107,7 @@ declare const xoTemplateSchema: z.ZodObject<{
|
|
|
1105
1107
|
description: z.ZodString;
|
|
1106
1108
|
icon: z.ZodOptional<z.ZodString>;
|
|
1107
1109
|
version: z.ZodOptional<z.ZodNumber>;
|
|
1108
|
-
locktime: z.ZodOptional<z.ZodNumber
|
|
1110
|
+
locktime: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
1109
1111
|
inputs: z.ZodArray<z.ZodObject<{
|
|
1110
1112
|
input: z.ZodString;
|
|
1111
1113
|
inputIndex: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1139,9 +1141,9 @@ declare const xoTemplateSchema: z.ZodObject<{
|
|
|
1139
1141
|
amount: z.ZodOptional<z.ZodUnion<readonly [z.ZodBigInt, z.ZodString, z.ZodNull]>>;
|
|
1140
1142
|
nft: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
1141
1143
|
capability: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1144
|
+
readonly NONE: "none";
|
|
1145
|
+
readonly MUTABLE: "mutable";
|
|
1146
|
+
readonly MINTING: "minting";
|
|
1145
1147
|
}>, z.ZodString]>>;
|
|
1146
1148
|
commitment: z.ZodOptional<z.ZodString>;
|
|
1147
1149
|
}, z.core.$strict>>>;
|
|
@@ -1210,9 +1212,9 @@ declare const xoTemplateSchema: z.ZodObject<{
|
|
|
1210
1212
|
amount: z.ZodOptional<z.ZodUnion<readonly [z.ZodBigInt, z.ZodString, z.ZodNull]>>;
|
|
1211
1213
|
nft: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
1212
1214
|
capability: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1215
|
+
readonly NONE: "none";
|
|
1216
|
+
readonly MUTABLE: "mutable";
|
|
1217
|
+
readonly MINTING: "minting";
|
|
1216
1218
|
}>, z.ZodString]>>;
|
|
1217
1219
|
commitment: z.ZodOptional<z.ZodString>;
|
|
1218
1220
|
}, z.core.$strict>>>;
|
|
@@ -1223,9 +1225,9 @@ declare const xoTemplateSchema: z.ZodObject<{
|
|
|
1223
1225
|
description: z.ZodString;
|
|
1224
1226
|
icon: z.ZodOptional<z.ZodString>;
|
|
1225
1227
|
lockingType: z.ZodOptional<z.ZodEnum<{
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1228
|
+
readonly P2S: "p2s";
|
|
1229
|
+
readonly P2PKH: "p2pkh";
|
|
1230
|
+
readonly P2SH: "p2sh";
|
|
1229
1231
|
}>>;
|
|
1230
1232
|
lockingBytecode: z.ZodString;
|
|
1231
1233
|
unlockingBytecode: z.ZodOptional<z.ZodString>;
|
|
@@ -1281,13 +1283,13 @@ declare const xoTemplateSchema: z.ZodObject<{
|
|
|
1281
1283
|
description: z.ZodString;
|
|
1282
1284
|
icon: z.ZodOptional<z.ZodString>;
|
|
1283
1285
|
type: z.ZodEnum<{
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1286
|
+
readonly BOOLEAN: "boolean";
|
|
1287
|
+
readonly BYTES: "bytes";
|
|
1288
|
+
readonly INTEGER: "integer";
|
|
1289
|
+
readonly BIGINT: "bigint";
|
|
1290
|
+
readonly STRING: "string";
|
|
1291
|
+
readonly PRIVATE_KEY: "private_key";
|
|
1292
|
+
readonly PUBLIC_KEY: "public_key";
|
|
1291
1293
|
}>;
|
|
1292
1294
|
value: z.ZodUnknown;
|
|
1293
1295
|
hint: z.ZodOptional<z.ZodString>;
|
|
@@ -1297,13 +1299,13 @@ declare const xoTemplateSchema: z.ZodObject<{
|
|
|
1297
1299
|
description: z.ZodString;
|
|
1298
1300
|
icon: z.ZodOptional<z.ZodString>;
|
|
1299
1301
|
type: z.ZodOptional<z.ZodEnum<{
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1302
|
+
readonly BOOLEAN: "boolean";
|
|
1303
|
+
readonly BYTES: "bytes";
|
|
1304
|
+
readonly INTEGER: "integer";
|
|
1305
|
+
readonly BIGINT: "bigint";
|
|
1306
|
+
readonly STRING: "string";
|
|
1307
|
+
readonly PRIVATE_KEY: "private_key";
|
|
1308
|
+
readonly PUBLIC_KEY: "public_key";
|
|
1307
1309
|
}>>;
|
|
1308
1310
|
hint: z.ZodOptional<z.ZodString>;
|
|
1309
1311
|
importDefaultValue: z.ZodOptional<z.ZodObject<{
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../source/extended-json.ts","../source/script.ts","../source/template/errors.ts","../source/template/identifier.ts","../source/template/parser.ts","../source/template/schemas.ts","../source/template/serialization.ts"],"mappings":";;;;;;;;;;AA8BA;;;;;AAqBA;;;;;;;;cArBa,oBAAA,GAAwB,YAAA,UAAsB,KAAA;;;;;;;;AEnB3D;;cFwCa,mBAAA,GAAuB,YAAA,UAAsB,KAAA;;;;;;;;cC5C7C,kBAAA,GAAsB,MAAA,EAAQ,UAAA;;;;;;;ADuB3C;;;cEnBa,qBAAA,GAAyB,MAAA,EAAQ,SAAA;;AFwC9C;;cEda,oBAAA,SAA6B,KAAA;cAC1B,OAAA;AAAA;;;;cAUH,0BAAA,SAAmC,KAAA;cAChC,MAAA;AAAA;;;;cASH,gCAAA,SAAyC,KAAA;cACtC,MAAA;AAAA;;;;;;;AF7BhB;;;;cGlBa,0BAAA,GAA8B,QAAA,EAAU,UAAA;;;;;;;AHkBrD;;;;;AAqBA;;cInCa,aAAA,GAAiB,aAAA,WAAwB,UAAA,KAAa,UAAA;;;;;;;AJcnE;;;;;AAqBA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../source/extended-json.ts","../source/script.ts","../source/template/errors.ts","../source/template/identifier.ts","../source/template/parser.ts","../source/template/schemas.ts","../source/template/serialization.ts"],"mappings":";;;;;;;;;;AA8BA;;;;;AAqBA;;;;;;;;cArBa,oBAAA,GAAwB,YAAA,UAAsB,KAAA;;;;;;;;AEnB3D;;cFwCa,mBAAA,GAAuB,YAAA,UAAsB,KAAA;;;;;;;;cC5C7C,kBAAA,GAAsB,MAAA,EAAQ,UAAA;;;;;;;ADuB3C;;;cEnBa,qBAAA,GAAyB,MAAA,EAAQ,SAAA;;AFwC9C;;cEda,oBAAA,SAA6B,KAAA;cAC1B,OAAA;AAAA;;;;cAUH,0BAAA,SAAmC,KAAA;cAChC,MAAA;AAAA;;;;cASH,gCAAA,SAAyC,KAAA;cACtC,MAAA;AAAA;;;;;;;AF7BhB;;;;cGlBa,0BAAA,GAA8B,QAAA,EAAU,UAAA;;;;;;;AHkBrD;;;;;AAqBA;;cInCa,aAAA,GAAiB,aAAA,WAAwB,UAAA,KAAa,UAAA;;;;;;;AJcnE;;;;;AAqBA;;;;cK9Ba,kBAAA,EAAkB,CAAA,CAAA,OAAA;EAAA;;;;;;;;;;;AHV/B;;;;;AA0BA;;;;;;;;;AAWA;;cGNa,6BAAA,EAA6B,CAAA,CAAA,OAAA;EAAA;;;;;;AHgB1C;;;;;;;;;;;;cGAa,2BAAA,EAA2B,CAAA,CAAA,OAAA;EAAA;;;;;;;AD1CxC;cCgDa,6BAAA,EAA6B,CAAA,CAAA,OAAA;EAAA;;;;;;;;;;AA3C1C;cAoDa,gBAAA,EAAgB,CAAA,CAAA,SAAA,CAAA,UAAA,CAAA,WAAA,GAAA,UAAA,CAAA,WAAA;;;;cAKhB,cAAA,EAAc,CAAA,CAAA,SAAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ALx0B7B;;;;cMlBa,iBAAA,GAAqB,QAAA,EAAU,UAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { binToHex, hexToBin, sha256, utf8ToBin } from "@bitauth/libauth";
|
|
2
|
+
import { BchVmVersions, XOTemplateLockingTypes, XOTemplateNftCapabilities, XOTemplatePrimitiveTypes } from "@xo-cash/types";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
|
|
4
5
|
//#region source/extended-json.ts
|
|
@@ -163,9 +164,8 @@ const generateTemplateIdentifier = (template) => {
|
|
|
163
164
|
* Validation schema for a BCH VM version identifier. Defines the set of known BCH VM versions
|
|
164
165
|
* that XO templates declare support for.
|
|
165
166
|
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* satisfies that requirement and allows `z.array(bchVmVersionSchema)` to be used elsewhere
|
|
167
|
+
* Uses `BchVmVersions` from `@xo-cash/types` so template validation stays aligned with the
|
|
168
|
+
* `BchVmVersion` type.
|
|
169
169
|
*
|
|
170
170
|
* ```
|
|
171
171
|
* {
|
|
@@ -173,15 +173,7 @@ const generateTemplateIdentifier = (template) => {
|
|
|
173
173
|
* }
|
|
174
174
|
* ```
|
|
175
175
|
*/
|
|
176
|
-
const bchVmVersionSchema = z.enum(
|
|
177
|
-
"BCH_2020_05",
|
|
178
|
-
"BCH_2021_05",
|
|
179
|
-
"BCH_2022_05",
|
|
180
|
-
"BCH_2023_05",
|
|
181
|
-
"BCH_2024_05",
|
|
182
|
-
"BCH_2025_05",
|
|
183
|
-
"BCH_2026_05"
|
|
184
|
-
]);
|
|
176
|
+
const bchVmVersionSchema = z.enum(BchVmVersions);
|
|
185
177
|
/**
|
|
186
178
|
* Validation schema for the capability of a non-fungible token. Defines the three capability
|
|
187
179
|
* types supported on BCH: minting tokens can create new NFTs, mutable tokens can update their
|
|
@@ -201,11 +193,7 @@ const bchVmVersionSchema = z.enum([
|
|
|
201
193
|
* }
|
|
202
194
|
* ```
|
|
203
195
|
*/
|
|
204
|
-
const xoTemplateNftCapabilitySchema = z.enum(
|
|
205
|
-
"minting",
|
|
206
|
-
"mutable",
|
|
207
|
-
"none"
|
|
208
|
-
]);
|
|
196
|
+
const xoTemplateNftCapabilitySchema = z.enum(XOTemplateNftCapabilities);
|
|
209
197
|
/**
|
|
210
198
|
* Validation schema for a BCH locking script type. Defines the standard locking script types
|
|
211
199
|
* supported on BCH.
|
|
@@ -220,24 +208,12 @@ const xoTemplateNftCapabilitySchema = z.enum([
|
|
|
220
208
|
* }
|
|
221
209
|
* ```
|
|
222
210
|
*/
|
|
223
|
-
const xoTemplateLockingTypeSchema = z.enum(
|
|
224
|
-
"p2s",
|
|
225
|
-
"p2pkh",
|
|
226
|
-
"p2sh"
|
|
227
|
-
]);
|
|
211
|
+
const xoTemplateLockingTypeSchema = z.enum(XOTemplateLockingTypes);
|
|
228
212
|
/**
|
|
229
213
|
* Validation schema for a primitive type identifier. Defines the set of primitive types
|
|
230
214
|
* that can be declared in an XO template. Used by constants, variables, and data fields.
|
|
231
215
|
*/
|
|
232
|
-
const xoTemplatePrimitiveTypeSchema = z.enum(
|
|
233
|
-
"boolean",
|
|
234
|
-
"bytes",
|
|
235
|
-
"integer",
|
|
236
|
-
"bigint",
|
|
237
|
-
"string",
|
|
238
|
-
"private_key",
|
|
239
|
-
"public_key"
|
|
240
|
-
]);
|
|
216
|
+
const xoTemplatePrimitiveTypeSchema = z.enum(XOTemplatePrimitiveTypes);
|
|
241
217
|
/**
|
|
242
218
|
* Validation schema for byte array fields i.e. Uint8Array instance.
|
|
243
219
|
*/
|
|
@@ -247,11 +223,11 @@ const uint8ArraySchema = z.instanceof(Uint8Array).describe("A sequence of unsign
|
|
|
247
223
|
*/
|
|
248
224
|
const satoshisSchema = z.bigint().describe("A satoshi amount expressed as a bigint.");
|
|
249
225
|
/** Maximum character length for name fields on view properties. */
|
|
250
|
-
const VIEW_PROPERTIES_NAME_MAX_LENGTH =
|
|
226
|
+
const VIEW_PROPERTIES_NAME_MAX_LENGTH = 1e3;
|
|
251
227
|
/** Maximum character length for description fields on view properties. */
|
|
252
228
|
const VIEW_PROPERTIES_DESCRIPTION_MAX_LENGTH = 5e3;
|
|
253
229
|
/** Maximum character length for icon fields on view properties. */
|
|
254
|
-
const VIEW_PROPERTIES_ICON_MAX_LENGTH =
|
|
230
|
+
const VIEW_PROPERTIES_ICON_MAX_LENGTH = 1e3;
|
|
255
231
|
/**
|
|
256
232
|
* Validation schema for view properties shared across many template elements i.e. name, description, icon.
|
|
257
233
|
* Extended by most other schemas in this file.
|
|
@@ -419,13 +395,14 @@ const xoTemplateRoleSlotSchema = z.object({
|
|
|
419
395
|
* {
|
|
420
396
|
* "actions": {
|
|
421
397
|
* "[id]": {
|
|
422
|
-
* "requirements": { "participants": [], "secrets": [] } ← this schema
|
|
398
|
+
* "requirements": { "variables": [], "participants": [], "secrets": [] } ← this schema
|
|
423
399
|
* }
|
|
424
400
|
* }
|
|
425
401
|
* }
|
|
426
402
|
* ```
|
|
427
403
|
*/
|
|
428
404
|
const xoTemplateActionRequirementsSchema = z.object({
|
|
405
|
+
variables: z.array(z.string()).optional().describe("List of variable identifiers required for this action."),
|
|
429
406
|
participants: z.array(xoTemplateRoleSlotSchema).optional().describe("The participants required for this action."),
|
|
430
407
|
secrets: z.array(z.string()).optional().describe("The secrets required for this action.")
|
|
431
408
|
}).strict();
|
|
@@ -687,7 +664,7 @@ const xoTemplateTransactionRoleDataSchema = xoTemplateViewPropertiesSchema.parti
|
|
|
687
664
|
*/
|
|
688
665
|
const xoTemplateTransactionSchema = xoTemplateViewPropertiesSchema.extend({
|
|
689
666
|
version: z.number().optional().describe("The version of the transaction."),
|
|
690
|
-
locktime: z.number().optional().describe("The locktime for this transaction."),
|
|
667
|
+
locktime: z.union([z.number(), z.string()]).optional().describe("The locktime for this transaction as a specific number or a CashASM expression."),
|
|
691
668
|
inputs: z.array(xoTemplateTransactionInputSchema).describe("The inputs for this transaction."),
|
|
692
669
|
outputs: z.array(xoTemplateTransactionOutputSchema).describe("The outputs for this transaction."),
|
|
693
670
|
roles: z.record(z.string(), xoTemplateTransactionRoleDataSchema).optional().describe("Specific context for each role participating in this transaction."),
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../source/extended-json.ts","../source/script.ts","../source/template/errors.ts","../source/template/serialization.ts","../source/template/identifier.ts","../source/template/schemas.ts","../source/template/parser.ts"],"sourcesContent":["import { binToHex, hexToBin } from '@bitauth/libauth';\n\n/**\n * Matches a bigint encoded in Extended JSON format: `<bigint: 123n>`.\n */\nconst EXTENDED_JSON_BIGINT_PATTERN = /^<bigint: (?<bigint>[+-]?[0-9]+)n>$/u;\n\n/**\n * Matches a Uint8Array encoded in Extended JSON format: `<uint8array: abcd>`.\n */\nconst EXTENDED_JSON_UINT8ARRAY_PATTERN = /^<uint8array: (?<hex>[0-9a-f]*)>$/u;\n\n/**\n * The JSON replacer that encodes `bigint` and `Uint8Array` values in Extended JSON format,\n * compatible with the format expected by `extendedJsonReviver`.\n *\n * - BigInts are encoded as `<bigint: 123n>`.\n * - Uint8Arrays are encoded as `<uint8array: abcd>`.\n * All other values pass through unchanged and if any incompatible type is encountered, an error is thrown.\n *\n * Note: To use this function, pass it as the second argument to `JSON.stringify` when serializing data.\n *\n * Note to developers: Libauth's `stringify` is the replacer. It also serializes functions and symbols,\n * which we do not support. Passing it would let templates include those values, but revival would then fail.\n * This module provides a dedicated replacer and reviver so serialization and deserialization stay aligned.\n *\n * @param _propertyKey The property key being serialized, required by the `JSON.stringify` replacer but not used here.\n * @param value The value to encode or pass through unchanged.\n * @returns The encoded string\n */\nexport const extendedJsonReplacer = (_propertyKey: string, value: unknown): unknown => {\n if (value instanceof Uint8Array) {\n return `<uint8array: ${binToHex(value)}>`;\n }\n\n if (typeof value === 'bigint') {\n return `<bigint: ${value.toString()}n>`;\n }\n\n return value;\n};\n\n/**\n * The JSON reviver that reconstructs `bigint` and `Uint8Array` values encoded by `extendedJsonReplacer`.\n *\n * Note: To use this function, pass it as the second argument to `JSON.parse` when deserializing data.\n *\n * @param _propertyKey The property key being deserialized, required by the `JSON.parse` reviver but not used here.\n * @param value The value to reconstruct or pass through unchanged.\n * @returns The reconstructed value\n */\nexport const extendedJsonReviver = (_propertyKey: string, value: unknown): unknown => {\n // If the value is not a string, return the original value\n if (typeof value !== 'string') {\n return value;\n }\n\n // Match the bigint pattern\n const bigintPatternMatch = value.match(EXTENDED_JSON_BIGINT_PATTERN);\n\n // If the value matches the bigint pattern, return the reconstructed bigint\n if (bigintPatternMatch) {\n return BigInt(bigintPatternMatch.groups!.bigint);\n }\n\n // Match the Uint8Array pattern\n const uint8arrayPatternMatch = value.match(EXTENDED_JSON_UINT8ARRAY_PATTERN);\n\n // If the value matches the Uint8Array pattern, return the reconstructed Uint8Array\n if (uint8arrayPatternMatch) {\n return hexToBin(uint8arrayPatternMatch.groups!.hex);\n }\n\n // If the value does not match either pattern, return the original value\n return value;\n};\n","import { binToHex, sha256 } from '@bitauth/libauth';\n\n/**\n * Converts a script to a scriptHash.\n * @param {Uint8Array} script - The script to convert.\n * @returns {string} The scriptHash as a reversed hex string.\n */\nexport const scriptToScriptHash = (script: Uint8Array): string => {\n // Hash the script.\n const hash = sha256.hash(script);\n\n // Reverse the hash. (Electrum style, reverse switches to little endian representation)\n const reversed = hash.reverse();\n\n // Convert the reversed hash to hex.\n return binToHex(reversed);\n};\n","/* eslint-disable max-classes-per-file */\n\nimport type { $ZodIssue } from 'zod/v4/core';\n\n/**\n * Formats the Zod validation failures into a single string with one line each: \"- <field>: <message>\" and top level failures\n * with no field path show as \"(root)\" for better readability.\n *\n * @param issues The Zod validation failures to format.\n * @returns A human readable error string for better debugging.\n */\nexport const buildErrorDescription = (issues: $ZodIssue[]): string => {\n // Initialize an empty array to store the formatted lines.\n const lines: string[] = [];\n\n // Iterate over the issues and format them into a string.\n for (const issue of issues) {\n // Get the issue path.\n const issuePath = issue.path.length > 0 ? issue.path.join('.') : '(root)';\n\n // The prefix that Zod adds to messages.\n const messagePrefix = 'Invalid input: ';\n\n // Remove the prefix for better readability.\n const issueMessage = issue.message.startsWith(messagePrefix) ? issue.message.slice(messagePrefix.length) : issue.message;\n\n // Add the formatted line to the array.\n lines.push(`- ${issuePath}: ${issueMessage}`);\n }\n\n // Return the formatted string.\n return `\\n${lines.join('\\n')}`;\n};\n\n/**\n * Thrown when the provided template does not satisfy the XOTemplate schema.\n */\nexport class TemplateInvalidError extends Error {\n constructor(details: string) {\n const message = `Template invalid: ${details}`;\n super(message);\n this.name = 'TemplateInvalidError';\n }\n}\n\n/**\n * Thrown when a string passed to `deserializeTemplate` cannot be parsed as JSON.\n */\nexport class TemplateJsonMalformedError extends Error {\n constructor(reason: string) {\n super(`Template JSON malformed, expected a valid JSON string: ${reason}`);\n this.name = 'TemplateJsonMalformedError';\n }\n}\n\n/**\n * Thrown when `serializeTemplate` fails to produce a JSON string from the template.\n */\nexport class TemplateSerializationFailedError extends Error {\n constructor(reason: string) {\n super(`Template serialization failed: ${reason}`);\n this.name = 'TemplateSerializationFailedError';\n }\n}\n","import type { XOTemplate } from '@xo-cash/types';\nimport { extendedJsonReplacer, extendedJsonReviver } from '../extended-json.ts';\nimport { TemplateJsonMalformedError, TemplateSerializationFailedError } from './errors.ts';\n\n/**\n * Serializes an XOTemplate to a JSON string. Encodes `bigint` and `Uint8Array` fields in\n * Extended JSON format so they can be reconstructed by `deserializeTemplate`.\n *\n * @param template The template to serialize.\n * @returns A JSON string representation of the template.\n * @throws {TemplateSerializationFailedError} If the template cannot be serialized to JSON.\n */\nexport const serializeTemplate = (template: XOTemplate): string => {\n try {\n // Serialize the template to a JSON string.\n return JSON.stringify(template, extendedJsonReplacer);\n } catch (serializationError) {\n const reason = serializationError instanceof Error ? serializationError.message : 'unknown error while serializing template';\n\n throw new TemplateSerializationFailedError(reason);\n }\n};\n\n/**\n * Deserializes a JSON string back into an XOTemplate object. Restores `bigint` and\n * `Uint8Array` fields encoded in Extended JSON format by `serializeTemplate`.\n *\n * @param serializedTemplate - A JSON string of an XOTemplate object.\n * @returns The reconstructed XOTemplate object.\n * @throws {TemplateJsonMalformedError} If the serialized template is not valid JSON.\n */\nexport const deserializeTemplate = (serializedTemplate: string): XOTemplate => {\n try {\n // Parse the serialized template using the extended JSON reviver.\n return JSON.parse(serializedTemplate, extendedJsonReviver);\n } catch (parsingError) {\n const reason = parsingError instanceof Error ? parsingError.message : 'unknown error while deserializing template';\n\n throw new TemplateJsonMalformedError(reason);\n }\n};\n","import { binToHex, sha256, utf8ToBin } from '@bitauth/libauth';\nimport type { XOTemplate } from '@xo-cash/types';\nimport { serializeTemplate } from './serialization.ts';\n\n/**\n * Generates a deterministic template identifier by hashing the template.\n *\n * Note: This expects a template that has been validated by `parseTemplate`.\n *\n * @param template - The template to generate an identifier for.\n * @returns The sha256 hex identifier for the template.\n */\nexport const generateTemplateIdentifier = (template: XOTemplate): string => {\n // Serialize the template.\n const serializedTemplate = serializeTemplate(template);\n\n // Hash the serialized template.\n const hash = sha256.hash(utf8ToBin(serializedTemplate));\n\n // Convert the hash to hex and return it.\n return binToHex(hash);\n};\n","/* eslint-disable @stylistic/newline-per-chained-call */\nimport { z } from 'zod';\n\n// ============================================================\n// Enums\n// ============================================================\n\n/**\n * Validation schema for a BCH VM version identifier. Defines the set of known BCH VM versions\n * that XO templates declare support for.\n *\n * Zod's `z.enum` requires the exact values to be defined inline because it needs to know each\n * specific value at compile time to validate against them. Defining the versions here directly\n * satisfies that requirement and allows `z.array(bchVmVersionSchema)` to be used elsewhere\n *\n * ```\n * {\n * \"supported\": [ \"BCH_2025_05\" ] ← each value\n * }\n * ```\n */\nexport 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' ]);\n\n/**\n * Validation schema for the capability of a non-fungible token. Defines the three capability\n * types supported on BCH: minting tokens can create new NFTs, mutable tokens can update their\n * commitment, and none tokens cannot be changed after creation.\n *\n * ```\n * {\n * \"inputs|outputs\": {\n * \"[id]\": {\n * \"token\": {\n * \"nft\": {\n * \"capability\": \"minting\" ← this schema\n * }\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateNftCapabilitySchema = z.enum([ 'minting', 'mutable', 'none' ]);\n\n/**\n * Validation schema for a BCH locking script type. Defines the standard locking script types\n * supported on BCH.\n *\n * ```\n * {\n * \"lockingScripts\": {\n * \"[id]\": {\n * \"lockingType\": \"p2pkh\" ← this schema\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateLockingTypeSchema = z.enum([ 'p2s', 'p2pkh', 'p2sh' ]);\n\n/**\n * Validation schema for a primitive type identifier. Defines the set of primitive types\n * that can be declared in an XO template. Used by constants, variables, and data fields.\n */\nexport const xoTemplatePrimitiveTypeSchema = z.enum([ 'boolean', 'bytes', 'integer', 'bigint', 'string', 'private_key', 'public_key' ]);\n\n// ============================================================\n// Primitives\n// ============================================================\n\n/**\n * Validation schema for byte array fields i.e. Uint8Array instance.\n */\nexport const uint8ArraySchema = z.instanceof(Uint8Array).describe('A sequence of unsigned 8-bit integers expressed as a Uint8Array.');\n\n/**\n * Validation schema for the Satoshis type i.e. bigint.\n */\nexport const satoshisSchema = z.bigint().describe('A satoshi amount expressed as a bigint.');\n\n// ============================================================\n// Shared\n// ============================================================\n\n/** Maximum character length for name fields on view properties. */\nexport const VIEW_PROPERTIES_NAME_MAX_LENGTH = 200;\n\n/** Maximum character length for description fields on view properties. */\nexport const VIEW_PROPERTIES_DESCRIPTION_MAX_LENGTH = 5000;\n\n/** Maximum character length for icon fields on view properties. */\nexport const VIEW_PROPERTIES_ICON_MAX_LENGTH = 50;\n\n/**\n * Validation schema for view properties shared across many template elements i.e. name, description, icon.\n * Extended by most other schemas in this file.\n */\nexport const xoTemplateViewPropertiesSchema = z\n .object({\n name: z.string().max(VIEW_PROPERTIES_NAME_MAX_LENGTH).describe('A short human-readable label for this element.'),\n description: z\n .string()\n .max(VIEW_PROPERTIES_DESCRIPTION_MAX_LENGTH)\n .describe('A human-readable explanation of what this element does and when it is relevant.'),\n icon: z.string().max(VIEW_PROPERTIES_ICON_MAX_LENGTH).optional().describe('An optional icon identifier or URL for this element.'),\n })\n .strict();\n\n// ============================================================\n// Intents\n// ============================================================\n\n/**\n * Validation schema for the base intent structure. Describes the common data parameters shared\n * by all intent types regardless of what they target.\n *\n * An optional templateIdentifier allows the intent to reference a target defined in a different\n * template, enabling cross-template interaction.\n *\n * Extended by: xoTemplateActionIntentSchema, xoTemplateOutputIntentSchema,\n * xoTemplateLockingScriptIntentSchema.\n */\nexport const xoTemplateIntentSchema = z\n .object({\n templateIdentifier: z\n .string()\n .optional()\n .describe('Optional identifier for the template used in this intent. If not provided, uses the current template.'),\n role: z.string().optional().describe('Optional identifier for the role used in this intent.'),\n generate: z.array(z.string()).optional().describe('Identifiers for items to generate when this intent is resolved, e.g. keys or secrets.'),\n variables: z.array(z.record(z.string(), z.unknown())).optional().describe('Variable values to apply when this intent is resolved.'),\n constants: z.array(z.record(z.string(), z.unknown())).optional().describe('Constant values to apply when this intent is resolved.'),\n secrets: z.array(z.record(z.string(), z.unknown())).optional().describe('Secret values to apply when this intent is resolved.'),\n })\n .strict();\n\n/**\n * Validation schema for an action intent. Extends the base intent structure with an action\n * identifier. Used in locking script action lists and in the template's start array.\n *\n * ```\n * {\n * \"start\": [\n * { \"action\": \"...\" } ← this schema\n * ],\n * \"lockingScripts\": {\n * \"[id]\": {\n * \"actions\": [\n * { \"action\": \"...\" } ← this schema\n * ],\n * \"roles\": {\n * \"[roleId]\": {\n * \"actions\": [\n * { \"action\": \"...\" } ← this schema\n * ]\n * }\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateActionIntentSchema = xoTemplateIntentSchema\n .extend({\n action: z.string().describe('The identifier for the intended action.'),\n })\n .strict();\n\n/**\n * Validation schema for an output intent. Extends the base intent structure with an output\n * identifier. Used in the template's defaults block.\n *\n * ```\n * {\n * \"defaults\": {\n * \"change\": { \"output\": \"...\" } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateOutputIntentSchema = xoTemplateIntentSchema\n .extend({\n output: z.string().describe('The identifier for the intended output.'),\n })\n .strict();\n\n/**\n * Validation schema for a locking script intent. Extends the base intent structure with\n * a locking script identifier.\n *\n * @todo The location of this schema in the template JSON is not yet determined.\n */\nexport const xoTemplateLockingScriptIntentSchema = xoTemplateIntentSchema\n .extend({\n lockingScript: z.string().describe('The identifier for the intended locking script.'),\n })\n .strict();\n\n// ============================================================\n// Actions\n// ============================================================\n\n/**\n * Validation schema for the slot count configuration on a role requirement. Declares how many\n * participants of a given role are needed. min sets the lower bound and max sets the upper bound.\n * When max is absent, there is no upper limit.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": {\n * \"requirements\": {\n * \"participants\": [\n * { \"slots\": { \"min\": 1, \"max\": 1 } } ← this schema\n * ]\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateRoleSlotsRequirementsSchema = z\n .object({\n min: z.number().describe('Minimum number of participants required for this role.'),\n max: z.number().optional().describe('Maximum number of participants allowed for this role. Undefined means unlimited.'),\n })\n .strict();\n\n/**\n * Validation schema for the capability requirements declared on a role within an action.\n * Describes what data, secrets, or state the role is responsible for providing when participating in an action.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": {\n * \"roles\": {\n * \"[roleId]\": {\n * \"requirements\": { \"variables\": [], \"secrets\": [] } ← this schema\n * }\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateActionRoleRequirementsSchema = z\n .object({\n variables: z.array(z.string()).optional().describe('List of variable identifiers required for this role.'),\n secrets: z.array(z.string()).optional().describe('List of secret identifiers required for this role.'),\n })\n .strict();\n\n/**\n * Validation schema for a role-specific definition within an action.\n * All view properties are optional.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": {\n * \"roles\": {\n * \"[roleId]\": { } ← this schema\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateActionRoleSchema = xoTemplateViewPropertiesSchema\n .partial()\n .extend({\n generate: z\n .array(z.string())\n .optional()\n .describe('Identifiers for data items that should be generated for this role when participating in the action.'),\n\n // Describes under what conditions this role can proceed with the action. All values listed\n // under requirements must be populated for the action to work. This is a developer and\n // author concern. It is not present on intents because intents are used to populate the\n // action rather than to define it, and their fields are flattened accordingly.\n requirements: xoTemplateActionRoleRequirementsSchema.optional().describe('The requirements for this role within this action.'),\n })\n .strict();\n\n/**\n * Validation schema for a role participation requirement in an action's requirements block.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": {\n * \"requirements\": {\n * \"participants\": [\n * { \"role\": \"...\", \"slots\": { } } ← this schema\n * ]\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateRoleSlotSchema = z\n .object({\n role: z.string().describe('The role identifier that this requirement applies to.'),\n slots: xoTemplateRoleSlotsRequirementsSchema.describe('Slot configuration specifying how many participants of this role are required.'),\n })\n .strict();\n\n/**\n * Validation schema for the requirements of an action.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": {\n * \"requirements\": { \"participants\": [], \"secrets\": [] } ← this schema\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateActionRequirementsSchema = z\n .object({\n participants: z.array(xoTemplateRoleSlotSchema).optional().describe('The participants required for this action.'),\n secrets: z.array(z.string()).optional().describe('The secrets required for this action.'),\n })\n .strict();\n\n/**\n * Validation schema for an action definition.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateActionSchema = xoTemplateViewPropertiesSchema\n .extend({\n roles: z.record(z.string(), xoTemplateActionRoleSchema).optional().describe('Specific context for each role participating in this action.'),\n requirements: xoTemplateActionRequirementsSchema.optional().describe('The requirements for this action.'),\n\n // This is a list of conditions that can influence how the action behaves.\n // This needs more work to be done.\n conditions: z.array(z.string()).optional().describe('Conditions that must be met for this action to be available.'),\n\n // A single transaction produced by the action.\n // In future this might be moved to a results block that can have multiple transactions.\n transaction: z\n .string()\n .optional()\n .describe(\"The identifier of the transaction this action produces, referencing an entry in the template's transactions.\"),\n\n // The data that is produced by the action.\n // In future this might be moved to a results block that can have multiple data fields.\n data: z.string().optional().describe(\"The identifier of the data field this action produces, referencing an entry in the template's data.\"),\n })\n .strict();\n\n// ============================================================\n// Tokens & Amounts\n// ============================================================\n\n/**\n * Validation schema for the non-fungible token configuration within a token field.\n *\n * ```\n * {\n * \"inputs|outputs\": {\n * \"[id]\": {\n * \"token\": {\n * \"nft\": { } ← this schema\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateNonFungibleTokenDetailsSchema = z\n .object({\n capability: z\n .union([ xoTemplateNftCapabilitySchema, z.string() ])\n .optional()\n .describe('The capability of the NFT. May be a known capability value or a CashASM expression resolving to a capability.'),\n commitment: z.string().optional().describe('The commitment data for the NFT, as a string or CashASM expression resolving to a commitment.'),\n })\n .strict();\n\n/**\n * Validation schema for the token configuration on inputs and outputs.\n *\n * ```\n * {\n * \"inputs|outputs\": {\n * \"[id]\": {\n * \"token\": { } ← this schema\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateTokenSchema = z\n .object({\n category: z.string().optional().describe('The category of the token, as a string or CashASM expression resolving to a category.'),\n amount: z\n .union([ z.bigint(), z.string(), z.null() ])\n .optional()\n .describe('The amount of fungible tokens as a bigint, a CashASM expression resolving to a bigint, or null indicating no FT is present.'),\n nft: xoTemplateNonFungibleTokenDetailsSchema\n .nullable()\n .optional()\n .describe('Non-fungible token configuration. Null indicates no NFT is present.'),\n })\n .strict();\n\n/**\n * Validation schema for the asset amounts configuration. Used by omitChangeAmounts on inputs\n * and by balance on locking scripts, outputs, and their roles.\n */\nexport const xoTemplateAssetAmountsSchema = z\n .object({\n\n /**\n * The satoshi amount.\n * - `Satoshis`: A specific bigint amount.\n * - `string`: A CashASM expression that resolves to the amount.\n * - `true`: all, i.e. the entire amount\n */\n satoshis: z\n .union([ satoshisSchema, z.string(), z.literal(true) ])\n .optional()\n .describe('The satoshi amount. Accepts a bigint for a specific value, a CashASM expression, or true for the entire amount.'),\n\n /**\n * The fungible token amount.\n * - `FungibleTokenAmount`: A specific bigint amount.\n * - `string`: A CashASM expression that resolves to the amount.\n * - `true`: all, i.e. the entire amount\n */\n fungibleTokens: z\n .union([ z.bigint(), z.string(), z.literal(true) ])\n .optional()\n .describe('The fungible token amount. Accepts a bigint for a specific value, a CashASM expression, or true for the entire amount.'),\n\n /**\n * Whether a non-fungible token is present (0 for absent, 1 for present),\n * or a CashASM expression that evaluates to 0 or 1.\n * - `true`: resolves to 1 if an NFT is present, or 0 if none is present. Use this when\n * the NFT is optional, to express that the NFT is estimated to be part of the balance\n * if present, or absent from it if not.\n * - `0`: None, i.e. nothing is expected to be included\n * - `1`: present and complete, as value > 1 does not make sense for non-fungible tokens\n * - `string`: A CashASM expression that evaluates to 0 or 1.\n */\n nonfungibleTokens: z\n .union([ z.literal(0), z.literal(1), z.string(), z.literal(true) ])\n .optional()\n .describe('Whether an NFT is present: 0 for absent, 1 for present, a CashASM expression evaluating to 0 or 1, or true to estimate the NFT as part of the balance if present, or absent from it if not.'),\n })\n .strict();\n\n// ============================================================\n// Locking Scripts\n// ============================================================\n\n/**\n * Validation schema for the state configuration shared by a locking script and its individual roles.\n * Declares which variables and secrets are tracked in the on-chain state for a given participant.\n *\n * ```\n * {\n * \"lockingScripts\": {\n * \"[id]\": {\n * \"state\": { \"variables\": [], \"secrets\": [] } ← this schema\n * \"roles\": {\n * \"[roleId]\": {\n * \"state\": { \"variables\": [], \"secrets\": [] } ← this schema\n * }\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateStateSchema = z\n .object({\n variables: z.array(z.string()).optional().describe('List of variable identifiers to track in state.'),\n secrets: z.array(z.string()).optional().describe('List of secret identifiers to track in state.'),\n })\n .strict();\n\n/**\n * Validation schema for a role definition for a locking script.\n *\n * ```\n * {\n * \"lockingScripts\": {\n * \"[id]\": {\n * \"roles\": {\n * \"[roleId]\": { } ← this schema\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateLockingScriptRoleSchema = xoTemplateViewPropertiesSchema\n .partial()\n .extend({\n state: xoTemplateStateSchema.optional().describe('List of items to track as state for this role.'),\n actions: z.array(xoTemplateActionIntentSchema).optional().describe('List of action references available to this role.'),\n balance: xoTemplateAssetAmountsSchema.partial().optional().describe('Estimated ownership in the optional set of asset amounts specified.'),\n selectable: z.boolean().optional().describe('Whether outputs locked to this script should be available for coin selection.'),\n privacy: z\n .union([ z.number(), z.string() ])\n .optional()\n .describe('Privacy level for outputs locked to this script. A numeric level or a CashASM expression that evaluates to a privacy level.'),\n })\n .strict();\n\n/**\n * Validation schema for a locking script definition.\n *\n * ```\n * {\n * \"lockingScripts\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateLockingScriptSchema = xoTemplateViewPropertiesSchema\n .extend({\n lockingType: xoTemplateLockingTypeSchema.optional().describe('The type of locking mechanism. Defaults to p2s if not specified.'),\n lockingBytecode: z.string().describe('The locking script bytecode.'),\n unlockingBytecode: z.string().optional().describe('Optional default unlocking bytecode when used in automatic coin selection.'),\n actions: z.array(xoTemplateActionIntentSchema).optional().describe('The actions available for this locking script.'),\n state: xoTemplateStateSchema.optional().describe('List of items to track as state for all participants.'),\n balance: xoTemplateAssetAmountsSchema.partial().optional().describe('Estimated ownership in the optional set of asset amounts specified.'),\n selectable: z.boolean().optional().describe('Whether outputs locked to this script should be available for coin selection.'),\n // Might be levels or tags\n privacy: z\n .union([ z.number(), z.string() ])\n .optional()\n .describe('Privacy level for outputs locked to this script. A numeric level or a CashASM expression that evaluates to a privacy level.'),\n roles: z\n .record(z.string(), xoTemplateLockingScriptRoleSchema)\n .optional()\n .describe('Specific context for each role participating in this locking script.'),\n })\n .strict();\n\n// ============================================================\n// Inputs\n// ============================================================\n\n/**\n * Validation schema for an input definition in the template. Extends view properties with optional\n * satoshi value, token configuration, and other transaction level fields.\n *\n * ```\n * {\n * \"inputs\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateInputSchema = xoTemplateViewPropertiesSchema\n .extend({\n valueSatoshis: z\n .union([ satoshisSchema, z.string() ])\n .optional()\n .describe('The amount of satoshis for this input as a bigint or a CashASM expression resolving to the amount.'),\n token: xoTemplateTokenSchema.nullable().optional().describe('Token configuration for this input.'),\n sequenceNumber: z\n .union([ z.number(), z.string() ])\n .optional()\n .describe('The sequence number of this input as a specific number or a CashASM expression.'),\n unlockingScript: z.string().optional().describe('Identifier of the unlocking script to use for the UTXO provided for this input.'),\n omitChangeAmounts: xoTemplateAssetAmountsSchema\n .optional()\n .describe('Amount of change that should be omitted from the automatic change handling. WARNING: Setting this can result in loss of funds!'),\n })\n .strict();\n\n// ============================================================\n// Outputs\n// ============================================================\n\n/**\n * Validation schema for an output definition. Extends the locking script schema so that\n * every output inherits the same locking script fields and adds output-specific fields.\n *\n * ```\n * {\n * \"outputs\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateOutputSchema = xoTemplateLockingScriptSchema\n .omit({ lockingType: true, lockingBytecode: true, unlockingBytecode: true })\n .extend({\n lockingScript: z.string().describe('Identifier of the locking script to use for this output.'),\n valueSatoshis: z\n .union([ satoshisSchema, z.string() ])\n .optional()\n .describe('The amount of satoshis for this output as a bigint or a CashASM expression resolving to the amount.'),\n token: xoTemplateTokenSchema.nullable().optional().describe('Token configuration for this output.'),\n })\n .strict();\n\n// ============================================================\n// Transactions\n// ============================================================\n\n/**\n * Validation schema for a transaction input reference for a transaction definition.\n *\n * ```\n * {\n * \"transactions\": {\n * \"[id]\": {\n * \"inputs\": [\n * { \"input\": \"...\" } ← this schema\n * ]\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateTransactionInputSchema = z\n .object({\n input: z.string().describe('The input definition identifier.'),\n inputIndex: z.number().optional().describe('Optional index of this input in the transaction.'),\n })\n .strict();\n\n/**\n * Validation schema for a transaction output reference for a transaction definition.\n *\n * ```\n * {\n * \"transactions\": {\n * \"[id]\": {\n * \"outputs\": [\n * { \"output\": \"...\" } ← this schema\n * ]\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateTransactionOutputSchema = z\n .object({\n output: z.string().describe('The output definition identifier.'),\n outputIndex: z.number().optional().describe('Optional index of this output in the transaction.'),\n })\n .strict();\n\n/**\n * Validation schema for role-specific data for a transaction definition.\n *\n * ```\n * {\n * \"transactions\": {\n * \"[id]\": {\n * \"roles\": {\n * \"[roleId]\": { } ← this schema\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateTransactionRoleDataSchema = xoTemplateViewPropertiesSchema\n .partial()\n .extend({\n inputs: z.array(xoTemplateTransactionInputSchema).optional().describe('The inputs required for this role.'),\n outputs: z.array(xoTemplateTransactionOutputSchema).optional().describe('The outputs required for this role.'),\n })\n .strict();\n\n/**\n * Validation schema for a transaction template definition.\n *\n * ```\n * {\n * \"transactions\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateTransactionSchema = xoTemplateViewPropertiesSchema\n .extend({\n version: z.number().optional().describe('The version of the transaction.'),\n locktime: z.number().optional().describe('The locktime for this transaction.'),\n inputs: z.array(xoTemplateTransactionInputSchema).describe('The inputs for this transaction.'),\n outputs: z.array(xoTemplateTransactionOutputSchema).describe('The outputs for this transaction.'),\n roles: z\n .record(z.string(), xoTemplateTransactionRoleDataSchema)\n .optional()\n .describe('Specific context for each role participating in this transaction.'),\n composable: z.boolean().optional().describe('Whether this transaction can be composed with other transactions.'),\n })\n .strict();\n\n// ============================================================\n// Template Data\n// ============================================================\n\n/**\n * Validation schema for a constant value definition.\n *\n * ```\n * {\n * \"constants\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateConstantSchema = xoTemplateViewPropertiesSchema\n .extend({\n type: xoTemplatePrimitiveTypeSchema.describe('The data type of this constant.'),\n value: z.unknown().describe('The value of this constant.'),\n hint: z.string().optional().describe('An optional hint to help apps and users understand what this constant represents.'),\n })\n .strict();\n\n/**\n * Validation schema for a data field definition.\n *\n * ```\n * {\n * \"data\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateDataSchema = z\n .object({\n type: xoTemplatePrimitiveTypeSchema.describe('The data type of this data field.'),\n value: z.unknown().describe('The value for this data field.'),\n hint: z.string().optional().describe('An optional hint to help apps and users understand this data field.'),\n })\n .strict();\n\n/**\n * Validation schema for an import default value intent. Extends the base intent with optional\n * view properties that the engine evaluates at runtime to produce human-readable output.\n *\n * ```\n * {\n * \"variables\": {\n * \"[id]\": {\n * \"importDefaultValue\": { } ← this schema\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateImportDefaultValueSchema = xoTemplateIntentSchema\n // .shape unwraps the ZodObject to the raw field map { name, description, icon } with each field made optional\n .extend(xoTemplateViewPropertiesSchema.partial().shape)\n .strict();\n\n/**\n * Validation schema for a variable definition.\n *\n * ```\n * {\n * \"variables\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateVariableSchema = xoTemplateViewPropertiesSchema\n .extend({\n type: xoTemplatePrimitiveTypeSchema.optional().describe('The data type of this variable.'),\n hint: z.string().optional().describe('A hint to help users understand what value to provide.'),\n\n // A neutral intent that the engine uses to populate the default value for this variable.\n // View properties (name, description, icon) may contain CashASM expressions that the\n // engine evaluates at runtime to produce human-readable output. The engine overrides\n // whatever values are set here when resolving the variable for a participant.\n importDefaultValue: xoTemplateImportDefaultValueSchema\n .optional()\n .describe('A neutral intent that the engine uses to populate the default value for this variable.'),\n })\n .strict();\n\n// ============================================================\n// Template Resources\n// ============================================================\n\n/**\n * Validation schema for a resource reference attached to a template element. Extends view\n * properties with a URL pointing to external documentation or tooling.\n *\n * ```\n * {\n * \"resources\": [\n * { \"name\": \"...\", \"description\": \"...\", \"url\": \"...\" } ← this schema\n * ]\n * }\n * ```\n */\nexport const xoTemplateResourceSchema = xoTemplateViewPropertiesSchema\n .extend({\n url: z.string().describe('The URL for this resource.'),\n })\n .strict();\n\n/**\n * Validation schema for an icon reference.\n *\n * ```\n * {\n * \"icons\": [\n * { \"name\": \"...\", \"hash\": \"...\" } ← this schema\n * ]\n * }\n * ```\n */\nexport const xoTemplateIconSchema = xoTemplateViewPropertiesSchema\n .pick({ name: true })\n .extend({\n hash: z.string().describe('The identifier of the icon.'),\n })\n .strict();\n\n// ============================================================\n// Defaults\n// ============================================================\n\n/**\n * Validation schema for the defaults block of a template.\n *\n * ```\n * {\n * \"defaults\": { } ← this schema\n * }\n * ```\n */\nexport const xoTemplateDefaultsSchema = z\n .object({\n change: xoTemplateOutputIntentSchema.optional().describe('Instructions for how to construct automated change output.'),\n })\n .strict();\n\n// ============================================================\n// Template\n// ============================================================\n\n/**\n * Validation schema for the full XOTemplate type.\n */\nexport const xoTemplateSchema = xoTemplateViewPropertiesSchema\n .extend({\n $schema: z\n .string()\n .describe('The URI that identifies the JSON Schema used by this template. This enables documentation, autocompletion, and validation in JSON documents.'),\n version: z.string().optional().describe('A string identifying the version of this template.'),\n supported: z.array(bchVmVersionSchema).min(1).describe('The BCH VM versions that this template supports. At least one version is required.'),\n defaults: xoTemplateDefaultsSchema.optional().describe('Optional default settings used in this template.'),\n roles: z.record(z.string(), xoTemplateViewPropertiesSchema).describe('The roles defined in this template.'),\n start: z.array(xoTemplateActionIntentSchema).describe('A list of entry points defining which actions are available at the start.'),\n actions: z.record(z.string(), xoTemplateActionSchema).describe('The actions defined in this template.'),\n data: z.record(z.string(), xoTemplateDataSchema).optional().describe('The data fields defined in this template.'),\n transactions: z.record(z.string(), xoTemplateTransactionSchema).optional().describe('The transaction templates defined in this template.'),\n inputs: z.record(z.string(), xoTemplateInputSchema).describe('The inputs defined in this template.'),\n outputs: z.record(z.string(), xoTemplateOutputSchema).describe('The outputs defined in this template.'),\n lockingScripts: z.record(z.string(), xoTemplateLockingScriptSchema).describe('The locking script templates defined in this template.'),\n scripts: z\n .record(z.string(), z.string())\n .describe('Scripts used in this template. Keys are script identifiers, values are bytecode or CashASM expressions.'),\n constants: z.record(z.string(), xoTemplateConstantSchema).optional().describe('The constants defined in this template.'),\n variables: z\n .record(z.string(), xoTemplateVariableSchema)\n .optional()\n .describe(\"The variables that must be provided for use in the template's scripts.\"),\n resources: z.array(xoTemplateResourceSchema).optional().describe('Resource references providing external documentation or tooling links.'),\n icons: z.array(xoTemplateIconSchema).optional().describe('The icons available for use throughout the template.'),\n scenarios: z.unknown().optional().describe('The scenarios defined in this template.'),\n })\n .strict();\n","import type { XOTemplate } from '@xo-cash/types';\nimport { xoTemplateSchema } from './schemas.ts';\nimport { TemplateInvalidError, buildErrorDescription } from './errors.ts';\nimport { deserializeTemplate, serializeTemplate } from './serialization.ts';\n\n/**\n * Accepts a template value and returns a validated XOTemplate object. The input may be\n * either an Extended JSON string or a pre-parsed object. Both are validated\n * against the XOTemplate schema.\n *\n * @param inputTemplate - The value to validate. May be an Extended JSON string or a pre-parsed object.\n * @returns The validated template object\n * @throws {TemplateSerializationFailedError} If a pre-parsed object input cannot be serialized to JSON for normalization.\n * @throws {TemplateJsonMalformedError} If the string input is not valid JSON.\n * @throws {TemplateInvalidError} If the value does not conform to the XOTemplate schema.\n */\nexport const parseTemplate = (inputTemplate: string | XOTemplate): XOTemplate => {\n // Regardless of whether the inputTemplate is a string, an imported template or an in-memory object, serialize and then\n // deserialize it to ensure the output shape is consistent. For example, optional fields explicitly set to 'undefined' would be passed through\n // and then dropped on the string path, resulting in structurally different results for the same template.\n const serializedTemplate = typeof inputTemplate === 'string' ? inputTemplate : serializeTemplate(inputTemplate);\n const templateObject = deserializeTemplate(serializedTemplate);\n\n // Validate the template against the schema.\n const parseResult = xoTemplateSchema.safeParse(templateObject);\n\n if (parseResult.success) {\n // Return the validated template object\n return parseResult.data as XOTemplate;\n }\n\n // Build a human-readable description of every validation failure\n const errorDescription = buildErrorDescription(parseResult.error.issues);\n\n // Throw a typed error with the description\n throw new TemplateInvalidError(errorDescription);\n};\n"],"mappings":";;;;;;;AAKA,MAAM,+BAA+B;;;;AAKrC,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;AAoBzC,MAAa,wBAAwB,cAAsB,UAA4B;AACnF,KAAI,iBAAiB,WACjB,QAAO,gBAAgB,SAAS,MAAM,CAAC;AAG3C,KAAI,OAAO,UAAU,SACjB,QAAO,YAAY,MAAM,UAAU,CAAC;AAGxC,QAAO;;;;;;;;;;;AAYX,MAAa,uBAAuB,cAAsB,UAA4B;AAElF,KAAI,OAAO,UAAU,SACjB,QAAO;CAIX,MAAM,qBAAqB,MAAM,MAAM,6BAA6B;AAGpE,KAAI,mBACA,QAAO,OAAO,mBAAmB,OAAQ,OAAO;CAIpD,MAAM,yBAAyB,MAAM,MAAM,iCAAiC;AAG5E,KAAI,uBACA,QAAO,SAAS,uBAAuB,OAAQ,IAAI;AAIvD,QAAO;;;;;;;;;;ACnEX,MAAa,sBAAsB,WAA+B;AAQ9D,QAAO,SANM,OAAO,KAAK,OAAO,CAGV,SAAS,CAGN;;;;;;;;;;;;ACJ7B,MAAa,yBAAyB,WAAgC;CAElE,MAAM,QAAkB,EAAE;AAG1B,MAAK,MAAM,SAAS,QAAQ;EAExB,MAAM,YAAY,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,IAAI,GAAG;EAMjE,MAAM,eAAe,MAAM,QAAQ,WAHb,kBAGsC,GAAG,MAAM,QAAQ,MAAM,GAAqB,GAAG,MAAM;AAGjH,QAAM,KAAK,KAA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SAAS,4CAA4C;CACjH,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,4BAA4B,CAAC,UAAU,CAAC,SAAS,sDAAsD;CAC1I,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,sBAAsB,CAAC,SAAS,uCAAuC;CACpG,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,uBAAuB,CAAC,SAAS,wCAAwC;CACvG,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,8BAA8B,CAAC,SAAS,yDAAyD;CACtI,SAAS,EACJ,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAC9B,SAAS,0GAA0G;CACxH,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,yBAAyB,CAAC,UAAU,CAAC,SAAS,0CAA0C;CACxH,WAAW,EACN,OAAO,EAAE,QAAQ,EAAE,yBAAyB,CAC5C,UAAU,CACV,SAAS,yEAAyE;CACvF,WAAW,EAAE,MAAM,yBAAyB,CAAC,UAAU,CAAC,SAAS,yEAAyE;CAC1I,OAAO,EAAE,MAAM,qBAAqB,CAAC,UAAU,CAAC,SAAS,uDAAuD;CAChH,WAAW,EAAE,SAAS,CAAC,UAAU,CAAC,SAAS,0CAA0C;CACxF,CAAC,CACD,QAAQ;;;;;;;;;;;;;;;AC92Bb,MAAa,iBAAiB,kBAAmD;CAK7E,MAAM,iBAAiB,oBADI,OAAO,kBAAkB,WAAW,gBAAgB,kBAAkB,cAAc,CACjD;CAG9D,MAAM,cAAc,iBAAiB,UAAU,eAAe;AAE9D,KAAI,YAAY,QAEZ,QAAO,YAAY;AAOvB,OAAM,IAAI,qBAHe,sBAAsB,YAAY,MAAM,OAAO,CAGxB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../source/extended-json.ts","../source/script.ts","../source/template/errors.ts","../source/template/serialization.ts","../source/template/identifier.ts","../source/template/schemas.ts","../source/template/parser.ts"],"sourcesContent":["import { binToHex, hexToBin } from '@bitauth/libauth';\n\n/**\n * Matches a bigint encoded in Extended JSON format: `<bigint: 123n>`.\n */\nconst EXTENDED_JSON_BIGINT_PATTERN = /^<bigint: (?<bigint>[+-]?[0-9]+)n>$/u;\n\n/**\n * Matches a Uint8Array encoded in Extended JSON format: `<uint8array: abcd>`.\n */\nconst EXTENDED_JSON_UINT8ARRAY_PATTERN = /^<uint8array: (?<hex>[0-9a-f]*)>$/u;\n\n/**\n * The JSON replacer that encodes `bigint` and `Uint8Array` values in Extended JSON format,\n * compatible with the format expected by `extendedJsonReviver`.\n *\n * - BigInts are encoded as `<bigint: 123n>`.\n * - Uint8Arrays are encoded as `<uint8array: abcd>`.\n * All other values pass through unchanged and if any incompatible type is encountered, an error is thrown.\n *\n * Note: To use this function, pass it as the second argument to `JSON.stringify` when serializing data.\n *\n * Note to developers: Libauth's `stringify` is the replacer. It also serializes functions and symbols,\n * which we do not support. Passing it would let templates include those values, but revival would then fail.\n * This module provides a dedicated replacer and reviver so serialization and deserialization stay aligned.\n *\n * @param _propertyKey The property key being serialized, required by the `JSON.stringify` replacer but not used here.\n * @param value The value to encode or pass through unchanged.\n * @returns The encoded string\n */\nexport const extendedJsonReplacer = (_propertyKey: string, value: unknown): unknown => {\n if (value instanceof Uint8Array) {\n return `<uint8array: ${binToHex(value)}>`;\n }\n\n if (typeof value === 'bigint') {\n return `<bigint: ${value.toString()}n>`;\n }\n\n return value;\n};\n\n/**\n * The JSON reviver that reconstructs `bigint` and `Uint8Array` values encoded by `extendedJsonReplacer`.\n *\n * Note: To use this function, pass it as the second argument to `JSON.parse` when deserializing data.\n *\n * @param _propertyKey The property key being deserialized, required by the `JSON.parse` reviver but not used here.\n * @param value The value to reconstruct or pass through unchanged.\n * @returns The reconstructed value\n */\nexport const extendedJsonReviver = (_propertyKey: string, value: unknown): unknown => {\n // If the value is not a string, return the original value\n if (typeof value !== 'string') {\n return value;\n }\n\n // Match the bigint pattern\n const bigintPatternMatch = value.match(EXTENDED_JSON_BIGINT_PATTERN);\n\n // If the value matches the bigint pattern, return the reconstructed bigint\n if (bigintPatternMatch) {\n return BigInt(bigintPatternMatch.groups!.bigint);\n }\n\n // Match the Uint8Array pattern\n const uint8arrayPatternMatch = value.match(EXTENDED_JSON_UINT8ARRAY_PATTERN);\n\n // If the value matches the Uint8Array pattern, return the reconstructed Uint8Array\n if (uint8arrayPatternMatch) {\n return hexToBin(uint8arrayPatternMatch.groups!.hex);\n }\n\n // If the value does not match either pattern, return the original value\n return value;\n};\n","import { binToHex, sha256 } from '@bitauth/libauth';\n\n/**\n * Converts a script to a scriptHash.\n * @param {Uint8Array} script - The script to convert.\n * @returns {string} The scriptHash as a reversed hex string.\n */\nexport const scriptToScriptHash = (script: Uint8Array): string => {\n // Hash the script.\n const hash = sha256.hash(script);\n\n // Reverse the hash. (Electrum style, reverse switches to little endian representation)\n const reversed = hash.reverse();\n\n // Convert the reversed hash to hex.\n return binToHex(reversed);\n};\n","/* eslint-disable max-classes-per-file */\n\nimport type { $ZodIssue } from 'zod/v4/core';\n\n/**\n * Formats the Zod validation failures into a single string with one line each: \"- <field>: <message>\" and top level failures\n * with no field path show as \"(root)\" for better readability.\n *\n * @param issues The Zod validation failures to format.\n * @returns A human readable error string for better debugging.\n */\nexport const buildErrorDescription = (issues: $ZodIssue[]): string => {\n // Initialize an empty array to store the formatted lines.\n const lines: string[] = [];\n\n // Iterate over the issues and format them into a string.\n for (const issue of issues) {\n // Get the issue path.\n const issuePath = issue.path.length > 0 ? issue.path.join('.') : '(root)';\n\n // The prefix that Zod adds to messages.\n const messagePrefix = 'Invalid input: ';\n\n // Remove the prefix for better readability.\n const issueMessage = issue.message.startsWith(messagePrefix) ? issue.message.slice(messagePrefix.length) : issue.message;\n\n // Add the formatted line to the array.\n lines.push(`- ${issuePath}: ${issueMessage}`);\n }\n\n // Return the formatted string.\n return `\\n${lines.join('\\n')}`;\n};\n\n/**\n * Thrown when the provided template does not satisfy the XOTemplate schema.\n */\nexport class TemplateInvalidError extends Error {\n constructor(details: string) {\n const message = `Template invalid: ${details}`;\n super(message);\n this.name = 'TemplateInvalidError';\n }\n}\n\n/**\n * Thrown when a string passed to `deserializeTemplate` cannot be parsed as JSON.\n */\nexport class TemplateJsonMalformedError extends Error {\n constructor(reason: string) {\n super(`Template JSON malformed, expected a valid JSON string: ${reason}`);\n this.name = 'TemplateJsonMalformedError';\n }\n}\n\n/**\n * Thrown when `serializeTemplate` fails to produce a JSON string from the template.\n */\nexport class TemplateSerializationFailedError extends Error {\n constructor(reason: string) {\n super(`Template serialization failed: ${reason}`);\n this.name = 'TemplateSerializationFailedError';\n }\n}\n","import type { XOTemplate } from '@xo-cash/types';\nimport { extendedJsonReplacer, extendedJsonReviver } from '../extended-json.ts';\nimport { TemplateJsonMalformedError, TemplateSerializationFailedError } from './errors.ts';\n\n/**\n * Serializes an XOTemplate to a JSON string. Encodes `bigint` and `Uint8Array` fields in\n * Extended JSON format so they can be reconstructed by `deserializeTemplate`.\n *\n * @param template The template to serialize.\n * @returns A JSON string representation of the template.\n * @throws {TemplateSerializationFailedError} If the template cannot be serialized to JSON.\n */\nexport const serializeTemplate = (template: XOTemplate): string => {\n try {\n // Serialize the template to a JSON string.\n return JSON.stringify(template, extendedJsonReplacer);\n } catch (serializationError) {\n const reason = serializationError instanceof Error ? serializationError.message : 'unknown error while serializing template';\n\n throw new TemplateSerializationFailedError(reason);\n }\n};\n\n/**\n * Deserializes a JSON string back into an XOTemplate object. Restores `bigint` and\n * `Uint8Array` fields encoded in Extended JSON format by `serializeTemplate`.\n *\n * @param serializedTemplate - A JSON string of an XOTemplate object.\n * @returns The reconstructed XOTemplate object.\n * @throws {TemplateJsonMalformedError} If the serialized template is not valid JSON.\n */\nexport const deserializeTemplate = (serializedTemplate: string): XOTemplate => {\n try {\n // Parse the serialized template using the extended JSON reviver.\n return JSON.parse(serializedTemplate, extendedJsonReviver);\n } catch (parsingError) {\n const reason = parsingError instanceof Error ? parsingError.message : 'unknown error while deserializing template';\n\n throw new TemplateJsonMalformedError(reason);\n }\n};\n","import { binToHex, sha256, utf8ToBin } from '@bitauth/libauth';\nimport type { XOTemplate } from '@xo-cash/types';\nimport { serializeTemplate } from './serialization.ts';\n\n/**\n * Generates a deterministic template identifier by hashing the template.\n *\n * Note: This expects a template that has been validated by `parseTemplate`.\n *\n * @param template - The template to generate an identifier for.\n * @returns The sha256 hex identifier for the template.\n */\nexport const generateTemplateIdentifier = (template: XOTemplate): string => {\n // Serialize the template.\n const serializedTemplate = serializeTemplate(template);\n\n // Hash the serialized template.\n const hash = sha256.hash(utf8ToBin(serializedTemplate));\n\n // Convert the hash to hex and return it.\n return binToHex(hash);\n};\n","/* eslint-disable @stylistic/newline-per-chained-call */\nimport { BchVmVersions, XOTemplateLockingTypes, XOTemplateNftCapabilities, XOTemplatePrimitiveTypes } from '@xo-cash/types';\nimport { z } from 'zod';\n\n// ============================================================\n// Enums\n// ============================================================\n\n/**\n * Validation schema for a BCH VM version identifier. Defines the set of known BCH VM versions\n * that XO templates declare support for.\n *\n * Uses `BchVmVersions` from `@xo-cash/types` so template validation stays aligned with the\n * `BchVmVersion` type.\n *\n * ```\n * {\n * \"supported\": [ \"BCH_2025_05\" ] ← each value\n * }\n * ```\n */\nexport const bchVmVersionSchema = z.enum(BchVmVersions);\n\n/**\n * Validation schema for the capability of a non-fungible token. Defines the three capability\n * types supported on BCH: minting tokens can create new NFTs, mutable tokens can update their\n * commitment, and none tokens cannot be changed after creation.\n *\n * ```\n * {\n * \"inputs|outputs\": {\n * \"[id]\": {\n * \"token\": {\n * \"nft\": {\n * \"capability\": \"minting\" ← this schema\n * }\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateNftCapabilitySchema = z.enum(XOTemplateNftCapabilities);\n\n/**\n * Validation schema for a BCH locking script type. Defines the standard locking script types\n * supported on BCH.\n *\n * ```\n * {\n * \"lockingScripts\": {\n * \"[id]\": {\n * \"lockingType\": \"p2pkh\" ← this schema\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateLockingTypeSchema = z.enum(XOTemplateLockingTypes);\n\n/**\n * Validation schema for a primitive type identifier. Defines the set of primitive types\n * that can be declared in an XO template. Used by constants, variables, and data fields.\n */\nexport const xoTemplatePrimitiveTypeSchema = z.enum(XOTemplatePrimitiveTypes);\n\n// ============================================================\n// Primitives\n// ============================================================\n\n/**\n * Validation schema for byte array fields i.e. Uint8Array instance.\n */\nexport const uint8ArraySchema = z.instanceof(Uint8Array).describe('A sequence of unsigned 8-bit integers expressed as a Uint8Array.');\n\n/**\n * Validation schema for the Satoshis type i.e. bigint.\n */\nexport const satoshisSchema = z.bigint().describe('A satoshi amount expressed as a bigint.');\n\n// ============================================================\n// Shared\n// ============================================================\n\n/** Maximum character length for name fields on view properties. */\nexport const VIEW_PROPERTIES_NAME_MAX_LENGTH = 1000;\n\n/** Maximum character length for description fields on view properties. */\nexport const VIEW_PROPERTIES_DESCRIPTION_MAX_LENGTH = 5000;\n\n/** Maximum character length for icon fields on view properties. */\nexport const VIEW_PROPERTIES_ICON_MAX_LENGTH = 1000;\n\n/**\n * Validation schema for view properties shared across many template elements i.e. name, description, icon.\n * Extended by most other schemas in this file.\n */\nexport const xoTemplateViewPropertiesSchema = z\n .object({\n name: z.string().max(VIEW_PROPERTIES_NAME_MAX_LENGTH).describe('A short human-readable label for this element.'),\n description: z\n .string()\n .max(VIEW_PROPERTIES_DESCRIPTION_MAX_LENGTH)\n .describe('A human-readable explanation of what this element does and when it is relevant.'),\n icon: z.string().max(VIEW_PROPERTIES_ICON_MAX_LENGTH).optional().describe('An optional icon identifier or URL for this element.'),\n })\n .strict();\n\n// ============================================================\n// Intents\n// ============================================================\n\n/**\n * Validation schema for the base intent structure. Describes the common data parameters shared\n * by all intent types regardless of what they target.\n *\n * An optional templateIdentifier allows the intent to reference a target defined in a different\n * template, enabling cross-template interaction.\n *\n * Extended by: xoTemplateActionIntentSchema, xoTemplateOutputIntentSchema,\n * xoTemplateLockingScriptIntentSchema.\n */\nexport const xoTemplateIntentSchema = z\n .object({\n templateIdentifier: z\n .string()\n .optional()\n .describe('Optional identifier for the template used in this intent. If not provided, uses the current template.'),\n role: z.string().optional().describe('Optional identifier for the role used in this intent.'),\n generate: z.array(z.string()).optional().describe('Identifiers for items to generate when this intent is resolved, e.g. keys or secrets.'),\n variables: z.array(z.record(z.string(), z.unknown())).optional().describe('Variable values to apply when this intent is resolved.'),\n constants: z.array(z.record(z.string(), z.unknown())).optional().describe('Constant values to apply when this intent is resolved.'),\n secrets: z.array(z.record(z.string(), z.unknown())).optional().describe('Secret values to apply when this intent is resolved.'),\n })\n .strict();\n\n/**\n * Validation schema for an action intent. Extends the base intent structure with an action\n * identifier. Used in locking script action lists and in the template's start array.\n *\n * ```\n * {\n * \"start\": [\n * { \"action\": \"...\" } ← this schema\n * ],\n * \"lockingScripts\": {\n * \"[id]\": {\n * \"actions\": [\n * { \"action\": \"...\" } ← this schema\n * ],\n * \"roles\": {\n * \"[roleId]\": {\n * \"actions\": [\n * { \"action\": \"...\" } ← this schema\n * ]\n * }\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateActionIntentSchema = xoTemplateIntentSchema\n .extend({\n action: z.string().describe('The identifier for the intended action.'),\n })\n .strict();\n\n/**\n * Validation schema for an output intent. Extends the base intent structure with an output\n * identifier. Used in the template's defaults block.\n *\n * ```\n * {\n * \"defaults\": {\n * \"change\": { \"output\": \"...\" } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateOutputIntentSchema = xoTemplateIntentSchema\n .extend({\n output: z.string().describe('The identifier for the intended output.'),\n })\n .strict();\n\n/**\n * Validation schema for a locking script intent. Extends the base intent structure with\n * a locking script identifier.\n *\n * @todo The location of this schema in the template JSON is not yet determined.\n */\nexport const xoTemplateLockingScriptIntentSchema = xoTemplateIntentSchema\n .extend({\n lockingScript: z.string().describe('The identifier for the intended locking script.'),\n })\n .strict();\n\n// ============================================================\n// Actions\n// ============================================================\n\n/**\n * Validation schema for the slot count configuration on a role requirement. Declares how many\n * participants of a given role are needed. min sets the lower bound and max sets the upper bound.\n * When max is absent, there is no upper limit.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": {\n * \"requirements\": {\n * \"participants\": [\n * { \"slots\": { \"min\": 1, \"max\": 1 } } ← this schema\n * ]\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateRoleSlotsRequirementsSchema = z\n .object({\n min: z.number().describe('Minimum number of participants required for this role.'),\n max: z.number().optional().describe('Maximum number of participants allowed for this role. Undefined means unlimited.'),\n })\n .strict();\n\n/**\n * Validation schema for the capability requirements declared on a role within an action.\n * Describes what data, secrets, or state the role is responsible for providing when participating in an action.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": {\n * \"roles\": {\n * \"[roleId]\": {\n * \"requirements\": { \"variables\": [], \"secrets\": [] } ← this schema\n * }\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateActionRoleRequirementsSchema = z\n .object({\n variables: z.array(z.string()).optional().describe('List of variable identifiers required for this role.'),\n secrets: z.array(z.string()).optional().describe('List of secret identifiers required for this role.'),\n })\n .strict();\n\n/**\n * Validation schema for a role-specific definition within an action.\n * All view properties are optional.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": {\n * \"roles\": {\n * \"[roleId]\": { } ← this schema\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateActionRoleSchema = xoTemplateViewPropertiesSchema\n .partial()\n .extend({\n generate: z\n .array(z.string())\n .optional()\n .describe('Identifiers for data items that should be generated for this role when participating in the action.'),\n\n // Describes under what conditions this role can proceed with the action. All values listed\n // under requirements must be populated for the action to work. This is a developer and\n // author concern. It is not present on intents because intents are used to populate the\n // action rather than to define it, and their fields are flattened accordingly.\n requirements: xoTemplateActionRoleRequirementsSchema.optional().describe('The requirements for this role within this action.'),\n })\n .strict();\n\n/**\n * Validation schema for a role participation requirement in an action's requirements block.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": {\n * \"requirements\": {\n * \"participants\": [\n * { \"role\": \"...\", \"slots\": { } } ← this schema\n * ]\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateRoleSlotSchema = z\n .object({\n role: z.string().describe('The role identifier that this requirement applies to.'),\n slots: xoTemplateRoleSlotsRequirementsSchema.describe('Slot configuration specifying how many participants of this role are required.'),\n })\n .strict();\n\n/**\n * Validation schema for the requirements of an action.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": {\n * \"requirements\": { \"variables\": [], \"participants\": [], \"secrets\": [] } ← this schema\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateActionRequirementsSchema = z\n .object({\n variables: z.array(z.string()).optional().describe('List of variable identifiers required for this action.'),\n participants: z.array(xoTemplateRoleSlotSchema).optional().describe('The participants required for this action.'),\n secrets: z.array(z.string()).optional().describe('The secrets required for this action.'),\n })\n .strict();\n\n/**\n * Validation schema for an action definition.\n *\n * ```\n * {\n * \"actions\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateActionSchema = xoTemplateViewPropertiesSchema\n .extend({\n roles: z.record(z.string(), xoTemplateActionRoleSchema).optional().describe('Specific context for each role participating in this action.'),\n requirements: xoTemplateActionRequirementsSchema.optional().describe('The requirements for this action.'),\n\n // This is a list of conditions that can influence how the action behaves.\n // This needs more work to be done.\n conditions: z.array(z.string()).optional().describe('Conditions that must be met for this action to be available.'),\n\n // A single transaction produced by the action.\n // In future this might be moved to a results block that can have multiple transactions.\n transaction: z\n .string()\n .optional()\n .describe(\"The identifier of the transaction this action produces, referencing an entry in the template's transactions.\"),\n\n // The data that is produced by the action.\n // In future this might be moved to a results block that can have multiple data fields.\n data: z.string().optional().describe(\"The identifier of the data field this action produces, referencing an entry in the template's data.\"),\n })\n .strict();\n\n// ============================================================\n// Tokens & Amounts\n// ============================================================\n\n/**\n * Validation schema for the non-fungible token configuration within a token field.\n *\n * ```\n * {\n * \"inputs|outputs\": {\n * \"[id]\": {\n * \"token\": {\n * \"nft\": { } ← this schema\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateNonFungibleTokenDetailsSchema = z\n .object({\n capability: z\n .union([ xoTemplateNftCapabilitySchema, z.string() ])\n .optional()\n .describe('The capability of the NFT. May be a known capability value or a CashASM expression resolving to a capability.'),\n commitment: z.string().optional().describe('The commitment data for the NFT, as a string or CashASM expression resolving to a commitment.'),\n })\n .strict();\n\n/**\n * Validation schema for the token configuration on inputs and outputs.\n *\n * ```\n * {\n * \"inputs|outputs\": {\n * \"[id]\": {\n * \"token\": { } ← this schema\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateTokenSchema = z\n .object({\n category: z.string().optional().describe('The category of the token, as a string or CashASM expression resolving to a category.'),\n amount: z\n .union([ z.bigint(), z.string(), z.null() ])\n .optional()\n .describe('The amount of fungible tokens as a bigint, a CashASM expression resolving to a bigint, or null indicating no FT is present.'),\n nft: xoTemplateNonFungibleTokenDetailsSchema\n .nullable()\n .optional()\n .describe('Non-fungible token configuration. Null indicates no NFT is present.'),\n })\n .strict();\n\n/**\n * Validation schema for the asset amounts configuration. Used by omitChangeAmounts on inputs\n * and by balance on locking scripts, outputs, and their roles.\n */\nexport const xoTemplateAssetAmountsSchema = z\n .object({\n\n /**\n * The satoshi amount.\n * - `Satoshis`: A specific bigint amount.\n * - `string`: A CashASM expression that resolves to the amount.\n * - `true`: all, i.e. the entire amount\n */\n satoshis: z\n .union([ satoshisSchema, z.string(), z.literal(true) ])\n .optional()\n .describe('The satoshi amount. Accepts a bigint for a specific value, a CashASM expression, or true for the entire amount.'),\n\n /**\n * The fungible token amount.\n * - `FungibleTokenAmount`: A specific bigint amount.\n * - `string`: A CashASM expression that resolves to the amount.\n * - `true`: all, i.e. the entire amount\n */\n fungibleTokens: z\n .union([ z.bigint(), z.string(), z.literal(true) ])\n .optional()\n .describe('The fungible token amount. Accepts a bigint for a specific value, a CashASM expression, or true for the entire amount.'),\n\n /**\n * Whether a non-fungible token is present (0 for absent, 1 for present),\n * or a CashASM expression that evaluates to 0 or 1.\n * - `true`: resolves to 1 if an NFT is present, or 0 if none is present. Use this when\n * the NFT is optional, to express that the NFT is estimated to be part of the balance\n * if present, or absent from it if not.\n * - `0`: None, i.e. nothing is expected to be included\n * - `1`: present and complete, as value > 1 does not make sense for non-fungible tokens\n * - `string`: A CashASM expression that evaluates to 0 or 1.\n */\n nonfungibleTokens: z\n .union([ z.literal(0), z.literal(1), z.string(), z.literal(true) ])\n .optional()\n .describe('Whether an NFT is present: 0 for absent, 1 for present, a CashASM expression evaluating to 0 or 1, or true to estimate the NFT as part of the balance if present, or absent from it if not.'),\n })\n .strict();\n\n// ============================================================\n// Locking Scripts\n// ============================================================\n\n/**\n * Validation schema for the state configuration shared by a locking script and its individual roles.\n * Declares which variables and secrets are tracked in the on-chain state for a given participant.\n *\n * ```\n * {\n * \"lockingScripts\": {\n * \"[id]\": {\n * \"state\": { \"variables\": [], \"secrets\": [] } ← this schema\n * \"roles\": {\n * \"[roleId]\": {\n * \"state\": { \"variables\": [], \"secrets\": [] } ← this schema\n * }\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateStateSchema = z\n .object({\n variables: z.array(z.string()).optional().describe('List of variable identifiers to track in state.'),\n secrets: z.array(z.string()).optional().describe('List of secret identifiers to track in state.'),\n })\n .strict();\n\n/**\n * Validation schema for a role definition for a locking script.\n *\n * ```\n * {\n * \"lockingScripts\": {\n * \"[id]\": {\n * \"roles\": {\n * \"[roleId]\": { } ← this schema\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateLockingScriptRoleSchema = xoTemplateViewPropertiesSchema\n .partial()\n .extend({\n state: xoTemplateStateSchema.optional().describe('List of items to track as state for this role.'),\n actions: z.array(xoTemplateActionIntentSchema).optional().describe('List of action references available to this role.'),\n balance: xoTemplateAssetAmountsSchema.partial().optional().describe('Estimated ownership in the optional set of asset amounts specified.'),\n selectable: z.boolean().optional().describe('Whether outputs locked to this script should be available for coin selection.'),\n privacy: z\n .union([ z.number(), z.string() ])\n .optional()\n .describe('Privacy level for outputs locked to this script. A numeric level or a CashASM expression that evaluates to a privacy level.'),\n })\n .strict();\n\n/**\n * Validation schema for a locking script definition.\n *\n * ```\n * {\n * \"lockingScripts\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateLockingScriptSchema = xoTemplateViewPropertiesSchema\n .extend({\n lockingType: xoTemplateLockingTypeSchema.optional().describe('The type of locking mechanism. Defaults to p2s if not specified.'),\n lockingBytecode: z.string().describe('The locking script bytecode.'),\n unlockingBytecode: z.string().optional().describe('Optional default unlocking bytecode when used in automatic coin selection.'),\n actions: z.array(xoTemplateActionIntentSchema).optional().describe('The actions available for this locking script.'),\n state: xoTemplateStateSchema.optional().describe('List of items to track as state for all participants.'),\n balance: xoTemplateAssetAmountsSchema.partial().optional().describe('Estimated ownership in the optional set of asset amounts specified.'),\n selectable: z.boolean().optional().describe('Whether outputs locked to this script should be available for coin selection.'),\n // Might be levels or tags\n privacy: z\n .union([ z.number(), z.string() ])\n .optional()\n .describe('Privacy level for outputs locked to this script. A numeric level or a CashASM expression that evaluates to a privacy level.'),\n roles: z\n .record(z.string(), xoTemplateLockingScriptRoleSchema)\n .optional()\n .describe('Specific context for each role participating in this locking script.'),\n })\n .strict();\n\n// ============================================================\n// Inputs\n// ============================================================\n\n/**\n * Validation schema for an input definition in the template. Extends view properties with optional\n * satoshi value, token configuration, and other transaction level fields.\n *\n * ```\n * {\n * \"inputs\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateInputSchema = xoTemplateViewPropertiesSchema\n .extend({\n valueSatoshis: z\n .union([ satoshisSchema, z.string() ])\n .optional()\n .describe('The amount of satoshis for this input as a bigint or a CashASM expression resolving to the amount.'),\n token: xoTemplateTokenSchema.nullable().optional().describe('Token configuration for this input.'),\n sequenceNumber: z\n .union([ z.number(), z.string() ])\n .optional()\n .describe('The sequence number of this input as a specific number or a CashASM expression.'),\n unlockingScript: z.string().optional().describe('Identifier of the unlocking script to use for the UTXO provided for this input.'),\n omitChangeAmounts: xoTemplateAssetAmountsSchema\n .optional()\n .describe('Amount of change that should be omitted from the automatic change handling. WARNING: Setting this can result in loss of funds!'),\n })\n .strict();\n\n// ============================================================\n// Outputs\n// ============================================================\n\n/**\n * Validation schema for an output definition. Extends the locking script schema so that\n * every output inherits the same locking script fields and adds output-specific fields.\n *\n * ```\n * {\n * \"outputs\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateOutputSchema = xoTemplateLockingScriptSchema\n .omit({ lockingType: true, lockingBytecode: true, unlockingBytecode: true })\n .extend({\n lockingScript: z.string().describe('Identifier of the locking script to use for this output.'),\n valueSatoshis: z\n .union([ satoshisSchema, z.string() ])\n .optional()\n .describe('The amount of satoshis for this output as a bigint or a CashASM expression resolving to the amount.'),\n token: xoTemplateTokenSchema.nullable().optional().describe('Token configuration for this output.'),\n })\n .strict();\n\n// ============================================================\n// Transactions\n// ============================================================\n\n/**\n * Validation schema for a transaction input reference for a transaction definition.\n *\n * ```\n * {\n * \"transactions\": {\n * \"[id]\": {\n * \"inputs\": [\n * { \"input\": \"...\" } ← this schema\n * ]\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateTransactionInputSchema = z\n .object({\n input: z.string().describe('The input definition identifier.'),\n inputIndex: z.number().optional().describe('Optional index of this input in the transaction.'),\n })\n .strict();\n\n/**\n * Validation schema for a transaction output reference for a transaction definition.\n *\n * ```\n * {\n * \"transactions\": {\n * \"[id]\": {\n * \"outputs\": [\n * { \"output\": \"...\" } ← this schema\n * ]\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateTransactionOutputSchema = z\n .object({\n output: z.string().describe('The output definition identifier.'),\n outputIndex: z.number().optional().describe('Optional index of this output in the transaction.'),\n })\n .strict();\n\n/**\n * Validation schema for role-specific data for a transaction definition.\n *\n * ```\n * {\n * \"transactions\": {\n * \"[id]\": {\n * \"roles\": {\n * \"[roleId]\": { } ← this schema\n * }\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateTransactionRoleDataSchema = xoTemplateViewPropertiesSchema\n .partial()\n .extend({\n inputs: z.array(xoTemplateTransactionInputSchema).optional().describe('The inputs required for this role.'),\n outputs: z.array(xoTemplateTransactionOutputSchema).optional().describe('The outputs required for this role.'),\n })\n .strict();\n\n/**\n * Validation schema for a transaction template definition.\n *\n * ```\n * {\n * \"transactions\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateTransactionSchema = xoTemplateViewPropertiesSchema\n .extend({\n version: z.number().optional().describe('The version of the transaction.'),\n locktime: z\n .union([ z.number(), z.string() ])\n .optional()\n .describe('The locktime for this transaction as a specific number or a CashASM expression.'),\n inputs: z.array(xoTemplateTransactionInputSchema).describe('The inputs for this transaction.'),\n outputs: z.array(xoTemplateTransactionOutputSchema).describe('The outputs for this transaction.'),\n roles: z\n .record(z.string(), xoTemplateTransactionRoleDataSchema)\n .optional()\n .describe('Specific context for each role participating in this transaction.'),\n composable: z.boolean().optional().describe('Whether this transaction can be composed with other transactions.'),\n })\n .strict();\n\n// ============================================================\n// Template Data\n// ============================================================\n\n/**\n * Validation schema for a constant value definition.\n *\n * ```\n * {\n * \"constants\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateConstantSchema = xoTemplateViewPropertiesSchema\n .extend({\n type: xoTemplatePrimitiveTypeSchema.describe('The data type of this constant.'),\n value: z.unknown().describe('The value of this constant.'),\n hint: z.string().optional().describe('An optional hint to help apps and users understand what this constant represents.'),\n })\n .strict();\n\n/**\n * Validation schema for a data field definition.\n *\n * ```\n * {\n * \"data\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateDataSchema = z\n .object({\n type: xoTemplatePrimitiveTypeSchema.describe('The data type of this data field.'),\n value: z.unknown().describe('The value for this data field.'),\n hint: z.string().optional().describe('An optional hint to help apps and users understand this data field.'),\n })\n .strict();\n\n/**\n * Validation schema for an import default value intent. Extends the base intent with optional\n * view properties that the engine evaluates at runtime to produce human-readable output.\n *\n * ```\n * {\n * \"variables\": {\n * \"[id]\": {\n * \"importDefaultValue\": { } ← this schema\n * }\n * }\n * }\n * ```\n */\nexport const xoTemplateImportDefaultValueSchema = xoTemplateIntentSchema\n // .shape unwraps the ZodObject to the raw field map { name, description, icon } with each field made optional\n .extend(xoTemplateViewPropertiesSchema.partial().shape)\n .strict();\n\n/**\n * Validation schema for a variable definition.\n *\n * ```\n * {\n * \"variables\": {\n * \"[id]\": { } ← this schema\n * }\n * }\n * ```\n */\nexport const xoTemplateVariableSchema = xoTemplateViewPropertiesSchema\n .extend({\n type: xoTemplatePrimitiveTypeSchema.optional().describe('The data type of this variable.'),\n hint: z.string().optional().describe('A hint to help users understand what value to provide.'),\n\n // A neutral intent that the engine uses to populate the default value for this variable.\n // View properties (name, description, icon) may contain CashASM expressions that the\n // engine evaluates at runtime to produce human-readable output. The engine overrides\n // whatever values are set here when resolving the variable for a participant.\n importDefaultValue: xoTemplateImportDefaultValueSchema\n .optional()\n .describe('A neutral intent that the engine uses to populate the default value for this variable.'),\n })\n .strict();\n\n// ============================================================\n// Template Resources\n// ============================================================\n\n/**\n * Validation schema for a resource reference attached to a template element. Extends view\n * properties with a URL pointing to external documentation or tooling.\n *\n * ```\n * {\n * \"resources\": [\n * { \"name\": \"...\", \"description\": \"...\", \"url\": \"...\" } ← this schema\n * ]\n * }\n * ```\n */\nexport const xoTemplateResourceSchema = xoTemplateViewPropertiesSchema\n .extend({\n url: z.string().describe('The URL for this resource.'),\n })\n .strict();\n\n/**\n * Validation schema for an icon reference.\n *\n * ```\n * {\n * \"icons\": [\n * { \"name\": \"...\", \"hash\": \"...\" } ← this schema\n * ]\n * }\n * ```\n */\nexport const xoTemplateIconSchema = xoTemplateViewPropertiesSchema\n .pick({ name: true })\n .extend({\n hash: z.string().describe('The identifier of the icon.'),\n })\n .strict();\n\n// ============================================================\n// Defaults\n// ============================================================\n\n/**\n * Validation schema for the defaults block of a template.\n *\n * ```\n * {\n * \"defaults\": { } ← this schema\n * }\n * ```\n */\nexport const xoTemplateDefaultsSchema = z\n .object({\n change: xoTemplateOutputIntentSchema.optional().describe('Instructions for how to construct automated change output.'),\n })\n .strict();\n\n// ============================================================\n// Template\n// ============================================================\n\n/**\n * Validation schema for the full XOTemplate type.\n */\nexport const xoTemplateSchema = xoTemplateViewPropertiesSchema\n .extend({\n $schema: z\n .string()\n .describe('The URI that identifies the JSON Schema used by this template. This enables documentation, autocompletion, and validation in JSON documents.'),\n version: z.string().optional().describe('A string identifying the version of this template.'),\n supported: z.array(bchVmVersionSchema).min(1).describe('The BCH VM versions that this template supports. At least one version is required.'),\n defaults: xoTemplateDefaultsSchema.optional().describe('Optional default settings used in this template.'),\n roles: z.record(z.string(), xoTemplateViewPropertiesSchema).describe('The roles defined in this template.'),\n start: z.array(xoTemplateActionIntentSchema).describe('A list of entry points defining which actions are available at the start.'),\n actions: z.record(z.string(), xoTemplateActionSchema).describe('The actions defined in this template.'),\n data: z.record(z.string(), xoTemplateDataSchema).optional().describe('The data fields defined in this template.'),\n transactions: z.record(z.string(), xoTemplateTransactionSchema).optional().describe('The transaction templates defined in this template.'),\n inputs: z.record(z.string(), xoTemplateInputSchema).describe('The inputs defined in this template.'),\n outputs: z.record(z.string(), xoTemplateOutputSchema).describe('The outputs defined in this template.'),\n lockingScripts: z.record(z.string(), xoTemplateLockingScriptSchema).describe('The locking script templates defined in this template.'),\n scripts: z\n .record(z.string(), z.string())\n .describe('Scripts used in this template. Keys are script identifiers, values are bytecode or CashASM expressions.'),\n constants: z.record(z.string(), xoTemplateConstantSchema).optional().describe('The constants defined in this template.'),\n variables: z\n .record(z.string(), xoTemplateVariableSchema)\n .optional()\n .describe(\"The variables that must be provided for use in the template's scripts.\"),\n resources: z.array(xoTemplateResourceSchema).optional().describe('Resource references providing external documentation or tooling links.'),\n icons: z.array(xoTemplateIconSchema).optional().describe('The icons available for use throughout the template.'),\n scenarios: z.unknown().optional().describe('The scenarios defined in this template.'),\n })\n .strict();\n","import type { XOTemplate } from '@xo-cash/types';\nimport { xoTemplateSchema } from './schemas.ts';\nimport { TemplateInvalidError, buildErrorDescription } from './errors.ts';\nimport { deserializeTemplate, serializeTemplate } from './serialization.ts';\n\n/**\n * Accepts a template value and returns a validated XOTemplate object. The input may be\n * either an Extended JSON string or a pre-parsed object. Both are validated\n * against the XOTemplate schema.\n *\n * @param inputTemplate - The value to validate. May be an Extended JSON string or a pre-parsed object.\n * @returns The validated template object\n * @throws {TemplateSerializationFailedError} If a pre-parsed object input cannot be serialized to JSON for normalization.\n * @throws {TemplateJsonMalformedError} If the string input is not valid JSON.\n * @throws {TemplateInvalidError} If the value does not conform to the XOTemplate schema.\n */\nexport const parseTemplate = (inputTemplate: string | XOTemplate): XOTemplate => {\n // Regardless of whether the inputTemplate is a string, an imported template or an in-memory object, serialize and then\n // deserialize it to ensure the output shape is consistent. For example, optional fields explicitly set to 'undefined' would be passed through\n // and then dropped on the string path, resulting in structurally different results for the same template.\n const serializedTemplate = typeof inputTemplate === 'string' ? inputTemplate : serializeTemplate(inputTemplate);\n const templateObject = deserializeTemplate(serializedTemplate);\n\n // Validate the template against the schema.\n const parseResult = xoTemplateSchema.safeParse(templateObject);\n\n if (parseResult.success) {\n // Return the validated template object\n return parseResult.data as XOTemplate;\n }\n\n // Build a human-readable description of every validation failure\n const errorDescription = buildErrorDescription(parseResult.error.issues);\n\n // Throw a typed error with the description\n throw new TemplateInvalidError(errorDescription);\n};\n"],"mappings":";;;;;;;;AAKA,MAAM,+BAA+B;;;;AAKrC,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;AAoBzC,MAAa,wBAAwB,cAAsB,UAA4B;AACnF,KAAI,iBAAiB,WACjB,QAAO,gBAAgB,SAAS,MAAM,CAAC;AAG3C,KAAI,OAAO,UAAU,SACjB,QAAO,YAAY,MAAM,UAAU,CAAC;AAGxC,QAAO;;;;;;;;;;;AAYX,MAAa,uBAAuB,cAAsB,UAA4B;AAElF,KAAI,OAAO,UAA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AAE,MAAM,qBAAqB,CAAC,UAAU,CAAC,SAAS,uDAAuD;CAChH,WAAW,EAAE,SAAS,CAAC,UAAU,CAAC,SAAS,0CAA0C;CACxF,CAAC,CACD,QAAQ;;;;;;;;;;;;;;;ACl3Bb,MAAa,iBAAiB,kBAAmD;CAK7E,MAAM,iBAAiB,oBADI,OAAO,kBAAkB,WAAW,gBAAgB,kBAAkB,cAAc,CACjD;CAG9D,MAAM,cAAc,iBAAiB,UAAU,eAAe;AAE9D,KAAI,YAAY,QAEZ,QAAO,YAAY;AAOvB,OAAM,IAAI,qBAHe,sBAAsB,YAAY,MAAM,OAAO,CAGxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xo-cash/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-development.15414951647",
|
|
4
4
|
"description": "XO Cash utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -44,9 +44,12 @@
|
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@bitauth/libauth": "^3.1.0-next.8",
|
|
47
|
-
"@xo-cash/types": "0.0.
|
|
47
|
+
"@xo-cash/types": "0.0.3",
|
|
48
48
|
"zod": "^4.3.6"
|
|
49
49
|
},
|
|
50
|
+
"overrides": {
|
|
51
|
+
"echarts": "6.1.0"
|
|
52
|
+
},
|
|
50
53
|
"devDependencies": {
|
|
51
54
|
"@chalp/eslint-airbnb": "^1.3.0",
|
|
52
55
|
"@generalprotocols/cspell-dictionary": "^1.0.1",
|