@helios-lang/contract-utils 0.2.80 → 0.2.81

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helios-lang/contract-utils",
3
- "version": "0.2.80",
3
+ "version": "0.2.81",
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",
@@ -40,7 +40,7 @@
40
40
  "@helios-lang/codec-utils": "^0.2.1",
41
41
  "@helios-lang/compiler-utils": "^0.2.1",
42
42
  "@helios-lang/crypto": "0.1.17",
43
- "@helios-lang/ledger": "^0.5.10",
43
+ "@helios-lang/ledger": "^0.5.12",
44
44
  "@helios-lang/type-utils": "^0.1.25",
45
45
  "@helios-lang/uplc": "^0.6.1"
46
46
  },
@@ -1,13 +0,0 @@
1
- # Codegen multi policy
2
-
3
- Run `npx hl2ts` to generate Javascript/Typescript equivalents of the `spending.hl` and `minting.hl` validators.
4
-
5
- Then have a look at `contract.js` to see how these validators can be used within Javascript/Typescript in a type-safe way (ideally using VSCode so you can hover over the types).
6
-
7
- # Installing compilers
8
-
9
- If you want to use an older version of Helios (under the @hyperionbt org), you can use the following command.
10
-
11
- ```
12
- npm install --save-exact @helios-lang/compiler:npm@hyperionbt/helios@<version>
13
- ```
@@ -1,32 +0,0 @@
1
- import { ContractContextBuilder } from "@helios-lang/contract-utils"
2
- import { Address, AssetClass } from "@helios-lang/ledger"
3
- import { TxBuilder } from "@helios-lang/tx-utils"
4
- import { match_string, match_string_policy } from "./index.js"
5
-
6
- export function createApp() {
7
- const context = ContractContextBuilder.new()
8
- .with(match_string)
9
- .with(match_string_policy)
10
- .build({
11
- isMainnet: false,
12
- expectedHashes: {
13
- match_string_policy:
14
- "f7c8a87011f1aec5967dd3cd68b7a2c26135d750867bfd957b4d8967" // expected hash for match_string_policy
15
- }
16
- })
17
-
18
- console.log(context.match_string_policy.$hash.toHex())
19
-
20
- const assetClass = new AssetClass(context.match_string_policy.$hash, [])
21
-
22
- const address = Address.fromHash(false, context.match_string.$hash)
23
-
24
- let b = TxBuilder.new({ isMainnet: false }).mint(assetClass, 10, true)
25
-
26
- let c = b
27
- .pay(address, 1_000_000n, { hash: { One: { message: "hello" } } })
28
- // Types from Helios are propagated into Typescript, allowing typesafe conversion of Datums
29
- .pay(address, 2_000_000n, { hash: { Two: { code: "hello" } } })
30
- }
31
-
32
- createApp()
@@ -1,40 +0,0 @@
1
- import { Cast } from "@helios-lang/contract-utils";
2
- import { Address, AssetClass, DatumHash, MintingPolicyHash, PubKey, PubKeyHash, SpendingCredential, StakingCredential, StakingHash, StakingValidatorHash, TimeRange, TxId, TxOutputDatum, ValidatorHash, Value } from "@helios-lang/ledger";
3
- import type { IntLike } from "@helios-lang/codec-utils";
4
- import type { CastConfig } from "@helios-lang/contract-utils";
5
- import type { ConfigurableCast } from "@helios-lang/contract-utils";
6
- import type { TimeLike } from "@helios-lang/ledger";
7
- import type { UplcData } from "@helios-lang/ledger";
8
- export const utils: {
9
- $name: "utils"
10
- $purpose: "module"
11
- $sourceCode: string
12
- $dependencies: [],
13
- $types: {
14
- MyUtilType: ConfigurableCast<{hello: bigint}, {hello: IntLike}>,
15
- },
16
- }
17
- export const match_string_policy: {
18
- $name: "match_string_policy"
19
- $purpose: "minting"
20
- $sourceCode: string
21
- $dependencies: []
22
- $hashDependencies: []
23
- $dependsOnOwnHash: boolean
24
- $Redeemer: ConfigurableCast<boolean, boolean>
25
- $types: {
26
- },
27
- }
28
- export const match_string: {
29
- $name: "match_string"
30
- $purpose: "spending"
31
- $sourceCode: string
32
- $dependencies: [typeof utils]
33
- $hashDependencies: [typeof match_string_policy]
34
- $dependsOnOwnHash: boolean
35
- $Redeemer: ConfigurableCast<string, string>
36
- $Datum: ConfigurableCast<{One: {message: string}} | {Two: {code: bigint}}, {One: {message: string}} | {Two: {code: IntLike}}>,
37
- $types: {
38
- Datum: ConfigurableCast<{One: {message: string}} | {Two: {code: bigint}}, {One: {message: string}} | {Two: {code: IntLike}}>,
39
- },
40
- }
@@ -1,52 +0,0 @@
1
- import { Cast } from "@helios-lang/contract-utils";
2
- import { Address, AssetClass, DatumHash, MintingPolicyHash, PubKey, PubKeyHash, SpendingCredential, StakingCredential, StakingHash, StakingValidatorHash, TimeRange, TxId, TxOutputDatum, ValidatorHash, Value } from "@helios-lang/ledger";
3
- /**
4
- * @typedef {import("@helios-lang/codec-utils").IntLike} IntLike
5
- */
6
- /**
7
- * @typedef {import("@helios-lang/contract-utils").CastConfig} CastConfig
8
- */
9
- /**
10
- * @template TStrict
11
- * @template TPermissive
12
- * @typedef {import("@helios-lang/contract-utils").ConfigurableCast<TStrict, TPermissive>} ConfigurableCast
13
- */
14
- /**
15
- * @typedef {import("@helios-lang/ledger").TimeLike} TimeLike
16
- */
17
- /**
18
- * @typedef {import("@helios-lang/ledger").UplcData} UplcData
19
- */
20
- export const utils = {
21
- $name: /** @type {const} */ ("utils"),
22
- $purpose: /** @type {const} */ ("module"),
23
- $sourceCode: "module utils\n\nstruct MyUtilType {\n hello: Int\n}\n\nconst my_assetclass: AssetClass = AssetClass::new(Scripts::match_string_policy, #)\n\nconst my_hash: ValidatorHash = Scripts::match_string\n\nfunc compare(a: String, b: String) -> Bool {\n a == b\n}",
24
- $dependencies: /** @type {const} */ ([]),
25
- $types: {
26
- MyUtilType: (config) => /** @type {Cast<{hello: bigint}, {hello: IntLike}>} */ (new Cast({"structFieldTypes":[{"name":"hello","type":{"primitiveType":"Int"}}]}, config)),
27
- },
28
- }
29
- export const match_string_policy = {
30
- $name: /** @type {const} */ ("match_string_policy"),
31
- $purpose: /** @type {const} */ ("minting"),
32
- $sourceCode: "minting match_string_policy\n\nfunc main(redeemer: Bool, _) -> Bool {\n redeemer\n}",
33
- $dependencies: /** @type {const} */ ([]),
34
- $hashDependencies: [],
35
- $dependsOnOwnHash: false,
36
- $Redeemer: (config) => /** @type {Cast<boolean, boolean>} */ (new Cast({"primitiveType":"Bool"}, config)),
37
- $types: {
38
- },
39
- }
40
- export const match_string = {
41
- $name: /** @type {const} */ ("match_string"),
42
- $purpose: /** @type {const} */ ("spending"),
43
- $sourceCode: "spending match_string\n\nimport { compare, my_assetclass } from utils\n\nenum Datum {\n One {\n message: String\n }\n\n Two {\n code: Int\n }\n}\n\nfunc main(datum: Datum, redeemer: String, ctx: ScriptContext) -> Bool {\n compare(datum.switch{d: One => d.message, d: Two => d.code.show()}, redeemer) &&\n ctx.tx.minted.get(my_assetclass) > 0\n}",
44
- $dependencies: /** @type {const} */ ([utils]),
45
- $hashDependencies: [match_string_policy],
46
- $dependsOnOwnHash: true,
47
- $Redeemer: (config) => /** @type {Cast<string, string>} */ (new Cast({"primitiveType":"String"}, config)),
48
- $Datum: (config) => /** @type {Cast<{One: {message: string}} | {Two: {code: bigint}}, {One: {message: string}} | {Two: {code: IntLike}}>} */ new Cast({"enumVariantTypes":[{"name":"One","fieldTypes":[{"name":"message","type":{"primitiveType":"String"}}]},{"name":"Two","fieldTypes":[{"name":"code","type":{"primitiveType":"Int"}}]}]}, config),
49
- $types: {
50
- Datum: (config) => /** @type {Cast<{One: {message: string}} | {Two: {code: bigint}}, {One: {message: string}} | {Two: {code: IntLike}}>} */ (new Cast({"enumVariantTypes":[{"name":"One","fieldTypes":[{"name":"message","type":{"primitiveType":"String"}}]},{"name":"Two","fieldTypes":[{"name":"code","type":{"primitiveType":"Int"}}]}]}, config)),
51
- },
52
- }
@@ -1,5 +0,0 @@
1
- minting match_string_policy
2
-
3
- func main(redeemer: Bool, _) -> Bool {
4
- redeemer
5
- }
@@ -1,136 +0,0 @@
1
- {
2
- "name": "spending_example",
3
- "lockfileVersion": 3,
4
- "requires": true,
5
- "packages": {
6
- "": {
7
- "name": "spending_example",
8
- "dependencies": {
9
- "@helios-lang/contract-utils": "file:../..",
10
- "@helios-lang/tx-utils": "^0.1.38",
11
- "@hyperionbt/helios": "^0.16.7"
12
- },
13
- "devDependencies": {
14
- "typescript": "^5.4.3"
15
- }
16
- },
17
- "../..": {
18
- "name": "@helios-lang/contract-utils",
19
- "version": "0.1.41",
20
- "license": "BSD-3-Clause",
21
- "dependencies": {
22
- "@helios-lang/cli-utils": "^0.1.4",
23
- "@helios-lang/codec-utils": "^0.1.29",
24
- "@helios-lang/compiler-utils": "^0.1.22",
25
- "@helios-lang/ledger": "^0.2.1",
26
- "@helios-lang/type-utils": "^0.1.8",
27
- "@helios-lang/uplc": "^0.1.27"
28
- },
29
- "bin": {
30
- "hl2ts": "src/hl2ts.js"
31
- },
32
- "devDependencies": {
33
- "@types/node": "^20.11.24",
34
- "prettier": "^3.1.0",
35
- "typescript": "^5.3.2"
36
- },
37
- "peerDependencies": {
38
- "@helios-lang/compiler": "*"
39
- }
40
- },
41
- "node_modules/@helios-lang/cbor": {
42
- "version": "0.1.18",
43
- "resolved": "https://registry.npmjs.org/@helios-lang/cbor/-/cbor-0.1.18.tgz",
44
- "integrity": "sha512-DgHJ4PQJqGKBLSnRD3PkZ0QjSzYrQIinEuVyK5XsdLS/s95z5/2rkPxd9v/VvbfAHdZlYT1fsV3Ei/pblxuJXw==",
45
- "dependencies": {
46
- "@helios-lang/codec-utils": "^0.1.29",
47
- "@helios-lang/type-utils": "^0.1.8"
48
- }
49
- },
50
- "node_modules/@helios-lang/codec-utils": {
51
- "version": "0.1.29",
52
- "resolved": "https://registry.npmjs.org/@helios-lang/codec-utils/-/codec-utils-0.1.29.tgz",
53
- "integrity": "sha512-Faa9AlB61BSed3fZ8T5t/hljeJP7tWdqPOuuAKMJPoyDIPdNhMesux0jZMRTyQByKEXE2DSq3TFvQCeAsE6zng=="
54
- },
55
- "node_modules/@helios-lang/compiler-utils": {
56
- "version": "0.1.22",
57
- "resolved": "https://registry.npmjs.org/@helios-lang/compiler-utils/-/compiler-utils-0.1.22.tgz",
58
- "integrity": "sha512-y2BEe5Gnnag7UGFTj+mOb2GdlYvuLaaBwekgHe+tFf1HYuyhfIFdSOyRdALYnh+LjQhcFhxgHzob55uyfTxdHQ==",
59
- "dependencies": {
60
- "@helios-lang/codec-utils": "^0.1.29",
61
- "@helios-lang/type-utils": "^0.1.8"
62
- }
63
- },
64
- "node_modules/@helios-lang/contract-utils": {
65
- "resolved": "../..",
66
- "link": true
67
- },
68
- "node_modules/@helios-lang/crypto": {
69
- "version": "0.1.8",
70
- "resolved": "https://registry.npmjs.org/@helios-lang/crypto/-/crypto-0.1.8.tgz",
71
- "integrity": "sha512-06ak82XadShfEguohj9bgnlI9Dxol1Hq9s1njP7F6UJwEL3WIvm/DrMGvHzx0+jg1s50WHl2SqZnA5CC+GLdKA==",
72
- "dependencies": {
73
- "@helios-lang/codec-utils": "^0.1.29"
74
- }
75
- },
76
- "node_modules/@helios-lang/ledger": {
77
- "version": "0.2.1",
78
- "resolved": "https://registry.npmjs.org/@helios-lang/ledger/-/ledger-0.2.1.tgz",
79
- "integrity": "sha512-un7pUstnpiboq3fnuIkls4tedO42febiY8s4tH/qEgVLtYz3TV3gicjwg36Bc8ff//CoUabhS3syOcgK0QNKXQ==",
80
- "dependencies": {
81
- "@helios-lang/cbor": "^0.1.18",
82
- "@helios-lang/codec-utils": "^0.1.29",
83
- "@helios-lang/crypto": "^0.1.8",
84
- "@helios-lang/type-utils": "^0.1.8",
85
- "@helios-lang/uplc": "^0.1.27"
86
- }
87
- },
88
- "node_modules/@helios-lang/tx-utils": {
89
- "version": "0.1.38",
90
- "resolved": "https://registry.npmjs.org/@helios-lang/tx-utils/-/tx-utils-0.1.38.tgz",
91
- "integrity": "sha512-Qbcgtpv8UpbL3bqBEfNG8DMx1ts8TK1KHMRlp9HlBkTMPfWvyoV1R+BLicCLN0fcMFxeG+pVuOgZFK9dG7TQ2Q==",
92
- "dependencies": {
93
- "@helios-lang/codec-utils": "^0.1.29",
94
- "@helios-lang/crypto": "^0.1.8",
95
- "@helios-lang/ledger": "^0.2.1",
96
- "@helios-lang/type-utils": "^0.1.8",
97
- "@helios-lang/uplc": "^0.1.27"
98
- }
99
- },
100
- "node_modules/@helios-lang/type-utils": {
101
- "version": "0.1.8",
102
- "resolved": "https://registry.npmjs.org/@helios-lang/type-utils/-/type-utils-0.1.8.tgz",
103
- "integrity": "sha512-zVGgJvNQHWuFfK1HLybynp6RAO31yIPkEp/ztdJJcdKS3TOVaUVAr3XHaFY8Hk2Pr7qO0lD2rvfl3Hkk+GApwQ=="
104
- },
105
- "node_modules/@helios-lang/uplc": {
106
- "version": "0.1.27",
107
- "resolved": "https://registry.npmjs.org/@helios-lang/uplc/-/uplc-0.1.27.tgz",
108
- "integrity": "sha512-WqFMpc2/SvZyX0ubsw/uNI+kMIK539QbeCAOXIVdDkotqC8qqXf+MeFqRepSe5T2luY1dhTnUqlRrYExd6dmvg==",
109
- "dependencies": {
110
- "@helios-lang/cbor": "^0.1.18",
111
- "@helios-lang/codec-utils": "^0.1.29",
112
- "@helios-lang/compiler-utils": "^0.1.22",
113
- "@helios-lang/crypto": "^0.1.8",
114
- "@helios-lang/type-utils": "^0.1.8"
115
- }
116
- },
117
- "node_modules/@hyperionbt/helios": {
118
- "version": "0.16.7",
119
- "resolved": "https://registry.npmjs.org/@hyperionbt/helios/-/helios-0.16.7.tgz",
120
- "integrity": "sha512-ysPaF0OCY0NJa1mc+LXERjH71VDNGUbYrrovKUHJv1v+eS1WJhKmxSHWh9sVa6b+sYoXdKwoCR20UQhzCF5jzA=="
121
- },
122
- "node_modules/typescript": {
123
- "version": "5.4.3",
124
- "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz",
125
- "integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==",
126
- "dev": true,
127
- "bin": {
128
- "tsc": "bin/tsc",
129
- "tsserver": "bin/tsserver"
130
- },
131
- "engines": {
132
- "node": ">=14.17"
133
- }
134
- }
135
- }
136
- }
@@ -1,12 +0,0 @@
1
- {
2
- "name": "spending_example",
3
- "type": "module",
4
- "dependencies": {
5
- "@helios-lang/contract-utils": "file:../..",
6
- "@helios-lang/tx-utils": "^0.1.38",
7
- "@hyperionbt/helios": "^0.16.7"
8
- },
9
- "devDependencies": {
10
- "typescript": "^5.4.3"
11
- }
12
- }
@@ -1,18 +0,0 @@
1
- spending match_string
2
-
3
- import { compare, my_assetclass } from "./utils.hl"
4
-
5
- enum Datum {
6
- One {
7
- message: String
8
- }
9
-
10
- Two {
11
- code: Int
12
- }
13
- }
14
-
15
- func main(datum: Datum, redeemer: String, ctx: ScriptContext) -> Bool {
16
- compare(datum.switch{d: One => d.message, d: Two => d.code.show()}, redeemer) &&
17
- ctx.tx.minted.get(my_assetclass) > 0
18
- }
@@ -1,13 +0,0 @@
1
- module utils
2
-
3
- struct MyUtilType {
4
- hello: Int
5
- }
6
-
7
- const my_assetclass: AssetClass = AssetClass::new(Scripts::match_string_policy, #)
8
-
9
- const my_hash: ValidatorHash = Scripts::match_string
10
-
11
- func compare(a: String, b: String) -> Bool {
12
- a == b
13
- }