@helios-lang/contract-utils 0.1.7 → 0.1.8

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 (39) hide show
  1. package/examples/spending/contract.js +16 -0
  2. package/examples/spending/index.d.ts +12 -2
  3. package/examples/spending/index.js +10 -0
  4. package/examples/spending/minting.hl +5 -0
  5. package/examples/spending/package-lock.json +34 -2
  6. package/examples/spending/package.json +5 -0
  7. package/jsconfig.json +16 -0
  8. package/package.json +6 -3
  9. package/src/codegen/TypescriptWriter.js +14 -6
  10. package/src/hl2ts.js +1 -1
  11. package/src/index.js +1 -1
  12. package/src/lib/Lib.js +15 -0
  13. package/src/lib/Libg_v0_16.js +106 -5
  14. package/src/lib/load.js +12 -49
  15. package/src/runtime/Cast.js +9 -6
  16. package/src/runtime/ContractContext.js +35 -0
  17. package/src/runtime/ContractContextBuilder.js +325 -0
  18. package/src/runtime/PermissiveType.js +6 -0
  19. package/src/runtime/StrictType.js +6 -0
  20. package/src/runtime/index.js +3 -1
  21. package/types/codegen/TypescriptWriter.d.ts.map +1 -1
  22. package/types/index.d.ts +1 -1
  23. package/types/lib/Lib.d.ts +29 -0
  24. package/types/lib/Lib.d.ts.map +1 -1
  25. package/types/lib/Libg_v0_16.d.ts +11 -11
  26. package/types/lib/Libg_v0_16.d.ts.map +1 -1
  27. package/types/lib/load.d.ts +5 -2
  28. package/types/lib/load.d.ts.map +1 -1
  29. package/types/runtime/Cast.d.ts +5 -5
  30. package/types/runtime/Cast.d.ts.map +1 -1
  31. package/types/runtime/ContractContext.d.ts +44 -0
  32. package/types/runtime/ContractContext.d.ts.map +1 -0
  33. package/types/runtime/ContractContextBuilder.d.ts +133 -0
  34. package/types/runtime/ContractContextBuilder.d.ts.map +1 -0
  35. package/types/runtime/PermissiveType.d.ts +3 -0
  36. package/types/runtime/PermissiveType.d.ts.map +1 -0
  37. package/types/runtime/StrictType.d.ts +3 -0
  38. package/types/runtime/StrictType.d.ts.map +1 -0
  39. package/types/runtime/index.d.ts +2 -0
@@ -0,0 +1,16 @@
1
+ import { ContractContextBuilder } from "@helios-lang/contract-utils"
2
+ import { Address, TxBuilder } from "@helios-lang/ledger"
3
+ import { match_string, match_string_policy } from "./index.js"
4
+
5
+ const context = ContractContextBuilder.new()
6
+ .with(match_string)
7
+ .with(match_string_policy)
8
+ .build()
9
+
10
+ console.log(context.match_string_policy.toHex())
11
+
12
+ const address = Address.fromHash(context.match_string)
13
+
14
+ const b = new TxBuilder()
15
+ .mint(context.match_string_policy, [["", 10]], "hello")
16
+ .pay(address, 0n, { hash: { One: { message: "hello" } } })
@@ -7,9 +7,19 @@ export const utils: {
7
7
  $sourceCode: string
8
8
  $dependencies: []
9
9
  }
10
+ export const match_string_policy: {
11
+ $name: "match_string_policy"
12
+ $purpose: "minting"
13
+ $sourceCode: string
14
+ $dependencies: []
15
+ $hashDependencies: []
16
+ $dependsOnOwnHash: boolean
17
+ $Redeemer: Cast<string, string>
18
+
19
+ }
10
20
  export const match_string: {
11
- $name: string
12
- $purpose: string
21
+ $name: "match_string"
22
+ $purpose: "spending"
13
23
  $sourceCode: string
14
24
  $dependencies: [typeof utils]
15
25
  $hashDependencies: []
@@ -5,6 +5,16 @@ export const utils = {
5
5
  $sourceCode: "module utils\n\nfunc compare(a: String, b: String) -> Bool {\n a == b\n}",
6
6
  $dependencies: [],
7
7
  }
8
+ export const match_string_policy = {
9
+ $name: "match_string_policy",
10
+ $purpose: "minting",
11
+ $sourceCode: "minting match_string_policy\n\nfunc main(redeemer: String, _) -> Bool {\n redeemer == \"Hello\"\n}",
12
+ $dependencies: [],
13
+ $hashDependencies: [],
14
+ $dependsOnOwnHash: false,
15
+ $Redeemer: new Cast({"primitiveType":"String"}),
16
+
17
+ }
8
18
  export const match_string = {
9
19
  $name: "match_string",
10
20
  $purpose: "spending",
@@ -0,0 +1,5 @@
1
+ minting match_string_policy
2
+
3
+ func main(redeemer: String, _) -> Bool {
4
+ redeemer == "Hello"
5
+ }
@@ -6,16 +6,24 @@
6
6
  "": {
7
7
  "name": "spending_example",
8
8
  "dependencies": {
9
+ "@helios-lang/compiler": "0.16.7-1",
9
10
  "@helios-lang/contract-utils": "file:../..",
10
11
  "@hyperionbt/helios": "^0.16.7"
12
+ },
13
+ "devDependencies": {
14
+ "typescript": "^5.4.3"
11
15
  }
12
16
  },
13
17
  "../..": {
14
18
  "name": "@helios-lang/contract-utils",
15
- "version": "0.1.1",
19
+ "version": "0.1.7",
16
20
  "license": "BSD-3-Clause",
17
21
  "dependencies": {
18
- "@helios-lang/compiler-utils": "^0.1.2"
22
+ "@helios-lang/codec-utils": "^0.1.26",
23
+ "@helios-lang/compiler-utils": "^0.1.20",
24
+ "@helios-lang/ledger": "^0.1.10",
25
+ "@helios-lang/type-utils": "^0.1.8",
26
+ "@helios-lang/uplc": "^0.1.21"
19
27
  },
20
28
  "bin": {
21
29
  "hl2ts": "src/hl2ts.js"
@@ -24,6 +32,17 @@
24
32
  "@types/node": "^20.11.24",
25
33
  "prettier": "^3.1.0",
26
34
  "typescript": "^5.3.2"
35
+ },
36
+ "peerDependencies": {
37
+ "@helios-lang/compiler": "^0.16.7"
38
+ }
39
+ },
40
+ "node_modules/@helios-lang/compiler": {
41
+ "version": "0.16.7-1",
42
+ "resolved": "https://registry.npmjs.org/@helios-lang/compiler/-/compiler-0.16.7-1.tgz",
43
+ "integrity": "sha512-M6x99ApFUNtNrPucx5IrcTbqHP1yyVQXeaKuQWOICgioSbWMKeogN7Hn2INk6f//DzGaqFZ7Cd1JOtt8zXHE/Q==",
44
+ "dependencies": {
45
+ "@hyperionbt/helios": "0.16.7"
27
46
  }
28
47
  },
29
48
  "node_modules/@helios-lang/contract-utils": {
@@ -34,6 +53,19 @@
34
53
  "version": "0.16.7",
35
54
  "resolved": "https://registry.npmjs.org/@hyperionbt/helios/-/helios-0.16.7.tgz",
36
55
  "integrity": "sha512-ysPaF0OCY0NJa1mc+LXERjH71VDNGUbYrrovKUHJv1v+eS1WJhKmxSHWh9sVa6b+sYoXdKwoCR20UQhzCF5jzA=="
56
+ },
57
+ "node_modules/typescript": {
58
+ "version": "5.4.3",
59
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz",
60
+ "integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==",
61
+ "dev": true,
62
+ "bin": {
63
+ "tsc": "bin/tsc",
64
+ "tsserver": "bin/tsserver"
65
+ },
66
+ "engines": {
67
+ "node": ">=14.17"
68
+ }
37
69
  }
38
70
  }
39
71
  }
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "spending_example",
3
+ "type": "module",
3
4
  "dependencies": {
5
+ "@helios-lang/compiler": "0.16.7-1",
4
6
  "@helios-lang/contract-utils": "file:../..",
5
7
  "@hyperionbt/helios": "^0.16.7"
8
+ },
9
+ "devDependencies": {
10
+ "typescript": "^5.4.3"
6
11
  }
7
12
  }
package/jsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "checkJs": true,
4
+ "declaration": true,
5
+ "declarationMap": true,
6
+ "declarationDir": "./types",
7
+ "skipLibCheck": true,
8
+ "noImplicitThis": true,
9
+ "strictNullChecks": true,
10
+ "moduleResolution": "nodenext",
11
+ "module": "nodenext",
12
+ "target": "esnext"
13
+ },
14
+ "exclude": ["node_modules", "**/*.d.ts"],
15
+ "include": ["src/**/*.js", "node_modules/@helios-lang/type-utils"]
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helios-lang/contract-utils",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Convenience and type-safety utilities for using Helios validators from within Typescript",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
@@ -34,8 +34,11 @@
34
34
  "dependencies": {
35
35
  "@helios-lang/codec-utils": "^0.1.26",
36
36
  "@helios-lang/compiler-utils": "^0.1.20",
37
- "@helios-lang/ledger": "^0.1.10",
37
+ "@helios-lang/ledger": "^0.1.20",
38
38
  "@helios-lang/type-utils": "^0.1.8",
39
- "@helios-lang/uplc": "^0.1.21"
39
+ "@helios-lang/uplc": "^0.1.22"
40
+ },
41
+ "peerDependencies": {
42
+ "@helios-lang/compiler": "0.16.7-1"
40
43
  }
41
44
  }
@@ -82,8 +82,8 @@ export class TypescriptWriter {
82
82
  }
83
83
  `,
84
84
  `export const ${v.name}: {
85
- $name: string
86
- $purpose: string
85
+ $name: "${v.name}"
86
+ $purpose: "${v.purpose}"
87
87
  $sourceCode: string
88
88
  $dependencies: [${v.moduleDepedencies.map((d) => `typeof ${d}`).join(", ")}]
89
89
  $hashDependencies: [${v.hashDependencies
@@ -99,11 +99,19 @@ export class TypescriptWriter {
99
99
  }
100
100
 
101
101
  writeHeaders() {
102
- this.wjs.writeLine("import { Cast } from \"@helios-lang/contract-utils\";")
102
+ this.wjs.writeLine(
103
+ 'import { Cast } from "@helios-lang/contract-utils";'
104
+ )
103
105
 
104
- this.wdts.writeLine("import type {UplcData} from \"@helios-lang/ledger\";")
105
- this.wdts.writeLine("import { Address, AssetClass, Credential, DatumHash, MintingPolicyHash, PubKeyHash, StakingCredential, StakingHash, StakingValidatorHash, TimeRange, TxId, TxOutputDatum, ValidatorHash, Value} from \"@helios-lang/ledger\";")
106
- this.wdts.writeLine("import { Cast } from \"@helios-lang/contract-utils\";")
106
+ this.wdts.writeLine(
107
+ 'import type {UplcData} from "@helios-lang/ledger";'
108
+ )
109
+ this.wdts.writeLine(
110
+ 'import { Address, AssetClass, Credential, DatumHash, MintingPolicyHash, PubKeyHash, StakingCredential, StakingHash, StakingValidatorHash, TimeRange, TxId, TxOutputDatum, ValidatorHash, Value} from "@helios-lang/ledger";'
111
+ )
112
+ this.wdts.writeLine(
113
+ 'import { Cast } from "@helios-lang/contract-utils";'
114
+ )
107
115
  }
108
116
 
109
117
  /**
package/src/hl2ts.js CHANGED
@@ -29,7 +29,7 @@ async function main() {
29
29
  w.writeHeaders()
30
30
  w.writeModules(modules)
31
31
  w.writeValidators(validators)
32
-
32
+
33
33
  const [js, dts] = w.finalize()
34
34
 
35
35
  const jsPath = join(outDir, "index.js")
package/src/index.js CHANGED
@@ -1 +1 @@
1
- export { Cast } from "./runtime/index.js"
1
+ export { Cast, ContractContextBuilder } from "./runtime/index.js"
package/src/lib/Lib.js CHANGED
@@ -1,8 +1,23 @@
1
+ /**
2
+ * @typedef {{
3
+ * otherValidators: {[name: string]: {purpose: string, hash: string}},
4
+ * dependsOnOwnHash?: boolean,
5
+ * ownHash?: string,
6
+ * optimize: boolean
7
+ * }} CompileOptions
8
+ */
9
+
10
+ /**
11
+ * @typedef {{
12
+ * cborHex: string
13
+ * }} CompileOutput
14
+ */
1
15
  /**
2
16
  * @typedef {{
3
17
  * version: string
4
18
  * typeCheck: (validators: {[name: string]: SourceDetails}, modules: {[name: string]: SourceDetails}) => ({
5
19
  * modules: {[name: string]: ModuleDetails}, validators: {[name: string]: ValidatorDetails}})
20
+ * compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput
6
21
  * }} Lib
7
22
  */
8
23
 
@@ -1,14 +1,17 @@
1
- /**
2
- * @typedef {import("./Lib.js").Lib} Lib
3
- * @typedef {import("./Lib.js").SourceDetails} SourceDetails
4
- */
5
-
6
1
  /**
7
2
  * @typedef {import("../codegen/index.js").Module} ModuleDetails
8
3
  * @typedef {import("../codegen/index.js").Validator} ValidatorDetails
9
4
  * @typedef {import("../codegen/index.js").TypeSchema} InternalTypeDetails
5
+ * @typedef {import("./Lib.js").CompileOptions} CompileOptions
6
+ * @typedef {import("./Lib.js").CompileOutput} CompileOutput
7
+ * @typedef {import("./Lib.js").Lib} Lib
8
+ * @typedef {import("./Lib.js").SourceDetails} SourceDetails
10
9
  */
11
10
 
11
+ import { bytesToHex } from "@helios-lang/compiler"
12
+ import { readHeader } from "@helios-lang/compiler-utils"
13
+ import { UplcProgramV1 } from "@helios-lang/uplc"
14
+
12
15
  /**
13
16
  * @typedef {{
14
17
  * [name: string]: string[]
@@ -339,4 +342,102 @@ export class Lib_v0_16 {
339
342
  }
340
343
  }
341
344
  }
345
+
346
+ /**
347
+ * @param {string} main
348
+ * @param {string[]} modules
349
+ * @param {CompileOptions} options
350
+ * @returns {CompileOutput}
351
+ */
352
+ compile(main, modules, options) {
353
+ const [purpose, name] = readHeader(main)
354
+ const otherValidators = options.otherValidators ?? {}
355
+ const otherValidatorTypes = Object.fromEntries(
356
+ Object.keys(otherValidators).map((k) => {
357
+ return [k, this.getValidatorType(otherValidators[k].purpose)]
358
+ })
359
+ )
360
+
361
+ const program = this.lib.Program.newInternal(
362
+ main,
363
+ modules,
364
+ otherValidatorTypes,
365
+ {
366
+ allowPosParams: false,
367
+ invertEntryPoint: true
368
+ }
369
+ )
370
+
371
+ /**
372
+ * @type {Map<any, any>}
373
+ */
374
+ const extra = new Map()
375
+ const IR = this.lib.IR
376
+
377
+ if (options.ownHash) {
378
+ const key = `__helios__scripts__${name}`
379
+
380
+ extra.set(key, new IR(`#${options.ownHash}`))
381
+ } else if (options.dependsOnOwnHash) {
382
+ const key = `__helios__scripts__${name}`
383
+ let ir = new IR(`__PARAM_${program.nPosParams - 1}`)
384
+
385
+ switch (purpose) {
386
+ case "spending":
387
+ ir = new IR([
388
+ new IR(
389
+ `__helios__scriptcontext__get_current_validator_hash(`
390
+ ),
391
+ ir,
392
+ new IR(`)()`)
393
+ ])
394
+ break
395
+ case "minting":
396
+ ir = new IR([
397
+ new IR(
398
+ `__helios__scriptcontext__get_current_minting_policy_hash(`
399
+ ),
400
+ ir,
401
+ new IR(`)()`)
402
+ ])
403
+ break
404
+ default:
405
+ throw new Error("unhandled purpose")
406
+ }
407
+
408
+ extra.set(key, ir)
409
+ }
410
+
411
+ for (let other in otherValidators) {
412
+ const key = `__helios__scripts__${other}`
413
+
414
+ extra.set(key, new IR(`#${otherValidators[other]}`))
415
+ }
416
+
417
+ const optimize = options.optimize
418
+ const ir = program.toIR(new this.lib.ToIRContext(optimize), extra)
419
+
420
+ if (program.nPosParams > 0) {
421
+ const irProgram = this.lib.IRParametricProgram.new(
422
+ ir,
423
+ purpose,
424
+ program.nPosParams,
425
+ optimize
426
+ )
427
+
428
+ const cborHex = bytesToHex(irProgram.toUplc().toCbor())
429
+
430
+ return {
431
+ cborHex
432
+ }
433
+ } else {
434
+ const irProgram = this.lib.IRProgram.new(ir, purpose, optimize)
435
+
436
+ const cborHex = bytesToHex(irProgram.toUplc().toCbor())
437
+
438
+ return {
439
+ cborHex
440
+ }
441
+ }
442
+ }
342
443
  }
package/src/lib/load.js CHANGED
@@ -1,5 +1,4 @@
1
- import { existsSync } from "node:fs"
2
- import { dirname, join } from "node:path"
1
+ import * as lib from "@helios-lang/compiler"
3
2
  import { getVersion } from "./Lib.js"
4
3
  import { Lib_v0_16 } from "./Libg_v0_16.js"
5
4
 
@@ -8,54 +7,18 @@ import { Lib_v0_16 } from "./Libg_v0_16.js"
8
7
  */
9
8
 
10
9
  /**
11
- * @returns {string}
10
+ * @returns {Lib}
12
11
  */
13
- function findRootDir() {
14
- let dir = process.cwd()
15
-
16
- while (dir != "/") {
17
- if (existsSync(join(dir, "package.json"))) {
18
- return dir
19
- } else {
20
- dir = dirname(dir)
21
- }
22
- }
23
-
24
- throw new Error("package.json not found")
25
- }
26
-
27
- /**
28
- * @returns {Promise<Lib>}
29
- */
30
- export async function loadLibrary() {
31
- const rootDir = findRootDir()
32
-
33
- const packageNames = ["@hyperionbt/helios/helios.js"]
34
-
35
- for (let packageName of packageNames) {
36
- try {
37
- const lib = await eval(
38
- `import("${rootDir}/node_modules/${packageName}")`
39
- )
40
-
41
- const [major, minor] = getVersion(lib)
42
-
43
- switch (major) {
44
- case 0:
45
- switch (minor) {
46
- case 16:
47
- return new Lib_v0_16(lib)
48
- }
49
- default:
50
- throw new Error(
51
- `compiler version ${lib.VERSION} not supported`
52
- )
12
+ export function loadLibrary() {
13
+ const [major, minor] = getVersion(lib)
14
+
15
+ switch (major) {
16
+ case 0:
17
+ switch (minor) {
18
+ case 16:
19
+ return new Lib_v0_16(lib)
53
20
  }
54
- } catch (_e) {
55
- console.error(_e)
56
- continue
57
- }
21
+ default:
22
+ throw new Error(`compiler version ${lib.VERSION} not supported`)
58
23
  }
59
-
60
- throw new Error("compiler not installed")
61
24
  }
@@ -36,8 +36,8 @@ import {
36
36
  */
37
37
 
38
38
  /**
39
- * @template TStrict
40
- * @template TPermissive
39
+ * @template [TStrict=UplcData]
40
+ * @template [TPermissive=UplcData]
41
41
  */
42
42
  export class Cast {
43
43
  /**
@@ -57,7 +57,7 @@ export class Cast {
57
57
  * @param {UplcData} data
58
58
  * @returns {TStrict}
59
59
  */
60
- fromUplc(data) {
60
+ fromUplcData(data) {
61
61
  return uplcToSchema(this.schema, data)
62
62
  }
63
63
 
@@ -65,7 +65,7 @@ export class Cast {
65
65
  * @param {TPermissive} x
66
66
  * @returns {UplcData}
67
67
  */
68
- toUplc(x) {
68
+ toUplcData(x) {
69
69
  return schemaToUplc(this.schema, x)
70
70
  }
71
71
  }
@@ -167,8 +167,11 @@ function schemaToUplc(schema, x) {
167
167
  const tag = schema.enumVariantTypes.findIndex(
168
168
  (v) => v.name == variantName
169
169
  )
170
- if (tag != -1) {
171
- throw new Error("invalid variant")
170
+
171
+ if (tag == -1) {
172
+ throw new Error(
173
+ `invalid variant ${variantName} (expected: ${schema.enumVariantTypes.map((v) => v.name).join(", ")})`
174
+ )
172
175
  }
173
176
 
174
177
  return new ConstrData(
@@ -0,0 +1,35 @@
1
+ import { ScriptHash } from "@helios-lang/ledger"
2
+ import { UplcProgramV2 } from "@helios-lang/uplc"
3
+ import { Cast } from "./Cast.js"
4
+
5
+ /**
6
+ * @typedef {{
7
+ * $name: string
8
+ * $purpose: string
9
+ * $program: {
10
+ * optimized: UplcProgramV2
11
+ * unoptimized: UplcProgramV2
12
+ * }
13
+ * $hash: ScriptHash
14
+ * $Redeemer: Cast<any, any>
15
+ * $Datum?: Cast<any, any>
16
+ * }} Validator
17
+ */
18
+
19
+ /**
20
+ * @template {{[name: string]: Validator}} T
21
+ */
22
+ export class ContractContext {
23
+ /**
24
+ * @readonly
25
+ * @type {T}
26
+ */
27
+ validators
28
+
29
+ /**
30
+ * @param {T} validators
31
+ */
32
+ constructor(validators) {
33
+ this.validators = validators
34
+ }
35
+ }
@@ -0,0 +1,325 @@
1
+ import { bytesToHex } from "@helios-lang/codec-utils"
2
+ import {
3
+ ScriptHash,
4
+ StakingValidatorHash,
5
+ ValidatorHash,
6
+ MintingPolicyHash
7
+ } from "@helios-lang/ledger"
8
+ import { None, expectSome } from "@helios-lang/type-utils"
9
+ import { UplcProgramV2 } from "@helios-lang/uplc"
10
+ import { loadLibrary } from "../lib/index.js"
11
+ import { Cast } from "./Cast.js"
12
+ import { ContractContext } from "./ContractContext.js"
13
+
14
+ /**
15
+ * @typedef {import("./ContractContext.js").Validator} CompiledValidator
16
+ */
17
+
18
+ /**
19
+ * @template TRedeemerStrict
20
+ * @template TRedeemerPermissive
21
+ * @typedef {import("@helios-lang/ledger").MintingContext<TRedeemerStrict, TRedeemerPermissive>} MintingContext
22
+ */
23
+
24
+ /**
25
+ * @template TDatumStrict
26
+ * @template TDatumPermissive
27
+ * @template TRedeemerStrict
28
+ * @template TRedeemerPermissive
29
+ * @typedef {import("@helios-lang/ledger").SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive>} SpendingContext
30
+ */
31
+
32
+ /**
33
+ * @template TRedeemerStrict
34
+ * @template TRedeemerPermissive
35
+ * @typedef {import("@helios-lang/ledger").StakingContext<TRedeemerStrict, TRedeemerPermissive>} StakingContext
36
+ */
37
+
38
+ /**
39
+ * @template {Cast} C
40
+ * @typedef {import("./PermissiveType.js").PermissiveType<C>} PermissiveType
41
+ */
42
+
43
+ /**
44
+ * @template {Cast} C
45
+ * @typedef {import("./StrictType.js").StrictType<C>} StrictType
46
+ */
47
+
48
+ /**
49
+ * @typedef {{
50
+ * $name: string
51
+ * $sourceCode: string
52
+ * $dependencies: Module[]
53
+ * }} Module
54
+ */
55
+
56
+ /**
57
+ * @typedef {{
58
+ * $name: string
59
+ * $purpose: string
60
+ * $sourceCode: string
61
+ * $dependencies: Module[]
62
+ * $hashDependencies: Validator[]
63
+ * $dependsOnOwnHash: boolean
64
+ * $Redeemer: Cast<any, any>
65
+ * $Datum?: Cast<any, any>
66
+ * }} Validator
67
+ */
68
+
69
+ /**
70
+ * @template {{[name: string]: Validator}} T
71
+ */
72
+ export class ContractContextBuilder {
73
+ /**
74
+ * @private
75
+ * @readonly
76
+ * @type {T}
77
+ */
78
+ validators
79
+
80
+ /**
81
+ * @private
82
+ * @param {T} validators
83
+ */
84
+ constructor(validators) {
85
+ this.validators = validators
86
+ }
87
+
88
+ /**
89
+ * @returns {ContractContextBuilder<{}>}
90
+ */
91
+ static new() {
92
+ return new ContractContextBuilder({})
93
+ }
94
+
95
+ /**
96
+ * @template {Validator} V
97
+ * @param {V} validator
98
+ * @returns {ContractContextBuilder<T & {
99
+ * [K in V["$name"]]: V
100
+ * }>}
101
+ */
102
+ with(validator) {
103
+ return new ContractContextBuilder({
104
+ ...this.validators,
105
+ [validator.$name]: validator
106
+ })
107
+ }
108
+
109
+ /**
110
+ *
111
+ * @param {Option<{[name: string]: string}>} expectedHashes
112
+ * @returns {{
113
+ * [K in keyof T]:
114
+ * T[K]["$purpose"] extends "spending" ? ValidatorHash<
115
+ * SpendingContext<
116
+ * StrictType<T[K]["$Datum"]>,
117
+ * PermissiveType<T[K]["$Datum"]>,
118
+ * StrictType<T[K]["$Redeemer"]>,
119
+ * PermissiveType<T[K]["$Redeemer"]>
120
+ * >
121
+ * > :
122
+ * T[K]["$purpose"] extends "minting" ? MintingPolicyHash<
123
+ * MintingContext<
124
+ * StrictType<T[K]["$Redeemer"]>,
125
+ * PermissiveType<T[K]["$Redeemer"]>
126
+ * >
127
+ * > :
128
+ * T[K]["$purpose"] extends ("certifying" | "rewarding") ? StakingValidatorHash<
129
+ * StakingContext<
130
+ * StrictType<T[K]["$Redeemer"]>,
131
+ * PermissiveType<T[K]["$Redeemer"]>
132
+ * >
133
+ * > : never
134
+ * }}
135
+ */
136
+ build(expectedHashes = None) {
137
+ const lib = loadLibrary()
138
+
139
+ /**
140
+ * @type {{[name: string]: (
141
+ * ValidatorHash<SpendingContext<any, any, any, any>> |
142
+ * MintingPolicyHash<MintingContext<any, any>> |
143
+ * StakingValidatorHash<StakingContext<any, any>>
144
+ * )}}
145
+ */
146
+ const validators = {}
147
+
148
+ /**
149
+ * @param {Validator} validator
150
+ * @returns {Map<string, string>}
151
+ */
152
+ function collectModules(validator) {
153
+ /**
154
+ * @type {Map<string, string>}
155
+ */
156
+ const result = new Map()
157
+
158
+ let stack = validator.$dependencies.slice()
159
+
160
+ let m = stack.pop()
161
+ while (m) {
162
+ if (result.has(m.$name)) {
163
+ continue
164
+ }
165
+
166
+ result.set(m.$name, m.$sourceCode)
167
+
168
+ stack = stack.concat(m.$dependencies)
169
+
170
+ m = stack.pop()
171
+ }
172
+
173
+ return result
174
+ }
175
+
176
+ /**
177
+ * @returns {{[name: string]: {purpose: string, hash: string}}}
178
+ */
179
+ function getOtherValidators() {
180
+ /**
181
+ * @type {{[name: string]: {purpose: string, hash: string}}}
182
+ */
183
+ const otherValidators = {}
184
+
185
+ for (let k in validators) {
186
+ const v = validators[k]
187
+
188
+ if (v instanceof ValidatorHash) {
189
+ otherValidators[k] = {
190
+ purpose: "spending",
191
+ hash: v.toHex()
192
+ }
193
+ } else if (v instanceof MintingPolicyHash) {
194
+ otherValidators[k] = {
195
+ purpose: "minting",
196
+ hash: v.toHex()
197
+ }
198
+ } else if (v instanceof StakingValidatorHash) {
199
+ otherValidators[k] = {
200
+ purpose: "staking",
201
+ hash: v.toHex()
202
+ }
203
+ } else {
204
+ throw new Error("unexpected ScriptHash")
205
+ }
206
+ }
207
+
208
+ return otherValidators
209
+ }
210
+
211
+ /**
212
+ * @param {Validator} validator
213
+ */
214
+ function buildValidator(validator) {
215
+ const name = validator.$name
216
+
217
+ if (name in validator) {
218
+ return
219
+ }
220
+
221
+ for (let v of validator.$hashDependencies) {
222
+ buildValidator(v)
223
+ }
224
+
225
+ const modules = collectModules(validator)
226
+
227
+ const { cborHex: optimizedCborHex } = lib.compile(
228
+ validator.$sourceCode,
229
+ Array.from(modules.values()),
230
+ {
231
+ optimize: true,
232
+ otherValidators: getOtherValidators(),
233
+ dependsOnOwnHash: validator.$dependsOnOwnHash
234
+ }
235
+ )
236
+
237
+ const optimizedProgram = UplcProgramV2.fromCbor(optimizedCborHex)
238
+
239
+ const ownHash = bytesToHex(optimizedProgram.hash())
240
+
241
+ if (expectedHashes && name in expectedHashes) {
242
+ if (expectedHashes[name] != ownHash) {
243
+ throw new Error(
244
+ `expected hash ${expectedHashes[name]} for validator ${name}, got ${ownHash}`
245
+ )
246
+ }
247
+ }
248
+
249
+ /**
250
+ * @type {ScriptHash}
251
+ */
252
+ let ownTypedHash
253
+
254
+ const purpose = validator.$purpose
255
+
256
+ switch (purpose) {
257
+ case "spending":
258
+ ownTypedHash = new ValidatorHash(ownHash)
259
+ break
260
+ case "minting":
261
+ ownTypedHash = new MintingPolicyHash(ownHash)
262
+ break
263
+ case "staking":
264
+ case "certifying":
265
+ case "rewarding":
266
+ ownTypedHash = new StakingValidatorHash(ownHash)
267
+ break
268
+ default:
269
+ throw new Error("unhandled purpose")
270
+ }
271
+
272
+ const { cborHex: unoptimizedCborHex } = lib.compile(
273
+ validator.$sourceCode,
274
+ Array.from(modules.values()),
275
+ {
276
+ optimize: false,
277
+ otherValidators: getOtherValidators(),
278
+ ownHash: validator.$dependsOnOwnHash ? ownHash : undefined
279
+ }
280
+ )
281
+
282
+ const unoptimizedProgram =
283
+ UplcProgramV2.fromCbor(unoptimizedCborHex)
284
+
285
+ if (purpose == "spending") {
286
+ validators[validator.$name] = new ValidatorHash(
287
+ ownTypedHash.bytes,
288
+ {
289
+ program: optimizedProgram.withAlt(unoptimizedProgram),
290
+ datum: expectSome(validator.$Datum),
291
+ redeemer: validator.$Redeemer
292
+ }
293
+ )
294
+ } else if (purpose == "minting") {
295
+ validators[validator.$name] = new MintingPolicyHash(
296
+ ownTypedHash.bytes,
297
+ {
298
+ program: optimizedProgram.withAlt(unoptimizedProgram),
299
+ redeemer: validator.$Redeemer
300
+ }
301
+ )
302
+ } else if (
303
+ purpose == "staking" ||
304
+ purpose == "certifying" ||
305
+ purpose == "rewarding"
306
+ ) {
307
+ validators[validator.$name] = new StakingValidatorHash(
308
+ ownTypedHash.bytes,
309
+ {
310
+ program: optimizedProgram.withAlt(unoptimizedProgram),
311
+ redeemer: validator.$Redeemer
312
+ }
313
+ )
314
+ } else {
315
+ throw new Error("unhandled purpose")
316
+ }
317
+ }
318
+
319
+ for (let k in this.validators) {
320
+ buildValidator(this.validators[k])
321
+ }
322
+
323
+ return /** @type {any} */ (validators)
324
+ }
325
+ }
@@ -0,0 +1,6 @@
1
+ import { Cast } from "./Cast.js"
2
+
3
+ /**
4
+ * @template {Cast} C
5
+ * @typedef {C extends Cast<any, infer TPermissive> ? TPermissive : never} PermissiveType
6
+ */
@@ -0,0 +1,6 @@
1
+ import { Cast } from "./Cast.js"
2
+
3
+ /**
4
+ * @template {Cast} C
5
+ * @typedef {C extends Cast<infer TStrict, any> ? TStrict : never} StrictType
6
+ */
@@ -1 +1,3 @@
1
- export { Cast } from "./Cast.js"
1
+ export { Cast } from "./Cast.js"
2
+ export { ContractContext } from "./ContractContext.js"
3
+ export { ContractContextBuilder } from "./ContractContextBuilder.js"
@@ -1 +1 @@
1
- {"version":3,"file":"TypescriptWriter.d.ts","sourceRoot":"","sources":["../../src/codegen/TypescriptWriter.js"],"names":[],"mappings":"AAGA;;;GAGG;AAEH;IAEQ,YAAuB;IACvB,aAAwB;IAG5B;;;;OAIG;IACH,UAJW,MAAM,QACN,MAAM,GACJ,gBAAgB,CAM5B;IAED;;;;OAIG;IACH,cAJW,MAAM,QACN,MAAM,GACJ,gBAAgB,CAY5B;IAED;;OAEG;IACH,eAFW,MAAM,QAmBhB;IAED;;OAEG;IACH,kBAFW,SAAS,QAiCnB;IAED,qBAMC;IAED;;OAEG;IACH;;aA4BC;IAED;;;OAGG;IACH;;aA8BC;IAED;;OAEG;IACH,YAFa,CAAC,MAAM,EAAE,MAAM,CAAC,CAI5B;CACJ;qBAnLY,OAAO,aAAa,EAAE,MAAM;wBAC5B,OAAO,gBAAgB,EAAE,SAAS;uBAJxB,aAAa"}
1
+ {"version":3,"file":"TypescriptWriter.d.ts","sourceRoot":"","sources":["../../src/codegen/TypescriptWriter.js"],"names":[],"mappings":"AAGA;;;GAGG;AAEH;IAEQ,YAAuB;IACvB,aAAwB;IAG5B;;;;OAIG;IACH,UAJW,MAAM,QACN,MAAM,GACJ,gBAAgB,CAM5B;IAED;;;;OAIG;IACH,cAJW,MAAM,QACN,MAAM,GACJ,gBAAgB,CAY5B;IAED;;OAEG;IACH,eAFW,MAAM,QAmBhB;IAED;;OAEG;IACH,kBAFW,SAAS,QAiCnB;IAED,qBAcC;IAED;;OAEG;IACH;;aA4BC;IAED;;;OAGG;IACH;;aA8BC;IAED;;OAEG;IACH,YAFa,CAAC,MAAM,EAAE,MAAM,CAAC,CAI5B;CACJ;qBA3LY,OAAO,aAAa,EAAE,MAAM;wBAC5B,OAAO,gBAAgB,EAAE,SAAS;uBAJxB,aAAa"}
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { Cast } from "./runtime/index.js";
1
+ export { Cast, ContractContextBuilder } from "./runtime/index.js";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1,8 +1,22 @@
1
+ /**
2
+ * @typedef {{
3
+ * otherValidators: {[name: string]: {purpose: string, hash: string}},
4
+ * dependsOnOwnHash?: boolean,
5
+ * ownHash?: string,
6
+ * optimize: boolean
7
+ * }} CompileOptions
8
+ */
9
+ /**
10
+ * @typedef {{
11
+ * cborHex: string
12
+ * }} CompileOutput
13
+ */
1
14
  /**
2
15
  * @typedef {{
3
16
  * version: string
4
17
  * typeCheck: (validators: {[name: string]: SourceDetails}, modules: {[name: string]: SourceDetails}) => ({
5
18
  * modules: {[name: string]: ModuleDetails}, validators: {[name: string]: ValidatorDetails}})
19
+ * compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput
6
20
  * }} Lib
7
21
  */
8
22
  /**
@@ -24,6 +38,20 @@
24
38
  export function getVersion(lib: {
25
39
  VERSION: string;
26
40
  }): number[];
41
+ export type CompileOptions = {
42
+ otherValidators: {
43
+ [name: string]: {
44
+ purpose: string;
45
+ hash: string;
46
+ };
47
+ };
48
+ dependsOnOwnHash?: boolean | undefined;
49
+ ownHash?: string | undefined;
50
+ optimize: boolean;
51
+ };
52
+ export type CompileOutput = {
53
+ cborHex: string;
54
+ };
27
55
  export type Lib = {
28
56
  version: string;
29
57
  typeCheck: (validators: {
@@ -38,6 +66,7 @@ export type Lib = {
38
66
  [name: string]: import("../codegen/Validator.js").Validator;
39
67
  };
40
68
  };
69
+ compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput;
41
70
  };
42
71
  export type InternalTypeDetails = import("../codegen/index.js").TypeSchema;
43
72
  export type ModuleDetails = import("../codegen/index.js").Module;
@@ -1 +1 @@
1
- {"version":3,"file":"Lib.d.ts","sourceRoot":"","sources":["../../src/lib/Lib.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;GAGG;AACH,gCAHW;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,GACf,MAAM,EAAE,CAIpB;;aA1Ba,MAAM;;;;;;;;;;;;;;kCAOP,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":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH;;;;;;;GAOG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;GAGG;AACH,gCAHW;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,GACf,MAAM,EAAE,CAIpB;;;;qBAzCgD,MAAM;kBAAQ,MAAM;;;;;cAGtD,OAAO;;4BAKT;IACZ,OAAW,EAAE,MAAM,CAAA;CAChB;;aAIU,MAAM;;;;;;;;;;;;;oBAGC,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,12 +1,3 @@
1
- /**
2
- * @typedef {import("./Lib.js").Lib} Lib
3
- * @typedef {import("./Lib.js").SourceDetails} SourceDetails
4
- */
5
- /**
6
- * @typedef {import("../codegen/index.js").Module} ModuleDetails
7
- * @typedef {import("../codegen/index.js").Validator} ValidatorDetails
8
- * @typedef {import("../codegen/index.js").TypeSchema} InternalTypeDetails
9
- */
10
1
  /**
11
2
  * @typedef {{
12
3
  * [name: string]: string[]
@@ -161,12 +152,21 @@ export class Lib_v0_16 implements Lib {
161
152
  * @returns {InternalTypeDetails}
162
153
  */
163
154
  getInternalTypeDetails(dt: DataType): InternalTypeDetails;
155
+ /**
156
+ * @param {string} main
157
+ * @param {string[]} modules
158
+ * @param {CompileOptions} options
159
+ * @returns {CompileOutput}
160
+ */
161
+ compile(main: string, modules: string[], options: CompileOptions): CompileOutput;
164
162
  }
165
- export type Lib = import("./Lib.js").Lib;
166
- export type SourceDetails = import("./Lib.js").SourceDetails;
167
163
  export type ModuleDetails = import("../codegen/index.js").Module;
168
164
  export type ValidatorDetails = import("../codegen/index.js").Validator;
169
165
  export type InternalTypeDetails = import("../codegen/index.js").TypeSchema;
166
+ export type CompileOptions = import("./Lib.js").CompileOptions;
167
+ export type CompileOutput = import("./Lib.js").CompileOutput;
168
+ export type Lib = import("./Lib.js").Lib;
169
+ export type SourceDetails = import("./Lib.js").SourceDetails;
170
170
  export type DagDependencies = {
171
171
  [name: string]: string[];
172
172
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Libg_v0_16.d.ts","sourceRoot":"","sources":["../../src/lib/Libg_v0_16.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;GAGG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;GAEG;AAEH;;;;;;GAMG;AACH;;;;;;;;;GASG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;GAGG;AAEH;;GAEG;AACH;IACI;;OAEG;IACH,iBAFW,GAAG,EAIb;IADG,SAAc;IAGlB;;OAEG;IACH,sBAEC;IAED;;;;OAIG;IACH,yBAWC;IAED;;;;;;OAMG;IACH,uBAcC;IAED;;;;;OAKG;IACH,iBAWC;IAED;;;;;OAKG;IACH,6BAeC;IAED;;;;OAIG;IACH;;;;;;;;;;;MAuEC;IAED;;;OAGG;IACH,wBAHW,UAAU,GACR,mBAAmB,CAgC/B;IAED;;;OAGG;IACH,2BAHW,QAAQ,GACN,mBAAmB,CAc/B;CACJ;kBApVY,OAAO,UAAU,EAAE,GAAG;4BACtB,OAAO,UAAU,EAAE,aAAa;4BAIhC,OAAO,qBAAqB,EAAE,MAAM;+BACpC,OAAO,qBAAqB,EAAE,SAAS;kCACvC,OAAO,qBAAqB,EAAE,UAAU;;;;uBAUxC,EACT;;kBAKe,MAAM,KAAK,OAAO;;4BAKxB;IACZ,MAAU,MAAM,CAAA;CACb;8BAIS;IACZ,MAAU,MAAM,CAAA;CACb;wBAIS,eAAe,GAAG,aAAa,GAAG,GAAG;;UAKvC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC;8BACK,MAAM,EAAE,KAAK,MAAM,EAAE;gBACnC,SAAS,EAAE;;;UAKjB,MAAM;gBACA,GAAG,SAAS,IAAI,MAAM,EAAE,EAAE,CAAC,KAAK,EAAE;WACvC,SAAS;yBACK,MAAM,EAAE;gBACjB,MAAM;kBACJ,QAAQ,EAAE;;uBAKhB;IACZ,WAAe,CAAC,EAAE,WAAW,CAAA;CAC1B;yBAIS;IACZ,IAAQ,EAAG,MAAM,CAAA;CACd,GAAG;IACN,IAAQ,EAAM,MAAM,CAAA;IACpB,QAAY,EAAE,UAAU,CAAA;CACrB,GAAG;IACN,IAAQ,EAAO,KAAK,CAAA;IACpB,OAAW,EAAI,UAAU,CAAA;IACzB,SAAa,EAAE,UAAU,CAAA;CACtB,GAAG;IACN,IAAQ,EAAM,QAAQ,CAAA;IACtB,QAAY,EAAE,UAAU,CAAA;CACrB,GAAG;IACN,IAAQ,EAAQ,QAAQ,CAAA;IACxB,UAAc,EAAE,eAAe,EAAE,CAAA;CAC9B,GAAG;IACN,IAAQ,EAAU,MAAM,CAAA;IACxB,YAAgB,EAAE;QAAC,MAAM,MAAM,CAAC;QAAC,UAAU,EAAE,eAAe,EAAE,CAAA;KAAC,EAAE,CAAA;CAC9D;8BAIS;IACZ,MAAU,MAAM,CAAA;CACb,GAAG,UAAU;0BAIJ;IACZ,SAAa,EAAE,MAAM,CAAA;IACrB,UAAc,EAAE,MAAM,CAAA;IACtB,YAAgB,EAAE,UAAU,CAAA;CACzB;wBAIS,EACT"}
1
+ {"version":3,"file":"Libg_v0_16.d.ts","sourceRoot":"","sources":["../../src/lib/Libg_v0_16.js"],"names":[],"mappings":"AAcA;;;;GAIG;AAEH;;;GAGG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;GAEG;AAEH;;;;;;GAMG;AACH;;;;;;;;;GASG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;GAGG;AAEH;;GAEG;AACH;IACI;;OAEG;IACH,iBAFW,GAAG,EAIb;IADG,SAAc;IAGlB;;OAEG;IACH,sBAEC;IAED;;;;OAIG;IACH,yBAWC;IAED;;;;;;OAMG;IACH,uBAcC;IAED;;;;;OAKG;IACH,iBAWC;IAED;;;;;OAKG;IACH,6BAeC;IAED;;;;OAIG;IACH;;;;;;;;;;;MAuEC;IAED;;;OAGG;IACH,wBAHW,UAAU,GACR,mBAAmB,CAgC/B;IAED;;;OAGG;IACH,2BAHW,QAAQ,GACN,mBAAmB,CAc/B;IAED;;;;;OAKG;IACH,cALW,MAAM,WACN,MAAM,EAAE,WACR,cAAc,GACZ,aAAa,CA4FzB;CACJ;4BAzbY,OAAO,qBAAqB,EAAE,MAAM;+BACpC,OAAO,qBAAqB,EAAE,SAAS;kCACvC,OAAO,qBAAqB,EAAE,UAAU;6BACxC,OAAO,UAAU,EAAE,cAAc;4BACjC,OAAO,UAAU,EAAE,aAAa;kBAChC,OAAO,UAAU,EAAE,GAAG;4BACtB,OAAO,UAAU,EAAE,aAAa;;;;uBAchC,EACT;;kBAKe,MAAM,KAAK,OAAO;;4BAKxB;IACZ,MAAU,MAAM,CAAA;CACb;8BAIS;IACZ,MAAU,MAAM,CAAA;CACb;wBAIS,eAAe,GAAG,aAAa,GAAG,GAAG;;UAKvC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC;8BACK,MAAM,EAAE,KAAK,MAAM,EAAE;gBACnC,SAAS,EAAE;;;UAKjB,MAAM;gBACA,GAAG,SAAS,IAAI,MAAM,EAAE,EAAE,CAAC,KAAK,EAAE;WACvC,SAAS;yBACK,MAAM,EAAE;gBACjB,MAAM;kBACJ,QAAQ,EAAE;;uBAKhB;IACZ,WAAe,CAAC,EAAE,WAAW,CAAA;CAC1B;yBAIS;IACZ,IAAQ,EAAG,MAAM,CAAA;CACd,GAAG;IACN,IAAQ,EAAM,MAAM,CAAA;IACpB,QAAY,EAAE,UAAU,CAAA;CACrB,GAAG;IACN,IAAQ,EAAO,KAAK,CAAA;IACpB,OAAW,EAAI,UAAU,CAAA;IACzB,SAAa,EAAE,UAAU,CAAA;CACtB,GAAG;IACN,IAAQ,EAAM,QAAQ,CAAA;IACtB,QAAY,EAAE,UAAU,CAAA;CACrB,GAAG;IACN,IAAQ,EAAQ,QAAQ,CAAA;IACxB,UAAc,EAAE,eAAe,EAAE,CAAA;CAC9B,GAAG;IACN,IAAQ,EAAU,MAAM,CAAA;IACxB,YAAgB,EAAE;QAAC,MAAM,MAAM,CAAC;QAAC,UAAU,EAAE,eAAe,EAAE,CAAA;KAAC,EAAE,CAAA;CAC9D;8BAIS;IACZ,MAAU,MAAM,CAAA;CACb,GAAG,UAAU;0BAIJ;IACZ,SAAa,EAAE,MAAM,CAAA;IACrB,UAAc,EAAE,MAAM,CAAA;IACtB,YAAgB,EAAE,UAAU,CAAA;CACzB;wBAIS,EACT"}
@@ -1,6 +1,9 @@
1
1
  /**
2
- * @returns {Promise<Lib>}
2
+ * @typedef {import("./Lib.js").Lib} Lib
3
3
  */
4
- export function loadLibrary(): Promise<Lib>;
4
+ /**
5
+ * @returns {Lib}
6
+ */
7
+ export function loadLibrary(): Lib;
5
8
  export type Lib = import("./Lib.js").Lib;
6
9
  //# sourceMappingURL=load.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/lib/load.js"],"names":[],"mappings":"AA0BA;;GAEG;AACH,+BAFa,QAAQ,GAAG,CAAC,CAiCxB;kBAtDY,OAAO,UAAU,EAAE,GAAG"}
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/lib/load.js"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;GAEG;AACH,+BAFa,GAAG,CAcf;kBAlBY,OAAO,UAAU,EAAE,GAAG"}
@@ -3,10 +3,10 @@
3
3
  * @typedef {import("../codegen/index.js").TypeSchema} TypeSchema
4
4
  */
5
5
  /**
6
- * @template TStrict
7
- * @template TPermissive
6
+ * @template [TStrict=UplcData]
7
+ * @template [TPermissive=UplcData]
8
8
  */
9
- export class Cast<TStrict, TPermissive> {
9
+ export class Cast<TStrict = import("@helios-lang/ledger").UplcData, TPermissive = import("@helios-lang/ledger").UplcData> {
10
10
  /**
11
11
  * @param {TypeSchema} schema
12
12
  */
@@ -20,12 +20,12 @@ export class Cast<TStrict, TPermissive> {
20
20
  * @param {UplcData} data
21
21
  * @returns {TStrict}
22
22
  */
23
- fromUplc(data: UplcData): TStrict;
23
+ fromUplcData(data: UplcData): TStrict;
24
24
  /**
25
25
  * @param {TPermissive} x
26
26
  * @returns {UplcData}
27
27
  */
28
- toUplc(x: TPermissive): UplcData;
28
+ toUplcData(x: TPermissive): UplcData;
29
29
  }
30
30
  export type UplcData = import("@helios-lang/uplc").UplcData;
31
31
  export type TypeSchema = import("../codegen/index.js").TypeSchema;
@@ -1 +1 @@
1
- {"version":3,"file":"Cast.d.ts","sourceRoot":"","sources":["../../src/runtime/Cast.js"],"names":[],"mappings":"AAgCA;;;GAGG;AAEH;;;GAGG;AACH;IAOI;;OAEG;IACH,oBAFW,UAAU,EAIpB;IAXD;;;OAGG;IACH,iBAFU,UAAU,CAEd;IASN;;;OAGG;IACH,eAHW,QAAQ,GACN,OAAO,CAInB;IAED;;;OAGG;IACH,UAHW,WAAW,GACT,QAAQ,CAIpB;CACJ;uBArCY,OAAO,mBAAmB,EAAE,QAAQ;yBACpC,OAAO,qBAAqB,EAAE,UAAU"}
1
+ {"version":3,"file":"Cast.d.ts","sourceRoot":"","sources":["../../src/runtime/Cast.js"],"names":[],"mappings":"AAgCA;;;GAGG;AAEH;;;GAGG;AACH;IAOI;;OAEG;IACH,oBAFW,UAAU,EAIpB;IAXD;;;OAGG;IACH,iBAFU,UAAU,CAEd;IASN;;;OAGG;IACH,mBAHW,QAAQ,GACN,OAAO,CAInB;IAED;;;OAGG;IACH,cAHW,WAAW,GACT,QAAQ,CAIpB;CACJ;uBArCY,OAAO,mBAAmB,EAAE,QAAQ;yBACpC,OAAO,qBAAqB,EAAE,UAAU"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @typedef {{
3
+ * $name: string
4
+ * $purpose: string
5
+ * $program: {
6
+ * optimized: UplcProgramV2
7
+ * unoptimized: UplcProgramV2
8
+ * }
9
+ * $hash: ScriptHash
10
+ * $Redeemer: Cast<any, any>
11
+ * $Datum?: Cast<any, any>
12
+ * }} Validator
13
+ */
14
+ /**
15
+ * @template {{[name: string]: Validator}} T
16
+ */
17
+ export class ContractContext<T extends {
18
+ [name: string]: Validator;
19
+ }> {
20
+ /**
21
+ * @param {T} validators
22
+ */
23
+ constructor(validators: T);
24
+ /**
25
+ * @readonly
26
+ * @type {T}
27
+ */
28
+ readonly validators: T;
29
+ }
30
+ export type Validator = {
31
+ $name: string;
32
+ $purpose: string;
33
+ $program: {
34
+ optimized: UplcProgramV2;
35
+ unoptimized: UplcProgramV2;
36
+ };
37
+ $hash: ScriptHash;
38
+ $Redeemer: Cast<any, any>;
39
+ $Datum?: Cast<any, any>;
40
+ };
41
+ import { UplcProgramV2 } from "@helios-lang/uplc";
42
+ import { ScriptHash } from "@helios-lang/ledger";
43
+ import { Cast } from "./Cast.js";
44
+ //# sourceMappingURL=ContractContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractContext.d.ts","sourceRoot":"","sources":["../../src/runtime/ContractContext.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH;;;IAOI;;OAEG;IACH,wBAFW,CAAC,EAIX;IAXD;;;OAGG;IACH,qBAFU,CAAC,CAED;CAQb;wBA7BY;IACZ,KAAS,EAAE,MAAM,CAAA;IACjB,QAAY,EAAE,MAAM,CAAA;IACpB,QAAY,EAAE;QACd,SAAe,EAAE,aAAa,CAAA;QAC9B,WAAiB,EAAE,aAAa,CAAA;KAC3B,CAAA;IACL,KAAS,EAAE,UAAU,CAAA;IACrB,SAAa,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,CAAA;IAC7B,MAAU,CAAC,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,CAAA;CACxB;8BAd0B,mBAAmB;2BADtB,qBAAqB;qBAE3B,WAAW"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @typedef {import("./ContractContext.js").Validator} CompiledValidator
3
+ */
4
+ /**
5
+ * @template TRedeemerStrict
6
+ * @template TRedeemerPermissive
7
+ * @typedef {import("@helios-lang/ledger").MintingContext<TRedeemerStrict, TRedeemerPermissive>} MintingContext
8
+ */
9
+ /**
10
+ * @template TDatumStrict
11
+ * @template TDatumPermissive
12
+ * @template TRedeemerStrict
13
+ * @template TRedeemerPermissive
14
+ * @typedef {import("@helios-lang/ledger").SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive>} SpendingContext
15
+ */
16
+ /**
17
+ * @template TRedeemerStrict
18
+ * @template TRedeemerPermissive
19
+ * @typedef {import("@helios-lang/ledger").StakingContext<TRedeemerStrict, TRedeemerPermissive>} StakingContext
20
+ */
21
+ /**
22
+ * @template {Cast} C
23
+ * @typedef {import("./PermissiveType.js").PermissiveType<C>} PermissiveType
24
+ */
25
+ /**
26
+ * @template {Cast} C
27
+ * @typedef {import("./StrictType.js").StrictType<C>} StrictType
28
+ */
29
+ /**
30
+ * @typedef {{
31
+ * $name: string
32
+ * $sourceCode: string
33
+ * $dependencies: Module[]
34
+ * }} Module
35
+ */
36
+ /**
37
+ * @typedef {{
38
+ * $name: string
39
+ * $purpose: string
40
+ * $sourceCode: string
41
+ * $dependencies: Module[]
42
+ * $hashDependencies: Validator[]
43
+ * $dependsOnOwnHash: boolean
44
+ * $Redeemer: Cast<any, any>
45
+ * $Datum?: Cast<any, any>
46
+ * }} Validator
47
+ */
48
+ /**
49
+ * @template {{[name: string]: Validator}} T
50
+ */
51
+ export class ContractContextBuilder<T extends {
52
+ [name: string]: Validator;
53
+ }> {
54
+ /**
55
+ * @returns {ContractContextBuilder<{}>}
56
+ */
57
+ static "new"(): ContractContextBuilder<{}>;
58
+ /**
59
+ * @private
60
+ * @param {T} validators
61
+ */
62
+ private constructor();
63
+ /**
64
+ * @private
65
+ * @readonly
66
+ * @type {T}
67
+ */
68
+ private readonly validators;
69
+ /**
70
+ * @template {Validator} V
71
+ * @param {V} validator
72
+ * @returns {ContractContextBuilder<T & {
73
+ * [K in V["$name"]]: V
74
+ * }>}
75
+ */
76
+ with<V extends Validator>(validator: V): ContractContextBuilder<T & { [K in V["$name"]]: V; }>;
77
+ /**
78
+ *
79
+ * @param {Option<{[name: string]: string}>} expectedHashes
80
+ * @returns {{
81
+ * [K in keyof T]:
82
+ * T[K]["$purpose"] extends "spending" ? ValidatorHash<
83
+ * SpendingContext<
84
+ * StrictType<T[K]["$Datum"]>,
85
+ * PermissiveType<T[K]["$Datum"]>,
86
+ * StrictType<T[K]["$Redeemer"]>,
87
+ * PermissiveType<T[K]["$Redeemer"]>
88
+ * >
89
+ * > :
90
+ * T[K]["$purpose"] extends "minting" ? MintingPolicyHash<
91
+ * MintingContext<
92
+ * StrictType<T[K]["$Redeemer"]>,
93
+ * PermissiveType<T[K]["$Redeemer"]>
94
+ * >
95
+ * > :
96
+ * T[K]["$purpose"] extends ("certifying" | "rewarding") ? StakingValidatorHash<
97
+ * StakingContext<
98
+ * StrictType<T[K]["$Redeemer"]>,
99
+ * PermissiveType<T[K]["$Redeemer"]>
100
+ * >
101
+ * > : never
102
+ * }}
103
+ */
104
+ build(expectedHashes?: Option<{
105
+ [name: string]: string;
106
+ }>): { [K_1 in keyof T]: T[K_1]["$purpose"] extends "spending" ? ValidatorHash<SpendingContext<import("./StrictType.js").StrictType<T[K_1]["$Datum"]>, import("./PermissiveType.js").PermissiveType<T[K_1]["$Datum"]>, import("./StrictType.js").StrictType<T[K_1]["$Redeemer"]>, import("./PermissiveType.js").PermissiveType<T[K_1]["$Redeemer"]>>> : T[K_1]["$purpose"] extends "minting" ? MintingPolicyHash<MintingContext<import("./StrictType.js").StrictType<T[K_1]["$Redeemer"]>, import("./PermissiveType.js").PermissiveType<T[K_1]["$Redeemer"]>>> : T[K_1]["$purpose"] extends "certifying" | "rewarding" ? StakingValidatorHash<StakingContext<import("./StrictType.js").StrictType<T[K_1]["$Redeemer"]>, import("./PermissiveType.js").PermissiveType<T[K_1]["$Redeemer"]>>> : never; };
107
+ }
108
+ export type CompiledValidator = import("./ContractContext.js").Validator;
109
+ export type MintingContext<TRedeemerStrict, TRedeemerPermissive> = import("@helios-lang/ledger").MintingContext<TRedeemerStrict, TRedeemerPermissive>;
110
+ export type SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive> = import("@helios-lang/ledger").SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive>;
111
+ export type StakingContext<TRedeemerStrict, TRedeemerPermissive> = import("@helios-lang/ledger").StakingContext<TRedeemerStrict, TRedeemerPermissive>;
112
+ export type PermissiveType<C extends Cast<import("@helios-lang/ledger").UplcData, import("@helios-lang/ledger").UplcData>> = import("./PermissiveType.js").PermissiveType<C>;
113
+ export type StrictType<C extends Cast<import("@helios-lang/ledger").UplcData, import("@helios-lang/ledger").UplcData>> = import("./StrictType.js").StrictType<C>;
114
+ export type Module = {
115
+ $name: string;
116
+ $sourceCode: string;
117
+ $dependencies: Module[];
118
+ };
119
+ export type Validator = {
120
+ $name: string;
121
+ $purpose: string;
122
+ $sourceCode: string;
123
+ $dependencies: Module[];
124
+ $hashDependencies: Validator[];
125
+ $dependsOnOwnHash: boolean;
126
+ $Redeemer: Cast<any, any>;
127
+ $Datum?: Cast<any, any>;
128
+ };
129
+ import { ValidatorHash } from "@helios-lang/ledger";
130
+ import { MintingPolicyHash } from "@helios-lang/ledger";
131
+ import { StakingValidatorHash } from "@helios-lang/ledger";
132
+ import { Cast } from "./Cast.js";
133
+ //# sourceMappingURL=ContractContextBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractContextBuilder.d.ts","sourceRoot":"","sources":["../../src/runtime/ContractContextBuilder.js"],"names":[],"mappings":"AAaA;;GAEG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;GAIG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;GAWG;AAEH;;GAEG;AACH;;;IAgBI;;OAEG;IACH,gBAFa,uBAAuB,EAAE,CAAC,CAItC;IAbD;;;OAGG;IACH,sBAEC;IAbD;;;;OAIG;IACH,4BAAU;IAiBV;;;;;;OAMG;IACH,+FAKC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH;;2wBA4LC;CACJ;gCAtTY,OAAO,sBAAsB,EAAE,SAAS;mEAMxC,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;6HAKlF,OAAO,qBAAqB,EAAE,cAAc,CAAC,CAAC,CAAC;yHAK/C,OAAO,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;qBAIvC;IACZ,KAAS,EAAE,MAAM,CAAA;IACjB,WAAe,EAAE,MAAM,CAAA;IACvB,aAAiB,EAAE,MAAM,EAAE,CAAA;CACxB;wBAIS;IACZ,KAAS,EAAE,MAAM,CAAA;IACjB,QAAY,EAAE,MAAM,CAAA;IACpB,WAAe,EAAE,MAAM,CAAA;IACvB,aAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,iBAAqB,EAAE,SAAS,EAAE,CAAA;IAClC,iBAAqB,EAAE,OAAO,CAAA;IAC9B,SAAa,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,CAAA;IAC7B,MAAU,CAAC,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,CAAA;CACxB;8BA3DG,qBAAqB;kCAArB,qBAAqB;qCAArB,qBAAqB;qBAIP,WAAW"}
@@ -0,0 +1,3 @@
1
+ export type PermissiveType<C extends Cast<import("@helios-lang/uplc/types/data/UplcData.js").UplcData, import("@helios-lang/uplc/types/data/UplcData.js").UplcData>> = C extends Cast<any, infer TPermissive> ? TPermissive : never;
2
+ import { Cast } from "./Cast.js";
3
+ //# sourceMappingURL=PermissiveType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PermissiveType.d.ts","sourceRoot":"","sources":["../../src/runtime/PermissiveType.js"],"names":[],"mappings":";qBAAqB,WAAW"}
@@ -0,0 +1,3 @@
1
+ export type StrictType<C extends Cast<import("@helios-lang/uplc/types/data/UplcData.js").UplcData, import("@helios-lang/uplc/types/data/UplcData.js").UplcData>> = C extends Cast<infer TStrict, any> ? TStrict : never;
2
+ import { Cast } from "./Cast.js";
3
+ //# sourceMappingURL=StrictType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StrictType.d.ts","sourceRoot":"","sources":["../../src/runtime/StrictType.js"],"names":[],"mappings":";qBAAqB,WAAW"}
@@ -1,2 +1,4 @@
1
1
  export { Cast } from "./Cast.js";
2
+ export { ContractContext } from "./ContractContext.js";
3
+ export { ContractContextBuilder } from "./ContractContextBuilder.js";
2
4
  //# sourceMappingURL=index.d.ts.map