@helios-lang/contract-utils 0.1.20 → 0.1.23

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 (99) hide show
  1. package/examples/multi-validator/README.md +5 -0
  2. package/examples/{spending → multi-validator}/contract.js +7 -2
  3. package/examples/{spending → multi-validator}/index.d.ts +1 -1
  4. package/examples/{spending → multi-validator}/index.js +3 -3
  5. package/examples/{spending → multi-validator}/spending.hl +3 -2
  6. package/package.json +5 -5
  7. package/src/{runtime → cast}/Cast.js +31 -8
  8. package/src/cast/index.js +12 -0
  9. package/src/codegen/LoadedModule.js +9 -0
  10. package/src/codegen/{TypescriptWriter.js → LoadedScriptsWriter.js} +117 -107
  11. package/src/codegen/LoadedValidator.js +23 -0
  12. package/src/codegen/{Module.js → TypeCheckedModule.js} +3 -3
  13. package/src/codegen/{Validator.js → TypeCheckedValidator.js} +5 -8
  14. package/src/codegen/TypeSchema.js +4 -0
  15. package/src/codegen/index.js +5 -4
  16. package/src/compiler/CompilerLib.js +51 -0
  17. package/src/{lib/Libg_v0_16.js → compiler/CompilerLib_v0_16.js} +243 -255
  18. package/src/compiler/index.js +6 -0
  19. package/src/compiler/ops.js +137 -0
  20. package/src/context/ContractContext.js +78 -0
  21. package/src/context/ContractContextBuilder.js +69 -0
  22. package/src/context/DagCompiler.js +229 -0
  23. package/src/context/index.js +1 -0
  24. package/src/hl2ts.js +31 -59
  25. package/src/index.js +12 -1
  26. package/types/cast/Cast.d.ts +32 -0
  27. package/types/cast/Cast.d.ts.map +1 -0
  28. package/types/cast/PermissiveType.d.ts +3 -0
  29. package/types/cast/PermissiveType.d.ts.map +1 -0
  30. package/types/cast/StrictType.d.ts +3 -0
  31. package/types/cast/StrictType.d.ts.map +1 -0
  32. package/types/cast/index.d.ts +5 -0
  33. package/types/cast/index.d.ts.map +1 -0
  34. package/types/codegen/LoadedModule.d.ts +6 -0
  35. package/types/codegen/LoadedModule.d.ts.map +1 -0
  36. package/types/codegen/LoadedScriptsWriter.d.ts +56 -0
  37. package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -0
  38. package/types/codegen/LoadedValidator.d.ts +16 -0
  39. package/types/codegen/LoadedValidator.d.ts.map +1 -0
  40. package/types/codegen/TypeCheckedModule.d.ts +11 -0
  41. package/types/codegen/TypeCheckedModule.d.ts.map +1 -0
  42. package/types/codegen/TypeCheckedValidator.d.ts +8 -0
  43. package/types/codegen/TypeCheckedValidator.d.ts.map +1 -0
  44. package/types/codegen/TypeSchema.d.ts +10 -0
  45. package/types/codegen/TypeSchema.d.ts.map +1 -1
  46. package/types/codegen/TypescriptWriter.d.ts +4 -4
  47. package/types/codegen/Validator.d.ts +1 -1
  48. package/types/codegen/index.d.ts +5 -4
  49. package/types/codegen/index.d.ts.map +1 -1
  50. package/types/compiler/CompilerLib.d.ts +45 -0
  51. package/types/compiler/CompilerLib.d.ts.map +1 -0
  52. package/types/compiler/CompilerLib_v0_16.d.ts +270 -0
  53. package/types/compiler/CompilerLib_v0_16.d.ts.map +1 -0
  54. package/types/compiler/index.d.ts +4 -0
  55. package/types/compiler/index.d.ts.map +1 -0
  56. package/types/compiler/ops.d.ts +24 -0
  57. package/types/compiler/ops.d.ts.map +1 -0
  58. package/types/context/ContractContext.d.ts +23 -0
  59. package/types/context/ContractContext.d.ts.map +1 -0
  60. package/types/context/ContractContextBuilder.d.ts +53 -0
  61. package/types/context/ContractContextBuilder.d.ts.map +1 -0
  62. package/types/context/DagCompiler.d.ts +64 -0
  63. package/types/context/DagCompiler.d.ts.map +1 -0
  64. package/types/context/index.d.ts +2 -0
  65. package/types/context/index.d.ts.map +1 -0
  66. package/types/hl2ts.d.ts +8 -4
  67. package/types/hl2ts.d.ts.map +1 -1
  68. package/types/index.d.ts +4 -1
  69. package/types/index.d.ts.map +1 -1
  70. package/types/lib/Lib.d.ts +13 -71
  71. package/types/lib/Lib.d.ts.map +1 -1
  72. package/types/lib/Libg_v0_16.d.ts +53 -52
  73. package/types/lib/Libg_v0_16.d.ts.map +1 -1
  74. package/types/lib/index.d.ts +0 -1
  75. package/types/lib/index.d.ts.map +1 -1
  76. package/types/lib/load.d.ts +1 -7
  77. package/types/lib/load.d.ts.map +1 -1
  78. package/types/runtime/ContractContext.d.ts +22 -43
  79. package/types/runtime/ContractContext.d.ts.map +1 -1
  80. package/types/runtime/ContractContextBuilder.d.ts +15 -123
  81. package/types/runtime/ContractContextBuilder.d.ts.map +1 -1
  82. package/types/runtime/DagCompiler.d.ts +64 -0
  83. package/types/runtime/DagCompiler.d.ts.map +1 -0
  84. package/types/runtime/PermissiveType.d.ts +1 -1
  85. package/types/runtime/StrictType.d.ts +1 -1
  86. package/types/runtime/index.d.ts +0 -2
  87. package/src/codegen/Writer.js +0 -37
  88. package/src/lib/Lib.js +0 -56
  89. package/src/lib/index.js +0 -6
  90. package/src/lib/load.js +0 -26
  91. package/src/runtime/ContractContext.js +0 -35
  92. package/src/runtime/ContractContextBuilder.js +0 -340
  93. package/src/runtime/index.js +0 -3
  94. /package/examples/{spending → multi-validator}/minting.hl +0 -0
  95. /package/examples/{spending → multi-validator}/package-lock.json +0 -0
  96. /package/examples/{spending → multi-validator}/package.json +0 -0
  97. /package/examples/{spending → multi-validator}/utils.hl +0 -0
  98. /package/src/{runtime → cast}/PermissiveType.js +0 -0
  99. /package/src/{runtime → cast}/StrictType.js +0 -0
@@ -2,14 +2,15 @@ import { bytesToHex } from "@helios-lang/compiler"
2
2
  import { readHeader } from "@helios-lang/compiler-utils"
3
3
 
4
4
  /**
5
- * @typedef {import("../codegen/index.js").Module} ModuleDetails
6
- * @typedef {import("../codegen/index.js").Validator} ValidatorDetails
5
+ * @typedef {import("../codegen/index.js").TypeCheckedModule} TypeCheckedModule
6
+ * @typedef {import("../codegen/index.js").TypeCheckedValidator} TypeCheckedValidator
7
+
7
8
  * @typedef {import("../codegen/index.js").TypeSchema} InternalTypeDetails
8
- * @typedef {import("./Lib.js").CompileOptions} CompileOptions
9
- * @typedef {import("./Lib.js").CompileOutput} CompileOutput
10
- * @typedef {import("./Lib.js").Lib} Lib
11
- * @typedef {import("./Lib.js").LibOptions} LibOptions
12
- * @typedef {import("./Lib.js").SourceDetails} SourceDetails
9
+ * @typedef {import("./CompilerLib.js").CompileOptions} CompileOptions
10
+ * @typedef {import("./CompilerLib.js").CompileOutput} CompileOutput
11
+ * @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
12
+ * @typedef {import("./CompilerLib.js").SourceDetails} SourceDetails
13
+ * @typedef {import("./CompilerLib.js").TypeCheckOutput} TypeCheckOutput
13
14
  */
14
15
 
15
16
  /**
@@ -20,7 +21,7 @@ import { readHeader } from "@helios-lang/compiler-utils"
20
21
 
21
22
  /**
22
23
  * @typedef {{
23
- * }} HashType
24
+ * }} ScriptHashType
24
25
  */
25
26
 
26
27
  /**
@@ -47,7 +48,22 @@ import { readHeader } from "@helios-lang/compiler-utils"
47
48
 
48
49
  /**
49
50
  * @typedef {{
50
- * name: {value: string}
51
+ * src: {
52
+ * raw: string
53
+ * }
54
+ * }} Site
55
+ */
56
+
57
+ /**
58
+ * @typedef {{
59
+ * value: string
60
+ * site: Site
61
+ * }} WordToken
62
+ */
63
+
64
+ /**
65
+ * @typedef {{
66
+ * name: WordToken
51
67
  * filterDependencies: (all: Module[]) => Module[]
52
68
  * statements: Statement[]
53
69
  * }} Module
@@ -55,6 +71,7 @@ import { readHeader } from "@helios-lang/compiler-utils"
55
71
  /**
56
72
  * @typedef {{
57
73
  * name: string
74
+ * purpose: "testing" | "minting" | "spending" | "staking" | "endpoint" | "module" | "unknown"
58
75
  * toIR: (ctx: any, extra: Map<string, IR>) => IR
59
76
  * types: UserTypes
60
77
  * mainImportedModules: Module[]
@@ -111,30 +128,14 @@ import { readHeader } from "@helios-lang/compiler-utils"
111
128
  */
112
129
 
113
130
  /**
114
- * @implements {Lib}
131
+ * @implements {CompilerLib}
115
132
  */
116
- export class Lib_v0_16 {
117
- /**
118
- * @private
119
- * @readonly
120
- * @type {LibOptions}
121
- */
122
- options
123
-
133
+ export class CompilerLib_v0_16 {
124
134
  /**
125
135
  * @param {any} lib
126
- * @param {LibOptions} options
127
136
  */
128
- constructor(lib, options) {
137
+ constructor(lib) {
129
138
  this.lib = lib
130
-
131
- this.lib.config.set({
132
- IS_TESTNET: !(options?.isMainnet ?? false),
133
- CHECK_CASTS: options?.checkCasts ?? false,
134
- IGNORE_UNEVALUATED_CONSTANTS: true
135
- })
136
-
137
- this.options = options
138
139
  }
139
140
 
140
141
  /**
@@ -146,9 +147,9 @@ export class Lib_v0_16 {
146
147
 
147
148
  /**
148
149
  * @param {string} purpose
149
- * @returns {HashType}
150
+ * @returns {ScriptHashType}
150
151
  */
151
- getValidatorType(purpose) {
152
+ getScriptHashType(purpose) {
152
153
  switch (purpose) {
153
154
  case "spending":
154
155
  return this.lib.ValidatorHashType
@@ -161,33 +162,227 @@ export class Lib_v0_16 {
161
162
  }
162
163
  }
163
164
 
165
+ /**
166
+ * @param {string[]} validators
167
+ * @param {string[]} modules
168
+ * @returns {TypeCheckOutput}
169
+ */
170
+ typeCheck(validators, modules) {
171
+ const validatorTypes = Object.fromEntries(
172
+ validators.map((v) => {
173
+ const [purpose, name] = readHeader(v)
174
+ return [name, this.getScriptHashType(purpose)]
175
+ })
176
+ )
177
+
178
+ // create validator programs
179
+ let validatorPrograms = this.createPrograms(
180
+ validators,
181
+ modules,
182
+ validatorTypes
183
+ )
184
+
185
+ // build dag
186
+ const dag = this.buildDagDependencies(validatorPrograms, validatorTypes)
187
+
188
+ /**
189
+ * @type {{[name: string]: TypeCheckedValidator}}
190
+ */
191
+ const typeCheckedValidators = {}
192
+
193
+ /**
194
+ * @type {{[name: string]: TypeCheckedModule}}
195
+ */
196
+ const typeCheckedModules = {}
197
+
198
+ // collect the validators and the modules from the typechecked programs
199
+ for (let v of validatorPrograms) {
200
+ const name = v.name
201
+ const purpose = v.purpose
202
+ const sourceCode = v.mainModule.name.site.src.raw
203
+ const hashDependencies = dag[name]
204
+
205
+ const allModules = v.mainImportedModules
206
+ const moduleDepedencies = v.mainModule
207
+ .filterDependencies(allModules)
208
+ .map((m) => m.name.value)
209
+
210
+ typeCheckedValidators[name] = {
211
+ name: name,
212
+ purpose: purpose,
213
+ sourceCode: sourceCode,
214
+ hashDependencies: hashDependencies,
215
+ moduleDepedencies: moduleDepedencies,
216
+ types: {},
217
+ Redeemer: this.getInternalTypeDetails(
218
+ v.mainArgTypes[purpose == "spending" ? 1 : 0]
219
+ ),
220
+ Datum:
221
+ purpose == "spending"
222
+ ? this.getInternalTypeDetails(v.mainArgTypes[0])
223
+ : undefined
224
+ }
225
+
226
+ // add any module dependencies that haven't been added before
227
+ for (let m of v.mainImportedModules) {
228
+ const name = m.name.value
229
+ const sourceCode = m.name.site.src.raw
230
+
231
+ if (name in typeCheckedModules) {
232
+ continue
233
+ }
234
+
235
+ typeCheckedModules[name] = {
236
+ name: name,
237
+ purpose: "module",
238
+ sourceCode: sourceCode,
239
+ moduleDepedencies: m
240
+ .filterDependencies(allModules)
241
+ .map((m) => m.name.value),
242
+ types: {} // not yet exported
243
+ }
244
+ }
245
+ }
246
+
247
+ return {
248
+ modules: typeCheckedModules,
249
+ validators: typeCheckedValidators
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Generate additional IR definitions
255
+ * * dependency on own precalculated hash (eg. unoptimized program should use hash of optimized program)
256
+ * * dependency on own hash through methods defined on the ScriptContext
257
+ * * dependency on hashes of other validators
258
+ * @private
259
+ * @param {string} name - name of the validator being compiled
260
+ * @param {string} purpose - purpose the validator being compiled
261
+ * @param {number} nPosParams
262
+ * @param {CompileOptions} options
263
+ * @returns {Map<string, IR>}
264
+ */
265
+ generateExtraIRDefinitions(name, purpose, nPosParams, options) {
266
+ /**
267
+ * @type {Map<string, IR>}
268
+ */
269
+ const extra = new Map()
270
+
271
+ const IR = this.lib.IR
272
+
273
+ // inject own hash (either precalculated, or via ScriptContext)
274
+ if (options.ownHash) {
275
+ extra.set(
276
+ `__helios__scripts__${name}`,
277
+ new IR(`#${options.ownHash}`)
278
+ )
279
+ } else if (options.dependsOnOwnHash) {
280
+ const key = `__helios__scripts__${name}`
281
+ let ir = new IR(`__PARAM_${nPosParams - 1}`)
282
+
283
+ switch (purpose) {
284
+ case "spending":
285
+ ir = new IR([
286
+ new IR(
287
+ `__helios__scriptcontext__get_current_validator_hash(`
288
+ ),
289
+ ir,
290
+ new IR(`)()`)
291
+ ])
292
+ break
293
+ case "minting":
294
+ ir = new IR([
295
+ new IR(
296
+ `__helios__scriptcontext__get_current_minting_policy_hash(`
297
+ ),
298
+ ir,
299
+ new IR(`)()`)
300
+ ])
301
+ break
302
+ default:
303
+ throw new Error("unhandled purpose")
304
+ }
305
+
306
+ extra.set(key, ir)
307
+ }
308
+
309
+ // inject hashes of other validators
310
+ Object.entries(options.hashDependencies ?? {}).forEach(
311
+ ([depName, dep]) => {
312
+ extra.set(`__helios__scripts__${depName}`, new IR(`#${dep}`))
313
+ }
314
+ )
315
+
316
+ return extra
317
+ }
318
+
319
+ /**
320
+ * @param {string} main
321
+ * @param {string[]} modules
322
+ * @param {CompileOptions} options
323
+ * @returns {CompileOutput}
324
+ */
325
+ compile(main, modules, options) {
326
+ const [purpose, name] = readHeader(main)
327
+
328
+ // use `Program.newInternal()` instead of `Program.new()` so we can inject custom IR before finally compiling to a UplcProgram
329
+ const program = this.lib.Program.newInternal(
330
+ main,
331
+ modules,
332
+ options.allValidatorHashTypes,
333
+ {
334
+ allowPosParams: false,
335
+ invertEntryPoint: true
336
+ }
337
+ )
338
+
339
+ const extra = this.generateExtraIRDefinitions(
340
+ name,
341
+ purpose,
342
+ program.nPosParams,
343
+ options
344
+ )
345
+ const optimize = options.optimize
346
+ const ir = program.toIR(new this.lib.ToIRContext(optimize), extra)
347
+
348
+ const irProgram =
349
+ program.nPosParams > 0
350
+ ? this.lib.IRParametricProgram.new(
351
+ ir,
352
+ purpose,
353
+ program.nPosParams,
354
+ optimize
355
+ )
356
+ : this.lib.IRProgram.new(ir, purpose, optimize)
357
+
358
+ const cborHex = bytesToHex(irProgram.toUplc().toCbor())
359
+
360
+ return {
361
+ prettyIR: irProgram.program.annotate(),
362
+ cborHex
363
+ }
364
+ }
365
+
164
366
  /**
165
367
  * @private
166
- * @param {SourceDetails[]} validators
167
- * @param {SourceDetails[]} modules
168
- * @param {{[name: string]: HashType}} validatorTypes
368
+ * @param {string[]} validators
369
+ * @param {string[]} modules
370
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
169
371
  * @returns {Program[]}
170
372
  */
171
373
  createPrograms(validators, modules, validatorTypes) {
172
- const moduleSrcs = modules.map((m) => m.sourceCode)
173
-
174
374
  return validators.map((v) =>
175
- this.lib.Program.newInternal(
176
- v.sourceCode,
177
- moduleSrcs,
178
- validatorTypes,
179
- {
180
- allowPosParams: false,
181
- invertEntryPoint: true
182
- }
183
- )
375
+ this.lib.Program.newInternal(v, modules, validatorTypes, {
376
+ allowPosParams: false,
377
+ invertEntryPoint: true
378
+ })
184
379
  )
185
380
  }
186
381
 
187
382
  /**
188
383
  * @private
189
384
  * @param {Program} program
190
- * @param {{[name: string]: HashType}} validatorTypes
385
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
191
386
  * @returns {IR}
192
387
  */
193
388
  toTestIR(program, validatorTypes) {
@@ -206,7 +401,7 @@ export class Lib_v0_16 {
206
401
  /**
207
402
  * @private
208
403
  * @param {Program[]} validators
209
- * @param {{[name: string]: HashType}} validatorTypes
404
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
210
405
  * @returns {DagDependencies}
211
406
  */
212
407
  buildDagDependencies(validators, validatorTypes) {
@@ -227,84 +422,7 @@ export class Lib_v0_16 {
227
422
  }
228
423
 
229
424
  /**
230
- * @param {{[name: string]: SourceDetails}} validators
231
- * @param {{[name: string]: SourceDetails}} modules
232
- * @returns {{modules: {[name: string]: ModuleDetails}, validators: {[name: string]: ValidatorDetails}}}
233
- */
234
- typeCheck(validators, modules) {
235
- const validatorTypes = Object.fromEntries(
236
- Object.values(validators).map((v) => [
237
- v.name,
238
- this.getValidatorType(v.purpose)
239
- ])
240
- )
241
-
242
- // create validator programs
243
- let validatorPrograms = this.createPrograms(
244
- Object.values(validators),
245
- Object.values(modules),
246
- validatorTypes
247
- )
248
-
249
- // build dag
250
- const dag = this.buildDagDependencies(validatorPrograms, validatorTypes)
251
-
252
- // sort the validators according to the dag, a valid order should exist
253
- // validatorPrograms = this.sortValidators(validatorPrograms, dag)
254
-
255
- /**
256
- * @type {{[name: string]: ValidatorDetails}}
257
- */
258
- const validatorDetails = {}
259
-
260
- /**
261
- * @type {{[name: string]: ModuleDetails}}
262
- */
263
- const moduleDetails = {}
264
-
265
- for (let v of validatorPrograms) {
266
- const hashDependencies = dag[v.name]
267
- const allModules = v.mainImportedModules
268
- const moduleDepedencies = v.mainModule
269
- .filterDependencies(allModules)
270
- .map((m) => m.name.value)
271
- const purpose = validators[v.name].purpose
272
-
273
- validatorDetails[v.name] = {
274
- name: v.name,
275
- purpose: validators[v.name].purpose,
276
- sourceCode: validators[v.name].sourceCode,
277
- hashDependencies: hashDependencies,
278
- moduleDepedencies: moduleDepedencies,
279
- types: {},
280
- Redeemer: this.getInternalTypeDetails(
281
- v.mainArgTypes[purpose == "spending" ? 1 : 0]
282
- ),
283
- Datum:
284
- purpose == "spending"
285
- ? this.getInternalTypeDetails(v.mainArgTypes[0])
286
- : undefined
287
- }
288
-
289
- for (let m of v.mainImportedModules) {
290
- if (!(m.name.value in moduleDetails)) {
291
- moduleDetails[m.name.value] = {
292
- name: m.name.value,
293
- purpose: "module",
294
- sourceCode: modules[m.name.value].sourceCode,
295
- moduleDepedencies: m
296
- .filterDependencies(allModules)
297
- .map((m) => m.name.value),
298
- types: {} // not yet exported
299
- }
300
- }
301
- }
302
- }
303
-
304
- return { modules: moduleDetails, validators: validatorDetails }
305
- }
306
-
307
- /**
425
+ * @private
308
426
  * @param {TypeSchema} it
309
427
  * @returns {InternalTypeDetails}
310
428
  */
@@ -341,6 +459,7 @@ export class Lib_v0_16 {
341
459
  }
342
460
 
343
461
  /**
462
+ * @private
344
463
  * @param {DataType} dt
345
464
  * @returns {InternalTypeDetails}
346
465
  */
@@ -357,135 +476,4 @@ export class Lib_v0_16 {
357
476
  }
358
477
  }
359
478
  }
360
-
361
- /**
362
- * @param {string[]} modules
363
- * @returns {string[]}
364
- */
365
- sortModules(modules) {
366
- if (!this.options?.moduleOrder) {
367
- return modules
368
- }
369
-
370
- const n = modules.length
371
- const tmp = modules.slice()
372
-
373
- tmp.sort((a, b) => {
374
- const nameA = readHeader(a)[1]
375
- const nameB = readHeader(b)[1]
376
-
377
- let iA = this.options.moduleOrder?.indexOf(nameA)
378
- let iB = this.options.moduleOrder?.indexOf(nameB)
379
-
380
- if (iA === undefined || iA == -1) {
381
- iA = n
382
- }
383
-
384
- if (iB === undefined || iB == -1) {
385
- iB = n
386
- }
387
-
388
- return iA - iB
389
- })
390
-
391
- return tmp
392
- }
393
-
394
- /**
395
- * @param {string} main
396
- * @param {string[]} modules
397
- * @param {CompileOptions} options
398
- * @returns {CompileOutput}
399
- */
400
- compile(main, modules, options) {
401
- const [purpose, name] = readHeader(main)
402
- const otherValidators = options.otherValidators ?? {}
403
- const otherValidatorTypes = options.allValidatorTypes
404
-
405
- modules = this.sortModules(modules)
406
-
407
- const program = this.lib.Program.newInternal(
408
- main,
409
- modules,
410
- otherValidatorTypes,
411
- {
412
- allowPosParams: false,
413
- invertEntryPoint: true
414
- }
415
- )
416
-
417
- /**
418
- * @type {Map<any, any>}
419
- */
420
- const extra = new Map()
421
- const IR = this.lib.IR
422
-
423
- if (options.ownHash) {
424
- const key = `__helios__scripts__${name}`
425
-
426
- extra.set(key, new IR(`#${options.ownHash}`))
427
- } else if (options.dependsOnOwnHash) {
428
- const key = `__helios__scripts__${name}`
429
- let ir = new IR(`__PARAM_${program.nPosParams - 1}`)
430
-
431
- switch (purpose) {
432
- case "spending":
433
- ir = new IR([
434
- new IR(
435
- `__helios__scriptcontext__get_current_validator_hash(`
436
- ),
437
- ir,
438
- new IR(`)()`)
439
- ])
440
- break
441
- case "minting":
442
- ir = new IR([
443
- new IR(
444
- `__helios__scriptcontext__get_current_minting_policy_hash(`
445
- ),
446
- ir,
447
- new IR(`)()`)
448
- ])
449
- break
450
- default:
451
- throw new Error("unhandled purpose")
452
- }
453
-
454
- extra.set(key, ir)
455
- }
456
-
457
- for (let other in otherValidators) {
458
- const key = `__helios__scripts__${other}`
459
-
460
- extra.set(key, new IR(`#${otherValidators[other].hash}`))
461
- }
462
-
463
- const optimize = options.optimize
464
- const ir = program.toIR(new this.lib.ToIRContext(optimize), extra)
465
-
466
- if (program.nPosParams > 0) {
467
- const irProgram = this.lib.IRParametricProgram.new(
468
- ir,
469
- purpose,
470
- program.nPosParams,
471
- optimize
472
- )
473
-
474
- const cborHex = bytesToHex(irProgram.toUplc().toCbor())
475
-
476
- return {
477
- prettyIR: irProgram.program.annotate(),
478
- cborHex
479
- }
480
- } else {
481
- const irProgram = this.lib.IRProgram.new(ir, purpose, optimize)
482
-
483
- const cborHex = bytesToHex(irProgram.toUplc().toCbor())
484
-
485
- return {
486
- prettyIR: irProgram.program.annotate(),
487
- cborHex
488
- }
489
- }
490
- }
491
479
  }
@@ -0,0 +1,6 @@
1
+ export { loadCompilerLib, typeCheckFiles, typeCheckScripts } from "./ops.js"
2
+
3
+ /**
4
+ * @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
5
+ * @typedef {import("./CompilerLib.js").TypeCheckOutput} TypeCheckOutput
6
+ */