@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
@@ -2,14 +2,14 @@ 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
  * @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
8
+ * @typedef {import("./CompilerLib.js").CompileOptions} CompileOptions
9
+ * @typedef {import("./CompilerLib.js").CompileOutput} CompileOutput
10
+ * @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
11
+ * @typedef {import("./CompilerLib.js").SourceDetails} SourceDetails
12
+ * @typedef {import("./CompilerLib.js").TypeCheckOutput} TypeCheckOutput
13
13
  */
14
14
 
15
15
  /**
@@ -20,7 +20,7 @@ import { readHeader } from "@helios-lang/compiler-utils"
20
20
 
21
21
  /**
22
22
  * @typedef {{
23
- * }} HashType
23
+ * }} ScriptHashType
24
24
  */
25
25
 
26
26
  /**
@@ -47,7 +47,22 @@ import { readHeader } from "@helios-lang/compiler-utils"
47
47
 
48
48
  /**
49
49
  * @typedef {{
50
- * name: {value: string}
50
+ * src: {
51
+ * raw: string
52
+ * }
53
+ * }} Site
54
+ */
55
+
56
+ /**
57
+ * @typedef {{
58
+ * value: string
59
+ * site: Site
60
+ * }} WordToken
61
+ */
62
+
63
+ /**
64
+ * @typedef {{
65
+ * name: WordToken
51
66
  * filterDependencies: (all: Module[]) => Module[]
52
67
  * statements: Statement[]
53
68
  * }} Module
@@ -55,6 +70,7 @@ import { readHeader } from "@helios-lang/compiler-utils"
55
70
  /**
56
71
  * @typedef {{
57
72
  * name: string
73
+ * purpose: "testing" | "minting" | "spending" | "staking" | "endpoint" | "module" | "unknown"
58
74
  * toIR: (ctx: any, extra: Map<string, IR>) => IR
59
75
  * types: UserTypes
60
76
  * mainImportedModules: Module[]
@@ -111,30 +127,14 @@ import { readHeader } from "@helios-lang/compiler-utils"
111
127
  */
112
128
 
113
129
  /**
114
- * @implements {Lib}
130
+ * @implements {CompilerLib}
115
131
  */
116
- export class Lib_v0_16 {
117
- /**
118
- * @private
119
- * @readonly
120
- * @type {LibOptions}
121
- */
122
- options
123
-
132
+ export class CompilerLib_v0_16 {
124
133
  /**
125
134
  * @param {any} lib
126
- * @param {LibOptions} options
127
135
  */
128
- constructor(lib, options) {
136
+ constructor(lib) {
129
137
  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
138
  }
139
139
 
140
140
  /**
@@ -146,9 +146,9 @@ export class Lib_v0_16 {
146
146
 
147
147
  /**
148
148
  * @param {string} purpose
149
- * @returns {HashType}
149
+ * @returns {ScriptHashType}
150
150
  */
151
- getValidatorType(purpose) {
151
+ getScriptHashType(purpose) {
152
152
  switch (purpose) {
153
153
  case "spending":
154
154
  return this.lib.ValidatorHashType
@@ -161,33 +161,227 @@ export class Lib_v0_16 {
161
161
  }
162
162
  }
163
163
 
164
+ /**
165
+ * @param {string[]} validators
166
+ * @param {string[]} modules
167
+ * @returns {TypeCheckOutput}
168
+ */
169
+ typeCheck(validators, modules) {
170
+ const validatorTypes = Object.fromEntries(
171
+ validators.map((v) => {
172
+ const [purpose, name] = readHeader(v)
173
+ return [name, this.getScriptHashType(purpose)]
174
+ })
175
+ )
176
+
177
+ // create validator programs
178
+ let validatorPrograms = this.createPrograms(
179
+ validators,
180
+ modules,
181
+ validatorTypes
182
+ )
183
+
184
+ // build dag
185
+ const dag = this.buildDagDependencies(validatorPrograms, validatorTypes)
186
+
187
+ /**
188
+ * @type {{[name: string]: TypeCheckedValidator}}
189
+ */
190
+ const typeCheckedValidators = {}
191
+
192
+ /**
193
+ * @type {{[name: string]: TypeCheckedModule}}
194
+ */
195
+ const typeCheckedModules = {}
196
+
197
+ // collect the validators and the modules from the typechecked programs
198
+ for (let v of validatorPrograms) {
199
+ const name = v.name
200
+ const purpose = v.purpose
201
+ const sourceCode = v.mainModule.name.site.src.raw
202
+ const hashDependencies = dag[name]
203
+
204
+ const allModules = v.mainImportedModules
205
+ const moduleDepedencies = v.mainModule
206
+ .filterDependencies(allModules)
207
+ .map((m) => m.name.value)
208
+
209
+ typeCheckedValidators[name] = {
210
+ name: name,
211
+ purpose: purpose,
212
+ sourceCode: sourceCode,
213
+ hashDependencies: hashDependencies,
214
+ moduleDepedencies: moduleDepedencies,
215
+ types: {},
216
+ Redeemer: this.getInternalTypeDetails(
217
+ v.mainArgTypes[purpose == "spending" ? 1 : 0]
218
+ ),
219
+ Datum:
220
+ purpose == "spending"
221
+ ? this.getInternalTypeDetails(v.mainArgTypes[0])
222
+ : undefined
223
+ }
224
+
225
+ // add any module dependencies that haven't been added before
226
+ for (let m of v.mainImportedModules) {
227
+ const name = m.name.value
228
+ const sourceCode = m.name.site.src.raw
229
+
230
+ if (name in typeCheckedModules) {
231
+ continue
232
+ }
233
+
234
+ typeCheckedModules[name] = {
235
+ name: name,
236
+ purpose: "module",
237
+ sourceCode: sourceCode,
238
+ moduleDepedencies: m
239
+ .filterDependencies(allModules)
240
+ .map((m) => m.name.value),
241
+ types: {}
242
+ }
243
+ }
244
+ }
245
+
246
+ return {
247
+ modules: typeCheckedModules,
248
+ validators: typeCheckedValidators
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Generate additional IR definitions
254
+ * * dependency on own precalculated hash (eg. unoptimized program should use hash of optimized program)
255
+ * * dependency on own hash through methods defined on the ScriptContext
256
+ * * dependency on hashes of other validators
257
+ * @private
258
+ * @param {string} name - name of the validator being compiled
259
+ * @param {string} purpose - purpose the validator being compiled
260
+ * @param {number} nPosParams
261
+ * @param {CompileOptions} options
262
+ * @returns {Map<string, IR>}
263
+ */
264
+ generateExtraIRDefinitions(name, purpose, nPosParams, options) {
265
+ /**
266
+ * @type {Map<string, IR>}
267
+ */
268
+ const extra = new Map()
269
+
270
+ const IR = this.lib.IR
271
+
272
+ // inject own hash (either precalculated, or via ScriptContext)
273
+ if (options.ownHash) {
274
+ extra.set(
275
+ `__helios__scripts__${name}`,
276
+ new IR(`#${options.ownHash}`)
277
+ )
278
+ } else if (options.dependsOnOwnHash) {
279
+ const key = `__helios__scripts__${name}`
280
+ let ir = new IR(`__PARAM_${nPosParams - 1}`)
281
+
282
+ switch (purpose) {
283
+ case "spending":
284
+ ir = new IR([
285
+ new IR(
286
+ `__helios__scriptcontext__get_current_validator_hash(`
287
+ ),
288
+ ir,
289
+ new IR(`)()`)
290
+ ])
291
+ break
292
+ case "minting":
293
+ ir = new IR([
294
+ new IR(
295
+ `__helios__scriptcontext__get_current_minting_policy_hash(`
296
+ ),
297
+ ir,
298
+ new IR(`)()`)
299
+ ])
300
+ break
301
+ default:
302
+ throw new Error("unhandled purpose")
303
+ }
304
+
305
+ extra.set(key, ir)
306
+ }
307
+
308
+ // inject hashes of other validators
309
+ Object.entries(options.hashDependencies ?? {}).forEach(
310
+ ([depName, dep]) => {
311
+ extra.set(`__helios__scripts__${depName}`, new IR(`#${dep}`))
312
+ }
313
+ )
314
+
315
+ return extra
316
+ }
317
+
318
+ /**
319
+ * @param {string} main
320
+ * @param {string[]} modules
321
+ * @param {CompileOptions} options
322
+ * @returns {CompileOutput}
323
+ */
324
+ compile(main, modules, options) {
325
+ const [purpose, name] = readHeader(main)
326
+
327
+ // use `Program.newInternal()` instead of `Program.new()` so we can inject custom IR before finally compiling to a UplcProgram
328
+ const program = this.lib.Program.newInternal(
329
+ main,
330
+ modules,
331
+ options.allValidatorHashTypes,
332
+ {
333
+ allowPosParams: false,
334
+ invertEntryPoint: true
335
+ }
336
+ )
337
+
338
+ const extra = this.generateExtraIRDefinitions(
339
+ name,
340
+ purpose,
341
+ program.nPosParams,
342
+ options
343
+ )
344
+ const optimize = options.optimize
345
+ const ir = program.toIR(new this.lib.ToIRContext(optimize), extra)
346
+
347
+ const irProgram =
348
+ program.nPosParams > 0
349
+ ? this.lib.IRParametricProgram.new(
350
+ ir,
351
+ purpose,
352
+ program.nPosParams,
353
+ optimize
354
+ )
355
+ : this.lib.IRProgram.new(ir, purpose, optimize)
356
+
357
+ const cborHex = bytesToHex(irProgram.toUplc().toCbor())
358
+
359
+ return {
360
+ prettyIR: irProgram.program.annotate(),
361
+ cborHex
362
+ }
363
+ }
364
+
164
365
  /**
165
366
  * @private
166
- * @param {SourceDetails[]} validators
167
- * @param {SourceDetails[]} modules
168
- * @param {{[name: string]: HashType}} validatorTypes
367
+ * @param {string[]} validators
368
+ * @param {string[]} modules
369
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
169
370
  * @returns {Program[]}
170
371
  */
171
372
  createPrograms(validators, modules, validatorTypes) {
172
- const moduleSrcs = modules.map((m) => m.sourceCode)
173
-
174
373
  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
- )
374
+ this.lib.Program.newInternal(v, modules, validatorTypes, {
375
+ allowPosParams: false,
376
+ invertEntryPoint: true
377
+ })
184
378
  )
185
379
  }
186
380
 
187
381
  /**
188
382
  * @private
189
383
  * @param {Program} program
190
- * @param {{[name: string]: HashType}} validatorTypes
384
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
191
385
  * @returns {IR}
192
386
  */
193
387
  toTestIR(program, validatorTypes) {
@@ -206,7 +400,7 @@ export class Lib_v0_16 {
206
400
  /**
207
401
  * @private
208
402
  * @param {Program[]} validators
209
- * @param {{[name: string]: HashType}} validatorTypes
403
+ * @param {{[name: string]: ScriptHashType}} validatorTypes
210
404
  * @returns {DagDependencies}
211
405
  */
212
406
  buildDagDependencies(validators, validatorTypes) {
@@ -227,84 +421,7 @@ export class Lib_v0_16 {
227
421
  }
228
422
 
229
423
  /**
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
- /**
424
+ * @private
308
425
  * @param {TypeSchema} it
309
426
  * @returns {InternalTypeDetails}
310
427
  */
@@ -341,6 +458,9 @@ export class Lib_v0_16 {
341
458
  }
342
459
 
343
460
  /**
461
+ * Tries to convert a compiler type into TypeSchema
462
+ * TODO: make sure it works for all structs and enums
463
+ * @private
344
464
  * @param {DataType} dt
345
465
  * @returns {InternalTypeDetails}
346
466
  */
@@ -357,135 +477,4 @@ export class Lib_v0_16 {
357
477
  }
358
478
  }
359
479
  }
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
480
  }
@@ -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
+ */