@helios-lang/contract-utils 0.1.6 → 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.
- package/examples/spending/contract.js +16 -0
- package/examples/spending/index.d.ts +29 -0
- package/examples/spending/index.js +27 -0
- package/examples/spending/minting.hl +5 -0
- package/examples/spending/package-lock.json +34 -2
- package/examples/spending/package.json +5 -0
- package/jsconfig.json +16 -0
- package/package.json +9 -4
- package/src/codegen/TypescriptWriter.js +14 -6
- package/src/hl2ts.js +2 -0
- package/src/index.js +1 -0
- package/src/lib/Lib.js +15 -0
- package/src/lib/Libg_v0_16.js +106 -5
- package/src/lib/load.js +12 -49
- package/src/runtime/Cast.js +9 -6
- package/src/runtime/ContractContext.js +35 -0
- package/src/runtime/ContractContextBuilder.js +325 -0
- package/src/runtime/PermissiveType.js +6 -0
- package/src/runtime/StrictType.js +6 -0
- package/src/runtime/index.js +3 -0
- package/types/codegen/Module.d.ts +24 -0
- package/types/codegen/Module.d.ts.map +1 -0
- package/types/codegen/TypeSchema.d.ts +54 -0
- package/types/codegen/TypeSchema.d.ts.map +1 -0
- package/types/codegen/TypescriptWriter.d.ts +50 -0
- package/types/codegen/TypescriptWriter.d.ts.map +1 -0
- package/types/codegen/Validator.d.ts +22 -0
- package/types/codegen/Validator.d.ts.map +1 -0
- package/types/codegen/Writer.d.ts +23 -0
- package/types/codegen/Writer.d.ts.map +1 -0
- package/types/codegen/index.d.ts +6 -0
- package/types/codegen/index.d.ts.map +1 -0
- package/types/hl2ts.d.ts +6 -0
- package/types/hl2ts.d.ts.map +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -0
- package/types/lib/Lib.d.ts +79 -0
- package/types/lib/Lib.d.ts.map +1 -0
- package/types/lib/Libg_v0_16.d.ts +233 -0
- package/types/lib/Libg_v0_16.d.ts.map +1 -0
- package/types/lib/index.d.ts +2 -0
- package/types/lib/index.d.ts.map +1 -0
- package/types/lib/load.d.ts +9 -0
- package/types/lib/load.d.ts.map +1 -0
- package/types/runtime/Cast.d.ts +32 -0
- package/types/runtime/Cast.d.ts.map +1 -0
- package/types/runtime/ContractContext.d.ts +44 -0
- package/types/runtime/ContractContext.d.ts.map +1 -0
- package/types/runtime/ContractContextBuilder.d.ts +133 -0
- package/types/runtime/ContractContextBuilder.d.ts.map +1 -0
- package/types/runtime/PermissiveType.d.ts +3 -0
- package/types/runtime/PermissiveType.d.ts.map +1 -0
- package/types/runtime/StrictType.d.ts +3 -0
- package/types/runtime/StrictType.d.ts.map +1 -0
- package/types/runtime/index.d.ts +4 -0
- package/types/runtime/index.d.ts.map +1 -0
- package/examples/spending/app.js +0 -13
- package/examples/spending/output.d.ts +0 -18
- package/examples/spending/output2.d.ts +0 -24
- package/examples/spending/output2.js +0 -34
- package/examples/spending/specialized.js +0 -6
- package/examples/spending/unspecialized.js +0 -18
|
@@ -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,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("./TypeSchema.js").TypeSchema} TypeSchema
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {{
|
|
6
|
+
* name: string
|
|
7
|
+
* purpose: string
|
|
8
|
+
* sourceCode: string
|
|
9
|
+
* moduleDepedencies: string[]
|
|
10
|
+
* types: {[name: string]: TypeSchema}
|
|
11
|
+
* }} Module
|
|
12
|
+
*/
|
|
13
|
+
export const _: {};
|
|
14
|
+
export type TypeSchema = import("./TypeSchema.js").TypeSchema;
|
|
15
|
+
export type Module = {
|
|
16
|
+
name: string;
|
|
17
|
+
purpose: string;
|
|
18
|
+
sourceCode: string;
|
|
19
|
+
moduleDepedencies: string[];
|
|
20
|
+
types: {
|
|
21
|
+
[name: string]: import("./TypeSchema.js").TypeSchema;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=Module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Module.d.ts","sourceRoot":"","sources":["../../src/codegen/Module.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;GAQG;AAEH,mBAAmB;yBAbN,OAAO,iBAAiB,EAAE,UAAU;;UAKtC,MAAM;aACH,MAAM;gBACH,MAAM;uBACC,MAAM,EAAE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {{
|
|
3
|
+
* primitiveType: string
|
|
4
|
+
* } | {
|
|
5
|
+
* listItemType: TypeSchema
|
|
6
|
+
* } | {
|
|
7
|
+
* mapKeyType: TypeSchema
|
|
8
|
+
* mapValueType: TypeSchema
|
|
9
|
+
* } | {
|
|
10
|
+
* optionSomeType: TypeSchema
|
|
11
|
+
* } | {
|
|
12
|
+
* structFieldTypes: {
|
|
13
|
+
* name: string
|
|
14
|
+
* type: TypeSchema
|
|
15
|
+
* }[]
|
|
16
|
+
* } | {
|
|
17
|
+
* enumVariantTypes: {
|
|
18
|
+
* name: string,
|
|
19
|
+
* fieldTypes: {
|
|
20
|
+
* name: string
|
|
21
|
+
* type: TypeSchema
|
|
22
|
+
* }[]
|
|
23
|
+
* }[]
|
|
24
|
+
* }} TypeSchema
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* @param {TypeSchema} schema
|
|
28
|
+
* @returns {[string, string]} - the first entry is the canonical type, the second is the permissive type
|
|
29
|
+
*/
|
|
30
|
+
export function genTypes(schema: TypeSchema): [string, string];
|
|
31
|
+
export type TypeSchema = {
|
|
32
|
+
primitiveType: string;
|
|
33
|
+
} | {
|
|
34
|
+
listItemType: TypeSchema;
|
|
35
|
+
} | {
|
|
36
|
+
mapKeyType: TypeSchema;
|
|
37
|
+
mapValueType: TypeSchema;
|
|
38
|
+
} | {
|
|
39
|
+
optionSomeType: TypeSchema;
|
|
40
|
+
} | {
|
|
41
|
+
structFieldTypes: {
|
|
42
|
+
name: string;
|
|
43
|
+
type: TypeSchema;
|
|
44
|
+
}[];
|
|
45
|
+
} | {
|
|
46
|
+
enumVariantTypes: {
|
|
47
|
+
name: string;
|
|
48
|
+
fieldTypes: {
|
|
49
|
+
name: string;
|
|
50
|
+
type: TypeSchema;
|
|
51
|
+
}[];
|
|
52
|
+
}[];
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=TypeSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeSchema.d.ts","sourceRoot":"","sources":["../../src/codegen/TypeSchema.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;GAGG;AACH,iCAHW,UAAU,GACR,CAAC,MAAM,EAAE,MAAM,CAAC,CA0H5B;yBArJY;IACZ,aAAmB,EAAE,MAAM,CAAA;CACxB,GAAG;IACN,YAAkB,EAAE,UAAU,CAAA;CAC3B,GAAG;IACN,UAAgB,EAAE,UAAU,CAAA;IAC5B,YAAkB,EAAE,UAAU,CAAA;CAC3B,GAAG;IACN,cAAoB,EAAE,UAAU,CAAA;CAC7B,GAAG;IACN,gBAAsB,EAAE;QACxB,MAAgB,MAAM,CAAA;QACtB,IAAc,EAAE,UAAU,CAAA;KACnB,EAAE,CAAA;CACN,GAAG;IACN,gBAAsB,EAAE;QACxB,MAAiB,MAAM,CAAC;QACxB,UAAqB,EAAE;YACvB,MAAqB,MAAM,CAAA;YAC3B,IAAmB,EAAE,UAAU,CAAA;SACnB,EAAE,CAAA;KACP,EAAE,CAAA;CACN"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("./Module.js").Module} Module
|
|
3
|
+
* @typedef {import("./Validator.js").Validator} Validator
|
|
4
|
+
*/
|
|
5
|
+
export class TypescriptWriter {
|
|
6
|
+
wjs: Writer;
|
|
7
|
+
wdts: Writer;
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} js
|
|
10
|
+
* @param {string} dts
|
|
11
|
+
* @returns {TypescriptWriter}
|
|
12
|
+
*/
|
|
13
|
+
write(js: string, dts?: string): TypescriptWriter;
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} js
|
|
16
|
+
* @param {string} dts
|
|
17
|
+
* @returns {TypescriptWriter}
|
|
18
|
+
*/
|
|
19
|
+
writeLine(js: string, dts?: string): TypescriptWriter;
|
|
20
|
+
/**
|
|
21
|
+
* @param {Module} m
|
|
22
|
+
*/
|
|
23
|
+
writeModule(m: Module): void;
|
|
24
|
+
/**
|
|
25
|
+
* @param {Validator} v
|
|
26
|
+
*/
|
|
27
|
+
writeValidator(v: Validator): void;
|
|
28
|
+
writeHeaders(): void;
|
|
29
|
+
/**
|
|
30
|
+
* @param {{[name: string]: Module}} ms
|
|
31
|
+
*/
|
|
32
|
+
writeModules(ms: {
|
|
33
|
+
[name: string]: import("./Module.js").Module;
|
|
34
|
+
}): void;
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param {{[name: string]: Validator}} validators
|
|
38
|
+
*/
|
|
39
|
+
writeValidators(validators: {
|
|
40
|
+
[name: string]: import("./Validator.js").Validator;
|
|
41
|
+
}): void;
|
|
42
|
+
/**
|
|
43
|
+
* @returns {[string, string]}
|
|
44
|
+
*/
|
|
45
|
+
finalize(): [string, string];
|
|
46
|
+
}
|
|
47
|
+
export type Module = import("./Module.js").Module;
|
|
48
|
+
export type Validator = import("./Validator.js").Validator;
|
|
49
|
+
import { Writer } from "./Writer.js";
|
|
50
|
+
//# sourceMappingURL=TypescriptWriter.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("./TypeSchema.js").TypeSchema} TypeSchema
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import("./Module.js").Module} Module
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Module & {
|
|
9
|
+
* hashDependencies: string[]
|
|
10
|
+
* Redeemer: TypeSchema
|
|
11
|
+
* Datum?: TypeSchema
|
|
12
|
+
* }} Validator
|
|
13
|
+
*/
|
|
14
|
+
export const _: {};
|
|
15
|
+
export type TypeSchema = import("./TypeSchema.js").TypeSchema;
|
|
16
|
+
export type Module = import("./Module.js").Module;
|
|
17
|
+
export type Validator = Module & {
|
|
18
|
+
hashDependencies: string[];
|
|
19
|
+
Redeemer: TypeSchema;
|
|
20
|
+
Datum?: TypeSchema;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=Validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../src/codegen/Validator.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AAEH;;;;;;GAMG;AAEH,mBAAmB;yBAfN,OAAO,iBAAiB,EAAE,UAAU;qBAIpC,OAAO,aAAa,EAAE,MAAM;wBAI5B,MAAM,GAAG;IACrB,gBAAoB,EAAE,MAAM,EAAE,CAAA;IAC9B,QAAY,EAAE,UAAU,CAAA;IACxB,KAAS,CAAC,EAAE,UAAU,CAAA;CACnB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class Writer {
|
|
2
|
+
/**
|
|
3
|
+
* @private
|
|
4
|
+
* @readonly
|
|
5
|
+
* @type {string[]}
|
|
6
|
+
*/
|
|
7
|
+
private readonly parts;
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} part
|
|
10
|
+
* @returns {Writer}
|
|
11
|
+
*/
|
|
12
|
+
write(part: string): Writer;
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} line
|
|
15
|
+
* @returns {Writer}
|
|
16
|
+
*/
|
|
17
|
+
writeLine(line: string): Writer;
|
|
18
|
+
/**
|
|
19
|
+
* @returns {string}
|
|
20
|
+
*/
|
|
21
|
+
finalize(): string;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=Writer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Writer.d.ts","sourceRoot":"","sources":["../../src/codegen/Writer.js"],"names":[],"mappings":"AAAA;IACI;;;;OAIG;IACH,uBAAK;IAML;;;OAGG;IACH,YAHW,MAAM,GACJ,MAAM,CAKlB;IAED;;;OAGG;IACH,gBAHW,MAAM,GACJ,MAAM,CAKlB;IAED;;OAEG;IACH,YAFa,MAAM,CAIlB;CACJ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { TypescriptWriter } from "./TypescriptWriter.js";
|
|
2
|
+
export { Writer } from "./Writer.js";
|
|
3
|
+
export type Module = import("./Module.js").Module;
|
|
4
|
+
export type TypeSchema = import("./TypeSchema.js").TypeSchema;
|
|
5
|
+
export type Validator = import("./Validator.js").Validator;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.js"],"names":[],"mappings":";;qBAIa,OAAO,aAAa,EAAE,MAAM;yBAC5B,OAAO,iBAAiB,EAAE,UAAU;wBACpC,OAAO,gBAAgB,EAAE,SAAS"}
|
package/types/hl2ts.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export type Lib = import("./lib/Lib.js").Lib;
|
|
3
|
+
export type SourceDetails = import("./lib/Lib.js").SourceDetails;
|
|
4
|
+
export type ModuleDetails = import("./lib/Lib.js").ModuleDetails;
|
|
5
|
+
export type ValidatorDetails = import("./lib/Lib.js").ValidatorDetails;
|
|
6
|
+
//# sourceMappingURL=hl2ts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hl2ts.d.ts","sourceRoot":"","sources":["../src/hl2ts.js"],"names":[],"mappings":";kBASa,OAAO,cAAc,EAAE,GAAG;4BAC1B,OAAO,cAAc,EAAE,aAAa;4BACpC,OAAO,cAAc,EAAE,aAAa;+BACpC,OAAO,cAAc,EAAE,gBAAgB"}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {{
|
|
16
|
+
* version: string
|
|
17
|
+
* typeCheck: (validators: {[name: string]: SourceDetails}, modules: {[name: string]: SourceDetails}) => ({
|
|
18
|
+
* modules: {[name: string]: ModuleDetails}, validators: {[name: string]: ValidatorDetails}})
|
|
19
|
+
* compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput
|
|
20
|
+
* }} Lib
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {import("../codegen/index.js").TypeSchema} InternalTypeDetails
|
|
24
|
+
* @typedef {import("../codegen/index.js").Module} ModuleDetails
|
|
25
|
+
* @typedef {import("../codegen/index.js").Validator} ValidatorDetails
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {{
|
|
29
|
+
* name: string
|
|
30
|
+
* purpose: string
|
|
31
|
+
* sourceCode: string
|
|
32
|
+
* }} SourceDetails
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* @param {{VERSION: string}} lib
|
|
36
|
+
* @returns {number[]}
|
|
37
|
+
*/
|
|
38
|
+
export function getVersion(lib: {
|
|
39
|
+
VERSION: string;
|
|
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
|
+
};
|
|
55
|
+
export type Lib = {
|
|
56
|
+
version: string;
|
|
57
|
+
typeCheck: (validators: {
|
|
58
|
+
[name: string]: SourceDetails;
|
|
59
|
+
}, modules: {
|
|
60
|
+
[name: string]: SourceDetails;
|
|
61
|
+
}) => {
|
|
62
|
+
modules: {
|
|
63
|
+
[name: string]: import("../codegen/Module.js").Module;
|
|
64
|
+
};
|
|
65
|
+
validators: {
|
|
66
|
+
[name: string]: import("../codegen/Validator.js").Validator;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput;
|
|
70
|
+
};
|
|
71
|
+
export type InternalTypeDetails = import("../codegen/index.js").TypeSchema;
|
|
72
|
+
export type ModuleDetails = import("../codegen/index.js").Module;
|
|
73
|
+
export type ValidatorDetails = import("../codegen/index.js").Validator;
|
|
74
|
+
export type SourceDetails = {
|
|
75
|
+
name: string;
|
|
76
|
+
purpose: string;
|
|
77
|
+
sourceCode: string;
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=Lib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|