@hazbase/simplicity 0.4.5 → 0.4.6

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 CHANGED
@@ -242,6 +242,13 @@ These helpers model a Liquidex-style exchange:
242
242
  - the resulting `X-PAYMENT` payload commits to both the payment output and the
243
243
  delivery output through a summary hash
244
244
 
245
+ When the delivered RWA output must go to a policy/Simplicity address instead of
246
+ the taker's normal wallet receive address, pass `takerDeliveryAddress` (or the
247
+ `deliveryAddress` alias) to `prepareLiquidAtomicDvpLwkWasmTakerPayment(...)`.
248
+ The loaded LWK module must expose a recipient-aware `liquidexTake` variant; if
249
+ it does not, the SDK fails explicitly instead of silently creating a PSET that
250
+ delivers to the wrong address.
251
+
245
252
  The LWK convenience helpers dynamically load `lwk_node` or `lwk_wasm` from the
246
253
  consuming application. Install one of them in the application that prepares or
247
254
  takes proposals:
@@ -445,12 +445,19 @@ function filterContractUtxosByRequestedAsset(utxos, input) {
445
445
  if (!input)
446
446
  return utxos;
447
447
  return utxos.filter((utxo) => {
448
+ const matchesRequestedOutpoint = Boolean(input.txid
449
+ && utxo.txid === input.txid
450
+ && (input.vout === undefined || utxo.vout === input.vout));
448
451
  if (input.txid && utxo.txid !== input.txid)
449
452
  return false;
450
453
  if (input.vout !== undefined && utxo.vout !== input.vout)
451
454
  return false;
452
- if (input.asset && normalizeAssetId(utxo.asset) !== normalizeAssetId(input.asset))
453
- return false;
455
+ if (input.asset) {
456
+ if (!utxo.asset)
457
+ return matchesRequestedOutpoint;
458
+ if (normalizeAssetId(utxo.asset) !== normalizeAssetId(input.asset))
459
+ return false;
460
+ }
454
461
  if (input.amountSat !== undefined && utxo.sat !== input.amountSat)
455
462
  return false;
456
463
  return true;
@@ -137,6 +137,16 @@ export interface LiquidAtomicDvpTakeProposalInput {
137
137
  proposal?: string;
138
138
  proposalPsetBase64?: string;
139
139
  proposalTxHex?: string;
140
+ /**
141
+ * Optional recipient for the maker-delivered asset when the taker PSET is
142
+ * completed. Use this for policy/Simplicity delivery addresses that are not a
143
+ * normal wallet receive address.
144
+ */
145
+ takerDeliveryAddress?: string;
146
+ /**
147
+ * Backwards-friendly alias for `takerDeliveryAddress`.
148
+ */
149
+ deliveryAddress?: string;
140
150
  payer?: string;
141
151
  esploraUrl?: string;
142
152
  waterfalls?: boolean;
@@ -154,6 +164,7 @@ export type LiquidAtomicDvpTakeProposalResult = ReturnType<typeof buildLiquidAto
154
164
  dwid?: string;
155
165
  proposalInput: LiquidAtomicDvpOutputRequirement;
156
166
  proposalOutput: LiquidAtomicDvpOutputRequirement;
167
+ takerDeliveryAddress?: string;
157
168
  };
158
169
  export interface LiquidAtomicDvpVerifyPayloadResult {
159
170
  isValid: boolean;
@@ -113,7 +113,8 @@ async function prepareLiquidAtomicDvpLwkWasmTakerPayment(input) {
113
113
  let builder = network.txBuilder();
114
114
  if (input.feeRate !== undefined)
115
115
  builder = builder.feeRate(input.feeRate);
116
- builder = builder.liquidexTake([validated]);
116
+ const takerDeliveryAddress = normalizeOptionalString(input.takerDeliveryAddress ?? input.deliveryAddress, "takerDeliveryAddress");
117
+ builder = applyLiquidexTake(lwk, builder, [validated], network, takerDeliveryAddress);
117
118
  const unsigned = builder.finish(wollet);
118
119
  const signed = signer.sign(unsigned);
119
120
  const pset = input.finalize === false ? signed : wollet.finalize(signed);
@@ -128,6 +129,7 @@ async function prepareLiquidAtomicDvpLwkWasmTakerPayment(input) {
128
129
  ...(typeof wollet.dwid === "function" ? { dwid: wollet.dwid() } : {}),
129
130
  proposalInput,
130
131
  proposalOutput,
132
+ ...(takerDeliveryAddress ? { takerDeliveryAddress } : {}),
131
133
  };
132
134
  }
133
135
  function buildLiquidAtomicDvpSummaryHash(input) {
@@ -360,6 +362,18 @@ function parseLwkTransaction(lwk, txHex) {
360
362
  return new lwk.Transaction(txHex);
361
363
  throw new Error("LWK Transaction support is required to validate a Liquidex proposal against a transaction.");
362
364
  }
365
+ function applyLiquidexTake(lwk, builder, validatedProposals, network, takerDeliveryAddress) {
366
+ if (!takerDeliveryAddress)
367
+ return builder.liquidexTake(validatedProposals);
368
+ const deliveryAddress = parseLwkAddress(lwk, takerDeliveryAddress, network);
369
+ for (const method of ["liquidexTakeWithRecipient", "liquidexTakeToAddress", "liquidexTakeTo"]) {
370
+ if (typeof builder[method] === "function") {
371
+ return builder[method](validatedProposals, deliveryAddress);
372
+ }
373
+ }
374
+ throw new Error("Liquidex taker delivery address override is not supported by the loaded LWK module. " +
375
+ "Upgrade LWK or use a fixed-recipient/manual atomic DvP PSET builder.");
376
+ }
363
377
  function parseLiquidexProposal(lwk, value) {
364
378
  const encoded = String(value ?? "").trim();
365
379
  if (!encoded)
@@ -435,6 +449,16 @@ function normalizeOutput(value, name) {
435
449
  recipient: requiredString(raw.recipient, `${name}.recipient`),
436
450
  };
437
451
  }
452
+ function normalizeOptionalString(value, name) {
453
+ if (value === undefined || value === null)
454
+ return undefined;
455
+ const text = String(value).trim();
456
+ if (!text)
457
+ return undefined;
458
+ if (text.length > 2048)
459
+ throw new Error(`${name} is too long`);
460
+ return text;
461
+ }
438
462
  function normalizeServiceSigner(value) {
439
463
  if (value === null || value === undefined)
440
464
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hazbase/simplicity",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "An SDK for Simplicity on Liquid",
5
5
  "author": "IndieSquare Inc <info@hazbase.com>",
6
6
  "keywords": [