@hazbase/simplicity 0.4.0 → 0.4.2

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.
@@ -313,6 +313,50 @@ export interface ExecuteResult {
313
313
  broadcasted: boolean;
314
314
  contractUtxo: ContractUtxo;
315
315
  }
316
+ export interface MultiAssetContractInput {
317
+ txid: string;
318
+ vout: number;
319
+ asset: string;
320
+ amountSat: number;
321
+ sequence?: number;
322
+ amountBlinder?: string;
323
+ assetBlinder?: string;
324
+ }
325
+ export interface MultiAssetContractOutput {
326
+ address: string;
327
+ asset: string;
328
+ amountSat: number;
329
+ }
330
+ export interface MultiAssetContractCallInput {
331
+ wallet: string;
332
+ signer: SignerConfig;
333
+ witness?: WitnessConfig;
334
+ contractInput?: {
335
+ txid: string;
336
+ vout?: number;
337
+ asset?: string;
338
+ amountSat?: number;
339
+ rawTxHex?: string;
340
+ blindingPrivateKey?: string;
341
+ };
342
+ extraInputs?: MultiAssetContractInput[];
343
+ outputs: MultiAssetContractOutput[];
344
+ feeSat?: number;
345
+ changeAddress?: string;
346
+ purpose?: string;
347
+ locktimeHeight?: number;
348
+ broadcast?: boolean;
349
+ }
350
+ export interface MultiAssetInspectResult extends InspectResult {
351
+ extraInputs: MultiAssetContractInput[];
352
+ requestedOutputs: MultiAssetContractOutput[];
353
+ changeOutputs: MultiAssetContractOutput[];
354
+ }
355
+ export interface MultiAssetExecuteResult extends ExecuteResult {
356
+ extraInputs: MultiAssetContractInput[];
357
+ requestedOutputs: MultiAssetContractOutput[];
358
+ changeOutputs: MultiAssetContractOutput[];
359
+ }
316
360
  export interface GaslessExecuteInput {
317
361
  relayer?: import("../gasless/RelayerClient").RelayerClient;
318
362
  fromLabel?: string;
@@ -0,0 +1,128 @@
1
+ /*
2
+ * RWA DvP escrow machine.
3
+ *
4
+ * Delivery path:
5
+ * - output 0 is the payment asset sent to treasury.
6
+ * - output 1 is the Liquid RWA asset sent to the buyer.
7
+ *
8
+ * Refund path:
9
+ * - output 0 is the payment asset returned to the refund recipient after
10
+ * TIMEOUT_HEIGHT.
11
+ *
12
+ * The SDK supplies output hash/script hash witnesses and signs sig_all_hash,
13
+ * so the operator signature covers the full transaction assembled by the SDK.
14
+ */
15
+ fn not(bit: bool) -> bool {
16
+ <u1>::into(jet::complement_1(<bool>::into(bit)))
17
+ }
18
+
19
+ fn require_hash_anchor(value: u256) {
20
+ let zero_hash: u256 = 0x0000000000000000000000000000000000000000000000000000000000000000;
21
+ assert!(not(jet::eq_256(value, zero_hash)));
22
+ }
23
+
24
+ fn require_terms_anchor() {
25
+ let terms_hash: u256 = 0x{{TERMS_HASH}};
26
+ require_hash_anchor(terms_hash);
27
+ }
28
+
29
+ fn require_policy_anchor() {
30
+ let policy_hash: u256 = 0x{{POLICY_HASH}};
31
+ require_hash_anchor(policy_hash);
32
+ }
33
+
34
+ fn require_bound_output(actual_output_hash: u256, actual_script_hash: u256, expected_output_hash: u256, expected_script_hash: u256, binding_mode: u8) {
35
+ match jet::eq_8(binding_mode, 0x03) {
36
+ true => {},
37
+ false => match jet::eq_8(binding_mode, 0x01) {
38
+ true => assert!(jet::eq_256(actual_output_hash, expected_output_hash)),
39
+ false => assert!(jet::eq_256(actual_script_hash, expected_script_hash)),
40
+ },
41
+ };
42
+ }
43
+
44
+ fn require_output_0(expected_output_hash: u256, expected_script_hash: u256, binding_mode: u8) {
45
+ let actual_output_hash: u256 = match jet::output_hash(0) {
46
+ Some(output_hash : u256) => output_hash,
47
+ None => panic!(),
48
+ };
49
+ let actual_script_hash: u256 = unwrap(jet::output_script_hash(0));
50
+ require_bound_output(actual_output_hash, actual_script_hash, expected_output_hash, expected_script_hash, binding_mode);
51
+ }
52
+
53
+ fn require_output_1(expected_output_hash: u256, expected_script_hash: u256, binding_mode: u8) {
54
+ let actual_output_hash: u256 = match jet::output_hash(1) {
55
+ Some(output_hash : u256) => output_hash,
56
+ None => panic!(),
57
+ };
58
+ let actual_script_hash: u256 = unwrap(jet::output_script_hash(1));
59
+ require_bound_output(actual_output_hash, actual_script_hash, expected_output_hash, expected_script_hash, binding_mode);
60
+ }
61
+
62
+ fn checksig(sig: Signature) {
63
+ let signer: Pubkey = 0x{{OPERATOR_XONLY}};
64
+ jet::bip_0340_verify((signer, jet::sig_all_hash()), sig);
65
+ }
66
+
67
+ fn delivery_spend(
68
+ payment_output_hash: u256,
69
+ payment_output_script_hash: u256,
70
+ payment_output_binding_mode: u8,
71
+ rwa_output_hash: u256,
72
+ rwa_output_script_hash: u256,
73
+ rwa_output_binding_mode: u8,
74
+ signer_signature: Signature
75
+ ) {
76
+ require_output_0(
77
+ payment_output_hash,
78
+ payment_output_script_hash,
79
+ payment_output_binding_mode
80
+ );
81
+ require_output_1(
82
+ rwa_output_hash,
83
+ rwa_output_script_hash,
84
+ rwa_output_binding_mode
85
+ );
86
+ checksig(signer_signature);
87
+ }
88
+
89
+ fn refund_spend(
90
+ refund_output_hash: u256,
91
+ refund_output_script_hash: u256,
92
+ refund_output_binding_mode: u8,
93
+ signer_signature: Signature
94
+ ) {
95
+ jet::check_lock_height({{TIMEOUT_HEIGHT}});
96
+ require_output_0(
97
+ refund_output_hash,
98
+ refund_output_script_hash,
99
+ refund_output_binding_mode
100
+ );
101
+ checksig(signer_signature);
102
+ }
103
+
104
+ fn main() {
105
+ require_terms_anchor();
106
+ require_policy_anchor();
107
+ let signer_signature: Signature = witness::SIGNER_SIGNATURE;
108
+ match witness::DELIVERY_OR_REFUND {
109
+ Some(marker: u8) => {
110
+ assert!(jet::eq_8(marker, 0x01));
111
+ delivery_spend(
112
+ witness::PAYMENT_OUTPUT_HASH,
113
+ witness::PAYMENT_OUTPUT_SCRIPT_HASH,
114
+ witness::PAYMENT_OUTPUT_BINDING_MODE,
115
+ witness::RWA_OUTPUT_HASH,
116
+ witness::RWA_OUTPUT_SCRIPT_HASH,
117
+ witness::RWA_OUTPUT_BINDING_MODE,
118
+ signer_signature
119
+ )
120
+ },
121
+ None => refund_spend(
122
+ witness::REFUND_OUTPUT_HASH,
123
+ witness::REFUND_OUTPUT_SCRIPT_HASH,
124
+ witness::REFUND_OUTPUT_BINDING_MODE,
125
+ signer_signature
126
+ ),
127
+ }
128
+ }
@@ -1,5 +1,5 @@
1
1
  import type { SimplicityClient } from "../client/SimplicityClient";
2
- import type { BondOutputBindingMode, OutputRawFields } from "../core/types";
2
+ import type { BondOutputBindingMode, MultiAssetContractInput, MultiAssetExecuteResult, MultiAssetInspectResult, OutputRawFields, SignerConfig, SimplicityArtifact, WitnessConfig } from "../core/types";
3
3
  import { type LiquidX402AssetKey, type LiquidX402Network, type LiquidX402PaymentPayload, type LiquidX402PaymentRequirements, type LiquidX402VerifyPaymentResult } from "../x402";
4
4
  export declare const RWA_DVP_PURCHASE_SCHEMA_VERSION: "rwa-dvp-purchase/v1";
5
5
  export declare const RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION: "rwa-dvp-delivery-claim/v1";
@@ -190,6 +190,74 @@ export interface RwaDvpPrepareRefundClaimInput {
190
190
  refundTxid?: string;
191
191
  createdAt?: string | Date;
192
192
  }
193
+ export interface RwaDvpCompileEscrowContractInput {
194
+ purchase: RwaDvpPurchaseDefinition;
195
+ operatorXonly: string;
196
+ timeoutHeight: number;
197
+ simfPath?: string;
198
+ }
199
+ export interface RwaDvpCompiledEscrowContract {
200
+ compiled: Awaited<ReturnType<SimplicityClient["compileFromFile"]>>;
201
+ artifact: SimplicityArtifact;
202
+ contractAddress: string;
203
+ timeoutHeight: number;
204
+ termsHash: string;
205
+ policyHash: string;
206
+ }
207
+ export interface RwaDvpClaimOutputBinding {
208
+ outputHash: string;
209
+ outputScriptHash: string;
210
+ bindingMode: BondOutputBindingMode;
211
+ }
212
+ export interface RwaDvpClaimExecutionBaseInput {
213
+ purchase: RwaDvpPurchaseDefinition;
214
+ artifactPath?: string;
215
+ artifact?: SimplicityArtifact;
216
+ wallet: string;
217
+ signer: SignerConfig;
218
+ feeSat?: number;
219
+ changeAddress?: string;
220
+ extraInputs?: MultiAssetContractInput[];
221
+ contractInputRawTxHex?: string;
222
+ contractInputBlindingPrivateKey?: string;
223
+ witness?: WitnessConfig;
224
+ locktimeHeight?: number;
225
+ }
226
+ export interface RwaDvpInspectDeliveryClaimInput extends RwaDvpClaimExecutionBaseInput {
227
+ descriptor: RwaDvpDeliveryClaimDescriptor;
228
+ }
229
+ export interface RwaDvpExecuteDeliveryClaimInput extends RwaDvpInspectDeliveryClaimInput {
230
+ broadcast?: boolean;
231
+ }
232
+ export interface RwaDvpInspectRefundClaimInput extends RwaDvpClaimExecutionBaseInput {
233
+ descriptor: RwaDvpRefundClaimDescriptor;
234
+ }
235
+ export interface RwaDvpExecuteRefundClaimInput extends RwaDvpInspectRefundClaimInput {
236
+ broadcast?: boolean;
237
+ }
238
+ export interface RwaDvpDeliveryClaimInspection {
239
+ descriptor: RwaDvpDeliveryClaimDescriptor;
240
+ verification: RwaDvpVerificationReport;
241
+ outputBinding: {
242
+ paymentToTreasury: RwaDvpClaimOutputBinding;
243
+ rwaToBuyer: RwaDvpClaimOutputBinding;
244
+ };
245
+ inspect: MultiAssetInspectResult;
246
+ }
247
+ export interface RwaDvpDeliveryClaimExecution extends Omit<RwaDvpDeliveryClaimInspection, "inspect"> {
248
+ execution: MultiAssetExecuteResult;
249
+ }
250
+ export interface RwaDvpRefundClaimInspection {
251
+ descriptor: RwaDvpRefundClaimDescriptor;
252
+ verification: RwaDvpVerificationReport;
253
+ outputBinding: {
254
+ refund: RwaDvpClaimOutputBinding;
255
+ };
256
+ inspect: MultiAssetInspectResult;
257
+ }
258
+ export interface RwaDvpRefundClaimExecution extends Omit<RwaDvpRefundClaimInspection, "inspect"> {
259
+ execution: MultiAssetExecuteResult;
260
+ }
193
261
  export interface RwaDvpVerificationReport {
194
262
  schemaVersion: typeof RWA_DVP_VERIFICATION_SCHEMA_VERSION;
195
263
  ok: boolean;
@@ -239,6 +307,11 @@ export declare function verifyRefundClaim(_sdk: SimplicityClient, input: {
239
307
  purchase: RwaDvpPurchaseDefinition;
240
308
  descriptor: RwaDvpRefundClaimDescriptor;
241
309
  }): RwaDvpVerificationReport;
310
+ export declare function compileEscrowContract(sdk: SimplicityClient, input: RwaDvpCompileEscrowContractInput): Promise<RwaDvpCompiledEscrowContract>;
311
+ export declare function inspectDeliveryClaim(sdk: SimplicityClient, input: RwaDvpInspectDeliveryClaimInput): Promise<RwaDvpDeliveryClaimInspection>;
312
+ export declare function executeDeliveryClaim(sdk: SimplicityClient, input: RwaDvpExecuteDeliveryClaimInput): Promise<RwaDvpDeliveryClaimExecution>;
313
+ export declare function inspectRefundClaim(sdk: SimplicityClient, input: RwaDvpInspectRefundClaimInput): Promise<RwaDvpRefundClaimInspection>;
314
+ export declare function executeRefundClaim(sdk: SimplicityClient, input: RwaDvpExecuteRefundClaimInput): Promise<RwaDvpRefundClaimExecution>;
242
315
  export declare function exportEvidence(_sdk: SimplicityClient, input: Omit<RwaDvpEvidenceBundle, "schemaVersion" | "createdAt" | "termsHash" | "policyHash"> & {
243
316
  createdAt?: string | Date;
244
317
  }): RwaDvpEvidenceBundle;