@hazbase/simplicity 0.0.1
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/LICENSE +182 -0
- package/README.md +778 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +628 -0
- package/dist/client/ContractFactory.d.ts +13 -0
- package/dist/client/ContractFactory.js +50 -0
- package/dist/client/DeployedContract.d.ts +12 -0
- package/dist/client/DeployedContract.js +43 -0
- package/dist/client/SimplicityClient.d.ts +21 -0
- package/dist/client/SimplicityClient.js +65 -0
- package/dist/core/artifact.d.ts +6 -0
- package/dist/core/artifact.js +100 -0
- package/dist/core/compiler.d.ts +3 -0
- package/dist/core/compiler.js +117 -0
- package/dist/core/errors.d.ts +33 -0
- package/dist/core/errors.js +70 -0
- package/dist/core/executor.d.ts +5 -0
- package/dist/core/executor.js +664 -0
- package/dist/core/presets.d.ts +16 -0
- package/dist/core/presets.js +251 -0
- package/dist/core/rpc.d.ts +7 -0
- package/dist/core/rpc.js +37 -0
- package/dist/core/summary.d.ts +6 -0
- package/dist/core/summary.js +27 -0
- package/dist/core/templating.d.ts +2 -0
- package/dist/core/templating.js +17 -0
- package/dist/core/toolchain.d.ts +14 -0
- package/dist/core/toolchain.js +82 -0
- package/dist/core/types.d.ts +258 -0
- package/dist/core/types.js +2 -0
- package/dist/gasless/RelayerClient.d.ts +13 -0
- package/dist/gasless/RelayerClient.js +76 -0
- package/dist/gasless/types.d.ts +144 -0
- package/dist/gasless/types.js +2 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +35 -0
- package/dist/presets/htlc.simf.tmpl +35 -0
- package/dist/presets/manifest.d.ts +1 -0
- package/dist/presets/manifest.js +5 -0
- package/dist/presets/p2pk.simf.tmpl +4 -0
- package/dist/presets/p2pkLockHeight.simf.tmpl +5 -0
- package/dist/presets/transferWithTimeout.simf.tmpl +26 -0
- package/package.json +45 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PRESET_MANIFEST = void 0;
|
|
7
|
+
exports.listPresets = listPresets;
|
|
8
|
+
exports.getPresetOrThrow = getPresetOrThrow;
|
|
9
|
+
exports.validatePresetParams = validatePresetParams;
|
|
10
|
+
exports.describePreset = describePreset;
|
|
11
|
+
exports.validateWitnessConfig = validateWitnessConfig;
|
|
12
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
+
const errors_1 = require("./errors");
|
|
14
|
+
const PRESET_DIR = node_path_1.default.resolve(__dirname, "..", "presets");
|
|
15
|
+
exports.PRESET_MANIFEST = {
|
|
16
|
+
p2pkLockHeight: {
|
|
17
|
+
id: "p2pkLockHeight",
|
|
18
|
+
title: "P2PK + Lock Height",
|
|
19
|
+
description: "Single signer contract gated by block height.",
|
|
20
|
+
simfTemplatePath: node_path_1.default.join(PRESET_DIR, "p2pkLockHeight.simf.tmpl"),
|
|
21
|
+
parameterSchema: {
|
|
22
|
+
MIN_HEIGHT: "number",
|
|
23
|
+
SIGNER_XONLY: "string",
|
|
24
|
+
},
|
|
25
|
+
witnessSchema: {
|
|
26
|
+
SIGNER_SIGNATURE: {
|
|
27
|
+
type: "Signature",
|
|
28
|
+
description: "Primary signer signature over sig_all_hash.",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
exampleWitness: {
|
|
32
|
+
values: {
|
|
33
|
+
SIGNER_SIGNATURE: {
|
|
34
|
+
type: "Signature",
|
|
35
|
+
value: "${SIGNATURE}",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
executionProfile: {
|
|
40
|
+
witnessMode: "inlineSignature",
|
|
41
|
+
supportsGasless: true,
|
|
42
|
+
supportsDirectExecute: true,
|
|
43
|
+
supportsRelayerExecute: true,
|
|
44
|
+
requiredWitnessFields: ["SIGNER_SIGNATURE"],
|
|
45
|
+
defaultFeeSat: 100,
|
|
46
|
+
recommendedUtxoPolicy: "smallest_over",
|
|
47
|
+
},
|
|
48
|
+
exampleParams: {
|
|
49
|
+
MIN_HEIGHT: 2344430,
|
|
50
|
+
SIGNER_XONLY: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
p2pk: {
|
|
54
|
+
id: "p2pk",
|
|
55
|
+
title: "P2PK",
|
|
56
|
+
description: "Single key spend preset.",
|
|
57
|
+
simfTemplatePath: node_path_1.default.join(PRESET_DIR, "p2pk.simf.tmpl"),
|
|
58
|
+
parameterSchema: {
|
|
59
|
+
SIGNER_XONLY: "string",
|
|
60
|
+
},
|
|
61
|
+
witnessSchema: {
|
|
62
|
+
SIGNER_SIGNATURE: {
|
|
63
|
+
type: "Signature",
|
|
64
|
+
description: "Primary signer signature over sig_all_hash.",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
exampleWitness: {
|
|
68
|
+
values: {
|
|
69
|
+
SIGNER_SIGNATURE: {
|
|
70
|
+
type: "Signature",
|
|
71
|
+
value: "${SIGNATURE}",
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
executionProfile: {
|
|
76
|
+
witnessMode: "inlineSignature",
|
|
77
|
+
supportsGasless: true,
|
|
78
|
+
supportsDirectExecute: true,
|
|
79
|
+
supportsRelayerExecute: true,
|
|
80
|
+
requiredWitnessFields: ["SIGNER_SIGNATURE"],
|
|
81
|
+
defaultFeeSat: 100,
|
|
82
|
+
recommendedUtxoPolicy: "smallest_over",
|
|
83
|
+
},
|
|
84
|
+
exampleParams: {
|
|
85
|
+
SIGNER_XONLY: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
htlc: {
|
|
89
|
+
id: "htlc",
|
|
90
|
+
title: "HTLC",
|
|
91
|
+
description: "Template placeholder around upstream HTLC example.",
|
|
92
|
+
simfTemplatePath: node_path_1.default.join(PRESET_DIR, "htlc.simf.tmpl"),
|
|
93
|
+
parameterSchema: {
|
|
94
|
+
EXPECTED_HASH: "string",
|
|
95
|
+
RECIPIENT_XONLY: "string",
|
|
96
|
+
SENDER_XONLY: "string",
|
|
97
|
+
TIMEOUT_HEIGHT: "number",
|
|
98
|
+
},
|
|
99
|
+
witnessSchema: {
|
|
100
|
+
COMPLETE_OR_CANCEL: {
|
|
101
|
+
type: "Either<(u256, Signature), Signature>",
|
|
102
|
+
description: "Use Left((preimage, recipient signature)) for claim or Right(sender signature) for timeout.",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
exampleWitness: {
|
|
106
|
+
values: {
|
|
107
|
+
COMPLETE_OR_CANCEL: {
|
|
108
|
+
type: "Either<(u256, Signature), Signature>",
|
|
109
|
+
value: "Left((0x0000000000000000000000000000000000000000000000000000000000000000, ${SIGNATURE}))",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
executionProfile: {
|
|
114
|
+
witnessMode: "inlineSignature",
|
|
115
|
+
supportsGasless: true,
|
|
116
|
+
supportsDirectExecute: true,
|
|
117
|
+
supportsRelayerExecute: true,
|
|
118
|
+
requiredWitnessFields: ["COMPLETE_OR_CANCEL"],
|
|
119
|
+
defaultFeeSat: 100,
|
|
120
|
+
recommendedUtxoPolicy: "smallest_over",
|
|
121
|
+
},
|
|
122
|
+
exampleParams: {
|
|
123
|
+
EXPECTED_HASH: "66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925",
|
|
124
|
+
RECIPIENT_XONLY: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
|
|
125
|
+
SENDER_XONLY: "c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5",
|
|
126
|
+
TIMEOUT_HEIGHT: 1000,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
transferWithTimeout: {
|
|
130
|
+
id: "transferWithTimeout",
|
|
131
|
+
title: "Transfer With Timeout",
|
|
132
|
+
description: "Cooperative transfer path plus unilateral timeout recovery path.",
|
|
133
|
+
simfTemplatePath: node_path_1.default.join(PRESET_DIR, "transferWithTimeout.simf.tmpl"),
|
|
134
|
+
parameterSchema: {
|
|
135
|
+
SENDER_XONLY: "string",
|
|
136
|
+
RECIPIENT_XONLY: "string",
|
|
137
|
+
TIMEOUT_HEIGHT: "number",
|
|
138
|
+
},
|
|
139
|
+
witnessSchema: {
|
|
140
|
+
SENDER_SIG: {
|
|
141
|
+
type: "Signature",
|
|
142
|
+
description: "Sender signature over sig_all_hash.",
|
|
143
|
+
},
|
|
144
|
+
TRANSFER_OR_TIMEOUT: {
|
|
145
|
+
type: "Option<Signature>",
|
|
146
|
+
signerAlias: "RECIPIENT",
|
|
147
|
+
description: "Use Some(recipient signature) for cooperative spend or None for timeout recovery.",
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
exampleWitness: {
|
|
151
|
+
signers: {
|
|
152
|
+
RECIPIENT: {
|
|
153
|
+
type: "schnorrPrivkeyHex",
|
|
154
|
+
privkeyHex: "<recipient-privkey-hex>",
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
values: {
|
|
158
|
+
SENDER_SIG: {
|
|
159
|
+
type: "Signature",
|
|
160
|
+
value: "${SIGNATURE}",
|
|
161
|
+
},
|
|
162
|
+
TRANSFER_OR_TIMEOUT: {
|
|
163
|
+
type: "Option<Signature>",
|
|
164
|
+
value: "Some(${SIGNATURE:RECIPIENT})",
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
executionProfile: {
|
|
169
|
+
witnessMode: "inlineSignature",
|
|
170
|
+
supportsGasless: true,
|
|
171
|
+
supportsDirectExecute: true,
|
|
172
|
+
supportsRelayerExecute: true,
|
|
173
|
+
requiredWitnessFields: ["SENDER_SIG", "TRANSFER_OR_TIMEOUT"],
|
|
174
|
+
defaultFeeSat: 100,
|
|
175
|
+
recommendedUtxoPolicy: "smallest_over",
|
|
176
|
+
},
|
|
177
|
+
exampleParams: {
|
|
178
|
+
SENDER_XONLY: "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
|
|
179
|
+
RECIPIENT_XONLY: "c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5",
|
|
180
|
+
TIMEOUT_HEIGHT: 1000,
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
function listPresets() {
|
|
185
|
+
return Object.values(exports.PRESET_MANIFEST);
|
|
186
|
+
}
|
|
187
|
+
function getPresetOrThrow(preset) {
|
|
188
|
+
const entry = exports.PRESET_MANIFEST[preset];
|
|
189
|
+
if (!entry) {
|
|
190
|
+
throw new errors_1.ValidationError(`Unknown preset: ${preset}`);
|
|
191
|
+
}
|
|
192
|
+
return entry;
|
|
193
|
+
}
|
|
194
|
+
function validatePresetParams(preset, params) {
|
|
195
|
+
const normalized = {};
|
|
196
|
+
for (const [key, kind] of Object.entries(preset.parameterSchema)) {
|
|
197
|
+
const value = params[key];
|
|
198
|
+
if (value === undefined) {
|
|
199
|
+
throw new errors_1.ValidationError(`Missing preset parameter: ${key}`);
|
|
200
|
+
}
|
|
201
|
+
if (kind === "number") {
|
|
202
|
+
const asNumber = typeof value === "number" ? value : Number(value);
|
|
203
|
+
if (!Number.isFinite(asNumber)) {
|
|
204
|
+
throw new errors_1.ValidationError(`Preset parameter ${key} must be a number`);
|
|
205
|
+
}
|
|
206
|
+
normalized[key] = asNumber;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
normalized[key] = String(value);
|
|
210
|
+
}
|
|
211
|
+
return normalized;
|
|
212
|
+
}
|
|
213
|
+
function describePreset(preset) {
|
|
214
|
+
return {
|
|
215
|
+
id: preset.id,
|
|
216
|
+
title: preset.title,
|
|
217
|
+
description: preset.description,
|
|
218
|
+
parameterSchema: preset.parameterSchema,
|
|
219
|
+
witnessSchema: preset.witnessSchema ?? {},
|
|
220
|
+
exampleParams: preset.exampleParams,
|
|
221
|
+
exampleWitness: preset.exampleWitness ?? null,
|
|
222
|
+
executionProfile: preset.executionProfile,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function validateWitnessConfig(preset, witness) {
|
|
226
|
+
const schema = preset.witnessSchema ?? {};
|
|
227
|
+
const values = witness?.values ?? {};
|
|
228
|
+
const signers = witness?.signers ?? {};
|
|
229
|
+
for (const field of preset.executionProfile.requiredWitnessFields) {
|
|
230
|
+
if (!(field in values) && field !== "SIGNER_SIGNATURE") {
|
|
231
|
+
throw new errors_1.ValidationError(`Missing witness value for preset '${preset.id}': ${field}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
for (const [name, entry] of Object.entries(values)) {
|
|
235
|
+
const spec = schema[name];
|
|
236
|
+
if (!spec) {
|
|
237
|
+
throw new errors_1.ValidationError(`Unexpected witness field for preset '${preset.id}': ${name}`);
|
|
238
|
+
}
|
|
239
|
+
if (entry.type !== spec.type) {
|
|
240
|
+
throw new errors_1.ValidationError(`Witness field '${name}' for preset '${preset.id}' must use type '${spec.type}'`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
for (const [name, spec] of Object.entries(schema)) {
|
|
244
|
+
if (!spec.signerAlias)
|
|
245
|
+
continue;
|
|
246
|
+
const placeholder = `\${SIGNATURE:${spec.signerAlias}}`;
|
|
247
|
+
if ((values[name]?.value ?? "").includes(placeholder) && !signers[spec.signerAlias]) {
|
|
248
|
+
throw new errors_1.ValidationError(`Witness field '${name}' references ${placeholder} but signer '${spec.signerAlias}' was not provided`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
package/dist/core/rpc.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ElementsRpcClient = void 0;
|
|
4
|
+
const node_buffer_1 = require("node:buffer");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
class ElementsRpcClient {
|
|
7
|
+
config;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
}
|
|
11
|
+
endpoint(wallet) {
|
|
12
|
+
if (!wallet && !this.config.wallet)
|
|
13
|
+
return this.config.url;
|
|
14
|
+
const selectedWallet = wallet ?? this.config.wallet;
|
|
15
|
+
return `${this.config.url}/wallet/${selectedWallet}`;
|
|
16
|
+
}
|
|
17
|
+
async call(method, params = [], wallet) {
|
|
18
|
+
const basicAuth = node_buffer_1.Buffer.from(`${this.config.username}:${this.config.password}`).toString("base64");
|
|
19
|
+
const response = await fetch(this.endpoint(wallet), {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: {
|
|
22
|
+
"content-type": "application/json",
|
|
23
|
+
authorization: `Basic ${basicAuth}`,
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify({ jsonrpc: "1.0", id: method, method, params }),
|
|
26
|
+
});
|
|
27
|
+
const payload = (await response.json());
|
|
28
|
+
if (!response.ok || payload.error) {
|
|
29
|
+
throw new errors_1.ExecutionError(`RPC ${method} failed`, {
|
|
30
|
+
status: response.status,
|
|
31
|
+
error: payload.error,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return payload.result;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ElementsRpcClient = ElementsRpcClient;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.stableStringify = stableStringify;
|
|
7
|
+
exports.sha256HexUtf8 = sha256HexUtf8;
|
|
8
|
+
exports.summarize = summarize;
|
|
9
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
10
|
+
function stableStringify(value) {
|
|
11
|
+
if (value === null || typeof value !== "object")
|
|
12
|
+
return JSON.stringify(value);
|
|
13
|
+
if (Array.isArray(value))
|
|
14
|
+
return `[${value.map((entry) => stableStringify(entry)).join(",")}]`;
|
|
15
|
+
const record = value;
|
|
16
|
+
return `{${Object.keys(record)
|
|
17
|
+
.sort()
|
|
18
|
+
.map((key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`)
|
|
19
|
+
.join(",")}}`;
|
|
20
|
+
}
|
|
21
|
+
function sha256HexUtf8(value) {
|
|
22
|
+
return node_crypto_1.default.createHash("sha256").update(value, "utf8").digest("hex");
|
|
23
|
+
}
|
|
24
|
+
function summarize(value) {
|
|
25
|
+
const canonicalJson = stableStringify(value);
|
|
26
|
+
return { canonicalJson, hash: sha256HexUtf8(canonicalJson) };
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderTemplate = renderTemplate;
|
|
4
|
+
exports.normalizeTemplateVars = normalizeTemplateVars;
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
function renderTemplate(source, vars) {
|
|
7
|
+
return source.replace(/\{\{([A-Z0-9_]+)\}\}/g, (_, key) => {
|
|
8
|
+
const value = vars[key];
|
|
9
|
+
if (value === undefined) {
|
|
10
|
+
throw new errors_1.ValidationError(`Template variable not provided: ${key}`);
|
|
11
|
+
}
|
|
12
|
+
return String(value);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function normalizeTemplateVars(vars) {
|
|
16
|
+
return vars ?? {};
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CommandResult {
|
|
2
|
+
stdout: string;
|
|
3
|
+
stderr: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function runCommand(command: string, args: string[], options?: {
|
|
6
|
+
cwd?: string;
|
|
7
|
+
}): Promise<CommandResult>;
|
|
8
|
+
export declare function runSimcCompile(simcPath: string, simfPath: string): Promise<string>;
|
|
9
|
+
export declare function runSimcWithWitness(simcPath: string, simfPath: string, witnessPath: string): Promise<string>;
|
|
10
|
+
export declare function runHalInfo(halPath: string, program: string): Promise<unknown>;
|
|
11
|
+
export declare function runHalUpdateInput(halPath: string, pset: string, inputIndex: number, utxoSpec: string, cmr: string, internalKey: string): Promise<unknown>;
|
|
12
|
+
export declare function runHalSighash(halPath: string, pset: string, inputIndex: number, cmr: string, privkeyHex: string): Promise<unknown>;
|
|
13
|
+
export declare function runHalFinalize(halPath: string, pset: string, inputIndex: number, program: string, witness: string): Promise<unknown>;
|
|
14
|
+
export declare function runHalExtract(halPath: string, pset: string): Promise<string>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runCommand = runCommand;
|
|
4
|
+
exports.runSimcCompile = runSimcCompile;
|
|
5
|
+
exports.runSimcWithWitness = runSimcWithWitness;
|
|
6
|
+
exports.runHalInfo = runHalInfo;
|
|
7
|
+
exports.runHalUpdateInput = runHalUpdateInput;
|
|
8
|
+
exports.runHalSighash = runHalSighash;
|
|
9
|
+
exports.runHalFinalize = runHalFinalize;
|
|
10
|
+
exports.runHalExtract = runHalExtract;
|
|
11
|
+
const node_child_process_1 = require("node:child_process");
|
|
12
|
+
const node_util_1 = require("node:util");
|
|
13
|
+
const errors_1 = require("./errors");
|
|
14
|
+
const execFileP = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
15
|
+
async function runCommand(command, args, options = {}) {
|
|
16
|
+
try {
|
|
17
|
+
const { stdout, stderr } = await execFileP(command, args, {
|
|
18
|
+
cwd: options.cwd,
|
|
19
|
+
maxBuffer: 1024 * 1024 * 50,
|
|
20
|
+
});
|
|
21
|
+
return { stdout: stdout.trim(), stderr: stderr.trim() };
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new errors_1.ToolchainError(`Command failed: ${command} ${args.join(" ")}`, error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function runSimcCompile(simcPath, simfPath) {
|
|
28
|
+
const result = await runCommand(simcPath, [simfPath]);
|
|
29
|
+
return result.stdout;
|
|
30
|
+
}
|
|
31
|
+
async function runSimcWithWitness(simcPath, simfPath, witnessPath) {
|
|
32
|
+
const result = await runCommand(simcPath, [simfPath, witnessPath]);
|
|
33
|
+
return result.stdout;
|
|
34
|
+
}
|
|
35
|
+
async function runHalInfo(halPath, program) {
|
|
36
|
+
const result = await runCommand(halPath, ["simplicity", "info", program]);
|
|
37
|
+
return JSON.parse(result.stdout);
|
|
38
|
+
}
|
|
39
|
+
async function runHalUpdateInput(halPath, pset, inputIndex, utxoSpec, cmr, internalKey) {
|
|
40
|
+
const result = await runCommand(halPath, [
|
|
41
|
+
"simplicity",
|
|
42
|
+
"pset",
|
|
43
|
+
"update-input",
|
|
44
|
+
pset,
|
|
45
|
+
String(inputIndex),
|
|
46
|
+
"-i",
|
|
47
|
+
utxoSpec,
|
|
48
|
+
"-c",
|
|
49
|
+
cmr,
|
|
50
|
+
"-p",
|
|
51
|
+
internalKey,
|
|
52
|
+
]);
|
|
53
|
+
return JSON.parse(result.stdout);
|
|
54
|
+
}
|
|
55
|
+
async function runHalSighash(halPath, pset, inputIndex, cmr, privkeyHex) {
|
|
56
|
+
const result = await runCommand(halPath, [
|
|
57
|
+
"simplicity",
|
|
58
|
+
"sighash",
|
|
59
|
+
pset,
|
|
60
|
+
String(inputIndex),
|
|
61
|
+
cmr,
|
|
62
|
+
"-x",
|
|
63
|
+
privkeyHex,
|
|
64
|
+
]);
|
|
65
|
+
return JSON.parse(result.stdout);
|
|
66
|
+
}
|
|
67
|
+
async function runHalFinalize(halPath, pset, inputIndex, program, witness) {
|
|
68
|
+
const result = await runCommand(halPath, [
|
|
69
|
+
"simplicity",
|
|
70
|
+
"pset",
|
|
71
|
+
"finalize",
|
|
72
|
+
pset,
|
|
73
|
+
String(inputIndex),
|
|
74
|
+
program,
|
|
75
|
+
witness,
|
|
76
|
+
]);
|
|
77
|
+
return JSON.parse(result.stdout);
|
|
78
|
+
}
|
|
79
|
+
async function runHalExtract(halPath, pset) {
|
|
80
|
+
const result = await runCommand(halPath, ["simplicity", "pset", "extract", pset]);
|
|
81
|
+
return result.stdout;
|
|
82
|
+
}
|