@helios-lang/contract-utils 0.1.20 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/examples/multi-validator/README.md +5 -0
  2. package/examples/{spending → multi-validator}/contract.js +7 -2
  3. package/examples/{spending → multi-validator}/index.d.ts +1 -1
  4. package/examples/{spending → multi-validator}/index.js +3 -3
  5. package/examples/{spending → multi-validator}/spending.hl +3 -2
  6. package/package.json +5 -5
  7. package/src/{runtime → cast}/Cast.js +31 -8
  8. package/src/cast/index.js +12 -0
  9. package/src/codegen/LoadedModule.js +9 -0
  10. package/src/codegen/{TypescriptWriter.js → LoadedScriptsWriter.js} +117 -107
  11. package/src/codegen/LoadedValidator.js +23 -0
  12. package/src/codegen/{Module.js → TypeCheckedModule.js} +3 -3
  13. package/src/codegen/{Validator.js → TypeCheckedValidator.js} +5 -8
  14. package/src/codegen/TypeSchema.js +4 -0
  15. package/src/codegen/index.js +5 -4
  16. package/src/compiler/CompilerLib.js +51 -0
  17. package/src/{lib/Libg_v0_16.js → compiler/CompilerLib_v0_16.js} +243 -255
  18. package/src/compiler/index.js +6 -0
  19. package/src/compiler/ops.js +137 -0
  20. package/src/context/ContractContext.js +78 -0
  21. package/src/context/ContractContextBuilder.js +69 -0
  22. package/src/context/DagCompiler.js +229 -0
  23. package/src/context/index.js +1 -0
  24. package/src/hl2ts.js +31 -59
  25. package/src/index.js +12 -1
  26. package/types/cast/Cast.d.ts +32 -0
  27. package/types/cast/Cast.d.ts.map +1 -0
  28. package/types/cast/PermissiveType.d.ts +3 -0
  29. package/types/cast/PermissiveType.d.ts.map +1 -0
  30. package/types/cast/StrictType.d.ts +3 -0
  31. package/types/cast/StrictType.d.ts.map +1 -0
  32. package/types/cast/index.d.ts +5 -0
  33. package/types/cast/index.d.ts.map +1 -0
  34. package/types/codegen/LoadedModule.d.ts +6 -0
  35. package/types/codegen/LoadedModule.d.ts.map +1 -0
  36. package/types/codegen/LoadedScriptsWriter.d.ts +56 -0
  37. package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -0
  38. package/types/codegen/LoadedValidator.d.ts +16 -0
  39. package/types/codegen/LoadedValidator.d.ts.map +1 -0
  40. package/types/codegen/TypeCheckedModule.d.ts +11 -0
  41. package/types/codegen/TypeCheckedModule.d.ts.map +1 -0
  42. package/types/codegen/TypeCheckedValidator.d.ts +8 -0
  43. package/types/codegen/TypeCheckedValidator.d.ts.map +1 -0
  44. package/types/codegen/TypeSchema.d.ts +10 -0
  45. package/types/codegen/TypeSchema.d.ts.map +1 -1
  46. package/types/codegen/TypescriptWriter.d.ts +4 -4
  47. package/types/codegen/Validator.d.ts +1 -1
  48. package/types/codegen/index.d.ts +5 -4
  49. package/types/codegen/index.d.ts.map +1 -1
  50. package/types/compiler/CompilerLib.d.ts +45 -0
  51. package/types/compiler/CompilerLib.d.ts.map +1 -0
  52. package/types/compiler/CompilerLib_v0_16.d.ts +270 -0
  53. package/types/compiler/CompilerLib_v0_16.d.ts.map +1 -0
  54. package/types/compiler/index.d.ts +4 -0
  55. package/types/compiler/index.d.ts.map +1 -0
  56. package/types/compiler/ops.d.ts +24 -0
  57. package/types/compiler/ops.d.ts.map +1 -0
  58. package/types/context/ContractContext.d.ts +23 -0
  59. package/types/context/ContractContext.d.ts.map +1 -0
  60. package/types/context/ContractContextBuilder.d.ts +53 -0
  61. package/types/context/ContractContextBuilder.d.ts.map +1 -0
  62. package/types/context/DagCompiler.d.ts +64 -0
  63. package/types/context/DagCompiler.d.ts.map +1 -0
  64. package/types/context/index.d.ts +2 -0
  65. package/types/context/index.d.ts.map +1 -0
  66. package/types/hl2ts.d.ts +8 -4
  67. package/types/hl2ts.d.ts.map +1 -1
  68. package/types/index.d.ts +4 -1
  69. package/types/index.d.ts.map +1 -1
  70. package/types/lib/Lib.d.ts +13 -71
  71. package/types/lib/Lib.d.ts.map +1 -1
  72. package/types/lib/Libg_v0_16.d.ts +53 -52
  73. package/types/lib/Libg_v0_16.d.ts.map +1 -1
  74. package/types/lib/index.d.ts +0 -1
  75. package/types/lib/index.d.ts.map +1 -1
  76. package/types/lib/load.d.ts +1 -7
  77. package/types/lib/load.d.ts.map +1 -1
  78. package/types/runtime/ContractContext.d.ts +22 -43
  79. package/types/runtime/ContractContext.d.ts.map +1 -1
  80. package/types/runtime/ContractContextBuilder.d.ts +15 -123
  81. package/types/runtime/ContractContextBuilder.d.ts.map +1 -1
  82. package/types/runtime/DagCompiler.d.ts +64 -0
  83. package/types/runtime/DagCompiler.d.ts.map +1 -0
  84. package/types/runtime/PermissiveType.d.ts +1 -1
  85. package/types/runtime/StrictType.d.ts +1 -1
  86. package/types/runtime/index.d.ts +0 -2
  87. package/src/codegen/Writer.js +0 -37
  88. package/src/lib/Lib.js +0 -56
  89. package/src/lib/index.js +0 -6
  90. package/src/lib/load.js +0 -26
  91. package/src/runtime/ContractContext.js +0 -35
  92. package/src/runtime/ContractContextBuilder.js +0 -340
  93. package/src/runtime/index.js +0 -3
  94. /package/examples/{spending → multi-validator}/minting.hl +0 -0
  95. /package/examples/{spending → multi-validator}/package-lock.json +0 -0
  96. /package/examples/{spending → multi-validator}/package.json +0 -0
  97. /package/examples/{spending → multi-validator}/utils.hl +0 -0
  98. /package/src/{runtime → cast}/PermissiveType.js +0 -0
  99. /package/src/{runtime → cast}/StrictType.js +0 -0
@@ -1,57 +1,17 @@
1
1
  /**
2
+ * @typedef {import("../codegen/LoadedModule.js").LoadedModule} LoadedModule
3
+ * @typedef {import("../codegen/LoadedValidator.js").LoadedValidator} LoadedValidator
2
4
  * @typedef {import("../lib/index.js").Lib} Lib
3
- * @typedef {import("../lib/index.js").LibOptions} LibOptions
4
- * @typedef {import("./ContractContext.js").Validator} CompiledValidator
5
5
  */
6
6
  /**
7
- * @template TRedeemerStrict
8
- * @template TRedeemerPermissive
9
- * @typedef {import("@helios-lang/ledger").MintingContext<TRedeemerStrict, TRedeemerPermissive>} MintingContext
7
+ * @template {{[name: string]: LoadedValidator}} T
8
+ * @typedef {import("./ContractContext.js").ContractContext<T>} ContractContext
10
9
  */
11
10
  /**
12
- * @template TDatumStrict
13
- * @template TDatumPermissive
14
- * @template TRedeemerStrict
15
- * @template TRedeemerPermissive
16
- * @typedef {import("@helios-lang/ledger").SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive>} SpendingContext
17
- */
18
- /**
19
- * @template TRedeemerStrict
20
- * @template TRedeemerPermissive
21
- * @typedef {import("@helios-lang/ledger").StakingContext<TRedeemerStrict, TRedeemerPermissive>} StakingContext
22
- */
23
- /**
24
- * @template {Cast} C
25
- * @typedef {import("./PermissiveType.js").PermissiveType<C>} PermissiveType
26
- */
27
- /**
28
- * @template {Cast} C
29
- * @typedef {import("./StrictType.js").StrictType<C>} StrictType
30
- */
31
- /**
32
- * @typedef {{
33
- * $name: string
34
- * $sourceCode: string
35
- * $dependencies: Module[]
36
- * }} Module
37
- */
38
- /**
39
- * @typedef {{
40
- * $name: string
41
- * $purpose: string
42
- * $sourceCode: string
43
- * $dependencies: Module[]
44
- * $hashDependencies: Validator[]
45
- * $dependsOnOwnHash: boolean
46
- * $Redeemer: Cast<any, any>
47
- * $Datum?: Cast<any, any>
48
- * }} Validator
49
- */
50
- /**
51
- * @template {{[name: string]: Validator}} T
11
+ * @template {{[name: string]: LoadedValidator}} T
52
12
  */
53
13
  export class ContractContextBuilder<T extends {
54
- [name: string]: Validator;
14
+ [name: string]: import("./DagCompiler.js").LoadedValidator;
55
15
  }> {
56
16
  /**
57
17
  * @returns {ContractContextBuilder<{}>}
@@ -60,7 +20,6 @@ export class ContractContextBuilder<T extends {
60
20
  /**
61
21
  * @private
62
22
  * @param {T} validators
63
- * @param {Option<Module[]>} forcedModules
64
23
  */
65
24
  private constructor();
66
25
  /**
@@ -70,92 +29,25 @@ export class ContractContextBuilder<T extends {
70
29
  */
71
30
  private readonly validators;
72
31
  /**
73
- * @private
74
- * @readonly
75
- * @type {Option<Module[]>}
76
- */
77
- private readonly forcedModules;
78
- /**
79
- * @param {Module[]} modules
80
- * @returns {ContractContextBuilder<T>}
81
- */
82
- setModules(modules: Module[]): ContractContextBuilder<T>;
83
- /**
84
- * @template {Validator} V
32
+ * @template {LoadedValidator} V
85
33
  * @param {V} validator
86
34
  * @returns {ContractContextBuilder<T & {
87
35
  * [K in V["$name"]]: V
88
36
  * }>}
89
37
  */
90
- with<V extends Validator>(validator: V): ContractContextBuilder<T & { [K in V["$name"]]: V; }>;
91
- /**
92
- * @private
93
- * @param {Validator} validator
94
- * @returns {Map<string, string>}
95
- */
96
- private getModules;
97
- /**
98
- * @private
99
- * @param {Lib} lib
100
- * @returns {{[name: string]: any}}
101
- */
102
- private getValidatorTypes;
38
+ with<V extends import("./DagCompiler.js").LoadedValidator>(validator: V): ContractContextBuilder<T & { [K in V["$name"]]: V; }>;
103
39
  /**
104
40
  * @param {Option<{[name: string]: string}>} expectedHashes
105
- * @param {LibOptions} options
106
- * @returns {{
107
- * [K in keyof T]:
108
- * T[K]["$purpose"] extends "spending" ? ValidatorHash<
109
- * SpendingContext<
110
- * StrictType<T[K]["$Datum"]>,
111
- * PermissiveType<T[K]["$Datum"]>,
112
- * StrictType<T[K]["$Redeemer"]>,
113
- * PermissiveType<T[K]["$Redeemer"]>
114
- * >
115
- * > :
116
- * T[K]["$purpose"] extends "minting" ? MintingPolicyHash<
117
- * MintingContext<
118
- * StrictType<T[K]["$Redeemer"]>,
119
- * PermissiveType<T[K]["$Redeemer"]>
120
- * >
121
- * > :
122
- * T[K]["$purpose"] extends ("certifying" | "rewarding") ? StakingValidatorHash<
123
- * StakingContext<
124
- * StrictType<T[K]["$Redeemer"]>,
125
- * PermissiveType<T[K]["$Redeemer"]>
126
- * >
127
- * > : never
128
- * }}
41
+ * @returns {ContractContext<T>}
129
42
  */
130
43
  build(expectedHashes?: Option<{
131
44
  [name: string]: string;
132
- }>, options?: LibOptions): { [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; };
45
+ }>): ContractContext<T>;
133
46
  }
47
+ export type LoadedModule = import("../codegen/LoadedModule.js").LoadedModule;
48
+ export type LoadedValidator = import("../codegen/LoadedValidator.js").LoadedValidator;
134
49
  export type Lib = import("../lib/index.js").Lib;
135
- export type LibOptions = import("../lib/index.js").LibOptions;
136
- export type CompiledValidator = import("./ContractContext.js").Validator;
137
- export type MintingContext<TRedeemerStrict, TRedeemerPermissive> = import("@helios-lang/ledger").MintingContext<TRedeemerStrict, TRedeemerPermissive>;
138
- export type SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive> = import("@helios-lang/ledger").SpendingContext<TDatumStrict, TDatumPermissive, TRedeemerStrict, TRedeemerPermissive>;
139
- export type StakingContext<TRedeemerStrict, TRedeemerPermissive> = import("@helios-lang/ledger").StakingContext<TRedeemerStrict, TRedeemerPermissive>;
140
- export type PermissiveType<C extends Cast<import("@helios-lang/ledger").UplcData, import("@helios-lang/ledger").UplcData>> = import("./PermissiveType.js").PermissiveType<C>;
141
- export type StrictType<C extends Cast<import("@helios-lang/ledger").UplcData, import("@helios-lang/ledger").UplcData>> = import("./StrictType.js").StrictType<C>;
142
- export type Module = {
143
- $name: string;
144
- $sourceCode: string;
145
- $dependencies: Module[];
146
- };
147
- export type Validator = {
148
- $name: string;
149
- $purpose: string;
150
- $sourceCode: string;
151
- $dependencies: Module[];
152
- $hashDependencies: Validator[];
153
- $dependsOnOwnHash: boolean;
154
- $Redeemer: Cast<any, any>;
155
- $Datum?: Cast<any, any>;
156
- };
157
- import { ValidatorHash } from "@helios-lang/ledger";
158
- import { MintingPolicyHash } from "@helios-lang/ledger";
159
- import { StakingValidatorHash } from "@helios-lang/ledger";
160
- import { Cast } from "./Cast.js";
50
+ export type ContractContext<T extends {
51
+ [name: string]: import("./DagCompiler.js").LoadedValidator;
52
+ }> = import("./ContractContext.js").ContractContext<T>;
161
53
  //# sourceMappingURL=ContractContextBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContractContextBuilder.d.ts","sourceRoot":"","sources":["../../src/runtime/ContractContextBuilder.js"],"names":[],"mappings":"AAaA;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;GAIG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;GAWG;AAEH;;GAEG;AACH;;;IAyBI;;OAEG;IACH,gBAFa,uBAAuB,EAAE,CAAC,CAItC;IAfD;;;;OAIG;IACH,sBAGC;IAtBD;;;;OAIG;IACH,4BAAU;IAEV;;;;OAIG;IACH,+BAAa;IAmBb;;;OAGG;IACH,oBAHW,MAAM,EAAE,GACN,uBAAuB,CAAC,CAAC,CAIrC;IAED;;;;;;OAMG;IACH,+FAQC;IAED;;;;OAIG;IACH,mBAyBC;IAED;;;;OAIG;IACH,0BAMC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH;;kBAzBW,UAAU,qwBAiKpB;CACJ;kBArUY,OAAO,iBAAiB,EAAE,GAAG;yBAC7B,OAAO,iBAAiB,EAAE,UAAU;gCACpC,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;8BA7DG,qBAAqB;kCAArB,qBAAqB;qCAArB,qBAAqB;qBAIP,WAAW"}
1
+ {"version":3,"file":"ContractContextBuilder.d.ts","sourceRoot":"","sources":["../../src/runtime/ContractContextBuilder.js"],"names":[],"mappings":"AAIA;;;;GAIG;AAEH;;;GAGG;AAEH;;GAEG;AACH;;;IAgBI;;OAEG;IACH,gBAFa,uBAAuB,EAAE,CAAC,CAItC;IAbD;;;OAGG;IACH,sBAEC;IAbD;;;;OAIG;IACH,4BAAU;IAiBV;;;;;;OAMG;IACH,gIAKC;IAED;;;OAGG;IACH;;SAFa,gBAAgB,CAAC,CAAC,CAU9B;CACJ;2BA/DY,OAAO,4BAA4B,EAAE,YAAY;8BACjD,OAAO,+BAA+B,EAAE,eAAe;kBACvD,OAAO,iBAAiB,EAAE,GAAG;;;KAK7B,OAAO,sBAAsB,EAAE,eAAe,CAAC,CAAC,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @param {LoadedValidator} validator
3
+ * @returns {string[]}
4
+ */
5
+ export function getModuleDependencies(validator: LoadedValidator): string[];
6
+ /**
7
+ * @typedef {import("../codegen/LoadedValidator.js").LoadedValidator} LoadedValidator
8
+ * @typedef {import("../lib/index.js").Lib} Lib
9
+ * @typedef {import("./ContractContext.js").AnyContractValidatorHash} AnyContractValidatorHash
10
+ */
11
+ /**
12
+ * Compiles a set of validators that depend on eachothers hashes (forming a Directed Acyclical Graph)
13
+ */
14
+ export class DagCompiler {
15
+ /**
16
+ * @param {Lib} lib
17
+ */
18
+ constructor(lib: Lib);
19
+ /**
20
+ * @private
21
+ * @readonly
22
+ * @type {Lib}
23
+ */
24
+ private readonly lib;
25
+ /**
26
+ * @private
27
+ * @readonly
28
+ * @type {{[name: string]: AnyContractValidatorHash}}
29
+ */
30
+ private readonly cache;
31
+ /**
32
+ * @param {LoadedValidator[]} validators
33
+ * @param {Option<{[name: string]: string}>} expectedHashes
34
+ * @returns {{[name: string]: AnyContractValidatorHash}}
35
+ */
36
+ build(validators: LoadedValidator[], expectedHashes?: Option<{
37
+ [name: string]: string;
38
+ }>): {
39
+ [name: string]: import("./ContractContext.js").AnyContractValidatorHash;
40
+ };
41
+ /**
42
+ * @private
43
+ * @param {LoadedValidator} validator
44
+ * @param {UplcProgramV2} program
45
+ * @param {string} hash - although this can be derived from `program`, reuse this to save some effort
46
+ */
47
+ private addToCache;
48
+ /**
49
+ * @private
50
+ * @param {LoadedValidator} validator
51
+ * @returns {{[name: string]: string}} - TODO: do we really need the purpose?
52
+ */
53
+ private getHashDependencies;
54
+ /**
55
+ * @private
56
+ * @param {LoadedValidator[]} validators
57
+ * @returns {{[name: string]: any}}
58
+ */
59
+ private getHashTypes;
60
+ }
61
+ export type LoadedValidator = import("../codegen/LoadedValidator.js").LoadedValidator;
62
+ export type Lib = import("../lib/index.js").Lib;
63
+ export type AnyContractValidatorHash = import("./ContractContext.js").AnyContractValidatorHash;
64
+ //# sourceMappingURL=DagCompiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DagCompiler.d.ts","sourceRoot":"","sources":["../../src/runtime/DagCompiler.js"],"names":[],"mappings":"AA4MA;;;GAGG;AACH,iDAHW,eAAe,GACb,MAAM,EAAE,CAsBpB;AA3ND;;;;GAIG;AAEH;;GAEG;AACH;IAeI;;OAEG;IACH,iBAFW,GAAG,EAKb;IApBD;;;;OAIG;IACH,qBAAG;IAEH;;;;OAIG;IACH,uBAAK;IAUL;;;;OAIG;IACH,kBAJW,eAAe,EAAE;;;;MAkF3B;IAED;;;;;OAKG;IACH,mBA6BC;IAED;;;;OAIG;IACH,4BAoBC;IAED;;;;OAIG;IACH,qBAMC;CACJ;8BAhMY,OAAO,+BAA+B,EAAE,eAAe;kBACvD,OAAO,iBAAiB,EAAE,GAAG;uCAC7B,OAAO,sBAAsB,EAAE,wBAAwB"}
@@ -1,3 +1,3 @@
1
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";
2
+ import { Cast } from "../cast/Cast.js";
3
3
  //# sourceMappingURL=PermissiveType.d.ts.map
@@ -1,3 +1,3 @@
1
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";
2
+ import { Cast } from "../cast/Cast.js";
3
3
  //# sourceMappingURL=StrictType.d.ts.map
@@ -1,4 +1,2 @@
1
- export { Cast } from "./Cast.js";
2
- export { ContractContext } from "./ContractContext.js";
3
1
  export { ContractContextBuilder } from "./ContractContextBuilder.js";
4
2
  //# sourceMappingURL=index.d.ts.map
@@ -1,37 +0,0 @@
1
- export class Writer {
2
- /**
3
- * @private
4
- * @readonly
5
- * @type {string[]}
6
- */
7
- parts
8
-
9
- constructor() {
10
- this.parts = []
11
- }
12
-
13
- /**
14
- * @param {string} part
15
- * @returns {Writer}
16
- */
17
- write(part) {
18
- this.parts.push(part)
19
- return this
20
- }
21
-
22
- /**
23
- * @param {string} line
24
- * @returns {Writer}
25
- */
26
- writeLine(line) {
27
- this.parts.push(`${line}\n`)
28
- return this
29
- }
30
-
31
- /**
32
- * @returns {string}
33
- */
34
- finalize() {
35
- return this.parts.join("")
36
- }
37
- }
package/src/lib/Lib.js DELETED
@@ -1,56 +0,0 @@
1
- /**
2
- * @typedef {{
3
- * allValidatorTypes: {[name: string]: any},
4
- * otherValidators: {[name: string]: {purpose: string, hash: string}},
5
- * dependsOnOwnHash?: boolean,
6
- * ownHash?: string,
7
- * optimize: boolean
8
- * }} CompileOptions
9
- */
10
-
11
- /**
12
- * @typedef {{
13
- * cborHex: string
14
- * prettyIR: string
15
- * }} CompileOutput
16
- */
17
-
18
- /**
19
- * @typedef {{
20
- * isMainnet?: boolean
21
- * checkCasts?: boolean
22
- * moduleOrder?: string[]
23
- * }} LibOptions
24
- */
25
-
26
- /**
27
- * @typedef {{
28
- * version: string
29
- * getValidatorType: (purpose: string) => any
30
- * typeCheck: (validators: {[name: string]: SourceDetails}, modules: {[name: string]: SourceDetails}) => ({
31
- * modules: {[name: string]: ModuleDetails}, validators: {[name: string]: ValidatorDetails}})
32
- * compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput
33
- * }} Lib
34
- */
35
-
36
- /**
37
- * @typedef {import("../codegen/index.js").TypeSchema} InternalTypeDetails
38
- * @typedef {import("../codegen/index.js").Module} ModuleDetails
39
- * @typedef {import("../codegen/index.js").Validator} ValidatorDetails
40
- */
41
-
42
- /**
43
- * @typedef {{
44
- * name: string
45
- * purpose: string
46
- * sourceCode: string
47
- * }} SourceDetails
48
- */
49
-
50
- /**
51
- * @param {{VERSION: string}} lib
52
- * @returns {number[]}
53
- */
54
- export function getVersion(lib) {
55
- return lib.VERSION.split(".").map((v) => Number(v))
56
- }
package/src/lib/index.js DELETED
@@ -1,6 +0,0 @@
1
- export { loadLibrary } from "./load.js"
2
-
3
- /**
4
- * @typedef {import("./Lib.js").Lib} Lib
5
- * @typedef {import("./Lib.js").LibOptions} LibOptions
6
- */
package/src/lib/load.js DELETED
@@ -1,26 +0,0 @@
1
- import * as lib from "@helios-lang/compiler"
2
- import { getVersion } from "./Lib.js"
3
- import { Lib_v0_16 } from "./Libg_v0_16.js"
4
-
5
- /**
6
- * @typedef {import("./Lib.js").Lib} Lib
7
- * @typedef {import("./Lib.js").LibOptions} LibOptions
8
- */
9
-
10
- /**
11
- * @param {LibOptions} options
12
- * @returns {Lib}
13
- */
14
- export function loadLibrary(options = {}) {
15
- const [major, minor] = getVersion(lib)
16
-
17
- switch (major) {
18
- case 0:
19
- switch (minor) {
20
- case 16:
21
- return new Lib_v0_16(lib, options)
22
- }
23
- default:
24
- throw new Error(`compiler version ${lib.VERSION} not supported`)
25
- }
26
- }
@@ -1,35 +0,0 @@
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
- }