@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
package/README.md
CHANGED
|
@@ -134,6 +134,212 @@ simplicity-cli definition verify \
|
|
|
134
134
|
|
|
135
135
|
For a bond-oriented walkthrough, see [docs/definitions/README.md](./docs/definitions/README.md).
|
|
136
136
|
|
|
137
|
+
## Trusted Issuance State JSON
|
|
138
|
+
|
|
139
|
+
The same hash-anchor model now also applies to issuance state documents such as a bond issuance record.
|
|
140
|
+
|
|
141
|
+
This is useful when you want to say not only:
|
|
142
|
+
|
|
143
|
+
- "these are the bond terms,"
|
|
144
|
+
|
|
145
|
+
but also:
|
|
146
|
+
|
|
147
|
+
- "this bond was issued in this amount, with this outstanding principal, under this controller."
|
|
148
|
+
|
|
149
|
+
The SDK now supports:
|
|
150
|
+
|
|
151
|
+
- loading and hashing a state JSON with `sdk.loadStateDocument(...)`,
|
|
152
|
+
- storing its hash in the artifact,
|
|
153
|
+
- committing `STATE_HASH` into custom `.simf` contract logic,
|
|
154
|
+
- verifying later that the issuance state JSON still matches the compiled contract.
|
|
155
|
+
|
|
156
|
+
For Bond issuance, the recommended shape is:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"issuanceId": "BOND-2026-001-ISSUE-1",
|
|
161
|
+
"bondId": "BOND-2026-001",
|
|
162
|
+
"issuerEntityId": "hazbase-treasury",
|
|
163
|
+
"issuedPrincipal": 1000000,
|
|
164
|
+
"outstandingPrincipal": 1000000,
|
|
165
|
+
"redeemedPrincipal": 0,
|
|
166
|
+
"currencyAssetId": "bitcoin",
|
|
167
|
+
"controllerXonly": "<xonly>",
|
|
168
|
+
"issuedAt": "2026-03-10T00:00:00Z",
|
|
169
|
+
"status": "ISSUED"
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
To move from an issued bond into a redemption state, the SDK now also supports a minimal state transition model:
|
|
174
|
+
|
|
175
|
+
- `ISSUED -> PARTIALLY_REDEEMED`
|
|
176
|
+
- `ISSUED/PARTIALLY_REDEEMED -> REDEEMED`
|
|
177
|
+
|
|
178
|
+
The next state records:
|
|
179
|
+
|
|
180
|
+
- `previousStateHash`
|
|
181
|
+
- `lastTransition.type`
|
|
182
|
+
- `lastTransition.amount`
|
|
183
|
+
- `lastTransition.at`
|
|
184
|
+
|
|
185
|
+
and the SDK verifies the principal invariant:
|
|
186
|
+
|
|
187
|
+
- `issuedPrincipal = outstandingPrincipal + redeemedPrincipal`
|
|
188
|
+
|
|
189
|
+
On top of that, the SDK can now build a `BondSettlementDescriptor`, which bundles the intended settlement envelope into one canonical document:
|
|
190
|
+
|
|
191
|
+
- `definitionHash`
|
|
192
|
+
- `previousStateHash`
|
|
193
|
+
- `nextStateHash`
|
|
194
|
+
- `nextContractAddress`
|
|
195
|
+
- `nextAmountSat`
|
|
196
|
+
- `maxFeeSat`
|
|
197
|
+
- status progression and principal deltas
|
|
198
|
+
|
|
199
|
+
The redemption machine commits that settlement descriptor hash as an additional anchor. This does not yet mean full runtime output introspection, but it does mean the machine can now honestly claim a committed settlement envelope instead of just a scattered set of fields.
|
|
200
|
+
|
|
201
|
+
Minimal TypeScript flow:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
const compiled = await sdk.bonds.defineBond({
|
|
205
|
+
definitionPath: "./docs/definitions/bond-definition.json",
|
|
206
|
+
issuancePath: "./docs/definitions/bond-issuance-state.json",
|
|
207
|
+
simfPath: "./docs/definitions/bond-issuance-anchor.simf",
|
|
208
|
+
artifactPath: "./bond-issuance.artifact.json",
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const verification = await sdk.bonds.verifyBond({
|
|
212
|
+
artifactPath: "./bond-issuance.artifact.json",
|
|
213
|
+
definitionPath: "./docs/definitions/bond-definition.json",
|
|
214
|
+
issuancePath: "./docs/definitions/bond-issuance-state.json",
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
console.log(verification.crossChecks.principalInvariantValid);
|
|
218
|
+
console.log(verification.issuance.trust.effectiveMode);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Minimal redemption flow:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
const preview = await sdk.bonds.buildBondRedemption({
|
|
225
|
+
definitionPath: "./docs/definitions/bond-definition.json",
|
|
226
|
+
previousIssuancePath: "./docs/definitions/bond-issuance-state.json",
|
|
227
|
+
amount: 250000,
|
|
228
|
+
redeemedAt: "2027-03-10T00:00:00Z",
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const compiled = await sdk.bonds.redeemBond({
|
|
232
|
+
definitionPath: "./docs/definitions/bond-definition.json",
|
|
233
|
+
previousIssuancePath: "./docs/definitions/bond-issuance-state.json",
|
|
234
|
+
amount: 250000,
|
|
235
|
+
redeemedAt: "2027-03-10T00:00:00Z",
|
|
236
|
+
simfPath: "./docs/definitions/bond-issuance-anchor.simf",
|
|
237
|
+
artifactPath: "./bond-redemption.artifact.json",
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const transition = await sdk.bonds.verifyBondTransition({
|
|
241
|
+
previousIssuancePath: "./docs/definitions/bond-issuance-state.json",
|
|
242
|
+
nextIssuancePath: "./docs/definitions/bond-issuance-state-partial-redemption.json",
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const payload = await sdk.bonds.buildBondPayload({
|
|
246
|
+
artifactPath: "./bond-redemption.artifact.json",
|
|
247
|
+
definitionPath: "./docs/definitions/bond-definition.json",
|
|
248
|
+
issuancePath: "./docs/definitions/bond-issuance-state-partial-redemption.json",
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const transitionPayload = await sdk.bonds.buildBondTransitionPayload({
|
|
252
|
+
definitionPath: "./docs/definitions/bond-definition.json",
|
|
253
|
+
previousIssuancePath: "./docs/definitions/bond-issuance-state.json",
|
|
254
|
+
nextIssuancePath: "./docs/definitions/bond-issuance-state-partial-redemption.json",
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
console.log(preview.nextHash);
|
|
258
|
+
console.log(compiled.state()?.hash);
|
|
259
|
+
console.log(transition.transition.statusProgressionValid);
|
|
260
|
+
console.log(payload.payload);
|
|
261
|
+
console.log(transitionPayload.payload.redeemAmount);
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
CLI equivalents:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
simplicity-cli state show \
|
|
268
|
+
--type bond-issuance \
|
|
269
|
+
--id BOND-2026-001-ISSUE-1 \
|
|
270
|
+
--json-path ./docs/definitions/bond-issuance-state.json
|
|
271
|
+
|
|
272
|
+
simplicity-cli state verify \
|
|
273
|
+
--artifact ./bond-issuance.artifact.json \
|
|
274
|
+
--type bond-issuance \
|
|
275
|
+
--id BOND-2026-001-ISSUE-1 \
|
|
276
|
+
--json-path ./docs/definitions/bond-issuance-state.json
|
|
277
|
+
|
|
278
|
+
simplicity-cli bond verify \
|
|
279
|
+
--artifact ./bond-issuance.artifact.json \
|
|
280
|
+
--definition-json ./docs/definitions/bond-definition.json \
|
|
281
|
+
--issuance-json ./docs/definitions/bond-issuance-state.json
|
|
282
|
+
|
|
283
|
+
simplicity-cli bond redeem \
|
|
284
|
+
--definition-json ./docs/definitions/bond-definition.json \
|
|
285
|
+
--previous-issuance-json ./docs/definitions/bond-issuance-state.json \
|
|
286
|
+
--amount 250000 \
|
|
287
|
+
--redeemed-at 2027-03-10T00:00:00Z \
|
|
288
|
+
--simf ./docs/definitions/bond-issuance-anchor.simf \
|
|
289
|
+
--next-issuance-out ./next-bond-issuance-state.json \
|
|
290
|
+
--artifact ./bond-redemption.artifact.json
|
|
291
|
+
|
|
292
|
+
simplicity-cli bond verify-transition \
|
|
293
|
+
--previous-issuance-json ./docs/definitions/bond-issuance-state.json \
|
|
294
|
+
--next-issuance-json ./docs/definitions/bond-issuance-state-partial-redemption.json
|
|
295
|
+
|
|
296
|
+
simplicity-cli bond compile-transition \
|
|
297
|
+
--definition-json ./docs/definitions/bond-definition.json \
|
|
298
|
+
--previous-issuance-json ./docs/definitions/bond-issuance-state.json \
|
|
299
|
+
--next-issuance-json ./docs/definitions/bond-issuance-state-partial-redemption.json \
|
|
300
|
+
--simf ./docs/definitions/bond-redemption-transition.simf \
|
|
301
|
+
--artifact ./bond-transition.artifact.json
|
|
302
|
+
|
|
303
|
+
simplicity-cli bond compile-redemption-machine \
|
|
304
|
+
--definition-json ./docs/definitions/bond-definition.json \
|
|
305
|
+
--previous-issuance-json ./docs/definitions/bond-issuance-state.json \
|
|
306
|
+
--next-issuance-json ./docs/definitions/bond-issuance-state-partial-redemption.json \
|
|
307
|
+
--simf ./docs/definitions/bond-redemption-state-machine.simf \
|
|
308
|
+
--artifact ./bond-redemption-machine.artifact.json
|
|
309
|
+
|
|
310
|
+
simplicity-cli bond verify-machine \
|
|
311
|
+
--artifact ./bond-redemption-machine.artifact.json \
|
|
312
|
+
--definition-json ./docs/definitions/bond-definition.json \
|
|
313
|
+
--previous-issuance-json ./docs/definitions/bond-issuance-state.json \
|
|
314
|
+
--next-issuance-json ./docs/definitions/bond-issuance-state-partial-redemption.json
|
|
315
|
+
|
|
316
|
+
simplicity-cli bond plan-rollover \
|
|
317
|
+
--current-artifact ./bond-issuance.artifact.json \
|
|
318
|
+
--definition-json ./docs/definitions/bond-definition.json \
|
|
319
|
+
--previous-issuance-json ./docs/definitions/bond-issuance-state.json \
|
|
320
|
+
--next-issuance-json ./docs/definitions/bond-issuance-state-partial-redemption.json \
|
|
321
|
+
--next-simf ./docs/definitions/bond-issuance-anchor.simf \
|
|
322
|
+
--next-artifact ./bond-next.artifact.json
|
|
323
|
+
|
|
324
|
+
simplicity-cli bond plan-machine-rollover \
|
|
325
|
+
--current-artifact ./bond-issuance.artifact.json \
|
|
326
|
+
--definition-json ./docs/definitions/bond-definition.json \
|
|
327
|
+
--previous-issuance-json ./docs/definitions/bond-issuance-state.json \
|
|
328
|
+
--next-issuance-json ./docs/definitions/bond-issuance-state-partial-redemption.json \
|
|
329
|
+
--machine-simf ./docs/definitions/bond-redemption-state-machine.simf \
|
|
330
|
+
--machine-artifact ./bond-redemption-machine.artifact.json
|
|
331
|
+
|
|
332
|
+
simplicity-cli bond transition-payload \
|
|
333
|
+
--definition-json ./docs/definitions/bond-definition.json \
|
|
334
|
+
--previous-issuance-json ./docs/definitions/bond-issuance-state.json \
|
|
335
|
+
--next-issuance-json ./docs/definitions/bond-issuance-state-partial-redemption.json
|
|
336
|
+
|
|
337
|
+
simplicity-cli bond payload \
|
|
338
|
+
--artifact ./bond-redemption.artifact.json \
|
|
339
|
+
--definition-json ./docs/definitions/bond-definition.json \
|
|
340
|
+
--issuance-json ./docs/definitions/bond-issuance-state-partial-redemption.json
|
|
341
|
+
```
|
|
342
|
+
|
|
137
343
|
## Install
|
|
138
344
|
|
|
139
345
|
You need three things:
|
|
@@ -811,6 +1017,19 @@ These examples are included to help you jump to the right workflow quickly.
|
|
|
811
1017
|
- [gasless-transfer.ts](./examples/gasless-transfer.ts): standard relayer-backed gasless L-BTC transfer.
|
|
812
1018
|
- [define-bond.ts](./examples/define-bond.ts): compile a bond example with a trusted definition hash anchor.
|
|
813
1019
|
- [show-bond-definition.ts](./examples/show-bond-definition.ts): verify and retrieve a trusted bond definition from JSON + artifact.
|
|
1020
|
+
- [define-bond-issuance.ts](./examples/define-bond-issuance.ts): compile a bond example with both trusted definition and issuance state anchors.
|
|
1021
|
+
- [show-bond-issuance.ts](./examples/show-bond-issuance.ts): load a bond artifact together with its verified issuance state.
|
|
1022
|
+
- [verify-bond-issuance.ts](./examples/verify-bond-issuance.ts): run combined Bond definition/state verification and invariant checks.
|
|
1023
|
+
- [redeem-bond-issuance.ts](./examples/redeem-bond-issuance.ts): build the next redemption state and compile a new anchored artifact.
|
|
1024
|
+
- [verify-bond-transition.ts](./examples/verify-bond-transition.ts): verify a previous/next issuance state transition.
|
|
1025
|
+
- [compile-bond-transition.ts](./examples/compile-bond-transition.ts): compile a transition contract that commits both previous and next issuance state hashes.
|
|
1026
|
+
- [compile-bond-redemption-machine.ts](./examples/compile-bond-redemption-machine.ts): compile a redemption transition contract that also commits redeem amount and transition kind.
|
|
1027
|
+
- [verify-bond-redemption-machine.ts](./examples/verify-bond-redemption-machine.ts): verify a compiled redemption machine artifact against definition, previous state, and next state inputs.
|
|
1028
|
+
- [plan-bond-rollover.ts](./examples/plan-bond-rollover.ts): build a runtime rollover plan that spends the current state UTXO into the next state's contract address.
|
|
1029
|
+
- [show-bond-transition-payload.ts](./examples/show-bond-transition-payload.ts): emit a bridge-ready payload for a previous/next redemption transition.
|
|
1030
|
+
- [show-bond-payload.ts](./examples/show-bond-payload.ts): emit a bridge-ready payload from a verified bond artifact.
|
|
1031
|
+
- [redeem-bond-issuance.ts](./examples/redeem-bond-issuance.ts): build a partially redeemed bond issuance state and anchor it in a new artifact.
|
|
1032
|
+
- [verify-bond-transition.ts](./examples/verify-bond-transition.ts): verify a redemption transition between two issuance state documents.
|
|
814
1033
|
|
|
815
1034
|
In addition to the in-repo examples, the package has also been validated from a blank external consumer project with:
|
|
816
1035
|
- `npm install @hazbase/simplicity`
|
|
@@ -843,6 +1062,16 @@ When you compile with `definition: { ... }`, the artifact also carries:
|
|
|
843
1062
|
|
|
844
1063
|
That is what allows the SDK and CLI to verify that an off-chain JSON definition still matches the contract you compiled.
|
|
845
1064
|
|
|
1065
|
+
When you also compile with `state: { ... }`, the artifact can additionally carry:
|
|
1066
|
+
- `stateType`
|
|
1067
|
+
- `stateId`
|
|
1068
|
+
- `schemaVersion`
|
|
1069
|
+
- `hash`
|
|
1070
|
+
- `trustMode`
|
|
1071
|
+
- `anchorMode`
|
|
1072
|
+
|
|
1073
|
+
That is what allows the SDK and CLI to verify that an off-chain issuance state document still matches the contract you compiled.
|
|
1074
|
+
|
|
846
1075
|
### When should I use a preset instead of a custom `.simf` file?
|
|
847
1076
|
|
|
848
1077
|
Use a preset first when you are learning the lifecycle or your use case already matches a built-in contract. Move to custom `.simf` when your business rules are app-specific.
|