@hazbase/simplicity 0.3.2 → 0.4.1
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 +12 -0
- package/dist/client/SimplicityClient.d.ts +11 -0
- package/dist/client/SimplicityClient.js +12 -0
- package/dist/domain/rwaDvp.d.ts +244 -0
- package/dist/domain/rwaDvp.js +309 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +17 -2
- package/dist/x402/index.d.ts +1 -0
- package/dist/x402/index.js +16 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -152,6 +152,18 @@ Main entrypoints:
|
|
|
152
152
|
Representative example:
|
|
153
153
|
- [show-receivable-business-flow.ts](./examples/show-receivable-business-flow.ts)
|
|
154
154
|
|
|
155
|
+
### RWA DvP and Liquid x402
|
|
156
|
+
|
|
157
|
+
Use `sdk.rwaDvp` when a purchase flow needs a Liquid PSET payment request,
|
|
158
|
+
delivery/refund claim descriptors, and an evidence bundle that ties the Liquid
|
|
159
|
+
payment and delivery to an external lock or allocation record.
|
|
160
|
+
|
|
161
|
+
For standard Liquid assets, `payment.asset` can be `"lbtc"` or `"usdt"`. If a
|
|
162
|
+
testnet issuer or deployment uses a different USDt asset id, set
|
|
163
|
+
`payment.asset: "usdt"` and pass the explicit `payment.assetId`; the generated
|
|
164
|
+
payment requirements will preserve that asset id instead of replacing it with
|
|
165
|
+
the SDK's default registry id.
|
|
166
|
+
|
|
155
167
|
## CLI and Confidence Commands
|
|
156
168
|
|
|
157
169
|
### Validation Surface
|
|
@@ -4,6 +4,7 @@ import { BondEvidenceBundle, OutputBindingSupportEvaluation, OutputBindingSuppor
|
|
|
4
4
|
import { RelayerClient } from "../gasless/RelayerClient";
|
|
5
5
|
import { GaslessTransferInput, GaslessTransferResult, RelayerClientConfig } from "../gasless/types";
|
|
6
6
|
import * as liquidX402 from "../x402";
|
|
7
|
+
import * as rwaDvp from "../domain/rwaDvp";
|
|
7
8
|
import { CompiledContract } from "./ContractFactory";
|
|
8
9
|
import { DeployedContract } from "./DeployedContract";
|
|
9
10
|
import { prepareRedemption, prepareClosing, exportFinalityPayload, buildSettlement, verifySettlement, define, executeClosing, executeRedemption, exportEvidence, inspectClosing, inspectRedemption, issue, load, verify, verifyIssuanceHistory, verifyClosing, verifyRedemption } from "../domain/bond";
|
|
@@ -33,6 +34,16 @@ export declare class SimplicityClient {
|
|
|
33
34
|
describeSupport: () => OutputBindingSupportMatrix;
|
|
34
35
|
evaluateSupport: (input: Parameters<typeof evaluateOutputBindingSupport>[0]) => OutputBindingSupportEvaluation;
|
|
35
36
|
};
|
|
37
|
+
readonly rwaDvp: {
|
|
38
|
+
definePurchase: (input: Parameters<typeof rwaDvp.definePurchase>[1]) => ReturnType<typeof rwaDvp.definePurchase>;
|
|
39
|
+
buildPaymentRequirements: (input: Parameters<typeof rwaDvp.buildPaymentRequirements>[1]) => ReturnType<typeof rwaDvp.buildPaymentRequirements>;
|
|
40
|
+
verifyPaymentPset: (input: Parameters<typeof rwaDvp.verifyPaymentPset>[1]) => ReturnType<typeof rwaDvp.verifyPaymentPset>;
|
|
41
|
+
prepareDeliveryClaim: (input: Parameters<typeof rwaDvp.prepareDeliveryClaim>[1]) => ReturnType<typeof rwaDvp.prepareDeliveryClaim>;
|
|
42
|
+
verifyDeliveryClaim: (input: Parameters<typeof rwaDvp.verifyDeliveryClaim>[1]) => ReturnType<typeof rwaDvp.verifyDeliveryClaim>;
|
|
43
|
+
prepareRefundClaim: (input: Parameters<typeof rwaDvp.prepareRefundClaim>[1]) => ReturnType<typeof rwaDvp.prepareRefundClaim>;
|
|
44
|
+
verifyRefundClaim: (input: Parameters<typeof rwaDvp.verifyRefundClaim>[1]) => ReturnType<typeof rwaDvp.verifyRefundClaim>;
|
|
45
|
+
exportEvidence: (input: Parameters<typeof rwaDvp.exportEvidence>[1]) => ReturnType<typeof rwaDvp.exportEvidence>;
|
|
46
|
+
};
|
|
36
47
|
readonly policies: {
|
|
37
48
|
listTemplates: () => ReturnType<typeof listPolicyTemplates>;
|
|
38
49
|
describeTemplate: (input: Parameters<typeof describePolicyTemplate>[0]) => ReturnType<typeof describePolicyTemplate>;
|
|
@@ -44,6 +44,7 @@ const outputBinding_1 = require("../core/outputBinding");
|
|
|
44
44
|
const rpc_1 = require("../core/rpc");
|
|
45
45
|
const RelayerClient_1 = require("../gasless/RelayerClient");
|
|
46
46
|
const liquidX402 = __importStar(require("../x402"));
|
|
47
|
+
const rwaDvp = __importStar(require("../domain/rwaDvp"));
|
|
47
48
|
const ContractFactory_1 = require("./ContractFactory");
|
|
48
49
|
const DeployedContract_1 = require("./DeployedContract");
|
|
49
50
|
const bond_1 = require("../domain/bond");
|
|
@@ -55,6 +56,7 @@ class SimplicityClient {
|
|
|
55
56
|
rpc;
|
|
56
57
|
payments;
|
|
57
58
|
outputBinding;
|
|
59
|
+
rwaDvp;
|
|
58
60
|
policies;
|
|
59
61
|
bonds;
|
|
60
62
|
funds;
|
|
@@ -82,6 +84,16 @@ class SimplicityClient {
|
|
|
82
84
|
describeSupport: () => (0, outputBinding_1.describeOutputBindingSupport)(),
|
|
83
85
|
evaluateSupport: (input) => (0, outputBinding_1.evaluateOutputBindingSupport)(input),
|
|
84
86
|
};
|
|
87
|
+
this.rwaDvp = {
|
|
88
|
+
definePurchase: (input) => rwaDvp.definePurchase(this, input),
|
|
89
|
+
buildPaymentRequirements: (input) => rwaDvp.buildPaymentRequirements(this, input),
|
|
90
|
+
verifyPaymentPset: (input) => rwaDvp.verifyPaymentPset(this, input),
|
|
91
|
+
prepareDeliveryClaim: (input) => rwaDvp.prepareDeliveryClaim(this, input),
|
|
92
|
+
verifyDeliveryClaim: (input) => rwaDvp.verifyDeliveryClaim(this, input),
|
|
93
|
+
prepareRefundClaim: (input) => rwaDvp.prepareRefundClaim(this, input),
|
|
94
|
+
verifyRefundClaim: (input) => rwaDvp.verifyRefundClaim(this, input),
|
|
95
|
+
exportEvidence: (input) => rwaDvp.exportEvidence(this, input),
|
|
96
|
+
};
|
|
85
97
|
this.policies = {
|
|
86
98
|
listTemplates: () => (0, policies_1.listPolicyTemplates)(),
|
|
87
99
|
describeTemplate: (input) => (0, policies_1.describePolicyTemplate)(input),
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import type { SimplicityClient } from "../client/SimplicityClient";
|
|
2
|
+
import type { BondOutputBindingMode, OutputRawFields } from "../core/types";
|
|
3
|
+
import { type LiquidX402AssetKey, type LiquidX402Network, type LiquidX402PaymentPayload, type LiquidX402PaymentRequirements, type LiquidX402VerifyPaymentResult } from "../x402";
|
|
4
|
+
export declare const RWA_DVP_PURCHASE_SCHEMA_VERSION: "rwa-dvp-purchase/v1";
|
|
5
|
+
export declare const RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION: "rwa-dvp-delivery-claim/v1";
|
|
6
|
+
export declare const RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION: "rwa-dvp-refund-claim/v1";
|
|
7
|
+
export declare const RWA_DVP_VERIFICATION_SCHEMA_VERSION: "rwa-dvp-verification/v1";
|
|
8
|
+
export declare const RWA_DVP_EVIDENCE_SCHEMA_VERSION: "rwa-dvp-evidence/v1";
|
|
9
|
+
export type RwaDvpPaymentAsset = LiquidX402AssetKey;
|
|
10
|
+
export interface RwaDvpEvmLockReference {
|
|
11
|
+
chainId: number;
|
|
12
|
+
lockManager: string;
|
|
13
|
+
orderKey: string;
|
|
14
|
+
token?: string;
|
|
15
|
+
backingOwner?: string;
|
|
16
|
+
classId?: string;
|
|
17
|
+
nonceId?: string;
|
|
18
|
+
amountAtomic: string;
|
|
19
|
+
termsHash?: string;
|
|
20
|
+
lockTxHash?: string;
|
|
21
|
+
consumeTxHash?: string;
|
|
22
|
+
releaseTxHash?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface RwaDvpPurchaseDefinition {
|
|
25
|
+
schemaVersion: typeof RWA_DVP_PURCHASE_SCHEMA_VERSION;
|
|
26
|
+
purchaseId: string;
|
|
27
|
+
network: LiquidX402Network;
|
|
28
|
+
evmLock: RwaDvpEvmLockReference;
|
|
29
|
+
payment: {
|
|
30
|
+
asset: RwaDvpPaymentAsset;
|
|
31
|
+
assetId: string;
|
|
32
|
+
amountAtomic: string;
|
|
33
|
+
escrowAddress: string;
|
|
34
|
+
treasuryAddress: string;
|
|
35
|
+
};
|
|
36
|
+
delivery: {
|
|
37
|
+
assetId: string;
|
|
38
|
+
amountAtomic: string;
|
|
39
|
+
recipientAddress: string;
|
|
40
|
+
};
|
|
41
|
+
refund: {
|
|
42
|
+
recipientAddress: string;
|
|
43
|
+
after: string;
|
|
44
|
+
};
|
|
45
|
+
expiresAt: string;
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
export interface RwaDvpDefinePurchaseInput {
|
|
49
|
+
purchaseId: string;
|
|
50
|
+
network?: LiquidX402Network;
|
|
51
|
+
evmLock: RwaDvpEvmLockReference;
|
|
52
|
+
payment: {
|
|
53
|
+
asset: RwaDvpPaymentAsset;
|
|
54
|
+
assetId?: string;
|
|
55
|
+
amountAtomic: string | number | bigint;
|
|
56
|
+
escrowAddress: string;
|
|
57
|
+
treasuryAddress?: string;
|
|
58
|
+
};
|
|
59
|
+
delivery: {
|
|
60
|
+
assetId: string;
|
|
61
|
+
amountAtomic: string | number | bigint;
|
|
62
|
+
recipientAddress: string;
|
|
63
|
+
};
|
|
64
|
+
refund: {
|
|
65
|
+
recipientAddress: string;
|
|
66
|
+
after: string | Date;
|
|
67
|
+
};
|
|
68
|
+
expiresAt: string | Date;
|
|
69
|
+
metadata?: Record<string, unknown>;
|
|
70
|
+
}
|
|
71
|
+
export interface RwaDvpSummary {
|
|
72
|
+
canonicalJson: string;
|
|
73
|
+
hash: string;
|
|
74
|
+
}
|
|
75
|
+
export interface RwaDvpPreparedPurchase {
|
|
76
|
+
definition: RwaDvpPurchaseDefinition;
|
|
77
|
+
summary: RwaDvpSummary;
|
|
78
|
+
termsHash: string;
|
|
79
|
+
policyHash: string;
|
|
80
|
+
}
|
|
81
|
+
export interface RwaDvpBuildPaymentRequirementsInput {
|
|
82
|
+
purchase: RwaDvpPurchaseDefinition;
|
|
83
|
+
resource: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
mimeType?: string;
|
|
86
|
+
maxTimeoutSeconds?: number;
|
|
87
|
+
maxFeeSat?: string | number | bigint;
|
|
88
|
+
metadata?: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
export interface RwaDvpVerifyPaymentPsetInput {
|
|
91
|
+
purchase: RwaDvpPurchaseDefinition;
|
|
92
|
+
requirements: LiquidX402PaymentRequirements | Record<string, unknown>;
|
|
93
|
+
paymentPayload: LiquidX402PaymentPayload | Record<string, unknown>;
|
|
94
|
+
now?: Date;
|
|
95
|
+
verifyPsetOutputs?: boolean;
|
|
96
|
+
}
|
|
97
|
+
export interface RwaDvpDeliveryClaimDescriptor {
|
|
98
|
+
schemaVersion: typeof RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION;
|
|
99
|
+
purchaseId: string;
|
|
100
|
+
network: LiquidX402Network;
|
|
101
|
+
termsHash: string;
|
|
102
|
+
policyHash: string;
|
|
103
|
+
mode: "simplicity-multi-asset-claim" | "operator-wallet-delivery-bridge";
|
|
104
|
+
paymentInput?: {
|
|
105
|
+
txid: string;
|
|
106
|
+
vout?: number;
|
|
107
|
+
assetId: string;
|
|
108
|
+
amountAtomic: string;
|
|
109
|
+
};
|
|
110
|
+
operatorRwaInput?: {
|
|
111
|
+
txid?: string;
|
|
112
|
+
vout?: number;
|
|
113
|
+
assetId: string;
|
|
114
|
+
amountAtomic: string;
|
|
115
|
+
reissuanceAllowed?: boolean;
|
|
116
|
+
};
|
|
117
|
+
outputs: {
|
|
118
|
+
paymentToTreasury: {
|
|
119
|
+
recipientAddress: string;
|
|
120
|
+
assetId: string;
|
|
121
|
+
amountAtomic: string;
|
|
122
|
+
outputIndex: number;
|
|
123
|
+
};
|
|
124
|
+
rwaToBuyer: {
|
|
125
|
+
recipientAddress: string;
|
|
126
|
+
assetId: string;
|
|
127
|
+
amountAtomic: string;
|
|
128
|
+
outputIndex: number;
|
|
129
|
+
outputBindingMode: BondOutputBindingMode;
|
|
130
|
+
rawOutput?: Partial<OutputRawFields>;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
fee: {
|
|
134
|
+
asset: "lbtc";
|
|
135
|
+
maxFeeSat: number;
|
|
136
|
+
feeOutputIndex?: number;
|
|
137
|
+
};
|
|
138
|
+
fundingTxid?: string;
|
|
139
|
+
deliveryTxid?: string;
|
|
140
|
+
createdAt: string;
|
|
141
|
+
}
|
|
142
|
+
export interface RwaDvpPrepareDeliveryClaimInput {
|
|
143
|
+
purchase: RwaDvpPurchaseDefinition;
|
|
144
|
+
fundingTxid?: string;
|
|
145
|
+
paymentInput?: RwaDvpDeliveryClaimDescriptor["paymentInput"];
|
|
146
|
+
operatorRwaInput?: RwaDvpDeliveryClaimDescriptor["operatorRwaInput"];
|
|
147
|
+
mode?: RwaDvpDeliveryClaimDescriptor["mode"];
|
|
148
|
+
outputBindingMode?: BondOutputBindingMode;
|
|
149
|
+
nextRawOutput?: Partial<OutputRawFields>;
|
|
150
|
+
paymentOutputIndex?: number;
|
|
151
|
+
deliveryOutputIndex?: number;
|
|
152
|
+
maxFeeSat?: number;
|
|
153
|
+
feeOutputIndex?: number;
|
|
154
|
+
deliveryTxid?: string;
|
|
155
|
+
createdAt?: string | Date;
|
|
156
|
+
}
|
|
157
|
+
export interface RwaDvpRefundClaimDescriptor {
|
|
158
|
+
schemaVersion: typeof RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION;
|
|
159
|
+
purchaseId: string;
|
|
160
|
+
network: LiquidX402Network;
|
|
161
|
+
termsHash: string;
|
|
162
|
+
policyHash: string;
|
|
163
|
+
paymentInput?: {
|
|
164
|
+
txid: string;
|
|
165
|
+
vout?: number;
|
|
166
|
+
assetId: string;
|
|
167
|
+
amountAtomic: string;
|
|
168
|
+
};
|
|
169
|
+
refundOutput: {
|
|
170
|
+
recipientAddress: string;
|
|
171
|
+
assetId: string;
|
|
172
|
+
amountAtomic: string;
|
|
173
|
+
outputIndex: number;
|
|
174
|
+
};
|
|
175
|
+
notBefore: string;
|
|
176
|
+
fee: {
|
|
177
|
+
asset: "lbtc";
|
|
178
|
+
maxFeeSat: number;
|
|
179
|
+
feeOutputIndex?: number;
|
|
180
|
+
};
|
|
181
|
+
refundTxid?: string;
|
|
182
|
+
createdAt: string;
|
|
183
|
+
}
|
|
184
|
+
export interface RwaDvpPrepareRefundClaimInput {
|
|
185
|
+
purchase: RwaDvpPurchaseDefinition;
|
|
186
|
+
paymentInput?: RwaDvpRefundClaimDescriptor["paymentInput"];
|
|
187
|
+
refundOutputIndex?: number;
|
|
188
|
+
maxFeeSat?: number;
|
|
189
|
+
feeOutputIndex?: number;
|
|
190
|
+
refundTxid?: string;
|
|
191
|
+
createdAt?: string | Date;
|
|
192
|
+
}
|
|
193
|
+
export interface RwaDvpVerificationReport {
|
|
194
|
+
schemaVersion: typeof RWA_DVP_VERIFICATION_SCHEMA_VERSION;
|
|
195
|
+
ok: boolean;
|
|
196
|
+
reason?: string;
|
|
197
|
+
purchaseId: string;
|
|
198
|
+
termsHash: string;
|
|
199
|
+
policyHash: string;
|
|
200
|
+
checks: Record<string, boolean>;
|
|
201
|
+
}
|
|
202
|
+
export interface RwaDvpEvidenceBundle {
|
|
203
|
+
schemaVersion: typeof RWA_DVP_EVIDENCE_SCHEMA_VERSION;
|
|
204
|
+
purchase: RwaDvpPurchaseDefinition;
|
|
205
|
+
termsHash: string;
|
|
206
|
+
policyHash: string;
|
|
207
|
+
paymentRequirements?: LiquidX402PaymentRequirements | Record<string, unknown>;
|
|
208
|
+
paymentVerification?: LiquidX402VerifyPaymentResult;
|
|
209
|
+
deliveryClaim?: RwaDvpDeliveryClaimDescriptor;
|
|
210
|
+
deliveryVerification?: RwaDvpVerificationReport;
|
|
211
|
+
refundClaim?: RwaDvpRefundClaimDescriptor;
|
|
212
|
+
refundVerification?: RwaDvpVerificationReport;
|
|
213
|
+
evm?: {
|
|
214
|
+
lockTxHash?: string;
|
|
215
|
+
consumeTxHash?: string;
|
|
216
|
+
releaseTxHash?: string;
|
|
217
|
+
};
|
|
218
|
+
createdAt: string;
|
|
219
|
+
}
|
|
220
|
+
export declare function definePurchase(_sdk: SimplicityClient, input: RwaDvpDefinePurchaseInput): RwaDvpPreparedPurchase;
|
|
221
|
+
export declare function summarizePurchase(purchase: RwaDvpPurchaseDefinition): RwaDvpSummary;
|
|
222
|
+
export declare function buildPaymentRequirements(_sdk: SimplicityClient, input: RwaDvpBuildPaymentRequirementsInput): LiquidX402PaymentRequirements;
|
|
223
|
+
export declare function verifyPaymentPset(sdk: SimplicityClient, input: RwaDvpVerifyPaymentPsetInput): Promise<LiquidX402VerifyPaymentResult>;
|
|
224
|
+
export declare function prepareDeliveryClaim(sdk: SimplicityClient, input: RwaDvpPrepareDeliveryClaimInput): {
|
|
225
|
+
descriptor: RwaDvpDeliveryClaimDescriptor;
|
|
226
|
+
summary: RwaDvpSummary;
|
|
227
|
+
verification: RwaDvpVerificationReport;
|
|
228
|
+
};
|
|
229
|
+
export declare function verifyDeliveryClaim(_sdk: SimplicityClient, input: {
|
|
230
|
+
purchase: RwaDvpPurchaseDefinition;
|
|
231
|
+
descriptor: RwaDvpDeliveryClaimDescriptor;
|
|
232
|
+
}): RwaDvpVerificationReport;
|
|
233
|
+
export declare function prepareRefundClaim(sdk: SimplicityClient, input: RwaDvpPrepareRefundClaimInput): {
|
|
234
|
+
descriptor: RwaDvpRefundClaimDescriptor;
|
|
235
|
+
summary: RwaDvpSummary;
|
|
236
|
+
verification: RwaDvpVerificationReport;
|
|
237
|
+
};
|
|
238
|
+
export declare function verifyRefundClaim(_sdk: SimplicityClient, input: {
|
|
239
|
+
purchase: RwaDvpPurchaseDefinition;
|
|
240
|
+
descriptor: RwaDvpRefundClaimDescriptor;
|
|
241
|
+
}): RwaDvpVerificationReport;
|
|
242
|
+
export declare function exportEvidence(_sdk: SimplicityClient, input: Omit<RwaDvpEvidenceBundle, "schemaVersion" | "createdAt" | "termsHash" | "policyHash"> & {
|
|
243
|
+
createdAt?: string | Date;
|
|
244
|
+
}): RwaDvpEvidenceBundle;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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
|
+
exports.definePurchase = definePurchase;
|
|
5
|
+
exports.summarizePurchase = summarizePurchase;
|
|
6
|
+
exports.buildPaymentRequirements = buildPaymentRequirements;
|
|
7
|
+
exports.verifyPaymentPset = verifyPaymentPset;
|
|
8
|
+
exports.prepareDeliveryClaim = prepareDeliveryClaim;
|
|
9
|
+
exports.verifyDeliveryClaim = verifyDeliveryClaim;
|
|
10
|
+
exports.prepareRefundClaim = prepareRefundClaim;
|
|
11
|
+
exports.verifyRefundClaim = verifyRefundClaim;
|
|
12
|
+
exports.exportEvidence = exportEvidence;
|
|
13
|
+
const errors_1 = require("../core/errors");
|
|
14
|
+
const summary_1 = require("../core/summary");
|
|
15
|
+
const x402_1 = require("../x402");
|
|
16
|
+
exports.RWA_DVP_PURCHASE_SCHEMA_VERSION = "rwa-dvp-purchase/v1";
|
|
17
|
+
exports.RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION = "rwa-dvp-delivery-claim/v1";
|
|
18
|
+
exports.RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION = "rwa-dvp-refund-claim/v1";
|
|
19
|
+
exports.RWA_DVP_VERIFICATION_SCHEMA_VERSION = "rwa-dvp-verification/v1";
|
|
20
|
+
exports.RWA_DVP_EVIDENCE_SCHEMA_VERSION = "rwa-dvp-evidence/v1";
|
|
21
|
+
function definePurchase(_sdk, input) {
|
|
22
|
+
const network = input.network ?? "liquidtestnet";
|
|
23
|
+
assertNonEmpty(input.purchaseId, "purchaseId");
|
|
24
|
+
assertNonEmpty(input.payment.escrowAddress, "payment.escrowAddress");
|
|
25
|
+
assertNonEmpty(input.delivery.recipientAddress, "delivery.recipientAddress");
|
|
26
|
+
assertNonEmpty(input.refund.recipientAddress, "refund.recipientAddress");
|
|
27
|
+
assertPositiveInteger(input.payment.amountAtomic, "payment.amountAtomic");
|
|
28
|
+
assertPositiveInteger(input.delivery.amountAtomic, "delivery.amountAtomic");
|
|
29
|
+
assertPositiveInteger(input.evmLock.amountAtomic, "evmLock.amountAtomic");
|
|
30
|
+
assertFutureishDate(input.expiresAt, "expiresAt");
|
|
31
|
+
assertFutureishDate(input.refund.after, "refund.after");
|
|
32
|
+
const assetId = input.payment.assetId ?? (0, x402_1.resolveLiquidX402Asset)(input.payment.asset, network).assetId;
|
|
33
|
+
const definition = {
|
|
34
|
+
schemaVersion: exports.RWA_DVP_PURCHASE_SCHEMA_VERSION,
|
|
35
|
+
purchaseId: input.purchaseId,
|
|
36
|
+
network,
|
|
37
|
+
evmLock: {
|
|
38
|
+
...input.evmLock,
|
|
39
|
+
amountAtomic: normalizeInteger(input.evmLock.amountAtomic),
|
|
40
|
+
},
|
|
41
|
+
payment: {
|
|
42
|
+
asset: input.payment.asset,
|
|
43
|
+
assetId,
|
|
44
|
+
amountAtomic: normalizeInteger(input.payment.amountAtomic),
|
|
45
|
+
escrowAddress: input.payment.escrowAddress,
|
|
46
|
+
treasuryAddress: input.payment.treasuryAddress ?? input.payment.escrowAddress,
|
|
47
|
+
},
|
|
48
|
+
delivery: {
|
|
49
|
+
assetId: input.delivery.assetId,
|
|
50
|
+
amountAtomic: normalizeInteger(input.delivery.amountAtomic),
|
|
51
|
+
recipientAddress: input.delivery.recipientAddress,
|
|
52
|
+
},
|
|
53
|
+
refund: {
|
|
54
|
+
recipientAddress: input.refund.recipientAddress,
|
|
55
|
+
after: normalizeIso(input.refund.after),
|
|
56
|
+
},
|
|
57
|
+
expiresAt: normalizeIso(input.expiresAt),
|
|
58
|
+
...(input.metadata ? { metadata: input.metadata } : {}),
|
|
59
|
+
};
|
|
60
|
+
const summary = summarizePurchase(definition);
|
|
61
|
+
return {
|
|
62
|
+
definition,
|
|
63
|
+
summary,
|
|
64
|
+
termsHash: summary.hash,
|
|
65
|
+
policyHash: summarizePolicy(definition).hash,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function summarizePurchase(purchase) {
|
|
69
|
+
return summarizeCanonical(purchase);
|
|
70
|
+
}
|
|
71
|
+
function buildPaymentRequirements(_sdk, input) {
|
|
72
|
+
const summary = summarizePurchase(input.purchase);
|
|
73
|
+
return (0, x402_1.buildLiquidX402Requirements)({
|
|
74
|
+
paymentRequestId: input.purchase.purchaseId,
|
|
75
|
+
resource: input.resource,
|
|
76
|
+
payTo: input.purchase.payment.escrowAddress,
|
|
77
|
+
amountAtomic: input.purchase.payment.amountAtomic,
|
|
78
|
+
network: input.purchase.network,
|
|
79
|
+
asset: input.purchase.payment.asset,
|
|
80
|
+
assetId: input.purchase.payment.assetId,
|
|
81
|
+
description: input.description ?? "Hazbase RWA Liquid delivery-versus-payment",
|
|
82
|
+
mimeType: input.mimeType ?? "application/json",
|
|
83
|
+
maxTimeoutSeconds: input.maxTimeoutSeconds,
|
|
84
|
+
expiresAt: input.purchase.expiresAt,
|
|
85
|
+
maxFeeSat: input.maxFeeSat,
|
|
86
|
+
metadata: {
|
|
87
|
+
...input.metadata,
|
|
88
|
+
purchaseId: input.purchase.purchaseId,
|
|
89
|
+
termsHash: summary.hash,
|
|
90
|
+
policyHash: summarizePolicy(input.purchase).hash,
|
|
91
|
+
deliveryAssetId: input.purchase.delivery.assetId,
|
|
92
|
+
deliveryAmountAtomic: input.purchase.delivery.amountAtomic,
|
|
93
|
+
deliveryRecipientAddress: input.purchase.delivery.recipientAddress,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async function verifyPaymentPset(sdk, input) {
|
|
98
|
+
const rpc = input.verifyPsetOutputs === false ? null : sdk.rpc;
|
|
99
|
+
const result = await (0, x402_1.verifyLiquidX402Payment)(rpc, {
|
|
100
|
+
requirements: input.requirements,
|
|
101
|
+
paymentPayload: input.paymentPayload,
|
|
102
|
+
now: input.now,
|
|
103
|
+
});
|
|
104
|
+
if (!result.isValid)
|
|
105
|
+
return result;
|
|
106
|
+
if (result.paymentRequestId !== input.purchase.purchaseId) {
|
|
107
|
+
return { ...result, isValid: false, invalidReason: "purchase_mismatch" };
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
function prepareDeliveryClaim(sdk, input) {
|
|
112
|
+
const purchaseSummary = summarizePurchase(input.purchase);
|
|
113
|
+
const policy = summarizePolicy(input.purchase);
|
|
114
|
+
const descriptor = {
|
|
115
|
+
schemaVersion: exports.RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION,
|
|
116
|
+
purchaseId: input.purchase.purchaseId,
|
|
117
|
+
network: input.purchase.network,
|
|
118
|
+
termsHash: purchaseSummary.hash,
|
|
119
|
+
policyHash: policy.hash,
|
|
120
|
+
mode: input.mode ?? "simplicity-multi-asset-claim",
|
|
121
|
+
...(input.paymentInput ? { paymentInput: input.paymentInput } : {}),
|
|
122
|
+
operatorRwaInput: input.operatorRwaInput ?? {
|
|
123
|
+
assetId: input.purchase.delivery.assetId,
|
|
124
|
+
amountAtomic: input.purchase.delivery.amountAtomic,
|
|
125
|
+
reissuanceAllowed: true,
|
|
126
|
+
},
|
|
127
|
+
outputs: {
|
|
128
|
+
paymentToTreasury: {
|
|
129
|
+
recipientAddress: input.purchase.payment.treasuryAddress,
|
|
130
|
+
assetId: input.purchase.payment.assetId,
|
|
131
|
+
amountAtomic: input.purchase.payment.amountAtomic,
|
|
132
|
+
outputIndex: input.paymentOutputIndex ?? 0,
|
|
133
|
+
},
|
|
134
|
+
rwaToBuyer: {
|
|
135
|
+
recipientAddress: input.purchase.delivery.recipientAddress,
|
|
136
|
+
assetId: input.purchase.delivery.assetId,
|
|
137
|
+
amountAtomic: input.purchase.delivery.amountAtomic,
|
|
138
|
+
outputIndex: input.deliveryOutputIndex ?? 1,
|
|
139
|
+
outputBindingMode: input.outputBindingMode ?? "descriptor-bound",
|
|
140
|
+
...(input.nextRawOutput ? { rawOutput: input.nextRawOutput } : {}),
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
fee: {
|
|
144
|
+
asset: "lbtc",
|
|
145
|
+
maxFeeSat: input.maxFeeSat ?? sdk.config.defaults?.feeSat ?? 1000,
|
|
146
|
+
...(input.feeOutputIndex !== undefined ? { feeOutputIndex: input.feeOutputIndex } : {}),
|
|
147
|
+
},
|
|
148
|
+
...(input.fundingTxid ? { fundingTxid: input.fundingTxid } : {}),
|
|
149
|
+
...(input.deliveryTxid ? { deliveryTxid: input.deliveryTxid } : {}),
|
|
150
|
+
createdAt: input.createdAt ? normalizeIso(input.createdAt) : new Date().toISOString(),
|
|
151
|
+
};
|
|
152
|
+
const verification = verifyDeliveryClaim(sdk, { purchase: input.purchase, descriptor });
|
|
153
|
+
return {
|
|
154
|
+
descriptor,
|
|
155
|
+
summary: summarizeCanonical(descriptor),
|
|
156
|
+
verification,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function verifyDeliveryClaim(_sdk, input) {
|
|
160
|
+
const termsHash = summarizePurchase(input.purchase).hash;
|
|
161
|
+
const policyHash = summarizePolicy(input.purchase).hash;
|
|
162
|
+
const checks = {
|
|
163
|
+
schemaVersion: input.descriptor.schemaVersion === exports.RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION,
|
|
164
|
+
purchaseId: input.descriptor.purchaseId === input.purchase.purchaseId,
|
|
165
|
+
network: input.descriptor.network === input.purchase.network,
|
|
166
|
+
termsHash: input.descriptor.termsHash === termsHash,
|
|
167
|
+
policyHash: input.descriptor.policyHash === policyHash,
|
|
168
|
+
paymentOutputAsset: input.descriptor.outputs.paymentToTreasury.assetId === input.purchase.payment.assetId,
|
|
169
|
+
paymentOutputAmount: input.descriptor.outputs.paymentToTreasury.amountAtomic === input.purchase.payment.amountAtomic,
|
|
170
|
+
paymentOutputRecipient: input.descriptor.outputs.paymentToTreasury.recipientAddress === input.purchase.payment.treasuryAddress,
|
|
171
|
+
deliveryOutputAsset: input.descriptor.outputs.rwaToBuyer.assetId === input.purchase.delivery.assetId,
|
|
172
|
+
deliveryOutputAmount: input.descriptor.outputs.rwaToBuyer.amountAtomic === input.purchase.delivery.amountAtomic,
|
|
173
|
+
deliveryOutputRecipient: input.descriptor.outputs.rwaToBuyer.recipientAddress === input.purchase.delivery.recipientAddress,
|
|
174
|
+
fee: Number.isInteger(input.descriptor.fee.maxFeeSat) && input.descriptor.fee.maxFeeSat >= 0,
|
|
175
|
+
};
|
|
176
|
+
return report(input.purchase.purchaseId, termsHash, policyHash, checks, "RWA DvP delivery claim descriptor mismatch");
|
|
177
|
+
}
|
|
178
|
+
function prepareRefundClaim(sdk, input) {
|
|
179
|
+
const termsHash = summarizePurchase(input.purchase).hash;
|
|
180
|
+
const policyHash = summarizePolicy(input.purchase).hash;
|
|
181
|
+
const descriptor = {
|
|
182
|
+
schemaVersion: exports.RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION,
|
|
183
|
+
purchaseId: input.purchase.purchaseId,
|
|
184
|
+
network: input.purchase.network,
|
|
185
|
+
termsHash,
|
|
186
|
+
policyHash,
|
|
187
|
+
...(input.paymentInput ? { paymentInput: input.paymentInput } : {}),
|
|
188
|
+
refundOutput: {
|
|
189
|
+
recipientAddress: input.purchase.refund.recipientAddress,
|
|
190
|
+
assetId: input.purchase.payment.assetId,
|
|
191
|
+
amountAtomic: input.purchase.payment.amountAtomic,
|
|
192
|
+
outputIndex: input.refundOutputIndex ?? 0,
|
|
193
|
+
},
|
|
194
|
+
notBefore: input.purchase.refund.after,
|
|
195
|
+
fee: {
|
|
196
|
+
asset: "lbtc",
|
|
197
|
+
maxFeeSat: input.maxFeeSat ?? sdk.config.defaults?.feeSat ?? 1000,
|
|
198
|
+
...(input.feeOutputIndex !== undefined ? { feeOutputIndex: input.feeOutputIndex } : {}),
|
|
199
|
+
},
|
|
200
|
+
...(input.refundTxid ? { refundTxid: input.refundTxid } : {}),
|
|
201
|
+
createdAt: input.createdAt ? normalizeIso(input.createdAt) : new Date().toISOString(),
|
|
202
|
+
};
|
|
203
|
+
const verification = verifyRefundClaim(sdk, { purchase: input.purchase, descriptor });
|
|
204
|
+
return {
|
|
205
|
+
descriptor,
|
|
206
|
+
summary: summarizeCanonical(descriptor),
|
|
207
|
+
verification,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function verifyRefundClaim(_sdk, input) {
|
|
211
|
+
const termsHash = summarizePurchase(input.purchase).hash;
|
|
212
|
+
const policyHash = summarizePolicy(input.purchase).hash;
|
|
213
|
+
const checks = {
|
|
214
|
+
schemaVersion: input.descriptor.schemaVersion === exports.RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION,
|
|
215
|
+
purchaseId: input.descriptor.purchaseId === input.purchase.purchaseId,
|
|
216
|
+
network: input.descriptor.network === input.purchase.network,
|
|
217
|
+
termsHash: input.descriptor.termsHash === termsHash,
|
|
218
|
+
policyHash: input.descriptor.policyHash === policyHash,
|
|
219
|
+
refundAsset: input.descriptor.refundOutput.assetId === input.purchase.payment.assetId,
|
|
220
|
+
refundAmount: input.descriptor.refundOutput.amountAtomic === input.purchase.payment.amountAtomic,
|
|
221
|
+
refundRecipient: input.descriptor.refundOutput.recipientAddress === input.purchase.refund.recipientAddress,
|
|
222
|
+
notBefore: input.descriptor.notBefore === input.purchase.refund.after,
|
|
223
|
+
fee: Number.isInteger(input.descriptor.fee.maxFeeSat) && input.descriptor.fee.maxFeeSat >= 0,
|
|
224
|
+
};
|
|
225
|
+
return report(input.purchase.purchaseId, termsHash, policyHash, checks, "RWA DvP refund claim descriptor mismatch");
|
|
226
|
+
}
|
|
227
|
+
function exportEvidence(_sdk, input) {
|
|
228
|
+
return {
|
|
229
|
+
schemaVersion: exports.RWA_DVP_EVIDENCE_SCHEMA_VERSION,
|
|
230
|
+
purchase: input.purchase,
|
|
231
|
+
termsHash: summarizePurchase(input.purchase).hash,
|
|
232
|
+
policyHash: summarizePolicy(input.purchase).hash,
|
|
233
|
+
...(input.paymentRequirements ? { paymentRequirements: input.paymentRequirements } : {}),
|
|
234
|
+
...(input.paymentVerification ? { paymentVerification: input.paymentVerification } : {}),
|
|
235
|
+
...(input.deliveryClaim ? { deliveryClaim: input.deliveryClaim } : {}),
|
|
236
|
+
...(input.deliveryVerification ? { deliveryVerification: input.deliveryVerification } : {}),
|
|
237
|
+
...(input.refundClaim ? { refundClaim: input.refundClaim } : {}),
|
|
238
|
+
...(input.refundVerification ? { refundVerification: input.refundVerification } : {}),
|
|
239
|
+
...(input.evm ? { evm: input.evm } : {}),
|
|
240
|
+
createdAt: input.createdAt ? normalizeIso(input.createdAt) : new Date().toISOString(),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function summarizePolicy(purchase) {
|
|
244
|
+
return summarizeCanonical({
|
|
245
|
+
schemaVersion: "rwa-dvp-policy/v1",
|
|
246
|
+
purchaseId: purchase.purchaseId,
|
|
247
|
+
network: purchase.network,
|
|
248
|
+
evmLock: purchase.evmLock,
|
|
249
|
+
paymentMustFundEscrow: {
|
|
250
|
+
asset: purchase.payment.asset,
|
|
251
|
+
assetId: purchase.payment.assetId,
|
|
252
|
+
amountAtomic: purchase.payment.amountAtomic,
|
|
253
|
+
escrowAddress: purchase.payment.escrowAddress,
|
|
254
|
+
},
|
|
255
|
+
deliveryClaimMustPay: {
|
|
256
|
+
treasuryAddress: purchase.payment.treasuryAddress,
|
|
257
|
+
buyerAddress: purchase.delivery.recipientAddress,
|
|
258
|
+
paymentAssetId: purchase.payment.assetId,
|
|
259
|
+
paymentAmountAtomic: purchase.payment.amountAtomic,
|
|
260
|
+
rwaAssetId: purchase.delivery.assetId,
|
|
261
|
+
rwaAmountAtomic: purchase.delivery.amountAtomic,
|
|
262
|
+
},
|
|
263
|
+
refundAfter: purchase.refund,
|
|
264
|
+
expiresAt: purchase.expiresAt,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function summarizeCanonical(value) {
|
|
268
|
+
const canonicalJson = (0, summary_1.stableStringify)(value);
|
|
269
|
+
return { canonicalJson, hash: (0, summary_1.sha256HexUtf8)(canonicalJson) };
|
|
270
|
+
}
|
|
271
|
+
function report(purchaseId, termsHash, policyHash, checks, reason) {
|
|
272
|
+
const ok = Object.values(checks).every(Boolean);
|
|
273
|
+
return {
|
|
274
|
+
schemaVersion: exports.RWA_DVP_VERIFICATION_SCHEMA_VERSION,
|
|
275
|
+
ok,
|
|
276
|
+
...(ok ? {} : { reason }),
|
|
277
|
+
purchaseId,
|
|
278
|
+
termsHash,
|
|
279
|
+
policyHash,
|
|
280
|
+
checks,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function assertNonEmpty(value, name) {
|
|
284
|
+
if (!value || !value.trim()) {
|
|
285
|
+
throw new errors_1.ValidationError(`${name} must be a non-empty string`, { code: "RWA_DVP_FIELD_REQUIRED", field: name });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function assertPositiveInteger(value, name) {
|
|
289
|
+
normalizeInteger(value);
|
|
290
|
+
if (BigInt(value) <= 0n) {
|
|
291
|
+
throw new errors_1.ValidationError(`${name} must be positive`, { code: "RWA_DVP_AMOUNT_INVALID", field: name });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function normalizeInteger(value) {
|
|
295
|
+
const text = typeof value === "bigint" ? value.toString() : String(value).trim();
|
|
296
|
+
if (!/^[0-9]+$/u.test(text)) {
|
|
297
|
+
throw new errors_1.ValidationError("amount must be an integer string", { code: "RWA_DVP_AMOUNT_INVALID" });
|
|
298
|
+
}
|
|
299
|
+
return BigInt(text).toString();
|
|
300
|
+
}
|
|
301
|
+
function assertFutureishDate(value, name) {
|
|
302
|
+
const time = new Date(value).getTime();
|
|
303
|
+
if (!Number.isFinite(time)) {
|
|
304
|
+
throw new errors_1.ValidationError(`${name} must be a valid date`, { code: "RWA_DVP_DATE_INVALID", field: name });
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function normalizeIso(value) {
|
|
308
|
+
return new Date(value).toISOString();
|
|
309
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,4 +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
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 = void 0;
|
|
19
|
+
exports.verifyRwaDvpDeliveryClaim = exports.summarizeRwaDvpPurchase = exports.prepareRwaDvpRefundClaim = exports.prepareRwaDvpDeliveryClaim = exports.exportRwaDvpEvidence = exports.defineRwaDvpPurchase = 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 = 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; } });
|
|
@@ -176,6 +176,21 @@ Object.defineProperty(exports, "validateReceivableFundingTransition", { enumerab
|
|
|
176
176
|
Object.defineProperty(exports, "validateReceivableRepaymentTransition", { enumerable: true, get: function () { return receivableValidation_1.validateReceivableRepaymentTransition; } });
|
|
177
177
|
Object.defineProperty(exports, "validateReceivableWriteOffTransition", { enumerable: true, get: function () { return receivableValidation_1.validateReceivableWriteOffTransition; } });
|
|
178
178
|
Object.defineProperty(exports, "verifyReceivableStateHistoryValidation", { enumerable: true, get: function () { return receivableValidation_1.verifyReceivableStateHistory; } });
|
|
179
|
+
var rwaDvp_1 = require("./domain/rwaDvp");
|
|
180
|
+
Object.defineProperty(exports, "RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION", { enumerable: true, get: function () { return rwaDvp_1.RWA_DVP_DELIVERY_CLAIM_SCHEMA_VERSION; } });
|
|
181
|
+
Object.defineProperty(exports, "RWA_DVP_EVIDENCE_SCHEMA_VERSION", { enumerable: true, get: function () { return rwaDvp_1.RWA_DVP_EVIDENCE_SCHEMA_VERSION; } });
|
|
182
|
+
Object.defineProperty(exports, "RWA_DVP_PURCHASE_SCHEMA_VERSION", { enumerable: true, get: function () { return rwaDvp_1.RWA_DVP_PURCHASE_SCHEMA_VERSION; } });
|
|
183
|
+
Object.defineProperty(exports, "RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION", { enumerable: true, get: function () { return rwaDvp_1.RWA_DVP_REFUND_CLAIM_SCHEMA_VERSION; } });
|
|
184
|
+
Object.defineProperty(exports, "RWA_DVP_VERIFICATION_SCHEMA_VERSION", { enumerable: true, get: function () { return rwaDvp_1.RWA_DVP_VERIFICATION_SCHEMA_VERSION; } });
|
|
185
|
+
Object.defineProperty(exports, "buildRwaDvpPaymentRequirements", { enumerable: true, get: function () { return rwaDvp_1.buildPaymentRequirements; } });
|
|
186
|
+
Object.defineProperty(exports, "defineRwaDvpPurchase", { enumerable: true, get: function () { return rwaDvp_1.definePurchase; } });
|
|
187
|
+
Object.defineProperty(exports, "exportRwaDvpEvidence", { enumerable: true, get: function () { return rwaDvp_1.exportEvidence; } });
|
|
188
|
+
Object.defineProperty(exports, "prepareRwaDvpDeliveryClaim", { enumerable: true, get: function () { return rwaDvp_1.prepareDeliveryClaim; } });
|
|
189
|
+
Object.defineProperty(exports, "prepareRwaDvpRefundClaim", { enumerable: true, get: function () { return rwaDvp_1.prepareRefundClaim; } });
|
|
190
|
+
Object.defineProperty(exports, "summarizeRwaDvpPurchase", { enumerable: true, get: function () { return rwaDvp_1.summarizePurchase; } });
|
|
191
|
+
Object.defineProperty(exports, "verifyRwaDvpDeliveryClaim", { enumerable: true, get: function () { return rwaDvp_1.verifyDeliveryClaim; } });
|
|
192
|
+
Object.defineProperty(exports, "verifyRwaDvpPaymentPset", { enumerable: true, get: function () { return rwaDvp_1.verifyPaymentPset; } });
|
|
193
|
+
Object.defineProperty(exports, "verifyRwaDvpRefundClaim", { enumerable: true, get: function () { return rwaDvp_1.verifyRefundClaim; } });
|
|
179
194
|
var policies_1 = require("./domain/policies");
|
|
180
195
|
Object.defineProperty(exports, "compilePolicyStateContract", { enumerable: true, get: function () { return policies_1.compilePolicyStateContract; } });
|
|
181
196
|
Object.defineProperty(exports, "buildPolicyOutputDescriptor", { enumerable: true, get: function () { return policies_1.buildPolicyOutputDescriptor; } });
|
package/dist/x402/index.d.ts
CHANGED
package/dist/x402/index.js
CHANGED
|
@@ -77,6 +77,7 @@ function resolveLiquidX402Asset(asset, network = exports.LIQUID_X402_DEFAULT_NET
|
|
|
77
77
|
function buildLiquidX402Requirements(input) {
|
|
78
78
|
const network = normalizeNetwork(input.network ?? exports.LIQUID_X402_DEFAULT_NETWORK);
|
|
79
79
|
const asset = resolveLiquidX402Asset(input.asset ?? "usdt", network);
|
|
80
|
+
const assetId = resolveLiquidX402AssetId(input.assetId, asset);
|
|
80
81
|
const amountAtomic = normalizeAmountAtomic(input.amountAtomic);
|
|
81
82
|
const expiresAt = normalizeExpiresAt(input.expiresAt, input.maxTimeoutSeconds);
|
|
82
83
|
const description = String(input.description ?? "").trim() || "Unlock resource";
|
|
@@ -100,11 +101,11 @@ function buildLiquidX402Requirements(input) {
|
|
|
100
101
|
mimeType,
|
|
101
102
|
payTo,
|
|
102
103
|
maxTimeoutSeconds,
|
|
103
|
-
asset:
|
|
104
|
+
asset: assetId,
|
|
104
105
|
extra: {
|
|
105
106
|
paymentRequestId,
|
|
106
107
|
asset: asset.key,
|
|
107
|
-
assetId
|
|
108
|
+
assetId,
|
|
108
109
|
decimals: asset.decimals,
|
|
109
110
|
expiresAt,
|
|
110
111
|
feeAsset: "lbtc",
|
|
@@ -306,7 +307,7 @@ async function settleLiquidX402Payment(rpc, input) {
|
|
|
306
307
|
if (mempool[0]?.allowed !== true) {
|
|
307
308
|
return {
|
|
308
309
|
success: false,
|
|
309
|
-
errorCode: mempool[0]
|
|
310
|
+
errorCode: mempoolRejectReason(mempool[0]),
|
|
310
311
|
rawTxHex: finalized.hex,
|
|
311
312
|
summaryHash: payload.summaryHash,
|
|
312
313
|
};
|
|
@@ -431,6 +432,12 @@ function normalizeAddressForComparison(value) {
|
|
|
431
432
|
function normalizeHexForComparison(value) {
|
|
432
433
|
return String(value ?? "").trim().toLowerCase().replace(/^0x/u, "");
|
|
433
434
|
}
|
|
435
|
+
function mempoolRejectReason(result) {
|
|
436
|
+
if (!result || typeof result !== "object")
|
|
437
|
+
return "mempool_rejected";
|
|
438
|
+
const raw = result;
|
|
439
|
+
return String(raw["reject-reason"] ?? raw.reject_reason ?? raw.error ?? "mempool_rejected").trim() || "mempool_rejected";
|
|
440
|
+
}
|
|
434
441
|
function coerceRequirements(value) {
|
|
435
442
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
436
443
|
throw new Error("requirements must be an object");
|
|
@@ -579,6 +586,12 @@ function isLiquidAssetAlias(input) {
|
|
|
579
586
|
value === "usdt-liquid" ||
|
|
580
587
|
value === "tether";
|
|
581
588
|
}
|
|
589
|
+
function resolveLiquidX402AssetId(input, asset) {
|
|
590
|
+
const value = String(input ?? "").trim();
|
|
591
|
+
if (!value)
|
|
592
|
+
return asset.assetId;
|
|
593
|
+
return isLiquidAssetAlias(value) ? asset.assetId : value;
|
|
594
|
+
}
|
|
582
595
|
function normalizeAmountAtomic(input) {
|
|
583
596
|
const raw = typeof input === "bigint" ? input.toString() : String(input ?? "").trim();
|
|
584
597
|
if (!/^\d+$/u.test(raw))
|