@helios-lang/contract-utils 0.1.20 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/examples/multi-validator/README.md +13 -0
  2. package/examples/multi-validator/contract.js +28 -0
  3. package/examples/{spending → multi-validator}/index.d.ts +3 -3
  4. package/examples/multi-validator/index.js +27 -0
  5. package/examples/multi-validator/minting.hl +5 -0
  6. package/examples/{spending → multi-validator}/package-lock.json +6 -15
  7. package/examples/{spending → multi-validator}/package.json +0 -1
  8. package/examples/multi-validator/spending.hl +18 -0
  9. package/examples/multi-validator/utils.hl +9 -0
  10. package/package.json +7 -6
  11. package/src/{runtime → cast}/Cast.js +31 -8
  12. package/src/cast/index.js +12 -0
  13. package/src/codegen/LoadedModule.js +9 -0
  14. package/src/codegen/{TypescriptWriter.js → LoadedScriptsWriter.js} +149 -108
  15. package/src/codegen/LoadedValidator.js +23 -0
  16. package/src/codegen/{Module.js → TypeCheckedModule.js} +3 -3
  17. package/src/codegen/{Validator.js → TypeCheckedValidator.js} +5 -8
  18. package/src/codegen/TypeSchema.js +6 -2
  19. package/src/codegen/index.js +5 -4
  20. package/src/compiler/CompilerLib.js +51 -0
  21. package/src/{lib/Libg_v0_16.js → compiler/CompilerLib_v0_16.js} +244 -255
  22. package/src/compiler/index.js +6 -0
  23. package/src/compiler/ops.js +137 -0
  24. package/src/context/ContractContext.js +78 -0
  25. package/src/context/ContractContextBuilder.js +69 -0
  26. package/src/context/DagCompiler.js +229 -0
  27. package/src/context/index.js +1 -0
  28. package/src/hl2ts.js +116 -104
  29. package/src/index.js +12 -1
  30. package/types/cast/Cast.d.ts +32 -0
  31. package/types/cast/Cast.d.ts.map +1 -0
  32. package/types/cast/PermissiveType.d.ts +3 -0
  33. package/types/cast/PermissiveType.d.ts.map +1 -0
  34. package/types/cast/StrictType.d.ts +3 -0
  35. package/types/cast/StrictType.d.ts.map +1 -0
  36. package/types/cast/index.d.ts +5 -0
  37. package/types/cast/index.d.ts.map +1 -0
  38. package/types/codegen/LoadedModule.d.ts +6 -0
  39. package/types/codegen/LoadedModule.d.ts.map +1 -0
  40. package/types/codegen/LoadedScriptsWriter.d.ts +57 -0
  41. package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -0
  42. package/types/codegen/LoadedValidator.d.ts +16 -0
  43. package/types/codegen/LoadedValidator.d.ts.map +1 -0
  44. package/types/codegen/TypeCheckedModule.d.ts +11 -0
  45. package/types/codegen/TypeCheckedModule.d.ts.map +1 -0
  46. package/types/codegen/TypeCheckedValidator.d.ts +8 -0
  47. package/types/codegen/TypeCheckedValidator.d.ts.map +1 -0
  48. package/types/codegen/TypeSchema.d.ts +10 -0
  49. package/types/codegen/TypeSchema.d.ts.map +1 -1
  50. package/types/codegen/TypescriptWriter.d.ts +4 -4
  51. package/types/codegen/Validator.d.ts +1 -1
  52. package/types/codegen/index.d.ts +5 -4
  53. package/types/codegen/index.d.ts.map +1 -1
  54. package/types/compiler/CompilerLib.d.ts +45 -0
  55. package/types/compiler/CompilerLib.d.ts.map +1 -0
  56. package/types/compiler/CompilerLib_v0_16.d.ts +271 -0
  57. package/types/compiler/CompilerLib_v0_16.d.ts.map +1 -0
  58. package/types/compiler/index.d.ts +4 -0
  59. package/types/compiler/index.d.ts.map +1 -0
  60. package/types/compiler/ops.d.ts +24 -0
  61. package/types/compiler/ops.d.ts.map +1 -0
  62. package/types/context/ContractContext.d.ts +23 -0
  63. package/types/context/ContractContext.d.ts.map +1 -0
  64. package/types/context/ContractContextBuilder.d.ts +53 -0
  65. package/types/context/ContractContextBuilder.d.ts.map +1 -0
  66. package/types/context/DagCompiler.d.ts +64 -0
  67. package/types/context/DagCompiler.d.ts.map +1 -0
  68. package/types/context/index.d.ts +2 -0
  69. package/types/context/index.d.ts.map +1 -0
  70. package/types/hl2ts.d.ts +9 -4
  71. package/types/hl2ts.d.ts.map +1 -1
  72. package/types/index.d.ts +4 -1
  73. package/types/index.d.ts.map +1 -1
  74. package/types/lib/Lib.d.ts +13 -71
  75. package/types/lib/Lib.d.ts.map +1 -1
  76. package/types/lib/Libg_v0_16.d.ts +53 -52
  77. package/types/lib/Libg_v0_16.d.ts.map +1 -1
  78. package/types/lib/index.d.ts +0 -1
  79. package/types/lib/index.d.ts.map +1 -1
  80. package/types/lib/load.d.ts +1 -7
  81. package/types/lib/load.d.ts.map +1 -1
  82. package/types/runtime/ContractContext.d.ts +22 -43
  83. package/types/runtime/ContractContext.d.ts.map +1 -1
  84. package/types/runtime/ContractContextBuilder.d.ts +15 -123
  85. package/types/runtime/ContractContextBuilder.d.ts.map +1 -1
  86. package/types/runtime/DagCompiler.d.ts +64 -0
  87. package/types/runtime/DagCompiler.d.ts.map +1 -0
  88. package/types/runtime/PermissiveType.d.ts +1 -1
  89. package/types/runtime/StrictType.d.ts +1 -1
  90. package/types/runtime/index.d.ts +0 -2
  91. package/examples/spending/contract.js +0 -16
  92. package/examples/spending/index.js +0 -27
  93. package/examples/spending/minting.hl +0 -5
  94. package/examples/spending/spending.hl +0 -17
  95. package/examples/spending/utils.hl +0 -5
  96. package/src/codegen/Writer.js +0 -37
  97. package/src/lib/Lib.js +0 -56
  98. package/src/lib/index.js +0 -6
  99. package/src/lib/load.js +0 -26
  100. package/src/runtime/ContractContext.js +0 -35
  101. package/src/runtime/ContractContextBuilder.js +0 -340
  102. package/src/runtime/index.js +0 -3
  103. /package/src/{runtime → cast}/PermissiveType.js +0 -0
  104. /package/src/{runtime → cast}/StrictType.js +0 -0
@@ -0,0 +1,271 @@
1
+ /**
2
+ * @typedef {import("../codegen/index.js").TypeCheckedModule} TypeCheckedModule
3
+ * @typedef {import("../codegen/index.js").TypeCheckedValidator} TypeCheckedValidator
4
+ * @typedef {import("../codegen/index.js").TypeSchema} InternalTypeDetails
5
+ * @typedef {import("./CompilerLib.js").CompileOptions} CompileOptions
6
+ * @typedef {import("./CompilerLib.js").CompileOutput} CompileOutput
7
+ * @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
8
+ * @typedef {import("./CompilerLib.js").SourceDetails} SourceDetails
9
+ * @typedef {import("./CompilerLib.js").TypeCheckOutput} TypeCheckOutput
10
+ */
11
+ /**
12
+ * @typedef {{
13
+ * [name: string]: string[]
14
+ * }} DagDependencies
15
+ */
16
+ /**
17
+ * @typedef {{
18
+ * }} ScriptHashType
19
+ */
20
+ /**
21
+ * @typedef {{
22
+ * includes: (m: string) => boolean
23
+ * }} IR
24
+ */
25
+ /**
26
+ * @typedef {{
27
+ * name: string
28
+ * }} EnumStatement
29
+ */
30
+ /**
31
+ * @typedef {{
32
+ * name: string
33
+ * }} StructStatement
34
+ */
35
+ /**
36
+ * @typedef {StructStatement | EnumStatement | any} Statement
37
+ */
38
+ /**
39
+ * @typedef {{
40
+ * src: {
41
+ * raw: string
42
+ * }
43
+ * }} Site
44
+ */
45
+ /**
46
+ * @typedef {{
47
+ * value: string
48
+ * site: Site
49
+ * }} WordToken
50
+ */
51
+ /**
52
+ * @typedef {{
53
+ * name: WordToken
54
+ * filterDependencies: (all: Module[]) => Module[]
55
+ * statements: Statement[]
56
+ * }} Module
57
+ */
58
+ /**
59
+ * @typedef {{
60
+ * name: string
61
+ * purpose: "testing" | "minting" | "spending" | "staking" | "endpoint" | "module" | "unknown"
62
+ * toIR: (ctx: any, extra: Map<string, IR>) => IR
63
+ * types: UserTypes
64
+ * mainImportedModules: Module[]
65
+ * mainModule: Module
66
+ * mainArgTypes: DataType[]
67
+ * }} Program
68
+ */
69
+ /**
70
+ * @typedef {{
71
+ * typeDetails?: TypeDetails
72
+ * }} DataType
73
+ */
74
+ /**
75
+ * @typedef {{
76
+ * type: string
77
+ * } | {
78
+ * type: "List"
79
+ * itemType: TypeSchema
80
+ * } | {
81
+ * type: "Map"
82
+ * keyType: TypeSchema
83
+ * valueType: TypeSchema
84
+ * } | {
85
+ * type: "Option"
86
+ * someType: TypeSchema
87
+ * } | {
88
+ * type: "Struct"
89
+ * fieldTypes: NamedTypeSchema[]
90
+ * } | {
91
+ * type: "Enum"
92
+ * variantTypes: {name: string, fieldTypes: NamedTypeSchema[]}[]
93
+ * }} TypeSchema
94
+ */
95
+ /**
96
+ * @typedef {{
97
+ * name: string
98
+ * } & TypeSchema} NamedTypeSchema
99
+ */
100
+ /**
101
+ * @typedef {{
102
+ * inputType: string
103
+ * outputType: string
104
+ * internalType: TypeSchema
105
+ * }} TypeDetails
106
+ */
107
+ /**
108
+ * @typedef {{
109
+ * }} UserTypes
110
+ */
111
+ /**
112
+ * @implements {CompilerLib}
113
+ */
114
+ export class CompilerLib_v0_16 implements CompilerLib {
115
+ /**
116
+ * @param {any} lib
117
+ */
118
+ constructor(lib: any);
119
+ lib: any;
120
+ /**
121
+ * @type {string}
122
+ */
123
+ get version(): string;
124
+ /**
125
+ * @param {string} purpose
126
+ * @returns {ScriptHashType}
127
+ */
128
+ getScriptHashType(purpose: string): ScriptHashType;
129
+ /**
130
+ * @param {string[]} validators
131
+ * @param {string[]} modules
132
+ * @returns {TypeCheckOutput}
133
+ */
134
+ typeCheck(validators: string[], modules: string[]): TypeCheckOutput;
135
+ /**
136
+ * Generate additional IR definitions
137
+ * * dependency on own precalculated hash (eg. unoptimized program should use hash of optimized program)
138
+ * * dependency on own hash through methods defined on the ScriptContext
139
+ * * dependency on hashes of other validators
140
+ * @private
141
+ * @param {string} name - name of the validator being compiled
142
+ * @param {string} purpose - purpose the validator being compiled
143
+ * @param {number} nPosParams
144
+ * @param {CompileOptions} options
145
+ * @returns {Map<string, IR>}
146
+ */
147
+ private generateExtraIRDefinitions;
148
+ /**
149
+ * @param {string} main
150
+ * @param {string[]} modules
151
+ * @param {CompileOptions} options
152
+ * @returns {CompileOutput}
153
+ */
154
+ compile(main: string, modules: string[], options: CompileOptions): CompileOutput;
155
+ /**
156
+ * @private
157
+ * @param {string[]} validators
158
+ * @param {string[]} modules
159
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
160
+ * @returns {Program[]}
161
+ */
162
+ private createPrograms;
163
+ /**
164
+ * @private
165
+ * @param {Program} program
166
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
167
+ * @returns {IR}
168
+ */
169
+ private toTestIR;
170
+ /**
171
+ * @private
172
+ * @param {Program[]} validators
173
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
174
+ * @returns {DagDependencies}
175
+ */
176
+ private buildDagDependencies;
177
+ /**
178
+ * @private
179
+ * @param {TypeSchema} it
180
+ * @returns {InternalTypeDetails}
181
+ */
182
+ private convertInternalType;
183
+ /**
184
+ * Tries to convert a compiler type into TypeSchema
185
+ * TODO: make sure it works for all structs and enums
186
+ * @private
187
+ * @param {DataType} dt
188
+ * @returns {InternalTypeDetails}
189
+ */
190
+ private getInternalTypeDetails;
191
+ }
192
+ export type TypeCheckedModule = import("../codegen/index.js").TypeCheckedModule;
193
+ export type TypeCheckedValidator = import("../codegen/index.js").TypeCheckedValidator;
194
+ export type InternalTypeDetails = import("../codegen/index.js").TypeSchema;
195
+ export type CompileOptions = import("./CompilerLib.js").CompileOptions;
196
+ export type CompileOutput = import("./CompilerLib.js").CompileOutput;
197
+ export type CompilerLib = import("./CompilerLib.js").CompilerLib;
198
+ export type SourceDetails = import("./CompilerLib.js").SourceDetails;
199
+ export type TypeCheckOutput = import("./CompilerLib.js").TypeCheckOutput;
200
+ export type DagDependencies = {
201
+ [name: string]: string[];
202
+ };
203
+ export type ScriptHashType = {};
204
+ export type IR = {
205
+ includes: (m: string) => boolean;
206
+ };
207
+ export type EnumStatement = {
208
+ name: string;
209
+ };
210
+ export type StructStatement = {
211
+ name: string;
212
+ };
213
+ export type Statement = StructStatement | EnumStatement | any;
214
+ export type Site = {
215
+ src: {
216
+ raw: string;
217
+ };
218
+ };
219
+ export type WordToken = {
220
+ value: string;
221
+ site: Site;
222
+ };
223
+ export type Module = {
224
+ name: WordToken;
225
+ filterDependencies: (all: Module[]) => Module[];
226
+ statements: Statement[];
227
+ };
228
+ export type Program = {
229
+ name: string;
230
+ purpose: "testing" | "minting" | "spending" | "staking" | "endpoint" | "module" | "unknown";
231
+ toIR: (ctx: any, extra: Map<string, IR>) => IR;
232
+ types: UserTypes;
233
+ mainImportedModules: Module[];
234
+ mainModule: Module;
235
+ mainArgTypes: DataType[];
236
+ };
237
+ export type DataType = {
238
+ typeDetails?: TypeDetails;
239
+ };
240
+ export type TypeSchema = {
241
+ type: string;
242
+ } | {
243
+ type: "List";
244
+ itemType: TypeSchema;
245
+ } | {
246
+ type: "Map";
247
+ keyType: TypeSchema;
248
+ valueType: TypeSchema;
249
+ } | {
250
+ type: "Option";
251
+ someType: TypeSchema;
252
+ } | {
253
+ type: "Struct";
254
+ fieldTypes: NamedTypeSchema[];
255
+ } | {
256
+ type: "Enum";
257
+ variantTypes: {
258
+ name: string;
259
+ fieldTypes: NamedTypeSchema[];
260
+ }[];
261
+ };
262
+ export type NamedTypeSchema = {
263
+ name: string;
264
+ } & TypeSchema;
265
+ export type TypeDetails = {
266
+ inputType: string;
267
+ outputType: string;
268
+ internalType: TypeSchema;
269
+ };
270
+ export type UserTypes = {};
271
+ //# sourceMappingURL=CompilerLib_v0_16.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompilerLib_v0_16.d.ts","sourceRoot":"","sources":["../../src/compiler/CompilerLib_v0_16.js"],"names":[],"mappings":"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"}
@@ -0,0 +1,4 @@
1
+ export type CompilerLib = import("./CompilerLib.js").CompilerLib;
2
+ export type TypeCheckOutput = import("./CompilerLib.js").TypeCheckOutput;
3
+ export { loadCompilerLib, typeCheckFiles, typeCheckScripts } from "./ops.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.js"],"names":[],"mappings":"0BAGa,OAAO,kBAAkB,EAAE,WAAW;8BACtC,OAAO,kBAAkB,EAAE,eAAe"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The compiler library is passed as an argument instead of loading locally, so any optional configuration of the library can be done externally
3
+ * @returns {CompilerLib}
4
+ */
5
+ export function loadCompilerLib(): CompilerLib;
6
+ /**
7
+ * The compiler library is passed as an argument instead of loading locally, so any optional configuration of the library can be done externally
8
+ * @param {CompilerLib} lib
9
+ * @param {{[path: string]: string}} files
10
+ * @param {(current: string, rel: string) => string} relToAbs
11
+ * @returns {TypeCheckOutput}
12
+ */
13
+ export function typeCheckFiles(lib: CompilerLib, files: {
14
+ [path: string]: string;
15
+ }, relToAbs: (current: string, rel: string) => string): TypeCheckOutput;
16
+ /**
17
+ * @param {CompilerLib} lib
18
+ * @param {string[]} scripts
19
+ * @returns {TypeCheckOutput}
20
+ */
21
+ export function typeCheckScripts(lib: CompilerLib, scripts: string[]): TypeCheckOutput;
22
+ export type CompilerLib = import("./CompilerLib.js").CompilerLib;
23
+ export type TypeCheckOutput = import("./CompilerLib.js").TypeCheckOutput;
24
+ //# sourceMappingURL=ops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ops.d.ts","sourceRoot":"","sources":["../../src/compiler/ops.js"],"names":[],"mappings":"AAoBA;;;GAGG;AACH,mCAFa,WAAW,CAgBvB;AAED;;;;;;GAMG;AACH,oCALW,WAAW;;uBAED,MAAM,OAAO,MAAM,KAAK,MAAM,GACtC,eAAe,CAM3B;AAED;;;;GAIG;AACH,sCAJW,WAAW,WACX,MAAM,EAAE,GACN,eAAe,CAM3B;0BAtDY,OAAO,kBAAkB,EAAE,WAAW;8BACtC,OAAO,kBAAkB,EAAE,eAAe"}
@@ -0,0 +1,23 @@
1
+ export type LoadedValidator = import("../codegen/index.js").LoadedValidator;
2
+ export type MintingContext<TRedeemerStrict, TRedeemerPermissive> = import("@helios-lang/ledger").MintingContext<TRedeemerStrict, TRedeemerPermissive>;
3
+ export type SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive> = import("@helios-lang/ledger").SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive>;
4
+ export type StakingContext<TRedeemerStrict, TRedeemerPermissive> = import("@helios-lang/ledger").StakingContext<TRedeemerStrict, TRedeemerPermissive>;
5
+ export type PermissiveType<C extends Cast<any, any>> = import("../cast/index.js").PermissiveType<C>;
6
+ export type StrictType<C extends Cast<any, any>> = import("../cast/index.js").StrictType<C>;
7
+ export type AnyContractValidatorHash = (ValidatorHash<SpendingContext<any, any, any, any>> | MintingPolicyHash<MintingContext<any, any>> | StakingValidatorHash<StakingContext<any, any>>);
8
+ export type ContractValidatorHash<V extends import("../codegen/LoadedValidator.js").LoadedValidator> = V extends {
9
+ "$purpose": "spending";
10
+ "$Datum": Cast;
11
+ } ? ValidatorHash<SpendingContext<StrictType<V["$Datum"]>, PermissiveType<V["$Datum"]>, StrictType<V["$Redeemer"]>, PermissiveType<V["$Redeemer"]>>> : V extends {
12
+ "$purpose": "minting";
13
+ } ? MintingPolicyHash<MintingContext<StrictType<V["$Redeemer"]>, PermissiveType<V["$Redeemer"]>>> : V extends {
14
+ "$purpose": ("certifying" | "rewarding");
15
+ } ? StakingValidatorHash<StakingContext<StrictType<V["$Redeemer"]>, PermissiveType<V["$Redeemer"]>>> : never;
16
+ export type ContractContext<T extends {
17
+ [name: string]: import("../codegen/LoadedValidator.js").LoadedValidator;
18
+ }> = { [K in keyof T]: ContractValidatorHash<T[K]>; };
19
+ import { Cast } from "../cast/index.js";
20
+ import { ValidatorHash } from "@helios-lang/ledger";
21
+ import { MintingPolicyHash } from "@helios-lang/ledger";
22
+ import { StakingValidatorHash } from "@helios-lang/ledger";
23
+ //# sourceMappingURL=ContractContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractContext.d.ts","sourceRoot":"","sources":["../../src/context/ContractContext.js"],"names":[],"mappings":"8BAQa,OAAO,qBAAqB,EAAE,eAAe;mEAM7C,OAAO,qBAAqB,EAAE,cAAc,CAAC,eAAe,EAAE,mBAAmB,CAAC;oGAQlF,OAAO,qBAAqB,EAAE,eAAe,CAAC,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,CAAC;mEAMnH,OAAO,qBAAqB,EAAE,cAAc,CAAC,eAAe,EAAE,mBAAmB,CAAC;uDAKlF,OAAO,kBAAkB,EAAE,cAAc,CAAC,CAAC,CAAC;mDAK5C,OAAO,kBAAkB,EAAE,UAAU,CAAC,CAAC,CAAC;uCAIxC,CACZ,cAAkB,gBAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,GACtD,kBAAsB,eAAe,GAAG,EAAE,GAAG,CAAC,CAAC,GAC/C,qBAAyB,eAAe,GAAG,EAAE,GAAG,CAAC,CAAC,CAC/C;uGAKS,CAAC,SAAS;IAAC,UAAU,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAA;CAAC,GAAG,cACjE,gBACA,WAAqB,CAAC,CAAC,QAAQ,CAAC,CAAC,EACjC,eAAyB,CAAC,CAAC,QAAQ,CAAC,CAAC,EACrC,WAAqB,CAAC,CAAC,WAAW,CAAC,CAAC,EACpC,eAAyB,CAAC,CAAC,WAAW,CAAC,CAAC,CAC/B,CACF,GACP,CAAO,SAAS;IAAC,UAAU,EAAE,SAAS,CAAA;CAAC,GAAG,kBAC1C,eACA,WAAqB,CAAC,CAAC,WAAW,CAAC,CAAC,EACpC,eAAyB,CAAC,CAAC,WAAW,CAAC,CAAC,CAC/B,CACF,GACP,CAAO,SAAS;IAAC,UAAU,EAAE,CAAC,YAAY,GAAG,WAAW,CAAC,CAAA;CAAC,GAAG,qBAC7D,eACA,WAAqB,CAAC,CAAC,WAAW,CAAC,CAAC,EACpC,eAAyB,CAAC,CAAC,WAAW,CAAC,CAAC,CAC/B,CACF,GAAG,KAAK;;;;qBAjEK,kBAAkB;8BADhC,qBAAqB;kCAArB,qBAAqB;qCAArB,qBAAqB"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @typedef {import("../codegen/LoadedModule.js").LoadedModule} LoadedModule
3
+ * @typedef {import("../codegen/LoadedValidator.js").LoadedValidator} LoadedValidator
4
+ * @typedef {import("../compiler/index.js").CompilerLib} CompilerLib
5
+ */
6
+ /**
7
+ * @template {{[name: string]: LoadedValidator}} T
8
+ * @typedef {import("./ContractContext.js").ContractContext<T>} ContractContext
9
+ */
10
+ /**
11
+ * @template {{[name: string]: LoadedValidator}} T
12
+ */
13
+ export class ContractContextBuilder<T extends {
14
+ [name: string]: import("./DagCompiler.js").LoadedValidator;
15
+ }> {
16
+ /**
17
+ * @returns {ContractContextBuilder<{}>}
18
+ */
19
+ static "new"(): ContractContextBuilder<{}>;
20
+ /**
21
+ * @private
22
+ * @param {T} validators
23
+ */
24
+ private constructor();
25
+ /**
26
+ * @private
27
+ * @readonly
28
+ * @type {T}
29
+ */
30
+ private readonly validators;
31
+ /**
32
+ * @template {LoadedValidator} V
33
+ * @param {V} validator
34
+ * @returns {ContractContextBuilder<T & {
35
+ * [K in V["$name"]]: V
36
+ * }>}
37
+ */
38
+ with<V extends import("./DagCompiler.js").LoadedValidator>(validator: V): ContractContextBuilder<T & { [K in V["$name"]]: V; }>;
39
+ /**
40
+ * @param {Option<{[name: string]: string}>} expectedHashes
41
+ * @returns {ContractContext<T>}
42
+ */
43
+ build(expectedHashes?: Option<{
44
+ [name: string]: string;
45
+ }>): ContractContext<T>;
46
+ }
47
+ export type LoadedModule = import("../codegen/LoadedModule.js").LoadedModule;
48
+ export type LoadedValidator = import("../codegen/LoadedValidator.js").LoadedValidator;
49
+ export type CompilerLib = import("../compiler/index.js").CompilerLib;
50
+ export type ContractContext<T extends {
51
+ [name: string]: import("./DagCompiler.js").LoadedValidator;
52
+ }> = import("./ContractContext.js").ContractContext<T>;
53
+ //# sourceMappingURL=ContractContextBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractContextBuilder.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextBuilder.js"],"names":[],"mappings":"AAIA;;;;GAIG;AAEH;;;GAGG;AAEH;;GAEG;AACH;;;IAgBI;;OAEG;IACH,gBAFa,uBAAuB,EAAE,CAAC,CAItC;IAbD;;;OAGG;IACH,sBAEC;IAbD;;;;OAIG;IACH,4BAAU;IAiBV;;;;;;OAMG;IACH,gIAKC;IAED;;;OAGG;IACH;;SAFa,gBAAgB,CAAC,CAAC,CAU9B;CACJ;2BA/DY,OAAO,4BAA4B,EAAE,YAAY;8BACjD,OAAO,+BAA+B,EAAE,eAAe;0BACvD,OAAO,sBAAsB,EAAE,WAAW;;;KAK1C,OAAO,sBAAsB,EAAE,eAAe,CAAC,CAAC,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @param {LoadedValidator} validator
3
+ * @returns {string[]}
4
+ */
5
+ export function getModuleDependencies(validator: LoadedValidator): string[];
6
+ /**
7
+ * @typedef {import("../codegen/LoadedValidator.js").LoadedValidator} LoadedValidator
8
+ * @typedef {import("../compiler/index.js").CompilerLib} CompilerLib
9
+ * @typedef {import("./ContractContext.js").AnyContractValidatorHash} AnyContractValidatorHash
10
+ */
11
+ /**
12
+ * Compiles a set of validators that depend on eachothers hashes (forming a Directed Acyclical Graph)
13
+ */
14
+ export class DagCompiler {
15
+ /**
16
+ * @param {CompilerLib} lib
17
+ */
18
+ constructor(lib: CompilerLib);
19
+ /**
20
+ * @private
21
+ * @readonly
22
+ * @type {CompilerLib}
23
+ */
24
+ private readonly lib;
25
+ /**
26
+ * @private
27
+ * @readonly
28
+ * @type {{[name: string]: AnyContractValidatorHash}}
29
+ */
30
+ private readonly cache;
31
+ /**
32
+ * @param {LoadedValidator[]} validators
33
+ * @param {Option<{[name: string]: string}>} expectedHashes
34
+ * @returns {{[name: string]: AnyContractValidatorHash}}
35
+ */
36
+ build(validators: LoadedValidator[], expectedHashes?: Option<{
37
+ [name: string]: string;
38
+ }>): {
39
+ [name: string]: import("./ContractContext.js").AnyContractValidatorHash;
40
+ };
41
+ /**
42
+ * @private
43
+ * @param {LoadedValidator} validator
44
+ * @param {UplcProgramV2} program
45
+ * @param {string} hash - although this can be derived from `program`, reuse this to save some effort
46
+ */
47
+ private addToCache;
48
+ /**
49
+ * @private
50
+ * @param {LoadedValidator} validator
51
+ * @returns {{[name: string]: string}} - TODO: do we really need the purpose?
52
+ */
53
+ private getHashDependencies;
54
+ /**
55
+ * @private
56
+ * @param {LoadedValidator[]} validators
57
+ * @returns {{[name: string]: any}}
58
+ */
59
+ private getHashTypes;
60
+ }
61
+ export type LoadedValidator = import("../codegen/LoadedValidator.js").LoadedValidator;
62
+ export type CompilerLib = import("../compiler/index.js").CompilerLib;
63
+ export type AnyContractValidatorHash = import("./ContractContext.js").AnyContractValidatorHash;
64
+ //# sourceMappingURL=DagCompiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DagCompiler.d.ts","sourceRoot":"","sources":["../../src/context/DagCompiler.js"],"names":[],"mappings":"AA4MA;;;GAGG;AACH,iDAHW,eAAe,GACb,MAAM,EAAE,CAsBpB;AA3ND;;;;GAIG;AAEH;;GAEG;AACH;IAeI;;OAEG;IACH,iBAFW,WAAW,EAKrB;IApBD;;;;OAIG;IACH,qBAAG;IAEH;;;;OAIG;IACH,uBAAK;IAUL;;;;OAIG;IACH,kBAJW,eAAe,EAAE;;;;MAkF3B;IAED;;;;;OAKG;IACH,mBA6BC;IAED;;;;OAIG;IACH,4BAoBC;IAED;;;;OAIG;IACH,qBAMC;CACJ;8BAhMY,OAAO,+BAA+B,EAAE,eAAe;0BACvD,OAAO,sBAAsB,EAAE,WAAW;uCAC1C,OAAO,sBAAsB,EAAE,wBAAwB"}
@@ -0,0 +1,2 @@
1
+ export { ContractContextBuilder } from "./ContractContextBuilder.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.js"],"names":[],"mappings":""}
package/types/hl2ts.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env node
2
- export type Lib = import("./lib/Lib.js").Lib;
3
- export type SourceDetails = import("./lib/Lib.js").SourceDetails;
4
- export type ModuleDetails = import("./lib/Lib.js").ModuleDetails;
5
- export type ValidatorDetails = import("./lib/Lib.js").ValidatorDetails;
2
+ export type CompilerLib = import("./compiler/CompilerLib.js").CompilerLib;
3
+ export type ModuleDetails = import("./compiler/CompilerLib.js").TypeCheckedModule;
4
+ export type ValidatorDetails = import("./compiler/CompilerLib.js").TypeCheckedValidator;
5
+ export type SourceDetails = {
6
+ name: string;
7
+ purpose: string;
8
+ sourceCode: string;
9
+ };
10
+ export type FormatKind = "javascript" | "typescript";
6
11
  //# sourceMappingURL=hl2ts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hl2ts.d.ts","sourceRoot":"","sources":["../src/hl2ts.js"],"names":[],"mappings":";kBASa,OAAO,cAAc,EAAE,GAAG;4BAC1B,OAAO,cAAc,EAAE,aAAa;4BACpC,OAAO,cAAc,EAAE,aAAa;+BACpC,OAAO,cAAc,EAAE,gBAAgB"}
1
+ {"version":3,"file":"hl2ts.d.ts","sourceRoot":"","sources":["../src/hl2ts.js"],"names":[],"mappings":";0BAiBa,OAAO,2BAA2B,EAAE,WAAW;4BAC/C,OAAO,2BAA2B,EAAE,iBAAiB;+BACrD,OAAO,2BAA2B,EAAE,oBAAoB;4BAIxD;IACZ,MAAU,MAAM,CAAA;IAChB,OAAW,EAAE,MAAM,CAAA;IACnB,UAAc,EAAE,MAAM,CAAA;CACnB;yBAIS,YAAY,GAAG,YAAY"}
package/types/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- export { Cast, ContractContextBuilder } from "./runtime/index.js";
1
+ export { Cast } from "./cast/index.js";
2
+ export { ContractContextBuilder } from "./context/index.js";
3
+ export type StrictType<C extends import("./cast/Cast.js").Cast<any, any>> = import("./cast/index.js").StrictType<C>;
4
+ export type PermissiveType<C extends import("./cast/Cast.js").Cast<any, any>> = import("./cast/index.js").PermissiveType<C>;
2
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;4EAKa,OAAO,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;gFAKvC,OAAO,iBAAiB,EAAE,cAAc,CAAC,CAAC,CAAC"}
@@ -1,62 +1,12 @@
1
- /**
2
- * @typedef {{
3
- * allValidatorTypes: {[name: string]: any},
4
- * otherValidators: {[name: string]: {purpose: string, hash: string}},
5
- * dependsOnOwnHash?: boolean,
6
- * ownHash?: string,
7
- * optimize: boolean
8
- * }} CompileOptions
9
- */
10
- /**
11
- * @typedef {{
12
- * cborHex: string
13
- * prettyIR: string
14
- * }} CompileOutput
15
- */
16
- /**
17
- * @typedef {{
18
- * isMainnet?: boolean
19
- * checkCasts?: boolean
20
- * moduleOrder?: string[]
21
- * }} LibOptions
22
- */
23
- /**
24
- * @typedef {{
25
- * version: string
26
- * getValidatorType: (purpose: string) => any
27
- * typeCheck: (validators: {[name: string]: SourceDetails}, modules: {[name: string]: SourceDetails}) => ({
28
- * modules: {[name: string]: ModuleDetails}, validators: {[name: string]: ValidatorDetails}})
29
- * compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput
30
- * }} Lib
31
- */
32
- /**
33
- * @typedef {import("../codegen/index.js").TypeSchema} InternalTypeDetails
34
- * @typedef {import("../codegen/index.js").Module} ModuleDetails
35
- * @typedef {import("../codegen/index.js").Validator} ValidatorDetails
36
- */
37
- /**
38
- * @typedef {{
39
- * name: string
40
- * purpose: string
41
- * sourceCode: string
42
- * }} SourceDetails
43
- */
44
- /**
45
- * @param {{VERSION: string}} lib
46
- * @returns {number[]}
47
- */
48
- export function getVersion(lib: {
49
- VERSION: string;
50
- }): number[];
1
+ export type InternalTypeDetails = import("../codegen/index.js").TypeSchema;
2
+ export type TypeCheckedModule = import("../codegen/index.js").TypeCheckedModule;
3
+ export type TypeCheckedValidator = import("../codegen/index.js").TypeCheckedValidator;
51
4
  export type CompileOptions = {
52
- allValidatorTypes: {
5
+ allValidatorHashTypes: {
53
6
  [name: string]: any;
54
7
  };
55
- otherValidators: {
56
- [name: string]: {
57
- purpose: string;
58
- hash: string;
59
- };
8
+ hashDependencies: {
9
+ [name: string]: string;
60
10
  };
61
11
  dependsOnOwnHash?: boolean | undefined;
62
12
  ownHash?: string | undefined;
@@ -66,34 +16,26 @@ export type CompileOutput = {
66
16
  cborHex: string;
67
17
  prettyIR: string;
68
18
  };
69
- export type LibOptions = {
70
- isMainnet?: boolean;
71
- checkCasts?: boolean;
72
- moduleOrder?: string[];
19
+ export type SourceDetails = {
20
+ name: string;
21
+ purpose: string;
22
+ sourceCode: string;
73
23
  };
74
24
  export type Lib = {
75
25
  version: string;
76
- getValidatorType: (purpose: string) => any;
26
+ getScriptHashType: (purpose: string) => any;
77
27
  typeCheck: (validators: {
78
28
  [name: string]: SourceDetails;
79
29
  }, modules: {
80
30
  [name: string]: SourceDetails;
81
31
  }) => {
82
32
  modules: {
83
- [name: string]: import("../codegen/Module.js").Module;
33
+ [name: string]: import("../codegen/TypeCheckedModule.js").TypeCheckedModule;
84
34
  };
85
35
  validators: {
86
- [name: string]: import("../codegen/Validator.js").Validator;
36
+ [name: string]: import("../codegen/TypeCheckedValidator.js").TypeCheckedValidator;
87
37
  };
88
38
  };
89
39
  compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput;
90
40
  };
91
- export type InternalTypeDetails = import("../codegen/index.js").TypeSchema;
92
- export type ModuleDetails = import("../codegen/index.js").Module;
93
- export type ValidatorDetails = import("../codegen/index.js").Validator;
94
- export type SourceDetails = {
95
- name: string;
96
- purpose: string;
97
- sourceCode: string;
98
- };
99
41
  //# sourceMappingURL=Lib.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Lib.d.ts","sourceRoot":"","sources":["../../src/lib/Lib.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;;;;GAQG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;GAGG;AACH,gCAHW;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,GACf,MAAM,EAAE,CAIpB;;;;;;;qBApDgD,MAAM;kBAAQ,MAAM;;;;;cAGtD,OAAO;;4BAKT;IACZ,OAAW,EAAE,MAAM,CAAA;IACnB,QAAY,EAAE,MAAM,CAAA;CACjB;yBAIS;IACZ,SAAa,CAAC,EAAE,OAAO,CAAA;IACvB,UAAc,CAAC,EAAE,OAAO,CAAA;IACxB,WAAe,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB;;aAKU,MAAM;gCACa,MAAM,KAAK,GAAG;;;;;;;;;;;;;oBAG1B,MAAM,WAAW,MAAM,EAAE,WAAW,cAAc,KAAK,aAAa;;kCAK5E,OAAO,qBAAqB,EAAE,UAAU;4BACxC,OAAO,qBAAqB,EAAE,MAAM;+BACpC,OAAO,qBAAqB,EAAE,SAAS;4BAIvC;IACZ,MAAU,MAAM,CAAA;IAChB,OAAW,EAAE,MAAM,CAAA;IACnB,UAAc,EAAE,MAAM,CAAA;CACnB"}
1
+ {"version":3,"file":"Lib.d.ts","sourceRoot":"","sources":["../../src/lib/Lib.js"],"names":[],"mappings":"kCAGa,OAAO,qBAAqB,EAAE,UAAU;gCACxC,OAAO,qBAAqB,EAAE,iBAAiB;mCAC/C,OAAO,qBAAqB,EAAE,oBAAoB;;;;;;;;;;cAShD,OAAO;;4BAKT;IACZ,OAAW,EAAE,MAAM,CAAA;IACnB,QAAY,EAAE,MAAM,CAAA;CACjB;4BAIS;IACZ,MAAU,MAAM,CAAA;IAChB,OAAW,EAAE,MAAM,CAAA;IACnB,UAAc,EAAE,MAAM,CAAA;CACnB;;aAKU,MAAM;iCACc,MAAM,KAAK,GAAG;;;;;;;;;;;;;oBAK3B,MAAM,WAAW,MAAM,EAAE,WAAW,cAAc,KAAK,aAAa"}