@helios-lang/contract-utils 0.1.19 → 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 +6 -6
  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 -254
  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,29 +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
- })
135
-
136
- this.options = options
137
139
  }
138
140
 
139
141
  /**
@@ -145,9 +147,9 @@ export class Lib_v0_16 {
145
147
 
146
148
  /**
147
149
  * @param {string} purpose
148
- * @returns {HashType}
150
+ * @returns {ScriptHashType}
149
151
  */
150
- getValidatorType(purpose) {
152
+ getScriptHashType(purpose) {
151
153
  switch (purpose) {
152
154
  case "spending":
153
155
  return this.lib.ValidatorHashType
@@ -160,33 +162,227 @@ export class Lib_v0_16 {
160
162
  }
161
163
  }
162
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
+
163
366
  /**
164
367
  * @private
165
- * @param {SourceDetails[]} validators
166
- * @param {SourceDetails[]} modules
167
- * @param {{[name: string]: HashType}} validatorTypes
368
+ * @param {string[]} validators
369
+ * @param {string[]} modules
370
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
168
371
  * @returns {Program[]}
169
372
  */
170
373
  createPrograms(validators, modules, validatorTypes) {
171
- const moduleSrcs = modules.map((m) => m.sourceCode)
172
-
173
374
  return validators.map((v) =>
174
- this.lib.Program.newInternal(
175
- v.sourceCode,
176
- moduleSrcs,
177
- validatorTypes,
178
- {
179
- allowPosParams: false,
180
- invertEntryPoint: true
181
- }
182
- )
375
+ this.lib.Program.newInternal(v, modules, validatorTypes, {
376
+ allowPosParams: false,
377
+ invertEntryPoint: true
378
+ })
183
379
  )
184
380
  }
185
381
 
186
382
  /**
187
383
  * @private
188
384
  * @param {Program} program
189
- * @param {{[name: string]: HashType}} validatorTypes
385
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
190
386
  * @returns {IR}
191
387
  */
192
388
  toTestIR(program, validatorTypes) {
@@ -205,7 +401,7 @@ export class Lib_v0_16 {
205
401
  /**
206
402
  * @private
207
403
  * @param {Program[]} validators
208
- * @param {{[name: string]: HashType}} validatorTypes
404
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
209
405
  * @returns {DagDependencies}
210
406
  */
211
407
  buildDagDependencies(validators, validatorTypes) {
@@ -226,84 +422,7 @@ export class Lib_v0_16 {
226
422
  }
227
423
 
228
424
  /**
229
- * @param {{[name: string]: SourceDetails}} validators
230
- * @param {{[name: string]: SourceDetails}} modules
231
- * @returns {{modules: {[name: string]: ModuleDetails}, validators: {[name: string]: ValidatorDetails}}}
232
- */
233
- typeCheck(validators, modules) {
234
- const validatorTypes = Object.fromEntries(
235
- Object.values(validators).map((v) => [
236
- v.name,
237
- this.getValidatorType(v.purpose)
238
- ])
239
- )
240
-
241
- // create validator programs
242
- let validatorPrograms = this.createPrograms(
243
- Object.values(validators),
244
- Object.values(modules),
245
- validatorTypes
246
- )
247
-
248
- // build dag
249
- const dag = this.buildDagDependencies(validatorPrograms, validatorTypes)
250
-
251
- // sort the validators according to the dag, a valid order should exist
252
- // validatorPrograms = this.sortValidators(validatorPrograms, dag)
253
-
254
- /**
255
- * @type {{[name: string]: ValidatorDetails}}
256
- */
257
- const validatorDetails = {}
258
-
259
- /**
260
- * @type {{[name: string]: ModuleDetails}}
261
- */
262
- const moduleDetails = {}
263
-
264
- for (let v of validatorPrograms) {
265
- const hashDependencies = dag[v.name]
266
- const allModules = v.mainImportedModules
267
- const moduleDepedencies = v.mainModule
268
- .filterDependencies(allModules)
269
- .map((m) => m.name.value)
270
- const purpose = validators[v.name].purpose
271
-
272
- validatorDetails[v.name] = {
273
- name: v.name,
274
- purpose: validators[v.name].purpose,
275
- sourceCode: validators[v.name].sourceCode,
276
- hashDependencies: hashDependencies,
277
- moduleDepedencies: moduleDepedencies,
278
- types: {},
279
- Redeemer: this.getInternalTypeDetails(
280
- v.mainArgTypes[purpose == "spending" ? 1 : 0]
281
- ),
282
- Datum:
283
- purpose == "spending"
284
- ? this.getInternalTypeDetails(v.mainArgTypes[0])
285
- : undefined
286
- }
287
-
288
- for (let m of v.mainImportedModules) {
289
- if (!(m.name.value in moduleDetails)) {
290
- moduleDetails[m.name.value] = {
291
- name: m.name.value,
292
- purpose: "module",
293
- sourceCode: modules[m.name.value].sourceCode,
294
- moduleDepedencies: m
295
- .filterDependencies(allModules)
296
- .map((m) => m.name.value),
297
- types: {} // not yet exported
298
- }
299
- }
300
- }
301
- }
302
-
303
- return { modules: moduleDetails, validators: validatorDetails }
304
- }
305
-
306
- /**
425
+ * @private
307
426
  * @param {TypeSchema} it
308
427
  * @returns {InternalTypeDetails}
309
428
  */
@@ -340,6 +459,7 @@ export class Lib_v0_16 {
340
459
  }
341
460
 
342
461
  /**
462
+ * @private
343
463
  * @param {DataType} dt
344
464
  * @returns {InternalTypeDetails}
345
465
  */
@@ -356,135 +476,4 @@ export class Lib_v0_16 {
356
476
  }
357
477
  }
358
478
  }
359
-
360
- /**
361
- * @param {string[]} modules
362
- * @returns {string[]}
363
- */
364
- sortModules(modules) {
365
- if (!this.options?.moduleOrder) {
366
- return modules
367
- }
368
-
369
- const n = modules.length
370
- const tmp = modules.slice()
371
-
372
- tmp.sort((a, b) => {
373
- const nameA = readHeader(a)[1]
374
- const nameB = readHeader(b)[1]
375
-
376
- let iA = this.options.moduleOrder?.indexOf(nameA)
377
- let iB = this.options.moduleOrder?.indexOf(nameB)
378
-
379
- if (iA === undefined || iA == -1) {
380
- iA = n
381
- }
382
-
383
- if (iB === undefined || iB == -1) {
384
- iB = n
385
- }
386
-
387
- return iA - iB
388
- })
389
-
390
- return tmp
391
- }
392
-
393
- /**
394
- * @param {string} main
395
- * @param {string[]} modules
396
- * @param {CompileOptions} options
397
- * @returns {CompileOutput}
398
- */
399
- compile(main, modules, options) {
400
- const [purpose, name] = readHeader(main)
401
- const otherValidators = options.otherValidators ?? {}
402
- const otherValidatorTypes = options.allValidatorTypes
403
-
404
- modules = this.sortModules(modules)
405
-
406
- const program = this.lib.Program.newInternal(
407
- main,
408
- modules,
409
- otherValidatorTypes,
410
- {
411
- allowPosParams: false,
412
- invertEntryPoint: true
413
- }
414
- )
415
-
416
- /**
417
- * @type {Map<any, any>}
418
- */
419
- const extra = new Map()
420
- const IR = this.lib.IR
421
-
422
- if (options.ownHash) {
423
- const key = `__helios__scripts__${name}`
424
-
425
- extra.set(key, new IR(`#${options.ownHash}`))
426
- } else if (options.dependsOnOwnHash) {
427
- const key = `__helios__scripts__${name}`
428
- let ir = new IR(`__PARAM_${program.nPosParams - 1}`)
429
-
430
- switch (purpose) {
431
- case "spending":
432
- ir = new IR([
433
- new IR(
434
- `__helios__scriptcontext__get_current_validator_hash(`
435
- ),
436
- ir,
437
- new IR(`)()`)
438
- ])
439
- break
440
- case "minting":
441
- ir = new IR([
442
- new IR(
443
- `__helios__scriptcontext__get_current_minting_policy_hash(`
444
- ),
445
- ir,
446
- new IR(`)()`)
447
- ])
448
- break
449
- default:
450
- throw new Error("unhandled purpose")
451
- }
452
-
453
- extra.set(key, ir)
454
- }
455
-
456
- for (let other in otherValidators) {
457
- const key = `__helios__scripts__${other}`
458
-
459
- extra.set(key, new IR(`#${otherValidators[other].hash}`))
460
- }
461
-
462
- const optimize = options.optimize
463
- const ir = program.toIR(new this.lib.ToIRContext(optimize), extra)
464
-
465
- if (program.nPosParams > 0) {
466
- const irProgram = this.lib.IRParametricProgram.new(
467
- ir,
468
- purpose,
469
- program.nPosParams,
470
- optimize
471
- )
472
-
473
- const cborHex = bytesToHex(irProgram.toUplc().toCbor())
474
-
475
- return {
476
- prettyIR: irProgram.program.annotate(),
477
- cborHex
478
- }
479
- } else {
480
- const irProgram = this.lib.IRProgram.new(ir, purpose, optimize)
481
-
482
- const cborHex = bytesToHex(irProgram.toUplc().toCbor())
483
-
484
- return {
485
- prettyIR: irProgram.program.annotate(),
486
- cborHex
487
- }
488
- }
489
- }
490
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
+ */