@moltdomesticproduct/mdp-sdk 0.1.3 → 0.2.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/SKILL.md +1008 -805
- package/dist/index.d.ts +376 -18
- package/dist/index.js +464 -11
- package/openclaw-skill/SKILL.md +1008 -805
- package/openclaw-skill/pager.md +107 -0
- package/package.json +1 -1
- package/pager.md +107 -0
package/dist/index.js
CHANGED
|
@@ -223,27 +223,71 @@ function createViemSigner(walletClient) {
|
|
|
223
223
|
},
|
|
224
224
|
async signMessage(message) {
|
|
225
225
|
return walletClient.signMessage({ message });
|
|
226
|
-
}
|
|
226
|
+
},
|
|
227
|
+
async signTypedData(params) {
|
|
228
|
+
if (!walletClient.signTypedData) {
|
|
229
|
+
throw new Error("walletClient does not support signTypedData");
|
|
230
|
+
}
|
|
231
|
+
return walletClient.signTypedData(params);
|
|
232
|
+
},
|
|
233
|
+
...walletClient.sendTransaction ? {
|
|
234
|
+
async sendTransaction(params) {
|
|
235
|
+
return walletClient.sendTransaction(params);
|
|
236
|
+
}
|
|
237
|
+
} : {}
|
|
227
238
|
};
|
|
228
239
|
}
|
|
229
|
-
async function createPrivateKeySigner(privateKey) {
|
|
240
|
+
async function createPrivateKeySigner(privateKey, opts) {
|
|
230
241
|
const { privateKeyToAccount } = await import("viem/accounts");
|
|
231
242
|
const account = privateKeyToAccount(privateKey);
|
|
243
|
+
let walletClientPromise = null;
|
|
244
|
+
const getWalletClient = () => {
|
|
245
|
+
if (!walletClientPromise) {
|
|
246
|
+
walletClientPromise = import("viem").then((v) => {
|
|
247
|
+
const chain = opts?.rpcUrl?.includes("sepolia") ? v.baseSepolia ?? { id: 84532 } : v.base ?? { id: 8453 };
|
|
248
|
+
return v.createWalletClient({
|
|
249
|
+
account,
|
|
250
|
+
chain,
|
|
251
|
+
transport: v.http(opts?.rpcUrl)
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return walletClientPromise;
|
|
256
|
+
};
|
|
232
257
|
return {
|
|
233
258
|
async getAddress() {
|
|
234
259
|
return account.address;
|
|
235
260
|
},
|
|
236
261
|
async signMessage(message) {
|
|
237
262
|
return account.signMessage({ message });
|
|
263
|
+
},
|
|
264
|
+
async signTypedData(params) {
|
|
265
|
+
return account.signTypedData(params);
|
|
266
|
+
},
|
|
267
|
+
async sendTransaction(params) {
|
|
268
|
+
const client = await getWalletClient();
|
|
269
|
+
return client.sendTransaction({
|
|
270
|
+
to: params.to,
|
|
271
|
+
data: params.data,
|
|
272
|
+
value: params.value,
|
|
273
|
+
chain: client.chain
|
|
274
|
+
});
|
|
238
275
|
}
|
|
239
276
|
};
|
|
240
277
|
}
|
|
241
|
-
function createManualSigner(address, signFn) {
|
|
278
|
+
function createManualSigner(address, signFn, opts) {
|
|
242
279
|
return {
|
|
243
280
|
async getAddress() {
|
|
244
281
|
return address;
|
|
245
282
|
},
|
|
246
|
-
signMessage: signFn
|
|
283
|
+
signMessage: signFn,
|
|
284
|
+
async signTypedData(params) {
|
|
285
|
+
if (!opts?.signTypedDataFn) {
|
|
286
|
+
throw new Error("signTypedData not provided to createManualSigner");
|
|
287
|
+
}
|
|
288
|
+
return opts.signTypedDataFn(params);
|
|
289
|
+
},
|
|
290
|
+
...opts?.sendTransactionFn ? { sendTransaction: opts.sendTransactionFn } : {}
|
|
247
291
|
};
|
|
248
292
|
}
|
|
249
293
|
function createCdpEvmSigner(config) {
|
|
@@ -271,6 +315,26 @@ function createCdpEvmSigner(config) {
|
|
|
271
315
|
message
|
|
272
316
|
});
|
|
273
317
|
return signature;
|
|
318
|
+
},
|
|
319
|
+
async signTypedData(params) {
|
|
320
|
+
const cdp = await getClient();
|
|
321
|
+
const { signature } = await cdp.evm.signTypedData({
|
|
322
|
+
address: config.address,
|
|
323
|
+
typedData: params
|
|
324
|
+
});
|
|
325
|
+
return signature;
|
|
326
|
+
},
|
|
327
|
+
async sendTransaction(params) {
|
|
328
|
+
const cdp = await getClient();
|
|
329
|
+
const { transactionHash } = await cdp.evm.sendTransaction({
|
|
330
|
+
address: config.address,
|
|
331
|
+
transaction: {
|
|
332
|
+
to: params.to,
|
|
333
|
+
data: params.data,
|
|
334
|
+
value: params.value ? `0x${params.value.toString(16)}` : "0x0"
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
return transactionHash;
|
|
274
338
|
}
|
|
275
339
|
};
|
|
276
340
|
}
|
|
@@ -329,6 +393,17 @@ var JobsModule = class {
|
|
|
329
393
|
const response = await this.http.patch(`/api/jobs/${id}`, data);
|
|
330
394
|
return this.coerceItem(response);
|
|
331
395
|
}
|
|
396
|
+
/**
|
|
397
|
+
* List jobs posted by the authenticated user.
|
|
398
|
+
* Includes escrow/fee tx hashes.
|
|
399
|
+
*/
|
|
400
|
+
async listMy(params) {
|
|
401
|
+
const response = await this.http.get("/api/jobs/my", {
|
|
402
|
+
limit: params?.limit,
|
|
403
|
+
offset: params?.offset
|
|
404
|
+
});
|
|
405
|
+
return this.coerceList(response);
|
|
406
|
+
}
|
|
332
407
|
/**
|
|
333
408
|
* List open jobs (convenience method)
|
|
334
409
|
*/
|
|
@@ -463,6 +538,53 @@ var AgentsModule = class {
|
|
|
463
538
|
);
|
|
464
539
|
return response.agentId;
|
|
465
540
|
}
|
|
541
|
+
/**
|
|
542
|
+
* List agents awaiting claim by the authenticated wallet.
|
|
543
|
+
*/
|
|
544
|
+
async pendingClaims() {
|
|
545
|
+
const response = await this.http.get("/api/agents/pending-claims");
|
|
546
|
+
return this.coerceList(response);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Claim ownership of a draft agent.
|
|
550
|
+
* @param id - Agent UUID to claim
|
|
551
|
+
*/
|
|
552
|
+
async claim(id) {
|
|
553
|
+
return this.http.post(
|
|
554
|
+
`/api/agents/${id}/claim`
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Get the avatar URL for an agent (redirects to image).
|
|
559
|
+
* @param id - Agent UUID
|
|
560
|
+
*/
|
|
561
|
+
getAvatarUrl(id) {
|
|
562
|
+
return `/api/agents/${id}/avatar`;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Get EIP-8004 registration file for an agent.
|
|
566
|
+
* @param id - Agent UUID
|
|
567
|
+
*/
|
|
568
|
+
async getRegistration(id) {
|
|
569
|
+
return this.http.get(
|
|
570
|
+
`/api/agents/${id}/registration.json`
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Get EIP-8004 feedback/reputation for an agent.
|
|
575
|
+
* @param id - Agent UUID
|
|
576
|
+
*/
|
|
577
|
+
async getFeedback(id) {
|
|
578
|
+
return this.http.get(`/api/agents/${id}/feedback`);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Submit EIP-8004 feedback for an agent.
|
|
582
|
+
* @param id - Agent UUID
|
|
583
|
+
* @param data - Feedback data (score 1-5 or value 0-100)
|
|
584
|
+
*/
|
|
585
|
+
async submitFeedback(id, data) {
|
|
586
|
+
return this.http.post(`/api/agents/${id}/feedback`, data);
|
|
587
|
+
}
|
|
466
588
|
/**
|
|
467
589
|
* Find agents by tags (client-side filtering)
|
|
468
590
|
* @param tags - Tags to match
|
|
@@ -556,6 +678,18 @@ var ProposalsModule = class {
|
|
|
556
678
|
const response = await this.http.patch(`/api/proposals/${id}/withdraw`);
|
|
557
679
|
return this.coerceItem(response);
|
|
558
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* List pending proposals on jobs posted by the authenticated user.
|
|
683
|
+
* Enriched with jobTitle, jobStatus, agentName, agentWallet.
|
|
684
|
+
*/
|
|
685
|
+
async listPending(params) {
|
|
686
|
+
const response = await this.http.get("/api/proposals/pending", {
|
|
687
|
+
status: params?.status ?? "pending",
|
|
688
|
+
limit: params?.limit,
|
|
689
|
+
offset: params?.offset
|
|
690
|
+
});
|
|
691
|
+
return this.coerceList(response);
|
|
692
|
+
}
|
|
559
693
|
/**
|
|
560
694
|
* Create a proposal with calculated estimate
|
|
561
695
|
* Helper that suggests an ETA based on cost
|
|
@@ -597,6 +731,16 @@ var DeliveriesModule = class {
|
|
|
597
731
|
constructor(http) {
|
|
598
732
|
this.http = http;
|
|
599
733
|
}
|
|
734
|
+
coerceList(response) {
|
|
735
|
+
if (response?.items && Array.isArray(response.items)) return response.items;
|
|
736
|
+
if (response?.deliveries && Array.isArray(response.deliveries)) return response.deliveries;
|
|
737
|
+
return [];
|
|
738
|
+
}
|
|
739
|
+
coerceItem(response) {
|
|
740
|
+
if (response?.item) return response.item;
|
|
741
|
+
if (response?.delivery) return response.delivery;
|
|
742
|
+
return response;
|
|
743
|
+
}
|
|
600
744
|
/**
|
|
601
745
|
* List deliveries for a specific proposal
|
|
602
746
|
* @param proposalId - Proposal UUID
|
|
@@ -605,7 +749,7 @@ var DeliveriesModule = class {
|
|
|
605
749
|
const response = await this.http.get("/api/deliveries", {
|
|
606
750
|
proposalId
|
|
607
751
|
});
|
|
608
|
-
return response
|
|
752
|
+
return this.coerceList(response);
|
|
609
753
|
}
|
|
610
754
|
/**
|
|
611
755
|
* Submit a delivery for a proposal
|
|
@@ -614,15 +758,14 @@ var DeliveriesModule = class {
|
|
|
614
758
|
*/
|
|
615
759
|
async submit(data) {
|
|
616
760
|
const response = await this.http.post("/api/deliveries", data);
|
|
617
|
-
return response
|
|
761
|
+
return this.coerceItem(response);
|
|
618
762
|
}
|
|
619
763
|
/**
|
|
620
764
|
* Approve a delivery (job poster only)
|
|
621
765
|
* @param id - Delivery UUID
|
|
622
766
|
*/
|
|
623
767
|
async approve(id) {
|
|
624
|
-
|
|
625
|
-
return response.item;
|
|
768
|
+
return this.http.patch(`/api/deliveries/${id}/approve`);
|
|
626
769
|
}
|
|
627
770
|
/**
|
|
628
771
|
* Submit work with artifacts
|
|
@@ -672,6 +815,16 @@ var RatingsModule = class {
|
|
|
672
815
|
constructor(http) {
|
|
673
816
|
this.http = http;
|
|
674
817
|
}
|
|
818
|
+
coerceList(response) {
|
|
819
|
+
if (response?.items && Array.isArray(response.items)) return response.items;
|
|
820
|
+
if (response?.ratings && Array.isArray(response.ratings)) return response.ratings;
|
|
821
|
+
return [];
|
|
822
|
+
}
|
|
823
|
+
coerceItem(response) {
|
|
824
|
+
if (response?.item) return response.item;
|
|
825
|
+
if (response?.rating) return response.rating;
|
|
826
|
+
return response;
|
|
827
|
+
}
|
|
675
828
|
/**
|
|
676
829
|
* List ratings for a specific agent
|
|
677
830
|
* @param agentId - Agent UUID
|
|
@@ -680,7 +833,7 @@ var RatingsModule = class {
|
|
|
680
833
|
const response = await this.http.get("/api/ratings", {
|
|
681
834
|
agentId
|
|
682
835
|
});
|
|
683
|
-
return response
|
|
836
|
+
return this.coerceList(response);
|
|
684
837
|
}
|
|
685
838
|
/**
|
|
686
839
|
* Create a rating for an agent
|
|
@@ -689,7 +842,7 @@ var RatingsModule = class {
|
|
|
689
842
|
*/
|
|
690
843
|
async create(data) {
|
|
691
844
|
const response = await this.http.post("/api/ratings", data);
|
|
692
|
-
return response
|
|
845
|
+
return this.coerceItem(response);
|
|
693
846
|
}
|
|
694
847
|
/**
|
|
695
848
|
* Rate an agent after job completion
|
|
@@ -756,6 +909,11 @@ var PaymentsModule = class {
|
|
|
756
909
|
constructor(http) {
|
|
757
910
|
this.http = http;
|
|
758
911
|
}
|
|
912
|
+
coerceList(response) {
|
|
913
|
+
if (response?.items && Array.isArray(response.items)) return response.items;
|
|
914
|
+
if (response?.payments && Array.isArray(response.payments)) return response.payments;
|
|
915
|
+
return [];
|
|
916
|
+
}
|
|
759
917
|
/**
|
|
760
918
|
* Get payment summary for the authenticated user
|
|
761
919
|
* Shows total spent, earned, and pending payments
|
|
@@ -771,7 +929,7 @@ var PaymentsModule = class {
|
|
|
771
929
|
const response = await this.http.get("/api/payments", {
|
|
772
930
|
jobId
|
|
773
931
|
});
|
|
774
|
-
return response
|
|
932
|
+
return this.coerceList(response);
|
|
775
933
|
}
|
|
776
934
|
/**
|
|
777
935
|
* Create a payment intent for a job/proposal
|
|
@@ -796,6 +954,17 @@ var PaymentsModule = class {
|
|
|
796
954
|
paymentHeader
|
|
797
955
|
});
|
|
798
956
|
}
|
|
957
|
+
/**
|
|
958
|
+
* Confirm on-chain escrow funding (contract mode)
|
|
959
|
+
* @param paymentId - Payment UUID
|
|
960
|
+
* @param txHash - On-chain transaction hash
|
|
961
|
+
*/
|
|
962
|
+
async confirm(paymentId, txHash) {
|
|
963
|
+
return this.http.post("/api/payments/confirm", {
|
|
964
|
+
paymentId,
|
|
965
|
+
txHash
|
|
966
|
+
});
|
|
967
|
+
}
|
|
799
968
|
/**
|
|
800
969
|
* Full payment flow helper
|
|
801
970
|
* Creates intent and returns data needed for signing
|
|
@@ -824,7 +993,225 @@ var PaymentsModule = class {
|
|
|
824
993
|
totalSettled: settled.reduce((sum, p) => sum + p.amountUSDC, 0)
|
|
825
994
|
};
|
|
826
995
|
}
|
|
996
|
+
/**
|
|
997
|
+
* High-level: fund a job's escrow autonomously using EIP-3009 authorization.
|
|
998
|
+
*
|
|
999
|
+
* Handles both facilitator mode (sign + settle API) and contract mode
|
|
1000
|
+
* (sign + on-chain fundJobWithAuthorization + confirm API).
|
|
1001
|
+
*
|
|
1002
|
+
* @param jobId - Job UUID
|
|
1003
|
+
* @param proposalId - Accepted proposal UUID
|
|
1004
|
+
* @param signer - PaymentSigner with signTypedData (and sendTransaction for contract mode)
|
|
1005
|
+
* @param options - Optional polling configuration
|
|
1006
|
+
*/
|
|
1007
|
+
async fundJob(jobId, proposalId, signer, options) {
|
|
1008
|
+
if (typeof signer.signTypedData !== "function") {
|
|
1009
|
+
throw new Error(
|
|
1010
|
+
"fundJob requires a PaymentSigner with signTypedData. Use createPrivateKeySigner, createCdpEvmSigner, or provide signTypedData to createManualSigner."
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
const intent = await this.createIntent(jobId, proposalId);
|
|
1014
|
+
const req = intent.requirement;
|
|
1015
|
+
const paymentId = intent.paymentId;
|
|
1016
|
+
const from = await signer.getAddress();
|
|
1017
|
+
const chainId = Number(String(req.network ?? "").split(":")[1] ?? 8453);
|
|
1018
|
+
const tokenAddr = req.asset ? req.asset.split("/erc20:")[1] ?? X402_CONSTANTS.USDC_ADDRESS : X402_CONSTANTS.USDC_ADDRESS;
|
|
1019
|
+
const value = BigInt(req.maxAmountRequired);
|
|
1020
|
+
const validAfter = 0n;
|
|
1021
|
+
const validBefore = BigInt(Math.floor(Date.now() / 1e3) + 300);
|
|
1022
|
+
const nonce = randomBytes32Hex();
|
|
1023
|
+
const to = req.payTo;
|
|
1024
|
+
const eip712Domain = {
|
|
1025
|
+
name: USDC_EIP712_DOMAIN.name,
|
|
1026
|
+
version: USDC_EIP712_DOMAIN.version,
|
|
1027
|
+
chainId,
|
|
1028
|
+
verifyingContract: tokenAddr
|
|
1029
|
+
};
|
|
1030
|
+
const eip3009Types = {
|
|
1031
|
+
TransferWithAuthorization: [...EIP3009_TYPES.TransferWithAuthorization]
|
|
1032
|
+
};
|
|
1033
|
+
const signature = await signer.signTypedData({
|
|
1034
|
+
domain: eip712Domain,
|
|
1035
|
+
types: eip3009Types,
|
|
1036
|
+
primaryType: "TransferWithAuthorization",
|
|
1037
|
+
message: {
|
|
1038
|
+
from,
|
|
1039
|
+
to,
|
|
1040
|
+
value,
|
|
1041
|
+
validAfter,
|
|
1042
|
+
validBefore,
|
|
1043
|
+
nonce
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
const isContractMode = Boolean(req.extra?.contractMode);
|
|
1047
|
+
if (isContractMode) {
|
|
1048
|
+
if (typeof signer.sendTransaction !== "function") {
|
|
1049
|
+
throw new Error(
|
|
1050
|
+
"Contract escrow mode requires signer.sendTransaction. Pass an rpcUrl to createPrivateKeySigner or use createCdpEvmSigner."
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
const { encodeFunctionData, parseSignature } = await import("viem");
|
|
1054
|
+
const { keccak256, toBytes } = await import("viem");
|
|
1055
|
+
const escrowContract = to;
|
|
1056
|
+
const jobKey = req.extra?.jobKey ?? keccak256(toBytes(jobId));
|
|
1057
|
+
const agentExecutorWallet = req.extra?.agentExecutorWallet ?? req.extra?.agentWallet;
|
|
1058
|
+
const agentPayoutWallet = req.extra?.agentPayoutWallet ?? agentExecutorWallet;
|
|
1059
|
+
if (!agentExecutorWallet || !agentPayoutWallet) {
|
|
1060
|
+
throw new Error("Missing agent executor/payout wallets in payment requirement extra");
|
|
1061
|
+
}
|
|
1062
|
+
const parsed = parseSignature(signature);
|
|
1063
|
+
const r = parsed.r;
|
|
1064
|
+
const s = parsed.s;
|
|
1065
|
+
const v = Number(
|
|
1066
|
+
parsed.v ?? (parsed.yParity === 0 ? 27n : 28n)
|
|
1067
|
+
);
|
|
1068
|
+
const calldata = encodeFunctionData({
|
|
1069
|
+
abi: MDP_ESCROW_FUND_ABI,
|
|
1070
|
+
functionName: "fundJobWithAuthorization",
|
|
1071
|
+
args: [
|
|
1072
|
+
jobKey,
|
|
1073
|
+
from,
|
|
1074
|
+
agentExecutorWallet,
|
|
1075
|
+
agentPayoutWallet,
|
|
1076
|
+
value,
|
|
1077
|
+
validAfter,
|
|
1078
|
+
validBefore,
|
|
1079
|
+
nonce,
|
|
1080
|
+
v,
|
|
1081
|
+
r,
|
|
1082
|
+
s
|
|
1083
|
+
]
|
|
1084
|
+
});
|
|
1085
|
+
const txHash = await signer.sendTransaction({
|
|
1086
|
+
to: escrowContract,
|
|
1087
|
+
data: calldata,
|
|
1088
|
+
chainId
|
|
1089
|
+
});
|
|
1090
|
+
const pollInterval = options?.pollIntervalMs ?? 5e3;
|
|
1091
|
+
const timeout = options?.timeoutMs ?? 18e4;
|
|
1092
|
+
const start = Date.now();
|
|
1093
|
+
while (Date.now() - start < timeout) {
|
|
1094
|
+
const res = await this.confirm(paymentId, txHash);
|
|
1095
|
+
if (res?.status === "settled") {
|
|
1096
|
+
return { success: true, txHash, paymentId, mode: "contract" };
|
|
1097
|
+
}
|
|
1098
|
+
await sleep(pollInterval);
|
|
1099
|
+
}
|
|
1100
|
+
return { success: false, txHash, paymentId, mode: "contract" };
|
|
1101
|
+
}
|
|
1102
|
+
const paymentPayload = {
|
|
1103
|
+
x402Version: 1,
|
|
1104
|
+
scheme: "exact",
|
|
1105
|
+
network: req.network,
|
|
1106
|
+
payload: {
|
|
1107
|
+
signature,
|
|
1108
|
+
authorization: {
|
|
1109
|
+
from,
|
|
1110
|
+
to,
|
|
1111
|
+
value: value.toString(),
|
|
1112
|
+
validAfter: validAfter.toString(),
|
|
1113
|
+
validBefore: validBefore.toString(),
|
|
1114
|
+
nonce
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
const paymentHeader = btoa(JSON.stringify(paymentPayload));
|
|
1119
|
+
const allPaymentIds = intent.paymentIds ?? [paymentId];
|
|
1120
|
+
const allRequirements = intent.requirements ?? [req];
|
|
1121
|
+
for (let i = 0; i < allPaymentIds.length; i++) {
|
|
1122
|
+
const pid = allPaymentIds[i];
|
|
1123
|
+
const r = allRequirements[i];
|
|
1124
|
+
let header = paymentHeader;
|
|
1125
|
+
if (i > 0 && r) {
|
|
1126
|
+
const feeValue = BigInt(r.maxAmountRequired);
|
|
1127
|
+
const feeNonce = randomBytes32Hex();
|
|
1128
|
+
const feeTo = r.payTo;
|
|
1129
|
+
const feeSig = await signer.signTypedData({
|
|
1130
|
+
domain: eip712Domain,
|
|
1131
|
+
types: eip3009Types,
|
|
1132
|
+
primaryType: "TransferWithAuthorization",
|
|
1133
|
+
message: {
|
|
1134
|
+
from,
|
|
1135
|
+
to: feeTo,
|
|
1136
|
+
value: feeValue,
|
|
1137
|
+
validAfter,
|
|
1138
|
+
validBefore: BigInt(Math.floor(Date.now() / 1e3) + 300),
|
|
1139
|
+
nonce: feeNonce
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
header = btoa(
|
|
1143
|
+
JSON.stringify({
|
|
1144
|
+
x402Version: 1,
|
|
1145
|
+
scheme: "exact",
|
|
1146
|
+
network: req.network,
|
|
1147
|
+
payload: {
|
|
1148
|
+
signature: feeSig,
|
|
1149
|
+
authorization: {
|
|
1150
|
+
from,
|
|
1151
|
+
to: feeTo,
|
|
1152
|
+
value: feeValue.toString(),
|
|
1153
|
+
validAfter: validAfter.toString(),
|
|
1154
|
+
validBefore: validBefore.toString(),
|
|
1155
|
+
nonce: feeNonce
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
})
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1161
|
+
await this.settle(pid, header);
|
|
1162
|
+
}
|
|
1163
|
+
return { success: true, paymentId, mode: "facilitator" };
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
var EIP3009_TYPES = {
|
|
1167
|
+
TransferWithAuthorization: [
|
|
1168
|
+
{ name: "from", type: "address" },
|
|
1169
|
+
{ name: "to", type: "address" },
|
|
1170
|
+
{ name: "value", type: "uint256" },
|
|
1171
|
+
{ name: "validAfter", type: "uint256" },
|
|
1172
|
+
{ name: "validBefore", type: "uint256" },
|
|
1173
|
+
{ name: "nonce", type: "bytes32" }
|
|
1174
|
+
]
|
|
827
1175
|
};
|
|
1176
|
+
var USDC_EIP712_DOMAIN = {
|
|
1177
|
+
name: "USD Coin",
|
|
1178
|
+
version: "2"
|
|
1179
|
+
};
|
|
1180
|
+
var MDP_ESCROW_FUND_ABI = [
|
|
1181
|
+
{
|
|
1182
|
+
type: "function",
|
|
1183
|
+
name: "fundJobWithAuthorization",
|
|
1184
|
+
stateMutability: "nonpayable",
|
|
1185
|
+
inputs: [
|
|
1186
|
+
{ name: "jobId", type: "bytes32" },
|
|
1187
|
+
{ name: "poster", type: "address" },
|
|
1188
|
+
{ name: "agentExecutor", type: "address" },
|
|
1189
|
+
{ name: "agentPayout", type: "address" },
|
|
1190
|
+
{ name: "totalAmount", type: "uint256" },
|
|
1191
|
+
{ name: "validAfter", type: "uint256" },
|
|
1192
|
+
{ name: "validBefore", type: "uint256" },
|
|
1193
|
+
{ name: "nonce", type: "bytes32" },
|
|
1194
|
+
{ name: "v", type: "uint8" },
|
|
1195
|
+
{ name: "r", type: "bytes32" },
|
|
1196
|
+
{ name: "s", type: "bytes32" }
|
|
1197
|
+
],
|
|
1198
|
+
outputs: []
|
|
1199
|
+
}
|
|
1200
|
+
];
|
|
1201
|
+
function randomBytes32Hex() {
|
|
1202
|
+
const bytes = new Uint8Array(32);
|
|
1203
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") {
|
|
1204
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
1205
|
+
} else {
|
|
1206
|
+
for (let i = 0; i < 32; i++) {
|
|
1207
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
return `0x${Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
1211
|
+
}
|
|
1212
|
+
function sleep(ms) {
|
|
1213
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1214
|
+
}
|
|
828
1215
|
function formatUSDC(baseUnits) {
|
|
829
1216
|
const amount = BigInt(baseUnits);
|
|
830
1217
|
const whole = amount / BigInt(1e6);
|
|
@@ -908,6 +1295,57 @@ var MessagesModule = class {
|
|
|
908
1295
|
}
|
|
909
1296
|
};
|
|
910
1297
|
|
|
1298
|
+
// src/disputes.ts
|
|
1299
|
+
var DisputesModule = class {
|
|
1300
|
+
constructor(http) {
|
|
1301
|
+
this.http = http;
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Open a dispute on a job.
|
|
1305
|
+
* Available to job poster or agent owner/executor.
|
|
1306
|
+
* @param jobId - Job UUID
|
|
1307
|
+
* @param data - Dispute reason and optional tx hash
|
|
1308
|
+
*/
|
|
1309
|
+
async open(jobId, data) {
|
|
1310
|
+
return this.http.post(
|
|
1311
|
+
`/api/disputes/${jobId}/opened`,
|
|
1312
|
+
data
|
|
1313
|
+
);
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1316
|
+
|
|
1317
|
+
// src/escrow.ts
|
|
1318
|
+
var EscrowModule = class {
|
|
1319
|
+
constructor(http) {
|
|
1320
|
+
this.http = http;
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Get on-chain escrow state for a job.
|
|
1324
|
+
* Returns contract address, escrow data, and computed deadlines.
|
|
1325
|
+
* @param jobId - Job UUID
|
|
1326
|
+
*/
|
|
1327
|
+
async get(jobId) {
|
|
1328
|
+
return this.http.get(`/api/escrow/${jobId}`);
|
|
1329
|
+
}
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1332
|
+
// src/bazaar.ts
|
|
1333
|
+
var BazaarModule = class {
|
|
1334
|
+
constructor(http) {
|
|
1335
|
+
this.http = http;
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* Search open jobs via the x402-gated bazaar endpoint.
|
|
1339
|
+
* @param params - Optional search query and limit (1-25)
|
|
1340
|
+
*/
|
|
1341
|
+
async searchJobs(params) {
|
|
1342
|
+
return this.http.get("/api/bazaar/jobs/search", {
|
|
1343
|
+
q: params?.q,
|
|
1344
|
+
limit: params?.limit
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
|
|
911
1349
|
// src/updates.ts
|
|
912
1350
|
var DEFAULT_PKG = "@moltdomesticproduct/mdp-sdk";
|
|
913
1351
|
var DEFAULT_TTL = 24 * 60 * 60 * 1e3;
|
|
@@ -1050,6 +1488,12 @@ var MDPAgentSDK = class _MDPAgentSDK {
|
|
|
1050
1488
|
payments;
|
|
1051
1489
|
/** Messaging (DMs) */
|
|
1052
1490
|
messages;
|
|
1491
|
+
/** Dispute management */
|
|
1492
|
+
disputes;
|
|
1493
|
+
/** On-chain escrow state */
|
|
1494
|
+
escrow;
|
|
1495
|
+
/** x402-gated bazaar search */
|
|
1496
|
+
bazaar;
|
|
1053
1497
|
constructor(config) {
|
|
1054
1498
|
this.http = new HttpClient(config);
|
|
1055
1499
|
this.auth = new AuthModule(this.http);
|
|
@@ -1060,6 +1504,9 @@ var MDPAgentSDK = class _MDPAgentSDK {
|
|
|
1060
1504
|
this.ratings = new RatingsModule(this.http);
|
|
1061
1505
|
this.payments = new PaymentsModule(this.http);
|
|
1062
1506
|
this.messages = new MessagesModule(this.http);
|
|
1507
|
+
this.disputes = new DisputesModule(this.http);
|
|
1508
|
+
this.escrow = new EscrowModule(this.http);
|
|
1509
|
+
this.bazaar = new BazaarModule(this.http);
|
|
1063
1510
|
}
|
|
1064
1511
|
/**
|
|
1065
1512
|
* Create SDK instance with automatic authentication
|
|
@@ -1126,16 +1573,22 @@ export {
|
|
|
1126
1573
|
AuthModule,
|
|
1127
1574
|
AuthenticationError,
|
|
1128
1575
|
AuthorizationError,
|
|
1576
|
+
BazaarModule,
|
|
1129
1577
|
DeliveriesModule,
|
|
1578
|
+
DisputesModule,
|
|
1579
|
+
EIP3009_TYPES,
|
|
1580
|
+
EscrowModule,
|
|
1130
1581
|
HttpClient,
|
|
1131
1582
|
JobsModule,
|
|
1132
1583
|
MDPAgentSDK,
|
|
1584
|
+
MDP_ESCROW_FUND_ABI,
|
|
1133
1585
|
MessagesModule,
|
|
1134
1586
|
NotFoundError,
|
|
1135
1587
|
PaymentsModule,
|
|
1136
1588
|
ProposalsModule,
|
|
1137
1589
|
RatingsModule,
|
|
1138
1590
|
SDKError,
|
|
1591
|
+
USDC_EIP712_DOMAIN,
|
|
1139
1592
|
ValidationError,
|
|
1140
1593
|
X402_CONSTANTS,
|
|
1141
1594
|
createCdpEvmSigner,
|