@hazbase/simplicity 0.0.3 → 0.0.5
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/README.md +229 -0
- package/dist/cli.js +388 -1
- package/dist/client/ContractFactory.d.ts +2 -1
- package/dist/client/ContractFactory.js +3 -0
- package/dist/client/DeployedContract.d.ts +15 -1
- package/dist/client/DeployedContract.js +22 -0
- package/dist/client/SimplicityClient.d.ts +304 -1
- package/dist/client/SimplicityClient.js +49 -0
- package/dist/core/artifact.js +8 -0
- package/dist/core/compiler.js +60 -5
- package/dist/core/executor.js +24 -0
- package/dist/core/state.d.ts +18 -0
- package/dist/core/state.js +278 -0
- package/dist/core/types.d.ts +106 -0
- package/dist/domain/bond.d.ts +2051 -0
- package/dist/domain/bond.js +1042 -0
- package/dist/domain/bondSettlementValidation.d.ts +18 -0
- package/dist/domain/bondSettlementValidation.js +122 -0
- package/dist/domain/bondValidation.d.ts +29 -0
- package/dist/domain/bondValidation.js +303 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +41 -1
- package/package.json +1 -1
|
@@ -1,21 +1,313 @@
|
|
|
1
1
|
import { ElementsRpcClient } from "../core/rpc";
|
|
2
|
-
import { DefinitionInput, DefinitionVerificationResult, CompileFromFileInput, CompileFromPresetInput, DefinitionDescriptor, SimplicityArtifact, SimplicityClientConfig } from "../core/types";
|
|
2
|
+
import { BondDefinition, BondIssuanceState, BondSettlementDescriptor, DefinitionInput, DefinitionVerificationResult, CompileFromFileInput, CompileFromPresetInput, DefinitionDescriptor, StateDocumentDescriptor, StateDocumentInput, StateVerificationResult, SimplicityArtifact, SimplicityClientConfig } from "../core/types";
|
|
3
3
|
import { RelayerClient } from "../gasless/RelayerClient";
|
|
4
4
|
import { GaslessTransferInput, GaslessTransferResult, RelayerClientConfig } from "../gasless/types";
|
|
5
5
|
import { CompiledContract } from "./ContractFactory";
|
|
6
6
|
import { DeployedContract } from "./DeployedContract";
|
|
7
|
+
import { buildBondPayload, buildBondRedemption, buildBondTransitionPayload, buildBondRolloverPlan, buildBondMachineRolloverPlan, buildBondMachineSettlementPlan, buildBondSettlementDescriptor, buildBondSettlementPayload, compileBondRedemptionMachine, compileBondTransition, executeBondStateRollover, executeBondMachineRollover, executeBondMachineSettlement, inspectBondStateRollover, inspectBondMachineRollover, inspectBondMachineSettlement, loadBond, redeemBond, verifyBond, verifyBondSettlementDescriptor, verifyBondRedemptionMachineArtifact, verifyBondTransition } from "../domain/bond";
|
|
7
8
|
export declare class SimplicityClient {
|
|
8
9
|
readonly config: SimplicityClientConfig;
|
|
9
10
|
readonly rpc: ElementsRpcClient;
|
|
10
11
|
readonly payments: {
|
|
11
12
|
gaslessTransfer: (input: GaslessTransferInput) => Promise<GaslessTransferResult>;
|
|
12
13
|
};
|
|
14
|
+
readonly bonds: {
|
|
15
|
+
defineBond: (input: {
|
|
16
|
+
definitionPath?: string;
|
|
17
|
+
definitionValue?: BondDefinition;
|
|
18
|
+
issuancePath?: string;
|
|
19
|
+
issuanceValue?: BondIssuanceState;
|
|
20
|
+
simfPath?: string;
|
|
21
|
+
artifactPath?: string;
|
|
22
|
+
}) => Promise<CompiledContract>;
|
|
23
|
+
verifyBond: (input: {
|
|
24
|
+
artifactPath?: string;
|
|
25
|
+
artifact?: SimplicityArtifact;
|
|
26
|
+
definitionPath?: string;
|
|
27
|
+
definitionValue?: BondDefinition;
|
|
28
|
+
issuancePath?: string;
|
|
29
|
+
issuanceValue?: BondIssuanceState;
|
|
30
|
+
}) => ReturnType<typeof verifyBond>;
|
|
31
|
+
redeemBond: (input: {
|
|
32
|
+
definitionPath?: string;
|
|
33
|
+
definitionValue?: BondDefinition;
|
|
34
|
+
previousIssuancePath?: string;
|
|
35
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
36
|
+
amount: number;
|
|
37
|
+
redeemedAt: string;
|
|
38
|
+
simfPath?: string;
|
|
39
|
+
artifactPath?: string;
|
|
40
|
+
}) => ReturnType<typeof redeemBond>;
|
|
41
|
+
verifyBondTransition: (input: {
|
|
42
|
+
previousIssuancePath?: string;
|
|
43
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
44
|
+
nextIssuancePath?: string;
|
|
45
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
46
|
+
}) => ReturnType<typeof verifyBondTransition>;
|
|
47
|
+
buildBondRedemption: (input: {
|
|
48
|
+
definitionPath?: string;
|
|
49
|
+
definitionValue?: BondDefinition;
|
|
50
|
+
previousIssuancePath?: string;
|
|
51
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
52
|
+
amount: number;
|
|
53
|
+
redeemedAt: string;
|
|
54
|
+
}) => ReturnType<typeof buildBondRedemption>;
|
|
55
|
+
buildBondPayload: (input: {
|
|
56
|
+
artifactPath?: string;
|
|
57
|
+
artifact?: SimplicityArtifact;
|
|
58
|
+
definitionPath?: string;
|
|
59
|
+
definitionValue?: BondDefinition;
|
|
60
|
+
issuancePath?: string;
|
|
61
|
+
issuanceValue?: BondIssuanceState;
|
|
62
|
+
}) => ReturnType<typeof buildBondPayload>;
|
|
63
|
+
buildBondTransitionPayload: (input: {
|
|
64
|
+
definitionPath?: string;
|
|
65
|
+
definitionValue?: BondDefinition;
|
|
66
|
+
previousIssuancePath?: string;
|
|
67
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
68
|
+
nextIssuancePath?: string;
|
|
69
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
70
|
+
}) => ReturnType<typeof buildBondTransitionPayload>;
|
|
71
|
+
buildBondSettlementDescriptor: (input: {
|
|
72
|
+
definitionPath?: string;
|
|
73
|
+
definitionValue?: BondDefinition;
|
|
74
|
+
previousIssuancePath?: string;
|
|
75
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
76
|
+
nextIssuancePath?: string;
|
|
77
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
78
|
+
nextStateSimfPath?: string;
|
|
79
|
+
nextAmountSat: number;
|
|
80
|
+
maxFeeSat?: number;
|
|
81
|
+
}) => ReturnType<typeof buildBondSettlementDescriptor>;
|
|
82
|
+
verifyBondSettlementDescriptor: (input: {
|
|
83
|
+
descriptorPath?: string;
|
|
84
|
+
descriptorValue?: BondSettlementDescriptor;
|
|
85
|
+
definitionPath?: string;
|
|
86
|
+
definitionValue?: BondDefinition;
|
|
87
|
+
previousIssuancePath?: string;
|
|
88
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
89
|
+
nextIssuancePath?: string;
|
|
90
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
91
|
+
nextStateSimfPath?: string;
|
|
92
|
+
nextAmountSat?: number;
|
|
93
|
+
maxFeeSat?: number;
|
|
94
|
+
}) => ReturnType<typeof verifyBondSettlementDescriptor>;
|
|
95
|
+
buildBondSettlementPayload: (input: {
|
|
96
|
+
definitionPath?: string;
|
|
97
|
+
definitionValue?: BondDefinition;
|
|
98
|
+
previousIssuancePath?: string;
|
|
99
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
100
|
+
nextIssuancePath?: string;
|
|
101
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
102
|
+
nextStateSimfPath?: string;
|
|
103
|
+
nextAmountSat: number;
|
|
104
|
+
maxFeeSat?: number;
|
|
105
|
+
}) => ReturnType<typeof buildBondSettlementPayload>;
|
|
106
|
+
buildBondRolloverPlan: (input: {
|
|
107
|
+
currentArtifactPath?: string;
|
|
108
|
+
currentArtifact?: SimplicityArtifact;
|
|
109
|
+
definitionPath?: string;
|
|
110
|
+
definitionValue?: BondDefinition;
|
|
111
|
+
previousIssuancePath?: string;
|
|
112
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
113
|
+
nextIssuancePath?: string;
|
|
114
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
115
|
+
nextSimfPath?: string;
|
|
116
|
+
nextArtifactPath?: string;
|
|
117
|
+
}) => ReturnType<typeof buildBondRolloverPlan>;
|
|
118
|
+
buildBondMachineRolloverPlan: (input: {
|
|
119
|
+
currentArtifactPath?: string;
|
|
120
|
+
currentArtifact?: SimplicityArtifact;
|
|
121
|
+
definitionPath?: string;
|
|
122
|
+
definitionValue?: BondDefinition;
|
|
123
|
+
previousIssuancePath?: string;
|
|
124
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
125
|
+
nextIssuancePath?: string;
|
|
126
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
127
|
+
nextStateSimfPath?: string;
|
|
128
|
+
machineSimfPath?: string;
|
|
129
|
+
machineArtifactPath?: string;
|
|
130
|
+
}) => ReturnType<typeof buildBondMachineRolloverPlan>;
|
|
131
|
+
buildBondMachineSettlementPlan: (input: {
|
|
132
|
+
currentMachineArtifactPath?: string;
|
|
133
|
+
currentMachineArtifact?: SimplicityArtifact;
|
|
134
|
+
definitionPath?: string;
|
|
135
|
+
definitionValue?: BondDefinition;
|
|
136
|
+
previousIssuancePath?: string;
|
|
137
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
138
|
+
nextIssuancePath?: string;
|
|
139
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
140
|
+
nextSimfPath?: string;
|
|
141
|
+
nextArtifactPath?: string;
|
|
142
|
+
}) => ReturnType<typeof buildBondMachineSettlementPlan>;
|
|
143
|
+
compileBondTransition: (input: {
|
|
144
|
+
definitionPath?: string;
|
|
145
|
+
definitionValue?: BondDefinition;
|
|
146
|
+
previousIssuancePath?: string;
|
|
147
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
148
|
+
nextIssuancePath?: string;
|
|
149
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
150
|
+
simfPath?: string;
|
|
151
|
+
artifactPath?: string;
|
|
152
|
+
}) => ReturnType<typeof compileBondTransition>;
|
|
153
|
+
compileBondRedemptionMachine: (input: {
|
|
154
|
+
definitionPath?: string;
|
|
155
|
+
definitionValue?: BondDefinition;
|
|
156
|
+
previousIssuancePath?: string;
|
|
157
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
158
|
+
nextIssuancePath?: string;
|
|
159
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
160
|
+
nextStateSimfPath?: string;
|
|
161
|
+
nextAmountSat?: number;
|
|
162
|
+
maxFeeSat?: number;
|
|
163
|
+
simfPath?: string;
|
|
164
|
+
artifactPath?: string;
|
|
165
|
+
}) => ReturnType<typeof compileBondRedemptionMachine>;
|
|
166
|
+
verifyBondRedemptionMachineArtifact: (input: {
|
|
167
|
+
artifactPath?: string;
|
|
168
|
+
artifact?: SimplicityArtifact;
|
|
169
|
+
definitionPath?: string;
|
|
170
|
+
definitionValue?: BondDefinition;
|
|
171
|
+
previousIssuancePath?: string;
|
|
172
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
173
|
+
nextIssuancePath?: string;
|
|
174
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
175
|
+
nextStateSimfPath?: string;
|
|
176
|
+
nextAmountSat?: number;
|
|
177
|
+
maxFeeSat?: number;
|
|
178
|
+
}) => ReturnType<typeof verifyBondRedemptionMachineArtifact>;
|
|
179
|
+
inspectBondStateRollover: (input: {
|
|
180
|
+
currentArtifactPath?: string;
|
|
181
|
+
currentArtifact?: SimplicityArtifact;
|
|
182
|
+
definitionPath?: string;
|
|
183
|
+
definitionValue?: BondDefinition;
|
|
184
|
+
previousIssuancePath?: string;
|
|
185
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
186
|
+
nextIssuancePath?: string;
|
|
187
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
188
|
+
nextSimfPath?: string;
|
|
189
|
+
nextArtifactPath?: string;
|
|
190
|
+
wallet: string;
|
|
191
|
+
signer: {
|
|
192
|
+
type: "schnorrPrivkeyHex";
|
|
193
|
+
privkeyHex: string;
|
|
194
|
+
};
|
|
195
|
+
feeSat?: number;
|
|
196
|
+
utxoPolicy?: "smallest_over" | "largest" | "newest";
|
|
197
|
+
}) => ReturnType<typeof inspectBondStateRollover>;
|
|
198
|
+
inspectBondMachineRollover: (input: {
|
|
199
|
+
currentArtifactPath?: string;
|
|
200
|
+
currentArtifact?: SimplicityArtifact;
|
|
201
|
+
definitionPath?: string;
|
|
202
|
+
definitionValue?: BondDefinition;
|
|
203
|
+
previousIssuancePath?: string;
|
|
204
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
205
|
+
nextIssuancePath?: string;
|
|
206
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
207
|
+
machineSimfPath?: string;
|
|
208
|
+
machineArtifactPath?: string;
|
|
209
|
+
wallet: string;
|
|
210
|
+
signer: {
|
|
211
|
+
type: "schnorrPrivkeyHex";
|
|
212
|
+
privkeyHex: string;
|
|
213
|
+
};
|
|
214
|
+
feeSat?: number;
|
|
215
|
+
utxoPolicy?: "smallest_over" | "largest" | "newest";
|
|
216
|
+
}) => ReturnType<typeof inspectBondMachineRollover>;
|
|
217
|
+
inspectBondMachineSettlement: (input: {
|
|
218
|
+
currentMachineArtifactPath?: string;
|
|
219
|
+
currentMachineArtifact?: SimplicityArtifact;
|
|
220
|
+
definitionPath?: string;
|
|
221
|
+
definitionValue?: BondDefinition;
|
|
222
|
+
previousIssuancePath?: string;
|
|
223
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
224
|
+
nextIssuancePath?: string;
|
|
225
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
226
|
+
nextSimfPath?: string;
|
|
227
|
+
nextArtifactPath?: string;
|
|
228
|
+
wallet: string;
|
|
229
|
+
signer: {
|
|
230
|
+
type: "schnorrPrivkeyHex";
|
|
231
|
+
privkeyHex: string;
|
|
232
|
+
};
|
|
233
|
+
feeSat?: number;
|
|
234
|
+
utxoPolicy?: "smallest_over" | "largest" | "newest";
|
|
235
|
+
}) => ReturnType<typeof inspectBondMachineSettlement>;
|
|
236
|
+
executeBondStateRollover: (input: {
|
|
237
|
+
currentArtifactPath?: string;
|
|
238
|
+
currentArtifact?: SimplicityArtifact;
|
|
239
|
+
definitionPath?: string;
|
|
240
|
+
definitionValue?: BondDefinition;
|
|
241
|
+
previousIssuancePath?: string;
|
|
242
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
243
|
+
nextIssuancePath?: string;
|
|
244
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
245
|
+
nextSimfPath?: string;
|
|
246
|
+
nextArtifactPath?: string;
|
|
247
|
+
wallet: string;
|
|
248
|
+
signer: {
|
|
249
|
+
type: "schnorrPrivkeyHex";
|
|
250
|
+
privkeyHex: string;
|
|
251
|
+
};
|
|
252
|
+
feeSat?: number;
|
|
253
|
+
utxoPolicy?: "smallest_over" | "largest" | "newest";
|
|
254
|
+
broadcast?: boolean;
|
|
255
|
+
}) => ReturnType<typeof executeBondStateRollover>;
|
|
256
|
+
executeBondMachineRollover: (input: {
|
|
257
|
+
currentArtifactPath?: string;
|
|
258
|
+
currentArtifact?: SimplicityArtifact;
|
|
259
|
+
definitionPath?: string;
|
|
260
|
+
definitionValue?: BondDefinition;
|
|
261
|
+
previousIssuancePath?: string;
|
|
262
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
263
|
+
nextIssuancePath?: string;
|
|
264
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
265
|
+
machineSimfPath?: string;
|
|
266
|
+
machineArtifactPath?: string;
|
|
267
|
+
wallet: string;
|
|
268
|
+
signer: {
|
|
269
|
+
type: "schnorrPrivkeyHex";
|
|
270
|
+
privkeyHex: string;
|
|
271
|
+
};
|
|
272
|
+
feeSat?: number;
|
|
273
|
+
utxoPolicy?: "smallest_over" | "largest" | "newest";
|
|
274
|
+
broadcast?: boolean;
|
|
275
|
+
}) => ReturnType<typeof executeBondMachineRollover>;
|
|
276
|
+
executeBondMachineSettlement: (input: {
|
|
277
|
+
currentMachineArtifactPath?: string;
|
|
278
|
+
currentMachineArtifact?: SimplicityArtifact;
|
|
279
|
+
definitionPath?: string;
|
|
280
|
+
definitionValue?: BondDefinition;
|
|
281
|
+
previousIssuancePath?: string;
|
|
282
|
+
previousIssuanceValue?: BondIssuanceState;
|
|
283
|
+
nextIssuancePath?: string;
|
|
284
|
+
nextIssuanceValue?: BondIssuanceState;
|
|
285
|
+
nextSimfPath?: string;
|
|
286
|
+
nextArtifactPath?: string;
|
|
287
|
+
wallet: string;
|
|
288
|
+
signer: {
|
|
289
|
+
type: "schnorrPrivkeyHex";
|
|
290
|
+
privkeyHex: string;
|
|
291
|
+
};
|
|
292
|
+
feeSat?: number;
|
|
293
|
+
utxoPolicy?: "smallest_over" | "largest" | "newest";
|
|
294
|
+
broadcast?: boolean;
|
|
295
|
+
}) => ReturnType<typeof executeBondMachineSettlement>;
|
|
296
|
+
loadBond: (input: {
|
|
297
|
+
artifactPath: string;
|
|
298
|
+
definitionPath?: string;
|
|
299
|
+
definitionValue?: BondDefinition;
|
|
300
|
+
issuancePath?: string;
|
|
301
|
+
issuanceValue?: BondIssuanceState;
|
|
302
|
+
}) => ReturnType<typeof loadBond>;
|
|
303
|
+
};
|
|
13
304
|
constructor(config: SimplicityClientConfig);
|
|
14
305
|
compileFromFile(input: CompileFromFileInput): Promise<CompiledContract>;
|
|
15
306
|
compileFromPreset(input: CompileFromPresetInput): Promise<CompiledContract>;
|
|
16
307
|
loadArtifact(path: string): Promise<CompiledContract>;
|
|
17
308
|
define(input: DefinitionInput): Promise<DefinitionDescriptor>;
|
|
18
309
|
loadDefinition(input: DefinitionInput): Promise<DefinitionDescriptor>;
|
|
310
|
+
loadStateDocument(input: StateDocumentInput): Promise<StateDocumentDescriptor>;
|
|
19
311
|
verifyDefinitionAgainstArtifact(input: {
|
|
20
312
|
artifactPath?: string;
|
|
21
313
|
artifact?: SimplicityArtifact;
|
|
@@ -27,6 +319,17 @@ export declare class SimplicityClient {
|
|
|
27
319
|
id?: string;
|
|
28
320
|
schemaVersion?: string;
|
|
29
321
|
}): Promise<DefinitionVerificationResult>;
|
|
322
|
+
verifyStateAgainstArtifact(input: {
|
|
323
|
+
artifactPath?: string;
|
|
324
|
+
artifact?: SimplicityArtifact;
|
|
325
|
+
jsonPath?: string;
|
|
326
|
+
value?: unknown;
|
|
327
|
+
expectedType?: string;
|
|
328
|
+
expectedId?: string;
|
|
329
|
+
type?: string;
|
|
330
|
+
id?: string;
|
|
331
|
+
schemaVersion?: string;
|
|
332
|
+
}): Promise<StateVerificationResult>;
|
|
30
333
|
fromArtifact(artifact: SimplicityArtifact): DeployedContract;
|
|
31
334
|
relayer(config: RelayerClientConfig): RelayerClient;
|
|
32
335
|
private gaslessTransfer;
|
|
@@ -5,21 +5,49 @@ exports.createSimplicityClient = createSimplicityClient;
|
|
|
5
5
|
const artifact_1 = require("../core/artifact");
|
|
6
6
|
const compiler_1 = require("../core/compiler");
|
|
7
7
|
const definition_1 = require("../core/definition");
|
|
8
|
+
const state_1 = require("../core/state");
|
|
8
9
|
const errors_1 = require("../core/errors");
|
|
9
10
|
const rpc_1 = require("../core/rpc");
|
|
10
11
|
const RelayerClient_1 = require("../gasless/RelayerClient");
|
|
11
12
|
const ContractFactory_1 = require("./ContractFactory");
|
|
12
13
|
const DeployedContract_1 = require("./DeployedContract");
|
|
14
|
+
const bond_1 = require("../domain/bond");
|
|
13
15
|
class SimplicityClient {
|
|
14
16
|
config;
|
|
15
17
|
rpc;
|
|
16
18
|
payments;
|
|
19
|
+
bonds;
|
|
17
20
|
constructor(config) {
|
|
18
21
|
this.config = config;
|
|
19
22
|
this.rpc = new rpc_1.ElementsRpcClient(config.rpc);
|
|
20
23
|
this.payments = {
|
|
21
24
|
gaslessTransfer: async (input) => this.gaslessTransfer(input),
|
|
22
25
|
};
|
|
26
|
+
this.bonds = {
|
|
27
|
+
defineBond: async (input) => (0, bond_1.defineBond)(this, input),
|
|
28
|
+
verifyBond: async (input) => (0, bond_1.verifyBond)(this, input),
|
|
29
|
+
redeemBond: async (input) => (0, bond_1.redeemBond)(this, input),
|
|
30
|
+
verifyBondTransition: async (input) => (0, bond_1.verifyBondTransition)(this, input),
|
|
31
|
+
buildBondRedemption: async (input) => (0, bond_1.buildBondRedemption)(this, input),
|
|
32
|
+
buildBondPayload: async (input) => (0, bond_1.buildBondPayload)(this, input),
|
|
33
|
+
buildBondTransitionPayload: async (input) => (0, bond_1.buildBondTransitionPayload)(this, input),
|
|
34
|
+
buildBondSettlementDescriptor: async (input) => (0, bond_1.buildBondSettlementDescriptor)(this, input),
|
|
35
|
+
verifyBondSettlementDescriptor: async (input) => (0, bond_1.verifyBondSettlementDescriptor)(this, input),
|
|
36
|
+
buildBondSettlementPayload: async (input) => (0, bond_1.buildBondSettlementPayload)(this, input),
|
|
37
|
+
buildBondRolloverPlan: async (input) => (0, bond_1.buildBondRolloverPlan)(this, input),
|
|
38
|
+
buildBondMachineRolloverPlan: async (input) => (0, bond_1.buildBondMachineRolloverPlan)(this, input),
|
|
39
|
+
buildBondMachineSettlementPlan: async (input) => (0, bond_1.buildBondMachineSettlementPlan)(this, input),
|
|
40
|
+
compileBondTransition: async (input) => (0, bond_1.compileBondTransition)(this, input),
|
|
41
|
+
compileBondRedemptionMachine: async (input) => (0, bond_1.compileBondRedemptionMachine)(this, input),
|
|
42
|
+
verifyBondRedemptionMachineArtifact: async (input) => (0, bond_1.verifyBondRedemptionMachineArtifact)(this, input),
|
|
43
|
+
inspectBondStateRollover: async (input) => (0, bond_1.inspectBondStateRollover)(this, input),
|
|
44
|
+
inspectBondMachineRollover: async (input) => (0, bond_1.inspectBondMachineRollover)(this, input),
|
|
45
|
+
inspectBondMachineSettlement: async (input) => (0, bond_1.inspectBondMachineSettlement)(this, input),
|
|
46
|
+
executeBondStateRollover: async (input) => (0, bond_1.executeBondStateRollover)(this, input),
|
|
47
|
+
executeBondMachineRollover: async (input) => (0, bond_1.executeBondMachineRollover)(this, input),
|
|
48
|
+
executeBondMachineSettlement: async (input) => (0, bond_1.executeBondMachineSettlement)(this, input),
|
|
49
|
+
loadBond: async (input) => (0, bond_1.loadBond)(this, input),
|
|
50
|
+
};
|
|
23
51
|
}
|
|
24
52
|
async compileFromFile(input) {
|
|
25
53
|
const artifact = await (0, compiler_1.compileFromFile)(this.config, input);
|
|
@@ -39,6 +67,9 @@ class SimplicityClient {
|
|
|
39
67
|
async loadDefinition(input) {
|
|
40
68
|
return (0, definition_1.loadDefinitionInput)(input);
|
|
41
69
|
}
|
|
70
|
+
async loadStateDocument(input) {
|
|
71
|
+
return (0, state_1.loadStateInput)(input);
|
|
72
|
+
}
|
|
42
73
|
async verifyDefinitionAgainstArtifact(input) {
|
|
43
74
|
const artifact = input.artifact ?? (input.artifactPath ? await (0, artifact_1.loadArtifact)(input.artifactPath, this.config.network) : undefined);
|
|
44
75
|
if (!artifact) {
|
|
@@ -57,6 +88,24 @@ class SimplicityClient {
|
|
|
57
88
|
expectedId: input.expectedId,
|
|
58
89
|
});
|
|
59
90
|
}
|
|
91
|
+
async verifyStateAgainstArtifact(input) {
|
|
92
|
+
const artifact = input.artifact ?? (input.artifactPath ? await (0, artifact_1.loadArtifact)(input.artifactPath, this.config.network) : undefined);
|
|
93
|
+
if (!artifact) {
|
|
94
|
+
throw new errors_1.ValidationError("artifactPath or artifact is required");
|
|
95
|
+
}
|
|
96
|
+
return (0, state_1.verifyStateAgainstArtifact)({
|
|
97
|
+
artifact,
|
|
98
|
+
state: {
|
|
99
|
+
type: input.type ?? input.expectedType ?? artifact.state?.stateType ?? "",
|
|
100
|
+
id: input.id ?? input.expectedId ?? artifact.state?.stateId ?? "",
|
|
101
|
+
schemaVersion: input.schemaVersion,
|
|
102
|
+
jsonPath: input.jsonPath,
|
|
103
|
+
value: input.value,
|
|
104
|
+
},
|
|
105
|
+
expectedType: input.expectedType,
|
|
106
|
+
expectedId: input.expectedId,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
60
109
|
fromArtifact(artifact) {
|
|
61
110
|
return new DeployedContract_1.DeployedContract(this.config, artifact);
|
|
62
111
|
}
|
package/dist/core/artifact.js
CHANGED
|
@@ -26,6 +26,12 @@ function normalizeArtifact(artifact, networkDefault = "liquidtestnet") {
|
|
|
26
26
|
anchorMode: current.definition.anchorMode ?? "artifact-hash-anchor",
|
|
27
27
|
}
|
|
28
28
|
: undefined,
|
|
29
|
+
state: current.state
|
|
30
|
+
? {
|
|
31
|
+
...current.state,
|
|
32
|
+
anchorMode: current.state.anchorMode ?? "artifact-hash-anchor",
|
|
33
|
+
}
|
|
34
|
+
: undefined,
|
|
29
35
|
};
|
|
30
36
|
}
|
|
31
37
|
if (!isArtifactV5(artifact)) {
|
|
@@ -65,6 +71,7 @@ function normalizeArtifact(artifact, networkDefault = "liquidtestnet") {
|
|
|
65
71
|
notes: null,
|
|
66
72
|
},
|
|
67
73
|
definition: undefined,
|
|
74
|
+
state: undefined,
|
|
68
75
|
legacy: {
|
|
69
76
|
simfTemplatePath: artifact.simfTemplatePath,
|
|
70
77
|
params: artifact.params,
|
|
@@ -101,6 +108,7 @@ async function loadArtifact(artifactPath, networkDefault = "liquidtestnet") {
|
|
|
101
108
|
}
|
|
102
109
|
: undefined,
|
|
103
110
|
definition: normalized.definition,
|
|
111
|
+
state: normalized.state,
|
|
104
112
|
};
|
|
105
113
|
}
|
|
106
114
|
async function saveArtifact(artifactPath, artifact) {
|
package/dist/core/compiler.js
CHANGED
|
@@ -12,6 +12,7 @@ const artifact_1 = require("./artifact");
|
|
|
12
12
|
const definition_1 = require("./definition");
|
|
13
13
|
const errors_1 = require("./errors");
|
|
14
14
|
const presets_1 = require("./presets");
|
|
15
|
+
const state_1 = require("./state");
|
|
15
16
|
const templating_1 = require("./templating");
|
|
16
17
|
const toolchain_1 = require("./toolchain");
|
|
17
18
|
function parseSimcProgram(output) {
|
|
@@ -74,6 +75,12 @@ async function buildArtifact(input) {
|
|
|
74
75
|
onChainAnchor: input.definition.onChainAnchor,
|
|
75
76
|
})
|
|
76
77
|
: undefined,
|
|
78
|
+
state: input.state
|
|
79
|
+
? (0, state_1.buildArtifactStateMetadata)(input.state, {
|
|
80
|
+
anchorMode: input.state.anchorMode,
|
|
81
|
+
onChainAnchor: input.state.onChainAnchor,
|
|
82
|
+
})
|
|
83
|
+
: undefined,
|
|
77
84
|
legacy: {
|
|
78
85
|
simfTemplatePath: input.sourceSimfPath,
|
|
79
86
|
params: {
|
|
@@ -85,14 +92,22 @@ async function buildArtifact(input) {
|
|
|
85
92
|
}
|
|
86
93
|
async function compileFromFile(config, input) {
|
|
87
94
|
const definition = input.definition ? await (0, definition_1.loadDefinitionInput)(input.definition) : undefined;
|
|
95
|
+
const state = input.state ? await (0, state_1.loadStateInput)(input.state) : undefined;
|
|
88
96
|
if (definition && input.templateVars?.DEFINITION_HASH !== undefined) {
|
|
89
97
|
throw new errors_1.ValidationError("DEFINITION_HASH must not be provided explicitly when definition metadata is supplied", { code: "DEFINITION_HASH_OVERRIDE_FORBIDDEN" });
|
|
90
98
|
}
|
|
91
99
|
if (definition && input.templateVars?.DEFINITION_ID !== undefined) {
|
|
92
100
|
throw new errors_1.ValidationError("DEFINITION_ID must not be provided explicitly when definition metadata is supplied", { code: "DEFINITION_ID_OVERRIDE_FORBIDDEN" });
|
|
93
101
|
}
|
|
102
|
+
if (state && input.templateVars?.STATE_HASH !== undefined) {
|
|
103
|
+
throw new errors_1.ValidationError("STATE_HASH must not be provided explicitly when state metadata is supplied", { code: "STATE_HASH_OVERRIDE_FORBIDDEN" });
|
|
104
|
+
}
|
|
105
|
+
if (state && input.templateVars?.STATE_ID !== undefined) {
|
|
106
|
+
throw new errors_1.ValidationError("STATE_ID must not be provided explicitly when state metadata is supplied", { code: "STATE_ID_OVERRIDE_FORBIDDEN" });
|
|
107
|
+
}
|
|
94
108
|
const rawSource = await (0, promises_1.readFile)(input.simfPath, "utf8");
|
|
95
109
|
let onChainAnchor;
|
|
110
|
+
let onChainStateAnchor;
|
|
96
111
|
if (input.definition?.anchorMode === "on-chain-constant-committed") {
|
|
97
112
|
const detection = (0, definition_1.detectOnChainDefinitionAnchor)(rawSource);
|
|
98
113
|
if (!rawSource.includes("{{DEFINITION_HASH}}")) {
|
|
@@ -110,10 +125,27 @@ async function compileFromFile(config, input) {
|
|
|
110
125
|
sourceVerified: true,
|
|
111
126
|
};
|
|
112
127
|
}
|
|
128
|
+
if (input.state?.anchorMode === "on-chain-constant-committed") {
|
|
129
|
+
const detection = (0, state_1.detectOnChainStateAnchor)(rawSource);
|
|
130
|
+
if (!rawSource.includes("{{STATE_HASH}}")) {
|
|
131
|
+
throw new errors_1.ValidationError("Requested on-chain constant-committed state anchor, but the .simf source does not contain {{STATE_HASH}}", { code: "STATE_HASH_PLACEHOLDER_MISSING" });
|
|
132
|
+
}
|
|
133
|
+
if (!detection.sourceVerified || !detection.helper) {
|
|
134
|
+
const code = detection.reason?.includes("called")
|
|
135
|
+
? "STATE_ONCHAIN_HELPER_NOT_CALLED"
|
|
136
|
+
: "STATE_ONCHAIN_HELPER_MISSING";
|
|
137
|
+
throw new errors_1.ValidationError(`Requested on-chain constant-committed state anchor, but the .simf source does not contain the required state helper pattern: ${detection.reason ?? "unknown reason"}`, { code });
|
|
138
|
+
}
|
|
139
|
+
onChainStateAnchor = {
|
|
140
|
+
helper: detection.helper,
|
|
141
|
+
templateVar: "STATE_HASH",
|
|
142
|
+
sourceVerified: true,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
113
145
|
const templateVars = {
|
|
114
146
|
...(input.templateVars ?? {}),
|
|
115
|
-
...(definition
|
|
116
|
-
...(
|
|
147
|
+
...(definition ? { DEFINITION_HASH: definition.hash, DEFINITION_ID: definition.definitionId } : {}),
|
|
148
|
+
...(state ? { STATE_HASH: state.hash, STATE_ID: state.stateId } : {}),
|
|
117
149
|
};
|
|
118
150
|
const rendered = (0, templating_1.renderTemplate)(rawSource, templateVars);
|
|
119
151
|
const workDir = await (0, promises_1.mkdtemp)(node_path_1.default.join((0, node_os_1.tmpdir)(), "simplicity-sdk-compile-"));
|
|
@@ -123,7 +155,7 @@ async function compileFromFile(config, input) {
|
|
|
123
155
|
config,
|
|
124
156
|
renderedSimfPath: renderedPath,
|
|
125
157
|
sourceMode: "file",
|
|
126
|
-
sourceSimfPath: input.simfPath,
|
|
158
|
+
sourceSimfPath: node_path_1.default.resolve(input.simfPath),
|
|
127
159
|
templateVars,
|
|
128
160
|
definition: definition
|
|
129
161
|
? {
|
|
@@ -132,6 +164,13 @@ async function compileFromFile(config, input) {
|
|
|
132
164
|
onChainAnchor,
|
|
133
165
|
}
|
|
134
166
|
: undefined,
|
|
167
|
+
state: state
|
|
168
|
+
? {
|
|
169
|
+
...state,
|
|
170
|
+
anchorMode: input.state?.anchorMode ?? "artifact-hash-anchor",
|
|
171
|
+
onChainAnchor: onChainStateAnchor,
|
|
172
|
+
}
|
|
173
|
+
: undefined,
|
|
135
174
|
});
|
|
136
175
|
if (input.artifactPath) {
|
|
137
176
|
await (0, artifact_1.saveArtifact)(input.artifactPath, artifact);
|
|
@@ -143,17 +182,27 @@ async function compileFromPreset(config, input) {
|
|
|
143
182
|
if (input.definition?.anchorMode === "on-chain-constant-committed") {
|
|
144
183
|
throw new errors_1.UnsupportedFeatureError(`Preset '${preset.id}' does not yet support on-chain constant-committed definition anchors`, { code: "DEFINITION_ANCHOR_MODE_UNSUPPORTED_FOR_PRESET", preset: preset.id });
|
|
145
184
|
}
|
|
185
|
+
if (input.state?.anchorMode === "on-chain-constant-committed") {
|
|
186
|
+
throw new errors_1.UnsupportedFeatureError(`Preset '${preset.id}' does not yet support on-chain constant-committed state anchors`, { code: "STATE_ANCHOR_MODE_UNSUPPORTED_FOR_PRESET", preset: preset.id });
|
|
187
|
+
}
|
|
146
188
|
const definition = input.definition ? await (0, definition_1.loadDefinitionInput)(input.definition) : undefined;
|
|
189
|
+
const state = input.state ? await (0, state_1.loadStateInput)(input.state) : undefined;
|
|
147
190
|
if (definition && input.params.DEFINITION_HASH !== undefined) {
|
|
148
191
|
throw new errors_1.ValidationError("DEFINITION_HASH must not be provided explicitly when definition metadata is supplied", { code: "DEFINITION_HASH_OVERRIDE_FORBIDDEN" });
|
|
149
192
|
}
|
|
150
193
|
if (definition && input.params.DEFINITION_ID !== undefined) {
|
|
151
194
|
throw new errors_1.ValidationError("DEFINITION_ID must not be provided explicitly when definition metadata is supplied", { code: "DEFINITION_ID_OVERRIDE_FORBIDDEN" });
|
|
152
195
|
}
|
|
196
|
+
if (state && input.params.STATE_HASH !== undefined) {
|
|
197
|
+
throw new errors_1.ValidationError("STATE_HASH must not be provided explicitly when state metadata is supplied", { code: "STATE_HASH_OVERRIDE_FORBIDDEN" });
|
|
198
|
+
}
|
|
199
|
+
if (state && input.params.STATE_ID !== undefined) {
|
|
200
|
+
throw new errors_1.ValidationError("STATE_ID must not be provided explicitly when state metadata is supplied", { code: "STATE_ID_OVERRIDE_FORBIDDEN" });
|
|
201
|
+
}
|
|
153
202
|
const params = {
|
|
154
203
|
...(0, presets_1.validatePresetParams)(preset, input.params),
|
|
155
|
-
...(definition
|
|
156
|
-
...(
|
|
204
|
+
...(definition ? { DEFINITION_HASH: definition.hash, DEFINITION_ID: definition.definitionId } : {}),
|
|
205
|
+
...(state ? { STATE_HASH: state.hash, STATE_ID: state.stateId } : {}),
|
|
157
206
|
};
|
|
158
207
|
const rawSource = await (0, promises_1.readFile)(preset.simfTemplatePath, "utf8");
|
|
159
208
|
const rendered = (0, templating_1.renderTemplate)(rawSource, params);
|
|
@@ -173,6 +222,12 @@ async function compileFromPreset(config, input) {
|
|
|
173
222
|
anchorMode: input.definition?.anchorMode ?? "artifact-hash-anchor",
|
|
174
223
|
}
|
|
175
224
|
: undefined,
|
|
225
|
+
state: state
|
|
226
|
+
? {
|
|
227
|
+
...state,
|
|
228
|
+
anchorMode: input.state?.anchorMode ?? "artifact-hash-anchor",
|
|
229
|
+
}
|
|
230
|
+
: undefined,
|
|
176
231
|
});
|
|
177
232
|
if (input.artifactPath) {
|
|
178
233
|
await (0, artifact_1.saveArtifact)(input.artifactPath, artifact);
|
package/dist/core/executor.js
CHANGED
|
@@ -213,6 +213,13 @@ function buildPsetSummary(decoded, meta) {
|
|
|
213
213
|
trustMode: meta.definitionTrustMode ?? null,
|
|
214
214
|
anchorMode: meta.definitionAnchorMode ?? null,
|
|
215
215
|
},
|
|
216
|
+
state: {
|
|
217
|
+
type: meta.stateType ?? null,
|
|
218
|
+
id: meta.stateId ?? null,
|
|
219
|
+
hash: meta.stateHash ?? null,
|
|
220
|
+
trustMode: meta.stateTrustMode ?? null,
|
|
221
|
+
anchorMode: meta.stateAnchorMode ?? null,
|
|
222
|
+
},
|
|
216
223
|
contract: {
|
|
217
224
|
address: meta.contractAddress,
|
|
218
225
|
cmr: meta.cmr,
|
|
@@ -304,6 +311,11 @@ async function buildExecutionState(config, artifact, input) {
|
|
|
304
311
|
definitionHash: artifact.definition?.hash,
|
|
305
312
|
definitionTrustMode: artifact.definition?.trustMode,
|
|
306
313
|
definitionAnchorMode: artifact.definition?.anchorMode,
|
|
314
|
+
stateType: artifact.state?.stateType,
|
|
315
|
+
stateId: artifact.state?.stateId,
|
|
316
|
+
stateHash: artifact.state?.hash,
|
|
317
|
+
stateTrustMode: artifact.state?.trustMode,
|
|
318
|
+
stateAnchorMode: artifact.state?.anchorMode,
|
|
307
319
|
expectedLiquidReceiver: input.expectedLiquidReceiver ?? recipientAddress,
|
|
308
320
|
contractAddress: artifact.compiled.contractAddress,
|
|
309
321
|
cmr: artifact.compiled.cmr,
|
|
@@ -460,6 +472,11 @@ async function executeGaslessContractCall(config, artifact, input) {
|
|
|
460
472
|
definitionHash: artifact.definition?.hash,
|
|
461
473
|
definitionTrustMode: artifact.definition?.trustMode,
|
|
462
474
|
definitionAnchorMode: artifact.definition?.anchorMode,
|
|
475
|
+
stateType: artifact.state?.stateType,
|
|
476
|
+
stateId: artifact.state?.stateId,
|
|
477
|
+
stateHash: artifact.state?.hash,
|
|
478
|
+
stateTrustMode: artifact.state?.trustMode,
|
|
479
|
+
stateAnchorMode: artifact.state?.anchorMode,
|
|
463
480
|
contractAddress: artifact.compiled.contractAddress,
|
|
464
481
|
cmr: artifact.compiled.cmr,
|
|
465
482
|
internalKey: artifact.compiled.internalKey,
|
|
@@ -653,6 +670,13 @@ async function executeRelayedGaslessContractCall(config, artifact, input, relaye
|
|
|
653
670
|
trustMode: artifact.definition?.trustMode ?? null,
|
|
654
671
|
anchorMode: artifact.definition?.anchorMode ?? null,
|
|
655
672
|
},
|
|
673
|
+
state: {
|
|
674
|
+
type: artifact.state?.stateType ?? null,
|
|
675
|
+
id: artifact.state?.stateId ?? null,
|
|
676
|
+
hash: artifact.state?.hash ?? null,
|
|
677
|
+
trustMode: artifact.state?.trustMode ?? null,
|
|
678
|
+
anchorMode: artifact.state?.anchorMode ?? null,
|
|
679
|
+
},
|
|
656
680
|
contract: {
|
|
657
681
|
address: request.detailedSummary.contract.contractAddress,
|
|
658
682
|
cmr: request.detailedSummary.contract.cmr,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ArtifactStateMetadata, DefinitionAnchorMode, SimplicityArtifact, StateDocumentDescriptor, StateDocumentInput, StateVerificationResult } from "./types";
|
|
2
|
+
export declare function loadStateInput(input: StateDocumentInput): Promise<StateDocumentDescriptor>;
|
|
3
|
+
export declare function detectOnChainStateAnchor(simfSource: string): {
|
|
4
|
+
sourceVerified: boolean;
|
|
5
|
+
helper?: "nonzero-eq_256";
|
|
6
|
+
reason?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function buildArtifactStateMetadata(state: StateDocumentDescriptor, options?: {
|
|
9
|
+
anchorMode?: DefinitionAnchorMode;
|
|
10
|
+
onChainAnchor?: ArtifactStateMetadata["onChainAnchor"];
|
|
11
|
+
}): ArtifactStateMetadata;
|
|
12
|
+
export declare function verifyStateDescriptorAgainstArtifact(state: StateDocumentDescriptor, artifactState?: ArtifactStateMetadata, expectedType?: string, expectedId?: string): StateVerificationResult;
|
|
13
|
+
export declare function verifyStateAgainstArtifact(input: {
|
|
14
|
+
artifact: SimplicityArtifact;
|
|
15
|
+
state: StateDocumentInput;
|
|
16
|
+
expectedType?: string;
|
|
17
|
+
expectedId?: string;
|
|
18
|
+
}): Promise<StateVerificationResult>;
|