@hazbase/simplicity 0.4.1 → 0.4.3
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 +116 -2
- package/dist/client/SimplicityClient.d.ts +5 -0
- package/dist/client/SimplicityClient.js +5 -0
- package/dist/core/executor.d.ts +3 -1
- package/dist/core/executor.js +307 -8
- package/dist/core/rpc.js +3 -1
- package/dist/core/toolchain.d.ts +24 -0
- package/dist/core/toolchain.js +106 -2
- package/dist/core/types.d.ts +44 -0
- package/dist/docs/definitions/rwa-dvp-escrow.simf +128 -0
- package/dist/domain/rwaDvp.d.ts +76 -1
- package/dist/domain/rwaDvp.js +427 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -2
- package/dist/x402/atomicDvp.d.ts +197 -0
- package/dist/x402/atomicDvp.js +482 -0
- package/dist/x402/index.d.ts +1 -0
- package/dist/x402/index.js +15 -0
- package/package.json +1 -1
package/dist/domain/rwaDvp.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.RWA_DVP_EVIDENCE_SCHEMA_VERSION = exports.RWA_DVP_VERIFICATION_SCHEMA_VERSION = exports.RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION = exports.RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION = exports.RWA_DVP_PURCHASE_SCHEMA_VERSION = void 0;
|
|
4
7
|
exports.definePurchase = definePurchase;
|
|
@@ -9,8 +12,17 @@ exports.prepareDeliveryClaim = prepareDeliveryClaim;
|
|
|
9
12
|
exports.verifyDeliveryClaim = verifyDeliveryClaim;
|
|
10
13
|
exports.prepareRefundClaim = prepareRefundClaim;
|
|
11
14
|
exports.verifyRefundClaim = verifyRefundClaim;
|
|
15
|
+
exports.compileEscrowContract = compileEscrowContract;
|
|
16
|
+
exports.inspectDeliveryClaim = inspectDeliveryClaim;
|
|
17
|
+
exports.executeDeliveryClaim = executeDeliveryClaim;
|
|
18
|
+
exports.inspectRefundClaim = inspectRefundClaim;
|
|
19
|
+
exports.executeRefundClaim = executeRefundClaim;
|
|
12
20
|
exports.exportEvidence = exportEvidence;
|
|
21
|
+
const node_fs_1 = require("node:fs");
|
|
22
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
13
23
|
const errors_1 = require("../core/errors");
|
|
24
|
+
const executor_1 = require("../core/executor");
|
|
25
|
+
const outputBinding_1 = require("../core/outputBinding");
|
|
14
26
|
const summary_1 = require("../core/summary");
|
|
15
27
|
const x402_1 = require("../x402");
|
|
16
28
|
exports.RWA_DVP_PURCHASE_SCHEMA_VERSION = "rwa-dvp-purchase/v1";
|
|
@@ -36,6 +48,7 @@ function definePurchase(_sdk, input) {
|
|
|
36
48
|
network,
|
|
37
49
|
evmLock: {
|
|
38
50
|
...input.evmLock,
|
|
51
|
+
tokenStandard: input.evmLock.tokenStandard ?? "ERC3475",
|
|
39
52
|
amountAtomic: normalizeInteger(input.evmLock.amountAtomic),
|
|
40
53
|
},
|
|
41
54
|
payment: {
|
|
@@ -224,6 +237,420 @@ function verifyRefundClaim(_sdk, input) {
|
|
|
224
237
|
};
|
|
225
238
|
return report(input.purchase.purchaseId, termsHash, policyHash, checks, "RWA DvP refund claim descriptor mismatch");
|
|
226
239
|
}
|
|
240
|
+
const ZERO_HASH_256 = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
241
|
+
function resolveRwaDvpDocsAsset(filename) {
|
|
242
|
+
const cwdCandidate = node_path_1.default.resolve(process.cwd(), "docs/definitions", filename);
|
|
243
|
+
if ((0, node_fs_1.existsSync)(cwdCandidate))
|
|
244
|
+
return cwdCandidate;
|
|
245
|
+
return node_path_1.default.resolve(__dirname, "../docs/definitions", filename);
|
|
246
|
+
}
|
|
247
|
+
function assertXonly(value, field) {
|
|
248
|
+
const normalized = value.trim().toLowerCase().replace(/^0x/u, "");
|
|
249
|
+
if (!/^[0-9a-f]{64}$/u.test(normalized)) {
|
|
250
|
+
throw new errors_1.ValidationError(`${field} must be a 32-byte x-only public key`);
|
|
251
|
+
}
|
|
252
|
+
return normalized;
|
|
253
|
+
}
|
|
254
|
+
function atomicToSafeSat(value, field) {
|
|
255
|
+
const normalized = normalizeInteger(value);
|
|
256
|
+
const amount = BigInt(normalized);
|
|
257
|
+
if (amount > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
258
|
+
throw new errors_1.ValidationError(`${field} exceeds JavaScript safe integer range`);
|
|
259
|
+
}
|
|
260
|
+
return Number(amount);
|
|
261
|
+
}
|
|
262
|
+
function decimalToSat(value) {
|
|
263
|
+
const parsed = Number(value);
|
|
264
|
+
if (!Number.isFinite(parsed)) {
|
|
265
|
+
throw new errors_1.ValidationError(`Invalid Liquid amount: ${String(value)}`);
|
|
266
|
+
}
|
|
267
|
+
return Math.round(parsed * 100_000_000);
|
|
268
|
+
}
|
|
269
|
+
function sameOutpoint(left, right) {
|
|
270
|
+
return left.txid === right.txid && (right.vout === undefined || left.vout === right.vout);
|
|
271
|
+
}
|
|
272
|
+
function assetEquals(left, right) {
|
|
273
|
+
return left.trim().toLowerCase() === right.trim().toLowerCase();
|
|
274
|
+
}
|
|
275
|
+
async function resolveWalletLbtcAssetId(sdk, network) {
|
|
276
|
+
const sidechain = await sdk.rpc.call("getsidechaininfo").catch(() => null);
|
|
277
|
+
const peggedAsset = sidechain?.pegged_asset;
|
|
278
|
+
if (peggedAsset && /^[0-9a-f]{64}$/iu.test(peggedAsset)) {
|
|
279
|
+
return peggedAsset.toLowerCase();
|
|
280
|
+
}
|
|
281
|
+
return (0, x402_1.resolveLiquidX402Asset)("lbtc", network).assetId;
|
|
282
|
+
}
|
|
283
|
+
async function listWalletInputs(sdk, wallet) {
|
|
284
|
+
const entries = await sdk.rpc.call("listunspent", [0, 9999999, [], true], wallet);
|
|
285
|
+
return entries
|
|
286
|
+
.filter((entry) => entry.spendable !== false)
|
|
287
|
+
.filter((entry) => entry.safe !== false)
|
|
288
|
+
.map((entry) => ({
|
|
289
|
+
txid: entry.txid,
|
|
290
|
+
vout: entry.vout,
|
|
291
|
+
asset: entry.asset,
|
|
292
|
+
amountSat: decimalToSat(entry.amount),
|
|
293
|
+
...(entry.amountblinder ? { amountBlinder: entry.amountblinder } : {}),
|
|
294
|
+
...(entry.assetblinder ? { assetBlinder: entry.assetblinder } : {}),
|
|
295
|
+
}));
|
|
296
|
+
}
|
|
297
|
+
function selectInputsForAsset(input) {
|
|
298
|
+
if (input.requiredSat <= 0)
|
|
299
|
+
return [];
|
|
300
|
+
const exclude = input.exclude ?? new Set();
|
|
301
|
+
const key = (entry) => `${entry.txid}:${entry.vout}`;
|
|
302
|
+
const matches = input.candidates
|
|
303
|
+
.filter((entry) => assetEquals(entry.asset, input.assetId))
|
|
304
|
+
.filter((entry) => !exclude.has(key(entry)));
|
|
305
|
+
const preferred = input.preferred?.txid
|
|
306
|
+
? matches.find((entry) => sameOutpoint(entry, input.preferred ?? {}))
|
|
307
|
+
: undefined;
|
|
308
|
+
if (preferred) {
|
|
309
|
+
if (preferred.amountSat < input.requiredSat) {
|
|
310
|
+
throw new errors_1.ValidationError("Preferred wallet input is smaller than the required amount", {
|
|
311
|
+
assetId: input.assetId,
|
|
312
|
+
requiredSat: input.requiredSat,
|
|
313
|
+
preferredAmountSat: preferred.amountSat,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
exclude.add(key(preferred));
|
|
317
|
+
return [preferred];
|
|
318
|
+
}
|
|
319
|
+
const selected = [];
|
|
320
|
+
let total = 0;
|
|
321
|
+
for (const candidate of matches.slice().sort((a, b) => a.amountSat - b.amountSat)) {
|
|
322
|
+
selected.push(candidate);
|
|
323
|
+
exclude.add(key(candidate));
|
|
324
|
+
total += candidate.amountSat;
|
|
325
|
+
if (total >= input.requiredSat)
|
|
326
|
+
return selected;
|
|
327
|
+
}
|
|
328
|
+
throw new errors_1.ValidationError("No wallet inputs satisfy the required asset amount", {
|
|
329
|
+
assetId: input.assetId,
|
|
330
|
+
requiredSat: input.requiredSat,
|
|
331
|
+
availableSat: total,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
async function resolveDeliveryExtraInputs(sdk, input) {
|
|
335
|
+
if (input.extraInputs)
|
|
336
|
+
return input.extraInputs;
|
|
337
|
+
const candidates = await listWalletInputs(sdk, input.wallet);
|
|
338
|
+
const exclude = new Set();
|
|
339
|
+
const rwa = selectInputsForAsset({
|
|
340
|
+
candidates,
|
|
341
|
+
assetId: input.descriptor.outputs.rwaToBuyer.assetId,
|
|
342
|
+
requiredSat: atomicToSafeSat(input.descriptor.outputs.rwaToBuyer.amountAtomic, "delivery.amountAtomic"),
|
|
343
|
+
exclude,
|
|
344
|
+
preferred: input.descriptor.operatorRwaInput?.txid
|
|
345
|
+
? { txid: input.descriptor.operatorRwaInput.txid, vout: input.descriptor.operatorRwaInput.vout }
|
|
346
|
+
: undefined,
|
|
347
|
+
});
|
|
348
|
+
const fee = selectInputsForAsset({
|
|
349
|
+
candidates,
|
|
350
|
+
assetId: await resolveWalletLbtcAssetId(sdk, input.purchase.network),
|
|
351
|
+
requiredSat: input.feeSat ?? input.descriptor.fee.maxFeeSat,
|
|
352
|
+
exclude,
|
|
353
|
+
});
|
|
354
|
+
return [...rwa, ...fee];
|
|
355
|
+
}
|
|
356
|
+
async function resolveRefundExtraInputs(sdk, input) {
|
|
357
|
+
if (input.extraInputs)
|
|
358
|
+
return input.extraInputs;
|
|
359
|
+
const candidates = await listWalletInputs(sdk, input.wallet);
|
|
360
|
+
return selectInputsForAsset({
|
|
361
|
+
candidates,
|
|
362
|
+
assetId: await resolveWalletLbtcAssetId(sdk, input.purchase.network),
|
|
363
|
+
requiredSat: input.feeSat ?? input.descriptor.fee.maxFeeSat,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
async function loadClaimArtifact(sdk, input) {
|
|
367
|
+
if (input.artifact)
|
|
368
|
+
return input.artifact;
|
|
369
|
+
if (input.artifactPath)
|
|
370
|
+
return (await sdk.loadArtifact(input.artifactPath)).artifact;
|
|
371
|
+
throw new errors_1.ValidationError("artifact or artifactPath is required for RWA DvP claim execution");
|
|
372
|
+
}
|
|
373
|
+
function modeToWitnessValue(mode) {
|
|
374
|
+
if (mode === "descriptor-bound")
|
|
375
|
+
return "0x01";
|
|
376
|
+
if (mode === "script-bound")
|
|
377
|
+
return "0x02";
|
|
378
|
+
return "0x03";
|
|
379
|
+
}
|
|
380
|
+
async function resolveClaimOutputBinding(sdk, input) {
|
|
381
|
+
const scriptPubKeyHex = await (0, outputBinding_1.getScriptPubKeyHexViaRpc)(sdk, input.recipientAddress);
|
|
382
|
+
const outputScriptHash = (0, outputBinding_1.hashHexBytes)(scriptPubKeyHex);
|
|
383
|
+
const rawOutput = (0, outputBinding_1.normalizeOutputRawFields)(input.rawOutput);
|
|
384
|
+
const rawOutputAnalysis = (0, outputBinding_1.analyzeOutputRawFields)(rawOutput);
|
|
385
|
+
const outputForm = (0, outputBinding_1.normalizeOutputForm)(input.outputForm);
|
|
386
|
+
let outputHash = ZERO_HASH_256;
|
|
387
|
+
if (input.outputBindingMode === "descriptor-bound") {
|
|
388
|
+
if (rawOutputAnalysis.valid && rawOutputAnalysis.normalized) {
|
|
389
|
+
outputHash = (0, outputBinding_1.computeRawOutputV1Hash)(rawOutputAnalysis.normalized);
|
|
390
|
+
}
|
|
391
|
+
else if ((0, outputBinding_1.isExplicitV1OutputForm)(outputForm)) {
|
|
392
|
+
const assetHex = await (0, outputBinding_1.resolveExplicitAssetHex)(sdk, input.assetId);
|
|
393
|
+
if (!assetHex) {
|
|
394
|
+
throw new errors_1.ValidationError("descriptor-bound output requires a 64-hex asset id or rawOutput fields", {
|
|
395
|
+
assetId: input.assetId,
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
outputHash = (0, outputBinding_1.computeExplicitV1OutputHash)({
|
|
399
|
+
assetHex,
|
|
400
|
+
nextAmountSat: atomicToSafeSat(input.amountAtomic, "output.amountAtomic"),
|
|
401
|
+
nextOutputScriptHash: outputScriptHash,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
throw new errors_1.ValidationError("descriptor-bound output requires explicit-v1 or raw-output-v1 fields");
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
outputHash,
|
|
410
|
+
outputScriptHash: input.outputBindingMode === "none" ? ZERO_HASH_256 : outputScriptHash,
|
|
411
|
+
bindingMode: input.outputBindingMode,
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function claimWitness(input) {
|
|
415
|
+
const values = {
|
|
416
|
+
...(input.base?.values ?? {}),
|
|
417
|
+
DELIVERY_OR_REFUND: {
|
|
418
|
+
type: "Option<u8>",
|
|
419
|
+
value: input.delivery ? "Some(0x01)" : "None",
|
|
420
|
+
},
|
|
421
|
+
PAYMENT_OUTPUT_HASH: {
|
|
422
|
+
type: "u256",
|
|
423
|
+
value: `0x${input.payment?.outputHash ?? ZERO_HASH_256}`,
|
|
424
|
+
},
|
|
425
|
+
PAYMENT_OUTPUT_SCRIPT_HASH: {
|
|
426
|
+
type: "u256",
|
|
427
|
+
value: `0x${input.payment?.outputScriptHash ?? ZERO_HASH_256}`,
|
|
428
|
+
},
|
|
429
|
+
PAYMENT_OUTPUT_BINDING_MODE: {
|
|
430
|
+
type: "u8",
|
|
431
|
+
value: modeToWitnessValue(input.payment?.bindingMode ?? "none"),
|
|
432
|
+
},
|
|
433
|
+
RWA_OUTPUT_HASH: {
|
|
434
|
+
type: "u256",
|
|
435
|
+
value: `0x${input.rwa?.outputHash ?? ZERO_HASH_256}`,
|
|
436
|
+
},
|
|
437
|
+
RWA_OUTPUT_SCRIPT_HASH: {
|
|
438
|
+
type: "u256",
|
|
439
|
+
value: `0x${input.rwa?.outputScriptHash ?? ZERO_HASH_256}`,
|
|
440
|
+
},
|
|
441
|
+
RWA_OUTPUT_BINDING_MODE: {
|
|
442
|
+
type: "u8",
|
|
443
|
+
value: modeToWitnessValue(input.rwa?.bindingMode ?? "none"),
|
|
444
|
+
},
|
|
445
|
+
REFUND_OUTPUT_HASH: {
|
|
446
|
+
type: "u256",
|
|
447
|
+
value: `0x${input.refund?.outputHash ?? ZERO_HASH_256}`,
|
|
448
|
+
},
|
|
449
|
+
REFUND_OUTPUT_SCRIPT_HASH: {
|
|
450
|
+
type: "u256",
|
|
451
|
+
value: `0x${input.refund?.outputScriptHash ?? ZERO_HASH_256}`,
|
|
452
|
+
},
|
|
453
|
+
REFUND_OUTPUT_BINDING_MODE: {
|
|
454
|
+
type: "u8",
|
|
455
|
+
value: modeToWitnessValue(input.refund?.bindingMode ?? "none"),
|
|
456
|
+
},
|
|
457
|
+
};
|
|
458
|
+
return {
|
|
459
|
+
...(input.base?.source ? { source: input.base.source } : {}),
|
|
460
|
+
...(input.base?.signers ? { signers: input.base.signers } : {}),
|
|
461
|
+
values,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function paymentContractInput(descriptor, input) {
|
|
465
|
+
if (descriptor.paymentInput?.txid) {
|
|
466
|
+
return {
|
|
467
|
+
txid: descriptor.paymentInput.txid,
|
|
468
|
+
...(descriptor.paymentInput.vout !== undefined ? { vout: descriptor.paymentInput.vout } : {}),
|
|
469
|
+
asset: descriptor.paymentInput.assetId,
|
|
470
|
+
amountSat: atomicToSafeSat(descriptor.paymentInput.amountAtomic, "paymentInput.amountAtomic"),
|
|
471
|
+
...(input?.contractInputRawTxHex ? { rawTxHex: input.contractInputRawTxHex } : {}),
|
|
472
|
+
...(input?.contractInputBlindingPrivateKey ? { blindingPrivateKey: input.contractInputBlindingPrivateKey } : {}),
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if ("fundingTxid" in descriptor && descriptor.fundingTxid) {
|
|
476
|
+
return { txid: descriptor.fundingTxid };
|
|
477
|
+
}
|
|
478
|
+
return undefined;
|
|
479
|
+
}
|
|
480
|
+
async function buildDeliveryClaimCallInput(sdk, input) {
|
|
481
|
+
const verification = verifyDeliveryClaim(sdk, { purchase: input.purchase, descriptor: input.descriptor });
|
|
482
|
+
if (!verification.ok) {
|
|
483
|
+
throw new errors_1.ValidationError(verification.reason ?? "RWA DvP delivery claim verification failed");
|
|
484
|
+
}
|
|
485
|
+
const artifact = await loadClaimArtifact(sdk, input);
|
|
486
|
+
const payment = input.descriptor.outputs.paymentToTreasury;
|
|
487
|
+
const rwa = input.descriptor.outputs.rwaToBuyer;
|
|
488
|
+
const paymentBinding = await resolveClaimOutputBinding(sdk, {
|
|
489
|
+
recipientAddress: payment.recipientAddress,
|
|
490
|
+
assetId: payment.assetId,
|
|
491
|
+
amountAtomic: payment.amountAtomic,
|
|
492
|
+
outputBindingMode: "script-bound",
|
|
493
|
+
});
|
|
494
|
+
const rwaBinding = await resolveClaimOutputBinding(sdk, {
|
|
495
|
+
recipientAddress: rwa.recipientAddress,
|
|
496
|
+
assetId: rwa.assetId,
|
|
497
|
+
amountAtomic: rwa.amountAtomic,
|
|
498
|
+
outputBindingMode: rwa.outputBindingMode,
|
|
499
|
+
rawOutput: rwa.rawOutput,
|
|
500
|
+
});
|
|
501
|
+
const outputs = [
|
|
502
|
+
{
|
|
503
|
+
address: payment.recipientAddress,
|
|
504
|
+
asset: payment.assetId,
|
|
505
|
+
amountSat: atomicToSafeSat(payment.amountAtomic, "payment.amountAtomic"),
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
address: rwa.recipientAddress,
|
|
509
|
+
asset: rwa.assetId,
|
|
510
|
+
amountSat: atomicToSafeSat(rwa.amountAtomic, "delivery.amountAtomic"),
|
|
511
|
+
},
|
|
512
|
+
];
|
|
513
|
+
const callInput = {
|
|
514
|
+
wallet: input.wallet,
|
|
515
|
+
signer: input.signer,
|
|
516
|
+
contractInput: paymentContractInput(input.descriptor, input),
|
|
517
|
+
extraInputs: await resolveDeliveryExtraInputs(sdk, input),
|
|
518
|
+
outputs,
|
|
519
|
+
feeSat: input.feeSat ?? input.descriptor.fee.maxFeeSat,
|
|
520
|
+
...(input.changeAddress ? { changeAddress: input.changeAddress } : {}),
|
|
521
|
+
purpose: "rwa_dvp_delivery_claim",
|
|
522
|
+
locktimeHeight: input.locktimeHeight ?? 0,
|
|
523
|
+
witness: claimWitness({
|
|
524
|
+
base: input.witness,
|
|
525
|
+
delivery: true,
|
|
526
|
+
payment: paymentBinding,
|
|
527
|
+
rwa: rwaBinding,
|
|
528
|
+
}),
|
|
529
|
+
};
|
|
530
|
+
return {
|
|
531
|
+
artifact,
|
|
532
|
+
verification,
|
|
533
|
+
outputBinding: {
|
|
534
|
+
paymentToTreasury: paymentBinding,
|
|
535
|
+
rwaToBuyer: rwaBinding,
|
|
536
|
+
},
|
|
537
|
+
callInput,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
async function buildRefundClaimCallInput(sdk, input) {
|
|
541
|
+
const verification = verifyRefundClaim(sdk, { purchase: input.purchase, descriptor: input.descriptor });
|
|
542
|
+
if (!verification.ok) {
|
|
543
|
+
throw new errors_1.ValidationError(verification.reason ?? "RWA DvP refund claim verification failed");
|
|
544
|
+
}
|
|
545
|
+
const artifact = await loadClaimArtifact(sdk, input);
|
|
546
|
+
const refund = input.descriptor.refundOutput;
|
|
547
|
+
const refundBinding = await resolveClaimOutputBinding(sdk, {
|
|
548
|
+
recipientAddress: refund.recipientAddress,
|
|
549
|
+
assetId: refund.assetId,
|
|
550
|
+
amountAtomic: refund.amountAtomic,
|
|
551
|
+
outputBindingMode: "script-bound",
|
|
552
|
+
});
|
|
553
|
+
const callInput = {
|
|
554
|
+
wallet: input.wallet,
|
|
555
|
+
signer: input.signer,
|
|
556
|
+
contractInput: paymentContractInput(input.descriptor, input),
|
|
557
|
+
extraInputs: await resolveRefundExtraInputs(sdk, input),
|
|
558
|
+
outputs: [
|
|
559
|
+
{
|
|
560
|
+
address: refund.recipientAddress,
|
|
561
|
+
asset: refund.assetId,
|
|
562
|
+
amountSat: atomicToSafeSat(refund.amountAtomic, "refund.amountAtomic"),
|
|
563
|
+
},
|
|
564
|
+
],
|
|
565
|
+
feeSat: input.feeSat ?? input.descriptor.fee.maxFeeSat,
|
|
566
|
+
...(input.changeAddress ? { changeAddress: input.changeAddress } : {}),
|
|
567
|
+
purpose: "rwa_dvp_refund_claim",
|
|
568
|
+
...(input.locktimeHeight !== undefined ? { locktimeHeight: input.locktimeHeight } : {}),
|
|
569
|
+
witness: claimWitness({
|
|
570
|
+
base: input.witness,
|
|
571
|
+
delivery: false,
|
|
572
|
+
refund: refundBinding,
|
|
573
|
+
}),
|
|
574
|
+
};
|
|
575
|
+
return {
|
|
576
|
+
artifact,
|
|
577
|
+
verification,
|
|
578
|
+
outputBinding: {
|
|
579
|
+
refund: refundBinding,
|
|
580
|
+
},
|
|
581
|
+
callInput,
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
async function compileEscrowContract(sdk, input) {
|
|
585
|
+
if (!Number.isInteger(input.timeoutHeight) || input.timeoutHeight < 0) {
|
|
586
|
+
throw new errors_1.ValidationError("timeoutHeight must be a non-negative integer");
|
|
587
|
+
}
|
|
588
|
+
const termsHash = summarizePurchase(input.purchase).hash;
|
|
589
|
+
const policyHash = summarizePolicy(input.purchase).hash;
|
|
590
|
+
const compiled = await sdk.compileFromFile({
|
|
591
|
+
simfPath: input.simfPath ?? resolveRwaDvpDocsAsset("rwa-dvp-escrow.simf"),
|
|
592
|
+
templateVars: {
|
|
593
|
+
TERMS_HASH: termsHash,
|
|
594
|
+
POLICY_HASH: policyHash,
|
|
595
|
+
OPERATOR_XONLY: assertXonly(input.operatorXonly, "operatorXonly"),
|
|
596
|
+
TIMEOUT_HEIGHT: input.timeoutHeight,
|
|
597
|
+
},
|
|
598
|
+
});
|
|
599
|
+
return {
|
|
600
|
+
compiled,
|
|
601
|
+
artifact: compiled.artifact,
|
|
602
|
+
contractAddress: compiled.deployment().contractAddress,
|
|
603
|
+
timeoutHeight: input.timeoutHeight,
|
|
604
|
+
termsHash,
|
|
605
|
+
policyHash,
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
async function inspectDeliveryClaim(sdk, input) {
|
|
609
|
+
const prepared = await buildDeliveryClaimCallInput(sdk, input);
|
|
610
|
+
const inspect = await (0, executor_1.inspectMultiAssetContractCall)(sdk.config, prepared.artifact, prepared.callInput);
|
|
611
|
+
return {
|
|
612
|
+
descriptor: input.descriptor,
|
|
613
|
+
verification: prepared.verification,
|
|
614
|
+
outputBinding: prepared.outputBinding,
|
|
615
|
+
inspect,
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
async function executeDeliveryClaim(sdk, input) {
|
|
619
|
+
const prepared = await buildDeliveryClaimCallInput(sdk, input);
|
|
620
|
+
const execution = await (0, executor_1.executeMultiAssetContractCall)(sdk.config, prepared.artifact, {
|
|
621
|
+
...prepared.callInput,
|
|
622
|
+
broadcast: input.broadcast,
|
|
623
|
+
});
|
|
624
|
+
return {
|
|
625
|
+
descriptor: input.descriptor,
|
|
626
|
+
verification: prepared.verification,
|
|
627
|
+
outputBinding: prepared.outputBinding,
|
|
628
|
+
execution,
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
async function inspectRefundClaim(sdk, input) {
|
|
632
|
+
const prepared = await buildRefundClaimCallInput(sdk, input);
|
|
633
|
+
const inspect = await (0, executor_1.inspectMultiAssetContractCall)(sdk.config, prepared.artifact, prepared.callInput);
|
|
634
|
+
return {
|
|
635
|
+
descriptor: input.descriptor,
|
|
636
|
+
verification: prepared.verification,
|
|
637
|
+
outputBinding: prepared.outputBinding,
|
|
638
|
+
inspect,
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
async function executeRefundClaim(sdk, input) {
|
|
642
|
+
const prepared = await buildRefundClaimCallInput(sdk, input);
|
|
643
|
+
const execution = await (0, executor_1.executeMultiAssetContractCall)(sdk.config, prepared.artifact, {
|
|
644
|
+
...prepared.callInput,
|
|
645
|
+
broadcast: input.broadcast,
|
|
646
|
+
});
|
|
647
|
+
return {
|
|
648
|
+
descriptor: input.descriptor,
|
|
649
|
+
verification: prepared.verification,
|
|
650
|
+
outputBinding: prepared.outputBinding,
|
|
651
|
+
execution,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
227
654
|
function exportEvidence(_sdk, input) {
|
|
228
655
|
return {
|
|
229
656
|
schemaVersion: exports.RWA_DVP_EVIDENCE_SCHEMA_VERSION,
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,6 @@ export { validateBondDefinition, validateBondIssuanceState, validateBondCrossChe
|
|
|
18
18
|
export { summarizeBondSettlementDescriptor, validateBondSettlementDescriptor, validateBondSettlementMatchesExpected, } from "./domain/bondSettlementValidation";
|
|
19
19
|
export { summarizeFundDefinition, summarizeCapitalCallState, summarizeLPPositionReceipt, summarizeDistributionDescriptor, summarizeFundClosingDescriptor, summarizeFundFinalityPayload, validateFundDefinition, validateCapitalCallState, validateLPPositionReceipt, validateDistributionDescriptor, validateFundClosingDescriptor, validateFundCrossChecks, validateDistributionAgainstReceipt, validateClosingAgainstReceipt, buildClaimedCapitalCallState, buildRefundedCapitalCallState, buildLPPositionReceipt, applyDistributionToReceipt, applyDistributionsToReceipt, buildDistributionDescriptor, buildFundClosingDescriptor, } from "./domain/fundValidation";
|
|
20
20
|
export { applyReceivableRepayment, buildDefaultedReceivableState, buildFundedReceivableState, buildReceivableClosingDescriptor, buildReceivableFundingClaimDescriptor, buildReceivableRepaymentClaimDescriptor, summarizeReceivableClosingDescriptor, summarizeReceivableDefinition, summarizeReceivableFundingClaimDescriptor, summarizeReceivableRepaymentClaimDescriptor, summarizeReceivableState, validateReceivableClosingAgainstState, validateReceivableClosingDescriptor, validateReceivableDefinition, validateReceivableFundingClaimAgainstState, validateReceivableFundingClaimDescriptor, validateReceivableRepaymentClaimAgainstState, validateReceivableRepaymentClaimDescriptor, validateReceivableState, validateReceivableCrossChecks, validateReceivableFundingTransition, validateReceivableRepaymentTransition, validateReceivableWriteOffTransition, verifyReceivableStateHistory as verifyReceivableStateHistoryValidation, } from "./domain/receivableValidation";
|
|
21
|
-
export { RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION, RWA_DVP_EVIDENCE_SCHEMA_VERSION, RWA_DVP_PURCHASE_SCHEMA_VERSION, RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION, RWA_DVP_VERIFICATION_SCHEMA_VERSION, buildPaymentRequirements as buildRwaDvpPaymentRequirements, definePurchase as defineRwaDvpPurchase, exportEvidence as exportRwaDvpEvidence, prepareDeliveryClaim as prepareRwaDvpDeliveryClaim, prepareRefundClaim as prepareRwaDvpRefundClaim, summarizePurchase as summarizeRwaDvpPurchase, verifyDeliveryClaim as verifyRwaDvpDeliveryClaim, verifyPaymentPset as verifyRwaDvpPaymentPset, verifyRefundClaim as verifyRwaDvpRefundClaim, } from "./domain/rwaDvp";
|
|
22
|
-
export type { RwaDvpDefinePurchaseInput, RwaDvpDeliveryClaimDescriptor, RwaDvpEvidenceBundle, RwaDvpEvmLockReference, RwaDvpPaymentAsset, RwaDvpPreparedPurchase, RwaDvpPrepareDeliveryClaimInput, RwaDvpPrepareRefundClaimInput, RwaDvpPurchaseDefinition, RwaDvpRefundClaimDescriptor, RwaDvpSummary, RwaDvpVerificationReport, } from "./domain/rwaDvp";
|
|
21
|
+
export { RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION, RWA_DVP_EVIDENCE_SCHEMA_VERSION, RWA_DVP_PURCHASE_SCHEMA_VERSION, RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION, RWA_DVP_VERIFICATION_SCHEMA_VERSION, buildPaymentRequirements as buildRwaDvpPaymentRequirements, compileEscrowContract as compileRwaDvpEscrowContract, definePurchase as defineRwaDvpPurchase, executeDeliveryClaim as executeRwaDvpDeliveryClaim, executeRefundClaim as executeRwaDvpRefundClaim, exportEvidence as exportRwaDvpEvidence, inspectDeliveryClaim as inspectRwaDvpDeliveryClaim, inspectRefundClaim as inspectRwaDvpRefundClaim, prepareDeliveryClaim as prepareRwaDvpDeliveryClaim, prepareRefundClaim as prepareRwaDvpRefundClaim, summarizePurchase as summarizeRwaDvpPurchase, verifyDeliveryClaim as verifyRwaDvpDeliveryClaim, verifyPaymentPset as verifyRwaDvpPaymentPset, verifyRefundClaim as verifyRwaDvpRefundClaim, } from "./domain/rwaDvp";
|
|
22
|
+
export type { RwaDvpDefinePurchaseInput, RwaDvpClaimOutputBinding, RwaDvpCompiledEscrowContract, RwaDvpCompileEscrowContractInput, RwaDvpDeliveryClaimDescriptor, RwaDvpDeliveryClaimExecution, RwaDvpDeliveryClaimInspection, RwaDvpEvidenceBundle, RwaDvpEvmLockReference, RwaDvpEvmTokenStandard, RwaDvpExecuteDeliveryClaimInput, RwaDvpExecuteRefundClaimInput, RwaDvpInspectDeliveryClaimInput, RwaDvpInspectRefundClaimInput, RwaDvpPaymentAsset, RwaDvpPreparedPurchase, RwaDvpPrepareDeliveryClaimInput, RwaDvpPrepareRefundClaimInput, RwaDvpPurchaseDefinition, RwaDvpRefundClaimDescriptor, RwaDvpRefundClaimExecution, RwaDvpRefundClaimInspection, RwaDvpSummary, RwaDvpVerificationReport, } from "./domain/rwaDvp";
|
|
23
23
|
export { compilePolicyStateContract, buildPolicyOutputDescriptor, listPolicyTemplates, loadPolicyTemplateManifest, validatePolicyTemplateManifest, describePolicyTemplate, validatePolicyTemplateParams, issue, prepareTransfer, executeTransfer, inspectTransfer, verifyState, verifyTransfer, exportEvidence as exportPolicyEvidence, summarizePolicyState, summarizePolicyOutputDescriptor, summarizePolicyTransferDescriptor, validatePolicyState, validatePolicyOutputDescriptor, validatePolicyTransferDescriptor, } from "./domain/policies";
|
package/dist/index.js
CHANGED
|
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.signPositionReceipt = exports.verifyCapitalCall = exports.executeCapitalCallRefund = exports.inspectCapitalCallRefund = exports.executeCapitalCallRollover = exports.inspectCapitalCallRollover = exports.executeCapitalCallClaim = exports.inspectCapitalCallClaim = exports.prepareCapitalCall = exports.loadFund = exports.verifyFund = exports.defineFund = exports.exportFinalityPayload = exports.exportBondEvidence = exports.verifyClosing = exports.executeClosing = exports.inspectClosing = exports.prepareClosing = exports.verifySettlement = exports.buildSettlement = exports.verifyRedemption = exports.executeRedemption = exports.inspectRedemption = exports.prepareRedemption = exports.issueBond = exports.loadBond = exports.verifyIssuanceHistory = exports.verifyBond = exports.defineBond = exports.verifyStateDescriptorAgainstArtifact = exports.verifyStateAgainstArtifact = exports.buildArtifactStateMetadata = exports.loadStateInput = exports.verifyDefinitionDescriptorAgainstArtifact = exports.verifyDefinitionAgainstArtifact = exports.buildArtifactDefinitionMetadata = exports.loadDefinitionInput = exports.evaluateOutputBindingSupport = exports.describeOutputBindingSupport = exports.normalizeArtifact = exports.saveArtifact = exports.loadArtifact = exports.getPresetOrThrow = exports.listPresets = exports.ElementsRpcClient = exports.RelayerClient = exports.DeployedContract = exports.CompiledContract = exports.SimplicityClient = exports.createSimplicityClient = void 0;
|
|
18
18
|
exports.validateFundDefinition = exports.summarizeFundFinalityPayload = exports.summarizeFundClosingDescriptor = exports.summarizeDistributionDescriptor = exports.summarizeLPPositionReceipt = exports.summarizeCapitalCallState = exports.summarizeFundDefinition = exports.validateBondSettlementMatchesExpected = exports.validateBondSettlementDescriptor = exports.summarizeBondSettlementDescriptor = exports.verifyBondIssuanceHistory = exports.summarizeBondIssuanceState = exports.buildRedeemedBondIssuanceState = exports.validateBondStateTransition = exports.validateBondCrossChecks = exports.validateBondIssuanceState = exports.validateBondDefinition = exports.exportReceivableFinalityPayload = exports.exportReceivableEvidence = exports.verifyReceivableStateHistory = exports.verifyReceivableClosing = exports.prepareReceivableClosing = exports.verifyReceivableWriteOff = exports.prepareReceivableWriteOff = exports.verifyReceivableRepaymentClaim = exports.executeReceivableRepaymentClaim = exports.inspectReceivableRepaymentClaim = exports.prepareReceivableRepaymentClaim = exports.verifyReceivableRepayment = exports.prepareReceivableRepayment = exports.verifyReceivableFundingClaim = exports.executeReceivableFundingClaim = exports.inspectReceivableFundingClaim = exports.prepareReceivableFundingClaim = exports.verifyReceivableFunding = exports.prepareReceivableFunding = exports.loadReceivable = exports.verifyReceivable = exports.defineReceivable = exports.exportFundFinalityPayload = exports.exportFundEvidence = exports.verifyFundClosing = exports.prepareFundClosing = exports.verifyDistribution = exports.executeDistributionClaim = exports.inspectDistributionClaim = exports.reconcilePosition = exports.prepareDistribution = exports.verifyPositionReceiptChain = exports.verifyPositionReceipt = void 0;
|
|
19
|
-
exports.
|
|
20
|
-
exports.validatePolicyTransferDescriptor = exports.validatePolicyOutputDescriptor = exports.validatePolicyState = exports.summarizePolicyTransferDescriptor = exports.summarizePolicyOutputDescriptor = exports.summarizePolicyState = exports.exportPolicyEvidence = exports.verifyTransfer = exports.verifyState = exports.inspectTransfer = exports.executeTransfer = exports.prepareTransfer = exports.issue = exports.validatePolicyTemplateParams = exports.describePolicyTemplate = exports.validatePolicyTemplateManifest = exports.loadPolicyTemplateManifest = exports.listPolicyTemplates = exports.buildPolicyOutputDescriptor = exports.compilePolicyStateContract = exports.verifyRwaDvpRefundClaim = exports.verifyRwaDvpPaymentPset = void 0;
|
|
19
|
+
exports.inspectRwaDvpDeliveryClaim = exports.exportRwaDvpEvidence = exports.executeRwaDvpRefundClaim = exports.executeRwaDvpDeliveryClaim = exports.defineRwaDvpPurchase = exports.compileRwaDvpEscrowContract = exports.buildRwaDvpPaymentRequirements = exports.RWA_DVP_VERIFICATION_SCHEMA_VERSION = exports.RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION = exports.RWA_DVP_PURCHASE_SCHEMA_VERSION = exports.RWA_DVP_EVIDENCE_SCHEMA_VERSION = exports.RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION = exports.verifyReceivableStateHistoryValidation = exports.validateReceivableWriteOffTransition = exports.validateReceivableRepaymentTransition = exports.validateReceivableFundingTransition = exports.validateReceivableCrossChecks = exports.validateReceivableState = exports.validateReceivableRepaymentClaimDescriptor = exports.validateReceivableRepaymentClaimAgainstState = exports.validateReceivableFundingClaimDescriptor = exports.validateReceivableFundingClaimAgainstState = exports.validateReceivableDefinition = exports.validateReceivableClosingDescriptor = exports.validateReceivableClosingAgainstState = exports.summarizeReceivableState = exports.summarizeReceivableRepaymentClaimDescriptor = exports.summarizeReceivableFundingClaimDescriptor = exports.summarizeReceivableDefinition = exports.summarizeReceivableClosingDescriptor = exports.buildReceivableRepaymentClaimDescriptor = exports.buildReceivableFundingClaimDescriptor = exports.buildReceivableClosingDescriptor = exports.buildFundedReceivableState = exports.buildDefaultedReceivableState = exports.applyReceivableRepayment = exports.buildFundClosingDescriptor = exports.buildDistributionDescriptor = exports.applyDistributionsToReceipt = exports.applyDistributionToReceipt = exports.buildLPPositionReceipt = exports.buildRefundedCapitalCallState = exports.buildClaimedCapitalCallState = exports.validateClosingAgainstReceipt = exports.validateDistributionAgainstReceipt = exports.validateFundCrossChecks = exports.validateFundClosingDescriptor = exports.validateDistributionDescriptor = exports.validateLPPositionReceipt = exports.validateCapitalCallState = void 0;
|
|
20
|
+
exports.validatePolicyTransferDescriptor = exports.validatePolicyOutputDescriptor = exports.validatePolicyState = exports.summarizePolicyTransferDescriptor = exports.summarizePolicyOutputDescriptor = exports.summarizePolicyState = exports.exportPolicyEvidence = exports.verifyTransfer = exports.verifyState = exports.inspectTransfer = exports.executeTransfer = exports.prepareTransfer = exports.issue = exports.validatePolicyTemplateParams = exports.describePolicyTemplate = exports.validatePolicyTemplateManifest = exports.loadPolicyTemplateManifest = exports.listPolicyTemplates = exports.buildPolicyOutputDescriptor = exports.compilePolicyStateContract = exports.verifyRwaDvpRefundClaim = exports.verifyRwaDvpPaymentPset = exports.verifyRwaDvpDeliveryClaim = exports.summarizeRwaDvpPurchase = exports.prepareRwaDvpRefundClaim = exports.prepareRwaDvpDeliveryClaim = exports.inspectRwaDvpRefundClaim = void 0;
|
|
21
21
|
var SimplicityClient_1 = require("./client/SimplicityClient");
|
|
22
22
|
Object.defineProperty(exports, "createSimplicityClient", { enumerable: true, get: function () { return SimplicityClient_1.createSimplicityClient; } });
|
|
23
23
|
Object.defineProperty(exports, "SimplicityClient", { enumerable: true, get: function () { return SimplicityClient_1.SimplicityClient; } });
|
|
@@ -183,8 +183,13 @@ Object.defineProperty(exports, "RWA_DVP_PURCHASE_SCHEMA_VERSION", { enumerable:
|
|
|
183
183
|
Object.defineProperty(exports, "RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION", { enumerable: true, get: function () { return rwaDvp_1.RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION; } });
|
|
184
184
|
Object.defineProperty(exports, "RWA_DVP_VERIFICATION_SCHEMA_VERSION", { enumerable: true, get: function () { return rwaDvp_1.RWA_DVP_VERIFICATION_SCHEMA_VERSION; } });
|
|
185
185
|
Object.defineProperty(exports, "buildRwaDvpPaymentRequirements", { enumerable: true, get: function () { return rwaDvp_1.buildPaymentRequirements; } });
|
|
186
|
+
Object.defineProperty(exports, "compileRwaDvpEscrowContract", { enumerable: true, get: function () { return rwaDvp_1.compileEscrowContract; } });
|
|
186
187
|
Object.defineProperty(exports, "defineRwaDvpPurchase", { enumerable: true, get: function () { return rwaDvp_1.definePurchase; } });
|
|
188
|
+
Object.defineProperty(exports, "executeRwaDvpDeliveryClaim", { enumerable: true, get: function () { return rwaDvp_1.executeDeliveryClaim; } });
|
|
189
|
+
Object.defineProperty(exports, "executeRwaDvpRefundClaim", { enumerable: true, get: function () { return rwaDvp_1.executeRefundClaim; } });
|
|
187
190
|
Object.defineProperty(exports, "exportRwaDvpEvidence", { enumerable: true, get: function () { return rwaDvp_1.exportEvidence; } });
|
|
191
|
+
Object.defineProperty(exports, "inspectRwaDvpDeliveryClaim", { enumerable: true, get: function () { return rwaDvp_1.inspectDeliveryClaim; } });
|
|
192
|
+
Object.defineProperty(exports, "inspectRwaDvpRefundClaim", { enumerable: true, get: function () { return rwaDvp_1.inspectRefundClaim; } });
|
|
188
193
|
Object.defineProperty(exports, "prepareRwaDvpDeliveryClaim", { enumerable: true, get: function () { return rwaDvp_1.prepareDeliveryClaim; } });
|
|
189
194
|
Object.defineProperty(exports, "prepareRwaDvpRefundClaim", { enumerable: true, get: function () { return rwaDvp_1.prepareRefundClaim; } });
|
|
190
195
|
Object.defineProperty(exports, "summarizeRwaDvpPurchase", { enumerable: true, get: function () { return rwaDvp_1.summarizePurchase; } });
|